y_

php prototyping library v0.1

Authentication, http requests, internationalization, updating data and logging the changes... all those functions you need to rewrite each time you want to prototype a php application!

y_ handles these functions and lets you focus on important things.

Available functions:

y_dbload()

function y_dbload($arg){
   global $y_feedback;
   $dbfullpath=$arg.'.json';
   if(is_file($dbfullpath)){
      $res=json_decode(file_get_contents($dbfullpath),true);
      return $res;
   }else{
      $y_feedback[]='base de données pas trouvée';
      return $y_feedback;
   }
}

y_auth()

y_i18n() +

if ($_REQUEST['lang']!=null) {$lang=$_REQUEST['lang'];} else {$lang='';}
function y_i18n($words){
   $langdir='lang/';
   global $lang;
   if (!is_file($langdir.$lang.'.txt')){
      $lang='fr';
   }
   $lang_array=json_decode(file_get_contents($langdir.$lang.'.txt'),true);
   foreach($lang_array as $k=>$v){
      if ($k==$words){
         return $v;
      }
   }
}

y_array_read()

function y_array_read(array $table,array $path){
   global $path_index, $result;
   if($path[0]==null){
      $result=$table;
   }else{
      $path_current=array_shift($path);
      if ($path!=null){
         y_array_read($table[$path_current],$path);
      }else{
         $result=$table[$path_current];
      }
   }
   return $result;
}

y_array_write()

function y_array_write_inner(array $path, $value){
   $result=array();
   $path_current=array_shift($path);
   if ($path!=null){
      $result[$path_current]=y_array_write_inner($path, $value);
   }else{
      $result[$path_current]=$value;
   }
   return $result;
}
function y_array_write(array $table, array $path, $value){
   return array_replace_recursive($table, y_array_write_inner($path,$value));
}

y_dbcrud()

function y_dbcrud(string $db, array $scope, $to){
   global $y_user, $y_var;
   $db_data=y_dbload($db);	
   if(is_array($db_data)){
      file_put_contents($db.'.json',json_encode(
         y_array_write($db_data,$scope,$to)
      ));
      $log_temp=y_dbload($y_var['log_db_path']);	
      if(is_array($log_temp)){
         $from=y_array_read($db_data,$scope);
         $log_temp[]=array(
            'date'=>date('Y-m-d H:i:s'),
            'user'=>$y_user,
            'db'=>$db,
            'scope'=>$scope,
            'from'=>$from,
            'to'=>$to
         );
         file_put_contents($y_var['log_db_path'].'.json',json_encode($log_temp));
         unset($log_temp);
      }
      unset($db_data);
   }
}

y_request() + request.json

Available variables:

Get started: