Skip to content

Commit

Permalink
Merge pull request #616 from nextcloud/enhancement/psr-event-dispatcher
Browse files Browse the repository at this point in the history
Add the psr/event-dispatcher package
  • Loading branch information
ChristophWurst committed Feb 10, 2021
2 parents 90a8336 + 0ac30c0 commit 4466d78
Show file tree
Hide file tree
Showing 19 changed files with 392 additions and 37 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -2,6 +2,8 @@
bin
*/**/phpstan.neon
.php_cs.dist
# ignore editor config
**/*.editorconfig
# ignore demo files
**/.travis.yml
# ignore .github files
Expand Down
11 changes: 6 additions & 5 deletions composer.json
Expand Up @@ -29,14 +29,17 @@
"microsoft/azure-storage-blob": "^1.5",
"nextcloud/lognormalizer": "^1.0",
"nikic/php-parser": "^4.2",
"opis/closure": "^3.6",
"patchwork/jsqueeze": "^2.0",
"pear/archive_tar": "^1.4.9",
"pear/pear-core-minimal": "^v1.10",
"phpseclib/phpseclib": "2.0.30",
"php-ds/php-ds": "^1.3",
"php-http/guzzle7-adapter": "^0.1.1",
"php-opencloud/openstack": "^3.1",
"phpseclib/phpseclib": "2.0.30",
"pimple/pimple": "3.3.1",
"psr/container": "^1.0",
"psr/event-dispatcher": "^1.0",
"punic/punic": "^1.6",
"sabre/dav": "^4.1.3",
"scssphp/scssphp": "^1.4.0",
Expand All @@ -45,14 +48,12 @@
"symfony/console": "4.4.19",
"symfony/event-dispatcher": "4.4.19",
"symfony/event-dispatcher-contracts": "1.1.9",
"symfony/polyfill-intl-normalizer": "^1.20",
"symfony/polyfill-intl-grapheme": "^1.20",
"symfony/polyfill-intl-normalizer": "^1.20",
"symfony/process": "4.4.19",
"symfony/routing": "4.4.19",
"symfony/translation": "4.4.19",
"web-auth/webauthn-lib": "^3.1",
"php-ds/php-ds": "^1.3",
"opis/closure": "^3.6"
"web-auth/webauthn-lib": "^3.1"
},
"scripts": {
"vendor": "composer install --no-dev && git clean -xdf && composer dump-autoload"
Expand Down
52 changes: 51 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions composer/ClassLoader.php
Expand Up @@ -42,6 +42,8 @@
*/
class ClassLoader
{
private $vendorDir;

// PSR-4
private $prefixLengthsPsr4 = array();
private $prefixDirsPsr4 = array();
Expand All @@ -57,6 +59,13 @@ class ClassLoader
private $missingClasses = array();
private $apcuPrefix;

private static $registeredLoaders = array();

public function __construct($vendorDir = null)
{
$this->vendorDir = $vendorDir;
}

public function getPrefixes()
{
if (!empty($this->prefixesPsr0)) {
Expand Down Expand Up @@ -300,6 +309,15 @@ public function getApcuPrefix()
public function register($prepend = false)
{
spl_autoload_register(array($this, 'loadClass'), true, $prepend);

if (null === $this->vendorDir) {
//no-op
} elseif ($prepend) {
self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders;
} else {
unset(self::$registeredLoaders[$this->vendorDir]);
self::$registeredLoaders[$this->vendorDir] = $this;
}
}

/**
Expand All @@ -308,6 +326,10 @@ public function register($prepend = false)
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));

if (null !== $this->vendorDir) {
unset(self::$registeredLoaders[$this->vendorDir]);
}
}

/**
Expand Down Expand Up @@ -367,6 +389,16 @@ public function findFile($class)
return $file;
}

/**
* Returns the currently registered loaders indexed by their corresponding vendor directories.
*
* @return self[]
*/
public static function getRegisteredLoaders()
{
return self::$registeredLoaders;
}

private function findFileWithExtension($class, $ext)
{
// PSR-4 lookup
Expand Down

0 comments on commit 4466d78

Please sign in to comment.