This commit is contained in:
Vincent BRIDIER 2025-10-03 11:18:22 +02:00
parent e03693c073
commit a9debcee55
No known key found for this signature in database
GPG key ID: 8571BFA20420D512
10 changed files with 944 additions and 88 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/vendor/

115
README.md
View file

@ -1,93 +1,32 @@
# Arcadia Genesis PHP Client
## Models
## Getting started
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
### Employee
#### Props
```php
public string $matricule;
public string $lastname;
public string $firstname;
public string $start_date;
public string|null $end_date;
public string|null $planned_end_date;
public string $establishment;
public string $site;
public string $service;
```
cd existing_repo
git remote add origin https://lab.s-web.fr/ldc-web/projets/arcadia-genesis-php-client.git
git branch -M main
git push -uf origin main
#### Usage
```php
<?php
use Uwil\ArcadiaGenesisPhpClient\Datas\EmployeesDatas;
require_once 'vendor/autoload.php';
$employee = EmployeesDatas::getById("0115590");
var_dump($employee);
?>
```
## Integrate with your tools
- [ ] [Set up project integrations](https://lab.s-web.fr/ldc-web/projets/arcadia-genesis-php-client/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
### INCO
TODO

19
composer.json Normal file
View file

@ -0,0 +1,19 @@
{
"name": "uwil/arcadia-genesis-php-client",
"description": "PHP Client implementation for Arcadia Genesis API",
"type": "library",
"autoload": {
"psr-4": {
"Uwil\\ArcadiaGenesisPhpClient\\": "src/"
}
},
"authors": [
{
"name": "LDC Digital",
"email": "digital@ldc.fr"
}
],
"require": {
"guzzlehttp/guzzle": "^7.10"
}
}

615
composer.lock generated Normal file
View file

@ -0,0 +1,615 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "3059da76fcaa7e8e27afbabae06ce160",
"packages": [
{
"name": "guzzlehttp/guzzle",
"version": "7.10.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
"reference": "b51ac707cfa420b7bfd4e4d5e510ba8008e822b4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/b51ac707cfa420b7bfd4e4d5e510ba8008e822b4",
"reference": "b51ac707cfa420b7bfd4e4d5e510ba8008e822b4",
"shasum": ""
},
"require": {
"ext-json": "*",
"guzzlehttp/promises": "^2.3",
"guzzlehttp/psr7": "^2.8",
"php": "^7.2.5 || ^8.0",
"psr/http-client": "^1.0",
"symfony/deprecation-contracts": "^2.2 || ^3.0"
},
"provide": {
"psr/http-client-implementation": "1.0"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8.2",
"ext-curl": "*",
"guzzle/client-integration-tests": "3.0.2",
"php-http/message-factory": "^1.1",
"phpunit/phpunit": "^8.5.39 || ^9.6.20",
"psr/log": "^1.1 || ^2.0 || ^3.0"
},
"suggest": {
"ext-curl": "Required for CURL handler support",
"ext-intl": "Required for Internationalized Domain Name (IDN) support",
"psr/log": "Required for using the Log middleware"
},
"type": "library",
"extra": {
"bamarni-bin": {
"bin-links": true,
"forward-command": false
}
},
"autoload": {
"files": [
"src/functions_include.php"
],
"psr-4": {
"GuzzleHttp\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Graham Campbell",
"email": "hello@gjcampbell.co.uk",
"homepage": "https://github.com/GrahamCampbell"
},
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
{
"name": "Jeremy Lindblom",
"email": "jeremeamia@gmail.com",
"homepage": "https://github.com/jeremeamia"
},
{
"name": "George Mponos",
"email": "gmponos@gmail.com",
"homepage": "https://github.com/gmponos"
},
{
"name": "Tobias Nyholm",
"email": "tobias.nyholm@gmail.com",
"homepage": "https://github.com/Nyholm"
},
{
"name": "Márk Sági-Kazár",
"email": "mark.sagikazar@gmail.com",
"homepage": "https://github.com/sagikazarmark"
},
{
"name": "Tobias Schultze",
"email": "webmaster@tubo-world.de",
"homepage": "https://github.com/Tobion"
}
],
"description": "Guzzle is a PHP HTTP client library",
"keywords": [
"client",
"curl",
"framework",
"http",
"http client",
"psr-18",
"psr-7",
"rest",
"web service"
],
"support": {
"issues": "https://github.com/guzzle/guzzle/issues",
"source": "https://github.com/guzzle/guzzle/tree/7.10.0"
},
"funding": [
{
"url": "https://github.com/GrahamCampbell",
"type": "github"
},
{
"url": "https://github.com/Nyholm",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/guzzlehttp/guzzle",
"type": "tidelift"
}
],
"time": "2025-08-23T22:36:01+00:00"
},
{
"name": "guzzlehttp/promises",
"version": "2.3.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/promises.git",
"reference": "481557b130ef3790cf82b713667b43030dc9c957"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/promises/zipball/481557b130ef3790cf82b713667b43030dc9c957",
"reference": "481557b130ef3790cf82b713667b43030dc9c957",
"shasum": ""
},
"require": {
"php": "^7.2.5 || ^8.0"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8.2",
"phpunit/phpunit": "^8.5.44 || ^9.6.25"
},
"type": "library",
"extra": {
"bamarni-bin": {
"bin-links": true,
"forward-command": false
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Promise\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Graham Campbell",
"email": "hello@gjcampbell.co.uk",
"homepage": "https://github.com/GrahamCampbell"
},
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
{
"name": "Tobias Nyholm",
"email": "tobias.nyholm@gmail.com",
"homepage": "https://github.com/Nyholm"
},
{
"name": "Tobias Schultze",
"email": "webmaster@tubo-world.de",
"homepage": "https://github.com/Tobion"
}
],
"description": "Guzzle promises library",
"keywords": [
"promise"
],
"support": {
"issues": "https://github.com/guzzle/promises/issues",
"source": "https://github.com/guzzle/promises/tree/2.3.0"
},
"funding": [
{
"url": "https://github.com/GrahamCampbell",
"type": "github"
},
{
"url": "https://github.com/Nyholm",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/guzzlehttp/promises",
"type": "tidelift"
}
],
"time": "2025-08-22T14:34:08+00:00"
},
{
"name": "guzzlehttp/psr7",
"version": "2.8.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "21dc724a0583619cd1652f673303492272778051"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/21dc724a0583619cd1652f673303492272778051",
"reference": "21dc724a0583619cd1652f673303492272778051",
"shasum": ""
},
"require": {
"php": "^7.2.5 || ^8.0",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.1 || ^2.0",
"ralouphie/getallheaders": "^3.0"
},
"provide": {
"psr/http-factory-implementation": "1.0",
"psr/http-message-implementation": "1.0"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8.2",
"http-interop/http-factory-tests": "0.9.0",
"phpunit/phpunit": "^8.5.44 || ^9.6.25"
},
"suggest": {
"laminas/laminas-httphandlerrunner": "Emit PSR-7 responses"
},
"type": "library",
"extra": {
"bamarni-bin": {
"bin-links": true,
"forward-command": false
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Psr7\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Graham Campbell",
"email": "hello@gjcampbell.co.uk",
"homepage": "https://github.com/GrahamCampbell"
},
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
{
"name": "George Mponos",
"email": "gmponos@gmail.com",
"homepage": "https://github.com/gmponos"
},
{
"name": "Tobias Nyholm",
"email": "tobias.nyholm@gmail.com",
"homepage": "https://github.com/Nyholm"
},
{
"name": "Márk Sági-Kazár",
"email": "mark.sagikazar@gmail.com",
"homepage": "https://github.com/sagikazarmark"
},
{
"name": "Tobias Schultze",
"email": "webmaster@tubo-world.de",
"homepage": "https://github.com/Tobion"
},
{
"name": "Márk Sági-Kazár",
"email": "mark.sagikazar@gmail.com",
"homepage": "https://sagikazarmark.hu"
}
],
"description": "PSR-7 message implementation that also provides common utility methods",
"keywords": [
"http",
"message",
"psr-7",
"request",
"response",
"stream",
"uri",
"url"
],
"support": {
"issues": "https://github.com/guzzle/psr7/issues",
"source": "https://github.com/guzzle/psr7/tree/2.8.0"
},
"funding": [
{
"url": "https://github.com/GrahamCampbell",
"type": "github"
},
{
"url": "https://github.com/Nyholm",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/guzzlehttp/psr7",
"type": "tidelift"
}
],
"time": "2025-08-23T21:21:41+00:00"
},
{
"name": "psr/http-client",
"version": "1.0.3",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-client.git",
"reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-client/zipball/bb5906edc1c324c9a05aa0873d40117941e5fa90",
"reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90",
"shasum": ""
},
"require": {
"php": "^7.0 || ^8.0",
"psr/http-message": "^1.0 || ^2.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Http\\Client\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"description": "Common interface for HTTP clients",
"homepage": "https://github.com/php-fig/http-client",
"keywords": [
"http",
"http-client",
"psr",
"psr-18"
],
"support": {
"source": "https://github.com/php-fig/http-client"
},
"time": "2023-09-23T14:17:50+00:00"
},
{
"name": "psr/http-factory",
"version": "1.1.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-factory.git",
"reference": "2b4765fddfe3b508ac62f829e852b1501d3f6e8a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-factory/zipball/2b4765fddfe3b508ac62f829e852b1501d3f6e8a",
"reference": "2b4765fddfe3b508ac62f829e852b1501d3f6e8a",
"shasum": ""
},
"require": {
"php": ">=7.1",
"psr/http-message": "^1.0 || ^2.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Http\\Message\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"description": "PSR-17: Common interfaces for PSR-7 HTTP message factories",
"keywords": [
"factory",
"http",
"message",
"psr",
"psr-17",
"psr-7",
"request",
"response"
],
"support": {
"source": "https://github.com/php-fig/http-factory"
},
"time": "2024-04-15T12:06:14+00:00"
},
{
"name": "psr/http-message",
"version": "2.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-message.git",
"reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71",
"reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71",
"shasum": ""
},
"require": {
"php": "^7.2 || ^8.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Http\\Message\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"description": "Common interface for HTTP messages",
"homepage": "https://github.com/php-fig/http-message",
"keywords": [
"http",
"http-message",
"psr",
"psr-7",
"request",
"response"
],
"support": {
"source": "https://github.com/php-fig/http-message/tree/2.0"
},
"time": "2023-04-04T09:54:51+00:00"
},
{
"name": "ralouphie/getallheaders",
"version": "3.0.3",
"source": {
"type": "git",
"url": "https://github.com/ralouphie/getallheaders.git",
"reference": "120b605dfeb996808c31b6477290a714d356e822"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822",
"reference": "120b605dfeb996808c31b6477290a714d356e822",
"shasum": ""
},
"require": {
"php": ">=5.6"
},
"require-dev": {
"php-coveralls/php-coveralls": "^2.1",
"phpunit/phpunit": "^5 || ^6.5"
},
"type": "library",
"autoload": {
"files": [
"src/getallheaders.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Ralph Khattar",
"email": "ralph.khattar@gmail.com"
}
],
"description": "A polyfill for getallheaders.",
"support": {
"issues": "https://github.com/ralouphie/getallheaders/issues",
"source": "https://github.com/ralouphie/getallheaders/tree/develop"
},
"time": "2019-03-08T08:55:37+00:00"
},
{
"name": "symfony/deprecation-contracts",
"version": "v3.6.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/deprecation-contracts.git",
"reference": "63afe740e99a13ba87ec199bb07bbdee937a5b62"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/63afe740e99a13ba87ec199bb07bbdee937a5b62",
"reference": "63afe740e99a13ba87ec199bb07bbdee937a5b62",
"shasum": ""
},
"require": {
"php": ">=8.1"
},
"type": "library",
"extra": {
"thanks": {
"url": "https://github.com/symfony/contracts",
"name": "symfony/contracts"
},
"branch-alias": {
"dev-main": "3.6-dev"
}
},
"autoload": {
"files": [
"function.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "A generic function and convention to trigger deprecation notices",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/deprecation-contracts/tree/v3.6.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2024-09-25T14:21:43+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": {},
"prefer-stable": false,
"prefer-lowest": false,
"platform": {},
"platform-dev": {},
"plugin-api-version": "2.6.0"
}

10
index.php Normal file
View file

@ -0,0 +1,10 @@
<?php
use Uwil\ArcadiaGenesisPhpClient\Datas\EmployeesDatas;
require_once 'vendor/autoload.php';
$employee = EmployeesDatas::getById("0117670");
var_dump($employee);
?>

View file

@ -0,0 +1,47 @@
<?php
namespace Uwil\ArcadiaGenesisPhpClient\Datas;
use Uwil\ArcadiaGenesisPhpClient\Models\Employee;
use Uwil\ArcadiaGenesisPhpClient\Traits\ArcadiaTrait;
use Uwil\ArcadiaGenesisPhpClient\Transport;
class EmployeesDatas
{
use ArcadiaTrait;
private static string $table = "RU_PERSONNE_SIRH";
private static array $definition = [
'matricule' => 'MATRICULE_FIC',
'lastname' => 'NOM_FIC',
'firstname' => 'PRENOM_FIC',
'start_date' => 'DATE_DEB_FIC',
'end_date' => 'DATE_FIN_FIC',
'planned_end_date' => 'DATE_EFFET_FIC',
'establishment' => 'ETAB_FIC',
'site' => 'SITE_FIC',
'service' => 'SERVICE_FIC'
];
public static function getById(string $id)
{
$params = [
'TABLE' => self::$table,
'S_COLS' => self::getArcadiaDefinition(),
'C_COLS' => self::getArcadiaDefinition(['matricule']),
'C_OPES' => ['='],
'C_VALS' => [$id],
];
$response = Transport::call($params);
if (empty($response[0]->values)) {
return null;
}
$employee = new Employee();
$employee->fill(self::mapObject($response[0]->values));
return $employee;
}
}

20
src/Models/Employee.php Normal file
View file

@ -0,0 +1,20 @@
<?php
namespace Uwil\ArcadiaGenesisPhpClient\Models;
use Uwil\ArcadiaGenesisPhpClient\Traits\ModelTrait;
class Employee
{
use ModelTrait;
public string $matricule;
public string $lastname;
public string $firstname;
public string $start_date;
public string|null $end_date;
public string|null $planned_end_date;
public string $establishment;
public string $site;
public string $service;
}

View file

@ -0,0 +1,40 @@
<?php
namespace Uwil\ArcadiaGenesisPhpClient\Traits;
trait ArcadiaTrait
{
private static function getArcadiaDefinition(array $scope = [])
{
if (empty($scope)) {
return array_values(static::$definition);
}
return array_values(array_intersect_key(static::$definition, array_flip($scope)));
}
private static function mapObject(object $object)
{
$array = [];
foreach (static::$definition as $key => $value)
{
$array[$key] = self::cleanValue($object->$value);
}
return $array;
}
// FIXME : On ne devrait pas avoir cette méthode.
private static function cleanValue(string $value) : string | null
{
// If we receive empty string instead of null, return null.
if (empty($value)) {
return null;
}
// If we receive date in FR format instead of ISO one, return ISO conversion.
$pattern = "/\b(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[0-2])\/[0-9]{4}\b/";
if (preg_match($pattern, $value, $matches)) {
$dateObject = \DateTime::createFromFormat('d/m/Y', $value);
return $dateObject->format('Y-m-d');
}
// If just string, return original value.
return $value;
}
}

13
src/Traits/ModelTrait.php Normal file
View file

@ -0,0 +1,13 @@
<?php
namespace Uwil\ArcadiaGenesisPhpClient\Traits;
trait ModelTrait
{
public function fill(array $datas)
{
foreach ($datas as $key => $value) {
$this->$key = $value;
}
}
}

152
src/Transport.php Normal file
View file

@ -0,0 +1,152 @@
<?php
namespace Uwil\ArcadiaGenesisPhpClient;
use GuzzleHttp\Psr7;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use InvalidArgumentException;
class Transport
{
private static string $endpoint = "https://lab501-arc05402.lesidc.com"; // FIXME : Move this
private static string $apiKey = "11319-1127611241-11748-11917-12156891612247-10244-11653-125778522-1195511335-11382-10886-108424242324222424242322242424232423"; // FIXME : Move this
private static string $apiSecret = "1046012368-8940-10144-1095-12022-10631103331003311372-107631276111238-12022-9129-1202-1223310126-10026957612620-10828100522324232224232414232423232423232324241424232324";
private static string $apiSignature = "TaLY2pzBFdyUd2liBteJPh2E3t6BIbiQuVy6KAgsL5I="; // FIXME : Move this
public function __construct(string $endpoint)
{
$this->endpoint = $endpoint;
}
public static function call(array $params)
{
$client = new Client([
'base_uri' => sprintf(
"%s%s",
self::$endpoint,
"/gaston/api/get",
),
'timeout' => 2.0,
]);
try {
$response = $client->request('GET', self::buildApiRequest($params), [
'headers' => [
'Content-Type' => 'application/json',
'API-KEY' => self::$apiKey,
'API-SIGNATURE' => self::$apiSignature // FIXME : Utiliser la methode getApiSignature() quand on aura le secret fourni comme dans la doc
]
]);
$body = $response->getBody()->getContents();
return $body ? json_decode($body) : null;
} catch (ClientException $e) {
//echo Psr7\Message::toString($e->getRequest());
$response = json_decode($e->getResponse()->getBody()->getContents());
var_dump($response);
exit;
}
}
private static function buildApiRequest(array $params)
{
// TABLE est obligatoire
if (empty($params['TABLE'])) {
throw new InvalidArgumentException("Le paramètre TABLE est obligatoire.");
}
// Paramètres autorisés
$allowedOps = ['=', '!=', '>', '>=', '<', '<=', 'BETWEEN', 'NOT BETWEEN', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN'];
$allowedOrder = ['ASC', 'DESC'];
// Nettoyer et préparer les paramètres
$queryParams = [];
// TABLE obligatoire
$queryParams['TABLE'] = $params['TABLE'];
// SOC facultatif
if (!empty($params['SOC'])) {
$queryParams['SOC'] = $params['SOC'];
}
// Colonnes à sélectionner
if (!empty($params['S_COLS']) && is_array($params['S_COLS'])) {
// Joindre avec pipe |
$queryParams['S_COLS'] = implode('|', $params['S_COLS']);
}
// Colonnes critères
if (!empty($params['C_COLS']) && is_array($params['C_COLS'])) {
$queryParams['C_COLS'] = implode('|', $params['C_COLS']);
}
// Opérateurs critères, vérifier qu’ils sont valides
if (!empty($params['C_OPES']) && is_array($params['C_OPES'])) {
$filteredOps = array_filter($params['C_OPES'], function($op) use ($allowedOps) {
// Comparaison insensible à la casse
return in_array(strtoupper($op), $allowedOps);
});
if (count($filteredOps) != count($params['C_OPES'])) {
throw new InvalidArgumentException("Un ou plusieurs opérateurs C_OPES sont invalides.");
}
$queryParams['C_OPES'] = implode('|', $params['C_OPES']);
}
// Valeurs critères
if (!empty($params['C_VALS']) && is_array($params['C_VALS'])) {
// Chaque valeur peut contenir plusieurs paramètres numériques séparés par virgules
// On supprime espaces inutiles
$valuesClean = array_map(function($val) {
return str_replace(' ', '', $val);
}, $params['C_VALS']);
$queryParams['C_VALS'] = implode('|', $valuesClean);
}
// Colonnes tri
if (!empty($params['T_COLS']) && is_array($params['T_COLS'])) {
$queryParams['T_COLS'] = implode('|', $params['T_COLS']);
}
// Ordres tri, valider existence dans ASC ou DESC
if (!empty($params['T_OPES']) && is_array($params['T_OPES'])) {
$filteredOrders = array_filter($params['T_OPES'], function($ord) use ($allowedOrder) {
return in_array(strtoupper($ord), $allowedOrder);
});
if (count($filteredOrders) != count($params['T_OPES'])) {
throw new InvalidArgumentException("Un ou plusieurs ordres de tri T_OPES sont invalides.");
}
$queryParams['T_OPES'] = implode('|', $params['T_OPES']);
}
// Construire la chaîne de requête
// FIXME : devrait être -> return '?' . http_build_query($queryParams); ou param query de guzzle mais cela lève une METAEXCEPTION
return '?' . self::build_query_without_encoding($queryParams);
}
private static function getApiSignature()
{
return base64_encode(
hash_hmac(
'sha256',
self::$apiKey,
self::$apiSecret,
true
)
);
}
private static function build_query_without_encoding(array $params): string {
$parts = [];
foreach ($params as $key => $value) {
// On concatène clé et valeur sans aucun encodage
$parts[] = $key . '=' . $value;
}
// On assemble les paires avec le caractère &
return implode('&', $parts);
}
}