*/
public function getRequiredDependencies() {
$deps = array();
- foreach ( $this->contents['require'] as $package => $version ) {
- if ( $package !== "php" && strpos( $package, 'ext-' ) !== 0 ) {
- $deps[$package] = self::normalizeVersion( $version );
+ if ( isset( $this->contents['require'] ) ) {
+ foreach ( $this->contents['require'] as $package => $version ) {
+ if ( $package !== "php" && strpos( $package, 'ext-' ) !== 0 ) {
+ $deps[$package] = self::normalizeVersion( $version );
+ }
}
}
}
}
+ // check, if the extension requires composer libraries
+ if ( $this->needsComposerAutoloader( dirname( $this->getArg( 0 ) ) ) ) {
+ // set the load composer autoloader automatically property
+ $this->output( "Detected composer dependencies, setting 'load_composer_autoloader' to true.\n" );
+ $this->json['load_composer_autoloader'] = true;
+ }
+
// Move some keys to the top
$out = array();
foreach ( $this->promote as $key ) {
$this->json['ResourceFileModulePaths'] = $defaults;
}
}
+
+ protected function needsComposerAutoloader( $path ) {
+ $path .= '/composer.json';
+ if ( file_exists( $path ) ) {
+ // assume, that the composer.json file is in the root of the extension path
+ $composerJson = new ComposerJson( $path );
+ // check, if there are some dependencies in the require section
+ if ( $composerJson->getRequiredDependencies() ) {
+ return true;
+ }
+ }
+ return false;
+ }
}
$maintClass = 'ConvertExtensionToRegistration';