This is called after initialize the model

@param Event $event
@param ModelsManager $manager
@param $model
323259
public function afterInitialize(Event $event, ModelsManager $manager, $model)
    {
        //Reflector
        /** @var \Phalcon\Annotations\Reflection $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();
                        $model->setConnectionService($arguments[0]);
                        $manager->setModelSource($model, $arguments[1]);
                        break;
                    /**
                     * Initializes Has-Many relations
                     */
                    case 'HasMany':
                        $arguments = $annotation->getArguments();
                        if (!isset($arguments[3])) {
                            $arguments[3] = null;
                        }
                        $manager->addHasMany($model, $arguments[0], $arguments[1], $arguments[2], $arguments[3]);
                        break;
                    /**
                     * Initializes Has-Many-To-Many relations
                     */
                    case 'HasManyToMany':
                        $arguments = $annotation->getArguments();
                        if (!isset($arguments[6])) {
                            $arguments[6] = null;
                        }
                        $manager->addHasManyToMany($model, $arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6]);
                        break;
                    /**
                     * Initializes Has-One relations
                     */
                    case 'HasOne':
                        $arguments = $annotation->getArguments();
                        if (!isset($arguments[3])) {
                            $arguments[3] = null;
                        }
                        $manager->addHasOne($model, $arguments[0], $arguments[1], $arguments[2], $arguments[3]);
                        break;
                    /**
                     * Initializes Has-Many relations
                     */
                    case 'BelongsTo':
                        $arguments = $annotation->getArguments();
                        if (!isset($arguments[3])) {
                            $arguments[3] = null;
                        }
                        $manager->addBelongsTo($model, $arguments[0], $arguments[1], $arguments[2], $arguments[3]);
                        break;
                }
            }
        }
    }
788408
public function addToManager(Manager $manager)
    {
        $this->registerFixedTypes($manager);
        $this->registerPeripheralTypes($manager);

        $this->extend('onBeforeAddToManager', $manager);

        // Add all DataObjects to the manager
        foreach ($this->types as $scaffold) {
            $scaffold->addToManager($manager);
            $inheritanceScaffolder = new InheritanceScaffolder(
                $scaffold->getDataObjectClass(),
                StaticSchema::config()->get('inheritanceTypeSuffix')
            );
            // Due to shared ancestry, it's inevitable that the same union type will get added multiple times.
            if (!$manager->hasType($inheritanceScaffolder->getName())) {
                $inheritanceScaffolder->addToManager($manager);
            }
        }

        foreach ($this->queries as $scaffold) {
            $scaffold->addToManager($manager);
        }

        foreach ($this->mutations as $scaffold) {
            $scaffold->addToManager($manager);
        }

        $this->extend('onAfterAddToManager', $manager);
    }
1169608
public function attach(EventManagerInterface $events)
    {
        $this->listeners[] = $events->attach(
            MvcEvent::EVENT_RENDER,
            [$this, 'renderLayoutSegments'],
            -100
        );
    }
382043
public function setEventManager(EventManagerInterface $eventManager)
    {
        if ($this->eventManager === $eventManager || $eventManager === null) {
            return;
        }

        if ($this->eventManager !== null) {
            $this->detach($this->eventManager);
        }

        $this->eventManager = $eventManager;
        $this->eventManager->addIdentifiers([
            'EntityService',
            'PolderKnowledge\EntityService\Service\EntityService',
            $this->getEntityServiceName(),
            trim($this->getEntityServiceName(), '\\'),
        ]);

        $this->attach($this->eventManager);
    }
225700
public function attach(EventManagerInterface $events)
    {
        $this->listeners[] = $events->attach(MvcEvent::EVENT_BOOTSTRAP,
            array(
                $this,
                'initialize'
            ), 1001);
        $this->listeners[] = $events->attach(MvcEvent::EVENT_BOOTSTRAP,
            array(
                $this,
                'check'
            ), 1000);
    }
641891
public function beforeValidationOnUpdate(Event $event, Model $model)
    {
        if($model instanceof ITimestampable) {
            $now = $this->getNow();
            $model->setUpdatedAt($now);
        }
    }
282735
public function load(ObjectManager $manager)
    {
        if (true == $this->hasReference('workflow-function-validator-production')) {
            $workflowRight = new WorkflowRight();
            $workflowRight->setUserId($this->getReference('user-admin')->getId());

            $authorization = new Authorization();
            $authorization->setReferenceId(WorkflowRightInterface::NODE);
            $authorization->addWorkflowFunction($this->getReference('workflow-function-validator-production'));

            $workflowRight->addAuthorization($authorization);

            $manager->persist($workflowRight);
            $manager->flush();
        }
    }
706757
@Override
    public boolean invoke(Manager manager, Object event) {
        try {
            Object[] arguments = resolveArguments(manager, event);
            if (containsNull(arguments)) {
                return false;
            }
            if (!method.isAccessible()) {
                method.setAccessible(true);
            }
            method.invoke(target, arguments);
            return true;
        } catch (Exception e) {
            if (e instanceof InvocationTargetException) {
                Throwable cause = ((InvocationTargetException) e).getTargetException();
                // Exception already wrapped by another Observer down the chain.
                if (cause instanceof InvocationException) {
                    throw (InvocationException) cause;
                }
                throw new InvocationException(cause);
            }
            throw new InvocationException(e);
        }
    }
1234527
public function init(ModuleManagerInterface $manager)
    {
        $serviceManager = $manager->getEvent()->getParam('ServiceManager');
        if ($serviceManager->get(Environment::class)->is(self::ENVIRONMENT_CLI)) {
            $manager->getEventManager()->attach(
                ModuleEvent::EVENT_LOAD_MODULES_POST,
                [$this, 'addCliConfig'],
                PHP_INT_MAX
            );
        }
        $manager->getEventManager()->attach(ModuleEvent::EVENT_MERGE_CONFIG, [$this, 'onMergeConfig']);
    }
788437
public function startup($event)
    {
        // startup-event
        $_event = new Event('Component.Manager.startup', $this, [
        ]);
        $this->Controller->eventManager()->dispatch($_event);

        if ($this->isPrefix()) {
            $this->_runCallback("startup", $event);

            // startup-event with Prefix
            $this->_runEvent("startup");
        }
    }
613858
public function attach(EventManagerInterface $events)
    {
        $sharedManager = $events->getSharedManager();
        $sharedManager->attach(ManagerRegistryFactory::class, ManagerRegistryFactory::EVENT_BUILD_LIST_CONNECTIONS, [$this, 'buildListConnectionsHandler']);
        $sharedManager->attach(ManagerRegistryFactory::class, ManagerRegistryFactory::EVENT_BUILD_LIST_OBJECT_MANAGERS, [$this, 'buildListObjectManagersHandler']);
    }
12449
public function beforeValidationOnCreate(Event $event, Model $model)
    {
        if ($model instanceof ISequenceSubject) {
            $type = $model->getSequenceType();
            //查找服务
            $generatorName = $this->getDi()->get('config')->get('model.sequence.' . $type);
            if (!$generatorName) {
                throw new NonExistingGeneratorException($generatorName);
            }

            /** @var IGenerator $generator */
            $generator = $this->getDi()->get($generatorName);

            $model->setNumber($generator->generate($model));
        }
    }
778703
public function getColumn(Model $model, $event)
    {
        if (!array_key_exists($event, $this->getBlameableFields($model))) {
            return;
        }

        $fields = $this->getBlameableFields($model);

        return $fields[$event];
    }
1127575
public function load(ObjectManager $manager)
    {
        /**
         * @var ObjectDirector $categoryDirector
         */
        $categoryDirector = $this->getDirector('category');

        /**
         * Category.
         *
         * @var CategoryInterface $rootCategory
         */
        $rootCategory = $categoryDirector
            ->create()
            ->setName('root-category')
            ->setSlug('root-category')
            ->setEnabled(true)
            ->setRoot(true);

        $categoryDirector->save($rootCategory);
        $this->addReference('rootCategory', $rootCategory);

        /**
         * Category.
         *
         * @var CategoryInterface $category
         */
        $category = $categoryDirector
            ->create()
            ->setName('category')
            ->setSlug('category')
            ->setEnabled(true)
            ->setParent($rootCategory)
            ->setRoot(false);

        $categoryDirector->save($category);
        $this->addReference('category', $category);

        /**
         * Second level category.
         *
         * @var CategoryInterface $secondLevelCategory
         */
        $secondLevelCategory = $categoryDirector
            ->create()
            ->setName('Second level category')
            ->setSlug('second-level-category')
            ->setEnabled(true)
            ->setParent($category)
            ->setRoot(false);

        $categoryDirector->save($secondLevelCategory);
        $this->addReference('secondLevelCategory', $secondLevelCategory);
    }
306987
protected function fireValidatingEvent(Model $model, $event)
    {
        return Event::until("eloquent.validating: ".get_class($model), [$model, $event]);
    }
289153
private function updateCounter(ModelEvent $event, $action)
    {
        if (!$this->constraint->isVersioningService()) {
            return;
        }

        $qb = $this->documentManager->createQueryBuilder($event->getCollectionClass());
        if ('update' == $action) {
            $qb->findAndUpdate()
                ->field('id')->equals($event->getCollectionId())
                ->field(VersionServiceConstraint::FIELD_NAME)->inc(1)
                ->getQuery()->execute();
        } else {
            $qb->findAndUpdate()
                ->field('id')->equals($event->getCollectionId())
                ->field(VersionServiceConstraint::FIELD_NAME)->set(1)
                ->getQuery()->execute();
        }
    }
367474
void initialize() throws ManagerCommunicationException
    {
        ResponseEvents re;

        re = server.sendEventGeneratingAction(new AgentsAction());

        for (ManagerEvent event : re.getEvents())
        {
            if (event instanceof AgentsEvent)
            {
                logger.info( event );
                handleAgentsEvent((AgentsEvent) event);
            }
        }
    }