当前位置: 首页>>代码示例>>PHP>>正文


PHP ClassRegistry::getInstance方法代码示例

本文整理汇总了PHP中ClassRegistry::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassRegistry::getInstance方法的具体用法?PHP ClassRegistry::getInstance怎么用?PHP ClassRegistry::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ClassRegistry的用法示例。


在下文中一共展示了ClassRegistry::getInstance方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: loadModel

 /**
  * Loads and instantiates models required by this controller.
  * If Controller::$persistModel; is true, controller will cache model instances on first request,
  * additional request will used cached models.
  * If the model is non existent, it will throw a missing database table error, as Cake generates
  * dynamic models for the time being.
  *
  * @param string $modelClass Name of model class to load
  * @param mixed $id Initial ID the instanced model class should have
  * @return mixed true when single model found and instance created, error returned if model not found.
  * @return bool
  */
 public function loadModel($modelClass, $id = null)
 {
     $cached = false;
     $object = null;
     list($plugin, $modelClass) = pluginSplit($modelClass, true, null);
     if (isset($this->_internals['persistModel']) && $this->_internals['persistModel'] === true) {
         $cached = $this->_persist($modelClass, null, $object);
     }
     if ($cached === false) {
         $this->_internals['modelNames'][] = $modelClass;
         $this->{$modelClass} = ClassRegistry::init(array('class' => $plugin . $modelClass, 'alias' => $modelClass, 'id' => $id));
         if (!$this->{$modelClass}) {
             $message = sprintf("Missing Model: %s", $modelClass);
             if (!empty($plugin)) {
                 $message .= sprintf(" in %s Plugin", substr($plugin, 0, -1));
             }
             throw new Exception($message);
         }
         if (isset($this->_internals['persistModel']) && $this->_internals['persistModel'] === true) {
             $this->_persist($modelClass, true, $this->{$modelClass});
             $registry =& ClassRegistry::getInstance();
             $this->_persist($modelClass . 'registry', true, $registry->__objects, 'registry');
         }
     } else {
         $this->_persist($modelClass . 'registry', true, $object, 'registry');
         $this->_persist($modelClass, true, $object);
         $this->_internals['modelNames'][] = $modelClass;
     }
     return true;
 }
开发者ID:josegonzalez,项目名称:cakephp-cake-djjob,代码行数:42,代码来源:CakeJob.php

示例2: load

 /**
  * Load the model and assign it to the controller
  *
  * @access public
  * @param string $modelClass
  * @return bool | mixed
  */
 function load($modelClass, $objectName = null)
 {
     if (!$this->controller) {
         return false;
     }
     $id = false;
     $object = null;
     $cached = false;
     $plugin = '';
     if ($this->controller->plugin) {
         $plugin = $this->controller->plugin . '.';
     }
     if (!class_exists($modelClass)) {
         $this->controller->loadModel($plugin . $modelClass);
     }
     if (class_exists($modelClass)) {
         if (!$objectName) {
             $objectName = $modelClass;
         }
         if ($this->controller->persistModel) {
             $cached = $this->_persist($modelClass, null, $object);
         }
         if (false === $cached) {
             $model =& new $modelClass($id);
             $this->controller->modelNames[] = $modelClass;
             $this->controller->{$objectName} =& $model;
             if ($this->controller->persistModel === true) {
                 $this->_persist($modelClass, true, $model);
                 $registry = ClassRegistry::getInstance();
                 $this->_persist($modelClass . 'registry', true, $registry->__objects, 'registry');
             }
         } else {
             $this->_persist($modelClass . 'registry', true, $object, 'registry');
             $this->_persist($modelClass, true, $object);
             $this->controller->{$objectName} = $this->{$modelClass};
             // unset the temp model, for PHP4
             unset($this->{$modelClass});
             $this->controller->modelNames[] = $modelClass;
         }
     } else {
         return $this->controller->cakeError('missingModel', array(array('className' => $modelClass, 'webroot' => '', 'base' => $this->controller->base)));
     }
     return true;
 }
开发者ID:jorge7,项目名称:densidad_suelo_mineras,代码行数:51,代码来源:model_loader.php

示例3: flush

 /**
  * Flushes all objects from the ClassRegistry.
  *
  * @return void
  */
 public static function flush()
 {
     $_this = ClassRegistry::getInstance();
     $_this->_objects = array();
     $_this->_map = array();
 }
开发者ID:Vighnesh123,项目名称:book-a-bus,代码行数:11,代码来源:ClassRegistry.php

示例4: flush

 /**
  * Flushes all objects from the ClassRegistry.
  *
  * @return void
  * @access public
  * @static
  */
 function flush()
 {
     $_this =& ClassRegistry::getInstance();
     $_this->__objects = array();
     $_this->__map = array();
 }
开发者ID:surfingtonio,项目名称:flashub.com,代码行数:13,代码来源:class_registry.php

示例5: loadModel

 /**
  * Loads and instantiates models required by this controller.
  * If Controller::persistModel; is true, controller will cache model instances on first request,
  * additional request will used cached models.
  * If the model is non existent, it will throw a missing database table error, as Cake generates
  * dynamic models for the time being.
  *
  * @param string $modelClass Name of model class to load
  * @param mixed $id Initial ID the instanced model class should have
  * @return mixed true when single model found and instance created error returned if models not found.
  * @access public
  */
 function loadModel($modelClass = null, $id = null)
 {
     if ($modelClass === null) {
         $modelClass = $this->modelClass;
     }
     $cached = false;
     $object = null;
     $plugin = null;
     if ($this->uses === false) {
         if ($this->plugin) {
             $plugin = $this->plugin . '.';
         }
     }
     if (strpos($modelClass, '.') !== false) {
         list($plugin, $modelClass) = explode('.', $modelClass);
         $plugin = $plugin . '.';
     }
     if ($this->persistModel === true) {
         $cached = $this->_persist($modelClass, null, $object);
     }
     if ($cached === false) {
         $this->modelNames[] = $modelClass;
         if (!PHP5) {
             $this->{$modelClass} =& ClassRegistry::init(array('class' => $plugin . $modelClass, 'alias' => $modelClass, 'id' => $id));
         } else {
             $this->{$modelClass} = ClassRegistry::init(array('class' => $plugin . $modelClass, 'alias' => $modelClass, 'id' => $id));
         }
         if (!$this->{$modelClass}) {
             return $this->cakeError('missingModel', array(array('className' => $modelClass, 'webroot' => '', 'base' => $this->base)));
         }
         if ($this->persistModel === true) {
             $this->_persist($modelClass, true, $this->{$modelClass});
             $registry = ClassRegistry::getInstance();
             $this->_persist($modelClass . 'registry', true, $registry->__objects, 'registry');
         }
     } else {
         $this->_persist($modelClass . 'registry', true, $object, 'registry');
         $this->_persist($modelClass, true, $object);
         $this->modelNames[] = $modelClass;
     }
 }
开发者ID:joseluistorres,项目名称:miacupones,代码行数:53,代码来源:controller.php

示例6: endTest

 function endTest()
 {
     FFactory::clean();
     ClassRegistry::getInstance()->flush();
 }
开发者ID:eripoll,项目名称:lebiplan,代码行数:5,代码来源:fixture_factory.test.php

示例7: startController

 /**
  * Callback issued when a controller's action is about to be invoked through testAction().
  *
  * @param Controller $controller	Controller that's about to be invoked.
  * @param array $params	Additional parameters as sent by testAction().
  */
 function startController(&$controller, $params = array())
 {
     if (isset($params['fixturize']) && (is_array($params['fixturize']) && !empty($params['fixturize']) || $params['fixturize'] === true)) {
         if (!isset($this->db)) {
             $this->_initDb();
         }
         $classRegistry =& ClassRegistry::getInstance();
         $models = array();
         foreach ($classRegistry->__map as $key => $name) {
             $object =& $classRegistry->getObject(Inflector::camelize($key));
             if (is_subclass_of($object, 'Model') && (is_array($params['fixturize']) && in_array($object->alias, $params['fixturize']) || $params['fixturize'] === true)) {
                 $models[$object->alias] = array('table' => $object->table, 'model' => $object->alias, 'key' => Inflector::camelize($key));
             }
         }
         if (!empty($models) && isset($this->db)) {
             $this->_queries = array('create' => array(), 'insert' => array(), 'drop' => array());
             foreach ($models as $model) {
                 $fixture =& new CakeTestFixture($this->db);
                 $fixture->name = $model['model'] . 'Test';
                 $fixture->table = $model['table'];
                 $fixture->import = array('model' => $model['model'], 'records' => true);
                 $fixture->init();
                 $createFixture = $fixture->create($this->db);
                 $insertsFixture = $fixture->insert();
                 $dropFixture = $fixture->drop();
                 if (!empty($createFixture)) {
                     $this->_queries['create'] = array_merge($this->_queries['create'], array($createFixture));
                 }
                 if (!empty($insertsFixture)) {
                     $this->_queries['insert'] = array_merge($this->_queries['insert'], $insertsFixture);
                 }
                 if (!empty($dropFixture)) {
                     $this->_queries['drop'] = array_merge($this->_queries['drop'], array($dropFixture));
                 }
             }
             foreach ($this->_queries['create'] as $query) {
                 if (isset($query) && $query !== false) {
                     $this->db->execute($query);
                 }
             }
             foreach ($this->_queries['insert'] as $query) {
                 if (isset($query) && $query !== false) {
                     $this->db->execute($query);
                 }
             }
             foreach ($models as $model) {
                 $object =& $classRegistry->getObject($model['key']);
                 if ($object !== false) {
                     $object->setDataSource('test_suite');
                     $object->cacheSources = false;
                 }
             }
         }
     }
 }
开发者ID:BLisa90,项目名称:cakecart,代码行数:61,代码来源:cake_test_case.php

示例8: constructClasses

 /**
  * Loads and instantiates models required by this controller.
  * If Controller::persistModel; is true, controller will create cached model instances on first request,
  * additional request will used cached models
  *
  * @return mixed true when single model found and instance created error returned if models not found.
  * @access public
  */
 function constructClasses()
 {
     if ($this->uses === null || $this->uses === array()) {
         return false;
     }
     if (empty($this->passedArgs) || !isset($this->passedArgs['0'])) {
         $id = false;
     } else {
         $id = $this->passedArgs['0'];
     }
     $cached = false;
     $object = null;
     if ($this->persistModel === true) {
         uses('neat_array');
     }
     if ($this->uses === false) {
         if (!class_exists($this->modelClass)) {
             loadModel($this->modelClass);
         }
     }
     if (class_exists($this->modelClass) && $this->uses === false) {
         if ($this->persistModel === true) {
             $cached = $this->_persist($this->modelClass, null, $object);
         }
         if ($cached === false) {
             $model =& new $this->modelClass($id);
             $this->modelNames[] = $this->modelClass;
             $this->{$this->modelClass} =& $model;
             if ($this->persistModel === true) {
                 $this->_persist($this->modelClass, true, $model);
                 $registry = ClassRegistry::getInstance();
                 $this->_persist($this->modelClass . 'registry', true, $registry->_objects, 'registry');
             }
         } else {
             $this->_persist($this->modelClass . 'registry', true, $object, 'registry');
             $this->_persist($this->modelClass, true, $object);
             $this->modelNames[] = $this->modelClass;
         }
         return true;
     } elseif ($this->uses === false) {
         return $this->cakeError('missingModel', array(array('className' => $this->modelClass, 'webroot' => '', 'base' => $this->base)));
     }
     if ($this->uses) {
         $uses = is_array($this->uses) ? $this->uses : array($this->uses);
         $this->modelClass = $uses[0];
         foreach ($uses as $modelClass) {
             $id = false;
             $cached = false;
             $object = null;
             $modelKey = Inflector::underscore($modelClass);
             if (!class_exists($modelClass)) {
                 loadModel($modelClass);
             }
             if (class_exists($modelClass)) {
                 if ($this->persistModel === true) {
                     $cached = $this->_persist($modelClass, null, $object);
                 }
                 if ($cached === false) {
                     $model =& new $modelClass($id);
                     $this->modelNames[] = $modelClass;
                     $this->{$modelClass} =& $model;
                     if ($this->persistModel === true) {
                         $this->_persist($modelClass, true, $model);
                         $registry = ClassRegistry::getInstance();
                         $this->_persist($modelClass . 'registry', true, $registry->_objects, 'registry');
                     }
                 } else {
                     $this->_persist($modelClass . 'registry', true, $object, 'registry');
                     $this->_persist($modelClass, true, $object);
                     $this->modelNames[] = $modelClass;
                 }
             } else {
                 return $this->cakeError('missingModel', array(array('className' => $modelClass, 'webroot' => '', 'base' => $this->base)));
             }
         }
         return true;
     }
 }
开发者ID:venka10,项目名称:RUS,代码行数:86,代码来源:controller.php

示例9: flush

 /**
  *  Limpa todos os objetos instanciados do registro.
  * 
  *  @return boolean true
  */
 public static function flush()
 {
     $self =& ClassRegistry::getInstance();
     $self->objects = array();
     return true;
 }
开发者ID:vfeitoza,项目名称:spaghettiphp,代码行数:11,代码来源:class_registry.php

示例10: testAction

 /**
  * Executes a Cake URL, optionally getting the view rendering or what is returned
  * when params['requested'] is set.
  *
  * @param string $url	Cake URL to execute (e.g: /articles/view/455)
  * @param array $params	Parameters
  *
  * @return mixed	What is returned from action (if $requested is true), or view rendered html
  *
  * @access protected
  */
 function testAction($url, $params = array())
 {
     $default = array('return' => 'result', 'fixturize' => false, 'data' => array(), 'method' => 'post');
     $params = am($default, $params);
     if (!empty($params['data'])) {
         $data = array('data' => $params['data']);
         if (low($params['method']) == 'get') {
             $_GET = $data;
         } else {
             $_POST = $data;
         }
     }
     $return = $params['return'];
     unset($params['data']);
     unset($params['method']);
     unset($params['return']);
     $dispatcher =& new CakeTestDispatcher();
     $dispatcher->testCase($this);
     if (low($return) != 'result') {
         $params['return'] = 0;
         ob_start();
         @$dispatcher->dispatch($url, $params);
         $result = ob_get_clean();
         if (low($return) == 'vars') {
             $view =& ClassRegistry::getObject('view');
             $viewVars = $view->getVars();
             $result = array();
             foreach ($viewVars as $var) {
                 $result[$var] = $view->getVar($var);
             }
             if (!empty($view->pageTitle)) {
                 $result = am($result, array('title' => $view->pageTitle));
             }
         }
     } else {
         $params['return'] = 1;
         $params['bare'] = 1;
         $params['requested'] = 1;
         $result = @$dispatcher->dispatch($url, $params);
     }
     $classRegistry =& ClassRegistry::getInstance();
     $keys = array_keys($classRegistry->__objects);
     foreach ($keys as $key) {
         $key = Inflector::camelize($key);
         $classRegistry->removeObject($key);
     }
     $classRegistry->__map = array();
     if (isset($this->_queries)) {
         unset($this->_queries);
     }
     return $result;
 }
开发者ID:rhencke,项目名称:mozilla-cvs-history,代码行数:63,代码来源:cake_test_case.php

示例11: strtolower

 /**
  * Return object which corresponds to given key.
  *
  * @param string $key
  * @return mixed
  */
 function &getObject($key)
 {
     $_this =& ClassRegistry::getInstance();
     $key = strtolower($key);
     return $_this->_objects[$key];
 }
开发者ID:carriercomm,项目名称:pastebin-5,代码行数:12,代码来源:class_registry.php

示例12:

 /**
  * Return object which corresponds to given key.
  *
  * @param string $key
  * @return mixed
  */
 function &getObject($key)
 {
     $_this =& ClassRegistry::getInstance();
     $key = Inflector::underscore($key);
     return $_this->_objects[$key];
 }
开发者ID:venka10,项目名称:RUS,代码行数:12,代码来源:class_registry.php

示例13: loadModel

 /**
  * Loads and instantiates models required by this controller.
  * If Controller::$persistModel; is true, controller will cache model instances on first request,
  * additional request will used cached models.
  * If the model is non existent, it will throw a missing database table error, as Cake generates
  * dynamic models for the time being.
  *
  * @param string $modelClass Name of model class to load
  * @param mixed $id Initial ID the instanced model class should have
  * @return mixed true when single model found and instance created, error returned if model not found.
  * @throws MissingModelException if the model class cannot be found.
  */
 public function loadModel($modelClass = null, $id = null)
 {
     if ($modelClass === null) {
         $modelClass = $this->modelClass;
     }
     $cached = false;
     $object = null;
     list($plugin, $modelClass) = pluginSplit($modelClass, true);
     if ($this->persistModel === true) {
         $cached = $this->_persist($modelClass, null, $object);
     }
     if ($cached === false) {
         $this->modelNames[] = $modelClass;
         $this->{$modelClass} = ClassRegistry::init(array('class' => $plugin . $modelClass, 'alias' => $modelClass, 'id' => $id));
         if (!$this->{$modelClass}) {
             throw new MissingModelException($modelClass);
         }
         if ($this->persistModel === true) {
             $this->_persist($modelClass, true, $this->{$modelClass});
             $registry = ClassRegistry::getInstance();
             $this->_persist($modelClass . 'registry', true, $registry->__objects, 'registry');
         }
     } else {
         $this->_persist($modelClass . 'registry', true, $object, 'registry');
         $this->_persist($modelClass, true, $object);
         $this->modelNames[] = $modelClass;
     }
     return true;
 }
开发者ID:robotarmy,项目名称:Phog,代码行数:41,代码来源:controller.php

示例14: loadModel

 /**
  * Loads and instantiates models required by this controller.
  * If Controller::persistModel; is true, controller will create cached model instances on first request,
  * additional request will used cached models
  *
  * @param string $modelClass Name of model class to load
  * @param mixed $id Initial ID the instanced model class should have
  * @return mixed true when single model found and instance created error returned if models not found.
  * @access public
  */
 function loadModel($modelClass = null, $id = false)
 {
     if ($modelClass === null) {
         $modelClass = $this->modelClass;
     }
     $cached = false;
     $object = null;
     $plugin = null;
     if ($this->plugin) {
         $plugin = $this->plugin . '.';
     }
     $modelKey = Inflector::underscore($modelClass);
     if (!class_exists($modelClass)) {
         loadModel($plugin . $modelClass);
     }
     if (class_exists($modelClass)) {
         if ($this->persistModel === true) {
             $cached = $this->_persist($modelClass, null, $object);
         }
         if ($cached === false) {
             $model =& new $modelClass($id);
             $this->modelNames[] = $modelClass;
             $this->{$modelClass} =& $model;
             if ($this->persistModel === true) {
                 $this->_persist($modelClass, true, $model);
                 $registry = ClassRegistry::getInstance();
                 $this->_persist($modelClass . 'registry', true, $registry->__objects, 'registry');
             }
         } else {
             $this->_persist($modelClass . 'registry', true, $object, 'registry');
             $this->_persist($modelClass, true, $object);
             $this->modelNames[] = $modelClass;
         }
     } else {
         return $this->cakeError('missingModel', array(array('className' => $modelClass, 'webroot' => '', 'base' => $this->base)));
     }
 }
开发者ID:rhencke,项目名称:mozilla-cvs-history,代码行数:47,代码来源:controller.php


注:本文中的ClassRegistry::getInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。