예제 #1
0
 public function getSource()
 {
     $nowClassName = get_class($this);
     $trueClassName = str_replace(__NAMESPACE__ . '\\', '', $nowClassName);
     $trueClassName = Text::uncamelize($trueClassName);
     return DB_PREFIX . strtolower($trueClassName);
 }
예제 #2
0
 /**
  * Generate view
  */
 public function build()
 {
     $action = Text::uncamelize($this->_options['action']);
     $viewName = explode('-', str_replace('_', '-', Text::uncamelize($this->_options['name'])));
     if (count($viewName) > 1) {
         array_pop($viewName);
     }
     $viewName = implode('-', $viewName);
     $viewDir = $this->_options['directory'] . DIRECTORY_SEPARATOR . $viewName;
     $viewPath = $viewDir . DIRECTORY_SEPARATOR . $action . '.volt';
     $code = "<?php\n" . Tools::getCopyright() . "\n?>\n";
     $code = str_replace("\t", "    ", $code);
     if (!file_exists($viewPath) || $this->_options['force'] == true) {
         if (!is_dir($viewDir)) {
             mkdir($viewDir, 0777, true);
             chmod($viewDir, 0777);
         }
         if (!@file_put_contents($viewPath, $code)) {
             throw new \Exception("Unable to write to '{$viewPath}'");
         }
         chmod($viewPath, 0777);
     } else {
         throw new \Exception("The View '{$action}' already exists");
     }
     return $viewName;
 }
예제 #3
0
 public function initialize()
 {
     foreach (self::$routes as $route => $controller) {
         $name = str_replace('_', '-', Text::uncamelize($controller));
         $this->add($route, $controller)->setName($name);
     }
 }
예제 #4
0
 public function run($parameters)
 {
     $name = $this->getOption(array('name', 1));
     $className = Text::camelize(isset($parameters[2]) ? $parameters[2] : $name);
     $fileName = Text::uncamelize($className);
     $schema = $this->getOption('schema');
     $modelBuilder = new \Phalcon\Builder\Model(array('name' => $name, 'schema' => $schema, 'className' => $className, 'fileName' => $fileName, 'genSettersGetters' => $this->isReceivedOption('get-set'), 'genDocMethods' => $this->isReceivedOption('doc'), 'namespace' => $this->getOption('namespace'), 'directory' => $this->getOption('directory'), 'force' => $this->isReceivedOption('force')));
     $modelBuilder->build();
 }
예제 #5
0
 /**
  * @param $parameters
  */
 public function run($parameters)
 {
     $name = $this->getOption(array('name', 1));
     $className = Text::camelize(isset($parameters[1]) ? $parameters[1] : $name);
     $fileName = Text::uncamelize($className);
     $schema = $this->getOption('schema');
     $modelBuilder = new ModelBuilder(array('name' => $name, 'schema' => $schema, 'className' => $className, 'fileName' => $fileName, 'genSettersGetters' => $this->isReceivedOption('get-set'), 'genDocMethods' => $this->isReceivedOption('doc'), 'namespace' => $this->getOption('namespace'), 'directory' => $this->getOption('directory'), 'modelsDir' => $this->getOption('output'), 'extends' => $this->getOption('extends'), 'excludeFields' => $this->getOption('excludefields'), 'force' => $this->isReceivedOption('force'), 'mapColumn' => $this->isReceivedOption('mapcolumn')));
     $modelBuilder->build();
 }
예제 #6
0
 /**
  * @param Filter $filter
  */
 public static function install($filter)
 {
     foreach (get_class_methods(get_called_class()) as $method) {
         if ($method != __METHOD__) {
             $filter->add(Text::uncamelize($method), function ($value) use($method) {
                 return call_user_func([get_called_class(), $method], $value);
             });
         }
     }
 }
예제 #7
0
 /**
  * Tests the uncamelize function
  *
  * @author Nikos Dimopoulos <*****@*****.**>
  * @since  2012-10-30
  */
 public function testUncamelizeString()
 {
     $uncamelizeTests = array('camelize' => 'camelize', 'CameLiZe' => 'came_li_ze', 'cAmeLize' => 'c_ame_lize', '_camelize' => '_camelize', '123camelize' => '123camelize', 'c_a_m_e_l_i_z_e' => 'c_a_m_e_l_i_z_e', 'Camelize' => 'camelize', 'camel_ize' => 'camel_ize', 'CameLize' => 'came_lize');
     $template = "Text::uncamelize did not convert the string '%s' correctly";
     foreach ($uncamelizeTests as $input => $uncamelized) {
         $expected = $uncamelized;
         $actual = PhText::uncamelize($input);
         $this->assertEquals($expected, $actual, sprintf($template, $input));
     }
 }
예제 #8
0
 /**
  * @param VoltCompiler $compiler
  */
 public static function install($compiler)
 {
     foreach (get_class_methods(get_called_class()) as $method) {
         if ($method != __METHOD__) {
             $compiler->addFunction(Text::uncamelize($method), function ($resolvedArgs, $exprArgs) use($method) {
                 return get_called_class() . '::' . $method . '(' . $resolvedArgs . ')';
             });
         }
     }
 }
예제 #9
0
 public function modulesConfig($modules_list)
 {
     $namespaces = array();
     $modules = array();
     if (!empty($modules_list)) {
         foreach ($modules_list as $module) {
             $namespaces[$module] = APPLICATION_PATH . '/modules/' . $module;
             $simple = Text::uncamelize($module);
             $simple = str_replace('_', '-', $simple);
             $modules[$simple] = array('className' => $module . '\\Module', 'path' => APPLICATION_PATH . '/modules/' . $module . '/Module.php');
         }
     }
     $modules_array = array('loader' => array('namespaces' => $namespaces), 'modules' => $modules);
     return $modules_array;
 }
예제 #10
0
 public function initialize()
 {
     if (static::PREFIX) {
         $this->setPrefix(static::PREFIX);
     }
     foreach (static::ROUTES as $route => $controller) {
         $namespace = '';
         if (static::SPACE) {
             $namespace = static::SPACE . '\\';
         }
         $name = implode('-', array_map(function ($name) {
             $name = Text::uncamelize($name);
             $name = str_replace('_', '-', $name);
             return $name;
         }, explode('\\', $controller)));
         $this->add($route, $namespace . $controller)->setName($name);
     }
 }
예제 #11
0
 public function afterExecuteRoute(\Phalcon\Events\Event $event, \Phalcon\Mvc\Dispatcher $dispatcher)
 {
     /** @var \Phalcon\Mvc\Router $route */
     $route = $dispatcher->getDI()->get('router');
     $view = $dispatcher->getDI()->getService('view')->resolve();
     $wasForwarded = $dispatcher->wasForwarded();
     if ($wasForwarded) {
         return;
     }
     if ($route->getMatchedRoute()) {
         $paths = $route->getMatchedRoute()->getPaths();
         $controller = $paths['controller'];
         $action = \Phalcon\Text::uncamelize($paths['action']);
         $action = str_replace("_", "-", $action);
         $template = $controller . '/' . $action;
         $view->pick([$template]);
     }
 }
예제 #12
0
 public function __construct()
 {
     $class = new \ReflectionClass('\\Phalcon\\Tag');
     $methods = $class->getMethods(\ReflectionMethod::IS_PUBLIC);
     $code = file_get_contents(__DIR__ . '/Generator.tpl');
     // Functions
     $skip = ['getEscaper', 'renderAttributes', 'setDI', 'getDI', 'getUrlService', 'getEscaperService', 'setAutoescape', 'setDefault', 'setDefaults', 'displayTo', 'hasValue', 'getValue', 'resetInput', 'setTitle', 'setTitleSeparator', 'appendTitle', 'prependTitle', 'setDocType'];
     $functions = [];
     foreach ($methods as $method) {
         if (in_array($method->getName(), $skip)) {
             continue;
         }
         $name = lcfirst(\Phalcon\Text::uncamelize($method->getName()));
         if ($method->getName() == 'getDocType') {
             $name = 'get_doctype';
         }
         $callable = sprintf('Phalcon\\Tag::%s', $method->getName());
         $functions[] = sprintf("new Twig_SimpleFunction('%s', '%s')", $name, $callable);
     }
     $functions = implode(",\n", $functions);
     // Create PHP code
     $this->code = str_replace('%functions%', $functions, $code);
 }
예제 #13
0
파일: Text.php 프로젝트: lisong/cphalcon
 public static function uncamelize($str)
 {
     return parent::uncamelize($str);
 }
예제 #14
0
파일: Text.php 프로젝트: mattvb91/cphalcon
 public static function uncamelize($str, $delimiter = null)
 {
     return parent::uncamelize($str, $delimiter);
 }
예제 #15
0
 /**
  * Return form fullname
  *
  * @param string $module
  * @param string $grid
  * @return string
  */
 protected function _getForm($module, $form)
 {
     $module = str_replace("-", "_", \Phalcon\Text::uncamelize($module));
     $module = explode("_", $module);
     foreach ($module as $i => &$word) {
         if ($i == 0) {
             continue;
         }
         $word = ucfirst($word);
     }
     $module = implode("", $module);
     $form = str_replace("-", "_", \Phalcon\Text::uncamelize($form));
     $form = explode("_", $form);
     foreach ($form as $i => &$word) {
         if ($i == 0) {
             continue;
         }
         $word = ucfirst($word);
     }
     $form = implode("\\", $form);
     return "\\" . ucfirst($module) . "\\Form\\Extjs\\" . ucfirst($form);
 }
예제 #16
0
 /**
  * Returns collection name mapped in the model
  *
  * @return string
  */
 public function getSource()
 {
     if (isset($this->_source) === false) {
         $this->_source = Text::uncamelize(get_class($this));
     }
     return $this->_source;
 }
예제 #17
0
 /**
  * Returns the mapped source for a model
  *
  * @param \Phalcon\Mvc\ModelInterface $model
  * @return string
  * @throws Exception
  */
 public function getModelSource($model)
 {
     if (is_object($model) === false || $model instanceof ModelInterface === false) {
         throw new Exception('Model is not an object');
     }
     $entity = strtolower(get_class($model));
     if (is_array($this->_sources) === true) {
         if (isset($this->_sources[$entity]) === true) {
             return $this->_sources[$entity];
         }
     } else {
         $this->_sources = array();
     }
     $source = Text::uncamelize($entity);
     $this->_sources[$entity] = $source;
     return $source;
 }
예제 #18
0
 /**
  * Выбирает название модели.
  * @param $url Url всего ppa запроса.
  * @return string Название модели.
  */
 public static function getModelName($url)
 {
     $modelName = preg_replace('/.*ppa\\/(s\\/)?([a-zA-Z0-9]+).*/', '$2', $url);
     return Text::camelize(Text::uncamelize($modelName));
 }
예제 #19
0
 private static function snakeCase($camelCase)
 {
     return \Phalcon\Text::uncamelize($camelCase);
 }
예제 #20
0
 /**
  * make layouts of model by scaffold
  *
  * @param array $options
  */
 private function _makeLayouts($path, $options)
 {
     //Make Layouts dir
     $dirPathLayouts = $options['viewsDir'] . '/layouts';
     //If not exists dir; we make it
     if (is_dir($dirPathLayouts) == false) {
         mkdir($dirPathLayouts);
     }
     $fileName = Text::uncamelize($options['name']);
     $viewPath = $dirPathLayouts . '/' . $fileName . '.phtml';
     if (!file_exists($viewPath)) {
         //View model layout
         $code = '';
         if (isset($options['theme'])) {
             $code .= '<?php \\Phalcon\\Tag::stylesheetLink("themes/lightness/style") ?>' . PHP_EOL;
             $code .= '<?php \\Phalcon\\Tag::stylesheetLink("themes/base") ?>' . PHP_EOL;
         }
         if (isset($options['theme'])) {
             $code .= '<div class="ui-layout" align="center">' . PHP_EOL;
         } else {
             $code .= '<div align="center">' . PHP_EOL;
         }
         $code .= "\t" . '<?php echo $this->getContent(); ?>' . PHP_EOL . '</div>';
         $code = str_replace("\t", "    ", $code);
         file_put_contents($viewPath, $code);
     }
 }
예제 #21
0
 /**
  * Handles method calls when a static method is not implemented
  *
  * @param string $method
  * @param array|null $arguments
  * @return mixed
  * @throws Exception
  */
 public static function __callStatic($method, $arguments = null)
 {
     if (is_string($method) === false) {
         throw new Exception('Invalid parameter type.');
     }
     if (is_array($arguments) === false && is_null($arguments) === false) {
         throw new Exception('Invalid parameter type.');
     }
     $extraMethod = null;
     $type = null;
     if (strpos($method, 'findFirstBy') === 0) {
         $type = 'findFirst';
         $extraMethod = substr($method, 11);
     } elseif (strpos($method, 'findBy') === 0) {
         $type = 'find';
         $extraMethod = substr($method, 6);
     } elseif (strpos($method, 'countBy') === 0) {
         $type = 'count';
         $extraMethod = substr($method, 7);
     }
     $modelName = get_called_class();
     if (is_null($extraMethod) === true) {
         //The method doesn't exist - throw an exception
         throw new Exception('The static method "' . $method . '" doesn\'t exist on model"' . $modelName . '"');
     }
     if (isset($arguments[0]) === false) {
         throw new Exception('The static method "' . $method . '" requires one argument');
     }
     $value = $arguments[0];
     $model = new $modelName();
     //Get the model's metadata
     $metaData = $model->getModelsMetaData();
     //Get the attributes
     $attributes = $metaData->getReverseColumnMap($model);
     if (is_array($attributes) === false) {
         //Use the standard attributes if there is no column map available
         $attributes = $metaData->getDataTypes($model);
     }
     //Check if the extra-method is an attribute
     if (isset($attributes[$extraMethod]) === true) {
         $field = $extraMethod;
     } else {
         //Lowercase the first letter of the extra-method
         $extraMethodFirst = lcfirst($extraMethod);
         if (isset($attributes[$extraMethodFirst]) === true) {
             $field = $extraMethodFirst;
         } else {
             //Get the possible real method name
             $field = Text::uncamelize($extraMethod);
             if (isset($attributes[$field]) === false) {
                 throw new Exception('Cannot resolve attribute "' . $extraMethod . '" in the model');
             }
         }
     }
     //Execute the query (static call)
     return call_user_func_array(array($modelName, $type), array('conditions' => $field . ' = ?0', 'bind' => array($value)));
 }
예제 #22
0
 /**
  * Reconfigure the route adding a new pattern and a set of paths
  *
  * @param string $pattern
  * @param array|null|string $paths
  * @throws Exception
  */
 public function reConfigure($pattern, $paths = null)
 {
     if (is_string($pattern) === false) {
         throw new Exception('The pattern must be string');
     }
     $originalPattern = $pattern;
     if (is_string($paths) === true) {
         $moduleName = null;
         $controllerName = null;
         $actionName = null;
         //Explode the short paths using the :: separator
         $parts = explode('::', $paths);
         $numberParts = count($parts);
         //Create the array paths dynamically
         switch ($numberParts) {
             case 3:
                 $moduleName = $parts[0];
                 $controllerName = $parts[1];
                 $actionName = $parts[2];
                 break;
             case 2:
                 $controllerName = $parts[0];
                 $actionName = $parts[1];
                 break;
             case 1:
                 $controllerName = $parts[0];
                 break;
                 //@note no default
         }
         $routePaths = array();
         //Process module name
         if (is_null($moduleName) === false) {
             $routePaths['module'] = $moduleName;
         }
         //Process controller name
         if (is_null($controllerName) === false) {
             //Check if we need to obtain the namespace
             if (strpos($controllerName, '\\') !== false) {
                 $classWithNamespace = get_class($controllerName);
                 //Extract the real class name from the namespaced class
                 //Extract the namespace from the namespaced class
                 $pos = strrpos($classWithNamespace, '\\');
                 if ($pos !== false) {
                     $namespaceName = substr($classWithNamespace, 0, $pos);
                     $realClassName = substr($classWithNamespace, $pos);
                 } else {
                     $realClassName = $classWithNamespace;
                 }
                 //Update the namespace
                 if (isset($namespaceName) === true) {
                     $routePaths['namespace'] = $namespaceName;
                 }
             } else {
                 $realClassName = $controllerName;
             }
             //Always pass the controller to lowercase
             $realClassName = Text::uncamelize($realClassName);
             //Update the controller path
             $routePaths['controller'] = $realClassName;
         }
         //Process action name
         if (is_null($actionName) === false) {
             $routePaths['action'] = $actionName;
         }
     } elseif (is_array($paths) === true) {
         $routePaths = $paths;
     } elseif (is_null($paths) === true) {
         $routePaths = array();
     } else {
         throw new Exception('The route contains invalid paths');
     }
     //If the route starts with '#' we assume that it is a regular expression
     if (Text::startsWith($pattern, '#') === false) {
         if (strpos($pattern, '{') !== false) {
             //The route has named parameters so we need to extract them
             $pattern = self::extractNamedParameters($pattern, $routePaths);
         }
         //Transform the route's pattern to a regular expression
         $pattern = $this->compilePattern($pattern);
     }
     //Update member variables
     $this->_pattern = $originalPattern;
     $this->_compiledPattern = $pattern;
     $this->_paths = $routePaths;
 }
예제 #23
0
 /**
  * Convert a CamelCase string to snake_case
  * @param $str string
  * @return string
  */
 public static function camelToSnake($str)
 {
     return Text::uncamelize($str);
 }
예제 #24
0
 protected function _getFullPathJs($filename = '', $prefix = '')
 {
     $prefix = $prefix != '' ? $prefix : $this->getControllerName();
     $filename = $filename != '' ? $filename : \Phalcon\Text::uncamelize($this->getActionName());
     return 'js/controllers/' . $prefix . '/' . $filename . '.js';
 }
예제 #25
0
 /**
  * @param $options
  */
 private function _makeLayoutsVolt($options)
 {
     //Make Layouts dir
     $dirPathLayouts = $options['viewsDir'] . DIRECTORY_SEPARATOR . 'layouts';
     //If not exists dir; we make it
     if (is_dir($dirPathLayouts) == false) {
         mkdir($dirPathLayouts);
     }
     $fileName = Text::uncamelize($options['fileName']);
     $viewPath = $dirPathLayouts . DIRECTORY_SEPARATOR . $fileName . '.volt';
     if (!file_exists($viewPath || $options['force'])) {
         //View model layout
         $code = '';
         if (isset($options['theme'])) {
             $code .= '{{ stylesheet_link("themes/lightness/style") }}' . PHP_EOL;
             $code .= '{{ stylesheet_link("themes/base") }}' . PHP_EOL;
         }
         if (isset($options['theme'])) {
             $code .= '<div class="ui-layout" align="center">' . PHP_EOL;
         } else {
             $code .= '<div align="center">' . PHP_EOL;
         }
         $code .= "\t" . '{{ content() }}' . PHP_EOL . '</div>';
         $code = str_replace("\t", "    ", $code);
         file_put_contents($viewPath, $code);
         @chmod($viewPath, 0777);
     }
 }
예제 #26
0
 private function getAllowedResources($permissionId, $namespace)
 {
     $allowedResources = array();
     $resources = $this->modelsManager->createBuilder()->from('Models\\BaseModels\\PermissionResources')->columns('Models\\BaseModels\\Resources.*')->innerJoin('Models\\BaseModels\\Resources')->where('permission_id = :permissionId: AND namespace = :namespace:', array('permissionId' => $permissionId, 'namespace' => $namespace))->getQuery()->execute();
     foreach ($resources as $resource) {
         $allowedResources[Text::uncamelize($resource->controller)][] = $resource->action;
     }
     return $allowedResources;
 }
예제 #27
0
 function getCtlName()
 {
     return Text::uncamelize(str_replace("Controller", "", get_class($this)));
 }
예제 #28
0
 protected function getFilename($name, Type $type)
 {
     if ($type->value == Type::VIEW) {
         return Util::catfile($this->viewsDir, Text::uncamelize($name)) . '/index.volt';
     } else {
         $dir = Util::catfile($this->dir, str_replace('\\', '/', $type->namespace));
         $class = $type->value == Type::CONTROLLER ? $name . 'Controller' : $name;
         return Util::catfile($dir, $class . ".php");
     }
 }
예제 #29
0
 /**
  * Make View layouts
  *
  * @return $this
  */
 private function _makeLayoutsVolt()
 {
     // Make Layouts dir
     $dirPathLayouts = $this->options->viewsDir . 'layouts';
     // If not exists dir; we make it
     if (is_dir($dirPathLayouts) == false) {
         mkdir($dirPathLayouts, 0777, true);
     }
     $fileName = Text::uncamelize($this->options->fileName);
     $viewPath = $dirPathLayouts . DIRECTORY_SEPARATOR . $fileName . '.volt';
     if (!file_exists($viewPath || $this->options->contains('force'))) {
         // View model layout
         $code = '';
         if ($this->options->contains('theme')) {
             $code .= '{{ stylesheet_link("themes/lightness/style") }}' . PHP_EOL;
             $code .= '{{ stylesheet_link("themes/base") }}' . PHP_EOL;
             $code .= '<div class="ui-layout" align="center">' . PHP_EOL;
         } else {
             $code .= '<div class="row center-block">' . PHP_EOL;
         }
         $code .= "\t" . '{{ content() }}' . PHP_EOL . '</div>';
         if ($this->isConsole()) {
             echo $viewPath, PHP_EOL;
         }
         $code = str_replace("\t", "    ", $code);
         file_put_contents($viewPath, $code);
     }
     return $this;
 }
예제 #30
0
 public function testUncamelizeException()
 {
     $this->setExpectedException('\\Phalcon\\Exception');
     \Phalcon\Text::uncamelize(1.2);
 }