public function saving($model) { if (is_null($model->slug)) { $model->slug = $model->name; } $model->slug = Slugger::slugify($model->slug); }
public function testSlugifyOptionsOverrideSluggerOptions() { $slugger = new \EasySlugger\Slugger('+'); $input = ' a+A+ - a+A_a _'; $output = $slugger->slugify($input, '_'); $this->assertSame('a_a_a_a_a', $output); }
public function index() { $models = config('anavel-crud.models'); if (empty($models)) { throw new \Exception("No models configured."); } $modelSlug = Slugger::slugify(key($models)); return new RedirectResponse(route('anavel-crud.model.index', $modelSlug)); }
public function downloadAction() { $id = $this->request->query->get('id'); /** @var Test $entity */ $entity = $this->em->getRepository('AppBundle:Test')->find($id); $filename = sprintf("%s-%s-%s.%s", Slugger::slugify($entity->getSubject()->getName()), Slugger::slugify($entity->getSeason()), Slugger::slugify($entity->getYear()), pathinfo($entity->getFilename(), PATHINFO_EXTENSION)); $fileToDownload = $this->get('vich_uploader.storage')->resolvePath($entity, 'file'); $response = new BinaryFileResponse($fileToDownload); $response->trustXSendfileTypeHeader(); $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $filename, iconv('UTF-8', 'ASCII//TRANSLIT', $filename)); return $response; }
public function index(ModelAbstractorFactory $modelFactory) { $models = config('anavel-crud.models'); if (empty($models)) { throw new \Exception('No models configured.'); } foreach ($models as $modelName => $model) { $modelSlug = Slugger::slugify($modelName); $modelAbstractor = $modelFactory->getByName($modelSlug); $config = $modelAbstractor->getConfig(); if (!array_key_exists('authorize', $config) || ($config['authorize'] === true && Gate::allows('adminIndex', $modelAbstractor->getInstance()) || $config['authorize'] === false)) { return new RedirectResponse(route('anavel-crud.model.index', $modelSlug)); } } abort(403); }
/** * @ApiDoc( * resource=true, * description="Download a file test", * https=true, * requirements={ * {"name": "id", "dataType"="integer", "requirement"="\d+", "description"="Test id"}, * } * ) * @Route("/tests/{id}/download") * @ParamConverter("test", class="AppBundle:Test", options={"mapping": {"id": "id"}}) * @QueryParam(name="show", requirements="[01]", default="0", description="0: The file is downloaded, 1: The file is opened on the browser.") */ public function getTestDownloadAction(Test $test, ParamFetcher $paramFetcher) { $filename = sprintf("%s-%s-%s.%s", Slugger::slugify($test->getSubject()->getName()), Slugger::slugify($test->getSeason()), Slugger::slugify($test->getYear()), pathinfo($test->getFilename(), PATHINFO_EXTENSION)); $responseType = ResponseHeaderBag::DISPOSITION_ATTACHMENT; if ($page = $paramFetcher->get('show') === "1") { $responseType = ResponseHeaderBag::DISPOSITION_INLINE; } $fileToDownload = $this->get('vich_uploader.storage')->resolvePath($test, 'file'); $response = new BinaryFileResponse($fileToDownload); $response->trustXSendfileTypeHeader(); $response->setContentDisposition($responseType, $filename, iconv('UTF-8', 'ASCII//TRANSLIT', $filename)); $em = $this->getDoctrine()->getManager(); $test->incrementDownloads(); $em->persist($test); $em->flush(); return $response; }
/** * Generate slug * * @param string $text * @return string */ function slugify($text) { return Slugger::slugify($text); }