Skip to content

Commit 1cd28f7

Browse files
committed
Merged LaravelCommon traits to Laravel5 module
1 parent 9026ae0 commit 1cd28f7

File tree

4 files changed

+240
-266
lines changed

4 files changed

+240
-266
lines changed

src/Codeception/Lib/Connector/Laravel5.php

Lines changed: 128 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
namespace Codeception\Lib\Connector;
33

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

2019
class Laravel5 extends Client
2120
{
22-
use LaravelCommon;
21+
/**
22+
* @var array
23+
*/
24+
private $bindings = [];
25+
26+
/**
27+
* @var array
28+
*/
29+
private $contextualBindings = [];
30+
31+
/**
32+
* @var array
33+
*/
34+
private $instances = [];
35+
36+
/**
37+
* @var array
38+
*/
39+
private $applicationHandlers = [];
2340

2441
/**
2542
* @var Application
@@ -356,4 +373,113 @@ public function disableMiddleware()
356373
$this->middlewareDisabled = true;
357374
$this->app->instance('middleware.disable', true);
358375
}
376+
377+
/**
378+
* Apply the registered application handlers.
379+
*/
380+
private function applyApplicationHandlers()
381+
{
382+
foreach ($this->applicationHandlers as $handler) {
383+
call_user_func($handler, $this->app);
384+
}
385+
}
386+
387+
/**
388+
* Apply the registered Laravel service container bindings.
389+
*/
390+
private function applyBindings()
391+
{
392+
foreach ($this->bindings as $abstract => $binding) {
393+
list($concrete, $shared) = $binding;
394+
395+
$this->app->bind($abstract, $concrete, $shared);
396+
}
397+
}
398+
399+
/**
400+
* Apply the registered Laravel service container contextual bindings.
401+
*/
402+
private function applyContextualBindings()
403+
{
404+
foreach ($this->contextualBindings as $concrete => $bindings) {
405+
foreach ($bindings as $abstract => $implementation) {
406+
$this->app->addContextualBinding($concrete, $abstract, $implementation);
407+
}
408+
}
409+
}
410+
411+
/**
412+
* Apply the registered Laravel service container instance bindings.
413+
*/
414+
private function applyInstances()
415+
{
416+
foreach ($this->instances as $abstract => $instance) {
417+
$this->app->instance($abstract, $instance);
418+
}
419+
}
420+
421+
//======================================================================
422+
// Public methods called by module
423+
//======================================================================
424+
425+
/**
426+
* Register a Laravel service container binding that should be applied
427+
* after initializing the Laravel Application object.
428+
*
429+
* @param $abstract
430+
* @param $concrete
431+
* @param bool $shared
432+
*/
433+
public function haveBinding($abstract, $concrete, $shared = false)
434+
{
435+
$this->bindings[$abstract] = [$concrete, $shared];
436+
}
437+
438+
/**
439+
* Register a Laravel service container contextual binding that should be applied
440+
* after initializing the Laravel Application object.
441+
*
442+
* @param $concrete
443+
* @param $abstract
444+
* @param $implementation
445+
*/
446+
public function haveContextualBinding($concrete, $abstract, $implementation)
447+
{
448+
if (! isset($this->contextualBindings[$concrete])) {
449+
$this->contextualBindings[$concrete] = [];
450+
}
451+
452+
$this->contextualBindings[$concrete][$abstract] = $implementation;
453+
}
454+
455+
/**
456+
* Register a Laravel service container instance binding that should be applied
457+
* after initializing the Laravel Application object.
458+
*
459+
* @param $abstract
460+
* @param $instance
461+
*/
462+
public function haveInstance($abstract, $instance)
463+
{
464+
$this->instances[$abstract] = $instance;
465+
}
466+
467+
/**
468+
* Register a handler than can be used to modify the Laravel application object after it is initialized.
469+
* The Laravel application object will be passed as an argument to the handler.
470+
*
471+
* @param $handler
472+
*/
473+
public function haveApplicationHandler($handler)
474+
{
475+
$this->applicationHandlers[] = $handler;
476+
}
477+
478+
/**
479+
* Clear the registered application handlers.
480+
*/
481+
public function clearApplicationHandlers()
482+
{
483+
$this->applicationHandlers = [];
484+
}
359485
}

src/Codeception/Lib/Connector/Shared/LaravelCommon.php

Lines changed: 0 additions & 139 deletions
This file was deleted.

0 commit comments

Comments
 (0)