Ejemplo n.º 1
0
 protected function benchmark(Netizen $user, $counter)
 {
     $key = $user->getUsername();
     $stopwatch = microtime(true);
     for ($k = 0; $k < $counter; $k++) {
         $this->repository->persist($user);
     }
     printf(" write %s %.1f ms\n", $key, (microtime(true) - $stopwatch) * 1000 / $counter);
     $stopwatch = microtime(true);
     for ($k = 0; $k < $counter; $k++) {
         $user = $this->repository->findByNickname($key);
     }
     printf(" read %s %.1f ms\n", $user->getUsername(), (microtime(true) - $stopwatch) * 1000 / $counter);
 }
Ejemplo n.º 2
0
 /**
  * From key to object
  *
  * {@inheritDoc}
  */
 public function reverseTransform($value)
 {
     if (null !== $value && !is_scalar($value)) {
         throw new TransformationFailedException('Expected a scalar.');
     }
     if (!$this->existsNickname($value)) {
         throw new TransformationFailedException("{$value} is an invalid choice");
     }
     $found = $this->repository->findByNickname($value);
     if (is_null($found)) {
         throw new TransformationFailedException("Author {$value} is not found");
     }
     return $found->getAuthor();
 }