-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from infoseci/for-upstream-contribution-latest-…
…changes Adding Cake 4 Support
- Loading branch information
Showing
9 changed files
with
104 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
namespace RochaMarcelo\CakePimpleDi\Middleware; | ||
|
||
use Cake\Http\Response; | ||
use Cake\Http\ServerRequest; | ||
use Psr\Http\Message\ResponseInterface; | ||
use RochaMarcelo\CakePimpleDi\Di\DiTrait; | ||
|
||
/** | ||
* Class ContainerizeRequestMiddleware | ||
* @package RochaMarcelo\Middleware | ||
* | ||
* When loaded this middleware provides a key 'request' and | ||
* a key for 'session' in the container. | ||
*/ | ||
class ContainerizeRequestMiddleware | ||
{ | ||
use DiTrait; | ||
|
||
/** | ||
* @param ServerRequest $request ServerRequest | ||
* @param Response $response Response | ||
* @param callable $next callable | ||
* @return ResponseInterface | ||
*/ | ||
public function __invoke(ServerRequest $request, Response $response, callable $next) | ||
{ | ||
$di = $this->di(); | ||
$di->set('request', $request); | ||
$di->set('session', $request->getSession()); | ||
|
||
$response = $next($request, $response); | ||
|
||
return $response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace RochaMarcelo\CakePimpleDi; | ||
|
||
use Cake\Core\BasePlugin; | ||
use Cake\Core\Configure; | ||
use Cake\Core\PluginApplicationInterface; | ||
use RochaMarcelo\CakePimpleDi\Di\Di; | ||
|
||
/** | ||
* Class Plugin | ||
* @package RochaMarcelo\CakePimpleDi | ||
*/ | ||
class Plugin extends BasePlugin | ||
{ | ||
public function getTemplatePath(): string | ||
{ | ||
return ''; | ||
} | ||
|
||
/** | ||
* @param PluginApplicationInterface $app | ||
*/ | ||
public function bootstrap(PluginApplicationInterface $app): void | ||
{ | ||
parent::bootstrap($app); // TODO: Change the autogenerated stub | ||
|
||
$config = Configure::consume('CakePimpleDi'); | ||
$scopes = []; | ||
if ( !isset($config['scopes']) ) { | ||
$scopes = [ | ||
'default' => (array)$config | ||
]; | ||
} | ||
|
||
foreach ( $scopes as $name => $config ) { | ||
$Di = Di::instance($name); | ||
|
||
$config = $config + [ | ||
'providers' => [] | ||
]; | ||
|
||
foreach ($config['providers'] as $provider ) { | ||
if ( is_string($provider) ) { | ||
$provider = new $provider; | ||
} | ||
|
||
$Di->register($provider); | ||
} | ||
|
||
if ( isset($config['services']) && is_array($config['services']) ) { | ||
$Di->setMany($config['services']); | ||
} | ||
} | ||
if (!empty($config['actionInjections'])) { | ||
\Cake\Event\EventManager::instance()->on(new \RochaMarcelo\CakePimpleDi\Event\ActionInjectionListener($config['actionInjections'])); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.