示例#1
0
 /**
  * Conditionally replace node value with new one
  *
  * @param string                       $key
  * @param string|integer|float|boolean $oldValue
  * @param mixed                        $newValue
  *
  * @return $this
  */
 public function replaceValue($key, $oldValue, $newValue)
 {
     if ($this->array->offsetExists($key) && $oldValue === $this->array->offsetExists($key)) {
         $this->array->offsetSet($key, $newValue);
     }
     return $this;
 }
示例#2
0
 /**
  * Enqueue a callback to be invoked repeatedly after the given interval.
  *
  * The execution order of timers scheduled to execute at the same time is
  * not guaranteed.
  *
  * @param int|float $interval The number of seconds to wait before execution.
  * @param callable $callback The callback to invoke.
  *
  * @return TimerInterface
  */
 public function addPeriodicTimer($interval, callable $callback)
 {
     $timer = null;
     $wrappedCallback = function () use($callback, &$timer) {
         return call_user_func($callback, $timer);
     };
     $id = $this->reactor->repeat($wrappedCallback, $interval * $this->timeScaleFactor);
     $timer = $this->createTimer($interval, $wrappedCallback, true);
     $this->timers->offsetSet($timer, $id);
     return $timer;
 }
示例#3
0
 /**
  * Returns the content to render
  *
  * @param Request $request
  * @param Response $response
  * @param null|callable $next
  * @return null|Response
  */
 public function dispatch(Request $request, Response $response, callable $next = null) : Response
 {
     // On GET requests that are not comming from PRG, just return the template
     if ($request->getMethod() === 'GET' && !$this->session->offsetExists(self::PRG_DATA)) {
         return $this->createTemplateResponse($request);
     }
     // On POST requests, get request data, store it in the session, and redirect to sel
     if ($request->getMethod() === 'POST') {
         $params = $request->getParsedBody();
         $this->session->offsetSet(self::PRG_DATA, $params);
         return new RedirectResponse($request->getUri());
     }
     // On a GET request that contains data, process the data and clear it from session
     $params = $this->session->offsetGet(self::PRG_DATA);
     $this->session->offsetUnset(self::PRG_DATA);
     $filter = $this->contactFilter;
     $filter->setData($params);
     if (!$filter->isValid()) {
         return $this->createTemplateResponse($request, ['errors' => $filter->getMessages(), 'currentData' => $params]);
     }
     // If the form is valid, send the email
     $result = $this->contactService->send($filter->getValues());
     return $this->createTemplateResponse($request, $result ? ['success' => true] : ['errors' => []]);
 }
示例#4
0
 public function save()
 {
     if (is_null($this->arr)) {
         throw new \LogicException(sprintf('%s: you must setTableData() before save().', __CLASS__), 1354113867);
     }
     if (!$this->isModified()) {
         return FALSE;
     }
     if (is_null($this->getKeyValue())) {
         throw new \LogicException(sprintf('%s: you must setKeyValue() before save().', __CLASS__), 1336388582);
     }
     if ($this->state === self::DELETED) {
         $this->arr->offsetUnset($this->getKeyValue());
         $this->data = new \ArrayObject();
         //$this->keyValue = NULL;
     } else {
         $this->mergeTableData();
         $this->arr->offsetSet($this->getKeyValue(), $this->data->getArrayCopy());
     }
     $this->state = self::CLEAN;
 }
示例#5
0
 /**
  * @see \ArrayAccess::offsetSet()
  */
 public function offsetSet($offset, $value)
 {
     $this->metadata->offsetSet($offset, $value);
 }
示例#6
0
 /**
  * Assign new value for template
  * @param string $index
  * @param mixed $value
  */
 public function assign($index, $value)
 {
     $this->variables->offsetSet($index, $value);
 }