Skip to content

Instantly share code, notes, and snippets.

@hidenorigoto
Created May 31, 2014 07:31
Show Gist options
  • Save hidenorigoto/1d12bdfc837f3f1f8baf to your computer and use it in GitHub Desktop.
Save hidenorigoto/1d12bdfc837f3f1f8baf to your computer and use it in GitHub Desktop.
bear diチャレンジ
<?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));
}
}
<?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