Permalink
Browse files

update silex and add Web profiler

  • Loading branch information...
Charles SANQUER
Charles SANQUER committed Feb 8, 2013
1 parent 3cb3a27 commit 6669ec70523dee53d954a7c279710ec32935da10
Showing with 862 additions and 227 deletions.
  1. +2 −0 .gitignore
  2. +68 −10 app/bootstrap.php
  3. +13 −3 app/console
  4. +22 −17 composer.json
  5. +751 −197 composer.lock
  6. +3 −0 web/index.php
  7. +3 −0 web/index_dev.php
@@ -1,5 +1,7 @@
vendor
app/cache
app/log
app/logs
app/config/config.yml
app/config/config.php
bin
@@ -1,11 +1,16 @@
<?php
use Symfony\Component\ClassLoader\DebugClassLoader;
use Symfony\Component\HttpKernel\Debug\ErrorHandler;
use Symfony\Component\HttpKernel\Debug\ExceptionHandler;
// get environment constants or set default
if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}
require_once __DIR__.DS.'..'.DS.'vendor'.DS.'autoload.php';
/**
* Create a Default Silex application with some extra service providers
*
@@ -18,12 +23,26 @@
function createDefaultSilexApp($appdir = __DIR__, $env = 'prod', $debug = false)
{
$fs = new \Symfony\Component\Filesystem\Filesystem();
$app = new \Silex\Application();
if (!$fs->exists($appdir)) {
die('the application directory doesn\'t exists !!');
}
$app = new \Silex\Application();
/*
* define environment variables
*/
$app['debug'] = (bool) $debug;
$app['env'] = $env;
if ($app['debug']) {
DebugClassLoader::enable();
ErrorHandler::register();
if ('cli' !== php_sapi_name()) {
ExceptionHandler::register();
}
}
/*
* define main paths
*/
@@ -32,26 +51,50 @@ function createDefaultSilexApp($appdir = __DIR__, $env = 'prod', $debug = false)
$app['web_dir'] = realpath($appdir.DS.'..'.DS.'web');
// get configs
if (file_exists($app['app_dir'].DS.'config'.DS.'config.php'))
$config = require_once $app['app_dir'].DS.'config'.DS.'config.php';
else if (file_exists($app['app_dir'].DS.'config'.DS.'config.yml')) {
try {
$config = \Symfony\Component\Yaml\Yaml::parse($app['app_dir'].DS.'config'.DS.'config.yml');
} catch (ParseException $e) {
printf("Unable to parse the YAML string: %s in config file", $e->getMessage());
exit();
}
}
else {
printf("no config file config file");
exit();
}
//set umask
$umask = isset($config['umask']) && is_int($config['umask']) ? $config['umask'] : 0002;
umask($umask);
//create cache directories
//create cache and log directories
$app['cache_dir'] = $appdir.DS.'cache';
$app['log_dir'] = $appdir.DS.'logs';
if (!$fs->exists($app['cache_dir'])) {
$rights = isset($config['cache_access']) && is_int($config['cache_access']) ? $config['cache_access'] : 0775;
$fs->mkdir(array(
$app['cache_dir'],
$app['cache_dir'].DS.'http',
$app['cache_dir'].DS.'twig',
$app['cache_dir'].DS.'profiler',
), $rights);
$fs->chmod($app['cache_dir'], $rights);
$fs->chmod($app['cache_dir'].DS.'http', $rights);
$fs->chmod($app['cache_dir'].DS.'twig', $rights);
$fs->chmod($app['cache_dir'].DS.'profiler', $rights);
}
if (!$fs->exists($app['log_dir'])) {
$fs->mkdir($app['log_dir'], 0775);
$fs->chmod($app['log_dir'], 0775);
}
$app['data_dir'] = $app['root_dir'].DS.'data';
if (!$fs->exists($app['data_dir'])) {
$fs->mkdir($app['data_dir'], 0777);
@@ -61,12 +104,6 @@ function createDefaultSilexApp($appdir = __DIR__, $env = 'prod', $debug = false)
if (!$fs->exists($app['uploads_dir'])) {
$fs->mkdir($app['uploads_dir'], 0777);
}
/*
* define environment variables
*/
$app['debug'] = (bool) $debug;
$app['env'] = $env;
/*
* add service providers
*/
@@ -84,6 +121,8 @@ function createDefaultSilexApp($appdir = __DIR__, $env = 'prod', $debug = false)
//add symfony2 forms and validators
$app->register(new \Silex\Provider\ValidatorServiceProvider());
$app->register(new Silex\Provider\ServiceControllerServiceProvider());
// must be registered before twig
$app->register(new \Silex\Provider\FormServiceProvider(), array(
'form.secret' => '4fws6dg4w6df4<qg4sh4646qfgsd4',
@@ -114,6 +153,25 @@ function createDefaultSilexApp($appdir = __DIR__, $env = 'prod', $debug = false)
),
));
$app['twig'] = $app->share($app->extend('twig', function($twig, $app) {
// add custom globals, filters, tags, ...
return $twig;
}));
// Web Profiler and Monolog
if ($app['debug']) {
$app->register(new Silex\Provider\MonologServiceProvider(), array(
'monolog.logfile' => $app['log_dir'].DS.'silex.log',
));
$app->register($p = new \Silex\Provider\WebProfilerServiceProvider(), array(
'profiler.cache_dir' => $app['cache_dir'].DS.'profiler',
));
$app->mount('/_profiler', $p);
}
//add swiftmailer with default SMTP transport
if (!empty($config['swiftmailer'])) {
$app->register(new \Silex\Provider\SwiftmailerServiceProvider(), array(
@@ -151,7 +209,7 @@ function createDefaultSilexApp($appdir = __DIR__, $env = 'prod', $debug = false)
if ($e instanceof Symfony\Component\HttpKernel\Exception\NotFoundHttpException) {
$content = vsprintf('<h1>%d - %s (%s)</h1>', array(
$e->getStatusCode(),
Symfony\Component\HttpFoundation\Response::$statusTexts[$e->getStatusCode()],
\Symfony\Component\HttpFoundation\Response::$statusTexts[$e->getStatusCode()],
$app['request']->getRequestUri()
));
$code = $e->getStatusCode();
@@ -5,7 +5,17 @@ if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}
require_once __DIR__.DS.'..'.DS.'vendor'.DS.'autoload.php';
if (!defined('SILEX_ENV')) {
define('SILEX_ENV', 'dev');
}
if (!defined('SILEX_DEBUG')) {
define('SILEX_DEBUG', false);
}
require_once __DIR__.DS.'bootstrap.php';
$app = createDefaultSilexApp(__DIR__, SILEX_ENV, SILEX_DEBUG);
use Spyrit\Silex\Utils\Command\CacheClearCommand;
use Symfony\Component\Console\Application as BaseApplication;
@@ -35,5 +45,5 @@ class Application extends BaseApplication
}
}
$application = new Application();
$application->run();
$console = new Application();
$console->run();
@@ -18,26 +18,31 @@
"minimum-stability": "dev",
"require": {
"silex/silex": "1.0.*",
"symfony/twig-bridge": "2.1.*",
"twig/twig": ">=1.8.0,<2.0-dev",
"twig/extensions": "dev-master",
"symfony/form": "2.1.*",
"symfony/validator": "2.1.*",
"symfony/finder": "2.1.*",
"symfony/filesystem": "2.1.*",
"silex/web-profiler": "1.0.*",
"swiftmailer/swiftmailer": "4.2.*",
"doctrine/dbal": "2.2.*",
"symfony/translation": "2.1.*",
"symfony/locale": "2.1.*",
"symfony/console": "2.1.*",
"symfony/config": "2.1.*",
"symfony/yaml": "2.1.*",
"symfony/process": "2.1.*",
"symfony/security": "2.1.*",
"symfony/monolog-bridge": "2.1.*",
"twig/twig": ">=1.8.0,<2.0-dev",
"twig/extensions": "dev-master",
"symfony/twig-bridge": ">=2.1,<2.3-dev",
"symfony/form": ">=2.1,<2.3-dev",
"symfony/validator": ">=2.1,<2.3-dev",
"symfony/finder": ">=2.1,<2.3-dev",
"symfony/filesystem": ">=2.1,<2.3-dev",
"symfony/translation": ">=2.1,<2.3-dev",
"symfony/locale": ">=2.1,<2.3-dev",
"symfony/browser-kit": ">=2.1,<2.3-dev",
"symfony/class-loader": ">=2.1,<2.3-dev",
"symfony/css-selector": ">=2.1,<2.3-dev",
"symfony/console": ">=2.1,<2.3-dev",
"symfony/config": ">=2.1,<2.3-dev",
"symfony/yaml": ">=2.1,<2.3-dev",
"symfony/process": ">=2.1,<2.3-dev",
"symfony/security": ">=2.1,<2.3-dev",
"symfony/monolog-bridge": ">=2.1,<2.3-dev",
"spyrit/silex-utils": "dev-master",
"fzaninotto/faker": "1.1.*@dev",
"spyrit/light-csv": "dev-master",
"spyrit/silex-utils": "dev-master"
"spyrit/light-csv": "dev-master"
},
"autoload": {
"psr-0": {"": "src/"}
Oops, something went wrong.

0 comments on commit 6669ec7

Please sign in to comment.