Skip to content

Commit ffaab4a

Browse files
authored
[Feature] Change to use Composer for autoload, drop PEAR/EZC (#1340)
* [Feature] Add support for autloading via Composer * Cleanup all pear and bundeld ezc code, not relevant anymore * Update autoload.php * Update config.php-RECOMMENDED
1 parent 0fa5986 commit ffaab4a

File tree

4 files changed

+31
-114
lines changed

4 files changed

+31
-114
lines changed

autoload.php

+11-38
Original file line numberDiff line numberDiff line change
@@ -19,54 +19,27 @@
1919
require_once __DIR__ . '/config.php';
2020
}
2121

22+
// Check for EZCBASE_ENABLED, if set we can skip autoloading Zeta Components
2223
if ( !defined( 'EZCBASE_ENABLED' ) )
2324
{
24-
$defaultAppName = "app";
25-
if ( !file_exists( __DIR__ . "/../$defaultAppName" ) )
26-
{
27-
$defaultAppName = "ezpublish";
28-
}
29-
30-
$appName = defined( 'EZP_APP_FOLDER_NAME' ) ? EZP_APP_FOLDER_NAME : $defaultAppName;
31-
$appFolder = __DIR__ . "/../$appName";
32-
$legacyVendorDir = __DIR__ . "/vendor";
25+
// Start by setting EZCBASE_ENABLED to avoid recursion
26+
define( 'EZCBASE_ENABLED', false );
3327

34-
// Bundled
35-
if ( defined( 'EZP_USE_BUNDLED_COMPONENTS' ) ? EZP_USE_BUNDLED_COMPONENTS === true : file_exists( __DIR__ . "/lib/ezc" ) )
36-
{
37-
set_include_path( __DIR__ . PATH_SEPARATOR . __DIR__ . "/lib/ezc" . PATH_SEPARATOR . get_include_path() );
38-
require 'Base/src/base.php';
39-
$baseEnabled = true;
40-
}
41-
// Custom config.php defined
42-
else if ( defined( 'EZC_BASE_PATH' ) )
28+
// If composer autoloader is already present we can skip trying to load it
29+
if ( class_exists( 'Composer\Autoload\ClassLoader', false ) )
4330
{
44-
require EZC_BASE_PATH;
45-
$baseEnabled = true;
31+
// do nothing
4632
}
47-
// Composer if in eZ Publish5 context
48-
else if ( strpos( $appFolder, "{$appName}/../{$appName}" ) === false && file_exists( "{$appFolder}/autoload.php" ) )
33+
// Composer if in eZ Platform context
34+
else if ( file_exists( __DIR__ . "/../vendor/autoload.php" ) )
4935
{
50-
require_once "{$appFolder}/autoload.php";
51-
$baseEnabled = false;
36+
require_once __DIR__ . "/../vendor/autoload.php";
5237
}
5338
// Composer if in eZ Publish legacy context
54-
else if ( file_exists( "{$legacyVendorDir}/autoload.php" ) )
39+
else if ( file_exists( __DIR__ . "/vendor/autoload.php" ) )
5540
{
56-
require_once "{$legacyVendorDir}/autoload.php";
57-
$baseEnabled = false;
41+
require_once __DIR__ . "/vendor/autoload.php";
5842
}
59-
// PEAR install
60-
else
61-
{
62-
$baseEnabled = @include 'ezc/Base/base.php';
63-
if ( !$baseEnabled )
64-
{
65-
$baseEnabled = @include 'Base/src/base.php';
66-
}
67-
}
68-
69-
define( 'EZCBASE_ENABLED', $baseEnabled );
7043
}
7144

7245
// Check if ezpAutoloader exists because it can be already declared if running in the Symfony context (e.g. CLI scripts)

bin/php/ezpgenerateautoloads.php

+6-36
Original file line numberDiff line numberDiff line change
@@ -16,52 +16,22 @@
1616

1717
// Setup, includes
1818
//{
19-
$defaultAppName = "app";
20-
if ( !file_exists( __DIR__ . "/../../../$defaultAppName" ) )
21-
{
22-
$defaultAppName = "ezpublish";
23-
}
2419

25-
$appName = defined( 'EZP_APP_FOLDER_NAME' ) ? EZP_APP_FOLDER_NAME : $defaultAppName;
26-
$appFolder = getcwd() . "/../$appName";
20+
$platformVendorDir = getcwd() . "/../vendor";
2721
$legacyVendorDir = getcwd() . "/vendor";
28-
29-
$baseEnabled = true;
30-
// Bundled
31-
if ( defined( 'EZP_USE_BUNDLED_COMPONENTS' ) ? EZP_USE_BUNDLED_COMPONENTS === true : file_exists( 'lib/ezc' ) )
22+
if ( class_exists( 'Composer\Autoload\ClassLoader', false ) )
3223
{
33-
set_include_path( './lib/ezc' . PATH_SEPARATOR . get_include_path() );
34-
require 'Base/src/base.php';
24+
// Do nothing, composer autoload already loaded
3525
}
36-
// Custom config.php defined
37-
else if ( defined( 'EZC_BASE_PATH' ) )
26+
// Composer if in eZ Platform context
27+
else if ( file_exists( "{$platformVendorDir}/autoload.php" ) )
3828
{
39-
require EZC_BASE_PATH;
40-
}
41-
// Composer if in eZ Publish5 context
42-
else if ( strpos( $appFolder, "{$appName}/../{$appName}" ) === false && file_exists( "{$appFolder}/autoload.php" ) )
43-
{
44-
require_once "{$appFolder}/autoload.php";
45-
$baseEnabled = false;
29+
require_once "{$platformVendorDir}/autoload.php";
4630
}
4731
// Composer if in eZ Publish legacy context
4832
else if ( file_exists( "{$legacyVendorDir}/autoload.php" ) )
4933
{
5034
require_once "{$legacyVendorDir}/autoload.php";
51-
$baseEnabled = false;
52-
}
53-
// PEAR
54-
else
55-
{
56-
if ( !@include 'ezc/Base/base.php' )
57-
{
58-
require 'Base/src/base.php';
59-
}
60-
}
61-
62-
if ( $baseEnabled )
63-
{
64-
spl_autoload_register( array( 'ezcBase', 'autoload' ) );
6535
}
6636

6737
require 'kernel/private/classes/ezautoloadgenerator.php';

composer.json

+14
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,20 @@
6363
"phpunit/phpunit": "3.7.*",
6464
"zetacomponents/php-generator": "~1.1"
6565
},
66+
"autoload": {
67+
"files": ["autoload.php"]
68+
},
69+
"scripts": {
70+
"legacy-scripts": [
71+
"@php bin/php/ezpgenerateautoloads.php"
72+
],
73+
"post-install-cmd": [
74+
"@legacy-scripts"
75+
],
76+
"post-update-cmd": [
77+
"@legacy-scripts"
78+
]
79+
},
6680
"conflict": {
6781
"ezsystems/ezpublish-kernel": "<6.12 || >=2014.11 <2017.10"
6882
},

config.php-RECOMMENDED

-40
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,6 @@
1212
*uncomment* the proposed settings.
1313
*/
1414

15-
16-
/*
17-
PATH TO THE EZCOMPONENTS
18-
------------------------
19-
config.php can set the components path like:
20-
*/
21-
//ini_set( 'include_path', ini_get( 'include_path' ). PATH_SEPARATOR . '../ezcomponents/trunk' );
22-
23-
/*
24-
USING COMPONENTS VIA COMPOSER
25-
-----------------------------
26-
If installation is in a eZ Publish 5/Symfony context, composer will be attempted to be used
27-
if the following file is found: '../EZP_APP_FOLDER_NAME/autoload.php'
28-
Default EZP_APP_FOLDER_NAME value is "app" and this constant gives you possibility to change it.
29-
In eZ Publish 5.x, default value of EZP_APP_FOLDER_NAME was "ezpublish".
30-
*/
31-
//define( 'EZP_APP_FOLDER_NAME', 'my_app' );
32-
33-
/*
34-
USING BUNDLED COMPONENTS
35-
------------------------
36-
If you are using a distribution of eZ Publish with which the necessary
37-
eZ Components are bundled (in lib/ezc), then you can use this setting to
38-
control if the bundled eZ Components should be used (true) or not (false).
39-
By default, when this setting is not present and the bundled eZ Components are
40-
present, they will be used. If you're using the bundled eZ Components it's recommended
41-
to define EZP_USE_BUNDLED_COMPONENTS as a boolean true anyway, for optimal speed.
42-
*/
43-
//define( 'EZP_USE_BUNDLED_COMPONENTS', true );
44-
45-
46-
/*
47-
If you are not using the bundled eZ Components, then for optimal speed it is
48-
recommended to set EZC_BASE_PATH to either ezc/Base/base.php or Base/src/base.php,
49-
depending on how you installed the eZ Components. By default, if this setting
50-
is not present, eZ Publish first tries to include ezc/Base/base.php in the standard
51-
php include path. If that fails Base/src/base.php is included.
52-
*/
53-
//define( 'EZC_BASE_PATH', '/usr/lib/ezc/Base/base.php' );
54-
5515
/*
5616
TIMEZONES
5717
---------

0 commit comments

Comments
 (0)