本文整理匯總了PHP中lithium\util\Inflector::tableize方法的典型用法代碼示例。如果您正苦於以下問題:PHP Inflector::tableize方法的具體用法?PHP Inflector::tableize怎麽用?PHP Inflector::tableize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類lithium\util\Inflector
的用法示例。
在下文中一共展示了Inflector::tableize方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: _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);
}
示例2: 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);
}
示例3: path
public function path($entity)
{
$resource = Inflector::tableize(basename(str_replace('\\', '/', $entity->model())));
if ($entity->exists()) {
return '/' . $resource . '/' . $entity->_id;
} else {
return '/' . $resource;
}
}
示例4: __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);
}
示例5: meta
/**
* Return meta information, for compatibility with LI3.
*
* @param string $key - name of property to return, e.g.
* 'name' or 'source'
* @param string $val - ignored
*/
public static function meta($key = null, $val = null)
{
$class = get_called_class();
$parts = explode("\\", $class);
$name = $parts[count($parts) - 1];
if ($key == 'name') {
return strtolower($name);
} else {
if ($key == 'source') {
return static::$sourceName ? static::$sourceName : strtolower(Inflector::tableize($name));
}
}
}
示例6: _initialize
/**
* Init default connection options and connects default finders.
*
* This method will set the `Model::$_schema`, `Model::$_meta`, `Model::$_finders` class
* attributes, as well as obtain a handle to the configured persistent storage connection
*
* @param string $class The fully-namespaced class name to initialize.
* @return object Returns the initialized model instance.
*/
protected static function _initialize($class)
{
$self = static::$_instances[$class];
if (isset(static::$_initialized[$class]) && static::$_initialized[$class]) {
return $self;
}
static::$_initialized[$class] = true;
$query = array();
$finders = array();
$meta = array();
$schema = array();
$source = array();
$classes = $self->_classes;
$initializers = array();
foreach (static::_parents() as $parent) {
$parentConfig = get_class_vars($parent);
foreach ($self->_autoConfig as $key) {
if (isset($parentConfig["_{$key}"])) {
$val = $parentConfig["_{$key}"];
${$key} = is_array($val) ? ${$key} + $val : $val;
}
}
if ($parent == __CLASS__) {
break;
}
}
$tmp = $self->_meta + $meta;
$source = array('meta' => array(), 'finders' => array(), 'schema' => array());
if ($tmp['connection']) {
$conn = $classes['connections']::get($tmp['connection']);
$source = ($conn ? $conn->configureClass($class) : array()) + $source;
}
$self->_classes = $classes;
$local = compact('class') + $self->_meta;
$self->_meta = $local + $source['meta'] + $meta;
$self->_initializers += array('name' => function ($self) {
return basename(str_replace('\\', '/', $self));
}, 'source' => function ($self) {
return Inflector::tableize($self::meta('name'));
}, 'title' => function ($self) {
$titleKeys = array('title', 'name');
$titleKeys = array_merge($titleKeys, (array) $self::meta('key'));
return $self::hasField($titleKeys);
});
if (is_object($self->_schema)) {
$self->_schema->append($source['schema']);
} elseif (is_array($self->_schema)) {
$self->_schema = $self->_schema + $source['schema'];
} else {
$self->_schema = $source['schema'];
}
$self->_finders += $source['finders'] + $self->_findFilters();
static::_relationsToLoad();
return $self;
}
示例7: meta
/**
* Set/get method for `Model` metadata.
*
* @see lithium\data\Model::$_meta
* @param string $key Model metadata key.
* @param string $value Model metadata value.
* @return mixed Metadata value for a given key.
*/
public static function meta($key = null, $value = null)
{
$self = static::_object();
if ($value) {
$self->_meta[$key] = $value;
}
if (is_array($key)) {
$self->_meta = $key + $self->_meta;
}
if (!$self->_meta['initialized']) {
$self->_meta['initialized'] = true;
if ($self->_meta['source'] === null) {
$self->_meta['source'] = Inflector::tableize($self->_meta['name']);
}
$titleKeys = array('title', 'name', $self->_meta['key']);
$self->_meta['title'] = $self->_meta['title'] ?: static::hasField($titleKeys);
}
if (is_array($key) || empty($key) || !empty($value)) {
return $self->_meta;
}
return isset($self->_meta[$key]) ? $self->_meta[$key] : null;
}
示例8: _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;
}
示例9: _initialize
/**
* Init default connection options and connects default finders.
*
* This method will set the `Model::$_schema`, `Model::$_meta`, `Model::$_finders` class
* attributes, as well as obtain a handle to the configured persistent storage connection
*
* @param string $class The fully-namespaced class name to initialize.
* @return object Returns the initialized model instance.
*/
protected static function _initialize($class)
{
$self = static::$_instances[$class];
if (isset(static::$_initialized[$class]) && static::$_initialized[$class]) {
return $self;
}
static::$_initialized[$class] = true;
$self->_inherit();
$source = array('classes' => array(), 'meta' => array(), 'finders' => array(), 'schema' => array());
$meta = $self->_meta;
if ($meta['connection']) {
$classes = $self->_classes;
$conn = $classes['connections']::get($meta['connection']);
$source = ($conn ? $conn->configureClass($class) : array()) + $source;
}
$self->_classes += $source['classes'];
$self->_meta = compact('class') + $self->_meta + $source['meta'];
$self->_initializers += array('name' => function ($self) {
return basename(str_replace('\\', '/', $self));
}, 'source' => function ($self) {
return Inflector::tableize($self::meta('name'));
}, 'title' => function ($self) {
$titleKeys = array('title', 'name');
$titleKeys = array_merge($titleKeys, (array) $self::meta('key'));
return $self::hasField($titleKeys);
});
if (is_object($self->_schema)) {
$self->_schema->append($source['schema']);
} else {
$self->_schema += $source['schema'];
}
$self->_finders += $source['finders'] + static::_finders();
$self->_classes += array('query' => 'lithium\\data\\model\\Query', 'validator' => 'lithium\\util\\Validator', 'entity' => 'lithium\\data\\Entity');
static::_relationsToLoad();
return $self;
}
示例10: 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());
}
示例11: testTabelize
/**
* testTableNaming method
*
* @return void
*/
public function testTabelize()
{
$this->assertEqual(Inflector::tableize('ArtistsGenre'), 'artists_genres');
$this->assertEqual(Inflector::tableize('FileSystem'), 'file_systems');
$this->assertEqual(Inflector::tableize('News'), 'news');
}
示例12: _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;
}
示例13: catch
* <current controller>/<current layout>_component
* component
* <current layout>_component
*
* <current controller> is tabelized name of current controller, for example:
* `ManageUsersController` is `manage_users`
* `UsersController` is `users`
*
* <current layout> is name of currently active layout, `'partial'` or `'backend'`
*
* To learn about template overloading read:
* @see li3_backend\extensions\controller\ComponentController::_viewAs()
*/
use lithium\util\Inflector;
$layout = $this->_config['layout'];
$controller = Inflector::tableize($this->_request->params['controller']);
/**
* Render controller's general component menu if exists
*/
try {
echo $this->_render('element', "{$controller}/component");
} catch (Exception $e) {
}
/**
* Render controller's component menu for current layout if exists
*/
try {
echo $this->_render('element', "{$controller}/{$layout}_component");
} catch (Exception $e) {
}
/**