示例#1
0
 /**
  * Handle GET requests.
  *
  * @param Alpha\Util\Http\Request $request
  *
  * @return Alpha\Util\Http\Response
  *
  * @throws Alpha\Exception\IllegalArguementException
  *
  * @since 1.0
  */
 public function doGET($request)
 {
     self::$logger->debug('>>doGET($request=[' . var_export($request, true) . '])');
     $params = $request->getParams();
     $body = '';
     try {
         // load the business object (BO) definition
         if (isset($params['logPath']) && file_exists(urldecode($params['logPath']))) {
             $logPath = urldecode($params['logPath']);
         } else {
             throw new IllegalArguementException('No log file available to view!');
         }
         $this->logPath = $logPath;
         $body .= View::displayPageHead($this);
         $log = new LogProviderFile();
         $log->setPath($this->logPath);
         if (preg_match('/alpha.*/', basename($this->logPath))) {
             $body .= $log->renderLog(array('Date/time', 'Level', 'Class', 'Message', 'Client', 'IP', 'Server hostname', 'URI'));
         }
         if (preg_match('/search.*/', basename($this->logPath))) {
             $body .= $log->renderLog(array('Search query', 'Search date', 'Client Application', 'Client IP'));
         }
         if (preg_match('/feeds.*/', basename($this->logPath))) {
             $body .= $log->renderLog(array('Business object', 'Feed type', 'Request date', 'Client Application', 'Client IP'));
         }
         if (preg_match('/tasks.*/', basename($this->logPath))) {
             $body .= $log->renderLog(array('Date/time', 'Level', 'Class', 'Message'));
         }
         $body .= View::displayPageFoot($this);
     } catch (IllegalArguementException $e) {
         self::$logger->warn($e->getMessage());
         $body .= View::displayPageHead($this);
         $body .= View::displayErrorMessage($e->getMessage());
         $body .= View::displayPageFoot($this);
     }
     self::$logger->debug('<<doGET');
     return new Response(200, $body, array('Content-Type' => 'text/html'));
 }
示例#2
0
 /**
  * Handle GET requests.
  *
  * @param Alpha\Util\Http\Request $request
  *
  * @return Alpha\Util\Http\Response
  *
  * @since 1.0
  *
  * @throws Alpha\Exception\ResourceNotFoundException
  */
 public function doGET($request)
 {
     self::$logger->debug('>>doGET($request=[' . var_export($request, true) . '])');
     $config = ConfigProvider::getInstance();
     $params = $request->getParams();
     $response = new Response(200);
     try {
         if (isset($params['ActiveRecordType'])) {
             $ActiveRecordType = urldecode($params['ActiveRecordType']);
         } else {
             throw new IllegalArguementException('ActiveRecordType not specified to generate feed!');
         }
         if (isset($params['type'])) {
             $type = $params['type'];
         } else {
             throw new IllegalArguementException('No feed type specified to generate feed!');
         }
         if (class_exists($ActiveRecordType)) {
             $this->ActiveRecordType = $ActiveRecordType;
         } else {
             throw new IllegalArguementException('No ActiveRecord available to render!');
         }
         $this->type = $type;
         $this->setup();
         switch ($type) {
             case 'RSS2':
                 $feed = new RSS2($this->ActiveRecordType, $this->title, str_replace('&', '&amp;', $request->getURI()), $this->description);
                 $feed->setFieldMappings($this->fieldMappings[0], $this->fieldMappings[1], $this->fieldMappings[2], $this->fieldMappings[3]);
                 $response->setHeader('Content-Type', 'application/rss+xml');
                 break;
             case 'RSS':
                 $feed = new RSS($this->ActiveRecordType, $this->title, str_replace('&', '&amp;', $request->getURI()), $this->description);
                 $feed->setFieldMappings($this->fieldMappings[0], $this->fieldMappings[1], $this->fieldMappings[2], $this->fieldMappings[3]);
                 $response->setHeader('Content-Type', 'application/rss+xml');
                 break;
             case 'Atom':
                 $feed = new Atom($this->ActiveRecordType, $this->title, str_replace('&', '&amp;', $request->getURI()), $this->description);
                 $feed->setFieldMappings($this->fieldMappings[0], $this->fieldMappings[1], $this->fieldMappings[2], $this->fieldMappings[3], $this->fieldMappings[4]);
                 if ($config->get('feeds.atom.author') != '') {
                     $feed->addAuthor($config->get('feeds.atom.author'));
                 }
                 $response->setHeader('Content-Type', 'application/atom+xml');
                 break;
         }
         // now add the twenty last items (from newest to oldest) to the feed, and render
         $feed->loadBOs(20, $this->sortBy);
         $response->setBody($feed->render());
         // log the request for this news feed
         $feedLog = new LogProviderFile();
         $feedLog->setPath($config->get('app.file.store.dir') . 'logs/feeds.log');
         $feedLog->writeLine(array($this->ActiveRecordType, $this->type, date('Y-m-d H:i:s'), $request->getUserAgent(), $request->getIP()));
     } catch (IllegalArguementException $e) {
         self::$logger->error($e->getMessage());
         throw new ResourceNotFoundException($e->getMessage());
     }
     self::$logger->debug('<<doGet');
     return $response;
 }
示例#3
0
 /**
  * Handle GET requests.
  *
  * @param Alpha\Util\Http\Request $request
  *
  * @return Alpha\Util\Http\Response
  *
  * @since 1.0
  *
  * @throws Alpha\Exception\IllegalArguementException
  */
 public function doGET($request)
 {
     self::$logger->debug('>>doGET($request=[' . var_export($request, true) . '])');
     $params = $request->getParams();
     if (isset($params['start']) ? $this->startPoint = $params['start'] : ($this->startPoint = 0)) {
     }
     $config = ConfigProvider::getInstance();
     $KPI = new KPI('search');
     $body = '';
     if (isset($params['query'])) {
         $this->query = $params['query'];
         // replace any %20 on the URL with spaces
         $params['query'] = str_replace('%20', ' ', $params['query']);
         $this->setTitle('Search results - ' . $params['query']);
         $body .= View::displayPageHead($this);
         // log the user's search query in a log file
         $log = new LogProviderFile();
         $log->setPath($config->get('app.file.store.dir') . 'logs/search.log');
         $log->writeLine(array($params['query'], date('Y-m-d H:i:s'), $request->getUserAgent(), $request->getIP()));
         $KPI->logStep('log search query');
         $provider = SearchProviderFactory::getInstance('Alpha\\Util\\Search\\SearchProviderTags');
         // if a BO name is provided, only search tags on that class, otherwise search all BOs
         if (isset($params['ActiveRecordType'])) {
             $results = $provider->search($params['query'], $params['bo'], $this->startPoint);
         } else {
             $results = $provider->search($params['query'], 'all', $this->startPoint);
         }
         $this->resultCount = $provider->getNumberFound();
         $KPI->logStep('search completed using SearchProviderTags provider');
         $body .= $this->renderResultList($results, $params['query']);
     } else {
         $this->setTitle('Search results');
         $body .= View::displayPageHead($this);
         self::$logger->debug('No search query provided!');
     }
     $body .= View::displayPageFoot($this);
     $KPI->log();
     self::$logger->debug('<<doGET');
     return new Response(200, $body, array('Content-Type' => 'text/html'));
 }
示例#4
0
文件: KPI.php 项目: alphadevx/alpha
 /**
  * Writes a step in the KPI event to a log file named logs/kpi-'.$this->name->getValue().'.csv, which will be created if it does
  * not exist.
  *
  * @since 1.1
  */
 public function logStep($stepName)
 {
     $config = ConfigProvider::getInstance();
     $this->endTime = microtime(true);
     $this->duration = $this->endTime - $this->startTime;
     $logfile = new LogProviderFile();
     $logfile->setPath($config->get('app.file.store.dir') . 'logs/kpi-' . $this->name->getValue() . '.csv');
     $logfile->setMaxSize($config->get('app.log.file.max.size'));
     $logfile->writeLine(array($this->timeStamp, $this->name->getValue() . ' [' . $stepName . ']', $this->sessionID, $this->startTime, $this->endTime, $this->duration));
 }