balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

App.php (2447B)


      1 <?php
      2 /**
      3  * The App details file
      4  */
      5 
      6 namespace Extendify\ExtendifySdk;
      7 
      8 use Extendify\ExtendifySdk\Plugin;
      9 
     10 /**
     11  * Controller for handling various app data
     12  */
     13 class App
     14 {
     15 
     16     /**
     17      * Plugin name
     18      *
     19      * @var string
     20      */
     21     public static $name = '';
     22 
     23     /**
     24      * Plugin slug
     25      *
     26      * @var string
     27      */
     28     public static $slug = '';
     29 
     30     /**
     31      * Plugin version
     32      *
     33      * @var string
     34      */
     35     public static $version = '';
     36 
     37     /**
     38      * Plugin API REST version
     39      *
     40      * @var string
     41      */
     42     public static $apiVersion = 'v1';
     43 
     44     /**
     45      * Plugin text domain
     46      *
     47      * @var string
     48      */
     49     public static $textDomain = '';
     50 
     51     /**
     52      * Plugin environment
     53      *
     54      * @var string
     55      */
     56     public static $environment = '';
     57 
     58     /**
     59      * Host plugin
     60      *
     61      * @var string
     62      */
     63     public static $sourcePlugin = 'Not set';
     64 
     65     /**
     66      * Host plugin
     67      *
     68      * @var string
     69      */
     70     public static $requiredCapability = 'upload_files';
     71 
     72     /**
     73      * Plugin config
     74      *
     75      * @var array
     76      */
     77     public static $config = [];
     78 
     79     /**
     80      * Process the readme file to get version and name
     81      *
     82      * @return void
     83      */
     84     public function __construct()
     85     {
     86         if (isset($GLOBALS['extendifySdkSourcePlugin'])) {
     87             self::$sourcePlugin = $GLOBALS['extendifySdkSourcePlugin'];
     88         }
     89 
     90         // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
     91         $readme = file_get_contents(dirname(__DIR__) . '/readme.txt');
     92 
     93         preg_match('/=== (.+) ===/', $readme, $matches);
     94         self::$name = $matches[1];
     95         self::$slug = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', self::$name), '-'));
     96 
     97         preg_match('/Stable tag: ([0-9.:]+)/', $readme, $matches);
     98         self::$version = $matches[1];
     99 
    100         // An easy way to check if we are in dev mode is to look for a dev specific file.
    101         $isDev = is_readable(EXTENDIFYSDK_PATH . 'node_modules') || is_readable(EXTENDIFYSDK_PATH . '.devbuild');
    102         self::$environment = $isDev ? 'DEVELOPMENT' : 'PRODUCTION';
    103 
    104         self::$textDomain = Plugin::getPluginInfo('TextDomain', self::$slug);
    105 
    106         // Add the config.
    107         // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
    108         $config = file_get_contents(dirname(__DIR__) . '/config.json');
    109         self::$config = json_decode($config, true);
    110     }
    111 }