Пример #1
0
 /**
  * Constructor
  *
  * @param \Cake\Controller\ComponentRegistry $collection Component Registry
  * @param array $config Array of configuration settings.
  */
 public function __construct(ComponentRegistry $collection, $config = [])
 {
     $this->_controller = $collection->getController();
     $this->_eventManager = $this->_controller->eventManager();
     parent::__construct($collection, $config);
     $this->_createCrudComponentInstance();
 }
 /**
  * Constructor. Parses the accepted content types accepted by the client using HTTP_ACCEPT
  *
  * @param ComponentRegistry $registry ComponentRegistry object.
  * @param array $config Config options array
  */
 public function __construct(ComponentRegistry $registry, $config = [])
 {
     $this->_defaultConfig = Hash::merge($this->_defaultConfig, $this->_translateConfigMessages(), (array) Configure::read('UserTools.Component'));
     $this->_controller = $registry->getController();
     $this->response = $this->_controller->response;
     parent::__construct($registry, $config);
 }
Пример #3
0
 /**
  * Constructor.
  *
  * @param \Cake\Controller\ComponentRegistry $collection
  * @param array $config
  */
 public function __construct(ComponentRegistry $collection, $config = [])
 {
     $this->Controller = $collection->getController();
     $defaults = (array) Configure::read('Ajax') + $this->_defaultConfig;
     $config += $defaults;
     parent::__construct($collection, $config);
 }
Пример #4
0
 /**
  * Constructor
  *
  * @param ComponentRegistry $registry The controller for this request.
  * @param array $config An array of config. This class does not use any config.
  */
 public function __construct(ComponentRegistry $registry, array $config = array())
 {
     $this->_registry = $registry;
     $controller = $registry->getController();
     $this->controller($controller);
     $this->config($config);
 }
 /**
  * Class constructor
  *
  * @param Cake\Controller\ComponentRegistry $collection ComponentRegistry instance.
  * @param array $config Configuration options
  * @return void
  */
 public function __construct(\Cake\Controller\ComponentRegistry $collection, array $config)
 {
     pr("AppPlusPlus __construct()");
     // make calling controller available
     $this->_controller = $collection->getController();
     // Enable Authentication if needed
     if ($this->Config('Authentication.enabled')) {
         $this->setupAuth();
     }
     // Load components for the calling calling controller
     $this->_controller->loadComponent('RequestHandler');
     $this->_controller->loadComponent('Flash');
     $this->_controller->loadComponent('Crud.Crud', ['actions' => ['Crud.Index', 'Crud.Add', 'Crud.Edit', 'Crud.View', 'Crud.Delete'], 'listeners' => ['Crud.Api', 'Crud.ApiPagination', 'Crud.ApiQueryLog']]);
     $this->_controller->loadComponent('Paginator', ['settings' => ['page' => 1, 'limit' => 25, 'maxLimit' => 100, 'whitelist' => ['limit', 'sort', 'page', 'direction']]]);
     //$this->_eventManager = $this->_controller->eventManager();
     parent::__construct($collection, $config);
 }
Пример #6
0
 /**
  * Magic method for lazy loading $components.
  *
  * @param string $name Name of component to get.
  * @return mixed A Component object or null.
  */
 public function __get($name)
 {
     if (isset($this->_componentMap[$name]) && !isset($this->{$name})) {
         $config = ['enabled' => false] + (array) $this->_componentMap[$name]['config'];
         $this->{$name} = $this->_registry->load($this->_componentMap[$name]['class'], $config);
     }
     if (isset($this->{$name})) {
         return $this->{$name};
     }
 }
Пример #7
0
 /**
  * Test a duplicate component being loaded more than once with same and differing configurations.
  *
  * @expectedException RuntimeException
  * @expectedExceptionMessage The "Banana" alias has already been loaded with the following config:
  * @return void
  */
 public function testDuplicateComponentInitialize()
 {
     $Collection = new ComponentRegistry();
     $Collection->load('Banana', ['property' => ['closure' => function () {
     }]]);
     $Collection->load('Banana', ['property' => ['closure' => function () {
     }]]);
     $this->assertInstanceOf('TestApp\\Controller\\Component\\BananaComponent', $Collection->Banana, 'class is wrong');
     $Collection->load('Banana', ['property' => ['differs']]);
 }
Пример #8
0
 /**
  * Get the component registry for this controller.
  *
  * If called with the first parameter, it will be set as the controller $this->_components property
  *
  * @param \Cake\Controller\ComponentRegistry|null $components Component registry.
  *
  * @return \Cake\Controller\ComponentRegistry
  */
 public function components($components = null)
 {
     if ($components === null && $this->_components === null) {
         $this->_components = new ComponentRegistry($this);
     }
     if ($components !== null) {
         $components->setController($this);
         $this->_components = $components;
     }
     return $this->_components;
 }
Пример #9
0
 /**
  * Constructor
  *
  * @param \Cake\Controller\ComponentRegistry $registry A ComponentRegistry this component can use to lazy load its components
  * @param array $config Array of configuration settings.
  */
 public function __construct(ComponentRegistry $registry, array $config = [])
 {
     $this->_registry = $registry;
     $controller = $registry->getController();
     if ($controller) {
         $this->request =& $controller->request;
         $this->response =& $controller->response;
     }
     $this->config($config);
     if (!empty($this->components)) {
         $this->_componentMap = $registry->normalizeArray($this->components);
     }
     $this->initialize($config);
 }
Пример #10
0
 /**
  * test
  *
  * @return void
  */
 public function testAuthenticateNoCookie()
 {
     $request = new Request('/');
     $request->env('HTTP_USER_AGENT', 'user-agent');
     $mockCookie = $this->getMockBuilder('Cake\\Controller\\Component\\CookieComponent')->disableOriginalConstructor()->setMethods(['check', 'read'])->getMock();
     $mockCookie->expects($this->once())->method('read')->with('remember_me')->will($this->returnValue(null));
     $registry = new ComponentRegistry($this->controller);
     $registry->set('Cookie', $mockCookie);
     $this->rememberMe = new RememberMeAuthenticate($registry);
     $result = $this->rememberMe->authenticate($request, new Response());
     $this->assertFalse($result);
 }
Пример #11
0
 /**
  * Constructor
  *
  * @param \Cake\Controller\ComponentRegistry $collection A ComponentCollection this component
  *   can use to lazy load its components.
  * @param array $config Array of configuration settings.
  */
 public function __construct(ComponentRegistry $collection, $config = [])
 {
     $config += ['actions' => [], 'listeners' => []];
     $config['actions'] = $this->normalizeArray($config['actions']);
     $config['listeners'] = $this->normalizeArray($config['listeners']);
     $this->_controller = $collection->getController();
     $this->_eventManager = $this->_controller->eventManager();
     parent::__construct($collection, $config);
 }
Пример #12
0
 /**
  * test a component being used more than once.
  *
  * @return void
  */
 public function testMultipleComponentInitialize()
 {
     $Collection = new ComponentRegistry();
     $Banana = $Collection->load('Banana');
     $Orange = $Collection->load('Orange');
     $this->assertSame($Banana, $Orange->Banana, 'Should be references');
     $Banana->testField = 'OrangeField';
     $this->assertSame($Banana->testField, $Orange->Banana->testField, 'References are broken');
 }