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


PHP Inflector::pluralize方法代碼示例

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


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

示例1: test_pluralize_singulars

 public function test_pluralize_singulars()
 {
     $ar = (require __DIR__ . '/cases/singular_to_plural.php');
     foreach ($ar as $singular => $plural) {
         $this->assertEquals($plural, self::$inflector->pluralize($singular));
         $this->assertEquals($plural, self::$inflector->pluralize($plural));
         $this->assertEquals(ucfirst($plural), self::$inflector->pluralize(ucfirst($singular)));
         $this->assertEquals(ucfirst($plural), self::$inflector->pluralize(ucfirst($plural)));
     }
 }
開發者ID:buildwithcraft,項目名稱:craft-utensils,代碼行數:10,代碼來源:InflectorTest.php

示例2: main

 /**
  * main
  *
  * @return void
  */
 public function main()
 {
     $model = $this->in('Model name:');
     $controller = Inflector::pluralize($model);
     $controllerActions = $this->in('Do you want to bake the controller with admin prefix: yes/no', 'y/n', 'n');
     $usePlugin = $this->in("Do you want to bake in plugin: yes/no", 'y/n', 'n');
     if ($usePlugin == 'y') {
         $pluginName = $this->in('Name of your plugin:', null, '');
         if ($pluginName == '') {
             $usePlugin = 'n';
         }
     }
     if ($controllerActions == 'y') {
         $controllerActions = '--admin';
     } else {
         $controllerActions = '--public';
     }
     $theme = 'fuelux';
     $modelCommand = "ajax_template.ext_bake model {$model}";
     $controllerCommand = "ajax_template.ext_bake controller {$controller} {$controllerActions}";
     $viewCommand = "ajax_template.ext_bake view {$controller}";
     $postfix = " --theme {$theme}";
     if ($usePlugin == 'y') {
         $postfix .= " --plugin {$pluginName}";
     }
     $this->dispatchShell($modelCommand . $postfix);
     $this->dispatchShell($controllerCommand . $postfix);
     $this->dispatchShell($viewCommand . $postfix);
 }
開發者ID:br-nhan,項目名稱:AjaxTemplate,代碼行數:34,代碼來源:TemplateShell.php

示例3: __find_all

	function __find_all ($class)
	{
		$query_string = "";

		if (count($class->attributes) > 0)
			$query_string = "?" . join('&', array_map(create_function('$a,$b', 'return "$a=$b";'), array_keys($class->attributes), array_values($class->attributes)));
		
		$response = $this->__request($class, 'GET', $query_string);
		
		$parser = new XMLParser();
		
		$array = $parser->parse_into_array($response->body);
		
		$class_name = "SS" . $class->class_name();
		$singular = Inflector::underscore($class->class_name());
		$plural = Inflector::pluralize($singular);
		
		$records = $array[$plural][$singular];
		
		if (ArrayHelper::is_associative($records))
			$records = array($records);
		
		$objects = array();
		foreach ($records as $attrs)
			$objects[] = new $class_name($attrs);

		return $objects;
	}
開發者ID:streamsend,項目名稱:streamsend-php,代碼行數:28,代碼來源:resource.php

示例4: loadTasks

 /**
  * Override loadTasks() to handle paths
  *
  * @access public
  */
 function loadTasks()
 {
     parent::loadTasks();
     $task = Inflector::classify($this->command);
     if (isset($this->{$task}) && !in_array($task, array('Project', 'DbConfig'))) {
         if (empty($this->{$task}->path)) {
             $path = Inflector::underscore(Inflector::pluralize($this->command));
             $this->{$task}->path = $this->params['working'] . DS . $path . DS;
         }
         if (isset($this->params['connection'])) {
             $this->{$task}->connection = $this->params['connection'];
         }
         foreach ($this->args as $i => $arg) {
             if (strpos($arg, '.')) {
                 list($this->params['plugin'], $this->args[$i]) = pluginSplit($arg);
                 break;
             }
         }
         if (isset($this->params['plugin'])) {
             $this->{$task}->plugin = $this->params['plugin'];
         }
         if (!is_dir($this->{$task}->path)) {
             $this->err(sprintf(__("%s directory could not be found.\nBe sure you have created %s", true), $task, $this->{$task}->path));
             $this->_stop();
         }
     }
 }
開發者ID:enangyusup,項目名稱:vbulletin-cakephp,代碼行數:32,代碼來源:bake.php

示例5: model

	public function model($args)
	{
		$singular = strtolower(array_shift($args));

		$plural = \Inflector::pluralize($singular);

		$filepath = APPPATH . 'classes/model/' . $singular .'.php';

		$class_name = ucfirst($singular);

		$model = <<<MODEL
<?php

class Model_{$class_name} extends ActiveRecord\Model { }

/* End of file $singular.php */
MODEL;

		if (self::write($filepath, $model))
		{
			\Cli::write('Created model: ' . \Fuel::clean_path($filepath));
		}

		if ( ! empty($args))
		{
			array_unshift($args, 'create_'.$plural);
			static::migration($args);
		}
	}
開發者ID:ralf57,項目名稱:fuel,代碼行數:29,代碼來源:generate.php

示例6: beforeRender

 /**
  * beforeRender is used for pre-render processing.
  * Search the model schema for enum fields and transform
  * them to use selects instead of text-input boxes
  *
  * During the model loop, we also check for form validation
  * errors, and add them to an array, so that we can consolidate
  * errors at the top of the page.
  *
  * This code is probably Mysql specific.
  */
 function beforeRender()
 {
     $this->_persistValidation();
     $validationErrors = array();
     foreach ($this->modelNames as $model) {
         // add validationerrors to view
         if (is_array($this->{$model}->validationErrors)) {
             $validationErrors = array_merge($validationErrors, array_values($this->{$model}->validationErrors));
         }
         // enum fixer
         foreach ($this->{$model}->_schema as $var => $field) {
             // === used here because 0 != FALSE
             if (strpos($field['type'], 'enum') === FALSE) {
                 continue;
             }
             preg_match_all("/\\'([^\\']+)\\'/", $field['type'], $strEnum);
             if (is_array($strEnum[1])) {
                 $varName = Inflector::camelize(Inflector::pluralize($var));
                 $varName[0] = strtolower($varName[0]);
                 // make nice cases in <selects>
                 $names = array();
                 foreach ($strEnum[1] as $name) {
                     $names[] = ucwords(strtolower($name));
                 }
                 $this->set($varName, array_combine($strEnum[1], $names));
             }
         }
     }
     $this->set('validationErrors', $validationErrors);
 }
開發者ID:busytoby,項目名稱:gitrbug,代碼行數:41,代碼來源:origami_app_controller.php

示例7: set

 /**
  * Sets the views meta data, if available
  *
  * @param array $data
  * @return void
  */
 public function set($data = array())
 {
     $Model = $this->__controller->{$this->__controller->modelClass};
     // assign the meta title variable, starting with data assigned
     // directly to MetaData, falling back next to the Model displayField
     // variable before falling again to the Model displayName variable
     if (!empty($data['MetaData']['title'])) {
         $metaTitle = $data['MetaData']['title'];
     } elseif (!empty($data[$Model->alias][$Model->displayField])) {
         $metaTitle = $data[$Model->alias][$Model->displayField];
     } else {
         $metaTitle = Inflector::pluralize($data[$Model->alias][$Model->displayName]);
     }
     if (!empty($metaTitle)) {
         $this->Controller->set(compact('metaTitle'));
     }
     // assign the meta description variable, starting with data
     // assigned directly to MetaData, falling back to content
     // and then body fields from within the supplied data
     if (!empty($data['MetaData']['description'])) {
         $metaDescription = $data['MetaData']['description'];
     } elseif (!empty($data[$Model->alias]['body'])) {
         // truncate the content variable to a max of 160 characters
         // ref: https://moz.com/learn/seo/meta-description
         $metaDescription = CakeText::truncate($data['MetaData']['description'], 160, array('html' => false));
     } elseif (!empty($data[$Model->alias]['content'])) {
         // truncate the content variable to a max of 160 characters
         // ref: https://moz.com/learn/seo/meta-description
         $metaDescription = CakeText::truncate($data[$Model->alias]['content'], 160, array('html' => false));
     }
     if (!empty($metaDescription)) {
         $this->Controller->set(compact('metaDescription'));
     }
     return;
 }
開發者ID:mrstu84,項目名稱:metadata,代碼行數:41,代碼來源:MetaComponent.php

示例8: chart

 public function chart($model = 'Payment', $interval = array('from' => '0001-01-01', 'to' => false))
 {
     if ($this->request->is('post')) {
         $model = $this->request->data['Chart']['model'];
         if (!empty($this->request->data['Chart']['from']) && !empty($this->request->data['Chart']['to'])) {
             $interval = array('from' => $this->request->data['Chart']['from'], 'to' => $this->request->data['Chart']['to']);
         } elseif (!empty($this->request->data['Chart']['from']) && empty($this->request->data['Chart']['to'])) {
             $interval = array('from' => $this->request->data['Chart']['from'], 'to' => date('Y-m-d'));
         } elseif (empty($this->request->data['Chart']['from']) && !empty($this->request->data['Chart']['to'])) {
             $interval = array('from' => '0001-01-01', 'to' => $this->request->data['Chart']['to']);
         }
     }
     if (!$interval['to']) {
         $interval['to'] = date('Y-m-d');
     }
     $chartName = 'chart';
     $pieChart = $this->HighCharts->create($chartName, 'pie');
     $data = array();
     $results = $this->{$model}->find('all', array('fields' => array('sum(value) as total', 'concat(IFNULL(concat(ParentCategory.name, " - "), ""), ChildCategory.name) as name', $model . '.description'), 'conditions' => array($model . '.date BETWEEN ? and ?' => $interval, 'or' => array($model . '.user_id' => $this->Authorization->User->id(), $model . '.team_id' => $this->Authorization->User->Team->id())), 'group' => $model . '.category_id', 'order' => 'total'));
     if (!$results) {
         $data = array(array('name' => __('No data available'), 'y' => 100.0, 'description' => 'descr'));
     }
     foreach ($results as $result) {
         $data[] = array('name' => $result[0]['name'], 'y' => (double) $result[0]['total'], 'description' => $result[$model]['description']);
     }
     if ($interval['from'] == '0001-01-01') {
         $interval['from'] = __('the beginning of time');
     }
     array_unshift($interval, Inflector::pluralize($model));
     $this->HighCharts->setChartParams($chartName, array('renderTo' => 'chart', 'tooltipEnabled' => true, 'tooltipFormatter' => "function() { return '<b>' + this.point.name + '</b>: '+ parseFloat(this.percentage).toFixed(2) +' %';}", 'chartMarginTop' => 40));
     $series = $this->HighCharts->addChartSeries();
     $series->addData($data);
     $pieChart->addSeries($series);
     $this->set('title', __('<strong>%s</strong> by category statistics from <strong>%s</strong> to <strong>%s</strong>', $interval));
 }
開發者ID:riverans,項目名稱:manage-expenses,代碼行數:35,代碼來源:ChartsController.php

示例9: api_index

 public function api_index()
 {
     //$this->{$this->modelClass}->recursive = 0;
     $name = Inflector::pluralize($this->modelKey);
     $items = $this->{$this->modelClass}->find('all');
     $this->set(array($name => $items, '_serialize' => array($name)));
 }
開發者ID:PNMJ,項目名稱:nudge,代碼行數:7,代碼來源:RestController.php

示例10: generate

 public static function generate($args, $subfolder = 'default')
 {
     $subfolder = trim($subfolder, '/');
     if (!is_dir(PKGPATH . 'oil/views/' . $subfolder)) {
         throw new Exception('The subfolder for scaffolding templates doesn\'t exist or is spelled wrong: ' . $subfolder . ' ');
     }
     // Do this first as there is the largest chance of error here
     Generate::model($args, false);
     // Go through all arguments after the first and make them into field arrays
     $fields = array();
     foreach (array_slice($args, 1) as $arg) {
         // Parse the argument for each field in a pattern of name:type[constraint]
         preg_match('/([a-z0-9_]+):([a-z0-9_]+)(\\[([0-9]+)\\])?/i', $arg, $matches);
         $fields[] = array('name' => strtolower($matches[1]), 'type' => isset($matches[2]) ? $matches[2] : 'string', 'constraint' => isset($matches[4]) ? $matches[4] : null);
     }
     $data['singular'] = $singular = strtolower(array_shift($args));
     $data['model'] = $model_name = 'Model_' . Generate::class_name($singular);
     $data['plural'] = $plural = \Inflector::pluralize($singular);
     $data['fields'] = $fields;
     $filepath = APPPATH . 'classes/controller/' . trim(str_replace(array('_', '-'), DS, $plural), DS) . '.php';
     $controller = \View::factory($subfolder . '/scaffold/controller', $data);
     $controller->actions = array(array('name' => 'index', 'params' => '', 'code' => \View::factory($subfolder . '/scaffold/actions/index', $data)), array('name' => 'view', 'params' => '$id = null', 'code' => \View::factory($subfolder . '/scaffold/actions/view', $data)), array('name' => 'create', 'params' => '$id = null', 'code' => \View::factory($subfolder . '/scaffold/actions/create', $data)), array('name' => 'edit', 'params' => '$id = null', 'code' => \View::factory($subfolder . '/scaffold/actions/edit', $data)), array('name' => 'delete', 'params' => '$id = null', 'code' => \View::factory($subfolder . '/scaffold/actions/delete', $data)));
     // Write controller
     Generate::create($filepath, $controller, 'controller');
     // Create each of the views
     foreach (array('index', 'view', 'create', 'edit', '_form') as $view) {
         Generate::create(APPPATH . 'views/' . $plural . '/' . $view . '.php', \View::factory($subfolder . '/scaffold/views/' . $view, $data), 'view');
     }
     // Add the default template if it doesnt exist
     if (!file_exists($app_template = APPPATH . 'views/template.php')) {
         Generate::create($app_template, file_get_contents(PKGPATH . 'oil/views/default/template.php'), 'view');
     }
     Generate::build();
 }
開發者ID:bryanheo,項目名稱:FuelPHP-Auth-AJAX,代碼行數:34,代碼來源:scaffold.php

示例11: model

    public static function model($args, $build = true)
    {
        $singular = strtolower(array_shift($args));
        if (empty($args)) {
            throw new Exception('No fields have been provided, the model will not know how to build the table.');
        }
        $plural = \Inflector::pluralize($singular);
        $filepath = APPPATH . 'classes/model/' . trim(str_replace(array('_', '-'), DS, $singular), DS) . '.php';
        // Uppercase each part of the class name and remove hyphens
        $class_name = static::class_name($singular);
        $model = <<<MODEL
<?php

class Model_{$class_name} extends Orm\\Model { }

/* End of file {$singular}.php */
MODEL;
        // Build the model
        static::create($filepath, $model, 'model');
        if (!empty($args)) {
            array_unshift($args, 'create_' . $plural);
            static::migration($args, false);
        } else {
            throw new Exception('Not enough arguments to create this migration.');
        }
        $build and static::build();
    }
開發者ID:bryanheo,項目名稱:FuelPHP-Auth-AJAX,代碼行數:27,代碼來源:generate.php

示例12: __construct

 /**
  * @param callable $convertClassToTableCallback
  */
 public function __construct(callable $convertClassToTableCallback = null)
 {
     $defaultCallback = function ($class) {
         return Inflector::snakecase(Inflector::pluralize(Inflector::basename($class)));
     };
     $this->convertClassToTableCallback = $convertClassToTableCallback ?: $defaultCallback;
 }
開發者ID:atijust,項目名稱:mappa,代碼行數:10,代碼來源:Hydrator.php

示例13: beforeRender

 /**
  * beforeRender callback
  *
  * @return void
  * @access public
  */
 public function beforeRender()
 {
     parent::beforeRender();
     $this->Jquery->uses('jquery', 'ui', 'potato.menu');
     $this->_categoryModel = $this->params['menu']['model'];
     $this->_categoryController = Inflector::underscore(Inflector::pluralize($this->_categoryModel));
 }
開發者ID:hadzi,項目名稱:brekfarm,代碼行數:13,代碼來源:menu.php

示例14: __call

 /**
  * Check method against the flag.
  *
  * To check user id against feature `google_analytics`
  *
  * DB
  * --
  *   user_ids : 2,40,3
  *
  * Controller
  * ----------
  *   Feature::flag('google_analytics')->ip_address(40) -> TRUE
  *
  * @param  $flag       Name of method to check user can access feature flag. Signalised version of column name.
  * @param  $arguments  String or Array to match against.
  * @return Bool        Whether user can access feature
  */
 public function __call($flag, $arguments)
 {
     // If feature flag is enabled, all users can access it
     if ($this->row->get('enabled') === 'Y') {
         return TRUE;
     }
     // User didnt pass in anything to check against
     // Dont give user access to feature by default
     if (count($arguments) < 1) {
         return FALSE;
     }
     // Change name to plural version
     // Table can store multiple values per match item on flag
     $flag = \Inflector::pluralize($flag);
     $value = $arguments[0];
     $match = $this->row->get($flag);
     $match = explode(',', $match);
     if (is_array($value)) {
         foreach ($value as $item) {
             if (in_array($item, $match)) {
                 return TRUE;
             }
         }
     }
     return in_array($value, $match) ? TRUE : FALSE;
 }
開發者ID:rcrowe,項目名稱:fuel-flags,代碼行數:43,代碼來源:flag.php

示例15: disparador

 /**
  * REST api dispatcher
  */
 public function disparador()
 {
     # Load the appropriate version of the api
     $api['version'] = $this->params['version'];
     # Detect method: get/post/put/delete
     $api['method'] = strtolower($_SERVER['REQUEST_METHOD']);
     # Override the method when it is explicitly set
     if (isset($this->params->query['method'])) {
         $api['method'] = strtolower($this->params->query['method']);
         unset($this->params->query['method']);
     }
     # Define the noun
     $api['modelo'] = ucwords(Inflector::singularize($this->params['noun']));
     $api['controller'] = Inflector::pluralize($this->params['noun']);
     $this->loadModel($api['modelo']);
     # Check if we have a passed argument we should use
     if (isset($this->request->params['pass'][1])) {
         $api['id'] = $this->request->params['pass'][1];
         if ($api['id'] === 0) {
             return $this->_apiFallo('ID inválido');
         }
     }
     # Define possible parameters
     $api['parameters'] = $this->request->query;
     # If the header has signature and key, override the api['parameters']-value
     #if (isset($header['HTTP_KEY']))
     #	$api['parameters']['key'] = $header['HTTP_KEY'];
     if (isset($header['HTTP_SIGNATURE'])) {
         $api['parameters']['signature'] = $header['HTTP_SIGNATURE'];
     }
     # Check if we need to suppress the response codes
     if (isset($api['parameters']['suppress_response_code'])) {
         unset($api['parameters']['suppress_response_code']);
         $api['suppress_response_code'] = true;
     }
     # Check if we are debugging: ?debug should be set (or debug should be defined in header)
     if (isset($api['parameters']['debug']) || isset($header['HTTP_DEBUG'])) {
         unset($api['parameters']['debug']);
         $api['debug'] = true;
         $result['call'] = $api;
     }
     if (empty($this->request->params['pass'][0])) {
         return $this->_apiFallo('Metodo no encontrado');
     }
     $action = 'api_' . $this->request->params['pass'][0];
     if (!method_exists($this, $action)) {
         return $this->_apiFallo('Metodo no encontrado');
     }
     if (empty($api['parameters']['key'])) {
         $api['key'] = 'id';
     } else {
         $api['key'] = $api['parameters']['key'];
         unset($api['parameters']['key']);
         if (!ClassRegistry::init($api['controller'])->hasField($api['key'])) {
             return $this->_apiFallo('Key no encontrado');
         }
     }
     $this->setAction($action, $api);
 }
開發者ID:oxicode,項目名稱:cakephp-modo-mantenimiento,代碼行數:62,代碼來源:RestController.php


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