18 private function callEntryPoints($eps, $autoload, $wrapper)
20 $loader =
new ClassLoader();
21 if (isset($autoload[
'psr-0'])) {
22 foreach ($autoload[
'psr-0'] as $prefix => $path) {
23 $loader->set($prefix, $path);
26 if (isset($autoload[
'psr-4'])) {
27 foreach ($autoload[
'psr-4'] as $prefix => $path) {
28 $loader->setPsr4($prefix, $path);
33 foreach ((array) $eps as $ep) {
34 if (!class_exists($ep,
false)) {
35 $loader->loadClass($ep);
38 $interfaces = (array) class_implements($ep);
39 if (!in_array(
'fpoirotte\\Cryptal\\Implementers\\PluginInterface', $interfaces)) {
40 throw new \InvalidArgumentException(
'Invalid entry point: ' . $ep);
43 call_user_func(
"$ep::registerAlgorithms", $wrapper);
45 $loader->unregister();
48 public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
50 $extra = $package->getExtra();
51 if (empty($extra[
'cryptal.entrypoint'])) {
52 throw new \UnexpectedValueException(
'Error while installing ' . $package->getPrettyName() .
53 ', cryptal-plugin packages should have an entry point ' .
54 'defined in their extra key to be usable.');
57 $res = parent::install($repo, $package);
60 $registry = Registry::getInstance();
62 $this->callEntryPoints($extra[
'cryptal.entrypoint'], $package->getAutoload(), $wrapper);
64 }
catch (\Exception $e) {
65 $this->io->writeError(
'Cryptal plugin installation failed, rolling back');
66 parent::uninstall($repo, $package);
73 public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
75 $extra = $target->getExtra();
76 if (empty($extra[
'cryptal.entrypoint'])) {
77 throw new \UnexpectedValueException(
'Error while installing ' . $target->getPrettyName() .
78 ', cryptal-plugin packages should have an entry point ' .
79 'defined in their extra key to be usable.');
82 $res = parent::update($repo, $initial, $target);
85 $registry = Registry::getInstance();
86 $registry->removeAlgorithms($initial->getPrettyName());
88 $this->callEntryPoints($extra[
'cryptal.entrypoint'], $target->getAutoload(), $wrapper);
90 }
catch (\Exception $e) {
91 $this->io->writeError(
'Cryptal plugin update failed, rolling back');
92 parent::install($repo, $initial);
99 public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
101 $res = parent::uninstall($repo, $package);
102 $registry = Registry::getInstance();
103 $registry->removeAlgorithms($package->getPrettyName());
108 public function supports($packageType)
110 return 'cryptal-plugin' === $packageType;
113 public function registerRootPackage(PackageInterface $package)
115 $extra = $package->getExtra();
116 if (empty($extra[
'cryptal.entrypoint'])) {
117 throw new \UnexpectedValueException(
'Error while installing ' . $package->getPrettyName() .
118 ', cryptal-plugin packages should have an entry point ' .
119 'defined in their extra key to be usable.');
123 $registry = Registry::getInstance();
124 $registry->removeAlgorithms($package->getPrettyName());
126 $this->callEntryPoints($extra[
'cryptal.entrypoint'], $package->getAutoload(), $wrapper);
128 }
catch (\Exception $e) {
129 $this->io->writeError(
'Cryptal plugin registration failed');