コード例 #1
0
 /**
  * @param mixed $resource
  * @param null  $type
  *
  * @return string
  */
 public function load($resource, $type = null)
 {
     try {
         OutBuffer::conf([OutBuffer::CFG_PRE => '  ' . ConsoleStringColorSwatches::$colors['+y/-'] . '> ' . ConsoleStringColorSwatches::$colors['+R/-']]);
         OutBuffer::line('+p/i-pre-load+p/b- [resolve]+w/i- %s');
         OutBuffer::show($resource);
         OutBuffer::stat('+p/i-resolver+p/b- [reading]+w/- reading file content into memory=+w/-[ +w/i-' . filesize($resource) . ' bytes +w/-]');
         $contents = $this->loadFileContents($resource);
         OutBuffer::stat('+p/i-resolver+p/b- [parsing]+w/- loading file content to native type');
         $decoded = $this->loadUsingSymfonyYaml($contents);
         echo PHP_EOL;
     } catch (\Exception $exception) {
         throw new RuntimeException('Could not decode YAML.', $exception);
     }
     return $decoded;
 }
コード例 #2
0
 /**
  * @param \Scribe\Doctrine\ORM\Mapping\Entity|mixed $entity
  * @param mixed                                     $index
  *
  * @throws \Exception
  *
  * @return $this
  */
 protected function loadAndMergeEntity($index, $entity)
 {
     try {
         $entityMetadata = $this->getClassMetadata($this->getEntityFQCN());
         $this->identLog[] = $identity = $entityMetadata->getIdentifierValues($entity);
         if (count($identity) > 0) {
             $identity = [key($identity) => current($identity)];
         } elseif (!$entity->hasIdentity()) {
             OutBuffer::stat('+y/b-preload +y/i-[warns]+w/- import could not begin for "%s:%d"', basename($this->metadata->getName()), $index);
             OutBuffer::stat('+y/b-preload +y/i-[warns]+w/- import strategy "merge" unavailable due to failed identifier map resolution');
         }
         $repository = $this->manager->getRepository($this->getEntityFQCN());
         $entitySearched = $repository->findOneBy($identity);
         $this->manager->initializeObject($entitySearched);
         if ($entitySearched && !$entity->isEqualTo($entitySearched)) {
             $mapper = new HydratorManager(new HydratorMapping(true));
             $entity = $mapper->getMappedObject($entity, $entitySearched);
             $this->manager->remove($entitySearched);
             $this->manager->merge($entity);
             $this->manager->persist($entity);
             $this->manager->flush();
             $this->manager->clear();
             ++$this->countUpdate;
             return $this;
         } elseif ($entitySearched && $entity->isEqualTo($entitySearched)) {
             $entity = $entitySearched;
             ++$this->countSkip;
             return $this;
         }
         $this->loadAndPersistEntity($entity);
     } catch (\Exception $e) {
         throw $e;
     }
     return $this;
 }