public function testAlias()
 {
     $container = new \League\Container\Container();
     $container->add('config', ['directions' => ['default' => []]]);
     $container->addServiceProvider('Laasti\\Directions\\Providers\\LeagueDirectionsProvider');
     $this->assertInstanceOf('Laasti\\Directions\\Router', $container->get('directions.routers.default'));
     $this->assertInstanceOf('Laasti\\Directions\\Router', $container->get('Laasti\\Directions\\RouterInterface'));
 }
Exemple #2
0
 public function __construct()
 {
     $routes = (require_once base_path() . '/routes.php');
     $container = new \League\Container\Container();
     $container->add('Application');
     $this->router = new \League\Route\RouteCollection($container);
     foreach ($routes as $route) {
         $this->router->addRoute($route['method'], $route['url'], $route['controller']);
     }
 }
 /**
  * Построение join-ов
  * 
  * @todo добавить типы связей 
  * has_many - один к многим (пост и коммеентарии)
  * belongs_to - многие к многим (пользователь имет множество оплат одного заказа)
  * has_one - один к одному
  */
 protected function setRelations(ISpecificationCriteria $Specification)
 {
     $joins = [];
     foreach ($this->mapping_fields as $field => $cfg) {
         if (isset($cfg['relation'])) {
             $reltype = isset($cfg['reltype']) ? $cfg['reltype'] : 'belongs_to';
             $this->relations[$field] = ['mapper' => $mapper = $this->DI->get($cfg['relation']), 'reltype' => $reltype];
             $table = $mapper->getEntityTable();
             $relation_key = isset($cfg['on']) ? $cfg['on'] : $mapper->key;
             $joins[$table] = ['alias' => $field, 'type' => $reltype != 'has_many' ? 'INNER' : 'LEFT OUTER', 'on' => "`{$this->table}`.{$cfg['field']} = `{$field}`.{$relation_key}"];
         }
     }
     if ($this->use_joins === true) {
         $Specification->setJoins($joins);
     }
 }
Exemple #4
0
 public function testContainerResolver()
 {
     $container = new \League\Container\Container();
     $middleware = $this->getMock('Laasti\\Stack\\Middleware\\PrepareableInterface');
     $middleware2 = $this->getMock('Laasti\\Stack\\Middleware\\PrepareableInterface');
     $resolver = new Stack\ContainerResolver($container, $middleware);
     $container->add('MyMiddleware', $middleware);
     $stack = new Stack\Stack($resolver);
     //Use key from container
     $stack->push('MyMiddleware');
     //Should still work
     $stack->push($middleware2);
     $responseMessage = 'Test response';
     $this->expectOutputString($responseMessage);
     $middleware->expects($this->exactly(1))->method('prepare')->will($this->returnValue(new Response($responseMessage)));
     $middleware2->expects($this->exactly(0))->method('prepare')->will($this->returnValue(new Response($responseMessage)));
     $stack->execute(new Request());
 }
Exemple #5
0
<?php

// Inversion of Control: Register services to the dependency injection container
$container = new \League\Container\Container();
$container->share('ArticlesRepository', '\\FizzBuzz\\Service\\ArticlesRepository');
$container->share('SectionsRepository', '\\FizzBuzz\\Service\\SectionsRepository');
return $container;
Exemple #6
0
 /**
  * @return Container
  */
 public static function forge()
 {
     $container = new \League\Container\Container();
     $container->delegate(new ReflectionContainer());
     return new self($container);
 }
<?php

$container = new League\Container\Container();
$container->delegate(new League\Container\ReflectionContainer());
$container->addServiceProvider(Demo7\Support\AuthenticationServiceProvider::class);
$container->addServiceProvider(Demo7\Support\RouterServiceProvider::class);
return $container;
Exemple #8
0
<?php

$app = new \League\Container\Container();
$app->share('paths', function () {
    return ['root' => __DIR__ . '/..', 'app' => __DIR__, 'public' => __DIR__ . '/../httpdocs', 'config' => __DIR__ . '/config.php', 'views' => __DIR__ . '/Views', 'storage' => __DIR__ . '/../temp', 'log' => __DIR__ . '/../log', 'routes' => __DIR__ . '/routes.php', 'listeners' => __DIR__ . '/listeners.php', 'commands' => __DIR__ . '/commands.php', 'version' => __DIR__ . '/../version.json'];
});
$providers = [new App\Provider\RequestProvider(), new App\Provider\ConfigProvider(), new App\Provider\DBProvider(), new App\Provider\RouterProvider(), new App\Provider\ViewProvider(), new App\Provider\DispatchProvider(), new App\Provider\ControllerResolverProvider(), new App\Provider\CommandProvider(), new App\Provider\AppProvider(), new App\Provider\EventProvider(), new App\Provider\SessionProvider()];
array_walk($providers, function ($provider) use($app) {
    $provider->register($app);
});
return $app;
<?php

$container = new League\Container\Container();
$container->singleton('A');
//trigger all autoloaders
$b = $container->get('B');
unset($b);
$t1 = microtime(true);
for ($i = 0; $i < 10000; $i++) {
    $a = $container->get('B');
}
$t2 = microtime(true);
$results = ['time' => $t2 - $t1, 'files' => count(get_included_files()), 'memory' => memory_get_peak_usage() / 1024 / 1024];
echo json_encode($results);
<?php

//Trigger all autoloaders
$container = new League\Container\Container();
$a = $container->get('J');
unset($a);
$t1 = microtime(true);
for ($i = 0; $i < 10000; $i++) {
    $a = $container->get('J');
}
$t2 = microtime(true);
$results = ['time' => $t2 - $t1, 'files' => count(get_included_files()), 'memory' => memory_get_peak_usage() / 1024 / 1024];
echo json_encode($results);
<?php

$container = new League\Container\Container();
//trigger all autoloaders
$a = $container->get('A');
unset($a);
$t1 = microtime(true);
for ($i = 0; $i < 10000; $i++) {
    $a = $container->get('A');
}
$t2 = microtime(true);
$results = ['time' => $t2 - $t1, 'files' => count(get_included_files()), 'memory' => memory_get_peak_usage() / 1024 / 1024];
echo json_encode($results);
Exemple #12
0
<?php

// Inversion of Control: Register services to the dependency injection container
$container = new \League\Container\Container();
$container->share('ArticlesRepository', '\\FizzBuzz\\Service\\ArticlesRepository');
$container->share('SectionsRepository', '\\FizzBuzz\\Service\\SectionsRepository');
$container->share('Renderer', function () use($container) {
    $tpl = new \FizzBuzz\Renderer();
    $tpl->container = $container;
    return $tpl;
});
$container->share('Menu', function () use($container) {
    $menu = new \FizzBuzz\Service\Menu($container);
    return $menu;
});
$container->share('Router', function () use($router) {
    return $router;
});
return $container;
Exemple #13
0
<?php

require_once __DIR__ . '/vendor/autoload.php';
add_theme_support('html5', array('search-form', 'comment-form', 'comment-list', 'gallery', 'caption'));
/**
 * Register language file
 */
add_action('after_setup_theme', function () {
    load_theme_textdomain('jets', get_template_directory() . '/languages');
});
/**
 * Set DI container
 */
$jets_container = new League\Container\Container();
/**
 * Register theme config
 */
$jets_container->share('config', function () {
    $path = __DIR__ . '/config/config.yaml';
    return new \Jets\Config($path);
});
/**
 * Register assets enqueuer
 */
$jets_container->share('enqueuer', function () use($jets_container) {
    $config = $jets_container->get('config');
    return new \Jets\Enqueuer($config);
});
/**
 * Register menus manager
 */
<?php

$container = new League\Container\Container();
/* Response */
$container->share('response', \Zend\Diactoros\Response::class);
/* Request */
$container->share('request', function () {
    return \Zend\Diactoros\ServerRequestFactory::fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);
});
/* Emitter */
$container->share('emitter', Zend\Diactoros\Response\SapiEmitter::class);
/* Template Engine */
$container->share('templater', function () {
    return new \League\Plates\Engine(__DIR__ . '/../resources/views');
});
/* Controllers */
$container->add(\Gulchuk\Controllers\Frontend\PageController::class)->withArguments(['request', 'response']);
$container->add(\Gulchuk\Controllers\Frontend\BlogController::class)->withArguments(['request', 'response']);
$container->add(\Gulchuk\Controllers\AuthController::class)->withArguments(['request', 'response']);
$container->add(\Gulchuk\Controllers\Backend\DashboardController::class)->withArguments(['request', 'response']);
return $container;
<?php

$container = new League\Container\Container();
for ($i = 0; $i < $argv[1]; $i++) {
    $j = $container->get('J');
}
$results = ['time' => 0, 'files' => count(get_included_files()), 'memory' => memory_get_peak_usage() / 1024 / 1024];
echo json_encode($results);