Esempio n. 1
0
 private function injectDependencies($params, $param, $rMethod)
 {
     $parameterName = $param->getName();
     if (isset($param->getClass()->name)) {
         switch ($param->getClass()->name) {
             case 'Symfony\\Component\\HttpFoundation\\Request':
                 $params[$parameterName] = $this->parser->getRequest();
                 break;
             case 'Gfw\\View':
                 $params[$parameterName] = $this->container->getView();
                 break;
             case 'Gfw\\Db':
                 $params[$parameterName] = $this->container->getDb();
                 break;
             case 'Symfony\\Component\\HttpFoundation\\Response':
                 $params[$parameterName] = $this->container->getResponse();
                 break;
             case 'Gfw\\Response\\Json':
                 $params[$parameterName] = $this->container->getJsonResponse();
                 break;
             case 'Gfw\\Container':
                 $params[$parameterName] = $this->container;
                 break;
             case 'Gfw\\Db\\PDO':
                 $rAnnotations = $rMethod->getAnnotations();
                 if ($rAnnotations->has('getPDO')) {
                     $getPDOAnotations = $rAnnotations->get('getPDO');
                     foreach ($getPDOAnotations as $getPDOAnotation) {
                         $dbName = $getPDOAnotation['args']['db'];
                         $toVariable = $getPDOAnotation['args']['toVariable'];
                         if ($toVariable == $parameterName) {
                             $params[$parameterName] = $this->container->getDb()->getPDO($dbName);
                         }
                     }
                 }
                 break;
             case 'Gfw\\Db\\Sql':
                 $rAnnotations = $rMethod->getAnnotations();
                 if ($rAnnotations->has('getSql')) {
                     $getSqlAnotations = $rAnnotations->get('getSql');
                     foreach ($getSqlAnotations as $getSqlAnotation) {
                         $dbName = $getSqlAnotation['args']['db'];
                         $toVariable = $getSqlAnotation['args']['toVariable'];
                         if ($toVariable == $parameterName) {
                             $params[$parameterName] = $this->container->getDb()->getPDO($dbName)->getSql();
                         }
                     }
                 }
                 break;
         }
     } else {
         $parameterValue = $param->isDefaultValueAvailable() ? $param->getDefaultValue() : NULL;
         $params[$parameterName] = $this->parser->getParameter($parameterName, $parameterValue);
     }
     return $params;
 }
Esempio n. 2
0
 private function getContainerFromParser(Parser $parser)
 {
     $container = new Container($parser->getRequest());
     $container['parser'] = function () use($parser) {
         return $parser;
     };
     return $container;
 }