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

  • 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: 
 46:     use EventDispatcherTrait;
 47: 
 48:     /**
 49:      * @var string Contains the path of the config directory
 50:      */
 51:     protected $configDir;
 52: 
 53:     /**
 54:      * Plugin Collection
 55:      *
 56:      * @var \Cake\Core\PluginCollection
 57:      */
 58:     protected $plugins;
 59: 
 60:     /**
 61:      * Constructor
 62:      *
 63:      * @param string $configDir The directory the bootstrap configuration is held in.
 64:      * @param \Cake\Event\EventManagerInterface $eventManager Application event manager instance.
 65:      */
 66:     public function __construct($configDir, EventManagerInterface $eventManager = null)
 67:     {
 68:         $this->configDir = $configDir;
 69:         $this->plugins = Plugin::getCollection();
 70:         $this->_eventManager = $eventManager ?: EventManager::instance();
 71:     }
 72: 
 73:     /**
 74:      * @param \Cake\Http\MiddlewareQueue $middleware The middleware queue to set in your App Class
 75:      * @return \Cake\Http\MiddlewareQueue
 76:      */
 77:     abstract public function middleware($middleware);
 78: 
 79:     /**
 80:      * {@inheritDoc}
 81:      */
 82:     public function pluginMiddleware($middleware)
 83:     {
 84:         foreach ($this->plugins->with('middleware') as $plugin) {
 85:             $middleware = $plugin->middleware($middleware);
 86:         }
 87: 
 88:         return $middleware;
 89:     }
 90: 
 91:     /**
 92:      * {@inheritDoc}
 93:      */
 94:     public function addPlugin($name, array $config = [])
 95:     {
 96:         if (is_string($name)) {
 97:             $plugin = $this->makePlugin($name, $config);
 98:         } else {
 99:             $plugin = $name;
100:         }
101:         if (!$plugin instanceof PluginInterface) {
102:             throw new InvalidArgumentException(sprintf(
103:                 "The `%s` plugin does not implement Cake\Core\PluginInterface.",
104:                 get_class($plugin)
105:             ));
106:         }
107:         $this->plugins->add($plugin);
108: 
109:         return $this;
110:     }
111: 
112:     /**
113:      * Get the plugin collection in use.
114:      *
115:      * @return \Cake\Core\PluginCollection
116:      */
117:     public function getPlugins()
118:     {
119:         return $this->plugins;
120:     }
121: 
122:     /**
123:      * Create a plugin instance from a classname and configuration
124:      *
125:      * @param string $name The plugin classname
126:      * @param array $config Configuration options for the plugin
127:      * @return \Cake\Core\PluginInterface
128:      */
129:     protected function makePlugin($name, array $config)
130:     {
131:         $className = $name;
132:         if (strpos($className, '\\') === false) {
133:             $className = str_replace('/', '\\', $className) . '\\' . 'Plugin';
134:         }
135:         if (class_exists($className)) {
136:             return new $className($config);
137:         }
138: 
139:         if (!isset($config['path'])) {
140:             $config['path'] = $this->plugins->findPath($name);
141:         }
142:         $config['name'] = $name;
143: 
144:         return new BasePlugin($config);
145:     }
146: 
147:     /**
148:      * {@inheritDoc}
149:      */
150:     public function bootstrap()
151:     {
152:         require_once $this->configDir . '/bootstrap.php';
153:     }
154: 
155:     /**
156:      * {@inheritDoc}
157:      */
158:     public function pluginBootstrap()
159:     {
160:         foreach ($this->plugins->with('bootstrap') as $plugin) {
161:             $plugin->bootstrap($this);
162:         }
163:     }
164: 
165:     /**
166:      * {@inheritDoc}
167:      *
168:      * By default this will load `config/routes.php` for ease of use and backwards compatibility.
169:      *
170:      * @param \Cake\Routing\RouteBuilder $routes A route builder to add routes into.
171:      * @return void
172:      */
173:     public function routes($routes)
174:     {
175:         if (!Router::$initialized) {
176:             // Prevent routes from being loaded again
177:             Router::$initialized = true;
178: 
179:             require $this->configDir . '/routes.php';
180:         }
181:     }
182: 
183:     /**
184:      * {@inheritDoc}
185:      */
186:     public function pluginRoutes($routes)
187:     {
188:         foreach ($this->plugins->with('routes') as $plugin) {
189:             $plugin->routes($routes);
190:         }
191: 
192:         return $routes;
193:     }
194: 
195:     /**
196:      * Define the console commands for an application.
197:      *
198:      * By default all commands in CakePHP, plugins and the application will be
199:      * loaded using conventions based names.
200:      *
201:      * @param \Cake\Console\CommandCollection $commands The CommandCollection to add commands into.
202:      * @return \Cake\Console\CommandCollection The updated collection.
203:      */
204:     public function console($commands)
205:     {
206:         return $commands->addMany($commands->autoDiscover());
207:     }
208: 
209:     /**
210:      * {@inheritDoc}
211:      */
212:     public function pluginConsole($commands)
213:     {
214:         foreach ($this->plugins->with('console') as $plugin) {
215:             $commands = $plugin->console($commands);
216:         }
217: 
218:         return $commands;
219:     }
220: 
221:     /**
222:      * Invoke the application.
223:      *
224:      * - Convert the PSR response into CakePHP equivalents.
225:      * - Create the controller that will handle this request.
226:      * - Invoke the controller.
227:      *
228:      * @param \Psr\Http\Message\ServerRequestInterface $request The request
229:      * @param \Psr\Http\Message\ResponseInterface $response The response
230:      * @param callable $next The next middleware
231:      * @return \Psr\Http\Message\ResponseInterface
232:      */
233:     public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
234:     {
235:         return $this->getDispatcher()->dispatch($request, $response);
236:     }
237: 
238:     /**
239:      * Get the ActionDispatcher.
240:      *
241:      * @return \Cake\Http\ActionDispatcher
242:      */
243:     protected function getDispatcher()
244:     {
245:         return new ActionDispatcher(null, $this->getEventManager(), DispatcherFactory::filters());
246:     }
247: }
248: 
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