public function asArray()
 {
     $data = [];
     $class = get_class($this);
     $reflection = new \ReflectionClass($class);
     $properties = $reflection->getProperties();
     foreach ($properties as $property) {
         $reader = new Reader($class, $property->getName(), 'property');
         $isQueryParameter = $reader->getParameter('isQueryParameter');
         $propertyName = Inflector::tableize($property->getName());
         if ($isQueryParameter === true && $this->{$property->getName()} !== null) {
             $data[$propertyName] = $this->{$property->getName()};
         }
     }
     return $data;
 }
 /**
  * @return array
  */
 public function getBody()
 {
     $data = [];
     $class = get_class($this);
     $reflection = new \ReflectionClass($class);
     $properties = $reflection->getProperties();
     foreach ($properties as $property) {
         $reader = new Reader($class, $property->getName(), 'property');
         $isBodyParameter = $reader->getParameter('isBodyParameter');
         if ($isBodyParameter === true) {
             $data[$property->getName()] = $this->{$property->getName()};
         }
     }
     return $data;
 }
Example #3
0
 public function initialize($modelClass)
 {
     $this->filterFields = null;
     $this->connect = (new DBConnector())->connector();
     $this->modelClass = $modelClass;
     $this->modelClass->_MODEL_STATUS_ = 'NEW';
     $this->reflectionClass = new \ReflectionClass($this->modelClass);
     $readerClass = new Reader($this->reflectionClass->getName());
     /****/
     $className = $this->reflectionClass->getName();
     $tableName = $readerClass->getParameter("table");
     $this->metaObject['class'] = $this->modelClass;
     $this->metaObject['className'] = $className;
     $this->metaObject['tableName'] = $tableName;
     $properties = $this->reflectionClass->getProperties();
     foreach ($properties as $property) {
         $propertyName = $property->getName();
         $parameters = new Reader($className, (string) $propertyName, 'property');
         $this->metaObject['properties'][$propertyName]['property'] = $propertyName;
         if (array_key_exists('field', $parameters->getParameters())) {
             $this->metaObject['properties'][$propertyName]['fieldName'] = $parameters->getParameter('field');
         }
         if (array_key_exists('auto', $parameters->getParameters())) {
             $this->metaObject['properties'][$propertyName]['auto'] = $parameters->getParameter('auto');
         }
         if (array_key_exists('hasOne', $parameters->getParameters())) {
             $this->metaObject['properties'][$propertyName]['hasOne'] = $parameters->getParameter('hasOne');
             $engine = new Engine();
             $engine->initialize(new $this->metaObject['properties'][$propertyName]['hasOne'](), false);
             $this->metaObject['properties'][$propertyName]['metaObject'] = $engine->getMetaObject();
             $this->metaObject['properties'][$propertyName]['engine'] = $engine;
         }
         if (array_key_exists('PK', $parameters->getParameters())) {
             $this->metaObject['PK'] = $parameters->getParameter('field');
             $this->metaObject['propertyPK'] = $propertyName;
             $this->metaObject['properties'][$propertyName]['PK'] = $parameters->getParameter('PK');
         }
         if (array_key_exists('ociseq', $parameters->getParameters())) {
             $this->metaObject['properties'][$propertyName]['ociseq'] = $parameters->getParameter('ociseq');
         }
         if (array_key_exists('belongsTo', $parameters->getParameters())) {
             $this->metaObject['properties'][$propertyName]['belongsTo'] = $parameters->getParameter('belongsTo');
             $c = $this->metaObject['properties'][$propertyName]['belongsTo'];
             if (array_key_exists($c, $this->parentEngines)) {
                 $engine = $this->parentEngines[$c];
                 //$engine->addParentEngine( $this->metaObject['className'], $this);
             } else {
                 $engine = new Engine();
                 $engine->addParentEngine($this->metaObject['className'], $this);
                 $engine->initialize(new $c());
             }
             $this->metaObject['properties'][$propertyName]['metaObject'] = $engine->getMetaObject();
             $this->metaObject['properties'][$propertyName]['engine'] = $engine;
         }
         if (array_key_exists('hasOne', $parameters->getParameters())) {
             $this->metaObject['properties'][$propertyName]['hasOne'] = $parameters->getParameter('hasOne');
             $c = $this->metaObject['properties'][$propertyName]['hasOne'];
             if (array_key_exists($c, $this->parentEngines)) {
                 $engine = $this->parentEngines[$c];
                 //$engine->addParentEngine( $this->metaObject['className'], $this);
             } else {
                 $engine = new Engine();
                 $engine->addParentEngine($this->metaObject['className'], $this);
                 $engine->initialize(new $c());
             }
             $this->metaObject['properties'][$propertyName]['metaObject'] = $engine->getMetaObject();
             $this->metaObject['properties'][$propertyName]['engine'] = $engine;
         }
         if (array_key_exists('hasMany', $parameters->getParameters())) {
             $this->metaObject['properties'][$propertyName]['hasMany'] = $parameters->getParameter('hasMany');
             $this->metaObject['properties'][$propertyName]['FK'] = $parameters->getParameter('FK');
             $c = $this->metaObject['properties'][$propertyName]['hasMany'];
             if (array_key_exists($c, $this->parentEngines)) {
                 $engine = $this->parentEngines[$c];
                 //$engine->addParentEngine( $this->metaObject['className'], $this);
             } else {
                 $engine = new Engine();
                 $engine->addParentEngine($this->metaObject['className'], $this);
                 $engine->initialize(new $c());
             }
             $this->metaObject['properties'][$propertyName]['metaObject'] = $engine->getMetaObject();
             $this->metaObject['properties'][$propertyName]['engine'] = $engine;
         }
         if (array_key_exists('through', $parameters->getParameters())) {
             $this->metaObject['properties'][$propertyName]['through'] = $parameters->getParameter('through');
         }
     }
     //$this->fieldFilter[] = $this->metaObject['propertyPK'];
     //echo 'fieldFilter';
     //var_dump($this->fieldFilter);
 }