22namespace Codeception \Lib \Connector ;
33
44use Codeception \Lib \Connector \Laravel5 \ExceptionHandlerDecorator ;
5- use Codeception \Lib \Connector \Shared \LaravelCommon ;
65use Codeception \Stub ;
76use Illuminate \Database \Eloquent \Model ;
87use Illuminate \Foundation \Application ;
@@ -19,7 +18,25 @@ class_alias('Symfony\Component\HttpKernel\Client', 'Symfony\Component\HttpKernel
1918
2019class 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}
0 commit comments