예제 #1
0
 public function testFailPaths()
 {
     $this->prepareInput();
     $model = new PublishModel($this->inputMock);
     $this->assertSame('*', $model->getPackageEntry());
     $this->assertSame('*', $model->getGroupEntry());
     $this->assertSame(getcwd(), $model->getConfigPath());
     $this->assertSame(getcwd(), $model->getPublishPath());
 }
예제 #2
0
 private function extractNotation($fileString)
 {
     // removing extra space characters for further work
     $fileString = preg_replace('/(\\ {0,1})/is', '', $fileString);
     // extracting file string notation
     $fileStringNotation = explode('->', $fileString);
     // if file notation contains copy/link
     // via destination "->" symbol
     if (count($fileStringNotation) == 2) {
         // throwing an exception if target path is absolute
         if ($fileStringNotation[0][0] == '/') {
             throw new \LogicException('.publisher does not work with absolute paths');
         }
         if ($fileStringNotation[1][0] == '/') {
             throw new \LogicException('.publisher does not work with absolute paths');
         }
         // composing source notation - (publish path + directory separator + distination)
         $fileStringNotation[1] = $this->model->getPublishPath() . '/' . $fileStringNotation[1];
         // checking if source want to be published
         // in one of possible locations
         // e.g.: "{public,web}/assets" will check if
         // public/assets or public/web is available.
         // e.g.: "assets/{scripts,js}" will check if
         // assets/scripts or assets/js is available.
         $reg = '/(.*?)(\\{)([\\w\\d\\.\\-\\@\\:\\,]{1,})(\\})([\\w\\d\\/\\.\\-\\@\\:\\,]{0,})/i';
         if (preg_match($reg, $fileStringNotation[1], $matches)) {
             // converting variants into array
             // e.g. {public,web,htdocs}/assets will produce ['public', 'web', 'htdocs']
             $variants = explode(',', $matches[3]);
             // suppose that none of variants exists
             $existed = false;
             foreach ($variants as $publishVariant) {
                 // if path exists setting it as
                 if ($existed = realpath($matches[1] . $publishVariant)) {
                     // replacing source notation with target path
                     // and breaking the loop
                     $fileStringNotation[1] = $matches[1] . $publishVariant . $matches[5];
                     break;
                 }
             }
             if (!$existed) {
                 // if none of variants exists
                 // replacing source notation with first "posible"
                 // target path
                 $fileStringNotation[1] = $matches[1] . $variants[0] . $matches[5];
             }
         }
     } elseif (count($fileStringNotation) == 1) {
         // if file notation string does not
         // contain destination symbol
         if ($fileStringNotation[0][0] == '/') {
             throw new \LogicException('.publisher does not work with absolute paths');
         }
         $fileStringNotation[1] = $this->model->getPublishPath();
     } else {
         // if we meet nonsense typo
         throw new \LogicException("Unexpected syntax in:" . $fileString);
     }
     return $fileStringNotation;
 }
예제 #3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $model = new PublishModel($input);
     // setting path to scan for .publisher.* config file
     $this->publisherScanner->setPath($model->getConfigPath());
     /**
      * @var IPublisherHandler $handler
      */
     $handler = $this->publisherScanner->scan(false);
     // if handler is null, throwing an exception
     // with message
     if (!$handler) {
         // retrieving available extensions
         // and making mask-like string
         $extensions = implode('|', $this->publisherScanner->getSupportedExtensions());
         throw new \Exception('You have to create .publisher.(' . $extensions . ') file first.');
     }
     $publisherHandler = new PublisherHandler($model, $handler, $this->fileSystem);
     $publisherHandler->setOutput($output)->process();
 }