Skip to content

Commit

Permalink
Merged LaravelCommon traits to Laravel5 module
Browse files Browse the repository at this point in the history
  • Loading branch information
Naktibalda committed Oct 10, 2019
1 parent 9026ae0 commit 1cd28f7
Show file tree
Hide file tree
Showing 4 changed files with 240 additions and 266 deletions.
130 changes: 128 additions & 2 deletions src/Codeception/Lib/Connector/Laravel5.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
namespace Codeception\Lib\Connector;

use Codeception\Lib\Connector\Laravel5\ExceptionHandlerDecorator;
use Codeception\Lib\Connector\Shared\LaravelCommon;
use Codeception\Stub;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Application;
Expand All @@ -19,7 +18,25 @@ class_alias('Symfony\Component\HttpKernel\Client', 'Symfony\Component\HttpKernel

class Laravel5 extends Client
{
use LaravelCommon;
/**
* @var array
*/
private $bindings = [];

/**
* @var array
*/
private $contextualBindings = [];

/**
* @var array
*/
private $instances = [];

/**
* @var array
*/
private $applicationHandlers = [];

/**
* @var Application
Expand Down Expand Up @@ -356,4 +373,113 @@ public function disableMiddleware()
$this->middlewareDisabled = true;
$this->app->instance('middleware.disable', true);
}

/**
* Apply the registered application handlers.
*/
private function applyApplicationHandlers()
{
foreach ($this->applicationHandlers as $handler) {
call_user_func($handler, $this->app);
}
}

/**
* Apply the registered Laravel service container bindings.
*/
private function applyBindings()
{
foreach ($this->bindings as $abstract => $binding) {
list($concrete, $shared) = $binding;

$this->app->bind($abstract, $concrete, $shared);
}
}

/**
* Apply the registered Laravel service container contextual bindings.
*/
private function applyContextualBindings()
{
foreach ($this->contextualBindings as $concrete => $bindings) {
foreach ($bindings as $abstract => $implementation) {
$this->app->addContextualBinding($concrete, $abstract, $implementation);
}
}
}

/**
* Apply the registered Laravel service container instance bindings.
*/
private function applyInstances()
{
foreach ($this->instances as $abstract => $instance) {
$this->app->instance($abstract, $instance);
}
}

//======================================================================
// Public methods called by module
//======================================================================

/**
* Register a Laravel service container binding that should be applied
* after initializing the Laravel Application object.
*
* @param $abstract
* @param $concrete
* @param bool $shared
*/
public function haveBinding($abstract, $concrete, $shared = false)
{
$this->bindings[$abstract] = [$concrete, $shared];
}

/**
* Register a Laravel service container contextual binding that should be applied
* after initializing the Laravel Application object.
*
* @param $concrete
* @param $abstract
* @param $implementation
*/
public function haveContextualBinding($concrete, $abstract, $implementation)
{
if (! isset($this->contextualBindings[$concrete])) {
$this->contextualBindings[$concrete] = [];
}

$this->contextualBindings[$concrete][$abstract] = $implementation;
}

/**
* Register a Laravel service container instance binding that should be applied
* after initializing the Laravel Application object.
*
* @param $abstract
* @param $instance
*/
public function haveInstance($abstract, $instance)
{
$this->instances[$abstract] = $instance;
}

/**
* Register a handler than can be used to modify the Laravel application object after it is initialized.
* The Laravel application object will be passed as an argument to the handler.
*
* @param $handler
*/
public function haveApplicationHandler($handler)
{
$this->applicationHandlers[] = $handler;
}

/**
* Clear the registered application handlers.
*/
public function clearApplicationHandlers()
{
$this->applicationHandlers = [];
}
}
139 changes: 0 additions & 139 deletions src/Codeception/Lib/Connector/Shared/LaravelCommon.php

This file was deleted.

Loading

0 comments on commit 1cd28f7

Please sign in to comment.