本文整理汇总了PHP中Cake\Utility\Inflector::classify方法的典型用法代码示例。如果您正苦于以下问题:PHP Inflector::classify方法的具体用法?PHP Inflector::classify怎么用?PHP Inflector::classify使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Utility\Inflector
的用法示例。
在下文中一共展示了Inflector::classify方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initialize
/**
* {@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;
}
示例2: getTransformer
/**
* 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();
}
示例3: _getLastThreeLikes
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();
}
示例4: newEntity
/**
* 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);
}
示例5: _getLastFiveComments
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();
}
示例6: views
/**
* 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;
}
}
示例7: __call
/**
* 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);
}
示例8: __construct
/**
* 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);
}
示例9: initialize
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]);
}
示例10: testClassNaming
/**
* 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'));
}
示例11: clean
/**
* 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');
}
示例12: fileName
/**
* {@inheritDoc}
*/
public function fileName($name)
{
return Inflector::classify($this->args[0]) . 'Seed.php';
}
示例13: addType
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);
}
示例14: _getHandlerByFieldType
/**
* 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;
}
示例15: _loadFilter
/**
* 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));
}