/**
  * 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
0
文件: inflector.php 项目: hracsi/HMVC
 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
0
 /**
  * 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
0
 /**
  * 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
0
 /**
  * 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);
 }
 /**
  * setUp method
  * 
  * @access public
  * @return void
  */
 function setUp()
 {
     $this->Inflector = Inflector::getInstance();
 }
示例#7
0
 /**
  * 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
0
 /**
  * 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];
 }
 /**
  * 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
0
文件: visualize.php 项目: vad/taolin
 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
0
/**
 * 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
0
 /**
  * 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'] = '******';
     }
     arsort($result);
     return $result;
 }
示例#13
0
<?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 <*****@*****.**>
 * @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
0
 /**
  * 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
0
 /**
  * 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);
 }
示例#16
0
 protected static function getCollection()
 {
     $className = get_called_class();
     $inflector = Inflector::getInstance();
     $collection_name = $inflector->tableize($className);
     if (self::$database == null) {
         throw new Exception("BaseMongoRecord::database must be initialized to a proper database string");
     }
     if (self::$connection == null) {
         throw new Exception("BaseMongoRecord::connection must be initialized to a valid Mongo object");
     }
     if (!self::$connection->connected) {
         self::$connection->connect();
     }
     return self::$connection->selectCollection(self::$database, $collection_name);
 }
示例#17
0
 /**
  * Return $word in singular form.
  *
  * @param string $word Word in plural
  * @return string Word in singular
  * @access public
  * @static
  */
 function singularize($word)
 {
     $_this =& Inflector::getInstance();
     if (!isset($_this->singularRules) || empty($_this->singularRules)) {
         $_this->__initSingularRules();
     }
     if (isset($_this->singularized[$word])) {
         return $_this->singularized[$word];
     }
     extract($_this->singularRules);
     if (!isset($regexUninflected) || !isset($regexIrregular)) {
         $regexUninflected = __enclose(join('|', $uninflected));
         $regexIrregular = __enclose(join('|', array_keys($irregular)));
         $_this->singularRules['regexUninflected'] = $regexUninflected;
         $_this->singularRules['regexIrregular'] = $regexIrregular;
     }
     if (preg_match('/(.*)\\b(' . $regexIrregular . ')$/i', $word, $regs)) {
         $_this->singularized[$word] = $regs[1] . substr($word, 0, 1) . substr($irregular[strtolower($regs[2])], 1);
         return $_this->singularized[$word];
     }
     if (preg_match('/^(' . $regexUninflected . ')$/i', $word, $regs)) {
         $_this->singularized[$word] = $word;
         return $word;
     }
     foreach ($singularRules as $rule => $replacement) {
         if (preg_match($rule, $word)) {
             $_this->singularized[$word] = preg_replace($rule, $replacement, $word);
             return $_this->singularized[$word];
         }
     }
     $_this->singularized[$word] = $word;
     return $word;
 }
示例#18
0
 /**
  * Return $word in singular form.
  *
  * @param string $word Word in plural
  * @return string Word in singular
  * @access public
  * @static
  * @link http://book.cakephp.org/view/572/Class-methods
  */
 function singularize($word)
 {
     $_this =& Inflector::getInstance();
     if (isset($_this->_singularized[$word])) {
         return $_this->_singularized[$word];
     }
     if (!isset($_this->_singular['merged']['uninflected'])) {
         $_this->_singular['merged']['uninflected'] = array_merge($_this->_singular['uninflected'], $_this->_uninflected);
     }
     if (!isset($_this->_singular['merged']['irregular'])) {
         $_this->_singular['merged']['irregular'] = array_merge($_this->_singular['irregular'], array_flip($_this->_plural['irregular']));
     }
     if (!isset($_this->_singular['cacheUninflected']) || !isset($_this->_singular['cacheIrregular'])) {
         $_this->_singular['cacheUninflected'] = '(?:' . join('|', $_this->_singular['merged']['uninflected']) . ')';
         $_this->_singular['cacheIrregular'] = '(?:' . join('|', array_keys($_this->_singular['merged']['irregular'])) . ')';
     }
     if (preg_match('/(.*)\\b(' . $_this->_singular['cacheIrregular'] . ')$/i', $word, $regs)) {
         $_this->_singularized[$word] = $regs[1] . substr($word, 0, 1) . substr($_this->_singular['merged']['irregular'][strtolower($regs[2])], 1);
         return $_this->_singularized[$word];
     }
     if (preg_match('/^(' . $_this->_singular['cacheUninflected'] . ')$/i', $word, $regs)) {
         $_this->_singularized[$word] = $word;
         return $word;
     }
     foreach ($_this->_singular['rules'] as $rule => $replacement) {
         if (preg_match($rule, $word)) {
             $_this->_singularized[$word] = preg_replace($rule, $replacement, $word);
             return $_this->_singularized[$word];
         }
     }
     $_this->_singularized[$word] = $word;
     return $word;
 }
示例#19
0
 /**
  * testInstantiation method
  *
  * @access public
  * @return void
  */
 function testInstantiation()
 {
     $Inflector =& Inflector::getInstance();
     $this->assertEqual(Inflector::getInstance(), $Inflector);
 }
示例#20
0
 /**
  * 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)
 {
     $_this =& Configure::getInstance();
     $Inflector =& Inflector::getInstance();
     $types = array('model' => array('suffix' => '.php', 'base' => 'AppModel'), 'controller' => array('suffix' => '_controller.php', 'base' => 'AppController'), 'helper' => array('suffix' => '.php', 'base' => 'AppHelper'), 'plugin' => array('suffix' => '', 'base' => null), 'class' => array('suffix' => '.php', 'base' => null));
     if (!isset($types[$type])) {
         return false;
     }
     if (empty($path)) {
         $pathVar = $type . 'Paths';
         $path = $_this->{$pathVar};
     }
     $objects = array();
     foreach ((array) $path as $dir) {
         $items = $_this->__list($dir, $types[$type]['suffix']);
         $objects = am($items, $objects);
         /*if (file_exists($path . $name . '.php')) {
         			Configure::store('Models', 'class.paths', array($className => array('path' => $path . $name . '.php')));
         			require($path . $name . '.php');
         			return true;
         		}*/
     }
     return array_map(array(&$Inflector, 'camelize'), $objects);
 }