/** * Use or instantiate a Flysystem disk * * @param string $dir The value from one of the config dirs * @return League\Flysystem\Filesystem | League\Flysystem\Cached\CachedAdapter */ public function makeDisk($dir) { // Check if the dir refers to an IoC binding and return it if ($this->app->bound($dir) && ($instance = $this->app->make($dir)) && (is_a($instance, 'League\\Flysystem\\Filesystem') || is_a($instance, 'League\\Flysystem\\Cached\\CachedAdapter'))) { return $instance; } // Instantiate a new Flysystem instance for local dirs return new Filesystem(new Adapter($dir)); }
/** * Runs the command! * * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * * @return null|int null or 0 if everything went fine, or an error code */ protected function execute(InputInterface $input, OutputInterface $output) { $app = $input->getArgument('application') ?: $this->getConfigValue('application'); $env = $input->getArgument('environment') ?: $this->getConfigValue('environment'); if (!$app) { return $this->variableNotDefined('application', $output); } if (!$env) { return $this->variableNotDefined('environment', $output); } if ($input->getOption('interactive')) { $this->scriptRunner->enableInteractivity($input, $this->getHelper('question')); } if ($input->getOption('force')) { $this->scriptRunner->continueOnError(); } $this->dispatchEvent('init', $output); $branch = exec('echo $(git branch | sed -n -e \'s/^\\* \\(.*\\)/\\1/p\')'); $commitMsg = exec('echo $(git log --format="%s" -n 1)'); $output->writeln("<info>APP:</info>" . $app); $output->writeln("<info>ENV:</info>" . $env); $this->dispatchEvent('before-pack', $output); $packer = $this->app->make('Dployer\\Services\\ProjectPacker'); $packer->setOutput($output); $filename = $packer->pack((array) $this->getConfigValue('exclude-paths'), (array) $this->getConfigValue('copy-paths')); $this->dispatchEvent('before-deploy', $output); $ebsManager = $this->app->make('Dployer\\Services\\EBSVersionManager'); $ebsManager->init($app, $env, $output); $versionLabel = $ebsManager->createVersion($filename, "[{$branch}] {$commitMsg}"); if ($versionLabel && $ebsManager->deployVersion($versionLabel)) { $this->removeZipFile($filename, $output); $output->writeln("<info>done</info>"); $this->dispatchEvent('finish', $output); return 0; } $this->dispatchEvent('finish', $output); $output->writeln("<error>failed</error>"); return 1; }
protected function setUp() { $app = new \Illuminate\Container\Container(); $app['config'] = $this->config = $this->generateMockConfiguration(); $app['session'] = $this->session = new Store(new MockArraySessionStorage()); $app['url'] = $this->urlGenerator = new UrlGenerator(new RouteCollection(), Request::create('/edifice', 'GET')); $app['html'] = $this->htmlBuilder = new HtmlBuilder($this->urlGenerator); $app['form'] = $this->formBuilder = new FormBuilder($this->htmlBuilder, $this->urlGenerator, 'csrfToken'); $this->edificeServiceProvider = new EdificeServiceProvider($app); $this->edificeServiceProvider->register(); $this->edifice = $app['edifice.form']; $app->make('Illuminate\\Container\\Container'); $app->instance('Illuminate\\Container\\Container', $app); }
<?php $container = new \Illuminate\Container\Container(); //trigger autoloader $j = $container->make('J'); $j2 = $container->make('J'); $t1 = microtime(true); for ($i = 0; $i < 10000; $i++) { $j = $container->make('J'); } $t2 = microtime(true); $results = ['time' => $t2 - $t1, 'files' => count(get_included_files()), 'memory' => memory_get_peak_usage() / 1024 / 1024]; echo json_encode($results);
set_include_path('configs:' . get_include_path()); setlocale(LC_TIME, 'fr_BE'); //Démarrage de la session session_start(); require "vendor/autoload.php"; //Gestion de la white list des routes include 'routes.php'; //Inclusion des données de connexion à la db. Ne contient que des constantes qui sont donc globales include 'db.php'; //Routage $routeParts = explode('/', $routes['default']); $a = isset($_REQUEST['a']) ? $_REQUEST['a'] : $routeParts[0]; $e = isset($_REQUEST['e']) ? $_REQUEST['e'] : $routeParts[1]; $route = $a . '/' . $e; if (!in_array($route, $routes)) { die('Vous essayez de joindre une ressource qui n’existe pas'); //À remplacer par une redirection vers view/error/x } //Création du container d’injection de dépendances $container = new Illuminate\Container\Container(); foreach (include 'bindings.php' as $interface => $concrete) { $container->bind($interface, $concrete); } //Détermination du controleur à utiliser $controllerName = '\\Controllers\\' . ucfirst($e); $controller = $container->make($controllerName); //Exécution de la fonction correspondant à l’action demandée $data = call_user_func([$controller, $a]); //$data contient toujours une clé 'view' et une clé 'data' //Inclusion de la vue maîtresse include 'views/layout.php';
<?php require_once "vendor/autoload.php"; $app = new \Illuminate\Container\Container(); $app->when('Axia')->needs('FuelInterface')->give('Ron97'); $axia = $app->make('Axia'); echo $axia->refuel(100) . PHP_EOL; $civic = $app->make('CivicTypeR'); echo $civic->refuel(100) . PHP_EOL;
<?php $container = new \Illuminate\Container\Container(); $container->bind('A', 'A', true); //Trigger autoloader $a = $container->make('B'); unset($a); $t1 = microtime(true); for ($i = 0; $i < 10000; $i++) { $b = $container->make('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 $container = new \Illuminate\Container\Container(); $t1 = microtime(true); for ($i = 0; $i < 10000; $i++) { $a = $container->make('A'); } $t2 = microtime(true); $results = ['time' => $t2 - $t1, 'files' => count(get_included_files()), 'memory' => memory_get_peak_usage() / 1024 / 1024]; echo json_encode($results);
// Use a callback to set additional settings $container->singleton('database', function ($container) { return new Acme\Database('username', 'password', 'host', 'database'); }); // Bind an existing "authentication" class instance to the container $auth = new Acme\Authentication(); $container->instance('auth', $auth); /* |-------------------------------------------------------------------------- | Routes |-------------------------------------------------------------------------- */ $app = new \Slim\Slim(); $app->get('/', function () use($container) { // Create new Acme\Template instance $template = $container->make('template'); // Render template echo $template->render('home'); }); $app->get('/send-email', function () use($container) { // Create new Acme\Mailer instance $mailer = $container->make('mailer'); // Set mail settings $mailer->to = '*****@*****.**'; $mailer->subject = 'Test email'; $mailer->body = 'This is a test email.'; // Send the email if ($mailer->send()) { echo 'Email successfully sent!'; } });
// IoC container setup $container = new \Illuminate\Container\Container(); // Application configuration $config = (include __BASE_DIR . 'app/config/config.php'); $config = new \App\Components\Config\Config($config); $container->instance('\\App\\Components\\Config\\Config', $config); $container->alias('\\App\\Components\\Config\\Config', 'config'); // Slim application setup $container->singleton('Slim\\Slim', function ($container) use($config) { $app = new \Slim\Slim(array('debug' => $config->get('app.debug'), 'mode' => $config->get('app.mode'), 'log.enabled' => $config->get('app.logging.enabled'), 'log.level' => $config->get('app.logging.level'), 'log.writer' => new \App\Components\Logging\FileSystemLogWriter(__BASE_DIR . 'app/storage/logs/' . date('ymd') . '.log'), 'templates.path' => __BASE_DIR . 'app/ressources/views', 'view' => new \Slim\Views\Twig())); // Twig template engine setup $app->view()->parserOptions = array('debug' => $config->get('app.debug'), 'cache' => __BASE_DIR . 'app/storage/cache/views'); $app->view()->parserExtensions = array(new \Slim\Views\TwigExtension()); // Laravel session component start and shutdown configuration $app->hook('slim.before', function ($container) use($container) { $container->make('session')->start(); }); $app->hook('slim.after.router', function ($container) use($container) { $container->make('session')->save(); }); return $app; }); $container->alias('Slim\\Slim', 'app'); // Setup router for simple controller routing $container->singleton('App\\Components\\Routing\\Router', function ($container) { $router = new \App\Components\Routing\Router($container->make('app'), $container); $router->setControllerNamespace('\\App\\Http\\Controllers'); return $router; }); $container->alias('App\\Components\\Routing\\Router', 'router'); // Filesystem access