예제 #1
0
 /**
  * Create fake records (Admin in persons, Backend in modules)
  */
 public static function generateFakeRecords()
 {
     $dbal = getApplication()->getStorage()->getAdapter();
     $master = getApplication()->getStorage()->getMaster();
     $admin = $master->getPersons()->create(array('hash' => '123', 'login' => 'admin', 'salt' => '123'))->save();
     $backend = $master->getModules()->create(array('id_person_owner' => $admin->getIdPerson(), 'name' => 'Backend'))->save();
     $user = $master->getPersons()->create(array('hash' => '123', 'login' => 'user', 'salt' => '321', 'id_module_default_module' => $backend->getIdModule()))->save();
     $user->setSalt('123456');
     $user->save();
     /**
      * Move old models start time to the past
      */
     $now = $dbal->fetchNow();
     $time = strtotime($now);
     $veryPastTime = date("Y-m-d H:i:s", $time - 10000);
     $pastTime = date("Y-m-d H:i:s", $time - 5001);
     $startTime = date("Y-m-d H:i:s", $time - 5000);
     $dbal->executeQuery("update person set v_start = :very_past, v_end = :past where v_end < '9999-12-31 23:59:59'", array('very_past' => $veryPastTime, 'past' => $pastTime));
     $dbal->executeQuery("update person set v_start = :start where v_end > :now", array('start' => $startTime, 'now' => $now));
     /**
      * Clear repositories maps
      */
     foreach (array($master->getModules(), $master->getPersons()) as $repo) {
         $mapProperty = Reflection::getReflectionProperty(get_class($repo), 'map');
         $mapProperty->setAccessible(true);
         $mapProperty->setValue($repo, array());
         $mapProperty->setAccessible(false);
     }
 }
예제 #2
0
 private function getRepositoryMap($repository)
 {
     $mapProperty = Reflection::getReflectionProperty(get_class($repository), 'map');
     $mapProperty->setAccessible(true);
     $map = $mapProperty->getValue($repository);
     $mapProperty->setAccessible(false);
     return $map;
 }
예제 #3
0
파일: Injector.php 프로젝트: cti/di
 function process($instance, $parameters)
 {
     $class = get_class($instance);
     $inspector = $this->getInspector();
     // injection contains class injection
     $injection = array();
     foreach ($inspector->getClassInjection($class) as $name => $inject) {
         if ($inject['new']) {
             $injection[$name] = $this->getManager()->create($inject['class']);
         } else {
             $injection[$name] = $this->getManager()->get($inject['class']);
         }
         $list = array();
         if ($this->references->offsetExists($injection[$name])) {
             $list = $this->references->offsetGet($injection[$name]);
         }
         $list[] = array('instance' => $instance, 'property' => $name);
         $this->references->offsetSet($injection[$name], $list);
     }
     $properties = $inspector->getClassProperties($class);
     foreach ($parameters as $name => $value) {
         if (isset($properties[$name])) {
             $injection[$name] = $value;
         }
     }
     foreach ($injection as $name => $value) {
         // public property
         if ($properties[$name]) {
             $instance->{$name} = $value;
             continue;
         }
         // protected property
         if ($this->getManager()->getConfigureAllProperties()) {
             $reflection = Reflection::getReflectionProperty($class, $name);
             $reflection->setAccessible(true);
             $reflection->setValue($instance, $value);
             $reflection->setAccessible(false);
         }
     }
 }