Beispiel #1
0
 public function handle(Request $request, Parameters $configuration, Context $context)
 {
     $condition = $configuration->get('condition');
     $language = new ExpressionLanguage($this);
     $values = array('rateLimit' => new RateLimit($this->connection, $context), 'app' => $context->getApp(), 'routeId' => $context->getRouteId(), 'uriFragments' => $request->getUriFragments(), 'parameters' => $request->getParameters(), 'body' => new Accessor(new Validate(), $request->getBody()));
     if (!empty($condition) && $language->evaluate($condition, $values)) {
         return $this->processor->execute($configuration->get('true'), $request, $context);
     } else {
         return $this->processor->execute($configuration->get('false'), $request, $context);
     }
 }
Beispiel #2
0
 public function handle(Request $request, Parameters $configuration, Context $context)
 {
     $connection = $this->connector->getConnection($configuration->get('connection'));
     if ($connection instanceof Connection) {
         // parse sql
         $sql = $this->templateParser->parse($request, $configuration, $context->withConnection($connection), $configuration->get('sql'));
         $connection->executeUpdate($sql, $this->templateParser->getSqlParameters());
         return new Response(200, [], array('success' => true, 'message' => 'Execution was successful'));
     } else {
         throw new ConfigurationException('Given connection must be an DBAL connection');
     }
 }
Beispiel #3
0
 public function handle(Request $request, Parameters $configuration, Context $context)
 {
     $connection = $this->connector->getConnection($configuration->get('connection'));
     if ($connection instanceof Connection) {
         // parse sql
         $sql = $this->templateParser->parse($request, $configuration, $context->withConnection($connection), $configuration->get('sql'));
         $result = $connection->fetchAll($sql, $this->templateParser->getSqlParameters());
         $key = $configuration->get('propertyName') ?: 'entry';
         return new Response(200, [], [$key => CurveArray::nest($result)]);
     } else {
         throw new ConfigurationException('Given connection must be a DBAL connection');
     }
 }
Beispiel #4
0
 public function handle(Request $request, Parameters $configuration, Context $context)
 {
     $connection = $this->connector->getConnection($configuration->get('connection'));
     if ($connection instanceof Connection) {
         // parse sql
         $sql = $this->templateParser->parse($request, $configuration, $context->withConnection($connection), $configuration->get('sql'));
         $result = $connection->fetchAssoc($sql, $this->templateParser->getSqlParameters());
         if (empty($result)) {
             throw new StatusCode\NotFoundException('Entry not available');
         }
         return new Response(200, [], CurveArray::nest($result));
     } else {
         throw new ConfigurationException('Given connection must be an DBAL connection');
     }
 }
Beispiel #5
0
 public function parse(Request $request, Parameters $configuration, Context $context, $data)
 {
     $cacheKey = $configuration->get(Parameters::ACTION_ID);
     $lastModified = $configuration->get(Parameters::ACTION_LAST_MODIFIED);
     $this->loader->set($data, $cacheKey, $lastModified);
     $this->twig->getFilter(Prepare::FILTER_NAME)->getCallable()->clear();
     $this->twig->getFilter(RowExists::FILTER_NAME)->getCallable()->setConnection($context->getConnection());
     try {
         return $this->twig->render($configuration->get(Parameters::ACTION_ID), ['request' => $request, 'context' => $context, 'body' => new Accessor(new Validate(), $request->getBody())]);
     } catch (\Twig_Error_Runtime $e) {
         // if we have an display exception throw the original exception
         if ($e->getPrevious() instanceof DisplayException) {
             throw $e->getPrevious();
         } else {
             throw $e;
         }
     }
 }