Skip to content

Instantly share code, notes, and snippets.

@kenjis
Created May 31, 2014 07:50
Show Gist options
  • Save kenjis/e88d142e6db4849a9c2c to your computer and use it in GitHub Desktop.
Save kenjis/e88d142e6db4849a9c2c to your computer and use it in GitHub Desktop.
<?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;
}
}
<?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));
}
}
<?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