CLI
2 years ago
Core
1 year ago
DemoSites
1 year ago
AssetsDependencyInjector.php
3 years ago
Config.php
3 years ago
FileLog.php
2 years ago
Flags.php
2 years ago
GoogleFontsLocalLoader.php
2 years ago
Migrations.php
4 years ago
NotificationsManager.php
2 years ago
PluginsManager.php
2 years ago
Config.php
76 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Kubio; |
| 4 | use Kubio\Core\LodashBasic; |
| 5 | use function file_get_contents; |
| 6 | use function json_decode; |
| 7 | use const KUBIO_ROOT_DIR; |
| 8 | |
| 9 | class Config { |
| 10 | public static $name = 'kubio'; |
| 11 | |
| 12 | public static $mainAttributeKey; |
| 13 | public static $elementsKey; |
| 14 | public static $elementsEnum; |
| 15 | public static $statesKey; |
| 16 | |
| 17 | public static $config_types = array(); |
| 18 | |
| 19 | |
| 20 | private static $medias_by_id = null; |
| 21 | private static $states_by_id = null; |
| 22 | |
| 23 | public static function load() { |
| 24 | $types_f = KUBIO_ROOT_DIR . 'build/types.json'; |
| 25 | self::$config_types = apply_filters( 'kubio/style-types', json_decode( file_get_contents( $types_f ), true ) ); |
| 26 | |
| 27 | self::$mainAttributeKey = Config::value( 'constants.support.mainAttributeKey' ); |
| 28 | self::$elementsKey = Config::value( 'constants.support.elementsKey' ); |
| 29 | self::$elementsEnum = Config::value( 'constants.support.elementsEnum' ); |
| 30 | self::$statesKey = Config::value( 'constants.support.statesKey' ); |
| 31 | } |
| 32 | |
| 33 | |
| 34 | public static function value( $path, $fallback = null ) { |
| 35 | return LodashBasic::get( self::$config_types, $path, $fallback ); |
| 36 | } |
| 37 | |
| 38 | public static function mediasById() { |
| 39 | |
| 40 | if ( static::$medias_by_id ) { |
| 41 | return static::$medias_by_id; |
| 42 | } |
| 43 | |
| 44 | $items = self::value( 'medias' ); |
| 45 | $result = array(); |
| 46 | |
| 47 | foreach ( $items as $item ) { |
| 48 | $result[ $item['id'] ] = $item; |
| 49 | } |
| 50 | |
| 51 | static::$medias_by_id = $result; |
| 52 | return static::$medias_by_id; |
| 53 | |
| 54 | } |
| 55 | |
| 56 | public static function statesById() { |
| 57 | |
| 58 | if ( static::$states_by_id ) { |
| 59 | return static::$states_by_id; |
| 60 | } |
| 61 | |
| 62 | $items = self::value( 'states' ); |
| 63 | $result = array(); |
| 64 | |
| 65 | foreach ( $items as $item ) { |
| 66 | $result[ $item['id'] ] = $item; |
| 67 | } |
| 68 | |
| 69 | static::$states_by_id = $result; |
| 70 | return static::$states_by_id; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | |
| 75 | Config::load(); |
| 76 |