示例#1
0
 protected function refresh()
 {
     $this->setSkipView(true);
     Url::refresh();
     Pimple::end();
 }
示例#2
0
 /**
  * Show pimple reference (only available in dev mode)
  */
 public function ref()
 {
     if (Pimple::getEnvironment() != 'development') {
         Pimple::end('Not allowed');
     }
     include_once 'ref/RefReader.php';
     $this->setSkipLayout(true);
     $reader = new RefReader();
     //$reader->read(PIMPLEBASE.'/lib/taglib/FormTagLib.php','RefTagLib','RefTagLibMethod');
     $reader->read(BASEDIR . '/taglib/', 'RefTagLib', 'RefTagLibMethod');
     $reader->read(PIMPLEBASE . '/lib/taglib/', 'RefTagLib', 'RefTagLibMethod');
     $tags = $reader->getClass('FormTagLib')->getTags();
     $taglibs = $reader->getClasses();
     $reader = new RefReader();
     $reader->read(BASEDIR . '/controller/', 'RefController', 'RefControllerMethod');
     $reader->read(PIMPLEBASE . '/lib/controller/', 'RefController', 'RefControllerMethod');
     $controllers = $reader->getClasses();
     return array('taglibs' => $taglibs, 'controllers' => $controllers);
 }
示例#3
0
文件: Cli.php 项目: hofmeister/Pimple
 /**
  * Returns true if succesful start - and false if already running...
  *
  * @param string $pidFile
  * @return boolean
  */
 public function startDaemon($pidFile)
 {
     if (is_file($pidFile)) {
         $pid = file_get_contents($pidFile);
         if ($this->isPidAlive($pid)) {
             return false;
         }
     }
     $pid = pcntl_fork();
     if ($pid) {
         //Parent process - exit...
         $fp = fopen($pidFile, 'w');
         if ($fp) {
             fputs($fp, $pid, strlen($pid));
             fclose($fp);
             $this->displayLine('Daemon started');
             Pimple::end();
         } else {
             $this->killPid($pid);
             $this->displayErrorAndExit(sprintf('Could not create pidfile: %s', $pidFile));
         }
     }
     $this->currentPid = $pidFile;
     $this->daemon = true;
     return true;
 }
示例#4
0
 public function execute()
 {
     if (Settings::get(Settings::DEBUG, false)) {
         if (isset($_GET['__clearcache'])) {
             //Clear cache
             Dir::emptyDir(CACHEDIR, true);
         }
         if (isset($_GET['__clearview'])) {
             //Clear cache
             Dir::emptyDir(Dir::concat(CACHEDIR, 'view'), true);
         }
         if (isset($_GET['__clearjs'])) {
             //Clear cache
             Dir::emptyDir(Dir::concat(CACHEDIR, 'js'), true);
         }
         if (isset($_GET['__clearcss'])) {
             //Clear cache
             Dir::emptyDir(Dir::concat(CACHEDIR, 'css'), true);
         }
     }
     try {
         if (!String::isAlphaNum($this->controller)) {
             header("HTTP/1.0 404 Invalid url");
             throw new HttpNotFoundException(T('Invalid controller: %s', $this->controller));
         }
         if (!String::isAlphaNum($this->action)) {
             header("HTTP/1.1 404 Invalid url");
             throw new HttpNotFoundException(T('Invalid action: %s', $this->action));
         }
         $ctrlClass = ucfirst($this->controller) . 'Controller';
         $appViewFile = 'application';
         $viewFile = $this->getViewFile();
         if (!class_exists($ctrlClass)) {
             $ctrlFile = Dir::normalize(BASEDIR) . 'controller/' . $ctrlClass . '.php';
             if (!File::exists($ctrlFile)) {
                 header("HTTP/1.1 404 Controller not found");
                 throw new HttpNotFoundException(T('Controller not found: %s', $ctrlFile));
             }
             require_once $ctrlFile;
         }
         if (!class_exists($ctrlClass)) {
             header("HTTP/1.1 404 Controller not Found");
             throw new HttpNotFoundException(T('Controller not found: %s', $ctrlClass));
         }
         $ctrl = new $ctrlClass();
         $this->controllerInstance = $ctrl;
         if (!method_exists($ctrl, $this->action)) {
             header("HTTP/1.1 404 Action not Found");
             throw new HttpNotFoundException(T('Action not found: %s::%s', $ctrlClass, $this->action));
         }
         $action = $this->action;
         if (!$ctrl->getSkipView()) {
             try {
                 $view = new View($viewFile);
             } catch (Exception $e) {
                 //Ignore for now
             }
         }
         try {
             $data = $ctrl->{$action}();
         } catch (ValidationException $e) {
             //Do nothing...
         } catch (Interrupt $e) {
             //Do nothing...
         } catch (ErrorException $e) {
             MessageHandler::instance()->addError($e->getMessage());
         }
         if (!$data) {
             $data = $ctrl->getData();
         }
         if (!$ctrl->getSkipView()) {
             if ($view) {
                 $this->body = $view->render($data);
             } else {
                 if (!Request::isAjax()) {
                     header("HTTP/1.1 500 View not Found");
                     throw new Exception(T('View not found: %s', $viewFile));
                 }
             }
         }
     } catch (HttpNotFoundException $e) {
         trigger_error(sprintf("Path not found %s", self::getPath()), E_USER_ERROR);
         if (!Request::isAjax()) {
             Url::redirect('error', 'notfound');
         }
         Pimple::end();
     } catch (Exception $e) {
         header("HTTP/1.1 500 Internal error");
         if (Request::isAjax()) {
             $this->body = json_encode(array('msg' => $e->getMessage(), 'trace' => $e->getTraceAsString()));
         } else {
             if (Settings::get(Settings::DEBUG, false)) {
                 $body = $e->__toString();
                 if (!stristr($body, '<')) {
                     $body = '<pre>' . $body . '</pre>';
                 }
                 $this->body = $body;
             } else {
                 trigger_error(sprintf("Unexpected exception thrown in %s:\n\t%s", self::getPath(), $e->__toString()), E_USER_ERROR);
                 Url::redirect('error', 'internal');
             }
         }
     }
     $this->view = new View($appViewFile);
 }
示例#5
0
    /**
     *
     * @param phtml $string
     * @return PhtmlNode
     */
    public function read($string,$file) {
        $string = String::normalize($string,false);
        $this->withinStack = array(self::NOTHING);
        $this->current = '';
        $this->debugTrace = '';
        $this->node = new PhtmlNode();
        $this->node->setContainer(true);
        $this->node->setTag('phtml');
        $this->phtmlRaw = $string;
        $this->lineCount = 1;
        $ignoredAscii = array(10,13,ord("\t"),ord(" "));
        
        for($i = 0; $i < mb_strlen($string);$i++) {
            $chr = mb_substr($string,$i,1);
            $this->charCount++;
            $this->prevChar = null;
            $this->nextChar = mb_substr($string,$i+1,1);
            $this->char = $chr;

            if ($this->char == "\n") {
                $this->lineCount++;
                $this->charCount = 0;
            }
            
            switch($chr) {
                case '<':
                    if (mb_substr($string,$i+1,3) == '!--') {
                        $this->pushWithin(self::COMMENT);
                        break;
                    }
                    if ($this->nextChar == '?') {
                        $this->pushWithin(self::PHP);
                        break;
                    } 
                    if (!$this->ignoreAll() && $this->nextChar == '/') {
                        $this->ignoreChars = true;
                        $this->pushWithin(self::TAGEND);
                        $this->getNode()->setContainer(true);
                        
                    } elseif ($this->nextChar == '!') {
                        $this->pushWithin(self::DOCTYPE);
                    } elseif (preg_match('/[A-Z0-9]/i',$this->nextChar) && !$this->isWithin(self::SCRIPT)) {
                        $this->onTagStart();
                    }
                    
                    break;
                case '>':
                    if (mb_substr($string,$i-2,2) == '--' && $this->isWithin(self::COMMENT)) {
                        $this->popWithin();
                        break;
                    }
                    //Handle conditional comments
                    if (($this->conditionalComment && $this->lastChar == ']') && $this->isWithin(self::COMMENT)) {
                        $this->conditionalComment = false;
                        $this->popWithin();
                        break;
                    }
                    if ($this->lastChar == '?' && $this->isWithin(self::PHP)) {
                        $this->popWithin();
                    } elseif ($this->isWithin(self::TAGEND)) {
                        $this->checkEndTag();
                        $this->popWithin();
                        $this->onNodeEnd();
                        $this->ignoreChars = false;
                        $this->ignoreNextChar(1);
                    } elseif ($this->isWithin(self::DOCTYPE)) {
                        $this->popWithin();
                        $this->onWordEnd();
                    } elseif(!$this->ignoreTags()) {
                        $this->onWordEnd();
                        if ($this->isWithin(self::TAG))
                            $this->ignoreNextChar(2);
                        $this->onTagEnd();
                    }
                    
                    break;
                case ':':
                    if ($this->isWithin(self::ATTR)) {
                        
                        break;
                    }
                case '%':
                    if ($this->ignoreTags()) break;
                    if ($this->nextChar == '{') {
                        $this->pushWithin(self::P_EVAL);
                        break;
                    }
                case '}':
                    if ($this->isWithin(self::P_EVAL) && $this->lastChar != '\\') {
                        $this->popWithin();
                        break;
                    }
                
                case ' ':
                case "\t":
                case "\n":
                case "\r":
                case '/':
                case '=':
                    if ($this->ignoreTags() && !$this->isWithin(self::ATTR)) break;
                    $this->onWordEnd();
                    break;
                case '"':
                case '\'':
                    if (!$this->isWithin(self::TAG,true)) break;
                    if ($this->isWithin(self::STRING)) {
                        $this->onStringEnd();
                    } else {
                        $this->onStringStart();
                    }
                    break;
                case '[':
                    if (mb_substr($string,$i-4,4) == '<!--' && $this->isWithin(self::COMMENT)) {
                        $this->conditionalComment = true;
                    }
                default:
                    $this->onWordStart();
                    
                    break;
            }
            $ascii = ord($this->char);
            if (in_array($ascii,$ignoredAscii))
                $this->debug("CHR:chr($ascii)");
            else
                $this->debug("CHR:$this->char");
            $this->addChar($this->char);
            $this->lastChar = $this->char;
        }
        $text = $this->getCurrent();
        if ($text)
            $this->getNode()->addChild(new PhtmlNodeText($text));

        $node = $this->getNode();
        $this->clear();
        if (Settings::get(Settings::DEBUG,false) && $_GET['__viewdebug'] == $file) {
            $test = new PhtmlException($this->phtmlRaw,$this->char,$this->lineCount,$this->charCount,$this->debugTrace);
            echo $test;
            Pimple::end();
        }
        return $node;
    }