Ejemplo n.º 1
0
 /**
  * Handle an incoming request.
  *
  * @param  Request  $request
  * @param  Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     try {
         $response = $next($request);
         if (headers_sent() === false && DebugR::isEnabled()) {
             ob_start();
             \Sledgehammer\statusbar(false);
             DebugR::send('sledgehammer-statusbar', ob_get_clean());
         }
     } catch (Exception $exception) {
         $this->reportAndThrow($exception);
     } catch (Error $error) {
         $this->reportAndThrow($error);
     }
     return $response;
 }
Ejemplo n.º 2
0
 /**
  * Send a response based on the request.
  */
 public function handleRequest()
 {
     // Build document
     $document = $this->generateDocument();
     if (!defined('Sledgehammer\\GENERATED')) {
         define('Sledgehammer\\GENERATED', microtime(true));
     }
     // Send headers
     $headers = $document->getHeaders();
     \Sledgehammer\send_headers($headers['http']);
     // Send the sledgehammer-statusbar as DebugR header.
     if (DebugR::isEnabled()) {
         ob_start();
         statusbar();
         DebugR::send('sledgehammer-statusbar', ob_get_clean(), true);
     }
     // Send the contents
     $document->render();
 }
Ejemplo n.º 3
0
 /**
  * Inspect the worpress database and.
  */
 public static function initialize()
 {
     static $initialized = false;
     if ($initialized) {
         return;
     }
     $initialized = true;
     if (function_exists('the_post') === false) {
         throw new Exception('Wordpress is not yet initialized');
     }
     // Lazy database connection
     Connection::$instances['wordpress'] = function () {
         if (defined('DB_USER') === false) {
             throw new Exception('No database configured');
         }
         $connection = new Connection('mysql://' . DB_USER . ':' . DB_PASSWORD . '@' . DB_HOST . '/' . DB_NAME);
         if (empty(Logger::$instances['Database[wordpress]'])) {
             $index = array_search($connection->logger, Logger::$instances);
             unset(Logger::$instances[$index]);
             Logger::$instances['Database[wordpress]'] = $connection->logger;
         }
         return $connection;
     };
     if (empty(Connection::$instances['default'])) {
         Connection::$instances['default'] = 'wordpress';
     }
     // Sledgehammer ORM configuration
     Repository::configureDefault(function ($repo) {
         $repo->registerBackend(new WordpressRepositoryBackend());
     });
     if (defined('Sledgehammer\\WEBPATH') === false) {
         $url = new Url(WP_HOME);
         $path = $url->path === '/' ? '/' : $url->path . '/';
         define('Sledgehammer\\WEBPATH', $path);
         define('Sledgehammer\\WEBROOT', $path);
     }
     define('WEBPATH', \Sledgehammer\WEBPATH);
     if (WP_DEBUG || !empty($_GET[\Sledgehammer\DEBUG_VAR])) {
         add_action('admin_enqueue_scripts', function () {
             wp_enqueue_style('sh-debug', '/../core/css/debug.css');
         });
         add_action('admin_footer', [self::class, 'statusbar']);
         add_action('wp_footer', [self::class, 'statusbar']);
         add_action('send_headers', function () {
             if (DebugR::isEnabled()) {
                 ob_start();
                 echo $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'];
                 \Sledgehammer\statusbar();
                 DebugR::send('sledgehammer-statusbar', ob_get_clean(), true);
             }
         }, PHP_INT_MAX);
         add_filter('template_include', function ($template) {
             if (empty(ErrorHandler::$instances['default'])) {
                 ErrorHandler::enable();
             }
             if (defined('Sledgehammer\\GENERATED') === false) {
                 define('Sledgehammer\\GENERATED', microtime(true));
             }
             return $template;
         }, PHP_INT_MAX);
     }
 }
Ejemplo n.º 4
0
    define('Sledgehammer\\TMP_DIR', $__TMP_DIR);
    unset($__TMP_DIR);
}
// Case insensitive "natural order" sorting method for natcasesort() in Collection->orderBy()
define('Sledgehammer\\SORT_NATURAL_CI', -2);
// Regex for supported operators for the compare() function
define('Sledgehammer\\COMPARE_OPERATORS', '==|!=|<|<=|>|>=|IN|NOT IN|LIKE|NOT LIKE');
/**
 * 2. Declare public functions.
 */
require_once __DIR__ . '/functions.php';
// Namespaced functions
require_once __DIR__ . '/helpers.php';
// Global functions (but not guaranteed)
\Sledgehammer\mkdirs(\Sledgehammer\TMP_DIR);
/*
 * 3. Configure and register the AutoLoader
 */
require_once __DIR__ . '/Object.php';
require_once __DIR__ . '/Debug/Autoloader.php';
spl_autoload_register('Sledgehammer\\Core\\Debug\\AutoLoader::lazyRegister');
/*
 * 4. Set DebugR statusbar header.
 */
if (headers_sent() === false) {
    DebugR::send('sledgehammer-statusbar', 'no statusbar data.', true);
}
/*
 * Timestamp (in microseconds) for when the Sledgehammer Framework was initialized.
 */
define('Sledgehammer\\INITIALIZED', microtime(true));