当前位置: 首页>>代码示例>>PHP>>正文


PHP Inflector::underscore方法代码示例

本文整理汇总了PHP中lithium\util\Inflector::underscore方法的典型用法代码示例。如果您正苦于以下问题:PHP Inflector::underscore方法的具体用法?PHP Inflector::underscore怎么用?PHP Inflector::underscore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lithium\util\Inflector的用法示例。


在下文中一共展示了Inflector::underscore方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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

示例2: _save

 /**
  * Override the save method to handle view specific params.
  *
  * @param array $params
  * @return mixed
  */
 protected function _save(array $params = array())
 {
     $params['path'] = Inflector::underscore($this->request->action);
     $params['file'] = $this->request->args(0);
     $contents = $this->_template();
     $result = String::insert($contents, $params);
     if (!empty($this->_library['path'])) {
         $path = $this->_library['path'] . "/views/{$params['path']}/{$params['file']}";
         $file = str_replace('//', '/', "{$path}.php");
         $directory = dirname($file);
         if (!is_dir($directory)) {
             if (!mkdir($directory, 0755, true)) {
                 return false;
             }
         }
         $directory = str_replace($this->_library['path'] . '/', '', $directory);
         if (file_exists($file)) {
             $prompt = "{$file} already exists. Overwrite?";
             $choices = array('y', 'n');
             if ($this->in($prompt, compact('choices')) !== 'y') {
                 return "{$params['file']} skipped.";
             }
         }
         if (is_int(file_put_contents($file, $result))) {
             return "{$params['file']}.php created in {$directory}.";
         }
     }
     return false;
 }
开发者ID:davidpersson,项目名称:FrameworkBenchmarks,代码行数:35,代码来源:View.php

示例3: relationship

 public function relationship($class, $type, $name, array $options = array())
 {
     $keys = Inflector::underscore($type == 'belongsTo' ? $name : $class::meta('name')) . '_id';
     $options += compact('name', 'type', 'keys');
     $options['from'] = $class;
     $relationship = $this->_classes['relationship'];
     return new $relationship($options);
 }
开发者ID:EHER,项目名称:monopolis,代码行数:8,代码来源:MockSource.php

示例4: 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

示例5: 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

示例6: _save

 /**
  * Override the save method to handle view specific params.
  *
  * @param array $params
  */
 protected function _save(array $params = array())
 {
     $params['path'] = Inflector::underscore($this->request->action);
     $params['file'] = $this->request->args(0);
     $contents = $this->_template();
     $result = String::insert($contents, $params);
     if (!empty($this->_library['path'])) {
         $path = $this->_library['path'] . "/views/{$params['path']}/{$params['file']}";
         $file = str_replace('//', '/', "{$path}.php");
         $directory = dirname($file);
         if (!is_dir($directory)) {
             if (!mkdir($directory, 0755, true)) {
                 return false;
             }
         }
         $directory = str_replace($this->_library['path'] . '/', '', $directory);
         if (file_put_contents($file, "<?php\n\n{$result}\n\n?>")) {
             return "{$params['file']}.php created in {$directory}.";
         }
     }
     return false;
 }
开发者ID:EHER,项目名称:chegamos,代码行数:27,代码来源:View.php

示例7: testLazyMetadataInit

 public function testLazyMetadataInit()
 {
     MockPost::config(array('schema' => new Schema(array('fields' => array('id' => array('type' => 'integer'), 'name' => array('type' => 'string'), 'label' => array('type' => 'string'))))));
     $this->assertIdentical('mock_posts', MockPost::meta('source'));
     $this->assertIdentical('name', MockPost::meta('title'));
     $this->assertEmpty(MockPost::meta('unexisting'));
     $config = array('schema' => new Schema(array('fields' => array('id' => array('type' => 'integer'), 'name' => array('type' => 'string'), 'label' => array('type' => 'string')))), 'initializers' => array('source' => function ($self) {
         return Inflector::tableize($self::meta('name'));
     }, 'name' => function ($self) {
         return Inflector::singularize('CoolPosts');
     }, 'title' => function ($self) {
         static $i = 1;
         return 'label' . $i++;
     }));
     MockPost::reset();
     MockPost::config($config);
     $this->assertIdentical('cool_posts', MockPost::meta('source'));
     $this->assertIdentical('label1', MockPost::meta('title'));
     $this->assertNotIdentical('label2', MockPost::meta('title'));
     $this->assertIdentical('label1', MockPost::meta('title'));
     $meta = MockPost::meta();
     $this->assertIdentical('label1', $meta['title']);
     $this->assertIdentical('CoolPost', MockPost::meta('name'));
     MockPost::reset();
     unset($config['initializers']['title']);
     $config['initializers']['source'] = function ($self) {
         return Inflector::underscore($self::meta('name'));
     };
     MockPost::config($config);
     $this->assertIdentical('cool_post', MockPost::meta('source'));
     $this->assertIdentical('name', MockPost::meta('title'));
     $this->assertIdentical('CoolPost', MockPost::meta('name'));
     MockPost::reset();
     MockPost::config($config);
     $expected = array('class' => 'lithium\\tests\\mocks\\data\\MockPost', 'connection' => false, 'key' => 'id', 'name' => 'CoolPost', 'title' => 'name', 'source' => 'cool_post');
     $this->assertEqual($expected, MockPost::meta());
 }
开发者ID:rapzo,项目名称:lithium,代码行数:37,代码来源:ModelTest.php

示例8: __callStatic

 /**
  * Allows the use of syntactic-sugar like `Mailer::deliverTestWithLocal()`
  * instead of `Mailer::deliver('test', array('delivery' => 'local'))`.
  *
  * @see li3_mailer\action\Mailer::deliver()
  * @link http://php.net/manual/en/language.oop5.overloading.php PHP
  *       Manual: Overloading
  * @throws BadMethodCallException On unhandled call, will
  *         throw an exception.
  * @param string $method Method name caught by `__callStatic()`.
  * @param array $params Arguments given to the above `$method` call.
  * @return mixed Results of dispatched `Mailer::deliver()` call.
  */
 public static function __callStatic($method, $params)
 {
     $pattern = '/^deliver(?P<message>\\w+)With(?P<delivery>\\w+)$/';
     $found = preg_match($pattern, $method, $args);
     if (!$found) {
         preg_match('/^deliver(?P<message>\\w+)$/', $method, $args);
     }
     if (!$args) {
         $class = get_called_class();
         $class = substr($class, strrpos($class, "\\") + 1);
         $error = "Method `{$method}` not defined or handled " . "in class `{$class}`.";
         throw new BadMethodCallException($error);
     }
     $message = Inflector::underscore($args['message']);
     if (isset($params[0]) && is_array($params[0])) {
         $params = $params[0];
     }
     if (isset($args['delivery'])) {
         $params['delivery'] = Inflector::underscore($args['delivery']);
     }
     return static::deliver($message, $params);
 }
开发者ID:globus40000,项目名称:li3_mailer,代码行数:35,代码来源:Mailer.php

示例9: export

 public static function export(array $resources, array $options = array())
 {
     $defaults = array('prefix' => null);
     $options += $defaults;
     $classes = static::$_classes;
     $remap = array();
     $names = array();
     foreach ($resources as $resource => $config) {
         if (is_int($resource)) {
             $resource = $config;
             $config = array();
         }
         $config += array('class' => Libraries::locate('resources', $resource), 'path' => str_replace('_', '-', Inflector::underscore($resource)), 'key' => 'id:(?:[0-9a-f]{24})|(?:\\d+)');
         $config += static::_instance($config['class'])->config();
         $first = substr($config['path'], 0, 1);
         $remap[$resource] = $config;
         $name = "[{$first}" . ucfirst($first) . "]" . substr($config['path'], 1);
         static::$_exports[$resource] = $config;
         static::$_bindings += array($config['binding'] => $resource);
         $template = join('/', array($options['prefix'], "{:controller:{$name}}", "{:action:[^0-9]+}", "{:{$config['key']}}"));
         $classes['router']::connect($template, array('action' => null));
     }
 }
开发者ID:nateabele,项目名称:li3_resources,代码行数:23,代码来源:Resources.php

示例10: __call

 public function __call($method, $args)
 {
     $params = empty($args) ? array() : $args[0];
     $method = Inflector::underscore($method);
     return $this->_context->view()->render(array('element' => "{$method}_partial"), $params);
 }
开发者ID:aniston,项目名称:Platypus,代码行数:6,代码来源:Partial.php

示例11: parseMatch

 /**
  * parseMatch Matches the current request parameters against a set of given parameters.
  * Can match against a shorthand string (Controller::action) or a full array. If a parameter
  * is provided then it must have an equivilent in the Request objects parmeters in order
  * to validate. * Is also acceptable to match a parameter without a specific value.
  *
  * @param mixed $match A set of parameters to validate the request against.
  * @param mixed $params The Lithium `Request` object, or an array with at least
  *        'request', and 'params'
  * @access public
  * @return boolean True if a match is found.
  */
 public static function parseMatch($match, $params)
 {
     if (empty($match)) {
         return false;
     }
     if (is_array($match)) {
         $_params = $params;
         if (!static::_parseClosures($match, $params['request'], $_params)) {
             return false;
         }
     } elseif (is_callable($match)) {
         return (bool) $match($params['request'], $params);
     }
     $matchParams = array();
     foreach ((array) $match as $key => $param) {
         if (is_string($param)) {
             if (preg_match('/^([A-Za-z0-9_\\*\\\\]+)::([A-Za-z0-9_\\*]+)$/', $param, $regexMatches)) {
                 $matchParams += array('controller' => $regexMatches[1], 'action' => $regexMatches[2]);
                 continue;
             }
         }
         $matchParams[$key] = $param;
     }
     foreach ($matchParams as $type => $value) {
         if ($value === '*') {
             continue;
         }
         if ($type === 'controller') {
             $value = Inflector::underscore($value);
         }
         $exists_in_request = array_key_exists($type, $params['params']);
         if (!$exists_in_request || $value !== Inflector::underscore($params['params'][$type])) {
             return false;
         }
     }
     return true;
 }
开发者ID:tmaiaroto,项目名称:li3_access,代码行数:49,代码来源:AuthRbac.php

示例12: 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

示例13: relationFieldName

 /**
  * Returns the field name of a relation name (underscore).
  *
  * @param string The type of the relation.
  * @param string The name of the relation.
  * @return string
  */
 public function relationFieldName($type, $name)
 {
     $fieldName = Inflector::underscore($name);
     if (preg_match('/Many$/', $type)) {
         $fieldName = Inflector::pluralize($fieldName);
     } else {
         $fieldName = Inflector::singularize($fieldName);
     }
     return $fieldName;
 }
开发者ID:unionofrad,项目名称:lithium,代码行数:17,代码来源:Source.php

示例14: _parseString

 /**
  * Helper function for taking a path string and parsing it into a controller and action array.
  *
  * @param string $path Path string to parse.
  * @param boolean $context
  * @return array
  */
 protected static function _parseString($path, $context)
 {
     if (!preg_match('/^[A-Za-z0-9_]+::[A-Za-z0-9_]+$/', $path)) {
         $base = $context ? $context->env('base') : '';
         $path = trim($path, '/');
         return $context !== false ? "{$base}/{$path}" : null;
     }
     list($controller, $action) = explode('::', $path, 2);
     $controller = Inflector::underscore($controller);
     return compact('controller', 'action');
 }
开发者ID:EHER,项目名称:monopolis,代码行数:18,代码来源:Router.php

示例15: __callStatic

 /**
  * Allows the use of syntactic-sugar like `Model::all()` instead of `Model::find('all')`.
  *
  * @see lithium\data\Model::find()
  * @see lithium\data\Model::$_meta
  * @link http://php.net/manual/en/language.oop5.overloading.php PHP Manual: Overloading
  *
  * @throws BadMethodCallException On unhandled call, will throw an exception.
  * @param string $method Method name caught by `__callStatic()`.
  * @param array $params Arguments given to the above `$method` call.
  * @return mixed Results of dispatched `Model::find()` call.
  */
 public static function __callStatic($method, $params)
 {
     $self = static::_object();
     $isFinder = isset($self->_finders[$method]);
     if ($isFinder && count($params) === 2 && is_array($params[1])) {
         $params = array($params[1] + array($method => $params[0]));
     }
     if ($method == 'all' || $isFinder) {
         if ($params && !is_array($params[0])) {
             $params[0] = array('conditions' => static::key($params[0]));
         }
         return $self::find($method, $params ? $params[0] : array());
     }
     preg_match('/^findBy(?P<field>\\w+)$|^find(?P<type>\\w+)By(?P<fields>\\w+)$/', $method, $args);
     if (!$args) {
         $message = "Method `%s` not defined or handled in class `%s`.";
         throw new BadMethodCallException(sprintf($message, $method, get_class($self)));
     }
     $field = Inflector::underscore($args['field'] ? $args['field'] : $args['fields']);
     $type = isset($args['type']) ? $args['type'] : 'first';
     $type[0] = strtolower($type[0]);
     $conditions = array($field => array_shift($params));
     $params = isset($params[0]) && count($params) == 1 ? $params[0] : $params;
     return $self::find($type, compact('conditions') + $params);
 }
开发者ID:newmight2015,项目名称:Blockchain-2,代码行数:37,代码来源:Model.php


注:本文中的lithium\util\Inflector::underscore方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。