/** * Overridden getter to avoid using of $_SERVER * * @param string|null $name * @param mixed|null $default * @return ParametersInterface|array|mixed|null */ public function getServer($name = null, $default = null) { if (null === $name) { return $this->_server; } return $this->_server->get($name, $default); }
public function save(ParametersInterface $data) { $em = $this->getEntityManager(); $attribute = $data->get('attribute'); $primaryKey = $data->get('primaryKey'); $content = $data->get('content') ? $data->get('content') : null; $constraints = $data->get('constraints', null); $repository = $this->getServiceRepository(); if ($constraints) { $constraints = json_decode(str_replace('\\', '\\\\', $constraints), true); } if ($primaryKey) { $entity = $repository->find($primaryKey); if ($entity) { /** * @var \Zend\InputFilter\InputFilterInterface $filter */ $filter = $this->getServiceManager()->get('serviceFilter')->filter($attribute, $content); if ($filter->isValid()) { if (!empty($constraints) && $content) { foreach ($constraints as $constraint) { if ($constraint["type"] == "foreign") { $content = $em->getReference($constraint["target"], $content); } } } if ($attribute == "thumbnail") { $this->deleteImages($entity); foreach (ServiceEntity::$thumbnailVariations as $variation) { $result = FileUtilService::resize($content, 'images/services', $variation["width"], $variation["height"]); if (!$result) { $this->message = $result; return false; } } } $entity->{'set' . ucfirst($attribute)}($content); if ($attribute == "name") { $entity->setUrl($this->getServiceUrl($entity)); } try { $em->persist($entity); $em->flush(); $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_SERVICE_SAVED"]); return true; } catch (\Exception $e) { $this->message = $this->getTranslator()->translate($this->getVocabulary()["ERROR_SERVICE_NOT_SAVED"]); } } else { $this->message = $filter->getMessages()[$attribute]; } } } return false; }
public function perform($id, $endpoint, ParametersInterface $params) { $api = $this->docs->getOne($id); $resourceSet = $api->getResourceSet(); $resourceSet->seek($endpoint); $resource = $resourceSet->current(); $urlValues = (array) $params->get('urlParams'); $queryValues = (array) $params->get('queryParams'); $headerValues = (array) $params->get('headers'); $bodyValue = $params->get('body'); // Prepare url params $urlParams = $resource->getUrlParams(); $urlParams->setValues($urlValues); $urlParams->populate($resource); // Prepare http query params $queryParams = $resource->getQueryParams(); $queryParams->setValues($queryValues); $queryParams->populate($resource); $config = $api->getConfig(); $uri = $config->getBaseUrl() . $resource->getUrl(); /** @var $client Client */ $client = $this->getHttpClient(); $client->setMethod($resource->getMethod()); $client->setUri($uri); // Setup headers $request = $client->getRequest(); $headers = $request->getHeaders(); foreach ($resource->getHeaders() as $header) { $key = $header->getName(); if (array_key_exists($key, $headerValues)) { $value = $headerValues[$key]; $headers->addHeaderLine($key, $value); } } // Setup body $body = $resource->getBody(); $body->parse($bodyValue); $request->setContent($body->toString()); $response = $client->send(); // If response is JSON then parse it to JSON. $body = $response->getBody(); $responseHeaders = $response->getHeaders(); $contentType = $responseHeaders->get('Content-type'); if ($contentType instanceof ContentType) { $value = $contentType->getFieldValue(); if (false !== strpos($value, 'json')) { $body = Json::decode($body); } } return array('requestUri' => $request->getUriString(), 'requestBody' => $request->getContent(), 'requestHeaders' => $headers->toArray(), 'responseHeaders' => $responseHeaders->toArray(), 'responseBody' => $body); }
/** * Return the parameter container responsible for file parameters or a single file. * * @param string|null $name Parameter name to retrieve, or null to get the whole container. * @param mixed|null $default Default value to use when the parameter is missing. * @return ParametersInterface|mixed */ public function getFiles($name = null, $default = null) { if ($this->fileParams === null) { $this->fileParams = new Parameters(); } if ($name === null) { return $this->fileParams; } return $this->fileParams->get($name, $default); }
public function save(ParametersInterface $data) { $em = $this->getEntityManager(); $attribute = $data->get('attribute'); $primaryKey = $data->get('primaryKey'); $content = $data->get('content') ? $data->get('content') : null; $constraints = $data->get('constraints', null); $repository = $this->getRepository('application', 'content'); if ($constraints) { $constraints = json_decode(str_replace('\\', '\\\\', $constraints), true); } if ($primaryKey) { $entity = $repository->find($primaryKey); if ($entity) { $filter = $this->getServiceManager()->get('contentFilter')->filter($attribute, $content); if ($filter->isValid()) { if (!empty($constraints) && $content) { foreach ($constraints as $constraint) { if ($constraint["type"] == "foreign") { $content = $em->getReference($constraint["target"], $content); } } } $entity->{'set' . ucfirst($attribute)}($content); try { $em->persist($entity); $em->flush(); $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_CONTENT_SAVED"]); return true; } catch (\Exception $e) { $this->message = $this->getTranslator()->translate($this->getVocabulary()["ERROR_CONTENT_NOT_SAVED"]); } } else { $this->message = $filter->getMessages()[$attribute]; } } } return false; }
/** * Update and save the user * * @param $data * @return bool */ public function save(ParametersInterface $data) { $em = $this->getEntityManager(); $attribute = $data->get('attribute'); $primaryKey = $data->get('primaryKey'); $content = $data->get('content') ? $data->get('content') : null; $constraints = $data->get('constraints', null); $repository = $this->getRepository('user', 'user'); if ($constraints) { $constraints = json_decode(str_replace('\\', '\\\\', $constraints), true); } if ($primaryKey) { $entity = $repository->find($primaryKey); if ($entity) { $filter = $this->getServiceManager()->get('userFilter')->filter($attribute, $content); if ($filter->isValid()) { if (!empty($constraints) && $content) { foreach ($constraints as $constraint) { if ($constraint["type"] == "foreign") { $content = $em->getReference($constraint["target"], $content); } } } $entity->{'set' . ucfirst($attribute)}($content); try { $em->persist($entity); $em->flush(); return true; } catch (\Exception $e) { $this->message = "Something went wrong, please try again."; } } else { $this->message = $filter->getMessages()[$attribute]; } } } return false; }
/** * @param Ticket $expenseTicket * @param ParametersInterface $files * @return array */ private function separateAttachments(Ticket $expenseTicket, ParametersInterface $files) { $ticketFiles = []; $itemFiles = []; if ($files->count()) { $expenseItems = $expenseTicket->getItems(); $files = $files->toArray(); foreach ($files['files'] as $index => $file) { if (false === strpos($index, 'item_')) { array_push($ticketFiles, $file); } else { $fileOrder = substr($index, strlen('item_')); foreach ($expenseItems as $item) { $itemData = $item->getData(); $itemId = $item->getId(); if ($itemData['order'] == $fileOrder) { $itemFiles[$itemId] = $file; break; } } } } } return [$ticketFiles, $itemFiles]; }
/** * Build info for received message * * @param mixed $handle * @param mixed $id * @param Queue $queue * @param ParametersInterface|array $options * @return array */ protected function buildMessageInfo($handle, $id, $queue, $options = null) { $name = $queue instanceof Queue ? $queue->getName() : (string) $queue; return ['handle' => $handle, 'messageId' => $id, 'queueId' => $this->getQueueId($name), 'queueName' => $name, 'adapter' => get_called_class(), 'options' => $options instanceof ParametersInterface ? $options->toArray() : (array) $options]; }
public function getItemDetails(ParametersInterface $data) { $orderDao = $this->getOrderDao(); $expenseTransactionDao = $this->getServiceLocator()->get('dao_finance_transaction_expense_transactions'); $expenseItemDao = $this->getServiceLocator()->get('dao_finance_expense_expense_item'); $orderId = $data->get('orderId', 0); $orderData = $orderDao->getDataForPOItem($orderId); if (!$orderData || !$orderData['po_item_id']) { return ['status' => 'error', 'msg' => 'Order with mentioned Id does not exist']; } $accountFrom = ''; $accountTo = ''; $hasNotTransaction = 1; $expenseItemDetail = $expenseItemDao->getRawItemData($orderData['po_item_id']); if (!$expenseItemDetail || !$expenseItemDetail['transaction_id']) { return ['accountFrom' => $accountFrom, 'accountTo' => $accountTo, 'hasNotTransaction' => $hasNotTransaction]; } $where = new Where(); $where->equalTo('ga_expense_transaction.id', $expenseItemDetail['transaction_id']); $transactionDetails = $expenseTransactionDao->getTransactions($where); if ($transactionDetails) { foreach ($transactionDetails as $row) { $accountFrom = $row['account_to']; $accountTo = $row['account_from']; } $hasNotTransaction = 0; } return ['accountFrom' => $accountFrom, 'accountTo' => $accountTo, 'hasNotTransaction' => $hasNotTransaction]; }
public function setServer(ParametersInterface $server) { $this->serverParams = $server; // This seems to be the only way to get the Authorization header on Apache if (function_exists('apache_request_headers')) { $apacheRequestHeaders = apache_request_headers(); if (!isset($this->serverParams['HTTP_AUTHORIZATION'])) { if (isset($apacheRequestHeaders['Authorization'])) { $this->serverParams->set('HTTP_AUTHORIZATION', $apacheRequestHeaders['Authorization']); } elseif (isset($apacheRequestHeaders['authorization'])) { $this->serverParams->set('HTTP_AUTHORIZATION', $apacheRequestHeaders['authorization']); } } } // set headers $headers = array(); foreach ($server as $key => $value) { if ($value && strpos($key, 'HTTP_') === 0) { if (strpos($key, 'HTTP_COOKIE') === 0) { // Cookies are handled using the $_COOKIE superglobal continue; } $name = strtr(substr($key, 5), '_', ' '); $name = strtr(ucwords(strtolower($name)), ' ', '-'); } elseif ($value && strpos($key, 'CONTENT_') === 0) { $name = substr($key, 8); // Content- $name = 'Content-' . ($name == 'MD5' ? $name : ucfirst(strtolower($name))); } else { continue; } $headers[$name] = $value; } $this->getHeaders()->addHeaders($headers); // set method if (isset($this->serverParams['REQUEST_METHOD'])) { $this->setMethod($this->serverParams['REQUEST_METHOD']); } // set HTTP version if (isset($this->serverParams['SERVER_PROTOCOL']) && strpos($this->serverParams['SERVER_PROTOCOL'], self::VERSION_10) !== false) { $this->setVersion(self::VERSION_10); } // set URI $uri = new HttpUri(); // URI scheme if (!empty($this->serverParams['HTTPS']) && $this->serverParams['HTTPS'] !== 'off' || !empty($this->serverParams['HTTP_X_FORWARDED_PROTO']) && $this->serverParams['HTTP_X_FORWARDED_PROTO'] == 'https') { $scheme = 'https'; } else { $scheme = 'http'; } $uri->setScheme($scheme); // URI host & port $uri->setHost($this->serverParams['SERVER_NAME']); $uri->setPort($this->serverParams['SERVER_PORT']); // URI path if (isset($this->serverParams['REQUEST_URI'])) { $this->setRequestUri($this->serverParams['REQUEST_URI']); } $requestUri = $this->getRequestUri(); if (($qpos = strpos($requestUri, '?')) !== false) { $requestUri = substr($requestUri, 0, $qpos); } $uri->setPath($requestUri); // URI query if (isset($this->serverParams['QUERY_STRING'])) { $uri->setQuery($this->serverParams['QUERY_STRING']); } $this->setUri($uri); return $this; }
public function save(ParametersInterface $data) { $em = $this->getEntityManager(); $attribute = $data->get('attribute'); $primaryKey = $data->get('primaryKey'); $content = $data->get('content') ? $data->get('content') : null; $constraints = $data->get('constraints', null); $repository = $this->getGalleryRepository(); $skipAssign = false; if ($constraints) { $constraints = json_decode(str_replace('\\', '\\\\', $constraints), true); } if ($primaryKey) { /** * @var \Image\Entity\Gallery $entity */ $entity = $repository->find($primaryKey); if ($entity) { /** * @var \Zend\InputFilter\InputFilterInterface $filter */ $filter = $this->getServiceManager()->get('galleryFilter')->filter($attribute, $content); if ($filter->isValid()) { if (!empty($constraints) && $content) { foreach ($constraints as $constraint) { if ($constraint["type"] == "foreign") { $content = $em->getReference($constraint["target"], $content); } } } if ($attribute == "images") { $joins = json_decode($content, true); // after we remove the images, we flash the entity $entity->clearImages(); $em->persist($entity); $em->flush(); $skipAssign = true; foreach ($joins as $join) { $image = $this->getImageRepository()->find($join["joinId"]); $galleryImage = $this->getRepository('image', 'galleryImage')->findOneBy(array("image" => $image, "gallery" => $entity)); if ($galleryImage) { $galleryImage->setTitle($join['title']); $galleryImage->setPosition($join['position']); } else { $galleryImage = new GalleryImage($join['title'], $join['position']); $image->addGalleries($galleryImage); } $entity->addImages($galleryImage); } } if (!$skipAssign) { $entity->{'set' . ucfirst($attribute)}($content); } if ($attribute == "name") { $entity->setUrl($this->getGalleryUrl($entity)); } try { $em->persist($entity); $em->flush(); $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_GALLERY_SAVED"]); return true; } catch (\Exception $e) { $this->message = $this->getTranslator()->translate($this->getVocabulary()["ERROR_GALLERY_NOT_SAVED"]); } } else { $this->message = $filter->getMessages()[$attribute]; } } } return false; }
/** * Filter and format the standard parameters to be consumed by the Twitter API * @param ParametersInterface $parameters * @return array */ private function filterParameters(ParametersInterface $parameters) { return array('q' => $parameters->get('search'), 'count' => $this->numberOfTweets * $this->geotaggedTweetProbabilityMultiplier, 'max_id' => $parameters->get('lastId') - 1); }
public function dispatch(ParametersInterface $parameters, Request $request) { return new JsonModel(['fields' => $this->addressService->getFieldsForCountry($parameters->get('countryCode'))]); }