Esempio n. 1
0
 /**
  * {@inheritdoc}
  *
  * @param array $config Strategy's configuration.
  * @return $this
  */
 public function initialize($config)
 {
     $config = parent::initialize($config)->config();
     $assocName = Inflector::pluralize(Inflector::classify($this->_alias));
     $this->_table->belongsTo($assocName, ['className' => $this->modelClass, 'foreignKey' => $config['field'], 'bindingKey' => 'name', 'conditions' => [$assocName . '.prefix' => $config['prefix']]]);
     return $this;
 }
Esempio n. 2
0
 /**
  * Generates instance of the Transformer.
  *
  * The method works with the App::className() method.
  * This means that you can call app-related Transformers like `Books`.
  * Plugin-related Transformers can be called like `Plugin.Books`
  *
  * @param $className
  * @return TransformerAbstract
  * @throws MissingTransformerException
  */
 public function getTransformer($className)
 {
     $transformer = App::className(Inflector::classify($className), 'Transformer', 'Transformer');
     if ($transformer === false) {
         throw new MissingTransformerException(['transformer' => $className]);
     }
     return new $transformer();
 }
Esempio n. 3
0
 public function _getLastThreeLikes()
 {
     $alias = Inflector::classify($this->source());
     $uid = __LOGGEDINUSERID;
     $like = TableRegistry::get('Social.Likes');
     $_like = $like->find()->where(['Likes.object_id' => $this->id, 'Likes.object' => $alias, 'Fans.id !=' => $uid])->limit(2)->order('Likes.created')->contain(['Fans' => ['fields' => ['id', 'first_name', 'last_name']]]);
     return $_like->toArray();
 }
Esempio n. 4
0
 /**
  * Todo: doc bloc
  */
 public function newEntity($data = null, array $options = [])
 {
     if ($data === null && isset($options['gateway'])) {
         $gateway = Inflector::classify($options['gateway']);
         $chargeClass = '\\Payments\\Model\\Entity\\' . $gateway . 'Charge';
         $entity = new $chargeClass([], ['source' => $this->registryAlias()]);
         return $entity;
     }
     return parent::newEntity($data, $options);
 }
Esempio n. 5
0
 public function _getLastFiveComments()
 {
     $alias = Inflector::classify($this->source());
     $comment = TableRegistry::get('Social.Comments');
     $comments = $comment->find()->where(['Comments.object_id' => $this->id, 'Comments.object' => $alias])->limit(__MAX_COMMENTS_LISTED)->order('Comments.created DESC')->contain(['Authors' => ['fields' => ['id', 'first_name', 'last_name', 'avatar']]]);
     // Reorder the Comments by creation order
     // (even though we got them by descending order)
     $collection = new Collection($comments);
     $comments = $collection->sortBy('Comment.created');
     return $comments->toArray();
 }
Esempio n. 6
0
 /**
  * Serve Html templates to batman.
  *
  * @return void
  */
 public function views($id)
 {
     $this->autoLayout = false;
     foreach (DashboardWidget::paths() as $path) {
         $path .= Inflector::classify($id) . DS . 'view.ctp';
         if (!file_exists($path)) {
             continue;
         }
         echo file_get_contents($path);
         exit;
     }
 }
Esempio n. 7
0
 /**
  * Proxies validation method calls to the Respect\Validation\Validator class.
  *
  * The last argument (context) will be sliced off for all methods since they
  * are unaware of it.
  *
  * @param string $method The validation method to call.
  * @param array $arguments The list of arguments to pass to the method.
  * @return bool Whether or not the validation rule passed.
  */
 public function __call($method, $arguments)
 {
     $class = $this->_namespace . '\\' . Inflector::classify($method);
     if (!class_exists($class)) {
         throw new Exception('Undefined iso codes validation method');
     }
     $context = array_pop($arguments);
     if (!is_array($context) || array_keys($context) === $this->_contextKeys) {
         array_push($arguments, $context);
     }
     return call_user_func_array([$class, 'validate'], $arguments);
 }
Esempio n. 8
0
 /**
  * Make the helper, possibly configuring with CrudData objects
  * 
  * @param \Cake\View\View $View
  * @param array $config An array of CrudData objects
  */
 public function __construct(View $View, array $config = array())
 {
     parent::__construct($View, $config);
     $config += ['_CrudData' => [], 'actions' => []];
     $this->_defaultAlias = new NameConventions(Inflector::pluralize(Inflector::classify($this->request->controller)));
     $this->_CrudData = $config['_CrudData'];
     $this->DecorationSetups = new DecorationFactory($this);
     //		$this->_Field = new Collection();
     foreach ($config['actions'] as $name => $pattern) {
         $this->{$name} = $pattern;
     }
     $this->useCrudData($this->_defaultAlias->name);
 }
Esempio n. 9
0
 public function initialize(array $config)
 {
     $this->alias = Inflector::classify($this->_table->alias());
     $this->_table->hasMany('Comments', ['foreignKey' => 'object_id', 'joinType' => 'INNER', 'className' => 'Social.Comments', 'conditions' => ['Comments.object' => $this->alias], 'dependent' => true]);
 }
Esempio n. 10
0
 /**
  * testClassNaming method
  *
  * @return void
  */
 public function testClassNaming()
 {
     $this->assertEquals('ArtistsGenre', Inflector::classify('artists_genres'));
     $this->assertEquals('FileSystem', Inflector::classify('file_systems'));
     $this->assertEquals('News', Inflector::classify('news'));
     $this->assertEquals('Bureau', Inflector::classify('bureaus'));
 }
 /**
  * Whitespaces before or after <?php and ?>.
  * The latter should be removed from PHP files by the way.
  *
  * @return void
  */
 public function clean()
 {
     if (!empty($this->args[0])) {
         $folder = realpath($this->args[0]);
     } elseif ($this->params['plugin']) {
         $folder = Plugin::path(Inflector::classify($this->params['plugin']));
     } else {
         $folder = APP;
     }
     $App = new Folder($folder);
     $this->out('Checking *.php in ' . $folder);
     $files = $App->findRecursive('.*\\.php');
     $this->out('Found ' . count($files) . ' files.');
     $action = $this->in('Continue? [y]/[n]', ['y', 'n'], 'n');
     if ($action !== 'y') {
         return $this->error('Aborted');
     }
     $folders = [];
     foreach ($files as $file) {
         $errors = [];
         $action = '';
         $this->out('Processing ' . $file, 1, Shell::VERBOSE);
         $c = file_get_contents($file);
         if (preg_match('/^[\\n\\r|\\n|\\r|\\s]+\\<\\?php/', $c)) {
             $errors[] = 'leading';
         }
         if (preg_match('/\\?\\>[\\n\\r|\\n|\\r|\\s]+$/', $c)) {
             $errors[] = 'trailing';
         }
         if (empty($errors)) {
             continue;
         }
         foreach ($errors as $e) {
             $this->report[$e][0]++;
         }
         $this->out('');
         $this->out('contains ' . implode(' and ', $errors) . ' whitespaces: ' . $this->shortPath($file));
         $dirname = dirname($file);
         if (in_array($dirname, $folders)) {
             $action = 'y';
         }
         while (empty($action)) {
             $action = $this->in('Remove? [y]/[n], [a] for all in this folder, [r] for all below, [*] for all files(!), [q] to quit', ['y', 'n', 'r', 'a', 'q', '*'], 'q');
         }
         if ($action === '*') {
             $action = 'y';
         } elseif ($action === 'a') {
             $action = 'y';
             $folders[] = $dirname;
             $this->out('All: ' . $dirname);
         }
         if ($action === 'q') {
             return $this->error('Abort... Done');
         }
         if ($action === 'y') {
             if (in_array('leading', $errors)) {
                 $c = preg_replace('/^\\s+\\<\\?php/', '<?php', $c);
             }
             if (in_array('trailing', $errors)) {
                 $c = preg_replace('/\\?\\>\\s+$/', '?>', $c);
             }
             file_put_contents($file, $c);
             foreach ($errors as $e) {
                 $this->report[$e][1]++;
             }
             $this->out('fixed ' . implode(' and ', $errors) . ' whitespaces: ' . $this->shortPath($file));
         }
     }
     // Report.
     $this->out('--------');
     $this->out('found ' . $this->report['leading'][0] . ' leading, ' . $this->report['trailing'][0] . ' trailing ws');
     $this->out('fixed ' . $this->report['leading'][1] . ' leading, ' . $this->report['trailing'][1] . ' trailing ws');
 }
Esempio n. 12
0
 /**
  * {@inheritDoc}
  */
 public function fileName($name)
 {
     return Inflector::classify($this->args[0]) . 'Seed.php';
 }
Esempio n. 13
0
 public function addType($key, $entityClass)
 {
     list($namespace, $entityName) = explode('\\Entity\\', $entityClass);
     $connection = $this->_table->connection();
     $table = $this->config('table');
     $alias = Inflector::pluralize($entityName);
     $className = $namespace . '\\Table\\' . $alias . 'Table';
     if (!class_exists($className)) {
         $className = null;
     }
     if (TableRegistry::exists($alias)) {
         $existingTable = TableRegistry::get($alias);
         if ($table !== $existingTable->table() || $connection !== $existingTable->connection() || $entityClass !== $existingTable->entityClass()) {
             throw new \Exception();
         }
     }
     $this->_typeMap[$key] = compact('alias', 'entityClass', 'table', 'connection', 'className');
     $method = 'new' . Inflector::classify($entityName);
     $this->config('implementedMethods.' . $method, $method);
 }
 /**
  * Method that retrieves handler class name based on provided field type.
  * It also handles more advanced field types like foreign key and list fields.
  * Example: if field type is 'string' then 'StringFieldHandler' will be returned.
  * Example: if field type is 'related:users' then 'RelatedFieldHandler' will be returned.
  * @param  string $type field type
  * @param  bool   $fqcn true to use fully-qualified class name
  * @return string       handler class name
  */
 protected function _getHandlerByFieldType($type, $fqcn = false)
 {
     if (false !== ($pos = strpos($type, ':'))) {
         $type = substr($type, 0, $pos);
     }
     $result = Inflector::classify($type) . static::HANDLER_SUFFIX;
     if ($fqcn) {
         $result = __NAMESPACE__ . '\\' . $result;
     }
     return $result;
 }
Esempio n. 15
0
 /**
  * Loads a search filter instance.
  *
  * @param string $name Name of the field
  * @param string $filter Filter name
  * @param array $options Filter options.
  * @return \Burzum\Search\Search\Filter\Base
  * @throws \InvalidArgumentException When no filter was found.
  */
 public function _loadFilter($name, $filter, array $options = [])
 {
     list($plugin, $filter) = pluginSplit($filter);
     $filter = Inflector::classify($filter);
     if (!empty($plugin)) {
         $className = '\\' . $plugin . '\\Search\\Type\\' . $filter;
         if (class_exists($className)) {
             return new $className($name, $options, $this);
         }
     }
     if (isset($config['typeClasses'][$filter])) {
         return new $config['typeClasses'][$filter]($filter, $options, $this);
     }
     if (class_exists('\\Burzum\\Search\\Search\\Filter\\' . $filter)) {
         $className = '\\Burzum\\Search\\Search\\Filter\\' . $filter;
         return new $className($name, $options, $this);
     }
     if (class_exists('\\App\\Search\\Type\\' . $filter)) {
         $className = '\\App\\Search\\Type\\' . $filter;
         return new $className($name, $options, $this);
     }
     throw new \InvalidArgumentException(sprintf('Can\'t find filter class %s!', $name));
 }
 /**
  * Get table alias
  *
  * @return string
  */
 public function alias()
 {
     return Inflector::pluralize(Inflector::classify($this->_table->getName()));
 }
Esempio n. 17
0
 public function initialize(array $config)
 {
     $this->alias = Inflector::classify($this->_table->alias());
     $this->_table->hasOne('Feeds', ['foreignKey' => 'object_id', 'joinType' => 'INNER', 'className' => 'Social.Feeds', 'conditions' => ['Feeds.object' => $this->alias], 'dependent' => true, 'cascadeCallbacks' => true]);
     $this->_table->hasMany('Activities', ['foreignKey' => 'object_id', 'joinType' => 'INNER', 'className' => 'Social.Activities', 'conditions' => ['Activities.object' => $this->alias], 'dependent' => true, 'cascadeCallbacks' => true]);
 }
Esempio n. 18
0
 /**
  * Loads a search filter.
  *
  * @param string $name Name of the field
  * @param string $filter Filter name
  * @param array $options Filter options.
  * @return \Search\Model\Filter\Base
  * @throws \InvalidArgumentException When no filter was found.
  */
 public function loadFilter($name, $filter, array $options = [])
 {
     if (empty($options['className'])) {
         $class = Inflector::classify($filter);
     } else {
         $class = $options['className'];
         unset($options['className']);
     }
     $className = App::className($class, 'Model\\Filter');
     if (!class_exists($className)) {
         throw new InvalidArgumentException(sprintf('Search filter "%s" was not found.', $class));
     }
     return new $className($name, $this, $options);
 }
Esempio n. 19
0
 /**
  * Creates the proper model name from a foreign key
  *
  * @param string $key Foreign key
  * @return string Model name
  */
 protected function _modelNameFromKey($key)
 {
     $key = str_replace('_id', '', $key);
     return Inflector::pluralize(Inflector::classify($key));
 }
Esempio n. 20
0
 public static function nameToField($name)
 {
     return Inflector::underscore(Inflector::classify($name));
 }
 /**
  * Sets either the view class if one exists or the layout and template path of the view.
  * The names of these are derived from the $type input parameter.
  *
  * ### Usage:
  *
  * Render the response as an 'ajax' response.
  *
  * ```
  * $this->RequestHandler->renderAs($this, 'ajax');
  * ```
  *
  * Render the response as an xml file and force the result as a file download.
  *
  * ```
  * $this->RequestHandler->renderAs($this, 'xml', ['attachment' => 'myfile.xml'];
  * ```
  *
  * @param Controller $controller A reference to a controller object
  * @param string $type Type of response to send (e.g: 'ajax')
  * @param array $options Array of options to use
  * @return void
  * @see RequestHandlerComponent::respondAs()
  */
 public function renderAs(Controller $controller, $type, array $options = [])
 {
     $defaults = ['charset' => 'UTF-8'];
     $view = null;
     $viewClassMap = $this->viewClassMap();
     if (Configure::read('App.encoding') !== null) {
         $defaults['charset'] = Configure::read('App.encoding');
     }
     $options += $defaults;
     if (array_key_exists($type, $viewClassMap)) {
         $view = $viewClassMap[$type];
     } else {
         $view = Inflector::classify($type);
     }
     $viewClass = App::className($view, 'View', 'View');
     if ($viewClass) {
         $controller->viewClass = $viewClass;
     } else {
         if (empty($this->_renderType)) {
             $controller->viewPath .= DS . $type;
         } else {
             $controller->viewPath = preg_replace("/([\\/\\\\]{$this->_renderType})\$/", DS . $type, $controller->viewPath);
         }
         $this->_renderType = $type;
         $controller->layoutPath = $type;
     }
     $response = $this->response;
     if ($response->getMimeType($type)) {
         $this->respondAs($type, $options);
     }
     $helper = ucfirst($type);
     if (!in_array($helper, $controller->helpers) && empty($controller->helpers[$helper])) {
         $helperClass = App::className($helper, 'View/Helper', 'Helper');
         if ($helperClass) {
             $controller->helpers[] = $helper;
         }
     }
 }
Esempio n. 22
0
 /**
  * Returns an array with enriched information about ALL installed Nginx modules.
  *
  * Modules can determined by running `nginx -V`and analysing arguments like this:
  * => Core modules:
  *    - argument is prefixed with "--with-"
  *    - argument is suffixed with  "_module"
  *
  * => 3rd party modules:
  *    - argument is prefixed with "--add-module="
  *    - module name found after the last /
  *    - module name always prefixed with either "nginx-" or "ngx_"
  *
  * @return array Single dimensional array with key/value pair collections
  */
 public function getNginxModules()
 {
     $cached = Cache::read('nginx_modules', 'short');
     if ($cached) {
         return $cached;
     }
     // shell command since no other option seems available
     $stdout = `2>&1 nginx -V | xargs -n1`;
     $lines = explode("\n", $stdout);
     sort($lines, SORT_NATURAL | SORT_FLAG_CASE);
     // prepare the result array
     $result = ['core' => [], '3rdparty' => []];
     foreach ($lines as $module) {
         // Extracts core modules
         if (preg_match('/^--with-((.{4})_(.*)_module)/m', $module, $matches)) {
             $module = $matches[1];
             $shortName = $this->_stripNginxModuleName($module);
             $category = $matches[2];
             $result['core'][] = ['name' => $module, 'short_name' => $shortName, 'category' => $category, 'link' => "http://nginx.org/en/docs/" . $category . "/ngx_" . $module . ".html"];
         }
         // Extracts 3rd party modules
         if (preg_match('/^--add-module=(.*)\\/((ngx_|nginx-)(.*))/m', $module, $matches)) {
             $module = $matches[2];
             $shortname = $this->_stripNginxModuleName($module);
             // Either use the known-deviation-link or generate the generic 3rd party wiki-link
             if (array_key_exists($shortname, $this->nginxModuleMeta)) {
                 $link = $this->nginxModuleMeta[$shortname]['link'];
             } else {
                 $wikiName = preg_replace('/-/', '_', $shortname);
                 $wikiName = "http_" . $wikiName . "_module";
                 $wikiName = Inflector::classify($wikiName);
                 $link = "http://wiki.nginx.org/{$wikiName}";
             }
             $result['3rdparty'][] = ['name' => $module, 'short_name' => $shortname, 'link' => $link];
         }
     }
     Cache::write('nginx_modules', $result, 'short');
     return $result;
 }
 /**
  * Constructor hook method.
  *
  * Implement this method to avoid having to overwrite
  * the constructor and call parent.
  *
  * @param array $config The configuration array this behavior is using.
  * @return void
  */
 public function initialize(array $config)
 {
     if ($this->_config['length'] === null) {
         $length = $this->_table->schema()->column($this->_config['field'])['length'];
         $this->_config['length'] = $length ?: 0;
     }
     $label = $this->_config['label'] = (array) $this->_config['label'];
     if ($this->_table->behaviors()->has('Translate')) {
         $this->_config['length'] = false;
     }
     if ($this->_config['length']) {
         foreach ($label as $field) {
             $alias = $this->_table->alias();
             if (strpos($field, '.')) {
                 list($alias, $field) = explode('.', $field);
                 if (!$this->_table->{$alias}->hasField($field)) {
                     throw new Exception('(SluggedBehavior::setup) model ' . $this->_table->{$alias}->name . ' is missing the field ' . $field . ' (specified in the setup for model ' . $this->_table->name . ') ');
                 }
             } elseif (!$this->_table->hasField($field) && !method_exists($this->_table->entityClass(), '_get' . Inflector::classify($field))) {
                 throw new Exception('(SluggedBehavior::setup) model ' . $this->_table->name . ' is missing the field ' . $field . ' specified in the setup.');
             }
         }
     }
 }
 /**
  * {@inheritDoc}
  */
 public function describe($endpoint)
 {
     $shortName = App::shortName(get_class($this), 'Webservice', 'Webservice');
     list($plugin, $name) = pluginSplit($shortName);
     $schemaShortName = implode('.', array_filter([$plugin, Inflector::classify($endpoint)]));
     $schemaClassName = App::className($schemaShortName, 'Model/Endpoint/Schema', 'Schema');
     if ($schemaClassName) {
         return new $schemaClassName($endpoint);
     }
     throw new MissingEndpointSchemaException(['schema' => $schemaShortName, 'webservice' => $shortName]);
 }