Skip to content

Instantly share code, notes, and snippets.

View thibaut-decherit's full-sized avatar

Thibaut Decherit thibaut-decherit

View GitHub Profile
@thibaut-decherit
thibaut-decherit / Date and DateTime format syntaxes.md
Created March 15, 2024 11:16
Date and DateTime format syntaxes

flatpickr

Follow this documentation: https://flatpickr.js.org/formatting/

You probably want something like Y-m-d H:i:S, adapt as needed.

Do NOT use m for minutes, it's for months.

PHP (Symfony DateTimeType form input 'format' option)

@thibaut-decherit
thibaut-decherit / Symfony - SessionTokenService and SessionTokenExtension.md
Last active August 23, 2023 16:08
Symfony - SessionTokenService and SessionTokenExtension

src/Service/SessionTokenService.php

<?php

namespace App\Service;

use App\Helper\RandomDataGeneratorHelper;
use Exception;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
@thibaut-decherit
thibaut-decherit / Symfony - File Entity and File Upload.md
Last active December 14, 2023 16:16
Symfony - File Entity and File Upload

Symfony - File Entity and File Upload

Note: The file's absolute path is NOT stored in database to prevent directory traversal in case an attacker manages to modify said path through SQL injection.

Inheritance schema

  • AbstractFile
    • AbstractImageFile (extends AbstractFile)
      • ProfilePicture (extends AbstractImageFile)
      • ProjectPicture (extends AbstractImageFile)

There are certain files created by particular editors, IDEs, operating systems, etc., that do not belong in a repository. But adding system-specific files to the repo's .gitignore is considered a poor practice. This file should only exclude files and directories that are a part of the package that should not be versioned (such as the node_modules directory) as well as files that are generated (and regenerated) as artifacts of a build process.

All other files should be in your own global gitignore file:

  • Create a file called .gitignore in your home directory and add any filepath patterns you want to ignore.
  • Tell git where your global gitignore file is.

Note: The specific name and path you choose aren't important as long as you configure git to find it, as shown below. You could substitute .config/git/ignore for .gitignore in your home directory, if you prefer.

@thibaut-decherit
thibaut-decherit / Symfony - Serve Private File.md
Created February 20, 2020 17:21
Symfony - Serve Private File

Symfony - Serve Private File

Following example demonstrates how to:

  • display a private file download prompt to the user (here for a PDF file)
  • serve a private image or PDF which will be displayed on a webpage

See https://symfony.com/doc/4.4/components/http_foundation.html#serving-files

Host these files in a directory outside of /public, so they can be accessed only through the controller and its @Security() authorization. For example you could create a /private-uploads directory at the root of your project.

@thibaut-decherit
thibaut-decherit / Symfony - Increment Database Field Properly.md
Last active August 23, 2023 16:12
Symfony Increment Database Field Properly
@thibaut-decherit
thibaut-decherit / PHP - RandomDataGeneratorHelper.md
Last active August 23, 2023 16:14
PHP - RandomDataGeneratorHelper

PHP - RandomDataGeneratorHelper

src/Helper/RandomDataGeneratorHelper.php

<?php

namespace App\Helper;

use Exception;
use RuntimeException;
@thibaut-decherit
thibaut-decherit / Symfony - FilesystemHelper.md
Last active August 23, 2023 16:15
Symfony - FilesystemHelper.md

Symfony - FilesystemHelper

src/Helper/FilesystemHelper.php

<?php

namespace App\Helper;

use Exception;
use InvalidArgumentException;
@thibaut-decherit
thibaut-decherit / Symfony - StringHelper.md
Last active August 23, 2023 16:16
Symfony - StringHelper.md

Symfony - StringHelper

src/Helper/StringHelper.php

<?php

namespace App\Helper;

/**
 * Class StringHelper
@thibaut-decherit
thibaut-decherit / Symfony - UniqueRandomDataGeneratorService.md
Last active June 25, 2020 14:42
Symfony - UniqueRandomDataGeneratorService

UniqueRandomDataGeneratorService

src/Service/UniqueRandomDataGeneratorService.php

<?php

namespace App\Service;

use App\Helper\RandomDataGeneratorHelper;
use Doctrine\ORM\EntityManagerInterface;