/**
  * 
  * @param string $class
  * @param string $repository
  * @param mixed $object
  * @return \ChartBlocks\Entity\EntityInterface
  * @throws Exception
  */
 public function createInstanceOf($entityName, $object)
 {
     $class = '\\ChartBlocks\\Entity\\' . $entityName;
     if ($object instanceof $class) {
         return $object;
     }
     if (false === class_exists($class)) {
         throw new \InvalidArgumentException("{$class} not found");
     }
     if (is_array($object)) {
         $repo = $this->client->getRepository($entityName);
         return new $class($repo, $object);
     }
     throw new Exception("Invalid object for creating {$class}");
 }
Example #2
0
 public function testGetRepositoryReturnsSameInstance()
 {
     $client = new Client();
     $first = $client->getRepository('chart');
     $second = $client->getRepository('chart');
     $this->assertEquals(spl_object_hash($first), spl_object_hash($second));
 }