コード例 #1
0
 public function testExceptionHandlerNotFoundDebug()
 {
     $app = new Application(['debug' => true]);
     $response = $app->handle(Request::create('/foo'));
     $this->assertContains('Unable to find the ROUTE for path "/foo"', html_entity_decode($response->getContent()));
     $this->assertEquals(404, $response->getStatusCode());
 }
コード例 #2
0
 public function onEventResponse(Application $app, Response $response)
 {
     if (null === $response->getCharset()) {
         $response->setCharset($app->getParameter('charset'));
     }
     $response->prepare($app->getRequest());
 }
コード例 #3
0
 public function register(Application $app)
 {
     $app->setParameter('cache', ['namespace' => null, 'type' => 'array']);
     $app->singleton('cache', function () use($app) {
         $cache = null;
         $type = $app->getParameter('cache.type', 'array');
         if ($type == 'array') {
             $cache = new ArrayCache();
         } elseif ($type == 'apc') {
             $cache = new ApcCache();
         } elseif ($type == 'xcache') {
             $cache = new XcacheCache();
         } elseif ($type == 'memcache') {
             $cache = new MemcacheCache();
             $memcache = new \Memcache();
             $memcache->addserver($app->getParameter('cache.memcached.host', '127.0.0.1'), $app->getParameter('cache.memcached.port', 11211));
             $cache->setMemcache($memcache);
         } elseif ($type == 'memcached') {
             $cache = new MemcachedCache();
             $memcached = new \Memcached();
             $memcached->addServer($app->getParameter('cache.memcached.host', '127.0.0.1'), $app->getParameter('cache.memcached.port', 11211));
             $cache->setMemcached($memcached);
         }
         $cache->setNamespace($app->getParameter('cache.namespace'));
         return $cache;
     });
 }
コード例 #4
0
 public function onEventException(Application $app, \Exception $e)
 {
     $response = $app->response('', 500);
     if ($e instanceof HttpException) {
         $response->setStatusCode($e->getStatusCode());
     }
     if ($app->getParameter('debug')) {
         $response->setContent($this->prettyException($e));
     }
     $app->setResponse($response);
 }
コード例 #5
0
 public function onEventRequest(Application $app, Request $request)
 {
     $matcher = $app->getRouter()->getMatcher();
     $route = $matcher->match($request->getMethod(), $request->getPathInfo());
     if ($route != null) {
         $request->attributes->set('_route', $route);
     }
     if ($matcher->isNeedRedirect()) {
         $url = $matcher->getRedirectUrl();
         $app->setResponse($app->redirect($url, 301));
         $app->stopEventPropagation();
     }
 }
コード例 #6
0
 public function __invoke(array $input)
 {
     $name = 'world';
     if (!empty($input['name'])) {
         $name = $input['name'];
     }
     ////////////////////
     $application = new Application();
     $application_data = $application->is_pjax();
     //print_r( '<pre>' );
     // print_r( $application_data );
     //print_r( '</pre>');
     ////////////////////
     // simple
     // Create new Plates instance
     //		$plates = new Engine(APPPATH.'templates');
     // Render a template
     // $template = $plates->render('partials/profile', ['name' => $name . ' | ' . $data_from_an_other_class]);
     //		$template = $plates->render('partials/profile', ['name' => $name . ' | ' . $application_data]);
     $data = ['friends' => ['mikka', 'makka', 'zorro']];
     //			$friends = [
     //			  ['name', 'zorro'],
     //			];
     ////////////////////
     // using folders
     // Create new Plates instance
     $plates = new Engine(APPPATH . 'templates');
     // Register a Plates extension
     $plates->loadExtension(new Utils());
     // Add folders
     $plates->addFolder('layout', APPPATH . 'templates');
     $plates->addFolder('partials', APPPATH . 'templates/partials');
     $plates->addFolder('static', APPPATH . 'templates/static');
     // assign data to plates
     $plates->addData($data, 'layout');
     // Render
     $template = $plates->render('partials::profile', ['name' => $name]);
     ////////////////////
     $invitation = 'I invite you';
     // return
     return (new Payload())->withStatus(Payload::OK)->withOutput(['hello' => $template, 'invitation' => $invitation]);
 }
コード例 #7
0
 public function register(Application $app)
 {
     $app->singleton('twig', function () use($app) {
         $options = array_replace(['charset' => $app->getParameter('charset'), 'debug' => $app->getParameter('debug'), 'strict_variables' => $app->getParameter('debug')], $app->getParameter('twig.options', []));
         /** @var Twig_LoaderInterface $loader */
         $loader = $app->make('twig.loader');
         $twig = new \Twig_Environment($loader, $options);
         $twig->addGlobal('app', $app);
         return $twig;
     });
     $app->singleton('twig.loader', function () use($app) {
         return new \Twig_Loader_Filesystem($app->getParameter('twig.path'));
     });
 }
コード例 #8
0
 public function onEventTerminate(Application $app)
 {
     // To speed things up (by avoiding Swift Mailer initialization), flush
     // messages only if our mailer has been created (potentially used)
     // IMPORTANT! For files spool you need flush queue from console
     if ($app->getParameter('swiftmailer.initialized') && $app->getParameter('swiftmailer.use_spool') && $app->getParameter('swiftmailer.options.spool_type', 'memory') == 'memory') {
         $app->make('swiftmailer.transport_spool')->getSpool()->flushQueue($app->make('swiftmailer.transport'));
     }
 }
コード例 #9
0
ファイル: WebTest.php プロジェクト: itlessons/php-application
 public function createApplication()
 {
     $app = new Application();
     $app->match('/hello', function () {
         return 'world';
     });
     $app->match('/html', function () {
         return '<h1>title</h1>';
     });
     $app->match('/server', function () use($app) {
         $user = $app->getRequest()->server->get('PHP_AUTH_USER');
         $pass = $app->getRequest()->server->get('PHP_AUTH_PW');
         return "<h1>{$user}:{$pass}</h1>";
     });
     return $app;
 }
コード例 #10
0
ファイル: Controller.php プロジェクト: render22/rssparser
 public function getrss()
 {
     session_start();
     $dm = App::getInstance()->getDbManipulation();
     $parser = new Parser();
     /*$pages=$parser->setSearchQuery("новости")
                 ->getSearchPages()
                 ->grabLinks()
                 ->getPages();
     
     
             $dm->saveLinks($pages);
             $rssLinks=$parser->parseGrabbedPages();
     
             $dm->saveRssLinks($rssLinks);
             $parser->setRssLinks($rssLinks);
             $rssContent=$parser->getRssContent();
             $_SESSION['rssContent']=$rssContent;*/
     //var_dump(array_keys($_SESSION['rssContent']));
     //exit;
     $parsedData = $parser->parseRss($_SESSION['rssContent']);
     $dm->saveRssContent($parsedData);
 }
コード例 #11
0
 public function register(Application $app)
 {
     $app->setParameter('db.options_default', ['dsn' => '', 'username' => 'root', 'password' => null, 'options' => []]);
     $app->singleton('db', function () use($app) {
         $manager = new Manager();
         $optionsDefault = $app->getParameter('db.options_default');
         $dbsOptions = $app->getParameter('dbs.options');
         if (!$dbsOptions) {
             $dbsOptions['default'] = $app->getParameter('db.options', []);
         }
         $defaultSet = false;
         foreach ($dbsOptions as $name => &$options) {
             $options = array_replace($optionsDefault, $options);
             $manager->addConnection($options, $name);
             if (!$defaultSet) {
                 $manager->setDefaultConnectionName($defaultSet);
                 $defaultSet = true;
             }
         }
         return $manager;
     });
 }
コード例 #12
0
ファイル: index.php プロジェクト: rajanlamic/php
<?php

// set include path
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__DIR__) . '/Application');
// register autoload, recognize namespace,
spl_autoload_register(function ($class) {
    require dirname(__DIR__) . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php';
});
// handle exception
set_exception_handler(function ($exception) {
    echo $exception->getMessage(), "\n";
    echo '<pre>' . print_r(debug_backtrace(), 1) . '</pre>';
});
// display error on development environment
if (isset($_SERVER['APPLICATION_ENV']) && $_SERVER['APPLICATION_ENV'] == 'development') {
    error_reporting(E_ALL);
    ini_set("display_errors", 1);
}
use Application\Application;
// run the application
$application = new Application();
$application->init(require 'Config/global.config.php')->run();
コード例 #13
0
 public function boot(Application $app)
 {
     $app->addEventListener(Application::EVENT_VIEW, [$this, 'onEventViews'], Application::PRIORITY_HIGH);
 }
コード例 #14
0
<?php

require __DIR__ . '/../config/autoload.php';
use Application\Application;
$application = new Application();
$application->start();
コード例 #15
0
ファイル: view.php プロジェクト: nerdsrescueme/Nerd-CMS
<?php

namespace Application;

use Nerd\Design\Architectural\MVC\View;
return ['view.setup' => function () {
    View::set('application', Application::instance());
    View::set('flash', Application::instance()->session->flash);
}, 'view.render' => function (View $view) {
}];
コード例 #16
0
 public function onEventRequest(Application $app, Request $request)
 {
     /** @var Session $session */
     $session = $app->make('session');
     $request->setSession($session);
 }
コード例 #17
0
ファイル: index.php プロジェクト: jkaan/Time-Registration
<?php

/**
 * This file is the main file of the application
 *
 * It requires all of the classes by requiring the autoload.php file
 *
 * Initializes Slim, gets the routes and adds them to the Slim instance
 */
require '../vendor/autoload.php';
use Application\Application;
use Application\Config\Database;
use Slim\Slim;
$app = new Slim(array('debug' => true));
error_reporting(-1);
$application = new Application();
$routes = $application->getRoutes();
foreach ($routes as $route) {
    $class = new $route['class']();
    $app->{$route}['method']($route['URL'], array($class, $route['action']));
}
$app->run();
コード例 #18
0
ファイル: bootstrap.php プロジェクト: nerdsrescueme/Nerd-CMS
 * Get and register the Composer autoloader as a secondary loader.
 */
require LIBRARY_PATH . '/../vendor/autoload.php';
/**
 * Here you could do some magic for multiple applications by dynamically switching
 * the application namespace for this request. To create another application you
 * would simply create another subfolder in LIBRARY_PATH with its own Application
 * class...
 */
define('APPLICATION_NS', 'application');
define('STORAGE_PATH', LIBRARY_PATH . DS . 'application/storage');
/**
 * Setup the current environment
 */
$env = Environment::$active;
//die(var_dump($env));
/**
 * The following items need to be done for every request, but since they require
 * APPLICATION_NS to be defined, the must be done in the application bootstrap file.
 *
 *   [!!] Edit at your own risk
 *
 */
error_reporting(Config::get('error.reporting'));
ini_set('display_errors', Config::get('error.display', true) ? 'On' : 'Off');
date_default_timezone_set(Config::get('application.timezone', 'UTC'));
\Nerd\Str::$mbString and mb_internal_encoding(Config::get('application.encoding', 'UTF-8'));
$application = Application::instance();
$application->triggerEvent('application.startup');
$application->response->send(true);
$application->triggerEvent('application.shutdown');
コード例 #19
0
ファイル: index.php プロジェクト: rajanlamic/php
<?php

// set include path
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__DIR__) . '/Application');
// register autoload, recognize namespace,
spl_autoload_register(function ($class) {
    require dirname(__DIR__) . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php';
});
// handle exception
set_exception_handler(function ($exception) {
    echo $exception->getMessage(), "\n";
    echo '<pre>' . print_r(debug_backtrace(), 1) . '</pre>';
});
// display error on development environment
if (isset($_SERVER['APPLICATION_ENV']) && $_SERVER['APPLICATION_ENV'] == 'development') {
    error_reporting(E_ALL);
    ini_set("display_errors", 1);
}
use Application\Application;
use Application\Event\Pubsub;
// run the application
$application = new Application();
$application->init(require 'Config/global.config.php')->run(new Pubsub());
コード例 #20
0
ファイル: controller.php プロジェクト: nerdsrescueme/Nerd-CMS
<?php

namespace Application;

use Nerd\Design\Architectural\MVC\Controller;
use Nerd\Design\Architectural\MVC\View;
use Nerd\Input;
return ['controller.setup' => function (Controller $controller) {
    $session = Application::instance()->session;
    if (!Input::protect($session->get('application.csrf'))) {
        throw new \Nerd\Http\Exception(403);
    }
    $controller->application = Application::instance();
    $controller->session = $session;
    $controller->flash = $session->flash;
    $controller->response = Application::instance()->response;
    $controller->template = new View('template');
}];
コード例 #21
0
ファイル: app.php プロジェクト: roelvdheijden/BKE
<?php

require_once __DIR__ . '/library/Autoload.php';
use Application\Application;
$app = new Application();
$app->run();
//var_dump($app);
コード例 #22
0
use AddressBook\Service\ContactRepository;
use Application\Application;
use Application\Db\Driver\DatabaseDriver;
use Application\Db\Driver\MysqlDriver;
use Application\Model\Config;
use Application\Service\ServiceManager;
use Application\View\ViewRenderer;
use Auth\Service\AuthService;
use Auth\Service\UserRepository;
// Init autoloader
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
    $loader = (include __DIR__ . '/vendor/autoload.php');
}
// Init application
chdir(__DIR__);
$application = new Application();
$application->bootstrap();
$serviceManager = $application->getServiceManager();
$serviceManager->registerFactoryCallback('config', function () use($application) {
    return $application->getConfig();
});
$serviceManager->registerFactoryCallback('database.config', function (ServiceManager $serviceManager) {
    /** @var Config $config */
    $config = $serviceManager->get('config');
    return $config['database'];
});
$serviceManager->registerFactoryCallback('database.driver', function (ServiceManager $serviceManager) {
    /** @var Config $config */
    $configDb = $serviceManager->get('database.config');
    $db = new MysqlDriver();
    $db->connect($configDb['db_user'], $configDb['db_password'], $configDb['db_host'], $configDb['db_port']);