Ce bundle fournit un ensemble de tâches Castor pour faciliter le développement et le déploiement d'applications Symfony.
Ce bundle nécessite l'installation préalable de Castor CLI sur votre système. Pour l'installer, suivez les instructions sur la page d'installation officielle de Castor.
- Installez le bundle via Composer :
composer require thedevopser/castor-symfony
- Enregistrez le bundle dans votre application en ajoutant la ligne suivante dans
config/bundles.php
:
return [
// ...
TheDevOpser\CastorBundle\CastorBundle::class => ['all' => true],
];
- Installez les fichiers castor.php et castorPersonal.php à la racine de votre projet :
php bin/console castor:install
Note: Lors des mises à jour du bundle, relancez cette commande pour obtenir la dernière version du fichier castor.php
. Le fichier castorPersonal.php
ne sera pas écrasé.
Le bundle installe deux fichiers à la racine de votre projet :
castor.php
: Le fichier principal contenant les tâches prédéfiniescastorPersonal.php
: Un fichier pour vos tâches personnalisées
Le fichier castorPersonal.php
est créé lors de la première installation et n'est jamais écrasé lors des mises à jour du bundle. C'est l'endroit idéal pour ajouter vos propres tâches et personnalisations.
Exemple de personnalisation dans castorPersonal.php
:
<?php
use Castor\Attribute\AsTask;
use function Castor\run;
#[AsTask(description: 'Ma tâche personnalisée')]
function maTask(): void
{
run('echo "Hello from my custom task!"');
}
castor project-init [--node] [--migrate]
: Initialise un nouveau projet Symfony- Options :
--node
: Active l'installation des dépendances Node.js--migrate
: Execute les migrations après l'initialisation
- Options :
castor install-packages
: Installe les dépendances Composer et Node.js- Options :
--node
: Active la prise en charge de Node.Js
- Options :
castor create-db
: Crée la base de donnéescastor create-migration
: Génère une nouvelle migrationcastor migrate
: Exécute les migrations en attente
castor phpstan
: Analyse le code avec PHPStancastor phpcsfixer
: Vérifie et corrige le formatage PSR-12castor phpcbf
: Corrige automatiquement les erreurs de style PSR-12
castor pull-main [--migrate]
: Met à jour la branche principale- Options :
--migrate
: Execute les migrations après la mise à jour
- Options :
castor rebase {branch}
: Rebase une branche sur main
castor docker-up
: Démarre les containers Dockercastor docker-down
: Arrête les containers Docker
castor clean [env]
: Nettoie le cache- Arguments :
env
: Environnement cible (défaut: 'dev')
- Arguments :
castor create-vhost [--ssl]
: Crée un virtual host pour votre projet- Options :
--ssl
: Active la configuration SSL si les certificats sont configurés
- Options :
Ajoutez la configuration suivante dans config/packages/castor.yaml
:
castor:
vhost:
url: "%env(CASTOR_VHOST_URL)%"
nom: null
server: "%env(CASTOR_VHOST_SERVER)%"
os: null
ssl:
enabled: "%env(CASTOR_VHOST_SSL_ENABLE)%"
certificate: null
certificate_key: null
Certaines de ces variables peuvent être définies dans le fichier .env :
CASTOR_VHOST_URL=local
CASTOR_VHOST_SERVER=apache2
CASTOR_VHOST_SSL_ENABLE=false
Configuration basique:
castor:
vhost:
url: "%env(CASTOR_VHOST_URL)%"
server: "%env(CASTOR_VHOST_SERVER)%"
CASTOR_VHOST_SERVER=apache2
CASTOR_VHOST_URL="dev.local"
Configuration avec SSL:
castor:
vhost:
url: "%env(CASTOR_VHOST_URL)%"
nom: "mysuperproject"
server: "%env(CASTOR_VHOST_SERVER)%"
os: "rhel"
ssl:
enabled: "%env(CASTOR_VHOST_SSL_ENABLE)%"
certificate: "/etc/ssl/certs/my-cert.pem"
certificate_key: "/etc/ssl/private/my-cert.key"
CASTOR_VHOST_SERVER=nginx
CASTOR_VHOST_URL="dev.local"
CASTOR_VHOST_SSL_ENABLE=true
This bundle provides a set of Castor tasks to facilitate the development and deployment of Symfony applications.
This bundle requires Castor CLI to be installed on your system. To install it, follow the instructions on the official Castor installation page.
- Install the bundle via Composer:
composer require thedevopser/castor-symfony
- Register the bundle in your application by adding the following line in
config/bundles.php
:
return [
// ...
TheDevOpser\CastorBundle\CastorBundle::class => ['all' => true],
];
- Install the castor.php and castorPersonal.php files at the root of your project:
php bin/console castor:install
Note: During bundle updates, rerun this command to get the latest version of the castor.php
file. The castorPersonal.php
file will not be overwritten.
The bundle installs two files at the root of your project:
castor.php
: The main file containing predefined taskscastorPersonal.php
: A file for your custom tasks
The castorPersonal.php
file is created during the first installation and is never overwritten during bundle updates. This is the ideal place to add your own tasks and customizations.
Example of customization in castorPersonal.php
:
<?php
use Castor\Attribute\AsTask;
use function Castor\run;
#[AsTask(description: 'My custom task')]
function myTask(): void
{
run('echo "Hello from my custom task!"');
}
castor project-init [--node] [--migrate]
: Initializes a new Symfony project- Options:
--node
: Enables Node.js dependencies installation--migrate
: Executes migrations after initialization
- Options:
castor install-packages
: Installs Composer and Node.js dependencies
castor create-db
: Creates the databasecastor create-migration
: Generates a new migrationcastor migrate
: Executes pending migrations
castor phpstan
: Analyzes code with PHPStancastor phpcsfixer
: Checks and fixes PSR-12 formattingcastor phpcbf
: Automatically fixes PSR-12 style errors
castor pull-main [--migrate]
: Updates the main branch- Options:
--migrate
: Executes migrations after update
- Options:
castor rebase {branch}
: Rebases a branch onto main
castor docker-up
: Starts Docker containerscastor docker-down
: Stops Docker containers
castor clean [env]
: Cleans the cache- Arguments:
env
: Target environment (default: 'dev')
- Arguments:
castor create-vhost [--ssl]
: Creates a virtual host for your project- Options:
--ssl
: Enables SSL configuration if certificates are configured
- Options:
Add the following configuration in config/packages/castor.yaml
:
castor:
vhost:
url: "%env(CASTOR_VHOST_URL)%"
nom: null
server: "%env(CASTOR_VHOST_SERVER)%"
os: null
ssl:
enabled: "%env(CASTOR_VHOST_SSL_ENABLE)%"
certificate: null
certificate_key: null
Variables can be defined in the .env file:
CASTOR_VHOST_URL=local
CASTOR_VHOST_SERVER=apache2
CASTOR_VHOST_SSL_ENABLE=false
Basic configuration:
castor:
vhost:
url: "%env(CASTOR_VHOST_URL)%"
server: "%env(CASTOR_VHOST_SERVER)%"
CASTOR_VHOST_SERVER=apache2
CASTOR_VHOST_URL="dev.local"
SSL configuration:
castor:
vhost:
url: "%env(CASTOR_VHOST_URL)%"
nom: "mysuperproject"
server: "%env(CASTOR_VHOST_SERVER)%"
os: "rhel"
ssl:
enabled: "%env(CASTOR_VHOST_SSL_ENABLE)%"
certificate: "/etc/ssl/certs/my-cert.pem"
certificate_key: "/etc/ssl/private/my-cert.key"
CASTOR_VHOST_SERVER=nginx
CASTOR_VHOST_URL="dev.local"
CASTOR_VHOST_SSL_ENABLE=true