From 3c9ddcbb8c141f2a3ab4847644ab75e3b549ac1b Mon Sep 17 00:00:00 2001 From: Sebastian Sellmeier Date: Tue, 3 Apr 2018 00:07:54 +0200 Subject: [PATCH] Inital Release --- .gitignore | 9 ++ .phpcs.php | 82 +++++++++++++++++++ .travis.yml | 54 ++++++++++++ CHANGELOG.md | 3 + LICENSE.md | 7 ++ README.md | 70 ++++++++++++++++ composer.json | 37 +++++++++ phpunit.dist.xml | 21 +++++ src/DependencyInjection/InwxApiExtension.php | 45 ++++++++++ src/Domrobot.php | 61 ++++++++++++++ .../InvalidConfigurationException.php | 11 +++ src/InwxApiBundle.php | 9 ++ src/Resources/config/services.yml | 10 +++ tests/AbstractKernelTest.php | 26 ++++++ .../ApiServiceExtensionTest.php | 20 +++++ tests/Resources/config/config.yml | 2 + tests/TestKernel.php | 46 +++++++++++ tests/var/cache/.gitkeep | 0 tests/var/logs/.gitkeep | 0 19 files changed, 513 insertions(+) create mode 100644 .gitignore create mode 100644 .phpcs.php create mode 100644 .travis.yml create mode 100644 CHANGELOG.md create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 composer.json create mode 100644 phpunit.dist.xml create mode 100644 src/DependencyInjection/InwxApiExtension.php create mode 100644 src/Domrobot.php create mode 100644 src/Exception/InvalidConfigurationException.php create mode 100644 src/InwxApiBundle.php create mode 100644 src/Resources/config/services.yml create mode 100644 tests/AbstractKernelTest.php create mode 100644 tests/DependencyInjection/ApiServiceExtensionTest.php create mode 100644 tests/Resources/config/config.yml create mode 100644 tests/TestKernel.php create mode 100644 tests/var/cache/.gitkeep create mode 100644 tests/var/logs/.gitkeep diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..530988a --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +tests/var/cache/* +!tests/var/cache/.gitkeep +tests/var/logs/* +!tests/var/logs/.gitkeep +vendor/ + +.php_cs.cache +composer.lock +php-cs-fixer diff --git a/.phpcs.php b/.phpcs.php new file mode 100644 index 0000000..f8a5bfa --- /dev/null +++ b/.phpcs.php @@ -0,0 +1,82 @@ +in(__DIR__) + ->exclude('tests/var/') + ->exclude('vendor') + ->files() + ->name('*.php') +; + +$config = PhpCsFixer\Config::create() + ->setRiskyAllowed(true) + ->setFinder($finder) + ->setRules([ + '@PSR2' => true, + '@Symfony' => true, + '@Symfony:risky' => true, + 'align_multiline_comment' => ['comment_type' => 'all_multiline'], + 'array_indentation' => true, + 'array_syntax' => true, + 'blank_line_before_return' => true, + 'class_keyword_remove' => false, + 'combine_consecutive_issets' => true, + 'combine_consecutive_unsets' => true, + 'comment_to_phpdoc' => true, + 'compact_nullable_typehint' => true, + 'date_time_immutable' => true, + 'escape_implicit_backslashes' => [ + 'double_quoted' => false, + 'heredoc_syntax' => true, + 'single_quoted' => true, + ], + 'explicit_indirect_variable' => true, + 'explicit_string_variable' => true, + 'final_internal_class' => true, + 'fully_qualified_strict_types' => true, + 'heredoc_to_nowdoc' => true, + 'linebreak_after_opening_tag' => true, + 'list_syntax' => true, + 'mb_str_functions' => true, + 'method_chaining_indentation' => true, + 'multiline_comment_opening_closing' => true, + 'multiline_whitespace_before_semicolons' => true, + 'native_function_invocation' => true, + 'no_alternative_syntax' => true, + 'no_blank_lines_before_namespace' => false, + 'no_null_property_initialization' => true, + 'no_php4_constructor' => true, + 'no_short_echo_tag' => true, + 'no_superfluous_elseif' => true, + 'no_unreachable_default_argument_value' => true, + 'no_useless_else' => true, + 'no_useless_return' => true, + 'not_operator_with_space' => true, + 'not_operator_with_successor_space' => true, + 'ordered_class_elements' => true, + 'ordered_imports' => true, + 'php_unit_dedicate_assert' => [ + 'target' => 'newest', + ], + 'php_unit_expectation' => true, + 'php_unit_mock' => true, + 'php_unit_namespaced' => true, + 'php_unit_no_expectation_annotation' => true, + 'php_unit_ordered_covers' => true, + 'php_unit_strict' => true, + 'php_unit_test_annotation' => true, + 'php_unit_test_class_requires_covers' => true, + 'phpdoc_add_missing_param_annotation' => [ + 'only_untyped' => false, + ], + 'phpdoc_order' => true, + 'phpdoc_types_order' => true, + 'psr0' => true, + 'simplified_null_return' => true, + 'strict_comparison' => true, + 'strict_param' => true, + 'string_line_ending' => true, + ]) +; + +return $config; diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..7bedb03 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,54 @@ +language: php +sudo: false + +env: + global: + - secure: p1AHe7WuwIKb/kzGisKsAFCBeiBQFF71p01TWfhvhawo1OF+ytfuAWQ9OUVFbBlANdiX2VbF8LkK1Pnkj0NLAHSry1kdyhLyEw54gTaOB66O1hf/1GBP8p9MljtGtDcBvreTtA3huEjW9eAyBeFD0IcN8NxNx6nKct7RsOHy+isiDbhezqwrYzoKVax5TaqTGb5zy1XeJRUbR4k7ZthKTcygvapmGEPLg3/Qidp6qPO2MhGwTWHu7oBUdE0cUbzrNVr1PCYZ6MYqQzLLUJDNCgsss/ap+2FTxz8ePLSXP8ce+zao0Mr3W+DCI+X1tHkgCSk9b1usj8RemUzu6dWSZqbAo2XyVWhlUSqgKDS43Dou17A35q9Dw6DkfbVhZQv9nAjhq492HcdhYBITg822L/sSo1oOems2awZlV9vRyr10ugMN6gI+KuyZkRyH36aO76IwjDx6+LL8rjrr1IXYV9EFCWWGS79Wa4QQaug5KvBc7vIaMPUGvUGhkZ2gYQuBN7cREGpgdie97dBlWA/UdCo9ecpWEzO5S2/UBu7fmRncAvFLFnW/UR2ZhYKXtY52BwBsmGQ/4LaJY7LaUGlptrf3Z6N6WC2Pev3V2be0KvcoCsnq2S/ZKgk0oN+SofTAKkm6EA8Ozl8MITlXTQKzkHcUH/VKH/uITIF5jsgsc88= + - secure: ha1UWXrQE555rvQ+UQCYf4lDdoAFui8NPNvEilr55Q4E3mWH58wHi6BI7XrAZR3I61V+FLUXRmGtucyOhHIJOeTryZT21PL8hm/MHt54k0A0VZ7oweO2cNQe+gFdaN1ibt5Dxyf2VSpiabnCSyjrbBgQYlVUCJKKUxiC2+V/PUmY5RU74d3yKWBzxnELYe6T3x0bHpYVKiTOuMMIg2Wg0iVvyTPJM4MlKHiYXLIsgk0FcL1wnBJyFWg2RJKAUsAwZFgc6G1TNTckAY60NBoX/5jNM3sqTtPws5s/nikqOM4QARz+L8TzQodUD0zJe3QfTVuC31Q3xhQq1vOg+RxENUscI+nApSPEbUWaGRQ/mPU+ToWgUzyRR80upnsgYOncPGeXMsq90fP73DDYZYOXE8P4tDz5JPsCF8kajyed2GeyzYBUD+XfZ6eYjAagfrLCP71GdQGkdcGzbz2OSBv84jdfaGT6xpRJx78OvuCm0pawU+ZPyK55Q1UWOW6aQijNVySHO15ND5R9VLmpYpgBbWZRBGAfnBV1U3BA7XtvR/shIzDeBJHIrygvQPIw3SV8stICIDsQANHHQxlggTbiJSfeDwMHToN/dFhuwN2Pp4xS9zok666Oniga+KuhROo4VyGFy6YV2fx1GQIAWxLW/MfC5KlPcenVi0hj8h1CXW4= + +matrix: + fast_finish: true + include: + - php: 5.6 + env: SYMFONY_VERSION=2.7.* + - php: 5.6 + env: SYMFONY_VERSION=2.8.* + - php: 5.6 + env: SYMFONY_VERSION=3.4.* + - php: 7.0 + env: SYMFONY_VERSION=2.7.* + - php: 7.0 + env: SYMFONY_VERSION=2.8.* + - php: 7.0 + env: SYMFONY_VERSION=3.4.* + - php: 7.1 + env: SYMFONY_VERSION=2.7.* + - php: 7.1 + env: SYMFONY_VERSION=2.8.* + - php: 7.1 + env: SYMFONY_VERSION=3.4.* + - php: 7.1 + env: SYMFONY_VERSION=4.0.* + - php: 7.2 + env: SYMFONY_VERSION=2.7.* + - php: 7.2 + env: SYMFONY_VERSION=2.8.* + - php: 7.2 + env: SYMFONY_VERSION=3.4.* + - php: 7.2 + env: SYMFONY_VERSION=4.0.* + +before_install: +- phpenv config-rm xdebug.ini || echo "xdebug not available"; +- echo "memory_limit=1G" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; + +install: +- if [ "$SYMFONY_VERSION" != "" ]; then composer require --dev --no-update "symfony/framework-bundle:${SYMFONY_VERSION}"; fi; +- composer install --no-interaction + +before_script: +- wget http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar -O php-cs-fixer && chmod +x php-cs-fixer + +script: +- "./vendor/bin/phpunit -c phpunit.dist.xml" +- "./php-cs-fixer fix --config .phpcs.php --diff --dry-run --no-interaction -v" diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..6790403 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +# Changelog +## v0.1.0 +* Initial Release diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..47ec3f4 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,7 @@ +Copyright 2018 Sebastian Sellmeier + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..c06eed3 --- /dev/null +++ b/README.md @@ -0,0 +1,70 @@ +# INWX Service Provider for Symfony + +[![Build Status](https://travis-ci.org/SebTM/inwx-api-bundle.svg?branch=master)](https://travis-ci.org/SebTM/inwx-api-bundle) +[![Total Downloads](https://img.shields.io/packagist/dt/SebTM/inwx-api-bundle.svg)](https://packagist.org/packages/SebTM/inwx-api-bundle) +[![GitHub license](https://img.shields.io/github/license/SebTM/inwx-api-bundle.svg)](https://github.com/SebTM/inwx-api-bundle/blob/master/LICENSE.md) + +A Symfony bundle for including the [INWX PHP-Client](https://github.com/inwx/php-client). + +## Installation + +The INWX bundle can be installed via [Composer](http://getcomposer.org) by +requiring the `sebtm/inwx-api-bundle` package in your project's `composer.json`: + +```json +{ + "require": { + "sebtm/inwx-api-bundle": "~0.1" + } +} +``` + +and adding an instance of `SebTM\INWX\InwxApiBundle` to your application's kernel: + +```php +class AppKernel extends Kernel +{ + public function registerBundles() + { + return [ + ... + new \SebTM\INWX\InwxApiBundle(), + ]; + } + ... +} +``` +(This is NOT needed for Symfony-Flex while using recipes!) + +## Configuration +### Sample YML Configuration + +The sample configuration which can be placed in `app/config/config.yml` file. + +```yaml +inwx_api: + environment: "production" + username: "username" + password: "password" + language: "en" + debug: false +``` + +Supported environments: "production", "test" +Supported languages: see documentation of INWX PHP-Client + +## Usage + +This bundle exposes an instance of the `SebTM\INWX\Domrobot` object: + +``` +Service | Instance Of +--- | --- +inwx_api | SebTM\INWX\Domrobot +``` + +## Links +* [INWX PHP-Client on Github](https://github.com/inwx/php-client) +* [INWX PHP-Client Documentation](https://www.inwx.de/en/help/apidoc) +* [License](https://opensource.org/licenses/MIT) +* [Symfony website](http://symfony.com/) diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..9c3d4e9 --- /dev/null +++ b/composer.json @@ -0,0 +1,37 @@ +{ + "name": "sebtm/inwx-api-bundle", + "description": "A Symfony bundle for using \"inwx/php-client\".", + "keywords": [ "inwx", "php", "client", "api", "symfony"], + "type": "symfony-bundle", + "minimum-stability": "stable", + "license": "MIT", + "authors": [ + { + "name": "Sebastian Sellmeier", + "email": "mail@sebastian-sellmeier.de" + } + ], + "require": { + "php": ">=5.6", + "inwx/domrobot": "^2.4" + }, + "require-dev": { + "symfony/framework-bundle": "^2.7|^2.8|^3.4|^4.0", + "symfony/yaml": "^2.7|^2.8|^3.4|^4.0", + "phpunit/phpunit": "^5.7|^6.5|^7.0" + }, + "autoload": { + "psr-4": { + "SebTM\\INWX\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "SebTM\\INWX\\Tests\\": "tests/" + } + }, + "config": { + "sort-packages": true + }, + "prefer-stable": true +} diff --git a/phpunit.dist.xml b/phpunit.dist.xml new file mode 100644 index 0000000..30da74d --- /dev/null +++ b/phpunit.dist.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + ./tests/ + + + diff --git a/src/DependencyInjection/InwxApiExtension.php b/src/DependencyInjection/InwxApiExtension.php new file mode 100644 index 0000000..5efde62 --- /dev/null +++ b/src/DependencyInjection/InwxApiExtension.php @@ -0,0 +1,45 @@ +load('services.yml'); + + $config = array( + 'environment' => \getenv('INWX_API_ENVIRONMENT'), + 'username' => \getenv('INWX_API_USERNAME'), + 'password' => \getenv('INWX_API_PASSWORD'), + 'language' => \getenv('INWX_API_LANGUAGE'), + 'debug' => \filter_var(\getenv('INWX_API_DEBUG'), FILTER_VALIDATE_BOOLEAN), + ); + + $validate = \array_search(false, $config, true); + if (false !== $validate && 'debug' !== $validate) { + throw new InvalidConfigurationException(); + } + + $definition = $container->getDefinition('inwx_api'); + $definition->replaceArgument(0, $config['environment']); + $definition->replaceArgument(1, $config['username']); + $definition->replaceArgument(2, $config['password']); + $definition->replaceArgument(3, $config['language']); + $definition->replaceArgument(4, $config['debug']); + } +} diff --git a/src/Domrobot.php b/src/Domrobot.php new file mode 100644 index 0000000..0f28fbb --- /dev/null +++ b/src/Domrobot.php @@ -0,0 +1,61 @@ +environment = $environment; + parent::__construct($this->getAddress($environment)); + + $this->setLanguage($language); + $this->setDebug($debug); + $this->login($username, $password); + } + + /** + * @return string + */ + public function getEnvironment() + { + return $this->environment; + } + + /** + * @param string $environment + * + * @throws \Exception Unsupported environment + * + * @return string + */ + protected function getAddress($environment) + { + switch ($environment) { + case 'production': + return ' https://api.domrobot.com/xmlrpc/'; + + case 'test': + return 'https://api.ote.domrobot.com/xmlrpc/'; + + default: + throw new \Exception('Unsupported environment!'); + } + } +} diff --git a/src/Exception/InvalidConfigurationException.php b/src/Exception/InvalidConfigurationException.php new file mode 100644 index 0000000..d054b6b --- /dev/null +++ b/src/Exception/InvalidConfigurationException.php @@ -0,0 +1,11 @@ +kernel = new TestKernel('test', true); + $this->kernel->boot(); + + $this->container = $this->kernel->getContainer(); + } +} diff --git a/tests/DependencyInjection/ApiServiceExtensionTest.php b/tests/DependencyInjection/ApiServiceExtensionTest.php new file mode 100644 index 0000000..7eac939 --- /dev/null +++ b/tests/DependencyInjection/ApiServiceExtensionTest.php @@ -0,0 +1,20 @@ +container->get('inwx_api'); + + $this->assertInstanceOf(\SebTM\INWX\Domrobot::class, $client); + } +} diff --git a/tests/Resources/config/config.yml b/tests/Resources/config/config.yml new file mode 100644 index 0000000..e6cb8ee --- /dev/null +++ b/tests/Resources/config/config.yml @@ -0,0 +1,2 @@ +framework: + secret: "TestSecret" diff --git a/tests/TestKernel.php b/tests/TestKernel.php new file mode 100644 index 0000000..e13ee79 --- /dev/null +++ b/tests/TestKernel.php @@ -0,0 +1,46 @@ +load(__DIR__.'/Resources/config/config.yml'); + } +} diff --git a/tests/var/cache/.gitkeep b/tests/var/cache/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/var/logs/.gitkeep b/tests/var/logs/.gitkeep new file mode 100644 index 0000000..e69de29