-
-
Save hidenorigoto/1d12bdfc837f3f1f8baf to your computer and use it in GitHub Desktop.
bear diチャレンジ
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
<?php | |
// src/Module/AppModule.php | |
namespace Koriym\Work\Module; | |
use BEAR\Package\Module\Package\StandardPackageModule; | |
use Monolog\Handler\StreamHandler; | |
use Monolog\Logger; | |
use Ray\Di\AbstractModule; | |
use Ray\Di\Di\Inject; | |
use Ray\Di\Di\Named; | |
class AppModule extends AbstractModule | |
{ | |
/** | |
* @var string | |
*/ | |
private $context; | |
/** | |
* @param string $context | |
* | |
* @Inject | |
* @Named("app_context") | |
*/ | |
public function __construct($context = 'prod') | |
{ | |
$this->context = $context; | |
parent::__construct(); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
protected function configure() | |
{ | |
$this->install(new StandardPackageModule('Koriym\Work', $this->context, dirname(dirname(__DIR__)))); | |
$this->bind('Psr\Log\LoggerInterface')->to('Monolog\Logger'); | |
$this->bind('Monolog\Logger')->toConstructor(['name'=>'bear!', 'handlers'=>[new StreamHandler(__DIR__ . '/../../logs/debug.log', Logger::DEBUG)], 'processors'=>[]]); | |
// override module | |
// $this->install(new SmartyModule($this)); | |
// $this->install(new AuraViewModule($this)); | |
// install application dependency | |
// $this->install(new App\Dependency); | |
// install application aspect | |
// $this->install(new App\Aspect($this)); | |
} | |
} |
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
<?php | |
// src/Resource/Page/Calc.php | |
namespace Koriym\Work\Resource\Page; | |
use BEAR\Resource\ResourceObject; | |
use BEAR\Sunday\Inject\ResourceInject; | |
use Psr\Log\LoggerInterface; | |
use Ray\Di\Di\Inject; | |
class Calc extends ResourceObject | |
{ | |
use ResourceInject; | |
/** | |
* @var LoggerInterface | |
*/ | |
private $logger; | |
/** | |
* @Inject() | |
*/ | |
public function setLogger(LoggerInterface $logger) | |
{ | |
$this->logger = $logger; | |
} | |
public function onGet($a, $b) | |
{ | |
$add = $this->resource | |
->get | |
->uri('app://self/add') | |
->withQuery(['a' => $a, 'b' => $b]) | |
->request(); | |
$this['a'] = $a; | |
$this['b'] = $b; | |
$this['add'] = $add; | |
$this['test'] = get_class($this->logger); | |
$this->logger->debug('di'); | |
return $this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment