@@ -1,29 +0,0 @@
|
||||
<?php namespace Illuminate\Console;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
trait AppNamespaceDetectorTrait {
|
||||
|
||||
/**
|
||||
* Get the application namespace from the Composer file.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
protected function getAppNamespace()
|
||||
{
|
||||
$composer = json_decode(file_get_contents(base_path().'/composer.json'), true);
|
||||
|
||||
foreach ((array) data_get($composer, 'autoload.psr-4') as $namespace => $path)
|
||||
{
|
||||
foreach ((array) $path as $pathChoice)
|
||||
{
|
||||
if (realpath(app_path()) == realpath(base_path().'/'.$pathChoice)) return $namespace;
|
||||
}
|
||||
}
|
||||
|
||||
throw new RuntimeException("Unable to detect application namespace.");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,167 +0,0 @@
|
||||
<?php namespace Illuminate\Console;
|
||||
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\BufferedOutput;
|
||||
use Symfony\Component\Console\Application as SymfonyApplication;
|
||||
use Symfony\Component\Console\Command\Command as SymfonyCommand;
|
||||
use Illuminate\Contracts\Console\Application as ApplicationContract;
|
||||
|
||||
class Application extends SymfonyApplication implements ApplicationContract {
|
||||
|
||||
/**
|
||||
* The Laravel application instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Container\Container
|
||||
*/
|
||||
protected $laravel;
|
||||
|
||||
/**
|
||||
* The output from the previous command.
|
||||
*
|
||||
* @var \Symfony\Component\Console\Output\BufferedOutput
|
||||
*/
|
||||
protected $lastOutput;
|
||||
|
||||
/**
|
||||
* Create a new Artisan console application.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Container\Container $laravel
|
||||
* @param \Illuminate\Contracts\Events\Dispatcher $events
|
||||
* @param string $version
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Container $laravel, Dispatcher $events, $version)
|
||||
{
|
||||
parent::__construct('Laravel Framework', $version);
|
||||
|
||||
$this->laravel = $laravel;
|
||||
$this->setAutoExit(false);
|
||||
$this->setCatchExceptions(false);
|
||||
|
||||
$events->fire('artisan.start', [$this]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run an Artisan console command by name.
|
||||
*
|
||||
* @param string $command
|
||||
* @param array $parameters
|
||||
* @return int
|
||||
*/
|
||||
public function call($command, array $parameters = array())
|
||||
{
|
||||
$parameters['command'] = $command;
|
||||
|
||||
$this->lastOutput = new BufferedOutput;
|
||||
|
||||
return $this->find($command)->run(new ArrayInput($parameters), $this->lastOutput);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the output for the last run command.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function output()
|
||||
{
|
||||
return $this->lastOutput ? $this->lastOutput->fetch() : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a command to the console.
|
||||
*
|
||||
* @param \Symfony\Component\Console\Command\Command $command
|
||||
* @return \Symfony\Component\Console\Command\Command
|
||||
*/
|
||||
public function add(SymfonyCommand $command)
|
||||
{
|
||||
if ($command instanceof Command)
|
||||
{
|
||||
$command->setLaravel($this->laravel);
|
||||
}
|
||||
|
||||
return $this->addToParent($command);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the command to the parent instance.
|
||||
*
|
||||
* @param \Symfony\Component\Console\Command\Command $command
|
||||
* @return \Symfony\Component\Console\Command\Command
|
||||
*/
|
||||
protected function addToParent(SymfonyCommand $command)
|
||||
{
|
||||
return parent::add($command);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a command, resolving through the application.
|
||||
*
|
||||
* @param string $command
|
||||
* @return \Symfony\Component\Console\Command\Command
|
||||
*/
|
||||
public function resolve($command)
|
||||
{
|
||||
return $this->add($this->laravel->make($command));
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve an array of commands through the application.
|
||||
*
|
||||
* @param array|mixed $commands
|
||||
* @return $this
|
||||
*/
|
||||
public function resolveCommands($commands)
|
||||
{
|
||||
$commands = is_array($commands) ? $commands : func_get_args();
|
||||
|
||||
foreach ($commands as $command)
|
||||
{
|
||||
$this->resolve($command);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default input definitions for the applications.
|
||||
*
|
||||
* This is used to add the --env option to every available command.
|
||||
*
|
||||
* @return \Symfony\Component\Console\Input\InputDefinition
|
||||
*/
|
||||
protected function getDefaultInputDefinition()
|
||||
{
|
||||
$definition = parent::getDefaultInputDefinition();
|
||||
|
||||
$definition->addOption($this->getEnvironmentOption());
|
||||
|
||||
return $definition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the global environment option for the definition.
|
||||
*
|
||||
* @return \Symfony\Component\Console\Input\InputOption
|
||||
*/
|
||||
protected function getEnvironmentOption()
|
||||
{
|
||||
$message = 'The environment the command should run under.';
|
||||
|
||||
return new InputOption('--env', null, InputOption::VALUE_OPTIONAL, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Laravel application instance.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application
|
||||
*/
|
||||
public function getLaravel()
|
||||
{
|
||||
return $this->laravel;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,387 +0,0 @@
|
||||
<?php namespace Illuminate\Console;
|
||||
|
||||
use Symfony\Component\Console\Helper\Table;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Output\NullOutput;
|
||||
use Symfony\Component\Console\Question\Question;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Question\ChoiceQuestion;
|
||||
use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||
use Illuminate\Contracts\Foundation\Application as LaravelApplication;
|
||||
|
||||
class Command extends \Symfony\Component\Console\Command\Command {
|
||||
|
||||
/**
|
||||
* The Laravel application instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Foundation\Application
|
||||
*/
|
||||
protected $laravel;
|
||||
|
||||
/**
|
||||
* The input interface implementation.
|
||||
*
|
||||
* @var \Symfony\Component\Console\Input\InputInterface
|
||||
*/
|
||||
protected $input;
|
||||
|
||||
/**
|
||||
* The output interface implementation.
|
||||
*
|
||||
* @var \Symfony\Component\Console\Output\OutputInterface
|
||||
*/
|
||||
protected $output;
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description;
|
||||
|
||||
/**
|
||||
* Create a new console command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct($this->name);
|
||||
|
||||
// We will go ahead and set the name, description, and parameters on console
|
||||
// commands just to make things a little easier on the developer. This is
|
||||
// so they don't have to all be manually specified in the constructors.
|
||||
$this->setDescription($this->description);
|
||||
|
||||
$this->specifyParameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the arguments and options on the command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function specifyParameters()
|
||||
{
|
||||
// We will loop through all of the arguments and options for the command and
|
||||
// set them all on the base command instance. This specifies what can get
|
||||
// passed into these commands as "parameters" to control the execution.
|
||||
foreach ($this->getArguments() as $arguments)
|
||||
{
|
||||
call_user_func_array(array($this, 'addArgument'), $arguments);
|
||||
}
|
||||
|
||||
foreach ($this->getOptions() as $options)
|
||||
{
|
||||
call_user_func_array(array($this, 'addOption'), $options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the console command.
|
||||
*
|
||||
* @param \Symfony\Component\Console\Input\InputInterface $input
|
||||
* @param \Symfony\Component\Console\Output\OutputInterface $output
|
||||
* @return int
|
||||
*/
|
||||
public function run(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->input = $input;
|
||||
|
||||
$this->output = $output;
|
||||
|
||||
return parent::run($input, $output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @param \Symfony\Component\Console\Input\InputInterface $input
|
||||
* @param \Symfony\Component\Console\Output\OutputInterface $output
|
||||
* @return mixed
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$method = method_exists($this, 'handle') ? 'handle' : 'fire';
|
||||
|
||||
return $this->laravel->call([$this, $method]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call another console command.
|
||||
*
|
||||
* @param string $command
|
||||
* @param array $arguments
|
||||
* @return int
|
||||
*/
|
||||
public function call($command, array $arguments = array())
|
||||
{
|
||||
$instance = $this->getApplication()->find($command);
|
||||
|
||||
$arguments['command'] = $command;
|
||||
|
||||
return $instance->run(new ArrayInput($arguments), $this->output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call another console command silently.
|
||||
*
|
||||
* @param string $command
|
||||
* @param array $arguments
|
||||
* @return int
|
||||
*/
|
||||
public function callSilent($command, array $arguments = array())
|
||||
{
|
||||
$instance = $this->getApplication()->find($command);
|
||||
|
||||
$arguments['command'] = $command;
|
||||
|
||||
return $instance->run(new ArrayInput($arguments), new NullOutput);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a command argument.
|
||||
*
|
||||
* @param string $key
|
||||
* @return string|array
|
||||
*/
|
||||
public function argument($key = null)
|
||||
{
|
||||
if (is_null($key)) return $this->input->getArguments();
|
||||
|
||||
return $this->input->getArgument($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a command option.
|
||||
*
|
||||
* @param string $key
|
||||
* @return string|array
|
||||
*/
|
||||
public function option($key = null)
|
||||
{
|
||||
if (is_null($key)) return $this->input->getOptions();
|
||||
|
||||
return $this->input->getOption($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm a question with the user.
|
||||
*
|
||||
* @param string $question
|
||||
* @param bool $default
|
||||
* @return bool
|
||||
*/
|
||||
public function confirm($question, $default = false)
|
||||
{
|
||||
$helper = $this->getHelperSet()->get('question');
|
||||
|
||||
$question = new ConfirmationQuestion("<question>{$question}</question> ", $default);
|
||||
|
||||
return $helper->ask($this->input, $this->output, $question);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prompt the user for input.
|
||||
*
|
||||
* @param string $question
|
||||
* @param string $default
|
||||
* @return string
|
||||
*/
|
||||
public function ask($question, $default = null)
|
||||
{
|
||||
$helper = $this->getHelperSet()->get('question');
|
||||
|
||||
$question = new Question("<question>$question</question> ", $default);
|
||||
|
||||
return $helper->ask($this->input, $this->output, $question);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prompt the user for input with auto completion.
|
||||
*
|
||||
* @param string $question
|
||||
* @param array $choices
|
||||
* @param string $default
|
||||
* @return string
|
||||
*/
|
||||
public function askWithCompletion($question, array $choices, $default = null)
|
||||
{
|
||||
$helper = $this->getHelperSet()->get('question');
|
||||
|
||||
$question = new Question("<question>$question</question> ", $default);
|
||||
|
||||
$question->setAutocompleterValues($choices);
|
||||
|
||||
return $helper->ask($this->input, $this->output, $question);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prompt the user for input but hide the answer from the console.
|
||||
*
|
||||
* @param string $question
|
||||
* @param bool $fallback
|
||||
* @return string
|
||||
*/
|
||||
public function secret($question, $fallback = true)
|
||||
{
|
||||
$helper = $this->getHelperSet()->get('question');
|
||||
|
||||
$question = new Question("<question>$question</question> ");
|
||||
|
||||
$question->setHidden(true)->setHiddenFallback($fallback);
|
||||
|
||||
return $helper->ask($this->input, $this->output, $question);
|
||||
}
|
||||
|
||||
/**
|
||||
* Give the user a single choice from an array of answers.
|
||||
*
|
||||
* @param string $question
|
||||
* @param array $choices
|
||||
* @param string $default
|
||||
* @param mixed $attempts
|
||||
* @param bool $multiple
|
||||
* @return bool
|
||||
*/
|
||||
public function choice($question, array $choices, $default = null, $attempts = null, $multiple = null)
|
||||
{
|
||||
$helper = $this->getHelperSet()->get('question');
|
||||
|
||||
$question = new ChoiceQuestion("<question>$question</question> ", $choices, $default);
|
||||
|
||||
$question->setMaxAttempts($attempts)->setMultiselect($multiple);
|
||||
|
||||
return $helper->ask($this->input, $this->output, $question);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format input to textual table.
|
||||
*
|
||||
* @param array $headers
|
||||
* @param array $rows
|
||||
* @param string $style
|
||||
* @return void
|
||||
*/
|
||||
public function table(array $headers, array $rows, $style = 'default')
|
||||
{
|
||||
$table = new Table($this->output);
|
||||
|
||||
$table->setHeaders($headers)->setRows($rows)->setStyle($style)->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a string as information output.
|
||||
*
|
||||
* @param string $string
|
||||
* @return void
|
||||
*/
|
||||
public function info($string)
|
||||
{
|
||||
$this->output->writeln("<info>$string</info>");
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a string as standard output.
|
||||
*
|
||||
* @param string $string
|
||||
* @return void
|
||||
*/
|
||||
public function line($string)
|
||||
{
|
||||
$this->output->writeln($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a string as comment output.
|
||||
*
|
||||
* @param string $string
|
||||
* @return void
|
||||
*/
|
||||
public function comment($string)
|
||||
{
|
||||
$this->output->writeln("<comment>$string</comment>");
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a string as question output.
|
||||
*
|
||||
* @param string $string
|
||||
* @return void
|
||||
*/
|
||||
public function question($string)
|
||||
{
|
||||
$this->output->writeln("<question>$string</question>");
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a string as error output.
|
||||
*
|
||||
* @param string $string
|
||||
* @return void
|
||||
*/
|
||||
public function error($string)
|
||||
{
|
||||
$this->output->writeln("<error>$string</error>");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the output implementation.
|
||||
*
|
||||
* @return \Symfony\Component\Console\Output\OutputInterface
|
||||
*/
|
||||
public function getOutput()
|
||||
{
|
||||
return $this->output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Laravel application instance.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application
|
||||
*/
|
||||
public function getLaravel()
|
||||
{
|
||||
return $this->laravel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Laravel application instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Foundation\Application $laravel
|
||||
* @return void
|
||||
*/
|
||||
public function setLaravel(LaravelApplication $laravel)
|
||||
{
|
||||
$this->laravel = $laravel;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
<?php namespace Illuminate\Console;
|
||||
|
||||
use Closure;
|
||||
|
||||
trait ConfirmableTrait {
|
||||
|
||||
/**
|
||||
* Confirm before proceeding with the action.
|
||||
*
|
||||
* @param string $warning
|
||||
* @param \Closure|null $callback
|
||||
* @return bool
|
||||
*/
|
||||
public function confirmToProceed($warning = 'Application In Production!', Closure $callback = null)
|
||||
{
|
||||
$shouldConfirm = $callback ?: $this->getDefaultConfirmCallback();
|
||||
|
||||
if (call_user_func($shouldConfirm))
|
||||
{
|
||||
if ($this->option('force')) return true;
|
||||
|
||||
$this->comment(str_repeat('*', strlen($warning) + 12));
|
||||
$this->comment('* '.$warning.' *');
|
||||
$this->comment(str_repeat('*', strlen($warning) + 12));
|
||||
$this->output->writeln('');
|
||||
|
||||
$confirmed = $this->confirm('Do you really wish to run this command? [y/N]');
|
||||
|
||||
if ( ! $confirmed)
|
||||
{
|
||||
$this->comment('Command Cancelled!');
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default confirmation callback.
|
||||
*
|
||||
* @return \Closure
|
||||
*/
|
||||
protected function getDefaultConfirmCallback()
|
||||
{
|
||||
return function() { return $this->getLaravel()->environment() == 'production'; };
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,206 +0,0 @@
|
||||
<?php namespace Illuminate\Console;
|
||||
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
abstract class GeneratorCommand extends Command {
|
||||
|
||||
use AppNamespaceDetectorTrait;
|
||||
|
||||
/**
|
||||
* The filesystem instance.
|
||||
*
|
||||
* @var \Illuminate\Filesystem\Filesystem
|
||||
*/
|
||||
protected $files;
|
||||
|
||||
/**
|
||||
* The type of class being generated.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* Create a new controller creator command instance.
|
||||
*
|
||||
* @param \Illuminate\Filesystem\Filesystem $files
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Filesystem $files)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->files = $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the stub file for the generator.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getStub();
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function fire()
|
||||
{
|
||||
$name = $this->parseName($this->getNameInput());
|
||||
|
||||
if ($this->files->exists($path = $this->getPath($name)))
|
||||
{
|
||||
return $this->error($this->type.' already exists!');
|
||||
}
|
||||
|
||||
$this->makeDirectory($path);
|
||||
|
||||
$this->files->put($path, $this->buildClass($name));
|
||||
|
||||
$this->info($this->type.' created successfully.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the destination class path.
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
protected function getPath($name)
|
||||
{
|
||||
$name = str_replace($this->getAppNamespace(), '', $name);
|
||||
|
||||
return $this->laravel['path'].'/'.str_replace('\\', '/', $name).'.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the name and format according to the root namespace.
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
protected function parseName($name)
|
||||
{
|
||||
$rootNamespace = $this->getAppNamespace();
|
||||
|
||||
if (starts_with($name, $rootNamespace))
|
||||
{
|
||||
return $name;
|
||||
}
|
||||
|
||||
if (str_contains($name, '/'))
|
||||
{
|
||||
$name = str_replace('/', '\\', $name);
|
||||
}
|
||||
|
||||
return $this->parseName($this->getDefaultNamespace(trim($rootNamespace, '\\')).'\\'.$name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default namespace for the class.
|
||||
*
|
||||
* @param string $rootNamespace
|
||||
* @return string
|
||||
*/
|
||||
protected function getDefaultNamespace($rootNamespace)
|
||||
{
|
||||
return $rootNamespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the directory for the class if necessary.
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
protected function makeDirectory($path)
|
||||
{
|
||||
if ( ! $this->files->isDirectory(dirname($path)))
|
||||
{
|
||||
$this->files->makeDirectory(dirname($path), 0777, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the class with the given name.
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
protected function buildClass($name)
|
||||
{
|
||||
$stub = $this->files->get($this->getStub());
|
||||
|
||||
return $this->replaceNamespace($stub, $name)->replaceClass($stub, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the namespace for the given stub.
|
||||
*
|
||||
* @param string $stub
|
||||
* @param string $name
|
||||
* @return $this
|
||||
*/
|
||||
protected function replaceNamespace(&$stub, $name)
|
||||
{
|
||||
$stub = str_replace(
|
||||
'{{namespace}}', $this->getNamespace($name), $stub
|
||||
);
|
||||
|
||||
$stub = str_replace(
|
||||
'{{rootNamespace}}', $this->getAppNamespace(), $stub
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full namespace name for a given class.
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
protected function getNamespace($name)
|
||||
{
|
||||
return trim(implode('\\', array_slice(explode('\\', $name), 0, -1)), '\\');
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the class name for the given stub.
|
||||
*
|
||||
* @param string $stub
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
protected function replaceClass($stub, $name)
|
||||
{
|
||||
$class = str_replace($this->getNamespace($name).'\\', '', $name);
|
||||
|
||||
return str_replace('{{class}}', $class, $stub);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the desired class name from the input.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getNameInput()
|
||||
{
|
||||
return $this->argument('name');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return array(
|
||||
array('name', InputArgument::REQUIRED, 'The name of the class'),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
<?php namespace Illuminate\Console;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class ScheduleServiceProvider extends ServiceProvider {
|
||||
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = true;
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->commands('Illuminate\Console\Scheduling\ScheduleRunCommand');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return [
|
||||
'Illuminate\Console\Scheduling\ScheduleRunCommand',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
<?php namespace Illuminate\Console\Scheduling;
|
||||
|
||||
use LogicException;
|
||||
use InvalidArgumentException;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
|
||||
class CallbackEvent extends Event {
|
||||
|
||||
/**
|
||||
* The callback to call.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $callback;
|
||||
|
||||
/**
|
||||
* The parameters to pass to the method.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $parameters;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param string $callback
|
||||
* @param array $parameters
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($callback, array $parameters = array())
|
||||
{
|
||||
$this->callback = $callback;
|
||||
$this->parameters = $parameters;
|
||||
|
||||
if ( ! is_string($this->callback) && ! is_callable($this->callback))
|
||||
{
|
||||
throw new InvalidArgumentException(
|
||||
"Invalid scheduled callback event. Must be string or callable."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the given event.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Container\Container $container
|
||||
* @return mixed
|
||||
*/
|
||||
public function run(Container $container)
|
||||
{
|
||||
if ($this->description)
|
||||
{
|
||||
touch($this->mutexPath());
|
||||
}
|
||||
|
||||
try {
|
||||
$response = $container->call($this->callback, $this->parameters);
|
||||
} catch (\Exception $e) {
|
||||
$this->removeMutex();
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->removeMutex();
|
||||
|
||||
parent::callAfterCallbacks($container);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the mutex file from disk.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function removeMutex()
|
||||
{
|
||||
if ($this->description)
|
||||
{
|
||||
@unlink($this->mutexPath());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not allow the event to overlap each other.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function withoutOverlapping()
|
||||
{
|
||||
if ( ! isset($this->description))
|
||||
{
|
||||
throw new LogicException(
|
||||
"A scheduled event name is required to prevent overlapping. Use the 'name' method before 'withoutOverlapping'."
|
||||
);
|
||||
}
|
||||
|
||||
return $this->skip(function()
|
||||
{
|
||||
return file_exists($this->mutexPath());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mutex path for the scheduled command.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function mutexPath()
|
||||
{
|
||||
return storage_path().'/framework/schedule-'.md5($this->description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the summary of the event for display.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSummaryForDisplay()
|
||||
{
|
||||
if (is_string($this->description)) return $this->description;
|
||||
|
||||
return is_string($this->callback) ? $this->callback : 'Closure';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,756 +0,0 @@
|
||||
<?php namespace Illuminate\Console\Scheduling;
|
||||
|
||||
use Closure;
|
||||
use Carbon\Carbon;
|
||||
use LogicException;
|
||||
use Cron\CronExpression;
|
||||
use GuzzleHttp\Client as HttpClient;
|
||||
use Illuminate\Contracts\Mail\Mailer;
|
||||
use Symfony\Component\Process\Process;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
|
||||
class Event {
|
||||
|
||||
/**
|
||||
* The command string.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $command;
|
||||
|
||||
/**
|
||||
* The cron expression representing the event's frequency.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $expression = '* * * * * *';
|
||||
|
||||
/**
|
||||
* The timezone the date should be evaluated on.
|
||||
*
|
||||
* @var \DateTimeZone|string
|
||||
*/
|
||||
public $timezone;
|
||||
|
||||
/**
|
||||
* The user the command should run as.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* The list of environments the command should run under.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $environments = [];
|
||||
|
||||
/**
|
||||
* Indicates if the command should run in maintenance mode.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $evenInMaintenanceMode = false;
|
||||
|
||||
/**
|
||||
* Indicates if the command should not overlap itself.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $withoutOverlapping = false;
|
||||
|
||||
/**
|
||||
* The filter callback.
|
||||
*
|
||||
* @var \Closure
|
||||
*/
|
||||
protected $filter;
|
||||
|
||||
/**
|
||||
* The reject callback.
|
||||
*
|
||||
* @var \Closure
|
||||
*/
|
||||
protected $reject;
|
||||
|
||||
/**
|
||||
* The location that output should be sent to.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $output = '/dev/null';
|
||||
|
||||
/**
|
||||
* The array of callbacks to be run after the event is finished.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $afterCallbacks = [];
|
||||
|
||||
/**
|
||||
* The human readable description of the event.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $description;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param string $command
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($command)
|
||||
{
|
||||
$this->command = $command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the given event.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Container\Container $container
|
||||
* @return void
|
||||
*/
|
||||
public function run(Container $container)
|
||||
{
|
||||
if (count($this->afterCallbacks) > 0)
|
||||
{
|
||||
$this->runCommandInForeground($container);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->runCommandInBackground();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the command in the background using exec.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function runCommandInBackground()
|
||||
{
|
||||
chdir(base_path());
|
||||
|
||||
exec($this->buildCommand());
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the command in the foreground.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Container\Container $container
|
||||
* @return void
|
||||
*/
|
||||
protected function runCommandInForeground(Container $container)
|
||||
{
|
||||
(new Process(
|
||||
trim($this->buildCommand(), '& '), base_path(), null, null, null
|
||||
))->run();
|
||||
|
||||
$this->callAfterCallbacks($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call all of the "after" callbacks for the event.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Container\Container $container
|
||||
* @return void
|
||||
*/
|
||||
protected function callAfterCallbacks(Container $container)
|
||||
{
|
||||
foreach ($this->afterCallbacks as $callback)
|
||||
{
|
||||
$container->call($callback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the comand string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function buildCommand()
|
||||
{
|
||||
if ($this->withoutOverlapping)
|
||||
{
|
||||
$command = '(touch '.$this->mutexPath().'; '.$this->command.'; rm '.$this->mutexPath().') > '.$this->output.' 2>&1 &';
|
||||
}
|
||||
else
|
||||
{
|
||||
$command = $this->command.' > '.$this->output.' 2>&1 &';
|
||||
}
|
||||
|
||||
|
||||
return $this->user ? 'sudo -u '.$this->user.' '.$command : $command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mutex path for the scheduled command.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function mutexPath()
|
||||
{
|
||||
return storage_path().'/framework/schedule-'.md5($this->expression.$this->command);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given event should run based on the Cron expression.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Foundation\Application $app
|
||||
* @return bool
|
||||
*/
|
||||
public function isDue(Application $app)
|
||||
{
|
||||
if ( ! $this->runsInMaintenanceMode() && $app->isDownForMaintenance())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->expressionPasses() &&
|
||||
$this->filtersPass($app) &&
|
||||
$this->runsInEnvironment($app->environment());
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the Cron expression passes.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function expressionPasses()
|
||||
{
|
||||
$date = Carbon::now();
|
||||
|
||||
if ($this->timezone)
|
||||
{
|
||||
$date->setTimezone($this->timezone);
|
||||
}
|
||||
|
||||
return CronExpression::factory($this->expression)->isDue($date->toDateTimeString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the filters pass for the event.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Foundation\Application $app
|
||||
* @return bool
|
||||
*/
|
||||
protected function filtersPass(Application $app)
|
||||
{
|
||||
if (($this->filter && ! $app->call($this->filter)) ||
|
||||
$this->reject && $app->call($this->reject))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the event runs in the given environment.
|
||||
*
|
||||
* @param string $environment
|
||||
* @return bool
|
||||
*/
|
||||
public function runsInEnvironment($environment)
|
||||
{
|
||||
return empty($this->environments) || in_array($environment, $this->environments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the event runs in maintenance mode.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function runsInMaintenanceMode()
|
||||
{
|
||||
return $this->evenInMaintenanceMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Cron expression representing the event's frequency.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return $this
|
||||
*/
|
||||
public function cron($expression)
|
||||
{
|
||||
$this->expression = $expression;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run hourly.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function hourly()
|
||||
{
|
||||
return $this->cron('0 * * * * *');
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run daily.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function daily()
|
||||
{
|
||||
return $this->cron('0 0 * * * *');
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the command at a given time.
|
||||
*
|
||||
* @param string $time
|
||||
* @return $this
|
||||
*/
|
||||
public function at($time)
|
||||
{
|
||||
return $this->dailyAt($time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run daily at a given time (10:00, 19:30, etc).
|
||||
*
|
||||
* @param string $time
|
||||
* @return $this
|
||||
*/
|
||||
public function dailyAt($time)
|
||||
{
|
||||
$segments = explode(':', $time);
|
||||
|
||||
return $this->spliceIntoPosition(2, (int) $segments[0])
|
||||
->spliceIntoPosition(1, count($segments) == 2 ? (int) $segments[1] : '0');
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run twice daily.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function twiceDaily()
|
||||
{
|
||||
return $this->cron('0 1,13 * * * *');
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run only on weekdays.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function weekdays()
|
||||
{
|
||||
return $this->spliceIntoPosition(5, '1-5');
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run only on Mondays.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function mondays()
|
||||
{
|
||||
return $this->days(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run only on Tuesdays.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function tuesdays()
|
||||
{
|
||||
return $this->days(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run only on Wednesdays.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function wednesdays()
|
||||
{
|
||||
return $this->days(3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run only on Thursdays.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function thursdays()
|
||||
{
|
||||
return $this->days(4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run only on Fridays.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function fridays()
|
||||
{
|
||||
return $this->days(5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run only on Saturdays.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function saturdays()
|
||||
{
|
||||
return $this->days(6);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run only on Sundays.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function sundays()
|
||||
{
|
||||
return $this->days(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run weekly.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function weekly()
|
||||
{
|
||||
return $this->cron('0 0 * * 0 *');
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run weekly on a given day and time.
|
||||
*
|
||||
* @param int $day
|
||||
* @param string $time
|
||||
* @return $this
|
||||
*/
|
||||
public function weeklyOn($day, $time = '0:0')
|
||||
{
|
||||
$this->dailyAt($time);
|
||||
|
||||
return $this->spliceIntoPosition(5, $day);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run monthly.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function monthly()
|
||||
{
|
||||
return $this->cron('0 0 1 * * *');
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run yearly.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function yearly()
|
||||
{
|
||||
return $this->cron('0 0 1 1 * *');
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run every five minutes.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function everyFiveMinutes()
|
||||
{
|
||||
return $this->cron('*/5 * * * * *');
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run every ten minutes.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function everyTenMinutes()
|
||||
{
|
||||
return $this->cron('*/10 * * * * *');
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run every thirty minutes.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function everyThirtyMinutes()
|
||||
{
|
||||
return $this->cron('0,30 * * * * *');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the days of the week the command should run on.
|
||||
*
|
||||
* @param array|dynamic $days
|
||||
* @return $this
|
||||
*/
|
||||
public function days($days)
|
||||
{
|
||||
$days = is_array($days) ? $days : func_get_args();
|
||||
|
||||
return $this->spliceIntoPosition(5, implode(',', $days));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the timezone the date should be evaluated on.
|
||||
*
|
||||
* @param \DateTimeZone|string $timezone
|
||||
* @return $this
|
||||
*/
|
||||
public function timezone($timezone)
|
||||
{
|
||||
$this->timezone = $timezone;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set which user the command should run as.
|
||||
*
|
||||
* @param string $user
|
||||
* @return $this
|
||||
*/
|
||||
public function user($user)
|
||||
{
|
||||
$this->user = $user;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit the environments the command should run in.
|
||||
*
|
||||
* @param array|dynamic $environments
|
||||
* @return $this
|
||||
*/
|
||||
public function environments($environments)
|
||||
{
|
||||
$this->environments = is_array($environments) ? $environments : func_get_args();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* State that the command should run even in maintenance mode.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function evenInMaintenanceMode()
|
||||
{
|
||||
$this->evenInMaintenanceMode = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not allow the event to overlap each other.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function withoutOverlapping()
|
||||
{
|
||||
$this->withoutOverlapping = true;
|
||||
|
||||
return $this->skip(function()
|
||||
{
|
||||
return file_exists($this->mutexPath());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a callback to further filter the schedule.
|
||||
*
|
||||
* @param \Closure $callback
|
||||
* @return $this
|
||||
*/
|
||||
public function when(Closure $callback)
|
||||
{
|
||||
$this->filter = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a callback to further filter the schedule.
|
||||
*
|
||||
* @param \Closure $callback
|
||||
* @return $this
|
||||
*/
|
||||
public function skip(Closure $callback)
|
||||
{
|
||||
$this->reject = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the output of the command to a given location.
|
||||
*
|
||||
* @param string $location
|
||||
* @return $this
|
||||
*/
|
||||
public function sendOutputTo($location)
|
||||
{
|
||||
$this->output = $location;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* E-mail the results of the scheduled operation.
|
||||
*
|
||||
* @param array|dynamic $addresses
|
||||
* @return $this
|
||||
*
|
||||
* @throws \LogicException
|
||||
*/
|
||||
public function emailOutputTo($addresses)
|
||||
{
|
||||
if (is_null($this->output) || $this->output == '/dev/null')
|
||||
{
|
||||
throw new LogicException("Must direct output to a file in order to e-mail results.");
|
||||
}
|
||||
|
||||
$addresses = is_array($addresses) ? $addresses : func_get_args();
|
||||
|
||||
return $this->then(function(Mailer $mailer) use ($addresses)
|
||||
{
|
||||
$this->emailOutput($mailer, $addresses);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* E-mail the output of the event to the recipients.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Mail\Mailer $mailer
|
||||
* @param array $addresses
|
||||
* @return void
|
||||
*/
|
||||
protected function emailOutput(Mailer $mailer, $addresses)
|
||||
{
|
||||
$mailer->raw(file_get_contents($this->output), function($m) use ($addresses)
|
||||
{
|
||||
$m->subject($this->getEmailSubject());
|
||||
|
||||
foreach ($addresses as $address)
|
||||
{
|
||||
$m->to($address);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the e-mail subject line for output results.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getEmailSubject()
|
||||
{
|
||||
if ($this->description)
|
||||
{
|
||||
return 'Scheduled Job Output ('.$this->description.')';
|
||||
}
|
||||
|
||||
return 'Scheduled Job Output';
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a callback to ping a given URL after the job runs.
|
||||
*
|
||||
* @param string $url
|
||||
* @return $this
|
||||
*/
|
||||
public function thenPing($url)
|
||||
{
|
||||
return $this->then(function() use ($url) { (new HttpClient)->get($url); });
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a callback to be called after the operation.
|
||||
*
|
||||
* @param \Closure $callback
|
||||
* @return $this
|
||||
*/
|
||||
public function then(Closure $callback)
|
||||
{
|
||||
$this->afterCallbacks[] = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the human-friendly description of the event.
|
||||
*
|
||||
* @param string $description
|
||||
* @return $this
|
||||
*/
|
||||
public function name($description)
|
||||
{
|
||||
return $this->description($description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the human-friendly description of the event.
|
||||
*
|
||||
* @param string $description
|
||||
* @return $this
|
||||
*/
|
||||
public function description($description)
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Splice the given value into the given position of the expression.
|
||||
*
|
||||
* @param int $position
|
||||
* @param string $value
|
||||
* @return void
|
||||
*/
|
||||
protected function spliceIntoPosition($position, $value)
|
||||
{
|
||||
$segments = explode(' ', $this->expression);
|
||||
|
||||
$segments[$position - 1] = $value;
|
||||
|
||||
return $this->cron(implode(' ', $segments));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the summary of the event for display.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSummaryForDisplay()
|
||||
{
|
||||
if (is_string($this->description)) return $this->description;
|
||||
|
||||
return $this->buildCommand();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Cron expression for the event.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getExpression()
|
||||
{
|
||||
return $this->expression;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
<?php namespace Illuminate\Console\Scheduling;
|
||||
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
|
||||
class Schedule {
|
||||
|
||||
/**
|
||||
* All of the events on the schedule.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $events = [];
|
||||
|
||||
/**
|
||||
* Add a new callback event to the schedule.
|
||||
*
|
||||
* @param string $callback
|
||||
* @param array $parameters
|
||||
* @return \Illuminate\Console\Scheduling\Event
|
||||
*/
|
||||
public function call($callback, array $parameters = array())
|
||||
{
|
||||
$this->events[] = $event = new CallbackEvent($callback, $parameters);
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new Artisan command event to the schedule.
|
||||
*
|
||||
* @param string $command
|
||||
* @return \Illuminate\Console\Scheduling\Event
|
||||
*/
|
||||
public function command($command)
|
||||
{
|
||||
return $this->exec(PHP_BINARY.' artisan '.$command);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new command event to the schedule.
|
||||
*
|
||||
* @param string $command
|
||||
* @return \Illuminate\Console\Scheduling\Event
|
||||
*/
|
||||
public function exec($command)
|
||||
{
|
||||
$this->events[] = $event = new Event($command);
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the events on the schedule.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function events()
|
||||
{
|
||||
return $this->events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the events on the schedule that are due.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Foundation\Application $app
|
||||
* @return array
|
||||
*/
|
||||
public function dueEvents(Application $app)
|
||||
{
|
||||
return array_filter($this->events, function($event) use ($app)
|
||||
{
|
||||
return $event->isDue($app);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
<?php namespace Illuminate\Console\Scheduling;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class ScheduleRunCommand extends Command {
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'schedule:run';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Run the scheduled commands';
|
||||
|
||||
/**
|
||||
* The schedule instance.
|
||||
*
|
||||
* @var \Illuminate\Console\Scheduling\Schedule
|
||||
*/
|
||||
protected $schedule;
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Schedule $schedule)
|
||||
{
|
||||
$this->schedule = $schedule;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function fire()
|
||||
{
|
||||
$events = $this->schedule->dueEvents($this->laravel);
|
||||
|
||||
foreach ($events as $event)
|
||||
{
|
||||
$this->line('<info>Running scheduled command:</info> '.$event->getSummaryForDisplay());
|
||||
|
||||
$event->run($this->laravel);
|
||||
}
|
||||
|
||||
if (count($events) === 0)
|
||||
{
|
||||
$this->info('No scheduled commands are ready to run.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
{
|
||||
"name": "illuminate/console",
|
||||
"description": "The Illuminate Console package.",
|
||||
"license": "MIT",
|
||||
"homepage": "http://laravel.com",
|
||||
"support": {
|
||||
"issues": "https://github.com/laravel/framework/issues",
|
||||
"source": "https://github.com/laravel/framework"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Taylor Otwell",
|
||||
"email": "taylorotwell@gmail.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.4.0",
|
||||
"illuminate/contracts": "5.0.*",
|
||||
"symfony/console": "2.6.*",
|
||||
"nesbot/carbon": "~1.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Illuminate\\Console\\": ""
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "5.0-dev"
|
||||
}
|
||||
},
|
||||
"suggest": {
|
||||
"guzzlehttp/guzzle": "Required to use the thenPing method on schedules (~5.0).",
|
||||
"mtdowling/cron-expression": "Required to use scheduling component (~1.0).",
|
||||
"symfony/process": "Required to use scheduling component (2.6.*).",
|
||||
"nesbot/carbon": "Required to use scheduling component (~1.0)."
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
}
|
||||
Reference in New Issue
Block a user