Upgrade to Laravel 5.7
Diff
composer.json | 6 +-
public/wp-config.php | 70 ++++++++++++++++++++-
src/Providers/KoseligServiceProvider.php | 16 ++++-
src/Routing/Routing.php | 114 +++++++++++++++++++++++++-------
src/Routing/TemplateRoute.php | 5 +-
5 files changed, 184 insertions(+), 27 deletions(-)
@@ -9,9 +9,9 @@
}
],
"require": {
"illuminate/support": "^5.6",
"illuminate/database": "^5.6",
"illuminate/routing": "^5.6",
"illuminate/support": "^5.7",
"illuminate/database": "^5.7",
"illuminate/routing": "^5.7",
"watson/rememberable": "^2.0",
"cweagans/composer-patches": "^1.6"
},
@@ -0,0 +1,70 @@
<?php
// wp-config file to make the wordpress backend aware of our presence
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels nice to relax.
|
*/
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Facade;
require __DIR__ . '/../vendor/koselig/library/src/helpers.php';
require __DIR__ . '/../vendor/autoload.php';
/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/
$app = require_once __DIR__ . '/../bootstrap/app.php';
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$app->bootstrapWith([
\Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables::class,
\Illuminate\Foundation\Bootstrap\LoadConfiguration::class,
\Illuminate\Foundation\Bootstrap\HandleExceptions::class,
\Illuminate\Foundation\Bootstrap\RegisterFacades::class,
]);
$app->instance('request', Request::capture());
Facade::clearResolvedInstance('request');
// force the root url to whatever is set in the env file, stops wordpress taking over the root url
// when loading from wp-config.php
url()->forceRootUrl(config('app.url'));
$app->bootstrapWith([
Illuminate\Foundation\Bootstrap\RegisterProviders::class,
Illuminate\Foundation\Bootstrap\BootProviders::class,
]);
@@ -4,6 +4,7 @@ namespace Koselig\Providers;
use Illuminate\Support\ServiceProvider;
use Koselig\Auth\AuthServiceProvider;
use Koselig\Hashing\HashServiceProvider;
use Koselig\Http\Request;
use Koselig\Mail\WordpressMailServiceProvider;
use Koselig\Routing\RoutingServiceProvider;
@@ -21,6 +22,9 @@ class KoseligServiceProvider extends ServiceProvider
*/
public function register()
{
// override request() method to provide our Request
$this->app->alias('request', Request::class);
// Generic service providers
$this->app->register(WordpressMailServiceProvider::class);
$this->app->register(WordpressServiceProvider::class);
@@ -39,4 +43,16 @@ class KoseligServiceProvider extends ServiceProvider
// Hashing service provider
$this->app->register(HashServiceProvider::class);
}
/**
* Perform post-registration booting of services.
*
* @return void
*/
public function boot()
{
$this->publishes([
__DIR__ . '/../../public/wp-config.php' => public_path()
], 'public');
}
}
@@ -2,6 +2,7 @@
namespace Koselig\Routing;
use Illuminate\Container\Container;
use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Route;
class Routing
@@ -169,6 +170,57 @@ class Routing
}
/**
* Determine if the action is routing to a controller.
*
* @param array $action
* @return bool
*/
protected function actionReferencesController($action)
{
if (!$action instanceof \Closure) {
return is_string($action) || (isset($action['uses']) && is_string($action['uses']));
}
return false;
}
/**
* Prepend the last group namespace onto the use clause.
*
* @param string $class
* @return string
*/
protected function prependGroupNamespace($class)
{
$group = end($this->groupStack);
return isset($group['namespace']) && strpos($class, '\\') !== 0
? $group['namespace'].'\\'.$class : $class;
}
/**
* Add a controller based route action to the action array.
*
* @param array|string $action
* @return array
*/
protected function convertToControllerAction($action)
{
if (is_string($action)) {
$action = ['uses' => $action];
}
// Here we'll merge any group "uses" statement if necessary so that the action
// has the proper clause for this property. Then we can simply set the name
// of the controller on the action and return the action array for usage.
if (!empty($this->groupStack)) {
$action['uses'] = $this->prependGroupNamespace($action['uses']);
}
// Here we will set this controller name on the action array just so we always
// have a copy of it for reference if we need it. This can be used while we
// search for a controller name or do some other type of fetch operation.
$action['controller'] = $action['uses'];
return $action;
}
/**
* Format <pre>$action</pre> in a nice way to pass to the {@link \Illuminate\Routing\RouteCollection}.
*
* @param $action
@@ -177,20 +229,8 @@ class Routing
*/
protected function formatAction($action)
{
if (!($action instanceof $action) && (is_string($action) || (isset($action['uses'])
&& is_string($action['uses'])))) {
if (is_string($action)) {
$action = ['uses' => $action];
}
if (!empty($stack = Route::getGroupStack())) {
$group = end($stack);
$action['uses'] = isset($group['namespace']) && strpos($action['uses'], '\\') !== 0 ?
$group['namespace'] . '\\' . $action['uses'] : $action['uses'];
}
$action['controller'] = $action['uses'];
if ($this->actionReferencesController($action)) {
$action = $this->convertToControllerAction($action);
}
if (!is_array($action)) {
@@ -205,6 +245,41 @@ class Routing
}
/**
* Add the necessary where clauses to the route based on its initial registration.
*
* @param \Illuminate\Routing\Route $route
* @return \Illuminate\Routing\Route
*/
protected function addWhereClausesToRoute($route)
{
$route->where(array_merge(
Route::getPatterns(), $route->getAction()['where'] ?? []
));
return $route;
}
/**
* Determine if the router currently has a group stack.
*
* @return bool
*/
public function hasGroupStack()
{
return !empty($this->groupStack);
}
/**
* Merge the group stack with the controller action.
*
* @param \Illuminate\Routing\Route $route
* @return void
*/
protected function mergeGroupAttributesIntoRoute($route)
{
$route->setAction($this->mergeWithLastGroup($route->getAction()));
}
/**
* Apply group stack properties to the route and apply global "wheres" to the
* route.
*
@@ -217,15 +292,10 @@ class Routing
// If we have groups that need to be merged, we will merge them now after this
// route has already been created and is ready to go. After we're done with
// the merge we will be ready to return the route back out to the caller.
if (Route::hasGroupStack()) {
$action = Route::mergeWithLastGroup($route->getAction());
$route->setAction($action);
if ($this->hasGroupStack()) {
$this->mergeGroupAttributesIntoRoute($route);
}
$where = isset($route->getAction()['where']) ? $route->getAction()['where'] : [];
$route->where(array_merge(Route::getPatterns(), $where));
$this->addWhereClausesToRoute($route);
return $route;
}
@@ -2,7 +2,8 @@
namespace Koselig\Routing;
use Illuminate\Routing\Route;
use Koselig\Http\Request;
use Illuminate\Http\Request;
use Koselig\Http\Request as KoseligRequest;
use Koselig\Models\Post;
use Koselig\Support\Wordpress;
use ReflectionFunction;
@@ -41,7 +42,7 @@ class TemplateRoute extends Route
*/
public function matches(Request $request, $includingMethod = true)
{
$post = $request->page();
$post = $request instanceof KoseligRequest ? $request->page() : null;
if (!$post) {
// the page we are on either isn't in the CMS or doesn't have a template.