コード例 #1
0
 /**
  * Altera o comportamento de empty() e isset() considerando FALSE e "" como
  * valores não vazios, use null para considerar vazio
  *
  * @param string $name
  * @return boolean
  * @todo testar esse metodo
  */
 public function __isset($name)
 {
     if (!is_callable(array($this, MethodSintaxe::buildGetterName($property)))) {
         throw new BadPropertyException($this, (string) $property);
     }
     $val = "";
     eval('$val=$this->' . MethodSintaxe::buildGetterName($name) . "();");
     return empty($val);
 }
コード例 #2
0
ファイル: Properties.php プロジェクト: laiello/samusframework
 /**
  * Altera o comportamento de empty() e isset() considerando FALSE e "" como
  * valores não vazios, use null para considerar vazio
  *
  * @param string $name
  * @return boolean
  * @todo testar esse metodo
  */
 public function __isset($name)
 {
     $val = "";
     eval('$val=$this->' . MethodSintaxe::buildGetterName($name) . "();");
     return empty($val);
 }
コード例 #3
0
ファイル: CRUD.php プロジェクト: laiello/samusframework
 /**
  * Atualiza no banco de dados um objeto, instancia de classe className, com os dados especificados que foram preenchidos
  * propriedades não especificadas são ignoradas
  * @param mixed $object
  * @param boolean|string $whereCondition caso seja true serã utilizado o valor de keyColumn
  * @param string $additionalParameters optional parametros adicionais para o UPDATE
  * @param int $limite=1 optional limite de objetos que serão atualizados, DEFAULT=1
  */
 public function update($object, $whereCondition = "", $topLevelClass = "")
 {
     if (self::isEmpty($topLevelClass)) {
         $topLevelClass = self::getTopLevelClass();
     }
     $tableName = "";
     $whereJoin = "";
     $contParent = 0;
     //$this->ref = new ReflectionClass($object);
     $ref1 = new ReflectionClass($object);
     $this->ref = $ref1;
     $parentClassesArray = array($this->ref);
     $r = $this->ref;
     while ($r->getParentClass()->getName() != $topLevelClass) {
         $r = $this->ref->getParentClass();
         $parentClassesArray[] = $r;
     }
     $parentClassesArray = array_reverse($parentClassesArray);
     $fkId = "";
     foreach ($parentClassesArray as $ref) {
         /*@var $ref ReflectionClass*/
         $colunas = "";
         $valores = "";
         $ai = new ArrayIterator($ref->getDefaultProperties());
         /**
          * @var $tempTableName string  nome da tabela q sera abaliado abaixo
          */
         $tempTableName = self::$tablePrefix . $this->upperToUnderline($ref->getName());
         $tableName .= $tempTableName . ' , ';
         while ($ai->valid()) {
             /*@var $propertie ReflectionProperty*/
             //verificar se as superclasse num tão pegando tudo
             $propertie = $ai->key();
             if ($this->validateAttributeColunm($propertie) and $propertie != self::DEFAULT_KEY_COLUNM) {
                 $valor = null;
                 $val = null;
                 $strCod = '$val = addslashes($object->' . MethodSintaxe::buildGetterName($propertie) . '());';
                 eval($strCod);
                 if ($val === false || !self::isEmpty($val) || is_int($val)) {
                     $colunas .= $tempTableName . '.' . $propertie . "= '";
                     $valor .= $val;
                     $colunas .= $valor . "' , ";
                 }
             }
             $ai->next();
         }
         $contParent++;
         //se tiver pelomenos uma classe pai
         if ($contParent > 1) {
             $whereJoin = $tempTableName . ".id = " . self::$tablePrefix . $this->upperToUnderline($parentClassesArray[$contParent - 2]->getName()) . ".id AND ";
         }
         if (!self::isEmpty($whereJoin)) {
             $whereJoin = substr($whereJoin, 0, -4);
         }
         $tableName = substr($tableName, 0, -2);
         //            if (! self::isEmpty($fkId)) { echo $fkId . '<hr>';
         //                $colunas .= self::DEFAULT_KEY_COLUNM . " , ";
         //                $valores .= $fkId . ' , ';
         //            }
         $colunas = substr($colunas, 0, -2);
         if (!self::isEmpty($whereCondition) && !is_int($whereCondition)) {
             if (substr($whereCondition, 0, 6) != " WHERE") {
                 $whereCondition = " WHERE {$tempTableName}." . $whereCondition;
             }
         } elseif (is_int($whereCondition)) {
             $this->setKeyColunm(self::DEFAULT_KEY_COLUNM);
             $whereCondition = " WHERE " . $this->getKeyColunm() . " =" . $whereCondition;
         } else {
             $whereCondition = " WHERE " . $this->getKeyColunm() . "=(" . $object->getId() . ")";
         }
         if (func_num_args() > 2) {
             $additionalParameter = func_get_arg(3);
         } else {
             $additionalParameters = "";
         }
         /*@var $refMet ReflectionMethod */
         $tableName = self::$tablePrefix . $this->upperToUnderline($ref->getName());
         $q1 = "UPDATE " . $tableName . " SET {$colunas} {$whereCondition} {$additionalParameters}";
         //mysqli_query(self::getConn() , $q1);
         self::executeQuery($q1);
         $fkId = CRUDQuery::lastInsertId();
         //            if (strlen(mysqli_error(self::getConn())) > 0) {
         //                throw new CRUDException("SQL ERROR: $q1 - " . mysqli_error(self::getConn()));
         //            }
     }
     return $object;
 }
コード例 #4
0
 /**
  * Define o tipo de escrita dos m�todos para camelCase ou n�o
  * camelCase usa maiusculas entre os nomes, se falso deve ser colocado um 
  * underline entre as palavras
  * @param $isCamelCase 
  */
 public static function setMethodSintaxe($isCamelCase = true)
 {
     self::$camelCase = $isCamelCase;
 }