From c527b74930da0c509e4a5ee9afa02e037094031d Mon Sep 17 00:00:00 2001 From: jtfnetoo Date: Tue, 31 Jan 2023 15:30:28 -0400 Subject: [PATCH] Estrutura inicial --- .gitignore | 34 +++ .styleci.yml | 1 + composer.json | 32 +++ .../Providers/IntegratorServiceProvider.php | 47 +++++ .../JasperServerRequestServiceContract.php | 75 +++++++ .../Services/JasperServerRequestService.php | 197 ++++++++++++++++++ src/config/config.php | 9 + tools/php-cs-fixer/composer.json | 5 + 8 files changed, 400 insertions(+) create mode 100644 .gitignore create mode 100644 .styleci.yml create mode 100644 composer.json create mode 100644 src/app/Providers/IntegratorServiceProvider.php create mode 100644 src/app/Services/Contracts/JasperServerRequestServiceContract.php create mode 100644 src/app/Services/JasperServerRequestService.php create mode 100644 src/config/config.php create mode 100755 tools/php-cs-fixer/composer.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a3bc88a --- /dev/null +++ b/.gitignore @@ -0,0 +1,34 @@ +### Laravel template +/vendor/ +node_modules/ +npm-debug.log +yarn-error.log +composer.lock + +# Laravel 4 specific +bootstrap/compiled.php +app/storage/ + +# Laravel 5 & Lumen specific +public/storage +public/hot + +# Laravel 5 & Lumen specific with changed public path +public_html/storage +public_html/hot + +storage/*.key +.env +Homestead.yaml +Homestead.json +/.vagrant +.phpunit.result.cache + +# php-cs-fixer +.php-cs-fixer.cache +tools/php-cs-fixer/vendor +tools/php-cs-fixer/composer.lock + +# IDE +.idea +.vscode \ No newline at end of file diff --git a/.styleci.yml b/.styleci.yml new file mode 100644 index 0000000..0485874 --- /dev/null +++ b/.styleci.yml @@ -0,0 +1 @@ +preset: symfony \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..d08a12b --- /dev/null +++ b/composer.json @@ -0,0 +1,32 @@ +{ + "name": "ae3/jasperserver-laravel-integrator", + "description": "Esta lib permite requisições às rotas rest2 do jasperserver a partir de um projeto em Laravel. ", + "minimum-stability": "dev", + "license": "MIT", + "authors": [ + { + "name": "José Tobias de Freitas Neto", + "email": "tobias@ae3tecnologia.com.br" + } + ], + "require": { + "php": "^7.1.3", + "laravel/framework": "5.8.*", + "jaspersoft/rest-client": "^2.0" + }, + "require-dev": { + "orchestra/testbench": "^3.8" + }, + "autoload": { + "psr-4": { + "Ae3\\JasperServer\\Laravel\\Integrator\\": "src/" + } + }, + "extra": { + "laravel": { + "providers": [ + "Ae3\\JasperServer\\Laravel\\Integrator\\app\\Providers\\IntegratorServiceProvider" + ] + } + } +} \ No newline at end of file diff --git a/src/app/Providers/IntegratorServiceProvider.php b/src/app/Providers/IntegratorServiceProvider.php new file mode 100644 index 0000000..69d6261 --- /dev/null +++ b/src/app/Providers/IntegratorServiceProvider.php @@ -0,0 +1,47 @@ +mergeConfigFrom(__DIR__ . '/../../config/config.php', 'jasperserver-laravel-integrator'); + } + + /** + * Bootstrap any application services. + * + * @return void + */ + public function boot() + { + if ($this->app->runningInConsole()) { + $this->publishes([ + __DIR__ . '/../../config/config.php' => config_path('jasperserver-laravel-integrator.php'), + ], 'config'); + } + + $this->app->bind(JasperServerRequestServiceContract::class, function ($app) { + $config = $app['config']['jasperserver-laravel-integrator']['server']; + + $client = $this->app->make(Client::class, [ + 'serverUrl' => $config['uri'], + 'username' => $config['username'], + 'password' => $config['password'] + ]); + + return new JasperServerRequestService($client); + }); + } +} diff --git a/src/app/Services/Contracts/JasperServerRequestServiceContract.php b/src/app/Services/Contracts/JasperServerRequestServiceContract.php new file mode 100644 index 0000000..24b6f0e --- /dev/null +++ b/src/app/Services/Contracts/JasperServerRequestServiceContract.php @@ -0,0 +1,75 @@ +client = $client; + } + + /** + * @param string $key + * @param $value + * @return $this + */ + public function addInputControl(string $key, $value): self + { + if (!$this->inputControls) { + $this->inputControls = []; + } + $this->inputControls[$key] = $value; + return $this; + } + + /** + * @param int $timeout + * @return $this + */ + public function setRequestTimeout(int $timeout): self + { + $this->requestTimeout = $timeout; + return $this; + } + + /** + * @param string $format + * @return $this + */ + public function setFormat(string $format): self + { + $this->format = $format; + return $this; + } + + /** + * @param $attachmentsPrefix + * @return $this + */ + public function setAttachmentsPrefix($attachmentsPrefix): self + { + $this->attachmentsPrefix = $attachmentsPrefix; + return $this; + } + + /** + * @param bool $freshData + * @return $this + */ + public function setFreshData(bool $freshData): self + { + $this->freshData = $freshData; + return $this; + } + + /** + * @param bool $interactive + * @return $this + */ + public function setInteractive(bool $interactive): self + { + $this->interactive = $interactive; + return $this; + } + + /** + * @param bool $onePagePerSheet + * @return $this + */ + public function setOnePagePerSheet(bool $onePagePerSheet): self + { + $this->onePagePerSheet = $onePagePerSheet; + return $this; + } + + /** + * @param string $pages + * @return $this + */ + public function setPages(string $pages): self + { + $this->pages = $pages; + return $this; + } + + /** + * @param bool $saveDataSnapshot + * @return $this + */ + public function setSaveDataSnapshot(bool $saveDataSnapshot): self + { + $this->saveDataSnapshot = $saveDataSnapshot; + return $this; + } + + /** + * @param string $transformerKey + * @return $this + */ + public function setTransformerKey(string $transformerKey): self + { + $this->transformerKey = $transformerKey; + return $this; + } + + /** + * @param string $uri + * @return string + */ + public function call(string $uri): string + { + return $this->client->reportService()->runReport( + $uri, + $this->format, + $this->pages, + $this->attachmentsPrefix, + $this->inputControls, + $this->interactive, + $this->onePagePerSheet, + $this->freshData, + $this->saveDataSnapshot, + $this->transformerKey + ); + } +} diff --git a/src/config/config.php b/src/config/config.php new file mode 100644 index 0000000..8149fc2 --- /dev/null +++ b/src/config/config.php @@ -0,0 +1,9 @@ + [ + 'uri' => env('JASPER_SERVER_URL'), + 'username' => env('JASPER_SERVER_USERNAME'), + 'password' => env('JASPER_SERVER_PASSWORD') + ] +]; diff --git a/tools/php-cs-fixer/composer.json b/tools/php-cs-fixer/composer.json new file mode 100755 index 0000000..e18a35e --- /dev/null +++ b/tools/php-cs-fixer/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "friendsofphp/php-cs-fixer": "^3.14" + } +}