Example #1
0
 public function __construct()
 {
     parent::__construct();
     $this->services = ['loader' => new Service('loader', new Loader()), 'config' => new Service('config', new Config([])), 'event' => new Service('event', new Dispatcher()), 'request' => new Service('request', new Request()), 'response' => new Service('response', new Response()), 'cookies' => new Service('cookies', new Cookies()), 'router' => new Service('router', new Router()), 'session' => new Service('session', new Files()), 'url' => new Service('url', new Url()), 'flash' => new Service('flash', new FlashSession()), 'view' => new Service('view', new NullTemplate())];
     // Make alias
     $this->services['eventDispatcher'] = $this->services['event'];
     $this->services['template'] = $this->services['view'];
 }
Example #2
0
<?php

namespace Sandbox;

use Dez\DependencyInjection\Container;
use Dez\EventDispatcher\Dispatcher;
use Dez\Http\Request;
use Dez\Router\Router;
use Dez\Url\Builder;
use Dez\Url\Uri;
use Dez\Url\Url;
error_reporting(1);
ini_set('display_errors', 1);
include_once '../vendor/autoload.php';
$di = Container::instance();
$di->set('eventDispatcher', new Dispatcher());
$di->set('router', function () {
    return new Router();
});
$di->set('request', new Request());
$di->set('url', function () {
    $url = new Url();
    $url->setBasePath('/dez-url/sandbox/');
    $url->setStaticPath('/dez-url/sandbox/media/');
    return $url;
});
/**
 * @var $url Url
 * @var $router Router
 */
$router = $di->get('router');
Example #3
0
<?php

namespace App;

use Dez\DependencyInjection\Container;
use Dez\Flash\Flash\Session;
use Dez\Session\Adapter\Files;
error_reporting(1);
ini_set('display_errors', 1);
include_once '../vendor/autoload.php';
$container = Container::instance();
$session = new Files();
$session->start();
$container->set('session', $session);
$container->set('flash', new Session());
/** @var Session $flash  */
$flash = $container->get('flash');
$flash->info('info message');
$flash->error('error message')->error('error message');
var_dump($flash->getMessages());
Example #4
0
namespace App\Config;

use Dez\Config\Adapter\Json as ConfigJson;
use Dez\DependencyInjection\Container as DiContainer;
use Dez\EventDispatcher\Dispatcher;
use Dez\Http\Cookies;
use Dez\Http\Request;
use Dez\Http\Response;
use Dez\Loader\Loader;
use Dez\Router\Router;
use Dez\Session\Adapter\CustomFiles as SessionCustomFiles;
use Dez\Url\Url;
use Dez\View\Engine\Php as ViewPhpEngine;
use Dez\View\View;
// requires services
$di = DiContainer::instance();
$di->set('loader', new Loader())->resolve([], $di)->register();
$di->set('config', new ConfigJson(__DIR__ . '/config.json'));
$di->set('eventDispatcher', new Dispatcher());
$di->set('event', $di['eventDispatcher']);
$di->set('request', new Request());
$di->set('cookies', new Cookies());
$di->set('response', new Response());
$di->set('session', function () use($di) {
    return (new SessionCustomFiles(['directory' => __DIR__ . '/../sessions']))->setName($di['config']['app']['session']['name'])->start();
})->resolve([], $di);
$di->set('router', function () {
    $router = new Router();
    return $router;
});
$di->set('url', function () {
Example #5
0
<?php

namespace SandBox\Router\Test;

use Dez\DependencyInjection\Container;
use Dez\EventDispatcher\Dispatcher;
use Dez\Http\Request;
use Dez\Router\Adapter\Xml;
use Dez\Router\EventRoute;
use Dez\Router\EventRouter;
use Dez\Router\Router;
error_reporting(1);
ini_set('display_errors', 'On');
include_once './../vendor/autoload.php';
$testRoutes = array('/', '/index', '/index/index', '/index/test', '/products', '/' . md5(time()), '/products/index/', '/products/show/101', '/products/1094', '/offer/item/202/best-offer-202.html', '/auth/api.json/backend-token/test/123qwe/hash/crypt-data/500');
$di = new Container();
$di->set('router', function () {
    return new Router();
});
// require for router
$di->set('eventDispatcher', function () {
    $dispatcher = new Dispatcher();
    /*    $dispatcher->addListener( EventRoute::BEFORE_COMPILE, function( $event, $name ) {
                var_dump($name);
            } );
    
            $dispatcher->addListener( EventRoute::AFTER_COMPILE, function( $event, $name ) {
                var_dump($name);
            } );
    
            $dispatcher->addListener( EventRouter::BEFORE_ROUTE_ADD, function( $event, $name ) {
Example #6
0
<?php

error_reporting(1);
ini_set('display_errors', 1);
include_once '../vendor/autoload.php';
include_once '../smarty-3.1.27/libs/Smarty.class.php';
$di = \Dez\DependencyInjection\Container::instance();
$di->set('eventDispatcher', function () {
    return new \Dez\EventDispatcher\Dispatcher();
});
$di->set('view', function () {
    $view = new \Dez\View\View();
    $view->setViewDirectory(__DIR__ . '/views');
    $view->registerEngine('.php', new \Dez\View\Engine\Php($view));
    $view->registerEngine('.phtml', new \Dez\View\Engine\Php($view));
    $view->registerEngine('.tpl', new \Dez\View\Engine\Smarty($view));
    return $view;
});
/** @var $view \Dez\View\View */
$view = $di->get('view');
$view->addLayout('wrap.php')->addLayout('wrap.php')->addLayout('wrap.php')->addLayout('wrap.php')->addLayout('wrap.php');
$view->setContent('<h1>Content from ' . __FILE__ . '</h1>');
try {
    $view->render('users.php');
    echo $view;
} catch (\Exception $e) {
    header('content-type: text/plain');
    die(get_class($e) . ': ' . $e->getMessage());
}