Пример #1
0
 /**
  * Facade, implementation de la fonction magic __callStatic de PHP
  *
  * @param string $method Le nom de la method a appelé
  * @param array $args    Les arguments a passé à la fonction
  * @throws ModelException
  * @return \Bow\Database\Table
  */
 public static function __callStatic($method, $args)
 {
     $scope = 'scope' . ucfirst($method);
     $table = Database::table(Str::lower(static::$table));
     /**
      * Lancement de l'execution des fonctions aliase définir dans les classe
      * héritant de la classe Model.
      *
      * Les classes  definir définir avec la montion scope.
      */
     if (method_exists($child = new static(), $scope)) {
         if (method_exists($table, $method)) {
             throw new ModelException($method . ' ne peut pas être utiliser comme fonction d\'aliase.', E_ERROR);
         }
         return call_user_func_array([$child, $scope], $args);
     }
     /**
      * Lancement de l'execution des fonctions liée a l'instance de la classe Table
      */
     if (method_exists($table, $method)) {
         $table = call_user_func_array([$table, $method], $args);
         return static::carbornize($table, $method, $child);
     }
     throw new ModelException('methode ' . $method . ' n\'est définie.', E_ERROR);
 }
Пример #2
0
 /**
  * Vérifie si on n'est dans le cas d'un requête AJAX.
  *
  * @return boolean
  */
 public function isAjax()
 {
     if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {
         $xhrObj = Str::lower($_SERVER['HTTP_X_REQUESTED_WITH']);
         if ($xhrObj == 'xmlhttprequest' || $xhrObj == 'activexobject') {
             return true;
         }
     }
     return false;
 }
Пример #3
0
 /**
  * where, ajout condition de type where, si chainé ajout un <<and>>
  *
  * WHERE column1 $comp $value|column
  *
  * @param $column
  * @param $comp
  * @param null $value
  * @param $boolean
  *
  * @throws TableException
  *
  * @return $this
  */
 public function where($column, $comp = '=', $value = null, $boolean = 'and')
 {
     if (!static::isComporaisonOperator($comp)) {
         $value = $comp;
         $comp = '=';
     }
     // Ajout de matcher sur id.
     if ($comp == '=' && $value === null) {
         $value = $column;
         $column = 'id';
     }
     if ($value === null) {
         throw new TableException('valeur de comparaison non définir', E_ERROR);
     }
     if (!in_array(Str::lower($boolean), ['and', 'or'])) {
         throw new TableException('le booléen ' . $boolean . ' non accepté', E_ERROR);
     }
     $this->whereDataBind[$column] = $value;
     if ($this->where == null) {
         $this->where = $column . ' ' . $comp . ' :' . $column;
     } else {
         $this->where .= ' ' . $boolean . ' ' . $column . ' ' . $comp . ' :' . $column;
     }
     return $this;
 }
Пример #4
0
 /**
  * @return string
  */
 public static function unique()
 {
     return Str::lower(uniqid());
 }