CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.8 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.8
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • App
  • BasePlugin
  • ClassLoader
  • Configure
  • ObjectRegistry
  • Plugin
  • PluginCollection

Interfaces

  • ConsoleApplicationInterface
  • HttpApplicationInterface
  • PluginApplicationInterface
  • PluginInterface

Traits

  • ConventionsTrait
  • InstanceConfigTrait
  • StaticConfigTrait
  1: <?php
  2: /**
  3:  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4:  * Copyright 2005-2011, Cake Software Foundation, Inc. (https://cakefoundation.org)
  5:  *
  6:  * Licensed under The MIT License
  7:  * Redistributions of files must retain the above copyright notice.
  8:  *
  9:  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 10:  * @link          https://cakephp.org CakePHP(tm) Project
 11:  * @since         3.6.0
 12:  * @license       https://opensource.org/licenses/mit-license.php MIT License
 13:  */
 14: namespace Cake\Core;
 15: 
 16: use InvalidArgumentException;
 17: use ReflectionClass;
 18: 
 19: /**
 20:  * Base Plugin Class
 21:  *
 22:  * Every plugin should extends from this class or implement the interfaces and
 23:  * include a plugin class in it's src root folder.
 24:  */
 25: class BasePlugin implements PluginInterface
 26: {
 27:     /**
 28:      * Do bootstrapping or not
 29:      *
 30:      * @var bool
 31:      */
 32:     protected $bootstrapEnabled = true;
 33: 
 34:     /**
 35:      * Load routes or not
 36:      *
 37:      * @var bool
 38:      */
 39:     protected $routesEnabled = true;
 40: 
 41:     /**
 42:      * Enable middleware
 43:      *
 44:      * @var bool
 45:      */
 46:     protected $middlewareEnabled = true;
 47: 
 48:     /**
 49:      * Console middleware
 50:      *
 51:      * @var bool
 52:      */
 53:     protected $consoleEnabled = true;
 54: 
 55:     /**
 56:      * The path to this plugin.
 57:      *
 58:      * @var string
 59:      */
 60:     protected $path;
 61: 
 62:     /**
 63:      * The class path for this plugin.
 64:      *
 65:      * @var string
 66:      */
 67:     protected $classPath;
 68: 
 69:     /**
 70:      * The config path for this plugin.
 71:      *
 72:      * @var string
 73:      */
 74:     protected $configPath;
 75: 
 76:     /**
 77:      * The name of this plugin
 78:      *
 79:      * @var string
 80:      */
 81:     protected $name;
 82: 
 83:     /**
 84:      * Constructor
 85:      *
 86:      * @param array $options Options
 87:      */
 88:     public function __construct(array $options = [])
 89:     {
 90:         foreach (static::VALID_HOOKS as $key) {
 91:             if (isset($options[$key])) {
 92:                 $this->{"{$key}Enabled"} = (bool)$options[$key];
 93:             }
 94:         }
 95:         foreach (['name', 'path', 'classPath', 'configPath'] as $path) {
 96:             if (isset($options[$path])) {
 97:                 $this->{$path} = $options[$path];
 98:             }
 99:         }
100: 
101:         $this->initialize();
102:     }
103: 
104:     /**
105:      * {@inheritdoc}
106:      */
107:     public function initialize()
108:     {
109:     }
110: 
111:     /**
112:      * {@inheritDoc}
113:      */
114:     public function getName()
115:     {
116:         if ($this->name) {
117:             return $this->name;
118:         }
119:         $parts = explode('\\', get_class($this));
120:         array_pop($parts);
121:         $this->name = implode('/', $parts);
122: 
123:         return $this->name;
124:     }
125: 
126:     /**
127:      * {@inheritDoc}
128:      */
129:     public function getPath()
130:     {
131:         if ($this->path) {
132:             return $this->path;
133:         }
134:         $reflection = new ReflectionClass($this);
135:         $path = dirname($reflection->getFileName());
136: 
137:         // Trim off src
138:         if (substr($path, -3) === 'src') {
139:             $path = substr($path, 0, -3);
140:         }
141:         $this->path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
142: 
143:         return $this->path;
144:     }
145: 
146:     /**
147:      * {@inheritDoc}
148:      */
149:     public function getConfigPath()
150:     {
151:         if ($this->configPath) {
152:             return $this->configPath;
153:         }
154:         $path = $this->getPath();
155: 
156:         return $path . 'config' . DIRECTORY_SEPARATOR;
157:     }
158: 
159:     /**
160:      * {@inheritDoc}
161:      */
162:     public function getClassPath()
163:     {
164:         if ($this->classPath) {
165:             return $this->classPath;
166:         }
167:         $path = $this->getPath();
168: 
169:         return $path . 'src' . DIRECTORY_SEPARATOR;
170:     }
171: 
172:     /**
173:      * {@inheritdoc}
174:      */
175:     public function enable($hook)
176:     {
177:         $this->checkHook($hook);
178:         $this->{"{$hook}Enabled}"} = true;
179: 
180:         return $this;
181:     }
182: 
183:     /**
184:      * {@inheritdoc}
185:      */
186:     public function disable($hook)
187:     {
188:         $this->checkHook($hook);
189:         $this->{"{$hook}Enabled"} = false;
190: 
191:         return $this;
192:     }
193: 
194:     /**
195:      * {@inheritdoc}
196:      */
197:     public function isEnabled($hook)
198:     {
199:         $this->checkHook($hook);
200: 
201:         return $this->{"{$hook}Enabled"} === true;
202:     }
203: 
204:     /**
205:      * Check if a hook name is valid
206:      *
207:      * @param string $hook The hook name to check
208:      * @throws \InvalidArgumentException on invalid hooks
209:      * @return void
210:      */
211:     protected function checkHook($hook)
212:     {
213:         if (!in_array($hook, static::VALID_HOOKS)) {
214:             throw new InvalidArgumentException(
215:                 "`$hook` is not a valid hook name. Must be one of " . implode(', ', static::VALID_HOOKS)
216:             );
217:         }
218:     }
219: 
220:     /**
221:      * {@inheritdoc}
222:      */
223:     public function routes($routes)
224:     {
225:         $path = $this->getConfigPath() . 'routes.php';
226:         if (file_exists($path)) {
227:             require $path;
228:         }
229:     }
230: 
231:     /**
232:      * {@inheritdoc}
233:      */
234:     public function bootstrap(PluginApplicationInterface $app)
235:     {
236:         $bootstrap = $this->getConfigPath() . 'bootstrap.php';
237:         if (file_exists($bootstrap)) {
238:             require $bootstrap;
239:         }
240:     }
241: 
242:     /**
243:      * {@inheritdoc}
244:      */
245:     public function console($commands)
246:     {
247:         return $commands->addMany($commands->discoverPlugin($this->getName()));
248:     }
249: 
250:     /**
251:      * {@inheritdoc}
252:      */
253:     public function middleware($middleware)
254:     {
255:         return $middleware;
256:     }
257: }
258: 
Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs