예제 #1
0
 public static function getMeta($entityName)
 {
     $tableName = new String(String::set($entityName)->toLower()->split('\\.')->last());
     $entityName = String::set($entityName)->replace('.', '\\');
     $refClass = new \ReflectionClass((string) $entityName);
     $tokens = token_get_all(file_get_contents($refClass->getFileName()));
     $meta = array('System.Data.Entity.Attributes.Table' => new Attributes\Table((string) $tableName), 'System.Data.Entity.Attributes.Key' => new Attributes\Key((string) $tableName->append('_id')), 'Columns' => array());
     $tmp = array();
     $exitLoop = false;
     foreach ($tokens as $token) {
         switch ($token[0]) {
             case T_DOC_COMMENT:
                 $lines = explode(PHP_EOL, $token[1]);
                 foreach ($lines as $line) {
                     $strAttr = trim(str_replace(array('*', '/'), '', $line));
                     if ($strAttr) {
                         $attribute = String::set($strAttr)->get('@', '(');
                         $args = String::set($strAttr)->get('(', ')');
                         if (!$attribute->indexOf('.')) {
                             $attribute = $attribute->prepend('System.Data.Entity.Attributes.');
                         }
                         try {
                             $meta[(string) $attribute] = Object::getInstance($attribute, str_getcsv($args, ','));
                         } catch (\Exception $e) {
                             throw new \System\Data\Entity\EntityException('The attribute "' . (string) $attribute . '" does not exist.');
                         }
                     }
                 }
                 break;
             case T_COMMENT:
                 $attribute = String::set($token[1])->subString(2)->get('@', '(');
                 $args = String::set($token[1])->get('(', ')', true);
                 if (!$attribute->indexOf('.')) {
                     $attribute = $attribute->prepend('System.Data.Entity.Attributes.');
                 }
                 if ((string) $args) {
                     $tmp[] = Object::getInstance($attribute, str_getcsv($args, ','));
                 } else {
                     $tmp[] = Object::getInstance($attribute);
                 }
                 break;
             case T_VARIABLE:
                 $property = String::set($token[1])->subString(1);
                 $meta['Columns'][(string) $property] = $tmp;
                 $tmp = array();
                 break;
             case T_FUNCTION:
                 $exitLoop = true;
                 break;
         }
         if ($exitLoop) {
             break;
         }
     }
     $metaData = new EntityMeta((string) $entityName, $meta);
     return $metaData;
 }
예제 #2
0
 /**
  * Dispatches a controller. This method is declared final and cannot be overriden.
  * 
  * @method  run
  * @return  void
  */
 public final function run()
 {
     if ($this->routes->count() == 0) {
         throw new \RuntimeException('One or more routes must be registered.');
     }
     $controllerDispacthed = false;
     foreach ($this->routes as $route) {
         $route->setHttpRequest($this->httpContext->getRequest());
         $routeData = $route->execute();
         if ($routeData) {
             $namespace = '';
             if (Environment::getRootPath() != Environment::getControllerPath()) {
                 $namespace = String::set(Environment::getControllerPath())->replace(Environment::getRootPath(), '')->trim('/');
             }
             $moduleName = $routeData->get('module') ? $routeData->get('module') . '.' : '';
             $class = String::set(sprintf('%s.%sControllers.%sController', $namespace, ucfirst(strtolower($moduleName)), ucfirst(strtolower($routeData->get('controller')))));
             try {
                 $controller = Object::getInstance($class);
                 $controller->getRegistry()->merge(get_object_vars($this));
             } catch (\ReflectionException $e) {
                 throw new Mvc\ControllerNotFoundException(sprintf("The controller '%s' does not exist.", $class));
             }
             if (!$controller instanceof Mvc\Controller) {
                 throw new Mvc\MvcException(sprintf("The controller '%s' does not inherit from System\\Web\\Mvc\\Controller.", $class));
             }
             $moduleClassName = String::set(sprintf('%s.%sControllers.%s', $namespace, ucfirst($moduleName), 'Module'));
             $this->authenticateRequest($controller);
             $this->preAction($controller);
             $moduleInstance = Object::getInstance($moduleClassName, null, false);
             if ($moduleInstance) {
                 if (method_exists($moduleInstance, 'load')) {
                     $moduleInstance->load($controller);
                 }
             }
             $controller->execute($this->httpContext);
             if ($moduleInstance) {
                 if (method_exists($moduleInstance, 'unload')) {
                     $moduleInstance->unload($controller);
                 }
             }
             $this->postAction($controller);
             $controllerDispacthed = true;
             break;
         }
     }
     if (false === $controllerDispacthed) {
         throw new Mvc\MvcException("Unable to dispatch a controller. None of the registered routes matched the request URI.");
     }
 }