diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml deleted file mode 100644 index e69de29..0000000 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..fb46884 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,28 @@ +name: test + +on: [push] + +concurrency: production_environment + +jobs: + test: + runs-on: ubuntu-latest + + name: Check code style and run tests + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.1 + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo + coverage: none + + - name: Install PHP dependencies (composer) + run: composer install + + - name: Check code style + run: composer phpcs diff --git a/.gitignore b/.gitignore index 5e5b895..b5b127d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,8 @@ /vendor/ -composer.lock .idea *.tar.gz *.zip *.code-workspace # Ignore *.sql except on the src/create_catalog_sql directory *.sql -!src/create_catalog_sql/*.sql \ No newline at end of file +!src/create_catalog_sql/*.sql diff --git a/README.md b/README.md index 9129868..a095fa8 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,17 @@ # catalogs-php A PHP framework to talk to Catalogs. Part of the [CloudFest 2024 Hackathon](https://hackathon.cloudfest.com/project/integrating-mariadb-catalogs-with-php-platforms/). -# Useage +# Installation Include the catalog-php with composer: - composer require mariadb/catalogs-php + ```bash + composer require mariadb/catalogs-php:dev-main + ``` +Include autoloader in your project. + + ```php + =5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" + }, + "bin": [ + "bin/phpcbf", + "bin/phpcs" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "Former lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "Current lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/PHP_CodeSniffer/issues", + "security": "https://github.com/PHPCSStandards/PHP_CodeSniffer/security/policy", + "source": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "wiki": "https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2024-02-16T15:06:51+00:00" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=8.0", + "ext-pdo": "*" + }, + "platform-dev": [], + "platform-overrides": { + "php": "8.0" + }, + "plugin-api-version": "2.6.0" +} diff --git a/src/Catalog.php b/src/Catalog.php index 2f6f030..9768e60 100644 --- a/src/Catalog.php +++ b/src/Catalog.php @@ -88,7 +88,7 @@ public function create(string $catName): int throw new Exception('Catalog name already exists.'); } - $root_privileges = $this->connection->query("SELECT * FROM mysql.global_priv WHERE User='{$this->dbUser}' AND Host='%';"); + $rootPrivileges = $this->connection->query("SELECT * FROM mysql.global_priv WHERE User='{$this->dbUser}' AND Host='%';"); $scripts = [ 'src/create_catalog_sql/mysql_system_tables.sql', @@ -121,9 +121,12 @@ public function create(string $catName): int $this->connection->exec($content); } - if ($root_privileges->rowCount() > 0) { - foreach ($root_privileges as $privilege) { - $this->connection->exec("INSERT INTO mysql.global_priv VALUES ('{$privilege['Host']}', '{$privilege['User']}', '{$privilege['Priv']}');"); + if ($rootPrivileges->rowCount() > 0) { + foreach ($rootPrivileges as $privilege) { + $host = $privilege['Host']; + $user = $privilege['User']; + $priv = $privilege['Priv']; + $this->connection->exec("INSERT INTO mysql.global_priv VALUES ('{$host}', '{$user}', '{$priv}');"); } } @@ -203,7 +206,7 @@ public function drop(string $catName): bool $this->connection->exec('DROP CATALOG '.$catName); } catch (\PDOException $e) { throw new \Exception('Error dropping catalog: '.$e->getMessage()); - }//end try + } return true;