本文整理匯總了PHP中Inflector::getInstance方法的典型用法代碼示例。如果您正苦於以下問題:PHP Inflector::getInstance方法的具體用法?PHP Inflector::getInstance怎麽用?PHP Inflector::getInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Inflector
的用法示例。
在下文中一共展示了Inflector::getInstance方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: forward
/**
* Enter description here...
*
* @return unknown
*/
function forward()
{
$_this =& AmfDispatcher::getInstance();
$_this->parse();
if ($_this->input !== null) {
$target = null;
$Inflector =& Inflector::getInstance();
$_this->requests = count($_this->bodies);
for ($i = 0; $i < $_this->requests; $i++) {
$_this->request++;
if (isset($_this->headers[$i])) {
$_this->header = $_this->headers[$i];
}
$_this->body = $_this->bodies[$i];
unset($_this->bodies[$i]);
if (isset($_this->body['target'])) {
$target = $_this->body['target'];
}
$_this->__dispatch($target);
}
exit;
}
return false;
}
示例2: underscore
public function underscore($camelCasedWord)
{
$_this =& Inflector::getInstance();
if (!($result = $_this->_cache(__FUNCTION__, $camelCasedWord))) {
$result = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $camelCasedWord));
$_this->_cache(__FUNCTION__, $camelCasedWord, $result);
}
return $result;
}
示例3: slug
/**
* Returns a string with all spaces converted to underscores (by default), accented
* characters converted to non-accented characters, and non word characters removed.
*
* @param string $string the string you want to slug
* @param string $replacement will replace keys in map
* @param array $map extra elements to map to the replacement
* @deprecated $map param will be removed in future versions. Use Inflector::rules() instead
* @return string
* @access public
* @static
* @link http://book.cakephp.org/view/1479/Class-methods
*/
function slug($string, $replacement = '_', $map = array())
{
$_this =& Inflector::getInstance();
if (is_array($replacement)) {
$map = $replacement;
$replacement = '_';
}
$quotedReplacement = preg_quote($replacement, '/');
$merge = array('/[^\\s\\p{Ll}\\p{Lm}\\p{Lo}\\p{Lt}\\p{Lu}\\p{Nd}]/mu' => ' ', '/\\s+/' => $replacement, sprintf('/^[%s]+|[%s]+$/', $quotedReplacement, $quotedReplacement) => '');
$map = $map + $_this->_transliteration + $merge;
return preg_replace(array_keys($map), array_values($map), $string);
}
示例4: __connectDefaultRoutes
/**
* Connects the default, built-in routes, including admin routes, and (deprecated) web services
* routes.
*
* @access private
*/
function __connectDefaultRoutes()
{
$_this =& Router::getInstance();
if ($_this->__defaultsMapped) {
return;
}
if ($admin = Configure::read('Routing.admin')) {
$params = array('prefix' => $admin, $admin => true);
}
if ($plugins = Configure::listObjects('plugin')) {
$Inflector =& Inflector::getInstance();
$plugins = array_map(array(&$Inflector, 'underscore'), $plugins);
}
if (!empty($plugins)) {
$match = array('plugin' => implode('|', $plugins));
$_this->connect('/:plugin/:controller/:action/*', array(), $match);
if ($admin) {
$_this->connect("/{$admin}/:plugin/:controller", $params, $match);
$_this->connect("/{$admin}/:plugin/:controller/:action/*", $params, $match);
}
}
if ($admin) {
$_this->connect("/{$admin}/:controller", $params);
$_this->connect("/{$admin}/:controller/:action/*", $params);
}
$_this->connect('/:controller', array('action' => 'index'));
$_this->connect('/:controller/:action/*');
if ($_this->named['rules'] === false) {
$_this->connectNamed(true);
}
$_this->__defaultsMapped = true;
}
示例5: getCollection
/**
* Get the collection for this class
*
* @return MongoCollection
* @throws Exception
*/
protected static function getCollection()
{
$className = get_called_class();
if (null !== static::$collectionName) {
$collectionName = static::$collectionName;
} else {
$collectionName = explode('\\', $className);
$collectionName = end($collectionName);
$inflector = Inflector::getInstance();
$collectionName = $inflector->tableize($collectionName);
}
if ($className::$database == null) {
throw new Exception("BaseMongoRecord::database must be initialized to a proper database string");
}
if ($className::$connection == null) {
throw new Exception("BaseMongoRecord::connection must be initialized to a valid Mongo object");
}
if (!$className::$connection->connected) {
$className::$connection->connect();
}
return $className::$connection->selectCollection($className::$database, $collectionName);
}
示例6: setUp
/**
* setUp method
*
* @access public
* @return void
*/
function setUp()
{
$this->Inflector = Inflector::getInstance();
}
示例7: __connectDefaultRoutes
/**
* Connects the default, built-in routes, including admin routes, and (deprecated) web services
* routes.
*
* @access private
*/
function __connectDefaultRoutes()
{
$_this =& Router::getInstance();
if ($_this->__defaultsMapped) {
return;
}
if ($admin = Configure::read('Routing.admin')) {
$params = array('prefix' => $admin, $admin => true);
}
$Inflector =& Inflector::getInstance();
$plugins = array_map(array(&$Inflector, 'underscore'), Configure::listObjects('plugin'));
if (!empty($plugins)) {
$match = array('plugin' => implode('|', $plugins));
$_this->connect('/:plugin/:controller/:action/*', array(), $match);
if ($admin) {
$_this->connect("/{$admin}/:plugin/:controller", $params, $match);
$_this->connect("/{$admin}/:plugin/:controller/:action/*", $params, $match);
}
}
if ($admin) {
$_this->connect("/{$admin}/:controller", $params);
$_this->connect("/{$admin}/:controller/:action/*", $params);
}
$_this->connect('/:controller', array('action' => 'index'));
/**
* Deprecated
*
*/
$_this->connect('/bare/:controller/:action/*', array('bare' => '1'));
$_this->connect('/ajax/:controller/:action/*', array('bare' => '1'));
if (Configure::read('Routing.webservices') == 'on') {
trigger_error('Deprecated: webservices routes are deprecated and will not be supported in future versions. Use Router::parseExtensions() instead.', E_USER_WARNING);
$_this->connect('/rest/:controller/:action/*', array('webservices' => 'Rest'));
$_this->connect('/rss/:controller/:action/*', array('webservices' => 'Rss'));
$_this->connect('/soap/:controller/:action/*', array('webservices' => 'Soap'));
$_this->connect('/xml/:controller/:action/*', array('webservices' => 'Xml'));
$_this->connect('/xmlrpc/:controller/:action/*', array('webservices' => 'XmlRpc'));
}
$_this->connect('/:controller/:action/*');
if (empty($_this->__namedArgs)) {
$_this->connectNamed(array('page', 'fields', 'order', 'limit', 'recursive', 'sort', 'direction', 'step'));
}
$_this->__defaultsMapped = true;
}
示例8: listObjects
/**
* Returns an index of objects of the given type, with the physical path to each object
*
* @param string $type Type of object, i.e. 'model', 'controller', 'helper', or 'plugin'
* @param mixed $path Optional
* @return Configure instance
* @access public
*/
function listObjects($type, $path = null, $cache = true)
{
$_this =& Configure::getInstance();
$objects = array();
$extension = false;
$name = $type;
if ($type === 'file' && !$path) {
return false;
} elseif ($type === 'file') {
$extension = true;
$name = $type . str_replace(DS, '', $path);
}
if (empty($_this->__objects) && $cache === true) {
$_this->__objects = Cache::read('object_map', '_cake_core_');
}
if (empty($_this->__objects) || !isset($_this->__objects[$type]) || $cache !== true) {
$Inflector =& Inflector::getInstance();
$types = array('model' => array('suffix' => '.php', 'base' => 'AppModel', 'core' => false), 'behavior' => array('suffix' => '.php', 'base' => 'ModelBehavior'), 'controller' => array('suffix' => '_controller.php', 'base' => 'AppController'), 'component' => array('suffix' => '.php', 'base' => null), 'view' => array('suffix' => '.php', 'base' => null), 'helper' => array('suffix' => '.php', 'base' => 'AppHelper'), 'plugin' => array('suffix' => '', 'base' => null), 'vendor' => array('suffix' => '', 'base' => null), 'class' => array('suffix' => '.php', 'base' => null), 'file' => array('suffix' => '.php', 'base' => null));
if (!isset($types[$type])) {
return false;
}
$objects = array();
if (empty($path)) {
$path = $_this->{$type . 'Paths'};
if (isset($types[$type]['core']) && $types[$type]['core'] === false) {
array_pop($path);
}
}
$items = array();
foreach ((array) $path as $dir) {
if ($type === 'file' || $type === 'class' || strpos($dir, $type) !== false) {
$items = $_this->__list($dir, $types[$type]['suffix'], $extension);
$objects = array_merge($items, array_diff($objects, $items));
}
}
if ($type !== 'file') {
$objects = array_map(array(&$Inflector, 'camelize'), $objects);
}
if ($cache === true) {
$_this->__objects[$name] = $objects;
$_this->__cache = true;
} else {
return $objects;
}
}
return $_this->__objects[$name];
}
示例9: has_many
/**
* has_many
* @param mix
* @return void
* @comment generate getter/setter for array of target class
*/
protected function has_many()
{
$numcls = func_num_args();
$cls_list = func_get_args();
$inflector = Inflector::getInstance();
$self = $this;
foreach ($cls_list as $clsname) {
$plurclsname = $inflector->pluralize($clsname);
//add,create,remove
$funcname = "add{$clsname}";
$this->addfunc($funcname, function ($item) use($clsname, $self) {
$id = $item->getID();
if ($id == null) {
//if id is null then recall the func after save
$item->afterSave_once = function () use($item, $self, $clsname) {
$addx = "add{$clsname}";
$self->{$addx}($item);
};
return $self;
}
$getx = "get{$clsname}ids";
$itemids = $self->{$getx}();
if ($itemids == null) {
$itemids = array();
}
array_push($itemids, $item->getID());
$setx = "set{$clsname}ids";
$self->{$setx}($itemids);
return $self;
});
$funcname = "create{$clsname}";
$this->addfunc($funcname, function () use($clsname, $self) {
$item = new $clsname();
$addx = "add{$clsname}";
$self->{$addx}($item);
return $item;
});
$funcname = "remove{$clsname}";
$this->addfunc($funcname, function ($item) use($clsname, $self) {
$getx = "get{$clsname}ids";
$itemids = $self->{$getx}();
$key = array_search($item->getID(), $itemids);
if (gettype($key) == "boolean") {
//no such value
return $self;
}
unset($itemids[$key]);
//remove the id
$setx = "set{$clsname}ids";
$self->{$setx}($itemids);
return $self;
});
$funcname = "get{$plurclsname}";
$this->addfunc($funcname, function () use($clsname, $self) {
$getx = "get{$clsname}ids";
$itemids = $self->{$getx}();
$items = $clsname::find(array('_id' => array('$in' => $itemids)));
return $items;
//return MongoRecordIterator
});
$funcname = "set{$plurclsname}";
$this->addfunc($funcname, function ($items) use($clsname, $self) {
$itemids = array();
foreach ($items as $item) {
array_push($itemids, $item->getID());
}
if (count($itemids) == 0) {
return $self;
}
$setx = "set{$clsname}ids";
$self->{$setx}($itemids);
return $self;
});
}
}
示例10: getAllModels
function getAllModels()
{
$Inflector =& Inflector::getInstance();
uses('Folder');
$folder = new Folder(MODELS);
$models = $folder->findRecursive('.*php');
$folder = new Folder(BEHAVIORS);
$behaviors = $folder->findRecursive('.*php');
$models = array_diff($models, $behaviors);
foreach ($models as $id => $model) {
$file = new File($model);
$models[$id] = $file->name();
}
$models = array_map(array(&$Inflector, 'camelize'), $models);
App::import('Model', $models);
return $models;
}
示例11: tableize
/**
* tableize
*
* takes a (CamelCase or not) name ('DbSession')
* makes it lower_case and plural ('db_sessions')
* this implementation is just stupid and needs replacing
*
* @access public
* @param string $table
* @return string
*/
function tableize($object)
{
$inflector =& Inflector::getInstance();
return $inflector->tableize($object);
}
示例12: groups
/**
* undocumented function
*
* @param string $key
* @return void
*/
function groups($key = null)
{
$result = array();
if (!empty($this->current['config']['groups'])) {
$groups = array_map('trim', explode(',', $this->current['config']['groups']));
$Inflector = Inflector::getInstance();
$groups = array_map(array($Inflector, 'slug'), $groups, array_fill(0, count($groups), '-'));
$result = array_combine($groups, $groups);
}
if (!isset($result['admin'])) {
$result['admin'] = 'admin';
}
if (!isset($result['user'])) {
$result['user'] = 'user';
}
arsort($result);
return $result;
}
示例13: dirname
<?php
/**
* Arquivo para adaptação da aplicação para Português-Brasil
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @author Juan Basso <jrbasso@gmail.com>
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
// Definindo idioma da aplicação
Configure::write('Config.language', 'pt-br');
// Adicionando o caminho do locale
$localePaths = Configure::read('localePaths');
$localePaths[] = dirname(dirname(__FILE__)) . DS . 'locale';
Configure::write('localePaths', $localePaths);
// Alteração do inflection
require dirname(__FILE__) . DS . 'inflections.php';
$inflector = Inflector::getInstance();
$inflector->__pluralRules = $pluralRules;
$inflector->__uninflectedPlural = $uninflectedPlural;
$inflector->__irregularPlural = $irregularPlural;
$inflector->__singularRules = $singularRules;
$inflector->__uninflectedSingular = $uninflectedPlural;
$inflector->__irregularSingular = array_flip($irregularPlural);
示例14: variable
/**
* Returns camelBacked version of an underscored string.
*
* @param string $string
* @return string in variable form
* @access public
* @static
* @link http://book.cakephp.org/view/572/Class-methods
*/
function variable($string)
{
$_this = Inflector::getInstance();
if (!($result = $_this->_cache(__FUNCTION__, $string))) {
$string2 = Inflector::camelize(Inflector::underscore($string));
$replace = strtolower(substr($string2, 0, 1));
$result = preg_replace('/\\w/', $replace, $string2, 1);
$_this->_cache(__FUNCTION__, $string, $result);
}
return $result;
}
示例15: testInstantiation
/**
* testInstantiation method
*
* @access public
* @return void
*/
function testInstantiation()
{
$this->skipUnless(strpos(Debugger::trace(), 'GroupTest') === false, '%s Cannot be run from within a group test');
$Instance = Inflector::getInstance();
$this->assertEqual(new Inflector(), $Instance);
}