static function factory(EntityManager $em, $uuid, $allowCache = false)
    {
        if (!Util\UUID::validate($uuid)) {
            throw new \Exception('Invalid UUID: \'' . $uuid . '\'');
        }
        if (!self::$cache) {
            self::$cache = $em->getConfiguration()->getQueryCacheImpl();
        }
        if ($allowCache && self::$cache && self::$cache->contains($uuid)) {
            // used hydrated cache result
            return self::$cache->fetch($uuid);
        }
        $dql = 'SELECT a, p
			FROM Volkszaehler\\Model\\Entity a
			LEFT JOIN a.properties p
			WHERE a.uuid = :uuid';
        $q = $em->createQuery($dql)->setParameter('uuid', $uuid);
        try {
            $entity = $q->getSingleResult();
            if ($allowCache && self::$cache) {
                self::$cache->save($uuid, $entity, Util\Configuration::read('cache.ttl'));
            }
            return $entity;
        } catch (\Doctrine\ORM\NoResultException $e) {
            throw new \Exception('No entity found with UUID: \'' . $uuid . '\'');
        }
    }
 /**
  * Constructor
  *
  * @param string $type
  */
 public function __construct($type)
 {
     if (!Definition\EntityDefinition::exists($type)) {
         throw new \Exception('Unknown entity type: \'' . $type . '\'');
     }
     $this->type = $type;
     $this->uuid = (string) Util\UUID::mint();
     // generate random UUID
     $this->properties = new Collections\ArrayCollection();
     $this->parents = new Collections\ArrayCollection();
 }
    /**
     * Get entity
     *
     * @param string $identifier
     */
    public function get($uuid = NULL)
    {
        if (isset($uuid)) {
            // single entity
            if (!Util\UUID::validate($uuid)) {
                throw new \Exception('Invalid UUID: \'' . $uuid . '\'');
            }
            $dql = 'SELECT a, p
				FROM Volkszaehler\\Model\\Entity a
				LEFT JOIN a.properties p
				WHERE a.uuid = :uuid';
            $q = $this->em->createQuery($dql);
            $q->setParameter('uuid', $uuid);
            try {
                return $q->getSingleResult();
            } catch (\Doctrine\ORM\NoResultException $e) {
                throw new \Exception('No entity found with UUID: \'' . $uuid . '\'', 404);
            }
        } else {
            // public entities
            return array('entities' => $this->filter(array('public' => TRUE)));
        }
    }
Exemple #4
0
 */
include '../lib/Util/Random.php';
include '../lib/Util/UUID.php';
use Volkszaehler\Model;
use Volkszaehler\Util;
$chars = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'v', 'u', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'V', 'U', 'W', 'X', 'Y', 'Z');
?>
<h4>PRNG tests</h4>

<p>PNRG generator: <?php 
echo Util\Random::init();
?>
</p>

<pre>

<?php 
echo 'Numbers: ' . implode(',', Util\Random::getNumbers(0, 15, 10)) . PHP_EOL;
echo 'String: ' . Util\Random::getString($chars, 100) . PHP_EOL;
echo 'Bytes: ' . Util\Random::getBytes(100) . PHP_EOL;
?>
</pre>
<h4>UUId tests</h4>
<pre>
<?php 
for ($i = 0; $i < 100; $i++) {
    echo Util\UUID::mint(4) . PHP_EOL;
}
?>
</pre>