Esempio n. 1
0
 public function __construct(IStorage $storage, IEventEmitter $emitter)
 {
     $this->storage = $storage;
     $this->emitter = $emitter;
     $this->setProperties($storage->read('user', array()));
     $this->emitUserEvent('user.create');
 }
 protected function setUp()
 {
     $this->storage = $this->getMock('IStorage');
     $this->storage->expects($this->once())->method('read')->will($this->returnValue(array('name' => 'John Doe', 'age' => 41)));
     $this->emitter = $this->getMock('IEventEmitter');
     $this->emitter->expects($this->once())->method('notify');
     $this->object = new User($this->storage, $this->emitter);
 }
Esempio n. 3
0
 /**
  * Uploads a new file
  */
 public function handleUploadFile()
 {
     $this->templateName = 'Upload.latte';
     $this->storage->addFile($_FILES['upload']['tmp_name'], $_FILES['upload']['name']);
     $this->template->url = $this->template->basePath . '/' . $this->storage->getBaseUrl() . '/' . $_FILES['upload']['name'];
     $this->template->message = 'Soubor byl nahrán';
     $this->template->setFile(__DIR__ . '/templates/' . $this->templateName);
     $this->template->render();
     $this->getPresenter()->terminate();
 }
Esempio n. 4
0
 public function Start($loop_time = 10800, $iterations_before_sleep = 100, $sleep_idle_seconds = 1)
 {
     $this->storage->setSemaphoreLifeTime($loop_time);
     if (!$this->storage->semaphore_create()) {
         return false;
     }
     $finish_time = time() + $loop_time;
     $empty_iterations = 0;
     while (time() < $finish_time) {
         if (!$this->storage->semaphore_exists()) {
             return false;
         }
         $empty_iterations++;
         while ($task = $this->storage->get_next_task()) {
             $empty_iterations = 0;
             //Unlink semaphore before executing task - if this task will take too long time,
             //other process will be able to execute other tasks
             if (!$this->storage->semaphore_delete()) {
                 return false;
             }
             $this->executeTask($task);
             if (time() > $finish_time) {
                 return false;
             }
             //if semaphore exists, it's mean that task's execution time was too long
             //and other process already executes other tasks, so this process should exit
             //if not exists, it's mean this process still is main tasks executor, so let's
             //create semaphore, to prevent multiple processes going to loop
             if (!$this->storage->semaphore_create()) {
                 return false;
             }
         }
         if ($empty_iterations > $iterations_before_sleep) {
             sleep($sleep_idle_seconds);
             $empty_iterations = 0;
         }
     }
     $this->storage->semaphore_delete();
     return true;
 }
Esempio n. 5
0
	/**
	 * @return Dictionary
	 */
	public function save()
	{
		$this->storage->save($this, $this->lang);
		return $this;
	}