/** * @param IKernel $kernel * @param IController $controller * @param string $action * * @return array */ public function injectActionParameters(IKernel $kernel, IController $controller, $action) { $injectedParameters = array(); $neededParameters = array(); $parametersAvailable = array($kernel->getResponse(), $kernel->getRequest(), $kernel->getServer(), $kernel->getEntityManager(), $this); try { $reflectionClass = new \ReflectionClass($controller); $parameters = $reflectionClass->getMethod($action)->getParameters(); } catch (\ReflectionException $e) { $parameters = array(); } foreach ($parameters as $parameter) { if ($parameter->getClass() != NULL) { $neededParameters[] = $parameter->getClass()->getName(); } } foreach ($neededParameters as $type) { foreach ($parametersAvailable as $parameter) { if ($parameter instanceof $type) { $injectedParameters[] = $parameter; } } } return $injectedParameters; }
/** * @param IConfiguration $applicationConfiguration */ public function init(IConfiguration $applicationConfiguration) { $this->router->parseExpressions(); $this->router->detectCurrentRoute($this->kernel->getRequest()->url(), $this->kernel->getServer()->getRequestMethod()); $this->kernel->getRequest()->assignExpressionValues($this->router); $ds = DIRECTORY_SEPARATOR; $proxyPath = $this->kernel->getServer()->getDocumentRoot() . "var" . $ds . "cache" . $ds . "Proxies"; $entityPath = $this->kernel->getServer()->getDocumentRoot() . "src"; if (!file_exists($proxyPath)) { mkdir($proxyPath, 0770, true); } $isDevMode = $applicationConfiguration->get("devmode") == true; $emConfig = Setup::createAnnotationMetadataConfiguration(array($entityPath), $isDevMode, $proxyPath); /*$emConfig->addCustomStringFunction("GROUP_CONCAT", "DoctrineExtensions\\Query\\Mysql\\GroupConcat"); $emConfig->addCustomStringFunction("DATE_FORMAT", "DoctrineExtensions\\Query\\Mysql\\DateFormat"); $emConfig->addCustomStringFunction("IFNULL", "DoctrineExtensions\\Query\\Mysql\\IfNull"); $emConfig->addCustomStringFunction("STR_TO_DATE", "DoctrineExtensions\\Query\\Mysql\\StrToDate"); $emConfig->addCustomStringFunction("CONCAT_WS", "DoctrineExtensions\\Query\\Mysql\\ConcatWs"); $emConfig->addCustomStringFunction("DATEDIFF", "DoctrineExtensions\\Query\\Mysql\\DateDiff"); $emConfig->addCustomStringFunction("MATCH_AGAINST", "DoctrineExtensions\\Query\\Mysql\\MatchAgainst"); $emConfig->addCustomStringFunction("REGEXP", "DoctrineExtensions\\Query\\Mysql\\Regexp"); $emConfig->addCustomStringFunction("IFELSE", "DoctrineExtensions\\Query\\Mysql\\IfElse");*/ if (!empty($applicationConfiguration->get("repository-factory"))) { $repositoryFactory = $applicationConfiguration->get("repository-factory"); $emConfig->setRepositoryFactory(new $repositoryFactory()); } if (!$isDevMode) { $memcache = new \Memcache(); $memcache->addServer("127.0.0.1", 11211); $cacheDriver = new MemcacheCache(); $cacheDriver->setMemcache($memcache); $cacheDriver->setNamespace($this->kernel->getServer()->getHttpHost()); $emConfig->setResultCacheImpl($cacheDriver); $emConfig->setQueryCacheImpl($cacheDriver); $emConfig->setMetadataCacheImpl($cacheDriver); } $conn = array('dbname' => $applicationConfiguration->get("dbname"), 'user' => $applicationConfiguration->get("dbuser"), 'password' => $applicationConfiguration->get("dbpassword"), 'host' => $applicationConfiguration->get("dbhost"), 'charset' => $applicationConfiguration->get("dbcharset"), 'driver' => $applicationConfiguration->get("dbdriver")); $em = $this->injector->getClassname("doctrine.entitymanager"); $this->kernel->setEntityManager($em::create($conn, $emConfig)); }