/** * @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 injectPropertiesEnvByVar(array $propertiesEnv) { if ($this->sphring->getYamlarh() === null) { return; } $yamlarh = $this->sphring->getYamlarh(); foreach ($propertiesEnv as $propertiesEnvKey => $propertiesEnvValue) { $yamlarh->addAccessibleVariable(strtolower($propertiesEnvKey), $propertiesEnvValue); } }
public function testNotFound() { $sphring = new Sphring(__DIR__ . '/../../../sphring/main.yml'); $sphring->loadContext(); $microWebFrameWork = $sphring->getBean('microwebframe.main'); $dispatcher = $microWebFrameWork->getRouter()->getDispatcher(); $request = Request::createFromGlobals(); $response = $dispatcher->dispatch($request->getMethod(), "/404"); $this->assertInstanceOf(Response::class, $response); $this->assertEquals(404, $response->getStatusCode()); }
public function initReader() { LoggerSphring::getInstance()->info("Initiating registering annotation"); $file = $this->sphring->getRootProject() . DIRECTORY_SEPARATOR . SphringComposerEnum::AUTLOADER_FILE; if (!is_file($file)) { $file = $this->sphring->getContextRoot() . DIRECTORY_SEPARATOR . SphringComposerEnum::AUTLOADER_FILE; } if (!is_file($file)) { $file = $this->getAutoloaderFromLibrary(); } if (!is_file($file)) { $file = $_SERVER['CONTEXT_DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . SphringComposerEnum::AUTLOADER_FILE; } if (!is_file($file)) { $file = dirname($this->composerManager->getComposerLockFile()) . DIRECTORY_SEPARATOR . SphringComposerEnum::AUTLOADER_FILE; } if (!is_file($file)) { throw new SphringAnnotationException("Can't found autoloader for annotation reading."); } $loader = (require $file); AnnotationRegistry::registerLoader(array($loader, 'loadClass')); }
/** * @param $beanId * @return object */ public function getBean($beanId) { return $this->sphring->getBean($beanId); }
protected function setUp() { file_put_contents(__DIR__ . '/Resources/Sphring/db.ct', 0); $sphring = new Sphring(__DIR__ . '/Resources/Sphring/main.yml'); $sphring->setRootProject(__DIR__ . '/../../..'); $sphring->setComposerLockFile(__DIR__ . '/../../../composer.lock'); $sphring->loadContext(); $this->sphring = $sphring; $_SERVER['HTTP_X_Broker_API_Version'] = '2.4'; $_SERVER['PHP_AUTH_USER'] = '******'; $_SERVER['PHP_AUTH_PW'] = 'changePassw0rd'; $this->microWebFrameWork = $sphring->getBean('microwebframe.main'); $this->dispatcher = $this->microWebFrameWork->getRouter()->getDispatcher(); $doctrineBoot = $this->sphring->getBean('microwebframe.doctrine'); $this->entityManager = $doctrineBoot->getEntityManager(); }