Пример #1
0
 /**
  * @param Request $request
  * @return Translator
  * @throws NoAvailableLocalesException
  */
 public function getTranslator(Request $request)
 {
     $dictionaryPaths = $this->config->get('dictionary.paths', []);
     if (!is_array($dictionaryPaths)) {
         $dictionaryPaths = [$dictionaryPaths];
     }
     foreach ($dictionaryPaths as $key => $path) {
         $dictionaryPaths[$key] = sprintf('%s/%s', $this->serverContext->getPath(ServerContext::DIR_ROOT), $path);
     }
     return new Translator($this->getLocalizer($request), $dictionaryPaths);
 }
Пример #2
0
 /**
  * @param Request $request
  * @return Action
  * @throws UnknownRouteException
  */
 public function route(Request $request)
 {
     list($actionName, $routeParameters) = $this->breakdownRoute($request);
     $template = $this->config->get(self::CONFIG_KEY_ACTION_NAMESPACE, sprintf('%s\\action', $this->serverContext->getApplication()));
     $actionClass = sprintf('%s\\%s', $template, self::wordize($actionName));
     if (!class_exists($actionClass)) {
         throw new UnknownRouteException(sprintf('Cannot find action: %s', $actionClass));
     }
     $request->query->add($routeParameters);
     return new $actionClass();
 }
Пример #3
0
 /**
  * @return EntityManager
  * @throws ProxiesNotWritableException
  * @throws \Doctrine\ORM\ORMException
  */
 public function getEntityManager()
 {
     $proxiesDir = $this->serverContext->getPath(ServerContext::DIR_TMP) . '/doctrineProxies';
     !is_dir($proxiesDir) && @mkdir($proxiesDir, 0755);
     if (!is_dir($proxiesDir) || !is_writable($proxiesDir)) {
         throw new ProxiesNotWritableException(sprintf('Doctrine proxies dir does not exists or not writeable: %s', $proxiesDir));
     }
     $connConfig = DoctrineSetup::createAnnotationMetadataConfiguration([$this->serverContext->getPath(ServerContext::DIR_SRC)], true);
     $connConfig->setProxyDir($proxiesDir);
     $connConfig->setProxyNamespace('Proxies');
     $conn = ['driver' => $this->config->get('doctrine.driver'), 'host' => $this->config->get('mysql.host'), 'dbname' => $this->config->get('mysql.dbname'), 'user' => $this->config->get('mysql.username'), 'password' => $this->config->get('mysql.password')];
     $em = EntityManager::create($conn, $connConfig);
     if ($logger = $this->config->get('doctrine.logger')) {
         $loggerClass = sprintf('\\Doctrine\\DBAL\\Logging\\%s', $logger);
         $em->getConfiguration()->setSQLLogger(new $loggerClass());
     }
     $em->getConfiguration()->setNamingStrategy(new UnderscoreNamingStrategy());
     return $em;
 }
Пример #4
0
 public function testInit()
 {
     $this->assertEquals('fooEnv', $this->serverContext->getEnvironment());
     $this->assertEquals('fooApp', $this->serverContext->getApplication());
     $this->assertEquals($this->rootPath . '/src', $this->serverContext->getPath(ServerContext::DIR_SRC));
     $this->assertEquals($this->rootPath . '/action', $this->serverContext->getPath(ServerContext::DIR_ACTIONS));
     $this->assertEquals($this->rootPath . '/config', $this->serverContext->getPath(ServerContext::DIR_CONFIG));
     $this->assertEquals($this->rootPath . '/public', $this->serverContext->getPath(ServerContext::DIR_PUBLIC));
 }
Пример #5
0
 /**
  * @param ServerContext $context
  * @param $environment
  * @param $projectRootPath
  * @return ServerContext
  */
 protected function buildContext(ServerContext $context, $environment, $projectRootPath)
 {
     $context->set('ENV', $environment);
     $context->set(ServerContext::DIR_ROOT, $projectRootPath);
     $context->set(ServerContext::DIR_SRC, $context->getPath(ServerContext::DIR_ROOT) . '/src');
     $context->set(ServerContext::DIR_ACTIONS, $context->getPath(ServerContext::DIR_ROOT) . '/action');
     $context->set(ServerContext::DIR_CONFIG, $context->getPath(ServerContext::DIR_ROOT) . '/config');
     $context->set(ServerContext::DIR_PUBLIC, $context->getPath(ServerContext::DIR_ROOT) . '/public');
     $context->set(ServerContext::DIR_TMP, $context->getPath(ServerContext::DIR_ROOT) . '/tmp');
     return $context;
 }
Пример #6
0
 public function testGetPath()
 {
     $this->assertNull($this->serverContext->getPath('unknown'));
     $this->serverContext->set(ServerContext::DIR_ACTIONS, '/path/to/actions');
     $this->assertEquals('/path/to/actions', $this->serverContext->getPath(ServerContext::DIR_ACTIONS));
 }