/** * Gets the option parser instance and configures it. * * @return \Cake\Console\ConsoleOptionParser */ public function getOptionParser() { $parser = parent::getOptionParser(); $parser->description('Asset Management for CakePHP.'); foreach ($this->_taskMap as $task => $config) { $taskParser = $this->{$task}->getOptionParser(); $parser->addSubcommand(Inflector::underscore($task), ['help' => $taskParser->description(), 'parser' => $taskParser]); } return $parser; }
/** * main * */ public function main() { $schemaPo = APP . 'Locale' . DS . 'schema.pot'; $conn = ConnectionManager::get('default'); $collection = $conn->schemaCollection(); $translations = new Translations(); $tables = $collection->listTables(); foreach ($tables as $table) { $translations->insert($table, Inflector::humanize(Inflector::underscore($table))); $translations->insert($table, Inflector::humanize(Inflector::underscore(Inflector::singularize($table)))); $columns = $collection->describe($table)->columns(); foreach ($columns as $column) { $c = $collection->describe($table)->column($column); $comment = $c['comment']; $t = new Translation($table . '.' . $column, Inflector::humanize(Inflector::underscore($column))); $translations[] = $t; $t->setTranslation($comment); $t = new Translation($table . '.' . $column, Inflector::humanize(Inflector::underscore(Inflector::singularize($table))) . ' ' . Inflector::humanize(Inflector::underscore($column))); $translations[] = $t; $t->setTranslation($comment); } } $poString = $translations->toPoString(); $caked = preg_replace('/msgctxt "([^"]+)"/i', '#: \\1', $poString); $this->createFile($schemaPo, $caked); }
/** * Scan the provided paths for shells, and append them into $shellList * * @param string $type The type of object. * @param array $shells The shell name. * @param array $shellList List of shells. * @return array The updated $shellList */ protected function _appendShells($type, $shells, $shellList) { foreach ($shells as $shell) { $shellList[$type][] = Inflector::underscore(str_replace('Shell', '', $shell)); } return $shellList; }
/** * Get/Create an instance from the registry. * * When getting an instance, if it does not already exist, * a new instance will be created using the provide alias, and options. * * @param string $alias The name of the alias to get. * @param array $options Configuration options for the type constructor. * @return \Cake\ElasticSearch\Type */ public static function get($alias, array $options = []) { if (isset(static::$instances[$alias])) { if (!empty($options) && static::$options[$alias] !== $options) { throw new RuntimeException(sprintf('You cannot configure "%s", it already exists in the registry.', $alias)); } return static::$instances[$alias]; } static::$options[$alias] = $options; list(, $classAlias) = pluginSplit($alias); $options = $options + ['name' => Inflector::underscore($classAlias)]; if (empty($options['className'])) { $options['className'] = Inflector::camelize($alias); } $className = App::className($options['className'], 'Model/Type', 'Type'); if ($className) { $options['className'] = $className; } else { if (!isset($options['name']) && strpos($options['className'], '\\') === false) { list(, $name) = pluginSplit($options['className']); $options['name'] = Inflector::underscore($name); } $options['className'] = 'Cake\\ElasticSearch\\Type'; } if (empty($options['connection'])) { $connectionName = $options['className']::defaultConnectionName(); $options['connection'] = ConnectionManager::get($connectionName); } static::$instances[$alias] = new $options['className']($options); return static::$instances[$alias]; }
/** * Class Constructor * * Merges defaults with * - Configure::read(Meta) * - Helper options * - viewVars _meta * in that order (the latter trumps) * * @param array $options */ public function __construct(View $View, $options = []) { parent::__construct($View, $options); $configureMeta = (array) Configure::read('Meta'); if (Configure::read('Meta.robots') && is_array(Configure::read('Meta.robots'))) { $configureMeta['robots'] = Hash::merge($this->meta['robots'], Configure::read('Meta.robots')); } $this->meta = $configureMeta + $this->meta; if (!empty($options['robots']) && is_array($options['robots'])) { $options['robots'] = Hash::merge($this->meta['robots'], $options['robots']); } $this->meta = $options + $this->meta; if (!empty($this->_View->viewVars['_meta'])) { $viewVarsMeta = (array) $this->_View->viewVars['_meta']; if (!empty($viewVarsMeta['robots']) && is_array($viewVarsMeta['robots'])) { $viewVarsMeta['robots'] = Hash::merge($this->meta['robots'], $viewVarsMeta['robots']); } $this->meta = $viewVarsMeta + $this->meta; } if ($this->meta['charset'] === null) { // By default include this $this->meta['charset'] = true; } if ($this->meta['icon'] === null) { // By default include this $this->meta['icon'] = true; } if ($this->meta['title'] === null) { $this->meta['title'] = __(Inflector::humanize(Inflector::underscore($this->request->params['controller']))) . ' - ' . __(Inflector::humanize(Inflector::underscore($this->request->params['action']))); } }
/** * Overrides the original method from phinx in order to return a tailored * Config object containing the connection details for the database. * * @param bool $forceRefresh * @return \Phinx\Config\Config */ public function getConfig($forceRefresh = false) { if ($this->configuration && $forceRefresh === false) { return $this->configuration; } $folder = 'Migrations'; if ($this->input->getOption('source')) { $folder = $this->input->getOption('source'); } $dir = ROOT . DS . 'config' . DS . $folder; $plugin = null; if ($this->input->getOption('plugin')) { $plugin = $this->input->getOption('plugin'); $dir = Plugin::path($plugin) . 'config' . DS . $folder; } if (!is_dir($dir)) { mkdir($dir, 0777, true); } $plugin = $plugin ? Inflector::underscore($plugin) . '_' : ''; $plugin = str_replace(['\\', '/', '.'], '_', $plugin); $connection = $this->getConnectionName($this->input); $connectionConfig = ConnectionManager::config($connection); $adapterName = $this->getAdapterName($connectionConfig['driver']); $config = ['paths' => ['migrations' => $dir], 'environments' => ['default_migration_table' => $plugin . 'phinxlog', 'default_database' => 'default', 'default' => ['adapter' => $adapterName, 'host' => isset($connectionConfig['host']) ? $connectionConfig['host'] : null, 'user' => isset($connectionConfig['username']) ? $connectionConfig['username'] : null, 'pass' => isset($connectionConfig['password']) ? $connectionConfig['password'] : null, 'port' => isset($connectionConfig['port']) ? $connectionConfig['port'] : null, 'name' => $connectionConfig['database'], 'charset' => isset($connectionConfig['encoding']) ? $connectionConfig['encoding'] : null, 'unix_socket' => isset($connectionConfig['unix_socket']) ? $connectionConfig['unix_socket'] : null]]]; if ($adapterName === 'mysql') { if (!empty($connectionConfig['ssl_key']) && !empty($connectionConfig['ssl_cert'])) { $config['environments']['default']['mysql_attr_ssl_key'] = $connectionConfig['ssl_key']; $config['environments']['default']['mysql_attr_ssl_cert'] = $connectionConfig['ssl_cert']; } if (!empty($connectionConfig['ssl_ca'])) { $config['environments']['default']['mysql_attr_ssl_ca'] = $connectionConfig['ssl_ca']; } } return $this->configuration = new Config($config); }
/** * Return the webroot path to the image generated variant if this exist or to the controller if not. * * @param string $imagePath Path to the original image file from webroot if absolute, or relative to img/ * @param string|array $variantName Name of the variant configuration key or options array * @param array $options options * @return string */ public function variant($imagePath, $variantName, array $options = []) { if (!array_key_exists('plugin', $options) || $options['plugin'] !== false) { list($plugin, $imagePath) = $this->_View->pluginSplit($imagePath, false); } $url = false; $imagePath = $imagePath[0] === '/' ? substr($imagePath, 1) : $imagePath; if (!isset($plugin)) { $originalFile = WWW_ROOT . $imagePath; $variantFile = dirname($originalFile) . DS . $variantName . DS . basename($originalFile); if (is_file($variantFile)) { $url = str_replace(DS, '/', str_replace(WWW_ROOT, '/', $variantFile)); } } else { $originalFile = WWW_ROOT . Inflector::underscore($plugin) . DS . $imagePath; $variantFile = dirname($originalFile) . DS . $variantName . DS . basename($originalFile); if (is_file($variantFile)) { $url = str_replace(DS, '/', str_replace(WWW_ROOT, '/', $variantFile)); } else { $originalFile = Plugin::path($plugin) . 'webroot' . DS . $imagePath; $variantFile = dirname($originalFile) . DS . $variantName . DS . basename($originalFile); if (is_file($variantFile)) { $url = str_replace(Plugin::path($plugin) . 'webroot' . DS, '/' . Inflector::underscore($plugin) . '/', $variantFile); $url = str_replace(DS, '/', $url); } } } if ($url === false) { $url = ['controller' => 'Presenter', 'action' => 'variant', 'plugin' => 'ImagePresenter', 'prefix' => false, '?' => ['image' => isset($plugin) ? "{$plugin}.{$imagePath}" : $imagePath, 'variant' => $variantName]]; } return Router::url($url); }
/** * Get list of plugins to process. Plugins without a webroot directory are skipped. * * @param string|null $name Name of plugin for which to symlink assets. * If null all plugins will be processed. * @return array List of plugins with meta data. */ protected function _list($name = null) { if ($name === null) { $pluginsList = Plugin::loaded(); } else { if (!Plugin::loaded($name)) { $this->err(sprintf('Plugin %s is not loaded.', $name)); return []; } $pluginsList = [$name]; } $plugins = []; foreach ($pluginsList as $plugin) { $path = Plugin::path($plugin) . 'webroot'; if (!is_dir($path)) { $this->out('', 1, Shell::VERBOSE); $this->out(sprintf('Skipping plugin %s. It does not have webroot folder.', $plugin), 2, Shell::VERBOSE); continue; } $link = Inflector::underscore($plugin); $dir = WWW_ROOT; $namespaced = false; if (strpos($link, '/') !== false) { $namespaced = true; $parts = explode('/', $link); $link = array_pop($parts); $dir = WWW_ROOT . implode(DIRECTORY_SEPARATOR, $parts) . DIRECTORY_SEPARATOR; } $plugins[$plugin] = ['srcPath' => Plugin::path($plugin) . 'webroot', 'destDir' => $dir, 'link' => $link, 'namespaced' => $namespaced]; } return $plugins; }
/** * Create bootstrap tabs. * * @param array $data * @param string $id * @return string * @SuppressWarnings(PHPMD.ShortVariable) */ public function tabs($id, array $data = []) { $i = 0; $output = []; foreach ($data as $key => $options) { $i++; $title = !is_array($options) ? $options : $key; $alias = Text::slug((string) Inflector::underscore($key), '-'); if (is_string($options)) { $options = []; } $_options = ['linkOptions' => ['data-toggle' => 'tab']]; if (isset($options['title'])) { $title = $options['title']; unset($options['title']); } $_options['linkOptions']['title'] = $title; if ($i == 1) { $_options = $this->addClass($_options, 'active'); } $options = Hash::merge($_options, $options); $linkOptions = $options['linkOptions']; unset($options['linkOptions']); $link = $this->Html->link($title, '#' . $alias, $linkOptions); $output[] = $this->Html->tag('li', $link, $options); } return $this->Html->tag('ul', implode('', $output), ['class' => 'nav nav-tabs', 'id' => $id]); }
/** * Overrides the original method from phinx in order to return a tailored * Config object containing the connection details for the database. * * @return Phinx\Config\Config */ public function getConfig() { if ($this->configuration) { return $this->configuration; } $folder = 'Migrations'; if ($this->input->getOption('source')) { $folder = $this->input->getOption('source'); } $dir = ROOT . DS . 'config' . DS . $folder; $plugin = null; if ($this->input->getOption('plugin')) { $plugin = $this->input->getOption('plugin'); $dir = Plugin::path($plugin) . 'config' . DS . $folder; } if (!is_dir($dir)) { mkdir($dir, 0777, true); } $plugin = $plugin ? Inflector::underscore($plugin) . '_' : ''; $plugin = str_replace(array('\\', '/', '.'), '_', $plugin); $connection = 'default'; if ($this->input->getOption('connection')) { $connection = $this->input->getOption('connection'); } $config = ConnectionManager::config($connection); return $this->configuration = new Config(['paths' => ['migrations' => $dir], 'environments' => ['default_migration_table' => $plugin . 'phinxlog', 'default_database' => 'default', 'default' => ['adapter' => $this->getAdapterName($config['driver']), 'host' => isset($config['host']) ? $config['host'] : null, 'user' => isset($config['username']) ? $config['username'] : null, 'pass' => isset($config['password']) ? $config['password'] : null, 'port' => isset($config['port']) ? $config['port'] : null, 'name' => $config['database'], 'charset' => $config['encoding']]]]); }
/** * Get classes for main wrapper. * * @return string */ public function getClasses() { $plugin = preg_replace('/[^A-Z0-9_\\.-]/i', '', $this->request->param('plugin')); $plugin = Inflector::underscore($plugin); $controller = mb_strtolower($this->request->param('controller')); $action = mb_strtolower($this->request->param('action')); return implode(' ', ['plg-' . Inflector::slug($plugin, '-'), 'cont-' . $controller, 'action-' . $action]); }
/** * Returns the cache key (prefix) to be used with a table class. * * @param \Cake\ORM\Table $table The table class * @return string */ public static function table(\Cake\ORM\Table $table) { $alias = get_class($table); if (false === isset(static::$liveCache[__FUNCTION__][$alias])) { static::$liveCache[__FUNCTION__][$alias] = implode('_', array_filter([Inflector::underscore($table->connection()->configName()), Fqn::prefix($alias), Inflector::underscore(Fqn::root($alias)), Inflector::underscore(Fqn::tail($alias)), Inflector::underscore($table->alias())])); } return static::$liveCache[__FUNCTION__][$alias]; }
public function getActionName($controller, $id) { $this->autoRender = false; $indexed_tables = $this->_getIndexedTables(); if (isset($indexed_tables[$controller][$id])) { echo $indexed_tables[$controller][$id] . ' (' . __(Inflector::humanize(Inflector::underscore($controller))) . ' / ' . $id . ')'; } }
/** * Get the element name for the panel. * * @return string */ public function elementName() { list($ns, $name) = namespaceSplit(get_class($this)); if ($this->plugin) { return $this->plugin . '.' . Inflector::underscore($name); } return Inflector::underscore($name); }
public function __call($method, $args) { $type = Inflector::underscore(substr($method, 3)); if (!isset($args[0])) { $args[0] = []; } $args[0] += [$this->config('typeField') => $type]; return call_user_func_array([$this->_table($type), 'newEntity'], $args); }
/** * @return array */ public function toArray() { $array = []; foreach (get_object_vars($this) as $property => $value) { $key = Inflector::underscore($property); $array[$key] = $value; } return $array; }
/** * Get plugin alias. * * @param $plugin * @return string */ public static function alias($plugin) { $_plg = $plugin; $plugin = FS::clean(Slug::filter($plugin), '/'); if (!strpos($_plg, '/') && !strpos($_plg, '\\')) { $plugin = Inflector::underscore($_plg); } return Str::low($plugin); }
/** * Get the phinx table name used to store migrations data * * @param string $plugin Plugin name * @return string */ protected function getPhinxTable($plugin = null) { $table = 'phinxlog'; if (empty($plugin)) { return $table; } $plugin = Inflector::underscore($plugin) . '_'; $plugin = str_replace(['\\', '/', '.'], '_', $plugin); return $plugin . $table; }
/** * Is triggered when invoking inaccessible methods in an object context. * * @param string $name The $name argument is the name of the method being called. * @param array $arguments The $arguments argument is an enumerated array containing * the parameters passed to the $name'ed method. * * @return mixed */ function __call($name, $arguments) { $propertyName = Inflector::underscore(substr($name, 3)); if (strpos($name, 'get', 0) !== false) { return $this->get($propertyName); } elseif (strpos($name, 'set', 0) !== false) { $this->set($propertyName, $arguments[0]); return $this; } }
/** * Helper method for underscoring keys in a URL array. * * @param array $url An array of URL keys. * @return array */ protected function _underscore($url) { if (!empty($url['controller'])) { $url['controller'] = Inflector::underscore($url['controller']); } if (!empty($url['plugin'])) { $url['plugin'] = Inflector::underscore($url['plugin']); } return $url; }
/** * Get/set the property this embed is attached to. * * @param string|null $name The property name to set. * @return string The property name. */ public function property($name = null) { if ($name === null) { if (!$this->property) { $this->property = Inflector::underscore($this->alias); } return $this->property; } $this->property = $name; }
public function item($item, $type) { $Activity = TableRegistry::get('Social.Activities'); $activity = $Activity->newEntity(['object_id' => $item->id, 'created' => $item->created, 'object' => $type, 'subject_id' => $item->user_id, 'type' => Inflector::underscore($type), 'data' => json_encode(['field' => 'content', 'value' => $item->content]), 'pole_id' => $item->pole_id, 'linked_object' => $item]); $activity->author = $item->author; $activity->feeds = $item->feeds; $this->_View->set('activity', $activity); $this->_View->set('icon', $this->icons[$activity->object]); return $this->_View->element('Social.Feed/' . $type); }
/** * Sets the property name that should be filled with data from the target table * in the source table record. * If no arguments are passed, currently configured type is returned. * * @param string|null $name The name of the property. Pass null to read the current value. * @return string */ public function property($name = null) { if ($name !== null) { return parent::property($name); } if ($name === null && !$this->_propertyName) { list(, $name) = pluginSplit($this->_name); $this->_propertyName = Inflector::underscore(Inflector::singularize($name)); } return $this->_propertyName; }
/** * Bake empty layout files for html/text emails. * * @param string $name The name of the mailer layouts are needed for. * @return void */ public function bakeLayouts($name) { $restore = $this->pathFragment; $layoutsPath = implode(DS, ['Template', 'Layout', 'Email']); foreach (['html', 'text'] as $type) { $this->pathFragment = implode(DS, [$layoutsPath, $type, Inflector::underscore($name) . '.ctp']); $path = $this->getPath(); $this->createFile($path, ''); } $this->pathFragment = $restore; }
/** * Return the cache key name for the current table, language and domain. * * @return string */ protected function cacheKey() { if ($this->cacheKey === null) { $plugin = Inflector::underscore(namespaceRoot(__CLASS__)); $class = Inflector::underscore(namespaceTail(__CLASS__)); $connection = Inflector::underscore($this->_table->connection()->configName()); $table = Inflector::underscore($this->_table->table()); $this->cacheKey = $plugin . '_' . $class . '_' . $connection . '_' . $table; } return $this->cacheKey; }
/** * Sets the name of the field representing the foreign key to the source table. * If no parameters are passed current field is returned * * @param string $key the key to be used to link both tables together * @return string */ public function foreignKey($key = null) { if ($key === null) { if ($this->_foreignKey === null) { $key = Inflector::singularize($this->source()->alias()); $this->_foreignKey = Inflector::underscore($key) . '_id'; } return $this->_foreignKey; } return parent::foreignKey($key); }
/** * _getDisplayTemplate * Cells operate in different ctp files. * Currently, for simplicity reasons, we define * the list of templates (ctp files) that we use * so display() becomes a basic wrapper for TabContent. * @param array $data passed from the event * * @return string $result containing template. */ protected function _getDisplayTemplate(array $data) { $result = 'display'; $displayTemplate = null; if (!empty($data['options']) && isset($data['options']['displayTemplate'])) { $displayTemplate = $data['options']['displayTemplate']; } if (in_array($displayTemplate, $this->_displayTemplates)) { $result = Inflector::underscore($displayTemplate); } return $result; }
/** * Returns the database method name or sets a new one * * @param string|null $method the new method name * @return string */ public function method($method = null) { if ($method !== null) { $this->_method = $method; } if ($this->_method === null) { $method = namespaceSplit(get_class($this)); $method = substr(end($method), 0, -6); $this->_method = Inflector::underscore($method); } return $this->_method; }
/** * Helper method for slugerizing keys in a URL array. * * @param array $url An array of URL keys. * * @return array */ protected function _slugerize($url) { if (isset($url['slug']) && !empty($url['slug'])) { $url['slug'] = strtolower(Inflector::slug($url['slug'])); } if (!empty($url['controller'])) { $url['controller'] = Inflector::underscore($url['controller']); } if (!empty($url['plugin'])) { $url['plugin'] = Inflector::underscore($url['plugin']); } return $url; }
/** * Loads all fixtures from disk if none defined. * * @param \Cake\TestSuite\TestCase $test The test case to inspect. * @return void */ public function fixturize($test) { if (!isset($test->fixtures)) { $folder = new Folder($this->_fixturePath); $fixtureFiles = $folder->find('.*Fixture\\.php'); foreach ($fixtureFiles as $fixtureFile) { $fixtureName = str_replace('Fixture.php', '', $fixtureFile); $fixtureName = Inflector::underscore($fixtureName); $test->fixtures[] = 'app.' . $fixtureName; } } parent::fixturize($test); }