Beispiel #1
0
 /**
  * Takes in an Registry and returns a ProjectState matching it.
  *
  * @param Registry $registry
  *
  * @return ProjectState
  *
  * @since 1.1.0
  *
  * @author Eddilbert Macharia (http://eddmash.com) <*****@*****.**>
  */
 public static function fromApps($registry)
 {
     $modelStates = [];
     foreach ($registry->getModels() as $modelName => $modelObj) {
         $modelStates[$modelName] = ModelState::fromModel($modelObj);
     }
     return static::createObject($modelStates);
 }
Beispiel #2
0
 /**
  * @param array $config
  * @ignore
  */
 public function __construct($config = [])
 {
     self::configure($this, $config);
     // setup the registry
     $this->registryCache = Registry::createObject();
     if (empty($this->migrationPath)) {
         $this->migrationPath = sprintf('%smigrations%s', APPPATH, DIRECTORY_SEPARATOR);
     }
     if (empty($this->modelsPath)) {
         $this->modelsPath = sprintf('%smodels%s', APPPATH, DIRECTORY_SEPARATOR);
     }
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public function getReverseRelatedObjects()
 {
     if (empty($this->_reverseRelationTreeCache)) {
         $allRelations = [];
         /* @var $model Model */
         /* @var $field RelatedField */
         $allModels = $this->registry->getModels(true);
         // collect all relation fields for this each model
         foreach ($allModels as $name => $model) {
             // just get the forward fields
             $fields = $model->meta->_getFields(['includeParents' => false, 'reverse' => false]);
             foreach ($fields as $field) {
                 if ($field->isRelation && $field->getRelatedModel() !== null) {
                     $allRelations[$field->relation->toModel->meta->modelName][$field->name] = $field;
                 }
             }
         }
         // set cache relation to models
         foreach ($allModels as $name => $model) {
             // get fields for each model
             $fields = isset($allRelations[$name]) ? $allRelations[$name] : [];
             $model->meta->_reverseRelationTreeCache = $fields;
         }
     }
     return $this->_reverseRelationTreeCache;
 }
Beispiel #4
0
 /**
  * {@inheritdoc}
  */
 public function __construct($modelStates)
 {
     parent::__construct();
     $this->_populate($modelStates);
 }