コード例 #1
0
<?php

Bootstrap::import('nl.bransom.Config');
/**
 * Description of DbConnection
 *
 * @author Rob Bosman
 */
class DbConnection
{
    private $mysqli;
    function __construct($schemaName)
    {
        $config = Config::getInstance();
        $configDb = $config->getSection('db');
        if (!isset($configDb['hostName']) or !isset($configDb['userName']) or !isset($configDb['password'])) {
            throw new Exception("Config error: please specify properties 'hostName', 'userName' and 'password'" . " in section [db].");
        }
        $hostName = $configDb['hostName'];
        $userName = $configDb['userName'];
        $password = $configDb['password'];
        $mysqli = new mysqli($hostName, $userName, $password, $schemaName);
        // check if connection has been made successfully
        if (mysqli_connect_errno()) {
            throw new Exception("Error connecting to database '{$userName}@{$hostName}' - " . mysqli_connect_error());
        }
        $mysqli->query('SET NAMES \'UTF8\'');
        $this->mysqli = $mysqli;
    }
    function __destruct()
    {
コード例 #2
0
<?php

Bootstrap::import('nl.bransom.rest.RestUrlParams');
Bootstrap::import('nl.bransom.persistency.meta.Entity');
/**
 * Description of QueryContext
 *
 * @author Rob Bosman
 */
class QueryContext
{
    const ALL_TIMES = 'All_TIMES';
    private $at;
    private $published;
    private $queryParamsMap;
    private $scopeMap;
    public function __construct(array $params, $mainEntity)
    {
        $this->at = RestUrlParams::parseTimestamp(RestUrlParams::extractValue($params, RestUrlParams::AT));
        if ($this->at == RestUrlParams::ALL_TIMES) {
            $this->at = self::ALL_TIMES;
        }
        $this->published = RestUrlParams::parseBoolean(RestUrlParams::extractValue($params, RestUrlParams::PUBLISHED));
        $this->queryParamsMap = array();
        $this->scopeMap = array();
        if ($mainEntity != NULL) {
            foreach ($params as $paramName => $paramValue) {
                // Parameters can be specified with or without entity-prefix, e.g. 'entity/property=value' or just
                // 'property=value'. Check if an entity-prefix is provided.
                $entityName = NULL;
                $propertyName = NULL;
コード例 #3
0
<?php

require_once realpath(dirname(__FILE__) . '/php/Bootstrap.class.php');
Bootstrap::initConfig(dirname(__FILE__) . '/config/config.ini');
Bootstrap::import('nl.bransom.persistency.meta.MetaData');
$metaData = MetaData::getInstance();
$appNames = $metaData->getAppNames();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
		<title>REST applications</title>
	</head>
	<body>
		<h3>REST applications</h3>
		<table>
			<?php 
foreach ($appNames as $appName) {
    ?>
				<tr><td colspan="2"><a href="REST/<?php 
    echo $appName;
    ?>
"><b><?php 
    echo $appName;
    ?>
</b></a></td></tr>
				<tr>
					<td>&nbsp;</td>
					<td>schema = <?php 
    echo $metaData->getSchema($appName)->getName();
コード例 #4
0
<?php

error_reporting(E_ALL | E_NOTICE | E_WARNING);
//$DEBUG_PROXY = 'localhost:8888';
require_once dirname(__FILE__) . '/../php/Bootstrap.class.php';
Bootstrap::initConfig(dirname(__FILE__) . '/../config/config.ini');
Bootstrap::import('nl.bransom.persistency.DbConnection');
class TestEngine
{
    public static function _createDatabaseSchema($schemaName)
    {
        $dbConnection = new DbConnection(NULL);
        $mySQLi = $dbConnection->getMySQLi();
        $queryResult = $mySQLi->multi_query("DROP DATABASE IF EXISTS `{$schemaName}`;" . "CREATE DATABASE IF NOT EXISTS `{$schemaName}`;");
        if (!$queryResult) {
            throw new Exception("Error creating database '{$schemaName}' - " . $mySQLi->error);
        }
        $queryResult->close();
    }
    public static function createDatabaseSchema($schemaName)
    {
        $dbConnection = new DbConnection(NULL);
        $mySQLi = $dbConnection->getMySQLi();
        $queryResult = $mySQLi->query("DROP DATABASE IF EXISTS `{$schemaName}`");
        if ($queryResult === FALSE) {
            throw new Exception("Error creating database '{$schemaName}' - " . $mySQLi->error);
        }
        $queryResult = $mySQLi->query("CREATE DATABASE IF NOT EXISTS `{$schemaName}`");
        if ($queryResult === FALSE) {
            throw new Exception("Error creating database '{$schemaName}' - " . $mySQLi->error);
        }
コード例 #5
0
<?php

Bootstrap::import('nl.bransom.Config');
Bootstrap::import('nl.bransom.auth.OpenIDConnect.OpenIDConnectHandler');
Bootstrap::import('nl.bransom.auth.HTPasswordHandler');
Bootstrap::startSession();
/**
 * Description of AuthHandler
 *
 * @author Rob Bosman
 */
class AuthHandler
{
    public static function getSignedInAccountId($appName, &$jwt = NULL)
    {
        $authModelPropertyName = 'authentication-model-for-app.' . $appName;
        $authModel = self::getAuthModel($authModelPropertyName);
        if ($authModel === NULL) {
            throw new Exception("Config error: please specify property '{$authModelPropertyName}' in section [auth].");
        }
        if (strcasecmp($authModel, 'OpenIDConnect') == 0) {
            $handler = new OpenIDConnectHandler($appName);
            return $handler->getSignedInAccountId($jwt);
        } else {
            if (strcasecmp($authModel, 'HTPassword') == 0) {
                return HTPasswordHandler::getSignedInAccountId();
            } else {
                if (strcasecmp($authModel, 'NONE') == 0 || $authModel == '') {
                    return 1;
                } else {
                    throw new Exception("Config error: unexpected value for property {$authModelPropertyName}: '{$authModel}'.");
コード例 #6
0
<?php

Bootstrap::import('nl.bransom.Config');
Bootstrap::import('nl.bransom.persistency.meta.Schema');
/**
 * Description of MetaData
 *
 * @author Rob Bosman
 */
class MetaData
{
    private static $instance;
    public static function getInstance()
    {
        if (!isset(MetaData::$instance)) {
            MetaData::$instance = new MetaData();
        }
        return MetaData::$instance;
    }
    private $appSchemaMap;
    private $appNamespaceUriMap;
    private $appContextRootMap;
    private function __construct()
    {
        $this->appSchemaMap = array();
        $this->appNamespaceUriMap = array();
        $this->appContextRootMap = array();
        $config = Config::getInstance();
        foreach ($config->getSection('db') as $propertyId => $value) {
            $prefix = 'schema-for-app.';
            if (strpos($propertyId, $prefix) === 0) {
コード例 #7
0
<?php

Bootstrap::import('nl.bransom.http.HttpResponseCodes');
Bootstrap::import('nl.bransom.http.InternetMediaTypes');
/**
 * Description of HttpResponder
 *
 * @author Rob Bosman
 */
class HttpResponder
{
    private static $isShutdownHandlerEnabled = FALSE;
    public static function handleFatalErrorsOnShutdown()
    {
        // Intercept any fatal error and start buffering all output to prevent fatal errors form being echoed
        // prematurely.
        register_shutdown_function('HttpResponder::handleFatalError');
        ob_start();
        self::$isShutdownHandlerEnabled = TRUE;
    }
    public static function handleFatalError()
    {
        if (self::$isShutdownHandlerEnabled === TRUE) {
            $errorMessage = ob_get_clean();
            error_log("FATAL ERROR - {$errorMessage}");
            self::respond(HttpResponseCodes::HTTP_INTERNAL_SERVER_ERROR, $errorMessage, 'text/html');
        }
    }
    public static function respond($httpResponseCode, $errorDetails = NULL, $contentType = NULL)
    {
        self::$isShutdownHandlerEnabled = FALSE;
コード例 #8
0
ファイル: import.php プロジェクト: RobBosman/vanace.WebItems
<?php

require_once realpath(dirname(__FILE__) . '/../../../bransom/php/Bootstrap.class.php');
Bootstrap::initConfig(dirname(__FILE__) . '/../../../bransom/config/config.ini');
Bootstrap::import('nl.bransom.http.HttpRequestHandler');
session_start();
$xmlUrl = $_POST['xmlUrl'];
$siteId = $_POST['site/id'];
$siteName = $_POST['site/name'];
$itemsetName = $_POST['itemset/name'];
// Download the XML and report any error.
error_reporting(E_ERROR);
$downloadedXml = new DOMDocument();
$downloadedXml->load($xmlUrl);
$lastError = error_get_last();
if ($lastError != NULL) {
    echo '<h1>Error</h1>' . $lastError['message'];
    exit;
}
error_reporting(E_ALL);
// Apply the style sheet to the downloaded XML.
$xslDoc = new DOMDocument();
$xslDoc->load('import.xsl');
$xsltProc = new XSLTProcessor();
$xsltProc->setParameter('', 'base-url', substr($xmlUrl, 0, strrpos($xmlUrl, '/')) . '/');
$xsltProc->setParameter('', 'site-id', $siteId);
$xsltProc->setParameter('', 'site-name', $siteName);
$xsltProc->setParameter('', 'itemset-name', $itemsetName);
$xsltProc->importStylesheet($xslDoc);
$dataXml = $xsltProc->transformToXML($downloadedXml);
// Convert image URL's to Base64 data.
コード例 #9
0
<?php

Bootstrap::import('nl.bransom.persistency.ObjectFetcher');
Bootstrap::import('nl.bransom.persistency.meta.ObjectEntity');
Bootstrap::import('nl.bransom.persistency.meta.Schema');
Bootstrap::import('nl.bransom.rest.ParsedObject');
Bootstrap::import('nl.bransom.rest.TemporaryIdMap');
/**
 * Description of RestParser
 *
 * @author Rob Bosman
 */
class RestParser
{
    private $parsedObjects;
    private $createdObjects;
    private $changedObjects;
    private $deletedObjects;
    private $touchedObjects;
    private $publishedObjects;
    function __construct()
    {
        $this->parsedObjects = array();
        $this->createdObjects = array();
        $this->changedObjects = array();
        $this->deletedObjects = array();
        $this->touchedObjects = array();
        $this->publishedObjects = array();
    }
    public function getParsedObjects()
    {
コード例 #10
0
<?php

Bootstrap::import('nl.bransom.Audit');
Bootstrap::import('nl.bransom.persistency.ObjectRef');
Bootstrap::import('nl.bransom.persistency.QueryEntity');
Bootstrap::import('nl.bransom.persistency.meta.Entity');
Bootstrap::import('nl.bransom.persistency.meta.Property');
Bootstrap::import('nl.bransom.persistency.meta.Schema');
Bootstrap::import('nl.bransom.persistency.Scope');
Bootstrap::import('nl.bransom.persistency.XmlConstants');
/**
 * Description of ObjectPublisher
 *
 * @author Rob Bosman
 */
class ObjectPublisher
{
    public function publish(Schema $schema, Entity $entity, $id, Audit $audit)
    {
        $this->unpublishObject($schema, $entity, $id);
        return $this->publishObject($schema, $entity, $id, $audit);
    }
    public function unpublishObject(Schema $schema, ObjectEntity $entity, $id)
    {
        $numUnpublished = 0;
        $mySQLi = $schema->getMySQLi();
        // Find any related objects that are (still) published.
        $ownedObjectRefs = $this->getOwnedObjectRefs($schema, $entity, $id, TRUE);
        if ($entity->getStateIdColumnName() != NULL) {
            // Unpublish the object at hand.
            $entityName = $entity->getName();
コード例 #11
0
ファイル: index.php プロジェクト: noikiy/lovetolove
<?php

require_once 'define.php';
require_once CONFIG_PATH . 'config.php';
date_default_timezone_set($config['time_zone']);
function __autoload($classname)
{
    require_once LIBRARY_PATH . $classname . '.php';
}
Session::init();
$imports = $config['import'];
$app = new Bootstrap();
$app->import($imports);
$app->run();
コード例 #12
0
<?php

Bootstrap::import('nl.bransom.auth.OpenIDConnect.HttpUtil');
Bootstrap::import('nl.bransom.auth.OpenIDConnect.OpenIDTokenVerifier');
Bootstrap::import('nl.bransom.auth.OpenIDConnect.SessionCache');
/**
 * Description of OpenIDContext
 *
 * @author RobB
 */
class OpenIDConnect
{
    const OPENID_CONFIG_URL_KEY = 'https://accounts.google.com/.well-known/openid-configuration';
    const OPENID_CONFIG_AUTH_ENDPOINT_KEY = 'authorization_endpoint';
    const OPENID_CONFIG_TOKEN_ENDPOINT_KEY = 'token_endpoint';
    const OPENID_CONFIG_JWKS_URI_KEY = 'jwks_uri';
    private static $ANTI_FORGERY_STATE_TOKEN_CACHE_KEY = array('id' => 'AntiForgeryStateToken', 'exp' => 600);
    // 10 minutes
    private static $OPENID_CONFIG_CACHE_KEY = array('id' => 'OpenIDConfig', 'exp' => 3600);
    // 1 hours
    private static $JWKS_CACHE_KEY = array('id' => 'JWKS', 'exp' => 3600);
    // 1 hours
    private static $PARKED_JWT_CACHE_KEY = array('id' => 'ParkedJWT', 'exp' => 10);
    // 10 seconds
    private $clientId;
    private $clientSecret;
    public function __construct($clientId, $clientSecret)
    {
        $this->clientId = $clientId;
        $this->clientSecret = $clientSecret;
    }
コード例 #13
0
<?php

Bootstrap::import('nl.bransom.persistency.Query');
Bootstrap::import('nl.bransom.persistency.Scope');
Bootstrap::import('nl.bransom.persistency.meta.Entity');
Bootstrap::import('nl.bransom.persistency.meta.Property');
/**
 * Description of QueryEntity
 *
 * @author Rob Bosman
 */
class QueryEntity extends Query
{
    const ID_CREATED = 'ID_CREATED';
    const ID_TERMINATED = 'ID_TERMINATED';
    const ID_PUBLISHED = 'ID_PUBLISHED';
    private $searchEntity;
    private $queryParams;
    private $propertyNames;
    private $scope;
    private $skipBinaries;
    public function __construct(Entity $searchEntity, QueryContext $queryContext, Scope $defaultScope, $id = NULL, $skipBinaries = FALSE)
    {
        parent::__construct($queryContext);
        $this->searchEntity = $searchEntity;
        $this->queryParams = $queryContext->getQueryParameters($searchEntity, $id);
        $this->propertyNames = array();
        $this->scope = $queryContext->getScope($searchEntity, $defaultScope);
        $this->skipBinaries = $skipBinaries;
        // If the scope doesn't include property values...
        if ($this->scope->includes(Scope::TAG_PROPERTIES) == Scope::INCLUDES_NONE) {
コード例 #14
0
<?php

Bootstrap::import('nl.bransom.persistency.meta.Entity');
Bootstrap::import('nl.bransom.persistency.meta.Relationship');
/**
 * Description of OneToManyRelationship
 *
 * @author Rob Bosman
 */
class OneToManyRelationship extends Relationship
{
    public function __construct(Entity $fkEntity, $fkColumnName, Entity $otherEntity, Entity $ownerEntity)
    {
        parent::__construct($fkEntity, array($fkColumnName => $otherEntity), $ownerEntity);
    }
}
コード例 #15
0
<?php

Bootstrap::import('nl.bransom.Audit');
Bootstrap::import('nl.bransom.persistency.ObjectPublisher');
Bootstrap::import('nl.bransom.persistency.QueryEntity');
Bootstrap::import('nl.bransom.persistency.meta.Entity');
Bootstrap::import('nl.bransom.persistency.meta.ObjectEntity');
Bootstrap::import('nl.bransom.persistency.meta.Property');
Bootstrap::import('nl.bransom.persistency.meta.Schema');
Bootstrap::import('nl.bransom.persistency.Scope');
/**
 * Description of ObjectModifier
 *
 * @author Rob Bosman
 */
class ObjectModifier
{
    private $objectPublisher;
    private $defaultQueryContext;
    function __construct(ObjectPublisher $objectPublisher)
    {
        $this->objectPublisher = $objectPublisher;
        $this->defaultQueryContext = new QueryContext(array(), NULL);
    }
    /**
     * Inserts a new object in the database and returns the newly created ID.
     *
     * @param Schema $schema
     * @param ObjectEntity $entity
     * @param array $content
     * @param Audit $audit
コード例 #16
0
<?php

error_reporting(E_ALL | E_NOTICE | E_WARNING);
require_once realpath(dirname(__FILE__) . '/../../bransom/php/Bootstrap.class.php');
Bootstrap::initConfig(dirname(__FILE__) . '/../../bransom/config/config.ini');
Bootstrap::import('nl.bransom.http.HttpRequestHandler');
Bootstrap::import('nl.bransom.http.HttpResponder');
HttpResponder::handleFatalErrorsOnShutdown();
// e.g. /webitems/newsreader/elsvanwijnen/image/330/data.jpg
$restTarget = HttpRequestHandler::getRestTarget($_SERVER['REQUEST_URI'], $_SERVER['PHP_SELF']);
// e.g [ elsvanwijnen, image, 330, data.jpg ]
if (count($restTarget) > 0) {
    $restTarget[0] = 'webitems';
}
$requestHandler = new HttpRequestHandler();
$requestHandler->dispatchRequest($_SERVER['REQUEST_METHOD'], $restTarget, $_SERVER['QUERY_STRING'], $_SERVER['HTTP_ACCEPT'], 'max-age=3600', $_REQUEST);
コード例 #17
0
<?php

Bootstrap::import('nl.bransom.persistency.QueryContext');
/**
 * Description of Query
 *
 * @author Rob Bosman
 */
abstract class Query
{
    private $queryContext;
    private $aliases;
    private $whereClauses;
    public function __construct(QueryContext $queryContext)
    {
        $this->queryContext = $queryContext;
        $this->aliases = array();
        $this->whereClauses = array();
    }
    public function getQueryContext()
    {
        return $this->queryContext;
    }
    public function getAlias($index = 0)
    {
        return $this->aliases[$index];
    }
    public function addWhereClause($paramName, $paramValue)
    {
        if (is_array($paramValue)) {
            $this->whereClauses[] = " AND " . $this->getAlias() . ".{$paramName} IN('" . implode("','", $paramValue) . "')";