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

  • ActionDispatcher
  • BaseApplication
  • Client
  • ControllerFactory
  • CorsBuilder
  • MiddlewareQueue
  • Response
  • ResponseEmitter
  • Runner
  • Server
  • ServerRequest
  • ServerRequestFactory
  • Session
  1: <?php
  2: /**
  3:  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4:  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5:  *
  6:  * Licensed under The MIT License
  7:  * For full copyright and license information, please see the LICENSE.txt
  8:  * Redistributions of files must retain the above copyright notice.
  9:  *
 10:  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 11:  * @link          https://cakephp.org CakePHP(tm) Project
 12:  * @since         3.3.0
 13:  * @license       https://opensource.org/licenses/mit-license.php MIT License
 14:  */
 15: namespace Cake\Http;
 16: 
 17: use Cake\Core\App;
 18: use Cake\Core\BasePlugin;
 19: use Cake\Core\ConsoleApplicationInterface;
 20: use Cake\Core\HttpApplicationInterface;
 21: use Cake\Core\Plugin;
 22: use Cake\Core\PluginApplicationInterface;
 23: use Cake\Core\PluginInterface;
 24: use Cake\Event\EventDispatcherTrait;
 25: use Cake\Event\EventManager;
 26: use Cake\Event\EventManagerInterface;
 27: use Cake\Routing\DispatcherFactory;
 28: use Cake\Routing\Router;
 29: use InvalidArgumentException;
 30: use Psr\Http\Message\ResponseInterface;
 31: use Psr\Http\Message\ServerRequestInterface;
 32: 
 33: /**
 34:  * Base class for application classes.
 35:  *
 36:  * The application class is responsible for bootstrapping the application,
 37:  * and ensuring that middleware is attached. It is also invoked as the last piece
 38:  * of middleware, and delegates request/response handling to the correct controller.
 39:  */
 40: abstract class BaseApplication implements
 41:     ConsoleApplicationInterface,
 42:     HttpApplicationInterface,
 43:     PluginApplicationInterface
 44: {
 45:     use EventDispatcherTrait;
 46: 
 47:     /**
 48:      * @var string Contains the path of the config directory
 49:      */
 50:     protected $configDir;
 51: 
 52:     /**
 53:      * Plugin Collection
 54:      *
 55:      * @var \Cake\Core\PluginCollection
 56:      */
 57:     protected $plugins;
 58: 
 59:     /**
 60:      * Constructor
 61:      *
 62:      * @param string $configDir The directory the bootstrap configuration is held in.
 63:      * @param \Cake\Event\EventManagerInterface $eventManager Application event manager instance.
 64:      */
 65:     public function __construct($configDir, EventManagerInterface $eventManager = null)
 66:     {
 67:         $this->configDir = $configDir;
 68:         $this->plugins = Plugin::getCollection();
 69:         $this->_eventManager = $eventManager ?: EventManager::instance();
 70:     }
 71: 
 72:     /**
 73:      * @param \Cake\Http\MiddlewareQueue $middleware The middleware queue to set in your App Class
 74:      * @return \Cake\Http\MiddlewareQueue
 75:      */
 76:     abstract public function middleware($middleware);
 77: 
 78:     /**
 79:      * {@inheritDoc}
 80:      */
 81:     public function pluginMiddleware($middleware)
 82:     {
 83:         foreach ($this->plugins->with('middleware') as $plugin) {
 84:             $middleware = $plugin->middleware($middleware);
 85:         }
 86: 
 87:         return $middleware;
 88:     }
 89: 
 90:     /**
 91:      * {@inheritDoc}
 92:      */
 93:     public function addPlugin($name, array $config = [])
 94:     {
 95:         if (is_string($name)) {
 96:             $plugin = $this->makePlugin($name, $config);
 97:         } else {
 98:             $plugin = $name;
 99:         }
100:         if (!$plugin instanceof PluginInterface) {
101:             throw new InvalidArgumentException(sprintf(
102:                 "The `%s` plugin does not implement Cake\Core\PluginInterface.",
103:                 get_class($plugin)
104:             ));
105:         }
106:         $this->plugins->add($plugin);
107: 
108:         return $this;
109:     }
110: 
111:     /**
112:      * Get the plugin collection in use.
113:      *
114:      * @return \Cake\Core\PluginCollection
115:      */
116:     public function getPlugins()
117:     {
118:         return $this->plugins;
119:     }
120: 
121:     /**
122:      * Create a plugin instance from a classname and configuration
123:      *
124:      * @param string $name The plugin classname
125:      * @param array $config Configuration options for the plugin
126:      * @return \Cake\Core\PluginInterface
127:      */
128:     protected function makePlugin($name, array $config)
129:     {
130:         $className = $name;
131:         if (strpos($className, '\\') === false) {
132:             $className = str_replace('/', '\\', $className) . '\\' . 'Plugin';
133:         }
134:         if (class_exists($className)) {
135:             return new $className($config);
136:         }
137: 
138:         if (!isset($config['path'])) {
139:             $config['path'] = $this->plugins->findPath($name);
140:         }
141:         $config['name'] = $name;
142: 
143:         return new BasePlugin($config);
144:     }
145: 
146:     /**
147:      * {@inheritDoc}
148:      */
149:     public function bootstrap()
150:     {
151:         require_once $this->configDir . '/bootstrap.php';
152:     }
153: 
154:     /**
155:      * {@inheritDoc}
156:      */
157:     public function pluginBootstrap()
158:     {
159:         foreach ($this->plugins->with('bootstrap') as $plugin) {
160:             $plugin->bootstrap($this);
161:         }
162:     }
163: 
164:     /**
165:      * {@inheritDoc}
166:      *
167:      * By default this will load `config/routes.php` for ease of use and backwards compatibility.
168:      *
169:      * @param \Cake\Routing\RouteBuilder $routes A route builder to add routes into.
170:      * @return void
171:      */
172:     public function routes($routes)
173:     {
174:         if (!Router::$initialized) {
175:             // Prevent routes from being loaded again
176:             Router::$initialized = true;
177: 
178:             require $this->configDir . '/routes.php';
179:         }
180:     }
181: 
182:     /**
183:      * {@inheritDoc}
184:      */
185:     public function pluginRoutes($routes)
186:     {
187:         foreach ($this->plugins->with('routes') as $plugin) {
188:             $plugin->routes($routes);
189:         }
190: 
191:         return $routes;
192:     }
193: 
194:     /**
195:      * Define the console commands for an application.
196:      *
197:      * By default all commands in CakePHP, plugins and the application will be
198:      * loaded using conventions based names.
199:      *
200:      * @param \Cake\Console\CommandCollection $commands The CommandCollection to add commands into.
201:      * @return \Cake\Console\CommandCollection The updated collection.
202:      */
203:     public function console($commands)
204:     {
205:         return $commands->addMany($commands->autoDiscover());
206:     }
207: 
208:     /**
209:      * {@inheritDoc}
210:      */
211:     public function pluginConsole($commands)
212:     {
213:         foreach ($this->plugins->with('console') as $plugin) {
214:             $commands = $plugin->console($commands);
215:         }
216: 
217:         return $commands;
218:     }
219: 
220:     /**
221:      * Invoke the application.
222:      *
223:      * - Convert the PSR response into CakePHP equivalents.
224:      * - Create the controller that will handle this request.
225:      * - Invoke the controller.
226:      *
227:      * @param \Psr\Http\Message\ServerRequestInterface $request The request
228:      * @param \Psr\Http\Message\ResponseInterface $response The response
229:      * @param callable $next The next middleware
230:      * @return \Psr\Http\Message\ResponseInterface
231:      */
232:     public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
233:     {
234:         return $this->getDispatcher()->dispatch($request, $response);
235:     }
236: 
237:     /**
238:      * Get the ActionDispatcher.
239:      *
240:      * @return \Cake\Http\ActionDispatcher
241:      */
242:     protected function getDispatcher()
243:     {
244:         return new ActionDispatcher(null, $this->getEventManager(), DispatcherFactory::filters());
245:     }
246: }
247: 
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