Пример #1
0
<?php

// Construct the IoC Container
$app = new Illuminate\Container\Container();
// Bind isolator for PHP functions
$app->bind('php', function () {
    return new Icecave\Isolator\Isolator();
}, true);
// Bind the Symfony Console application
$app->bind('console', function () {
    return new Symfony\Component\Console\Application('dployer', '1.2.2');
}, true);
function app()
{
    global $app;
    return $app;
}
Пример #2
0
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

$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);
Пример #4
0
|--------------------------------------------------------------------------
| Bootstrap
|--------------------------------------------------------------------------
*/
// Include project libraries, including a number of mock
// examples of common, real-world services
require_once 'vendor/autoload.php';
require_once 'libraries/Authentication.php';
require_once 'libraries/Controller.php';
require_once 'libraries/Database.php';
require_once 'libraries/Mailer.php';
require_once 'libraries/Template.php';
// Create new IoC Container instance
$container = new Illuminate\Container\Container();
// Bind a "template" class to the container
$container->bind('template', 'Acme\\Template');
// Bind a "mailer" class to the container
// Use a callback to set additional settings
$container->bind('mailer', function ($container) {
    $mailer = new Acme\Mailer();
    $mailer->username = '******';
    $mailer->password = '******';
    $mailer->from = '*****@*****.**';
    return $mailer;
});
// Bind a shared "database" class to the container
// 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
Пример #5
0
<?php

require_once "vendor/autoload.php";
$app = new \Illuminate\Container\Container();
$app->bind('FuelInterface', 'Ron95');
// Imagine if out of sudden, you need to calculate GST
// for all the fuels.
$app->afterResolving('FuelInterface', function ($fuel) {
    return $fuel->setPrice($fuel->getPrice() * 1.06);
});
$axia = $app->make('Axia');
echo $axia->refuel(100) . PHP_EOL;
$civic = $app->make('CivicTypeR');
echo $civic->refuel(100) . PHP_EOL;
Пример #6
0
<?php

/*  This is a basic bootstrap for some of the laravel 5.0 components and entry point to the app itself.
 *  See this article for more infohttp://www.gufran.me/post/laravel-components/ 
 *  */
ini_set('display_errors', 'On');
error_reporting(E_ALL);
require './vendor/autoload.php';
Illuminate\Support\ClassLoader::register();
$path = str_finish(dirname(__FILE__), '/');
// register the autoloader and add directories
$app = new Illuminate\Container\Container();
$app->bind('app', $app);
// this line is different from gufran's post because I'm on laravel 5 and I think his guide was on laravel 4.
require './vendor/illuminate/support/helpers.php';
#require './vendor/illuminate/Foundation/helpers.php';
//
// also bind the base path for some helper methods to use
// Overcome the mental block, you can bind literally anything into the container
$app->bind('path.base', $path);
// Yes, that is an abstract class but you can still access
// static methods
Illuminate\Support\Facades\Facade::setFacadeApplication($app);
// register application instance with container
$app['app'] = $app;
// set environment
$app['env'] = 'production';
$params = parse_ini_file('database.ini');
$baseUrl = $params['baseUrl'];
$basePath = $params['basePath'];
$app['baseUrl'] = $baseUrl;