Exemplo n.º 1
0
 private function setupFileSystem()
 {
     $instanceIndexOne = new Index(['identifier1' => $this->referenceFactory->create($this->newSource('identifier1', 'checksum1')), 'identifier2' => $this->referenceFactory->create($this->newSource('identifier2', 'checksum2', [new ReturnStatement(true)])), 'identifier4' => $this->referenceFactory->create($this->newSource('identifier4', 'checksum4'))]);
     $instanceIndexTwo = new Index(['identifier3' => $this->referenceFactory->create($this->newSource('identifier3', 'checksum3'))]);
     $this->vfs = vfsStream::setup('root', null, ['directory' => ['index_default.php' => sprintf('<?php %s%s;', PHP_EOL, (new ReturnStatement($this->objectBuilder->build($instanceIndexOne)))->compile($this->export)), 'index_custom.php' => sprintf('<?php %s%s;', PHP_EOL, (new ReturnStatement($this->objectBuilder->build($instanceIndexTwo)))->compile($this->export)), '_index_meta.php' => sprintf('<?php %s%s;', PHP_EOL, (new ReturnStatement(new Scalar(['default' => 'index_default', 'custom' => 'index_custom'])))->compile($this->export)), 'default' => ['identifier1.php' => '<?php ' . PHP_EOL . 'return function ($item, $item2) {' . PHP_EOL . '  return spritnf("%s-%s", $item, $item2); ' . PHP_EOL . '};', 'identifier4.php' => '<?php return 9999;'], 'custom' => ['identifier3.php' => '<?php return false;']]]);
     return $this->vfs;
 }
Exemplo n.º 2
0
 /**
  * Stores source into storage if it is not available
  * or if checksum is different
  *
  * @param SourceInterface $source
  *
  * @return ReferenceInterface
  */
 public function store(SourceInterface $source)
 {
     $existingReference = $this->find($source);
     if ($existingReference && $existingReference->getChecksum() === $source->getChecksum()) {
         return $existingReference;
     }
     $newReference = $this->referenceFactory->create($source);
     $dispersion = $this->dispersion->calculate($newReference->getId());
     $index = $this->loadIndex($dispersion);
     if (!$index) {
         $index = $this->createIndex($dispersion);
     }
     $index->add($newReference);
     $filePath = $this->getReferenceFilePath($newReference, $dispersion);
     $container = $source->load();
     $this->writePhpFile($filePath, $container);
     return $newReference;
 }