repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6 values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1 value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
Indatus/dispatcher | src/Indatus/Dispatcher/Drivers/DateTime/Scheduler.php | Scheduler.daily | public function daily()
{
$this->setScheduleMinute(0);
$this->setScheduleHour(0);
$this->setScheduleDayOfMonth(self::ANY);
$this->setScheduleMonth(self::ANY);
$this->setScheduleDayOfWeek(self::ANY);
return $this;
} | php | public function daily()
{
$this->setScheduleMinute(0);
$this->setScheduleHour(0);
$this->setScheduleDayOfMonth(self::ANY);
$this->setScheduleMonth(self::ANY);
$this->setScheduleDayOfWeek(self::ANY);
return $this;
} | [
"public",
"function",
"daily",
"(",
")",
"{",
"$",
"this",
"->",
"setScheduleMinute",
"(",
"0",
")",
";",
"$",
"this",
"->",
"setScheduleHour",
"(",
"0",
")",
";",
"$",
"this",
"->",
"setScheduleDayOfMonth",
"(",
"self",
"::",
"ANY",
")",
";",
"$",
"... | Run once a day at midnight
@return $this | [
"Run",
"once",
"a",
"day",
"at",
"midnight"
] | train | https://github.com/Indatus/dispatcher/blob/9548ab90d0c1e9a2ff7239f28e470de4493c00ff/src/Indatus/Dispatcher/Drivers/DateTime/Scheduler.php#L274-L283 |
Indatus/dispatcher | src/Indatus/Dispatcher/Drivers/DateTime/Scheduler.php | Scheduler.everyMinutes | public function everyMinutes($minutes)
{
$minutesSchedule = self::ANY;
if ($minutes != 1) {
$minutesSchedule .= '/'.$minutes;
}
$this->setScheduleMinute($minutesSchedule);
return $this;
} | php | public function everyMinutes($minutes)
{
$minutesSchedule = self::ANY;
if ($minutes != 1) {
$minutesSchedule .= '/'.$minutes;
}
$this->setScheduleMinute($minutesSchedule);
return $this;
} | [
"public",
"function",
"everyMinutes",
"(",
"$",
"minutes",
")",
"{",
"$",
"minutesSchedule",
"=",
"self",
"::",
"ANY",
";",
"if",
"(",
"$",
"minutes",
"!=",
"1",
")",
"{",
"$",
"minutesSchedule",
".=",
"'/'",
".",
"$",
"minutes",
";",
"}",
"$",
"this... | Run a command every X minutes
@param int $minutes
@return $this | [
"Run",
"a",
"command",
"every",
"X",
"minutes"
] | train | https://github.com/Indatus/dispatcher/blob/9548ab90d0c1e9a2ff7239f28e470de4493c00ff/src/Indatus/Dispatcher/Drivers/DateTime/Scheduler.php#L365-L375 |
Indatus/dispatcher | src/Indatus/Dispatcher/Commands/Run.php | Run.fire | public function fire()
{
/** @var \Indatus\Dispatcher\OptionReader $optionReader */
$optionReader = App::make('Indatus\Dispatcher\OptionReader', [
$this->option(),
]);
/** @var \Indatus\Dispatcher\Debugger $debugger */
$debugger = App::make('Indatus\Dispatcher\Debugger', [
$optionReader,
$this->getOutput(),
]);
$this->commandService->runDue($debugger);
} | php | public function fire()
{
/** @var \Indatus\Dispatcher\OptionReader $optionReader */
$optionReader = App::make('Indatus\Dispatcher\OptionReader', [
$this->option(),
]);
/** @var \Indatus\Dispatcher\Debugger $debugger */
$debugger = App::make('Indatus\Dispatcher\Debugger', [
$optionReader,
$this->getOutput(),
]);
$this->commandService->runDue($debugger);
} | [
"public",
"function",
"fire",
"(",
")",
"{",
"/** @var \\Indatus\\Dispatcher\\OptionReader $optionReader */",
"$",
"optionReader",
"=",
"App",
"::",
"make",
"(",
"'Indatus\\Dispatcher\\OptionReader'",
",",
"[",
"$",
"this",
"->",
"option",
"(",
")",
",",
"]",
")",
... | Execute the console command.
@return mixed | [
"Execute",
"the",
"console",
"command",
"."
] | train | https://github.com/Indatus/dispatcher/blob/9548ab90d0c1e9a2ff7239f28e470de4493c00ff/src/Indatus/Dispatcher/Commands/Run.php#L64-L78 |
Indatus/dispatcher | src/Indatus/Dispatcher/Commands/Make.php | Make.extendStub | protected function extendStub($stub)
{
/** @var \Illuminate\Filesystem\Filesystem $files */
$files = App::make('Illuminate\Filesystem\Filesystem');
$content = $files->get(__DIR__.DIRECTORY_SEPARATOR.'stubs'.DIRECTORY_SEPARATOR.'command.stub');
$replacements = [
'use Illuminate\Console\Command' => "use Indatus\\Dispatcher\\Scheduling\\ScheduledCommand;\n".
"use Indatus\\Dispatcher\\Scheduling\\Schedulable;\n".
"use Indatus\\Dispatcher\\Drivers\\".ucwords(Config::get('dispatcher::driver'))."\\Scheduler",
'extends Command {' => 'extends ScheduledCommand {',
'parent::__construct();' => $content,
];
$stub = str_replace(array_keys($replacements), array_values($replacements), $stub);
return $stub;
} | php | protected function extendStub($stub)
{
/** @var \Illuminate\Filesystem\Filesystem $files */
$files = App::make('Illuminate\Filesystem\Filesystem');
$content = $files->get(__DIR__.DIRECTORY_SEPARATOR.'stubs'.DIRECTORY_SEPARATOR.'command.stub');
$replacements = [
'use Illuminate\Console\Command' => "use Indatus\\Dispatcher\\Scheduling\\ScheduledCommand;\n".
"use Indatus\\Dispatcher\\Scheduling\\Schedulable;\n".
"use Indatus\\Dispatcher\\Drivers\\".ucwords(Config::get('dispatcher::driver'))."\\Scheduler",
'extends Command {' => 'extends ScheduledCommand {',
'parent::__construct();' => $content,
];
$stub = str_replace(array_keys($replacements), array_values($replacements), $stub);
return $stub;
} | [
"protected",
"function",
"extendStub",
"(",
"$",
"stub",
")",
"{",
"/** @var \\Illuminate\\Filesystem\\Filesystem $files */",
"$",
"files",
"=",
"App",
"::",
"make",
"(",
"'Illuminate\\Filesystem\\Filesystem'",
")",
";",
"$",
"content",
"=",
"$",
"files",
"->",
"get... | Make sure we're implementing our own class
@param $stub
@return string | [
"Make",
"sure",
"we",
"re",
"implementing",
"our",
"own",
"class"
] | train | https://github.com/Indatus/dispatcher/blob/9548ab90d0c1e9a2ff7239f28e470de4493c00ff/src/Indatus/Dispatcher/Commands/Make.php#L50-L67 |
Indatus/dispatcher | src/Indatus/Dispatcher/BackgroundProcessRunner.php | BackgroundProcessRunner.run | public function run(
ScheduledCommandInterface $scheduledCommand,
array $arguments = [],
array $options = [],
Debugger $debugger = null
) {
$runCommand = $this->commandService->getRunCommand($scheduledCommand, $arguments, $options);
if (!is_null($debugger)) {
$debugger->commandRun($scheduledCommand, $runCommand);
}
exec($runCommand);
return true;
} | php | public function run(
ScheduledCommandInterface $scheduledCommand,
array $arguments = [],
array $options = [],
Debugger $debugger = null
) {
$runCommand = $this->commandService->getRunCommand($scheduledCommand, $arguments, $options);
if (!is_null($debugger)) {
$debugger->commandRun($scheduledCommand, $runCommand);
}
exec($runCommand);
return true;
} | [
"public",
"function",
"run",
"(",
"ScheduledCommandInterface",
"$",
"scheduledCommand",
",",
"array",
"$",
"arguments",
"=",
"[",
"]",
",",
"array",
"$",
"options",
"=",
"[",
"]",
",",
"Debugger",
"$",
"debugger",
"=",
"null",
")",
"{",
"$",
"runCommand",
... | Run a scheduled command
@param \Indatus\Dispatcher\Scheduling\ScheduledCommandInterface $scheduledCommand
@param array $arguments
@param array $options
@return bool | [
"Run",
"a",
"scheduled",
"command"
] | train | https://github.com/Indatus/dispatcher/blob/9548ab90d0c1e9a2ff7239f28e470de4493c00ff/src/Indatus/Dispatcher/BackgroundProcessRunner.php#L35-L50 |
Indatus/dispatcher | src/Indatus/Dispatcher/Drivers/DateTime/ScheduleService.php | ScheduleService.isDue | public function isDue(Schedulable $scheduler)
{
/** @var \Indatus\Dispatcher\Drivers\DateTime\ScheduleInterpreter $interpreter */
$interpreter = App::make('Indatus\Dispatcher\Drivers\DateTime\ScheduleInterpreter', [$scheduler]);
/** @var \Illuminate\Contracts\Logging\Log $logger */
$logger = App::make('Illuminate\Contracts\Logging\Log');
try {
return $interpreter->isDue();
} catch (Exception $e) {
$logger->error($e);
}
return false;
} | php | public function isDue(Schedulable $scheduler)
{
/** @var \Indatus\Dispatcher\Drivers\DateTime\ScheduleInterpreter $interpreter */
$interpreter = App::make('Indatus\Dispatcher\Drivers\DateTime\ScheduleInterpreter', [$scheduler]);
/** @var \Illuminate\Contracts\Logging\Log $logger */
$logger = App::make('Illuminate\Contracts\Logging\Log');
try {
return $interpreter->isDue();
} catch (Exception $e) {
$logger->error($e);
}
return false;
} | [
"public",
"function",
"isDue",
"(",
"Schedulable",
"$",
"scheduler",
")",
"{",
"/** @var \\Indatus\\Dispatcher\\Drivers\\DateTime\\ScheduleInterpreter $interpreter */",
"$",
"interpreter",
"=",
"App",
"::",
"make",
"(",
"'Indatus\\Dispatcher\\Drivers\\DateTime\\ScheduleInterpreter'... | Determine if a schedule is due to be run.
@param \Indatus\Dispatcher\Scheduling\Schedulable $scheduler
@return bool | [
"Determine",
"if",
"a",
"schedule",
"is",
"due",
"to",
"be",
"run",
"."
] | train | https://github.com/Indatus/dispatcher/blob/9548ab90d0c1e9a2ff7239f28e470de4493c00ff/src/Indatus/Dispatcher/Drivers/DateTime/ScheduleService.php#L29-L44 |
Indatus/dispatcher | src/Indatus/Dispatcher/Drivers/DateTime/ScheduleInterpreter.php | ScheduleInterpreter.isDue | public function isDue()
{
$cron = App::make('Cron\CronExpression', [$this->scheduler->getCronSchedule()]);
// if a week is defined, so some special weekly stuff
if ($this->scheduler->getScheduleWeek() !== Scheduler::NONE) {
return $this->thisWeek() && $cron->isDue();
}
//otherwise us only standard cron scheduling
return $cron->isDue();
} | php | public function isDue()
{
$cron = App::make('Cron\CronExpression', [$this->scheduler->getCronSchedule()]);
// if a week is defined, so some special weekly stuff
if ($this->scheduler->getScheduleWeek() !== Scheduler::NONE) {
return $this->thisWeek() && $cron->isDue();
}
//otherwise us only standard cron scheduling
return $cron->isDue();
} | [
"public",
"function",
"isDue",
"(",
")",
"{",
"$",
"cron",
"=",
"App",
"::",
"make",
"(",
"'Cron\\CronExpression'",
",",
"[",
"$",
"this",
"->",
"scheduler",
"->",
"getCronSchedule",
"(",
")",
"]",
")",
";",
"// if a week is defined, so some special weekly stuff... | Determine if the current schedule is due to be run
@return bool | [
"Determine",
"if",
"the",
"current",
"schedule",
"is",
"due",
"to",
"be",
"run"
] | train | https://github.com/Indatus/dispatcher/blob/9548ab90d0c1e9a2ff7239f28e470de4493c00ff/src/Indatus/Dispatcher/Drivers/DateTime/ScheduleInterpreter.php#L41-L52 |
Indatus/dispatcher | src/Indatus/Dispatcher/Drivers/DateTime/ScheduleInterpreter.php | ScheduleInterpreter.thisWeek | public function thisWeek()
{
$scheduleWeek = $this->scheduler->getScheduleWeek();
$currentWeek = $this->now->format('W');
//if a month is defined, week refers to the week of the month
$scheduleMonth = $this->scheduler->getScheduleMonth();
if (!is_null($scheduleMonth) && $scheduleMonth !== Scheduler::NONE) {
return $this->isCurrent($scheduleWeek, $this->now->weekOfMonth);
}
//if it's an odd or even week
if ($scheduleWeek == 'odd' && $currentWeek & 1) {
return true;
} elseif ($scheduleWeek == 'even' && !($currentWeek & 1)) {
return true;
}
return $this->isCurrent($scheduleWeek, $this->now->weekOfYear);
} | php | public function thisWeek()
{
$scheduleWeek = $this->scheduler->getScheduleWeek();
$currentWeek = $this->now->format('W');
//if a month is defined, week refers to the week of the month
$scheduleMonth = $this->scheduler->getScheduleMonth();
if (!is_null($scheduleMonth) && $scheduleMonth !== Scheduler::NONE) {
return $this->isCurrent($scheduleWeek, $this->now->weekOfMonth);
}
//if it's an odd or even week
if ($scheduleWeek == 'odd' && $currentWeek & 1) {
return true;
} elseif ($scheduleWeek == 'even' && !($currentWeek & 1)) {
return true;
}
return $this->isCurrent($scheduleWeek, $this->now->weekOfYear);
} | [
"public",
"function",
"thisWeek",
"(",
")",
"{",
"$",
"scheduleWeek",
"=",
"$",
"this",
"->",
"scheduler",
"->",
"getScheduleWeek",
"(",
")",
";",
"$",
"currentWeek",
"=",
"$",
"this",
"->",
"now",
"->",
"format",
"(",
"'W'",
")",
";",
"//if a month is d... | Determine if the provided expression refers to this week
@return bool | [
"Determine",
"if",
"the",
"provided",
"expression",
"refers",
"to",
"this",
"week"
] | train | https://github.com/Indatus/dispatcher/blob/9548ab90d0c1e9a2ff7239f28e470de4493c00ff/src/Indatus/Dispatcher/Drivers/DateTime/ScheduleInterpreter.php#L59-L78 |
Indatus/dispatcher | src/Indatus/Dispatcher/Drivers/DateTime/ScheduleInterpreter.php | ScheduleInterpreter.isCurrent | protected function isCurrent($expression, $current)
{
// if it's any
if ($expression == Scheduler::ANY) {
return true;
}
// if this is in a series
if (is_array($expression)) {
return in_array($current, $expression);
}
// if there's a direct match
if ((string) $expression === (string) $current) {
return true;
}
return false;
} | php | protected function isCurrent($expression, $current)
{
// if it's any
if ($expression == Scheduler::ANY) {
return true;
}
// if this is in a series
if (is_array($expression)) {
return in_array($current, $expression);
}
// if there's a direct match
if ((string) $expression === (string) $current) {
return true;
}
return false;
} | [
"protected",
"function",
"isCurrent",
"(",
"$",
"expression",
",",
"$",
"current",
")",
"{",
"// if it's any",
"if",
"(",
"$",
"expression",
"==",
"Scheduler",
"::",
"ANY",
")",
"{",
"return",
"true",
";",
"}",
"// if this is in a series",
"if",
"(",
"is_arr... | This method checks syntax for all scheduling components.
- If there's a direct match
- If it's an ANY match
- If the expression exists in the series
@param string $expression The expression to compare
@param string $current The current value to compare against
@return bool | [
"This",
"method",
"checks",
"syntax",
"for",
"all",
"scheduling",
"components",
"."
] | train | https://github.com/Indatus/dispatcher/blob/9548ab90d0c1e9a2ff7239f28e470de4493c00ff/src/Indatus/Dispatcher/Drivers/DateTime/ScheduleInterpreter.php#L92-L110 |
Indatus/dispatcher | src/Indatus/Dispatcher/Scheduling/Schedulable.php | Schedulable.args | public function args(array $arguments)
{
// provide a new instance of the scheduler class if this
// is the first method that was called. This allows for
// $scheduler->opts() to return a new instance of the
// scheduler when it's first called
if (count($this->options) == 0) {
$scheduler = App::make(get_called_class());
$scheduler->setArguments($arguments);
return $scheduler;
}
$this->setArguments($arguments);
return $this;
} | php | public function args(array $arguments)
{
// provide a new instance of the scheduler class if this
// is the first method that was called. This allows for
// $scheduler->opts() to return a new instance of the
// scheduler when it's first called
if (count($this->options) == 0) {
$scheduler = App::make(get_called_class());
$scheduler->setArguments($arguments);
return $scheduler;
}
$this->setArguments($arguments);
return $this;
} | [
"public",
"function",
"args",
"(",
"array",
"$",
"arguments",
")",
"{",
"// provide a new instance of the scheduler class if this",
"// is the first method that was called. This allows for",
"// $scheduler->opts() to return a new instance of the",
"// scheduler when it's first called",
"i... | Define arguments for this schedule when it runs.
@param array $arguments
@return \Indatus\Dispatcher\Scheduling\Schedulable | [
"Define",
"arguments",
"for",
"this",
"schedule",
"when",
"it",
"runs",
"."
] | train | https://github.com/Indatus/dispatcher/blob/9548ab90d0c1e9a2ff7239f28e470de4493c00ff/src/Indatus/Dispatcher/Scheduling/Schedulable.php#L32-L48 |
Indatus/dispatcher | src/Indatus/Dispatcher/Scheduling/Schedulable.php | Schedulable.opts | public function opts(array $options)
{
// provide a new instance of the scheduler class if this
// is the first method that was called. This allows for
// $scheduler->opts() to return a new instance of the
// scheduler when it's first called
if (count($this->arguments) == 0) {
$scheduler = App::make(get_called_class());
$scheduler->setOptions($options);
return $scheduler;
}
$this->setOptions($options);
return $this;
} | php | public function opts(array $options)
{
// provide a new instance of the scheduler class if this
// is the first method that was called. This allows for
// $scheduler->opts() to return a new instance of the
// scheduler when it's first called
if (count($this->arguments) == 0) {
$scheduler = App::make(get_called_class());
$scheduler->setOptions($options);
return $scheduler;
}
$this->setOptions($options);
return $this;
} | [
"public",
"function",
"opts",
"(",
"array",
"$",
"options",
")",
"{",
"// provide a new instance of the scheduler class if this",
"// is the first method that was called. This allows for",
"// $scheduler->opts() to return a new instance of the",
"// scheduler when it's first called",
"if"... | Define options for this schedule when it runs.
@param array $options
@return \Indatus\Dispatcher\Scheduling\Schedulable | [
"Define",
"options",
"for",
"this",
"schedule",
"when",
"it",
"runs",
"."
] | train | https://github.com/Indatus/dispatcher/blob/9548ab90d0c1e9a2ff7239f28e470de4493c00ff/src/Indatus/Dispatcher/Scheduling/Schedulable.php#L79-L95 |
Indatus/dispatcher | src/Indatus/Dispatcher/Scheduling/Schedulable.php | Schedulable.setEnvironmentOption | private function setEnvironmentOption()
{
if (!array_key_exists('env', $this->options)) {
$this->options = array_merge(
$this->options,
['env' => App::environment()]
);
}
} | php | private function setEnvironmentOption()
{
if (!array_key_exists('env', $this->options)) {
$this->options = array_merge(
$this->options,
['env' => App::environment()]
);
}
} | [
"private",
"function",
"setEnvironmentOption",
"(",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"'env'",
",",
"$",
"this",
"->",
"options",
")",
")",
"{",
"$",
"this",
"->",
"options",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"options",
",",
... | Propagate scheduled:run environment
to scheduled commands, only if 'env' option was not specified | [
"Propagate",
"scheduled",
":",
"run",
"environment",
"to",
"scheduled",
"commands",
"only",
"if",
"env",
"option",
"was",
"not",
"specified"
] | train | https://github.com/Indatus/dispatcher/blob/9548ab90d0c1e9a2ff7239f28e470de4493c00ff/src/Indatus/Dispatcher/Scheduling/Schedulable.php#L124-L132 |
Indatus/dispatcher | src/Indatus/Dispatcher/Debugger.php | Debugger.commandNotRun | public function commandNotRun(ScheduledCommandInterface $command, $reason)
{
if ($this->optionReader->isDebugMode()) {
$this->output->writeln(' <comment>'.$command->getName().'</comment>: '.$reason);
}
} | php | public function commandNotRun(ScheduledCommandInterface $command, $reason)
{
if ($this->optionReader->isDebugMode()) {
$this->output->writeln(' <comment>'.$command->getName().'</comment>: '.$reason);
}
} | [
"public",
"function",
"commandNotRun",
"(",
"ScheduledCommandInterface",
"$",
"command",
",",
"$",
"reason",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"optionReader",
"->",
"isDebugMode",
"(",
")",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",... | Indicate why a command was not run
@param ScheduledCommandInterface $command
@param $reason | [
"Indicate",
"why",
"a",
"command",
"was",
"not",
"run"
] | train | https://github.com/Indatus/dispatcher/blob/9548ab90d0c1e9a2ff7239f28e470de4493c00ff/src/Indatus/Dispatcher/Debugger.php#L31-L36 |
Indatus/dispatcher | src/Indatus/Dispatcher/Debugger.php | Debugger.commandRun | public function commandRun(ScheduledCommandInterface $command, $runCommand)
{
if ($this->optionReader->isDebugMode()) {
$this->output->writeln(' <info>'.$command->getName().'</info>: '.$runCommand);
}
} | php | public function commandRun(ScheduledCommandInterface $command, $runCommand)
{
if ($this->optionReader->isDebugMode()) {
$this->output->writeln(' <info>'.$command->getName().'</info>: '.$runCommand);
}
} | [
"public",
"function",
"commandRun",
"(",
"ScheduledCommandInterface",
"$",
"command",
",",
"$",
"runCommand",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"optionReader",
"->",
"isDebugMode",
"(",
")",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"("... | Indicate why a command has run
@param ScheduledCommandInterface $command
@param $runCommand | [
"Indicate",
"why",
"a",
"command",
"has",
"run"
] | train | https://github.com/Indatus/dispatcher/blob/9548ab90d0c1e9a2ff7239f28e470de4493c00ff/src/Indatus/Dispatcher/Debugger.php#L44-L49 |
Indatus/dispatcher | src/Indatus/Dispatcher/ConfigResolver.php | ConfigResolver.resolveSchedulerClass | public function resolveSchedulerClass()
{
try {
return $this->container->make($this->getDriver().'\\Scheduler', [$this]);
} catch (ReflectionException $e) {
return $this->container->make('Indatus\Dispatcher\Drivers\\'.$this->getDriver().'\\Scheduler', [$this]);
}
} | php | public function resolveSchedulerClass()
{
try {
return $this->container->make($this->getDriver().'\\Scheduler', [$this]);
} catch (ReflectionException $e) {
return $this->container->make('Indatus\Dispatcher\Drivers\\'.$this->getDriver().'\\Scheduler', [$this]);
}
} | [
"public",
"function",
"resolveSchedulerClass",
"(",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"container",
"->",
"make",
"(",
"$",
"this",
"->",
"getDriver",
"(",
")",
".",
"'\\\\Scheduler'",
",",
"[",
"$",
"this",
"]",
")",
";",
"}",
"catch",... | Resolve a class based on the driver configuration
@return \Indatus\Dispatcher\Scheduling\Schedulable | [
"Resolve",
"a",
"class",
"based",
"on",
"the",
"driver",
"configuration"
] | train | https://github.com/Indatus/dispatcher/blob/9548ab90d0c1e9a2ff7239f28e470de4493c00ff/src/Indatus/Dispatcher/ConfigResolver.php#L35-L42 |
Indatus/dispatcher | src/Indatus/Dispatcher/ConfigResolver.php | ConfigResolver.resolveServiceClass | public function resolveServiceClass()
{
try {
return $this->container->make($this->getDriver().'\\ScheduleService');
} catch (ReflectionException $e) {
return $this->container->make('Indatus\Dispatcher\Drivers\\'.$this->getDriver().'\\ScheduleService');
}
} | php | public function resolveServiceClass()
{
try {
return $this->container->make($this->getDriver().'\\ScheduleService');
} catch (ReflectionException $e) {
return $this->container->make('Indatus\Dispatcher\Drivers\\'.$this->getDriver().'\\ScheduleService');
}
} | [
"public",
"function",
"resolveServiceClass",
"(",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"container",
"->",
"make",
"(",
"$",
"this",
"->",
"getDriver",
"(",
")",
".",
"'\\\\ScheduleService'",
")",
";",
"}",
"catch",
"(",
"ReflectionException",
... | Resolve a class based on the driver configuration
@return \Indatus\Dispatcher\Scheduling\ScheduleService | [
"Resolve",
"a",
"class",
"based",
"on",
"the",
"driver",
"configuration"
] | train | https://github.com/Indatus/dispatcher/blob/9548ab90d0c1e9a2ff7239f28e470de4493c00ff/src/Indatus/Dispatcher/ConfigResolver.php#L49-L56 |
Indatus/dispatcher | src/Indatus/Dispatcher/ServiceProvider.php | ServiceProvider.boot | public function boot()
{
$this->package('indatus/dispatcher');
$resolver = $this->app->make('\Indatus\Dispatcher\ConfigResolver');
//load the scheduler of the appropriate driver
$this->app->bind('Indatus\Dispatcher\Scheduling\Schedulable', function () use ($resolver) {
return $resolver->resolveSchedulerClass();
});
//load the schedule service of the appropriate driver
$this->app->bind('Indatus\Dispatcher\Services\ScheduleService', function () use ($resolver) {
return $resolver->resolveServiceClass();
});
} | php | public function boot()
{
$this->package('indatus/dispatcher');
$resolver = $this->app->make('\Indatus\Dispatcher\ConfigResolver');
//load the scheduler of the appropriate driver
$this->app->bind('Indatus\Dispatcher\Scheduling\Schedulable', function () use ($resolver) {
return $resolver->resolveSchedulerClass();
});
//load the schedule service of the appropriate driver
$this->app->bind('Indatus\Dispatcher\Services\ScheduleService', function () use ($resolver) {
return $resolver->resolveServiceClass();
});
} | [
"public",
"function",
"boot",
"(",
")",
"{",
"$",
"this",
"->",
"package",
"(",
"'indatus/dispatcher'",
")",
";",
"$",
"resolver",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'\\Indatus\\Dispatcher\\ConfigResolver'",
")",
";",
"//load the scheduler of the... | Bootstrap the application events.
@return void | [
"Bootstrap",
"the",
"application",
"events",
"."
] | train | https://github.com/Indatus/dispatcher/blob/9548ab90d0c1e9a2ff7239f28e470de4493c00ff/src/Indatus/Dispatcher/ServiceProvider.php#L29-L44 |
Indatus/dispatcher | src/Indatus/Dispatcher/ServiceProvider.php | ServiceProvider.registerCommands | private function registerCommands()
{
//scheduled:summary
$this->app->bindShared('command.scheduled.summary', function (Application $app) {
return $app->make('Indatus\Dispatcher\Commands\ScheduleSummary');
});
//scheduled:make
$this->app->bindShared('command.scheduled.make', function (Application $app) {
return $app->make('Indatus\Dispatcher\Commands\Make');
});
//scheduled:run
$this->app->bindShared('command.scheduled.run', function (Application $app) {
return $app->make('Indatus\Dispatcher\Commands\Run');
});
$this->commands($this->provides());
} | php | private function registerCommands()
{
//scheduled:summary
$this->app->bindShared('command.scheduled.summary', function (Application $app) {
return $app->make('Indatus\Dispatcher\Commands\ScheduleSummary');
});
//scheduled:make
$this->app->bindShared('command.scheduled.make', function (Application $app) {
return $app->make('Indatus\Dispatcher\Commands\Make');
});
//scheduled:run
$this->app->bindShared('command.scheduled.run', function (Application $app) {
return $app->make('Indatus\Dispatcher\Commands\Run');
});
$this->commands($this->provides());
} | [
"private",
"function",
"registerCommands",
"(",
")",
"{",
"//scheduled:summary",
"$",
"this",
"->",
"app",
"->",
"bindShared",
"(",
"'command.scheduled.summary'",
",",
"function",
"(",
"Application",
"$",
"app",
")",
"{",
"return",
"$",
"app",
"->",
"make",
"(... | Register artisan commands
@codeCoverageIgnore | [
"Register",
"artisan",
"commands"
] | train | https://github.com/Indatus/dispatcher/blob/9548ab90d0c1e9a2ff7239f28e470de4493c00ff/src/Indatus/Dispatcher/ServiceProvider.php#L75-L93 |
lexik/LexikMaintenanceBundle | Command/DriverUnlockCommand.php | DriverUnlockCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
if (!$this->confirmUnlock($input, $output)) {
return;
}
$driver = $this->getContainer()->get('lexik_maintenance.driver.factory')->getDriver();
$unlockMessage = $driver->getMessageUnlock($driver->unlock());
$output->writeln('<info>'.$unlockMessage.'</info>');
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
if (!$this->confirmUnlock($input, $output)) {
return;
}
$driver = $this->getContainer()->get('lexik_maintenance.driver.factory')->getDriver();
$unlockMessage = $driver->getMessageUnlock($driver->unlock());
$output->writeln('<info>'.$unlockMessage.'</info>');
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"confirmUnlock",
"(",
"$",
"input",
",",
"$",
"output",
")",
")",
"{",
"return",
";",
"}",
"$",... | {@inheritdoc} | [
"{"
] | train | https://github.com/lexik/LexikMaintenanceBundle/blob/3a3e916776934a95834235e4a1d71e4595d515f5/Command/DriverUnlockCommand.php#L36-L47 |
lexik/LexikMaintenanceBundle | Command/DriverUnlockCommand.php | DriverUnlockCommand.askConfirmation | protected function askConfirmation($question, InputInterface $input, OutputInterface $output) {
if (!$this->getHelperSet()->has('question')) {
return $this->getHelper('dialog')
->askConfirmation($output, '<question>' . $question . '</question>', 'y');
}
return $this->getHelper('question')
->ask($input, $output, new \Symfony\Component\Console\Question\ConfirmationQuestion($question));
} | php | protected function askConfirmation($question, InputInterface $input, OutputInterface $output) {
if (!$this->getHelperSet()->has('question')) {
return $this->getHelper('dialog')
->askConfirmation($output, '<question>' . $question . '</question>', 'y');
}
return $this->getHelper('question')
->ask($input, $output, new \Symfony\Component\Console\Question\ConfirmationQuestion($question));
} | [
"protected",
"function",
"askConfirmation",
"(",
"$",
"question",
",",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getHelperSet",
"(",
")",
"->",
"has",
"(",
"'question'",
")",
")",
... | This method ensure that we stay compatible with symfony console 2.3 by using the deprecated dialog helper
but use the ConfirmationQuestion when available.
@param $question
@param InputInterface $input
@param OutputInterface $output
@return mixed | [
"This",
"method",
"ensure",
"that",
"we",
"stay",
"compatible",
"with",
"symfony",
"console",
"2",
".",
"3",
"by",
"using",
"the",
"deprecated",
"dialog",
"helper",
"but",
"use",
"the",
"ConfirmationQuestion",
"when",
"available",
"."
] | train | https://github.com/lexik/LexikMaintenanceBundle/blob/3a3e916776934a95834235e4a1d71e4595d515f5/Command/DriverUnlockCommand.php#L91-L99 |
lexik/LexikMaintenanceBundle | Drivers/DriverFactory.php | DriverFactory.getDriver | public function getDriver()
{
$class = $this->driverOptions['class'];
if (!class_exists($class)) {
throw new \ErrorException("Class '".$class."' not found in ".get_class($this));
}
if ($class === self::DATABASE_DRIVER) {
$driver = $this->dbDriver;
$driver->setOptions($this->driverOptions['options']);
} else {
$driver = new $class($this->driverOptions['options']);
}
$driver->setTranslator($this->translator);
return $driver;
} | php | public function getDriver()
{
$class = $this->driverOptions['class'];
if (!class_exists($class)) {
throw new \ErrorException("Class '".$class."' not found in ".get_class($this));
}
if ($class === self::DATABASE_DRIVER) {
$driver = $this->dbDriver;
$driver->setOptions($this->driverOptions['options']);
} else {
$driver = new $class($this->driverOptions['options']);
}
$driver->setTranslator($this->translator);
return $driver;
} | [
"public",
"function",
"getDriver",
"(",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"driverOptions",
"[",
"'class'",
"]",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"throw",
"new",
"\\",
"ErrorException",
"(",
"\"Class '... | Return the driver
@return mixed
@throws \ErrorException | [
"Return",
"the",
"driver"
] | train | https://github.com/lexik/LexikMaintenanceBundle/blob/3a3e916776934a95834235e4a1d71e4595d515f5/Drivers/DriverFactory.php#L60-L78 |
lexik/LexikMaintenanceBundle | DependencyInjection/Configuration.php | Configuration.getConfigTreeBuilder | public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('lexik_maintenance');
$rootNode
->addDefaultsIfNotSet()
->children()
->arrayNode('authorized')
->addDefaultsIfNotSet()
->children()
->scalarNode('path')
->defaultNull()
->end()
->scalarNode('host')
->defaultNull()
->end()
->variableNode('ips')
->defaultNull()
->end()
->variableNode('query')
->defaultValue(array())
->end()
->variableNode('cookie')
->defaultValue(array())
->end()
->scalarNode('route')
->defaultNull()
->end()
->variableNode('attributes')
->defaultValue(array())
->end()
->end()
->end()
->arrayNode('driver')
->addDefaultsIfNotSet()
->children()
->scalarNode('class')
->defaultNull()
->end()
->integerNode('ttl')
->defaultNull()
->end()
->variableNode('options')
->defaultValue(array())
->end()
->end()
->end()
->arrayNode('response')
->addDefaultsIfNotSet()
->children()
->integerNode('code')
->defaultValue( 503 )
->end()
->scalarNode('status')
->defaultValue('Service Temporarily Unavailable')
->end()
->scalarNode('exception_message')
->defaultValue('Service Temporarily Unavailable')
->end()
->end()
->end()
->end();
return $treeBuilder;
} | php | public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('lexik_maintenance');
$rootNode
->addDefaultsIfNotSet()
->children()
->arrayNode('authorized')
->addDefaultsIfNotSet()
->children()
->scalarNode('path')
->defaultNull()
->end()
->scalarNode('host')
->defaultNull()
->end()
->variableNode('ips')
->defaultNull()
->end()
->variableNode('query')
->defaultValue(array())
->end()
->variableNode('cookie')
->defaultValue(array())
->end()
->scalarNode('route')
->defaultNull()
->end()
->variableNode('attributes')
->defaultValue(array())
->end()
->end()
->end()
->arrayNode('driver')
->addDefaultsIfNotSet()
->children()
->scalarNode('class')
->defaultNull()
->end()
->integerNode('ttl')
->defaultNull()
->end()
->variableNode('options')
->defaultValue(array())
->end()
->end()
->end()
->arrayNode('response')
->addDefaultsIfNotSet()
->children()
->integerNode('code')
->defaultValue( 503 )
->end()
->scalarNode('status')
->defaultValue('Service Temporarily Unavailable')
->end()
->scalarNode('exception_message')
->defaultValue('Service Temporarily Unavailable')
->end()
->end()
->end()
->end();
return $treeBuilder;
} | [
"public",
"function",
"getConfigTreeBuilder",
"(",
")",
"{",
"$",
"treeBuilder",
"=",
"new",
"TreeBuilder",
"(",
")",
";",
"$",
"rootNode",
"=",
"$",
"treeBuilder",
"->",
"root",
"(",
"'lexik_maintenance'",
")",
";",
"$",
"rootNode",
"->",
"addDefaultsIfNotSet... | {@inheritDoc} | [
"{"
] | train | https://github.com/lexik/LexikMaintenanceBundle/blob/3a3e916776934a95834235e4a1d71e4595d515f5/DependencyInjection/Configuration.php#L21-L86 |
lexik/LexikMaintenanceBundle | Listener/MaintenanceListener.php | MaintenanceListener.onKernelRequest | public function onKernelRequest(GetResponseEvent $event)
{
if(!$event->isMasterRequest()){
return;
}
$request = $event->getRequest();
if (is_array($this->query)) {
foreach ($this->query as $key => $pattern) {
if (!empty($pattern) && preg_match('{'.$pattern.'}', $request->get($key))) {
return;
}
}
}
if (is_array($this->cookie)) {
foreach ($this->cookie as $key => $pattern) {
if (!empty($pattern) && preg_match('{'.$pattern.'}', $request->cookies->get($key))) {
return;
}
}
}
if (is_array($this->attributes)) {
foreach ($this->attributes as $key => $pattern) {
if (!empty($pattern) && preg_match('{'.$pattern.'}', $request->attributes->get($key))) {
return;
}
}
}
if (null !== $this->path && !empty($this->path) && preg_match('{'.$this->path.'}', rawurldecode($request->getPathInfo()))) {
return;
}
if (null !== $this->host && !empty($this->host) && preg_match('{'.$this->host.'}i', $request->getHost())) {
return;
}
if (count((array) $this->ips) !== 0 && $this->checkIps($request->getClientIp(), $this->ips)) {
return;
}
$route = $request->get('_route');
if (null !== $this->route && preg_match('{'.$this->route.'}', $route) || (true === $this->debug && '_' === $route[0])) {
return;
}
// Get driver class defined in your configuration
$driver = $this->driverFactory->getDriver();
if ($driver->decide() && HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
$this->handleResponse = true;
throw new ServiceUnavailableException($this->http_exception_message);
}
} | php | public function onKernelRequest(GetResponseEvent $event)
{
if(!$event->isMasterRequest()){
return;
}
$request = $event->getRequest();
if (is_array($this->query)) {
foreach ($this->query as $key => $pattern) {
if (!empty($pattern) && preg_match('{'.$pattern.'}', $request->get($key))) {
return;
}
}
}
if (is_array($this->cookie)) {
foreach ($this->cookie as $key => $pattern) {
if (!empty($pattern) && preg_match('{'.$pattern.'}', $request->cookies->get($key))) {
return;
}
}
}
if (is_array($this->attributes)) {
foreach ($this->attributes as $key => $pattern) {
if (!empty($pattern) && preg_match('{'.$pattern.'}', $request->attributes->get($key))) {
return;
}
}
}
if (null !== $this->path && !empty($this->path) && preg_match('{'.$this->path.'}', rawurldecode($request->getPathInfo()))) {
return;
}
if (null !== $this->host && !empty($this->host) && preg_match('{'.$this->host.'}i', $request->getHost())) {
return;
}
if (count((array) $this->ips) !== 0 && $this->checkIps($request->getClientIp(), $this->ips)) {
return;
}
$route = $request->get('_route');
if (null !== $this->route && preg_match('{'.$this->route.'}', $route) || (true === $this->debug && '_' === $route[0])) {
return;
}
// Get driver class defined in your configuration
$driver = $this->driverFactory->getDriver();
if ($driver->decide() && HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
$this->handleResponse = true;
throw new ServiceUnavailableException($this->http_exception_message);
}
} | [
"public",
"function",
"onKernelRequest",
"(",
"GetResponseEvent",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"$",
"event",
"->",
"isMasterRequest",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"request",
"=",
"$",
"event",
"->",
"getRequest",
"(",
")",
";... | @param GetResponseEvent $event GetResponseEvent
@return void
@throws ServiceUnavailableException | [
"@param",
"GetResponseEvent",
"$event",
"GetResponseEvent"
] | train | https://github.com/lexik/LexikMaintenanceBundle/blob/3a3e916776934a95834235e4a1d71e4595d515f5/Listener/MaintenanceListener.php#L152-L208 |
lexik/LexikMaintenanceBundle | Listener/MaintenanceListener.php | MaintenanceListener.onKernelResponse | public function onKernelResponse(FilterResponseEvent $event)
{
if ($this->handleResponse && $this->http_code !== null) {
$response = $event->getResponse();
$response->setStatusCode($this->http_code, $this->http_status);
}
} | php | public function onKernelResponse(FilterResponseEvent $event)
{
if ($this->handleResponse && $this->http_code !== null) {
$response = $event->getResponse();
$response->setStatusCode($this->http_code, $this->http_status);
}
} | [
"public",
"function",
"onKernelResponse",
"(",
"FilterResponseEvent",
"$",
"event",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"handleResponse",
"&&",
"$",
"this",
"->",
"http_code",
"!==",
"null",
")",
"{",
"$",
"response",
"=",
"$",
"event",
"->",
"getRespo... | Rewrites the http code of the response
@param FilterResponseEvent $event FilterResponseEvent
@return void | [
"Rewrites",
"the",
"http",
"code",
"of",
"the",
"response"
] | train | https://github.com/lexik/LexikMaintenanceBundle/blob/3a3e916776934a95834235e4a1d71e4595d515f5/Listener/MaintenanceListener.php#L216-L222 |
lexik/LexikMaintenanceBundle | Listener/MaintenanceListener.php | MaintenanceListener.checkIps | protected function checkIps($requestedIp, $ips)
{
$ips = (array) $ips;
$valid = false;
$i = 0;
while ($i<count($ips) && !$valid) {
$valid = IpUtils::checkIp($requestedIp, $ips[$i]);
$i++;
}
return $valid;
} | php | protected function checkIps($requestedIp, $ips)
{
$ips = (array) $ips;
$valid = false;
$i = 0;
while ($i<count($ips) && !$valid) {
$valid = IpUtils::checkIp($requestedIp, $ips[$i]);
$i++;
}
return $valid;
} | [
"protected",
"function",
"checkIps",
"(",
"$",
"requestedIp",
",",
"$",
"ips",
")",
"{",
"$",
"ips",
"=",
"(",
"array",
")",
"$",
"ips",
";",
"$",
"valid",
"=",
"false",
";",
"$",
"i",
"=",
"0",
";",
"while",
"(",
"$",
"i",
"<",
"count",
"(",
... | Checks if the requested ip is valid.
@param string $requestedIp
@param string|array $ips
@return boolean | [
"Checks",
"if",
"the",
"requested",
"ip",
"is",
"valid",
"."
] | train | https://github.com/lexik/LexikMaintenanceBundle/blob/3a3e916776934a95834235e4a1d71e4595d515f5/Listener/MaintenanceListener.php#L231-L244 |
lexik/LexikMaintenanceBundle | Drivers/ShmDriver.php | ShmDriver.createLock | protected function createLock()
{
if ($this->shmId) {
return shm_put_var($this->shmId, self::VARIABLE_KEY, self::VALUE_TO_STORE);
}
return false;
} | php | protected function createLock()
{
if ($this->shmId) {
return shm_put_var($this->shmId, self::VARIABLE_KEY, self::VALUE_TO_STORE);
}
return false;
} | [
"protected",
"function",
"createLock",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"shmId",
")",
"{",
"return",
"shm_put_var",
"(",
"$",
"this",
"->",
"shmId",
",",
"self",
"::",
"VARIABLE_KEY",
",",
"self",
"::",
"VALUE_TO_STORE",
")",
";",
"}",
"ret... | {@inheritdoc} | [
"{"
] | train | https://github.com/lexik/LexikMaintenanceBundle/blob/3a3e916776934a95834235e4a1d71e4595d515f5/Drivers/ShmDriver.php#L73-L80 |
lexik/LexikMaintenanceBundle | Drivers/ShmDriver.php | ShmDriver.isExists | public function isExists()
{
if ($this->shmId) {
if (!shm_has_var($this->shmId, self::VARIABLE_KEY) ) {
return false;
}
$data = shm_get_var($this->shmId, self::VARIABLE_KEY);
return ($data == self::VALUE_TO_STORE);
}
return false;
} | php | public function isExists()
{
if ($this->shmId) {
if (!shm_has_var($this->shmId, self::VARIABLE_KEY) ) {
return false;
}
$data = shm_get_var($this->shmId, self::VARIABLE_KEY);
return ($data == self::VALUE_TO_STORE);
}
return false;
} | [
"public",
"function",
"isExists",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"shmId",
")",
"{",
"if",
"(",
"!",
"shm_has_var",
"(",
"$",
"this",
"->",
"shmId",
",",
"self",
"::",
"VARIABLE_KEY",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
... | {@inheritdoc} | [
"{"
] | train | https://github.com/lexik/LexikMaintenanceBundle/blob/3a3e916776934a95834235e4a1d71e4595d515f5/Drivers/ShmDriver.php#L97-L108 |
lexik/LexikMaintenanceBundle | DependencyInjection/LexikMaintenanceExtension.php | LexikMaintenanceExtension.registerDsnConfiguration | protected function registerDsnConfiguration($options)
{
if ( ! isset($options['table'])) {
throw new InvalidArgumentException('You need to define table for dsn use');
}
if ( ! isset($options['user'])) {
throw new InvalidArgumentException('You need to define user for dsn use');
}
if ( ! isset($options['password'])) {
throw new InvalidArgumentException('You need to define password for dsn use');
}
} | php | protected function registerDsnConfiguration($options)
{
if ( ! isset($options['table'])) {
throw new InvalidArgumentException('You need to define table for dsn use');
}
if ( ! isset($options['user'])) {
throw new InvalidArgumentException('You need to define user for dsn use');
}
if ( ! isset($options['password'])) {
throw new InvalidArgumentException('You need to define password for dsn use');
}
} | [
"protected",
"function",
"registerDsnConfiguration",
"(",
"$",
"options",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'table'",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'You need to define table for dsn use'",
")",
... | Load dsn configuration
@param array $options A configuration array
@throws InvalidArgumentException | [
"Load",
"dsn",
"configuration"
] | train | https://github.com/lexik/LexikMaintenanceBundle/blob/3a3e916776934a95834235e4a1d71e4595d515f5/DependencyInjection/LexikMaintenanceExtension.php#L62-L75 |
lexik/LexikMaintenanceBundle | Drivers/DatabaseDriver.php | DatabaseDriver.setOptions | public function setOptions($options)
{
$this->options = $options;
if (isset($this->options['dsn'])) {
$this->pdoDriver = new DsnQuery($this->options);
} else {
if (isset($this->options['connection'])) {
$this->pdoDriver = new DefaultQuery($this->doctrine->getManager($this->options['connection']));
} else {
$this->pdoDriver = new DefaultQuery($this->doctrine->getManager());
}
}
} | php | public function setOptions($options)
{
$this->options = $options;
if (isset($this->options['dsn'])) {
$this->pdoDriver = new DsnQuery($this->options);
} else {
if (isset($this->options['connection'])) {
$this->pdoDriver = new DefaultQuery($this->doctrine->getManager($this->options['connection']));
} else {
$this->pdoDriver = new DefaultQuery($this->doctrine->getManager());
}
}
} | [
"public",
"function",
"setOptions",
"(",
"$",
"options",
")",
"{",
"$",
"this",
"->",
"options",
"=",
"$",
"options",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'dsn'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"pdoDriver",
"=",... | Set options from configuration
@param array $options Options | [
"Set",
"options",
"from",
"configuration"
] | train | https://github.com/lexik/LexikMaintenanceBundle/blob/3a3e916776934a95834235e4a1d71e4595d515f5/Drivers/DatabaseDriver.php#L53-L66 |
lexik/LexikMaintenanceBundle | Drivers/DatabaseDriver.php | DatabaseDriver.createLock | protected function createLock()
{
$db = $this->pdoDriver->initDb();
try {
$ttl = null;
if (isset($this->options['ttl']) && $this->options['ttl'] !== 0) {
$now = new \Datetime('now');
$ttl = $this->options['ttl'];
$ttl = $now->modify(sprintf('+%s seconds', $ttl))->format('Y-m-d H:i:s');
}
$status = $this->pdoDriver->insertQuery($ttl, $db);
} catch (\Exception $e) {
$status = false;
}
return $status;
} | php | protected function createLock()
{
$db = $this->pdoDriver->initDb();
try {
$ttl = null;
if (isset($this->options['ttl']) && $this->options['ttl'] !== 0) {
$now = new \Datetime('now');
$ttl = $this->options['ttl'];
$ttl = $now->modify(sprintf('+%s seconds', $ttl))->format('Y-m-d H:i:s');
}
$status = $this->pdoDriver->insertQuery($ttl, $db);
} catch (\Exception $e) {
$status = false;
}
return $status;
} | [
"protected",
"function",
"createLock",
"(",
")",
"{",
"$",
"db",
"=",
"$",
"this",
"->",
"pdoDriver",
"->",
"initDb",
"(",
")",
";",
"try",
"{",
"$",
"ttl",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'ttl'",
"]... | {@inheritdoc} | [
"{"
] | train | https://github.com/lexik/LexikMaintenanceBundle/blob/3a3e916776934a95834235e4a1d71e4595d515f5/Drivers/DatabaseDriver.php#L71-L88 |
lexik/LexikMaintenanceBundle | Drivers/DatabaseDriver.php | DatabaseDriver.createUnlock | protected function createUnlock()
{
$db = $this->pdoDriver->initDb();
try {
$status = $this->pdoDriver->deleteQuery($db);
} catch (\Exception $e) {
$status = false;
}
return $status;
} | php | protected function createUnlock()
{
$db = $this->pdoDriver->initDb();
try {
$status = $this->pdoDriver->deleteQuery($db);
} catch (\Exception $e) {
$status = false;
}
return $status;
} | [
"protected",
"function",
"createUnlock",
"(",
")",
"{",
"$",
"db",
"=",
"$",
"this",
"->",
"pdoDriver",
"->",
"initDb",
"(",
")",
";",
"try",
"{",
"$",
"status",
"=",
"$",
"this",
"->",
"pdoDriver",
"->",
"deleteQuery",
"(",
"$",
"db",
")",
";",
"}... | {@inheritdoc} | [
"{"
] | train | https://github.com/lexik/LexikMaintenanceBundle/blob/3a3e916776934a95834235e4a1d71e4595d515f5/Drivers/DatabaseDriver.php#L93-L104 |
lexik/LexikMaintenanceBundle | Drivers/DatabaseDriver.php | DatabaseDriver.isExists | public function isExists()
{
$db = $this->pdoDriver->initDb();
$data = $this->pdoDriver->selectQuery($db);
if (!$data) {
return null;
}
if (null !== $data[0]['ttl']) {
$now = new \DateTime('now');
$ttl = new \DateTime($data[0]['ttl']);
if ($ttl < $now) {
return $this->createUnlock();
}
}
return true;
} | php | public function isExists()
{
$db = $this->pdoDriver->initDb();
$data = $this->pdoDriver->selectQuery($db);
if (!$data) {
return null;
}
if (null !== $data[0]['ttl']) {
$now = new \DateTime('now');
$ttl = new \DateTime($data[0]['ttl']);
if ($ttl < $now) {
return $this->createUnlock();
}
}
return true;
} | [
"public",
"function",
"isExists",
"(",
")",
"{",
"$",
"db",
"=",
"$",
"this",
"->",
"pdoDriver",
"->",
"initDb",
"(",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"pdoDriver",
"->",
"selectQuery",
"(",
"$",
"db",
")",
";",
"if",
"(",
"!",
"$",
... | {@inheritdoc} | [
"{"
] | train | https://github.com/lexik/LexikMaintenanceBundle/blob/3a3e916776934a95834235e4a1d71e4595d515f5/Drivers/DatabaseDriver.php#L109-L128 |
lexik/LexikMaintenanceBundle | Command/DriverLockCommand.php | DriverLockCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
$driver = $this->getDriver();
if ($input->isInteractive()) {
if (!$this->askConfirmation('WARNING! Are you sure you wish to continue? (y/n)', $input, $output)) {
$output->writeln('<error>Maintenance cancelled!</error>');
return;
}
} elseif (null !== $input->getArgument('ttl')) {
$this->ttl = $input->getArgument('ttl');
} elseif ($driver instanceof DriverTtlInterface) {
$this->ttl = $driver->getTtl();
}
// set ttl from command line if given and driver supports it
if ($driver instanceof DriverTtlInterface) {
$driver->setTtl($this->ttl);
}
$output->writeln('<info>'.$driver->getMessageLock($driver->lock()).'</info>');
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
$driver = $this->getDriver();
if ($input->isInteractive()) {
if (!$this->askConfirmation('WARNING! Are you sure you wish to continue? (y/n)', $input, $output)) {
$output->writeln('<error>Maintenance cancelled!</error>');
return;
}
} elseif (null !== $input->getArgument('ttl')) {
$this->ttl = $input->getArgument('ttl');
} elseif ($driver instanceof DriverTtlInterface) {
$this->ttl = $driver->getTtl();
}
// set ttl from command line if given and driver supports it
if ($driver instanceof DriverTtlInterface) {
$driver->setTtl($this->ttl);
}
$output->writeln('<info>'.$driver->getMessageLock($driver->lock()).'</info>');
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"driver",
"=",
"$",
"this",
"->",
"getDriver",
"(",
")",
";",
"if",
"(",
"$",
"input",
"->",
"isInteractive",
"(",
")",
")",
... | {@inheritdoc} | [
"{"
] | train | https://github.com/lexik/LexikMaintenanceBundle/blob/3a3e916776934a95834235e4a1d71e4595d515f5/Command/DriverLockCommand.php#L52-L73 |
lexik/LexikMaintenanceBundle | Command/DriverLockCommand.php | DriverLockCommand.interact | protected function interact(InputInterface $input, OutputInterface $output)
{
$driver = $this->getDriver();
$default = $driver->getOptions();
$formatter = $this->getHelperSet()->get('formatter');
if (null !== $input->getArgument('ttl') && !is_numeric($input->getArgument('ttl'))) {
throw new \InvalidArgumentException('Time must be an integer');
}
$output->writeln(array(
'',
$formatter->formatBlock('You are about to launch maintenance', 'bg=red;fg=white', true),
'',
));
$ttl = null;
if ($driver instanceof DriverTtlInterface) {
if (null === $input->getArgument('ttl')) {
$output->writeln(array(
'',
'Do you want to redefine maintenance life time ?',
'If yes enter the number of seconds. Press enter to continue',
'',
));
$ttl = $this->askAndValidate(
$input,
$output,
sprintf('<info>%s</info> [<comment>Default value in your configuration: %s</comment>]%s ', 'Set time', $driver->hasTtl() ? $driver->getTtl() : 'unlimited', ':'),
function($value) use ($default) {
if (!is_numeric($value) && null === $default) {
return null;
} elseif (!is_numeric($value)) {
throw new \InvalidArgumentException('Time must be an integer');
}
return $value;
},
1,
isset($default['ttl']) ? $default['ttl'] : 0
);
}
$ttl = (int) $ttl;
$this->ttl = $ttl ? $ttl : $input->getArgument('ttl');
} else {
$output->writeln(array(
'',
sprintf('<fg=red>Ttl doesn\'t work with %s driver</>', get_class($driver)),
'',
));
}
} | php | protected function interact(InputInterface $input, OutputInterface $output)
{
$driver = $this->getDriver();
$default = $driver->getOptions();
$formatter = $this->getHelperSet()->get('formatter');
if (null !== $input->getArgument('ttl') && !is_numeric($input->getArgument('ttl'))) {
throw new \InvalidArgumentException('Time must be an integer');
}
$output->writeln(array(
'',
$formatter->formatBlock('You are about to launch maintenance', 'bg=red;fg=white', true),
'',
));
$ttl = null;
if ($driver instanceof DriverTtlInterface) {
if (null === $input->getArgument('ttl')) {
$output->writeln(array(
'',
'Do you want to redefine maintenance life time ?',
'If yes enter the number of seconds. Press enter to continue',
'',
));
$ttl = $this->askAndValidate(
$input,
$output,
sprintf('<info>%s</info> [<comment>Default value in your configuration: %s</comment>]%s ', 'Set time', $driver->hasTtl() ? $driver->getTtl() : 'unlimited', ':'),
function($value) use ($default) {
if (!is_numeric($value) && null === $default) {
return null;
} elseif (!is_numeric($value)) {
throw new \InvalidArgumentException('Time must be an integer');
}
return $value;
},
1,
isset($default['ttl']) ? $default['ttl'] : 0
);
}
$ttl = (int) $ttl;
$this->ttl = $ttl ? $ttl : $input->getArgument('ttl');
} else {
$output->writeln(array(
'',
sprintf('<fg=red>Ttl doesn\'t work with %s driver</>', get_class($driver)),
'',
));
}
} | [
"protected",
"function",
"interact",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"driver",
"=",
"$",
"this",
"->",
"getDriver",
"(",
")",
";",
"$",
"default",
"=",
"$",
"driver",
"->",
"getOptions",
"(",
")"... | {@inheritdoc} | [
"{"
] | train | https://github.com/lexik/LexikMaintenanceBundle/blob/3a3e916776934a95834235e4a1d71e4595d515f5/Command/DriverLockCommand.php#L78-L131 |
lexik/LexikMaintenanceBundle | Command/DriverLockCommand.php | DriverLockCommand.askAndValidate | protected function askAndValidate(InputInterface $input, OutputInterface $output, $question, $validator, $attempts = 1, $default = null) {
if (!$this->getHelperSet()->has('question')) {
return $this->getHelper('dialog')
->askAndValidate($output, $question, $validator, $attempts, $default);
}
$question = new \Symfony\Component\Console\Question\Question($question, $default);
$question->setValidator($validator);
$question->setMaxAttempts($attempts);
return $this->getHelper('question')
->ask($input, $output, $question);
} | php | protected function askAndValidate(InputInterface $input, OutputInterface $output, $question, $validator, $attempts = 1, $default = null) {
if (!$this->getHelperSet()->has('question')) {
return $this->getHelper('dialog')
->askAndValidate($output, $question, $validator, $attempts, $default);
}
$question = new \Symfony\Component\Console\Question\Question($question, $default);
$question->setValidator($validator);
$question->setMaxAttempts($attempts);
return $this->getHelper('question')
->ask($input, $output, $question);
} | [
"protected",
"function",
"askAndValidate",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
",",
"$",
"question",
",",
"$",
"validator",
",",
"$",
"attempts",
"=",
"1",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"!"... | This method ensure that we stay compatible with symfony console 2.3 by using the deprecated dialog helper
but use the ConfirmationQuestion when available.
@param InputInterface $input
@param OutputInterface $output
@param $question
@param $validator
@param int $attempts
@param null $default
@return mixed | [
"This",
"method",
"ensure",
"that",
"we",
"stay",
"compatible",
"with",
"symfony",
"console",
"2",
".",
"3",
"by",
"using",
"the",
"deprecated",
"dialog",
"helper",
"but",
"use",
"the",
"ConfirmationQuestion",
"when",
"available",
"."
] | train | https://github.com/lexik/LexikMaintenanceBundle/blob/3a3e916776934a95834235e4a1d71e4595d515f5/Command/DriverLockCommand.php#L174-L186 |
lexik/LexikMaintenanceBundle | Drivers/MemCacheDriver.php | MemCacheDriver.createLock | protected function createLock()
{
return $this->memcacheInstance->set($this->keyName, self::VALUE_TO_STORE, false, (isset($this->options['ttl']) ? $this->options['ttl'] : 0));
} | php | protected function createLock()
{
return $this->memcacheInstance->set($this->keyName, self::VALUE_TO_STORE, false, (isset($this->options['ttl']) ? $this->options['ttl'] : 0));
} | [
"protected",
"function",
"createLock",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"memcacheInstance",
"->",
"set",
"(",
"$",
"this",
"->",
"keyName",
",",
"self",
"::",
"VALUE_TO_STORE",
",",
"false",
",",
"(",
"isset",
"(",
"$",
"this",
"->",
"options"... | {@inheritdoc} | [
"{"
] | train | https://github.com/lexik/LexikMaintenanceBundle/blob/3a3e916776934a95834235e4a1d71e4595d515f5/Drivers/MemCacheDriver.php#L69-L72 |
lexik/LexikMaintenanceBundle | Drivers/FileDriver.php | FileDriver.isExists | public function isExists()
{
if (file_exists($this->filePath)) {
if (isset($this->options['ttl']) && is_numeric($this->options['ttl'])) {
$this->isEndTime($this->options['ttl']);
}
return true;
} else {
return false;
}
} | php | public function isExists()
{
if (file_exists($this->filePath)) {
if (isset($this->options['ttl']) && is_numeric($this->options['ttl'])) {
$this->isEndTime($this->options['ttl']);
}
return true;
} else {
return false;
}
} | [
"public",
"function",
"isExists",
"(",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"filePath",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'ttl'",
"]",
")",
"&&",
"is_numeric",
"(",
"$",
"this",
"->",... | {@inheritDoc} | [
"{"
] | train | https://github.com/lexik/LexikMaintenanceBundle/blob/3a3e916776934a95834235e4a1d71e4595d515f5/Drivers/FileDriver.php#L47-L57 |
lexik/LexikMaintenanceBundle | Drivers/FileDriver.php | FileDriver.isEndTime | public function isEndTime($timeTtl)
{
$now = new \DateTime('now');
$accessTime = date("Y-m-d H:i:s.", filemtime($this->filePath));
$accessTime = new \DateTime($accessTime);
$accessTime->modify(sprintf('+%s seconds', $timeTtl));
if ($accessTime < $now) {
return $this->createUnlock();
} else {
return true;
}
} | php | public function isEndTime($timeTtl)
{
$now = new \DateTime('now');
$accessTime = date("Y-m-d H:i:s.", filemtime($this->filePath));
$accessTime = new \DateTime($accessTime);
$accessTime->modify(sprintf('+%s seconds', $timeTtl));
if ($accessTime < $now) {
return $this->createUnlock();
} else {
return true;
}
} | [
"public",
"function",
"isEndTime",
"(",
"$",
"timeTtl",
")",
"{",
"$",
"now",
"=",
"new",
"\\",
"DateTime",
"(",
"'now'",
")",
";",
"$",
"accessTime",
"=",
"date",
"(",
"\"Y-m-d H:i:s.\"",
",",
"filemtime",
"(",
"$",
"this",
"->",
"filePath",
")",
")",... | Test if time to life is expired
@param integer $timeTtl The ttl value
@return boolean | [
"Test",
"if",
"time",
"to",
"life",
"is",
"expired"
] | train | https://github.com/lexik/LexikMaintenanceBundle/blob/3a3e916776934a95834235e4a1d71e4595d515f5/Drivers/FileDriver.php#L66-L78 |
lexik/LexikMaintenanceBundle | Drivers/Query/PdoQuery.php | PdoQuery.prepareStatement | protected function prepareStatement($db, $query)
{
try {
$stmt = $db->prepare($query);
} catch (\Exception $e) {
$stmt = false;
}
if (false === $stmt) {
throw new \RuntimeException('The database cannot successfully prepare the statement');
}
return $stmt;
} | php | protected function prepareStatement($db, $query)
{
try {
$stmt = $db->prepare($query);
} catch (\Exception $e) {
$stmt = false;
}
if (false === $stmt) {
throw new \RuntimeException('The database cannot successfully prepare the statement');
}
return $stmt;
} | [
"protected",
"function",
"prepareStatement",
"(",
"$",
"db",
",",
"$",
"query",
")",
"{",
"try",
"{",
"$",
"stmt",
"=",
"$",
"db",
"->",
"prepare",
"(",
"$",
"query",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"stmt"... | PrepareStatement
@param \PDO $db PDO instance
@param string $query Query
@return Statement
@throws \RuntimeException | [
"PrepareStatement"
] | train | https://github.com/lexik/LexikMaintenanceBundle/blob/3a3e916776934a95834235e4a1d71e4595d515f5/Drivers/Query/PdoQuery.php#L115-L128 |
lexik/LexikMaintenanceBundle | Drivers/Query/DefaultQuery.php | DefaultQuery.initDb | public function initDb()
{
if (null === $this->db) {
$db = $this->em->getConnection();
$this->db = $db;
$this->createTableQuery();
}
return $this->db;
} | php | public function initDb()
{
if (null === $this->db) {
$db = $this->em->getConnection();
$this->db = $db;
$this->createTableQuery();
}
return $this->db;
} | [
"public",
"function",
"initDb",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"db",
")",
"{",
"$",
"db",
"=",
"$",
"this",
"->",
"em",
"->",
"getConnection",
"(",
")",
";",
"$",
"this",
"->",
"db",
"=",
"$",
"db",
";",
"$",
"thi... | {@inheritdoc} | [
"{"
] | train | https://github.com/lexik/LexikMaintenanceBundle/blob/3a3e916776934a95834235e4a1d71e4595d515f5/Drivers/Query/DefaultQuery.php#L33-L42 |
lexik/LexikMaintenanceBundle | Drivers/Query/DefaultQuery.php | DefaultQuery.createTableQuery | public function createTableQuery()
{
$type = $this->em->getConnection()->getDatabasePlatform()->getName() != 'mysql' ? 'timestamp' : 'datetime';
$this->db->exec(
sprintf('CREATE TABLE IF NOT EXISTS %s (ttl %s DEFAULT NULL)', self::NAME_TABLE, $type)
);
} | php | public function createTableQuery()
{
$type = $this->em->getConnection()->getDatabasePlatform()->getName() != 'mysql' ? 'timestamp' : 'datetime';
$this->db->exec(
sprintf('CREATE TABLE IF NOT EXISTS %s (ttl %s DEFAULT NULL)', self::NAME_TABLE, $type)
);
} | [
"public",
"function",
"createTableQuery",
"(",
")",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"em",
"->",
"getConnection",
"(",
")",
"->",
"getDatabasePlatform",
"(",
")",
"->",
"getName",
"(",
")",
"!=",
"'mysql'",
"?",
"'timestamp'",
":",
"'datetime'",
... | {@inheritdoc} | [
"{"
] | train | https://github.com/lexik/LexikMaintenanceBundle/blob/3a3e916776934a95834235e4a1d71e4595d515f5/Drivers/Query/DefaultQuery.php#L47-L54 |
lexik/LexikMaintenanceBundle | Drivers/Query/DefaultQuery.php | DefaultQuery.insertQuery | public function insertQuery($ttl, $db)
{
return $this->exec(
$db, sprintf('INSERT INTO %s (ttl) VALUES (:ttl)',
self::NAME_TABLE),
array(':ttl' => $ttl)
);
} | php | public function insertQuery($ttl, $db)
{
return $this->exec(
$db, sprintf('INSERT INTO %s (ttl) VALUES (:ttl)',
self::NAME_TABLE),
array(':ttl' => $ttl)
);
} | [
"public",
"function",
"insertQuery",
"(",
"$",
"ttl",
",",
"$",
"db",
")",
"{",
"return",
"$",
"this",
"->",
"exec",
"(",
"$",
"db",
",",
"sprintf",
"(",
"'INSERT INTO %s (ttl) VALUES (:ttl)'",
",",
"self",
"::",
"NAME_TABLE",
")",
",",
"array",
"(",
"':... | {@inheritdoc} | [
"{"
] | train | https://github.com/lexik/LexikMaintenanceBundle/blob/3a3e916776934a95834235e4a1d71e4595d515f5/Drivers/Query/DefaultQuery.php#L75-L82 |
lexik/LexikMaintenanceBundle | Drivers/Query/DsnQuery.php | DsnQuery.initDb | public function initDb()
{
if (null === $this->db) {
if (!class_exists('PDO') || !in_array('mysql', \PDO::getAvailableDrivers(), true)) {
throw new \RuntimeException('You need to enable PDO_Mysql extension for the profiler to run properly.');
}
$db = new \PDO($this->options['dsn'], $this->options['user'], $this->options['password']);
$this->db = $db;
$this->createTableQuery();
}
return $this->db;
} | php | public function initDb()
{
if (null === $this->db) {
if (!class_exists('PDO') || !in_array('mysql', \PDO::getAvailableDrivers(), true)) {
throw new \RuntimeException('You need to enable PDO_Mysql extension for the profiler to run properly.');
}
$db = new \PDO($this->options['dsn'], $this->options['user'], $this->options['password']);
$this->db = $db;
$this->createTableQuery();
}
return $this->db;
} | [
"public",
"function",
"initDb",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"db",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"'PDO'",
")",
"||",
"!",
"in_array",
"(",
"'mysql'",
",",
"\\",
"PDO",
"::",
"getAvailableDrivers",
"(",
... | {@inheritdoc} | [
"{"
] | train | https://github.com/lexik/LexikMaintenanceBundle/blob/3a3e916776934a95834235e4a1d71e4595d515f5/Drivers/Query/DsnQuery.php#L18-L32 |
lexik/LexikMaintenanceBundle | Drivers/Query/DsnQuery.php | DsnQuery.createTableQuery | public function createTableQuery()
{
$type = $this->db->getAttribute(\PDO::ATTR_DRIVER_NAME) != 'mysql' ? 'timestamp' : 'datetime';
$this->db->exec(sprintf('CREATE TABLE IF NOT EXISTS %s (ttl %s DEFAULT NULL)', $this->options['table'], $type));
} | php | public function createTableQuery()
{
$type = $this->db->getAttribute(\PDO::ATTR_DRIVER_NAME) != 'mysql' ? 'timestamp' : 'datetime';
$this->db->exec(sprintf('CREATE TABLE IF NOT EXISTS %s (ttl %s DEFAULT NULL)', $this->options['table'], $type));
} | [
"public",
"function",
"createTableQuery",
"(",
")",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"db",
"->",
"getAttribute",
"(",
"\\",
"PDO",
"::",
"ATTR_DRIVER_NAME",
")",
"!=",
"'mysql'",
"?",
"'timestamp'",
":",
"'datetime'",
";",
"$",
"this",
"->",
"db... | {@inheritdoc} | [
"{"
] | train | https://github.com/lexik/LexikMaintenanceBundle/blob/3a3e916776934a95834235e4a1d71e4595d515f5/Drivers/Query/DsnQuery.php#L37-L42 |
lexik/LexikMaintenanceBundle | Drivers/Query/DsnQuery.php | DsnQuery.insertQuery | public function insertQuery($ttl, $db)
{
return $this->exec(
$db,
sprintf('INSERT INTO %s (ttl) VALUES (:ttl)',
$this->options['table']),
array(':ttl' => $ttl)
);
} | php | public function insertQuery($ttl, $db)
{
return $this->exec(
$db,
sprintf('INSERT INTO %s (ttl) VALUES (:ttl)',
$this->options['table']),
array(':ttl' => $ttl)
);
} | [
"public",
"function",
"insertQuery",
"(",
"$",
"ttl",
",",
"$",
"db",
")",
"{",
"return",
"$",
"this",
"->",
"exec",
"(",
"$",
"db",
",",
"sprintf",
"(",
"'INSERT INTO %s (ttl) VALUES (:ttl)'",
",",
"$",
"this",
"->",
"options",
"[",
"'table'",
"]",
")",... | {@inheritdoc} | [
"{"
] | train | https://github.com/lexik/LexikMaintenanceBundle/blob/3a3e916776934a95834235e4a1d71e4595d515f5/Drivers/Query/DsnQuery.php#L63-L71 |
borisrepl/boris | lib/Boris/EvalWorker.php | EvalWorker.setLocal | public function setLocal($local, $value = null)
{
if (!is_array($local)) {
$local = array(
$local => $value
);
}
$this->_exports = array_merge($this->_exports, $local);
} | php | public function setLocal($local, $value = null)
{
if (!is_array($local)) {
$local = array(
$local => $value
);
}
$this->_exports = array_merge($this->_exports, $local);
} | [
"public",
"function",
"setLocal",
"(",
"$",
"local",
",",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"local",
")",
")",
"{",
"$",
"local",
"=",
"array",
"(",
"$",
"local",
"=>",
"$",
"value",
")",
";",
"}",
"$",
... | Set local variables to be placed in the workers's scope.
@param array|string $local
@param mixed $value, if $local is a string | [
"Set",
"local",
"variables",
"to",
"be",
"placed",
"in",
"the",
"workers",
"s",
"scope",
"."
] | train | https://github.com/borisrepl/boris/blob/793a5f196bc47b93ed95c5dcdacee52c7b3536fc/lib/Boris/EvalWorker.php#L44-L53 |
borisrepl/boris | lib/Boris/EvalWorker.php | EvalWorker.start | public function start()
{
$__scope = $this->_runHooks($this->_startHooks);
extract($__scope);
$this->_write($this->_socket, self::READY);
/* Note the naming of the local variables due to shared scope with the user here */
for (;;) {
declare (ticks = 1);
// don't exit on ctrl-c
pcntl_signal(SIGINT, SIG_IGN, true);
$this->_cancelled = false;
$__input = $this->_transform($this->_read($this->_socket));
if ($__input === null) {
continue;
}
$__response = self::DONE;
$this->_ppid = posix_getpid();
$this->_pid = pcntl_fork();
if ($this->_pid < 0) {
throw new \RuntimeException('Failed to fork child labourer');
} elseif ($this->_pid > 0) {
// kill the child on ctrl-c
pcntl_signal(SIGINT, array(
$this,
'cancelOperation'
), true);
pcntl_waitpid($this->_pid, $__status);
if (!$this->_cancelled && $__status != (self::ABNORMAL_EXIT << 8)) {
$__response = self::EXITED;
} else {
$this->_runHooks($this->_failureHooks);
$__response = self::FAILED;
}
} else {
// if the user has installed a custom exception handler, install a new
// one which calls it and then (if the custom handler didn't already exit)
// exits with the correct status.
// If not, leave the exception handler unset; we'll display
// an uncaught exception error and carry on.
$__oldexh = set_exception_handler(array(
$this,
'delegateExceptionHandler'
));
if ($__oldexh && !$this->_userExceptionHandler) {
$this->_userExceptionHandler = $__oldexh; // save the old handler (once)
} else {
restore_exception_handler();
}
// undo ctrl-c signal handling ready for user code execution
pcntl_signal(SIGINT, SIG_DFL, true);
$__pid = posix_getpid();
$__result = eval($__input);
if (posix_getpid() != $__pid) {
// whatever the user entered caused a forked child
// (totally valid, but we don't want that child to loop and wait for input)
exit(0);
}
if (preg_match('/\s*return\b/i', $__input)) {
fwrite(STDOUT, sprintf("%s\n", $this->_inspector->inspect($__result)));
}
$this->_expungeOldWorker();
}
$this->_write($this->_socket, $__response);
if ($__response == self::EXITED) {
exit(0);
}
}
} | php | public function start()
{
$__scope = $this->_runHooks($this->_startHooks);
extract($__scope);
$this->_write($this->_socket, self::READY);
/* Note the naming of the local variables due to shared scope with the user here */
for (;;) {
declare (ticks = 1);
// don't exit on ctrl-c
pcntl_signal(SIGINT, SIG_IGN, true);
$this->_cancelled = false;
$__input = $this->_transform($this->_read($this->_socket));
if ($__input === null) {
continue;
}
$__response = self::DONE;
$this->_ppid = posix_getpid();
$this->_pid = pcntl_fork();
if ($this->_pid < 0) {
throw new \RuntimeException('Failed to fork child labourer');
} elseif ($this->_pid > 0) {
// kill the child on ctrl-c
pcntl_signal(SIGINT, array(
$this,
'cancelOperation'
), true);
pcntl_waitpid($this->_pid, $__status);
if (!$this->_cancelled && $__status != (self::ABNORMAL_EXIT << 8)) {
$__response = self::EXITED;
} else {
$this->_runHooks($this->_failureHooks);
$__response = self::FAILED;
}
} else {
// if the user has installed a custom exception handler, install a new
// one which calls it and then (if the custom handler didn't already exit)
// exits with the correct status.
// If not, leave the exception handler unset; we'll display
// an uncaught exception error and carry on.
$__oldexh = set_exception_handler(array(
$this,
'delegateExceptionHandler'
));
if ($__oldexh && !$this->_userExceptionHandler) {
$this->_userExceptionHandler = $__oldexh; // save the old handler (once)
} else {
restore_exception_handler();
}
// undo ctrl-c signal handling ready for user code execution
pcntl_signal(SIGINT, SIG_DFL, true);
$__pid = posix_getpid();
$__result = eval($__input);
if (posix_getpid() != $__pid) {
// whatever the user entered caused a forked child
// (totally valid, but we don't want that child to loop and wait for input)
exit(0);
}
if (preg_match('/\s*return\b/i', $__input)) {
fwrite(STDOUT, sprintf("%s\n", $this->_inspector->inspect($__result)));
}
$this->_expungeOldWorker();
}
$this->_write($this->_socket, $__response);
if ($__response == self::EXITED) {
exit(0);
}
}
} | [
"public",
"function",
"start",
"(",
")",
"{",
"$",
"__scope",
"=",
"$",
"this",
"->",
"_runHooks",
"(",
"$",
"this",
"->",
"_startHooks",
")",
";",
"extract",
"(",
"$",
"__scope",
")",
";",
"$",
"this",
"->",
"_write",
"(",
"$",
"this",
"->",
"_soc... | Start the worker.
This method never returns. | [
"Start",
"the",
"worker",
"."
] | train | https://github.com/borisrepl/boris/blob/793a5f196bc47b93ed95c5dcdacee52c7b3536fc/lib/Boris/EvalWorker.php#L90-L172 |
borisrepl/boris | lib/Boris/EvalWorker.php | EvalWorker.cancelOperation | public function cancelOperation()
{
printf("Cancelling...\n");
$this->_cancelled = true;
posix_kill($this->_pid, SIGKILL);
pcntl_signal_dispatch();
} | php | public function cancelOperation()
{
printf("Cancelling...\n");
$this->_cancelled = true;
posix_kill($this->_pid, SIGKILL);
pcntl_signal_dispatch();
} | [
"public",
"function",
"cancelOperation",
"(",
")",
"{",
"printf",
"(",
"\"Cancelling...\\n\"",
")",
";",
"$",
"this",
"->",
"_cancelled",
"=",
"true",
";",
"posix_kill",
"(",
"$",
"this",
"->",
"_pid",
",",
"SIGKILL",
")",
";",
"pcntl_signal_dispatch",
"(",
... | While a child process is running, terminate it immediately. | [
"While",
"a",
"child",
"process",
"is",
"running",
"terminate",
"it",
"immediately",
"."
] | train | https://github.com/borisrepl/boris/blob/793a5f196bc47b93ed95c5dcdacee52c7b3536fc/lib/Boris/EvalWorker.php#L177-L183 |
borisrepl/boris | lib/Boris/EvalWorker.php | EvalWorker._runHooks | private function _runHooks($hooks)
{
extract($this->_exports);
foreach ($hooks as $__hook) {
if (is_string($__hook)) {
eval($__hook);
} elseif (is_callable($__hook)) {
call_user_func($__hook, $this, get_defined_vars());
} else {
throw new \RuntimeException(sprintf('Hooks must be closures or strings of PHP code. Got [%s].', gettype($__hook)));
}
// hooks may set locals
extract($this->_exports);
}
return get_defined_vars();
} | php | private function _runHooks($hooks)
{
extract($this->_exports);
foreach ($hooks as $__hook) {
if (is_string($__hook)) {
eval($__hook);
} elseif (is_callable($__hook)) {
call_user_func($__hook, $this, get_defined_vars());
} else {
throw new \RuntimeException(sprintf('Hooks must be closures or strings of PHP code. Got [%s].', gettype($__hook)));
}
// hooks may set locals
extract($this->_exports);
}
return get_defined_vars();
} | [
"private",
"function",
"_runHooks",
"(",
"$",
"hooks",
")",
"{",
"extract",
"(",
"$",
"this",
"->",
"_exports",
")",
";",
"foreach",
"(",
"$",
"hooks",
"as",
"$",
"__hook",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"__hook",
")",
")",
"{",
"eval"... | -- Private Methods | [
"--",
"Private",
"Methods"
] | train | https://github.com/borisrepl/boris/blob/793a5f196bc47b93ed95c5dcdacee52c7b3536fc/lib/Boris/EvalWorker.php#L196-L214 |
borisrepl/boris | lib/Boris/ReadlineClient.php | ReadlineClient.start | public function start($prompt, $historyFile)
{
readline_read_history($historyFile);
declare (ticks = 1);
pcntl_signal(SIGCHLD, SIG_IGN);
pcntl_signal(SIGINT, array(
$this,
'clear'
), true);
// wait for the worker to finish executing hooks
if (fread($this->_socket, 1) != EvalWorker::READY) {
throw new \RuntimeException('EvalWorker failed to start');
}
$parser = new ShallowParser();
$buf = '';
$lineno = 1;
for (;;) {
$this->_clear = false;
$line = readline(sprintf('[%d] %s', $lineno, ($buf == '' ? $prompt : str_pad('*> ', strlen($prompt), ' ', STR_PAD_LEFT))));
if ($this->_clear) {
$buf = '';
continue;
}
if (false === $line) {
$buf = 'exit(0);'; // ctrl-d acts like exit
}
if (strlen($line) > 0) {
readline_add_history($line);
}
$buf .= sprintf("%s\n", $line);
if ($statements = $parser->statements($buf)) {
++$lineno;
$buf = '';
foreach ($statements as $stmt) {
if (false === $written = fwrite($this->_socket, $stmt)) {
throw new \RuntimeException('Socket error: failed to write data');
}
if ($written > 0) {
$status = fread($this->_socket, 1);
if ($status == EvalWorker::EXITED) {
readline_write_history($historyFile);
echo "\n";
exit(0);
} elseif ($status == EvalWorker::FAILED) {
break;
}
}
}
}
}
} | php | public function start($prompt, $historyFile)
{
readline_read_history($historyFile);
declare (ticks = 1);
pcntl_signal(SIGCHLD, SIG_IGN);
pcntl_signal(SIGINT, array(
$this,
'clear'
), true);
// wait for the worker to finish executing hooks
if (fread($this->_socket, 1) != EvalWorker::READY) {
throw new \RuntimeException('EvalWorker failed to start');
}
$parser = new ShallowParser();
$buf = '';
$lineno = 1;
for (;;) {
$this->_clear = false;
$line = readline(sprintf('[%d] %s', $lineno, ($buf == '' ? $prompt : str_pad('*> ', strlen($prompt), ' ', STR_PAD_LEFT))));
if ($this->_clear) {
$buf = '';
continue;
}
if (false === $line) {
$buf = 'exit(0);'; // ctrl-d acts like exit
}
if (strlen($line) > 0) {
readline_add_history($line);
}
$buf .= sprintf("%s\n", $line);
if ($statements = $parser->statements($buf)) {
++$lineno;
$buf = '';
foreach ($statements as $stmt) {
if (false === $written = fwrite($this->_socket, $stmt)) {
throw new \RuntimeException('Socket error: failed to write data');
}
if ($written > 0) {
$status = fread($this->_socket, 1);
if ($status == EvalWorker::EXITED) {
readline_write_history($historyFile);
echo "\n";
exit(0);
} elseif ($status == EvalWorker::FAILED) {
break;
}
}
}
}
}
} | [
"public",
"function",
"start",
"(",
"$",
"prompt",
",",
"$",
"historyFile",
")",
"{",
"readline_read_history",
"(",
"$",
"historyFile",
")",
";",
"declare",
"(",
"ticks",
"=",
"1",
")",
";",
"pcntl_signal",
"(",
"SIGCHLD",
",",
"SIG_IGN",
")",
";",
"pcnt... | Start the client with an prompt and readline history path.
This method never returns.
@param string $prompt
@param string $historyFile | [
"Start",
"the",
"client",
"with",
"an",
"prompt",
"and",
"readline",
"history",
"path",
"."
] | train | https://github.com/borisrepl/boris/blob/793a5f196bc47b93ed95c5dcdacee52c7b3536fc/lib/Boris/ReadlineClient.php#L35-L96 |
borisrepl/boris | lib/Boris/CLIOptionsHandler.php | CLIOptionsHandler.handle | public function handle($boris)
{
$args = getopt('hvr:', array(
'help',
'version',
'require:'
));
foreach ($args as $option => $value) {
switch ($option) {
/*
* Sets files to load at startup, may be used multiple times,
* i.e: boris -r test.php,foo/bar.php -r ba/foo.php --require hey.php
*/
case 'r':
case 'require':
$this->_handleRequire($boris, $value);
break;
/*
* Show Usage info
*/
case 'h':
case 'help':
$this->_handleUsageInfo();
break;
/*
* Show version
*/
case 'v':
case 'version':
$this->_handleVersion();
break;
}
}
} | php | public function handle($boris)
{
$args = getopt('hvr:', array(
'help',
'version',
'require:'
));
foreach ($args as $option => $value) {
switch ($option) {
/*
* Sets files to load at startup, may be used multiple times,
* i.e: boris -r test.php,foo/bar.php -r ba/foo.php --require hey.php
*/
case 'r':
case 'require':
$this->_handleRequire($boris, $value);
break;
/*
* Show Usage info
*/
case 'h':
case 'help':
$this->_handleUsageInfo();
break;
/*
* Show version
*/
case 'v':
case 'version':
$this->_handleVersion();
break;
}
}
} | [
"public",
"function",
"handle",
"(",
"$",
"boris",
")",
"{",
"$",
"args",
"=",
"getopt",
"(",
"'hvr:'",
",",
"array",
"(",
"'help'",
",",
"'version'",
",",
"'require:'",
")",
")",
";",
"foreach",
"(",
"$",
"args",
"as",
"$",
"option",
"=>",
"$",
"v... | Accept the REPL object and perform any setup necessary from the CLI flags.
@param Boris $boris | [
"Accept",
"the",
"REPL",
"object",
"and",
"perform",
"any",
"setup",
"necessary",
"from",
"the",
"CLI",
"flags",
"."
] | train | https://github.com/borisrepl/boris/blob/793a5f196bc47b93ed95c5dcdacee52c7b3536fc/lib/Boris/CLIOptionsHandler.php#L15-L51 |
borisrepl/boris | lib/Boris/CLIOptionsHandler.php | CLIOptionsHandler._handleRequire | private function _handleRequire($boris, $paths)
{
$require = array_reduce((array) $paths, function($acc, $v)
{
return array_merge($acc, explode(',', $v));
}, array());
$boris->onStart(function($worker, $scope) use ($require)
{
foreach ($require as $path) {
require $path;
}
$worker->setLocal(get_defined_vars());
});
} | php | private function _handleRequire($boris, $paths)
{
$require = array_reduce((array) $paths, function($acc, $v)
{
return array_merge($acc, explode(',', $v));
}, array());
$boris->onStart(function($worker, $scope) use ($require)
{
foreach ($require as $path) {
require $path;
}
$worker->setLocal(get_defined_vars());
});
} | [
"private",
"function",
"_handleRequire",
"(",
"$",
"boris",
",",
"$",
"paths",
")",
"{",
"$",
"require",
"=",
"array_reduce",
"(",
"(",
"array",
")",
"$",
"paths",
",",
"function",
"(",
"$",
"acc",
",",
"$",
"v",
")",
"{",
"return",
"array_merge",
"(... | -- Private Methods | [
"--",
"Private",
"Methods"
] | train | https://github.com/borisrepl/boris/blob/793a5f196bc47b93ed95c5dcdacee52c7b3536fc/lib/Boris/CLIOptionsHandler.php#L55-L70 |
borisrepl/boris | lib/Boris/Config.php | Config.apply | public function apply(Boris $boris)
{
$applied = false;
foreach ($this->_searchPaths as $path) {
if (is_readable($path)) {
$this->_loadInIsolation($path, $boris);
$applied = true;
$this->_files[] = $path;
if (!$this->_cascade) {
break;
}
}
}
return $applied;
} | php | public function apply(Boris $boris)
{
$applied = false;
foreach ($this->_searchPaths as $path) {
if (is_readable($path)) {
$this->_loadInIsolation($path, $boris);
$applied = true;
$this->_files[] = $path;
if (!$this->_cascade) {
break;
}
}
}
return $applied;
} | [
"public",
"function",
"apply",
"(",
"Boris",
"$",
"boris",
")",
"{",
"$",
"applied",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"_searchPaths",
"as",
"$",
"path",
")",
"{",
"if",
"(",
"is_readable",
"(",
"$",
"path",
")",
")",
"{",
"$",
... | Searches for configuration files in the available
search paths, and applies them.
Returns true if any configuration files were found.
@param Boris\Boris $boris
@return bool | [
"Searches",
"for",
"configuration",
"files",
"in",
"the",
"available",
"search",
"paths",
"and",
"applies",
"them",
"."
] | train | https://github.com/borisrepl/boris/blob/793a5f196bc47b93ed95c5dcdacee52c7b3536fc/lib/Boris/Config.php#L50-L68 |
borisrepl/boris | lib/Boris/ShallowParser.php | ShallowParser.statements | public function statements($buffer)
{
$result = $this->_createResult($buffer);
while (strlen($result->buffer) > 0) {
$this->_resetResult($result);
if ($result->state == '<<<') {
if (!$this->_initializeHeredoc($result)) {
continue;
}
}
$rules = array(
'_scanUse',
'_scanEscapedChar',
'_scanRegion',
'_scanStateEntrant',
'_scanWsp',
'_scanChar'
);
foreach ($rules as $method) {
if ($this->$method($result)) {
break;
}
}
if ($result->stop) {
break;
}
}
if (!empty($result->statements) && trim($result->stmt) === '' && strlen($result->buffer) == 0) {
$this->_combineStatements($result);
$this->_prepareForDebug($result);
return $result->statements;
}
} | php | public function statements($buffer)
{
$result = $this->_createResult($buffer);
while (strlen($result->buffer) > 0) {
$this->_resetResult($result);
if ($result->state == '<<<') {
if (!$this->_initializeHeredoc($result)) {
continue;
}
}
$rules = array(
'_scanUse',
'_scanEscapedChar',
'_scanRegion',
'_scanStateEntrant',
'_scanWsp',
'_scanChar'
);
foreach ($rules as $method) {
if ($this->$method($result)) {
break;
}
}
if ($result->stop) {
break;
}
}
if (!empty($result->statements) && trim($result->stmt) === '' && strlen($result->buffer) == 0) {
$this->_combineStatements($result);
$this->_prepareForDebug($result);
return $result->statements;
}
} | [
"public",
"function",
"statements",
"(",
"$",
"buffer",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"_createResult",
"(",
"$",
"buffer",
")",
";",
"while",
"(",
"strlen",
"(",
"$",
"result",
"->",
"buffer",
")",
">",
"0",
")",
"{",
"$",
"this"... | Break the $buffer into chunks, with one for each highest-level construct possible.
If the buffer is incomplete, returns an empty array.
@param string $buffer
@return array | [
"Break",
"the",
"$buffer",
"into",
"chunks",
"with",
"one",
"for",
"each",
"highest",
"-",
"level",
"construct",
"possible",
"."
] | train | https://github.com/borisrepl/boris/blob/793a5f196bc47b93ed95c5dcdacee52c7b3536fc/lib/Boris/ShallowParser.php#L31-L69 |
borisrepl/boris | lib/Boris/ShallowParser.php | ShallowParser._createResult | private function _createResult($buffer)
{
$result = new \stdClass();
$result->buffer = $buffer;
$result->stmt = '';
$result->state = null;
$result->states = array();
$result->statements = array();
$result->stop = false;
return $result;
} | php | private function _createResult($buffer)
{
$result = new \stdClass();
$result->buffer = $buffer;
$result->stmt = '';
$result->state = null;
$result->states = array();
$result->statements = array();
$result->stop = false;
return $result;
} | [
"private",
"function",
"_createResult",
"(",
"$",
"buffer",
")",
"{",
"$",
"result",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"result",
"->",
"buffer",
"=",
"$",
"buffer",
";",
"$",
"result",
"->",
"stmt",
"=",
"''",
";",
"$",
"result",
"-... | -- Private Methods | [
"--",
"Private",
"Methods"
] | train | https://github.com/borisrepl/boris/blob/793a5f196bc47b93ed95c5dcdacee52c7b3536fc/lib/Boris/ShallowParser.php#L78-L89 |
borisrepl/boris | lib/Boris/Boris.php | Boris.start | public function start()
{
declare (ticks = 1);
pcntl_signal(SIGINT, SIG_IGN, true);
if (!$pipes = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP)) {
throw new \RuntimeException('Failed to create socket pair');
}
$pid = pcntl_fork();
if ($pid > 0) {
if (function_exists('setproctitle')) {
setproctitle('boris (master)');
}
fclose($pipes[0]);
$client = new ReadlineClient($pipes[1]);
$client->start($this->_prompt, $this->_historyFile);
} elseif ($pid < 0) {
throw new \RuntimeException('Failed to fork child process');
} else {
if (function_exists('setproctitle')) {
setproctitle('boris (worker)');
}
fclose($pipes[1]);
$worker = new EvalWorker($pipes[0]);
$worker->setLocal($this->_exports);
$worker->setStartHooks($this->_startHooks);
$worker->setFailureHooks($this->_failureHooks);
$worker->setInspector($this->_inspector);
$worker->start();
}
} | php | public function start()
{
declare (ticks = 1);
pcntl_signal(SIGINT, SIG_IGN, true);
if (!$pipes = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP)) {
throw new \RuntimeException('Failed to create socket pair');
}
$pid = pcntl_fork();
if ($pid > 0) {
if (function_exists('setproctitle')) {
setproctitle('boris (master)');
}
fclose($pipes[0]);
$client = new ReadlineClient($pipes[1]);
$client->start($this->_prompt, $this->_historyFile);
} elseif ($pid < 0) {
throw new \RuntimeException('Failed to fork child process');
} else {
if (function_exists('setproctitle')) {
setproctitle('boris (worker)');
}
fclose($pipes[1]);
$worker = new EvalWorker($pipes[0]);
$worker->setLocal($this->_exports);
$worker->setStartHooks($this->_startHooks);
$worker->setFailureHooks($this->_failureHooks);
$worker->setInspector($this->_inspector);
$worker->start();
}
} | [
"public",
"function",
"start",
"(",
")",
"{",
"declare",
"(",
"ticks",
"=",
"1",
")",
";",
"pcntl_signal",
"(",
"SIGINT",
",",
"SIG_IGN",
",",
"true",
")",
";",
"if",
"(",
"!",
"$",
"pipes",
"=",
"stream_socket_pair",
"(",
"STREAM_PF_UNIX",
",",
"STREA... | Start the REPL (display the readline prompt).
This method never returns. | [
"Start",
"the",
"REPL",
"(",
"display",
"the",
"readline",
"prompt",
")",
"."
] | train | https://github.com/borisrepl/boris/blob/793a5f196bc47b93ed95c5dcdacee52c7b3536fc/lib/Boris/Boris.php#L143-L177 |
borisrepl/boris | lib/Boris/ColoredInspector.php | ColoredInspector._dump | public function _dump($value)
{
$tests = array(
'is_null' => '_dumpNull',
'is_string' => '_dumpString',
'is_bool' => '_dumpBoolean',
'is_integer' => '_dumpInteger',
'is_float' => '_dumpFloat',
'is_array' => '_dumpArray',
'is_object' => '_dumpObject'
);
foreach ($tests as $predicate => $outputMethod) {
if (call_user_func($predicate, $value))
return call_user_func(array(
$this,
$outputMethod
), $value);
}
return $this->_fallback->inspect($value);
} | php | public function _dump($value)
{
$tests = array(
'is_null' => '_dumpNull',
'is_string' => '_dumpString',
'is_bool' => '_dumpBoolean',
'is_integer' => '_dumpInteger',
'is_float' => '_dumpFloat',
'is_array' => '_dumpArray',
'is_object' => '_dumpObject'
);
foreach ($tests as $predicate => $outputMethod) {
if (call_user_func($predicate, $value))
return call_user_func(array(
$this,
$outputMethod
), $value);
}
return $this->_fallback->inspect($value);
} | [
"public",
"function",
"_dump",
"(",
"$",
"value",
")",
"{",
"$",
"tests",
"=",
"array",
"(",
"'is_null'",
"=>",
"'_dumpNull'",
",",
"'is_string'",
"=>",
"'_dumpString'",
",",
"'is_bool'",
"=>",
"'_dumpBoolean'",
",",
"'is_integer'",
"=>",
"'_dumpInteger'",
","... | -- Private Methods | [
"--",
"Private",
"Methods"
] | train | https://github.com/borisrepl/boris/blob/793a5f196bc47b93ed95c5dcdacee52c7b3536fc/lib/Boris/ColoredInspector.php#L89-L110 |
InfyOmLabs/generator-builder | src/Commands/GeneratorBuilderRoutesPublisherCommand.php | GeneratorBuilderRoutesPublisherCommand.publishViews | public function publishViews()
{
$sourceDir = __DIR__ . "/../../views/";
$destinationDir = base_path('resources/views/infyom/generator-builder/');
if (file_exists($destinationDir)) {
$answer = $this->ask('Do you want to overwrite generator-builder? (y|N) :', false);
if (strtolower($answer) != 'y' and strtolower($answer) != 'yes') {
return false;
}
} else {
File::makeDirectory($destinationDir, 493, true);
}
File::copyDirectory($sourceDir, $destinationDir);
$this->comment('generator-builder views published');
$this->info($destinationDir);
} | php | public function publishViews()
{
$sourceDir = __DIR__ . "/../../views/";
$destinationDir = base_path('resources/views/infyom/generator-builder/');
if (file_exists($destinationDir)) {
$answer = $this->ask('Do you want to overwrite generator-builder? (y|N) :', false);
if (strtolower($answer) != 'y' and strtolower($answer) != 'yes') {
return false;
}
} else {
File::makeDirectory($destinationDir, 493, true);
}
File::copyDirectory($sourceDir, $destinationDir);
$this->comment('generator-builder views published');
$this->info($destinationDir);
} | [
"public",
"function",
"publishViews",
"(",
")",
"{",
"$",
"sourceDir",
"=",
"__DIR__",
".",
"\"/../../views/\"",
";",
"$",
"destinationDir",
"=",
"base_path",
"(",
"'resources/views/infyom/generator-builder/'",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"destin... | Publishes views. | [
"Publishes",
"views",
"."
] | train | https://github.com/InfyOmLabs/generator-builder/blob/1a554fa57bfac0deff019cf7847fcdde162c7350/src/Commands/GeneratorBuilderRoutesPublisherCommand.php#L57-L76 |
Airmanbzh/php-html-generator | src/HtmlTag.php | HtmlTag.addClass | public function addClass($value)
{
if (!isset($this->attributeList['class']) || is_null($this->attributeList['class'])) {
$this->attributeList['class'] = array();
}
$this->attributeList['class'][] = $value;
return $this;
} | php | public function addClass($value)
{
if (!isset($this->attributeList['class']) || is_null($this->attributeList['class'])) {
$this->attributeList['class'] = array();
}
$this->attributeList['class'][] = $value;
return $this;
} | [
"public",
"function",
"addClass",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"attributeList",
"[",
"'class'",
"]",
")",
"||",
"is_null",
"(",
"$",
"this",
"->",
"attributeList",
"[",
"'class'",
"]",
")",
")",
"{",
... | Add a class to classList
@param string $value
@return HtmlTag instance | [
"Add",
"a",
"class",
"to",
"classList"
] | train | https://github.com/Airmanbzh/php-html-generator/blob/6cb31f402db0732d39a30a2da631f33fa888db3d/src/HtmlTag.php#L37-L44 |
Airmanbzh/php-html-generator | src/HtmlTag.php | HtmlTag.removeClass | public function removeClass($value)
{
if (!is_null($this->attributeList['class'])) {
unset($this->attributeList['class'][array_search($value, $this->attributeList['class'])]);
}
return $this;
} | php | public function removeClass($value)
{
if (!is_null($this->attributeList['class'])) {
unset($this->attributeList['class'][array_search($value, $this->attributeList['class'])]);
}
return $this;
} | [
"public",
"function",
"removeClass",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"attributeList",
"[",
"'class'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"attributeList",
"[",
"'class'",
"]",
"[",
"arr... | Remove a class from classList
@param string $value
@return HtmlTag instance | [
"Remove",
"a",
"class",
"from",
"classList"
] | train | https://github.com/Airmanbzh/php-html-generator/blob/6cb31f402db0732d39a30a2da631f33fa888db3d/src/HtmlTag.php#L51-L57 |
Airmanbzh/php-html-generator | src/Markup.php | Markup.set | public function set($attribute, $value = null)
{
if (is_array($attribute)) {
foreach ($attribute as $key => $value) {
$this[$key] = $value;
}
} else {
$this[$attribute] = $value;
}
return $this;
} | php | public function set($attribute, $value = null)
{
if (is_array($attribute)) {
foreach ($attribute as $key => $value) {
$this[$key] = $value;
}
} else {
$this[$attribute] = $value;
}
return $this;
} | [
"public",
"function",
"set",
"(",
"$",
"attribute",
",",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"attribute",
")",
")",
"{",
"foreach",
"(",
"$",
"attribute",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"thi... | (Re)Define an attribute or many attributes
@param string|array $attribute
@param string $value
@return static instance | [
"(",
"Re",
")",
"Define",
"an",
"attribute",
"or",
"many",
"attributes"
] | train | https://github.com/Airmanbzh/php-html-generator/blob/6cb31f402db0732d39a30a2da631f33fa888db3d/src/Markup.php#L128-L138 |
Airmanbzh/php-html-generator | src/Markup.php | Markup.getPrevious | public function getPrevious()
{
$prev = $this;
$find = false;
if (!is_null($this->parent)) {
foreach ($this->parent->content as $c) {
if ($c === $this) {
$find=true;
break;
}
if (!$find) {
$prev = $c;
}
}
}
return $prev;
} | php | public function getPrevious()
{
$prev = $this;
$find = false;
if (!is_null($this->parent)) {
foreach ($this->parent->content as $c) {
if ($c === $this) {
$find=true;
break;
}
if (!$find) {
$prev = $c;
}
}
}
return $prev;
} | [
"public",
"function",
"getPrevious",
"(",
")",
"{",
"$",
"prev",
"=",
"$",
"this",
";",
"$",
"find",
"=",
"false",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"parent",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"parent",
"->",... | Return previous element or itself
@return static instance | [
"Return",
"previous",
"element",
"or",
"itself"
] | train | https://github.com/Airmanbzh/php-html-generator/blob/6cb31f402db0732d39a30a2da631f33fa888db3d/src/Markup.php#L241-L257 |
Airmanbzh/php-html-generator | src/Markup.php | Markup.toString | public function toString()
{
$string = '';
if (!empty($this->tag)) {
$string .= '<' . $this->tag;
$string .= $this->attributesToString();
if ($this->autoclosed) {
$string .= '/>';
} else {
$string .= '>' . $this->contentToString() . '</' . $this->tag . '>';
}
} else {
$string .= $this->text;
$string .= $this->contentToString();
}
return $string;
} | php | public function toString()
{
$string = '';
if (!empty($this->tag)) {
$string .= '<' . $this->tag;
$string .= $this->attributesToString();
if ($this->autoclosed) {
$string .= '/>';
} else {
$string .= '>' . $this->contentToString() . '</' . $this->tag . '>';
}
} else {
$string .= $this->text;
$string .= $this->contentToString();
}
return $string;
} | [
"public",
"function",
"toString",
"(",
")",
"{",
"$",
"string",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"tag",
")",
")",
"{",
"$",
"string",
".=",
"'<'",
".",
"$",
"this",
"->",
"tag",
";",
"$",
"string",
".=",
"$",
"... | Generation method
@return string | [
"Generation",
"method"
] | train | https://github.com/Airmanbzh/php-html-generator/blob/6cb31f402db0732d39a30a2da631f33fa888db3d/src/Markup.php#L318-L334 |
Airmanbzh/php-html-generator | src/Markup.php | Markup.attributesToString | protected function attributesToString()
{
$string = '';
$XMLConvention = in_array(static::$outputLanguage, array(ENT_XML1, ENT_XHTML));
if (!empty($this->attributeList)) {
foreach ($this->attributeList as $key => $value) {
if ($value!==null && ($value!==false || $XMLConvention)) {
$string.= ' ' . $key;
if ($value===true) {
if ($XMLConvention) {
$value = $key;
} else {
continue;
}
}
$string.= '="' . implode(
' ',
array_map(
static::$avoidXSS ? 'static::unXSS' : 'strval',
is_array($value) ? $value : array($value)
)
) . '"';
}
}
}
return $string;
} | php | protected function attributesToString()
{
$string = '';
$XMLConvention = in_array(static::$outputLanguage, array(ENT_XML1, ENT_XHTML));
if (!empty($this->attributeList)) {
foreach ($this->attributeList as $key => $value) {
if ($value!==null && ($value!==false || $XMLConvention)) {
$string.= ' ' . $key;
if ($value===true) {
if ($XMLConvention) {
$value = $key;
} else {
continue;
}
}
$string.= '="' . implode(
' ',
array_map(
static::$avoidXSS ? 'static::unXSS' : 'strval',
is_array($value) ? $value : array($value)
)
) . '"';
}
}
}
return $string;
} | [
"protected",
"function",
"attributesToString",
"(",
")",
"{",
"$",
"string",
"=",
"''",
";",
"$",
"XMLConvention",
"=",
"in_array",
"(",
"static",
"::",
"$",
"outputLanguage",
",",
"array",
"(",
"ENT_XML1",
",",
"ENT_XHTML",
")",
")",
";",
"if",
"(",
"!"... | return current list of attribute as a string $key="$val" $key2="$val2"
@return string | [
"return",
"current",
"list",
"of",
"attribute",
"as",
"a",
"string",
"$key",
"=",
"$val",
"$key2",
"=",
"$val2"
] | train | https://github.com/Airmanbzh/php-html-generator/blob/6cb31f402db0732d39a30a2da631f33fa888db3d/src/Markup.php#L340-L366 |
Airmanbzh/php-html-generator | src/Markup.php | Markup.contentToString | protected function contentToString()
{
$string = '';
if (!is_null($this->content)) {
foreach ($this->content as $c) {
$string .= $c->toString();
}
}
return $string;
} | php | protected function contentToString()
{
$string = '';
if (!is_null($this->content)) {
foreach ($this->content as $c) {
$string .= $c->toString();
}
}
return $string;
} | [
"protected",
"function",
"contentToString",
"(",
")",
"{",
"$",
"string",
"=",
"''",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"content",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"content",
"as",
"$",
"c",
")",
"{",
"$",
"s... | return current list of content as a string
@return string | [
"return",
"current",
"list",
"of",
"content",
"as",
"a",
"string"
] | train | https://github.com/Airmanbzh/php-html-generator/blob/6cb31f402db0732d39a30a2da631f33fa888db3d/src/Markup.php#L372-L382 |
Airmanbzh/php-html-generator | src/Markup.php | Markup.unXSS | public static function unXSS($input)
{
$return = '';
if (version_compare(phpversion(), '5.4', '<')) {
$return = htmlspecialchars($input);
} else {
$return = htmlentities($input, ENT_QUOTES | ENT_DISALLOWED | static::$outputLanguage);
}
return $return;
} | php | public static function unXSS($input)
{
$return = '';
if (version_compare(phpversion(), '5.4', '<')) {
$return = htmlspecialchars($input);
} else {
$return = htmlentities($input, ENT_QUOTES | ENT_DISALLOWED | static::$outputLanguage);
}
return $return;
} | [
"public",
"static",
"function",
"unXSS",
"(",
"$",
"input",
")",
"{",
"$",
"return",
"=",
"''",
";",
"if",
"(",
"version_compare",
"(",
"phpversion",
"(",
")",
",",
"'5.4'",
",",
"'<'",
")",
")",
"{",
"$",
"return",
"=",
"htmlspecialchars",
"(",
"$",... | Protects value from XSS injection by replacing some characters by XML / HTML entities
@param string $input The unprotected value
@return string A safe string | [
"Protects",
"value",
"from",
"XSS",
"injection",
"by",
"replacing",
"some",
"characters",
"by",
"XML",
"/",
"HTML",
"entities"
] | train | https://github.com/Airmanbzh/php-html-generator/blob/6cb31f402db0732d39a30a2da631f33fa888db3d/src/Markup.php#L389-L399 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/Table/Table.php | Table.getRow | public function getRow($index)
{
return isset($this->rows[$index]) ? $this->rows[$index] : null;
} | php | public function getRow($index)
{
return isset($this->rows[$index]) ? $this->rows[$index] : null;
} | [
"public",
"function",
"getRow",
"(",
"$",
"index",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"rows",
"[",
"$",
"index",
"]",
")",
"?",
"$",
"this",
"->",
"rows",
"[",
"$",
"index",
"]",
":",
"null",
";",
"}"
] | @param int $index
@return null|TableRow | [
"@param",
"int",
"$index"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/Table/Table.php#L55-L58 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/Table/Table.php | Table.getCellByPosition | public function getCellByPosition(TablePosition $position)
{
$row = $this->getRow($position->getRow());
return $row ? $row->getCell($position->getCell()) : null;
} | php | public function getCellByPosition(TablePosition $position)
{
$row = $this->getRow($position->getRow());
return $row ? $row->getCell($position->getCell()) : null;
} | [
"public",
"function",
"getCellByPosition",
"(",
"TablePosition",
"$",
"position",
")",
"{",
"$",
"row",
"=",
"$",
"this",
"->",
"getRow",
"(",
"$",
"position",
"->",
"getRow",
"(",
")",
")",
";",
"return",
"$",
"row",
"?",
"$",
"row",
"->",
"getCell",
... | @param TablePosition $position
@return null|TableCell | [
"@param",
"TablePosition",
"$position"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/Table/Table.php#L78-L83 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/Table/Table.php | Table.getPositionBefore | public function getPositionBefore(TablePosition $position, $offset = 1)
{
if ($position->getCell() > ($offset - 1)) {
$newRow = $position->getRow();
$newCell = $position->getCell() - $offset;
} elseif ($position->getRow() > 0) {
$cellsToMove = $offset;
$newRow = $position->getRow();
$newCell = $position->getCell();
while ($cellsToMove > 0 && $newRow >= 0) {
if ($cellsToMove > $newCell) {
--$newRow;
if ($newRow < 0) {
return;
}
$cellsToMove = $cellsToMove - ($newCell + 1);
$cellCount = count($this->getRow($newRow)->getCells());
$newCell = $cellCount - 1;
} else {
$newCell = $newCell - $cellsToMove;
$cellsToMove -= $newCell;
}
}
} else {
return;
}
if ($newRow >= 0 && $newCell >= 0) {
return new TablePosition($newRow, $newCell);
}
return;
} | php | public function getPositionBefore(TablePosition $position, $offset = 1)
{
if ($position->getCell() > ($offset - 1)) {
$newRow = $position->getRow();
$newCell = $position->getCell() - $offset;
} elseif ($position->getRow() > 0) {
$cellsToMove = $offset;
$newRow = $position->getRow();
$newCell = $position->getCell();
while ($cellsToMove > 0 && $newRow >= 0) {
if ($cellsToMove > $newCell) {
--$newRow;
if ($newRow < 0) {
return;
}
$cellsToMove = $cellsToMove - ($newCell + 1);
$cellCount = count($this->getRow($newRow)->getCells());
$newCell = $cellCount - 1;
} else {
$newCell = $newCell - $cellsToMove;
$cellsToMove -= $newCell;
}
}
} else {
return;
}
if ($newRow >= 0 && $newCell >= 0) {
return new TablePosition($newRow, $newCell);
}
return;
} | [
"public",
"function",
"getPositionBefore",
"(",
"TablePosition",
"$",
"position",
",",
"$",
"offset",
"=",
"1",
")",
"{",
"if",
"(",
"$",
"position",
"->",
"getCell",
"(",
")",
">",
"(",
"$",
"offset",
"-",
"1",
")",
")",
"{",
"$",
"newRow",
"=",
"... | @param TablePosition $position
@param int $offset
@return TablePosition|null | [
"@param",
"TablePosition",
"$position",
"@param",
"int",
"$offset"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/Table/Table.php#L91-L125 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/Table/Table.php | Table.getPositionAfter | public function getPositionAfter(TablePosition $position, $offset = 1)
{
$cellsToMove = $offset;
$newRow = $position->getRow();
$newCell = $position->getCell();
while ($cellsToMove > 0 && $newRow < count($this->rows)) {
$cellCount = count($this->getRow($newRow)->getCells());
$cellsLeft = $cellCount - $newCell - 1;
if ($cellsToMove > $cellsLeft) {
++$newRow;
$cellsToMove -= $cellsLeft - 1;
$newCell = 0;
} else {
$newCell = $newCell + $cellsToMove;
$cellsToMove -= $cellsLeft;
}
}
if ($newRow >= 0 && $newCell >= 0) {
return new TablePosition($newRow, $newCell);
}
return;
} | php | public function getPositionAfter(TablePosition $position, $offset = 1)
{
$cellsToMove = $offset;
$newRow = $position->getRow();
$newCell = $position->getCell();
while ($cellsToMove > 0 && $newRow < count($this->rows)) {
$cellCount = count($this->getRow($newRow)->getCells());
$cellsLeft = $cellCount - $newCell - 1;
if ($cellsToMove > $cellsLeft) {
++$newRow;
$cellsToMove -= $cellsLeft - 1;
$newCell = 0;
} else {
$newCell = $newCell + $cellsToMove;
$cellsToMove -= $cellsLeft;
}
}
if ($newRow >= 0 && $newCell >= 0) {
return new TablePosition($newRow, $newCell);
}
return;
} | [
"public",
"function",
"getPositionAfter",
"(",
"TablePosition",
"$",
"position",
",",
"$",
"offset",
"=",
"1",
")",
"{",
"$",
"cellsToMove",
"=",
"$",
"offset",
";",
"$",
"newRow",
"=",
"$",
"position",
"->",
"getRow",
"(",
")",
";",
"$",
"newCell",
"=... | @param TablePosition $position
@param int $offset
@return TablePosition|null | [
"@param",
"TablePosition",
"$position",
"@param",
"int",
"$offset"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/Table/Table.php#L133-L159 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/AbstractDiff.php | AbstractDiff.initPurifier | public function initPurifier($defaultPurifierSerializerCache = null)
{
if (null !== $this->purifierConfig) {
$HTMLPurifierConfig = $this->purifierConfig;
} else {
$HTMLPurifierConfig = \HTMLPurifier_Config::createDefault();
}
// Cache.SerializerPath defaults to Null and sets
// the location to inside the vendor HTMLPurifier library
// under the DefinitionCache/Serializer folder.
if (!is_null($defaultPurifierSerializerCache)) {
$HTMLPurifierConfig->set('Cache.SerializerPath', $defaultPurifierSerializerCache);
}
// Cache.SerializerPermissions defaults to 0744.
// This setting allows the cache files to be deleted by any user, as they are typically
// created by the web/php user (www-user, php-fpm, etc.)
$HTMLPurifierConfig->set('Cache.SerializerPermissions', 0777);
$this->purifier = new \HTMLPurifier($HTMLPurifierConfig);
} | php | public function initPurifier($defaultPurifierSerializerCache = null)
{
if (null !== $this->purifierConfig) {
$HTMLPurifierConfig = $this->purifierConfig;
} else {
$HTMLPurifierConfig = \HTMLPurifier_Config::createDefault();
}
// Cache.SerializerPath defaults to Null and sets
// the location to inside the vendor HTMLPurifier library
// under the DefinitionCache/Serializer folder.
if (!is_null($defaultPurifierSerializerCache)) {
$HTMLPurifierConfig->set('Cache.SerializerPath', $defaultPurifierSerializerCache);
}
// Cache.SerializerPermissions defaults to 0744.
// This setting allows the cache files to be deleted by any user, as they are typically
// created by the web/php user (www-user, php-fpm, etc.)
$HTMLPurifierConfig->set('Cache.SerializerPermissions', 0777);
$this->purifier = new \HTMLPurifier($HTMLPurifierConfig);
} | [
"public",
"function",
"initPurifier",
"(",
"$",
"defaultPurifierSerializerCache",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"purifierConfig",
")",
"{",
"$",
"HTMLPurifierConfig",
"=",
"$",
"this",
"->",
"purifierConfig",
";",
"}",
"... | Initializes HTMLPurifier with cache location.
@param null|string $defaultPurifierSerializerCache | [
"Initializes",
"HTMLPurifier",
"with",
"cache",
"location",
"."
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/AbstractDiff.php#L127-L148 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/AbstractDiff.php | AbstractDiff.prepare | protected function prepare()
{
$this->initPurifier($this->config->getPurifierCacheLocation());
$this->oldText = $this->purifyHtml($this->oldText);
$this->newText = $this->purifyHtml($this->newText);
} | php | protected function prepare()
{
$this->initPurifier($this->config->getPurifierCacheLocation());
$this->oldText = $this->purifyHtml($this->oldText);
$this->newText = $this->purifyHtml($this->newText);
} | [
"protected",
"function",
"prepare",
"(",
")",
"{",
"$",
"this",
"->",
"initPurifier",
"(",
"$",
"this",
"->",
"config",
"->",
"getPurifierCacheLocation",
"(",
")",
")",
";",
"$",
"this",
"->",
"oldText",
"=",
"$",
"this",
"->",
"purifyHtml",
"(",
"$",
... | Prepare (purify) the HTML
@return void | [
"Prepare",
"(",
"purify",
")",
"the",
"HTML"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/AbstractDiff.php#L155-L161 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/AbstractDiff.php | AbstractDiff.convertHtmlToListOfWords | protected function convertHtmlToListOfWords($characterString)
{
$mode = 'character';
$current_word = '';
$words = array();
$keepNewLines = $this->getConfig()->isKeepNewLines();
foreach ($characterString as $i => $character) {
switch ($mode) {
case 'character':
if ($this->isStartOfTag($character)) {
if ($current_word != '') {
$words[] = $current_word;
}
$current_word = '<';
$mode = 'tag';
} elseif (preg_match("/\s/u", $character)) {
if ($current_word !== '') {
$words[] = $current_word;
}
$current_word = $keepNewLines ? $character : preg_replace('/\s+/Su', ' ', $character);
$mode = 'whitespace';
} else {
if (
(($this->ctypeAlphanumUnicode($character) === true) && ($this->stringUtil->strlen($current_word) === 0 || $this->isPartOfWord($current_word))) ||
(in_array($character, $this->config->getSpecialCaseChars()) && isset($characterString[$i + 1]) && $this->isPartOfWord($characterString[$i + 1]))
) {
$current_word .= $character;
} else {
$words[] = $current_word;
$current_word = $character;
}
}
break;
case 'tag' :
if ($this->isEndOfTag($character)) {
$current_word .= '>';
$words[] = $current_word;
$current_word = '';
if (!preg_match('[^\s]u', $character)) {
$mode = 'whitespace';
} else {
$mode = 'character';
}
} else {
$current_word .= $character;
}
break;
case 'whitespace':
if ($this->isStartOfTag($character)) {
if ($current_word !== '') {
$words[] = $current_word;
}
$current_word = '<';
$mode = 'tag';
} elseif (preg_match("/\s/u", $character)) {
$current_word .= $character;
if (!$keepNewLines) $current_word = preg_replace('/\s+/Su', ' ', $current_word);
} else {
if ($current_word != '') {
$words[] = $current_word;
}
$current_word = $character;
$mode = 'character';
}
break;
default:
break;
}
}
if ($current_word != '') {
$words[] = $current_word;
}
return $words;
} | php | protected function convertHtmlToListOfWords($characterString)
{
$mode = 'character';
$current_word = '';
$words = array();
$keepNewLines = $this->getConfig()->isKeepNewLines();
foreach ($characterString as $i => $character) {
switch ($mode) {
case 'character':
if ($this->isStartOfTag($character)) {
if ($current_word != '') {
$words[] = $current_word;
}
$current_word = '<';
$mode = 'tag';
} elseif (preg_match("/\s/u", $character)) {
if ($current_word !== '') {
$words[] = $current_word;
}
$current_word = $keepNewLines ? $character : preg_replace('/\s+/Su', ' ', $character);
$mode = 'whitespace';
} else {
if (
(($this->ctypeAlphanumUnicode($character) === true) && ($this->stringUtil->strlen($current_word) === 0 || $this->isPartOfWord($current_word))) ||
(in_array($character, $this->config->getSpecialCaseChars()) && isset($characterString[$i + 1]) && $this->isPartOfWord($characterString[$i + 1]))
) {
$current_word .= $character;
} else {
$words[] = $current_word;
$current_word = $character;
}
}
break;
case 'tag' :
if ($this->isEndOfTag($character)) {
$current_word .= '>';
$words[] = $current_word;
$current_word = '';
if (!preg_match('[^\s]u', $character)) {
$mode = 'whitespace';
} else {
$mode = 'character';
}
} else {
$current_word .= $character;
}
break;
case 'whitespace':
if ($this->isStartOfTag($character)) {
if ($current_word !== '') {
$words[] = $current_word;
}
$current_word = '<';
$mode = 'tag';
} elseif (preg_match("/\s/u", $character)) {
$current_word .= $character;
if (!$keepNewLines) $current_word = preg_replace('/\s+/Su', ' ', $current_word);
} else {
if ($current_word != '') {
$words[] = $current_word;
}
$current_word = $character;
$mode = 'character';
}
break;
default:
break;
}
}
if ($current_word != '') {
$words[] = $current_word;
}
return $words;
} | [
"protected",
"function",
"convertHtmlToListOfWords",
"(",
"$",
"characterString",
")",
"{",
"$",
"mode",
"=",
"'character'",
";",
"$",
"current_word",
"=",
"''",
";",
"$",
"words",
"=",
"array",
"(",
")",
";",
"$",
"keepNewLines",
"=",
"$",
"this",
"->",
... | @param array $characterString
@return array | [
"@param",
"array",
"$characterString"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/AbstractDiff.php#L448-L524 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/Table/TablePosition.php | TablePosition.compare | public static function compare($a, $b)
{
if ($a->getRow() == $b->getRow()) {
return $a->getCell() - $b->getCell();
}
return $a->getRow() - $b->getRow();
} | php | public static function compare($a, $b)
{
if ($a->getRow() == $b->getRow()) {
return $a->getCell() - $b->getCell();
}
return $a->getRow() - $b->getRow();
} | [
"public",
"static",
"function",
"compare",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"if",
"(",
"$",
"a",
"->",
"getRow",
"(",
")",
"==",
"$",
"b",
"->",
"getRow",
"(",
")",
")",
"{",
"return",
"$",
"a",
"->",
"getCell",
"(",
")",
"-",
"$",
"... | @param TablePosition $a
@param TablePosition $b
@return int | [
"@param",
"TablePosition",
"$a",
"@param",
"TablePosition",
"$b"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/Table/TablePosition.php#L61-L68 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/Table/TableRow.php | TableRow.setTable | public function setTable(Table $table = null)
{
$this->table = $table;
if ($table && !in_array($this, $table->getRows())) {
$table->addRow($this);
}
return $this;
} | php | public function setTable(Table $table = null)
{
$this->table = $table;
if ($table && !in_array($this, $table->getRows())) {
$table->addRow($this);
}
return $this;
} | [
"public",
"function",
"setTable",
"(",
"Table",
"$",
"table",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"table",
"=",
"$",
"table",
";",
"if",
"(",
"$",
"table",
"&&",
"!",
"in_array",
"(",
"$",
"this",
",",
"$",
"table",
"->",
"getRows",
"(",
")... | @param Table|null $table
@return $this | [
"@param",
"Table|null",
"$table"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/Table/TableRow.php#L33-L42 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/Table/TableRow.php | TableRow.addCell | public function addCell(TableCell $cell)
{
$this->cells[] = $cell;
if (!$cell->getRow()) {
$cell->setRow($this);
}
return $this;
} | php | public function addCell(TableCell $cell)
{
$this->cells[] = $cell;
if (!$cell->getRow()) {
$cell->setRow($this);
}
return $this;
} | [
"public",
"function",
"addCell",
"(",
"TableCell",
"$",
"cell",
")",
"{",
"$",
"this",
"->",
"cells",
"[",
"]",
"=",
"$",
"cell",
";",
"if",
"(",
"!",
"$",
"cell",
"->",
"getRow",
"(",
")",
")",
"{",
"$",
"cell",
"->",
"setRow",
"(",
"$",
"this... | @param TableCell $cell
@return $this | [
"@param",
"TableCell",
"$cell"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/Table/TableRow.php#L57-L66 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/Table/TableRow.php | TableRow.getCell | public function getCell($index)
{
return isset($this->cells[$index]) ? $this->cells[$index] : null;
} | php | public function getCell($index)
{
return isset($this->cells[$index]) ? $this->cells[$index] : null;
} | [
"public",
"function",
"getCell",
"(",
"$",
"index",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"cells",
"[",
"$",
"index",
"]",
")",
"?",
"$",
"this",
"->",
"cells",
"[",
"$",
"index",
"]",
":",
"null",
";",
"}"
] | @param int $index
@return TableCell|null | [
"@param",
"int",
"$index"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/Table/TableRow.php#L88-L91 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/ListDiff.php | ListDiff.create | public static function create($oldText, $newText, HtmlDiffConfig $config = null)
{
$diff = new self($oldText, $newText);
if (null !== $config) {
$diff->setConfig($config);
}
return $diff;
} | php | public static function create($oldText, $newText, HtmlDiffConfig $config = null)
{
$diff = new self($oldText, $newText);
if (null !== $config) {
$diff->setConfig($config);
}
return $diff;
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"oldText",
",",
"$",
"newText",
",",
"HtmlDiffConfig",
"$",
"config",
"=",
"null",
")",
"{",
"$",
"diff",
"=",
"new",
"self",
"(",
"$",
"oldText",
",",
"$",
"newText",
")",
";",
"if",
"(",
"null",
... | @param string $oldText
@param string $newText
@param HtmlDiffConfig|null $config
@return ListDiff | [
"@param",
"string",
"$oldText",
"@param",
"string",
"$newText",
"@param",
"HtmlDiffConfig|null",
"$config"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/ListDiff.php#L19-L28 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/ListDiff.php | ListDiff.hasBetterMatch | protected function hasBetterMatch(array $matchData, $currentIndex)
{
$matchPercentage = $matchData[$currentIndex];
foreach ($matchData as $index => $percentage) {
if ($index > $currentIndex &&
$percentage > $matchPercentage &&
$percentage > $this->config->getMatchThreshold()
) {
return true;
}
}
return false;
} | php | protected function hasBetterMatch(array $matchData, $currentIndex)
{
$matchPercentage = $matchData[$currentIndex];
foreach ($matchData as $index => $percentage) {
if ($index > $currentIndex &&
$percentage > $matchPercentage &&
$percentage > $this->config->getMatchThreshold()
) {
return true;
}
}
return false;
} | [
"protected",
"function",
"hasBetterMatch",
"(",
"array",
"$",
"matchData",
",",
"$",
"currentIndex",
")",
"{",
"$",
"matchPercentage",
"=",
"$",
"matchData",
"[",
"$",
"currentIndex",
"]",
";",
"foreach",
"(",
"$",
"matchData",
"as",
"$",
"index",
"=>",
"$... | @param array $matchData
@param int $currentIndex
@return bool | [
"@param",
"array",
"$matchData",
"@param",
"int",
"$currentIndex"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/ListDiff.php#L198-L211 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/HtmlDiff.php | HtmlDiff.createIsolatedDiffTagPlaceholders | protected function createIsolatedDiffTagPlaceholders(&$words)
{
$openIsolatedDiffTags = 0;
$isolatedDiffTagIndices = array();
$isolatedDiffTagStart = 0;
$currentIsolatedDiffTag = null;
foreach ($words as $index => $word) {
$openIsolatedDiffTag = $this->isOpeningIsolatedDiffTag($word, $currentIsolatedDiffTag);
if ($openIsolatedDiffTag) {
if ($this->isSelfClosingTag($word) || $this->stringUtil->stripos($word, '<img') !== false) {
if ($openIsolatedDiffTags === 0) {
$isolatedDiffTagIndices[] = array(
'start' => $index,
'length' => 1,
'tagType' => $openIsolatedDiffTag,
);
$currentIsolatedDiffTag = null;
}
} else {
if ($openIsolatedDiffTags === 0) {
$isolatedDiffTagStart = $index;
}
++$openIsolatedDiffTags;
$currentIsolatedDiffTag = $openIsolatedDiffTag;
}
} elseif ($openIsolatedDiffTags > 0 && $this->isClosingIsolatedDiffTag($word, $currentIsolatedDiffTag)) {
--$openIsolatedDiffTags;
if ($openIsolatedDiffTags == 0) {
$isolatedDiffTagIndices[] = array('start' => $isolatedDiffTagStart, 'length' => $index - $isolatedDiffTagStart + 1, 'tagType' => $currentIsolatedDiffTag);
$currentIsolatedDiffTag = null;
}
}
}
$isolatedDiffTagScript = array();
$offset = 0;
foreach ($isolatedDiffTagIndices as $isolatedDiffTagIndex) {
$start = $isolatedDiffTagIndex['start'] - $offset;
$placeholderString = $this->config->getIsolatedDiffTagPlaceholder($isolatedDiffTagIndex['tagType']);
$isolatedDiffTagScript[$start] = array_splice($words, $start, $isolatedDiffTagIndex['length'], $placeholderString);
$offset += $isolatedDiffTagIndex['length'] - 1;
}
return $isolatedDiffTagScript;
} | php | protected function createIsolatedDiffTagPlaceholders(&$words)
{
$openIsolatedDiffTags = 0;
$isolatedDiffTagIndices = array();
$isolatedDiffTagStart = 0;
$currentIsolatedDiffTag = null;
foreach ($words as $index => $word) {
$openIsolatedDiffTag = $this->isOpeningIsolatedDiffTag($word, $currentIsolatedDiffTag);
if ($openIsolatedDiffTag) {
if ($this->isSelfClosingTag($word) || $this->stringUtil->stripos($word, '<img') !== false) {
if ($openIsolatedDiffTags === 0) {
$isolatedDiffTagIndices[] = array(
'start' => $index,
'length' => 1,
'tagType' => $openIsolatedDiffTag,
);
$currentIsolatedDiffTag = null;
}
} else {
if ($openIsolatedDiffTags === 0) {
$isolatedDiffTagStart = $index;
}
++$openIsolatedDiffTags;
$currentIsolatedDiffTag = $openIsolatedDiffTag;
}
} elseif ($openIsolatedDiffTags > 0 && $this->isClosingIsolatedDiffTag($word, $currentIsolatedDiffTag)) {
--$openIsolatedDiffTags;
if ($openIsolatedDiffTags == 0) {
$isolatedDiffTagIndices[] = array('start' => $isolatedDiffTagStart, 'length' => $index - $isolatedDiffTagStart + 1, 'tagType' => $currentIsolatedDiffTag);
$currentIsolatedDiffTag = null;
}
}
}
$isolatedDiffTagScript = array();
$offset = 0;
foreach ($isolatedDiffTagIndices as $isolatedDiffTagIndex) {
$start = $isolatedDiffTagIndex['start'] - $offset;
$placeholderString = $this->config->getIsolatedDiffTagPlaceholder($isolatedDiffTagIndex['tagType']);
$isolatedDiffTagScript[$start] = array_splice($words, $start, $isolatedDiffTagIndex['length'], $placeholderString);
$offset += $isolatedDiffTagIndex['length'] - 1;
}
return $isolatedDiffTagScript;
} | [
"protected",
"function",
"createIsolatedDiffTagPlaceholders",
"(",
"&",
"$",
"words",
")",
"{",
"$",
"openIsolatedDiffTags",
"=",
"0",
";",
"$",
"isolatedDiffTagIndices",
"=",
"array",
"(",
")",
";",
"$",
"isolatedDiffTagStart",
"=",
"0",
";",
"$",
"currentIsola... | @param array $words
@return array | [
"@param",
"array",
"$words"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/HtmlDiff.php#L152-L195 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/HtmlDiff.php | HtmlDiff.isOpeningIsolatedDiffTag | protected function isOpeningIsolatedDiffTag($item, $currentIsolatedDiffTag = null)
{
$tagsToMatch = $currentIsolatedDiffTag !== null
? array($currentIsolatedDiffTag => $this->config->getIsolatedDiffTagPlaceholder($currentIsolatedDiffTag))
: $this->config->getIsolatedDiffTags();
$pattern = '#<%s(\s+[^>]*)?>#iUu';
foreach ($tagsToMatch as $key => $value) {
if (preg_match(sprintf($pattern, $key), $item)) {
return $key;
}
}
return false;
} | php | protected function isOpeningIsolatedDiffTag($item, $currentIsolatedDiffTag = null)
{
$tagsToMatch = $currentIsolatedDiffTag !== null
? array($currentIsolatedDiffTag => $this->config->getIsolatedDiffTagPlaceholder($currentIsolatedDiffTag))
: $this->config->getIsolatedDiffTags();
$pattern = '#<%s(\s+[^>]*)?>#iUu';
foreach ($tagsToMatch as $key => $value) {
if (preg_match(sprintf($pattern, $key), $item)) {
return $key;
}
}
return false;
} | [
"protected",
"function",
"isOpeningIsolatedDiffTag",
"(",
"$",
"item",
",",
"$",
"currentIsolatedDiffTag",
"=",
"null",
")",
"{",
"$",
"tagsToMatch",
"=",
"$",
"currentIsolatedDiffTag",
"!==",
"null",
"?",
"array",
"(",
"$",
"currentIsolatedDiffTag",
"=>",
"$",
... | @param string $item
@param null|string $currentIsolatedDiffTag
@return false|string | [
"@param",
"string",
"$item",
"@param",
"null|string",
"$currentIsolatedDiffTag"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/HtmlDiff.php#L203-L216 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/HtmlDiff.php | HtmlDiff.diffIsolatedPlaceholder | protected function diffIsolatedPlaceholder($operation, $pos, $placeholder, $stripWrappingTags = true)
{
$oldText = implode('', $this->findIsolatedDiffTagsInOld($operation, $pos));
$newText = implode('', $this->newIsolatedDiffTags[$pos]);
if ($this->isListPlaceholder($placeholder)) {
return $this->diffList($oldText, $newText);
} elseif ($this->config->isUseTableDiffing() && $this->isTablePlaceholder($placeholder)) {
return $this->diffTables($oldText, $newText);
} elseif ($this->isLinkPlaceholder($placeholder)) {
return $this->diffElementsByAttribute($oldText, $newText, 'href', 'a');
} elseif ($this->isImagePlaceholder($placeholder)) {
return $this->diffElementsByAttribute($oldText, $newText, 'src', 'img');
}
return $this->diffElements($oldText, $newText, $stripWrappingTags);
} | php | protected function diffIsolatedPlaceholder($operation, $pos, $placeholder, $stripWrappingTags = true)
{
$oldText = implode('', $this->findIsolatedDiffTagsInOld($operation, $pos));
$newText = implode('', $this->newIsolatedDiffTags[$pos]);
if ($this->isListPlaceholder($placeholder)) {
return $this->diffList($oldText, $newText);
} elseif ($this->config->isUseTableDiffing() && $this->isTablePlaceholder($placeholder)) {
return $this->diffTables($oldText, $newText);
} elseif ($this->isLinkPlaceholder($placeholder)) {
return $this->diffElementsByAttribute($oldText, $newText, 'href', 'a');
} elseif ($this->isImagePlaceholder($placeholder)) {
return $this->diffElementsByAttribute($oldText, $newText, 'src', 'img');
}
return $this->diffElements($oldText, $newText, $stripWrappingTags);
} | [
"protected",
"function",
"diffIsolatedPlaceholder",
"(",
"$",
"operation",
",",
"$",
"pos",
",",
"$",
"placeholder",
",",
"$",
"stripWrappingTags",
"=",
"true",
")",
"{",
"$",
"oldText",
"=",
"implode",
"(",
"''",
",",
"$",
"this",
"->",
"findIsolatedDiffTag... | @param Operation $operation
@param int $pos
@param string $placeholder
@param bool $stripWrappingTags
@return string | [
"@param",
"Operation",
"$operation",
"@param",
"int",
"$pos",
"@param",
"string",
"$placeholder",
"@param",
"bool",
"$stripWrappingTags"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/HtmlDiff.php#L326-L342 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/HtmlDiff.php | HtmlDiff.diffElements | protected function diffElements($oldText, $newText, $stripWrappingTags = true)
{
$wrapStart = '';
$wrapEnd = '';
if ($stripWrappingTags) {
$pattern = '/(^<[^>]+>)|(<\/[^>]+>$)/iu';
$matches = array();
if (preg_match_all($pattern, $newText, $matches)) {
$wrapStart = isset($matches[0][0]) ? $matches[0][0] : '';
$wrapEnd = isset($matches[0][1]) ? $matches[0][1] : '';
}
$oldText = preg_replace($pattern, '', $oldText);
$newText = preg_replace($pattern, '', $newText);
}
$diff = self::create($oldText, $newText, $this->config);
return $wrapStart.$diff->build().$wrapEnd;
} | php | protected function diffElements($oldText, $newText, $stripWrappingTags = true)
{
$wrapStart = '';
$wrapEnd = '';
if ($stripWrappingTags) {
$pattern = '/(^<[^>]+>)|(<\/[^>]+>$)/iu';
$matches = array();
if (preg_match_all($pattern, $newText, $matches)) {
$wrapStart = isset($matches[0][0]) ? $matches[0][0] : '';
$wrapEnd = isset($matches[0][1]) ? $matches[0][1] : '';
}
$oldText = preg_replace($pattern, '', $oldText);
$newText = preg_replace($pattern, '', $newText);
}
$diff = self::create($oldText, $newText, $this->config);
return $wrapStart.$diff->build().$wrapEnd;
} | [
"protected",
"function",
"diffElements",
"(",
"$",
"oldText",
",",
"$",
"newText",
",",
"$",
"stripWrappingTags",
"=",
"true",
")",
"{",
"$",
"wrapStart",
"=",
"''",
";",
"$",
"wrapEnd",
"=",
"''",
";",
"if",
"(",
"$",
"stripWrappingTags",
")",
"{",
"$... | @param string $oldText
@param string $newText
@param bool $stripWrappingTags
@return string | [
"@param",
"string",
"$oldText",
"@param",
"string",
"$newText",
"@param",
"bool",
"$stripWrappingTags"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/HtmlDiff.php#L351-L371 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/HtmlDiff.php | HtmlDiff.diffList | protected function diffList($oldText, $newText)
{
$diff = ListDiffLines::create($oldText, $newText, $this->config);
return $diff->build();
} | php | protected function diffList($oldText, $newText)
{
$diff = ListDiffLines::create($oldText, $newText, $this->config);
return $diff->build();
} | [
"protected",
"function",
"diffList",
"(",
"$",
"oldText",
",",
"$",
"newText",
")",
"{",
"$",
"diff",
"=",
"ListDiffLines",
"::",
"create",
"(",
"$",
"oldText",
",",
"$",
"newText",
",",
"$",
"this",
"->",
"config",
")",
";",
"return",
"$",
"diff",
"... | @param string $oldText
@param string $newText
@return string | [
"@param",
"string",
"$oldText",
"@param",
"string",
"$newText"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/HtmlDiff.php#L379-L384 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/HtmlDiff.php | HtmlDiff.diffTables | protected function diffTables($oldText, $newText)
{
$diff = TableDiff::create($oldText, $newText, $this->config);
return $diff->build();
} | php | protected function diffTables($oldText, $newText)
{
$diff = TableDiff::create($oldText, $newText, $this->config);
return $diff->build();
} | [
"protected",
"function",
"diffTables",
"(",
"$",
"oldText",
",",
"$",
"newText",
")",
"{",
"$",
"diff",
"=",
"TableDiff",
"::",
"create",
"(",
"$",
"oldText",
",",
"$",
"newText",
",",
"$",
"this",
"->",
"config",
")",
";",
"return",
"$",
"diff",
"->... | @param string $oldText
@param string $newText
@return string | [
"@param",
"string",
"$oldText",
"@param",
"string",
"$newText"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/HtmlDiff.php#L392-L397 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/HtmlDiff.php | HtmlDiff.getAttributeFromTag | protected function getAttributeFromTag($text, $attribute)
{
$matches = array();
if (preg_match(sprintf('/<[^>]*\b%s\s*=\s*([\'"])(.*)\1[^>]*>/iu', $attribute), $text, $matches)) {
return htmlspecialchars_decode($matches[2]);
}
return;
} | php | protected function getAttributeFromTag($text, $attribute)
{
$matches = array();
if (preg_match(sprintf('/<[^>]*\b%s\s*=\s*([\'"])(.*)\1[^>]*>/iu', $attribute), $text, $matches)) {
return htmlspecialchars_decode($matches[2]);
}
return;
} | [
"protected",
"function",
"getAttributeFromTag",
"(",
"$",
"text",
",",
"$",
"attribute",
")",
"{",
"$",
"matches",
"=",
"array",
"(",
")",
";",
"if",
"(",
"preg_match",
"(",
"sprintf",
"(",
"'/<[^>]*\\b%s\\s*=\\s*([\\'\"])(.*)\\1[^>]*>/iu'",
",",
"$",
"attribute... | @param string $text
@param string $attribute
@return null|string | [
"@param",
"string",
"$text",
"@param",
"string",
"$attribute"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/HtmlDiff.php#L441-L449 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/HtmlDiff.php | HtmlDiff.isPlaceholderType | protected function isPlaceholderType($text, $types, $strict = true)
{
if (!is_array($types)) {
$types = array($types);
}
$criteria = array();
foreach ($types as $type) {
if ($this->config->isIsolatedDiffTag($type)) {
$criteria[] = $this->config->getIsolatedDiffTagPlaceholder($type);
} else {
$criteria[] = $type;
}
}
return in_array($text, $criteria, $strict);
} | php | protected function isPlaceholderType($text, $types, $strict = true)
{
if (!is_array($types)) {
$types = array($types);
}
$criteria = array();
foreach ($types as $type) {
if ($this->config->isIsolatedDiffTag($type)) {
$criteria[] = $this->config->getIsolatedDiffTagPlaceholder($type);
} else {
$criteria[] = $type;
}
}
return in_array($text, $criteria, $strict);
} | [
"protected",
"function",
"isPlaceholderType",
"(",
"$",
"text",
",",
"$",
"types",
",",
"$",
"strict",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"types",
")",
")",
"{",
"$",
"types",
"=",
"array",
"(",
"$",
"types",
")",
";",
"... | @param string $text
@param array|string $types
@param bool $strict
@return bool | [
"@param",
"string",
"$text",
"@param",
"array|string",
"$types",
"@param",
"bool",
"$strict"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/HtmlDiff.php#L488-L504 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/HtmlDiff.php | HtmlDiff.findIsolatedDiffTagsInOld | protected function findIsolatedDiffTagsInOld($operation, $posInNew)
{
$offset = $posInNew - $operation->startInNew;
return $this->oldIsolatedDiffTags[$operation->startInOld + $offset];
} | php | protected function findIsolatedDiffTagsInOld($operation, $posInNew)
{
$offset = $posInNew - $operation->startInNew;
return $this->oldIsolatedDiffTags[$operation->startInOld + $offset];
} | [
"protected",
"function",
"findIsolatedDiffTagsInOld",
"(",
"$",
"operation",
",",
"$",
"posInNew",
")",
"{",
"$",
"offset",
"=",
"$",
"posInNew",
"-",
"$",
"operation",
"->",
"startInNew",
";",
"return",
"$",
"this",
"->",
"oldIsolatedDiffTags",
"[",
"$",
"o... | @param Operation $operation
@param int $posInNew
@return array | [
"@param",
"Operation",
"$operation",
"@param",
"int",
"$posInNew"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/HtmlDiff.php#L522-L527 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/HtmlDiff.php | HtmlDiff.checkCondition | protected function checkCondition($word, $condition)
{
return $condition == 'tag' ? $this->isTag($word) : !$this->isTag($word);
} | php | protected function checkCondition($word, $condition)
{
return $condition == 'tag' ? $this->isTag($word) : !$this->isTag($word);
} | [
"protected",
"function",
"checkCondition",
"(",
"$",
"word",
",",
"$",
"condition",
")",
"{",
"return",
"$",
"condition",
"==",
"'tag'",
"?",
"$",
"this",
"->",
"isTag",
"(",
"$",
"word",
")",
":",
"!",
"$",
"this",
"->",
"isTag",
"(",
"$",
"word",
... | @param string $word
@param string $condition
@return bool | [
"@param",
"string",
"$word",
"@param",
"string",
"$condition"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/HtmlDiff.php#L601-L604 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/HtmlDiff.php | HtmlDiff.stripTagAttributes | protected function stripTagAttributes($word)
{
$space = $this->stringUtil->strpos($word, ' ', 1);
if ($space) {
return '<' . $this->stringUtil->substr($word, 1, $space) . '>';
}
return trim($word, '<>');
} | php | protected function stripTagAttributes($word)
{
$space = $this->stringUtil->strpos($word, ' ', 1);
if ($space) {
return '<' . $this->stringUtil->substr($word, 1, $space) . '>';
}
return trim($word, '<>');
} | [
"protected",
"function",
"stripTagAttributes",
"(",
"$",
"word",
")",
"{",
"$",
"space",
"=",
"$",
"this",
"->",
"stringUtil",
"->",
"strpos",
"(",
"$",
"word",
",",
"' '",
",",
"1",
")",
";",
"if",
"(",
"$",
"space",
")",
"{",
"return",
"'<'",
"."... | @param string $word
@return string | [
"@param",
"string",
"$word"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/HtmlDiff.php#L770-L779 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/HtmlDiff.php | HtmlDiff.findMatch | protected function findMatch($startInOld, $endInOld, $startInNew, $endInNew)
{
$groupDiffs = $this->isGroupDiffs();
$bestMatchInOld = $startInOld;
$bestMatchInNew = $startInNew;
$bestMatchSize = 0;
$matchLengthAt = array();
for ($indexInOld = $startInOld; $indexInOld < $endInOld; ++$indexInOld) {
$newMatchLengthAt = array();
$index = $this->oldWords[ $indexInOld ];
if ($this->isTag($index)) {
$index = $this->stripTagAttributes($index);
}
if (!isset($this->wordIndices[ $index ])) {
$matchLengthAt = $newMatchLengthAt;
continue;
}
foreach ($this->wordIndices[ $index ] as $indexInNew) {
if ($indexInNew < $startInNew) {
continue;
}
if ($indexInNew >= $endInNew) {
break;
}
$newMatchLength = (isset($matchLengthAt[ $indexInNew - 1 ]) ? $matchLengthAt[ $indexInNew - 1 ] : 0) + 1;
$newMatchLengthAt[ $indexInNew ] = $newMatchLength;
if ($newMatchLength > $bestMatchSize ||
(
$groupDiffs &&
$bestMatchSize > 0 &&
$this->isOnlyWhitespace($this->array_slice_cached($this->oldWords, $bestMatchInOld, $bestMatchSize))
)
) {
$bestMatchInOld = $indexInOld - $newMatchLength + 1;
$bestMatchInNew = $indexInNew - $newMatchLength + 1;
$bestMatchSize = $newMatchLength;
}
}
$matchLengthAt = $newMatchLengthAt;
}
// Skip match if none found or match consists only of whitespace
if ($bestMatchSize !== 0 &&
(
!$groupDiffs ||
!$this->isOnlyWhitespace($this->array_slice_cached($this->oldWords, $bestMatchInOld, $bestMatchSize))
)
) {
return new Match($bestMatchInOld, $bestMatchInNew, $bestMatchSize);
}
return null;
} | php | protected function findMatch($startInOld, $endInOld, $startInNew, $endInNew)
{
$groupDiffs = $this->isGroupDiffs();
$bestMatchInOld = $startInOld;
$bestMatchInNew = $startInNew;
$bestMatchSize = 0;
$matchLengthAt = array();
for ($indexInOld = $startInOld; $indexInOld < $endInOld; ++$indexInOld) {
$newMatchLengthAt = array();
$index = $this->oldWords[ $indexInOld ];
if ($this->isTag($index)) {
$index = $this->stripTagAttributes($index);
}
if (!isset($this->wordIndices[ $index ])) {
$matchLengthAt = $newMatchLengthAt;
continue;
}
foreach ($this->wordIndices[ $index ] as $indexInNew) {
if ($indexInNew < $startInNew) {
continue;
}
if ($indexInNew >= $endInNew) {
break;
}
$newMatchLength = (isset($matchLengthAt[ $indexInNew - 1 ]) ? $matchLengthAt[ $indexInNew - 1 ] : 0) + 1;
$newMatchLengthAt[ $indexInNew ] = $newMatchLength;
if ($newMatchLength > $bestMatchSize ||
(
$groupDiffs &&
$bestMatchSize > 0 &&
$this->isOnlyWhitespace($this->array_slice_cached($this->oldWords, $bestMatchInOld, $bestMatchSize))
)
) {
$bestMatchInOld = $indexInOld - $newMatchLength + 1;
$bestMatchInNew = $indexInNew - $newMatchLength + 1;
$bestMatchSize = $newMatchLength;
}
}
$matchLengthAt = $newMatchLengthAt;
}
// Skip match if none found or match consists only of whitespace
if ($bestMatchSize !== 0 &&
(
!$groupDiffs ||
!$this->isOnlyWhitespace($this->array_slice_cached($this->oldWords, $bestMatchInOld, $bestMatchSize))
)
) {
return new Match($bestMatchInOld, $bestMatchInNew, $bestMatchSize);
}
return null;
} | [
"protected",
"function",
"findMatch",
"(",
"$",
"startInOld",
",",
"$",
"endInOld",
",",
"$",
"startInNew",
",",
"$",
"endInNew",
")",
"{",
"$",
"groupDiffs",
"=",
"$",
"this",
"->",
"isGroupDiffs",
"(",
")",
";",
"$",
"bestMatchInOld",
"=",
"$",
"startI... | @param int $startInOld
@param int $endInOld
@param int $startInNew
@param int $endInNew
@return Match|null | [
"@param",
"int",
"$startInOld",
"@param",
"int",
"$endInOld",
"@param",
"int",
"$startInNew",
"@param",
"int",
"$endInNew"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/HtmlDiff.php#L789-L844 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/HtmlDiff.php | HtmlDiff.array_slice_cached | protected function array_slice_cached(&$array, $offset, $length = null)
{
static $lastOffset = null;
static $lastLength = null;
static $cache = null;
// PHP has no support for by-reference comparing.
// to prevent false positive hits, reset the cache when the oldWords or newWords is changed.
if ($this->resetCache === true) {
$cache = null;
$this->resetCache = false;
}
if (
$cache !== null &&
$lastLength === $length &&
$lastOffset === $offset
) { // Hit
return $cache;
} // Miss
$lastOffset = $offset;
$lastLength = $length;
$cache = implode('', array_slice($array, $offset, $length));
return $cache;
} | php | protected function array_slice_cached(&$array, $offset, $length = null)
{
static $lastOffset = null;
static $lastLength = null;
static $cache = null;
// PHP has no support for by-reference comparing.
// to prevent false positive hits, reset the cache when the oldWords or newWords is changed.
if ($this->resetCache === true) {
$cache = null;
$this->resetCache = false;
}
if (
$cache !== null &&
$lastLength === $length &&
$lastOffset === $offset
) { // Hit
return $cache;
} // Miss
$lastOffset = $offset;
$lastLength = $length;
$cache = implode('', array_slice($array, $offset, $length));
return $cache;
} | [
"protected",
"function",
"array_slice_cached",
"(",
"&",
"$",
"array",
",",
"$",
"offset",
",",
"$",
"length",
"=",
"null",
")",
"{",
"static",
"$",
"lastOffset",
"=",
"null",
";",
"static",
"$",
"lastLength",
"=",
"null",
";",
"static",
"$",
"cache",
... | Special array_slice function that caches its last request.
The diff algorithm seems to request the same information many times in a row.
by returning the previous answer the algorithm preforms way faster.
The result is a string instead of an array, this way we safe on the amount of
memory intensive implode() calls.
@param array &$array
@param integer $offset
@param integer|null $length
@return string | [
"Special",
"array_slice",
"function",
"that",
"caches",
"its",
"last",
"request",
"."
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/HtmlDiff.php#L872-L900 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/Table/AbstractTableElement.php | AbstractTableElement.cloneNode | public function cloneNode(\DOMDocument $domDocument)
{
return $domDocument->importNode($this->getDomNode()->cloneNode(false), false);
} | php | public function cloneNode(\DOMDocument $domDocument)
{
return $domDocument->importNode($this->getDomNode()->cloneNode(false), false);
} | [
"public",
"function",
"cloneNode",
"(",
"\\",
"DOMDocument",
"$",
"domDocument",
")",
"{",
"return",
"$",
"domDocument",
"->",
"importNode",
"(",
"$",
"this",
"->",
"getDomNode",
"(",
")",
"->",
"cloneNode",
"(",
"false",
")",
",",
"false",
")",
";",
"}"... | @param \DOMDocument $domDocument
@return \DOMElement | [
"@param",
"\\",
"DOMDocument",
"$domDocument"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/Table/AbstractTableElement.php#L76-L79 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/Table/TableCell.php | TableCell.setRow | public function setRow(TableRow $row = null)
{
$this->row = $row;
if (null !== $row && !in_array($this, $row->getCells())) {
$row->addCell($this);
}
return $this;
} | php | public function setRow(TableRow $row = null)
{
$this->row = $row;
if (null !== $row && !in_array($this, $row->getCells())) {
$row->addCell($this);
}
return $this;
} | [
"public",
"function",
"setRow",
"(",
"TableRow",
"$",
"row",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"row",
"=",
"$",
"row",
";",
"if",
"(",
"null",
"!==",
"$",
"row",
"&&",
"!",
"in_array",
"(",
"$",
"this",
",",
"$",
"row",
"->",
"getCells",
... | @param TableRow|null $row
@return $this | [
"@param",
"TableRow|null",
"$row"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/Table/TableCell.php#L28-L37 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/Table/TableDiff.php | TableDiff.getRowMatches | protected function getRowMatches($oldMatchData, $newMatchData)
{
$matches = array();
$startInOld = 0;
$startInNew = 0;
$endInOld = count($oldMatchData);
$endInNew = count($newMatchData);
$this->findRowMatches($newMatchData, $startInOld, $endInOld, $startInNew, $endInNew, $matches);
return $matches;
} | php | protected function getRowMatches($oldMatchData, $newMatchData)
{
$matches = array();
$startInOld = 0;
$startInNew = 0;
$endInOld = count($oldMatchData);
$endInNew = count($newMatchData);
$this->findRowMatches($newMatchData, $startInOld, $endInOld, $startInNew, $endInNew, $matches);
return $matches;
} | [
"protected",
"function",
"getRowMatches",
"(",
"$",
"oldMatchData",
",",
"$",
"newMatchData",
")",
"{",
"$",
"matches",
"=",
"array",
"(",
")",
";",
"$",
"startInOld",
"=",
"0",
";",
"$",
"startInNew",
"=",
"0",
";",
"$",
"endInOld",
"=",
"count",
"(",... | @param array $oldMatchData
@param array $newMatchData
@return array | [
"@param",
"array",
"$oldMatchData",
"@param",
"array",
"$newMatchData"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/Table/TableDiff.php#L308-L320 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/Table/TableDiff.php | TableDiff.findRowMatch | protected function findRowMatch($newMatchData, $startInOld, $endInOld, $startInNew, $endInNew)
{
$bestMatch = null;
$bestPercentage = 0;
foreach ($newMatchData as $newIndex => $oldMatches) {
if ($newIndex < $startInNew) {
continue;
}
if ($newIndex >= $endInNew) {
break;
}
foreach ($oldMatches as $oldIndex => $percentage) {
if ($oldIndex < $startInOld) {
continue;
}
if ($oldIndex >= $endInOld) {
break;
}
if ($percentage > $bestPercentage) {
$bestPercentage = $percentage;
$bestMatch = array(
'oldIndex' => $oldIndex,
'newIndex' => $newIndex,
'percentage' => $percentage,
);
}
}
}
if ($bestMatch !== null) {
return new RowMatch(
$bestMatch['newIndex'],
$bestMatch['oldIndex'],
$bestMatch['newIndex'] + 1,
$bestMatch['oldIndex'] + 1,
$bestMatch['percentage']
);
}
return;
} | php | protected function findRowMatch($newMatchData, $startInOld, $endInOld, $startInNew, $endInNew)
{
$bestMatch = null;
$bestPercentage = 0;
foreach ($newMatchData as $newIndex => $oldMatches) {
if ($newIndex < $startInNew) {
continue;
}
if ($newIndex >= $endInNew) {
break;
}
foreach ($oldMatches as $oldIndex => $percentage) {
if ($oldIndex < $startInOld) {
continue;
}
if ($oldIndex >= $endInOld) {
break;
}
if ($percentage > $bestPercentage) {
$bestPercentage = $percentage;
$bestMatch = array(
'oldIndex' => $oldIndex,
'newIndex' => $newIndex,
'percentage' => $percentage,
);
}
}
}
if ($bestMatch !== null) {
return new RowMatch(
$bestMatch['newIndex'],
$bestMatch['oldIndex'],
$bestMatch['newIndex'] + 1,
$bestMatch['oldIndex'] + 1,
$bestMatch['percentage']
);
}
return;
} | [
"protected",
"function",
"findRowMatch",
"(",
"$",
"newMatchData",
",",
"$",
"startInOld",
",",
"$",
"endInOld",
",",
"$",
"startInNew",
",",
"$",
"endInNew",
")",
"{",
"$",
"bestMatch",
"=",
"null",
";",
"$",
"bestPercentage",
"=",
"0",
";",
"foreach",
... | @param array $newMatchData
@param int $startInOld
@param int $endInOld
@param int $startInNew
@param int $endInNew
@return RowMatch|null | [
"@param",
"array",
"$newMatchData",
"@param",
"int",
"$startInOld",
"@param",
"int",
"$endInOld",
"@param",
"int",
"$startInNew",
"@param",
"int",
"$endInNew"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/Table/TableDiff.php#L373-L417 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/Table/TableDiff.php | TableDiff.diffRows | protected function diffRows($oldRow, $newRow, array &$appliedRowSpans, $forceExpansion = false)
{
// create tr dom element
$rowToClone = $newRow ?: $oldRow;
/* @var $diffRow \DOMElement */
$diffRow = $this->diffDom->importNode($rowToClone->getDomNode()->cloneNode(false), false);
$oldCells = $oldRow ? $oldRow->getCells() : array();
$newCells = $newRow ? $newRow->getCells() : array();
$position = new DiffRowPosition();
$extraRow = null;
/* @var $expandCells \DOMElement[] */
$expandCells = array();
/* @var $cellsWithMultipleRows \DOMElement[] */
$cellsWithMultipleRows = array();
$newCellCount = count($newCells);
while ($position->getIndexInNew() < $newCellCount) {
if (!$position->areColumnsEqual()) {
$type = $position->getLesserColumnType();
if ($type === 'new') {
$row = $newRow;
$targetRow = $extraRow;
} else {
$row = $oldRow;
$targetRow = $diffRow;
}
if ($row && $targetRow && (!$type === 'old' || isset($oldCells[$position->getIndexInOld()]))) {
$this->syncVirtualColumns($row, $position, $cellsWithMultipleRows, $targetRow, $type, true);
continue;
}
}
/* @var $newCell TableCell */
$newCell = $newCells[$position->getIndexInNew()];
/* @var $oldCell TableCell */
$oldCell = isset($oldCells[$position->getIndexInOld()]) ? $oldCells[$position->getIndexInOld()] : null;
if ($oldCell && $newCell->getColspan() != $oldCell->getColspan()) {
if (null === $extraRow) {
/* @var $extraRow \DOMElement */
$extraRow = $this->diffDom->importNode($rowToClone->getDomNode()->cloneNode(false), false);
}
if ($oldCell->getColspan() > $newCell->getColspan()) {
$this->diffCellsAndIncrementCounters(
$oldCell,
null,
$cellsWithMultipleRows,
$diffRow,
$position,
true
);
$this->syncVirtualColumns($newRow, $position, $cellsWithMultipleRows, $extraRow, 'new', true);
} else {
$this->diffCellsAndIncrementCounters(
null,
$newCell,
$cellsWithMultipleRows,
$extraRow,
$position,
true
);
$this->syncVirtualColumns($oldRow, $position, $cellsWithMultipleRows, $diffRow, 'old', true);
}
} else {
$diffCell = $this->diffCellsAndIncrementCounters(
$oldCell,
$newCell,
$cellsWithMultipleRows,
$diffRow,
$position
);
$expandCells[] = $diffCell;
}
}
$oldCellCount = count($oldCells);
while ($position->getIndexInOld() < $oldCellCount) {
$diffCell = $this->diffCellsAndIncrementCounters(
$oldCells[$position->getIndexInOld()],
null,
$cellsWithMultipleRows,
$diffRow,
$position
);
$expandCells[] = $diffCell;
}
if ($extraRow) {
foreach ($expandCells as $expandCell) {
$rowspan = $expandCell->getAttribute('rowspan') ?: 1;
$expandCell->setAttribute('rowspan', 1 + $rowspan);
}
}
if ($extraRow || $forceExpansion) {
foreach ($appliedRowSpans as $rowSpanCells) {
/* @var $rowSpanCells \DOMElement[] */
foreach ($rowSpanCells as $extendCell) {
$rowspan = $extendCell->getAttribute('rowspan') ?: 1;
$extendCell->setAttribute('rowspan', 1 + $rowspan);
}
}
}
if (!$forceExpansion) {
array_shift($appliedRowSpans);
$appliedRowSpans = array_values($appliedRowSpans);
}
$appliedRowSpans = array_merge($appliedRowSpans, array_values($cellsWithMultipleRows));
return array($diffRow, $extraRow);
} | php | protected function diffRows($oldRow, $newRow, array &$appliedRowSpans, $forceExpansion = false)
{
// create tr dom element
$rowToClone = $newRow ?: $oldRow;
/* @var $diffRow \DOMElement */
$diffRow = $this->diffDom->importNode($rowToClone->getDomNode()->cloneNode(false), false);
$oldCells = $oldRow ? $oldRow->getCells() : array();
$newCells = $newRow ? $newRow->getCells() : array();
$position = new DiffRowPosition();
$extraRow = null;
/* @var $expandCells \DOMElement[] */
$expandCells = array();
/* @var $cellsWithMultipleRows \DOMElement[] */
$cellsWithMultipleRows = array();
$newCellCount = count($newCells);
while ($position->getIndexInNew() < $newCellCount) {
if (!$position->areColumnsEqual()) {
$type = $position->getLesserColumnType();
if ($type === 'new') {
$row = $newRow;
$targetRow = $extraRow;
} else {
$row = $oldRow;
$targetRow = $diffRow;
}
if ($row && $targetRow && (!$type === 'old' || isset($oldCells[$position->getIndexInOld()]))) {
$this->syncVirtualColumns($row, $position, $cellsWithMultipleRows, $targetRow, $type, true);
continue;
}
}
/* @var $newCell TableCell */
$newCell = $newCells[$position->getIndexInNew()];
/* @var $oldCell TableCell */
$oldCell = isset($oldCells[$position->getIndexInOld()]) ? $oldCells[$position->getIndexInOld()] : null;
if ($oldCell && $newCell->getColspan() != $oldCell->getColspan()) {
if (null === $extraRow) {
/* @var $extraRow \DOMElement */
$extraRow = $this->diffDom->importNode($rowToClone->getDomNode()->cloneNode(false), false);
}
if ($oldCell->getColspan() > $newCell->getColspan()) {
$this->diffCellsAndIncrementCounters(
$oldCell,
null,
$cellsWithMultipleRows,
$diffRow,
$position,
true
);
$this->syncVirtualColumns($newRow, $position, $cellsWithMultipleRows, $extraRow, 'new', true);
} else {
$this->diffCellsAndIncrementCounters(
null,
$newCell,
$cellsWithMultipleRows,
$extraRow,
$position,
true
);
$this->syncVirtualColumns($oldRow, $position, $cellsWithMultipleRows, $diffRow, 'old', true);
}
} else {
$diffCell = $this->diffCellsAndIncrementCounters(
$oldCell,
$newCell,
$cellsWithMultipleRows,
$diffRow,
$position
);
$expandCells[] = $diffCell;
}
}
$oldCellCount = count($oldCells);
while ($position->getIndexInOld() < $oldCellCount) {
$diffCell = $this->diffCellsAndIncrementCounters(
$oldCells[$position->getIndexInOld()],
null,
$cellsWithMultipleRows,
$diffRow,
$position
);
$expandCells[] = $diffCell;
}
if ($extraRow) {
foreach ($expandCells as $expandCell) {
$rowspan = $expandCell->getAttribute('rowspan') ?: 1;
$expandCell->setAttribute('rowspan', 1 + $rowspan);
}
}
if ($extraRow || $forceExpansion) {
foreach ($appliedRowSpans as $rowSpanCells) {
/* @var $rowSpanCells \DOMElement[] */
foreach ($rowSpanCells as $extendCell) {
$rowspan = $extendCell->getAttribute('rowspan') ?: 1;
$extendCell->setAttribute('rowspan', 1 + $rowspan);
}
}
}
if (!$forceExpansion) {
array_shift($appliedRowSpans);
$appliedRowSpans = array_values($appliedRowSpans);
}
$appliedRowSpans = array_merge($appliedRowSpans, array_values($cellsWithMultipleRows));
return array($diffRow, $extraRow);
} | [
"protected",
"function",
"diffRows",
"(",
"$",
"oldRow",
",",
"$",
"newRow",
",",
"array",
"&",
"$",
"appliedRowSpans",
",",
"$",
"forceExpansion",
"=",
"false",
")",
"{",
"// create tr dom element",
"$",
"rowToClone",
"=",
"$",
"newRow",
"?",
":",
"$",
"o... | @param TableRow|null $oldRow
@param TableRow|null $newRow
@param array $appliedRowSpans
@param bool $forceExpansion
@return array | [
"@param",
"TableRow|null",
"$oldRow",
"@param",
"TableRow|null",
"$newRow",
"@param",
"array",
"$appliedRowSpans",
"@param",
"bool",
"$forceExpansion"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/Table/TableDiff.php#L427-L544 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/Table/TableDiff.php | TableDiff.getNewCellNode | protected function getNewCellNode(TableCell $oldCell = null, TableCell $newCell = null)
{
// If only one cell exists, use it
if (!$oldCell || !$newCell) {
$clone = $newCell
? $newCell->getDomNode()->cloneNode(false)
: $oldCell->getDomNode()->cloneNode(false);
} else {
$oldNode = $oldCell->getDomNode();
$newNode = $newCell->getDomNode();
/* @var $clone \DOMElement */
$clone = $newNode->cloneNode(false);
$oldRowspan = $oldNode->getAttribute('rowspan') ?: 1;
$oldColspan = $oldNode->getAttribute('colspan') ?: 1;
$newRowspan = $newNode->getAttribute('rowspan') ?: 1;
$newColspan = $newNode->getAttribute('colspan') ?: 1;
$clone->setAttribute('rowspan', max($oldRowspan, $newRowspan));
$clone->setAttribute('colspan', max($oldColspan, $newColspan));
}
return $this->diffDom->importNode($clone);
} | php | protected function getNewCellNode(TableCell $oldCell = null, TableCell $newCell = null)
{
// If only one cell exists, use it
if (!$oldCell || !$newCell) {
$clone = $newCell
? $newCell->getDomNode()->cloneNode(false)
: $oldCell->getDomNode()->cloneNode(false);
} else {
$oldNode = $oldCell->getDomNode();
$newNode = $newCell->getDomNode();
/* @var $clone \DOMElement */
$clone = $newNode->cloneNode(false);
$oldRowspan = $oldNode->getAttribute('rowspan') ?: 1;
$oldColspan = $oldNode->getAttribute('colspan') ?: 1;
$newRowspan = $newNode->getAttribute('rowspan') ?: 1;
$newColspan = $newNode->getAttribute('colspan') ?: 1;
$clone->setAttribute('rowspan', max($oldRowspan, $newRowspan));
$clone->setAttribute('colspan', max($oldColspan, $newColspan));
}
return $this->diffDom->importNode($clone);
} | [
"protected",
"function",
"getNewCellNode",
"(",
"TableCell",
"$",
"oldCell",
"=",
"null",
",",
"TableCell",
"$",
"newCell",
"=",
"null",
")",
"{",
"// If only one cell exists, use it",
"if",
"(",
"!",
"$",
"oldCell",
"||",
"!",
"$",
"newCell",
")",
"{",
"$",... | @param TableCell|null $oldCell
@param TableCell|null $newCell
@return \DOMElement | [
"@param",
"TableCell|null",
"$oldCell",
"@param",
"TableCell|null",
"$newCell"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/Table/TableDiff.php#L552-L576 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/Table/TableDiff.php | TableDiff.diffCells | protected function diffCells($oldCell, $newCell, $usingExtraRow = false)
{
$diffCell = $this->getNewCellNode($oldCell, $newCell);
$oldContent = $oldCell ? $this->getInnerHtml($oldCell->getDomNode()) : '';
$newContent = $newCell ? $this->getInnerHtml($newCell->getDomNode()) : '';
$htmlDiff = HtmlDiff::create(
mb_convert_encoding($oldContent, 'UTF-8', 'HTML-ENTITIES'),
mb_convert_encoding($newContent, 'UTF-8', 'HTML-ENTITIES'),
$this->config
);
$diff = $htmlDiff->build();
$this->setInnerHtml($diffCell, $diff);
if (null === $newCell) {
$diffCell->setAttribute('class', trim($diffCell->getAttribute('class').' del'));
}
if (null === $oldCell) {
$diffCell->setAttribute('class', trim($diffCell->getAttribute('class').' ins'));
}
if ($usingExtraRow) {
$diffCell->setAttribute('class', trim($diffCell->getAttribute('class').' extra-row'));
}
return $diffCell;
} | php | protected function diffCells($oldCell, $newCell, $usingExtraRow = false)
{
$diffCell = $this->getNewCellNode($oldCell, $newCell);
$oldContent = $oldCell ? $this->getInnerHtml($oldCell->getDomNode()) : '';
$newContent = $newCell ? $this->getInnerHtml($newCell->getDomNode()) : '';
$htmlDiff = HtmlDiff::create(
mb_convert_encoding($oldContent, 'UTF-8', 'HTML-ENTITIES'),
mb_convert_encoding($newContent, 'UTF-8', 'HTML-ENTITIES'),
$this->config
);
$diff = $htmlDiff->build();
$this->setInnerHtml($diffCell, $diff);
if (null === $newCell) {
$diffCell->setAttribute('class', trim($diffCell->getAttribute('class').' del'));
}
if (null === $oldCell) {
$diffCell->setAttribute('class', trim($diffCell->getAttribute('class').' ins'));
}
if ($usingExtraRow) {
$diffCell->setAttribute('class', trim($diffCell->getAttribute('class').' extra-row'));
}
return $diffCell;
} | [
"protected",
"function",
"diffCells",
"(",
"$",
"oldCell",
",",
"$",
"newCell",
",",
"$",
"usingExtraRow",
"=",
"false",
")",
"{",
"$",
"diffCell",
"=",
"$",
"this",
"->",
"getNewCellNode",
"(",
"$",
"oldCell",
",",
"$",
"newCell",
")",
";",
"$",
"oldC... | @param TableCell|null $oldCell
@param TableCell|null $newCell
@param bool $usingExtraRow
@return \DOMElement | [
"@param",
"TableCell|null",
"$oldCell",
"@param",
"TableCell|null",
"$newCell",
"@param",
"bool",
"$usingExtraRow"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/Table/TableDiff.php#L585-L614 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/Table/TableDiff.php | TableDiff.createDocumentWithHtml | protected function createDocumentWithHtml($text)
{
$dom = new \DOMDocument();
$dom->loadHTML(mb_convert_encoding(
$this->purifier->purify(mb_convert_encoding($text, $this->config->getEncoding(), mb_detect_encoding($text))),
'HTML-ENTITIES',
$this->config->getEncoding()
));
return $dom;
} | php | protected function createDocumentWithHtml($text)
{
$dom = new \DOMDocument();
$dom->loadHTML(mb_convert_encoding(
$this->purifier->purify(mb_convert_encoding($text, $this->config->getEncoding(), mb_detect_encoding($text))),
'HTML-ENTITIES',
$this->config->getEncoding()
));
return $dom;
} | [
"protected",
"function",
"createDocumentWithHtml",
"(",
"$",
"text",
")",
"{",
"$",
"dom",
"=",
"new",
"\\",
"DOMDocument",
"(",
")",
";",
"$",
"dom",
"->",
"loadHTML",
"(",
"mb_convert_encoding",
"(",
"$",
"this",
"->",
"purifier",
"->",
"purify",
"(",
... | @param string $text
@return \DOMDocument | [
"@param",
"string",
"$text"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/Table/TableDiff.php#L627-L637 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.