Ejemplo n.º 1
0
 public function _preAction()
 {
     if (!$this->request->isXHR() && !in_array($this->route->getName(), array('init', 'index', 'login', 'logout', 'tmpFile'))) {
         //            $this->redirectToUri('/');
     }
     $moduleName = Inflector::underscore(substr($this->route->getControllerName(), 0, -10));
     if (AdminService::getStructure()->has($moduleName)) {
         $moduleConfig = AdminService::getStructure($moduleName);
         $this->route->setControllerName($moduleConfig['type'] . 'Controller');
         $this->request->setVar('moduleName', $moduleName);
     }
 }
Ejemplo n.º 2
0
 public function defaultAction()
 {
     $this->writeln('Available commands:');
     $controllers = array('SolveConsole\\Controllers\\DbController', 'SolveConsole\\Controllers\\GenController');
     $commandsList = '';
     foreach ($controllers as $controllerName) {
         $r = new \ReflectionClass($controllerName);
         $name = Inflector::underscore(substr($r->getShortName(), 0, -10));
         $help = DocComment::parseFromString($r->getDocComment())->getAnnotationsAsString('help');
         $commandsList .= '  <bold>' . $name . "</bold>\t" . $help . "\n";
     }
     $this->writeln($commandsList);
 }
Ejemplo n.º 3
0
 public function configure()
 {
     parent::configure();
     $this->_slot = new Slot();
     $this->_slot->setTemplateDir($this->_view->getTemplatesPath());
     $this->_slot->setCompileDir(DC::getEnvironment()->getTmpRoot() . 'templates/' . DC::getApplication()->getName() . '/');
     $fs = new FSService();
     DC::getAutoloader()->registerSharedPath(DC::getEnvironment()->getUserClassesRoot() . 'helpers');
     if ($files = $fs->in(DC::getEnvironment()->getUserClassesRoot() . 'helpers')->find('*Block.php')) {
         foreach ($files as $file) {
             $this->_slot->registerBlock(Inflector::underscore(substr($file, strrpos($file, DIRECTORY_SEPARATOR) + 1, -9)), '\\');
         }
     }
 }
Ejemplo n.º 4
0
 public function defaultAction()
 {
     $methods = $this->_reflect->getMethods(\ReflectionMethod::IS_PUBLIC);
     $methodsList = '';
     $skippedMethods = array('_preAction', '_postAction', 'defaultAction');
     foreach ($methods as $method) {
         if (!in_array($method->getName(), $skippedMethods) && substr($method->getName(), -6) === 'Action') {
             $commandMethod = str_replace('_', '-', Inflector::underscore(substr($method->getName(), 0, -6)));
             $doc = DocComment::parseFromString($method->getDocComment());
             $optional = $doc->getAnnotationsAsString('optional');
             $methodsList .= "  <bold>" . $commandMethod . (strlen($commandMethod) < 16 ? str_repeat(' ', 12 - strlen($commandMethod)) : '') . "\t</bold>" . $doc->getDescription() . ($optional ? "\n\t\t" . $optional : "") . "\n";
         }
     }
     if (!empty($methodsList)) {
         $this->writeln('Here are methods of ' . $this->_command . ":");
         $this->writeln($methodsList);
     } else {
         $this->writeln('Command ' . $this->_commandColor . ' does not have any methods');
     }
 }
Ejemplo n.º 5
0
 public function __call($method, $params)
 {
     if (substr($method, -10) == 'RelatedIDs') {
         ModelRelation::getInstanceForModel($this)->{$method}($this, $params[0], $params[1]);
         return $this;
     } elseif (substr($method, 0, 10) == 'setRelated') {
         ModelRelation::getInstanceForModel($this)->setRelatedIDs($this, substr($method, 10), $params[0]);
         return $this;
     } elseif (substr($method, 0, 12) == 'clearRelated') {
         ModelRelation::getInstanceForModel($this)->clearRelatedIDs($this, substr($method, 12), empty($params[0]) ? array() : $params[0]);
         return $this;
     } elseif ($methodInfo = ModelOperator::getInstanceAbilityMethod($this->_name, $method)) {
         array_unshift($params, $this);
         call_user_func_array(array($methodInfo['ability'], $method), $params);
         return $this;
     } elseif (substr($method, 0, 3) == 'set') {
         $this->offsetSet(Inflector::underscore(substr($method, 3)), $params[0]);
         return $this;
     } elseif (substr($method, 0, 3) == 'get') {
         return $this->offsetGet(Inflector::underscore(substr($method, 3)));
     }
     throw new \Exception('Undefined method for model: ' . $method);
 }
Ejemplo n.º 6
0
 protected function reloadConfig()
 {
     $abilityName = get_class($this);
     $abilityName = Inflector::underscore(substr($abilityName, strrpos($abilityName, '\\') + 1, -7));
     $this->_config = $this->_modelStructure->getAbilityInfo($abilityName);
 }
Ejemplo n.º 7
0
 /**
  * @param Model $caller
  * @return string
  */
 private function _getObjectFolder($caller)
 {
     $id = $caller->getID();
     if (!intval($id)) {
         $int = ord($id[0]) . ord($id[1]);
     } else {
         $int = $id > 9 ? $id[0] . $id[1] : '0' . $id;
     }
     return Inflector::pluralize(Inflector::underscore($this->_modelName)) . '/' . $int . '/' . (int) $id % 100;
 }
Ejemplo n.º 8
0
 /**
  * @param string $modelName
  * @param string $relationName
  * @return array
  * @throws \Exception if not found relation info
  */
 public static function calculateRelationVariables($modelName, $relationName)
 {
     $relationName = Inflector::underscore($relationName);
     if (!empty(self::$_variablesCache[$modelName . $relationName])) {
         return self::$_variablesCache[$modelName . $relationName];
     }
     $modelStructure = ModelStructure::getInstanceForModel($modelName);
     $relationInfo = $modelStructure->getRelationInfo($relationName);
     if (is_null($relationInfo)) {
         throw new \Exception('Relation ' . $relationName . ' is not found, probably capitalization');
     }
     if (!is_array($relationInfo)) {
         $relationInfo = array();
     }
     $info = array();
     $info['localTable'] = $modelStructure->getTableName();
     foreach ($relationInfo as $key => $value) {
         $info[lcfirst(Inflector::camelize($key))] = $value;
     }
     if (!isset($info['model']) && !isset($info['table'])) {
         $info['model'] = ucfirst(Inflector::singularize($relationName));
     }
     if (isset($info['model'])) {
         $relatedStructure = ModelStructure::getInstanceForModel($info['model']);
         $info['foreignTable'] = $relatedStructure->getTableName();
         $info['relatedModelName'] = $info['model'];
         $info['hydration'] = 'model';
         unset($info['model']);
     } else {
         $info['relatedModelName'] = ucfirst(Inflector::singularize($info['table']));
         $info['foreignTable'] = $info['table'];
         unset($info['table']);
         $info['hydration'] = 'simple';
         if (empty($info['fields'])) {
             $info['fields'] = '*';
         }
         $info['fieldsToRetrieve'] = $info['fields'];
         unset($info['fields']);
         $relatedStructure = null;
     }
     if (!isset($info['localKey'])) {
         $info['localKey'] = $modelStructure->getPrimaryKey();
     }
     if (!isset($info['foreignKey'])) {
         $info['foreignKey'] = empty($relatedStructure) ? 'id' : $relatedStructure->getPrimaryKey();
     }
     $foreignTable = $relatedStructure ? $relatedStructure->getTableName() : (isset($info['table']) ? $info['table'] : $relationName);
     $autoLocalField = 'id_' . Inflector::underscore($info['relatedModelName']);
     $autoForeignField = 'id_' . Inflector::underscore($modelName);
     $hasLocalField = false;
     $hasForeignField = false;
     if ($info['hydration'] == 'model') {
         if ($relatedStructure->hasColumn($autoForeignField)) {
             if (empty($info['type'])) {
                 $info['type'] = 'one_to_many';
             }
             if (empty($info['foreignField'])) {
                 $info['foreignField'] = $autoForeignField;
             }
             $hasForeignField = true;
         }
         if ($modelStructure->hasColumn($autoLocalField)) {
             if (empty($info['type'])) {
                 $info['type'] = 'many_to_one';
             }
             if (empty($info['localField'])) {
                 $info['localField'] = $autoLocalField;
             }
             $hasLocalField = true;
         }
         if (!$hasForeignField && !$hasLocalField) {
             if (empty($info['type'])) {
                 $info['type'] = 'many_to_many';
             }
             if (empty($info['foreignField'])) {
                 $info['foreignField'] = $autoForeignField;
             }
             if (empty($info['localField'])) {
                 $info['localField'] = $autoLocalField;
             }
         }
     }
     $info['relationToMany'] = substr($info['type'], -4) == 'many' ? true : false;
     $info['relationType'] = $info['type'];
     unset($info['type']);
     if (strpos($info['relatedModelName'], '\\') === false) {
         $info['relatedModelName'] = 'Entities\\' . $info['relatedModelName'];
     }
     if (empty($info['manyTable'])) {
         $info['manyTable'] = $info['localTable'] > $foreignTable ? $info['localTable'] . '_' . $foreignTable : $foreignTable . '_' . $info['localTable'];
     }
     self::$_variablesCache[$modelName . $relationName] = $info;
     return $info;
 }
Ejemplo n.º 9
0
 public function testUnderscore()
 {
     $this->assertEquals('hello_world', Inflector::underscore('Hello world!'), 'underscore');
     $this->assertEquals('hello_world', Inflector::underscore('HelloWorld!'), 'underscore');
     $this->assertEquals('this_istext', Inflector::underscore('ThisISText'), 'underscore');
 }