@@ -33,9 +33,9 @@ discard block |
||
33 | 33 | * @param array $sources Associative list of translation domains and lists of translation directories. |
34 | 34 | * @param string $locale ISO language name, like "en" or "en_US" |
35 | 35 | */ |
36 | - public function __construct( array $sources, $locale ) |
|
36 | + public function __construct(array $sources, $locale) |
|
37 | 37 | { |
38 | - parent::__construct( $locale ); |
|
38 | + parent::__construct($locale); |
|
39 | 39 | |
40 | 40 | $this->sources = $sources; |
41 | 41 | } |
@@ -49,15 +49,15 @@ discard block |
||
49 | 49 | * @return string The translated string |
50 | 50 | * @throws \Aimeos\MW\Translation\Exception Throws exception on initialization of the translation |
51 | 51 | */ |
52 | - public function dt( $domain, $singular ) |
|
52 | + public function dt($domain, $singular) |
|
53 | 53 | { |
54 | - foreach( $this->getTranslations( $domain ) as $object ) |
|
54 | + foreach ($this->getTranslations($domain) as $object) |
|
55 | 55 | { |
56 | - if( ( $result = $object->get( $singular ) ) !== false ) |
|
56 | + if (($result = $object->get($singular)) !== false) |
|
57 | 57 | { |
58 | - if( is_array( $result ) && isset( $result[0] ) ) { |
|
58 | + if (is_array($result) && isset($result[0])) { |
|
59 | 59 | return (string) $result[0]; |
60 | - } elseif( is_string( $result ) ) { |
|
60 | + } elseif (is_string($result)) { |
|
61 | 61 | return $result; |
62 | 62 | } |
63 | 63 | } |
@@ -77,18 +77,18 @@ discard block |
||
77 | 77 | * @return string Returns the translated singular or plural form of the string depending on the given number |
78 | 78 | * @throws \Aimeos\MW\Translation\Exception Throws exception on initialization of the translation |
79 | 79 | */ |
80 | - public function dn( $domain, $singular, $plural, $number ) |
|
80 | + public function dn($domain, $singular, $plural, $number) |
|
81 | 81 | { |
82 | - $idx = $this->getPluralIndex( (int) $number, $this->getLocale() ); |
|
82 | + $idx = $this->getPluralIndex((int) $number, $this->getLocale()); |
|
83 | 83 | |
84 | - foreach( $this->getTranslations( $domain ) as $object ) |
|
84 | + foreach ($this->getTranslations($domain) as $object) |
|
85 | 85 | { |
86 | - if( ( $list = $object->get( $singular ) ) !== false && isset( $list[$idx] ) ) { |
|
86 | + if (($list = $object->get($singular)) !== false && isset($list[$idx])) { |
|
87 | 87 | return (string) $list[$idx]; |
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
91 | - return ( $idx > 0 ? (string) $plural : $singular ); |
|
91 | + return ($idx > 0 ? (string) $plural : $singular); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | |
@@ -98,11 +98,11 @@ discard block |
||
98 | 98 | * @param string $domain Translation domain |
99 | 99 | * @return array Associative list with original string as key and associative list with index => translation as value |
100 | 100 | */ |
101 | - public function getAll( $domain ) |
|
101 | + public function getAll($domain) |
|
102 | 102 | { |
103 | 103 | $messages = []; |
104 | 104 | |
105 | - foreach( $this->getTranslations( $domain ) as $object ) { |
|
105 | + foreach ($this->getTranslations($domain) as $object) { |
|
106 | 106 | $messages = $messages + $object->all(); |
107 | 107 | } |
108 | 108 | |
@@ -117,25 +117,25 @@ discard block |
||
117 | 117 | * @return array List of translation objects implementing \Aimeos\MW\Translation\File\Mo |
118 | 118 | * @throws \Aimeos\MW\Translation\Exception If initialization fails |
119 | 119 | */ |
120 | - protected function getTranslations( $domain ) |
|
120 | + protected function getTranslations($domain) |
|
121 | 121 | { |
122 | - if( !isset( $this->files[$domain] ) ) |
|
122 | + if (!isset($this->files[$domain])) |
|
123 | 123 | { |
124 | - if ( !isset( $this->sources[$domain] ) ) |
|
124 | + if (!isset($this->sources[$domain])) |
|
125 | 125 | { |
126 | - $msg = sprintf( 'No translation directory for domain "%1$s" available', $domain ); |
|
127 | - throw new \Aimeos\MW\Translation\Exception( $msg ); |
|
126 | + $msg = sprintf('No translation directory for domain "%1$s" available', $domain); |
|
127 | + throw new \Aimeos\MW\Translation\Exception($msg); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | // Reverse locations so the former gets not overwritten by the later |
131 | - $locations = array_reverse( $this->getTranslationFileLocations( $this->sources[$domain], $this->getLocale() ) ); |
|
131 | + $locations = array_reverse($this->getTranslationFileLocations($this->sources[$domain], $this->getLocale())); |
|
132 | 132 | |
133 | - foreach( $locations as $location ) { |
|
134 | - $this->files[$domain][$location] = new \Aimeos\MW\Translation\File\Mo( $location ); |
|
133 | + foreach ($locations as $location) { |
|
134 | + $this->files[$domain][$location] = new \Aimeos\MW\Translation\File\Mo($location); |
|
135 | 135 | } |
136 | 136 | } |
137 | 137 | |
138 | - return ( isset( $this->files[$domain] ) ? $this->files[$domain] : [] ); |
|
138 | + return (isset($this->files[$domain]) ? $this->files[$domain] : []); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | } |
@@ -36,14 +36,14 @@ discard block |
||
36 | 36 | * |
37 | 37 | * @param string $filepath Absolute path to the Gettext .mo file |
38 | 38 | */ |
39 | - public function __construct( $filepath ) |
|
39 | + public function __construct($filepath) |
|
40 | 40 | { |
41 | - if( ( $str = file_get_contents( $filepath ) ) === false ) { |
|
42 | - throw new \Aimeos\MW\Translation\Exception( sprintf( 'Unable to read from file "%1$s"', $filepath ) ); |
|
41 | + if (($str = file_get_contents($filepath)) === false) { |
|
42 | + throw new \Aimeos\MW\Translation\Exception(sprintf('Unable to read from file "%1$s"', $filepath)); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | $this->str = $str; |
46 | - $this->strlen = strlen( $str ); |
|
46 | + $this->strlen = strlen($str); |
|
47 | 47 | $this->messages = $this->extract(); |
48 | 48 | } |
49 | 49 | |
@@ -65,11 +65,11 @@ discard block |
||
65 | 65 | * @param string $original Untranslated string |
66 | 66 | * @return array|boolean List of translations or false if none is available |
67 | 67 | */ |
68 | - public function get( $original ) |
|
68 | + public function get($original) |
|
69 | 69 | { |
70 | 70 | $original = (string) $original; |
71 | 71 | |
72 | - if( isset( $this->messages[$original] ) ) { |
|
72 | + if (isset($this->messages[$original])) { |
|
73 | 73 | return $this->messages[$original]; |
74 | 74 | } |
75 | 75 | |
@@ -85,27 +85,27 @@ discard block |
||
85 | 85 | */ |
86 | 86 | protected function extract() |
87 | 87 | { |
88 | - $magic = $this->readInt( 'V' ); |
|
88 | + $magic = $this->readInt('V'); |
|
89 | 89 | |
90 | - if( ( $magic === self::MAGIC1 ) || ( $magic === self::MAGIC3 ) ) { //to make sure it works for 64-bit platforms |
|
90 | + if (($magic === self::MAGIC1) || ($magic === self::MAGIC3)) { //to make sure it works for 64-bit platforms |
|
91 | 91 | $byteOrder = 'V'; //low endian |
92 | - } elseif( $magic === ( self::MAGIC2 & 0xFFFFFFFF ) ) { |
|
92 | + } elseif ($magic === (self::MAGIC2 & 0xFFFFFFFF)) { |
|
93 | 93 | $byteOrder = 'N'; //big endian |
94 | 94 | } else { |
95 | - throw new \Aimeos\MW\Translation\Exception( 'Invalid MO file' ); |
|
95 | + throw new \Aimeos\MW\Translation\Exception('Invalid MO file'); |
|
96 | 96 | } |
97 | 97 | |
98 | - $this->readInt( $byteOrder ); |
|
99 | - $total = $this->readInt( $byteOrder ); //total string count |
|
100 | - $originals = $this->readInt( $byteOrder ); //offset of original table |
|
101 | - $trans = $this->readInt( $byteOrder ); //offset of translation table |
|
98 | + $this->readInt($byteOrder); |
|
99 | + $total = $this->readInt($byteOrder); //total string count |
|
100 | + $originals = $this->readInt($byteOrder); //offset of original table |
|
101 | + $trans = $this->readInt($byteOrder); //offset of translation table |
|
102 | 102 | |
103 | - $this->seekto( $originals ); |
|
104 | - $originalTable = $this->readIntArray( $byteOrder, $total * 2 ); |
|
105 | - $this->seekto( $trans ); |
|
106 | - $translationTable = $this->readIntArray( $byteOrder, $total * 2 ); |
|
103 | + $this->seekto($originals); |
|
104 | + $originalTable = $this->readIntArray($byteOrder, $total * 2); |
|
105 | + $this->seekto($trans); |
|
106 | + $translationTable = $this->readIntArray($byteOrder, $total * 2); |
|
107 | 107 | |
108 | - return $this->extractTable( $originalTable, $translationTable, $total ); |
|
108 | + return $this->extractTable($originalTable, $translationTable, $total); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | |
@@ -117,33 +117,33 @@ discard block |
||
117 | 117 | * @param integer $total Total number of translations |
118 | 118 | * @return array Associative list of original singular as keys and one or more translations as values |
119 | 119 | */ |
120 | - protected function extractTable( $originalTable, $translationTable, $total ) |
|
120 | + protected function extractTable($originalTable, $translationTable, $total) |
|
121 | 121 | { |
122 | 122 | $messages = []; |
123 | 123 | |
124 | - for( $i = 0; $i < $total; ++$i ) |
|
124 | + for ($i = 0; $i < $total; ++$i) |
|
125 | 125 | { |
126 | 126 | $plural = null; |
127 | 127 | $next = $i * 2; |
128 | 128 | |
129 | - $this->seekto( $originalTable[$next + 2] ); |
|
130 | - $original = $this->read( $originalTable[$next + 1] ); |
|
131 | - $this->seekto( $translationTable[$next + 2] ); |
|
132 | - $translated = $this->read( $translationTable[$next + 1] ); |
|
129 | + $this->seekto($originalTable[$next + 2]); |
|
130 | + $original = $this->read($originalTable[$next + 1]); |
|
131 | + $this->seekto($translationTable[$next + 2]); |
|
132 | + $translated = $this->read($translationTable[$next + 1]); |
|
133 | 133 | |
134 | - if( $original === '' || $translated === '' ) { // Headers |
|
134 | + if ($original === '' || $translated === '') { // Headers |
|
135 | 135 | continue; |
136 | 136 | } |
137 | 137 | |
138 | - if( strpos( $original, "\x04" ) !== false ) { |
|
139 | - list( $context, $original ) = explode( "\x04", $original, 2 ); |
|
138 | + if (strpos($original, "\x04") !== false) { |
|
139 | + list($context, $original) = explode("\x04", $original, 2); |
|
140 | 140 | } |
141 | 141 | |
142 | - if( strpos( $original, "\000" ) !== false ) { |
|
143 | - list( $original, $plural ) = explode( "\000", $original ); |
|
142 | + if (strpos($original, "\000") !== false) { |
|
143 | + list($original, $plural) = explode("\000", $original); |
|
144 | 144 | } |
145 | 145 | |
146 | - if( $plural === null ) |
|
146 | + if ($plural === null) |
|
147 | 147 | { |
148 | 148 | $messages[$original] = $translated; |
149 | 149 | continue; |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | |
152 | 152 | $messages[$original] = []; |
153 | 153 | |
154 | - foreach( explode( "\x00", $translated ) as $idx => $value ) { |
|
154 | + foreach (explode("\x00", $translated) as $idx => $value) { |
|
155 | 155 | $messages[$original][$idx] = $value; |
156 | 156 | } |
157 | 157 | } |
@@ -166,14 +166,14 @@ discard block |
||
166 | 166 | * @param string $byteOrder Format code for unpack() |
167 | 167 | * @return integer Read integer |
168 | 168 | */ |
169 | - protected function readInt( $byteOrder ) |
|
169 | + protected function readInt($byteOrder) |
|
170 | 170 | { |
171 | - if( ( $content = $this->read( 4 )) === false ) { |
|
171 | + if (($content = $this->read(4)) === false) { |
|
172 | 172 | return false; |
173 | 173 | } |
174 | 174 | |
175 | - $content = unpack( $byteOrder, $content ); |
|
176 | - return array_shift( $content ); |
|
175 | + $content = unpack($byteOrder, $content); |
|
176 | + return array_shift($content); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | |
@@ -184,9 +184,9 @@ discard block |
||
184 | 184 | * @param integer $count Number of four byte integers to read |
185 | 185 | * @return array List of integers |
186 | 186 | */ |
187 | - protected function readIntArray( $byteOrder, $count ) |
|
187 | + protected function readIntArray($byteOrder, $count) |
|
188 | 188 | { |
189 | - return unpack( $byteOrder . $count, $this->read( 4 * $count ) ); |
|
189 | + return unpack($byteOrder.$count, $this->read(4 * $count)); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | |
@@ -198,8 +198,8 @@ discard block |
||
198 | 198 | */ |
199 | 199 | protected function read($bytes) |
200 | 200 | { |
201 | - $data = substr( $this->str, $this->pos, $bytes ); |
|
202 | - $this->seekto( $this->pos + $bytes ); |
|
201 | + $data = substr($this->str, $this->pos, $bytes); |
|
202 | + $this->seekto($this->pos + $bytes); |
|
203 | 203 | |
204 | 204 | return $data; |
205 | 205 | } |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | */ |
214 | 214 | protected function seekto($pos) |
215 | 215 | { |
216 | - $this->pos = ( $this->strlen < $pos ? $this->strlen : $pos ); |
|
216 | + $this->pos = ($this->strlen < $pos ? $this->strlen : $pos); |
|
217 | 217 | return $this->pos; |
218 | 218 | } |
219 | 219 | } |
220 | 220 | \ No newline at end of file |
@@ -13,14 +13,14 @@ discard block |
||
13 | 13 | |
14 | 14 | $includepaths = $aimeos->getIncludePaths(); |
15 | 15 | $includepaths[] = get_include_path(); |
16 | - set_include_path( implode( PATH_SEPARATOR, $includepaths ) ); |
|
16 | + set_include_path(implode(PATH_SEPARATOR, $includepaths)); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | |
20 | - public static function getContext( $site = 'unittest' ) |
|
20 | + public static function getContext($site = 'unittest') |
|
21 | 21 | { |
22 | - if( !isset( self::$context[$site] ) ) { |
|
23 | - self::$context[$site] = self::createContext( $site ); |
|
22 | + if (!isset(self::$context[$site])) { |
|
23 | + self::$context[$site] = self::createContext($site); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | return clone self::$context[$site]; |
@@ -29,58 +29,58 @@ discard block |
||
29 | 29 | |
30 | 30 | private static function getAimeos() |
31 | 31 | { |
32 | - if( !isset( self::$aimeos ) ) |
|
32 | + if (!isset(self::$aimeos)) |
|
33 | 33 | { |
34 | 34 | require_once 'Bootstrap.php'; |
35 | - spl_autoload_register( 'Aimeos\Bootstrap::autoload' ); |
|
35 | + spl_autoload_register('Aimeos\Bootstrap::autoload'); |
|
36 | 36 | |
37 | - $extdir = dirname( dirname( dirname( __DIR__ ) ) ); |
|
38 | - self::$aimeos = new \Aimeos\Bootstrap( array( $extdir ), false ); |
|
37 | + $extdir = dirname(dirname(dirname(__DIR__))); |
|
38 | + self::$aimeos = new \Aimeos\Bootstrap(array($extdir), false); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | return self::$aimeos; |
42 | 42 | } |
43 | 43 | |
44 | 44 | |
45 | - private static function createContext( $site ) |
|
45 | + private static function createContext($site) |
|
46 | 46 | { |
47 | 47 | $ctx = new \Aimeos\MShop\Context\Item\Standard(); |
48 | 48 | $aimeos = self::getAimeos(); |
49 | 49 | |
50 | 50 | |
51 | - $paths = $aimeos->getConfigPaths( 'mysql' ); |
|
52 | - $paths[] = __DIR__ . DIRECTORY_SEPARATOR . 'config'; |
|
51 | + $paths = $aimeos->getConfigPaths('mysql'); |
|
52 | + $paths[] = __DIR__.DIRECTORY_SEPARATOR.'config'; |
|
53 | 53 | |
54 | - $conf = new \Aimeos\MW\Config\PHPArray( [], $paths ); |
|
55 | - $ctx->setConfig( $conf ); |
|
54 | + $conf = new \Aimeos\MW\Config\PHPArray([], $paths); |
|
55 | + $ctx->setConfig($conf); |
|
56 | 56 | |
57 | 57 | |
58 | - $dbm = new \Aimeos\MW\DB\Manager\PDO( $conf ); |
|
59 | - $ctx->setDatabaseManager( $dbm ); |
|
58 | + $dbm = new \Aimeos\MW\DB\Manager\PDO($conf); |
|
59 | + $ctx->setDatabaseManager($dbm); |
|
60 | 60 | |
61 | 61 | |
62 | - $logger = new \Aimeos\MW\Logger\File( $site . '.log', \Aimeos\MW\Logger\Base::DEBUG ); |
|
63 | - $ctx->setLogger( $logger ); |
|
62 | + $logger = new \Aimeos\MW\Logger\File($site.'.log', \Aimeos\MW\Logger\Base::DEBUG); |
|
63 | + $ctx->setLogger($logger); |
|
64 | 64 | |
65 | 65 | |
66 | 66 | $cache = new \Aimeos\MW\Cache\None(); |
67 | - $ctx->setCache( $cache ); |
|
67 | + $ctx->setCache($cache); |
|
68 | 68 | |
69 | 69 | |
70 | - $i18n = new \Aimeos\MW\Translation\None( 'de' ); |
|
71 | - $ctx->setI18n( array( 'de' => $i18n ) ); |
|
70 | + $i18n = new \Aimeos\MW\Translation\None('de'); |
|
71 | + $ctx->setI18n(array('de' => $i18n)); |
|
72 | 72 | |
73 | 73 | |
74 | 74 | $session = new \Aimeos\MW\Session\None(); |
75 | - $ctx->setSession( $session ); |
|
75 | + $ctx->setSession($session); |
|
76 | 76 | |
77 | 77 | |
78 | - $localeManager = \Aimeos\MShop\Locale\Manager\Factory::createManager( $ctx ); |
|
79 | - $localeItem = $localeManager->bootstrap( $site, '', '', false ); |
|
78 | + $localeManager = \Aimeos\MShop\Locale\Manager\Factory::createManager($ctx); |
|
79 | + $localeItem = $localeManager->bootstrap($site, '', '', false); |
|
80 | 80 | |
81 | - $ctx->setLocale( $localeItem ); |
|
81 | + $ctx->setLocale($localeItem); |
|
82 | 82 | |
83 | - $ctx->setEditor( 'ai-gettext:unittest' ); |
|
83 | + $ctx->setEditor('ai-gettext:unittest'); |
|
84 | 84 | |
85 | 85 | return $ctx; |
86 | 86 | } |