/** * Rename nodes * * @param array $keys * * @throws NonAssocException * * @return $this */ public function renameKeys(array $keys) { if (!is_assoc($keys)) { throw new NonAssocException(); } foreach ($keys as $oldKey => $newKey) { if (!$this->array->offsetExists($oldKey)) { continue; } $this->array->offsetSet($newKey, $this->array->offsetGet($oldKey)); $this->array->offsetUnset($oldKey); } return $this; }
/** * Cancel a pending timer. * * @param TimerInterface $timer The timer to cancel. */ public function cancelTimer(TimerInterface $timer) { if ($this->timers->offsetExists($timer)) { $id = $this->timers->offsetGet($timer); $this->timers->offsetUnset($timer); $this->reactor->cancel($id); } }
/** * 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' => []]); }
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; }
/** * @see \ArrayAccess::offsetUnset() */ public function offsetUnset($offset) { $this->metadata->offsetUnset($offset); }