### Initialize hook Like Controller and Table, this class has an initialize() hook that you can use to add custom 'constructor' logic. It is important to remember that each request (and sub-request) will only make one instance of any given component. ### Life cycle callbacks Components can provide several callbacks that are fired at various stages of the request cycle. The available callbacks are: - beforeFilter(Event $event) Called before the controller's beforeFilter method by default. - startup(Event $event) Called after the controller's beforeFilter method, and before the controller action is called. - beforeRender(Event $event) Called before the Controller beforeRender, and before the view class is loaded. - shutdown(Event $event) Called after the action is complete and the view has been rendered but before Controller::afterFilter(). - beforeRedirect(Event $event $url, Response $response) Called before a redirect is done. Allows you to change the URL that will be redirected to by returning a Response instance with new URL set using Response::location(). Redirection can be prevented by stopping the event propagation. While the controller is not an explicit argument for the callback methods it is the subject of each event and can be fetched using Event::subject().
See also: Cake\Controller\Controller::$components
Inheritance: implements Cake\Event\EventListenerInterface, use trait Cake\Core\InstanceConfigTrait, use trait Cake\Log\LogTrait
コード例 #1
1
 public function __construct(ComponentCollection $collection, $settings = array())
 {
     parent::__construct($collection, $settings);
     // initialize callback urls
     $router = new Router();
     $baseurl = $router->url('/', true);
     $this->controller = $collection->getController();
     $this->http = new Client();
     // Load in PHP extension ZIP...?
     if (extension_loaded('zip') == true) {
         $this->zip = new ZipArchive();
         $this->Controller = $collection->getController();
     } else {
         throw new MissingComponentException(__('Error: Not Load extension "ZIP" in PHP.INI!!'));
     }
     $this->controller->loadModel('EmailTemplates');
     $this->EmailTemplates = $this->controller->EmailTemplates;
     /*
     
      // prefetch partner details
      $this->Partners = $this->controller->Partners;        
      $this->partner_id = $this->controller->Auth->user('partner_id');
      $this->partner = $this->Partners->get($this->partner_id);
      // end prefetch
     */
 }
コード例 #2
1
 /**
  * initialize
  *
  * @param array $config Config.
  * @return void
  */
 public function initialize(array $config)
 {
     parent::initialize($config);
     $this->setController($this->_registry->getController());
     // adding request handler
     $this->Controller->loadComponent('RequestHandler');
     // accepts json
     $this->Controller->RequestHandler->renderAs($this->Controller, 'json');
     // set the default modelName
     if (is_null($this->config('modelName'))) {
         $this->config('modelName', $this->Controller->name);
     }
     if (Configure::read('Api.JWT')) {
         if ($this->Controller->Auth) {
             $this->Controller->Auth->config('authenticate', ['ADmad/JwtAuth.Jwt' => ['parameter' => '_token', 'userModel' => 'Users.Users', 'scope' => ['Users.active' => 1], 'fields' => ['id' => 'id']]]);
         }
     }
 }
コード例 #3
0
ファイル: IniAcl.php プロジェクト: edukondaluetg/acl
 /**
  * Initialize method
  *
  * @param Component $component Component instance.
  * @return void
  */
 public function initialize(Component $component)
 {
     $adapter = $component->config('adapter');
     if (is_array($adapter)) {
         $this->options = $adapter + $this->options;
     }
     $engine = new IniConfig(dirname($this->options['config']) . DS);
     $this->options = $engine->read(basename($this->options['config']));
 }
コード例 #4
0
ファイル: PhpAcl.php プロジェクト: edukondaluetg/acl
 /**
  * Initialize method
  *
  * @param Component $Component Component instance
  * @return void
  */
 public function initialize(Component $Component)
 {
     $adapter = $Component->config('adapter');
     if (is_array($adapter)) {
         $this->options = $adapter + $this->options;
     }
     $engine = new PhpConfig(dirname($this->options['config']) . DS);
     $config = $engine->read(basename($this->options['config']));
     $this->build($config);
     $Component->Aco = $this->Aco;
     $Component->Aro = $this->Aro;
 }
コード例 #5
0
 /**
  * Constructor
  *
  * @param \Cake\Controller\ComponentRegistry $collection
  * @param array $config Config options array
  */
 public function __construct(ComponentRegistry $collection, $config = [])
 {
     parent::__construct($collection, $config);
     $Controller = $collection->getController();
     $this->request = $Controller->request;
     $this->response = $Controller->response;
 }
コード例 #6
0
 /**
  * initialize method
  * @param array $config The config data
  * @return void
  */
 public function initialize(array $config)
 {
     parent::initialize($config);
     if (Configure::read('Users.GoogleAuthenticator.login')) {
         $this->tfa = new TwoFactorAuth(Configure::read('Users.GoogleAuthenticator.issuer'), Configure::read('Users.GoogleAuthenticator.digits'), Configure::read('Users.GoogleAuthenticator.period'), Configure::read('Users.GoogleAuthenticator.algorithm'), Configure::read('Users.GoogleAuthenticator.qrcodeprovider'), Configure::read('Users.GoogleAuthenticator.rngprovider'), Configure::read('Users.GoogleAuthenticator.encryptionKey'));
     }
 }
コード例 #7
0
 /**
  * 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);
 }
コード例 #8
0
 /**
  * Constructor
  *
  * @param ComponentRegistry $registry A ComponentRegistry object.
  * @param array             $config   Array of configuration settings.
  */
 public function __construct(ComponentRegistry $registry, array $config = [])
 {
     parent::__construct($registry, $config);
     if ($registry->getController() instanceof \Cake\Controller\Controller) {
         $this->_controller = $registry->getController();
     }
 }
コード例 #9
0
 /**
  * initialize
  *
  * Initialize callback for Components.
  *
  * @param array $config Configurations.
  * @return void
  */
 public function initialize(array $config)
 {
     parent::initialize($config);
     $this->Controller = $this->_registry->getController();
     // set up the default helper
     $this->Controller->helpers['Utils.Menu'] = [];
 }
コード例 #10
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();
 }
コード例 #11
0
ファイル: UnionComponent.php プロジェクト: Cheren/union
 /**
  * Component constructor.
  *
  * @param ComponentRegistry $registry
  * @param array $config
  */
 public function __construct(ComponentRegistry $registry, array $config = [])
 {
     parent::__construct($registry, $config);
     if ($controller = $registry->getController()) {
         $this->_controller = $controller;
     }
 }
コード例 #12
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);
 }
コード例 #13
0
 /**
  * Initialize config data and properties.
  *
  * @param array $config The config data.
  * @return void
  */
 public function initialize(array $config)
 {
     parent::initialize($config);
     $this->_cookieName = Configure::read('Users.RememberMe.Cookie.name');
     $this->_validateConfig();
     $this->setCookieOptions();
     $this->_attachEvents();
 }
コード例 #14
0
 /**
  * Initialize Callback
  *
  * @param array $config
  */
 public function initialize(array $config)
 {
     parent::initialize($config);
     $this->Controller = $this->_registry->getController();
     if ($this->config('Auth')) {
         $this->Controller->loadComponent('Auth', $this->config('Auth'));
     }
     $this->Controller->loadComponent('Utils.Menu');
 }
コード例 #15
0
 public function initialize(array $config)
 {
     parent::initialize($config);
     $this->_controller = $this->_registry->getController();
     $action = $this->_controller->request->param('action');
     if (in_array($action, ['edit', 'add'])) {
         $this->__setCurrentUserPermissions();
     }
 }
コード例 #16
0
 public function initialize(array $config)
 {
     parent::initialize($config);
     $this->uid = uniqid();
     $this->request_pg = new \PagSeguroPaymentRequest();
     $this->request_pg->setShippingType(self::NOT_SPECIFIED);
     $this->request_pg->setReference($this->uid);
     $this->request_pg->setCurrency('BRL');
 }
コード例 #17
0
 /**
  * Initialize method
  * @param  array  $config configuration array
  * @return void
  */
 public function initialize(array $config)
 {
     parent::initialize($config);
     $this->_controller = $this->_registry->getController();
     $this->_user = $this->Auth->user();
     $this->_capabilitiesTable = TableRegistry::get('RolesCapabilities.Capabilities');
     $this->_capabilitiesTable->setCurrentRequest($config['currentRequest']);
     $this->_capabilitiesTable->setCurrentUser($this->Auth->user());
 }
コード例 #18
0
 /**
  * Constructor
  *
  * @param ComponentRegistry $registry A ComponentRegistry object.
  * @param array             $config   Array of configuration settings.
  */
 public function __construct(ComponentRegistry $registry, array $config = [])
 {
     parent::__construct($registry, $config);
     if ($registry->getController() instanceof \Cake\Controller\Controller) {
         $this->_session = $registry->getController()->request->session();
     }
     $facebookConfig = Configure::read('Facebook');
     FacebookSession::setDefaultApplication($facebookConfig['app_id'], $facebookConfig['app_secret']);
 }
コード例 #19
0
 public function initialize(array $config)
 {
     parent::initialize($config);
     $this->Controller = $this->_registry->getController();
     if ($this->request->is('service')) {
         $this->service = true;
         $this->Controller->viewClass = 'json';
         $this->data = [self::SUCCESS_KEY => false, self::CODE_KEY => 0, self::MESSAGE_KEY => 'Default message'];
     }
 }
コード例 #20
0
 public function __construct(ComponentRegistry $collection, array $config = array())
 {
     parent::__construct($collection, $config);
     $this->controller = $collection->getController();
     /*
      * Register event listener in the constructor (and not in the startup() method)
      * to ensure the listener is set when code in Controller->beforeFilter() is executed
      * (startup() is called after Controller->beforeFilter())
      */
     $this->listenToModelBeforeSave();
 }
コード例 #21
0
ファイル: AclComponent.php プロジェクト: ceeram/acl
 /**
  * Constructor. Will return an instance of the correct ACL class as defined in `Configure::read('Acl.classname')`
  *
  * @param ComponentRegistry $collection A ComponentRegistry
  * @param array $config Array of configuration settings
  * @throws \Cake\Error\Exception when Acl.classname could not be loaded.
  */
 public function __construct(ComponentRegistry $collection, array $config = array())
 {
     parent::__construct($collection, $config);
     $className = $name = Configure::read('Acl.classname');
     if (!class_exists($className)) {
         $className = App::className('Acl.' . $name, 'Adapter');
         if (!$className) {
             throw new Error\Exception(sprintf('Could not find %s.', $name));
         }
     }
     $this->adapter($className);
 }
コード例 #22
0
ファイル: UsersAuthComponent.php プロジェクト: cakedc/users
 /**
  * Initialize method, setup Auth if not already done passing the $config provided and
  * setup the default table to Users.Users if not provided
  *
  * @param array $config config options
  * @return void
  */
 public function initialize(array $config)
 {
     parent::initialize($config);
     $this->_validateConfig();
     $this->_initAuth();
     if (Configure::read('Users.Social.login')) {
         $this->_loadSocialLogin();
     }
     if (Configure::read('Users.RememberMe.active')) {
         $this->_loadRememberMe();
     }
     $this->_attachPermissionChecker();
 }
コード例 #23
0
 public function initialize(array $config)
 {
     parent::initialize($config);
     $privatni = $config['privatni'];
     $verejny = $config['verejny'];
     $heslo = $config['heslo'];
     $fp = fopen($privatni, "r");
     $this->privatni = fread($fp, filesize($privatni));
     fclose($fp);
     $this->heslo = $heslo;
     $fp = fopen($verejny, "r");
     $this->verejny = fread($fp, filesize($verejny));
     fclose($fp);
 }
コード例 #24
0
 public function __construct(&$controller, $settings = array())
 {
     parent::__construct($controller, $settings);
     if (isset($settings['skipAuthCheck'])) {
         $this->skipAuthCheck = $settings['skipAuthCheck'];
     }
     if (!empty($settings['exclude_check_on'])) {
         foreach ($settings['exclude_check_on'] as $exclude_check_on) {
             $this->_excludeCheckOnList[] = $exclude_check_on;
         }
     }
     $this->secret = Configure::read('shared_secret');
     $this->api_key = Configure::read('api_key');
     $this->scope = Configure::read('scope');
 }
コード例 #25
0
 public function __construct(ComponentRegistry $collection, array $config = array())
 {
     parent::__construct($collection, $config);
     // initialize callback urls
     $router = new Router();
     $baseurl = $router->url('/', true);
     $this->callback_url = $baseurl . 'external_apps/salesforce/callback';
     //end
     $this->controller = $collection->getController();
     $this->http = new Client();
     $this->controller->loadModel('Vendors');
     // prefetch vendor details
     $this->Vendors = $this->controller->Vendors;
     $this->vendor_id = $this->controller->Auth->user('vendor_id');
     $this->vendor = $this->Vendors->get($this->vendor_id);
     // end prefetch
 }
コード例 #26
0
 /**
  * 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);
 }
コード例 #27
0
 public function initialize(array $config)
 {
     parent::initialize($config);
     // if mode is not set in bootstrap, defaults to 'Test'
     $mode = Configure::read('Stripe.mode');
     if ($mode) {
         $this->mode = $mode;
     }
     // set the Stripe API key
     $this->key = Configure::read('Stripe.' . $this->mode . 'Secret');
     if (!$this->key) {
         throw new Exception('Stripe API Secret key is not set');
     }
     // if currency is not set, defaults to 'usd'
     $currency = Configure::read('Stripe.currency');
     if ($currency) {
         $this->currency = strtolower($currency);
     }
 }
コード例 #28
0
 public function __construct(ComponentRegistry $collection, array $config = array())
 {
     parent::__construct($collection, $config);
     // initialize callback urls
     $router = new Router();
     $baseurl = $router->url('/', true);
     $this->facebook['callback_url'] = $baseurl . 'social_apps/facebook/callback';
     $this->twitter['callback_url'] = $baseurl . 'social_apps/twitter/callback';
     $this->linkedin['callback_url'] = $baseurl . 'social_apps/linkedin/callback';
     //end
     $this->controller = $collection->getController();
     $this->http = new Client();
     FacebookSession::setDefaultApplication($this->facebook['appID'], $this->facebook['appSecret']);
     $this->controller->loadModel('Partners');
     // prefetch partner details
     $this->Partners = $this->controller->Partners;
     $this->partner_id = $this->controller->Auth->user('partner_id');
     $this->partner = $this->Partners->get($this->partner_id);
     // end prefetch
 }
コード例 #29
0
ファイル: FlashComponent.php プロジェクト: hop1/cakephp
 /**
  * Constructor
  *
  * @param ComponentRegistry $registry A ComponentRegistry for this component
  * @param array $config Array of config.
  */
 public function __construct(ComponentRegistry $registry, array $config = [])
 {
     parent::__construct($registry, $config);
     $this->_session = $registry->getController()->request->session();
 }
コード例 #30
0
 public function __construct(ComponentRegistry $collection, array $config = array())
 {
     parent::__construct($collection, $config);
     $this->http = new Client();
 }