예제 #1
0
 /**
  * @param  mixed              $target
  * @param  Event              $event
  * @return Event|CommandEvent
  */
 protected function checkListenerExpectedEvent($target, Event $event)
 {
     try {
         $reflected = new \ReflectionParameter($target, 0);
     } catch (\Exception $e) {
         return $event;
     }
     $typehint = $reflected->getClass();
     if (!$typehint instanceof \ReflectionClass) {
         return $event;
     }
     $expected = $typehint->getName();
     // BC support
     if (!$event instanceof $expected && $expected === 'Composer\\Script\\CommandEvent') {
         $event = new \Composer\Script\CommandEvent($event->getName(), $event->getComposer(), $event->getIO(), $event->isDevMode(), $event->getArguments());
     }
     if (!$event instanceof $expected && $expected === 'Composer\\Script\\PackageEvent') {
         $event = new \Composer\Script\PackageEvent($event->getName(), $event->getComposer(), $event->getIO(), $event->isDevMode(), $event->getPolicy(), $event->getPool(), $event->getInstalledRepo(), $event->getRequest(), $event->getOperations(), $event->getOperation());
     }
     if (!$event instanceof $expected && $expected === 'Composer\\Script\\Event') {
         $event = new \Composer\Script\Event($event->getName(), $event->getComposer(), $event->getIO(), $event->isDevMode(), $event->getArguments(), $event->getFlags());
     }
     return $event;
 }
예제 #2
0
 /**
  * @param  mixed              $target
  * @param  Event              $event
  * @return Event|CommandEvent
  */
 protected function checkListenerExpectedEvent($target, Event $event)
 {
     if (in_array($event->getName(), array('init', 'command', 'pre-file-download'), true)) {
         return $event;
     }
     try {
         $reflected = new \ReflectionParameter($target, 0);
     } catch (\Exception $e) {
         return $event;
     }
     $typehint = $reflected->getClass();
     if (!$typehint instanceof \ReflectionClass) {
         return $event;
     }
     $expected = $typehint->getName();
     // BC support
     if (!$event instanceof $expected && $expected === 'Composer\\Script\\CommandEvent') {
         trigger_error('The callback ' . $this->serializeCallback($target) . ' declared at ' . $reflected->getDeclaringFunction()->getFileName() . ' accepts a ' . $expected . ' but ' . $event->getName() . ' events use a ' . get_class($event) . ' instance. Please adjust your type hint accordingly, see https://getcomposer.org/doc/articles/scripts.md#event-classes', E_USER_DEPRECATED);
         $event = new \Composer\Script\CommandEvent($event->getName(), $event->getComposer(), $event->getIO(), $event->isDevMode(), $event->getArguments());
     }
     if (!$event instanceof $expected && $expected === 'Composer\\Script\\PackageEvent') {
         trigger_error('The callback ' . $this->serializeCallback($target) . ' declared at ' . $reflected->getDeclaringFunction()->getFileName() . ' accepts a ' . $expected . ' but ' . $event->getName() . ' events use a ' . get_class($event) . ' instance. Please adjust your type hint accordingly, see https://getcomposer.org/doc/articles/scripts.md#event-classes', E_USER_DEPRECATED);
         $event = new \Composer\Script\PackageEvent($event->getName(), $event->getComposer(), $event->getIO(), $event->isDevMode(), $event->getPolicy(), $event->getPool(), $event->getInstalledRepo(), $event->getRequest(), $event->getOperations(), $event->getOperation());
     }
     if (!$event instanceof $expected && $expected === 'Composer\\Script\\Event') {
         trigger_error('The callback ' . $this->serializeCallback($target) . ' declared at ' . $reflected->getDeclaringFunction()->getFileName() . ' accepts a ' . $expected . ' but ' . $event->getName() . ' events use a ' . get_class($event) . ' instance. Please adjust your type hint accordingly, see https://getcomposer.org/doc/articles/scripts.md#event-classes', E_USER_DEPRECATED);
         $event = new \Composer\Script\Event($event->getName(), $event->getComposer(), $event->getIO(), $event->isDevMode(), $event->getArguments(), $event->getFlags());
     }
     return $event;
 }