@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | * @since 3.9.0 |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 13 | +if ( ! defined('ABSPATH')) { |
|
| 14 | 14 | exit; |
| 15 | 15 | } |
| 16 | 16 | |
@@ -85,15 +85,15 @@ discard block |
||
| 85 | 85 | public static function get_languages() { |
| 86 | 86 | |
| 87 | 87 | // Lazily load the languages. |
| 88 | - if ( null === self::$languages ) { |
|
| 88 | + if (null === self::$languages) { |
|
| 89 | 89 | |
| 90 | 90 | // Get the language names from WP's own (multisite) function. |
| 91 | - foreach ( self::$codes as $key ) { |
|
| 92 | - self::$languages[ $key ] = self::get_language_name( $key ); |
|
| 91 | + foreach (self::$codes as $key) { |
|
| 92 | + self::$languages[$key] = self::get_language_name($key); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | // Sort by language name. |
| 96 | - asort( self::$languages ); |
|
| 96 | + asort(self::$languages); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | return self::$languages; |
@@ -109,8 +109,8 @@ discard block |
||
| 109 | 109 | * @return string The language corresponding to $code if it exists. If it does not exist, |
| 110 | 110 | * then the first two letters of $code is returned. |
| 111 | 111 | */ |
| 112 | - public static function get_language_name( $code = '' ) { |
|
| 113 | - $code = strtolower( substr( $code, 0, 2 ) ); |
|
| 112 | + public static function get_language_name($code = '') { |
|
| 113 | + $code = strtolower(substr($code, 0, 2)); |
|
| 114 | 114 | $lang_codes = array( |
| 115 | 115 | 'aa' => 'Afar', |
| 116 | 116 | 'ab' => 'Abkhazian', |
@@ -307,9 +307,9 @@ discard block |
||
| 307 | 307 | * @param array $lang_codes Key/value pair of language codes where key is the short version. |
| 308 | 308 | * @param string $code A two-letter designation of the language. |
| 309 | 309 | */ |
| 310 | - $lang_codes = apply_filters( 'lang_codes', $lang_codes, $code ); |
|
| 310 | + $lang_codes = apply_filters('lang_codes', $lang_codes, $code); |
|
| 311 | 311 | |
| 312 | - return strtr( $code, $lang_codes ); |
|
| 312 | + return strtr($code, $lang_codes); |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | - exit; |
|
| 14 | + exit; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -21,295 +21,295 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | class Wordlift_Languages { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * An array that will contain language codes => language names pairs. It gets lazily loaded the first time by the |
|
| 26 | - * `get_languages` function. |
|
| 27 | - * |
|
| 28 | - * @since 3.9.0 |
|
| 29 | - * @var array|null An array of language codes => language names pairs or NULL if not initialized yet. |
|
| 30 | - */ |
|
| 31 | - private static $languages = null; |
|
| 24 | + /** |
|
| 25 | + * An array that will contain language codes => language names pairs. It gets lazily loaded the first time by the |
|
| 26 | + * `get_languages` function. |
|
| 27 | + * |
|
| 28 | + * @since 3.9.0 |
|
| 29 | + * @var array|null An array of language codes => language names pairs or NULL if not initialized yet. |
|
| 30 | + */ |
|
| 31 | + private static $languages = null; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * The list of supported language codes. |
|
| 35 | - * |
|
| 36 | - * @since 3.9.0 |
|
| 37 | - * |
|
| 38 | - * @var array An array of language codes. |
|
| 39 | - */ |
|
| 40 | - private static $codes = array( |
|
| 41 | - 'ar', |
|
| 42 | - 'be', |
|
| 43 | - 'bg', |
|
| 44 | - 'ca', |
|
| 45 | - 'cs', |
|
| 46 | - 'da', |
|
| 47 | - 'de', |
|
| 48 | - 'el', |
|
| 49 | - 'en', |
|
| 50 | - 'es', |
|
| 51 | - 'et', |
|
| 52 | - 'fi', |
|
| 53 | - 'fr', |
|
| 54 | - 'he', |
|
| 55 | - 'hr', |
|
| 56 | - 'hu', |
|
| 57 | - 'id', |
|
| 58 | - 'is', |
|
| 59 | - 'it', |
|
| 60 | - 'lt', |
|
| 61 | - 'lv', |
|
| 62 | - 'nl', |
|
| 63 | - 'no', |
|
| 64 | - 'pl', |
|
| 65 | - 'pt', |
|
| 66 | - 'ro', |
|
| 67 | - 'ru', |
|
| 68 | - 'sk', |
|
| 69 | - 'sl', |
|
| 70 | - 'sq', |
|
| 71 | - 'sr', |
|
| 72 | - 'sv', |
|
| 73 | - 'tr', |
|
| 74 | - 'uk', |
|
| 75 | - 'zh-cn', |
|
| 76 | - ); |
|
| 33 | + /** |
|
| 34 | + * The list of supported language codes. |
|
| 35 | + * |
|
| 36 | + * @since 3.9.0 |
|
| 37 | + * |
|
| 38 | + * @var array An array of language codes. |
|
| 39 | + */ |
|
| 40 | + private static $codes = array( |
|
| 41 | + 'ar', |
|
| 42 | + 'be', |
|
| 43 | + 'bg', |
|
| 44 | + 'ca', |
|
| 45 | + 'cs', |
|
| 46 | + 'da', |
|
| 47 | + 'de', |
|
| 48 | + 'el', |
|
| 49 | + 'en', |
|
| 50 | + 'es', |
|
| 51 | + 'et', |
|
| 52 | + 'fi', |
|
| 53 | + 'fr', |
|
| 54 | + 'he', |
|
| 55 | + 'hr', |
|
| 56 | + 'hu', |
|
| 57 | + 'id', |
|
| 58 | + 'is', |
|
| 59 | + 'it', |
|
| 60 | + 'lt', |
|
| 61 | + 'lv', |
|
| 62 | + 'nl', |
|
| 63 | + 'no', |
|
| 64 | + 'pl', |
|
| 65 | + 'pt', |
|
| 66 | + 'ro', |
|
| 67 | + 'ru', |
|
| 68 | + 'sk', |
|
| 69 | + 'sl', |
|
| 70 | + 'sq', |
|
| 71 | + 'sr', |
|
| 72 | + 'sv', |
|
| 73 | + 'tr', |
|
| 74 | + 'uk', |
|
| 75 | + 'zh-cn', |
|
| 76 | + ); |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Get the list of WordLift's supported languages in an array with language code => language name pairs. |
|
| 80 | - * |
|
| 81 | - * @since 3.9.0 |
|
| 82 | - * |
|
| 83 | - * @return array An array with language code => language name pairs. |
|
| 84 | - */ |
|
| 85 | - public static function get_languages() { |
|
| 78 | + /** |
|
| 79 | + * Get the list of WordLift's supported languages in an array with language code => language name pairs. |
|
| 80 | + * |
|
| 81 | + * @since 3.9.0 |
|
| 82 | + * |
|
| 83 | + * @return array An array with language code => language name pairs. |
|
| 84 | + */ |
|
| 85 | + public static function get_languages() { |
|
| 86 | 86 | |
| 87 | - // Lazily load the languages. |
|
| 88 | - if ( null === self::$languages ) { |
|
| 87 | + // Lazily load the languages. |
|
| 88 | + if ( null === self::$languages ) { |
|
| 89 | 89 | |
| 90 | - // Get the language names from WP's own (multisite) function. |
|
| 91 | - foreach ( self::$codes as $key ) { |
|
| 92 | - self::$languages[ $key ] = self::get_language_name( $key ); |
|
| 93 | - } |
|
| 90 | + // Get the language names from WP's own (multisite) function. |
|
| 91 | + foreach ( self::$codes as $key ) { |
|
| 92 | + self::$languages[ $key ] = self::get_language_name( $key ); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - // Sort by language name. |
|
| 96 | - asort( self::$languages ); |
|
| 97 | - } |
|
| 95 | + // Sort by language name. |
|
| 96 | + asort( self::$languages ); |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - return self::$languages; |
|
| 100 | - } |
|
| 99 | + return self::$languages; |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * Returns the language for a language code. This function is a clone of WP's function provided in `ms.php`. |
|
| 104 | - * |
|
| 105 | - * @since 3.9.3 |
|
| 106 | - * |
|
| 107 | - * @param string $code Optional. The two-letter language code. Default empty. |
|
| 108 | - * |
|
| 109 | - * @return string The language corresponding to $code if it exists. If it does not exist, |
|
| 110 | - * then the first two letters of $code is returned. |
|
| 111 | - */ |
|
| 112 | - public static function get_language_name( $code = '' ) { |
|
| 113 | - $code = strtolower( substr( $code, 0, 2 ) ); |
|
| 114 | - $lang_codes = array( |
|
| 115 | - 'aa' => 'Afar', |
|
| 116 | - 'ab' => 'Abkhazian', |
|
| 117 | - 'af' => 'Afrikaans', |
|
| 118 | - 'ak' => 'Akan', |
|
| 119 | - 'sq' => 'Albanian', |
|
| 120 | - 'am' => 'Amharic', |
|
| 121 | - 'ar' => 'Arabic', |
|
| 122 | - 'an' => 'Aragonese', |
|
| 123 | - 'hy' => 'Armenian', |
|
| 124 | - 'as' => 'Assamese', |
|
| 125 | - 'av' => 'Avaric', |
|
| 126 | - 'ae' => 'Avestan', |
|
| 127 | - 'ay' => 'Aymara', |
|
| 128 | - 'az' => 'Azerbaijani', |
|
| 129 | - 'ba' => 'Bashkir', |
|
| 130 | - 'bm' => 'Bambara', |
|
| 131 | - 'eu' => 'Basque', |
|
| 132 | - 'be' => 'Belarusian', |
|
| 133 | - 'bn' => 'Bengali', |
|
| 134 | - 'bh' => 'Bihari', |
|
| 135 | - 'bi' => 'Bislama', |
|
| 136 | - 'bs' => 'Bosnian', |
|
| 137 | - 'br' => 'Breton', |
|
| 138 | - 'bg' => 'Bulgarian', |
|
| 139 | - 'my' => 'Burmese', |
|
| 140 | - 'ca' => 'Catalan; Valencian', |
|
| 141 | - 'ch' => 'Chamorro', |
|
| 142 | - 'ce' => 'Chechen', |
|
| 143 | - 'zh' => 'Chinese', |
|
| 144 | - 'cu' => 'Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic', |
|
| 145 | - 'cv' => 'Chuvash', |
|
| 146 | - 'kw' => 'Cornish', |
|
| 147 | - 'co' => 'Corsican', |
|
| 148 | - 'cr' => 'Cree', |
|
| 149 | - 'cs' => 'Czech', |
|
| 150 | - 'da' => 'Danish', |
|
| 151 | - 'dv' => 'Divehi; Dhivehi; Maldivian', |
|
| 152 | - 'nl' => 'Dutch; Flemish', |
|
| 153 | - 'dz' => 'Dzongkha', |
|
| 154 | - 'en' => 'English', |
|
| 155 | - 'eo' => 'Esperanto', |
|
| 156 | - 'et' => 'Estonian', |
|
| 157 | - 'ee' => 'Ewe', |
|
| 158 | - 'fo' => 'Faroese', |
|
| 159 | - 'fj' => 'Fijjian', |
|
| 160 | - 'fi' => 'Finnish', |
|
| 161 | - 'fr' => 'French', |
|
| 162 | - 'fy' => 'Western Frisian', |
|
| 163 | - 'ff' => 'Fulah', |
|
| 164 | - 'ka' => 'Georgian', |
|
| 165 | - 'de' => 'German', |
|
| 166 | - 'gd' => 'Gaelic; Scottish Gaelic', |
|
| 167 | - 'ga' => 'Irish', |
|
| 168 | - 'gl' => 'Galician', |
|
| 169 | - 'gv' => 'Manx', |
|
| 170 | - 'el' => 'Greek, Modern', |
|
| 171 | - 'gn' => 'Guarani', |
|
| 172 | - 'gu' => 'Gujarati', |
|
| 173 | - 'ht' => 'Haitian; Haitian Creole', |
|
| 174 | - 'ha' => 'Hausa', |
|
| 175 | - 'he' => 'Hebrew', |
|
| 176 | - 'hz' => 'Herero', |
|
| 177 | - 'hi' => 'Hindi', |
|
| 178 | - 'ho' => 'Hiri Motu', |
|
| 179 | - 'hu' => 'Hungarian', |
|
| 180 | - 'ig' => 'Igbo', |
|
| 181 | - 'is' => 'Icelandic', |
|
| 182 | - 'io' => 'Ido', |
|
| 183 | - 'ii' => 'Sichuan Yi', |
|
| 184 | - 'iu' => 'Inuktitut', |
|
| 185 | - 'ie' => 'Interlingue', |
|
| 186 | - 'ia' => 'Interlingua (International Auxiliary Language Association)', |
|
| 187 | - 'id' => 'Indonesian', |
|
| 188 | - 'ik' => 'Inupiaq', |
|
| 189 | - 'it' => 'Italian', |
|
| 190 | - 'jv' => 'Javanese', |
|
| 191 | - 'ja' => 'Japanese', |
|
| 192 | - 'kl' => 'Kalaallisut; Greenlandic', |
|
| 193 | - 'kn' => 'Kannada', |
|
| 194 | - 'ks' => 'Kashmiri', |
|
| 195 | - 'kr' => 'Kanuri', |
|
| 196 | - 'kk' => 'Kazakh', |
|
| 197 | - 'km' => 'Central Khmer', |
|
| 198 | - 'ki' => 'Kikuyu; Gikuyu', |
|
| 199 | - 'rw' => 'Kinyarwanda', |
|
| 200 | - 'ky' => 'Kirghiz; Kyrgyz', |
|
| 201 | - 'kv' => 'Komi', |
|
| 202 | - 'kg' => 'Kongo', |
|
| 203 | - 'ko' => 'Korean', |
|
| 204 | - 'kj' => 'Kuanyama; Kwanyama', |
|
| 205 | - 'ku' => 'Kurdish', |
|
| 206 | - 'lo' => 'Lao', |
|
| 207 | - 'la' => 'Latin', |
|
| 208 | - 'lv' => 'Latvian', |
|
| 209 | - 'li' => 'Limburgan; Limburger; Limburgish', |
|
| 210 | - 'ln' => 'Lingala', |
|
| 211 | - 'lt' => 'Lithuanian', |
|
| 212 | - 'lb' => 'Luxembourgish; Letzeburgesch', |
|
| 213 | - 'lu' => 'Luba-Katanga', |
|
| 214 | - 'lg' => 'Ganda', |
|
| 215 | - 'mk' => 'Macedonian', |
|
| 216 | - 'mh' => 'Marshallese', |
|
| 217 | - 'ml' => 'Malayalam', |
|
| 218 | - 'mi' => 'Maori', |
|
| 219 | - 'mr' => 'Marathi', |
|
| 220 | - 'ms' => 'Malay', |
|
| 221 | - 'mg' => 'Malagasy', |
|
| 222 | - 'mt' => 'Maltese', |
|
| 223 | - 'mo' => 'Moldavian', |
|
| 224 | - 'mn' => 'Mongolian', |
|
| 225 | - 'na' => 'Nauru', |
|
| 226 | - 'nv' => 'Navajo; Navaho', |
|
| 227 | - 'nr' => 'Ndebele, South; South Ndebele', |
|
| 228 | - 'nd' => 'Ndebele, North; North Ndebele', |
|
| 229 | - 'ng' => 'Ndonga', |
|
| 230 | - 'ne' => 'Nepali', |
|
| 231 | - 'nn' => 'Norwegian Nynorsk; Nynorsk, Norwegian', |
|
| 232 | - 'nb' => 'Bokmål, Norwegian, Norwegian Bokmål', |
|
| 233 | - 'no' => 'Norwegian', |
|
| 234 | - 'ny' => 'Chichewa; Chewa; Nyanja', |
|
| 235 | - 'oc' => 'Occitan, Provençal', |
|
| 236 | - 'oj' => 'Ojibwa', |
|
| 237 | - 'or' => 'Oriya', |
|
| 238 | - 'om' => 'Oromo', |
|
| 239 | - 'os' => 'Ossetian; Ossetic', |
|
| 240 | - 'pa' => 'Panjabi; Punjabi', |
|
| 241 | - 'fa' => 'Persian', |
|
| 242 | - 'pi' => 'Pali', |
|
| 243 | - 'pl' => 'Polish', |
|
| 244 | - 'pt' => 'Portuguese', |
|
| 245 | - 'ps' => 'Pushto', |
|
| 246 | - 'qu' => 'Quechua', |
|
| 247 | - 'rm' => 'Romansh', |
|
| 248 | - 'ro' => 'Romanian', |
|
| 249 | - 'rn' => 'Rundi', |
|
| 250 | - 'ru' => 'Russian', |
|
| 251 | - 'sg' => 'Sango', |
|
| 252 | - 'sa' => 'Sanskrit', |
|
| 253 | - 'sr' => 'Serbian', |
|
| 254 | - 'hr' => 'Croatian', |
|
| 255 | - 'si' => 'Sinhala; Sinhalese', |
|
| 256 | - 'sk' => 'Slovak', |
|
| 257 | - 'sl' => 'Slovenian', |
|
| 258 | - 'se' => 'Northern Sami', |
|
| 259 | - 'sm' => 'Samoan', |
|
| 260 | - 'sn' => 'Shona', |
|
| 261 | - 'sd' => 'Sindhi', |
|
| 262 | - 'so' => 'Somali', |
|
| 263 | - 'st' => 'Sotho, Southern', |
|
| 264 | - 'es' => 'Spanish; Castilian', |
|
| 265 | - 'sc' => 'Sardinian', |
|
| 266 | - 'ss' => 'Swati', |
|
| 267 | - 'su' => 'Sundanese', |
|
| 268 | - 'sw' => 'Swahili', |
|
| 269 | - 'sv' => 'Swedish', |
|
| 270 | - 'ty' => 'Tahitian', |
|
| 271 | - 'ta' => 'Tamil', |
|
| 272 | - 'tt' => 'Tatar', |
|
| 273 | - 'te' => 'Telugu', |
|
| 274 | - 'tg' => 'Tajik', |
|
| 275 | - 'tl' => 'Tagalog', |
|
| 276 | - 'th' => 'Thai', |
|
| 277 | - 'bo' => 'Tibetan', |
|
| 278 | - 'ti' => 'Tigrinya', |
|
| 279 | - 'to' => 'Tonga (Tonga Islands)', |
|
| 280 | - 'tn' => 'Tswana', |
|
| 281 | - 'ts' => 'Tsonga', |
|
| 282 | - 'tk' => 'Turkmen', |
|
| 283 | - 'tr' => 'Turkish', |
|
| 284 | - 'tw' => 'Twi', |
|
| 285 | - 'ug' => 'Uighur; Uyghur', |
|
| 286 | - 'uk' => 'Ukrainian', |
|
| 287 | - 'ur' => 'Urdu', |
|
| 288 | - 'uz' => 'Uzbek', |
|
| 289 | - 've' => 'Venda', |
|
| 290 | - 'vi' => 'Vietnamese', |
|
| 291 | - 'vo' => 'Volapük', |
|
| 292 | - 'cy' => 'Welsh', |
|
| 293 | - 'wa' => 'Walloon', |
|
| 294 | - 'wo' => 'Wolof', |
|
| 295 | - 'xh' => 'Xhosa', |
|
| 296 | - 'yi' => 'Yiddish', |
|
| 297 | - 'yo' => 'Yoruba', |
|
| 298 | - 'za' => 'Zhuang; Chuang', |
|
| 299 | - 'zu' => 'Zulu', |
|
| 300 | - ); |
|
| 102 | + /** |
|
| 103 | + * Returns the language for a language code. This function is a clone of WP's function provided in `ms.php`. |
|
| 104 | + * |
|
| 105 | + * @since 3.9.3 |
|
| 106 | + * |
|
| 107 | + * @param string $code Optional. The two-letter language code. Default empty. |
|
| 108 | + * |
|
| 109 | + * @return string The language corresponding to $code if it exists. If it does not exist, |
|
| 110 | + * then the first two letters of $code is returned. |
|
| 111 | + */ |
|
| 112 | + public static function get_language_name( $code = '' ) { |
|
| 113 | + $code = strtolower( substr( $code, 0, 2 ) ); |
|
| 114 | + $lang_codes = array( |
|
| 115 | + 'aa' => 'Afar', |
|
| 116 | + 'ab' => 'Abkhazian', |
|
| 117 | + 'af' => 'Afrikaans', |
|
| 118 | + 'ak' => 'Akan', |
|
| 119 | + 'sq' => 'Albanian', |
|
| 120 | + 'am' => 'Amharic', |
|
| 121 | + 'ar' => 'Arabic', |
|
| 122 | + 'an' => 'Aragonese', |
|
| 123 | + 'hy' => 'Armenian', |
|
| 124 | + 'as' => 'Assamese', |
|
| 125 | + 'av' => 'Avaric', |
|
| 126 | + 'ae' => 'Avestan', |
|
| 127 | + 'ay' => 'Aymara', |
|
| 128 | + 'az' => 'Azerbaijani', |
|
| 129 | + 'ba' => 'Bashkir', |
|
| 130 | + 'bm' => 'Bambara', |
|
| 131 | + 'eu' => 'Basque', |
|
| 132 | + 'be' => 'Belarusian', |
|
| 133 | + 'bn' => 'Bengali', |
|
| 134 | + 'bh' => 'Bihari', |
|
| 135 | + 'bi' => 'Bislama', |
|
| 136 | + 'bs' => 'Bosnian', |
|
| 137 | + 'br' => 'Breton', |
|
| 138 | + 'bg' => 'Bulgarian', |
|
| 139 | + 'my' => 'Burmese', |
|
| 140 | + 'ca' => 'Catalan; Valencian', |
|
| 141 | + 'ch' => 'Chamorro', |
|
| 142 | + 'ce' => 'Chechen', |
|
| 143 | + 'zh' => 'Chinese', |
|
| 144 | + 'cu' => 'Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic', |
|
| 145 | + 'cv' => 'Chuvash', |
|
| 146 | + 'kw' => 'Cornish', |
|
| 147 | + 'co' => 'Corsican', |
|
| 148 | + 'cr' => 'Cree', |
|
| 149 | + 'cs' => 'Czech', |
|
| 150 | + 'da' => 'Danish', |
|
| 151 | + 'dv' => 'Divehi; Dhivehi; Maldivian', |
|
| 152 | + 'nl' => 'Dutch; Flemish', |
|
| 153 | + 'dz' => 'Dzongkha', |
|
| 154 | + 'en' => 'English', |
|
| 155 | + 'eo' => 'Esperanto', |
|
| 156 | + 'et' => 'Estonian', |
|
| 157 | + 'ee' => 'Ewe', |
|
| 158 | + 'fo' => 'Faroese', |
|
| 159 | + 'fj' => 'Fijjian', |
|
| 160 | + 'fi' => 'Finnish', |
|
| 161 | + 'fr' => 'French', |
|
| 162 | + 'fy' => 'Western Frisian', |
|
| 163 | + 'ff' => 'Fulah', |
|
| 164 | + 'ka' => 'Georgian', |
|
| 165 | + 'de' => 'German', |
|
| 166 | + 'gd' => 'Gaelic; Scottish Gaelic', |
|
| 167 | + 'ga' => 'Irish', |
|
| 168 | + 'gl' => 'Galician', |
|
| 169 | + 'gv' => 'Manx', |
|
| 170 | + 'el' => 'Greek, Modern', |
|
| 171 | + 'gn' => 'Guarani', |
|
| 172 | + 'gu' => 'Gujarati', |
|
| 173 | + 'ht' => 'Haitian; Haitian Creole', |
|
| 174 | + 'ha' => 'Hausa', |
|
| 175 | + 'he' => 'Hebrew', |
|
| 176 | + 'hz' => 'Herero', |
|
| 177 | + 'hi' => 'Hindi', |
|
| 178 | + 'ho' => 'Hiri Motu', |
|
| 179 | + 'hu' => 'Hungarian', |
|
| 180 | + 'ig' => 'Igbo', |
|
| 181 | + 'is' => 'Icelandic', |
|
| 182 | + 'io' => 'Ido', |
|
| 183 | + 'ii' => 'Sichuan Yi', |
|
| 184 | + 'iu' => 'Inuktitut', |
|
| 185 | + 'ie' => 'Interlingue', |
|
| 186 | + 'ia' => 'Interlingua (International Auxiliary Language Association)', |
|
| 187 | + 'id' => 'Indonesian', |
|
| 188 | + 'ik' => 'Inupiaq', |
|
| 189 | + 'it' => 'Italian', |
|
| 190 | + 'jv' => 'Javanese', |
|
| 191 | + 'ja' => 'Japanese', |
|
| 192 | + 'kl' => 'Kalaallisut; Greenlandic', |
|
| 193 | + 'kn' => 'Kannada', |
|
| 194 | + 'ks' => 'Kashmiri', |
|
| 195 | + 'kr' => 'Kanuri', |
|
| 196 | + 'kk' => 'Kazakh', |
|
| 197 | + 'km' => 'Central Khmer', |
|
| 198 | + 'ki' => 'Kikuyu; Gikuyu', |
|
| 199 | + 'rw' => 'Kinyarwanda', |
|
| 200 | + 'ky' => 'Kirghiz; Kyrgyz', |
|
| 201 | + 'kv' => 'Komi', |
|
| 202 | + 'kg' => 'Kongo', |
|
| 203 | + 'ko' => 'Korean', |
|
| 204 | + 'kj' => 'Kuanyama; Kwanyama', |
|
| 205 | + 'ku' => 'Kurdish', |
|
| 206 | + 'lo' => 'Lao', |
|
| 207 | + 'la' => 'Latin', |
|
| 208 | + 'lv' => 'Latvian', |
|
| 209 | + 'li' => 'Limburgan; Limburger; Limburgish', |
|
| 210 | + 'ln' => 'Lingala', |
|
| 211 | + 'lt' => 'Lithuanian', |
|
| 212 | + 'lb' => 'Luxembourgish; Letzeburgesch', |
|
| 213 | + 'lu' => 'Luba-Katanga', |
|
| 214 | + 'lg' => 'Ganda', |
|
| 215 | + 'mk' => 'Macedonian', |
|
| 216 | + 'mh' => 'Marshallese', |
|
| 217 | + 'ml' => 'Malayalam', |
|
| 218 | + 'mi' => 'Maori', |
|
| 219 | + 'mr' => 'Marathi', |
|
| 220 | + 'ms' => 'Malay', |
|
| 221 | + 'mg' => 'Malagasy', |
|
| 222 | + 'mt' => 'Maltese', |
|
| 223 | + 'mo' => 'Moldavian', |
|
| 224 | + 'mn' => 'Mongolian', |
|
| 225 | + 'na' => 'Nauru', |
|
| 226 | + 'nv' => 'Navajo; Navaho', |
|
| 227 | + 'nr' => 'Ndebele, South; South Ndebele', |
|
| 228 | + 'nd' => 'Ndebele, North; North Ndebele', |
|
| 229 | + 'ng' => 'Ndonga', |
|
| 230 | + 'ne' => 'Nepali', |
|
| 231 | + 'nn' => 'Norwegian Nynorsk; Nynorsk, Norwegian', |
|
| 232 | + 'nb' => 'Bokmål, Norwegian, Norwegian Bokmål', |
|
| 233 | + 'no' => 'Norwegian', |
|
| 234 | + 'ny' => 'Chichewa; Chewa; Nyanja', |
|
| 235 | + 'oc' => 'Occitan, Provençal', |
|
| 236 | + 'oj' => 'Ojibwa', |
|
| 237 | + 'or' => 'Oriya', |
|
| 238 | + 'om' => 'Oromo', |
|
| 239 | + 'os' => 'Ossetian; Ossetic', |
|
| 240 | + 'pa' => 'Panjabi; Punjabi', |
|
| 241 | + 'fa' => 'Persian', |
|
| 242 | + 'pi' => 'Pali', |
|
| 243 | + 'pl' => 'Polish', |
|
| 244 | + 'pt' => 'Portuguese', |
|
| 245 | + 'ps' => 'Pushto', |
|
| 246 | + 'qu' => 'Quechua', |
|
| 247 | + 'rm' => 'Romansh', |
|
| 248 | + 'ro' => 'Romanian', |
|
| 249 | + 'rn' => 'Rundi', |
|
| 250 | + 'ru' => 'Russian', |
|
| 251 | + 'sg' => 'Sango', |
|
| 252 | + 'sa' => 'Sanskrit', |
|
| 253 | + 'sr' => 'Serbian', |
|
| 254 | + 'hr' => 'Croatian', |
|
| 255 | + 'si' => 'Sinhala; Sinhalese', |
|
| 256 | + 'sk' => 'Slovak', |
|
| 257 | + 'sl' => 'Slovenian', |
|
| 258 | + 'se' => 'Northern Sami', |
|
| 259 | + 'sm' => 'Samoan', |
|
| 260 | + 'sn' => 'Shona', |
|
| 261 | + 'sd' => 'Sindhi', |
|
| 262 | + 'so' => 'Somali', |
|
| 263 | + 'st' => 'Sotho, Southern', |
|
| 264 | + 'es' => 'Spanish; Castilian', |
|
| 265 | + 'sc' => 'Sardinian', |
|
| 266 | + 'ss' => 'Swati', |
|
| 267 | + 'su' => 'Sundanese', |
|
| 268 | + 'sw' => 'Swahili', |
|
| 269 | + 'sv' => 'Swedish', |
|
| 270 | + 'ty' => 'Tahitian', |
|
| 271 | + 'ta' => 'Tamil', |
|
| 272 | + 'tt' => 'Tatar', |
|
| 273 | + 'te' => 'Telugu', |
|
| 274 | + 'tg' => 'Tajik', |
|
| 275 | + 'tl' => 'Tagalog', |
|
| 276 | + 'th' => 'Thai', |
|
| 277 | + 'bo' => 'Tibetan', |
|
| 278 | + 'ti' => 'Tigrinya', |
|
| 279 | + 'to' => 'Tonga (Tonga Islands)', |
|
| 280 | + 'tn' => 'Tswana', |
|
| 281 | + 'ts' => 'Tsonga', |
|
| 282 | + 'tk' => 'Turkmen', |
|
| 283 | + 'tr' => 'Turkish', |
|
| 284 | + 'tw' => 'Twi', |
|
| 285 | + 'ug' => 'Uighur; Uyghur', |
|
| 286 | + 'uk' => 'Ukrainian', |
|
| 287 | + 'ur' => 'Urdu', |
|
| 288 | + 'uz' => 'Uzbek', |
|
| 289 | + 've' => 'Venda', |
|
| 290 | + 'vi' => 'Vietnamese', |
|
| 291 | + 'vo' => 'Volapük', |
|
| 292 | + 'cy' => 'Welsh', |
|
| 293 | + 'wa' => 'Walloon', |
|
| 294 | + 'wo' => 'Wolof', |
|
| 295 | + 'xh' => 'Xhosa', |
|
| 296 | + 'yi' => 'Yiddish', |
|
| 297 | + 'yo' => 'Yoruba', |
|
| 298 | + 'za' => 'Zhuang; Chuang', |
|
| 299 | + 'zu' => 'Zulu', |
|
| 300 | + ); |
|
| 301 | 301 | |
| 302 | - /** |
|
| 303 | - * Filters the language codes. |
|
| 304 | - * |
|
| 305 | - * @since MU |
|
| 306 | - * |
|
| 307 | - * @param array $lang_codes Key/value pair of language codes where key is the short version. |
|
| 308 | - * @param string $code A two-letter designation of the language. |
|
| 309 | - */ |
|
| 310 | - $lang_codes = apply_filters( 'lang_codes', $lang_codes, $code ); |
|
| 302 | + /** |
|
| 303 | + * Filters the language codes. |
|
| 304 | + * |
|
| 305 | + * @since MU |
|
| 306 | + * |
|
| 307 | + * @param array $lang_codes Key/value pair of language codes where key is the short version. |
|
| 308 | + * @param string $code A two-letter designation of the language. |
|
| 309 | + */ |
|
| 310 | + $lang_codes = apply_filters( 'lang_codes', $lang_codes, $code ); |
|
| 311 | 311 | |
| 312 | - return strtr( $code, $lang_codes ); |
|
| 313 | - } |
|
| 312 | + return strtr( $code, $lang_codes ); |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | 315 | } |
@@ -8,8 +8,8 @@ |
||
| 8 | 8 | ?> |
| 9 | 9 | <form method="post" action="options.php"> |
| 10 | 10 | <?php |
| 11 | - settings_fields( 'wl_settings__webhooks' ); |
|
| 12 | - do_settings_sections( 'wl_settings__webhooks' ); |
|
| 13 | - submit_button( 'Save Settings' ); |
|
| 14 | - ?> |
|
| 11 | + settings_fields( 'wl_settings__webhooks' ); |
|
| 12 | + do_settings_sections( 'wl_settings__webhooks' ); |
|
| 13 | + submit_button( 'Save Settings' ); |
|
| 14 | + ?> |
|
| 15 | 15 | </form> |
@@ -3,12 +3,12 @@ |
||
| 3 | 3 | * HTML for Webhook Settings Tab. |
| 4 | 4 | * Added for feature request 1496 |
| 5 | 5 | */ |
| 6 | -settings_errors( 'wl_webhook_error' ); |
|
| 6 | +settings_errors('wl_webhook_error'); |
|
| 7 | 7 | ?> |
| 8 | 8 | <form method="post" action="options.php"> |
| 9 | 9 | <?php |
| 10 | - settings_fields( 'wl_settings__webhooks' ); |
|
| 11 | - do_settings_sections( 'wl_settings__webhooks' ); |
|
| 12 | - submit_button( 'Save Settings' ); |
|
| 10 | + settings_fields('wl_settings__webhooks'); |
|
| 11 | + do_settings_sections('wl_settings__webhooks'); |
|
| 12 | + submit_button('Save Settings'); |
|
| 13 | 13 | ?> |
| 14 | 14 | </form> |
@@ -14,88 +14,88 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class Wordlift_Analytics_Connect { |
| 16 | 16 | |
| 17 | - const HANDLE = 'wordlift'; |
|
| 17 | + const HANDLE = 'wordlift'; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Gets an array of related entities with their post IDs and titles. |
|
| 21 | - * |
|
| 22 | - * @method get_analytics_event_data |
|
| 23 | - * @since 3.21.0 |
|
| 24 | - * |
|
| 25 | - * @param int $post_id post id we want related data for. |
|
| 26 | - * |
|
| 27 | - * @return array |
|
| 28 | - */ |
|
| 29 | - public static function get_analytics_event_data( $post_id ) { |
|
| 30 | - // If no ID was passed get current ID. |
|
| 31 | - if ( ! $post_id ) { |
|
| 32 | - $post_id = get_queried_object_id(); |
|
| 33 | - } |
|
| 34 | - /** |
|
| 35 | - * TODO: set/get this from cache. |
|
| 36 | - */ |
|
| 37 | - $related_items = array(); |
|
| 38 | - $related_ids = wl_core_get_related_entity_ids( $post_id ); |
|
| 19 | + /** |
|
| 20 | + * Gets an array of related entities with their post IDs and titles. |
|
| 21 | + * |
|
| 22 | + * @method get_analytics_event_data |
|
| 23 | + * @since 3.21.0 |
|
| 24 | + * |
|
| 25 | + * @param int $post_id post id we want related data for. |
|
| 26 | + * |
|
| 27 | + * @return array |
|
| 28 | + */ |
|
| 29 | + public static function get_analytics_event_data( $post_id ) { |
|
| 30 | + // If no ID was passed get current ID. |
|
| 31 | + if ( ! $post_id ) { |
|
| 32 | + $post_id = get_queried_object_id(); |
|
| 33 | + } |
|
| 34 | + /** |
|
| 35 | + * TODO: set/get this from cache. |
|
| 36 | + */ |
|
| 37 | + $related_items = array(); |
|
| 38 | + $related_ids = wl_core_get_related_entity_ids( $post_id ); |
|
| 39 | 39 | |
| 40 | - $entity_service = Wordlift_Entity_Service::get_instance(); |
|
| 41 | - // If the current item is also an entity then add it to the list of IDs. |
|
| 42 | - if ( $entity_service->is_entity( $post_id ) ) { |
|
| 43 | - $related_ids[] = $post_id; |
|
| 44 | - } |
|
| 45 | - $entity_type_service = Wordlift_Entity_Type_Service::get_instance(); |
|
| 46 | - // Get the post titles of related items and connect them in an array. |
|
| 47 | - foreach ( $related_ids as $related_id ) { |
|
| 48 | - $type = $entity_type_service->get( $related_id ); |
|
| 49 | - $type = isset( $type['uri'] ) ? $type['uri'] : 'unknown'; |
|
| 50 | - $label = $entity_service->get_labels( $related_id ); |
|
| 51 | - $label = $label[0]; |
|
| 40 | + $entity_service = Wordlift_Entity_Service::get_instance(); |
|
| 41 | + // If the current item is also an entity then add it to the list of IDs. |
|
| 42 | + if ( $entity_service->is_entity( $post_id ) ) { |
|
| 43 | + $related_ids[] = $post_id; |
|
| 44 | + } |
|
| 45 | + $entity_type_service = Wordlift_Entity_Type_Service::get_instance(); |
|
| 46 | + // Get the post titles of related items and connect them in an array. |
|
| 47 | + foreach ( $related_ids as $related_id ) { |
|
| 48 | + $type = $entity_type_service->get( $related_id ); |
|
| 49 | + $type = isset( $type['uri'] ) ? $type['uri'] : 'unknown'; |
|
| 50 | + $label = $entity_service->get_labels( $related_id ); |
|
| 51 | + $label = $label[0]; |
|
| 52 | 52 | |
| 53 | - $related_items[ $related_id ] = array( |
|
| 54 | - 'uri' => $entity_service->get_uri( $related_id ), |
|
| 55 | - 'type' => $type, |
|
| 56 | - 'label' => $label, |
|
| 57 | - ); |
|
| 58 | - } |
|
| 53 | + $related_items[ $related_id ] = array( |
|
| 54 | + 'uri' => $entity_service->get_uri( $related_id ), |
|
| 55 | + 'type' => $type, |
|
| 56 | + 'label' => $label, |
|
| 57 | + ); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - return $related_items; |
|
| 61 | - } |
|
| 60 | + return $related_items; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Gets the configuration data assosiated with the analytics settings. For |
|
| 65 | - * frontend script use primarily. |
|
| 66 | - * |
|
| 67 | - * @method get_analytics_config_data |
|
| 68 | - * @since 3.21.0 |
|
| 69 | - * @return array |
|
| 70 | - */ |
|
| 71 | - public static function get_analytics_config_data() { |
|
| 72 | - $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
| 73 | - // get some values from the config service. |
|
| 74 | - $config = array( |
|
| 75 | - 'entity_uri_dimension' => $configuration_service->get_analytics_entity_uri_dimension(), |
|
| 76 | - 'entity_type_dimension' => $configuration_service->get_analytics_entity_type_dimension(), |
|
| 77 | - ); |
|
| 63 | + /** |
|
| 64 | + * Gets the configuration data assosiated with the analytics settings. For |
|
| 65 | + * frontend script use primarily. |
|
| 66 | + * |
|
| 67 | + * @method get_analytics_config_data |
|
| 68 | + * @since 3.21.0 |
|
| 69 | + * @return array |
|
| 70 | + */ |
|
| 71 | + public static function get_analytics_config_data() { |
|
| 72 | + $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
| 73 | + // get some values from the config service. |
|
| 74 | + $config = array( |
|
| 75 | + 'entity_uri_dimension' => $configuration_service->get_analytics_entity_uri_dimension(), |
|
| 76 | + 'entity_type_dimension' => $configuration_service->get_analytics_entity_type_dimension(), |
|
| 77 | + ); |
|
| 78 | 78 | |
| 79 | - return $config; |
|
| 80 | - } |
|
| 79 | + return $config; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Enqueues our scripts for the frontend analytics handling and attaches |
|
| 84 | - * any data we will want to use there. |
|
| 85 | - * |
|
| 86 | - * @method enqueue_scripts |
|
| 87 | - * @since 3.21.0 |
|
| 88 | - */ |
|
| 89 | - public function enqueue_scripts() { |
|
| 90 | - $entity_data = self::get_analytics_event_data( get_the_ID() ); |
|
| 91 | - // Bail early if there is no event data that we would send. |
|
| 92 | - if ( ! $entity_data ) { |
|
| 93 | - return; |
|
| 94 | - } |
|
| 95 | - $data = self::get_analytics_config_data(); |
|
| 82 | + /** |
|
| 83 | + * Enqueues our scripts for the frontend analytics handling and attaches |
|
| 84 | + * any data we will want to use there. |
|
| 85 | + * |
|
| 86 | + * @method enqueue_scripts |
|
| 87 | + * @since 3.21.0 |
|
| 88 | + */ |
|
| 89 | + public function enqueue_scripts() { |
|
| 90 | + $entity_data = self::get_analytics_event_data( get_the_ID() ); |
|
| 91 | + // Bail early if there is no event data that we would send. |
|
| 92 | + if ( ! $entity_data ) { |
|
| 93 | + return; |
|
| 94 | + } |
|
| 95 | + $data = self::get_analytics_config_data(); |
|
| 96 | 96 | |
| 97 | - // Uses the analytics code in the main WordLift plugin. |
|
| 98 | - wp_localize_script( self::HANDLE, 'wordliftAnalyticsConfigData', $data ); |
|
| 99 | - wp_localize_script( self::HANDLE, 'wordliftAnalyticsEntityData', $entity_data ); |
|
| 100 | - } |
|
| 97 | + // Uses the analytics code in the main WordLift plugin. |
|
| 98 | + wp_localize_script( self::HANDLE, 'wordliftAnalyticsConfigData', $data ); |
|
| 99 | + wp_localize_script( self::HANDLE, 'wordliftAnalyticsEntityData', $entity_data ); |
|
| 100 | + } |
|
| 101 | 101 | } |
@@ -26,32 +26,32 @@ discard block |
||
| 26 | 26 | * |
| 27 | 27 | * @return array |
| 28 | 28 | */ |
| 29 | - public static function get_analytics_event_data( $post_id ) { |
|
| 29 | + public static function get_analytics_event_data($post_id) { |
|
| 30 | 30 | // If no ID was passed get current ID. |
| 31 | - if ( ! $post_id ) { |
|
| 31 | + if ( ! $post_id) { |
|
| 32 | 32 | $post_id = get_queried_object_id(); |
| 33 | 33 | } |
| 34 | 34 | /** |
| 35 | 35 | * TODO: set/get this from cache. |
| 36 | 36 | */ |
| 37 | 37 | $related_items = array(); |
| 38 | - $related_ids = wl_core_get_related_entity_ids( $post_id ); |
|
| 38 | + $related_ids = wl_core_get_related_entity_ids($post_id); |
|
| 39 | 39 | |
| 40 | 40 | $entity_service = Wordlift_Entity_Service::get_instance(); |
| 41 | 41 | // If the current item is also an entity then add it to the list of IDs. |
| 42 | - if ( $entity_service->is_entity( $post_id ) ) { |
|
| 42 | + if ($entity_service->is_entity($post_id)) { |
|
| 43 | 43 | $related_ids[] = $post_id; |
| 44 | 44 | } |
| 45 | 45 | $entity_type_service = Wordlift_Entity_Type_Service::get_instance(); |
| 46 | 46 | // Get the post titles of related items and connect them in an array. |
| 47 | - foreach ( $related_ids as $related_id ) { |
|
| 48 | - $type = $entity_type_service->get( $related_id ); |
|
| 49 | - $type = isset( $type['uri'] ) ? $type['uri'] : 'unknown'; |
|
| 50 | - $label = $entity_service->get_labels( $related_id ); |
|
| 47 | + foreach ($related_ids as $related_id) { |
|
| 48 | + $type = $entity_type_service->get($related_id); |
|
| 49 | + $type = isset($type['uri']) ? $type['uri'] : 'unknown'; |
|
| 50 | + $label = $entity_service->get_labels($related_id); |
|
| 51 | 51 | $label = $label[0]; |
| 52 | 52 | |
| 53 | - $related_items[ $related_id ] = array( |
|
| 54 | - 'uri' => $entity_service->get_uri( $related_id ), |
|
| 53 | + $related_items[$related_id] = array( |
|
| 54 | + 'uri' => $entity_service->get_uri($related_id), |
|
| 55 | 55 | 'type' => $type, |
| 56 | 56 | 'label' => $label, |
| 57 | 57 | ); |
@@ -87,15 +87,15 @@ discard block |
||
| 87 | 87 | * @since 3.21.0 |
| 88 | 88 | */ |
| 89 | 89 | public function enqueue_scripts() { |
| 90 | - $entity_data = self::get_analytics_event_data( get_the_ID() ); |
|
| 90 | + $entity_data = self::get_analytics_event_data(get_the_ID()); |
|
| 91 | 91 | // Bail early if there is no event data that we would send. |
| 92 | - if ( ! $entity_data ) { |
|
| 92 | + if ( ! $entity_data) { |
|
| 93 | 93 | return; |
| 94 | 94 | } |
| 95 | 95 | $data = self::get_analytics_config_data(); |
| 96 | 96 | |
| 97 | 97 | // Uses the analytics code in the main WordLift plugin. |
| 98 | - wp_localize_script( self::HANDLE, 'wordliftAnalyticsConfigData', $data ); |
|
| 99 | - wp_localize_script( self::HANDLE, 'wordliftAnalyticsEntityData', $entity_data ); |
|
| 98 | + wp_localize_script(self::HANDLE, 'wordliftAnalyticsConfigData', $data); |
|
| 99 | + wp_localize_script(self::HANDLE, 'wordliftAnalyticsEntityData', $entity_data); |
|
| 100 | 100 | } |
| 101 | 101 | } |
@@ -25,7 +25,7 @@ |
||
| 25 | 25 | public function process(ContainerBuilder $container) |
| 26 | 26 | { |
| 27 | 27 | foreach ($container->getExtensions() as $extension) { |
| 28 | - if (!$extension instanceof CompilerPassInterface) { |
|
| 28 | + if ( ! $extension instanceof CompilerPassInterface) { |
|
| 29 | 29 | continue; |
| 30 | 30 | } |
| 31 | 31 | $extension->process($container); |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare (strict_types=1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | namespace Wordlift\Modules\Common\Psr\Container; |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -2,6 +2,6 @@ |
||
| 2 | 2 | |
| 3 | 3 | // autoload.php @generated by Composer |
| 4 | 4 | |
| 5 | -require_once __DIR__ . '/composer/autoload_real.php'; |
|
| 5 | +require_once __DIR__.'/composer/autoload_real.php'; |
|
| 6 | 6 | |
| 7 | 7 | return ComposerAutoloaderInit9b4e3e175e03285e60ba6309cc2e3477::getLoader(); |
@@ -5,22 +5,22 @@ |
||
| 5 | 5 | $issues = array(); |
| 6 | 6 | |
| 7 | 7 | if ( ! ( PHP_VERSION_ID >= 50200 ) ) { |
| 8 | - $issues[] = 'Your Composer dependencies require a PHP version ">= 5.2.0". You are running ' . PHP_VERSION . '.'; |
|
| 8 | + $issues[] = 'Your Composer dependencies require a PHP version ">= 5.2.0". You are running ' . PHP_VERSION . '.'; |
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | if ( $issues ) { |
| 12 | - if ( ! headers_sent() ) { |
|
| 13 | - header( 'HTTP/1.1 500 Internal Server Error' ); |
|
| 14 | - } |
|
| 15 | - if ( ! ini_get( 'display_errors' ) ) { |
|
| 16 | - if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) { |
|
| 17 | - fwrite( STDERR, 'Composer detected issues in your platform:' . PHP_EOL . PHP_EOL . implode( PHP_EOL, $issues ) . PHP_EOL . PHP_EOL ); |
|
| 18 | - } elseif ( ! headers_sent() ) { |
|
| 19 | - echo 'Composer detected issues in your platform:' . PHP_EOL . PHP_EOL . str_replace( 'You are running ' . PHP_VERSION . '.', '', implode( PHP_EOL, $issues ) ) . PHP_EOL . PHP_EOL; |
|
| 20 | - } |
|
| 21 | - } |
|
| 22 | - trigger_error( |
|
| 23 | - 'Composer detected issues in your platform: ' . implode( ' ', $issues ), |
|
| 24 | - E_USER_ERROR |
|
| 25 | - ); |
|
| 12 | + if ( ! headers_sent() ) { |
|
| 13 | + header( 'HTTP/1.1 500 Internal Server Error' ); |
|
| 14 | + } |
|
| 15 | + if ( ! ini_get( 'display_errors' ) ) { |
|
| 16 | + if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) { |
|
| 17 | + fwrite( STDERR, 'Composer detected issues in your platform:' . PHP_EOL . PHP_EOL . implode( PHP_EOL, $issues ) . PHP_EOL . PHP_EOL ); |
|
| 18 | + } elseif ( ! headers_sent() ) { |
|
| 19 | + echo 'Composer detected issues in your platform:' . PHP_EOL . PHP_EOL . str_replace( 'You are running ' . PHP_VERSION . '.', '', implode( PHP_EOL, $issues ) ) . PHP_EOL . PHP_EOL; |
|
| 20 | + } |
|
| 21 | + } |
|
| 22 | + trigger_error( |
|
| 23 | + 'Composer detected issues in your platform: ' . implode( ' ', $issues ), |
|
| 24 | + E_USER_ERROR |
|
| 25 | + ); |
|
| 26 | 26 | } |
@@ -4,23 +4,23 @@ |
||
| 4 | 4 | |
| 5 | 5 | $issues = array(); |
| 6 | 6 | |
| 7 | -if ( ! ( PHP_VERSION_ID >= 50200 ) ) { |
|
| 8 | - $issues[] = 'Your Composer dependencies require a PHP version ">= 5.2.0". You are running ' . PHP_VERSION . '.'; |
|
| 7 | +if ( ! (PHP_VERSION_ID >= 50200)) { |
|
| 8 | + $issues[] = 'Your Composer dependencies require a PHP version ">= 5.2.0". You are running '.PHP_VERSION.'.'; |
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | -if ( $issues ) { |
|
| 12 | - if ( ! headers_sent() ) { |
|
| 13 | - header( 'HTTP/1.1 500 Internal Server Error' ); |
|
| 11 | +if ($issues) { |
|
| 12 | + if ( ! headers_sent()) { |
|
| 13 | + header('HTTP/1.1 500 Internal Server Error'); |
|
| 14 | 14 | } |
| 15 | - if ( ! ini_get( 'display_errors' ) ) { |
|
| 16 | - if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) { |
|
| 17 | - fwrite( STDERR, 'Composer detected issues in your platform:' . PHP_EOL . PHP_EOL . implode( PHP_EOL, $issues ) . PHP_EOL . PHP_EOL ); |
|
| 18 | - } elseif ( ! headers_sent() ) { |
|
| 19 | - echo 'Composer detected issues in your platform:' . PHP_EOL . PHP_EOL . str_replace( 'You are running ' . PHP_VERSION . '.', '', implode( PHP_EOL, $issues ) ) . PHP_EOL . PHP_EOL; |
|
| 15 | + if ( ! ini_get('display_errors')) { |
|
| 16 | + if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') { |
|
| 17 | + fwrite(STDERR, 'Composer detected issues in your platform:'.PHP_EOL.PHP_EOL.implode(PHP_EOL, $issues).PHP_EOL.PHP_EOL); |
|
| 18 | + } elseif ( ! headers_sent()) { |
|
| 19 | + echo 'Composer detected issues in your platform:'.PHP_EOL.PHP_EOL.str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)).PHP_EOL.PHP_EOL; |
|
| 20 | 20 | } |
| 21 | 21 | } |
| 22 | 22 | trigger_error( |
| 23 | - 'Composer detected issues in your platform: ' . implode( ' ', $issues ), |
|
| 23 | + 'Composer detected issues in your platform: '.implode(' ', $issues), |
|
| 24 | 24 | E_USER_ERROR |
| 25 | 25 | ); |
| 26 | 26 | } |
@@ -42,375 +42,375 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | class ClassLoader { |
| 44 | 44 | |
| 45 | - // PSR-4 |
|
| 46 | - private $prefixLengthsPsr4 = array(); |
|
| 47 | - private $prefixDirsPsr4 = array(); |
|
| 48 | - private $fallbackDirsPsr4 = array(); |
|
| 49 | - |
|
| 50 | - // PSR-0 |
|
| 51 | - private $prefixesPsr0 = array(); |
|
| 52 | - private $fallbackDirsPsr0 = array(); |
|
| 53 | - |
|
| 54 | - private $useIncludePath = false; |
|
| 55 | - private $classMap = array(); |
|
| 56 | - private $classMapAuthoritative = false; |
|
| 57 | - private $missingClasses = array(); |
|
| 58 | - private $apcuPrefix; |
|
| 59 | - |
|
| 60 | - public function getPrefixes() { |
|
| 61 | - if ( ! empty( $this->prefixesPsr0 ) ) { |
|
| 62 | - return call_user_func_array( 'array_merge', array_values( $this->prefixesPsr0 ) ); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - return array(); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - public function getPrefixesPsr4() { |
|
| 69 | - return $this->prefixDirsPsr4; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - public function getFallbackDirs() { |
|
| 73 | - return $this->fallbackDirsPsr0; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - public function getFallbackDirsPsr4() { |
|
| 77 | - return $this->fallbackDirsPsr4; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - public function getClassMap() { |
|
| 81 | - return $this->classMap; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @param array $classMap Class to filename map |
|
| 86 | - */ |
|
| 87 | - public function addClassMap( array $classMap ) { |
|
| 88 | - if ( $this->classMap ) { |
|
| 89 | - $this->classMap = array_merge( $this->classMap, $classMap ); |
|
| 90 | - } else { |
|
| 91 | - $this->classMap = $classMap; |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Registers a set of PSR-0 directories for a given prefix, either |
|
| 97 | - * appending or prepending to the ones previously set for this prefix. |
|
| 98 | - * |
|
| 99 | - * @param string $prefix The prefix |
|
| 100 | - * @param array|string $paths The PSR-0 root directories |
|
| 101 | - * @param bool $prepend Whether to prepend the directories |
|
| 102 | - */ |
|
| 103 | - public function add( $prefix, $paths, $prepend = false ) { |
|
| 104 | - if ( ! $prefix ) { |
|
| 105 | - if ( $prepend ) { |
|
| 106 | - $this->fallbackDirsPsr0 = array_merge( |
|
| 107 | - (array) $paths, |
|
| 108 | - $this->fallbackDirsPsr0 |
|
| 109 | - ); |
|
| 110 | - } else { |
|
| 111 | - $this->fallbackDirsPsr0 = array_merge( |
|
| 112 | - $this->fallbackDirsPsr0, |
|
| 113 | - (array) $paths |
|
| 114 | - ); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - return; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - $first = $prefix[0]; |
|
| 121 | - if ( ! isset( $this->prefixesPsr0[ $first ][ $prefix ] ) ) { |
|
| 122 | - $this->prefixesPsr0[ $first ][ $prefix ] = (array) $paths; |
|
| 123 | - |
|
| 124 | - return; |
|
| 125 | - } |
|
| 126 | - if ( $prepend ) { |
|
| 127 | - $this->prefixesPsr0[ $first ][ $prefix ] = array_merge( |
|
| 128 | - (array) $paths, |
|
| 129 | - $this->prefixesPsr0[ $first ][ $prefix ] |
|
| 130 | - ); |
|
| 131 | - } else { |
|
| 132 | - $this->prefixesPsr0[ $first ][ $prefix ] = array_merge( |
|
| 133 | - $this->prefixesPsr0[ $first ][ $prefix ], |
|
| 134 | - (array) $paths |
|
| 135 | - ); |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Registers a set of PSR-4 directories for a given namespace, either |
|
| 141 | - * appending or prepending to the ones previously set for this namespace. |
|
| 142 | - * |
|
| 143 | - * @param string $prefix The prefix/namespace, with trailing '\\' |
|
| 144 | - * @param array|string $paths The PSR-4 base directories |
|
| 145 | - * @param bool $prepend Whether to prepend the directories |
|
| 146 | - * |
|
| 147 | - * @throws \InvalidArgumentException |
|
| 148 | - */ |
|
| 149 | - public function addPsr4( $prefix, $paths, $prepend = false ) { |
|
| 150 | - if ( ! $prefix ) { |
|
| 151 | - // Register directories for the root namespace. |
|
| 152 | - if ( $prepend ) { |
|
| 153 | - $this->fallbackDirsPsr4 = array_merge( |
|
| 154 | - (array) $paths, |
|
| 155 | - $this->fallbackDirsPsr4 |
|
| 156 | - ); |
|
| 157 | - } else { |
|
| 158 | - $this->fallbackDirsPsr4 = array_merge( |
|
| 159 | - $this->fallbackDirsPsr4, |
|
| 160 | - (array) $paths |
|
| 161 | - ); |
|
| 162 | - } |
|
| 163 | - } elseif ( ! isset( $this->prefixDirsPsr4[ $prefix ] ) ) { |
|
| 164 | - // Register directories for a new namespace. |
|
| 165 | - $length = strlen( $prefix ); |
|
| 166 | - if ( '\\' !== $prefix[ $length - 1 ] ) { |
|
| 167 | - throw new \InvalidArgumentException( 'A non-empty PSR-4 prefix must end with a namespace separator.' ); |
|
| 168 | - } |
|
| 169 | - $this->prefixLengthsPsr4[ $prefix[0] ][ $prefix ] = $length; |
|
| 170 | - $this->prefixDirsPsr4[ $prefix ] = (array) $paths; |
|
| 171 | - } elseif ( $prepend ) { |
|
| 172 | - // Prepend directories for an already registered namespace. |
|
| 173 | - $this->prefixDirsPsr4[ $prefix ] = array_merge( |
|
| 174 | - (array) $paths, |
|
| 175 | - $this->prefixDirsPsr4[ $prefix ] |
|
| 176 | - ); |
|
| 177 | - } else { |
|
| 178 | - // Append directories for an already registered namespace. |
|
| 179 | - $this->prefixDirsPsr4[ $prefix ] = array_merge( |
|
| 180 | - $this->prefixDirsPsr4[ $prefix ], |
|
| 181 | - (array) $paths |
|
| 182 | - ); |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * Registers a set of PSR-0 directories for a given prefix, |
|
| 188 | - * replacing any others previously set for this prefix. |
|
| 189 | - * |
|
| 190 | - * @param string $prefix The prefix |
|
| 191 | - * @param array|string $paths The PSR-0 base directories |
|
| 192 | - */ |
|
| 193 | - public function set( $prefix, $paths ) { |
|
| 194 | - if ( ! $prefix ) { |
|
| 195 | - $this->fallbackDirsPsr0 = (array) $paths; |
|
| 196 | - } else { |
|
| 197 | - $this->prefixesPsr0[ $prefix[0] ][ $prefix ] = (array) $paths; |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * Registers a set of PSR-4 directories for a given namespace, |
|
| 203 | - * replacing any others previously set for this namespace. |
|
| 204 | - * |
|
| 205 | - * @param string $prefix The prefix/namespace, with trailing '\\' |
|
| 206 | - * @param array|string $paths The PSR-4 base directories |
|
| 207 | - * |
|
| 208 | - * @throws \InvalidArgumentException |
|
| 209 | - */ |
|
| 210 | - public function setPsr4( $prefix, $paths ) { |
|
| 211 | - if ( ! $prefix ) { |
|
| 212 | - $this->fallbackDirsPsr4 = (array) $paths; |
|
| 213 | - } else { |
|
| 214 | - $length = strlen( $prefix ); |
|
| 215 | - if ( '\\' !== $prefix[ $length - 1 ] ) { |
|
| 216 | - throw new \InvalidArgumentException( 'A non-empty PSR-4 prefix must end with a namespace separator.' ); |
|
| 217 | - } |
|
| 218 | - $this->prefixLengthsPsr4[ $prefix[0] ][ $prefix ] = $length; |
|
| 219 | - $this->prefixDirsPsr4[ $prefix ] = (array) $paths; |
|
| 220 | - } |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * Turns on searching the include path for class files. |
|
| 225 | - * |
|
| 226 | - * @param bool $useIncludePath |
|
| 227 | - */ |
|
| 228 | - public function setUseIncludePath( $useIncludePath ) { |
|
| 229 | - $this->useIncludePath = $useIncludePath; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * Can be used to check if the autoloader uses the include path to check |
|
| 234 | - * for classes. |
|
| 235 | - * |
|
| 236 | - * @return bool |
|
| 237 | - */ |
|
| 238 | - public function getUseIncludePath() { |
|
| 239 | - return $this->useIncludePath; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * Turns off searching the prefix and fallback directories for classes |
|
| 244 | - * that have not been registered with the class map. |
|
| 245 | - * |
|
| 246 | - * @param bool $classMapAuthoritative |
|
| 247 | - */ |
|
| 248 | - public function setClassMapAuthoritative( $classMapAuthoritative ) { |
|
| 249 | - $this->classMapAuthoritative = $classMapAuthoritative; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * Should class lookup fail if not found in the current class map? |
|
| 254 | - * |
|
| 255 | - * @return bool |
|
| 256 | - */ |
|
| 257 | - public function isClassMapAuthoritative() { |
|
| 258 | - return $this->classMapAuthoritative; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * APCu prefix to use to cache found/not-found classes, if the extension is enabled. |
|
| 263 | - * |
|
| 264 | - * @param string|null $apcuPrefix |
|
| 265 | - */ |
|
| 266 | - public function setApcuPrefix( $apcuPrefix ) { |
|
| 267 | - $this->apcuPrefix = function_exists( 'apcu_fetch' ) && filter_var( ini_get( 'apc.enabled' ), FILTER_VALIDATE_BOOLEAN ) ? $apcuPrefix : null; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * The APCu prefix in use, or null if APCu caching is not enabled. |
|
| 272 | - * |
|
| 273 | - * @return string|null |
|
| 274 | - */ |
|
| 275 | - public function getApcuPrefix() { |
|
| 276 | - return $this->apcuPrefix; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * Registers this instance as an autoloader. |
|
| 281 | - * |
|
| 282 | - * @param bool $prepend Whether to prepend the autoloader or not |
|
| 283 | - */ |
|
| 284 | - public function register( $prepend = false ) { |
|
| 285 | - spl_autoload_register( array( $this, 'loadClass' ), true, $prepend ); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * Unregisters this instance as an autoloader. |
|
| 290 | - */ |
|
| 291 | - public function unregister() { |
|
| 292 | - spl_autoload_unregister( array( $this, 'loadClass' ) ); |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * Loads the given class or interface. |
|
| 297 | - * |
|
| 298 | - * @param string $class The name of the class |
|
| 299 | - * @return bool|null True if loaded, null otherwise |
|
| 300 | - */ |
|
| 301 | - public function loadClass( $class ) { |
|
| 302 | - if ( $file = $this->findFile( $class ) ) { |
|
| 303 | - includeFile( $file ); |
|
| 304 | - |
|
| 305 | - return true; |
|
| 306 | - } |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * Finds the path to the file where the class is defined. |
|
| 311 | - * |
|
| 312 | - * @param string $class The name of the class |
|
| 313 | - * |
|
| 314 | - * @return string|false The path if found, false otherwise |
|
| 315 | - */ |
|
| 316 | - public function findFile( $class ) { |
|
| 317 | - // class map lookup |
|
| 318 | - if ( isset( $this->classMap[ $class ] ) ) { |
|
| 319 | - return $this->classMap[ $class ]; |
|
| 320 | - } |
|
| 321 | - if ( $this->classMapAuthoritative || isset( $this->missingClasses[ $class ] ) ) { |
|
| 322 | - return false; |
|
| 323 | - } |
|
| 324 | - if ( null !== $this->apcuPrefix ) { |
|
| 325 | - $file = apcu_fetch( $this->apcuPrefix . $class, $hit ); |
|
| 326 | - if ( $hit ) { |
|
| 327 | - return $file; |
|
| 328 | - } |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - $file = $this->findFileWithExtension( $class, '.php' ); |
|
| 332 | - |
|
| 333 | - // Search for Hack files if we are running on HHVM |
|
| 334 | - if ( false === $file && defined( 'HHVM_VERSION' ) ) { |
|
| 335 | - $file = $this->findFileWithExtension( $class, '.hh' ); |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - if ( null !== $this->apcuPrefix ) { |
|
| 339 | - apcu_add( $this->apcuPrefix . $class, $file ); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - if ( false === $file ) { |
|
| 343 | - // Remember that this class does not exist. |
|
| 344 | - $this->missingClasses[ $class ] = true; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - return $file; |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - private function findFileWithExtension( $class, $ext ) { |
|
| 351 | - // PSR-4 lookup |
|
| 352 | - $logicalPathPsr4 = strtr( $class, '\\', DIRECTORY_SEPARATOR ) . $ext; |
|
| 353 | - |
|
| 354 | - $first = $class[0]; |
|
| 355 | - if ( isset( $this->prefixLengthsPsr4[ $first ] ) ) { |
|
| 356 | - $subPath = $class; |
|
| 357 | - while ( false !== $lastPos = strrpos( $subPath, '\\' ) ) { |
|
| 358 | - $subPath = substr( $subPath, 0, $lastPos ); |
|
| 359 | - $search = $subPath . '\\'; |
|
| 360 | - if ( isset( $this->prefixDirsPsr4[ $search ] ) ) { |
|
| 361 | - $pathEnd = DIRECTORY_SEPARATOR . substr( $logicalPathPsr4, $lastPos + 1 ); |
|
| 362 | - foreach ( $this->prefixDirsPsr4[ $search ] as $dir ) { |
|
| 363 | - if ( file_exists( $file = $dir . $pathEnd ) ) { |
|
| 364 | - return $file; |
|
| 365 | - } |
|
| 366 | - } |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - // PSR-4 fallback dirs |
|
| 372 | - foreach ( $this->fallbackDirsPsr4 as $dir ) { |
|
| 373 | - if ( file_exists( $file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4 ) ) { |
|
| 374 | - return $file; |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - // PSR-0 lookup |
|
| 379 | - if ( false !== $pos = strrpos( $class, '\\' ) ) { |
|
| 380 | - // namespaced class name |
|
| 381 | - $logicalPathPsr0 = substr( $logicalPathPsr4, 0, $pos + 1 ) |
|
| 382 | - . strtr( substr( $logicalPathPsr4, $pos + 1 ), '_', DIRECTORY_SEPARATOR ); |
|
| 383 | - } else { |
|
| 384 | - // PEAR-like class name |
|
| 385 | - $logicalPathPsr0 = strtr( $class, '_', DIRECTORY_SEPARATOR ) . $ext; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - if ( isset( $this->prefixesPsr0[ $first ] ) ) { |
|
| 389 | - foreach ( $this->prefixesPsr0[ $first ] as $prefix => $dirs ) { |
|
| 390 | - if ( 0 === strpos( $class, $prefix ) ) { |
|
| 391 | - foreach ( $dirs as $dir ) { |
|
| 392 | - if ( file_exists( $file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0 ) ) { |
|
| 393 | - return $file; |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - } |
|
| 397 | - } |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - // PSR-0 fallback dirs |
|
| 401 | - foreach ( $this->fallbackDirsPsr0 as $dir ) { |
|
| 402 | - if ( file_exists( $file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0 ) ) { |
|
| 403 | - return $file; |
|
| 404 | - } |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - // PSR-0 include paths. |
|
| 408 | - if ( $this->useIncludePath && $file = stream_resolve_include_path( $logicalPathPsr0 ) ) { |
|
| 409 | - return $file; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - return false; |
|
| 413 | - } |
|
| 45 | + // PSR-4 |
|
| 46 | + private $prefixLengthsPsr4 = array(); |
|
| 47 | + private $prefixDirsPsr4 = array(); |
|
| 48 | + private $fallbackDirsPsr4 = array(); |
|
| 49 | + |
|
| 50 | + // PSR-0 |
|
| 51 | + private $prefixesPsr0 = array(); |
|
| 52 | + private $fallbackDirsPsr0 = array(); |
|
| 53 | + |
|
| 54 | + private $useIncludePath = false; |
|
| 55 | + private $classMap = array(); |
|
| 56 | + private $classMapAuthoritative = false; |
|
| 57 | + private $missingClasses = array(); |
|
| 58 | + private $apcuPrefix; |
|
| 59 | + |
|
| 60 | + public function getPrefixes() { |
|
| 61 | + if ( ! empty( $this->prefixesPsr0 ) ) { |
|
| 62 | + return call_user_func_array( 'array_merge', array_values( $this->prefixesPsr0 ) ); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + return array(); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + public function getPrefixesPsr4() { |
|
| 69 | + return $this->prefixDirsPsr4; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + public function getFallbackDirs() { |
|
| 73 | + return $this->fallbackDirsPsr0; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + public function getFallbackDirsPsr4() { |
|
| 77 | + return $this->fallbackDirsPsr4; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + public function getClassMap() { |
|
| 81 | + return $this->classMap; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @param array $classMap Class to filename map |
|
| 86 | + */ |
|
| 87 | + public function addClassMap( array $classMap ) { |
|
| 88 | + if ( $this->classMap ) { |
|
| 89 | + $this->classMap = array_merge( $this->classMap, $classMap ); |
|
| 90 | + } else { |
|
| 91 | + $this->classMap = $classMap; |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Registers a set of PSR-0 directories for a given prefix, either |
|
| 97 | + * appending or prepending to the ones previously set for this prefix. |
|
| 98 | + * |
|
| 99 | + * @param string $prefix The prefix |
|
| 100 | + * @param array|string $paths The PSR-0 root directories |
|
| 101 | + * @param bool $prepend Whether to prepend the directories |
|
| 102 | + */ |
|
| 103 | + public function add( $prefix, $paths, $prepend = false ) { |
|
| 104 | + if ( ! $prefix ) { |
|
| 105 | + if ( $prepend ) { |
|
| 106 | + $this->fallbackDirsPsr0 = array_merge( |
|
| 107 | + (array) $paths, |
|
| 108 | + $this->fallbackDirsPsr0 |
|
| 109 | + ); |
|
| 110 | + } else { |
|
| 111 | + $this->fallbackDirsPsr0 = array_merge( |
|
| 112 | + $this->fallbackDirsPsr0, |
|
| 113 | + (array) $paths |
|
| 114 | + ); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + return; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + $first = $prefix[0]; |
|
| 121 | + if ( ! isset( $this->prefixesPsr0[ $first ][ $prefix ] ) ) { |
|
| 122 | + $this->prefixesPsr0[ $first ][ $prefix ] = (array) $paths; |
|
| 123 | + |
|
| 124 | + return; |
|
| 125 | + } |
|
| 126 | + if ( $prepend ) { |
|
| 127 | + $this->prefixesPsr0[ $first ][ $prefix ] = array_merge( |
|
| 128 | + (array) $paths, |
|
| 129 | + $this->prefixesPsr0[ $first ][ $prefix ] |
|
| 130 | + ); |
|
| 131 | + } else { |
|
| 132 | + $this->prefixesPsr0[ $first ][ $prefix ] = array_merge( |
|
| 133 | + $this->prefixesPsr0[ $first ][ $prefix ], |
|
| 134 | + (array) $paths |
|
| 135 | + ); |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Registers a set of PSR-4 directories for a given namespace, either |
|
| 141 | + * appending or prepending to the ones previously set for this namespace. |
|
| 142 | + * |
|
| 143 | + * @param string $prefix The prefix/namespace, with trailing '\\' |
|
| 144 | + * @param array|string $paths The PSR-4 base directories |
|
| 145 | + * @param bool $prepend Whether to prepend the directories |
|
| 146 | + * |
|
| 147 | + * @throws \InvalidArgumentException |
|
| 148 | + */ |
|
| 149 | + public function addPsr4( $prefix, $paths, $prepend = false ) { |
|
| 150 | + if ( ! $prefix ) { |
|
| 151 | + // Register directories for the root namespace. |
|
| 152 | + if ( $prepend ) { |
|
| 153 | + $this->fallbackDirsPsr4 = array_merge( |
|
| 154 | + (array) $paths, |
|
| 155 | + $this->fallbackDirsPsr4 |
|
| 156 | + ); |
|
| 157 | + } else { |
|
| 158 | + $this->fallbackDirsPsr4 = array_merge( |
|
| 159 | + $this->fallbackDirsPsr4, |
|
| 160 | + (array) $paths |
|
| 161 | + ); |
|
| 162 | + } |
|
| 163 | + } elseif ( ! isset( $this->prefixDirsPsr4[ $prefix ] ) ) { |
|
| 164 | + // Register directories for a new namespace. |
|
| 165 | + $length = strlen( $prefix ); |
|
| 166 | + if ( '\\' !== $prefix[ $length - 1 ] ) { |
|
| 167 | + throw new \InvalidArgumentException( 'A non-empty PSR-4 prefix must end with a namespace separator.' ); |
|
| 168 | + } |
|
| 169 | + $this->prefixLengthsPsr4[ $prefix[0] ][ $prefix ] = $length; |
|
| 170 | + $this->prefixDirsPsr4[ $prefix ] = (array) $paths; |
|
| 171 | + } elseif ( $prepend ) { |
|
| 172 | + // Prepend directories for an already registered namespace. |
|
| 173 | + $this->prefixDirsPsr4[ $prefix ] = array_merge( |
|
| 174 | + (array) $paths, |
|
| 175 | + $this->prefixDirsPsr4[ $prefix ] |
|
| 176 | + ); |
|
| 177 | + } else { |
|
| 178 | + // Append directories for an already registered namespace. |
|
| 179 | + $this->prefixDirsPsr4[ $prefix ] = array_merge( |
|
| 180 | + $this->prefixDirsPsr4[ $prefix ], |
|
| 181 | + (array) $paths |
|
| 182 | + ); |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * Registers a set of PSR-0 directories for a given prefix, |
|
| 188 | + * replacing any others previously set for this prefix. |
|
| 189 | + * |
|
| 190 | + * @param string $prefix The prefix |
|
| 191 | + * @param array|string $paths The PSR-0 base directories |
|
| 192 | + */ |
|
| 193 | + public function set( $prefix, $paths ) { |
|
| 194 | + if ( ! $prefix ) { |
|
| 195 | + $this->fallbackDirsPsr0 = (array) $paths; |
|
| 196 | + } else { |
|
| 197 | + $this->prefixesPsr0[ $prefix[0] ][ $prefix ] = (array) $paths; |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * Registers a set of PSR-4 directories for a given namespace, |
|
| 203 | + * replacing any others previously set for this namespace. |
|
| 204 | + * |
|
| 205 | + * @param string $prefix The prefix/namespace, with trailing '\\' |
|
| 206 | + * @param array|string $paths The PSR-4 base directories |
|
| 207 | + * |
|
| 208 | + * @throws \InvalidArgumentException |
|
| 209 | + */ |
|
| 210 | + public function setPsr4( $prefix, $paths ) { |
|
| 211 | + if ( ! $prefix ) { |
|
| 212 | + $this->fallbackDirsPsr4 = (array) $paths; |
|
| 213 | + } else { |
|
| 214 | + $length = strlen( $prefix ); |
|
| 215 | + if ( '\\' !== $prefix[ $length - 1 ] ) { |
|
| 216 | + throw new \InvalidArgumentException( 'A non-empty PSR-4 prefix must end with a namespace separator.' ); |
|
| 217 | + } |
|
| 218 | + $this->prefixLengthsPsr4[ $prefix[0] ][ $prefix ] = $length; |
|
| 219 | + $this->prefixDirsPsr4[ $prefix ] = (array) $paths; |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * Turns on searching the include path for class files. |
|
| 225 | + * |
|
| 226 | + * @param bool $useIncludePath |
|
| 227 | + */ |
|
| 228 | + public function setUseIncludePath( $useIncludePath ) { |
|
| 229 | + $this->useIncludePath = $useIncludePath; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * Can be used to check if the autoloader uses the include path to check |
|
| 234 | + * for classes. |
|
| 235 | + * |
|
| 236 | + * @return bool |
|
| 237 | + */ |
|
| 238 | + public function getUseIncludePath() { |
|
| 239 | + return $this->useIncludePath; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * Turns off searching the prefix and fallback directories for classes |
|
| 244 | + * that have not been registered with the class map. |
|
| 245 | + * |
|
| 246 | + * @param bool $classMapAuthoritative |
|
| 247 | + */ |
|
| 248 | + public function setClassMapAuthoritative( $classMapAuthoritative ) { |
|
| 249 | + $this->classMapAuthoritative = $classMapAuthoritative; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * Should class lookup fail if not found in the current class map? |
|
| 254 | + * |
|
| 255 | + * @return bool |
|
| 256 | + */ |
|
| 257 | + public function isClassMapAuthoritative() { |
|
| 258 | + return $this->classMapAuthoritative; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * APCu prefix to use to cache found/not-found classes, if the extension is enabled. |
|
| 263 | + * |
|
| 264 | + * @param string|null $apcuPrefix |
|
| 265 | + */ |
|
| 266 | + public function setApcuPrefix( $apcuPrefix ) { |
|
| 267 | + $this->apcuPrefix = function_exists( 'apcu_fetch' ) && filter_var( ini_get( 'apc.enabled' ), FILTER_VALIDATE_BOOLEAN ) ? $apcuPrefix : null; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * The APCu prefix in use, or null if APCu caching is not enabled. |
|
| 272 | + * |
|
| 273 | + * @return string|null |
|
| 274 | + */ |
|
| 275 | + public function getApcuPrefix() { |
|
| 276 | + return $this->apcuPrefix; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * Registers this instance as an autoloader. |
|
| 281 | + * |
|
| 282 | + * @param bool $prepend Whether to prepend the autoloader or not |
|
| 283 | + */ |
|
| 284 | + public function register( $prepend = false ) { |
|
| 285 | + spl_autoload_register( array( $this, 'loadClass' ), true, $prepend ); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * Unregisters this instance as an autoloader. |
|
| 290 | + */ |
|
| 291 | + public function unregister() { |
|
| 292 | + spl_autoload_unregister( array( $this, 'loadClass' ) ); |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * Loads the given class or interface. |
|
| 297 | + * |
|
| 298 | + * @param string $class The name of the class |
|
| 299 | + * @return bool|null True if loaded, null otherwise |
|
| 300 | + */ |
|
| 301 | + public function loadClass( $class ) { |
|
| 302 | + if ( $file = $this->findFile( $class ) ) { |
|
| 303 | + includeFile( $file ); |
|
| 304 | + |
|
| 305 | + return true; |
|
| 306 | + } |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * Finds the path to the file where the class is defined. |
|
| 311 | + * |
|
| 312 | + * @param string $class The name of the class |
|
| 313 | + * |
|
| 314 | + * @return string|false The path if found, false otherwise |
|
| 315 | + */ |
|
| 316 | + public function findFile( $class ) { |
|
| 317 | + // class map lookup |
|
| 318 | + if ( isset( $this->classMap[ $class ] ) ) { |
|
| 319 | + return $this->classMap[ $class ]; |
|
| 320 | + } |
|
| 321 | + if ( $this->classMapAuthoritative || isset( $this->missingClasses[ $class ] ) ) { |
|
| 322 | + return false; |
|
| 323 | + } |
|
| 324 | + if ( null !== $this->apcuPrefix ) { |
|
| 325 | + $file = apcu_fetch( $this->apcuPrefix . $class, $hit ); |
|
| 326 | + if ( $hit ) { |
|
| 327 | + return $file; |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + $file = $this->findFileWithExtension( $class, '.php' ); |
|
| 332 | + |
|
| 333 | + // Search for Hack files if we are running on HHVM |
|
| 334 | + if ( false === $file && defined( 'HHVM_VERSION' ) ) { |
|
| 335 | + $file = $this->findFileWithExtension( $class, '.hh' ); |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + if ( null !== $this->apcuPrefix ) { |
|
| 339 | + apcu_add( $this->apcuPrefix . $class, $file ); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + if ( false === $file ) { |
|
| 343 | + // Remember that this class does not exist. |
|
| 344 | + $this->missingClasses[ $class ] = true; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + return $file; |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + private function findFileWithExtension( $class, $ext ) { |
|
| 351 | + // PSR-4 lookup |
|
| 352 | + $logicalPathPsr4 = strtr( $class, '\\', DIRECTORY_SEPARATOR ) . $ext; |
|
| 353 | + |
|
| 354 | + $first = $class[0]; |
|
| 355 | + if ( isset( $this->prefixLengthsPsr4[ $first ] ) ) { |
|
| 356 | + $subPath = $class; |
|
| 357 | + while ( false !== $lastPos = strrpos( $subPath, '\\' ) ) { |
|
| 358 | + $subPath = substr( $subPath, 0, $lastPos ); |
|
| 359 | + $search = $subPath . '\\'; |
|
| 360 | + if ( isset( $this->prefixDirsPsr4[ $search ] ) ) { |
|
| 361 | + $pathEnd = DIRECTORY_SEPARATOR . substr( $logicalPathPsr4, $lastPos + 1 ); |
|
| 362 | + foreach ( $this->prefixDirsPsr4[ $search ] as $dir ) { |
|
| 363 | + if ( file_exists( $file = $dir . $pathEnd ) ) { |
|
| 364 | + return $file; |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + // PSR-4 fallback dirs |
|
| 372 | + foreach ( $this->fallbackDirsPsr4 as $dir ) { |
|
| 373 | + if ( file_exists( $file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4 ) ) { |
|
| 374 | + return $file; |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + // PSR-0 lookup |
|
| 379 | + if ( false !== $pos = strrpos( $class, '\\' ) ) { |
|
| 380 | + // namespaced class name |
|
| 381 | + $logicalPathPsr0 = substr( $logicalPathPsr4, 0, $pos + 1 ) |
|
| 382 | + . strtr( substr( $logicalPathPsr4, $pos + 1 ), '_', DIRECTORY_SEPARATOR ); |
|
| 383 | + } else { |
|
| 384 | + // PEAR-like class name |
|
| 385 | + $logicalPathPsr0 = strtr( $class, '_', DIRECTORY_SEPARATOR ) . $ext; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + if ( isset( $this->prefixesPsr0[ $first ] ) ) { |
|
| 389 | + foreach ( $this->prefixesPsr0[ $first ] as $prefix => $dirs ) { |
|
| 390 | + if ( 0 === strpos( $class, $prefix ) ) { |
|
| 391 | + foreach ( $dirs as $dir ) { |
|
| 392 | + if ( file_exists( $file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0 ) ) { |
|
| 393 | + return $file; |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + // PSR-0 fallback dirs |
|
| 401 | + foreach ( $this->fallbackDirsPsr0 as $dir ) { |
|
| 402 | + if ( file_exists( $file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0 ) ) { |
|
| 403 | + return $file; |
|
| 404 | + } |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + // PSR-0 include paths. |
|
| 408 | + if ( $this->useIncludePath && $file = stream_resolve_include_path( $logicalPathPsr0 ) ) { |
|
| 409 | + return $file; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + return false; |
|
| 413 | + } |
|
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | /** |
@@ -419,5 +419,5 @@ discard block |
||
| 419 | 419 | * Prevents access to $this/self from included files. |
| 420 | 420 | */ |
| 421 | 421 | function includeFile( $file ) { |
| 422 | - include $file; |
|
| 422 | + include $file; |
|
| 423 | 423 | } |
@@ -58,8 +58,8 @@ discard block |
||
| 58 | 58 | private $apcuPrefix; |
| 59 | 59 | |
| 60 | 60 | public function getPrefixes() { |
| 61 | - if ( ! empty( $this->prefixesPsr0 ) ) { |
|
| 62 | - return call_user_func_array( 'array_merge', array_values( $this->prefixesPsr0 ) ); |
|
| 61 | + if ( ! empty($this->prefixesPsr0)) { |
|
| 62 | + return call_user_func_array('array_merge', array_values($this->prefixesPsr0)); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | return array(); |
@@ -84,9 +84,9 @@ discard block |
||
| 84 | 84 | /** |
| 85 | 85 | * @param array $classMap Class to filename map |
| 86 | 86 | */ |
| 87 | - public function addClassMap( array $classMap ) { |
|
| 88 | - if ( $this->classMap ) { |
|
| 89 | - $this->classMap = array_merge( $this->classMap, $classMap ); |
|
| 87 | + public function addClassMap(array $classMap) { |
|
| 88 | + if ($this->classMap) { |
|
| 89 | + $this->classMap = array_merge($this->classMap, $classMap); |
|
| 90 | 90 | } else { |
| 91 | 91 | $this->classMap = $classMap; |
| 92 | 92 | } |
@@ -100,9 +100,9 @@ discard block |
||
| 100 | 100 | * @param array|string $paths The PSR-0 root directories |
| 101 | 101 | * @param bool $prepend Whether to prepend the directories |
| 102 | 102 | */ |
| 103 | - public function add( $prefix, $paths, $prepend = false ) { |
|
| 104 | - if ( ! $prefix ) { |
|
| 105 | - if ( $prepend ) { |
|
| 103 | + public function add($prefix, $paths, $prepend = false) { |
|
| 104 | + if ( ! $prefix) { |
|
| 105 | + if ($prepend) { |
|
| 106 | 106 | $this->fallbackDirsPsr0 = array_merge( |
| 107 | 107 | (array) $paths, |
| 108 | 108 | $this->fallbackDirsPsr0 |
@@ -118,19 +118,19 @@ discard block |
||
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | $first = $prefix[0]; |
| 121 | - if ( ! isset( $this->prefixesPsr0[ $first ][ $prefix ] ) ) { |
|
| 122 | - $this->prefixesPsr0[ $first ][ $prefix ] = (array) $paths; |
|
| 121 | + if ( ! isset($this->prefixesPsr0[$first][$prefix])) { |
|
| 122 | + $this->prefixesPsr0[$first][$prefix] = (array) $paths; |
|
| 123 | 123 | |
| 124 | 124 | return; |
| 125 | 125 | } |
| 126 | - if ( $prepend ) { |
|
| 127 | - $this->prefixesPsr0[ $first ][ $prefix ] = array_merge( |
|
| 126 | + if ($prepend) { |
|
| 127 | + $this->prefixesPsr0[$first][$prefix] = array_merge( |
|
| 128 | 128 | (array) $paths, |
| 129 | - $this->prefixesPsr0[ $first ][ $prefix ] |
|
| 129 | + $this->prefixesPsr0[$first][$prefix] |
|
| 130 | 130 | ); |
| 131 | 131 | } else { |
| 132 | - $this->prefixesPsr0[ $first ][ $prefix ] = array_merge( |
|
| 133 | - $this->prefixesPsr0[ $first ][ $prefix ], |
|
| 132 | + $this->prefixesPsr0[$first][$prefix] = array_merge( |
|
| 133 | + $this->prefixesPsr0[$first][$prefix], |
|
| 134 | 134 | (array) $paths |
| 135 | 135 | ); |
| 136 | 136 | } |
@@ -146,10 +146,10 @@ discard block |
||
| 146 | 146 | * |
| 147 | 147 | * @throws \InvalidArgumentException |
| 148 | 148 | */ |
| 149 | - public function addPsr4( $prefix, $paths, $prepend = false ) { |
|
| 150 | - if ( ! $prefix ) { |
|
| 149 | + public function addPsr4($prefix, $paths, $prepend = false) { |
|
| 150 | + if ( ! $prefix) { |
|
| 151 | 151 | // Register directories for the root namespace. |
| 152 | - if ( $prepend ) { |
|
| 152 | + if ($prepend) { |
|
| 153 | 153 | $this->fallbackDirsPsr4 = array_merge( |
| 154 | 154 | (array) $paths, |
| 155 | 155 | $this->fallbackDirsPsr4 |
@@ -160,24 +160,24 @@ discard block |
||
| 160 | 160 | (array) $paths |
| 161 | 161 | ); |
| 162 | 162 | } |
| 163 | - } elseif ( ! isset( $this->prefixDirsPsr4[ $prefix ] ) ) { |
|
| 163 | + } elseif ( ! isset($this->prefixDirsPsr4[$prefix])) { |
|
| 164 | 164 | // Register directories for a new namespace. |
| 165 | - $length = strlen( $prefix ); |
|
| 166 | - if ( '\\' !== $prefix[ $length - 1 ] ) { |
|
| 167 | - throw new \InvalidArgumentException( 'A non-empty PSR-4 prefix must end with a namespace separator.' ); |
|
| 165 | + $length = strlen($prefix); |
|
| 166 | + if ('\\' !== $prefix[$length - 1]) { |
|
| 167 | + throw new \InvalidArgumentException('A non-empty PSR-4 prefix must end with a namespace separator.'); |
|
| 168 | 168 | } |
| 169 | - $this->prefixLengthsPsr4[ $prefix[0] ][ $prefix ] = $length; |
|
| 170 | - $this->prefixDirsPsr4[ $prefix ] = (array) $paths; |
|
| 171 | - } elseif ( $prepend ) { |
|
| 169 | + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; |
|
| 170 | + $this->prefixDirsPsr4[$prefix] = (array) $paths; |
|
| 171 | + } elseif ($prepend) { |
|
| 172 | 172 | // Prepend directories for an already registered namespace. |
| 173 | - $this->prefixDirsPsr4[ $prefix ] = array_merge( |
|
| 173 | + $this->prefixDirsPsr4[$prefix] = array_merge( |
|
| 174 | 174 | (array) $paths, |
| 175 | - $this->prefixDirsPsr4[ $prefix ] |
|
| 175 | + $this->prefixDirsPsr4[$prefix] |
|
| 176 | 176 | ); |
| 177 | 177 | } else { |
| 178 | 178 | // Append directories for an already registered namespace. |
| 179 | - $this->prefixDirsPsr4[ $prefix ] = array_merge( |
|
| 180 | - $this->prefixDirsPsr4[ $prefix ], |
|
| 179 | + $this->prefixDirsPsr4[$prefix] = array_merge( |
|
| 180 | + $this->prefixDirsPsr4[$prefix], |
|
| 181 | 181 | (array) $paths |
| 182 | 182 | ); |
| 183 | 183 | } |
@@ -190,11 +190,11 @@ discard block |
||
| 190 | 190 | * @param string $prefix The prefix |
| 191 | 191 | * @param array|string $paths The PSR-0 base directories |
| 192 | 192 | */ |
| 193 | - public function set( $prefix, $paths ) { |
|
| 194 | - if ( ! $prefix ) { |
|
| 193 | + public function set($prefix, $paths) { |
|
| 194 | + if ( ! $prefix) { |
|
| 195 | 195 | $this->fallbackDirsPsr0 = (array) $paths; |
| 196 | 196 | } else { |
| 197 | - $this->prefixesPsr0[ $prefix[0] ][ $prefix ] = (array) $paths; |
|
| 197 | + $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; |
|
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | 200 | |
@@ -207,16 +207,16 @@ discard block |
||
| 207 | 207 | * |
| 208 | 208 | * @throws \InvalidArgumentException |
| 209 | 209 | */ |
| 210 | - public function setPsr4( $prefix, $paths ) { |
|
| 211 | - if ( ! $prefix ) { |
|
| 210 | + public function setPsr4($prefix, $paths) { |
|
| 211 | + if ( ! $prefix) { |
|
| 212 | 212 | $this->fallbackDirsPsr4 = (array) $paths; |
| 213 | 213 | } else { |
| 214 | - $length = strlen( $prefix ); |
|
| 215 | - if ( '\\' !== $prefix[ $length - 1 ] ) { |
|
| 216 | - throw new \InvalidArgumentException( 'A non-empty PSR-4 prefix must end with a namespace separator.' ); |
|
| 214 | + $length = strlen($prefix); |
|
| 215 | + if ('\\' !== $prefix[$length - 1]) { |
|
| 216 | + throw new \InvalidArgumentException('A non-empty PSR-4 prefix must end with a namespace separator.'); |
|
| 217 | 217 | } |
| 218 | - $this->prefixLengthsPsr4[ $prefix[0] ][ $prefix ] = $length; |
|
| 219 | - $this->prefixDirsPsr4[ $prefix ] = (array) $paths; |
|
| 218 | + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; |
|
| 219 | + $this->prefixDirsPsr4[$prefix] = (array) $paths; |
|
| 220 | 220 | } |
| 221 | 221 | } |
| 222 | 222 | |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | * |
| 226 | 226 | * @param bool $useIncludePath |
| 227 | 227 | */ |
| 228 | - public function setUseIncludePath( $useIncludePath ) { |
|
| 228 | + public function setUseIncludePath($useIncludePath) { |
|
| 229 | 229 | $this->useIncludePath = $useIncludePath; |
| 230 | 230 | } |
| 231 | 231 | |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | * |
| 246 | 246 | * @param bool $classMapAuthoritative |
| 247 | 247 | */ |
| 248 | - public function setClassMapAuthoritative( $classMapAuthoritative ) { |
|
| 248 | + public function setClassMapAuthoritative($classMapAuthoritative) { |
|
| 249 | 249 | $this->classMapAuthoritative = $classMapAuthoritative; |
| 250 | 250 | } |
| 251 | 251 | |
@@ -263,8 +263,8 @@ discard block |
||
| 263 | 263 | * |
| 264 | 264 | * @param string|null $apcuPrefix |
| 265 | 265 | */ |
| 266 | - public function setApcuPrefix( $apcuPrefix ) { |
|
| 267 | - $this->apcuPrefix = function_exists( 'apcu_fetch' ) && filter_var( ini_get( 'apc.enabled' ), FILTER_VALIDATE_BOOLEAN ) ? $apcuPrefix : null; |
|
| 266 | + public function setApcuPrefix($apcuPrefix) { |
|
| 267 | + $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null; |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | /** |
@@ -281,15 +281,15 @@ discard block |
||
| 281 | 281 | * |
| 282 | 282 | * @param bool $prepend Whether to prepend the autoloader or not |
| 283 | 283 | */ |
| 284 | - public function register( $prepend = false ) { |
|
| 285 | - spl_autoload_register( array( $this, 'loadClass' ), true, $prepend ); |
|
| 284 | + public function register($prepend = false) { |
|
| 285 | + spl_autoload_register(array($this, 'loadClass'), true, $prepend); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | /** |
| 289 | 289 | * Unregisters this instance as an autoloader. |
| 290 | 290 | */ |
| 291 | 291 | public function unregister() { |
| 292 | - spl_autoload_unregister( array( $this, 'loadClass' ) ); |
|
| 292 | + spl_autoload_unregister(array($this, 'loadClass')); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | /** |
@@ -298,9 +298,9 @@ discard block |
||
| 298 | 298 | * @param string $class The name of the class |
| 299 | 299 | * @return bool|null True if loaded, null otherwise |
| 300 | 300 | */ |
| 301 | - public function loadClass( $class ) { |
|
| 302 | - if ( $file = $this->findFile( $class ) ) { |
|
| 303 | - includeFile( $file ); |
|
| 301 | + public function loadClass($class) { |
|
| 302 | + if ($file = $this->findFile($class)) { |
|
| 303 | + includeFile($file); |
|
| 304 | 304 | |
| 305 | 305 | return true; |
| 306 | 306 | } |
@@ -313,54 +313,54 @@ discard block |
||
| 313 | 313 | * |
| 314 | 314 | * @return string|false The path if found, false otherwise |
| 315 | 315 | */ |
| 316 | - public function findFile( $class ) { |
|
| 316 | + public function findFile($class) { |
|
| 317 | 317 | // class map lookup |
| 318 | - if ( isset( $this->classMap[ $class ] ) ) { |
|
| 319 | - return $this->classMap[ $class ]; |
|
| 318 | + if (isset($this->classMap[$class])) { |
|
| 319 | + return $this->classMap[$class]; |
|
| 320 | 320 | } |
| 321 | - if ( $this->classMapAuthoritative || isset( $this->missingClasses[ $class ] ) ) { |
|
| 321 | + if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { |
|
| 322 | 322 | return false; |
| 323 | 323 | } |
| 324 | - if ( null !== $this->apcuPrefix ) { |
|
| 325 | - $file = apcu_fetch( $this->apcuPrefix . $class, $hit ); |
|
| 326 | - if ( $hit ) { |
|
| 324 | + if (null !== $this->apcuPrefix) { |
|
| 325 | + $file = apcu_fetch($this->apcuPrefix.$class, $hit); |
|
| 326 | + if ($hit) { |
|
| 327 | 327 | return $file; |
| 328 | 328 | } |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | - $file = $this->findFileWithExtension( $class, '.php' ); |
|
| 331 | + $file = $this->findFileWithExtension($class, '.php'); |
|
| 332 | 332 | |
| 333 | 333 | // Search for Hack files if we are running on HHVM |
| 334 | - if ( false === $file && defined( 'HHVM_VERSION' ) ) { |
|
| 335 | - $file = $this->findFileWithExtension( $class, '.hh' ); |
|
| 334 | + if (false === $file && defined('HHVM_VERSION')) { |
|
| 335 | + $file = $this->findFileWithExtension($class, '.hh'); |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | - if ( null !== $this->apcuPrefix ) { |
|
| 339 | - apcu_add( $this->apcuPrefix . $class, $file ); |
|
| 338 | + if (null !== $this->apcuPrefix) { |
|
| 339 | + apcu_add($this->apcuPrefix.$class, $file); |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | - if ( false === $file ) { |
|
| 342 | + if (false === $file) { |
|
| 343 | 343 | // Remember that this class does not exist. |
| 344 | - $this->missingClasses[ $class ] = true; |
|
| 344 | + $this->missingClasses[$class] = true; |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | return $file; |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | - private function findFileWithExtension( $class, $ext ) { |
|
| 350 | + private function findFileWithExtension($class, $ext) { |
|
| 351 | 351 | // PSR-4 lookup |
| 352 | - $logicalPathPsr4 = strtr( $class, '\\', DIRECTORY_SEPARATOR ) . $ext; |
|
| 352 | + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR).$ext; |
|
| 353 | 353 | |
| 354 | 354 | $first = $class[0]; |
| 355 | - if ( isset( $this->prefixLengthsPsr4[ $first ] ) ) { |
|
| 355 | + if (isset($this->prefixLengthsPsr4[$first])) { |
|
| 356 | 356 | $subPath = $class; |
| 357 | - while ( false !== $lastPos = strrpos( $subPath, '\\' ) ) { |
|
| 358 | - $subPath = substr( $subPath, 0, $lastPos ); |
|
| 359 | - $search = $subPath . '\\'; |
|
| 360 | - if ( isset( $this->prefixDirsPsr4[ $search ] ) ) { |
|
| 361 | - $pathEnd = DIRECTORY_SEPARATOR . substr( $logicalPathPsr4, $lastPos + 1 ); |
|
| 362 | - foreach ( $this->prefixDirsPsr4[ $search ] as $dir ) { |
|
| 363 | - if ( file_exists( $file = $dir . $pathEnd ) ) { |
|
| 357 | + while (false !== $lastPos = strrpos($subPath, '\\')) { |
|
| 358 | + $subPath = substr($subPath, 0, $lastPos); |
|
| 359 | + $search = $subPath.'\\'; |
|
| 360 | + if (isset($this->prefixDirsPsr4[$search])) { |
|
| 361 | + $pathEnd = DIRECTORY_SEPARATOR.substr($logicalPathPsr4, $lastPos + 1); |
|
| 362 | + foreach ($this->prefixDirsPsr4[$search] as $dir) { |
|
| 363 | + if (file_exists($file = $dir.$pathEnd)) { |
|
| 364 | 364 | return $file; |
| 365 | 365 | } |
| 366 | 366 | } |
@@ -369,27 +369,27 @@ discard block |
||
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | // PSR-4 fallback dirs |
| 372 | - foreach ( $this->fallbackDirsPsr4 as $dir ) { |
|
| 373 | - if ( file_exists( $file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4 ) ) { |
|
| 372 | + foreach ($this->fallbackDirsPsr4 as $dir) { |
|
| 373 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr4)) { |
|
| 374 | 374 | return $file; |
| 375 | 375 | } |
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | // PSR-0 lookup |
| 379 | - if ( false !== $pos = strrpos( $class, '\\' ) ) { |
|
| 379 | + if (false !== $pos = strrpos($class, '\\')) { |
|
| 380 | 380 | // namespaced class name |
| 381 | - $logicalPathPsr0 = substr( $logicalPathPsr4, 0, $pos + 1 ) |
|
| 382 | - . strtr( substr( $logicalPathPsr4, $pos + 1 ), '_', DIRECTORY_SEPARATOR ); |
|
| 381 | + $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) |
|
| 382 | + . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); |
|
| 383 | 383 | } else { |
| 384 | 384 | // PEAR-like class name |
| 385 | - $logicalPathPsr0 = strtr( $class, '_', DIRECTORY_SEPARATOR ) . $ext; |
|
| 385 | + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR).$ext; |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | - if ( isset( $this->prefixesPsr0[ $first ] ) ) { |
|
| 389 | - foreach ( $this->prefixesPsr0[ $first ] as $prefix => $dirs ) { |
|
| 390 | - if ( 0 === strpos( $class, $prefix ) ) { |
|
| 391 | - foreach ( $dirs as $dir ) { |
|
| 392 | - if ( file_exists( $file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0 ) ) { |
|
| 388 | + if (isset($this->prefixesPsr0[$first])) { |
|
| 389 | + foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { |
|
| 390 | + if (0 === strpos($class, $prefix)) { |
|
| 391 | + foreach ($dirs as $dir) { |
|
| 392 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
| 393 | 393 | return $file; |
| 394 | 394 | } |
| 395 | 395 | } |
@@ -398,14 +398,14 @@ discard block |
||
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | // PSR-0 fallback dirs |
| 401 | - foreach ( $this->fallbackDirsPsr0 as $dir ) { |
|
| 402 | - if ( file_exists( $file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0 ) ) { |
|
| 401 | + foreach ($this->fallbackDirsPsr0 as $dir) { |
|
| 402 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
| 403 | 403 | return $file; |
| 404 | 404 | } |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | // PSR-0 include paths. |
| 408 | - if ( $this->useIncludePath && $file = stream_resolve_include_path( $logicalPathPsr0 ) ) { |
|
| 408 | + if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { |
|
| 409 | 409 | return $file; |
| 410 | 410 | } |
| 411 | 411 | |
@@ -418,6 +418,6 @@ discard block |
||
| 418 | 418 | * |
| 419 | 419 | * Prevents access to $this/self from included files. |
| 420 | 420 | */ |
| 421 | -function includeFile( $file ) { |
|
| 421 | +function includeFile($file) { |
|
| 422 | 422 | include $file; |
| 423 | 423 | } |
@@ -2,7 +2,7 @@ |
||
| 2 | 2 | |
| 3 | 3 | // autoload_namespaces.php @generated by Composer |
| 4 | 4 | |
| 5 | -$vendorDir = dirname( ( __DIR__ ) ); |
|
| 6 | -$baseDir = dirname( $vendorDir ); |
|
| 5 | +$vendorDir = dirname((__DIR__)); |
|
| 6 | +$baseDir = dirname($vendorDir); |
|
| 7 | 7 | |
| 8 | 8 | return array(); |