本文整理汇总了PHP中ClassRegistry::keys方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassRegistry::keys方法的具体用法?PHP ClassRegistry::keys怎么用?PHP ClassRegistry::keys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ClassRegistry
的用法示例。
在下文中一共展示了ClassRegistry::keys方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeRender
function beforeRender()
{
$models = ClassRegistry::keys();
foreach ($models as $currentModel) {
if (ClassRegistry::isKeySet($currentModel)) {
$currentObject =& ClassRegistry::getObject($currentModel);
if (is_a($currentObject, 'Model') && !empty($currentObject->validationErrors)) {
$this->validationErrors[Inflector::camelize($currentModel)] =& $currentObject->validationErrors;
}
}
}
}
示例2: render
public function render($view = null, $layout = null)
{
$event = new CakeEvent('Controller.beforeRender', $this);
$this->getEventManager()->dispatch($event);
if ($event->isStopped()) {
$this->autoRender = false;
return $this->response;
}
if (!empty($this->uses) && is_array($this->uses)) {
foreach ($this->uses as $model) {
list($plugin, $className) = pluginSplit($model);
$this->request->params['models'][$className] = compact('plugin', 'className');
}
}
$viewClass = $this->viewClass;
if ($this->viewClass != 'View') {
list($plugin, $viewClass) = pluginSplit($viewClass, true);
$viewClass = $viewClass . 'View';
App::uses($viewClass, $plugin . 'View');
} else {
// ELSE IS CUSTOM In ORDER To Provide the right layout even were we are ( as plugin ... )
list($plugin, $viewClass) = pluginSplit($viewClass, true);
$viewClass = 'Trois' . 'View';
App::uses($viewClass, 'Trois.' . 'View');
}
$View = new $viewClass($this);
$models = ClassRegistry::keys();
foreach ($models as $currentModel) {
$currentObject = ClassRegistry::getObject($currentModel);
if (is_a($currentObject, 'Model')) {
$className = get_class($currentObject);
list($plugin) = pluginSplit(App::location($className));
$this->request->params['models'][$currentObject->alias] = compact('plugin', 'className');
$View->validationErrors[$currentObject->alias] =& $currentObject->validationErrors;
}
}
$this->autoRender = false;
$this->View = $View;
$this->response->body($View->render($view, $layout));
return $this->response;
}
示例3: disableBehavior
/**
* @brief Disables a behavior in tests
*
* This function will overwrite the given behavior to a clean
* instance of the ModelBehavior class so the behavior will act like it never
* existed.
*
* @param mixed $behaviors Single behavior name or an array of names
*
* @return void
*/
public function disableBehavior($behaviors)
{
if (!is_array($behaviors)) {
$behaviors = array($behaviors);
}
foreach ($behaviors as $behavior) {
list($plugin, $name) = pluginSplit($behavior);
$class = $name . 'Behavior';
$ModelBehavior = new ModelBehavior();
if (ClassRegistry::isKeySet($class)) {
ClassRegistry::removeObject($class);
if (!empty($plugin)) {
ClassRegistry::removeObject($plugin . '.' . $class);
}
foreach (ClassRegistry::keys() as $key) {
$instance = ClassRegistry::getObject($key);
if (property_exists($instance, 'Behaviors')) {
$instance->Behaviors->{$name} = $ModelBehavior;
}
}
}
ClassRegistry::addObject($class, $ModelBehavior);
if (!empty($plugin)) {
ClassRegistry::addObject($plugin . '.' . $class, $ModelBehavior);
}
}
}
示例4: testPersist
/**
* testPersist method
*
* @access public
* @return void
*/
function testPersist()
{
@unlink(CACHE . 'persistent' . DS . 'testmodel.php');
$this->assertFalse($this->object->testPersist('TestModel', null, $test));
$this->assertFalse($this->object->testPersist('TestModel', true, $test));
$this->assertTrue($this->object->testPersist('TestModel', null, $test));
$this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'testmodel.php'));
$this->assertTrue($this->object->testPersist('TestModel', true, $test));
$this->assertNull($this->object->TestModel);
@unlink(CACHE . 'persistent' . DS . 'testmodel.php');
$model =& new ObjectTestModel();
$expected = ClassRegistry::keys();
ClassRegistry::flush();
$data = array('object_test_model' => $model);
$this->assertFalse($this->object->testPersist('ObjectTestModel', true, $data));
$this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'objecttestmodel.php'));
$this->object->testPersist('ObjectTestModel', true, $model, 'registry');
$result = ClassRegistry::keys();
$this->assertEqual($result, $expected);
$newModel = ClassRegistry::getObject('object_test_model');
$this->assertEqual('ObjectTestModel', $newModel->name);
@unlink(CACHE . 'persistent' . DS . 'objecttestmodel.php');
}
示例5: testImport
/**
* testImport
*
* @return void
*/
public function testImport()
{
$testSuiteDb = ConnectionManager::getDataSource('test');
$testSuiteConfig = $testSuiteDb->config;
ConnectionManager::create('new_test_suite', array_merge($testSuiteConfig, array('prefix' => 'new_' . $testSuiteConfig['prefix'])));
$newTestSuiteDb = ConnectionManager::getDataSource('new_test_suite');
$Source = new CakeTestFixtureTestFixture();
$Source->create($newTestSuiteDb);
$Source->insert($newTestSuiteDb);
$Fixture = new CakeTestFixtureDefaultImportFixture();
$Fixture->fields = $Fixture->records = null;
$Fixture->import = array('model' => 'FixtureImportTestModel', 'connection' => 'new_test_suite');
$Fixture->init();
$this->assertEquals(array('id', 'name', 'created'), array_keys($Fixture->fields));
$keys = array_flip(ClassRegistry::keys());
$this->assertFalse(array_key_exists('fixtureimporttestmodel', $keys));
$Source->drop($newTestSuiteDb);
}
示例6: testExecuteIntoInteractive
/**
* test the interactive side of bake.
*
* @return void
*/
public function testExecuteIntoInteractive()
{
$tables = $this->Task->listAll('test');
$article = array_search('bake_articles', $tables) + 1;
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
$this->Task->interactive = true;
$this->Task->expects($this->any())->method('in')->will($this->onConsecutiveCalls($article, 'n', 'y', 'y', 'y', 'y', 'n', 'y'));
$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
$this->Task->Test->expects($this->once())->method('bake');
$this->Task->Fixture->expects($this->once())->method('bake');
$filename = '/my/path/BakeArticle.php';
$this->Task->expects($this->once())->method('createFile')->with($filename, $this->stringContains('class BakeArticle'));
$this->Task->execute();
$this->assertEquals(count(ClassRegistry::keys()), 0);
$this->assertEquals(count(ClassRegistry::mapKeys()), 0);
}
示例7: create
/**
* Returns an HTML FORM element.
*
* ### Options:
*
* - `type` Form method defaults to POST
* - `action` The controller action the form submits to, (optional).
* - `url` The url the form submits to. Can be a string or a url array. If you use 'url'
* you should leave 'action' undefined.
* - `default` Allows for the creation of Ajax forms.
* - `onsubmit` Used in conjunction with 'default' to create ajax forms.
* - `inputDefaults` set the default $options for FormHelper::input(). Any options that would
* be set when using FormHelper::input() can be set here. Options set with `inputDefaults`
* can be overridden when calling input()
* - `encoding` Set the accept-charset encoding for the form. Defaults to `Configure::read('App.encoding')`
*
* @access public
* @param string $model The model object which the form is being defined for
* @param array $options An array of html attributes and options.
* @return string An formatted opening FORM tag.
* @link http://book.cakephp.org/view/1384/Creating-Forms
*/
function create($model = null, $options = array())
{
$created = $id = false;
$append = '';
if (is_array($model) && empty($options)) {
$options = $model;
$model = null;
}
if (empty($model) && $model !== false && !empty($this->request['models'])) {
$model = $this->request['models'][0];
$this->defaultModel = $this->request['models'][0];
} elseif (empty($model) && empty($this->request['models'])) {
$model = false;
}
$models = ClassRegistry::keys();
foreach ($models as $currentModel) {
if (ClassRegistry::isKeySet($currentModel)) {
$currentObject =& ClassRegistry::getObject($currentModel);
if (is_a($currentObject, 'Model') && !empty($currentObject->validationErrors)) {
$this->validationErrors[Inflector::camelize($currentModel)] =& $currentObject->validationErrors;
}
}
}
if ($model !== false) {
$object = $this->_introspectModel($model);
$this->setEntity($model . '.', true);
}
$modelEntity = $this->model();
if ($model !== false && isset($this->fieldset[$modelEntity]['key'])) {
$data = $this->fieldset[$modelEntity];
$recordExists = isset($this->request->data[$model]) && !empty($this->request->data[$model][$data['key']]) && !is_array($this->request->data[$model][$data['key']]);
if ($recordExists) {
$created = true;
$id = $this->request->data[$model][$data['key']];
}
}
$options = array_merge(array('type' => $created && empty($options['action']) ? 'put' : 'post', 'action' => null, 'url' => null, 'default' => true, 'encoding' => strtolower(Configure::read('App.encoding')), 'inputDefaults' => array()), $options);
$this->_inputDefaults = $options['inputDefaults'];
unset($options['inputDefaults']);
if (!isset($options['id'])) {
$domId = isset($options['action']) ? $options['action'] : $this->request['action'];
$options['id'] = $this->domId($domId . 'Form');
}
if ($options['action'] === null && $options['url'] === null) {
$options['action'] = $this->request->here(false);
} elseif (empty($options['url']) || is_array($options['url'])) {
if (empty($options['url']['controller'])) {
if (!empty($model) && $model != $this->defaultModel) {
$options['url']['controller'] = Inflector::underscore(Inflector::pluralize($model));
} elseif (!empty($this->request->params['controller'])) {
$options['url']['controller'] = Inflector::underscore($this->request->params['controller']);
}
}
if (empty($options['action'])) {
$options['action'] = $this->request->params['action'];
}
$actionDefaults = array('plugin' => $this->plugin, 'controller' => $this->_View->viewPath, 'action' => $options['action']);
$options['action'] = array_merge($actionDefaults, (array) $options['url']);
if (empty($options['action'][0]) && !empty($id)) {
$options['action'][0] = $id;
}
} elseif (is_string($options['url'])) {
$options['action'] = $options['url'];
}
unset($options['url']);
switch (strtolower($options['type'])) {
case 'get':
$htmlAttributes['method'] = 'get';
break;
case 'file':
$htmlAttributes['enctype'] = 'multipart/form-data';
$options['type'] = $created ? 'put' : 'post';
case 'post':
case 'put':
case 'delete':
$append .= $this->hidden('_method', array('name' => '_method', 'value' => strtoupper($options['type']), 'id' => null));
default:
$htmlAttributes['method'] = 'post';
//.........这里部分代码省略.........
示例8: validationErrors
/**
* Return all vaidation errors.
*
* @return array
*/
public function validationErrors()
{
$return = array();
$models = ClassRegistry::keys();
foreach ($models as $currentModel) {
$currentObject = ClassRegistry::getObject($currentModel);
if ($currentObject instanceof Model) {
$return[$currentObject->alias] = $currentObject->validationErrors;
}
}
return $return;
}
示例9: render
/**
* Instantiates the correct view class, hands it its data, and uses it to render the view output.
*
* @param string $action Action name to render
* @param string $layout Layout to use
* @param string $file File to use for rendering
* @return string Full output string of view contents
* @access public
* @link http://book.cakephp.org/view/428/render
*/
function render($action = null, $layout = null, $file = null)
{
$this->beforeRender();
$viewClass = $this->view;
if ($this->view != 'View') {
if (strpos($viewClass, '.') !== false) {
list($plugin, $viewClass) = explode('.', $viewClass);
}
$viewClass = $viewClass . 'View';
App::import('View', $this->view);
}
$this->Component->beforeRender($this);
$this->params['models'] = $this->modelNames;
if (Configure::read() > 2) {
$this->set('cakeDebug', $this);
}
$View =& new $viewClass($this);
if (!empty($this->modelNames)) {
$models = array();
foreach ($this->modelNames as $currentModel) {
if (isset($this->{$currentModel}) && is_a($this->{$currentModel}, 'Model')) {
$models[] = Inflector::underscore($currentModel);
}
$isValidModel = isset($this->{$currentModel}) && is_a($this->{$currentModel}, 'Model') && !empty($this->{$currentModel}->validationErrors);
if ($isValidModel) {
$View->validationErrors[Inflector::camelize($currentModel)] =& $this->{$currentModel}->validationErrors;
}
}
$models = array_diff(ClassRegistry::keys(), $models);
foreach ($models as $currentModel) {
if (ClassRegistry::isKeySet($currentModel)) {
$currentObject =& ClassRegistry::getObject($currentModel);
if (is_a($currentObject, 'Model') && !empty($currentObject->validationErrors)) {
$View->validationErrors[Inflector::camelize($currentModel)] =& $currentObject->validationErrors;
}
}
}
}
$this->autoRender = false;
$this->output .= $View->render($action, $layout, $file);
return $this->output;
}
示例10: render
/**
* Gets an instance of the view object & prepares it for rendering the output, then
* asks the view to actualy do the job.
*
* @param string $action Action name to render
* @param string $layout Layout to use
* @param string $file File to use for rendering
* @return boolean Success
* @access public
*/
function render($action = null, $layout = null, $file = null)
{
$this->beforeRender();
$viewClass = $this->view;
if ($this->view != 'View') {
if (strpos($viewClass, '.') !== false) {
list($plugin, $viewClass) = explode('.', $viewClass);
}
$viewClass = $viewClass . 'View';
App::import('View', $this->view);
}
foreach ($this->components as $c) {
$path = preg_split('/\\/|\\./', $c);
$c = $path[count($path) - 1];
if (isset($this->{$c}) && is_object($this->{$c}) && is_callable(array($this->{$c}, 'beforeRender'))) {
if (!array_key_exists('enabled', get_object_vars($this->{$c})) || $this->{$c}->enabled == true) {
$this->{$c}->beforeRender($this);
}
}
}
$this->params['models'] = $this->modelNames;
if (Configure::read() > 2) {
$this->set('cakeDebug', $this);
}
$this->__viewClass =& new $viewClass($this);
if (!empty($this->modelNames)) {
$models = array();
foreach ($this->modelNames as $currentModel) {
if (isset($this->{$currentModel}) && is_a($this->{$currentModel}, 'Model')) {
$models[] = Inflector::underscore($currentModel);
}
if (isset($this->{$currentModel}) && is_a($this->{$currentModel}, 'Model') && !empty($this->{$currentModel}->validationErrors)) {
$this->__viewClass->validationErrors[Inflector::camelize($currentModel)] =& $this->{$currentModel}->validationErrors;
}
}
$models = array_diff(ClassRegistry::keys(), $models);
foreach ($models as $currentModel) {
if (ClassRegistry::isKeySet($currentModel)) {
$currentObject =& ClassRegistry::getObject($currentModel);
if (is_a($currentObject, 'Model') && !empty($currentObject->validationErrors)) {
$this->__viewClass->validationErrors[Inflector::camelize($currentModel)] =& $currentObject->validationErrors;
}
}
}
}
$this->autoRender = false;
return $this->__viewClass->render($action, $layout, $file);
}
示例11: testAction
/**
* Tests an action using the controller itself and skipping the dispatcher, and
* returning the view vars.
*
* Since `CakeTestCase::testAction` was causing so many problems and is
* incredibly slow, it is overwritten here to go about it a bit differently.
* Import `ExtendedTestCase` from 'Lib' and extend test cases using `ExtendedTestCase`
* instead to gain this functionality.
*
* For backwards compatibility with the original `CakeTestCase::testAction`, set
* `testController` to `null`.
*
* ### Options:
* - `data` Data to pass to the controller
*
* ### Limitations:
* - only reinstantiates the default model
* - not 100% complete, i.e., some callbacks may not be fired like they would
* if regularly called through the dispatcher
*
* @param string $url The url to test
* @param array $options A list of options
* @return array The view vars
* @link http://mark-story.com/posts/view/testing-cakephp-controllers-the-hard-way
* @link http://mark-story.com/posts/view/testing-cakephp-controllers-mock-objects-edition
* @link http://www.42pixels.com/blog/testing-controllers-the-slightly-less-hard-way
*/
function testAction($url = '', $options = array())
{
if (is_null($this->testController)) {
return parent::testAction($url, $options);
}
$Controller = $this->testController;
// reset parameters
ClassRegistry::flush();
$Controller->passedArgs = array();
$Controller->params = array();
$Controller->url = null;
$Controller->action = null;
$Controller->viewVars = array();
$keys = ClassRegistry::keys();
foreach ($keys as $key) {
if (is_a(ClassRegistry::getObject(Inflector::camelize($key)), 'Model')) {
ClassRegistry::getObject(Inflector::camelize($key))->create(false);
}
}
$Controller->Session->delete('Message');
$Controller->activeUser = null;
$default = array('data' => array(), 'method' => 'post');
$options = array_merge($default, $options);
// set up the controller based on the url
$urlParams = Router::parse($url);
$extra = array_diff_key($options, array('data' => null, 'method' => null, 'return' => null));
$urlParams = array_merge($urlParams, $extra);
$action = $urlParams['action'];
$prefix = null;
$urlParams['url']['url'] = $url;
if (strtolower($options['method']) == 'get') {
$urlParams['url'] = array_merge($options['data'], $urlParams['url']);
} else {
$Controller->data = $options['data'];
}
if (isset($urlParams['prefix'])) {
$action = $urlParams['prefix'] . '_' . $action;
$prefix = $urlParams['prefix'] . '/';
}
$Controller->passedArgs = $urlParams['named'];
$Controller->params = $urlParams;
$Controller->url = $urlParams;
$Controller->action = $prefix . $urlParams['plugin'] . '/' . $urlParams['controller'] . '/' . $urlParams['action'];
// only initialize the components once
if ($this->_componentsInitialized === false) {
$this->_componentsInitialized = true;
$Controller->Component->initialize($Controller);
}
$Controller->beforeFilter();
$Controller->Component->startup($Controller);
call_user_func_array(array(&$Controller, $action), $urlParams['pass']);
$Controller->beforeRender();
$Controller->Component->triggerCallback('beforeRender', $Controller);
return $Controller->viewVars;
}
示例12: testBakeModel
/**
* test that execute passes runs bake depending with named model.
*
* @return void
* @access public
*/
function testBakeModel()
{
$this->Task->connection = 'test_suite';
$this->Task->path = '/my/path/';
$filename = '/my/path/article.php';
$this->Task->setReturnValue('_checkUnitTest', 1);
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class Article extends AppModel/')));
$model =& new Model(array('name' => 'Article', 'table' => 'articles', 'ds' => 'test_suite'));
$this->Task->bake($model);
$this->assertEqual(count(ClassRegistry::keys()), 0);
$this->assertEqual(count(ClassRegistry::mapKeys()), 0);
}
示例13: _attachLinkedModels
/**
* Iterates through an array and attaches those models to $Model
*
* This function is here solely to trick `Controller::paginate()` into thinking
* that the models in $linked are directly and should only be used if the 'link'
* key is present
*
* @param Model $Model
* @param array $linked
* @see LinkableBehavior
*/
protected function _attachLinkedModels(&$Model, $linked)
{
$keys = ClassRegistry::keys();
$linked = Set::normalize($linked);
foreach ($linked as $_model => $attrs) {
if (in_array(Inflector::underscore($_model), $keys)) {
$Model->{$_model} = ClassRegistry::init($_model);
}
if (!is_array($attrs) && in_array(Inflector::underscore($attrs), $keys)) {
$Model->{$attrs} = ClassRegistry::init($attrs);
} elseif (is_array($attrs)) {
$this->_attachLinkedModels($Model, $attrs);
}
}
}
示例14: render
/**
* Instantiates the correct view class, hands it its data, and uses it to render the view output.
*
* @param string $view View to use for rendering
* @param string $layout Layout to use
* @return string Full output string of view contents
* @link http://book.cakephp.org/view/980/render
*/
public function render($view = null, $layout = null)
{
$this->beforeRender();
$this->Components->trigger('beforeRender', array(&$this));
$viewClass = $this->viewClass;
if ($this->viewClass != 'View') {
list($plugin, $viewClass) = pluginSplit($viewClass);
$viewClass = $viewClass . 'View';
App::import('View', $this->viewClass);
}
$this->request->params['models'] = $this->modelNames;
$View = new $viewClass($this);
if (!empty($this->modelNames)) {
$models = array();
foreach ($this->modelNames as $currentModel) {
if (isset($this->{$currentModel}) && is_a($this->{$currentModel}, 'Model')) {
$models[] = Inflector::underscore($currentModel);
}
$isValidModel = isset($this->{$currentModel}) && is_a($this->{$currentModel}, 'Model') && !empty($this->{$currentModel}->validationErrors);
if ($isValidModel) {
$View->validationErrors[Inflector::camelize($currentModel)] =& $this->{$currentModel}->validationErrors;
}
}
$models = array_diff(ClassRegistry::keys(), $models);
foreach ($models as $currentModel) {
if (ClassRegistry::isKeySet($currentModel)) {
$currentObject = ClassRegistry::getObject($currentModel);
if (is_a($currentObject, 'Model') && !empty($currentObject->validationErrors)) {
$View->validationErrors[Inflector::camelize($currentModel)] =& $currentObject->validationErrors;
}
}
}
}
$this->autoRender = false;
$this->View = $View;
return $this->response->body($View->render($view, $layout));
}
示例15: testInit
/**
* testInit
*
* @access public
* @return void
*/
function testInit()
{
$Fixture =& new CakeTestFixtureTestFixture();
unset($Fixture->table);
$Fixture->init();
$this->assertEqual($Fixture->table, 'fixture_tests');
$this->assertEqual($Fixture->primaryKey, 'id');
$Fixture =& new CakeTestFixtureTestFixture();
$Fixture->primaryKey = 'my_random_key';
$Fixture->init();
$this->assertEqual($Fixture->primaryKey, 'my_random_key');
$this->_initDb();
$Source =& new CakeTestFixtureTestFixture();
$Source->create($this->db);
$Source->insert($this->db);
$Fixture =& new CakeTestFixtureImportFixture();
$expected = array('id', 'name', 'created');
$this->assertEqual(array_keys($Fixture->fields), $expected);
$db =& ConnectionManager::getDataSource('test_suite');
$config = $db->config;
$config['prefix'] = 'fixture_test_suite_';
ConnectionManager::create('fixture_test_suite', $config);
$Fixture->fields = $Fixture->records = null;
$Fixture->import = array('table' => 'fixture_tests', 'connection' => 'test_suite', 'records' => true);
$Fixture->init();
$this->assertEqual(count($Fixture->records), count($Source->records));
$Fixture =& new CakeTestFixtureImportFixture();
$Fixture->fields = $Fixture->records = null;
$Fixture->import = array('model' => 'FixtureImportTestModel', 'connection' => 'test_suite');
$Fixture->init();
$this->assertEqual(array_keys($Fixture->fields), array('id', 'name', 'created'));
//assert that model has been removed from registry, stops infinite loops.
$keys = array_flip(ClassRegistry::keys());
$this->assertFalse(array_key_exists('fixtureimporttestmodel', $keys));
$Source->drop($this->db);
}