本文整理汇总了PHP中lithium\util\Inflector::slug方法的典型用法代码示例。如果您正苦于以下问题:PHP Inflector::slug方法的具体用法?PHP Inflector::slug怎么用?PHP Inflector::slug使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lithium\util\Inflector
的用法示例。
在下文中一共展示了Inflector::slug方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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'));
}
示例3: 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);
}
示例4: 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;
}
示例5: _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';
}
}
示例6: run
/**
* Auto run the help command
*
* @param string $name COMMAND to get help
* @return void
*/
public function run($name = null)
{
if (!$name) {
$this->out('COMMANDS', 'heading1', 2);
$commands = Libraries::locate('command', null, array('recursive' => false));
foreach ($commands as $command) {
$info = Inspector::info($command);
$name = strtolower(Inflector::slug($info['shortName']));
$this->out($this->_pad($name), 'heading2');
$this->out($this->_pad($info['description']), 2);
}
$message = 'See `{:command}li3 help COMMAND{:end}`';
$message .= ' for more information on a specific command.';
$this->out($message, 2);
return true;
}
$name = Inflector::classify($name);
if (!($class = Libraries::locate('command', $name))) {
$this->error("{$name} not found");
return false;
}
if (strpos($name, '\\') !== false) {
$name = join('', array_slice(explode("\\", $name), -1));
}
$name = strtolower(Inflector::slug($name));
$methods = $this->_methods($class);
$properties = $this->_properties($class);
$this->out('USAGE', 'heading1');
$this->out($this->_pad(sprintf("{:command}li3 %s{:end}{:option}%s{:end} [ARGS]", $name ?: 'COMMAND', array_reduce($properties, function ($a, $b) {
return "{$a} {$b['usage']}";
}))));
$info = Inspector::info($class);
if (!empty($info['description'])) {
$this->nl();
$this->out('DESCRIPTION');
$this->out($this->_pad(strtok($info['description'], "\n"), 1));
$this->nl();
}
if ($properties || $methods) {
$this->out('OPTIONS', 'heading2');
}
if ($properties) {
$this->_render($properties);
}
if ($methods) {
$this->_render($methods);
}
return true;
}
示例7: __init
/**
* Initialize location
* Apply method filters
*/
public static function __init()
{
static::config();
static::applyFilter('mkdir', function ($self, $params, $chain) {
$name = explode('/', $params['name']);
foreach ($name as $i => $s) {
$name[$i] = Inflector::slug($s);
}
$params['name'] = join('/', $name);
return $chain->next($self, $params, $chain);
});
static::applyFilter('upload', function ($self, $params, $chain) {
$file = explode('.', $params['file']['name']);
$end = count($file) - 1;
$extension = $file[$end];
unset($file[$end]);
$name = join($file);
$params['file']['name'] = Inflector::slug($name) . ".{$extension}";
return $chain->next($self, $params, $chain);
});
static::applyFilter('copy', function ($self, $params, $chain) {
$source = trim($params['source'], '/');
$dest = trim($params['dest'], '/');
if (substr($dest, 0, strlen($source)) === $source) {
return false;
}
return $chain->next($self, $params, $chain);
});
static::applyFilter('move', function ($self, $params, $chain) {
$source = trim($params['oldname'], '/');
$dest = trim($params['newname'], '/');
if (substr($dest, 0, strlen($source)) === $source) {
return false;
}
return $chain->next($self, $params, $chain);
});
}
示例8: testDefaultCookieName
public function testDefaultCookieName()
{
$cookie = new Cookie();
$expected = Inflector::slug(basename(Libraries::get(true, 'path'))) . 'cookie';
$this->assertEqual($expected, $cookie->key());
}
示例9: 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;
}
示例10: __construct
public function __construct(array $config = array())
{
$self =& $this;
$defaults = array('base' => array(), 'text' => array(), 'textarea' => array(), 'select' => array('multiple' => false), 'attributes' => array('id' => function ($method, $name, $options) use(&$self) {
if (in_array($method, array('create', 'end', 'label', 'error'))) {
return;
}
if (!$name || $method == 'hidden' && $name == '_method') {
return;
}
$id = Inflector::camelize(Inflector::slug($name));
$model = ($binding = $self->binding()) ? $binding->model() : null;
return $model ? basename(str_replace('\\', '/', $model)) . $id : $id;
}, 'name' => function ($method, $name, $options) {
if (!strpos($name, '.')) {
return $name;
}
$name = explode('.', $name);
$first = array_shift($name);
return $first . '[' . join('][', $name) . ']';
}));
parent::__construct(Set::merge($defaults, $config));
}
示例11: foreach
<?php
$nav = $panels = '';
foreach ($tabs as $tab => $fields) {
$slug = strtolower(\lithium\util\Inflector::slug($tab));
$active = $nav ? '' : ' active';
$nav .= sprintf('<li class="%s"><a href="#%s" data-toggle="tab">%s</a></li>', $active, $slug, $tab);
$panels .= sprintf('<div class="tab-pane%s" id="%s">', $active, $slug);
$panels .= $this->scaffold->render('form.fields', compact('fields', 'skip', 'readonly'));
$panels .= '</div>';
}
?>
<div class="row">
<div class="col-md-4">
<h3><?php
echo $this->scaffold->human;
?>
meta</h3>
<div class="well">
<div class="form-group">
<?php
echo $this->scaffold->render('form.meta', compact('skip', 'readonly'));
?>
</div>
</div>
</div>
<div class="col-md-8">
<h3><?php
echo $this->scaffold->human;
示例12: testDefaultCookieName
public function testDefaultCookieName()
{
$cookie = new Cookie();
$expected = Inflector::slug(basename(LITHIUM_APP_PATH)) . 'cookie';
$this->assertEqual($expected, $cookie->key());
}
示例13: _renderCommands
/**
* Output the formatted available commands.
*
* @return void
*/
protected function _renderCommands()
{
$commands = Libraries::locate('command', null, array('recursive' => false));
foreach ($commands as $key => $command) {
$library = strtok($command, '\\');
if (!$key || strtok($commands[$key - 1], '\\') != $library) {
$this->out("{:heading}COMMANDS{:end} {:blue}via {$library}{:end}");
}
$info = Inspector::info($command);
$name = strtolower(Inflector::slug($info['shortName']));
$this->out($this->_pad($name), 'heading');
$this->out($this->_pad($info['description']), 2);
}
$message = 'See `{:command}li3 help COMMAND{:end}`';
$message .= ' for more information on a specific command.';
$this->out($message, 2);
}
示例14: getPlaceUrl
public function getPlaceUrl()
{
return ROOT_URL . \strtolower(Inflector::slug($this->getAddress()->getCity()->getState())) . '/' . \strtolower(Inflector::slug($this->getAddress()->getCity()->getName())) . '/' . \strtolower(Inflector::slug($this->getCategory())) . '/' . \strtolower(Inflector::slug($this->getName())) . '/' . $this->getId() . '.html';
}
示例15: __construct
public function __construct(array $config = array())
{
$self =& $this;
$defaults = array('base' => array(), 'text' => array(), 'textarea' => array(), 'select' => array('multiple' => false), 'attributes' => array('id' => function ($method, $name, $options) use(&$self) {
if (in_array($method, array('create', 'end', 'label', 'error'))) {
return;
}
if (!$name || $method === 'hidden' && $name === '_method') {
return;
}
$info = $self->binding($name);
$model = $info->class;
$id = Inflector::camelize(Inflector::slug($info->name));
return $model ? basename(str_replace('\\', '/', $model)) . $id : $id;
}, 'name' => function ($method, $name, $options) {
if (!strpos($name, '.')) {
return $name;
}
$name = explode('.', $name);
$first = array_shift($name);
return $first . '[' . join('][', $name) . ']';
}), 'binding' => function ($object, $name = null) {
$result = compact('name') + array('data' => null, 'errors' => null, 'class' => null);
if (is_object($object)) {
$result = compact('name') + array('data' => $object->data($name), 'errors' => $object->errors($name), 'class' => $object->model());
}
return (object) $result;
});
parent::__construct(Set::merge($defaults, $config));
}