Skip to content

Commit

Permalink
Merge pull request ezsystems#32 from ezsystems/psr-2
Browse files Browse the repository at this point in the history
Switched to PSR-2
  • Loading branch information
lolautruche committed Sep 1, 2015
2 parents a4c6288 + c4f2e08 commit 5aff919
Show file tree
Hide file tree
Showing 176 changed files with 3,213 additions and 3,801 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -3,3 +3,5 @@ composer.lock
ezpublish_legacy
bin
config.php
.php_cs.cache

29 changes: 29 additions & 0 deletions .php_cs
@@ -0,0 +1,29 @@
<?php

return Symfony\CS\Config\Config::create()
->setUsingLinter(false)
->setUsingCache(true)
->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL)
->fixers([
'concat_with_spaces',
'-concat_without_spaces',
'-empty_return',
'-phpdoc_params',
'-phpdoc_separation',
'-phpdoc_to_comment',
'-spaces_cast',
'-blankline_after_open_tag',
'-single_blank_line_before_namespace',
// psr0 has weird issues with our PSR-4 layout, so deactivating it.
'-psr0',
])
->finder(
Symfony\CS\Finder\DefaultFinder::create()
->in(__DIR__)
->exclude([
'vendor',
])
->files()->name('*.php')
)
;

46 changes: 18 additions & 28 deletions bootstrap.php
@@ -1,61 +1,51 @@
<?php
/**
* File containing the bootstrapping of eZ Publish API for unit test use
* File containing the bootstrapping of eZ Publish API for unit test use.
*
* Setups class loading.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
* @version //autogentag//
*/

use eZ\Publish\Core\MVC\Legacy\Kernel as LegacyKernel;
use eZ\Publish\Core\MVC\Legacy\Kernel\CLIHandler as LegacyKernelCLI;

// Get global config.php settings
if ( !file_exists( __DIR__ . '/config.php' ) )
{
if ( !symlink( __DIR__ . '/config.php-DEVELOPMENT', __DIR__ . '/config.php' ) )
{
throw new \RuntimeException( 'Could not symlink config.php-DEVELOPMENT to config.php, please copy config.php-DEVELOPMENT to config.php & customize to your needs!' );
if (!file_exists(__DIR__ . '/config.php')) {
if (!symlink(__DIR__ . '/config.php-DEVELOPMENT', __DIR__ . '/config.php')) {
throw new \RuntimeException('Could not symlink config.php-DEVELOPMENT to config.php, please copy config.php-DEVELOPMENT to config.php & customize to your needs!');
}
}

if ( !( $settings = include ( __DIR__ . '/config.php' ) ) )
{
throw new \RuntimeException( 'Could not read config.php, please copy config.php-DEVELOPMENT to config.php & customize to your needs!' );
if (!($settings = include(__DIR__ . '/config.php'))) {
throw new \RuntimeException('Could not read config.php, please copy config.php-DEVELOPMENT to config.php & customize to your needs!');
}

// Setup class loader, detect ezpublish-community repo context and use vendor files from there if that is the case
$rootDir = __DIR__;
if ( ( $vendorPathPos = strrpos( $rootDir, '/vendor/ezsystems/ezpublish' ) ) !== false )
$rootDir = substr( $rootDir, 0, $vendorPathPos );
require_once $rootDir . "/vendor/autoload.php";

if (($vendorPathPos = strrpos($rootDir, '/vendor/ezsystems/ezpublish')) !== false) {
$rootDir = substr($rootDir, 0, $vendorPathPos);
}
require_once $rootDir . '/vendor/autoload.php';

// Bootstrap eZ Publish legacy kernel if configured
if ( !empty( $settings['legacy_dir'] ) )
{
if ( !defined( 'EZCBASE_ENABLED' ) )
{
define( 'EZCBASE_ENABLED', false );
if (!empty($settings['legacy_dir'])) {
if (!defined('EZCBASE_ENABLED')) {
define('EZCBASE_ENABLED', false);
require_once $settings['legacy_dir'] . '/autoload.php';
}

if ( empty( $_ENV['legacyKernel'] ) )
{
if (empty($_ENV['legacyKernel'])) {
// Define $legacyKernelHandler to whatever you need before loading this bootstrap file.
// CLI handler is used by defaut, but you must use \ezpKernelWeb if not in CLI context (i.e. REST server)
// $legacyKernelHandler can be a closure returning the appropriate kernel handler (to avoid autoloading issues)
if ( isset( $legacyKernelHandler ) )
{
if (isset($legacyKernelHandler)) {
$legacyKernelHandler = $legacyKernelHandler instanceof \Closure ? $legacyKernelHandler() : $legacyKernelHandler;
} else {
$legacyKernelHandler = new LegacyKernelCLI();
}
else
{
$legacyKernelHandler = new LegacyKernelCLI;
}
$legacyKernel = new LegacyKernel( $legacyKernelHandler, $settings['legacy_dir'], getcwd() );
$legacyKernel = new LegacyKernel($legacyKernelHandler, $settings['legacy_dir'], getcwd());

// Exposing in env variables in order be able to use them in test cases.
$_ENV['legacyKernel'] = $legacyKernel;
Expand Down
21 changes: 9 additions & 12 deletions bundle/Cache/LegacyCachePurger.php
Expand Up @@ -6,7 +6,6 @@
* @license For full copyright and license information view LICENSE file distributed with this source code.
* @version //autogentag//
*/

namespace eZ\Bundle\EzPublishLegacyBundle\Cache;

use eZ\Bundle\EzPublishLegacyBundle\LegacyMapper\Configuration;
Expand Down Expand Up @@ -35,15 +34,13 @@ public function __construct(
Filesystem $fs,
$legacyRootDir,
SiteAccess $siteAccess
)
{
) {
$this->legacyKernelClosure = $legacyKernelClosure;

// If ezp_extension.php doesn't exist or siteaccess name is "setup", it means that eZ Publish is not yet installed.
// Hence we deactivate configuration mapper to avoid potential issues (e.g. ezxFormToken which cannot be loaded).
if ( !$fs->exists( "$legacyRootDir/var/autoload/ezp_extension.php" ) || $siteAccess->name === 'setup' )
{
$configurationMapper->setEnabled( false );
if (!$fs->exists("$legacyRootDir/var/autoload/ezp_extension.php") || $siteAccess->name === 'setup') {
$configurationMapper->setEnabled(false);
}
}

Expand All @@ -53,6 +50,7 @@ public function __construct(
private function getLegacyKernel()
{
$closure = $this->legacyKernelClosure;

return $closure();
}

Expand All @@ -61,23 +59,22 @@ private function getLegacyKernel()
*
* @param string $cacheDir The cache directory.
*/
public function clear( $cacheDir )
public function clear($cacheDir)
{
$this->getLegacyKernel()->runCallback(
function ()
{
function () {
$helper = new eZCacheHelper(
$cli = eZCLI::instance(),
$script = eZScript::instance(
array(
'description' => "eZ Publish Cache Handler",
'description' => 'eZ Publish Cache Handler',
'use-session' => false,
'use-modules' => false,
'use-extensions' => true
'use-extensions' => true,
)
)
);
$helper->clearItems( eZCache::fetchByTag( "template,ini,i18n" ), "Legacy file cache (Template, ini and i18n)" );
$helper->clearItems(eZCache::fetchByTag('template,ini,i18n'), 'Legacy file cache (Template, ini and i18n)');
},
false,
false
Expand Down

0 comments on commit 5aff919

Please sign in to comment.