/** * @param $beanId * @param $info * @return AbstractBean * @throws \Arthurh\Sphring\Exception\SphringException */ public function createBean($beanId, $info) { $beanClass = $this->getType($info['type']); $bean = new $beanClass($beanId); unset($info['type']); if (!$bean instanceof AbstractBean) { throw new SphringException("'%s' is not a valid bean, it must extends '%s'", $beanClass, AbstractBean::class); } $validator = Validator::getInstance(); $sphringBoot = $this->sphring->getSphringEventDispatcher()->getSphringBoot(); $validator->setBeanPropertyListener($sphringBoot->getSphringBootBeanProperty()->getBeanPropertyListener()); try { $validator->validate($bean->getValidBeanFile(), $info); } catch (NodeValidatorException $e) { echo $bean->getValidBeanFile(); throw new SphringException("'%s' is not a valid bean: %s", $beanId, $e->getMessage(), $e); } catch (SphringException $e) { throw new SphringException("'%s' can't be validated: %s", $beanId, $e->getMessage(), $e); } $bean->setSphringEventDispatcher($this->sphring->getSphringEventDispatcher()); foreach ($info as $key => $value) { $set = 'set' . ucfirst($key); $bean->{$set}($value); } return $bean; }
/** * */ private function dispatchAnnotations() { $bean = new Bean(get_class($this)); $bean->setObject($this); $annotationDispatcher = new AnnotationsDispatcher($bean, get_class($this), $this->sphring->getSphringEventDispatcher()); $annotationDispatcher->dispatchAnnotations(); }