Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/w3bdesign/statens-vegvesen-php
Fetches Statens Vegvesen API data with PHP and renders the data with Twig. Styling with Bootstrap 5.
https://github.com/w3bdesign/statens-vegvesen-php
composer oop php twig
Last synced: about 1 month ago
JSON representation
Fetches Statens Vegvesen API data with PHP and renders the data with Twig. Styling with Bootstrap 5.
- Host: GitHub
- URL: https://github.com/w3bdesign/statens-vegvesen-php
- Owner: w3bdesign
- License: mit
- Created: 2023-04-18T20:54:08.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-06-16T08:30:05.000Z (over 1 year ago)
- Last Synced: 2024-10-27T23:51:56.905Z (3 months ago)
- Topics: composer, oop, php, twig
- Language: PHP
- Homepage:
- Size: 78.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Display vehicle information from Statens Vegvesen
## Description
PHP port of https://github.com/w3bdesign/Statens-Vegvesen
Fetching vehicle information from the REST API on and displaying it.
It requires an API key that has to be set inside `.env` (rename .env.example to .env) that you can get from
## Features
- PHP with OOP
- Separation of HTML and PHP code
- Composer with class autoloader
- Error handling and type annotations
- Twig for rendering HTML
- Bootstrap 5
- Responsive design
- Input validation with HTML5
- PHPDoc comments## Instructions
To implement this inside your code, you'll need to do the following:
1. Run `composer install`
1. Import the autoloader with `require_once "vendor/autoload.php";`
2. Include the class in your project by adding the `use` statement at the top of your file:
```php
use Vehicle\VehicleDataFetcher;
use Vehicle\VehicleDataRender;```
3. Create a new instance of the `VehicleDataFetcher` class:
```php
$hasError = false;if ($_SERVER["REQUEST_METHOD"] === "POST") {
try {
$vehicleDataFetcher = new VehicleDataFetcher();
// This should be fetched from an input text value with $_POST
$regNummer = "AX58167;
$vehicleData = $vehicleDataFetcher->getVehicleData($regNummer);
} catch (Exception $e) {
$hasError = true;
}
}
```4.Render the data inside your code:
```php
if (isset($vehicleData)) {
$vehicleDataRender = new VehicleDataRender($vehicleData);
echo $vehicleDataRender->render();
}
```5. Handle the returned data or error message:
```php
if ($hasError) {
echo "";
" . $e->getMessage() . "
return;
}
```