private function getConnection()
 {
     $dir = __DIR__;
     $config = "driver=pdo_sqlite&path={$dir}/../var/db/todo.sqlite3";
     $injector = new Injector(new DbalModule($config));
     return $injector->getInstance(Connection::class);
 }
 /**
  * @test
  */
 public function test_rollbacking_nested_transaction()
 {
     $dir = __DIR__;
     $config = "driver=pdo_sqlite&path={$dir}/../var/db/todo.sqlite3";
     $injector = new Injector(new TestModule($config));
     $annotation = new Transactional();
     $annotation->txType = TransactionScope::REQUIRES_NEW;
     $trans = new DbalTransaction($injector->getInstance(Connection::class), $annotation);
     $scope = new TransactionScope($trans, $annotation);
     $model = $injector->getInstance(TodoModel::class);
     $scope->runInto(function () use($model) {
         $this->assertTrue($model->select(999) === false);
         $this->assertTrue($model->select(888) === false);
         try {
             $model->insertRecordAllowingNestedTransaction(999, 'test memo');
             $model->insertFailAllowingNestedTransaction(888, 'failed', function ($m) {
                 $row = $m->select(888);
                 $this->assertFalse($row === false);
                 $this->assertEquals(888, $row['id']);
                 $this->assertEquals('failed', $row['todo']);
             });
         } catch (\LogicException $ex) {
         }
         $row = $model->select(999);
         $this->assertFalse($row === false);
         $this->assertEquals(999, $row['id']);
         $this->assertEquals('test memo', $row['todo']);
         // For latter transaction, Rollback is not executed.
         $this->assertTrue($model->select(888) === false);
     });
     $row = $model->select(999);
     $this->assertFalse($row === false);
     $this->assertEquals(999, $row['id']);
     $this->assertEquals('test memo', $row['todo']);
     // For latter transaction, Rollback is not executed.
     $this->assertTrue($model->select(888) === false);
 }
예제 #3
0
use Ray\Di\ApcConfig;
use Ray\Di\Annotation;
use Ray\Di\Definition;
use Doctrine\Common\Annotations\AnnotationReader;
use BEAR\Package\Exception\InvalidMode;
// init
umask(0);
// mode
$mode = isset($mode) ? $mode : 'Prod';
// cached application ?
$cacheKey = __NAMESPACE__ . PHP_SAPI . $mode;
// load
require_once __DIR__ . '/load.php';
$app = apc_fetch($cacheKey);
if ($app) {
    return $app;
}
$moduleName = __NAMESPACE__ . '\\Module\\' . $mode . 'Module';
if (!class_exists($moduleName)) {
    throw new InvalidMode("Invalid mode [{$mode}], check [{$moduleName}]");
}
// create application object
$injector = new Injector(new Container(new Forge(new ApcConfig(new Annotation(new Definition(), new AnnotationReader())))), new $moduleName());
$app = $injector->getInstance('BEAR\\Sunday\\Application\\Context');
// log binding info
$logFile = dirname(__DIR__) . "/data/log/module.{$cacheKey}.log";
file_put_contents($logFile, (string) $injector);
// store
apc_store($cacheKey, $app);
apc_store($cacheKey . '-injector', $injector);
return $app;
예제 #4
0
use Task\Project;
$defaultModule = new DefaultModule();
$injector = new Injector($defaultModule);
$project = new Project('photo_organize');
/**
 * @param OutputInterface $output
 * @return \Rx\Observer\CallbackObserver
 */
function outputObserver(OutputInterface $output)
{
    return new Rx\Observer\CallbackObserver(function ($value) use($output) {
        $time = date("Y-m-d H:i:s");
        $output->writeln("{$time} | {$value}");
    }, function (Exception $error) use($output) {
        $output->writeln(date("Y-m-d H:i:s") . " | Exception: " . $error->getMessage());
    }, function () use($output) {
        $output->writeln(date("Y-m-d H:i:s") . " | Complete!");
    });
}
$project->addTask('symlink', function () use($injector) {
    $targetDir = $this->getInput()->getOption('symlink_dst');
    $sourceDir = $this->getInput()->getOption('symlink_src');
    $verbose = $this->getInput()->getOption('verbose');
    /** @var SymlinkUseCase $useCase */
    $useCase = $injector->getInstance(SymlinkUseCase::class);
    $useCase->getOutput()->subscribe(outputObserver($this->getOutput()));
    /* @var SymlinkUseCase $useCase */
    $useCase->execute($sourceDir, $targetDir, $this->getInput()->getOption('dryrun'));
})->addOption('symlink_dst', 'd', InputOption::VALUE_REQUIRED, "Directory to create symlinks in")->addOption('symlink_src', 's', InputOption::VALUE_REQUIRED, "Directory to recurse for media files")->addOption('dryrun', 'x', InputOption::VALUE_NONE, "Preview the resulting structure");
# Return the project!
return $project;
 public function testBindApp()
 {
     $actual = $this->injector->getInstance('BEAR\\Sunday\\Extension\\Application\\AppInterface');
     $this->assertInstanceOf('My\\Hello\\App', $actual);
 }