Browse Source

Split Application interface into console/web

Having separate interfaces allows each context to be used independently
or combined if needed.
Mark Story 8 years ago
parent
commit
b01aa36991

+ 5 - 4
src/Console/CommandRunner.php

@@ -20,7 +20,8 @@ use Cake\Console\ConsoleIo;
 use Cake\Console\Exception\StopException;
 use Cake\Console\Shell;
 use Cake\Event\EventManagerTrait;
-use Cake\Core\ApplicationInterface;
+use Cake\Core\ConsoleApplicationInterface;
+use Cake\Core\HttpApplicationInterface;
 use Cake\Shell\HelpShell;
 use Cake\Shell\VersionShell;
 use RuntimeException;
@@ -35,7 +36,7 @@ class CommandRunner
     /**
      * The application console commands are being run for.
      *
-     * @var \Cake\Core\ApplicationInterface
+     * @var \Cake\Core\ConsoleApplicationInterface
      */
     protected $app;
 
@@ -56,10 +57,10 @@ class CommandRunner
     /**
      * Constructor
      *
-     * @param \Cake\Core\ApplicationInterface $app The application to run CLI commands for.
+     * @param \Cake\Core\ConsoleApplicationInterface $app The application to run CLI commands for.
      * @param string $root The root command name to be removed from argv.
      */
-    public function __construct(ApplicationInterface $app, $root = 'cake')
+    public function __construct(ConsoleApplicationInterface $app, $root = 'cake')
     {
         $this->app = $app;
         $this->root = $root;

+ 38 - 0
src/Core/ConsoleApplicationInterface.php

@@ -0,0 +1,38 @@
+<?php
+/**
+ * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
+ * Copyright 2005-2011, Cake Software Foundation, Inc. (https://cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
+ * @link          https://cakephp.org CakePHP(tm) Project
+ * @since         3.5.0
+ * @license       https://opensource.org/licenses/mit-license.php MIT License
+ */
+namespace Cake\Core;
+
+/**
+ * An interface defining the methods that the
+ * console runner depend on.
+ */
+interface ConsoleApplicationInterface
+{
+    /**
+     * Load all the application configuration and bootstrap logic.
+     *
+     * Override this method to add additional bootstrap logic for your application.
+     *
+     * @return void
+     */
+    public function bootstrap();
+
+    /**
+     * Define the console commands for an application.
+     *
+     * @param \Cake\Console\CommandCollection $commands The CommandCollection to add commands into.
+     * @return \Cake\Console\CommandCollection The updated collection.
+     */
+    public function console($commands);
+}

+ 2 - 10
src/Core/ApplicationInterface.php

@@ -15,9 +15,9 @@ namespace Cake\Core;
 
 /**
  * An interface defining the methods that the
- * console runner/http server depend on.
+ * http server depend on.
  */
-interface ApplicationInterface
+interface HttpApplicationInterface
 {
     /**
      * Load all the application configuration and bootstrap logic.
@@ -39,14 +39,6 @@ interface ApplicationInterface
     public function routes($routes);
 
     /**
-     * Define the console commands for an application.
-     *
-     * @param \Cake\Console\CommandCollection $commands The CommandCollection to add commands into.
-     * @return \Cake\Console\CommandCollection The updated collection.
-     */
-    public function console($commands);
-
-    /**
      * Define the HTTP middleware layers for an application.
      *
      * @param \Cake\Http\MiddlewareQueue $middleware The middleware queue to set in your App Class

+ 3 - 2
src/Http/BaseApplication.php

@@ -14,7 +14,8 @@
  */
 namespace Cake\Http;
 
-use Cake\Core\ApplicationInterface;
+use Cake\Core\ConsoleApplicationInterface;
+use Cake\Core\HttpApplicationInterface;
 use Cake\Routing\DispatcherFactory;
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
@@ -26,7 +27,7 @@ use Psr\Http\Message\ServerRequestInterface;
  * and ensuring that middleware is attached. It is also invoked as the last piece
  * of middleware, and delegates request/response handling to the correct controller.
  */
-abstract class BaseApplication implements ApplicationInterface
+abstract class BaseApplication implements ConsoleApplicationInterface, HttpApplicationInterface
 {
 
     /**

+ 6 - 6
src/Http/Server.php

@@ -14,7 +14,7 @@
  */
 namespace Cake\Http;
 
-use Cake\Core\ApplicationInterface;
+use Cake\Core\HttpApplicationInterface;
 use Cake\Event\EventDispatcherTrait;
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
@@ -30,7 +30,7 @@ class Server
     use EventDispatcherTrait;
 
     /**
-     * @var \Cake\Core\ApplicationInterface
+     * @var \Cake\Core\HttpApplicationInterface
      */
     protected $app;
 
@@ -42,9 +42,9 @@ class Server
     /**
      * Constructor
      *
-     * @param \Cake\Core\ApplicationInterface $app The application to use.
+     * @param \Cake\Core\HttpApplicationInterface $app The application to use.
      */
-    public function __construct(ApplicationInterface $app)
+    public function __construct(HttpApplicationInterface $app)
     {
         $this->setApp($app);
         $this->setRunner(new Runner());
@@ -109,10 +109,10 @@ class Server
     /**
      * Set the application.
      *
-     * @param Cake\Core\ApplicationInterface $app The application to set.
+     * @param Cake\Core\HttpApplicationInterface $app The application to set.
      * @return $this
      */
-    public function setApp(ApplicationInterface $app)
+    public function setApp(HttpApplicationInterface $app)
     {
         $this->app = $app;