data::load PHP Method

load() protected static method

protected static load ( )
    protected static function load()
    {
        $data = array();
        if (file_exists(__DIR__ . self::$filename)) {
            $data = json_decode(file_get_contents(__DIR__ . self::$filename), true);
        }
        return $data;
    }

Usage Example

コード例 #1
0
 public function __toString()
 {
     $this->data = data::load($this);
     $r = '';
     if (isset($_GET['check'])) {
         $id = $_GET['check'];
         if (!$this->data->checks->has($id)) {
             wp_die('Invalid check ID!');
         }
         $check = $this->data->checks->get($id);
         if (isset($_GET['action'])) {
             $action = $_GET['action'];
             $actions = $check->get_actions();
             if (!isset($actions[$action])) {
                 wp_die('Invalid check action!');
             }
             return call_user_func([$check, $action]);
         }
     }
     if (isset($_GET['do_check'])) {
         $id = $_GET['do_check'];
         if ($this->data->checks->has($id)) {
             $check = $this->data->checks->get($id);
             if ($check->step == 'start') {
                 $r .= $check->init();
             }
             $r .= $check->step();
             $this->data->save();
         } else {
             wp_die(sprintf('Check %s does not exist!', $id));
         }
     } else {
         $r = $this->get_table();
     }
     return $r;
 }