22/*
33 * This file is a part of the CKFinder bundle for Symfony.
44 *
5- * Copyright (C) 2016 , CKSource - Frederico Knabben . All rights reserved.
5+ * Copyright (c) 2022 , CKSource Holding sp. z o.o . All rights reserved.
66 *
77 * Licensed under the terms of the MIT license.
88 * For the full copyright and license information, please view the LICENSE.txt
1212namespace CKSource \Bundle \CKFinderBundle \Controller ;
1313
1414use CKSource \Bundle \CKFinderBundle \Form \Type \CKFinderFileChooserType ;
15+ use CKSource \CKFinder \CKFinder ;
1516use Symfony \Bundle \FrameworkBundle \Controller \AbstractController ;
16- use Symfony \Component \DependencyInjection \ContainerAwareInterface ;
17- use Symfony \Component \DependencyInjection \ContainerInterface ;
1817use Symfony \Component \Form \Extension \Core \Type \DateType ;
19- use Symfony \Component \Form \Extension \Core \Type \FormType ;
2018use Symfony \Component \Form \Extension \Core \Type \TextType ;
2119use Symfony \Component \HttpFoundation \Request ;
2220use Symfony \Component \HttpFoundation \Response ;
2321
2422/**
2523 * Controller for handling requests to CKFinder connector.
2624 */
27- class CKFinderController implements ContainerAwareInterface
25+ class CKFinderController extends AbstractController
2826{
29- /**
30- * @var ContainerInterface
31- */
32- protected $ container ;
33-
34- /**
35- * {@inheritDoc}
36- */
37- public function setContainer (ContainerInterface $ container = null )
38- {
39- $ this ->container = $ container ;
40- }
41-
4227 /**
4328 * Action that handles all CKFinder requests.
44- *
45- * @param Request $request
46- *
47- * @return \Symfony\Component\HttpFoundation\Response
4829 */
49- public function requestAction (Request $ request )
30+ public function requestAction (Request $ request ): Response
5031 {
51- /* @var \CKSource\CKFinder\CKFinder $ckfinder */
52- $ ckfinder = $ this ->container ->get ('ckfinder.connector ' );
53-
54- return $ ckfinder ->handle ($ request );
32+ return $ this ->container ->get ('ckfinder.connector ' )->handle ($ request );
5533 }
5634
5735 /**
5836 * Action for CKFinder usage examples.
5937 *
60- * To browse examples, please uncomment ckfinder_examplesroute in
61- * Resources/config/routing.yml and navigate to the /ckfinder/examples path.
62- *
63- * @param string|null $example
64- *
65- * @return \Symfony\Component\HttpFoundation\Response
38+ * To browse examples, please uncomment ckfinder_examples route in
39+ * Resources/config/routing.yaml and navigate to the /ckfinder/examples path.
6640 */
67- public function examplesAction ($ example = null )
41+ public function examplesAction (? string $ example = null ): Response
6842 {
6943 switch ($ example ) {
7044 case 'fullpage ' :
@@ -80,47 +54,37 @@ public function examplesAction($example = null)
8054 case 'ckeditor5 ' :
8155 return $ this ->render ('@CKSourceCKFinder/examples/ckeditor5.html.twig ' );
8256 case 'filechooser ' :
83- $ formBuilder = $ this ->container ->get ('form.factory ' )->createBuilder (FormType::class );
57+ $ formBuilder = $ this ->container ->get ('form.factory ' )->createBuilder ();
8458 $ form = $ formBuilder
8559 ->add ('foo ' , TextType::class)
8660 ->add ('bar ' , DateType::class)
87- ->add ('ckf1 ' , CKFinderFileChooserType::class, array (
61+ ->add ('ckf1 ' , CKFinderFileChooserType::class, [
8862 'label ' => 'File Chooser 1 ' ,
8963 'button_text ' => 'Browse files (popup) ' ,
90- 'button_attr ' => array (
64+ 'button_attr ' => [
9165 'class ' => 'my-class '
92- )
93- ) )
94- ->add ('ckf2 ' , CKFinderFileChooserType::class, array (
66+ ]
67+ ] )
68+ ->add ('ckf2 ' , CKFinderFileChooserType::class, [
9569 'label ' => 'File Chooser 2 ' ,
9670 'mode ' => 'modal ' ,
9771 'button_text ' => 'Browse files (modal) ' ,
98- ) )
72+ ] )
9973 ->getForm ();
10074
101- return $ this ->render ('@CKSourceCKFinder/examples/filechooser.html.twig ' , array (
75+ return $ this ->render ('@CKSourceCKFinder/examples/filechooser.html.twig ' , [
10276 'form ' => $ form ->createView ()
103- ) );
77+ ] );
10478 }
10579
10680 return $ this ->render ('@CKSourceCKFinder/examples/index.html.twig ' );
10781 }
10882
109- /**
110- * @param $viewName
111- * @param array $parameters
112- * @return Response
113- */
114- protected function render ($ viewName , $ parameters = [])
83+ public static function getSubscribedServices (): array
11584 {
116- if (!$ this ->container ->has ('twig ' )) {
117- throw new \LogicException ('Twig Bundle is not available. Try running "composer require symfony/twig-bundle". ' );
118- }
119-
120- $ twig = $ this ->container ->get ('twig ' );
121-
122- $ content = $ twig ->render ($ viewName , $ parameters );
123-
124- return new Response ($ content );
85+ return [
86+ 'ckfinder.connector ' => 'CKSource\CKFinder\CKFinder ' ,
87+ ...parent ::getSubscribedServices ()
88+ ];
12589 }
12690}
0 commit comments