1. Go to this page and download the library: Download amphibee/marius-api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
amphibee / marius-api example snippets
use AmphiBee\MariusApi\Facades\Campus;
use AmphiBee\MariusApi\Facades\Formation;
use AmphiBee\MariusApi\Facades\Candidature;
use AmphiBee\MariusApi\Exceptions\MariusApiException;
try {
// Get all campuses with their courses
$campuses = Campus::getCampuses();
foreach ($campuses as $campus) {
echo $campus->campus; // Campus name
echo $campus->id_campus; // Campus ID
// Access campus courses
foreach ($campus->formations as $formation) {
echo $formation->nom_formation;
echo $formation->niveau_sortie;
}
}
} catch (MariusApiException $e) {
// Handle API errors
Log::error('Marius API Error: ' . $e->getMessage());
}
try {
// Get courses for a specific campus
$formations = Formation::getFormationsByCampus('1');
foreach ($formations as $formation) {
echo $formation->id_formation;
echo $formation->nom_formation;
echo $formation->niveau_sortie;
}
} catch (MariusApiException $e) {
// Handle API errors
}
use AmphiBee\MariusApi\DTO\CandidatureDTO;
try {
$application = new CandidatureDTO([
'civilite' => 'Mr',
'nom' => 'Doe',
'prenom' => 'John',
'email' => '[email protected]',
'portable' => '0612345678',
'id_campus' => '1',
'id_formation' => '30'
]);
$response = Candidature::submit($application);
// $response contains the API response with the application ID
} catch (MariusApiException $e) {
// Handle API errors
}
namespace App\Http\Controllers;
use AmphiBee\MariusApi\DTO\CandidatureDTO;
use AmphiBee\MariusApi\Exceptions\MariusApiException;
use AmphiBee\MariusApi\Facades\Campus as Campus;
use AmphiBee\MariusApi\Facades\Formation as Formation;
use AmphiBee\MariusApi\Facades\Candidature as Candidature;
use Illuminate\Http\Request;
class ApplicationController extends Controller
{
public function index()
{
try {
return view('application.form', [
'campuses' => Campus::getCampuses()
]);
} catch (MariusApiException $e) {
return back()->withError($e->getMessage());
}
}
public function getFormations(string $campusId)
{
try {
return response()->json([
'formations' => Formation::getFormationsByCampus($campusId)
]);
} catch (MariusApiException $e) {
return response()->json(['error' => $e->getMessage()], 422);
}
}
public function submit(Request $request)
{
try {
$application = new CandidatureDTO($request->validated());
$response = Candidature::submit($application);
return redirect()
->route('application.success')
->with('application_id', $response['id_candidature']);
} catch (MariusApiException $e) {
return back()
->withInput()
->withError($e->getMessage());
}
}
}
use AmphiBee\MariusApi\Facades\Campus;
use AmphiBee\MariusApi\Facades\Formation;
use AmphiBee\MariusApi\Facades\Candidature;
it('can list all campuses', function () {
// Arrange
Campus::shouldReceive('getCampuses')
->once()
->andReturn([
// Your mock data here
]);
// Act
$response = $this->get('/applications/create');
// Assert
$response->assertOk();
});
it('can get formations for campus', function () {
// Arrange
Formation::shouldReceive('getFormationsByCampus')
->with('1')
->once()
->andReturn([
// Your mock data here
]);
// Act
$response = $this->get('/api/campus/1/formations');
// Assert
$response->assertOk();
});
use AmphiBee\MariusApi\Exceptions\MariusApiException;
try {
$campuses = Campus::getCampuses();
} catch (MariusApiException $e) {
// The error contains the message and HTTP code from the API error
Log::error('Marius API Error: ' . $e->getMessage());
// Handle the error appropriately
}
use AmphiBee\MariusApi\DTO\CandidatureDTO;
// Create from array
$application = new CandidatureDTO([
'civilite' => 'Mr',
'nom' => 'Doe',
'prenom' => 'John',
'email' => '[email protected]',
'portable' => '0612345678',
'id_campus' => '1',
'id_formation' => '30'
]);
// Create from request
$application = new CandidatureDTO($request->validated());
// Submit
$response = Candidature::submit($application);
use AmphiBee\MariusApi\DTO\CandidatureDTO;
use Illuminate\Support\Facades\Log;
try {
$application = new CandidatureDTO([
'civilite' => 'Mr',
'nom' => 'Doe',
// ... autres données
]);
$response = Candidature::submit($application);
// Log the raw response
Log::channel('api')->info('Marius API Response', [
'response' => Candidature::getRawResponse()
]);
} catch (MariusApiException $e) {
Log::channel('api')->error('Marius API Error', [
'message' => $e->getMessage(),
'trace' => $e->getTraceAsString()
]);
}
use AmphiBee\MariusApi\Exceptions\MariusApiException;
try {
$campuses = $campusService->getCampuses();
} catch (MariusApiException $e) {
// The error contains the message and HTTP code from the API error
echo $e->getMessage();
}
log
[2024-03-14 10:30:00] local.INFO: Marius API - Données d'entrée {"data":{"civilite":"Mr","nom":"Doe",...}}
[2024-03-14 10:30:01] local.INFO: Marius API - Réponse {"response":{"id_candidature":"123",...}}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.