Example #1
0
 /**
  * Loads the DAL for the given path and do some check about the supported version of the loaded files and that
  * there is no circular references between them.
  *
  * This method will check that:
  *
  * - The PostgreSQL version matches the supported version of the DAL.
  * - The loaded DAL does not induces circular reference.
  *
  * @param string   $path  The path of the DAL to load.
  * @param string[] $stack The stack of paths that have been loaded since the current call.
  *
  * @throws LogicException When a circular reference is detected.
  * @throws LogicException When the version of PostgreSQL doesn't match the minimum version required.
  *
  * @return AbstractDal
  */
 private function loadLayerAndCheck($path, array $stack)
 {
     if (in_array($path, $stack)) {
         throw new LogicException(sprintf('Circular reference detected:' . PHP_EOL . '  - file: %s' . PHP_EOL . '  - load: %s then crash', implode(PHP_EOL . '  - load: ', $stack), $path));
     }
     $metadata = unserialize(file_get_contents($this->getMetaFilename($path)));
     $pgVersion = $this->connection->getVersion();
     $cmpVersion = $metadata->getSupport();
     if (version_compare($pgVersion, $cmpVersion, '<')) {
         throw new LogicException(sprintf('The current version of PostgreSQL is "%s" and the DAL "%s" requires a minimum version of "%s"', $pgVersion, $path, $cmpVersion));
     }
     $stack[] = $path;
     $this->graphNodes[$path] = $graphNode = new GraphNode();
     $mapper = new HierarchicalMapper($graphNode);
     $mapper->setType('#', new FragmentConverter());
     $blueprint = new HierarchicalBlueprint($graphNode, $this->connection, $mapper, $this->executionStrategies, $this->environment);
     foreach ($metadata->getImports() as $import => $map) {
         $this->doLoad($import, $stack);
         $graphNode->import($this->graphNodes[$import], $map);
     }
     return $this->loadLayer($this->getFilename($path), $mapper, $blueprint);
 }
Example #2
0
 /**
  * It resolves origins resource names from aliases.
  */
 function it_resolves_origin_resource_names_from_aliases()
 {
     $handler = (object) [];
     $node1 = new GraphNode();
     $node1->setResourceHandler('foo', $handler);
     $node1->export('foo');
     $node1->export('foo', 'bar');
     $node2 = new GraphNode();
     $node2->import($node1, ['foo' => 'foo', 'bar' => 'baz']);
     $node2->export('foo');
     $node2->export('baz', 'qux');
     $this->import($node2, ['foo' => 'foo', 'qux' => 'quux']);
     $this->getResourceHandler('quux')->shouldReturn($handler);
     $this->getResourceIdentifier('quux')->shouldReturn('foo');
     $this->getResourceHandler('foo')->shouldReturn($handler);
     $this->getResourceIdentifier('foo')->shouldReturn('foo');
 }