コード例 #1
0
ファイル: Console.php プロジェクト: seytar/psx
 /**
  * @return \Symfony\Component\Console\Application
  */
 public function getConsole()
 {
     $application = new Application('psx', Base::getVersion());
     $application->setHelperSet(new HelperSet($this->appendConsoleHelpers()));
     $this->appendConsoleCommands($application);
     return $application;
 }
コード例 #2
0
ファイル: GadgetAbstract.php プロジェクト: visapi/amun
 public function onLoad()
 {
     // set parameters
     $this->container->setParameter('session.name', 'amun-' . md5($this->config['psx_url']));
     $this->container->setParameter('user.id', User::findUserId($this->getSession(), $this->getRegistry()));
     $this->container->setParameter('gadget.id', $this->location->getServiceId());
     // dependencies
     $this->get = $this->getInputGet();
     $this->post = $this->getInputPost();
     $this->registry = $this->getRegistry();
     $this->session = $this->getSession();
     $this->user = $this->getUser();
     $this->gadget = $this->getGadget();
     $this->args = $this->gadget->getArgs();
     // manager
     $this->hm = $this->getHandlerManager();
     // load cache
     if ($this->gadget->hasCache() && Base::getRequestMethod() == 'GET') {
         $expire = $this->gadget->getExpire();
         $expire = $expire instanceof DateInterval ? $expire : new DateInterval('P1D');
         $modified = new DateTime();
         $expires = clone $modified;
         $expires->add($expire);
         $type = $this->user->isAnonymous() ? 'public' : 'private';
         $maxAge = DateTime::convertIntervalToSeconds($expire);
         header('Expires: ' . $expires->format(DateTime::RFC1123));
         header('Last-Modified: ' . $modified->format(DateTime::RFC1123));
         header('Cache-Control: ' . $type . ', max-age=' . $maxAge);
         header('Pragma:');
         // remove pragma header
     }
 }
コード例 #3
0
ファイル: Callback.php プロジェクト: visapi/amun
 /**
  * @httpMethod POST
  * @path /{type}/{secret}
  */
 public function insertCommit()
 {
     try {
         $type = $this->getUriFragments('type');
         $secret = $this->getUriFragments('secret');
         // parse request
         $type = TypeAbstract::factory($type);
         $project = $type->getRequest(Base::getRawInput());
         // get project
         $con = new Condition(array('secret', '=', $secret));
         $id = $this->sql->select($this->registry['table.vcshook'], array('id'), $con, Sql::SELECT_FIELD);
         if (!empty($id) && $project->hasCommits()) {
             $count = 0;
             foreach ($project->getCommits() as $commit) {
                 try {
                     $record = $this->hm->getHandler('AmunService\\Vcshook\\Commit')->getRecord();
                     $record->setProjectId($id);
                     $record->setAuthor($commit->getAuthor());
                     $record->setUrl($commit->getUrl());
                     $record->setMessage($commit->getMessage());
                     $record->setTimestamp($commit->getTimestamp());
                     // notify listener
                     $this->event->notifyListener('vcshook.commit', array($record));
                     $count++;
                 } catch (\Exception $e) {
                     // import fails we go the next commit and ignore the
                     // error
                 }
             }
             if ($count == 0) {
                 throw new Exception('No commits inserted');
             }
         } else {
             throw new Exception('Invalid project or no commits available');
         }
         $msg = new Message('Inserted ' . $count . ' commits', true);
         $this->setResponse($msg);
     } catch (\Exception $e) {
         $msg = new Message($e->getMessage(), false);
         $this->setResponse($msg, null, 500);
     }
 }
コード例 #4
0
ファイル: Render.php プロジェクト: visapi/amun
 /**
  * Renders the content as html markup
  *
  * @httpMethod POST
  * @path /
  * @nickname doRender
  * @responseClass PSX_Data_ResultSet
  */
 public function doRender()
 {
     if ($this->user->hasRight('content_page_preview')) {
         try {
             $oembed = $this->get->oembed('boolean');
             $markdown = $this->get->markdown('boolean');
             $input = Base::getRawInput();
             $filter = new Filter\Html($this->registry, $this->user, $oembed);
             if ($markdown) {
                 $input = Markdown::decode($input);
             }
             header('Content-Type: text/html');
             echo $filter->apply($input);
             exit;
         } catch (\Exception $e) {
             $msg = new Message($e->getMessage(), false);
             $this->setResponse($msg);
         }
     } else {
         $msg = new Message('Access not allowed', false);
         $this->setResponse($msg, null, $this->user->isAnonymous() ? 401 : 403);
     }
 }
コード例 #5
0
ファイル: ApplicationAbstract.php プロジェクト: visapi/amun
 public function onLoad()
 {
     // set parameters
     $this->container->setParameter('session.name', 'amun-' . md5($this->config['psx_url']));
     $this->container->setParameter('user.id', User::findUserId($this->getSession(), $this->getRegistry()));
     $this->container->setParameter('page.id', $this->location->getServiceId());
     $this->container->setParameter('service.id', $this->getPage()->getServiceId());
     // set xrds location header
     header('X-XRDS-Location: ' . $this->config['psx_url'] . '/' . $this->config['psx_dispatch'] . 'api/xrds');
     // dependencies
     $this->validate = $this->getValidate();
     $this->get = $this->getInputGet();
     $this->post = $this->getInputPost();
     $this->registry = $this->getRegistry();
     $this->session = $this->getSession();
     $this->user = $this->getUser();
     $this->page = $this->getPage();
     $this->service = $this->getService();
     $this->template = $this->getTemplate();
     // manager
     $this->hm = $this->getHandlerManager();
     // load nav
     if ($this->page->hasNav()) {
         $this->navigation = $this->getNavigation();
         $this->navigation->load();
     }
     // load path
     if ($this->page->hasPath()) {
         $this->path = $this->getPath();
         $this->path->load();
     }
     // load gadgets
     if ($this->page->hasGadget()) {
         $this->gadgetContainer = $this->getGadgetContainer();
         $this->gadgetContainer->load($this->getLoader(), $this->page, $this->getHtmlCss());
     }
     // load cache
     if ($this->page->hasCache() && Base::getRequestMethod() == 'GET') {
         $expire = $this->page->getExpire();
         $expire = $expire instanceof DateInterval ? $expire : new DateInterval('P1D');
         $modified = new DateTime();
         $expires = clone $modified;
         $expires->add($expire);
         $type = $this->user->isAnonymous() ? 'public' : 'private';
         $maxAge = DateTime::convertIntervalToSeconds($expire);
         header('Expires: ' . $expires->format(DateTime::RFC1123));
         header('Last-Modified: ' . $modified->format(DateTime::RFC1123));
         header('Cache-Control: ' . $type . ', max-age=' . $maxAge);
         header('Pragma:');
         // remove pragma header
     }
     // template dependencies
     $this->htmlJs = $this->getHtmlJs();
     $this->htmlCss = $this->getHtmlCss();
     $this->htmlContent = $this->getHtmlContent();
     // set application template path
     $dir = $this->service->getAutoloadPath() . '/' . $this->service->getNamespace() . '/Resource';
     $dir = str_replace('\\', '/', $dir);
     $this->template->setDir($dir);
     // add html fragments
     $this->loadHtmlFragments();
     // add default css
     $this->htmlCss->add('default');
     $this->htmlJs->add('amun');
 }
コード例 #6
0
ファイル: Index.php プロジェクト: visapi/amun
 private function serve(ProviderInterface $provider, $services)
 {
     // get response
     $manager = new Manager($this->config, $provider);
     $response = $manager->serve($services);
     // remove caching header
     header('Expires:');
     header('Last-Modified:');
     header('Cache-Control:');
     header('Pragma:');
     // gzip encoding
     $acceptEncoding = Base::getRequestHeader('Accept-Encoding');
     if ($this->config['psx_gzip'] === true && strpos($acceptEncoding, 'gzip') !== false) {
         header('Content-Encoding: gzip');
         $response = gzencode($response, 9);
     }
     // caching header
     $etag = md5($response);
     $match = Base::getRequestHeader('If-None-Match');
     $match = $match !== false ? trim($match, '"') : '';
     header('Etag: "' . $etag . '"');
     if ($match != $etag) {
         echo $response;
     } else {
         Base::setResponseCode(304);
     }
     exit;
 }