Skip to content

Commit

Permalink
Merge pull request #25 from mybuilder/symfony-5-support
Browse files Browse the repository at this point in the history
Symfony 5 support
  • Loading branch information
Gavin Love authored May 11, 2020
2 parents 6a145bc + f7adb95 commit 5086c6e
Show file tree
Hide file tree
Showing 21 changed files with 230 additions and 509 deletions.
67 changes: 30 additions & 37 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,36 @@
language: php

cache:
directories:
- $HOME/.composer/cache/files
- .phpunit

env:
global:
- SYMFONY_PHPUNIT_DIR=.phpunit

matrix:
fast_finish: true
include:
- php: 5.6
env: SYMFONY_VERSION=2.8.*
- php: 5.6
env: SYMFONY_VERSION=3.0.*
- php: 5.6
env: SYMFONY_VERSION=3.1.*
- php: 5.6
env: SYMFONY_VERSION=3.2.*
- php: 5.6
env: SYMFONY_VERSION=3.3.*
- php: 5.6
env: SYMFONY_VERSION=3.4.*
- php: 7.0
env: SYMFONY_VERSION=2.8.*
- php: 7.0
env: SYMFONY_VERSION=3.0.*
- php: 7.0
env: SYMFONY_VERSION=3.1.*
- php: 7.0
env: SYMFONY_VERSION=3.2.*
- php: 7.0
env: SYMFONY_VERSION=3.4.*
- php: 7.1
env: SYMFONY_VERSION=3.4.*
- php: 7.1
env: SYMFONY_VERSION=4.0.*
- php: 7.1
env: SYMFONY_VERSION=4.1.*
- php: 7.2
env: SYMFONY_VERSION=3.4.*
- php: 7.2
env: SYMFONY_VERSION=4.0.*
- php: 7.2
env: SYMFONY_VERSION=4.1.*
- php: 7.3
env: SYMFONY_VERSION="3.4.*"
- php: 7.3
env: SYMFONY_VERSION="4.4.*"
- php: 7.3
env: SYMFONY_VERSION="5.0.*"
- php: 7.4
env: SYMFONY_VERSION="3.4.*"
- php: 7.4
env: SYMFONY_VERSION="4.4.*"
- php: 7.4
env: SYMFONY_VERSION="5.0.*"

before_install:
- composer self-update
- composer validate
- if [ "$SYMFONY_VERSION" != "" ]; then composer require --no-update symfony/process:"${SYMFONY_VERSION}"; fi

before_script:
- composer require symfony/process:${SYMFONY_VERSION}
install:
- composer update $COMPOSER_FLAGS

script: bin/phpunit
script: bin/phpunit -v
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2013-2017 MyBuilder Limited
Copyright (c) 2013-2020 MyBuilder Limited

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -12,7 +12,7 @@ all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Expand Down
27 changes: 9 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,18 @@

Easily configure cron through PHP.

If you use Symfony 2, you could use our [cool bundle](https://github.com/mybuilder/cronos-bundle) in order to configure your app jobs through fancy annotations!
If you use Symfony 3/4/5, you could use our [cool bundle](https://github.com/mybuilder/cronos-bundle) in order to configure your app jobs through fancy annotations!

## Setup and Configuration
Add the following to your `composer.json` file
```json
{
"require": {
"mybuilder/cronos": "~1.0"
}
}
```

Update the vendor libraries
Require the library via composer:

curl -s http://getcomposer.org/installer | php
php composer.phar install
composer require mybuilder/cronos

## Usage

### Build Cron

```php
<?php

Expand Down Expand Up @@ -84,13 +76,12 @@ $cronUpdater->replaceWith($cron);

## Troubleshooting

* The current user must have a existing crontab file to use the updater, use crontab -e to create one.
* The current user must have a existing crontab file to use the updater, use `crontab -e` to create one.
* When a cron line is executed it is executed with the user that owns the crontab, but it will not execute any of the users default shell files so all paths etc need to be specified in the command called from the cron line.
* Your crontab will not be executed if you do not have useable shell in /etc/passwd
* If your jobs don't seem to be running check that the cron deamon is running, also check your username is in /etc/cron.allow and not in /etc/cron.deny.
* Environmental substitutions do not work, you can not use things like $PATH, $HOME, or ~/sbin.
* You can not use % in the command, if you need to use it escape the command in backticks.

* Your crontab will not be executed if you do not have usable shell in `/etc/passwd`
* If your jobs don't seem to be running, check the cron daemon is running, also check your username is in `/etc/cron.allow` and not in `/etc/cron.deny`.
* Environmental substitutions do not work, you cannot use things like `$PATH`, `$HOME`, or `~/sbin`.
* You cannot use `%` in the command, if you need to use it, escape the command in backticks.

---

Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
}
],
"require": {
"php": ">=5.6.0 || ^7.0",
"symfony/process": "~2.2|~3.0|^4.0"
"php": ">=7.3",
"symfony/process": "~3.0|^4.0|^5.0"
},
"suggest": {
"symfony/filesystem": "Allows using Symfony Filesystem"
},
"require-dev": {
"phpunit/phpunit": "~5.0",
"mockery/mockery": "~0.9"
"roave/security-advisories": "dev-master",
"phpunit/phpunit": "^9.0"
},
"autoload": {
"psr-4": { "MyBuilder\\Cronos\\": "src" }
Expand Down
24 changes: 9 additions & 15 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,19 @@

<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit
backupGlobals = "false"
backupStaticAttributes = "false"
colors = "true"
convertErrorsToExceptions = "true"
convertNoticesToExceptions = "true"
convertWarningsToExceptions = "true"
processIsolation = "false"
stopOnFailure = "true"
syntaxCheck = "false"
bootstrap = "./vendor/autoload.php" >
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="true"
bootstrap="./vendor/autoload.php">

<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<listeners>
<listener class="\Mockery\Adapter\Phpunit\TestListener" />
</listeners>

</phpunit>
18 changes: 5 additions & 13 deletions src/Formatter/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,21 @@

class Comment
{
/**
* @var string
*/
/** @var string */
private $comment;

/**
* @param string $comment
*/
public function __construct($comment)
public function __construct(string $comment)
{
$this->comment = $comment;
}

/**
* @return string
*/
public function format()
public function format(): string
{
return '#' . $this->removeLineBreaks($this->comment);
}

private function removeLineBreaks($text)
private function removeLineBreaks($text): string
{
return str_replace(array("\r", "\r\n", "\n", PHP_EOL), '', $text);
return \str_replace(["\r", "\r\n", "\n", \PHP_EOL], '', $text);
}
}
46 changes: 12 additions & 34 deletions src/Formatter/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,73 +4,51 @@

class Cron
{
/**
* @var Header
*/
/** @var Header */
private $header;

/**
* @var mixed[]
*/
private $lines = array();
/** @var mixed[] */
private $lines = [];

/**
* @return Header
*/
public function header()
public function header(): Header
{
$this->header = new Header($this);

return $this->header;
}

/**
* @param string $command
*
* @return Job
*/
public function job($command)
public function job(string $command): Job
{
$line = new Job($command, $this);
$this->lines[] = $line;

return $line;
}

/**
* @param string $comment
*
* @return Cron
*/
public function comment($comment)
public function comment(string $comment): Cron
{
$this->lines[] = new Comment($comment);

return $this;
}

/**
* @return int
*/
public function countLines()
public function countLines(): int
{
return count($this->lines);
}

/**
* @return string
*/
public function format()
public function format(): string
{
$lines = '';

foreach ($this->lines as $line) {
$lines .= $line->format() . PHP_EOL;
$lines .= $line->format() . \PHP_EOL;
}

return (($this->hasHeader()) ? $this->header->format() . PHP_EOL : '') . trim($lines) . PHP_EOL;
return (($this->hasHeader()) ? $this->header->format() . \PHP_EOL : '') . \trim($lines) . \PHP_EOL;
}

public function hasHeader()
public function hasHeader(): bool
{
return $this->header !== null;
}
Expand Down
Loading

0 comments on commit 5086c6e

Please sign in to comment.