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


PHP util\Inflector类代码示例

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


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

示例1: _init

 /**
  * Initialization of the cookie adapter.
  *
  * @return void
  */
 protected function _init()
 {
     parent::_init();
     if (!$this->_config['name']) {
         $this->_config['name'] = Inflector::slug(basename(LITHIUM_APP_PATH)) . 'cookie';
     }
 }
开发者ID:EHER,项目名称:monopolis,代码行数:12,代码来源:Cookie.php

示例2: file

 /**
  * Get content of file, parse it with lessc and return formatted css
  *
  * @todo allow for css-file name only, and search it in all avail. webroots
  * @param string $file full path to file
  * @param array $options Additional options to control flow of method
  *                       - header - controls, whether to prepend a header
  *                       - cache - controls, whether to cache the result
  *                       - cachePath - Where to cache files, defaults to
  *                                     resources/tmp/cache
  * @return string|boolean generated css, false in case of error
  */
 public static function file($file, array $options = array())
 {
     $defaults = array('header' => true, 'cache' => true, 'cachePath' => Libraries::get(true, 'resources') . '/tmp/cache', 'cacheKey' => Inflector::slug(str_replace(array(LITHIUM_APP_PATH, '.less'), array('', '.css'), $file)));
     $options += $defaults;
     $css_file = $options['cachePath'] . '/' . $options['cacheKey'];
     if (file_exists($css_file) && filemtime($css_file) >= filemtime($file)) {
         return file_get_contents($css_file);
     }
     if (!file_exists($file)) {
         return false;
     }
     try {
         $less = static::_getLess($file);
         $output = $less->parse();
     } catch (Exception $e) {
         $output = "/* less compiler exception: {$e->getMessage()} */";
     }
     if ($options['header']) {
         $output = static::_prependHeader($output);
     }
     if ($options['cache']) {
         file_put_contents($css_file, $output);
     }
     return $output;
 }
开发者ID:raisinbread,项目名称:li3_less,代码行数:37,代码来源:Less.php

示例3: render

 public function render($data, $contents = array(), array $options = array())
 {
     $this->_mustache();
     $defaults = array('id' => '', 'class' => '', 'hash' => true, 'right' => '');
     $options += $defaults;
     $tabs = $panes = array();
     foreach ($data as $slug => $tab) {
         if (!is_array($tab)) {
             $tab = array('name' => $tab);
         }
         $slug = is_numeric($slug) ? strtolower(Inflector::slug($tab['name'])) : $slug;
         $tab = $this->_tab($tab, array('id' => $slug));
         if (empty($tab['url'])) {
             $tab['url'] = $options['hash'] ? sprintf('#%s', $slug) : $slug;
         } else {
             $slug = str_replace('#', '', $tab['url']);
         }
         if (isset($tab['content'])) {
             $panes[] = $this->_pane($tab['content'], $tab);
             unset($tab['content']);
         }
         $tabs[] = $tab;
     }
     $params = $options += compact('tabs', 'panes');
     return $this->mustache->render('tabs', $params, array('library' => 'li3_bootstrap'));
 }
开发者ID:bruensicke,项目名称:li3_bootstrap,代码行数:26,代码来源:Tab.php

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

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

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

示例7: add

 public static function add($name, array $config = array())
 {
     $session = static::$_classes['session'];
     $name = strtolower(Inflector::slug($name));
     $defaults = array('adapter' => '', 'name' => $name);
     return static::$_configurations[$name] = $config + $defaults;
 }
开发者ID:joseym,项目名称:li3_analytics,代码行数:7,代码来源:Trackers.php

示例8: _source

 /**
  * Get DB table name for the migration
  * Table name is pluralized (tableized) class name by default
  *
  * @param $request
  * @return string
  */
 protected function _source($request)
 {
     if ($request->source) {
         return $request->source;
     }
     return Inflector::tableize($request->action);
 }
开发者ID:djordje,项目名称:li3_migrations,代码行数:14,代码来源:Migration.php

示例9: library

 public static function library($name, array $options = array())
 {
     $defaults = array('docs' => 'config/docs/index.json', 'language' => 'en');
     $options += $defaults;
     if (!($config = Libraries::get($name))) {
         return array();
     }
     if (file_exists($file = "{$config['path']}/{$options['docs']}")) {
         $config += (array) json_decode(file_get_contents($file), true);
     }
     if (isset($config['languages']) && in_array($options['language'], $config['languages'])) {
         $config += $config[$options['language']];
         foreach ($config['languages'] as $language) {
             unset($config[$language]);
         }
     }
     $docConfig = Libraries::get('li3_docs');
     $category = 'libraries';
     if (isset($docConfig['categories']) && is_array($docConfig['categories'])) {
         if (isset($config['category'])) {
             unset($config['category']);
         }
         foreach ($docConfig['categories'] as $key => $include) {
             if ($include === true || !in_array($name, array_values((array) $include))) {
                 continue;
             }
             $category = $key;
         }
     }
     return $config + array('title' => Inflector::humanize($name), 'category' => $category);
 }
开发者ID:rapzo,项目名称:li3_docs,代码行数:31,代码来源:Extractor.php

示例10: testTransliteration

	public function testTransliteration() {
		$data = array(
			'transliteration' => array(
				'\$' => 'dollar',
				'&' => 'and'
			)
		);
		Catalog::write('runtime', 'inflection', 'en', $data);

		Inflector::rules(
			'transliteration', Catalog::read('runtime', 'inflection.transliteration', 'en')
		);

		$result = Inflector::slug('this & that');
		$expected = 'this-and-that';
		$this->assertEqual($expected, $result);

		$data = array(
			'transliteration' => array(
				't' => 'd',
				'&' => 'und'
			)
		);
		Catalog::write('runtime', 'inflection', 'de', $data);

		Inflector::rules(
			'transliteration', Catalog::read('runtime', 'inflection.transliteration', 'de')
		);

		$result = Inflector::slug('this & that');
		$expected = 'dhis-und-dhad';
		$this->assertEqual($expected, $result);
	}
开发者ID:niel,项目名称:lithium,代码行数:33,代码来源:CatalogInflectorTest.php

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

示例12: path

 public function path($entity)
 {
     $resource = Inflector::tableize(basename(str_replace('\\', '/', $entity->model())));
     if ($entity->exists()) {
         return '/' . $resource . '/' . $entity->_id;
     } else {
         return '/' . $resource;
     }
 }
开发者ID:johnny13,项目名称:li3_rest,代码行数:9,代码来源:Resource.php

示例13: _class

 /**
  * Get the class name for the mock.
  *
  * @param string $request
  * @return string
  */
 protected function _class($request)
 {
     $name = $request->action;
     $type = $request->command;
     if ($command = $this->_instance($type)) {
         $request->params['action'] = $name;
         $name = $command->invokeMethod('_class', array($request));
     }
     return Inflector::classify("Mock{$name}");
 }
开发者ID:EHER,项目名称:chegamos,代码行数:16,代码来源:Mock.php

示例14: __construct

 /**
  * Growl logger constructor. Accepts an array of settings which are merged with the default
  * settings and used to create the connection and handle notifications.
  *
  * @see lithium\analysis\Logger::write()
  * @param array $config The settings to configure the logger. Available settings are as follows:
  *              - `'name`' _string_: The name of the application as it should appear in Growl's
  *                system settings. Defaults to the directory name containing your application.
  *              - `'host'` _string_: The Growl host with which to communicate, usually your
  *                local machine. Use this setting to send notifications to another machine on
  *                the network. Defaults to `'127.0.0.1'`.
  *              - `'port'` _integer_: Port of the host machine. Defaults to the standard Growl
  *                port, `9887`.
  *              - `'password'` _string_: Only required if the host machine requires a password.
  *                If notification or registration fails, check this against the host machine's
  *                Growl settings.
  *              - '`protocol'` _string_: Protocol to use when opening socket communication to
  *                Growl. Defaults to `'udp'`.
  *              - `'title'` _string_: The default title to display when showing Growl messages.
  *                The default value is the same as `'name'`, but can be changed on a per-message
  *                basis by specifying a `'title'` key in the `$options` parameter of
  *                `Logger::write()`.
  *              - `'notification'` _array_: A list of message types you wish to register with
  *                Growl to be able to send. Defaults to `array('Errors', 'Messages')`.
  * @return void
  */
 public function __construct(array $config = array())
 {
     $name = basename(LITHIUM_APP_PATH);
     $defaults = array('name' => $name, 'host' => '127.0.0.1', 'port' => 9887, 'password' => null, 'protocol' => 'udp', 'title' => Inflector::humanize($name), 'notifications' => array('Errors', 'Messages'), 'connection' => function ($host, $port) {
         if ($conn = fsockopen($host, $port, $message, $code)) {
             return $conn;
         }
         throw new NetworkException("Growl connection failed: ({$code}) {$message}");
     });
     parent::__construct($config + $defaults);
 }
开发者ID:EHER,项目名称:chegamos,代码行数:37,代码来源:Growl.php

示例15: __init

 public static function __init($options = array())
 {
     $self = static::_instance();
     if (!isset($self->_meta['source'])) {
         $model = get_class($self);
         $tmp = explode('\\', $model);
         $modelName = end($tmp);
         $self->_meta['source'] = \lithium\util\Inflector::tableize($modelName);
     }
     parent::__init($options);
 }
开发者ID:alkemann,项目名称:AL13,代码行数:11,代码来源:TestModel.php


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