Ejemplo n.º 1
0
 /**
  * Adds a file to the archive.
  *
  * @param string $file  The path to the file.
  * @param string $local The path to the file in the archive.
  */
 public function addFile($file, $local = null)
 {
     if (null === $this->dispatcher) {
         // @codeCoverageIgnoreStart
         if (null === $local) {
             parent::addFile($file);
         } else {
             parent::addFile($file, $local);
         }
         // @codeCoverageIgnoreEnd
         return;
     }
     $event = new PreAddFileEvent($this, $file, $local);
     $this->dispatcher->dispatch(Events::PRE_ADD_FILE, $event);
     if (!$event->isSkipped()) {
         /*
          * By using `Phar::addFile()` directly, it eliminates any
          * possibility of making changes to the contents of the file
          * before it is added to the archive. To work around this issue,
          * `Builder::addFromString()` is used to add the file after its
          * contents have been read.
          */
         $this->addFromString(null === $event->getLocal() ? $event->getFile() : $event->getLocal(), $this->getFileContents($event->getFile()));
         $event = new PostAddFileEvent($this, $event->getFile(), $event->getLocal());
         $this->dispatcher->dispatch(Events::POST_ADD_FILE, $event);
     }
 }
Ejemplo n.º 2
0
 /**
  * Logs when a file is added.
  *
  * @param PostAddFileEvent $event The event arguments.
  */
 public function onPostAddFile(PostAddFileEvent $event)
 {
     $this->logger->info(sprintf('The file "%s" has been added as "%s".', basename($event->getFile()), null === $event->getLocal() ? basename($event->getFile()) : basename($event->getLocal())), array('file' => $event->getFile(), 'local' => $event->getLocal()));
 }