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.7 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.7
      • 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:     /**
 29:      * Do bootstrapping or not
 30:      *
 31:      * @var bool
 32:      */
 33:     protected $bootstrapEnabled = true;
 34: 
 35:     /**
 36:      * Load routes or not
 37:      *
 38:      * @var bool
 39:      */
 40:     protected $routesEnabled = true;
 41: 
 42:     /**
 43:      * Enable middleware
 44:      *
 45:      * @var bool
 46:      */
 47:     protected $middlewareEnabled = true;
 48: 
 49:     /**
 50:      * Console middleware
 51:      *
 52:      * @var bool
 53:      */
 54:     protected $consoleEnabled = true;
 55: 
 56:     /**
 57:      * The path to this plugin.
 58:      *
 59:      * @var string
 60:      */
 61:     protected $path;
 62: 
 63:     /**
 64:      * The class path for this plugin.
 65:      *
 66:      * @var string
 67:      */
 68:     protected $classPath;
 69: 
 70:     /**
 71:      * The config path for this plugin.
 72:      *
 73:      * @var string
 74:      */
 75:     protected $configPath;
 76: 
 77:     /**
 78:      * The name of this plugin
 79:      *
 80:      * @var string
 81:      */
 82:     protected $name;
 83: 
 84:     /**
 85:      * Constructor
 86:      *
 87:      * @param array $options Options
 88:      */
 89:     public function __construct(array $options = [])
 90:     {
 91:         foreach (static::VALID_HOOKS as $key) {
 92:             if (isset($options[$key])) {
 93:                 $this->{"{$key}Enabled"} = (bool)$options[$key];
 94:             }
 95:         }
 96:         foreach (['name', 'path', 'classPath', 'configPath'] as $path) {
 97:             if (isset($options[$path])) {
 98:                 $this->{$path} = $options[$path];
 99:             }
100:         }
101: 
102:         $this->initialize();
103:     }
104: 
105:     /**
106:      * {@inheritdoc}
107:      */
108:     public function initialize()
109:     {
110:     }
111: 
112:     /**
113:      * {@inheritDoc}
114:      */
115:     public function getName()
116:     {
117:         if ($this->name) {
118:             return $this->name;
119:         }
120:         $parts = explode('\\', get_class($this));
121:         array_pop($parts);
122:         $this->name = implode('/', $parts);
123: 
124:         return $this->name;
125:     }
126: 
127:     /**
128:      * {@inheritDoc}
129:      */
130:     public function getPath()
131:     {
132:         if ($this->path) {
133:             return $this->path;
134:         }
135:         $reflection = new ReflectionClass($this);
136:         $path = dirname($reflection->getFileName());
137: 
138:         // Trim off src
139:         if (substr($path, -3) === 'src') {
140:             $path = substr($path, 0, -3);
141:         }
142:         $this->path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
143: 
144:         return $this->path;
145:     }
146: 
147:     /**
148:      * {@inheritDoc}
149:      */
150:     public function getConfigPath()
151:     {
152:         if ($this->configPath) {
153:             return $this->configPath;
154:         }
155:         $path = $this->getPath();
156: 
157:         return $path . 'config' . DIRECTORY_SEPARATOR;
158:     }
159: 
160:     /**
161:      * {@inheritDoc}
162:      */
163:     public function getClassPath()
164:     {
165:         if ($this->classPath) {
166:             return $this->classPath;
167:         }
168:         $path = $this->getPath();
169: 
170:         return $path . 'src' . DIRECTORY_SEPARATOR;
171:     }
172: 
173:     /**
174:      * {@inheritdoc}
175:      */
176:     public function enable($hook)
177:     {
178:         $this->checkHook($hook);
179:         $this->{"{$hook}Enabled}"} = true;
180: 
181:         return $this;
182:     }
183: 
184:     /**
185:      * {@inheritdoc}
186:      */
187:     public function disable($hook)
188:     {
189:         $this->checkHook($hook);
190:         $this->{"{$hook}Enabled"} = false;
191: 
192:         return $this;
193:     }
194: 
195:     /**
196:      * {@inheritdoc}
197:      */
198:     public function isEnabled($hook)
199:     {
200:         $this->checkHook($hook);
201: 
202:         return $this->{"{$hook}Enabled"} === true;
203:     }
204: 
205:     /**
206:      * Check if a hook name is valid
207:      *
208:      * @param string $hook The hook name to check
209:      * @throws \InvalidArgumentException on invalid hooks
210:      * @return void
211:      */
212:     protected function checkHook($hook)
213:     {
214:         if (!in_array($hook, static::VALID_HOOKS)) {
215:             throw new InvalidArgumentException(
216:                 "`$hook` is not a valid hook name. Must be one of " . implode(', ', static::VALID_HOOKS)
217:             );
218:         }
219:     }
220: 
221:     /**
222:      * {@inheritdoc}
223:      */
224:     public function routes($routes)
225:     {
226:         $path = $this->getConfigPath() . 'routes.php';
227:         if (file_exists($path)) {
228:             require $path;
229:         }
230:     }
231: 
232:     /**
233:      * {@inheritdoc}
234:      */
235:     public function bootstrap(PluginApplicationInterface $app)
236:     {
237:         $bootstrap = $this->getConfigPath() . 'bootstrap.php';
238:         if (file_exists($bootstrap)) {
239:             require $bootstrap;
240:         }
241:     }
242: 
243:     /**
244:      * {@inheritdoc}
245:      */
246:     public function console($commands)
247:     {
248:         return $commands->addMany($commands->discoverPlugin($this->getName()));
249:     }
250: 
251:     /**
252:      * {@inheritdoc}
253:      */
254:     public function middleware($middleware)
255:     {
256:         return $middleware;
257:     }
258: }
259: 
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