Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added timezone option #94

Merged
merged 18 commits into from
May 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added
- `timezone` option to config file - PR [#94](https://github.com/lavary/crunz/pull/94),
[@PabloKowalczyk](https://github.com/PabloKowalczyk)

### Deprecated
- `timezone` option in config file is now required,
lack of it will result in Exception in version `2.0`

## 1.6.1 - 2018-05-13

### Fixed
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,11 @@ source: tasks
# to make sure all the existing tasks files are renamed accordingly.
suffix: Tasks.php

# Timezone is used to calculate task run time
# This option is very important and not setting it is deprecated
# and will result in exception in 2.0 version.
timezone: ~

# By default the errors are not logged by Crunz
# You may set the value to true for logging the errors
log_errors: false
Expand Down
5 changes: 3 additions & 2 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ touch "$PHP_INI_PATH";

echo "display_errors = On" >> "$PHP_INI_PATH";
echo "display_startup_errors = On" >> "$PHP_INI_PATH";
echo "error_reporting = E_ALL" >> "$PHP_INI_PATH";
echo "log_errors = On" >> "$PHP_INI_PATH";
echo "error_log = /var/log/php_error.log" >> "$PHP_INI_PATH";

SCRIPT

$composer = <<SCRIPT

COMPOSER_VERSION="1.6.4";
COMPOSER_VERSION="1.6.5";
BIN_DIR="/home/vagrant/bin";
COMPOSER_FILE="$BIN_DIR/composer";

Expand Down Expand Up @@ -71,5 +72,5 @@ Vagrant.configure("2") do |config|
end

config.vm.provision "shell", inline: $script
config.vm.provision "shell", inline: $composer
config.vm.provision "shell", inline: $composer, privileged: false
end
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,26 @@
"php": "^5.6 || ^7.0",
"guzzlehttp/guzzle": "^6.1",
"jeremeamia/superclosure": "^2.2",
"nikic/php-parser": "^2.1.1 || ^3.0 || ^4.0",
"monolog/monolog": "^1.19",
"mtdowling/cron-expression": "^1.1",
"nesbot/carbon": "^1.21",
"nikic/php-parser": "^2.1.1 || ^3.0 || ^4.0",
"swiftmailer/swiftmailer": "^5.4 || ^6.0",
"symfony/config": "^2.7 || ^3.3 || ^4.0",
"symfony/console": "^2.7 || ^3.3 || ^4.0",
"symfony/dependency-injection": "^2.7 || ^3.3 || ^4.0",
"symfony/filesystem": "^2.7 || ^3.3 || ^4.0",
"symfony/finder": "^2.7 || ^3.3 || ^4.0",
"symfony/process": "^2.7.11 || ^3.3 || ^4.0",
"symfony/yaml": "^2.7 || ^3.3 || ^4.0",
"symfony/property-access": "^2.7 || ^3.3 || ^4.0"
"symfony/property-access": "^2.7 || ^3.3 || ^4.0",
"symfony/yaml": "^2.7 || ^3.3 || ^4.0"
},
"require-dev": {
"ext-mbstring": "*",
"friendsofphp/php-cs-fixer": "2.2.19",
"phpdocumentor/reflection-docblock": "^2.0.1",
"phpunit/phpunit": "5.7.27",
"sebastian/comparator": "1.2.4",
"symfony/debug": "^3.3 || ^4.0",
"symfony/phpunit-bridge": "^2.8 || ^3.3 || ^4.0",
"symfony/var-dumper": "^3.4"
},
Expand Down
23 changes: 23 additions & 0 deletions config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<argument type="service" id="Crunz\Task\Collection"/>
<argument type="service" id="Crunz\Configuration\Configuration"/>
<argument type="service" id="Crunz\EventRunner"/>
<argument type="service" id="Crunz\Task\Timezone"/>
</service>

<service
Expand All @@ -27,6 +28,8 @@
id="Crunz\Console\Command\ConfigGeneratorCommand"
public="true"
>
<argument type="service" id="Crunz\Timezone\ProviderInterface"/>
<argument type="service" id="Symfony\Component\Filesystem\Filesystem"/>
</service>

<service
Expand Down Expand Up @@ -127,6 +130,12 @@
<argument type="service" id="Crunz\Configuration\Configuration"/>
</service>

<service
class="Crunz\Timezone\Provider"
id="Crunz\Timezone\ProviderInterface"
public="false"
/>

<service
class="Crunz\EventRunner"
id="Crunz\EventRunner"
Expand All @@ -137,5 +146,19 @@
<argument type="service" id="Crunz\Mailer"/>
<argument type="service" id="Crunz\Logger\LoggerFactory"/>
</service>

<service
class="Symfony\Component\Filesystem\Filesystem"
id="Symfony\Component\Filesystem\Filesystem"
/>

<service
class="Crunz\Task\Timezone"
id="Crunz\Task\Timezone"
public="false"
>
<argument type="service" id="Crunz\Configuration\Configuration"/>
<argument type="service" id="Crunz\Timezone\ProviderInterface"/>
</service>
</services>
</container>
21 changes: 12 additions & 9 deletions crunz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ source: tasks
# to make sure all the existing tasks files are renamed accordingly.
suffix: Tasks.php

# Timezone is used to calculate task run time
# This option is very important and not setting it is deprecated
# and will result in exception in 2.0 version.
timezone: ~

# By default the errors are not logged by Crunz
# You may set the value to true for logging the errors
log_errors: false

# This is the absolute path to the errors' log file
# You need to make sure you have the required permission to write to this file though.
errors_log_file:
errors_log_file: ~

# By default the output is not logged as they are redirected to the
# null output.
Expand All @@ -27,7 +32,7 @@ log_output: false
# This is the absolute path to the global output log file
# The events which have dedicated log files (defined with them), won't be
# logged to this file though.
output_log_file:
output_log_file: ~

# By default line breaks in logs aren't allowed.
# Set the value to true to allow them.
Expand All @@ -40,7 +45,6 @@ email_output: false
email_errors: false

# Global Swift Mailer settings
#
mailer:
# Possible values: smtp, mail, and sendmail
transport: smtp
Expand All @@ -50,10 +54,9 @@ mailer:


# SMTP settings
#
smtp:
host:
port:
username:
password:
encryption:
host: ~
port: ~
username: ~
password: ~
encryption: ~
45 changes: 45 additions & 0 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
use Symfony\Component\Config\ConfigCache;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Console\Application as SymfonyApplication;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
Expand Down Expand Up @@ -63,6 +68,21 @@ public function __construct($appName, $appVersion)
}
}

public function run(InputInterface $input = null, OutputInterface $output = null)
{
if ($output === null) {
$output = new ConsoleOutput();
}

if (null === $input) {
$input = new ArgvInput();
}

$this->registerDeprecationHandler($input, $output);

return parent::run($input, $output);
}

private function initializeContainer()
{
$class = 'CrunzContainer';
Expand Down Expand Up @@ -138,6 +158,9 @@ private function dumpContainer(
$cache->write($content, $container->getResources());
}

/**
* @return string
*/
private function getCacheDir()
{
return implode(
Expand All @@ -148,4 +171,26 @@ private function getCacheDir()
]
);
}

private function registerDeprecationHandler(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
\set_error_handler(
function (
$errorNumber,
$errorString,
$file,
$line
) use ($io) {
$io->block(
"{$errorString} File {$file}, line {$line}",
'Deprecation',
'bg=yellow;fg=black',
' ',
true
);
},
E_USER_DEPRECATED
);
}
}
4 changes: 4 additions & 0 deletions src/Configuration/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public function getConfigTreeBuilder()
->info('The suffix for filenames' . PHP_EOL)
->end()

->scalarNode('timezone')
->info('Timezone used to calculate task run date')
->end()

->booleanNode('log_errors')
->defaultFalse()
->info('Flag for logging errors' . PHP_EOL)
Expand Down
4 changes: 2 additions & 2 deletions src/Console/Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ class Command extends BaseCommand
/**
* Input object.
*
* @var use Symfony\Component\Console\Input\InputInterface
* @var \Symfony\Component\Console\Input\InputInterface
*/
protected $input;

/**
* output object.
*
* @var use Symfony\Component\Console\Input\OutputInterface
* @var \Symfony\Component\Console\Output\OutputInterface
*/
protected $output;
}
Loading