Exemple #1
0
 function __construct($id, $data)
 {
     $this->id = $id;
     $this->message = \PMVC\value($data, ['message']);
     $this->field = \PMVC\value($data, ['field']);
     $this->forward = \PMVC\value($data, ['forward']);
 }
Exemple #2
0
 function validate()
 {
     $inputPath = $this['path'];
     if (is_dir($inputPath)) {
         $path = $inputPath;
     } else {
         $inputPathInfo = pathinfo($inputPath);
         $dir = \PMVC\value($inputPathInfo, ['dirname']);
         if (in_array($dir, ['.', '/'])) {
             $dir = null;
         }
         $path = $dir;
         $pattern = $inputPathInfo['basename'];
     }
     if (empty($path) || !realpath($path)) {
         return !trigger_error('No path found.');
     } else {
         if (empty($pattern)) {
             $pattern = '*';
         }
         $this['path'] = $path;
         $this['pattern'] = $pattern;
         return true;
     }
 }
Exemple #3
0
 public function onSetConfig__run_form_($subject)
 {
     $subject->detach($this);
     $method = \PMVC\value(\PMVC\getOption(_RUN_FORM), ['_method']);
     if (!empty($method)) {
         $this['method'] = $method;
     }
 }
Exemple #4
0
 public function isDev($type)
 {
     if (empty($type)) {
         return false;
     }
     $d = \PMVC\plug('debug');
     $level = \PMVC\value($d, ['level']);
     $level = explode(',', $level);
     return in_array($type, $level);
 }
Exemple #5
0
 public function init()
 {
     if (empty($this['output'])) {
         $this['output'] = 'debug_console';
     }
     if (empty($this['truncate'])) {
         $this['truncate'] = 100;
     }
     p\callPlugin('dispatcher', 'attach', [$this, 'SetConfig__run_form_']);
     $this->setLevelType(\PMVC\value($_REQUEST, [INPUT_FIELD]), false);
 }
 private function _run()
 {
     if (empty($this['NODE'])) {
         return false;
     }
     // echo '{"themePath":"home"}' | node ./server.js
     $js = \PMVC\value($this, ['jsFile'], $this['themeFolder'] . '/server.js');
     $cmd = $this['NODE'] . ' ' . $js;
     \PMVC\dev(function () use($cmd) {
         $s = "echo '" . $this['reactData'] . "' | " . $cmd;
         return $s;
     }, 'view');
     return $this->_shell($cmd, $this['reactData'], $this->_returnCode);
 }
 /**
  * @see https://developers.google.com/maps/documentation/streetview/intro#url_parameters
  * @parameters int heading [0-360] 
  * @parameters int fov [0-120] default 90 
  * @parameters int pitch [-90-90] default 10 
  */
 public function toStreet()
 {
     $url = \PMVC\plug('url')->getUrl('https://maps.googleapis.com/maps/api/streetview');
     $query = ['location' => $this['center'], 'size' => \PMVC\value($this, ['size'], '640x300')];
     if (isset($this['heading'])) {
         $query['heading'] = $this['heading'];
     }
     if (isset($this['fov'])) {
         $query['fov'] = $this['fov'];
     }
     if (isset($this['pitch'])) {
         $query['pitch'] = $this['pitch'];
     }
     $url->query = $query;
     return (string) $url;
 }
Exemple #8
0
 public function request($url, $params = [])
 {
     $respond = null;
     $url->set($this->getBaseUrl());
     $header = ['X-Algolia-Application-Id: ' . $this['app'], 'X-Algolia-API-Key: ' . $this['key']];
     $params[CURLOPT_HTTPHEADER] = array_merge(\PMVC\value($params, [CURLOPT_HTTPHEADER], []), $header);
     $curl = \PMVC\plug('curl');
     $curl->get((string) $url, function ($r) use(&$respond, $url) {
         if (500 > $r->code) {
             $respond = (object) ['header' => $r->header, 'body' => \PMVC\fromJson($r->body), 'code' => $r->code];
         } else {
             return !trigger_error('Get result error. Error Code:' . $r->code . ' url: ' . $url);
         }
     })->set($params);
     $curl->process();
     return $respond;
 }
Exemple #9
0
 public function get($k)
 {
     if ($this['isDev'] && \PMVC\value($_REQUEST, ['--' . $k])) {
         return $_REQUEST['--' . $k];
     } elseif (isset($this[$k])) {
         if (is_callable($this[$k])) {
             $isCache = false;
             $v = $this[$k]($isCache, $k, $this);
             if ($isCache) {
                 $this[$k] = $v;
             }
             return $v;
         } else {
             return $this[$k];
         }
     } else {
         return \PMVC\value($_SERVER, [$k]);
     }
 }
Exemple #10
0
 public function genPageList($num, Page $page = null, $url = null)
 {
     if (is_null($page)) {
         $page = $this['page'];
     }
     $this->calNav($page);
     $pages = [];
     $return = [CURRENT_PAGE => [$this->toArray($page)]];
     $current = (int) $page[CURRENT_PAGE];
     $pages[$current] = CURRENT_PAGE;
     if ($num) {
         $liCount = $this->calPageList($page, $num);
         for ($i = $liCount[BEGIN]; $i <= $liCount[END]; $i++) {
             if (strcmp($i, $current) !== 0) {
                 $pages[$i] = $this->toArray(new Page($i, $url));
             }
         }
     }
     if (!empty($page[FIRST_PAGE])) {
         if (\PMVC\value($liCount, [BEGIN], -1) > $page[FIRST_PAGE]) {
             $firstPage = $this->toArray(new Page($page[FIRST_PAGE], $url));
             if (strcmp(2, $liCount[BEGIN]) === 0) {
                 $pages[1] = $firstPage;
             } else {
                 $return[FIRST_PAGE] = $firstPage;
             }
         }
     }
     if (isset($page[FORWARD])) {
         $return[CURRENT_PAGE][FORWARD] = $this->toArray(new Page($page[FORWARD], $url));
     }
     if (isset($page[BACKWARD])) {
         $return[CURRENT_PAGE][BACKWARD] = $this->toArray(new Page($page[BACKWARD], $url));
     }
     if (!isset($pages[$page[LAST_PAGE]]) && !empty($page[LAST_PAGE])) {
         $lastPage = $this->toArray(new Page($page[LAST_PAGE], $url));
         if (isset($i) && strcmp($i, $page[LAST_PAGE]) === 0) {
             $pages[$i] = $lastPage;
         } else {
             $return[LAST_PAGE] = $lastPage;
         }
     }
     ksort($pages);
     foreach ($pages as $p) {
         $return['list'][] = $p;
     }
     return $return;
 }
Exemple #11
0
 public function get($s)
 {
     return \PMVC\value($_SERVER, [$s]);
 }