1 | <?php |
||
10 | class XMLRepository implements SourceInterface |
||
11 | { |
||
12 | private $config; |
||
13 | |||
14 | public function setConfig(Config $config) |
||
15 | { |
||
16 | $this->config = $config; |
||
17 | } |
||
18 | |||
19 | 3 | public function chapters() |
|
36 | |||
37 | 3 | public function chapter($chapter) |
|
48 | |||
49 | 42 | public function ayah($surah, $ayah, $translation = 'ar') |
|
79 | |||
80 | public function initialize() |
||
81 | { |
||
82 | // If original quran not exist in storage_path, copy one |
||
83 | $quran_source = realpath(__DIR__ . '/../../../data/ar.quran.xml'); |
||
84 | $quran_dest = $this->config->get('storage_path') . '/ar.quran.xml'; |
||
85 | |||
86 | $meta_source = realpath(__DIR__ . '/../../../data/quran-data.xml'); |
||
87 | $meta_dest = $this->config->get('storage_path') . '/quran-data.xml'; |
||
88 | |||
89 | // If storage path didn't exist, create it |
||
90 | if (!file_exists($this->config->get('storage_path'))) { |
||
91 | mkdir($this->config->get('storage_path')); |
||
92 | } |
||
93 | |||
94 | // Copy quran |
||
95 | if (!file_exists($quran_dest)) { |
||
96 | copy($quran_source, $quran_dest); |
||
97 | } |
||
98 | |||
99 | // Copy metadata |
||
100 | if (!file_exists($meta_dest)) { |
||
101 | copy($meta_source, $meta_dest); |
||
102 | } |
||
103 | |||
104 | // Sync translation files to storage path |
||
105 | $dw = new Downloader($this->config); |
||
106 | $dw->sync(); |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * Get the first match xml from translation. |
||
111 | * |
||
112 | * @param string $translation Translation prefix or short form |
||
113 | * |
||
114 | * @return string|false String of path to the translation if exists, or false otherwise |
||
115 | */ |
||
116 | 39 | private function firstMatchAvailableTranslation($translation) |
|
134 | |||
135 | } |