Browse Source

content folder variable de bundle

Frederic 3 years ago
parent
commit
d0b3e96c70

+ 2
- 1
.gitignore View File

@@ -1,3 +1,4 @@
1 1
 /vendor/
2 2
 composer.lock
3
-/symfony.lock
3
+/symfony.lock
4
+/Tests/content/

+ 2
- 1
Controller/ExampleController.php View File

@@ -8,6 +8,7 @@ class ExampleController extends AbstractController
8 8
 {
9 9
     public function view()
10 10
     {
11
-        return $this->render('@LogiproExample/Example/example.html.twig');
11
+        //return $this->render('@LogiproExample/Example/example.html.twig');
12
+        return Response('coucou');
12 13
     }
13 14
 }

+ 5
- 0
DependencyInjection/Configuration.php View File

@@ -18,6 +18,11 @@ class Configuration implements ConfigurationInterface
18 18
                     ->cannotBeEmpty()
19 19
                     ->defaultValue('public/uploads/packages')
20 20
                 ->end()
21
+                ->scalarNode('content_folder')
22
+                    ->isRequired()
23
+                    ->cannotBeEmpty()
24
+                    ->defaultValue('public/content')
25
+                ->end()
21 26
             ->end()
22 27
         ;
23 28
 

+ 2
- 0
DependencyInjection/LogiproSCORMExtension.php View File

@@ -18,8 +18,10 @@ class LogiproSCORMExtension extends Extension
18 18
         $config = $this->processConfiguration($configuration, $configs);
19 19
 
20 20
         $container->setParameter('logipro_scorm.package_folder', $config['package_folder']);
21
+        $container->setParameter('logipro_scorm.content_folder', $config['content_folder']);
21 22
 
22 23
         $definition = $container->getDefinition('Logipro\Bundle\SCORMBundle\Services\ScormEngine');
23 24
         $definition->replaceArgument(0, $config['package_folder']);
25
+        $definition->replaceArgument(1, $config['content_folder']);
24 26
     }
25 27
 }

+ 7
- 20
Entity/ZipFile.php View File

@@ -85,7 +85,7 @@ class ZipFile extends AbstractEntity
85 85
     protected $mapCourseZipfiles;
86 86
 
87 87
     //Getters and setters
88
-    
88
+   
89 89
 
90 90
     /**
91 91
      * Get the value of $zipFileId
@@ -316,7 +316,6 @@ class ZipFile extends AbstractEntity
316 316
             $this->zipFileprint = md5_file($filePath);
317 317
             $this->uploadDate = $uploadDate;
318 318
             $this->endUploadDate = $endUploadDate;
319
-            $this->filePath = $filePath;
320 319
 
321 320
             return true;
322 321
         } else {
@@ -364,7 +363,6 @@ class ZipFile extends AbstractEntity
364 363
             $this->zipFileprint = $hash;
365 364
             $this->uploadDate = $uploadDate;
366 365
             $this->endUploadDate = $endUploadDate;
367
-            $this->filePath = $filePath;
368 366
 
369 367
             $response['upload'] = true;
370 368
         }
@@ -375,20 +373,19 @@ class ZipFile extends AbstractEntity
375 373
     /**
376 374
      * Extraire le fichier zip vers le répertoire $directory
377 375
      *
378
-     * @param string $directory
379
-     *
380 376
      * @return void
381 377
      */
382
-    public function extractZipFile($directory)
378
+    public function extractZipFile(string $packageFolder, string $contentFolder)
383 379
     {
380
+        $zipfilePath = $packageFolder.'/'.$this->zipFileName;
384 381
         $zip = new \ZipArchive();
385
-        $openResult = $zip->open($this->filePath);
382
+        $openResult = $zip->open($zipfilePath);
386 383
         if ($openResult == false) {
387
-            throw new PackageException(sprintf("Impossible d'ouvrir %s", $this->filePath));
384
+            throw new PackageException(sprintf("Impossible d'ouvrir %s", $zipfilePath));
388 385
         }
389
-        $extractResult = $zip->extractTo($directory);
386
+        $extractResult = $zip->extractTo($contentFolder);
390 387
         if ($extractResult == false) {
391
-            throw new PackageException(sprintf("Impossible d'extraire %s", $directory));
388
+            throw new PackageException(sprintf("Impossible d'extraire %s", $contentFolder));
392 389
         }
393 390
         $zip->close();
394 391
     }
@@ -407,14 +404,4 @@ class ZipFile extends AbstractEntity
407 404
         }
408 405
         return $dom;
409 406
     }
410
-
411
-    public function explodeZip()
412
-    {
413
-        $pathZips = $this->filePath; // TODO: devrait etre stocké dans une variable de config, pas dans chaque entité
414
-        $pathContent = __DIR__.'/../content'; // TODO: devrait etre variable de config
415
-
416
-        if (files_exist($pathContent) == false) {
417
-            touch($pathContent);
418
-        }
419
-    }
420 407
 }

+ 10
- 0
LogiproSCORMBundle.php View File

@@ -3,7 +3,17 @@
3 3
 namespace Logipro\Bundle\SCORMBundle;
4 4
 
5 5
 use Symfony\Component\HttpKernel\Bundle\Bundle;
6
+use Symfony\Component\DependencyInjection\ContainerBuilder;
6 7
 
7 8
 class LogiproSCORMBundle extends Bundle
8 9
 {
10
+    public function boot()
11
+    {
12
+        $param = $this->container->getParameter('logipro_scorm.package_folder');
13
+    }
14
+
15
+    public function build(ContainerBuilder $container)
16
+    {
17
+        parent::build($container);
18
+    }
9 19
 }

+ 30
- 0
README.md View File

@@ -38,6 +38,36 @@ php bin/console doctrine:database:create
38 38
 php bin/console doctrine:schema:update --force
39 39
 ```
40 40
 
41
+Security
42
+--------
43
+
44
+Package resources access has cookie authentification. It allows application access only to user 
45
+owning resources. For instance none would be able to access diurecly by url.
46
+(example : http://yourdomaine/content/SeqPostSCORM20044th/imsmanifest.xml will return a 403)
47
+
48
+You must configure the following things :
49
+
50
+*1*) in your .htaccess add rewriting url following rules
51
+
52
+```console
53
+RewriteCond  %{REQUEST_URI} /content/path
54
+RewriteCond %{HTTP_COOKIE} !SCORMBundle= [NC]
55
+RewriteRule .* /401.html [L]
56
+```
57
+
58
+where /content/path must be the part of uri corresponding to the content_folder var in logipro_scorm.yaml
59
+
60
+For instance if you have in logipro_scorm.yaml
61
+
62
+```console
63
+logipro_scorm:
64
+  package_folder: '%kernel.project_dir%/public/uploads/packages'
65
+  content_folder: '%kernel.project_dir%/public/content
66
+```
67
+then 
68
+```console
69
+RewriteCond  %{REQUEST_URI} /content/path
70
+```
41 71
 
42 72
 Resources
43 73
 ---------

+ 1
- 0
Resources/config/services.xml View File

@@ -6,6 +6,7 @@
6 6
     <services>
7 7
         <service id="Logipro\Bundle\SCORMBundle\Services\ScormEngine" class="Logipro\Bundle\SCORMBundle\Services\ScormEngine" public="true">
8 8
             <argument></argument> <!-- will be filled in with package_folder dynamically -->
9
+            <argument></argument> <!-- will be filled in with content_folder dynamically -->
9 10
         </service>
10 11
         <service id="scorm.services.engine" alias="Logipro\Bundle\SCORMBundle\Services\ScormEngine"/>
11 12
     </services>

+ 4
- 1
Services/ScormEngine.php View File

@@ -26,9 +26,12 @@ class ScormEngine implements ContainerAwareInterface
26 26
 
27 27
     protected $packageFolder;
28 28
 
29
-    public function __construct(string $packageFolder)
29
+    protected $contentFolder;
30
+
31
+    public function __construct(string $packageFolder, string $contentFolder)
30 32
     {
31 33
         $this->packageFolder = $packageFolder;
34
+        $this->contentFolder = $contentFolder;
32 35
     }
33 36
 
34 37
     // ACTIVITÉ

+ 14
- 2
Tests/Entity/ZipFileTest.php View File

@@ -5,11 +5,23 @@ namespace Logipro\Bundle\SCORMBundle\Tests\Entity;
5 5
 use PHPUnit\Framework\TestCase;
6 6
 use Logipro\Bundle\SCORMBundle\Entity\ZipFile;
7 7
 
8
+
9
+
8 10
 class ZipFileTest extends TestCase
9 11
 {
10
-    public function testExplodeZip()
12
+    protected $contentFolder;
13
+
14
+    public function testExtractZipFile()
11 15
     {
12
-        //$myZip = $this->createMock(ZipFile::class);
16
+        $myZip= new ZipFile();
13 17
 
18
+        $myZip->setZipFileName('SequencingPostTestRollup4thEd_SCORM20044thEdition.zip');
19
+        $contentFolder = __DIR__.'/../content/SeqPostSCORM20044th';
20
+        if (!file_exists($contentFolder)) {
21
+            mkdir($contentFolder, 0777, true);
22
+        }
23
+        $myZip->extractZipFile(__DIR__.'/../packages/SCORM2004', $contentFolder);
24
+        $verif = file_exists($contentFolder.'/imsmanifest.xml');
25
+        $this->assertSame(true, $verif);
14 26
     }
15 27
 }

Loading…
Cancel
Save