Example #1
0
 public function setUp()
 {
     $containerBuilder = new \DI\ContainerBuilder();
     $containerBuilder->addDefinitions([iConfig::class => \DI\object(Config::class)->constructor(require __DIR__ . '/../config/main.php')]);
     $this->_container = $containerBuilder->build();
     $this->init();
 }
 /**
  * PHP-DIのコンテナを初期化する。
  */
 protected function initializeContainer()
 {
     parent::initializeContainer();
     $builder = new \DI\ContainerBuilder();
     $builder->wrapContainer($this->getContainer());
     $builder->useAnnotations(true);
     $this->getContainer()->setFallbackContainer($builder->build());
 }
Example #3
0
 /**
  *
  */
 public static function init()
 {
     $builder = new \DI\ContainerBuilder();
     $builder->setDefinitionCache(new ApcCache());
     $builder->writeProxiesToFile(true, 'tmp/proxies');
     self::$container = $builder->build();
     self::$container->set('routeCollection', new RouteCollection());
 }
 /**
  * @param array $definitions
  *
  * @return \DI\Container
  */
 public static function build($definitions)
 {
     $builder = new \DI\ContainerBuilder();
     $builder->useAutowiring(false);
     $builder->useAnnotations(false);
     $builder->addDefinitions($definitions);
     return $builder->build();
 }
Example #5
0
 public function __construct()
 {
     $builder = new \DI\ContainerBuilder();
     $container = $builder->build();
     //Register Notification Implementation
     $container->set('Services_NotifyInterface', \DI\object('Services_TwitterNotify'));
     $this->_container = $container;
     return $container;
 }
Example #6
0
 protected function setUp()
 {
     $builder = new \DI\ContainerBuilder();
     $builder->useAnnotations(true);
     $builder->addDefinitions([Twig_Environment::class => function () {
         $loader = new Twig_Loader_Filesystem(realpath(__DIR__ . '/../../templates'));
         return new Twig_Environment($loader, array('cache' => 'test/template_cache', 'auto_reload' => true));
     }]);
     $this->router = new ControllerRouter($builder->build());
 }
Example #7
0
 public function __construct($api_key, $api_secret)
 {
     $builder = new \DI\ContainerBuilder();
     $di = $builder->build();
     $di->set('api_key', $api_key);
     $di->set('api_secret', $api_secret);
     $di->set('request', new Request());
     self::setDi($di);
     $this->initProperties();
 }
Example #8
0
function container($class)
{
    global $container;
    if (!$container) {
        $container = DI\ContainerBuilder::buildDevContainer();
    }
    return $container->get($class);
}
Example #9
0
 public static function run($worker_id, $data)
 {
     $jobs = Config::getJobs();
     $job =& $jobs[$worker_id];
     if ($job === null) {
         var_dump($worker_id);
         return false;
     }
     $builder = new \DI\ContainerBuilder();
     // $builder->setDefinitionCache(new Doctrine\Common\Cache\RedisCache());
     $builder->writeProxiesToFile(true, 'tmp/proxies');
     // $builder->useAutowiring(false);
     $builder->useAnnotations(false);
     $builder->addDefinitions('diconfig.php');
     $container = $builder->build();
     // $dependencies = &$job['dependencies'];
     //
     // if ($dependencies !== null) {
     //     $dependencies_classes = explode(',',$dependencies);
     //     foreach($dependencies_classes  as $class) {
     //         $depend_jober = new $class($params);
     //         $params = $depend_jober->run();
     //         if ($params === false) {
     //             return false;
     //         }
     //     }
     // }
     $retries =& $job['retries'];
     $job_params =& $job['params'];
     $class =& $job['class'];
     $exec_count = 0;
     do {
         $result = $container->get($class)->run($data, $job_params);
         $exec_count++;
     } while ($result === false && $exec_count < $retries);
     if ($result === false) {
         $notify = Config::getNotify();
         switch ($notify['dispatch_mode']) {
             case 1:
                 break;
             case 2:
                 break;
         }
     }
 }
Example #10
0
}
if (is_file('Config.php')) {
    require 'Config.php';
} else {
    echo '<a href="/install.php">Please install Fraym.</a>';
    exit(0);
}
$classLoader = (require 'Vendor/autoload.php');
date_default_timezone_set(TIMEZONE);
define('CACHE_DI_PATH', 'Cache/DI');
define('CACHE_DOCTRINE_PROXY_PATH', 'Cache/DoctrineProxies');
define('JS_FOLDER', '/js');
define('CSS_FOLDER', '/css');
define('CONSOLIDATE_FOLDER', '/consolidated');
\Fraym\Cache\Cache::createCacheFolders();
$builder = new \DI\ContainerBuilder();
$builder->useAnnotations(true);
if (\Fraym\Core::ENV_STAGING === ENV || \Fraym\Core::ENV_PRODUCTION === ENV) {
    error_reporting(-1);
    ini_set("display_errors", 0);
    $builder->writeProxiesToFile(true, CACHE_DI_PATH);
    define('GLOBAL_CACHING_ENABLED', true);
    $apcEnabled = (extension_loaded('apc') || extension_loaded('apcu')) && ini_get('apc.enabled');
} else {
    error_reporting(-1);
    ini_set("display_errors", 1);
    define('GLOBAL_CACHING_ENABLED', false);
    $apcEnabled = false;
}
define('APC_ENABLED', $apcEnabled);
if (defined('IMAGE_PROCESSOR') && IMAGE_PROCESSOR === 'Imagick') {
Example #11
0
<?php

/**
 * @author Deivid Fortuna <*****@*****.**>
 *
 */
ob_start();
error_reporting(E_ALL);
ini_set('display_errors', 1);
date_default_timezone_set('America/Sao_Paulo');
$root = dirname($_SERVER["PHP_SELF"]) == DIRECTORY_SEPARATOR ? "" : dirname($_SERVER["PHP_SELF"]);
define("ROOT", $root . '/');
define('DIR_ROOT', __DIR__ . DIRECTORY_SEPARATOR);
header("Content-type: text/html;charset=utf-8");
// Configura o sistema
require_once 'src/Brain/Constants.php';
require __DIR__ . '/vendor/autoload.php';
$container = DI\ContainerBuilder::buildDevContainer();
$Brain = $container->get("Brain\\System");
$Brain->wake();
Example #12
0
    }
}
class Body
{
}
class Document
{
    /**
     * @Inject
     * @var Head
     */
    private $head;
    private $body;
    /**
     * @Inject
     * @param Body $body
     */
    public function setBody($body)
    {
        $this->body = $body;
    }
}
// create a container instance
$builder = new DI\ContainerBuilder();
$builder->useAutowiring(false);
$builder->useAnnotations(true);
$builder->addDefinitions(['firstName' => 'Adrian', 'lastName' => 'Pietka']);
$container = $builder->build();
// get instance of Document class
$document = $container->get('Document');
var_dump($document);
Example #13
0
<?php

require "../vendor/autoload.php";
$builder = new \DI\ContainerBuilder();
$container = $builder->addDefinitions("container-definition.php")->buildDevContainer();
$container->call(function (phpdisample\sample\UserService $service) {
    $service->save(23, "foobar");
    var_dump($service->get(23));
});
<?php

$builder = new \DI\ContainerBuilder();
$builder->addDefinitions(__DIR__ . '/config-test3.php');
$builder->setDefinitionCache(new \Doctrine\Common\Cache\ArrayCache());
$container = $builder->build();
//trigger autoloader
$j = $container->get('J');
unset($j);
$t1 = microtime(true);
for ($i = 0; $i < 10000; $i++) {
    $j = $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

require_once '../testclasses.php';
function __autoload($className)
{
    $className = ltrim($className, '\\');
    $fileName = '';
    $namespace = '';
    if ($lastNsPos = strrpos($className, '\\')) {
        $namespace = substr($className, 0, $lastNsPos);
        $className = substr($className, $lastNsPos + 1);
        $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
    }
    $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
    require $fileName;
}
require_once 'DI/functions.php';
$builder = new \DI\ContainerBuilder();
$builder->addDefinitions('config-test3.php');
$cache = new \Doctrine\Common\Cache\MemcachedCache();
$m = new Memcached();
$m->addServer('localhost', 11211);
$cache->setMemcached($m);
$builder->setDefinitionCache($cache);
$container = $builder->build();
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);
Example #16
0
    }
    $builder = new \DI\ContainerBuilder();
    if (APC_ENABLED) {
        $cache = new Doctrine\Common\Cache\ApcCache();
    } else {
        $cache = new Doctrine\Common\Cache\ArrayCache();
    }
    $cache->setNamespace('Fraym_instance_' . FRAYM_INSTANCE);
    $builder->setDefinitionCache($cache);
    $builder->writeProxiesToFile(true, 'Cache/DI');
    $diContainer = $builder->build();
    define('GLOBAL_CACHING_ENABLED', true);
} else {
    error_reporting(-1);
    ini_set("display_errors", 1);
    $builder = new \DI\ContainerBuilder();
    if (APC_ENABLED && \Fraym\Core::ENV_TESTING === ENV) {
        $cache = new Doctrine\Common\Cache\ApcCache();
    } else {
        $cache = new Doctrine\Common\Cache\ArrayCache();
    }
    $builder->setDefinitionCache($cache);
    $diContainer = $builder->build();
    define('GLOBAL_CACHING_ENABLED', false);
}
$diContainer->set('db.options', array('driver' => DB_DRIVER, 'user' => DB_USER, 'password' => DB_PASS, 'host' => DB_HOST, 'dbname' => DB_NAME, 'charset' => DB_CHARSET));
if (defined('IMAGE_PROCESSOR') && IMAGE_PROCESSOR === 'Imagick') {
    $diContainer->set('Imagine', DI\link('Imagine\\Imagick\\Imagine'));
} elseif (defined('IMAGE_PROCESSOR') && IMAGE_PROCESSOR === 'Gmagick') {
    $diContainer->set('Imagine', DI\link('Imagine\\Gmagick\\Imagine'));
} else {
Example #17
0
<?php

declare (strict_types=1);
require __DIR__ . '/../vendor/autoload.php';
/*
 * Load configuration
 */
$configPath = __DIR__ . '/../config';
$services = (require $configPath . '/services.php');
$middleware = (require $configPath . '/middleware.php');
/*
 * Build container
 */
$containerBuilder = new DI\ContainerBuilder();
$containerBuilder->addDefinitions($services);
$container = $containerBuilder->build();
/*
 * Build application middleware pipeline
 */
$relayBuilder = $container->get(Relay\RelayBuilder::class);
$app = $relayBuilder->newInstance($middleware);
/*
 * Run application middleware pipeline
 */
$request = $container->get('initial_request');
$response = $container->get('initial_response');
$response = $app($request, $response);
/*
 * Emit response
 */
$emitter = $container->get(Zend\Diactoros\Response\EmitterInterface::class);
Example #18
0
<?php

/**
 *
 * User: snake
 * Date: 15-8-5
 */
require __DIR__ . "/vendor/autoload.php";
$configFile = __DIR__ . "/config/config.php";
$builder = new DI\ContainerBuilder();
$builder->addDefinitions($configFile);
$container = $builder->buildDevContainer();
/**
 * @var Lanara\Helper $helper
 */
$helper = $container->get(\Lanara\Helper::class);
$debug = "debug";
Example #19
0
    $input = new Symfony\Component\Console\Input\ArrayInput(array('command' => 'install'));
    $application = new Composer\Console\Application();
    $output = new \Symfony\Component\Console\Output\BufferedOutput();
    $application->setAutoExit(false);
    $result = $application->run($input, $output);
    echo json_encode(['message' => 'Done. Reloading installation...', 'done' => false, 'error' => $result !== 0 ? nl2br($output->fetch()) : false]);
    exit;
}
require 'Vendor/autoload.php';
define('CACHE_DI_PATH', 'Cache/DI');
define('CACHE_DOCTRINE_PROXY_PATH', 'Cache/DoctrineProxies');
define('CACHE_DOCTRINE_MODULE_FILE', 'Cache/doctrine_module_dir.cache');
define('JS_FOLDER', '/js');
define('CSS_FOLDER', '/css');
define('CONSOLIDATE_FOLDER', '/consolidated');
define('ENV', 'development');
error_reporting(-1);
ini_set("display_errors", 1);
$builder = new \DI\ContainerBuilder();
$builder->useAnnotations(true);
$cache = new Doctrine\Common\Cache\ArrayCache();
$builder->setDefinitionCache($cache);
$builder->addDefinitions(['db.options' => array('driver' => '', 'user' => '', 'password' => '', 'host' => '', 'dbname' => '', 'charset' => '')]);
$diContainer = $builder->build();
define('GLOBAL_CACHING_ENABLED', false);
define('APC_ENABLED', false);
$core = $diContainer->get('Fraym\\Core');
$core->init(\Fraym\Core::ROUTE_CUSTOM);
$installer = $diContainer->get('Fraym\\Install\\InstallController');
$installer->setup();
$core->response->finish(false, true);
Example #20
0
<?php

/**
 * friendloc.bootstrap.php
 * User: johnnyutkin
 * Date: 30.12.15
 * Time: 22:46
 */
require_once __DIR__ . '/../../vendor/autoload.php';
$containerBuilder = new \DI\ContainerBuilder();
$containerBuilder->addDefinitions([\thewulf7\friendloc\components\config\iConfig::class => \DI\object(\thewulf7\friendloc\components\config\Config::class)->constructor(require __DIR__ . '/../config/main.php'), \thewulf7\friendloc\components\Application::class => \DI\object(\thewulf7\friendloc\components\Application::class)]);
$c = $containerBuilder->build();
/** @var \thewulf7\friendloc\components\Application $app */
$app = $c->get('\\thewulf7\\friendloc\\components\\Application');
$app->init();
Example #21
0
<?php

use thewulf7\friendloc\components\Application;
use thewulf7\friendloc\components\config\{iConfig, Config};
use function DI\object;
use function DI\get;
ini_set('display_errors', 0);
require '../../vendor/autoload.php';
$containerBuilder = new \DI\ContainerBuilder();
$containerBuilder->addDefinitions([iConfig::class => object(Config::class)->constructor(require '../config/main.php'), Application::class => object(Application::class)]);
/** @var Application $app */
$app = $containerBuilder->build()->get('\\thewulf7\\friendloc\\components\\Application');
$app->setDevMode(true)->run();
<?php

/*
Plugin Name: Sarcofag
Plugin URI: http://milsdev.com/#portfolio
Description: OOP wrapper for the WordPress
Version: 0.0-alpha
Author: Mil's
Author URI: http://milsdev.com/
*/
$loader = (include ABSPATH . '/vendor/autoload.php');
$loader->setPsr4('Sarcofag\\', [__DIR__ . '/src']);
$containerBuilder = new DI\ContainerBuilder();
$containerBuilder->addDefinitions(__DIR__ . '/config/di.inc.php');
$activePlugins = get_option('active_plugins');
foreach ($activePlugins as $activePlugin) {
    $pluginDiConfig = WP_PLUGIN_DIR . '/' . trim(dirname($activePlugin), '/') . '/config/di.inc.php';
    if (!file_exists($pluginDiConfig)) {
        continue;
    }
    $containerBuilder->addDefinitions(require $pluginDiConfig);
}
if (file_exists(get_template_directory() . '/src/config/di.inc.php')) {
    $containerBuilder->addDefinitions(require get_template_directory() . '/src/config/di.inc.php');
}
$di = $containerBuilder->build();
foreach ($di->get('autoloader.paths') as $namespace => $autoloaderPaths) {
    if (is_array($autoloaderPaths)) {
        $autoloaderPaths = array_map('realpath', $autoloaderPaths);
    } else {
        $autoloaderPaths = [realpath($autoloaderPaths)];
Example #23
0
 /**
  * @return ContainerInterface
  */
 private function getPHPDIContainer()
 {
     if ($this->phpdiContainer === null) {
         $builder = new \DI\ContainerBuilder();
         $builder->wrapContainer($this->getContainer());
         $this->phpdiContainer = $this->buildPHPDIContainer($builder);
     }
     return $this->phpdiContainer;
 }
Example #24
0
<?php

use Curve\AppKernel;
require_once __DIR__ . '/vendor/autoload.php';
$containerBuilder = new \DI\ContainerBuilder();
$containerBuilder->addDefinitions(__DIR__ . '/src/Curve/AppContainer.php');
$container = $containerBuilder->build();
/** @var AppKernel $app */
$app = $container->get("Curve\\AppKernel");
$input = json_decode(file_get_contents($argv[1]), true);
echo $app->start($input)->getTotal() . "\n";
Example #25
0
<?php

// Create cache provider
$cache = new \Doctrine\Common\Cache\FilesystemCache(CACHE_PATH);
// Create the dependency injection container
$builder = new \DI\ContainerBuilder();
// The container uses a technique called autowiring.
$builder->useAutowiring(true);
// Set cache provider
$builder->setDefinitionCache($cache);
// Added dependencies settings
$builder->addDefinitions(CONFIG_PATH . '/dependencies.php');
// Builder container
$container = $builder->build();
// Check request uri is defined
$console = empty($_SERVER['REQUEST_URI']) ? true : false;
// Good to go!
$app = $container->get(App\Autoload::class);
$app->run($console);
Example #26
0
// class definition
class Author
{
    public $firstName = 'Adrian';
    public $lastName = 'Pietka';
}
class Head
{
    public function __construct(Author $author)
    {
        $this->author = $author;
    }
}
class Body
{
}
class Document
{
    public function __construct(Head $head, Body $body)
    {
        $this->head = $head;
        $this->body = $body;
    }
}
// create a container instance
$builder = new DI\ContainerBuilder();
// $builder->useAutowiring(false); // disabling autowiring
$container = $builder->build();
// get instance of Document class
$document = $container->get('Document');
var_dump($document);
<?php

$builder = new \DI\ContainerBuilder();
$builder->setDefinitionCache(new \Doctrine\Common\Cache\ArrayCache());
$container = $builder->build();
//trigger autoloader
$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);
Example #28
0
File: index.php Project: vtk13/cc
<?php

require_once '../vendor/autoload.php';
session_start();
function h($value)
{
    return htmlspecialchars($value);
}
$builder = new \DI\ContainerBuilder();
$builder->useAnnotations(true);
$builder->addDefinitions('../config/config.php');
$router = new \Vtk13\Mvc\Handlers\ControllerRouter($builder->build(), 'Vtk13\\Cc\\Controller\\', '/', 'index');
$response = $router->handle(\Vtk13\Mvc\Http\Request::createFromGlobals());
if (!headers_sent()) {
    header($response->getStatusLine());
    foreach ($response->getHeaders() as $name => $value) {
        header("{$name}: {$value}");
    }
    echo $response->getBody();
}
Example #29
0
<?php

require __DIR__ . '/../vendor/autoload.php';
date_default_timezone_set('UTC');
session_start();
$builder = new DI\ContainerBuilder();
$builder->addDefinitions('../config/di.php');
$builder->addDefinitions(['api.base_url' => 'http://localhost:8080', 'oauth2.client_id' => 'GPa5aZntQiqREY1E9ZWV', 'oauth2.client_secret' => '735fa055695bd683b7bfc0de4e6b4fc2ce2c7f46', 'oauth2.redirect_uri' => 'http://localhost:8081/authorize.php', 'oauth2.base_url' => 'http://localhost:8080']);
$container = $builder->build();
Example #30
0
<?php

set_time_limit(0);
mb_internal_encoding('UTF-8');
define('DS', DIRECTORY_SEPARATOR);
define('ROOT', __DIR__);
define('SRC', ROOT . DS . 'src');
define('DATA', ROOT . DS . 'data');
define('BASE', ROOT . DS . 'db');
require ROOT . '/vendor/autoload.php';
/** @var \DI\Container $container */
use Interop\Container\ContainerInterface;
$builder = new DI\ContainerBuilder();
$builder->useAnnotations(true);
$builder->addDefinitions(['config.path' => ROOT . DS . 'config', 'config' => function (ContainerInterface $c) {
    $config = \Symfony\Component\Yaml\Yaml::parse(file_get_contents($c->get('config.path') . DS . 'bot.yml'));
    return $config;
}, 'loop' => \DI\object(React\EventLoop\StreamSelectLoop::class), 'event' => \DI\object(Sabre\Event\EventEmitter::class)]);
$container = $builder->build();
spl_autoload_register(function ($className) use($container) {
    $className = ltrim($className, "\\");
    $fileName = '';
    if (($lastNsPos = strrpos($className, "\\")) !== false) {
        $namespace = substr($className, 0, $lastNsPos);
        $className = substr($className, $lastNsPos + 1);
        $fileName = str_replace("\\", DS, $namespace) . DS;
    }
    $fileName .= str_replace('_', DS, $className) . '.php';
    $requirePath = __DIR__ . DS . 'src' . DS . $fileName;
    require $requirePath;
});