當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Inflector::pluralize方法代碼示例

本文整理匯總了PHP中lithium\util\Inflector::pluralize方法的典型用法代碼示例。如果您正苦於以下問題:PHP Inflector::pluralize方法的具體用法?PHP Inflector::pluralize怎麽用?PHP Inflector::pluralize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在lithium\util\Inflector的用法示例。


在下文中一共展示了Inflector::pluralize方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: _autoSelects

 protected function _autoSelects($name, array $options = array())
 {
     $model = $this->_binding->model();
     $method = Inflector::pluralize($name);
     $rules = $this->instance->validates;
     if (method_exists($model, $method)) {
         $list = $model::$method();
         if (!empty($list)) {
             $options['list'] = $list;
             return $options;
         }
     }
     if (isset($rules[$name])) {
         if (is_array($rules[$name][0])) {
             $rule_list = $rules[$name];
         } else {
             $rule_list = array($rules[$name]);
         }
         foreach ($rule_list as $rule) {
             if ($rule[0] === 'inList' and isset($rule['list'])) {
                 foreach ($rule['list'] as $optval) {
                     $options['list'][$optval] = Inflector::humanize($optval);
                 }
             }
         }
     }
     return $options;
 }
開發者ID:bruensicke,項目名稱:li3_bootstrap,代碼行數:28,代碼來源:Form.php

示例2: testIndexScaffold

 public function testIndexScaffold()
 {
     $this->_controller->index();
     $scaffold = $this->_controller->access('scaffold');
     $expected = array('base' => '/radium/configurations', 'controller' => 'Configurations', 'library' => 'radium', 'class' => 'MockConfigurations', 'model' => 'radium\\tests\\mocks\\data\\MockConfigurations', 'slug' => Inflector::underscore('MockConfigurations'), 'singular' => Inflector::singularize('MockConfigurations'), 'plural' => Inflector::pluralize('MockConfigurations'), 'table' => Inflector::tableize('MockConfigurations'), 'human' => Inflector::humanize('MockConfigurations'));
     $this->assertEqual($expected, $scaffold);
 }
開發者ID:bruensicke,項目名稱:radium,代碼行數:7,代碼來源:ScaffoldControllerTest.php

示例3: _prepareAcl

 /**
  * Prepare `Aco` and `Aro` identifiers to be used for finding Acos and Aros nodes
  */
 protected function _prepareAcl()
 {
     $request = $this->request->params;
     $user = $this->_user;
     $guest = $this->_guest;
     $buildAroPath = function ($group = null, $path = array()) use(&$buildAroPath) {
         $parent = null;
         $path[] = Inflector::pluralize($group['slug']);
         if ($group['parent_id']) {
             $parent = UserGroups::first(array('conditions' => array('parent_id' => $group['parent_id'])));
         }
         if ($parent) {
             return $buildAroPath($parent, $path);
         }
         return join('/', $path);
     };
     $prepareAco = function () use($request) {
         extract($request);
         $library = isset($library) ? $library . '/' : '';
         return $library . 'controllers/' . $controller;
     };
     $prepareAro = function () use($user, $guest, $buildAroPath) {
         if ($guest) {
             return 'guests';
         }
         return 'users/' . $buildAroPath($user['user_group']);
     };
     $this->_aco = $prepareAco();
     $this->_aro = $prepareAro();
 }
開發者ID:djordje,項目名稱:li3_usermanager,代碼行數:33,代碼來源:AccessController.php

示例4: _class

 /**
  * Get the class name for the mock.
  *
  * @param string $request
  * @return string
  */
 protected function _class($request)
 {
     $type = $request->action;
     $name = $request->args();
     if ($command = $this->_instance($type)) {
         $request->params['action'] = $name;
         $name = $command->invokeMethod('_class', array($request));
     }
     return Inflector::pluralize("Mock{$name}");
 }
開發者ID:WarToaster,項目名稱:HangOn,代碼行數:16,代碼來源:Mock.php

示例5: run

 public function run($name = null, $null = null)
 {
     $library = Libraries::get($this->library);
     if (empty($library['prefix'])) {
         return false;
     }
     $model = Inflector::classify($name);
     $use = "\\{$library['prefix']}models\\{$model}";
     $params = array('namespace' => "{$library['prefix']}controllers", 'use' => $use, 'class' => "{$name}Controller", 'model' => $model, 'singular' => Inflector::singularize(Inflector::underscore($name)), 'plural' => Inflector::pluralize(Inflector::underscore($name)));
     if ($this->_save($this->template, $params)) {
         $this->out("{$params['class']} created in {$params['namespace']}.");
         return true;
     }
     return false;
 }
開發者ID:kdambekalns,項目名稱:framework-benchs,代碼行數:15,代碼來源:Controller.php

示例6: relationship

 public function relationship($class, $type, $name, array $config = array())
 {
     $field = Inflector::underscore(Inflector::singularize($name));
     $key = "{$field}_id";
     $primary = $class::meta('key');
     if (is_array($primary)) {
         $key = array_combine($primary, $primary);
     } elseif ($type === 'hasMany' || $type === 'hasOne') {
         if ($type === 'hasMany') {
             $field = Inflector::pluralize($field);
         }
         $secondary = Inflector::underscore(Inflector::singularize($class::meta('name')));
         $key = array($primary => "{$secondary}_id");
     }
     $from = $class;
     $fieldName = $field;
     $config += compact('type', 'name', 'key', 'from', 'fieldName');
     return $this->_instance('relationship', $config);
 }
開發者ID:nilamdoc,項目名稱:KYCGlobal,代碼行數:19,代碼來源:MockSource.php

示例7: handlers

 public static function handlers($handlers = null)
 {
     if (!static::$_handlers) {
         static::$_handlers = array('binding' => function ($request, $options) {
             $model = $options['binding'];
             $name = $options['name'];
             $model = Libraries::locate('models', $model ?: Inflector::pluralize($name));
             if (!$model || is_string($model) && !class_exists($model)) {
                 $msg = "Could not find resource-mapped model class for resource `{$name}`.";
                 throw new UnmappedResourceException($msg);
             }
             return $model;
         }, 'isRequired' => function ($request, $options, $result = null) {
             $name = $options['name'];
             $required = $options['required'];
             $model = $options['binding'];
             $isCountable = $result && $result instanceof Countable;
             $isValid = $result && !$isCountable || $isCountable && $result->valid();
             if ($isValid || !$required) {
                 return $result;
             }
             $model = is_object($model) ? get_class($model) : $model;
             $message = "Resource `{$name}` not found in model `{$model}`.";
             throw new ResourceNotFoundException($message);
         }, 'default' => array(function ($request, $options) {
             $isRequired = Resources::handlers('isRequired');
             $query = (array) $options['call'] + array('all');
             $call = $query[0];
             unset($query[0]);
             return $isRequired($request, $options, $options['binding']::$call($query));
         }, 'create' => function ($request, $options) {
             return $options['binding']::create($request->data);
         }));
     }
     if (is_array($handlers)) {
         static::$_handlers = $handlers + static::$_handlers;
     }
     if ($handlers && is_string($handlers)) {
         return isset(static::$_handlers[$handlers]) ? static::$_handlers[$handlers] : null;
     }
     return static::$_handlers;
 }
開發者ID:nateabele,項目名稱:li3_resources,代碼行數:42,代碼來源:Resources.php

示例8: link_types

    /**
     * Returns a list of links to model types' actions (Page types, User types, etc.)
     * By default, with no options specified, this returns a list of links to create any type of page (except core page).
     *
     * @param $model_name String The model name (can be lowercase, the Util class corrects it)
     * @param $action String The controller action
     * @param $options Array Various options that get passed to Util::list_types() and the key "link_options" can contain an array of options for the $this->html->link()
     * @return String HTML list of links
     * @see minerva\libraries\util\Util::list_types()
    */
    public function link_types($model_name='Page', $action='create', $options=array()) {
        $options += array('exclude_minerva' => true, 'link_options' => array());
        $libraries = Util::list_types($model_name, $options);
        $output = '';
        
        (count($libraries) > 0) ? $output .= '<ul>':$output .= '';
	foreach($libraries as $library) {
            if(substr($library, 0, 7) == 'minerva') {
                $model = $library;
            } else {
                $model = 'minerva\libraries\\' . $library;
            }
	    $type = current(explode('\\', $library));
	    if(strtolower($type) == 'minerva') {
		$type = null;
	    }
	    $output .= '<li>' . $this->link($model::display_name(), '/' . Inflector::pluralize($model_name) . '/' . $action . '/' . $type, $options['link_options']) . '</li>';
	}
        (count($libraries) > 0) ? $output .= '</ul>':$output .= '';
        
        return $output;
    }
開發者ID:nateabele,項目名稱:Minerva-Plugin,代碼行數:32,代碼來源:Html.php

示例9: stats

 /**
  * Return statistics from the test runs.
  *
  * @return array
  */
 public function stats()
 {
     $results = (array) $this->results['group'];
     $defaults = array('asserts' => 0, 'passes' => array(), 'fails' => array(), 'exceptions' => array(), 'errors' => array(), 'skips' => array());
     $stats = array_reduce($results, function ($stats, $result) use($defaults) {
         $stats = (array) $stats + $defaults;
         $result = empty($result[0]) ? array($result) : $result;
         foreach ($result as $response) {
             if (empty($response['result'])) {
                 continue;
             }
             $result = $response['result'];
             if (in_array($result, array('fail', 'exception'))) {
                 $response = array_merge(array('class' => 'unknown', 'method' => 'unknown'), $response);
                 $stats['errors'][] = $response;
             }
             unset($response['file'], $response['result']);
             if (in_array($result, array('pass', 'fail'))) {
                 $stats['asserts']++;
             }
             if (in_array($result, array('pass', 'fail', 'exception', 'skip'))) {
                 $stats[Inflector::pluralize($result)][] = $response;
             }
         }
         return $stats;
     });
     $stats = (array) $stats + $defaults;
     $count = array_map(function ($value) {
         return is_array($value) ? count($value) : $value;
     }, $stats);
     $success = $count['passes'] === $count['asserts'] && $count['errors'] === 0;
     return compact('stats', 'count', 'success');
 }
開發者ID:unionofrad,項目名稱:lithium,代碼行數:38,代碼來源:Report.php

示例10: _default

 /**
  * Run through the default set. model, controller, test model, test controller
  *
  * @param string $name class name to create
  * @return boolean
  */
 protected function _default($name)
 {
     $commands = array(array('model', Inflector::pluralize($name)), array('controller', Inflector::pluralize($name)), array('test', 'model', Inflector::pluralize($name)), array('test', 'controller', Inflector::pluralize($name)));
     foreach ($commands as $args) {
         $command = $this->template = $this->request->params['command'] = array_shift($args);
         $this->request->params['action'] = array_shift($args);
         $this->request->params['args'] = $args;
         if (!$this->_execute($command)) {
             return false;
         }
     }
     return true;
 }
開發者ID:davidpersson,項目名稱:FrameworkBenchmarks,代碼行數:19,代碼來源:Create.php

示例11: _files

 /**
  * Returns absolute paths to files according to configuration.
  *
  * @param string $category
  * @param string $locale
  * @param string $scope
  * @return array
  */
 protected function _files($category, $locale, $scope)
 {
     $path = $this->_config['path'];
     $scope = $scope ?: 'default';
     if (($pos = strpos($category, 'Template')) !== false) {
         $category = substr($category, 0, $pos);
         return array("{$path}/{$category}_{$scope}.pot");
     }
     if ($category == 'message') {
         $category = Inflector::pluralize($category);
     }
     $category = strtoupper($category);
     return array("{$path}/{$locale}/LC_{$category}/{$scope}.mo", "{$path}/{$locale}/LC_{$category}/{$scope}.po");
 }
開發者ID:kdambekalns,項目名稱:framework-benchs,代碼行數:22,代碼來源:Gettext.php

示例12: _readEmbeddedFilter

 protected function _readEmbeddedFilter()
 {
     // filter for relations
     self::applyFilter('read', function ($self, $params, $chain) {
         $results = $chain->next($self, $params, $chain);
         if (isset($params['options']['with']) && !empty($params['options']['with'])) {
             $model = is_object($params['query']) ? $params['query']->model() : null;
             $relations = $model::relations();
             foreach ($params['options']['with'] as $k => $name) {
                 if (isset($relations[$name])) {
                     $relation = $relations[$name]->data();
                     $relationModel = Libraries::locate('models', $relation['to']);
                     if (!empty($relationModel) && !empty($results) && isset($relation['embedded'])) {
                         $embedded_on = $relation['embedded'];
                         $resultsArray = $results->to('array');
                         foreach ($resultsArray as $k => $result) {
                             $relationalData = Set::extract($result, '/' . str_replace('.', '/', $embedded_on));
                             if (!empty($embedded_on)) {
                                 $keys = explode('.', $embedded_on);
                                 $lastKey = array_slice($keys, -1, 1);
                                 $lastKey = $lastKey[0];
                                 $data = array();
                                 foreach ($relationalData as $rk => $rv) {
                                     if (!empty($rv)) {
                                         if (!is_array($rv)) {
                                             $data[$rk] = $rv;
                                         } else {
                                             if (isset($rv[$lastKey]) && !empty($rv[$lastKey])) {
                                                 $data[$rk] = $rv[$lastKey];
                                             }
                                         }
                                     }
                                 }
                                 if (!empty($data)) {
                                     // TODO : Add support for conditions, fields, order, page, limit
                                     $validFields = array_fill_keys(array('with'), null);
                                     $options = array_intersect_key($relation, $validFields);
                                     $options['data'] = $data;
                                     if ($relation['type'] == 'hasMany') {
                                         $type = 'all';
                                     } else {
                                         $type = 'first';
                                     }
                                     $relationResult = $relationModel::find($type, $options);
                                 } else {
                                     if ($relation['type'] == 'hasMany') {
                                         $relationResult = $self->item($relationModel, array(), array('class' => 'set'));
                                     } else {
                                         $relationResult = null;
                                     }
                                 }
                                 // if fieldName === true, use the default lithium fieldName.
                                 // if fieldName != relationName, then it was manually set, so use it
                                 // else, just use the embedded key
                                 $relationName = $relation['type'] == 'hasOne' ? Inflector::pluralize($relation['name']) : $relation['name'];
                                 if ($relation['fieldName'] === true) {
                                     $relation['fieldName'] = lcfirst($relationName);
                                     $keys = explode('.', $relation['fieldName']);
                                 } else {
                                     if ($relation['fieldName'] != lcfirst($relationName)) {
                                         $keys = explode('.', $relation['fieldName']);
                                     }
                                 }
                                 $ref = $results[$k];
                                 foreach ($keys as $k => $key) {
                                     if (!isset($ref->{$key})) {
                                         $ref->{$key} = $self->item(null, array(), array('class' => 'entity'));
                                     }
                                     if (count($keys) - 1 == $k) {
                                         $ref->{$key} = $relationResult;
                                     } else {
                                         $ref = $ref->{$key};
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         return $results;
     });
 }
開發者ID:brandonwestcott,項目名稱:li3_embedded,代碼行數:83,代碼來源:MongoEmbedded.php

示例13: switch

 }
 switch ($type) {
     case 'rte':
     case 'textarea':
         $options = array('type' => 'textarea', 'class' => "form-control autogrow {$field}", 'rows' => 3);
         if (in_array($field, $readonly)) {
             $options['disabled'] = 'disabled';
             $options['class'] .= ' uneditable-textarea';
         }
         if ($type == 'rte') {
             $options['class'] .= ' rte';
         }
         echo $this->form->field($field, $options);
         break;
     case 'select':
         $method = Inflector::underscore(Inflector::pluralize($field));
         $options = array('type' => 'select', 'class' => "form-control {$field}", 'data-switch' => $field, 'list' => $model::$method());
         if (isset($schema[$field]['null']) && $schema[$field]['null'] === true) {
             $options['empty'] = true;
         }
         if (in_array($field, $readonly)) {
             $options['type'] = 'text';
             $options['value'] = $model::$method($this->scaffold->object->{$field});
             $options['disabled'] = 'disabled';
             $options['class'] .= ' uneditable-input';
         }
         echo $this->form->field($field, $options);
         break;
     case 'configuration':
         $options = array('type' => 'select', 'class' => "form-control {$field}", 'data-switch' => 'configuration', 'list' => Configurations::find('list'));
         if (isset($schema[$field]['null']) && $schema[$field]['null'] === true) {
開發者ID:bruensicke,項目名稱:radium,代碼行數:31,代碼來源:form.fields.html.php

示例14: _default

 /**
  * If no resource parameter definition exists for a method, generate a default mapping.
  *
  * @param string $method The class method name to be called, i.e. `'index'`, `'add'`, etc.
  * @return array Returns an array where the key is the singular or plural name of the `Resource`
  *         class, i.e. `'post'` or `'posts'`, and the value is a sub-array with an
  *         optionally-non-namespaced model name or fully-qualified class name as the first
  *         value, and a `'call'` key, indicating the name of the class method to call.
  */
 protected function _default($method)
 {
     $name = lcfirst(static::_name());
     $isPlural = $method == 'index';
     $call = array(true => 'first', $isPlural => 'all', $method == 'add' => 'create');
     $key = $isPlural ? Inflector::pluralize($name) : Inflector::singularize($name);
     return array($key => array(static::binding(), 'call' => $call[true], 'required' => !$isPlural));
 }
開發者ID:nateabele,項目名稱:li3_resources,代碼行數:17,代碼來源:Resource.php

示例15: bind

 /**
  * Connect a resource to the `Router`.
  *
  * @param string $resource The name of the resource
  * @param array $options
  */
 public static function bind($resource, $options = array())
 {
     $resources = explode('/', $resource);
     $splitCount = count($resources);
     $class = static::$_classes['route'];
     $scope = isset($options['scope']) ? '(/{:scope:' . strtolower($options['scope']) . '})' : '';
     if ($splitCount > 1) {
         $controller = $resources[$splitCount - 1];
         $resource = Inflector::underscore($controller);
         for ($i = $splitCount - 2; $i >= 0; $i--) {
             $resource = Inflector::underscore($resources[$i]) . '/{:' . Inflector::underscore($resources[$i]) . '_id:[0-9a-f]{24}|[0-9]+}/' . $resource;
         }
     } else {
         $resource = Inflector::pluralize(strtolower(Inflector::slug($resource)));
         $controller = $resource;
         $resource = Inflector::underscore($resource);
     }
     $types = static::$_types;
     if (isset($options['types'])) {
         $types = $options['types'] + $types;
     }
     if (isset($options['except'])) {
         foreach (array_intersect((array) $options['except'], array_keys($types)) as $k) {
             unset($types[$k]);
         }
     }
     if (isset($options['only'])) {
         foreach (array_keys($types) as $k) {
             if (!in_array($k, (array) $options['only'])) {
                 unset($types[$k]);
             }
         }
     }
     $configs = array();
     foreach ($types as $action => $params) {
         $config = array('template' => $scope . String::insert($params['template'], array('resource' => $resource)), 'params' => $params['params'] + array('controller' => $controller, 'action' => isset($params['action']) ? $params['action'] : $action));
         $configs[] = $config;
         if (@$options['type_support'] != false) {
             if (isset($params['type_support']) && $params['type_support'] || @$options['type_support']) {
                 $config = array('template' => $scope . String::insert($params['template'] . '(.{:type:\\w+})?', array('resource' => $resource)), 'params' => $params['params'] + array('controller' => $controller, 'action' => isset($params['action']) ? $params['action'] : $action));
                 $configs[] = $config;
             }
         }
     }
     return $configs;
 }
開發者ID:johnny13,項目名稱:li3_rest,代碼行數:52,代碼來源:Resource.php


注:本文中的lithium\util\Inflector::pluralize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。