Fixes during secondary app dev

While working on another app some bugs came up that are related to the
way the framework is included and working in combination with the app.
These changes make it more general purpose friendly.
This commit is contained in:
Dennis Eichhorn 2016-09-07 20:54:28 +02:00
parent ba881536a4
commit 14d4061beb
9 changed files with 90 additions and 10 deletions

View File

@ -47,7 +47,7 @@ class Autoloader
public static function default_autoloader(string $class)
{
$class = ltrim($class, '\\');
$class = str_replace(['_', '\\'], DIRECTORY_SEPARATOR, $class);
$class = str_replace(['_', '\\'], '/', $class);
/** @noinspection PhpIncludeInspection */
include_once __DIR__ . '/../' . $class . '.php';
@ -66,7 +66,7 @@ class Autoloader
public static function exists(string $class)
{
$class = ltrim($class, '\\');
$class = str_replace(['_', '\\'], DIRECTORY_SEPARATOR, $class);
$class = str_replace(['_', '\\'], '/', $class);
if (file_exists(__DIR__ . '/../' . $class . '.php')) {
return $class;

View File

@ -60,6 +60,9 @@ class ConnectionFactory
case 'mysql':
return new MysqlConnection($dbdata);
break;
case 'mssql':
return new SqlServerConnection($dbdata);
break;
default:
throw new \InvalidArgumentException('Database "' . $dbdata['db'] . '" is not supported.');
}

View File

@ -66,7 +66,7 @@ class MysqlConnection extends ConnectionAbstract
$this->prefix = $dbdata['prefix'];
try {
$this->con = new \PDO($this->dbdata['db'] . ':host=' . $this->dbdata['host'] . ';dbname=' . $this->dbdata['database'] . ';charset=utf8', $this->dbdata['login'], $this->dbdata['password']);
$this->con = new \PDO($this->dbdata['db'] . ':host=' . $this->dbdata['host'] . ':' . $this->dbdata['port'] . ';dbname=' . $this->dbdata['database'] . ';charset=utf8', $this->dbdata['login'], $this->dbdata['password']);
$this->con->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
$this->con->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);

View File

@ -15,7 +15,66 @@
*/
namespace phpOMS\DataStorage\Database\Connection;
abstract class SqlServerConnection extends \Exception
{
use phpOMS\DataStorage\Database\DatabaseStatus;
use phpOMS\DataStorage\Database\DatabaseType;
use phpOMS\DataStorage\Database\Query\Grammar\MysqlGrammar;
use phpOMS\DataStorage\Database\Schema\Grammar\MysqlGrammar as MysqlSchemaGrammar;
/**
* Database handler.
*
* Handles the database connection.
* Implementing wrapper functions for multiple databases is planned (far away).
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class SqlServerConnection extends ConnectionAbstract
{
/**
* Object constructor.
*
* Creates the database object and overwrites all default values.
*
* @param string[] $dbdata the basic database information for establishing a connection
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct(array $dbdata)
{
$this->type = DatabaseType::SQLSRV;
$this->grammar = new MysqlGrammar();
$this->schemaGrammar = new MysqlSchemaGrammar();
$this->connect($dbdata);
}
/**
* {@inheritdoc}
*/
public function connect(array $dbdata = null)
{
$this->close();
$this->dbdata = isset($dbdata) ? $dbdata : $this->dbdata;
$this->prefix = $dbdata['prefix'];
try {
$this->con = new \PDO('dblib:host=' . $this->dbdata['host'] . ':' . $this->dbdata['port'] . ';dbname=' . $this->dbdata['database'] . ';charset=utf8', $this->dbdata['login'], $this->dbdata['password']);
$this->con->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
$this->con->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$this->status = DatabaseStatus::OK;
} catch (\PDOException $e) {
$this->status = DatabaseStatus::MISSING_DATABASE;
$this->con = null;
} finally {
$this->dbdata['password'] = '****';
}
}
}

View File

@ -178,7 +178,7 @@ class Dispatcher
private function getController(string $controller)
{
if (!isset($this->controllers[$controller])) {
if (!file_exists($path = ROOT_PATH . '/' . str_replace('\\', '/', $controller) . '.php')) {
if (!file_exists($path = __DIR__ . '/../../' . str_replace('\\', '/', $controller) . '.php')) {
throw new PathException($path);
}

View File

@ -121,7 +121,6 @@ class Request extends RequestAbstract
$this->cleanupGlobals();
$this->path = explode('/', $this->uri->getPath());
$this->l11n->setLanguage($this->path[0]);
$this->setupUriBuilder();
$this->createRequestHashs();
@ -204,7 +203,7 @@ class Request extends RequestAbstract
UriFactory::setQuery('/scheme', $this->uri->getScheme());
UriFactory::setQuery('/host', $this->uri->getHost());
UriFactory::setQuery('/lang', $this->l11n->getLanguage());
UriFactory::setQuery('/base', $this->uri->getBase());
UriFactory::setQuery('/base', rtrim($this->uri->getBase(), '/'));
UriFactory::setQuery('/rootPath', $this->uri->getRootPath());
UriFactory::setQuery('?', $this->uri->getQuery());
UriFactory::setQuery('%', $this->uri->__toString());

View File

@ -111,7 +111,7 @@ class Router
public function route($request, int $verb = RouteVerb::GET) : array
{
if ($request instanceof RequestAbstract) {
$uri = $request->getUri();
$uri = $request->getUri()->getPath();
$verb = $request->getRouteVerb();
} elseif (is_string($request)) {
$uri = $request;

View File

@ -164,7 +164,6 @@ class Http implements UriInterface
}
$this->fragment = $url['fragment'] ?? null;
$this->base = $this->scheme . '://' . $this->host . $this->rootPath;
}
@ -257,6 +256,14 @@ class Http implements UriInterface
return $this->path ?? '';
}
/**
* {@inheritdoc}
*/
public function getPathElement(int $pos) : string
{
return explode('/', $this->path)[$pos];
}
/**
* {@inheritdoc}
*/

View File

@ -101,6 +101,18 @@ interface UriInterface
*/
public function getPath() : string;
/**
* Get path element.
*
* @param int $pos Position of the path
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getPathElement(int $pos) : string;
/**
* Get query.
*