Esempio n. 1
0
 /**
  * Builds and returns the HTML needed to fill a tab to display
  * within the Debug Bar
  *
  * @return string
  */
 public function display() : string
 {
     $routes = Services::routes(true);
     $router = Services::router(null, true);
     $output = "<h3>Matched Route</h3>";
     $output .= "<table><tbody>";
     if ($match = $router->getMatchedRoute()) {
         $output .= "<tr><td>{$match[0]}</td>";
         $output .= "<td>{$match[1]}</td></tr>";
     }
     $output .= "<tr><td>Directory:</td><td>" . htmlspecialchars($router->directory()) . "</td></tr>";
     $output .= "<tr><td>Controller:</td><td>" . htmlspecialchars($router->controllerName()) . "</td></tr>";
     $output .= "<tr><td>Method:</td><td>" . htmlspecialchars($router->methodName()) . "</td></tr>";
     $output .= "<tr><td>Params:</td><td>" . print_r($router->params(), true) . "</td></tr>";
     $output .= "</table></tbody>";
     $output .= "<h3>Defined Routes</h3>";
     $output .= "<table><tbody>";
     $routes = $routes->getRoutes();
     foreach ($routes as $from => $to) {
         $output .= "<tr>";
         $output .= "<td>" . htmlspecialchars($from) . "</td>";
         $output .= "<td>" . htmlspecialchars($to) . "</td>";
         $output .= "</tr>";
     }
     $output .= "</tbody></table>";
     return $output;
 }
Esempio n. 2
0
 /**
  * Child classes should implement this to return the timeline data
  * formatted for correct usage.
  *
  * @return mixed
  */
 protected function formatTimelineData() : array
 {
     $data = [];
     $benchmark = Services::timer(true);
     $rows = $benchmark->getTimers(6);
     foreach ($rows as $name => $info) {
         if ($name == 'total_execution') {
             continue;
         }
         $data[] = ['name' => ucwords(str_replace('_', ' ', $name)), 'component' => 'Timer', 'start' => $info['start'], 'duration' => $info['end'] - $info['start']];
     }
     return $data;
 }
Esempio n. 3
0
 /**
  * Builds and returns the HTML needed to fill a tab to display
  * within the Debug Bar
  *
  * @return string
  */
 public function display() : string
 {
     $logger = Services::logger(true);
     $logs = $logger->logCache;
     if (empty($logs) || !is_array($logs)) {
         return '<p>Nothing was logged. If you were expecting logged items, ensure that LoggerConfig file has the correct threshold set.</p>';
     }
     $output = "<table><theader><tr><th>Severity</th><th>Message</th></tr></theader><tbody>";
     foreach ($logs as $log) {
         $output .= "<tr>";
         $output .= "<td>{$log['level']}</td>";
         $output .= "<td>" . htmlspecialchars($log['msg'], ENT_SUBSTITUTE, 'UTF-8') . "</td>";
         $output .= "</tr>";
     }
     return $output . "</tbody></table>";
 }
Esempio n. 4
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     $this->viewer = Services::renderer(null, true);
 }
 /**
  * Attaches the header and the content to the passed in request object.
  * 
  * @param ResponseInterface response
  */
 public function sendLogs(ResponseInterface &$response = null)
 {
     if (is_null($response)) {
         $response = Services::response(null, true);
     }
     $data = base64_encode(utf8_encode(json_encode($this->json)));
     $response->setHeader($this->header, $data);
 }
Esempio n. 6
0
</td>
							</tr>
						<?php 
    }
    ?>
						</tbody>
					</table>

				<?php 
}
?>
			</div>

			<!-- Response -->
			<?php 
$response = \CodeIgniter\Services::response(null, true);
$response->setStatusCode(http_response_code());
?>
			<div class="content" id="response">
				<table>
					<tr>
						<td style="width: 15em">Response Status</td>
						<td><?php 
echo $response->getStatusCode() . ' - ' . $response->getReason();
?>
</td>
					</tr>
				</table>

				<?php 
$headers = $response->getHeaders();
Esempio n. 7
0
 /**
  * Gathers the script output from the buffer, replaces some execution
  * time tag in the output and displays the debug toolbar, if required.
  */
 protected function gatherOutput()
 {
     $this->output = ob_get_contents();
     ob_end_clean();
     $totalTime = $this->benchmark->getElapsedTime('total_execution');
     $this->output = str_replace('{elapsed_time}', $totalTime, $this->output);
     //--------------------------------------------------------------------
     // Display the Debug Toolbar?
     //--------------------------------------------------------------------
     if (!is_cli() && ENVIRONMENT != 'production' && $this->config->toolbarEnabled) {
         $toolbar = Services::toolbar($this->config);
         $this->output .= $toolbar->run($this->startTime, $totalTime, $this->startMemory, $this->request, $this->response);
     }
 }
Esempio n. 8
0
 /**
  * Convenience method that works with the current global $request and
  * $router instances to redirect using named/reverse-routed routes
  * to determine the URL to go to. If nothing is found, will treat
  * as a traditional redirect and pass the string in, letting
  * $response->redirect() determine the correct method and code.
  *
  * If more control is needed, you must use $response->redirect explicitly.
  *
  * @param string   $uri
  * @param $params
  */
 function redirect(string $uri, ...$params)
 {
     $response = Services::response(null, true);
     $routes = Services::routes(true);
     if ($route = $routes->reverseRoute($uri, ...$params)) {
         $uri = $route;
     }
     $response->redirect($uri);
 }
Esempio n. 9
0
 /**
  * Provides a convenient way to work with the Negotiate class
  * for content negotiation.
  *
  * @param string $type
  * @param array  $supported
  * @param bool   $strictMatch
  *
  * @return mixed
  */
 public function negotiate(string $type, array $supported, bool $strictMatch = false)
 {
     if (is_null($this->negotiate)) {
         $this->negotiate = Services::negotiator($this, true);
     }
     switch (strtolower($type)) {
         case 'media':
             return $this->negotiate->media($supported, $strictMatch);
             break;
         case 'charset':
             return $this->negotiate->charset($supported);
             break;
         case 'encoding':
             return $this->negotiate->encoding($supported);
             break;
         case 'language':
             return $this->negotiate->language($supported);
             break;
     }
     throw new \InvalidArgumentException($type . ' is not a valid negotiation type.');
 }
Esempio n. 10
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     $this->runner = Services::migrations();
 }
Esempio n. 11
0
 /**
  * URL String
  *
  * Returns the URI segments.
  *
  * @return	string
  */
 function uri_string() : string
 {
     return \CodeIgniter\Services::request()->uri->getPath();
 }
Esempio n. 12
0
 public function testRun404OverrideByClosure()
 {
     $_SERVER['argv'] = ['index.php', '/'];
     $_SERVER['argc'] = 2;
     // Inject mock router.
     $routes = new RouteCollection();
     $routes->setAutoRoute(false);
     $routes->set404Override(function () {
         echo '404 Override by Closure.';
     });
     $router = Services::router($routes);
     Services::injectMock('router', $router);
     ob_start();
     $this->codeigniter->run($routes);
     $output = ob_get_clean();
     $this->assertContains('404 Override by Closure.', $output);
 }
Esempio n. 13
0
 /**
  * Constructor.
  * 
  * @param RequestInterface $request
  * @param ResponseInterface $response
  * @param Logger $logger
  */
 public function __construct(RequestInterface $request, ResponseInterface $response, Logger $logger = null)
 {
     $this->request = $request;
     $this->response = $response;
     $this->logger = is_null($logger) ? Services::logger(true) : $logger;
     $this->logger->info('Controller "' . get_class($this) . '" loaded.');
     if ($this->forceHTTPS > 0) {
         $this->forceHTTPS($this->forceHTTPS);
     }
     $this->loadHelpers();
 }