Example #1
0
 /**
  * @param string $message
  * @param array  $params
  *
  * @return string
  */
 private function translateFlashMessage($message, $params = array())
 {
     $resource = ucfirst(str_replace('_', ' ', $this->config->getResourceName()));
     $resourceLower = strtolower($resource);
     $baseParams = array('%resource%' => $resource, '%resource_lower%' => $resourceLower);
     return $this->translator->trans($message, array_merge($baseParams, $params), 'flashes');
 }
Example #2
0
 /**
  * Prepare a new log object.
  *
  * Grabs data from the request and elsewhere to construct a new log object
  * from controller data.
  *
  * @param string $action
  * @return LogInterface
  */
 private function prepareLog($action)
 {
     $request = $this->config->getRequest();
     $method = strtolower($request->getMethod());
     $attributes = $this->prepareAttributes($request->attributes);
     $query = $request->query->all();
     $post = $request->request->all();
     extract($attributes);
     // $route, $params, $id
     $log = new Log();
     $log->setUser($this->user)->setAction($action)->setResource($this->config->getResourceName())->setResourceId($id)->setRoute($route)->setAttributes($params)->setQuery($query ? $query : null)->setRequest($post ? $post : null);
     return $log;
 }
 /**
  * @param Request $request
  * @param array   $criteria
  * @return object
  * @throws NotFoundHttpException
  */
 public function findOr404(Request $request, array $criteria = array())
 {
     if ($request->get('slug')) {
         $default = array('slug' => $request->get('slug'));
     } elseif ($request->get('id')) {
         $default = array('id' => $request->get('id'));
     } else {
         $default = array();
     }
     $criteria = array_merge($default, $criteria);
     if (!($resource = $this->resourceResolver->getResource($this->getRepository(), 'findOneBy', array($this->config->getCriteria($criteria))))) {
         throw new NotFoundHttpException(sprintf('Requested %s does not exist with these criteria: %s.', $this->config->getResourceName(), json_encode($this->config->getCriteria($criteria))));
     }
     return $resource;
 }