/* |-------------------------------------------------------------------------- | Register Middleware |-------------------------------------------------------------------------- | | Next, we will register the middleware with the application. These can | be global middleware that run before and after each request into a | route or middleware that'll be assigned to some specific routes. | */ // $app->middleware([ // App\Http\Middleware\ExampleMiddleware::class // ]); // $app->routeMiddleware([ // 'auth' => App\Http\Middleware\Authenticate::class, // ]); /* |-------------------------------------------------------------------------- | Register Service Providers |-------------------------------------------------------------------------- | | Here we will register all of the application's service providers which | are used to bind services into the container. Service providers are | totally optional, so you are not required to uncomment this line. | */ // $app->register(App\Providers\AppServiceProvider::class); // $app->register(App\Providers\AuthServiceProvider::class); // $app->register(App\Providers\EventServiceProvider::class); $app->register(App\Providers\RouteServiceProvider::class); return $app;
use Symfony\Component\Console\Question\ConfirmationQuestion; use Knp\Provider\ConsoleServiceProvider; use Silex\Provider; use MyApp\Values\RenderableValue; class Application extends Silex\Application { use \Silex\Application\TwigTrait; use \Silex\Application\FormTrait; use \Silex\Application\SecurityTrait; use \Silex\Application\UrlGeneratorTrait; } $app = new Application(); $app['debug'] = $config["debug"]; $app['config'] = $config; // Service for terminal commands $app->register(new ConsoleServiceProvider(), array('console.name' => $config['application']['name'], 'console.version' => $config['application']['version'], 'console.project_directory' => __DIR__ . '/..')); // Import Database config, and start Doctrine service $dbconfig = (include __DIR__ . "/config/db.include.php"); $dbconfig["driver"] = 'pdo_pgsql'; $app->register(new DoctrineServiceProvider(), array("db.options" => $dbconfig)); $app->register(new DoctrineOrmServiceProvider(), array("orm.em.options" => array("mappings" => array(array("type" => "annotation", "namespace" => "MyApp\\Entities", "path" => __DIR__ . "/../src/entities/", "alias" => ""))), "orm.custom.functions.string" => array("plainto_tsquery" => "Utils\\Database\\Functions\\PlainToTsquery", "TS_MATCH_OP" => "Utils\\Database\\Functions\\TsMatch"), 'orm.auto_generate_proxies' => $app['debug'])); // Postgis and custom types Type::addType('log_action', 'Utils\\Database\\Types\\LogAction'); $app->register(new \Silex\Provider\TwigServiceProvider(), array('twig.path' => array('default' => __DIR__ . '/../views'))); $app['twig.loader.filesystem']->addPath($app['twig.loader.filesystem']->getPaths()[0] . '/values', 'values'); $app->register(new \Silex\Provider\UrlGeneratorServiceProvider()); $app->register(new \Silex\Provider\FormServiceProvider()); $app->register(new \Silex\Provider\ValidatorServiceProvider()); $app->register(new \Silex\Provider\TranslationServiceProvider(), array('translator.domains' => array())); $app->register(new Provider\SecurityServiceProvider()); $app->register(new Provider\RememberMeServiceProvider());
<?php require_once __DIR__ . '/../vendor/autoload.php'; require_once '../src/bootstrap.php'; $app = new Application($config); // Register providers $app->register(new Silex\Provider\TwigServiceProvider(), $config['twig.options']); $app->register(new Silex\Provider\DoctrineServiceProvider(), $config['db.options']); $app->register(new Silex\Provider\UrlGeneratorServiceProvider()); $app->mount('/', new Main\Controllers\IndexController()); $app->mount('/admin', new Admin\Controllers\IndexController()); $app->run();
<?php namespace Epic; session_start(); ini_set('display_errors', 1); error_reporting(E_ALL); define('SITE_URL', 'http://epic-blog/lesson%2010/src/public/index.php'); require '../vendor/autoload.php'; $app = new \Application(); $app->register('template', Template::service()); Lib\connection(['host' => 'localhost', 'dbname' => 'blog', 'user' => 'root', 'password' => 'vagrant', 'encoding' => 'utf8']); $router = new Router(); $router->add('home', '\\Epic\\Controllers\\Home', [function () { !empty(Lib\user()) ?: Lib\redirect(SITE_URL . '?action=login'); }]); $router->add('profile', '\\Epic\\Controllers\\Profile', [function () { !empty(Lib\user()) ?: Lib\redirect(SITE_URL . '?action=login'); }]); $router->add('login', '\\Epic\\Controllers\\Login'); $router->handle();
{ $this->log = $log; $this->verbosity = $verbosity; } public function infoLog($msg) { if ($this->verbosity) { $this->log->writeln($msg); } } } } if (!isset($console)) { $console = new Application(); } $console->register('psfs:create:module')->setDefinition(array(new InputArgument('module', InputArgument::OPTIONAL, 'Nombre del módulo a crear')))->setDescription('Comando de creación de módulos psfs')->setCode(function (InputInterface $input, OutputInterface $output) { $module = $input->getArgument('module'); $helper = new QuestionHelper(); $log = new CLog($output, $output->isVerbose()); try { //En caso de no tener nombre del módulo lo solicitamos al usuario if (empty($module)) { $question = new Question("Introduce el nombre del módulo a crear:\n"); $module = $helper->ask($input, $output, $question); } //Sólo si tenemos nombre del módulo if (!empty($module)) { \PSFS\services\GeneratorService::getInstance()->createStructureModule($module, $log); } } catch (\Exception $e) { $output->writeln($e->getMessage());
<?php require_once 'vendor/autoload.php'; use Silex\Provider\TwigServiceProvider; use Silex\Provider\TranslationServiceProvider; use Silex\Provider\FormServiceProvider; use Silex\Provider\ValidatorServiceProvider; use Silex\Provider\UrlGeneratorServiceProvider; use Silex\Provider\HttpCacheServiceProvider; use Blongden\Guestbook; class Application extends Silex\Application { use Silex\Application\TwigTrait; use Silex\Application\UrlGeneratorTrait; } $app = new Application(); $app->register(new TwigServiceProvider(), ['twig.path' => __DIR__ . '/views']); $app->register(new TranslationServiceProvider(), ['locale_fallback' => 'en']); $app->register(new FormServiceProvider()); $app->register(new ValidatorServiceProvider()); $app->register(new UrlGeneratorServiceProvider()); $app->register(new HttpCacheServiceProvider(), ['http_cache.cache_dir' => __DIR__ . '/cache', 'http_cache.options' => ['debug' => true]]); $app['guestbook'] = $app->share(function () { return new Guestbook('guestbook.json'); }); $app['request_time'] = $_SERVER['REQUEST_TIME']; return $app;
<?php // require autoload require_once __DIR__ . "/../vendor/autoload.php"; $app = new Application(); /** * Register Doctrine DBAL Provider */ $app->register(new \Silex\Provider\DoctrineServiceProvider(), ['db.options' => ['driver' => 'pdo_mysql', 'dbname' => 'livetext', 'host' => 'localhost', 'user' => 'root', 'charset' => 'UTF8', 'port' => 3306]]); /** * Controller as service */ $app->register(new \Silex\Provider\ServiceControllerServiceProvider()); /** * Register Form Provider */ $app->register(new \Silex\Provider\FormServiceProvider(), ['form.secret' => 'f7271de7effc8a2d663c9f672c7f2a9b3024539b']); /** * Register Validator */ $app->register(new \Silex\Provider\ValidatorServiceProvider()); /** * Twig Register */ $app->register(new \Silex\Provider\TwigServiceProvider(), ['twig.path' => __DIR__ . "/views", 'twig.form.templates' => ['livetext/form/bootstrap.html.twig'], 'twig.options' => ['cache' => $app['debug'] ? null : __DIR__ . '/cache']]); /** * URL Generator Register */ $app->register(new \Silex\Provider\UrlGeneratorServiceProvider()); /** * Translation Register
use Symfony\Component\Console\Question\ConfirmationQuestion; use Knp\Provider\ConsoleServiceProvider; use Silex\Provider\DoctrineServiceProvider; use Dflydev\Silex\Provider\DoctrineOrm\DoctrineOrmServiceProvider; use Jsor\Doctrine\PostGIS\Event\ORMSchemaEventSubscriber; use Silex\Provider; class Application extends Silex\Application { use \Silex\Application\TwigTrait; use \Silex\Application\FormTrait; use \Silex\Application\SecurityTrait; use \Silex\Application\UrlGeneratorTrait; } $app = new Application(); $app['debug'] = APP_DEBUG; $app->register(new ConsoleServiceProvider(), array('console.name' => 'temporary', 'console.version' => 1, 'console.project_directory' => __DIR__ . '/..')); $app->register(new \Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); $app['twig.loader.filesystem']->addPath($config['wiki_dir'] . '/views/values', 'values'); // Import Database config, and start Doctrine service $dbconfig = (include $config['wiki_dir'] . "/app/config/db.include.php"); $dbconfig["driver"] = 'pdo_pgsql'; $app->register(new DoctrineServiceProvider(), array("db.options" => $dbconfig)); $app->register(new DoctrineOrmServiceProvider(), array("orm.em.options" => array("mappings" => array(array("type" => "annotation", "namespace" => "SeArch\\Entities", "path" => __DIR__ . "/../src/entities/", "alias" => ""), array("type" => "annotation", "namespace" => "MyApp\\Entities", "path" => $config['wiki_dir'] . "/src/entities/", "alias" => "app"))), "orm.custom.functions.string" => array("ST_Intersects" => "Jsor\\Doctrine\\PostGIS\\Functions\\ST_Intersects", "ST_Transform" => "Jsor\\Doctrine\\PostGIS\\Functions\\ST_Transform", "ST_Buffer" => "Jsor\\Doctrine\\PostGIS\\Functions\\ST_Buffer", "ST_SetSRID" => "Jsor\\Doctrine\\PostGIS\\Functions\\ST_SetSRID", "ST_Point" => "Jsor\\Doctrine\\PostGIS\\Functions\\ST_Point", 'ST_Distance' => 'Jsor\\Doctrine\\PostGIS\\Functions\\ST_Distance', 'ST_MakePolygon' => 'Jsor\\Doctrine\\PostGIS\\Functions\\ST_MakePolygon', 'ST_GeomFromText' => 'Jsor\\Doctrine\\PostGIS\\Functions\\ST_GeomFromText'), 'orm.auto_generate_proxies' => $app['debug'])); $app['orm.em']->getEventManager()->addEventSubscriber(new ORMSchemaEventSubscriber()); $app->match('/', function (Application $app) { $em = $app['orm.em']; $layerRepository = $em->getRepository(':Layer'); $layers = $layerRepository->findBy(array(), array('order_draw' => 'ASC')); $groupRepository = $em->getRepository(':Group'); $groups = $groupRepository->findBy(array(), array('order_legend' => 'ASC')); return $app['twig']->render('home.twig', array('layers' => $layers, "groups" => $groups));
<?php /** * Comando de de creación de estructura de document root */ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; if (!isset($console)) { $console = new Application(); } $console->register('psfs:create:root')->setDefinition(array(new InputArgument('path', InputArgument::OPTIONAL, 'Path en el que crear el Document Root')))->setDescription('Comando de creación del Document Root del projecto')->setCode(function (InputInterface $input, OutputInterface $output) { // Creates the html path $path = $input->getArgument('path'); if (empty($path)) { $path = WEB_DIR; } \PSFS\base\config\Config::createDir($path); $paths = array("js", "css", "img", "media", "font"); foreach ($paths as $htmlPath) { \PSFS\base\config\Config::createDir($path . DIRECTORY_SEPARATOR . $htmlPath); } // Generates the root needed files $files = ['_' => '_.php', 'browserconfig' => 'browserconfig.xml', 'crossdomain' => 'crossdomain.xml', 'humans' => 'humans.txt', 'robots' => 'robots.txt']; foreach ($files as $templates => $filename) { $text = \PSFS\base\Template::getInstance()->dump("generator/html/" . $templates . '.html.twig'); if (false === file_put_contents($path . DIRECTORY_SEPARATOR . $filename, $text)) { $output->writeln('Can\\t create the file ' . $filename); } else { $output->writeln($filename . ' created successfully'); }