Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Fixes composer installation errors due to problematic configuration files #5

Merged

Conversation

weierophinney
Copy link
Member

@weierophinney weierophinney commented Nov 2, 2017

If a module configuration file contains elements that depend on autoloading and/or elements that are clearly not configuration, calling include on it can lead to failure to complete a composer installation/removal action.

This patch modifies the logic as follows:

  • If a configuration file does not have asset_manager configuration, it is skipped.
  • Both installation and uninstallation actions tokenize the configuration file to look for problematic elements, notably exec() and eval() calls; these raise warnings by the installer if detected.
  • Instead of performing install operations immediately, the Plugin class now aggregates install operations as closures around the relevant events, and executes these during a post-autoload-dump plugin hook; this fixes autoloading issues. Uninstall operations still occur immediately as the relevant uninstall and update events.

Fixes #4

…iles

If a module configuration file contains elements that depend on
autoloading and/or elements that are clearly not configuration, calling
`include` on it can lead to failure to complete a composer
installation/removal action.

This patch modifies the logic to tokenize the configuration file and
look for problematic elements; when encountered, the (un)installer will skip
including that configuration file, and instead emit a warning.
.travis.yml Outdated
@@ -47,18 +48,22 @@ matrix:
- php: hhvm

before_install:
- if [[ $TRAVIS_PHP_VERSION != "hhvm" && $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini ; fi
- if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
- travis_retry composer self-update
Copy link
Member

Choose a reason for hiding this comment

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

…_manager configuration

If a configuration file does not contain `asset_manager` configuration,
we do not need to do anything with it in the first place, and do not
need to emit warnings.

If the file contains any class pseudo-constant usage (e.g.
`AssetInstallerFactory::class`), we do not need to flag the file as
unusable, as PHP will resolve these regardless of autoloading.

As such, we'll only have issues with class constants, static members,
and cases where we are calling `new` or extending or implementing
classes or interfaces.
];

/**
* @var string $packageConfigPath
Copy link
Member

Choose a reason for hiding this comment

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

@param instead of @var

}

/**
* @var string $packageConfigPath
Copy link
Member

Choose a reason for hiding this comment

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

As above, @param instead of @var

…dumping

Per conversations with @Xerkus, this patch modifies the `Plugin` class
to create closures around each install, uninstall, and update event in
order to delay their execution until the `post-autoload-dump` event
executes. What that event executes, it will:

- loop through all uninstall closures and execute them.
- loop through all install closures and execute them.

This approach should solve autoloading issues (e.g., when resolving
class constants).
Uninstall operations should not suffer the same autoloading issues, as
the autoloader will already be in place. However, if they run during
post-autoload-dump, they _will_ have issues. As such, this commit
modifies the logic to run uninstall operations immediately, instead of
memoizing them to run later.
src/Plugin.php Outdated
}

/**
* Updates assets provided by the package, if any.
*
* Uninstalls any previously installed assets for the package, and then
* runs an install for the package.
* memoizes an install operation to run post-autoload-dump.
Copy link
Member Author

Choose a reason for hiding this comment

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

No typo: read about memoization on wikipedia. 😄

}

// ::class notation is okay
if ($token[0] === T_DOUBLE_COLON
Copy link

Choose a reason for hiding this comment

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

this check is no longer needed

* @param string|array Token to test as a class pseudoconstant
* @return bool
*/
private function isClassPseudoConstant($token)
Copy link

Choose a reason for hiding this comment

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

same here, no longer needed

Moves the uninstall operations originally in the post-package-update
hook to a pre-package-update hook. This should autoloading stays the
same (in cases where classes, class constants, config files, etc.
disappear).
Prevents deprecation notices.
@weierophinney weierophinney merged commit 7c3f23c into zfcampus:master Nov 2, 2017
weierophinney added a commit that referenced this pull request Nov 2, 2017
weierophinney added a commit that referenced this pull request Nov 2, 2017
weierophinney added a commit that referenced this pull request Nov 2, 2017
@weierophinney weierophinney deleted the hotfix/4-class-constant-detection branch November 2, 2017 22:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Package is triggering autoload errors
3 participants