/**
  * This is called after initializing the model.
  *
  * @param Phalcon\Events\Event $event
  * @param Phalcon\Mvc\Model\Manager $manager
  * @param mixed $model
  */
 public function afterInitialize(Event $event, ModelsManager $manager, $model)
 {
     $reflector = $this->annotations->get($model);
     $annotations = $reflector->getClassAnnotations();
     if ($annotations) {
         foreach ($annotations as $annotation) {
             switch ($annotation->getName()) {
                 case 'ORM\\Source':
                     $arguments = $annotation->getArguments();
                     $manager->setModelSource($model, $arguments[0]);
                     break;
                 case 'ORM\\HasMany':
                     $arguments = $annotation->getArguments();
                     $manager->addHasMany($model, $arguments[0], $arguments[1], $arguments[2]);
                     break;
                 case 'ORM\\BelongsTo':
                     $arguments = $annotation->getArguments();
                     if (isset($arguments[3])) {
                         $manager->addBelongsTo($model, $arguments[0], $arguments[1], $arguments[2], $arguments[3]);
                     } else {
                         $manager->addBelongsTo($model, $arguments[0], $arguments[1], $arguments[2]);
                     }
                     break;
             }
         }
     }
 }
Beispiel #2
0
 /**
  * This is called after initialize the model.
  *
  * @param Event         $event   Event object.
  * @param ModelsManager $manager Model manager
  * @param AbstractModel $model   Model object.
  *
  * @return string
  */
 public function afterInitialize(Event $event, ModelsManager $manager, $model)
 {
     //Reflector
     $reflector = $this->annotations->get($model);
     /**
      * Read the annotations in the class' docblock
      */
     $annotations = $reflector->getClassAnnotations();
     if ($annotations) {
         /**
          * Traverse the annotations
          */
         foreach ($annotations as $annotation) {
             switch ($annotation->getName()) {
                 /**
                  * Initializes the model's source
                  */
                 case 'Source':
                     $arguments = $annotation->getArguments();
                     $manager->setModelSource($model, $arguments[0]);
                     break;
                     /**
                      * Initializes Has-Many relations
                      */
                 /**
                  * Initializes Has-Many relations
                  */
                 case 'HasMany':
                     $arguments = $annotation->getArguments();
                     if (isset($arguments[3])) {
                         $manager->addHasMany($model, $arguments[0], $arguments[1], $arguments[2], $arguments[3]);
                     } else {
                         $manager->addHasMany($model, $arguments[0], $arguments[1], $arguments[2]);
                     }
                     break;
                     /**
                      * Initializes BelongsTo relations
                      */
                 /**
                  * Initializes BelongsTo relations
                  */
                 case 'BelongsTo':
                     $arguments = $annotation->getArguments();
                     if (isset($arguments[3])) {
                         $manager->addBelongsTo($model, $arguments[0], $arguments[1], $arguments[2], $arguments[3]);
                     } else {
                         $manager->addBelongsTo($model, $arguments[0], $arguments[1], $arguments[2]);
                     }
                     break;
             }
         }
     }
     return $event->getType();
 }
 /**
  * This is called after initialize the model
  *
  * @param Phalcon\Events\Event $event
  */
 public function afterInitialize(Event $event, ModelsManager $manager, ModelInterface $model)
 {
     //Reflector
     $reflector = $this->annotations->get($model);
     /**
      * Read the annotations in the class' docblock
      */
     $annotations = $reflector->getClassAnnotations();
     if ($annotations) {
         /**
          * Traverse the annotations
          */
         foreach ($annotations as $annotation) {
             switch ($annotation->getName()) {
                 /**
                  * Initializes the model's source
                  */
                 case 'Source':
                     $arguments = $annotation->getArguments();
                     $manager->setModelSource($model, $arguments[0]);
                     break;
                     /**
                      * Initializes Has-Many relations
                      */
                 /**
                  * Initializes Has-Many relations
                  */
                 case 'HasMany':
                     $arguments = $annotation->getArguments();
                     $manager->addHasMany($model, $arguments[0], $arguments[1], $arguments[2]);
                     break;
                     /**
                      * Initializes Has-Many relations
                      */
                 /**
                  * Initializes Has-Many relations
                  */
                 case 'BelongsTo':
                     $arguments = $annotation->getArguments();
                     if (isset($arguments[3])) {
                         $manager->addBelongsTo($model, $arguments[0], $arguments[1], $arguments[2], $arguments[3]);
                     } else {
                         $manager->addBelongsTo($model, $arguments[0], $arguments[1], $arguments[2]);
                     }
                     break;
                     /**
                      * Initializes has-One relations
                      */
                 /**
                  * Initializes has-One relations
                  */
                 case 'hasOne':
                     $arguments = $annotation->getArguments();
                     if (isset($arguments[3])) {
                         $manager->addHasOne($model, $arguments[0], $arguments[1], $arguments[2], $arguments[3]);
                     } else {
                         $manager->addHasOne($model, $arguments[0], $arguments[1], $arguments[2]);
                     }
                     break;
                     /**
                      * Initializes hasManyToMany relations
                      */
                 /**
                  * Initializes hasManyToMany relations
                  */
                 case 'hasManyToMany':
                     $arguments = $annotation->getArguments();
                     if (isset($arguments[6])) {
                         $manager->addHasManyToMany($model, $arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6]);
                     } else {
                         $manager->addHasManyToMany($model, $arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5]);
                     }
                     break;
                     /**
                      * Initializes the model's Behavior
                      */
                 /**
                  * Initializes the model's Behavior
                  */
                 case 'Behavior':
                     $arguments = $annotation->getArguments();
                     $behaviorName = $arguments[0];
                     if (isset($arguments[1])) {
                         $manager->addBehavior($model, new $behaviorName($arguments[1]));
                     } else {
                         $manager->addBehavior($model, new $behaviorName());
                     }
                     break;
                     /**
                      * Initializes the model's source connection
                      */
                 /**
                  * Initializes the model's source connection
                  */
                 case 'setConnectionService':
                     $arguments = $annotation->getArguments();
                     $manager->setConnectionService($model, $arguments[0]);
                     break;
             }
         }
     }
 }