Skip to content

Instantly share code, notes, and snippets.

View jgauthi's full-sized avatar

jgauthi

  • France
View GitHub Profile
@jgauthi
jgauthi / csv_to_array.php
Last active March 19, 2021 17:15
Convert CSV File to php array
<?php
function csv_to_array(string $file, string $delimiter = ';'): array
{
if (!file_exists($file)) {
throw new InvalidArgumentException("File '{$file}' not found");
}
$titles = $content = [];
@jgauthi
jgauthi / ExportSwaggerCommand.php
Last active April 5, 2021 14:25
[Symfony] Export Apidoc to YAML File
<?php
// src/Command/ExportSwaggerCommand.php
namespace App\Command;
use Nelmio\ApiDocBundle\ApiDocGenerator;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\{InputArgument, InputInterface};
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Yaml\Yaml;
@jgauthi
jgauthi / CinemaController.php
Last active April 7, 2021 17:17
[Symfony] Nelmio Apidoc v4, OpenApi 3 example
<?php
namespace App\Controller\Api;
use App\Collection\CinemaCollection;
use FOS\RestBundle\Controller\{AbstractFOSRestController, Annotations as Rest};
use FOS\RestBundle\View\View;
use Nelmio\ApiDocBundle\Annotation\{Model, Security};
use OpenApi\Annotations as OA;
use Symfony\Component\HttpFoundation\Request;
@jgauthi
jgauthi / CinemaController.php
Last active April 10, 2021 13:31
Nelmio api doc configuration example in symfony, with authentification schema and some refs.
<?php
// src/Controller/Api/CinemaController.php
namespace App\Controller\Api;
use App\Collection\CinemaCollection;
use FOS\RestBundle\Controller\{AbstractFOSRestController, Annotations as Rest};
use FOS\RestBundle\View\View;
use Nelmio\ApiDocBundle\Annotation\{Model, Security};
use OpenApi\Annotations as OA;
@jgauthi
jgauthi / fos_rest.yaml
Last active September 15, 2021 15:43
[Symfony] Example configuration bundle: Fos Rest
# config/packages/fos_rest.yaml
# Documentation: https://symfony.com/doc/master/bundles/FOSRestBundle/
fos_rest:
routing_loader: false
view:
view_response_listener: 'force'
formats:
json: true
xml: true
zone:
@jgauthi
jgauthi / AppFixtures.php
Last active February 12, 2024 12:43
[Symfony] Example of generation of fixture with yaml files (Nelmio Alice)
<?php
// src/DataFixtures/AppFixtures.php
namespace App\DataFixtures;
use App\DataFixtures\ORM\AppNativeLoader;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
class AppFixtures extends Fixture
{
@jgauthi
jgauthi / hCaptcha.php
Last active June 13, 2021 12:09
Form validation with HCAPTCHA (google recaptcha alternative)
<?php
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
// Complete configuration: https://hcaptcha.com
const HCAPTCHA_SECRET_KEY = '...';
const HCAPTCHA_API_KEY = '...';
/**
* @throws Exception
@jgauthi
jgauthi / redis-glue-test.php
Last active June 23, 2021 13:25 — forked from raphaelstolt/redis-glue-test.php
Redis installation test script
<?php
const TEST_KEY = 'are_we_glued';
const REDIS_HOST = 'localhost';
const REDIS_PORT = 6379;
$redis = new Redis;
try {
$redis->connect(REDIS_HOST, REDIS_PORT);
$redis->set(TEST_KEY, 'yes');
$glueStatus = $redis->get(TEST_KEY);
@jgauthi
jgauthi / example.php
Created July 26, 2022 12:49 — forked from dunglas/example.php
A GraphQL client using the Symfony HttpClient component
<?php
$query = <<<'GRAPHQL'
query GetUser($user: String!) {
user (login: $user) {
name
email
repositoriesContributedTo {
totalCount
}
@jgauthi
jgauthi / 1-Load_data.postman.js
Last active January 3, 2023 14:39
Postman: Example request body created in Javascript
// 1. First route: Get data and index them in Postman Variable
// Set this content in Request > "Tests" Tab
// Step: You can get barcode with Sale > Get by ID
var jsonData = JSON.parse(responseBody);
if (jsonData.data.idSale) {
postman.setEnvironmentVariable("saleId", jsonData.data.idSale);
}