Skip to content

Commit 1a8971c

Browse files
committed
Fixes related to Phar environment
1 parent 4e12ce0 commit 1a8971c

8 files changed

+25
-27
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
vendor
22
cache
33
.idea
4+
*.phar

bin/laracron.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
use Trig\LaraCron\Exception\ExitCommandException;
99
use Trig\LaraCron\ExitCodes;
1010
use Illuminate\Console\Scheduling\Schedule;
11+
use Illuminate\Container\Container;
1112

12-
$configFile = realpath(__DIR__.'/../laracron.json');
13+
$configFile = realpath('.') . '/laracron.json';
1314

1415
$io = new OutputStyle(
1516
new ArgvInput(),
@@ -19,6 +20,12 @@
1920
try {
2021
$cronApp = new \Trig\LaraCron\CronApplication($configFile);
2122

23+
function base_path($path = null)
24+
{
25+
$container = Container::getInstance();
26+
return $container->get('config')['basePath'].($path ? DIRECTORY_SEPARATOR.$path : $path);
27+
}
28+
2229
$cronApp->booting(
2330
function (\Trig\LaraCron\CronApplication $app) use ($io) {
2431
if ('redis' === ($app->get('config')['cache.default'] ?? null) && !class_exists('Redis')) {

composer.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
"autoload": {
1414
"psr-4": {
1515
"Trig\\": "src//"
16-
},
17-
"files": [
18-
"src/functions.php"
19-
]
16+
}
2017
},
2118
"authors": [
2219
{

laracron.json

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
{
22
"scheduledJobs": {
33
"everyMinute": [
4-
"app/console list",
5-
"app/console"
4+
"php --version"
65
],
7-
"*/10 * * * *": [
8-
"echo '*/10 * * * *'"
6+
"* * * * *": [
97
]
108
},
11-
12-
"log": "php://stdout",
9+
"log": "cron.log",
1310
"cache.default": "file",
1411
"cache.prefix": "laracron",
1512
"cache.stores.file": {

src/LaraCron/Command/BuildPharCommand.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,16 @@ function ($path) use ($basePath) {
4848
->ignoreDotFiles(true);
4949

5050
$pharFile = $basePath.'/laracron.phar';
51-
$stubFile = $basePath.'/bin/laracron.php';
51+
if (file_exists($pharFile)) {
52+
unlink($pharFile);
53+
}
5254

5355
$this->output->progressAdvance(1);
5456
$phar = new \Phar($pharFile);
5557
$phar->buildFromIterator($files->getIterator(), $basePath);
5658

5759
$this->output->progressAdvance(1);
58-
$phar->setStub($phar->createDefaultStub($stubFile));
60+
$phar->setStub($phar->createDefaultStub('bin/laracron.php'));
5961
$this->output->writeln("Build completed. Phar saved to <comment>{$pharFile}</comment>");
6062
}
6163

src/LaraCron/Command/ScheduleRunCommand.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ public function handle()
1616
$config = $this->getLaravel()->get('config');
1717
foreach ($config['scheduledJobs'] ?? [] as $definition => $commands) {
1818
foreach ($commands as $command) {
19-
$event = $this->schedule->exec($command)
19+
$event = $this->schedule
20+
->exec($command)
2021
->name($this->getUniqueName($definition, $command))
21-
->onOneServer();
22+
->onOneServer()
23+
->appendOutputTo($config['log']);
2224

2325
$isCronDefinition = false !== strpos($definition, ' ');
2426

src/LaraCron/CronApplication.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,10 @@ private function getConfig(string $configFile): array
476476
throw new ExitCommandException('ERROR_CONFIG_JSON_ERROR', ExitCodes::ERROR_CONFIG_JSON_ERROR);
477477
}
478478

479-
$config['basePath'] = realpath(__DIR__ . '/../../');
479+
$config['basePath'] = realpath('.');
480+
if (isset($config['cache.stores.file']['path'])) {
481+
$config['cache.stores.file']['path'] = $config['basePath'].DIRECTORY_SEPARATOR.ltrim($config['cache.stores.file']['path'], '/');
482+
}
480483

481484
return $config;
482485
}

src/functions.php

-11
This file was deleted.

0 commit comments

Comments
 (0)