Created
May 31, 2014 07:50
-
-
Save kenjis/e88d142e6db4849a9c2c to your computer and use it in GitHub Desktop.
BEAR.Sunday workshop https://github.com/BEARSunday/bearsunday.github.io/wiki/workshop
This file contains hidden or 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 | |
namespace Koriym\Work\Resource\App; | |
use BEAR\Resource\ResourceObject; | |
use Psr\Log\LoggerInterface; | |
use Ray\Di\Di\Inject; | |
class Add extends ResourceObject | |
{ | |
private $logger; | |
/** | |
* @inject | |
*/ | |
public function __construct(LoggerInterface $logger) | |
{ | |
$this->logger = $logger; | |
} | |
public function onGet($a, $b) | |
{ | |
$this['result'] = $a + $b; | |
$this->logger->debug(sprintf('%d + %d = %d', $a, $b, $this['result'])); | |
return $this; | |
} | |
} |
This file contains hidden or 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 | |
namespace Koriym\Work\Module; | |
use BEAR\Package\Module\Package\StandardPackageModule; | |
use Ray\Di\AbstractModule; | |
use Ray\Di\Di\Inject; | |
use Ray\Di\Di\Named; | |
use Ray\Di\Di\Scope; | |
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')->toProvider('Koriym\Work\Provider\MonologLoggerProvider')->in(Scope::SINGLETON); | |
// 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 hidden or 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 | |
namespace Koriym\Work\Provider; | |
use Monolog\Handler\StreamHandler; | |
use Monolog\Logger; | |
use Ray\Di\ProviderInterface; | |
class MonologLoggerProvider implements ProviderInterface | |
{ | |
use \BEAR\Sunday\Inject\LogDirInject; | |
public function get() | |
{ | |
$log = new Logger('monolog'); | |
$log->pushHandler(new StreamHandler($this->logDir.'/debug.log', Logger::DEBUG)); | |
return $log; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment