| 1 |
<?php |
| 2 |
|
| 3 |
namespace Gianism\Pattern; |
| 4 |
|
| 5 |
use Gianism\Controller\Network; |
| 6 |
use Gianism\Controller\ProfileChecker; |
| 7 |
use Gianism\Helper\MessageHelper; |
| 8 |
use Gianism\Helper\i18n; |
| 9 |
use Gianism\Helper\Option; |
| 10 |
use Gianism\Helper\Input; |
| 11 |
use Gianism\Helper\ServiceManager; |
| 12 |
use Gianism\Helper\Session; |
| 13 |
|
| 14 |
/** |
| 15 |
* Application base trait |
| 16 |
* @package Gianism |
| 17 |
* @property \wpdb $db Database controller |
| 18 |
* @property string $url Base URL of plugin. |
| 19 |
* @property string $dir Base directory of plugin. |
| 20 |
* @property Option $option Option instance. |
| 21 |
* @property Session $session Session instance |
| 22 |
* @property Input $input Input instance. |
| 23 |
* @property ServiceManager $service ServiceManager instance |
| 24 |
* @property ProfileChecker $profile_checker Profile checker instance |
| 25 |
* @property Network $network Network controller |
| 26 |
*/ |
| 27 |
trait AppBase { |
| 28 |
|
| 29 |
use i18n; |
| 30 |
use MessageHelper; |
| 31 |
|
| 32 |
protected $name = 'gianism'; |
| 33 |
|
| 34 |
/** |
| 35 |
* Version number |
| 36 |
* |
| 37 |
* @var string |
| 38 |
*/ |
| 39 |
protected $version = \GIANISM_VERSION; |
| 40 |
|
| 41 |
/** |
| 42 |
* Getter |
| 43 |
* |
| 44 |
* @param string $name |
| 45 |
* |
| 46 |
* @return mixed |
| 47 |
*/ |
| 48 |
public function __get( $name ) { |
| 49 |
switch ( $name ) { |
| 50 |
case 'db': |
| 51 |
global $wpdb; |
| 52 |
return $wpdb; |
| 53 |
case 'url': |
| 54 |
return plugin_dir_url( dirname( __DIR__, 2 ) ); |
| 55 |
case 'dir': |
| 56 |
return plugin_dir_path( dirname( __DIR__, 2 ) ); |
| 57 |
case 'option': |
| 58 |
return Option::get_instance(); |
| 59 |
case 'input': |
| 60 |
return Input::get_instance(); |
| 61 |
case 'session': |
| 62 |
return Session::get_instance(); |
| 63 |
case 'service': |
| 64 |
return ServiceManager::get_instance(); |
| 65 |
case 'profile_checker': |
| 66 |
return ProfileChecker::get_instance(); |
| 67 |
case 'network': |
| 68 |
return Network::get_instance(); |
| 69 |
default: |
| 70 |
return null; |
| 71 |
} |
| 72 |
} |
| 73 |
} |
| 74 |
|