コード例 #1
0
 public function setUp()
 {
     parent::setUp();
     // \Eccube\Applicationは重いから呼ばない
     $app = new \Silex\Application();
     $app->register(new \Silex\Provider\FormServiceProvider());
     $app->register(new \Eccube\ServiceProvider\ValidatorServiceProvider());
     $self = $this;
     $app['form.types'] = $app->share($app->extend('form.types', function ($types) use($app, $self) {
         $types[] = new \Eccube\Form\Type\PriceType($self->config);
         return $types;
     }));
     // CSRF tokenを無効にしてFormを作成
     $this->form = $app['form.factory']->createBuilder('price', null, array('csrf_protection' => false))->getForm();
 }
コード例 #2
0
 public function setUp()
 {
     parent::setUp();
     $app = new \Silex\Application();
     $app->register(new \Silex\Provider\FormServiceProvider());
     $app->register(new \Eccube\ServiceProvider\ValidatorServiceProvider());
     $app['form.types'] = $app->share($app->extend('form.types', function ($types) use($app) {
         $config['config']['name_len'] = 50;
         $types[] = new \Eccube\Form\Type\NameType($config['config']);
         // Nameに依存する
         return $types;
     }));
     // CSRF tokenを無効にしてFormを作成
     $this->form = $app['form.factory']->createBuilder('form', null, array('csrf_protection' => false))->add('name', 'name')->getForm();
 }
コード例 #3
0
ファイル: app.php プロジェクト: kevcom/scheduler
<?php

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\ParameterBag;
$app = new Silex\Application();
// Create the Silex application, in which all configuration is going to go
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$app['debug'] = true;
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../templates'));
$app['twig'] = $app->share($app->extend('twig', function ($twig, $app) {
    $twig->addFunction(new \Twig_SimpleFunction('asset', function ($asset) use($app) {
        return sprintf('%s/%s', trim($app['request']->getBasePath()), ltrim($asset, '/'));
        //return __DIR__.'/../assets';
    }));
    return $twig;
}));
$app->before(function (Request $request) {
    if (0 === strpos($request->headers->get('Content-Type'), 'application/json')) {
        $data = json_decode($request->getContent(), true);
        $request->request->replace(is_array($data) ? $data : array());
    }
});
return $app;
コード例 #4
0
ファイル: bootstrap.php プロジェクト: pygillier/tdfbdc
<?php

use Cocur\Slugify\Bridge\Twig\SlugifyExtension;
use Cocur\Slugify\Slugify;
require_once __DIR__ . '/../vendor/autoload.php';
$app = new Silex\Application();
// Data sources
$app['import_url'] = "http://www.letour.fr/le-tour/2015/fr/300/classement/bloc-classement-page/ITG.html";
// Locale
Locale::setDefault('fr-FR');
// Debug enabled
$app['debug'] = true;
// Url helpers
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
// Cache support
$app->register(new Silex\Provider\HttpCacheServiceProvider(), array('http_cache.cache_dir' => __DIR__ . '/../cache/'));
// Doctrine support
$app->register(new Silex\Provider\DoctrineServiceProvider(), array('db.options' => array('driver' => 'pdo_sqlite', 'path' => __DIR__ . '/../data/tdfbdc.db')));
// Twig support
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app['twig'] = $app->share($app->extend('twig', function ($twig, $app) {
    $twig->addExtension(new Twig_Extensions_Extension_Intl());
    $twig->addExtension(new SlugifyExtension(Slugify::create()));
    return $twig;
}));
// Controllers
require_once __DIR__ . "/controllers.php";
// Go !
$app->run();
コード例 #5
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
$app = new Silex\Application();
$config = array();
if (file_exists(__DIR__ . '/../config/config.php')) {
    require_once __DIR__ . '/../config/config.php';
}
$app['config'] = $config;
$app['config.dir'] = __DIR__ . '/../config';
$app->register(new Silex\Provider\DoctrineServiceProvider(), array('db.options' => $config['db']));
$app->register(new Silex\Provider\ServiceControllerServiceProvider());
if (isset($config['http_cache']) && $config['http_cache'] !== false) {
    $app->register(new Silex\Provider\HttpCacheServiceProvider(), array('http_cache.cache_dir' => __DIR__ . '/../cache/http', 'http_cache.esi' => null, 'http_cache.options' => isset($config['http_cache']) && is_array($config['http_cache']) ? $config['http_cache'] : array()));
}
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../templates', 'twig.options' => isset($config['twig']) ? $config['twig'] : array()));
// Set config as a global variable for templates.
$app['twig'] = $app->share($app->extend('twig', function ($twig, $app) use($config) {
    $twig->addGlobal('config', $config);
    return $twig;
}));
return $app;
コード例 #6
0
<?php

require_once __DIR__ . '/vendor/autoload.php';
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Routing\Loader\YamlFileLoader;
use Symfony\Component\Routing\RouteCollection;
$app = new Silex\Application();
//load routes from config/routes.yml
$app['routes'] = $app->extend('routes', function (RouteCollection $routes, Silex\Application $app) {
    $loader = new YamlFileLoader(new FileLocator(__DIR__ . '/config'));
    $collection = $loader->load('routes.yml');
    $routes->addCollection($collection);
    return $routes;
});
//register logger
$app->register(new Silex\Provider\MonologServiceProvider(), array('monolog.logfile' => __DIR__ . '/log/dev.log'));
$m = new MongoClient();
$app['db'] = $m->timeshare;
return $app;
//$app->run();
コード例 #7
0
ファイル: App.php プロジェクト: nicolastorre/portfolio
$app['userController'] = $app->share(function () use($app) {
    return new Portfolio\Classes\Controller\UserController(array('userRepository' => $app['userRepository']));
});
$app['staticController'] = $app->share(function () use($app) {
    return new Portfolio\Classes\Controller\StaticController();
});
$app['paiementController'] = $app->share(function () use($app) {
    return new Portfolio\Classes\Controller\PaiementController();
});
// Bootstrap the application
$app->boot();
/* Variables Glabal et Extensions TWIG */
$app['twig']->addGlobal('links', array('email' => "#", 'linkedin' => "https://fr.linkedin.com/in/nicotorre", 'twitter' => "https://twitter.com/nicowez", 'github' => "https://github.com/nicolastorre"));
$app['twig']->addGlobal('recentArticles', $app['articleRepository']->findLast());
$app['twig'] = $app->share($app->extend('twig', function ($twig, $app) {
    $twig->addExtension(new \Portfolio\Classes\Twig\Extension\ImgDirExtension($app));
    return $twig;
}));
$app['twig'] = $app->share($app->extend('twig', function ($twig, $app) {
    $twig->addExtension(new \Portfolio\Classes\Twig\Extension\UserExtension($app));
    return $twig;
}));
$app['twig'] = $app->share($app->extend('twig', function ($twig, $app) {
    $twig->addExtension(new \Portfolio\Classes\Twig\Extension\DeleteFormExtension($app));
    return $twig;
}));
$app['twig'] = $app->share($app->extend('twig', function ($twig, $app) {
    $twig->addExtension(new Twig_Extensions_Extension_Text());
    return $twig;
}));
/* Gestion des erreurs */
if (isset($app['debug']) and !$app['debug']) {
コード例 #8
0
ファイル: PriceTypeTest.php プロジェクト: ec-cube/ec-cube
 public function createApplication()
 {
     // \Eccube\Applicationは重いから呼ばない
     $app = new \Silex\Application();
     $app->register(new \Silex\Provider\FormServiceProvider());
     $app->register(new \Eccube\ServiceProvider\ValidatorServiceProvider());
     $app['eccube.service.plugin'] = $app->share(function () use($app) {
         return new \Eccube\Service\PluginService($app);
     });
     $self = $this;
     $app['form.types'] = $app->share($app->extend('form.types', function ($types) use($app, $self) {
         $types[] = new \Eccube\Form\Type\PriceType($self->config);
         return $types;
     }));
     return $app;
 }
コード例 #9
0
ファイル: index.php プロジェクト: juanmadlg/coopTip
$app = new Silex\Application();
$app['debug'] = true;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Translation\Loader\YamlFileLoader;
// Register Service Provider (IOD)
$app->register(new Silex\Provider\ServiceControllerServiceProvider());
// Register Session
$app->register(new Silex\Provider\SessionServiceProvider());
// Register Monolog (log service)
$app->register(new Silex\Provider\MonologServiceProvider(), array('monolog.logfile' => __DIR__ . '/development.log'));
// Register Translation Service
$app->register(new Silex\Provider\TranslationServiceProvider());
$app['translator'] = $app->share($app->extend('translator', function ($translator, $app) {
    $translator->addLoader('yaml', new YamlFileLoader());
    $translator->addResource('yaml', __DIR__ . '/locales/en.yml', 'en');
    $translator->addResource('yaml', __DIR__ . '/locales/es.yml', 'es');
    return $translator;
}));
// Register Twig (templates service)
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/views'));
// Register Doctrine (mySql provider)
$configuration = getConfiguration();
$app->register(new Silex\Provider\DoctrineServiceProvider(), array('db.options' => array('driver' => 'pdo_mysql', 'host' => $configuration['host'], 'dbname' => $configuration['dbname'], 'user' => $configuration['user'], 'password' => $configuration['password'], 'charset' => 'utf8', 'driverOptions' => array(1002 => 'SET NAMES utf8'))));
// Register Security Provider
$app->register(new Silex\Provider\SecurityServiceProvider(), array('security.firewalls' => array('account' => array('pattern' => '^/account/', 'form' => array('login_path' => '/login', 'check_path' => '/account/login_check'), 'logout' => array('logout_path' => '/account/logout'), 'users' => $app->share(function () use($app) {
    return new UserProvider($app['db']);
})))));
// Managers declaration
$app['accountManager'] = function ($app) {
    return new AccountManager($app['db'], $app["monolog"]);
};
コード例 #10
0
ファイル: bootstrap.php プロジェクト: amdad/portfolio
require_once __DIR__ . '/config.php';
require_once __DIR__ . '/functions.php';
$app = new Silex\Application();
$app['debug'] = true;
$app->register(new Silex\Provider\TwigServiceProvider(), unserialize(TWIG_CONFIG));
$app['twig'] = $app->share($app->extend('twig', function (Twig_Environment $twig, Silex\Application $app) {
    $twig->addGlobal('globals', unserialize(TWIG_GLOBALS));
    $filter = new Twig_SimpleFilter('form', function ($string) {
        return form($string);
    });
    $twig->addFilter($filter);
    $click = new Twig_SimpleFilter('clickable', function ($string) {
        return Twitter::clickable($string);
    });
    $twig->addFilter($click);
    $markdown = new Twig_SimpleFilter('md', function ($string) {
        return cockpit("cockpit")->markdown($string);
    });
    $twig->addFilter($markdown);
    $thumb = new Twig_SimpleFilter('thumb', function ($string) {
        return cockpit("mediamanager")->thumbnail($string, "300", "100");
    });
    $twig->addFilter($thumb);
    $crop = new Twig_SimpleFilter('crop', function ($string, $size) {
        $par = explode(",", $size);
        return cockpit("mediamanager")->thumbnail($string, $par[0], $par[1]);
    });
    $twig->addFilter($crop);
    return $twig;
}));
return $app;
コード例 #11
0
ファイル: assetic.php プロジェクト: kevcom/scheduler
<?php

$app = new Silex\Application();
$app->register(new Silex\Extension\TwigExtension());
$app['twig.path'] = __DIR__ . '/twig';
$app->register(new SilexAssetic\AsseticServiceProvider());
$app['assetic.path_to_web'] = __DIR__ . '/assetic/output';
$app['assetic.options'] = array('formulae_cache_dir' => __DIR__ . '/assetic/cache', 'debug' => false);
$app['assetic.filter_manager'] = $app['assetic.filter_manager'] = $app->share($app->extend('assetic.filter_manager', function ($fm, $app) {
    $fm->set('yui_css', new Assetic\Filter\Yui\CssCompressorFilter('/usr/share/yui-compressor/yui-compressor.jar'));
    $fm->set('yui_js', new Assetic\Filter\Yui\JsCompressorFilter('/usr/share/yui-compressor/yui-compressor.jar'));
    return $fm;
}));
$app['assetic.asset_manager'] = $app->share($app->extend('assetic.asset_manager', function ($am, $app) {
    $am->set('styles', new Assetic\Asset\AssetCache(new Assetic\Asset\GlobAsset(__DIR__ . '/assetic/resources/css/*.css', array($fm->get('yui_css'))), new Assetic\Cache\FilesystemCache(__DIR__ . '/assetic/cache')));
    $am->get('styles')->setTargetPath('css/styles');
    return $am;
}));
$app->get('/', function () use($app) {
    return 'Hello!';
});
$app->run();
コード例 #12
0
ファイル: index.php プロジェクト: julkapuk/project_silex
<?php

ini_set('error_reporting', E_ALL);
ini_set('display_errors', E_ALL);
require_once dirname(dirname(__FILE__)) . '/vendor/autoload.php';
use Symfony\Component\Translation\Loader\YamlFileLoader;
$app = new Silex\Application();
$app['debug'] = true;
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => dirname(dirname(__FILE__)) . '/src/views'));
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$app->register(new Silex\Provider\TranslationServiceProvider(), array('locale' => 'pl', 'locale_fallbacks' => array('pl')));
$app['translator'] = $app->share($app->extend('translator', function ($translator, $app) {
    $translator->addLoader('yaml', new YamlFileLoader());
    $translator->addResource('yaml', dirname(dirname(__FILE__)) . '/config/locales/pl.yml', 'pl');
    return $translator;
}));
$app->register(new Silex\Provider\SessionServiceProvider());
$app->register(new Silex\Provider\FormServiceProvider());
$app->register(new Silex\Provider\ValidatorServiceProvider());
$app->register(new Silex\Provider\SecurityServiceProvider(), array('security.firewalls' => array('admin' => array('pattern' => '^.*$', 'form' => array('login_path' => 'auth_login', 'check_path' => 'auth_login_check', 'default_target_path' => '/', 'username_parameter' => 'loginForm[login]', 'password_parameter' => 'loginForm[password]'), 'anonymous' => true, 'logout' => array('logout_path' => 'auth_logout', 'target_url' => '/'), 'users' => $app->share(function () use($app) {
    return new Provider\UserProvider($app);
}))), 'security.access_rules' => array(array('^/.+$', 'IS_AUTHENTICATED_ANONYMOUSLY'), array('^/images/u/add', 'ROLE_USER'), array('^/admin/.+$', 'ROLE_ADMIN')), 'security.role_hierarchy' => array('ROLE_ADMIN' => array('ROLE_USER'))));
//var_dump($app['security.encoder.digest']->encodePassword('password', ''));
$app->mount('/hello', new Controller\HelloController());
$app->mount('/', new Controller\IndexController());
$app->mount('auth', new Controller\AuthController());
$app->mount('/registration', new Controller\RegistrationController());
$app->mount('/comments', new Controller\CommentsController());
$app->mount('/images', new Controller\ImagesController());
$app->mount('/photos', new Controller\PhotosController());
$app->run();
コード例 #13
0
 public function createApplication()
 {
     $app = new \Silex\Application();
     $app->register(new \Silex\Provider\FormServiceProvider());
     $app->register(new \Eccube\ServiceProvider\ValidatorServiceProvider());
     $app['eccube.service.plugin'] = $app->share(function () use($app) {
         return new \Eccube\Service\PluginService($app);
     });
     // fix php5.3
     $self = $this;
     $app['form.types'] = $app->share($app->extend('form.types', function ($types) use($app, $self) {
         $types[] = new \Eccube\Form\Type\RepeatedEmailType();
         return $types;
     }));
     return $app;
 }
コード例 #14
0
ファイル: app.php プロジェクト: ronanguilloux/silexmarkdown
$env = isset($env) ? $env : 'prod';
if (in_array($env, array('dev', 'test', 'prod'))) {
    require __DIR__ . "/../../resources/config/{$env}.php";
}
// -----------------------------------------------
// Services registering
$app->register(new HttpCacheServiceProvider());
// see ./resources/config
$app->register(new TwigServiceProvider(), array('twig.path' => __DIR__ . '/views', 'twig.class_path' => __DIR__ . '/../vendor/twig/lib'));
$app->register(new MarkdownServiceProvider(), array('md.path' => __DIR__ . '/../../resources/markdown'));
// -----------------------------------------------
// Assetic configuration
if (isset($app['assetic.enabled']) && $app['assetic.enabled']) {
    $app->register(new AsseticServiceProvider(), array('assetic.options' => array('debug' => $app['debug'], 'auto_dump_assets' => $app['debug'])));
    $app['assetic.filter_manager'] = $app->share($app->extend('assetic.filter_manager', function ($fm, $app) {
        $fm->set('lessphp', new Assetic\Filter\LessphpFilter());
        return $fm;
    }));
    $app['assetic.asset_manager'] = $app->share($app->extend('assetic.asset_manager', function ($am, $app) {
        $am->set('styles', new Assetic\Asset\AssetCache(new Assetic\Asset\GlobAsset($app['assetic.input.path_to_css'], array($app['assetic.filter_manager']->get('lessphp'))), new Assetic\Cache\FilesystemCache($app['assetic.path_to_cache'])));
        $am->get('styles')->setTargetPath($app['assetic.output.path_to_css']);
        $am->set('scripts', new Assetic\Asset\AssetCache(new Assetic\Asset\GlobAsset($app['assetic.input.path_to_js']), new Assetic\Cache\FilesystemCache($app['assetic.path_to_cache'])));
        $am->get('scripts')->setTargetPath($app['assetic.output.path_to_js']);
        return $am;
    }));
}
// -----------------------------------------------
// Controllers
$app->match('/', function () use($app) {
    return $app->redirect('/0');
})->bind('homepage');
$app->match('/{res}', function ($res) use($app) {
コード例 #15
0
ファイル: Bootstrap.php プロジェクト: themrwilliams/opencfp
 function getApp()
 {
     if (isset($this->_app)) {
         return $this->_app;
     }
     // Initialize out Silex app and let's do it
     $app = new \Silex\Application();
     if ($this->getConfig('twig.debug')) {
         $app['debug'] = $this->getConfig('twig.debug');
     }
     // Register our session provider
     $app->register(new \Silex\Provider\SessionServiceProvider());
     $app->before(function ($request) use($app) {
         $app['session']->start();
     });
     $app['url'] = $this->getConfig('application.url');
     $app['uploadPath'] = $this->getConfig('upload.path');
     $app['confAirport'] = $this->getConfig('application.airport');
     $app['arrival'] = $this->getConfig('application.arrival');
     $app['departure'] = $this->getConfig('application.departure');
     // Register the Twig provider and lazy-load the global values
     $app->register(new \Silex\Provider\TwigServiceProvider(), array('twig.path' => APP_DIR . $this->getConfig('twig.template_dir')));
     $that = $this;
     $app['twig'] = $app->share($app->extend('twig', function ($twig, $app) use($that) {
         $twig->addGlobal('site', array('url' => $that->getConfig('application.url'), 'title' => $that->getConfig('application.title'), 'email' => $that->getConfig('application.email'), 'eventurl' => $that->getConfig('application.eventurl'), 'enddate' => $that->getConfig('application.enddate')));
         return $twig;
     }));
     // Register our use of the Form Service Provider
     $app->register(new \Silex\Provider\FormServiceProvider());
     $app->register(new \Silex\Provider\ValidatorServiceProvider());
     $app->register(new \Silex\Provider\TranslationServiceProvider(), array('translator.messages' => array()));
     $app['db'] = $this->getDb();
     $app['spot'] = $this->getSpot();
     $app['purifier'] = $this->getPurifier();
     // We're using Sentry, so make it available to app
     $app['sentry'] = $app->share(function () use($app) {
         $hasher = new \Cartalyst\Sentry\Hashing\NativeHasher();
         $userProvider = new \Cartalyst\Sentry\Users\Eloquent\Provider($hasher);
         $groupProvider = new \Cartalyst\Sentry\Groups\Eloquent\Provider();
         $throttleProvider = new \Cartalyst\Sentry\Throttling\Eloquent\Provider($userProvider);
         $session = new \OpenCFP\SymfonySentrySession($app['session']);
         $cookie = new \Cartalyst\Sentry\Cookies\NativeCookie(array());
         $sentry = new \Cartalyst\Sentry\Sentry($userProvider, $groupProvider, $throttleProvider, $session, $cookie);
         \Cartalyst\Sentry\Facades\Native\Sentry::setupDatabaseResolver($app['db']);
         $throttleProvider->disable();
         return $sentry;
     });
     $app['twig'] = $app->share($app->extend('twig', function ($twig, $app) {
         $twig->addGlobal('user', $app['sentry']->getUser());
         return $twig;
     }));
     // Configure our flash messages functionality
     $app->before(function () use($app) {
         $flash = $app['session']->get('flash');
         $app['session']->set('flash', null);
         if (!empty($flash)) {
             $app['twig']->addGlobal('flash', $flash);
         }
     });
     // Add current page global
     $app->before(function (Request $request) use($app) {
         $app['twig']->addGlobal('current_page', $request->getRequestUri());
     });
     // Define error template paths
     if (!$app['debug']) {
         $app->error(function (\Exception $e, $code) use($app) {
             switch ($code) {
                 case 401:
                     $message = $app['twig']->render('error/401.twig');
                     break;
                 case 403:
                     $message = $app['twig']->render('error/403.twig');
                     break;
                 case 404:
                     $message = $app['twig']->render('error/404.twig');
                     break;
                 default:
                     $message = $app['twig']->render('error/500.twig');
             }
             return new Response($message, $code);
         });
     }
     $app = $this->defineRoutes($app);
     // Add the starting date for submissions
     $app['cfpdate'] = $this->getConfig('application.cfpdate');
     return $app;
 }
コード例 #16
0
ファイル: index.php プロジェクト: princebabay/WebCup2015
    $arrayObj = [];
    foreach ($results as $value) {
        $myObject = new myObject();
        $myObject->setId($value['id']);
        $myObject->setTitle($value['title']);
        $myObject->setSummary($value['summary']);
        $myObject->setText($value['text']);
        $myObject->setImg($value['img']);
        $arrayObj[] = $myObject;
    }
    return $app['twig']->render('search.twig', array('search' => 'true', 'results' => $results, 'keyword' => $keyword));
})->method('POST');
$app['twig'] = $app->share($app->extend('twig', function ($twig, $app) {
    $twig->addFunction(new \Twig_SimpleFunction('asset', function ($asset) {
        // implement whatever logic you need to determine the asset path
        return sprintf('http://localhost/webcup2015/web/views/%s', ltrim($asset, '/'));
    }));
    return $twig;
}));
$blogPosts = array(1 => array('date' => '2011-03-29', 'author' => 'igorw', 'title' => 'Using Silex', 'body' => '...'), 2 => array('date' => '2011-03-30', 'author' => 'hgignore', 'title' => 'Using Silex 1.2', 'body' => '...'));
$blog = $app['controllers_factory'];
$blog->get('/', function () {
    return 'Blog home page';
});
$forum = $app['controllers_factory'];
$forum->get('/', function () {
    return 'Forum home page';
});
$app->mount('/blog', $blog);
$app->mount('/forum', $forum);
$app['debug'] = true;
コード例 #17
0
ファイル: app.php プロジェクト: digitas/digex
<?php

require_once __DIR__ . '/../vendor/autoload.php';
umask(00);
//This will let the permissions be 0777
$app = new Silex\Application();
$app->register(new Digex\Provider\DigexServiceProvider());
$app['translator'] = $app->share($app->extend('translator', function ($translator, $app) {
    $translator->addLoader('yaml', new Symfony\Component\Translation\Loader\YamlFileLoader());
    $filename = __DIR__ . '/trans/' . $app['locale'] . '.yml';
    if (file_exists($filename)) {
        $translator->addResource('yaml', $filename, $app['locale']);
    }
    return $translator;
}));
/** CUSTOMIZE HERE **/
$app->mount('/', new Digitas\Demo\Controller\DefaultControllerProvider());
$app->mount('/admin', new Digitas\Admin\Controller\SecurityControllerProvider());
$app->mount('/admin', new Digitas\Admin\Controller\DefaultControllerProvider());
return $app;
コード例 #18
0
ファイル: app.php プロジェクト: astranchet/pamplemousse
use DerAlex\Silex\YamlConfigServiceProvider;
$app = new Silex\Application();
/** Configuration */
$app->register(new YamlConfigServiceProvider(__DIR__ . '/../config/app.yml'));
/** Debug **/
$app['debug'] = $app['config']['debug'];
/**  Application */
$app->register(new DoctrineServiceProvider(), array('db.options' => $app['config']['database']));
$app->register(new FormServiceProvider());
$app->register(new MonologServiceProvider(), array('monolog.logfile' => __DIR__ . '/../log/app.log', 'monolog.name' => 'pamplemousse', 'monolog.level' => 100));
$app->register(new Silex\Provider\SecurityServiceProvider(), array('security.firewalls' => array('admin' => array('pattern' => '^/admin', 'form' => array('login_path' => '/login', 'check_path' => '/admin/login_check'), 'logout' => array('logout_path' => '/admin/logout', 'invalidate_session' => true), 'users' => $app['config']['users']))));
$app->register(new SessionServiceProvider());
$app->register(new TranslationServiceProvider(), array('translator.messages' => array()));
$app->register(new TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app['twig'] = $app->share($app->extend('twig', function ($twig, $app) {
    $twig->addExtension(new Pamplemousse\Twig_Extension\DatesFilter($app['config']));
    return $twig;
}));
$app->register(new UrlGeneratorServiceProvider());
/** Services */
$app['user'] = $app->share(function ($app) {
    $token = $app['security.token_storage']->getToken();
    if ($token !== null) {
        return $token->getUser();
    }
    return null;
});
$app['comments'] = $app->share(function ($app) {
    return new Pamplemousse\Comments\Service($app);
});
$app['photos'] = $app->share(function ($app) {
    return new Pamplemousse\Photos\Service($app);
コード例 #19
0
ファイル: FaxTypeTest.php プロジェクト: geany-y/LikeNiko
 public function createApplication()
 {
     // \Eccube\Applicationは重いから呼ばない
     $app = new \Silex\Application();
     $app->register(new \Silex\Provider\FormServiceProvider());
     $app->register(new \Eccube\ServiceProvider\ValidatorServiceProvider());
     $app['form.types'] = $app->share($app->extend('form.types', function ($types) use($app) {
         $types[] = new \Eccube\Form\Type\TelType();
         $types[] = new \Eccube\Form\Type\FaxType();
         return $types;
     }));
     return $app;
 }
コード例 #20
0
ファイル: index.php プロジェクト: Addvilz/website
 * @return array
 */
$getPaste = function ($db, $id) {
    $stmt = $db->prepare('SELECT * FROM paste WHERE paste_id = :id');
    $stmt->execute(array('id' => $id));
    return $stmt->fetch();
};
/**
 * Build the application, and set-up twig integration.
 */
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app['twig'] = $app->share($app->extend('twig', function ($twig, $app) use($config) {
    if (isset($config['debug']) && $config['debug'] == true) {
        $twig->addFilter('var_dump', new \Twig_Filter_Function('var_dump'));
        $app['debug'] = true;
    }
    $twig->addFilter('highlight', new \Twig_Filter_Function('highlightSaffire'));
    return $twig;
}));
/**
 * Display the homepage.
 * 
 * @todo We might want to reconsider how we do highlighting: maybe it would be 
 * easier to do on the fly?
 */
$app->get('/', function () use($app, $db, $getRecent) {
    return $app['twig']->render('home.html.twig', array('recent' => $getRecent($db), 'name' => isset($_COOKIE['name']) ? $_COOKIE['name'] : ''));
});
/**
 * Display the codepad.
 */
コード例 #21
0
ファイル: index.php プロジェクト: ilosada/chamilo-lms-icpna
$app['sys_config_path'] = isset($_configuration['sys_config_path']) ? $_configuration['sys_config_path'] : $app['root_sys'] . 'config/';
$app['sys_course_path'] = isset($_configuration['sys_course_path']) ? $_configuration['sys_course_path'] : $app['sys_data_path'] . '/course';
$app['sys_log_path'] = isset($_configuration['sys_log_path']) ? $_configuration['sys_log_path'] : $app['root_sys'] . 'logs/';
$app['sys_temp_path'] = isset($_configuration['sys_temp_path']) ? $_configuration['sys_temp_path'] : $app['sys_data_path'] . 'temp/';
// Registering services
$app['debug'] = false;
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$app->register(new Silex\Provider\FormServiceProvider());
$app->register(new Silex\Provider\SessionServiceProvider());
$app->register(new Silex\Provider\DoctrineServiceProvider());
$app->register(new Silex\Provider\TranslationServiceProvider());
$app['translator'] = $app->share($app->extend('translator', function ($translator, $app) {
    /*$translator->addLoader('pofile', new PoFileLoader());
      $file = 'main/locale/'.$locale.'.po';
      $translator->addResource('pofile', $file, $locale);*/
    /*$translator->addLoader('yaml', new Symfony\Component\Translation\Loader\YamlFileLoader());
      $translator->addResource('yaml', __DIR__.'/lang/fr.yml', 'fr');
      $translator->addResource('yaml', __DIR__.'/lang/en.yml', 'en');
      $translator->addResource('yaml', __DIR__.'/lang/es.yml', 'es');*/
    return $translator;
}));
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => array('templates'), 'twig.options' => array('debug' => $app['debug'], 'charset' => 'utf-8', 'strict_variables' => false, 'autoescape' => true, 'cache' => false, 'optimizations' => -1)));
use Knp\Provider\ConsoleServiceProvider;
$app->register(new ConsoleServiceProvider(), array('console.name' => 'Chamilo', 'console.version' => '1.0.0', 'console.project_directory' => __DIR__ . '/..'));
// Adding commands.
/** @var Knp\Console\Application $console */
$console = $app['console'];
$console->addCommands(array(new \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand(), new \Doctrine\DBAL\Tools\Console\Command\ImportCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand(), new Chash\Command\Installation\UpgradeCommand(), new Chash\Command\Installation\InstallCommand(), new Chash\Command\Files\CleanDataFilesCommand(), new Chash\Command\Files\CleanTempFolderCommand(), new Chash\Command\Files\CleanConfigFilesCommand(), new Chash\Command\Files\MailConfCommand(), new Chash\Command\Files\SetPermissionsAfterInstallCommand(), new Chash\Command\Files\GenerateTempFileStructureCommand()));
$helpers = array('configuration' => new Chash\Helpers\ConfigurationHelper());
$helperSet = $console->getHelperSet();
foreach ($helpers as $name => $helper) {
    $helperSet->set($helper, $name);
コード例 #22
0
ファイル: index.php プロジェクト: Av007/quickform
$app['debug'] = $config['debug'];
if ($app['debug']) {
    ini_set('display_errors', 1);
}
$app->register(new ValidatorServiceProvider());
$app->register(new FormServiceProvider());
$app->register(new SwiftmailerServiceProvider(), array_replace($config['mail'], array('disable_delivery' => $config['debug'])));
$app->register(new UrlGeneratorServiceProvider());
$app->register(new SessionServiceProvider());
$app->register(new Silex\Provider\TranslationServiceProvider(), array('locale_fallback' => $config['locale'], 'locale' => $config['locale'], 'translator.domains' => array()));
// enable database
$app->register(new Silex\Provider\DoctrineServiceProvider(), array('db.options' => array('driver' => 'pdo_sqlite', 'path' => MAIN_PATH . '/app.db')));
// enable localization
$app['translator'] = $app->share($app->extend('translator', function (Silex\Translator $translator) {
    $translator->addLoader('yaml', new YamlFileLoader());
    $translator->addResource('yaml', MAIN_PATH . '/locales/en.yml', 'en');
    $translator->addResource('yaml', MAIN_PATH . '/locales/ru.yml', 'ru');
    return $translator;
}));
$app->register(new Silex\Provider\MonologServiceProvider(), array('monolog.logfile' => MAIN_PATH . '/logs/app.log'));
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => array(MAIN_PATH . '/views'), 'twig.options' => array('cache' => MAIN_PATH . '/cache/twig')));
$app->before(function () use($app) {
    $app['translator']->addLoader('xlf', new XliffFileLoader());
    $app['translator']->addResource('xlf', __DIR__ . '/../vendor/symfony/validator/Resources/translations/validators.ru.xlf', 'ru', 'validators');
});
/** @var \Symfony\Component\HttpFoundation\Session\Session $session */
$session = $app['session'];
$session->start();
if ($lang = $session->get('locale', $config['locale'])) {
    // apply localization
    /*$app->before(function () use ($app, $lang) {
            $app['locale'] = $lang;
コード例 #23
0
ファイル: AppKernel.php プロジェクト: allejo/WuPulse
<?php

use allejo\DaPulse\PulseBoard;
// Create the main application
$app = new Silex\Application();
// Register kernel extensions
$app->register(new DerAlex\Silex\YamlConfigServiceProvider(__DIR__ . '/../config.yml'));
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
// Register Twig extensions
$app['twig'] = $app->share($app->extend('twig', function ($twig, $app) {
    $twig->addExtension(new allejo\DaPulser\Twig\DateParserFilter($app));
    $twig->addExtension(new allejo\DaPulser\Twig\WufooUploadFilter($app));
    return $twig;
}));
// Setup our DaPulse library
PulseBoard::setApiKey($app['config']['dapulse']['apikey']);
return $app;
コード例 #24
0
ファイル: app.php プロジェクト: rev42/revpdf
    } else {
        return $app->redirect($app['url_generator']->generate('homepage', array('locale' => $app['locale.fallback'])));
    }
});
/**
 * Services:
 *
 * translator: An instance of Translator, that is used for translation.
 * translator.loader: An instance of an implementation of the translation
 *                    LoaderInterface, defaults to an ArrayLoader.
 * translator.message_selector: An instance of MessageSelector.
 */
$app->register(new TranslationServiceProvider(), array('locale.fallback' => $app['locale_fallback']));
$app['translator'] = $app->share($app->extend('translator', function ($translator, $app) {
    $translator->addLoader('yaml', new YamlFileLoader());
    $translator->addResource('yaml', __DIR__ . '/../resources/locales/en.yml', 'en');
    $translator->addResource('yaml', __DIR__ . '/../resources/locales/fr.yml', 'fr');
    return $translator;
}));
/**
 * Services:
 *  monolog: The monolog logger instance.
 *  monolog.configure: Protected closure that takes the logger as an argument.
 * You can override it if you do not want the default behavior.
 *      100 => 'DEBUG',
 *      200 => 'INFO',
 *      300 => 'WARNING',
 *      400 => 'ERROR',
 *      500 => 'CRITICAL',
 *      550 => 'ALERT',
 */
$app->register(new MonologServiceProvider(), array('monolog.logfile' => $app['log.filepath'], 'monolog.name' => 'app', 'monolog.level' => $app['debug'] == 1 ? 100 : 400));
コード例 #25
0
ファイル: app.php プロジェクト: Takuto88/start
}
/* i18n support */
$app->register(new Silex\Provider\TranslationServiceProvider());
$app['locales'] = $app->share(function () use($app) {
    // Read available locales
    $localeFiles = glob(__DIR__ . '/resources/i18n/*.php');
    $locales = array();
    foreach ($localeFiles as $file) {
        $locale = basename($file, ".php");
        $locales[$locale] = $file;
    }
    return $locales;
});
$app['translator'] = $app->share($app->extend('translator', function ($translator, $app) {
    foreach ($app['locales'] as $locale => $file) {
        $translator->addResource('array', require $file, $locale);
    }
    return $translator;
}));
$app['twig']->addExtension(new Symfony\Bridge\Twig\Extension\TranslationExtension($app['translator']));
/* Dependency Injection wiring */
$app['service.messages'] = $app->share(function () use($app) {
    return new Start\Service\Impl\MessageServiceImpl($app['orm.em']);
});
$app['controllers.helloworld'] = $app->share(function () use($app) {
    return new Start\Controller\HelloWorldController($app['twig']);
});
$app['controllers.messages'] = $app->share(function () use($app) {
    return new Start\Controller\MessageController($app['service.messages']);
});
return $app;
コード例 #26
0
ファイル: index.php プロジェクト: Newleatk/ist
---------------------------------------------------------------------------------------*/
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
/*---------------------------------------------------------------------------------------
---------------------------------------SILEX DEBUGGING-----------------------------------
---------------------------------------------------------------------------------------*/
$app['debug'] = true;
/*---------------------------------------------------------------------------------------
-----------------------------------DATABASE DECLARATION----------------------------------
---------------------------------------------------------------------------------------*/
include_once "requires/db.php";
/*---------------------------------------------------------------------------------------
---------------------------------------NAV DEFINITION------------------------------------
---------------------------------------------------------------------------------------*/
$app['twig'] = $app->share($app->extend('twig', function ($twig) {
    $twig->addGlobal('nav', array(array("text" => "Home", "url" => "index", "children" => array(array("text" => "Dashboard", "url" => "index"))), array("text" => "Issues", "url" => "issues", "children" => array(array("text" => "Show on hold issues", "url" => "issues", "params" => array("tag" => "on_hold")), array("text" => "Show open issues", "url" => "issues", "params" => array("tag" => "open")), array("text" => "Show resolved issues", "url" => "issues", "params" => array("tag" => "resolved"), "separator" => true), array("text" => "Show latest issues", "url" => "issues", "params" => array("sort_by" => "latest"))))));
    $twig->addGlobal('timestamp_now', time());
    return $twig;
}));
/*---------------------------------------------------------------------------------------
----------------------------------------ROUTING NAME-------------------------------------
---------------------------------------------------------------------------------------*/
$app->before(function (Request $request) use($app) {
    $app['twig']->addGlobal('current_page_name', $request->get("_route"));
});
/*---------------------------------------------------------------------------------------
-----------------------------------------INDEX PAGE--------------------------------------
---------------------------------------------------------------------------------------*/
$app->get('/', function () use($db, $app) {
    return $app['twig']->render('index.twig', array());
})->bind("index");
/*---------------------------------------------------------------------------------------
コード例 #27
0
ファイル: init.php プロジェクト: Devdits/pinboard
require_once __DIR__ . '/../vendor/autoload.php';
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Pinboard\Logger\DbalLogger;
use Pinboard\Stopwatch\Stopwatch;
$app = new Silex\Application();
$app['params'] = Symfony\Component\Yaml\Yaml::parse(file_get_contents(__DIR__ . '/../config/parameters.yml'));
$app->register(new Silex\Provider\SessionServiceProvider());
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app['twig'] = $app->share($app->extend('twig', function ($twig, $app) {
    if (!isset($app['params']['base_url']) || empty($app['params']['base_url'])) {
        $baseUrl = '/';
    } else {
        $baseUrl = $app['params']['base_url'];
    }
    if (substr($baseUrl, -1) != '/') {
        $baseUrl .= '/';
    }
    $twig->addGlobal('base_url', $baseUrl);
    return $twig;
}));
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$dbOptions = array('driver' => 'pdo_mysql', 'dbname' => $app['params']['db']['name'], 'host' => $app['params']['db']['host'], 'user' => $app['params']['db']['user'], 'password' => $app['params']['db']['pass']);
if (isset($app['params']['db']['port'])) {
    $dbOptions['port'] = $app['params']['db']['port'];
}
if (isset($app['params']['db']['unix_socket'])) {
    $dbOptions['unix_socket'] = $app['params']['db']['unix_socket'];
}
$app->register(new Silex\Provider\DoctrineServiceProvider(), array('db.options' => $dbOptions));
$app['dbs.config']['default']->setSQLLogger(new DbalLogger(new Stopwatch(), $app['params']['db']['host']));
コード例 #28
0
ファイル: TelTypeTest.php プロジェクト: hiroyasu55/ec-cube
 public function createApplication()
 {
     $app = new \Silex\Application();
     $app->register(new \Silex\Provider\FormServiceProvider());
     $app->register(new \Eccube\ServiceProvider\ValidatorServiceProvider());
     // fix php5.3
     $self = $this;
     $app['form.types'] = $app->share($app->extend('form.types', function ($types) use($app, $self) {
         $types[] = new \Eccube\Form\Type\TelType($self->config);
         return $types;
     }));
     return $app;
 }
コード例 #29
0
$app['debug'] = true;
//
// Twig
//
$app->register(new TwigServiceProvider(), array('twig.path' => __DIR__ . '/templates', 'twig.options' => array('cache' => __DIR__ . '/../cache/twig', 'debug' => $app['debug'], 'strict_variables' => true)));
//
// Translator
//
$app->register(new TranslationServiceProvider(), array('locale' => 'fr', 'locale_fallback' => 'fr'));
$app['translator'] = $app->share($app->extend('translator', function ($translator, $app) {
    $translator->addLoader('yaml', new YamlFileLoader());
    if (file_exists(__DIR__ . '/locales/messages.en.yml')) {
        $translator->addResource('yaml', __DIR__ . '/locales/messages.en.yml', 'en');
    }
    if (file_exists(__DIR__ . '/locales/messages.de.yml')) {
        $translator->addResource('yaml', __DIR__ . '/locales/messages.de.yml', 'de');
    }
    if (file_exists(__DIR__ . '/locales/messages.fr.yml')) {
        $translator->addResource('yaml', __DIR__ . '/locales/messages.fr.yml', 'fr');
    }
    return $translator;
}));
//
// Assetic
//
$app->register(new SilexAssetic\AsseticServiceProvider());
$app['assetic.path_to_web'] = __DIR__ . '/../web';
$app['assetic.options'] = array('auto_dump_assets' => true);
$app['assetic.filter_manager'] = $app->share($app->extend('assetic.filter_manager', function ($fm, $app) {
    $node = getenv('NODE_BIN_PATH') === false ? '/usr/bin/js' : getenv('NODE_BIN_PATH');
    $fm->set('less', new Assetic\Filter\LessFilter($node));
コード例 #30
0
ファイル: app.php プロジェクト: deanc/silex-starter-pack
    } else {
        if ($locale = $app['session']->get('locale')) {
            $app['locale'] = $locale;
        }
    }
});
// do some security stuff
$app->after(function (Request $request, Response $response) {
    $response->headers->set('X-Frame-Options', 'DENY');
    $response->headers->set('X-Content-Type-Options', 'nosniff');
    $response->headers->set('X-UA-Compatible', 'IE=edge');
});
$app->register(new Silex\Provider\TranslationServiceProvider(), array('locale_fallbacks' => array('en_GB')));
$app['translator'] = $app->share($app->extend('translator', function ($translator, $app) {
    $translator->addLoader('yaml', new YamlFileLoader());
    $translator->addResource('yaml', __DIR__ . '/../translations/en_GB.yml', 'en_GB');
    //$translator->addResource('yaml', __DIR__.'/../translations/fi_FI.yml', 'fi_FI');
    return $translator;
}));
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$app->register(new Silex\Provider\FormServiceProvider());
// templates
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
// db
$dbOptions = array('db.options' => array('driver' => DB_DRIVER, 'host' => DB_HOST, 'dbname' => DB_NAME, 'user' => DB_USER, 'password' => DB_PASS));
if (DB_FORCE_UTF8) {
    $dbOptions['db.options']['driverOptions'] = array(1002 => 'SET NAMES utf8');
}
$app->register(new Silex\Provider\DoctrineServiceProvider(), $dbOptions);
$app->register(new Silex\Provider\ValidatorServiceProvider());
$app->register(new Silex\Provider\SessionServiceProvider());
$app->register(new Silex\Provider\SecurityServiceProvider(), array('security.firewalls' => array('admin_secured_area' => array('pattern' => '^/a/', 'form' => array('login_path' => '/login', 'check_path' => '/a/login_check', 'default_target_path' => 'default_security_target'), 'logout' => array('logout_path' => '/a/logout'), 'users' => array(ADMIN_USERNAME => array('ROLE_ADMIN', ADMIN_PASSWORD_HASH))), 'anonymous' => array('anonymous' => true))));