1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
<?php /** * Provides iteration over all installed files for a given language and matches them to bundles */ class Loco_package_Locale {
/** * @var array */ private $match;
/** * @var array */ private $bundles;
/** * Maps file paths to projects in which they were found * @var ArrayObject */ private $index;
/** * Construct with locale to filter on */ public function __construct( ?Loco_locale $locale = null ){ $this->index = new ArrayObject; $this->match = []; if( $locale ){ $this->addLocale( $locale ); } }
/** * Add another locale to search on */ public function addLocale( Loco_Locale $locale ):self { if( $locale->isValid() ){ $sufx = $locale.'.po'; $this->match[$sufx] = - strlen($sufx); } return $this; }
/** * @return Loco_package_Project|null */ public function getProject( Loco_fs_File $file ){ $path = $file->getPath(); if( isset($this->index[$path]) ){ return $this->index[$path]; } return null; }
/** * @return Loco_package_Bundle[] */ public function getBundles(){ $bundles = $this->bundles; if( ! $bundles ){ $bundles = [ Loco_package_Core::create() ]; $bundles = array_merge( $bundles, Loco_package_Plugin::getAll() ); $bundles = array_merge( $bundles, Loco_package_Theme::getAll() ); $this->bundles = $bundles; } return $bundles; }
/** * @return loco_fs_FileList */ public function findLocaleFiles(){ $index = $this->index; $suffixes = $this->match; $list = new Loco_fs_FileList; foreach( $this->getBundles() as $bundle ){ /* @var Loco_package_Project $project */ foreach( $bundle as $project ){ /* @var $file Loco_fs_File */ foreach( $project->findLocaleFiles('po') as $file ){ $path = $file->getPath(); foreach( $suffixes as $sufx => $snip ){ if( substr($path,$snip) === $sufx ){ $list->add( $file ); $index[$path] = $project; break; } } } } } return $list; }
/** * @return loco_fs_FileList */ public function findTemplateFiles(){ $index = $this->index; $list = new Loco_fs_FileList; foreach( $this->getBundles() as $bundle ){ /* @var $project Loco_package_Project */ foreach( $bundle as $project ){ $file = $project->getPot(); if( $file && $file->exists() ){ $list->add( $file ); $path = $file->getPath(); $index[$path] = $project; } } } return $list; }
}
|