Skip to content

Commit

Permalink
Merge pull request #42 from Chris53897/feature/symfony-6
Browse files Browse the repository at this point in the history
Drop support of Symfony < 4.4 and add support of Symfony 6
  • Loading branch information
maxbaldanza authored Jan 4, 2023
2 parents bbb2f99 + 0462299 commit 887fa15
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 78 deletions.
27 changes: 19 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,28 @@ on: [push]

jobs:
run:
runs-on: ${{ matrix.operating-system }}
runs-on: ubuntu-latest
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['7.3', '7.4', '8.1']
symfony-versions: ['3.4.*', '4.4.*', '5.4.*']
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }} with Symfony ${{ matrix.symfony-versions }}
include:
- php-versions: 7.3
symfony-versions: 4.4.*
- php-versions: 7.4
symfony-versions: 5.4.*
- php-versions: 8.0
symfony-versions: 5.4.*
- php-versions: 8.0
symfony-versions: 6.0.*
- php-versions: 8.1
symfony-versions: 6.2.*
- php-versions: 8.2
symfony-versions: 6.2.*

name: PHP ${{ matrix.php-versions }} Test with Symfony ${{ matrix.symfony-versions }}
steps:
# —— Setup Github actions 🐙 —————————————————————————————————————————————
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

# https://github.com/shivammathur/setup-php (community)
- name: Setup PHP, with composer and extensions
Expand All @@ -35,10 +46,10 @@ jobs:
# —— Composer 🧙‍️ —————————————————————————————————————————————————————————
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache composer dependencies
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
# Use composer.json for key, if composer.lock is not committed.
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
composer.lock
composer.phar
.phpunit.result.cache
bin/
vendor/
/Tests/Fixtures/app/cache/
var/
.phpunit.result.cache
4 changes: 2 additions & 2 deletions Command/DumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DumpCommand extends CommandBase
/**
* @inheritdoc
*/
protected function configure()
protected function configure(): void
{
$this
->setName('cronos:dump')
Expand All @@ -25,7 +25,7 @@ protected function configure()
/**
* @inheritdoc
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$cron = $this->configureCronExport($input, $output);

Expand Down
4 changes: 2 additions & 2 deletions Command/ReplaceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ReplaceCommand extends CommandBase
/**
* @inheritdoc
*/
protected function configure()
protected function configure(): void
{
$this
->setName('cronos:replace')
Expand All @@ -22,7 +22,7 @@ protected function configure()
/**
* @inheritdoc
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$cron = $this->configureCronExport($input, $output);
$key = $this->getExportKey();
Expand Down
19 changes: 3 additions & 16 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,10 @@ class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder(): TreeBuilder
{
if (method_exists(TreeBuilder::class, 'getRootNode')) {
// Symfony 4
$treeBuilder = new TreeBuilder('my_builder_cronos');
$rootNode = $treeBuilder->getRootNode();
} else {
// Symfony 3
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('my_builder_cronos');
}
$treeBuilder = new TreeBuilder('my_builder_cronos');
$rootNode = $treeBuilder->getRootNode();

if (method_exists(Kernel::class, 'getProjectDir')) {
// `kernel.project_dir` available since Symfony 3.3
$pathToConsole = '%kernel.project_dir%/bin/console';
} else {
// `kernel.root_dir` dropped in Symfony 5
$pathToConsole = '%kernel.root_dir%/../bin/console';
}
$pathToConsole = '%kernel.project_dir%/bin/console';

$rootNode
->children()
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/MyBuilderCronosExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class MyBuilderCronosExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$config = $this->processConfiguration(new Configuration(), $configs);

Expand Down
57 changes: 23 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Cronos Bundle

A bundle for Symfony 3/4/5 that allows you to use `@Cron` annotations to configure when cron should run your console commands.
A bundle for Symfony 4/5/6 that allows you to use `@Cron` annotations to configure when cron should run your console commands.

Uses the [Cronos](https://github.com/mybuilder/cronos) library to do the actual output and updating.

Expand All @@ -11,23 +11,12 @@ Uses the [Cronos](https://github.com/mybuilder/cronos) library to do the actual
Run the composer require command:

```bash
$ php composer.phar require mybuilder/cronos-bundle
$ composer require mybuilder/cronos-bundle
```

### Enable the bundle

Enable the bundle in the `app/AppKernel.php` for Symfony 3:

```php
public function registerBundles(): array
{
return [
new MyBuilder\Bundle\CronosBundle\MyBuilderCronosBundle(),
];
}
```

Enable the bundle in the `config/bundles.php` for Symfony 4/5:
If you do not use Symfony Flex, enable the bundle in the `config/bundles.php` for Symfony 4/5/6:

```php
return [
Expand All @@ -37,7 +26,7 @@ return [

### Configure the bundle

You can add the following to your `config.yml` (Symfony 3) / `packages/my_builder_cronos.yaml` (Symfony 4/5) to configure the package.
You can add the following to your `config/packages/my_builder_cronos.yaml` (Symfony 4/5/6) to configure the package.

```yaml
my_builder_cronos:
Expand All @@ -50,14 +39,14 @@ my_builder_cronos:
shell: /bin/bash
```
option | description
---------|-----------------------------------------
key | Unique key that wraps all the cron configured for the current application.
mailto | Sets the default email address for all cron output to go to.
path | Sets the path for all commands in the crontab it works just like the shell PATH, but it does not inherit from your environment. That means you cannot use ~ or other shell expansions.
executor | Allows you to specify a program that all commands should be passed to such as `/usr/local/bin/php`.
console | Allows you to specify the console that all commands should be passed to such as `bin/console`.
shell | Allows you to specify which shell each program should be run with.
| option | description |
|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| key | Unique key that wraps all the cron configured for the current application. |
| mailto | Sets the default email address for all cron output to go to. |
| path | Sets the path for all commands in the crontab it works just like the shell PATH, but it does not inherit from your environment. That means you cannot use ~ or other shell expansions. |
| executor | Allows you to specify a program that all commands should be passed to such as `/usr/local/bin/php`. |
| console | Allows you to specify the console that all commands should be passed to such as `bin/console`. |
| shell | Allows you to specify which shell each program should be run with. |

## Usage

Expand All @@ -83,21 +72,21 @@ class SendQueuedEmailsCommand extends Command {}

The whole point of cron is being able to specify when a script is run therefore there are a lot of options.

You should read the [general cron info](http://en.wikipedia.org/wiki/Cron) for a general idea of cron and what you can use in these time fields.
You should read the [general cron info](https://en.wikipedia.org/wiki/Cron) for a general idea of cron and what you can use in these time fields.

**Please note** You CANNOT use `*/` in the annotations, if you want `*/5` just put `/5` and [Cronos](https://github.com/mybuilder/cronos) will automatically change it to `*/5`.

### Annotation examples

annotation | description
---------------------------------------------------------|------------------------------------------
`@Cron(minute="/5")` | Every 5 minutes
`@Cron(minute="5")` | At the 5th minute of each hour
`@Cron(minute="5", hour="8")` | 5 minutes past 8am every day
`@Cron(minute="5", hour="8", dayOfWeek="0")` | 5 minutes past 8am every Sunday
`@Cron(minute="5", hour="8", dayOfMonth="1")` | 5 minutes past 8am on first of each month
`@Cron(minute="5", hour="8", dayOfMonth="1", month="1")` | 5 minutes past 8am on first of of January
`@Cron(minute="/5", params="--user=barman")` | Every 5 minutes, with a custom param
| annotation | description |
|----------------------------------------------------------|-------------------------------------------|
| `@Cron(minute="/5")` | Every 5 minutes |
| `@Cron(minute="5")` | At the 5th minute of each hour |
| `@Cron(minute="5", hour="8")` | 5 minutes past 8am every day |
| `@Cron(minute="5", hour="8", dayOfWeek="0")` | 5 minutes past 8am every Sunday |
| `@Cron(minute="5", hour="8", dayOfMonth="1")` | 5 minutes past 8am on first of each month |
| `@Cron(minute="5", hour="8", dayOfMonth="1", month="1")` | 5 minutes past 8am on first of of January |
| `@Cron(minute="/5", params="--user=barman")` | Every 5 minutes, with a custom param |

## Building the cron

Expand Down Expand Up @@ -128,4 +117,4 @@ You can choose which environment you want to run the commands in cron under like

---

Created by [MyBuilder](http://www.mybuilder.com/) - Check out our [blog](http://tech.mybuilder.com/) for more insight into this and other open-source projects we release.
Created by [MyBuilder](https://www.mybuilder.com/) - Check out our [blog](https://tech.mybuilder.com/) for more insight into this and other open-source projects we release.
2 changes: 1 addition & 1 deletion Tests/CronosTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class CronosTestCase extends WebTestCase
{
protected static function getKernelClass()
protected static function getKernelClass(): string
{
require_once __DIR__ . '/Fixtures/app/AppKernel.php';

Expand Down
2 changes: 1 addition & 1 deletion Tests/Fixtures/Command/TestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
class TestCommand extends Command
{
protected function configure()
protected function configure(): void
{
$this->setName('cronos:test-command');
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Fixtures/app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

class AppKernel extends Kernel
{
public function registerBundles()
public function registerBundles(): iterable
{
return [
new FrameworkBundle(),
new MyBuilderCronosBundle(),
];
}

public function registerContainerConfiguration(LoaderInterface $loader)
public function registerContainerConfiguration(LoaderInterface $loader): void
{
$loader->load(__DIR__ . '/config/' . $this->getEnvironment() . '.yml');
}
Expand Down
21 changes: 11 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
{
"name": "mybuilder/cronos-bundle",
"description": "Symfony 3/4/5 bundle which allows you to use @Cron annotations to configure cron to run your console commands.",
"description": "Symfony 4/5/6 bundle which allows you to use @Cron annotations to configure cron to run your console commands.",
"keywords": ["cron", "cronos"],
"minimum-stability": "stable",
"type" : "symfony-bundle",
"license": "MIT",
"authors": [
{
"name": "Gavin Love",
"homepage": "http://www.mybuilder.com"
"homepage": "https://www.mybuilder.com"
},
{
"name": "Keyvan Akbary",
"homepage": "http://www.mybuilder.com"
"homepage": "https://www.mybuilder.com"
}
],
"require": {
"php": ">=7.3",
"mybuilder/cronos": "~3.0",
"doctrine/annotations": "1.*",
"symfony/console": "~3.0||^4.0||^5.0",
"symfony/config": "~3.0||^4.0||^5.0",
"symfony/dependency-injection": "~3.0||^4.0||^5.0",
"symfony/framework-bundle": "~3.0||^4.0||^5.0",
"symfony/http-kernel": "~3.0||^4.0||^5.0",
"symfony/property-access": "~3.0||^4.0||^5.0",
"symfony/yaml": "~3.0||^4.0||^5.0"
"symfony/console": "^4.4 || ^5.0 || ^6.0",
"symfony/config": "^4.4 || ^5.0 || ^6.0",
"symfony/dependency-injection": "^4.4 || ^5.0 || ^6.0",
"symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0",
"symfony/http-kernel": "^4.4 || ^5.0 || ^6.0",
"symfony/property-access": "^4.4 || ^5.0 || ^6.0",
"symfony/yaml": "^4.4 || ^5.0 || ^6.0"
},
"require-dev": {
"roave/security-advisories": "dev-master",
Expand Down

0 comments on commit 887fa15

Please sign in to comment.