diff --git a/Autoloader.php b/Autoloader.php index f92859284..f19cc431c 100644 --- a/Autoloader.php +++ b/Autoloader.php @@ -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; diff --git a/DataStorage/Database/Connection/ConnectionFactory.php b/DataStorage/Database/Connection/ConnectionFactory.php index 3d06ec94e..6a215faa4 100644 --- a/DataStorage/Database/Connection/ConnectionFactory.php +++ b/DataStorage/Database/Connection/ConnectionFactory.php @@ -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.'); } diff --git a/DataStorage/Database/Connection/MysqlConnection.php b/DataStorage/Database/Connection/MysqlConnection.php index 05d23b585..937b6b87a 100644 --- a/DataStorage/Database/Connection/MysqlConnection.php +++ b/DataStorage/Database/Connection/MysqlConnection.php @@ -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); diff --git a/DataStorage/Database/Connection/SqlServerConnection.php b/DataStorage/Database/Connection/SqlServerConnection.php index cd87d9ccf..2f8671941 100644 --- a/DataStorage/Database/Connection/SqlServerConnection.php +++ b/DataStorage/Database/Connection/SqlServerConnection.php @@ -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 + * @author Dennis Eichhorn + * @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 + */ + 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'] = '****'; + } + } } \ No newline at end of file diff --git a/Dispatcher/Dispatcher.php b/Dispatcher/Dispatcher.php index c28f6a88e..ec4e874d0 100644 --- a/Dispatcher/Dispatcher.php +++ b/Dispatcher/Dispatcher.php @@ -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); } diff --git a/Message/Http/Request.php b/Message/Http/Request.php index 12f6df690..d43271c17 100644 --- a/Message/Http/Request.php +++ b/Message/Http/Request.php @@ -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()); diff --git a/Router/Router.php b/Router/Router.php index 14a042552..3e3027d48 100644 --- a/Router/Router.php +++ b/Router/Router.php @@ -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; diff --git a/Uri/Http.php b/Uri/Http.php index 425906bc9..e1dcfb922 100644 --- a/Uri/Http.php +++ b/Uri/Http.php @@ -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} */ diff --git a/Uri/UriInterface.php b/Uri/UriInterface.php index 2cf869db1..fe4d653ac 100644 --- a/Uri/UriInterface.php +++ b/Uri/UriInterface.php @@ -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 + */ + public function getPathElement(int $pos) : string; + /** * Get query. *