public function test_add()
 {
     ErrorHandler::enable();
     $repo = $this->getRepo();
     $neo = $repo->createActor(array('name' => 'Keanu Reeves'));
     $repo->saveActor($neo);
     $this->assertSame(2, $neo->id);
 }
예제 #2
0
파일: Page.php 프로젝트: sledgehammer/mvc
 /**
  * Vraag de headers op en werk de interne headers array bij.
  *
  * @return array
  */
 public function getHeaders()
 {
     $headers = array('http' => array('Content-Type' => $this->contentType), 'charset' => Framework::$charset, 'htmlParameters' => array(), 'bodyParameters' => array());
     if (defined('Sledgehammer\\WEBPATH') && \Sledgehammer\WEBPATH != '/' && file_exists(\Sledgehammer\PATH . 'application/public/favicon.ico')) {
         $headers['link']['favicon'] = array('rel' => 'shortcut icon', 'href' => \Sledgehammer\WEBROOT . 'favicon.ico', 'type' => 'image/x-icon');
     }
     // $headers['http']['Content-Type'] = 'application/xhtml+xml';
     if (ErrorHandler::instance()->html) {
         $headers['css']['debug'] = \Sledgehammer\WEBROOT . 'core/css/debug.css';
     }
     $this->headers = \Sledgehammer\merge_headers($headers, $this->content);
     if (empty($this->headers['title'])) {
         notice('getHeaders() should contain a "title" element for a HTMLDocument');
     }
     return $this->headers;
 }
예제 #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);
     }
 }
예제 #4
0
<?php

use Plandown\App;
use Sledgehammer\Core\Debug\ErrorHandler;
/**
 * rewrite.php
 */
define('Sledgehammer\\STARTED', microtime(true));
if (isset($_SERVER['HEROKU_ADMIN'])) {
    $_SERVER['SERVER_ADMIN'] = $_SERVER['HEROKU_ADMIN'];
}
include dirname(__FILE__) . '/../vendor/sledgehammer/core/src/render_public_folders.php';
require dirname(__FILE__) . '/../vendor/autoload.php';
ErrorHandler::enable();
$app = new App();
$app->handleRequest();
예제 #5
0
<?php

/**
 * Install a PEAR package into the /verdor/pear/ folder.
 */
namespace Sledgehammer\Core;

use Sledgehammer\Core\Debug\Autoloader;
use Sledgehammer\Core\Debug\ErrorHandler;
require __DIR__ . '/../bootstrap.php';
ErrorHandler::instance()->html = false;
ErrorHandler::instance()->cli = true;
Autoloader::instance()->importFolder(__DIR__ . '/classes');
if ($argc < 2) {
    echo '  Usage: php ' . $argv[0] . " [channel] [channel/]package[-version] ...\n ";
    echo "  Examples:\n";
    echo '    php ' . $argv[0] . " pear.phpunit.de/PHPUnit\n";
    echo '    php ' . $argv[0] . " PhpDocumentor\n";
    echo '    php ' . $argv[0] . " pear.doctrine-project.org DoctrineORM CouchDB-alpha DoctrineCommon-2.1.2\n";
    echo "\n";
    exit(1);
}
$targets = array('php' => \Sledgehammer\PATH . 'vendor/pear/php', 'data' => \Sledgehammer\PATH . 'vendor/pear/data', 'script' => \Sledgehammer\PATH . 'vendor/pear/script', 'bin' => \Sledgehammer\PATH . 'vendor/pear/bin', 'doc' => \Sledgehammer\PATH . 'vendor/pear/docs', 'www' => APP_DIR . 'vendor/pear/www');
$pear = new PearInstaller($targets);
$pear->on('channelAdded', function ($sender, $domain, $channel) {
    echo 'Channel "' . $domain . '" loaded. (' . count($channel['packages']) . " packages)\n";
});
$pear->on('installed', function ($sender, $package, $version) {
    echo '  ' . $package . ' [' . $version . "] installed.\n";
});
unset($argv[0]);
예제 #6
0
파일: Json.php 프로젝트: sledgehammer/core
 /**
  * Reports the error/exception to the ErrorHandler and returns the error as Json object.
  * The javascript client should detect and report the error to the user:
  *   if (result.success !== true) { alert(result.error); }.
  *
  * @param string|Exception $error The error message or Exception
  * @param int              $http  The HTTP status code (defaults to 400 Bad Request)
  *
  * @return Json
  */
 public static function error($error, $http = 400)
 {
     if (headers_sent() === false && DebugR::isEnabled()) {
         ErrorHandler::instance()->html = false;
     }
     if ($error instanceof Exception) {
         \Sledgehammer\report_exception($error);
         $error = $error->getMessage();
     } else {
         \Sledgehammer\warning($error);
     }
     return new self(array('success' => false, 'error' => $error), array('http' => array('Status' => $http . ' ' . Framework::$statusCodes[$http], 'Content-Type' => ErrorHandler::instance()->html ? 'text/html;  charset=utf-8' : 'application/json')));
 }
예제 #7
0
 /**
  * Report deprecated functionality.
  *
  * @param string $message     The message
  * @param mixed  $information [optional] Additional information
  */
 function deprecated($message = 'This functionality will no longer be supported in upcomming releases', $information = null)
 {
     ErrorHandler::instance()->report(E_USER_DEPRECATED, $message, $information, true);
 }