diff --git a/vendor/mevdschee/php-crud-api/docker/debian10/Dockerfile b/vendor/mevdschee/php-crud-api/docker/debian10/Dockerfile new file mode 100644 index 0000000..cc844e2 --- /dev/null +++ b/vendor/mevdschee/php-crud-api/docker/debian10/Dockerfile @@ -0,0 +1,15 @@ +FROM debian:10 + +ARG DEBIAN_FRONTEND=noninteractive + +# install: php / mysql / postgres / tools / mssql deps +RUN apt-get update && apt-get -y install \ +php-cli php-xml \ +mariadb-server mariadb-client php-mysql \ +postgresql php-pgsql \ +postgresql-11-postgis-2.5 \ +git wget + +# install run script +ADD run.sh /usr/sbin/docker-run +CMD docker-run diff --git a/vendor/mevdschee/php-crud-api/docker/debian10/run.sh b/vendor/mevdschee/php-crud-api/docker/debian10/run.sh new file mode 100755 index 0000000..1862598 --- /dev/null +++ b/vendor/mevdschee/php-crud-api/docker/debian10/run.sh @@ -0,0 +1,58 @@ +#!/bin/bash +echo "================================================" +echo " Debian 10 (PHP 7.3)" +echo "================================================" + +echo -n "[1/4] Starting MariaDB 10.3 ..... " +# make sure mysql can create socket and lock +mkdir /var/run/mysqld && chmod 777 /var/run/mysqld +# run mysql server +nohup mysqld > /root/mysql.log 2>&1 & +# wait for mysql to become available +while ! mysqladmin ping -hlocalhost >/dev/null 2>&1; do + sleep 1 +done +# create database and user on mysql +mysql -u root >/dev/null << 'EOF' +CREATE DATABASE `php-crud-api` CHARACTER SET utf8 COLLATE utf8_general_ci; +CREATE USER 'php-crud-api'@'localhost' IDENTIFIED BY 'php-crud-api'; +GRANT ALL PRIVILEGES ON `php-crud-api`.* TO 'php-crud-api'@'localhost' WITH GRANT OPTION; +FLUSH PRIVILEGES; +EOF +echo "done" + +echo -n "[2/4] Starting PostgreSQL 11.4 .. " +# run postgres server +nohup su - -c "/usr/lib/postgresql/11/bin/postgres -D /etc/postgresql/11/main" postgres > /root/postgres.log 2>&1 & +# wait for postgres to become available +until su - -c "psql -U postgres -c '\q'" postgres >/dev/null 2>&1; do + sleep 1; +done +# create database and user on postgres +su - -c "psql -U postgres >/dev/null" postgres << 'EOF' +CREATE USER "php-crud-api" WITH PASSWORD 'php-crud-api'; +CREATE DATABASE "php-crud-api"; +GRANT ALL PRIVILEGES ON DATABASE "php-crud-api" to "php-crud-api"; +\c "php-crud-api"; +CREATE EXTENSION IF NOT EXISTS postgis; +\q +EOF +echo "done" + +echo -n "[3/4] Starting SQLServer 2017 ... " +echo "skipped" + +echo -n "[4/4] Cloning PHP-CRUD-API v2 ... " +# install software +if [ -d /php-crud-api ]; then + echo "skipped" +else + git clone --quiet https://github.com/mevdschee/php-crud-api.git + echo "done" +fi + +echo "------------------------------------------------" + +# run the tests +cd php-crud-api +php test.php diff --git a/vendor/mevdschee/php-crud-api/src/Tqdev/PhpCrudApi/Database/LazyPdo.php b/vendor/mevdschee/php-crud-api/src/Tqdev/PhpCrudApi/Database/LazyPdo.php new file mode 100644 index 0000000..87c2797 --- /dev/null +++ b/vendor/mevdschee/php-crud-api/src/Tqdev/PhpCrudApi/Database/LazyPdo.php @@ -0,0 +1,124 @@ +dsn = $dsn; + $this->user = $user; + $this->password = $password; + $this->options = $options; + $this->commands = array(); + // explicitly NOT calling super::__construct + } + + public function addInitCommand(string $command)/*: void*/ + { + $this->commands[] = $command; + } + + private function pdo() + { + if (!$this->pdo) { + $this->pdo = new \PDO($this->dsn, $this->user, $this->password, $this->options); + foreach ($this->commands as $command) { + $this->pdo->query($command); + } + } + return $this->pdo; + } + + public function reconstruct(string $dsn, /*?string*/ $user = null, /*?string*/ $password = null, array $options = array()): bool + { + $this->dsn = $dsn; + $this->user = $user; + $this->password = $password; + $this->options = $options; + $this->commands = array(); + if ($this->pdo) { + $this->pdo = null; + return true; + } + return false; + } + + public function inTransaction(): bool + { + // Do not call parent method if there is no pdo object + return $this->pdo && parent::inTransaction(); + } + + public function setAttribute($attribute, $value): bool + { + if ($this->pdo) { + return $this->pdo()->setAttribute($attribute, $value); + } + $this->options[$attribute] = $value; + return true; + } + + public function getAttribute($attribute): mixed + { + return $this->pdo()->getAttribute($attribute); + } + + public function beginTransaction(): bool + { + return $this->pdo()->beginTransaction(); + } + + public function commit(): bool + { + return $this->pdo()->commit(); + } + + public function rollBack(): bool + { + return $this->pdo()->rollBack(); + } + + public function errorCode(): mixed + { + return $this->pdo()->errorCode(); + } + + public function errorInfo(): array + { + return $this->pdo()->errorInfo(); + } + + public function exec($query): int + { + return $this->pdo()->exec($query); + } + + public function prepare($statement, $options = array()) + { + return $this->pdo()->prepare($statement, $options); + } + + public function quote($string, $parameter_type = null): string + { + return $this->pdo()->quote($string, $parameter_type); + } + + public function lastInsertId(/* ?string */$name = null): string + { + return $this->pdo()->lastInsertId($name); + } + + public function query(string $statement): \PDOStatement + { + return call_user_func_array(array($this->pdo(), 'query'), func_get_args()); + } +} diff --git a/vendor/mevdschee/php-crud-api/src/Tqdev/PhpCrudApi/Middleware/ReconnectMiddleware.php b/vendor/mevdschee/php-crud-api/src/Tqdev/PhpCrudApi/Middleware/ReconnectMiddleware.php new file mode 100644 index 0000000..fd844e6 --- /dev/null +++ b/vendor/mevdschee/php-crud-api/src/Tqdev/PhpCrudApi/Middleware/ReconnectMiddleware.php @@ -0,0 +1,93 @@ +reflection = $reflection; + $this->db = $db; + } + + private function getDriver(): string + { + $driverHandler = $this->getProperty('driverHandler', ''); + if ($driverHandler) { + return call_user_func($driverHandler); + } + return ''; + } + + private function getAddress(): string + { + $addressHandler = $this->getProperty('addressHandler', ''); + if ($addressHandler) { + return call_user_func($addressHandler); + } + return ''; + } + + private function getPort(): int + { + $portHandler = $this->getProperty('portHandler', ''); + if ($portHandler) { + return call_user_func($portHandler); + } + return 0; + } + + private function getDatabase(): string + { + $databaseHandler = $this->getProperty('databaseHandler', ''); + if ($databaseHandler) { + return call_user_func($databaseHandler); + } + return ''; + } + + private function getUsername(): string + { + $usernameHandler = $this->getProperty('usernameHandler', ''); + if ($usernameHandler) { + return call_user_func($usernameHandler); + } + return ''; + } + + private function getPassword(): string + { + $passwordHandler = $this->getProperty('passwordHandler', ''); + if ($passwordHandler) { + return call_user_func($passwordHandler); + } + return ''; + } + + public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface + { + $driver = $this->getDriver(); + $address = $this->getAddress(); + $port = $this->getPort(); + $database = $this->getDatabase(); + $username = $this->getUsername(); + $password = $this->getPassword(); + if ($driver || $address || $port || $database || $username || $password) { + $this->db->reconstruct($driver, $address, $port, $database, $username, $password); + } + return $next->handle($request); + } +}