Esempio n. 1
0
 public static function isControllerExists($controllerName, $namespace = null)
 {
     if (empty($namespace)) {
         $namespace = self::$_activeNamespace;
     }
     $fullControllerName = ucfirst($namespace) . '\\Controllers\\' . ucfirst(Inflector::camelize($controllerName));
     return class_exists($fullControllerName);
 }
Esempio n. 2
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);
     }
 }
Esempio n. 3
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);
 }
Esempio n. 4
0
 /**
  * Generates default database model structure
  */
 public function modelAction()
 {
     $name = ucfirst(Inflector::camelize($this->getFirstParamOrAsk('Enter model name')));
     $path = DC::getEnvironment()->getUserClassesRoot() . 'db/';
     $mo = ModelOperator::getInstance($path);
     if ($mo->getModelStructure($name)) {
         $this->warning('model ' . $name . ' is already exists', '~ model exists, skipping:');
         return true;
     }
     $mo->generateBasicStructure($name);
     $mo->saveModelStructure($name);
     $this->notify($path . 'structure/' . $name . '.yml', '+ model created');
 }
Esempio n. 5
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)), '\\');
         }
     }
 }
Esempio n. 6
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');
     }
 }
Esempio n. 7
0
 public function offsetSet($offset, $value)
 {
     if (method_exists($this, 'set' . Inflector::camelize($offset))) {
         $this->{'set' . Inflector::camelize($offset)}($value);
     }
     $this->_data[$offset] = $value;
     $this->_changedData[$offset] = $value;
     if (array_key_exists($offset, $this->_invokedGetters)) {
         $this->_invokedGetters[$offset] = $value;
     }
 }
Esempio n. 8
0
File: Slot.php Progetto: solve/slot
 public function registerBlock($block, $namespace = '\\Solve\\Slot\\Blocks\\')
 {
     $className = Inflector::camelize($block . 'Block');
     $r = new \ReflectionClass($namespace . $className);
     $doc = $r->getDocComment();
     $config = array('paired' => strpos($doc, '@paired') !== false, 'runtime' => strpos($doc, '@runtime') !== false, 'namespace' => $namespace);
     $this->_compiler->registerBlock($block, $config);
 }
Esempio n. 9
0
 /**
  * Updates many to many tables
  * @param $info
  * @return mixed
  */
 public function updateManyTable($info)
 {
     $structure = array('table' => $info['manyTable'], 'columns' => array(), 'indexes' => array(), 'constraints' => array());
     $localName = Inflector::singularize($info['localTable']);
     $foreignName = Inflector::singularize($info['foreignTable']);
     $structure['columns']['id'] = array('type' => 'int(11) unsigned', 'auto_increment' => true);
     $structure['columns']['id_' . $localName] = 'int(11) unsigned';
     $structure['columns']['id_' . $foreignName] = 'int(11) unsigned';
     $structure['indexes']['primary'] = array('columns' => array('id'), 'type' => 'primary');
     $structure['indexes']['unique_id_' . $localName . '_id_' . $foreignName] = array('columns' => array('id_' . $localName, 'id_' . $foreignName), 'type' => 'unique');
     $foreignKeysInfo = array('local_table' => $info['manyTable'], 'foreign_table' => $info['localTable'], 'local_field' => 'id_' . $localName, 'foreign_field' => $info['foreignKey']);
     $structure['constraints'][$this->generateForeignKeyName($foreignKeysInfo)] = $foreignKeysInfo;
     $foreignKeysInfo = array('local_table' => $info['manyTable'], 'foreign_table' => $info['foreignTable'], 'local_field' => 'id_' . $foreignName, 'foreign_field' => $info['foreignKey']);
     $structure['constraints'][$this->generateForeignKeyName($foreignKeysInfo)] = $foreignKeysInfo;
     $diffs = $this->getDifferenceSQL($structure, $info['manyTable']);
     if ($diffs['result'] === true) {
         QC::executeSQL('SET FOREIGN_KEY_CHECKS = 0');
         if (!empty($diffs['sql']['ADD'])) {
             try {
                 QC::executeArrayOfSQL($diffs['sql']['ADD']);
             } catch (\Exception $e) {
                 var_dump($e->getMessage());
                 die;
             }
         }
     }
     return $diffs['result'];
 }
Esempio n. 10
0
 protected function reloadConfig()
 {
     $abilityName = get_class($this);
     $abilityName = Inflector::underscore(substr($abilityName, strrpos($abilityName, '\\') + 1, -7));
     $this->_config = $this->_modelStructure->getAbilityInfo($abilityName);
 }
Esempio n. 11
0
 /**
  * @param Model $caller
  */
 public function preSave($caller)
 {
     if (array_key_exists($this->_sourceField, $caller->getChangedData())) {
         $caller->{$this->_valueField} = Inflector::slugify($caller->getChangedData($this->_sourceField));
     }
 }
Esempio n. 12
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;
 }
Esempio n. 13
0
 /**
  * @param $modelName
  * @param $abilityName
  * @return BaseModelAbility
  * @throws \Exception
  */
 public static function getAbilityInstanceForModel($modelName, $abilityName)
 {
     $abilityClass = '\\Solve\\Database\\Models\\Abilities\\' . Inflector::camelize($abilityName) . 'Ability';
     if (!class_exists($abilityClass)) {
         throw new \Exception('Ability ' . $abilityName . ' not found');
     }
     $abilityInstance = call_user_func(array($abilityClass, 'getInstanceForModel'), $modelName);
     self::cacheAbilitiesMethods($modelName, $abilityName, $abilityInstance);
     return $abilityInstance;
 }
Esempio n. 14
0
 private static function _prepareActionName($string)
 {
     return lcfirst(Inflector::camelize($string));
 }
Esempio n. 15
0
 /**
  * @param $tag\
  * @param $token
  * @return BaseBlock
  */
 private function getBlockObject($tag, $token)
 {
     $namespace = isset($this->_blocks[$tag]['namespace']) ? $this->_blocks[$tag]['namespace'] : '\\Solve\\Slot\\Blocks\\';
     $blockClassName = $namespace . Inflector::camelize($tag . 'Block');
     /**
      * @var BaseBlock $blockObject
      */
     $blockObject = new $blockClassName($token, $this);
     return $blockObject;
 }
Esempio n. 16
0
function echoSingleVar($var)
{
    echo \Solve\Utils\Inflector::dumperGet($var) . "\n";
}
Esempio n. 17
0
 public function testNumberToStringShort()
 {
     Inflector::setDefaultLanguage("ru");
     $this->assertEquals('триста один руб. 21 коп.', Inflector::priceToStringShort('301,21', true, 'руб.'), 'short version');
     $this->assertEquals('пятьсот пятнадцать руб.', Inflector::priceToStringShort('515,21', false, 'руб.'), 'short version without float');
 }
Esempio n. 18
0
 public function detectApplication()
 {
     DC::getEventDispatcher()->dispatchEvent('route.buildRequest', Request::getIncomeRequest());
     /**
      * @var ArrayStorage $appList
      */
     $appList = DC::getProjectConfig('applications');
     if (empty($appList)) {
         throw new \Exception('Empty application list');
     }
     $defaultAppName = DC::getProjectConfig('defaultApplication', 'frontend');
     $this->_name = $defaultAppName;
     $uri = (string) Request::getIncomeRequest()->getUri();
     $uriParts = explode('/', $uri);
     $webRoot = DC::getRouter()->getWebRoot();
     if (strlen($webRoot) > 1) {
         if (strpos($uri, substr($webRoot, 1)) === 0) {
             $uriParts = explode('/', substr($uri, strlen($webRoot)));
         }
     }
     if (!empty($uriParts) && (count($uriParts) > 0 && $uriParts[0] != '/')) {
         foreach ($appList as $appName => $appParams) {
             if ($appName == $defaultAppName) {
                 continue;
             }
             $appUri = !empty($appParams['uri']) ? $appParams['uri'] : $appName;
             if (strpos($uriParts[0], $appUri) === 0) {
                 array_shift($uriParts);
                 Request::getIncomeRequest()->setUri((strlen($webRoot) > 1 ? $webRoot . '/' : '') . implode('/', $uriParts));
                 $this->_name = $appName;
                 break;
             }
         }
     }
     $this->_config = DC::getProjectConfig('applications/' . $this->_name);
     if (!is_array($this->_config)) {
         $this->_config = array('uri' => $this->_name);
     }
     if (empty($this->_config['path'])) {
         $this->_config['path'] = Inflector::camelize($this->_name) . '/';
     }
     $this->_namespace = Inflector::camelize($this->_name);
     $this->_root = DC::getEnvironment()->getApplicationRoot() . $this->_config['path'];
     DC::getAutoloader()->registerNamespacePath($this->_namespace, DC::getEnvironment()->getApplicationRoot());
     ControllerService::setActiveNamespace($this->_namespace);
     return $this->_name;
 }
Esempio n. 19
0
File: View.php Progetto: solve/solve
 protected function detectTemplate()
 {
     $route = DC::getApplication()->getRoute();
     $folder = Inflector::slugify(substr($route->getControllerName(), 0, -10));
     $action = Inflector::slugify(substr($route->getActionName(), 0, -6));
     if (is_file($this->getTemplatesPath() . $folder . '/' . $action . '.slot')) {
         $this->setTemplateName($folder . '/' . $action);
     } elseif (is_file($this->getTemplatesPath() . $action . '.slot')) {
         $this->setTemplateName($action);
     } else {
         throw new \Exception('Cannot detect template:' . $folder . '/' . $action);
     }
 }
Esempio n. 20
0
 /**
  * @param Model|ModelCollection $caller
  */
 protected function loadAbilitiesForCaller($caller)
 {
     $files = $caller->_getStructure()->getAbilityInfo('files');
     if (!empty($files)) {
         foreach (array_keys($files) as $fileAlias) {
             $getterName = 'get' . Inflector::classify($fileAlias);
             if ($caller instanceof Model) {
                 $caller = array($caller);
             }
             foreach ($caller as $object) {
                 $object->{$getterName}();
             }
         }
     }
 }
Esempio n. 21
0
 /**
  * @param mixed $offset
  * @param Model $value
  * @throws \Exception
  */
 public function offsetSet($offset, $value)
 {
     if (method_exists($this, 'set' . Inflector::camelize($offset))) {
         $this->{'set' . Inflector::camelize($offset)}($value);
     }
     if (is_null($offset)) {
         if (!is_object($value) || $value->isNew()) {
             throw new \Exception('Trying to add empty or non-object item to collection');
         }
         $offset = count($this->_data);
         if (array_key_exists($value->getID(), $this->_pk_map)) {
             throw new \Exception('Object with id ' . $value[$this->_primaryKey] . ' already exists in collection');
         }
         $this->_pk_map[$value->getID()] = $offset;
     }
     $this->_data[$offset] = $value;
 }