本文整理汇总了PHP中lithium\util\Inflector::humanize方法的典型用法代码示例。如果您正苦于以下问题:PHP Inflector::humanize方法的具体用法?PHP Inflector::humanize怎么用?PHP Inflector::humanize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lithium\util\Inflector
的用法示例。
在下文中一共展示了Inflector::humanize方法的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);
}
示例2: 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);
}
示例3: __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);
}
示例4: init
/**
* must be called with an array with the following fields to create an asset:
*
* Array (
* 'name' => 'foobar' // Name of file to be humanized for records name
* 'type' => 'jpg' // file-extension, will be adapted to correct asset type
* 'tmp_name' => '/dir/some-file.jpg' // FQDN of file, to be retrieved
* 'size' => 44 // optional, size in bytes of file
* ),
*
* @param array $file array as described above
* @param array $options additional options
* - `type`: overwrite type of file, if you want to disable automatic detection
* - `delete`: triggers deletion of retrieved temporary file, defaults to true
* - `keep`: triggers keeping temporary files in case of errors, defaults to true
* @return array parsed content of Assets bytes
*/
public static function init($file, array $options = array())
{
$defaults = array('type' => 'default', 'delete' => true, 'keep' => true);
$options += $defaults;
// fetch file, if remote
// determine size of file on its own
// determine md5 of file
// find by md5, first
$md5 = md5_file($file['tmp_name']);
$asset = static::findByMd5($md5, array('fields' => '_id'));
if ($asset) {
if ($options['delete']) {
unlink($file['tmp_name']);
}
$error = 'Asset already present';
return compact('error', 'asset');
}
$mime = Mime::type($file['type']);
if (is_array($mime)) {
$mime = reset($mime);
}
$data = array('name' => Inflector::humanize($file['name']), 'filename' => sprintf('%s.%s', $file['name'], $file['type']), 'slug' => strtolower(sprintf('%s.%s', $file['name'], $file['type'])), 'md5' => $md5, 'extension' => $file['type'], 'type' => static::mimetype($mime), 'mime' => $mime, 'size' => $file['size'], 'file' => file_get_contents($file['tmp_name']));
try {
$asset = static::create($data);
if ($asset->validates()) {
$file['success'] = (bool) $asset->save();
$file['asset'] = $asset;
} else {
$file['errors'] = $asset->errors();
}
} catch (Exception $e) {
// return array('error' => 'asset could not be saved.');
$file = array('error' => $e->getMessage());
}
if (!empty($file['success']) && empty($file['error']) && !$options['keep']) {
unlink($file['tmp_name']);
}
return $file;
}
示例5: testStorageMechanism
/**
* Tests the storage mechanism for `$_underscored`, `$_camelized`,
* `$_humanized` and `$_pluralized`.
*
* @return void
*/
public function testStorageMechanism()
{
Inflector::reset();
$expected = array('TestField' => 'test_field');
$this->assertFalse($this->getProtectedValue('$_underscored'));
$this->assertEqual(Inflector::underscore('TestField'), 'test_field');
$this->assertEqual($expected, $this->getProtectedValue('$_underscored'));
$this->assertEqual(Inflector::underscore('TestField'), 'test_field');
$expected = array('test_field' => 'TestField');
$this->assertFalse($this->getProtectedValue('$_camelized'));
$this->assertEqual(Inflector::camelize('test_field', true), 'TestField');
$this->assertEqual($expected, $this->getProtectedValue('$_camelized'));
$this->assertEqual(Inflector::camelize('test_field', true), 'TestField');
$expected = array('test_field:_' => 'Test Field');
$this->assertFalse($this->getProtectedValue('$_humanized'));
$this->assertEqual(Inflector::humanize('test_field'), 'Test Field');
$this->assertEqual($expected, $this->getProtectedValue('$_humanized'));
$this->assertEqual(Inflector::humanize('test_field'), 'Test Field');
$expected = array('field' => 'fields');
$this->assertFalse($this->getProtectedValue('$_pluralized'));
$this->assertEqual(Inflector::pluralize('field'), 'fields');
$this->assertEqual($expected, $this->getProtectedValue('$_pluralized'));
$this->assertEqual(Inflector::pluralize('field'), 'fields');
}
示例6: _item
/**
* creates all necessary array keys for rendering a menu/list item
*
* @param array $navitem all available data for a single navigation item
* @return array navitem filled with all needed keys
*/
private function _item($navitem)
{
$context = $this->_context;
$navitem['url'] = empty($navitem['url']) && !empty($navitem['name']) ? '/' . Inflector::tableize($navitem['name']) : $navitem['url'];
$navitem['name'] = empty($navitem['name']) && !empty($navitem['url']) ? Inflector::humanize(basename($navitem['url'])) : $navitem['name'];
$navitem['active'] = (bool) stristr($navitem['url'], $context->scaffold->slug);
$navitem['link'] = $context->url($navitem['url']);
$navitem['badge'] = empty($navitem['badge']) ? null : $this->_badge($navitem['badge']);
return $navitem;
}
示例7: label
/**
* Generates an HTML `<label></label>` object.
*
* @param string $id The DOM ID of the field that the label is for.
* @param string $title The content inside the `<label></label>` object.
* @param array $options Besides HTML attributes, this parameter allows one additional flag:
* - `'escape'` _boolean_: Defaults to `true`. Indicates whether the title of the
* label should be escaped. If `false`, it will be treated as raw HTML.
* @return string Returns a `<label>` tag for the name and with HTML attributes.
*/
public function label($id, $title = null, array $options = array())
{
$defaults = array('escape' => true);
if (is_array($title)) {
list($title, $options) = each($title);
}
$title = $title ?: Inflector::humanize(str_replace('.', '_', $id));
list($name, $options, $template) = $this->_defaults(__FUNCTION__, $id, $options);
list($scope, $options) = $this->_options($defaults, $options);
if (strpos($id, '.')) {
$generator = $this->_config['attributes']['id'];
$id = $generator(__METHOD__, $id, $options);
}
return $this->_render(__METHOD__, $template, compact('id', 'title', 'options'), $scope);
}
示例8: sort_header
/**
* Create a html link for sorting by the field, used with pagination
*
* @param string $field
* @param string $title
* @return string
*/
public function sort_header($field, $title = null)
{
if (!$title) {
$title = \lithium\util\Inflector::humanize($field);
}
$url = $this->_url();
if (!isset($url['?']['dir'])) {
$url['?']['dir'] = 'ASC';
}
if (isset($url['?']['sort']) && $url['?']['sort'] == $field) {
$url['?']['dir'] = $url['?']['dir'] == 'ASC' ? 'DESC' : 'ASC';
}
$url['?']['sort'] = $field;
return $this->tag('link', array('title' => $title, 'url' => $url));
}
示例9: array
}
?>
</ul>
</nav>
<?php
}
?>
</div>
<?php
foreach ($categories as $cat) {
?>
<div class="section">
<section>
<h3><?php
echo $this->title($t(Inflector::humanize($cat), array('scope' => 'li3_docs')));
?>
</h3>
<?php
foreach ($libraries as $lib => $config) {
?>
<?php
if ($config['category'] != $cat) {
continue;
}
?>
<h4 class="title">
<?php
echo $this->html->link($config['title'], compact('lib') + $defaults);
?>
示例10: __construct
/**
* Constructor. 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(Libraries::get(true, 'path'));
$defaults = compact('name') + array('host' => '127.0.0.1', 'port' => 9887, 'password' => null, 'protocol' => 'udp', 'title' => Inflector::humanize($name), 'notifications' => array('Errors', 'Messages'), 'registered' => false);
parent::__construct($config + $defaults);
}
示例11: foreach
?>
<div class="controls hide" id="stepTwoQuestions-<?php
echo $name;
?>
">
<?php
foreach ($matrix['questions'] as $category => $questions) {
?>
<?php
if (count($questions) <= 0) {
continue;
}
?>
<div style="margin-bottom: 16px">
<h4><?php
echo \lithium\util\Inflector::humanize($category);
?>
</h4>
<div class="questionGroup">
<?php
foreach ($questions as $key => $question) {
?>
<label class="radio">
<input type="radio" name="grank-<?php
echo $name;
?>
-<?php
echo $category;
?>
" data-category="<?php
echo $category;
示例12: isset
<div class="control-group user-multi-select" data-field-name="<?php
echo $fieldname;
?>
">
<label class="control-label"><?php
echo isset($label) ? $label : \lithium\util\Inflector::humanize($fieldname);
?>
:</label>
<div class="controls">
<div id="existingCaptains" class="user-list">
<?php
foreach ($user_list as $u) {
?>
<div><input type="hidden" name="<?php
echo $fieldname;
?>
[]" value="<?php
echo $u->_id;
?>
"> <span class="span3 uneditable-input"><?php
echo $u->firstname;
?>
<?php
echo $u->lastname;
?>
</span> <a href="#remove" class="remove"><i class="icon-remove"></i></a></div>
<?php
}
?>
</div>
示例13: label
public function label($name, $title = null, $options = array())
{
$title = $title ?: Inflector::humanize($name);
list($name, $options, $template) = $this->_defaults(__FUNCTION__, $name, $options);
return $this->_render(__METHOD__, $template, compact('name', 'title', 'options'));
}
示例14: label
/**
* Generates an HTML `<label></label>` object.
*
* @param string $name The DOM ID of the field that the label is for.
* @param string $title The content inside the `<label></label>` object.
* @param array $options Besides HTML attributes, this parameter allows one additional flag:
* - `'escape'` _boolean_: Defaults to `true`. Indicates whether the title of the
* label should be escaped. If `false`, it will be treated as raw HTML.
* @return string Returns a `<label>` tag for the name and with HTML attributes.
*/
public function label($name, $title = null, array $options = array())
{
$defaults = array('escape' => true);
if (is_array($title)) {
list($title, $options) = each($title);
}
$title = $title ?: Inflector::humanize($name);
list($name, $options, $template) = $this->_defaults(__FUNCTION__, $name, $options);
list($scope, $options) = $this->_options($defaults, $options);
return $this->_render(__METHOD__, $template, compact('name', 'title', 'options'), $scope);
}
示例15: _scaffold
/**
* Generates different variations of the configured $this->model property name
*
* If no model is configured (i.e. `null`) - it automatically detects the corresponding
* model for this Controller via Inflection and `Libraries::locate()`.
*
* @see lithium\core\Libraries::locate()
* @param string $field defines, what variation of the default you want to have
* available are 'class', 'model', 'singular', 'plural' and 'table' and 'human'.
* if omitted, returns array containing all of them.
* @return array|string
**/
protected function _scaffold($field = null)
{
if (is_null($this->model)) {
$this->model = (string) Libraries::locate('models', $this->request->controller);
}
if (is_null($this->scaffold)) {
$class = basename(str_replace('\\', '/', $this->model));
$base = !empty($this->library) ? array('controller' => $this->controller, 'library' => $this->library) : array('controller' => $this->controller);
$this->scaffold = array('base' => Router::match($base, $this->request), 'controller' => strtolower($this->controller), 'library' => $this->library, 'class' => $class, 'model' => $this->model, 'slug' => Inflector::underscore($class), 'singular' => Inflector::singularize($class), 'plural' => Inflector::pluralize($class), 'table' => Inflector::tableize($class), 'human' => Inflector::humanize($class));
}
if (!is_null($field)) {
return isset($this->scaffold[$field]) ? $this->scaffold[$field] : false;
}
Environment::set(true, array('scaffold' => $this->scaffold));
return $this->scaffold;
}