11<?php
2+
23/**
34 * ElpParser.php
45 *
@@ -33,70 +34,70 @@ class ELPParser implements \JsonSerializable
3334{
3435 /**
3536 * Path to the .elp file
36- *
37+ *
3738 * @var string
3839 */
3940 protected string $ filePath ;
4041
4142 /**
4243 * ELP file version (2 or 3)
43- *
44+ *
4445 * @var int
4546 */
4647 protected int $ version ;
4748
4849 /**
4950 * Extracted content and metadata
50- *
51+ *
5152 * @var array
5253 */
5354 protected array $ content = [];
5455
5556 /**
5657 * Raw extracted strings
57- *
58+ *
5859 * @var array
5960 */
6061 protected array $ strings = [];
6162
6263 /**
6364 * Title of the ELP content
64- *
65+ *
6566 * @var string
6667 */
6768 protected string $ title = '' ;
6869
6970 /**
7071 * Description of the ELP content
71- *
72+ *
7273 * @var string
7374 */
7475 protected string $ description = '' ;
7576
7677 /**
7778 * Author of the ELP content
78- *
79+ *
7980 * @var string
8081 */
8182 protected string $ author = '' ;
8283
8384 /**
8485 * License of the ELP content
85- *
86+ *
8687 * @var string
8788 */
8889 protected string $ license = '' ;
8990
9091 /**
9192 * Language of the ELP content
92- *
93+ *
9394 * @var string
9495 */
9596 protected string $ language = '' ;
9697
9798 /**
9899 * Learning resource type
99- *
100+ *
100101 * @var string
101102 */
102103 protected string $ learningResourceType = '' ;
@@ -105,7 +106,7 @@ class ELPParser implements \JsonSerializable
105106 * Create a new ELPParser instance
106107 *
107108 * @param string $filePath Path to the .elp file
108- *
109+ *
109110 * @throws Exception If file cannot be opened or is invalid
110111 * @return void
111112 */
@@ -119,7 +120,7 @@ public function __construct(string $filePath)
119120 * Static method to create an ELPParser from a file path
120121 *
121122 * @param string $filePath Path to the .elp file
122- *
123+ *
123124 * @throws Exception If file cannot be opened or is invalid
124125 * @return self
125126 */
@@ -137,7 +138,7 @@ public static function fromFile(string $filePath): self
137138 protected function parse (): void
138139 {
139140 $ zip = new ZipArchive ();
140-
141+
141142 if (!file_exists ($ this ->filePath )) {
142143 throw new Exception ('File does not exist. ' );
143144 }
@@ -181,7 +182,7 @@ protected function parse(): void
181182 * Parse the XML content and extract relevant information
182183 *
183184 * @param string $xmlContent XML content as a string
184- *
185+ *
185186 * @throws Exception If XML parsing fails
186187 * @return void
187188 */
@@ -210,7 +211,7 @@ protected function parseXML(string $xmlContent): void
210211 * Extract strings from the XML document
211212 *
212213 * @param SimpleXMLElement $xml XML document
213- *
214+ *
214215 * @return void
215216 */
216217 protected function extractStrings (SimpleXMLElement $ xml ): void
@@ -223,7 +224,7 @@ protected function extractStrings(SimpleXMLElement $xml): void
223224 * Recursively extract all text strings from XML
224225 *
225226 * @param SimpleXMLElement $element XML element to extract from
226- *
227+ *
227228 * @return array Extracted strings
228229 */
229230 protected function recursiveStringExtraction (SimpleXMLElement $ element ): array
@@ -279,7 +280,7 @@ public function getStrings(): array
279280 * Extract metadata from version 3 XML format
280281 *
281282 * @param SimpleXMLElement $xml XML document
282- *
283+ *
283284 * @return void
284285 */
285286 protected function extractVersion3Metadata (SimpleXMLElement $ xml ): void
@@ -290,24 +291,24 @@ protected function extractVersion3Metadata(SimpleXMLElement $xml): void
290291 $ value = (string )$ property ->value ;
291292
292293 switch ($ key ) {
293- case 'pp_title ' :
294- $ this ->title = $ value ;
295- break ;
296- case 'pp_description ' :
297- $ this ->description = $ value ;
298- break ;
299- case 'pp_author ' :
300- $ this ->author = $ value ;
301- break ;
302- case 'license ' :
303- $ this ->license = $ value ;
304- break ;
305- case 'lom_general_language ' :
306- $ this ->language = $ value ;
307- break ;
308- case 'pp_learningResourceType ' :
309- $ this ->learningResourceType = $ value ;
310- break ;
294+ case 'pp_title ' :
295+ $ this ->title = $ value ;
296+ break ;
297+ case 'pp_description ' :
298+ $ this ->description = $ value ;
299+ break ;
300+ case 'pp_author ' :
301+ $ this ->author = $ value ;
302+ break ;
303+ case 'license ' :
304+ $ this ->license = $ value ;
305+ break ;
306+ case 'lom_general_language ' :
307+ $ this ->language = $ value ;
308+ break ;
309+ case 'pp_learningResourceType ' :
310+ $ this ->learningResourceType = $ value ;
311+ break ;
311312 }
312313 }
313314 }
@@ -377,7 +378,7 @@ public function getLearningResourceType(): string
377378 * Extract metadata from version 2 XML format
378379 *
379380 * @param SimpleXMLElement $xml XML document
380- *
381+ *
381382 * @return void
382383 */
383384 protected function extractVersion2Metadata (SimpleXMLElement $ xml ): void
@@ -402,35 +403,35 @@ protected function extractVersion2Metadata(SimpleXMLElement $xml): void
402403 } elseif ($ currentKey !== null ) {
403404 // Extract the value based on the type of element
404405 switch ($ elementName ) {
405- case 'unicode ' :
406- $ metadata [$ currentKey ] = (string )$ element ['value ' ];
407- break ;
408- case 'bool ' :
409- $ metadata [$ currentKey ] = ((string )$ element ['value ' ]) === '1 ' ;
410- break ;
411- case 'int ' :
412- $ metadata [$ currentKey ] = (int )$ element ['value ' ];
413- break ;
414- case 'list ' :
415- // Handle lists if necessary
416- $ listValues = [];
417- foreach ($ element ->children () as $ listItem ) {
418- if ($ listItem ->getName () === 'unicode ' ) {
419- $ listValues [] = (string )$ listItem ['value ' ];
406+ case 'unicode ' :
407+ $ metadata [$ currentKey ] = (string )$ element ['value ' ];
408+ break ;
409+ case 'bool ' :
410+ $ metadata [$ currentKey ] = ((string )$ element ['value ' ]) === '1 ' ;
411+ break ;
412+ case 'int ' :
413+ $ metadata [$ currentKey ] = (int )$ element ['value ' ];
414+ break ;
415+ case 'list ' :
416+ // Handle lists if necessary
417+ $ listValues = [];
418+ foreach ($ element ->children () as $ listItem ) {
419+ if ($ listItem ->getName () === 'unicode ' ) {
420+ $ listValues [] = (string )$ listItem ['value ' ];
421+ }
422+ // Add handling for other types of elements within the list if necessary
420423 }
421- // Add handling for other types of elements within the list if necessary
422- }
423- $ metadata [$ currentKey ] = $ listValues ;
424- break ;
425- case 'dictionary ' :
426- // Handle nested dictionaries if necessary
427- // This may require a recursive function
428- // For simplicity, it can be omitted or implemented as needed
429- break ;
424+ $ metadata [$ currentKey ] = $ listValues ;
425+ break ;
426+ case 'dictionary ' :
427+ // Handle nested dictionaries if necessary
428+ // This may require a recursive function
429+ // For simplicity, it can be omitted or implemented as needed
430+ break ;
430431 // Add other cases as needed
431- default :
432- // Handle unknown types or ignore them
433- break ;
432+ default :
433+ // Handle unknown types or ignore them
434+ break ;
434435 }
435436
436437 // Reset the current key after assigning the value
@@ -445,7 +446,6 @@ protected function extractVersion2Metadata(SimpleXMLElement $xml): void
445446 $ this ->license = $ metadata ['license ' ] ?? '' ;
446447 $ this ->language = $ metadata ['_lang ' ] ?? '' ;
447448 $ this ->learningResourceType = $ metadata ['_learningResourceType ' ] ?? '' ;
448-
449449 }
450450
451451
@@ -542,7 +542,7 @@ public function getMetadata(): array
542542 $ meta = [
543543 [
544544 'schema ' => 'Package ' ,
545- 'content ' => [
545+ 'content ' => [
546546 'title ' => $ data ['_title ' ] ?? '' ,
547547 'lang ' => $ data ['_lang ' ] ?? '' ,
548548 'description ' => [
@@ -618,40 +618,40 @@ protected function parseElement(SimpleXMLElement $element): mixed
618618 $ name = $ element ->getName ();
619619
620620 switch ($ name ) {
621- case 'unicode ' :
622- case 'string ' :
623- return (string ) $ element ['value ' ];
624- case 'int ' :
625- return (int ) $ element ['value ' ];
626- case 'bool ' :
627- return ((string ) $ element ['value ' ]) === '1 ' ;
628- case 'list ' :
629- $ list = [];
630- foreach ($ element ->children () as $ child ) {
631- $ list [] = $ this ->parseElement ($ child );
632- }
633- return $ list ;
634- case 'dictionary ' :
635- $ dict = [];
636- $ key = null ;
637- foreach ($ element ->children () as $ child ) {
638- $ cname = $ child ->getName ();
639- if (($ cname === 'string ' || $ cname === 'unicode ' ) && (string ) $ child ['role ' ] === 'key ' ) {
640- $ key = (string ) $ child ['value ' ];
641- } elseif ($ key !== null ) {
642- $ dict [$ key ] = $ this ->parseElement ($ child );
643- $ key = null ;
621+ case 'unicode ' :
622+ case 'string ' :
623+ return (string ) $ element ['value ' ];
624+ case 'int ' :
625+ return (int ) $ element ['value ' ];
626+ case 'bool ' :
627+ return ((string ) $ element ['value ' ]) === '1 ' ;
628+ case 'list ' :
629+ $ list = [];
630+ foreach ($ element ->children () as $ child ) {
631+ $ list [] = $ this ->parseElement ($ child );
644632 }
645- }
646- return $ dict ;
647- case 'instance ' :
648- return $ this ->parseElement ($ element ->dictionary );
649- case 'none ' :
650- return null ;
651- case 'reference ' :
652- return ['ref ' => (string ) $ element ['key ' ]];
653- default :
654- return null ;
633+ return $ list ;
634+ case 'dictionary ' :
635+ $ dict = [];
636+ $ key = null ;
637+ foreach ($ element ->children () as $ child ) {
638+ $ cname = $ child ->getName ();
639+ if (($ cname === 'string ' || $ cname === 'unicode ' ) && (string ) $ child ['role ' ] === 'key ' ) {
640+ $ key = (string ) $ child ['value ' ];
641+ } elseif ($ key !== null ) {
642+ $ dict [$ key ] = $ this ->parseElement ($ child );
643+ $ key = null ;
644+ }
645+ }
646+ return $ dict ;
647+ case 'instance ' :
648+ return $ this ->parseElement ($ element ->dictionary );
649+ case 'none ' :
650+ return null ;
651+ case 'reference ' :
652+ return ['ref ' => (string ) $ element ['key ' ]];
653+ default :
654+ return null ;
655655 }
656656 }
657657
@@ -726,14 +726,14 @@ protected function slug(string $text): string
726726 * Extract contents of an ELP file to a specified directory
727727 *
728728 * @param string $destinationPath Directory to extract contents to
729- *
729+ *
730730 * @throws Exception If extraction fails
731731 * @return void
732732 */
733733 public function extract (string $ destinationPath ): void
734734 {
735735 $ zip = new ZipArchive ();
736-
736+
737737 if ($ zip ->open ($ this ->filePath ) !== true ) {
738738 throw new Exception ("Unable to open ELP file for extraction " );
739739 }
@@ -826,8 +826,9 @@ function removeAccents(string $text, string $locale = ''): string
826826 'Ố ' => 'O ' , 'ố ' => 'o ' , 'Ớ ' => 'O ' , 'ớ ' => 'o ' , 'Ứ ' => 'U ' , 'ứ ' => 'u ' ,
827827 ];
828828
829- if ('de_DE ' === $ locale || 'de_DE_formal ' === $ locale
830- || 'de_CH ' === $ locale || 'de_CH_informal ' === $ locale
829+ if (
830+ 'de_DE ' === $ locale || 'de_DE_formal ' === $ locale
831+ || 'de_CH ' === $ locale || 'de_CH_informal ' === $ locale
831832 || 'de_AT ' === $ locale
832833 ) {
833834 $ chars ['Ä ' ] = 'Ae ' ;
0 commit comments