Skip to content

Commit

Permalink
cmf sandbox is now more inline with symfony-standard, uses the sensio…
Browse files Browse the repository at this point in the history
… generator bootstrap files, added missing packages that allows users to create bundles, added new sf2 deps checker (ie. php version number)
  • Loading branch information
Neil Ferreira committed Jun 11, 2012
1 parent 9581fd2 commit 6498a24
Show file tree
Hide file tree
Showing 19 changed files with 234 additions and 206 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ Create an apache virtual host entry along the lines of

And add an entry to your hosts file for cmf.lo

# If you are running Symfony2 for the first time, run http://cmf.lo/check.php to ensure your system settings have been setup inline with the expected behaviour of the Symfony2 framework.

Then point your browser to http://cmf.lo/app_dev.php


Expand Down
13 changes: 11 additions & 2 deletions app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@ class AppKernel extends Kernel
public function registerBundles()
{
$bundles = array(
// enable symfony-standard bundles
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Knp\Bundle\MenuBundle\KnpMenuBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
// new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new JMS\AopBundle\JMSAopBundle(),
new JMS\DiExtraBundle\JMSDiExtraBundle($this),
new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),

new Doctrine\Bundle\PHPCRBundle\DoctrinePHPCRBundle(),
new Knp\Bundle\MenuBundle\KnpMenuBundle(),

// enable cmf bundles
new Symfony\Cmf\Bundle\RoutingExtraBundle\SymfonyCmfRoutingExtraBundle(),
Expand All @@ -28,6 +35,7 @@ public function registerBundles()
new Symfony\Cmf\Bundle\BlockBundle\SymfonyCmfBlockBundle(),
new Symfony\Cmf\Bundle\SimpleCmsBundle\SymfonyCmfSimpleCmsBundle(),

// create.js editing related
new Liip\VieBundle\LiipVieBundle(),
new FOS\RestBundle\FOSRestBundle(),
new FOS\JsRoutingBundle\FOSJsRoutingBundle(),
Expand All @@ -49,6 +57,7 @@ public function registerBundles()

if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();

// additional bundle for tests
$bundles[] = new Liip\FunctionalTestBundle\LiipFunctionalTestBundle();
Expand All @@ -61,4 +70,4 @@ public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
}
}
}
24 changes: 8 additions & 16 deletions app/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,25 @@
if (!$loader = include __DIR__.'/../vendor/autoload.php') {
$nl = PHP_SAPI === 'cli' ? PHP_EOL : '<br />';
echo "$nl$nl";
if (is_writable(dirname(__DIR__)) && $installer = @file_get_contents('http://getcomposer.org/installer')) {
echo 'You must set up the project dependencies.'.$nl;
$installerPath = dirname(__DIR__).'/install-composer.php';
file_put_contents($installerPath, $installer);
echo 'The composer installer has been downloaded in '.$installerPath.$nl;
die('Run the following commands in '.dirname(__DIR__).':'.$nl.$nl.
'php install-composer.php'.$nl.
'php composer.phar install'.$nl);
}
die('You must set up the project dependencies.'.$nl.
'Run the following commands in '.dirname(__DIR__).':'.$nl.$nl.
'curl -s http://getcomposer.org/installer | php'.$nl.
'php composer.phar install'.$nl);
}

use Doctrine\Common\Annotations\AnnotationRegistry;

// intl
if (!function_exists('intl_get_error_code')) {
require_once __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';

$loader->add('', __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs');
}


use Doctrine\Common\Annotations\AnnotationRegistry;

AnnotationRegistry::registerLoader(function($class) use ($loader) {
$loader->loadClass($class);
return class_exists($class, false);
});
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
AnnotationRegistry::registerFile(__DIR__.'/../vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/Mapping/Annotations/DoctrineAnnotations.php');

// Swiftmailer needs a special autoloader to allow
// the lazy loading of the init file (which is expensive)
require_once __DIR__.'/../vendor/swiftmailer/swiftmailer/lib/classes/Swift.php';
Swift::registerAutoload(__DIR__.'/../vendor/swiftmailer/swiftmailer/lib/swift_init.php');
99 changes: 23 additions & 76 deletions app/check.php
Original file line number Diff line number Diff line change
@@ -1,104 +1,51 @@
<?php

if (!$iniPath = get_cfg_var('cfg_file_path')) {
$iniPath = 'WARNING: not using a php.ini file';
}
require_once dirname(__FILE__).'/SymfonyRequirements.php';

$symfonyRequirements = new SymfonyRequirements();

$iniPath = $symfonyRequirements->getPhpIniConfigPath();

echo "********************************\n";
echo "* *\n";
echo "* Symfony requirements check *\n";
echo "* *\n";
echo "********************************\n\n";
echo sprintf("php.ini used by PHP: %s\n\n", $iniPath);

echo "** WARNING **\n";
echo $iniPath ? sprintf("* Configuration file used by PHP: %s\n\n", $iniPath) : "* WARNING: No configuration file (php.ini) used by PHP!\n\n";

echo "** ATTENTION **\n";
echo "* The PHP CLI can use a different php.ini file\n";
echo "* than the one used with your web server.\n";
if ('\\' == DIRECTORY_SEPARATOR) {
echo "* (especially on the Windows platform)\n";
}
echo "* If this is the case, please ALSO launch this\n";
echo "* utility from your web server.\n";
echo "** WARNING **\n";

// mandatory
echo_title("Mandatory requirements");
check(version_compare(phpversion(), '5.3.2', '>='), sprintf('Checking that PHP version is at least 5.3.2 (%s installed)', phpversion()), 'Install PHP 5.3.2 or newer (current version is '.phpversion(), true);
check(ini_get('date.timezone'), 'Checking that the "date.timezone" setting is set', 'Set the "date.timezone" setting in php.ini (like Europe/Paris)', true);
check(is_writable(__DIR__.'/../app/cache'), sprintf('Checking that app/cache/ directory is writable'), 'Change the permissions of the app/cache/ directory so that the web server can write in it', true);
check(is_writable(__DIR__.'/../app/logs'), sprintf('Checking that the app/logs/ directory is writable'), 'Change the permissions of the app/logs/ directory so that the web server can write in it', true);
check(function_exists('json_encode'), 'Checking that the json_encode() is available', 'Install and enable the json extension', true);
check(class_exists('SQLite3') || in_array('sqlite', PDO::getAvailableDrivers()), 'Checking that the SQLite3 or PDO_SQLite extension is available', 'Install and enable the SQLite3 or PDO_SQLite extension.', true);
check(function_exists('session_start'), 'Checking that the session_start() is available', 'Install and enable the session extension', true);
check(function_exists('ctype_alpha'), 'Checking that the ctype_alpha() is available', 'Install and enable the ctype extension', true);

// warnings
echo_title("Optional checks");
check(class_exists('DomDocument'), 'Checking that the PHP-XML module is installed', 'Install and enable the php-xml module', false);
check(defined('LIBXML_COMPACT'), 'Checking that the libxml version is at least 2.6.21', 'Upgrade your php-xml module with a newer libxml', false);
check(function_exists('token_get_all'), 'Checking that the token_get_all() function is available', 'Install and enable the Tokenizer extension (highly recommended)', false);
check(function_exists('mb_strlen'), 'Checking that the mb_strlen() function is available', 'Install and enable the mbstring extension', false);
check(function_exists('iconv'), 'Checking that the iconv() function is available', 'Install and enable the iconv extension', false);
check(function_exists('utf8_decode'), 'Checking that the utf8_decode() is available', 'Install and enable the XML extension', false);
if (PHP_OS != 'WINNT') {
check(function_exists('posix_isatty'), 'Checking that the posix_isatty() is available', 'Install and enable the php_posix extension (used to colorized the CLI output)', false);
}
check(class_exists('Locale'), 'Checking that the intl extension is available', 'Install and enable the intl extension (used for validators)', false);
if (class_exists('Locale')) {
$version = '';

if (defined('INTL_ICU_VERSION')) {
$version = INTL_ICU_VERSION;
} else {
$reflector = new \ReflectionExtension('intl');

ob_start();
$reflector->info();
$output = strip_tags(ob_get_clean());
echo "* To be on the safe side, please also launch the requirements check\n";
echo "* from your web server using the web/config.php script.\n";

preg_match('/^ICU version +(?:=> )?(.*)$/m', $output, $matches);
$version = $matches[1];
}
echo_title('Mandatory requirements');

check(version_compare($version, '4.0', '>='), 'Checking that the intl ICU version is at least 4+', 'Upgrade your intl extension with a newer ICU version (4+)', false);
foreach ($symfonyRequirements->getRequirements() as $req) {
echo_requirement($req);
}

$accelerator =
(function_exists('apc_store') && ini_get('apc.enabled'))
||
function_exists('eaccelerator_put') && ini_get('eaccelerator.enable')
||
function_exists('xcache_set')
;
check($accelerator, 'Checking that a PHP accelerator is installed', 'Install a PHP accelerator like APC (highly recommended)', false);
check(function_exists('apc_store') && ini_get('apc.enabled') && version_compare(phpversion('apc'), '3.0.17', '>='), 'Checking that the APC version is at least 3.0.17', 'Upgrade your APC extension (3.0.17+)', true);

check(!ini_get('short_open_tag'), 'Checking that php.ini has short_open_tag set to off', 'Set short_open_tag to off in php.ini', false);
check(!ini_get('magic_quotes_gpc'), 'Checking that php.ini has magic_quotes_gpc set to off', 'Set magic_quotes_gpc to off in php.ini', false);
check(!ini_get('register_globals'), 'Checking that php.ini has register_globals set to off', 'Set register_globals to off in php.ini', false);
check(!ini_get('session.auto_start'), 'Checking that php.ini has session.auto_start set to off', 'Set session.auto_start to off in php.ini', false);

echo_title("Optional checks (Doctrine)");
echo_title('Optional recommendations');

check(class_exists('PDO'), 'Checking that PDO is installed', 'Install PDO (mandatory for Doctrine)', false);
if (class_exists('PDO')) {
$drivers = PDO::getAvailableDrivers();
check(count($drivers), 'Checking that PDO has some drivers installed: '.implode(', ', $drivers), 'Install PDO drivers (mandatory for Doctrine)');
foreach ($symfonyRequirements->getRecommendations() as $req) {
echo_requirement($req);
}

/**
* Checks a configuration.
* Prints a Requirement instance
*/
function check($boolean, $message, $help = '', $fatal = false)
function echo_requirement(Requirement $requirement)
{
echo $boolean ? " OK " : sprintf("\n\n[[%s]] ", $fatal ? ' ERROR ' : 'WARNING');
echo sprintf("$message%s\n", $boolean ? '' : ': FAILED');
$result = $requirement->isFulfilled() ? 'OK' : ($requirement->isOptional() ? 'WARNING' : 'ERROR');
echo ' ' . str_pad($result, 9);
echo $requirement->getTestMessage() . "\n";

if (!$boolean) {
echo " *** $help ***\n";
if ($fatal) {
die("You must fix this problem before resuming the check.\n");
}
if (!$requirement->isFulfilled()) {
echo sprintf(" %s\n\n", $requirement->getHelpText());
}
}

Expand Down
10 changes: 10 additions & 0 deletions app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ twig:
assetic:
debug: %kernel.debug%
use_controller: false
# bundles: [ ] # if enabled, every bundle must be added
#java: /usr/bin/java
filters:
cssrewrite: ~
coffee:
Expand All @@ -37,6 +39,14 @@ assetic:
# yui_css:
# jar: %kernel.root_dir%/java/yuicompressor-2.4.2.jar

# Swiftmailer Configuration
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
spool: { type: memory }

# for jackalope-doctrine-dbal
doctrine:
dbal:
Expand Down
3 changes: 3 additions & 0 deletions app/config/config_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ monolog:

assetic:
use_controller: true

#swiftmailer:
# delivery_address: me@example.com
7 changes: 4 additions & 3 deletions app/config/config_prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ imports:
- { resource: config.yml }

#doctrine:
# metadata_cache_driver: apc
# result_cache_driver: apc
# query_cache_driver: apc
# orm:
# metadata_cache_driver: apc
# result_cache_driver: apc
# query_cache_driver: apc

monolog:
handlers:
Expand Down
3 changes: 3 additions & 0 deletions app/config/config_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ framework:
web_profiler:
toolbar: false
intercept_redirects: false

swiftmailer:
disable_delivery: true
7 changes: 6 additions & 1 deletion app/config/parameters.yml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
parameters:
locale: en

secret: xxxxxxxxxx
secret: ThisTokenIsNotSoSecretChangeIt

liip_vie.use_coffee: false
# a little hack to avoid errors on missing node/coffescript.
Expand All @@ -16,3 +16,8 @@ parameters:
database_name: sandbox
database_user: root
database_password:

mailer_transport: smtp
mailer_host: localhost
mailer_user: ~
mailer_password: ~
2 changes: 1 addition & 1 deletion app/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ vie:
resource: "@LiipVieBundle/Resources/config/routing/phpcr_odm.xml"

vie_asset_management:
resource: "@LiipVieBundle/Resources/config/routing/asset_search.xml"
resource: "@LiipVieBundle/Resources/config/routing/asset_search.xml"
6 changes: 5 additions & 1 deletion app/config/security.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
jms_security_extra:
secure_all_services: false
expressions: true

security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext
Expand Down Expand Up @@ -26,4 +30,4 @@ security:

access_control:
#- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
#- { path: ^/_internal, roles: IS_AUTHENTICATED_ANONYMOUSLY, ip: 127.0.0.1 }
#- { path: ^/_internal/secure, roles: IS_AUTHENTICATED_ANONYMOUSLY, ip: 127.0.0.1 }
12 changes: 9 additions & 3 deletions app/console
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
#!/usr/bin/env php
<?php

require_once __DIR__.'/autoload.php';
// if you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
//umask(0000);

set_time_limit(0);

require_once __DIR__.'/bootstrap.php.cache';
require_once __DIR__.'/AppKernel.php';

use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;

$input = new ArgvInput();
$env = $input->getParameterOption(array('--env', '-e'), getenv('SYMFONY_ENV') ?: 'dev');
$debug = !$input->hasParameterOption(array('--no-debug', ''));
$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(array('--no-debug', '')) && $env !== 'prod';

$kernel = new AppKernel($env, $debug);
$application = new Application($kernel);
$application->run();
$application->run($input);
7 changes: 4 additions & 3 deletions app/phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
>
bootstrap="tests/bootstrap.php" >

<testsuites>
<testsuite name="Project Test Suite">
Expand All @@ -34,10 +33,12 @@
<directory>../src</directory>
<exclude>
<directory>../src/*/*Bundle/Resources</directory>
<directory>../src/*/*Bundle/Tests</directory>
<directory>../src/*/Bundle/*Bundle/Resources</directory>
<directory>../src/*/Bundle/*Bundle/Tests</directory>
</exclude>
<directory>../vendor/symfony-cmf/src</directory>
</whitelist>
</filter>

</phpunit>
</phpunit>
2 changes: 1 addition & 1 deletion app/tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php

require __DIR__.'/../autoload.php';
require __DIR__.'/../bootstrap.php.cache';
require __DIR__.'/WebTestCase.php';

4 comments on commit 6498a24

@lsmith77
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe its just me .. but i find the bootstrap.php.cache an incredibly bad practice

@neilferreira
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What part of it are you not a fan of? I haven't really found any reason to fault it yet.

@lsmith77
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because it makes debugging more complicated since at run time it will use copied versions of various internal classes. also if you use APC then it offers no tangible performance benefits

@dbu
Copy link
Member

@dbu dbu commented on 6498a24 Jun 14, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we removed it because we said the sandbox is just a demo and we don't care about perfect performance. i guess neilf added it to make the sandbox as similar to symfony standard edition as possible. i don't mind too much either way, though i don't like the added debugging complication.

Please sign in to comment.