Example #1
0
File: Sqon.php Project: sqon/sqon
 /**
  * {@inheritdoc}
  */
 public function setPathsUsingIterator(Iterator $iterator)
 {
     $this->dispatch(BeforeSetPathsUsingIteratorEvent::NAME, BeforeSetPathsUsingIteratorEvent::class, function (BeforeSetPathsUsingIteratorEvent $event) use(&$iterator) {
         $iterator = $event->getIterator();
     }, $iterator);
     $this->database->begin();
     try {
         foreach ($iterator as $path => $manager) {
             if (!is_string($path)) {
                 // @codeCoverageIgnoreStart
                 throw new SqonException('The key returned by the iterator must be the path.');
                 // @codeCoverageIgnoreEnd
             }
             if (!$manager instanceof PathInterface) {
                 // @codeCoverageIgnoreStart
                 throw new SqonException('The value returned by the iterator must be a path manager.');
                 // @codeCoverageIgnoreEnd
             }
             $this->setPath($this->cleanPath($path), $manager);
         }
         // @codeCoverageIgnoreStart
     } catch (Exception $exception) {
         $this->database->rollback();
         throw $exception;
     }
     // @codeCoverageIgnoreEnd
     $this->database->commit();
     $this->dispatch(AfterSetPathsUsingIteratorEvent::NAME, AfterSetPathsUsingIteratorEvent::class, null, $iterator);
     return $this;
 }
Example #2
0
 /**
  * Creates a new database manager.
  */
 protected function setUp()
 {
     $this->pdo = new PDO('sqlite:' . $this->createTemporaryFile(), null, null, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
     $this->manager = new Database($this->pdo);
     $this->manager->createSchema();
     $columns = ['path', 'type', 'compression', 'modified', 'permissions', 'contents'];
     $this->insert = $this->pdo->prepare(sprintf('INSERT INTO paths (%s) VALUES (:%s)', join(', ', $columns), join(', :', $columns)));
     $this->values = ['compression' => Database::NONE, 'path' => 'test.php', 'type' => Memory::FILE, 'modified' => time(), 'permissions' => 0644, 'contents' => 'test'];
 }