Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Change to use Composer for autoload, drop PEAR/EZC #1340

Merged
merged 4 commits into from
Jan 15, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 10 additions & 35 deletions autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,52 +19,27 @@
require_once __DIR__ . '/config.php';
}

// Check for EZCBASE_ENABLED, if set we can skip autoloading Zeta Components
if ( !defined( 'EZCBASE_ENABLED' ) )
{
$defaultAppName = "app";
if ( !file_exists( __DIR__ . "/../$defaultAppName" ) )
// If composer autloader is already present we can skip trying to load it
if ( class_exists( 'Composer\Autoload\ClassLoader', false ) )
{
$defaultAppName = "ezpublish";
}

$appName = defined( 'EZP_APP_FOLDER_NAME' ) ? EZP_APP_FOLDER_NAME : $defaultAppName;
$appFolder = __DIR__ . "/../$appName";
$legacyVendorDir = __DIR__ . "/vendor";

// Bundled
if ( defined( 'EZP_USE_BUNDLED_COMPONENTS' ) ? EZP_USE_BUNDLED_COMPONENTS === true : file_exists( __DIR__ . "/lib/ezc" ) )
{
set_include_path( __DIR__ . PATH_SEPARATOR . __DIR__ . "/lib/ezc" . PATH_SEPARATOR . get_include_path() );
require 'Base/src/base.php';
$baseEnabled = true;
}
// Custom config.php defined
else if ( defined( 'EZC_BASE_PATH' ) )
{
require EZC_BASE_PATH;
$baseEnabled = true;
$baseEnabled = false;
}
// Composer if in eZ Publish5 context
else if ( strpos( $appFolder, "{$appName}/../{$appName}" ) === false && file_exists( "{$appFolder}/autoload.php" ) )
// Composer if in eZ Platform context
else if ( file_exists( __DIR__ . "/../vendor/autoload.php" ) )
{
require_once "{$appFolder}/autoload.php";

require_once __DIR__ . "/../vendor/autoload.php";
$baseEnabled = false;
}
// Composer if in eZ Publish legacy context
else if ( file_exists( "{$legacyVendorDir}/autoload.php" ) )
else if ( file_exists( __DIR__ . "/vendor/autoload.php" ) )
{
require_once "{$legacyVendorDir}/autoload.php";
require_once __DIR__ . "/vendor/autoload.php";
$baseEnabled = false;
}
// PEAR install
else
{
$baseEnabled = @include 'ezc/Base/base.php';
if ( !$baseEnabled )
{
$baseEnabled = @include 'Base/src/base.php';
}
}

define( 'EZCBASE_ENABLED', $baseEnabled );
}
Expand Down
42 changes: 6 additions & 36 deletions bin/php/ezpgenerateautoloads.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,22 @@

// Setup, includes
//{
$defaultAppName = "app";
if ( !file_exists( __DIR__ . "/../../../$defaultAppName" ) )
{
$defaultAppName = "ezpublish";
}

$appName = defined( 'EZP_APP_FOLDER_NAME' ) ? EZP_APP_FOLDER_NAME : $defaultAppName;
$appFolder = getcwd() . "/../$appName";
$platformVendorDir = getcwd() . "/../vendor";
$legacyVendorDir = getcwd() . "/vendor";

$baseEnabled = true;
// Bundled
if ( defined( 'EZP_USE_BUNDLED_COMPONENTS' ) ? EZP_USE_BUNDLED_COMPONENTS === true : file_exists( 'lib/ezc' ) )
if ( class_exists( 'Composer\Autoload\ClassLoader', false ) )
{
set_include_path( './lib/ezc' . PATH_SEPARATOR . get_include_path() );
require 'Base/src/base.php';
// Do nothing, composer autoload already loaded
}
// Custom config.php defined
else if ( defined( 'EZC_BASE_PATH' ) )
// Composer if in eZ Platform context
else if ( file_exists( "{$platformVendorDir}/autoload.php" ) )
{
require EZC_BASE_PATH;
}
// Composer if in eZ Publish5 context
else if ( strpos( $appFolder, "{$appName}/../{$appName}" ) === false && file_exists( "{$appFolder}/autoload.php" ) )
{
require_once "{$appFolder}/autoload.php";
$baseEnabled = false;
require_once "{$platformVendorDir}/autoload.php";
}
// Composer if in eZ Publish legacy context
else if ( file_exists( "{$legacyVendorDir}/autoload.php" ) )
{
require_once "{$legacyVendorDir}/autoload.php";
$baseEnabled = false;
}
// PEAR
else
{
if ( !@include 'ezc/Base/base.php' )
{
require 'Base/src/base.php';
}
}

if ( $baseEnabled )
{
spl_autoload_register( array( 'ezcBase', 'autoload' ) );
}

require 'kernel/private/classes/ezautoloadgenerator.php';
Expand Down
14 changes: 14 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@
"phpunit/phpunit": "3.7.*",
"zetacomponents/php-generator": "~1.1"
},
"autoload": {
"files": ["autoload.php"]
},
"scripts": {
"legacy-scripts": [
"@php bin/php/ezpgenerateautoloads.php"
],
"post-install-cmd": [
"@legacy-scripts"
],
"post-update-cmd": [
"@legacy-scripts"
]
},
"conflict": {
"ezsystems/ezpublish-kernel": "<6.12 || >=2014.11 <2017.10"
},
Expand Down