repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1
value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
thephpleague/climate | src/Util/Output.php | Output.getAvailable | public function getAvailable()
{
$writers = [];
foreach ($this->writers as $key => $writer) {
$writers[$key] = $this->getReadable($writer);
}
return $writers;
} | php | public function getAvailable()
{
$writers = [];
foreach ($this->writers as $key => $writer) {
$writers[$key] = $this->getReadable($writer);
}
return $writers;
} | [
"public",
"function",
"getAvailable",
"(",
")",
"{",
"$",
"writers",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"writers",
"as",
"$",
"key",
"=>",
"$",
"writer",
")",
"{",
"$",
"writers",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
... | Get the currently available writers
@return array | [
"Get",
"the",
"currently",
"available",
"writers"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Util/Output.php#L160-L169 | train |
thephpleague/climate | src/Util/Output.php | Output.write | public function write($content)
{
if ($this->new_line) {
$content .= PHP_EOL;
}
foreach ($this->getCurrentWriters() as $writer) {
$writer->write($content);
}
$this->resetOneTimers();
} | php | public function write($content)
{
if ($this->new_line) {
$content .= PHP_EOL;
}
foreach ($this->getCurrentWriters() as $writer) {
$writer->write($content);
}
$this->resetOneTimers();
} | [
"public",
"function",
"write",
"(",
"$",
"content",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"new_line",
")",
"{",
"$",
"content",
".=",
"PHP_EOL",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"getCurrentWriters",
"(",
")",
"as",
"$",
"writer",
")",
... | Write the content using the provided writer
@param string $content | [
"Write",
"the",
"content",
"using",
"the",
"provided",
"writer"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Util/Output.php#L176-L187 | train |
thephpleague/climate | src/Util/Output.php | Output.getWriters | protected function getWriters($keys)
{
$writers = array_flip(Helper::toArray($keys));
return Helper::flatten(array_intersect_key($this->writers, $writers));
} | php | protected function getWriters($keys)
{
$writers = array_flip(Helper::toArray($keys));
return Helper::flatten(array_intersect_key($this->writers, $writers));
} | [
"protected",
"function",
"getWriters",
"(",
"$",
"keys",
")",
"{",
"$",
"writers",
"=",
"array_flip",
"(",
"Helper",
"::",
"toArray",
"(",
"$",
"keys",
")",
")",
";",
"return",
"Helper",
"::",
"flatten",
"(",
"array_intersect_key",
"(",
"$",
"this",
"->"... | Get the writers based on their keys
@param string|array $keys
@return array | [
"Get",
"the",
"writers",
"based",
"on",
"their",
"keys"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Util/Output.php#L287-L292 | train |
thephpleague/climate | src/Argument/Manager.php | Manager.add | public function add($argument, array $options = [])
{
if (is_array($argument)) {
$this->addMany($argument);
return;
}
if (is_string($argument)) {
$argument = Argument::createFromArray($argument, $options);
}
if (!$argument instanceof Argument) {
throw new InvalidArgumentException('Please provide an argument name or object.');
}
$this->arguments[$argument->name()] = $argument;
} | php | public function add($argument, array $options = [])
{
if (is_array($argument)) {
$this->addMany($argument);
return;
}
if (is_string($argument)) {
$argument = Argument::createFromArray($argument, $options);
}
if (!$argument instanceof Argument) {
throw new InvalidArgumentException('Please provide an argument name or object.');
}
$this->arguments[$argument->name()] = $argument;
} | [
"public",
"function",
"add",
"(",
"$",
"argument",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"argument",
")",
")",
"{",
"$",
"this",
"->",
"addMany",
"(",
"$",
"argument",
")",
";",
"return",
";",
"}"... | Add an argument.
@param Argument|string|array $argument
@param $options
@return void
@throws InvalidArgumentException if $argument isn't an array or Argument object. | [
"Add",
"an",
"argument",
"."
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Argument/Manager.php#L61-L77 | train |
thephpleague/climate | src/Argument/Manager.php | Manager.addMany | protected function addMany(array $arguments = [])
{
foreach ($arguments as $name => $options) {
$this->add($name, $options);
}
} | php | protected function addMany(array $arguments = [])
{
foreach ($arguments as $name => $options) {
$this->add($name, $options);
}
} | [
"protected",
"function",
"addMany",
"(",
"array",
"$",
"arguments",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"arguments",
"as",
"$",
"name",
"=>",
"$",
"options",
")",
"{",
"$",
"this",
"->",
"add",
"(",
"$",
"name",
",",
"$",
"options",
")",
... | Add multiple arguments to a CLImate script.
@param array $arguments | [
"Add",
"multiple",
"arguments",
"to",
"a",
"CLImate",
"script",
"."
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Argument/Manager.php#L84-L89 | train |
thephpleague/climate | src/Argument/Manager.php | Manager.getArray | public function getArray($name)
{
return isset($this->arguments[$name]) ? $this->arguments[$name]->values() : [];
} | php | public function getArray($name)
{
return isset($this->arguments[$name]) ? $this->arguments[$name]->values() : [];
} | [
"public",
"function",
"getArray",
"(",
"$",
"name",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"arguments",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"this",
"->",
"arguments",
"[",
"$",
"name",
"]",
"->",
"values",
"(",
")",
":",
"[",
"]",... | Retrieve an argument's all values as an array.
@param string $name
@return string[]|int[]|float[]|bool[] | [
"Retrieve",
"an",
"argument",
"s",
"all",
"values",
"as",
"an",
"array",
"."
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Argument/Manager.php#L119-L122 | train |
thephpleague/climate | src/Argument/Manager.php | Manager.defined | public function defined($name, array $argv = null)
{
// The argument isn't defined if it's not defined by the calling code.
if (!$this->exists($name)) {
return false;
}
$argument = $this->arguments[$name];
$command_arguments = $this->parser->arguments($argv);
foreach ($command_arguments as $command_argument) {
if ($this->isArgument($argument, $command_argument)) {
return true;
}
}
return false;
} | php | public function defined($name, array $argv = null)
{
// The argument isn't defined if it's not defined by the calling code.
if (!$this->exists($name)) {
return false;
}
$argument = $this->arguments[$name];
$command_arguments = $this->parser->arguments($argv);
foreach ($command_arguments as $command_argument) {
if ($this->isArgument($argument, $command_argument)) {
return true;
}
}
return false;
} | [
"public",
"function",
"defined",
"(",
"$",
"name",
",",
"array",
"$",
"argv",
"=",
"null",
")",
"{",
"// The argument isn't defined if it's not defined by the calling code.",
"if",
"(",
"!",
"$",
"this",
"->",
"exists",
"(",
"$",
"name",
")",
")",
"{",
"return... | Determine if an argument has been defined on the command line.
This can be useful for making sure an argument is present on the command
line before parse()'ing them into argument objects.
@param string $name
@param array $argv
@return bool | [
"Determine",
"if",
"an",
"argument",
"has",
"been",
"defined",
"on",
"the",
"command",
"line",
"."
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Argument/Manager.php#L145-L162 | train |
thephpleague/climate | src/Argument/Manager.php | Manager.isArgument | protected function isArgument($argument, $command_argument)
{
$possibilities = [
$argument->prefix() => "-{$argument->prefix()}",
$argument->longPrefix() => "--{$argument->longPrefix()}",
];
foreach ($possibilities as $key => $search) {
if ($key && strpos($command_argument, $search) === 0) {
return true;
}
}
return false;
} | php | protected function isArgument($argument, $command_argument)
{
$possibilities = [
$argument->prefix() => "-{$argument->prefix()}",
$argument->longPrefix() => "--{$argument->longPrefix()}",
];
foreach ($possibilities as $key => $search) {
if ($key && strpos($command_argument, $search) === 0) {
return true;
}
}
return false;
} | [
"protected",
"function",
"isArgument",
"(",
"$",
"argument",
",",
"$",
"command_argument",
")",
"{",
"$",
"possibilities",
"=",
"[",
"$",
"argument",
"->",
"prefix",
"(",
")",
"=>",
"\"-{$argument->prefix()}\"",
",",
"$",
"argument",
"->",
"longPrefix",
"(",
... | Check if the defined argument matches the command argument.
@param Argument $argument
@param string $command_argument
@return bool | [
"Check",
"if",
"the",
"defined",
"argument",
"matches",
"the",
"command",
"argument",
"."
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Argument/Manager.php#L172-L186 | train |
8p/EightPointsGuzzleBundle | src/DependencyInjection/EightPointsGuzzleExtension.php | EightPointsGuzzleExtension.load | public function load(array $configs, ContainerBuilder $container)
{
$configPath = implode(DIRECTORY_SEPARATOR, [__DIR__, '..', 'Resources', 'config']);
$loader = new XmlFileLoader($container, new FileLocator($configPath));
$loader->load('services.xml');
$configuration = new Configuration($this->getAlias(), $container->getParameter('kernel.debug'), $this->plugins);
$config = $this->processConfiguration($configuration, $configs);
$logging = $config['logging'] === true;
$profiling = $config['profiling'] === true;
foreach ($this->plugins as $plugin) {
$container->addObjectResource(new \ReflectionClass(get_class($plugin)));
$plugin->load($config, $container);
}
if ($logging) {
$this->defineTwigDebugExtension($container);
$this->defineLogger($container);
$this->defineDataCollector($container, $config['slow_response_time'] / 1000);
$this->defineFormatter($container);
$this->defineSymfonyLogFormatter($container);
$this->defineSymfonyLogMiddleware($container);
}
foreach ($config['clients'] as $name => $options) {
$argument = [
'base_uri' => $options['base_url'],
'handler' => $this->createHandler($container, $name, $options, $logging, $profiling)
];
// if present, add default options to the constructor argument for the Guzzle client
if (isset($options['options']) && is_array($options['options'])) {
foreach ($options['options'] as $key => $value) {
if ($value === null || (is_array($value) && count($value) === 0)) {
continue;
}
$argument[$key] = $value;
}
}
$client = new Definition($options['class']);
$client->addArgument($argument);
$client->setPublic(true);
$client->setLazy($options['lazy']);
// set service name based on client name
$serviceName = sprintf('%s.client.%s', $this->getAlias(), $name);
$container->setDefinition($serviceName, $client);
}
} | php | public function load(array $configs, ContainerBuilder $container)
{
$configPath = implode(DIRECTORY_SEPARATOR, [__DIR__, '..', 'Resources', 'config']);
$loader = new XmlFileLoader($container, new FileLocator($configPath));
$loader->load('services.xml');
$configuration = new Configuration($this->getAlias(), $container->getParameter('kernel.debug'), $this->plugins);
$config = $this->processConfiguration($configuration, $configs);
$logging = $config['logging'] === true;
$profiling = $config['profiling'] === true;
foreach ($this->plugins as $plugin) {
$container->addObjectResource(new \ReflectionClass(get_class($plugin)));
$plugin->load($config, $container);
}
if ($logging) {
$this->defineTwigDebugExtension($container);
$this->defineLogger($container);
$this->defineDataCollector($container, $config['slow_response_time'] / 1000);
$this->defineFormatter($container);
$this->defineSymfonyLogFormatter($container);
$this->defineSymfonyLogMiddleware($container);
}
foreach ($config['clients'] as $name => $options) {
$argument = [
'base_uri' => $options['base_url'],
'handler' => $this->createHandler($container, $name, $options, $logging, $profiling)
];
// if present, add default options to the constructor argument for the Guzzle client
if (isset($options['options']) && is_array($options['options'])) {
foreach ($options['options'] as $key => $value) {
if ($value === null || (is_array($value) && count($value) === 0)) {
continue;
}
$argument[$key] = $value;
}
}
$client = new Definition($options['class']);
$client->addArgument($argument);
$client->setPublic(true);
$client->setLazy($options['lazy']);
// set service name based on client name
$serviceName = sprintf('%s.client.%s', $this->getAlias(), $name);
$container->setDefinition($serviceName, $client);
}
} | [
"public",
"function",
"load",
"(",
"array",
"$",
"configs",
",",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"configPath",
"=",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"[",
"__DIR__",
",",
"'..'",
",",
"'Resources'",
",",
"'config'",
"]",
")",
... | Loads the Guzzle configuration.
@param array $configs an array of configuration settings
@param \Symfony\Component\DependencyInjection\ContainerBuilder $container a ContainerBuilder instance
@throws \InvalidArgumentException
@throws \Symfony\Component\DependencyInjection\Exception\BadMethodCallException
@throws \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
@throws \Exception
@return void | [
"Loads",
"the",
"Guzzle",
"configuration",
"."
] | bfb387774313ee2bccc5dad4e81047334f50ea86 | https://github.com/8p/EightPointsGuzzleBundle/blob/bfb387774313ee2bccc5dad4e81047334f50ea86/src/DependencyInjection/EightPointsGuzzleExtension.php#L50-L102 | train |
8p/EightPointsGuzzleBundle | src/DependencyInjection/EightPointsGuzzleExtension.php | EightPointsGuzzleExtension.defineDataCollector | protected function defineDataCollector(ContainerBuilder $container, float $slowResponseTime)
{
$dataCollectorDefinition = new Definition('%eight_points_guzzle.data_collector.class%');
$dataCollectorDefinition->addArgument(new Reference('eight_points_guzzle.logger'));
$dataCollectorDefinition->addArgument($slowResponseTime);
$dataCollectorDefinition->setPublic(false);
$dataCollectorDefinition->addTag('data_collector', [
'id' => 'eight_points_guzzle',
'template' => '@EightPointsGuzzle/debug.html.twig',
]);
$container->setDefinition('eight_points_guzzle.data_collector', $dataCollectorDefinition);
} | php | protected function defineDataCollector(ContainerBuilder $container, float $slowResponseTime)
{
$dataCollectorDefinition = new Definition('%eight_points_guzzle.data_collector.class%');
$dataCollectorDefinition->addArgument(new Reference('eight_points_guzzle.logger'));
$dataCollectorDefinition->addArgument($slowResponseTime);
$dataCollectorDefinition->setPublic(false);
$dataCollectorDefinition->addTag('data_collector', [
'id' => 'eight_points_guzzle',
'template' => '@EightPointsGuzzle/debug.html.twig',
]);
$container->setDefinition('eight_points_guzzle.data_collector', $dataCollectorDefinition);
} | [
"protected",
"function",
"defineDataCollector",
"(",
"ContainerBuilder",
"$",
"container",
",",
"float",
"$",
"slowResponseTime",
")",
"{",
"$",
"dataCollectorDefinition",
"=",
"new",
"Definition",
"(",
"'%eight_points_guzzle.data_collector.class%'",
")",
";",
"$",
"dat... | Define Data Collector
@param \Symfony\Component\DependencyInjection\ContainerBuilder $container
@param float $slowResponseTime
@throws \Symfony\Component\DependencyInjection\Exception\BadMethodCallException
@return void | [
"Define",
"Data",
"Collector"
] | bfb387774313ee2bccc5dad4e81047334f50ea86 | https://github.com/8p/EightPointsGuzzleBundle/blob/bfb387774313ee2bccc5dad4e81047334f50ea86/src/DependencyInjection/EightPointsGuzzleExtension.php#L201-L212 | train |
8p/EightPointsGuzzleBundle | src/DependencyInjection/EightPointsGuzzleExtension.php | EightPointsGuzzleExtension.defineRequestTimeMiddleware | protected function defineRequestTimeMiddleware(ContainerBuilder $container, Definition $handler, string $clientName)
{
$requestTimeMiddlewareDefinitionName = sprintf('eight_points_guzzle.middleware.request_time.%s', $clientName);
$requestTimeMiddlewareDefinition = new Definition('%eight_points_guzzle.middleware.request_time.class%');
$requestTimeMiddlewareDefinition->addArgument(new Reference('eight_points_guzzle.logger'));
$requestTimeMiddlewareDefinition->addArgument(new Reference('eight_points_guzzle.data_collector'));
$requestTimeMiddlewareDefinition->setPublic(true);
$container->setDefinition($requestTimeMiddlewareDefinitionName, $requestTimeMiddlewareDefinition);
$requestTimeExpression = new Expression(sprintf("service('%s')", $requestTimeMiddlewareDefinitionName));
$handler->addMethodCall('after', ['log', $requestTimeExpression, 'request_time']);
} | php | protected function defineRequestTimeMiddleware(ContainerBuilder $container, Definition $handler, string $clientName)
{
$requestTimeMiddlewareDefinitionName = sprintf('eight_points_guzzle.middleware.request_time.%s', $clientName);
$requestTimeMiddlewareDefinition = new Definition('%eight_points_guzzle.middleware.request_time.class%');
$requestTimeMiddlewareDefinition->addArgument(new Reference('eight_points_guzzle.logger'));
$requestTimeMiddlewareDefinition->addArgument(new Reference('eight_points_guzzle.data_collector'));
$requestTimeMiddlewareDefinition->setPublic(true);
$container->setDefinition($requestTimeMiddlewareDefinitionName, $requestTimeMiddlewareDefinition);
$requestTimeExpression = new Expression(sprintf("service('%s')", $requestTimeMiddlewareDefinitionName));
$handler->addMethodCall('after', ['log', $requestTimeExpression, 'request_time']);
} | [
"protected",
"function",
"defineRequestTimeMiddleware",
"(",
"ContainerBuilder",
"$",
"container",
",",
"Definition",
"$",
"handler",
",",
"string",
"$",
"clientName",
")",
"{",
"$",
"requestTimeMiddlewareDefinitionName",
"=",
"sprintf",
"(",
"'eight_points_guzzle.middlew... | Define Request Time Middleware
@param \Symfony\Component\DependencyInjection\ContainerBuilder $container
@param \Symfony\Component\DependencyInjection\Definition $handler
@param string $clientName
@return void | [
"Define",
"Request",
"Time",
"Middleware"
] | bfb387774313ee2bccc5dad4e81047334f50ea86 | https://github.com/8p/EightPointsGuzzleBundle/blob/bfb387774313ee2bccc5dad4e81047334f50ea86/src/DependencyInjection/EightPointsGuzzleExtension.php#L239-L250 | train |
8p/EightPointsGuzzleBundle | src/DependencyInjection/EightPointsGuzzleExtension.php | EightPointsGuzzleExtension.defineLogMiddleware | protected function defineLogMiddleware(ContainerBuilder $container, Definition $handler, string $clientName)
{
$logMiddlewareDefinitionName = sprintf('eight_points_guzzle.middleware.log.%s', $clientName);
$logMiddlewareDefinition = new Definition('%eight_points_guzzle.middleware.log.class%');
$logMiddlewareDefinition->addArgument(new Reference('eight_points_guzzle.logger'));
$logMiddlewareDefinition->addArgument(new Reference('eight_points_guzzle.formatter'));
$logMiddlewareDefinition->setPublic(true);
$container->setDefinition($logMiddlewareDefinitionName, $logMiddlewareDefinition);
$logExpression = new Expression(sprintf("service('%s').log()", $logMiddlewareDefinitionName));
$handler->addMethodCall('push', [$logExpression, 'log']);
} | php | protected function defineLogMiddleware(ContainerBuilder $container, Definition $handler, string $clientName)
{
$logMiddlewareDefinitionName = sprintf('eight_points_guzzle.middleware.log.%s', $clientName);
$logMiddlewareDefinition = new Definition('%eight_points_guzzle.middleware.log.class%');
$logMiddlewareDefinition->addArgument(new Reference('eight_points_guzzle.logger'));
$logMiddlewareDefinition->addArgument(new Reference('eight_points_guzzle.formatter'));
$logMiddlewareDefinition->setPublic(true);
$container->setDefinition($logMiddlewareDefinitionName, $logMiddlewareDefinition);
$logExpression = new Expression(sprintf("service('%s').log()", $logMiddlewareDefinitionName));
$handler->addMethodCall('push', [$logExpression, 'log']);
} | [
"protected",
"function",
"defineLogMiddleware",
"(",
"ContainerBuilder",
"$",
"container",
",",
"Definition",
"$",
"handler",
",",
"string",
"$",
"clientName",
")",
"{",
"$",
"logMiddlewareDefinitionName",
"=",
"sprintf",
"(",
"'eight_points_guzzle.middleware.log.%s'",
... | Define Log Middleware for client
@param \Symfony\Component\DependencyInjection\ContainerBuilder $container
@param \Symfony\Component\DependencyInjection\Definition $handler
@param string $clientName
@return void | [
"Define",
"Log",
"Middleware",
"for",
"client"
] | bfb387774313ee2bccc5dad4e81047334f50ea86 | https://github.com/8p/EightPointsGuzzleBundle/blob/bfb387774313ee2bccc5dad4e81047334f50ea86/src/DependencyInjection/EightPointsGuzzleExtension.php#L261-L272 | train |
8p/EightPointsGuzzleBundle | src/DependencyInjection/EightPointsGuzzleExtension.php | EightPointsGuzzleExtension.defineProfileMiddleware | protected function defineProfileMiddleware(ContainerBuilder $container, Definition $handler, string $clientName)
{
$profileMiddlewareDefinitionName = sprintf('eight_points_guzzle.middleware.profile.%s', $clientName);
$profileMiddlewareDefinition = new Definition('%eight_points_guzzle.middleware.profile.class%');
$profileMiddlewareDefinition->addArgument(new Reference('debug.stopwatch'));
$profileMiddlewareDefinition->setPublic(true);
$container->setDefinition($profileMiddlewareDefinitionName, $profileMiddlewareDefinition);
$profileExpression = new Expression(sprintf("service('%s').profile()", $profileMiddlewareDefinitionName));
$handler->addMethodCall('push', [$profileExpression, 'profile']);
} | php | protected function defineProfileMiddleware(ContainerBuilder $container, Definition $handler, string $clientName)
{
$profileMiddlewareDefinitionName = sprintf('eight_points_guzzle.middleware.profile.%s', $clientName);
$profileMiddlewareDefinition = new Definition('%eight_points_guzzle.middleware.profile.class%');
$profileMiddlewareDefinition->addArgument(new Reference('debug.stopwatch'));
$profileMiddlewareDefinition->setPublic(true);
$container->setDefinition($profileMiddlewareDefinitionName, $profileMiddlewareDefinition);
$profileExpression = new Expression(sprintf("service('%s').profile()", $profileMiddlewareDefinitionName));
$handler->addMethodCall('push', [$profileExpression, 'profile']);
} | [
"protected",
"function",
"defineProfileMiddleware",
"(",
"ContainerBuilder",
"$",
"container",
",",
"Definition",
"$",
"handler",
",",
"string",
"$",
"clientName",
")",
"{",
"$",
"profileMiddlewareDefinitionName",
"=",
"sprintf",
"(",
"'eight_points_guzzle.middleware.prof... | Define Profile Middleware for client
@param \Symfony\Component\DependencyInjection\ContainerBuilder $container
@param \Symfony\Component\DependencyInjection\Definition $handler
@param string $clientName
@return void | [
"Define",
"Profile",
"Middleware",
"for",
"client"
] | bfb387774313ee2bccc5dad4e81047334f50ea86 | https://github.com/8p/EightPointsGuzzleBundle/blob/bfb387774313ee2bccc5dad4e81047334f50ea86/src/DependencyInjection/EightPointsGuzzleExtension.php#L283-L293 | train |
8p/EightPointsGuzzleBundle | src/DependencyInjection/EightPointsGuzzleExtension.php | EightPointsGuzzleExtension.createEventMiddleware | protected function createEventMiddleware(string $name) : Definition
{
$eventMiddleWare = new Definition('%eight_points_guzzle.middleware.event_dispatcher.class%');
$eventMiddleWare->addArgument(new Reference('event_dispatcher'));
$eventMiddleWare->addArgument($name);
$eventMiddleWare->setPublic(true);
return $eventMiddleWare;
} | php | protected function createEventMiddleware(string $name) : Definition
{
$eventMiddleWare = new Definition('%eight_points_guzzle.middleware.event_dispatcher.class%');
$eventMiddleWare->addArgument(new Reference('event_dispatcher'));
$eventMiddleWare->addArgument($name);
$eventMiddleWare->setPublic(true);
return $eventMiddleWare;
} | [
"protected",
"function",
"createEventMiddleware",
"(",
"string",
"$",
"name",
")",
":",
"Definition",
"{",
"$",
"eventMiddleWare",
"=",
"new",
"Definition",
"(",
"'%eight_points_guzzle.middleware.event_dispatcher.class%'",
")",
";",
"$",
"eventMiddleWare",
"->",
"addArg... | Create Middleware For dispatching events
@param string $name
@return \Symfony\Component\DependencyInjection\Definition | [
"Create",
"Middleware",
"For",
"dispatching",
"events"
] | bfb387774313ee2bccc5dad4e81047334f50ea86 | https://github.com/8p/EightPointsGuzzleBundle/blob/bfb387774313ee2bccc5dad4e81047334f50ea86/src/DependencyInjection/EightPointsGuzzleExtension.php#L313-L321 | train |
8p/EightPointsGuzzleBundle | src/Middleware/ProfileMiddleware.php | ProfileMiddleware.profile | public function profile() : \Closure
{
$stopwatch = $this->stopwatch;
return function (callable $handler) use ($stopwatch) {
return function ($request, array $options) use ($handler, $stopwatch) {
$event = $stopwatch->start(
sprintf('%s %s', $request->getMethod(), $request->getUri()),
'eight_points_guzzle'
);
return $handler($request, $options)->then(
function ($response) use ($event) {
$event->stop();
return $response;
},
function ($reason) use ($event) {
$event->stop();
return \GuzzleHttp\Promise\rejection_for($reason);
}
);
};
};
} | php | public function profile() : \Closure
{
$stopwatch = $this->stopwatch;
return function (callable $handler) use ($stopwatch) {
return function ($request, array $options) use ($handler, $stopwatch) {
$event = $stopwatch->start(
sprintf('%s %s', $request->getMethod(), $request->getUri()),
'eight_points_guzzle'
);
return $handler($request, $options)->then(
function ($response) use ($event) {
$event->stop();
return $response;
},
function ($reason) use ($event) {
$event->stop();
return \GuzzleHttp\Promise\rejection_for($reason);
}
);
};
};
} | [
"public",
"function",
"profile",
"(",
")",
":",
"\\",
"Closure",
"{",
"$",
"stopwatch",
"=",
"$",
"this",
"->",
"stopwatch",
";",
"return",
"function",
"(",
"callable",
"$",
"handler",
")",
"use",
"(",
"$",
"stopwatch",
")",
"{",
"return",
"function",
... | Profiling each Request
@return \Closure | [
"Profiling",
"each",
"Request"
] | bfb387774313ee2bccc5dad4e81047334f50ea86 | https://github.com/8p/EightPointsGuzzleBundle/blob/bfb387774313ee2bccc5dad4e81047334f50ea86/src/Middleware/ProfileMiddleware.php#L27-L55 | train |
8p/EightPointsGuzzleBundle | src/DependencyInjection/Compiler/EventHandlerCompilerPass.php | EventHandlerCompilerPass.process | public function process(ContainerBuilder $container)
{
$taggedServices = $container->findTaggedServiceIds('kernel.event_listener');
foreach ($taggedServices as $id => $tags) {
foreach ($tags as $attributes) {
if (isset($attributes['service']) && in_array($attributes['event'], GuzzleEvents::EVENTS, true)) {
$container->getDefinition($id)->addMethodCall(
'setServiceName',
[$attributes['service']]
);
}
}
}
} | php | public function process(ContainerBuilder $container)
{
$taggedServices = $container->findTaggedServiceIds('kernel.event_listener');
foreach ($taggedServices as $id => $tags) {
foreach ($tags as $attributes) {
if (isset($attributes['service']) && in_array($attributes['event'], GuzzleEvents::EVENTS, true)) {
$container->getDefinition($id)->addMethodCall(
'setServiceName',
[$attributes['service']]
);
}
}
}
} | [
"public",
"function",
"process",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"taggedServices",
"=",
"$",
"container",
"->",
"findTaggedServiceIds",
"(",
"'kernel.event_listener'",
")",
";",
"foreach",
"(",
"$",
"taggedServices",
"as",
"$",
"id",
"=... | We tag handlers with specific services to listen too.
We get all event tagged services from the container.
We then go through each event, and look for the value eight_points_guzzle_bundle.
For each one we find, we check if the service key is set, and then
call setServiceName on each EventListener.
@param \Symfony\Component\DependencyInjection\ContainerBuilder $container
@throws \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
@return void | [
"We",
"tag",
"handlers",
"with",
"specific",
"services",
"to",
"listen",
"too",
"."
] | bfb387774313ee2bccc5dad4e81047334f50ea86 | https://github.com/8p/EightPointsGuzzleBundle/blob/bfb387774313ee2bccc5dad4e81047334f50ea86/src/DependencyInjection/Compiler/EventHandlerCompilerPass.php#L25-L39 | train |
8p/EightPointsGuzzleBundle | src/Middleware/LogMiddleware.php | LogMiddleware.log | public function log() : \Closure
{
$logger = $this->logger;
$formatter = $this->formatter;
return function (callable $handler) use ($logger, $formatter) {
return function ($request, array $options) use ($handler, $logger, $formatter) {
// generate id that will be used to supplement the log with information
$requestId = uniqid('eight_points_guzzle_');
// initial registration of log
$logger->info('', compact('request', 'requestId'));
// this id will be used by RequestTimeMiddleware
$options['request_id'] = $requestId;
return $handler($request, $options)->then(
function ($response) use ($logger, $request, $formatter, $requestId) {
$message = $formatter->format($request, $response);
$context = compact('request', 'response', 'requestId');
$logger->info($message, $context);
return $response;
},
function ($reason) use ($logger, $request, $formatter, $requestId) {
$response = $reason instanceof RequestException ? $reason->getResponse() : null;
$message = $formatter->format($request, $response, $reason);
$context = compact('request', 'response', 'requestId');
$logger->notice($message, $context);
return \GuzzleHttp\Promise\rejection_for($reason);
}
);
};
};
} | php | public function log() : \Closure
{
$logger = $this->logger;
$formatter = $this->formatter;
return function (callable $handler) use ($logger, $formatter) {
return function ($request, array $options) use ($handler, $logger, $formatter) {
// generate id that will be used to supplement the log with information
$requestId = uniqid('eight_points_guzzle_');
// initial registration of log
$logger->info('', compact('request', 'requestId'));
// this id will be used by RequestTimeMiddleware
$options['request_id'] = $requestId;
return $handler($request, $options)->then(
function ($response) use ($logger, $request, $formatter, $requestId) {
$message = $formatter->format($request, $response);
$context = compact('request', 'response', 'requestId');
$logger->info($message, $context);
return $response;
},
function ($reason) use ($logger, $request, $formatter, $requestId) {
$response = $reason instanceof RequestException ? $reason->getResponse() : null;
$message = $formatter->format($request, $response, $reason);
$context = compact('request', 'response', 'requestId');
$logger->notice($message, $context);
return \GuzzleHttp\Promise\rejection_for($reason);
}
);
};
};
} | [
"public",
"function",
"log",
"(",
")",
":",
"\\",
"Closure",
"{",
"$",
"logger",
"=",
"$",
"this",
"->",
"logger",
";",
"$",
"formatter",
"=",
"$",
"this",
"->",
"formatter",
";",
"return",
"function",
"(",
"callable",
"$",
"handler",
")",
"use",
"("... | Logging each Request
@return \Closure | [
"Logging",
"each",
"Request"
] | bfb387774313ee2bccc5dad4e81047334f50ea86 | https://github.com/8p/EightPointsGuzzleBundle/blob/bfb387774313ee2bccc5dad4e81047334f50ea86/src/Middleware/LogMiddleware.php#L32-L74 | train |
8p/EightPointsGuzzleBundle | src/EightPointsGuzzleBundle.php | EightPointsGuzzleBundle.getContainerExtension | public function getContainerExtension() : ExtensionInterface
{
if ($this->extension === null) {
$this->extension = new EightPointsGuzzleExtension($this->plugins);
}
return $this->extension;
} | php | public function getContainerExtension() : ExtensionInterface
{
if ($this->extension === null) {
$this->extension = new EightPointsGuzzleExtension($this->plugins);
}
return $this->extension;
} | [
"public",
"function",
"getContainerExtension",
"(",
")",
":",
"ExtensionInterface",
"{",
"if",
"(",
"$",
"this",
"->",
"extension",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"extension",
"=",
"new",
"EightPointsGuzzleExtension",
"(",
"$",
"this",
"->",
"pl... | Overwrite getContainerExtension
- no naming convention of alias needed
- extension class can be moved easily now
@return \Symfony\Component\DependencyInjection\Extension\ExtensionInterface The container extension | [
"Overwrite",
"getContainerExtension",
"-",
"no",
"naming",
"convention",
"of",
"alias",
"needed",
"-",
"extension",
"class",
"can",
"be",
"moved",
"easily",
"now"
] | bfb387774313ee2bccc5dad4e81047334f50ea86 | https://github.com/8p/EightPointsGuzzleBundle/blob/bfb387774313ee2bccc5dad4e81047334f50ea86/src/EightPointsGuzzleBundle.php#L52-L59 | train |
8p/EightPointsGuzzleBundle | src/Middleware/RequestTimeMiddleware.php | RequestTimeMiddleware.getOnStatsCallback | protected function getOnStatsCallback($initialOnStats, $requestId) : \Closure
{
return function (TransferStats $stats) use ($initialOnStats, $requestId) {
if (is_callable($initialOnStats)) {
call_user_func($initialOnStats, $stats);
}
$this->dataCollector->addTotalTime((float)$stats->getTransferTime());
if ($requestId && $this->logger instanceof Logger) {
$this->logger->addTransferTimeByRequestId($requestId, (float)$stats->getTransferTime());
}
};
} | php | protected function getOnStatsCallback($initialOnStats, $requestId) : \Closure
{
return function (TransferStats $stats) use ($initialOnStats, $requestId) {
if (is_callable($initialOnStats)) {
call_user_func($initialOnStats, $stats);
}
$this->dataCollector->addTotalTime((float)$stats->getTransferTime());
if ($requestId && $this->logger instanceof Logger) {
$this->logger->addTransferTimeByRequestId($requestId, (float)$stats->getTransferTime());
}
};
} | [
"protected",
"function",
"getOnStatsCallback",
"(",
"$",
"initialOnStats",
",",
"$",
"requestId",
")",
":",
"\\",
"Closure",
"{",
"return",
"function",
"(",
"TransferStats",
"$",
"stats",
")",
"use",
"(",
"$",
"initialOnStats",
",",
"$",
"requestId",
")",
"{... | Create callback for on_stats options.
If request has on_stats option, it will be called inside of this callback.
@param null|callable $initialOnStats
@param null|string $requestId
@return \Closure | [
"Create",
"callback",
"for",
"on_stats",
"options",
".",
"If",
"request",
"has",
"on_stats",
"option",
"it",
"will",
"be",
"called",
"inside",
"of",
"this",
"callback",
"."
] | bfb387774313ee2bccc5dad4e81047334f50ea86 | https://github.com/8p/EightPointsGuzzleBundle/blob/bfb387774313ee2bccc5dad4e81047334f50ea86/src/Middleware/RequestTimeMiddleware.php#L56-L69 | train |
dwightwatson/rememberable | src/Query/Builder.php | Builder.flushCache | public function flushCache($cacheTags = null)
{
$cache = $this->getCacheDriver();
if ( ! method_exists($cache, 'tags')) {
return false;
}
$cacheTags = $cacheTags ?: $this->cacheTags;
$cache->tags($cacheTags)->flush();
return true;
} | php | public function flushCache($cacheTags = null)
{
$cache = $this->getCacheDriver();
if ( ! method_exists($cache, 'tags')) {
return false;
}
$cacheTags = $cacheTags ?: $this->cacheTags;
$cache->tags($cacheTags)->flush();
return true;
} | [
"public",
"function",
"flushCache",
"(",
"$",
"cacheTags",
"=",
"null",
")",
"{",
"$",
"cache",
"=",
"$",
"this",
"->",
"getCacheDriver",
"(",
")",
";",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"cache",
",",
"'tags'",
")",
")",
"{",
"return",
"fals... | Flush the cache for the current model or a given tag name
@param mixed $cacheTags
@return boolean | [
"Flush",
"the",
"cache",
"for",
"the",
"current",
"model",
"or",
"a",
"given",
"tag",
"name"
] | f3451ed6c4f9b902e1d1b3817dc62508c6b16d90 | https://github.com/dwightwatson/rememberable/blob/f3451ed6c4f9b902e1d1b3817dc62508c6b16d90/src/Query/Builder.php#L223-L236 | train |
barbushin/php-console | src/PhpConsole/Dispatcher/Debug.php | Debug.dispatchDebug | public function dispatchDebug($data, $tags = null, $ignoreTraceCalls = 0) {
if($this->isActive()) {
$message = new DebugMessage();
$message->data = $this->dumper->dump($data);
if($tags) {
$message->tags = explode('.', $tags);
}
if($this->detectTraceAndSource && $ignoreTraceCalls !== null) {
$message->trace = $this->fetchTrace(debug_backtrace(), $message->file, $message->line, $ignoreTraceCalls);
}
$this->sendMessage($message);
}
} | php | public function dispatchDebug($data, $tags = null, $ignoreTraceCalls = 0) {
if($this->isActive()) {
$message = new DebugMessage();
$message->data = $this->dumper->dump($data);
if($tags) {
$message->tags = explode('.', $tags);
}
if($this->detectTraceAndSource && $ignoreTraceCalls !== null) {
$message->trace = $this->fetchTrace(debug_backtrace(), $message->file, $message->line, $ignoreTraceCalls);
}
$this->sendMessage($message);
}
} | [
"public",
"function",
"dispatchDebug",
"(",
"$",
"data",
",",
"$",
"tags",
"=",
"null",
",",
"$",
"ignoreTraceCalls",
"=",
"0",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isActive",
"(",
")",
")",
"{",
"$",
"message",
"=",
"new",
"DebugMessage",
"(",
... | Send debug data message to client
@param mixed $data
@param null|string $tags Tags separated by dot, e.g. "low.db.billing"
@param int|array $ignoreTraceCalls Ignore tracing classes by name prefix `array('PhpConsole')` or fixed number of calls to ignore | [
"Send",
"debug",
"data",
"message",
"to",
"client"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/Dispatcher/Debug.php#L28-L40 | train |
barbushin/php-console | src/PhpConsole/Auth.php | Auth.getServerAuthStatus | public final function getServerAuthStatus(ClientAuth $clientAuth = null) {
$serverAuthStatus = new ServerAuthStatus();
$serverAuthStatus->publicKey = $this->getPublicKey();
$serverAuthStatus->isSuccess = $clientAuth && $this->isValidAuth($clientAuth);
return $serverAuthStatus;
} | php | public final function getServerAuthStatus(ClientAuth $clientAuth = null) {
$serverAuthStatus = new ServerAuthStatus();
$serverAuthStatus->publicKey = $this->getPublicKey();
$serverAuthStatus->isSuccess = $clientAuth && $this->isValidAuth($clientAuth);
return $serverAuthStatus;
} | [
"public",
"final",
"function",
"getServerAuthStatus",
"(",
"ClientAuth",
"$",
"clientAuth",
"=",
"null",
")",
"{",
"$",
"serverAuthStatus",
"=",
"new",
"ServerAuthStatus",
"(",
")",
";",
"$",
"serverAuthStatus",
"->",
"publicKey",
"=",
"$",
"this",
"->",
"getP... | Get authorization result data for client
@codeCoverageIgnore
@param ClientAuth|null $clientAuth
@return ServerAuthStatus | [
"Get",
"authorization",
"result",
"data",
"for",
"client"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/Auth.php#L51-L56 | train |
barbushin/php-console | src/PhpConsole/Auth.php | Auth.isValidAuth | public final function isValidAuth(ClientAuth $clientAuth) {
return $clientAuth->publicKey === $this->getPublicKey() && $clientAuth->token === $this->getToken();
} | php | public final function isValidAuth(ClientAuth $clientAuth) {
return $clientAuth->publicKey === $this->getPublicKey() && $clientAuth->token === $this->getToken();
} | [
"public",
"final",
"function",
"isValidAuth",
"(",
"ClientAuth",
"$",
"clientAuth",
")",
"{",
"return",
"$",
"clientAuth",
"->",
"publicKey",
"===",
"$",
"this",
"->",
"getPublicKey",
"(",
")",
"&&",
"$",
"clientAuth",
"->",
"token",
"===",
"$",
"this",
"-... | Check if client authorization data is valid
@codeCoverageIgnore
@param ClientAuth $clientAuth
@return bool | [
"Check",
"if",
"client",
"authorization",
"data",
"is",
"valid"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/Auth.php#L64-L66 | train |
barbushin/php-console | src/PhpConsole/Auth.php | Auth.getClientUid | protected function getClientUid() {
$clientUid = '';
if($this->publicKeyByIp) {
if(isset($_SERVER['REMOTE_ADDR'])) {
$clientUid .= $_SERVER['REMOTE_ADDR'];
}
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$clientUid .= $_SERVER['HTTP_X_FORWARDED_FOR'];
}
}
return $clientUid;
} | php | protected function getClientUid() {
$clientUid = '';
if($this->publicKeyByIp) {
if(isset($_SERVER['REMOTE_ADDR'])) {
$clientUid .= $_SERVER['REMOTE_ADDR'];
}
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$clientUid .= $_SERVER['HTTP_X_FORWARDED_FOR'];
}
}
return $clientUid;
} | [
"protected",
"function",
"getClientUid",
"(",
")",
"{",
"$",
"clientUid",
"=",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"publicKeyByIp",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'REMOTE_ADDR'",
"]",
")",
")",
"{",
"$",
"clientUid",
".... | Get client unique identification
@return string | [
"Get",
"client",
"unique",
"identification"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/Auth.php#L72-L83 | train |
barbushin/php-console | src/PhpConsole/Storage/AllKeysList.php | AllKeysList.push | public function push($key, $data) {
$keysData = $this->getKeysData();
$this->clearExpiredKeys($keysData);
$keysData[$key] = array(
'time' => time(),
'data' => $data
);
$this->saveKeysData($keysData);
} | php | public function push($key, $data) {
$keysData = $this->getKeysData();
$this->clearExpiredKeys($keysData);
$keysData[$key] = array(
'time' => time(),
'data' => $data
);
$this->saveKeysData($keysData);
} | [
"public",
"function",
"push",
"(",
"$",
"key",
",",
"$",
"data",
")",
"{",
"$",
"keysData",
"=",
"$",
"this",
"->",
"getKeysData",
"(",
")",
";",
"$",
"this",
"->",
"clearExpiredKeys",
"(",
"$",
"keysData",
")",
";",
"$",
"keysData",
"[",
"$",
"key... | Save postponed data to storage
@param string $key
@param string $data | [
"Save",
"postponed",
"data",
"to",
"storage"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/Storage/AllKeysList.php#L50-L58 | train |
barbushin/php-console | src/PhpConsole/Storage/AllKeysList.php | AllKeysList.clearExpiredKeys | protected function clearExpiredKeys(array &$keysData) {
$expireTime = time() - $this->keyLifetime;
foreach($keysData as $key => $item) {
if($item['time'] < $expireTime) {
unset($keysData[$key]);
}
}
} | php | protected function clearExpiredKeys(array &$keysData) {
$expireTime = time() - $this->keyLifetime;
foreach($keysData as $key => $item) {
if($item['time'] < $expireTime) {
unset($keysData[$key]);
}
}
} | [
"protected",
"function",
"clearExpiredKeys",
"(",
"array",
"&",
"$",
"keysData",
")",
"{",
"$",
"expireTime",
"=",
"time",
"(",
")",
"-",
"$",
"this",
"->",
"keyLifetime",
";",
"foreach",
"(",
"$",
"keysData",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
... | Remove postponed data that is out of limit
@param array $keysData | [
"Remove",
"postponed",
"data",
"that",
"is",
"out",
"of",
"limit"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/Storage/AllKeysList.php#L64-L71 | train |
barbushin/php-console | src/PhpConsole/EvalProvider.php | EvalProvider.evaluate | public function evaluate($code) {
$code = $this->applyHandlersToCode($code);
$code = $this->adaptCodeToEval($code);
$this->backupGlobals();
$this->applyOpenBaseDirSetting();
$startTime = microtime(true);
static::executeCode('', $this->sharedVars);
$selfTime = microtime(true) - $startTime;
ob_start();
$result = new EvalResult();
$startTime = microtime(true);
try {
$result->return = static::executeCode($code, $this->sharedVars);
}
catch(\Throwable $exception) {
$result->exception = $exception;
}
catch(\Exception $exception) {
$result->exception = $exception;
}
$result->time = abs(microtime(true) - $startTime - $selfTime);
$result->output = ob_get_clean();
$this->restoreGlobals();
return $result;
} | php | public function evaluate($code) {
$code = $this->applyHandlersToCode($code);
$code = $this->adaptCodeToEval($code);
$this->backupGlobals();
$this->applyOpenBaseDirSetting();
$startTime = microtime(true);
static::executeCode('', $this->sharedVars);
$selfTime = microtime(true) - $startTime;
ob_start();
$result = new EvalResult();
$startTime = microtime(true);
try {
$result->return = static::executeCode($code, $this->sharedVars);
}
catch(\Throwable $exception) {
$result->exception = $exception;
}
catch(\Exception $exception) {
$result->exception = $exception;
}
$result->time = abs(microtime(true) - $startTime - $selfTime);
$result->output = ob_get_clean();
$this->restoreGlobals();
return $result;
} | [
"public",
"function",
"evaluate",
"(",
"$",
"code",
")",
"{",
"$",
"code",
"=",
"$",
"this",
"->",
"applyHandlersToCode",
"(",
"$",
"code",
")",
";",
"$",
"code",
"=",
"$",
"this",
"->",
"adaptCodeToEval",
"(",
"$",
"code",
")",
";",
"$",
"this",
"... | Execute PHP code handling execution time, output & exception
@param string $code
@return EvalResult | [
"Execute",
"PHP",
"code",
"handling",
"execution",
"time",
"output",
"&",
"exception"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/EvalProvider.php#L27-L56 | train |
barbushin/php-console | src/PhpConsole/EvalProvider.php | EvalProvider.applyHandlersToCode | protected function applyHandlersToCode($code) {
foreach($this->codeCallbackHandlers as $callback) {
call_user_func_array($callback, array(&$code));
}
return $code;
} | php | protected function applyHandlersToCode($code) {
foreach($this->codeCallbackHandlers as $callback) {
call_user_func_array($callback, array(&$code));
}
return $code;
} | [
"protected",
"function",
"applyHandlersToCode",
"(",
"$",
"code",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"codeCallbackHandlers",
"as",
"$",
"callback",
")",
"{",
"call_user_func_array",
"(",
"$",
"callback",
",",
"array",
"(",
"&",
"$",
"code",
")",
... | Call added code handlers
@param $code
@return mixed | [
"Call",
"added",
"code",
"handlers"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/EvalProvider.php#L75-L80 | train |
barbushin/php-console | src/PhpConsole/EvalProvider.php | EvalProvider.backupGlobals | protected function backupGlobals() {
$this->globalsBackup = array();
foreach($GLOBALS as $key => $value) {
if($key != 'GLOBALS') {
$this->globalsBackup[$key] = $value;
}
}
} | php | protected function backupGlobals() {
$this->globalsBackup = array();
foreach($GLOBALS as $key => $value) {
if($key != 'GLOBALS') {
$this->globalsBackup[$key] = $value;
}
}
} | [
"protected",
"function",
"backupGlobals",
"(",
")",
"{",
"$",
"this",
"->",
"globalsBackup",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"GLOBALS",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"key",
"!=",
"'GLOBALS'",
")",
... | Store global vars data in backup var | [
"Store",
"global",
"vars",
"data",
"in",
"backup",
"var"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/EvalProvider.php#L85-L92 | train |
barbushin/php-console | src/PhpConsole/EvalProvider.php | EvalProvider.restoreGlobals | protected function restoreGlobals() {
foreach($this->globalsBackup as $key => $value) {
$GLOBALS[$key] = $value;
}
foreach(array_diff(array_keys($GLOBALS), array_keys($this->globalsBackup)) as $newKey) {
if($newKey != 'GLOBALS') {
unset($GLOBALS[$newKey]);
}
}
} | php | protected function restoreGlobals() {
foreach($this->globalsBackup as $key => $value) {
$GLOBALS[$key] = $value;
}
foreach(array_diff(array_keys($GLOBALS), array_keys($this->globalsBackup)) as $newKey) {
if($newKey != 'GLOBALS') {
unset($GLOBALS[$newKey]);
}
}
} | [
"protected",
"function",
"restoreGlobals",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"globalsBackup",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"GLOBALS",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"foreach",
"(",
"array_di... | Restore global vars data from backup var | [
"Restore",
"global",
"vars",
"data",
"from",
"backup",
"var"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/EvalProvider.php#L97-L106 | train |
barbushin/php-console | src/PhpConsole/EvalProvider.php | EvalProvider.executeCode | protected static function executeCode($_code, array $_sharedVars) {
foreach($_sharedVars as $var => $value) {
if(isset($GLOBALS[$var]) && $var[0] == '_') { // extract($this->sharedVars, EXTR_OVERWRITE) and $$var = $value do not overwrites global vars
$GLOBALS[$var] = $value;
}
elseif(!isset($$var)) {
$$var = $value;
}
}
return eval($_code);
} | php | protected static function executeCode($_code, array $_sharedVars) {
foreach($_sharedVars as $var => $value) {
if(isset($GLOBALS[$var]) && $var[0] == '_') { // extract($this->sharedVars, EXTR_OVERWRITE) and $$var = $value do not overwrites global vars
$GLOBALS[$var] = $value;
}
elseif(!isset($$var)) {
$$var = $value;
}
}
return eval($_code);
} | [
"protected",
"static",
"function",
"executeCode",
"(",
"$",
"_code",
",",
"array",
"$",
"_sharedVars",
")",
"{",
"foreach",
"(",
"$",
"_sharedVars",
"as",
"$",
"var",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"GLOBALS",
"[",
"$",
"v... | Execute code with shared vars
@param $_code
@param array $_sharedVars
@return mixed | [
"Execute",
"code",
"with",
"shared",
"vars"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/EvalProvider.php#L114-L125 | train |
barbushin/php-console | src/PhpConsole/EvalProvider.php | EvalProvider.forceEndingSemicolon | protected function forceEndingSemicolon($code) {
$code = rtrim($code, "; \r\n");
return $code[strlen($code) - 1] != '}' ? $code . ';' : $code;
} | php | protected function forceEndingSemicolon($code) {
$code = rtrim($code, "; \r\n");
return $code[strlen($code) - 1] != '}' ? $code . ';' : $code;
} | [
"protected",
"function",
"forceEndingSemicolon",
"(",
"$",
"code",
")",
"{",
"$",
"code",
"=",
"rtrim",
"(",
"$",
"code",
",",
"\"; \\r\\n\"",
")",
";",
"return",
"$",
"code",
"[",
"strlen",
"(",
"$",
"code",
")",
"-",
"1",
"]",
"!=",
"'}'",
"?",
"... | Add semicolon to the end of code if it's required
@param string $code
@return string | [
"Add",
"semicolon",
"to",
"the",
"end",
"of",
"code",
"if",
"it",
"s",
"required"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/EvalProvider.php#L147-L150 | train |
barbushin/php-console | src/PhpConsole/EvalProvider.php | EvalProvider.adaptCodeToEval | protected function adaptCodeToEval($code) {
$code = $this->trimPhpTags($code);
$code = $this->forceEndingSemicolon($code);
return $code;
} | php | protected function adaptCodeToEval($code) {
$code = $this->trimPhpTags($code);
$code = $this->forceEndingSemicolon($code);
return $code;
} | [
"protected",
"function",
"adaptCodeToEval",
"(",
"$",
"code",
")",
"{",
"$",
"code",
"=",
"$",
"this",
"->",
"trimPhpTags",
"(",
"$",
"code",
")",
";",
"$",
"code",
"=",
"$",
"this",
"->",
"forceEndingSemicolon",
"(",
"$",
"code",
")",
";",
"return",
... | Apply some default code handlers
@param string $code
@return string | [
"Apply",
"some",
"default",
"code",
"handlers"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/EvalProvider.php#L157-L161 | train |
barbushin/php-console | src/PhpConsole/EvalProvider.php | EvalProvider.forcePhpConsoleClassesAutoLoad | protected function forcePhpConsoleClassesAutoLoad() {
foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__), \RecursiveIteratorIterator::LEAVES_ONLY) as $path) {
/** @var $path \SplFileInfo */
if($path->isFile() && $path->getExtension() == 'php' && $path->getFilename() !== 'PsrLogger.php') {
require_once($path->getPathname());
}
}
} | php | protected function forcePhpConsoleClassesAutoLoad() {
foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__), \RecursiveIteratorIterator::LEAVES_ONLY) as $path) {
/** @var $path \SplFileInfo */
if($path->isFile() && $path->getExtension() == 'php' && $path->getFilename() !== 'PsrLogger.php') {
require_once($path->getPathname());
}
}
} | [
"protected",
"function",
"forcePhpConsoleClassesAutoLoad",
"(",
")",
"{",
"foreach",
"(",
"new",
"\\",
"RecursiveIteratorIterator",
"(",
"new",
"\\",
"RecursiveDirectoryIterator",
"(",
"__DIR__",
")",
",",
"\\",
"RecursiveIteratorIterator",
"::",
"LEAVES_ONLY",
")",
"... | Autoload all PHP Console classes
@codeCoverageIgnore | [
"Autoload",
"all",
"PHP",
"Console",
"classes"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/EvalProvider.php#L177-L184 | train |
barbushin/php-console | src/PhpConsole/EvalProvider.php | EvalProvider.applyOpenBaseDirSetting | protected function applyOpenBaseDirSetting() {
if($this->openBaseDirs) {
$value = implode(PATH_SEPARATOR, $this->openBaseDirs);
if(ini_get('open_basedir') != $value) {
$this->forcePhpConsoleClassesAutoLoad();
if(ini_set('open_basedir', $value) === false) {
throw new \Exception('Unable to set "open_basedir" php.ini setting');
}
}
}
} | php | protected function applyOpenBaseDirSetting() {
if($this->openBaseDirs) {
$value = implode(PATH_SEPARATOR, $this->openBaseDirs);
if(ini_get('open_basedir') != $value) {
$this->forcePhpConsoleClassesAutoLoad();
if(ini_set('open_basedir', $value) === false) {
throw new \Exception('Unable to set "open_basedir" php.ini setting');
}
}
}
} | [
"protected",
"function",
"applyOpenBaseDirSetting",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"openBaseDirs",
")",
"{",
"$",
"value",
"=",
"implode",
"(",
"PATH_SEPARATOR",
",",
"$",
"this",
"->",
"openBaseDirs",
")",
";",
"if",
"(",
"ini_get",
"(",
"... | Set actual "open_basedir" PHP ini option
@throws \Exception
@codeCoverageIgnore | [
"Set",
"actual",
"open_basedir",
"PHP",
"ini",
"option"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/EvalProvider.php#L191-L201 | train |
barbushin/php-console | src/PhpConsole/Dispatcher.php | Dispatcher.fetchTrace | protected function fetchTrace(array $trace, &$file = null, &$line = null, $ignoreTraceCalls = 0) {
$ignoreByNumber = is_numeric($ignoreTraceCalls) ? $ignoreTraceCalls : 0;
$ignoreByClassPrefixes = is_array($ignoreTraceCalls) ? array_merge($ignoreTraceCalls, array(__NAMESPACE__)) : null;
foreach($trace as $i => $call) {
if(!$file && $i == $ignoreTraceCalls && isset($call['file'])) {
$file = $call['file'];
$line = $call['line'];
}
if($ignoreByClassPrefixes && isset($call['class'])) {
foreach($ignoreByClassPrefixes as $classPrefix) {
if(strpos($call['class'], $classPrefix) !== false) {
unset($trace[$i]);
continue;
}
}
}
if($i < $ignoreByNumber || (isset($call['file']) && $call['file'] == $file && $call['line'] == $line)) {
unset($trace[$i]);
}
}
$traceCalls = array();
foreach(array_reverse($trace) as $call) {
$args = array();
if(isset($call['args'])) {
foreach($call['args'] as $arg) {
if(is_object($arg)) {
$args[] = get_class($arg);
}
elseif(is_array($arg)) {
$args[] = 'Array[' . count($arg) . ']';
}
else {
$arg = var_export($arg, 1);
$args[] = strlen($arg) > 15 ? substr($arg, 0, 15) . '...\'' : $arg;
}
}
}
if(strpos($call['function'], '{closure}')) {
$call['function'] = '{closure}';
}
$traceCall = new TraceCall();
$traceCall->call = (isset($call['class']) ? $call['class'] . $call['type'] : '') . $call['function'] . '(' . implode(', ', $args) . ')';
if(isset($call['file'])) {
$traceCall->file = $call['file'];
}
if(isset($call['line'])) {
$traceCall->line = $call['line'];
}
$traceCalls[] = $traceCall;
}
return $traceCalls;
} | php | protected function fetchTrace(array $trace, &$file = null, &$line = null, $ignoreTraceCalls = 0) {
$ignoreByNumber = is_numeric($ignoreTraceCalls) ? $ignoreTraceCalls : 0;
$ignoreByClassPrefixes = is_array($ignoreTraceCalls) ? array_merge($ignoreTraceCalls, array(__NAMESPACE__)) : null;
foreach($trace as $i => $call) {
if(!$file && $i == $ignoreTraceCalls && isset($call['file'])) {
$file = $call['file'];
$line = $call['line'];
}
if($ignoreByClassPrefixes && isset($call['class'])) {
foreach($ignoreByClassPrefixes as $classPrefix) {
if(strpos($call['class'], $classPrefix) !== false) {
unset($trace[$i]);
continue;
}
}
}
if($i < $ignoreByNumber || (isset($call['file']) && $call['file'] == $file && $call['line'] == $line)) {
unset($trace[$i]);
}
}
$traceCalls = array();
foreach(array_reverse($trace) as $call) {
$args = array();
if(isset($call['args'])) {
foreach($call['args'] as $arg) {
if(is_object($arg)) {
$args[] = get_class($arg);
}
elseif(is_array($arg)) {
$args[] = 'Array[' . count($arg) . ']';
}
else {
$arg = var_export($arg, 1);
$args[] = strlen($arg) > 15 ? substr($arg, 0, 15) . '...\'' : $arg;
}
}
}
if(strpos($call['function'], '{closure}')) {
$call['function'] = '{closure}';
}
$traceCall = new TraceCall();
$traceCall->call = (isset($call['class']) ? $call['class'] . $call['type'] : '') . $call['function'] . '(' . implode(', ', $args) . ')';
if(isset($call['file'])) {
$traceCall->file = $call['file'];
}
if(isset($call['line'])) {
$traceCall->line = $call['line'];
}
$traceCalls[] = $traceCall;
}
return $traceCalls;
} | [
"protected",
"function",
"fetchTrace",
"(",
"array",
"$",
"trace",
",",
"&",
"$",
"file",
"=",
"null",
",",
"&",
"$",
"line",
"=",
"null",
",",
"$",
"ignoreTraceCalls",
"=",
"0",
")",
"{",
"$",
"ignoreByNumber",
"=",
"is_numeric",
"(",
"$",
"ignoreTrac... | Convert backtrace to array of TraceCall with source file & line detection
@param array $trace Standard PHP backtrace array
@param null|string $file Reference to var that will contain source file path
@param null|string $line Reference to var that will contain source line number
@param int|array $ignoreTraceCalls Ignore tracing classes by name prefix `array('PhpConsole')` or fixed number of calls to ignore
@return TraceCall[] | [
"Convert",
"backtrace",
"to",
"array",
"of",
"TraceCall",
"with",
"source",
"file",
"&",
"line",
"detection"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/Dispatcher.php#L63-L118 | train |
barbushin/php-console | src/PhpConsole/Storage/MongoDB.php | MongoDB.get | protected function get($key) {
$record = $this->mongoCollection->findOne(array('key' => $key));
if($record && is_array($record) && array_key_exists('data', $record)) {
return $record['data'];
}
} | php | protected function get($key) {
$record = $this->mongoCollection->findOne(array('key' => $key));
if($record && is_array($record) && array_key_exists('data', $record)) {
return $record['data'];
}
} | [
"protected",
"function",
"get",
"(",
"$",
"key",
")",
"{",
"$",
"record",
"=",
"$",
"this",
"->",
"mongoCollection",
"->",
"findOne",
"(",
"array",
"(",
"'key'",
"=>",
"$",
"key",
")",
")",
";",
"if",
"(",
"$",
"record",
"&&",
"is_array",
"(",
"$",... | Get data by key if not expired
@param $key
@return string | [
"Get",
"data",
"by",
"key",
"if",
"not",
"expired"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/Storage/MongoDB.php#L70-L75 | train |
barbushin/php-console | src/PhpConsole/Handler.php | Handler.start | public function start() {
if($this->isStarted) {
throw new \Exception(get_called_class() . ' is already started, use ' . get_called_class() . '::getInstance()->isStarted() to check it.');
}
$this->isStarted = true;
if($this->handleErrors) {
$this->initErrorsHandler();
}
if($this->handleExceptions) {
$this->initExceptionsHandler();
}
} | php | public function start() {
if($this->isStarted) {
throw new \Exception(get_called_class() . ' is already started, use ' . get_called_class() . '::getInstance()->isStarted() to check it.');
}
$this->isStarted = true;
if($this->handleErrors) {
$this->initErrorsHandler();
}
if($this->handleExceptions) {
$this->initExceptionsHandler();
}
} | [
"public",
"function",
"start",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isStarted",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"get_called_class",
"(",
")",
".",
"' is already started, use '",
".",
"get_called_class",
"(",
")",
".",
"'::getInstan... | Start errors & exceptions handlers
@throws \Exception | [
"Start",
"errors",
"&",
"exceptions",
"handlers"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/Handler.php#L62-L74 | train |
barbushin/php-console | src/PhpConsole/Handler.php | Handler.initErrorsHandler | protected function initErrorsHandler() {
ini_set('display_errors', false);
error_reporting($this->errorsHandlerLevel ? : E_ALL | E_STRICT);
$this->oldErrorsHandler = set_error_handler(array($this, 'handleError'));
register_shutdown_function(array($this, 'checkFatalErrorOnShutDown'));
$this->connector->registerFlushOnShutDown();
} | php | protected function initErrorsHandler() {
ini_set('display_errors', false);
error_reporting($this->errorsHandlerLevel ? : E_ALL | E_STRICT);
$this->oldErrorsHandler = set_error_handler(array($this, 'handleError'));
register_shutdown_function(array($this, 'checkFatalErrorOnShutDown'));
$this->connector->registerFlushOnShutDown();
} | [
"protected",
"function",
"initErrorsHandler",
"(",
")",
"{",
"ini_set",
"(",
"'display_errors'",
",",
"false",
")",
";",
"error_reporting",
"(",
"$",
"this",
"->",
"errorsHandlerLevel",
"?",
":",
"E_ALL",
"|",
"E_STRICT",
")",
";",
"$",
"this",
"->",
"oldErr... | Override PHP errors handler to PHP Console handler | [
"Override",
"PHP",
"errors",
"handler",
"to",
"PHP",
"Console",
"handler"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/Handler.php#L148-L154 | train |
barbushin/php-console | src/PhpConsole/Handler.php | Handler.handleError | public function handleError($code = null, $text = null, $file = null, $line = null, $context = null, $ignoreTraceCalls = 0) {
if(!$this->isStarted || error_reporting() === 0 || $this->isHandlingDisabled() || ($this->errorsHandlerLevel && !($code & $this->errorsHandlerLevel))) {
return;
}
$this->onHandlingStart();
$this->connector->getErrorsDispatcher()->dispatchError($code, $text, $file, $line, is_numeric($ignoreTraceCalls) ? $ignoreTraceCalls + 1 : $ignoreTraceCalls);
if($this->oldErrorsHandler && $this->callOldHandlers) {
call_user_func_array($this->oldErrorsHandler, array($code, $text, $file, $line, $context));
}
$this->onHandlingComplete();
} | php | public function handleError($code = null, $text = null, $file = null, $line = null, $context = null, $ignoreTraceCalls = 0) {
if(!$this->isStarted || error_reporting() === 0 || $this->isHandlingDisabled() || ($this->errorsHandlerLevel && !($code & $this->errorsHandlerLevel))) {
return;
}
$this->onHandlingStart();
$this->connector->getErrorsDispatcher()->dispatchError($code, $text, $file, $line, is_numeric($ignoreTraceCalls) ? $ignoreTraceCalls + 1 : $ignoreTraceCalls);
if($this->oldErrorsHandler && $this->callOldHandlers) {
call_user_func_array($this->oldErrorsHandler, array($code, $text, $file, $line, $context));
}
$this->onHandlingComplete();
} | [
"public",
"function",
"handleError",
"(",
"$",
"code",
"=",
"null",
",",
"$",
"text",
"=",
"null",
",",
"$",
"file",
"=",
"null",
",",
"$",
"line",
"=",
"null",
",",
"$",
"context",
"=",
"null",
",",
"$",
"ignoreTraceCalls",
"=",
"0",
")",
"{",
"... | Handle error data
@param int|null $code
@param string|null $text
@param string|null $file
@param int|null $line
@param null $context
@param int|array $ignoreTraceCalls Ignore tracing classes by name prefix `array('PhpConsole')` or fixed number of calls to ignore | [
"Handle",
"error",
"data"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/Handler.php#L178-L188 | train |
barbushin/php-console | src/PhpConsole/Handler.php | Handler.handleException | public function handleException($exception) {
if(!$this->isStarted || $this->isHandlingDisabled()) {
return;
}
try {
$this->onHandlingStart();
$this->connector->getErrorsDispatcher()->dispatchException($exception);
if($this->oldExceptionsHandler && $this->callOldHandlers) {
call_user_func($this->oldExceptionsHandler, $exception);
}
}
catch(\Throwable $internalException) {
$this->handleException($internalException);
}
catch(\Exception $internalException) {
$this->handleException($internalException);
}
$this->onHandlingComplete();
} | php | public function handleException($exception) {
if(!$this->isStarted || $this->isHandlingDisabled()) {
return;
}
try {
$this->onHandlingStart();
$this->connector->getErrorsDispatcher()->dispatchException($exception);
if($this->oldExceptionsHandler && $this->callOldHandlers) {
call_user_func($this->oldExceptionsHandler, $exception);
}
}
catch(\Throwable $internalException) {
$this->handleException($internalException);
}
catch(\Exception $internalException) {
$this->handleException($internalException);
}
$this->onHandlingComplete();
} | [
"public",
"function",
"handleException",
"(",
"$",
"exception",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isStarted",
"||",
"$",
"this",
"->",
"isHandlingDisabled",
"(",
")",
")",
"{",
"return",
";",
"}",
"try",
"{",
"$",
"this",
"->",
"onHandlingS... | Handle exception object
@param \Exception|\Throwable $exception | [
"Handle",
"exception",
"object"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/Handler.php#L216-L234 | train |
barbushin/php-console | src/PhpConsole/Handler.php | Handler.debug | public function debug($data, $tags = null, $ignoreTraceCalls = 0) {
if($this->connector->isActiveClient()) {
$this->connector->getDebugDispatcher()->dispatchDebug($data, $tags, is_numeric($ignoreTraceCalls) ? $ignoreTraceCalls + 1 : $ignoreTraceCalls);
}
} | php | public function debug($data, $tags = null, $ignoreTraceCalls = 0) {
if($this->connector->isActiveClient()) {
$this->connector->getDebugDispatcher()->dispatchDebug($data, $tags, is_numeric($ignoreTraceCalls) ? $ignoreTraceCalls + 1 : $ignoreTraceCalls);
}
} | [
"public",
"function",
"debug",
"(",
"$",
"data",
",",
"$",
"tags",
"=",
"null",
",",
"$",
"ignoreTraceCalls",
"=",
"0",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"connector",
"->",
"isActiveClient",
"(",
")",
")",
"{",
"$",
"this",
"->",
"connector",
... | Handle debug data
@param mixed $data
@param string|null $tags Tags separated by dot, e.g. "low.db.billing"
@param int|array $ignoreTraceCalls Ignore tracing classes by name prefix `array('PhpConsole')` or fixed number of calls to ignore | [
"Handle",
"debug",
"data"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/Handler.php#L242-L246 | train |
barbushin/php-console | src/PhpConsole/Connector.php | Connector.initConnection | private function initConnection() {
if($this->isCliMode()) {
return;
}
$this->initServerCookie();
$this->client = $this->initClient();
if($this->client) {
ob_start();
$this->isActiveClient = true;
$this->registerFlushOnShutDown();
$this->setHeadersLimit(isset($_SERVER['SERVER_SOFTWARE']) && stripos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false
? 4096 // default headers limit for Nginx
: 8192 // default headers limit for all other web-servers
);
$this->listenGetPostponedResponse();
$this->postponeResponseId = $this->setPostponeHeader();
}
} | php | private function initConnection() {
if($this->isCliMode()) {
return;
}
$this->initServerCookie();
$this->client = $this->initClient();
if($this->client) {
ob_start();
$this->isActiveClient = true;
$this->registerFlushOnShutDown();
$this->setHeadersLimit(isset($_SERVER['SERVER_SOFTWARE']) && stripos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false
? 4096 // default headers limit for Nginx
: 8192 // default headers limit for all other web-servers
);
$this->listenGetPostponedResponse();
$this->postponeResponseId = $this->setPostponeHeader();
}
} | [
"private",
"function",
"initConnection",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isCliMode",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"initServerCookie",
"(",
")",
";",
"$",
"this",
"->",
"client",
"=",
"$",
"this",
"->",
"i... | Notify clients that there is active PHP Console on server & check if there is request from client with active PHP Console
@throws \Exception | [
"Notify",
"clients",
"that",
"there",
"is",
"active",
"PHP",
"Console",
"on",
"server",
"&",
"check",
"if",
"there",
"is",
"request",
"from",
"client",
"with",
"active",
"PHP",
"Console"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/Connector.php#L116-L135 | train |
barbushin/php-console | src/PhpConsole/Connector.php | Connector.initClient | private function initClient() {
if(isset($_COOKIE[self::CLIENT_INFO_COOKIE])) {
$clientData = @json_decode(base64_decode($_COOKIE[self::CLIENT_INFO_COOKIE], true), true);
if(!$clientData) {
throw new \Exception('Wrong format of response cookie data: ' . $_COOKIE[self::CLIENT_INFO_COOKIE]);
}
$client = new Client($clientData);
if(isset($clientData['auth'])) {
$client->auth = new ClientAuth($clientData['auth']);
}
return $client;
}
} | php | private function initClient() {
if(isset($_COOKIE[self::CLIENT_INFO_COOKIE])) {
$clientData = @json_decode(base64_decode($_COOKIE[self::CLIENT_INFO_COOKIE], true), true);
if(!$clientData) {
throw new \Exception('Wrong format of response cookie data: ' . $_COOKIE[self::CLIENT_INFO_COOKIE]);
}
$client = new Client($clientData);
if(isset($clientData['auth'])) {
$client->auth = new ClientAuth($clientData['auth']);
}
return $client;
}
} | [
"private",
"function",
"initClient",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_COOKIE",
"[",
"self",
"::",
"CLIENT_INFO_COOKIE",
"]",
")",
")",
"{",
"$",
"clientData",
"=",
"@",
"json_decode",
"(",
"base64_decode",
"(",
"$",
"_COOKIE",
"[",
"self",
... | Get connected client data(
@return Client|null
@throws \Exception | [
"Get",
"connected",
"client",
"data",
"("
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/Connector.php#L142-L155 | train |
barbushin/php-console | src/PhpConsole/Connector.php | Connector.initServerCookie | private function initServerCookie() {
if(!isset($_COOKIE[self::SERVER_COOKIE]) || $_COOKIE[self::SERVER_COOKIE] != self::SERVER_PROTOCOL) {
$isSuccess = setcookie(self::SERVER_COOKIE, self::SERVER_PROTOCOL, null, '/');
if(!$isSuccess) {
throw new \Exception('Unable to set PHP Console server cookie');
}
}
} | php | private function initServerCookie() {
if(!isset($_COOKIE[self::SERVER_COOKIE]) || $_COOKIE[self::SERVER_COOKIE] != self::SERVER_PROTOCOL) {
$isSuccess = setcookie(self::SERVER_COOKIE, self::SERVER_PROTOCOL, null, '/');
if(!$isSuccess) {
throw new \Exception('Unable to set PHP Console server cookie');
}
}
} | [
"private",
"function",
"initServerCookie",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"_COOKIE",
"[",
"self",
"::",
"SERVER_COOKIE",
"]",
")",
"||",
"$",
"_COOKIE",
"[",
"self",
"::",
"SERVER_COOKIE",
"]",
"!=",
"self",
"::",
"SERVER_PROTOCOL",
")... | Notify clients that there is active PHP Console on server
@throws \Exception | [
"Notify",
"clients",
"that",
"there",
"is",
"active",
"PHP",
"Console",
"on",
"server"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/Connector.php#L161-L168 | train |
barbushin/php-console | src/PhpConsole/Connector.php | Connector.setAllowedIpMasks | public function setAllowedIpMasks(array $ipMasks) {
if($this->isActiveClient()) {
if(isset($_SERVER['REMOTE_ADDR'])) {
$ip = $_SERVER['REMOTE_ADDR'];
foreach($ipMasks as $ipMask) {
if(preg_match('~^' . str_replace(array('.', '*'), array('\.', '\w+'), $ipMask) . '$~i', $ip)) {
return;
}
}
}
$this->disable();
}
} | php | public function setAllowedIpMasks(array $ipMasks) {
if($this->isActiveClient()) {
if(isset($_SERVER['REMOTE_ADDR'])) {
$ip = $_SERVER['REMOTE_ADDR'];
foreach($ipMasks as $ipMask) {
if(preg_match('~^' . str_replace(array('.', '*'), array('\.', '\w+'), $ipMask) . '$~i', $ip)) {
return;
}
}
}
$this->disable();
}
} | [
"public",
"function",
"setAllowedIpMasks",
"(",
"array",
"$",
"ipMasks",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isActiveClient",
"(",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'REMOTE_ADDR'",
"]",
")",
")",
"{",
"$",
"ip",
"=",
... | Set IP masks of clients that will be allowed to connect to PHP Console
@param array $ipMasks Use *(star character) for "any numbers" placeholder array('192.168.*.*', '10.2.12*.*', '127.0.0.1', '2001:0:5ef5:79fb:*:*:*:*') | [
"Set",
"IP",
"masks",
"of",
"clients",
"that",
"will",
"be",
"allowed",
"to",
"connect",
"to",
"PHP",
"Console"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/Connector.php#L197-L209 | train |
barbushin/php-console | src/PhpConsole/Connector.php | Connector.getDebugDispatcher | public function getDebugDispatcher() {
if(!$this->debugDispatcher) {
$this->debugDispatcher = new Dispatcher\Debug($this, $this->getDumper());
}
return $this->debugDispatcher;
} | php | public function getDebugDispatcher() {
if(!$this->debugDispatcher) {
$this->debugDispatcher = new Dispatcher\Debug($this, $this->getDumper());
}
return $this->debugDispatcher;
} | [
"public",
"function",
"getDebugDispatcher",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"debugDispatcher",
")",
"{",
"$",
"this",
"->",
"debugDispatcher",
"=",
"new",
"Dispatcher",
"\\",
"Debug",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"getDumper... | Get dispatcher responsible for sending debug messages
@return Dispatcher\Debug | [
"Get",
"dispatcher",
"responsible",
"for",
"sending",
"debug",
"messages"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/Connector.php#L252-L257 | train |
barbushin/php-console | src/PhpConsole/Connector.php | Connector.getEvalDispatcher | public function getEvalDispatcher() {
if(!$this->evalDispatcher) {
$this->evalDispatcher = new Dispatcher\Evaluate($this, new EvalProvider(), $this->getDumper());
}
return $this->evalDispatcher;
} | php | public function getEvalDispatcher() {
if(!$this->evalDispatcher) {
$this->evalDispatcher = new Dispatcher\Evaluate($this, new EvalProvider(), $this->getDumper());
}
return $this->evalDispatcher;
} | [
"public",
"function",
"getEvalDispatcher",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"evalDispatcher",
")",
"{",
"$",
"this",
"->",
"evalDispatcher",
"=",
"new",
"Dispatcher",
"\\",
"Evaluate",
"(",
"$",
"this",
",",
"new",
"EvalProvider",
"(",
"... | Get dispatcher responsible for handling eval requests
@return Dispatcher\Evaluate | [
"Get",
"dispatcher",
"responsible",
"for",
"handling",
"eval",
"requests"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/Connector.php#L271-L276 | train |
barbushin/php-console | src/PhpConsole/Connector.php | Connector.setPassword | public function setPassword($password, $publicKeyByIp = true) {
if($this->auth) {
throw new \Exception('Password already defined');
}
$this->convertEncoding($password, self::CLIENT_ENCODING, $this->serverEncoding);
$this->auth = new Auth($password, $publicKeyByIp);
if($this->client) {
$this->isAuthorized = $this->client->auth && $this->auth->isValidAuth($this->client->auth);
}
} | php | public function setPassword($password, $publicKeyByIp = true) {
if($this->auth) {
throw new \Exception('Password already defined');
}
$this->convertEncoding($password, self::CLIENT_ENCODING, $this->serverEncoding);
$this->auth = new Auth($password, $publicKeyByIp);
if($this->client) {
$this->isAuthorized = $this->client->auth && $this->auth->isValidAuth($this->client->auth);
}
} | [
"public",
"function",
"setPassword",
"(",
"$",
"password",
",",
"$",
"publicKeyByIp",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"auth",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Password already defined'",
")",
";",
"}",
"$",
"this",... | Protect PHP Console connection by password
Use Connector::getInstance()->setAllowedIpMasks() for additional secure
@param string $password
@param bool $publicKeyByIp Set authorization token depending on client IP
@throws \Exception | [
"Protect",
"PHP",
"Console",
"connection",
"by",
"password"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/Connector.php#L340-L349 | train |
barbushin/php-console | src/PhpConsole/Connector.php | Connector.convertEncoding | protected function convertEncoding(&$string, $toEncoding, $fromEncoding) {
if($string && is_string($string) && $toEncoding != $fromEncoding) {
static $isMbString;
if($isMbString === null) {
$isMbString = extension_loaded('mbstring');
}
if($isMbString) {
$string = @mb_convert_encoding($string, $toEncoding, $fromEncoding) ? : $string;
}
else {
$string = @iconv($fromEncoding, $toEncoding . '//IGNORE', $string) ? : $string;
}
if(!$string && $toEncoding == 'UTF-8') {
$string = utf8_encode($string);
}
}
} | php | protected function convertEncoding(&$string, $toEncoding, $fromEncoding) {
if($string && is_string($string) && $toEncoding != $fromEncoding) {
static $isMbString;
if($isMbString === null) {
$isMbString = extension_loaded('mbstring');
}
if($isMbString) {
$string = @mb_convert_encoding($string, $toEncoding, $fromEncoding) ? : $string;
}
else {
$string = @iconv($fromEncoding, $toEncoding . '//IGNORE', $string) ? : $string;
}
if(!$string && $toEncoding == 'UTF-8') {
$string = utf8_encode($string);
}
}
} | [
"protected",
"function",
"convertEncoding",
"(",
"&",
"$",
"string",
",",
"$",
"toEncoding",
",",
"$",
"fromEncoding",
")",
"{",
"if",
"(",
"$",
"string",
"&&",
"is_string",
"(",
"$",
"string",
")",
"&&",
"$",
"toEncoding",
"!=",
"$",
"fromEncoding",
")"... | Convert string encoding
@param string $string
@param string $toEncoding
@param string|null $fromEncoding
@throws \Exception | [
"Convert",
"string",
"encoding"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/Connector.php#L388-L404 | train |
barbushin/php-console | src/PhpConsole/Connector.php | Connector.proceedResponsePackage | private function proceedResponsePackage() {
if($this->isActiveClient()) {
$response = new Response();
$response->isSslOnlyMode = $this->isSslOnlyMode;
if(isset($_POST[self::POST_VAR_NAME]['getBackData'])) {
$response->getBackData = $_POST[self::POST_VAR_NAME]['getBackData'];
}
if(!$this->isSslOnlyMode || $this->isSsl()) {
if($this->auth) {
$response->auth = $this->auth->getServerAuthStatus($this->client->auth);
}
if(!$this->auth || $this->isAuthorized()) {
$response->isLocal = isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] == '127.0.0.1';
$response->docRoot = isset($_SERVER['DOCUMENT_ROOT']) ? $_SERVER['DOCUMENT_ROOT'] : null;
$response->sourcesBasePath = $this->sourcesBasePath;
$response->isEvalEnabled = $this->isEvalListenerStarted;
$response->messages = $this->messages;
}
}
$responseData = $this->serializeResponse($response);
if(strlen($responseData) > $this->headersLimit || !$this->setHeaderData($responseData, self::HEADER_NAME, false)) {
$this->getPostponeStorage()->push($this->postponeResponseId, $responseData);
}
}
} | php | private function proceedResponsePackage() {
if($this->isActiveClient()) {
$response = new Response();
$response->isSslOnlyMode = $this->isSslOnlyMode;
if(isset($_POST[self::POST_VAR_NAME]['getBackData'])) {
$response->getBackData = $_POST[self::POST_VAR_NAME]['getBackData'];
}
if(!$this->isSslOnlyMode || $this->isSsl()) {
if($this->auth) {
$response->auth = $this->auth->getServerAuthStatus($this->client->auth);
}
if(!$this->auth || $this->isAuthorized()) {
$response->isLocal = isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] == '127.0.0.1';
$response->docRoot = isset($_SERVER['DOCUMENT_ROOT']) ? $_SERVER['DOCUMENT_ROOT'] : null;
$response->sourcesBasePath = $this->sourcesBasePath;
$response->isEvalEnabled = $this->isEvalListenerStarted;
$response->messages = $this->messages;
}
}
$responseData = $this->serializeResponse($response);
if(strlen($responseData) > $this->headersLimit || !$this->setHeaderData($responseData, self::HEADER_NAME, false)) {
$this->getPostponeStorage()->push($this->postponeResponseId, $responseData);
}
}
} | [
"private",
"function",
"proceedResponsePackage",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isActiveClient",
"(",
")",
")",
"{",
"$",
"response",
"=",
"new",
"Response",
"(",
")",
";",
"$",
"response",
"->",
"isSslOnlyMode",
"=",
"$",
"this",
"->",
... | Send response data to client
@throws \Exception | [
"Send",
"response",
"data",
"to",
"client"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/Connector.php#L477-L505 | train |
barbushin/php-console | src/PhpConsole/Connector.php | Connector.listenGetPostponedResponse | private function listenGetPostponedResponse() {
if(isset($_POST[self::POST_VAR_NAME]['getPostponedResponse'])) {
header('Content-Type: application/json; charset=' . self::CLIENT_ENCODING);
echo $this->getPostponeStorage()->pop($_POST[self::POST_VAR_NAME]['getPostponedResponse']);
$this->disable();
exit;
}
} | php | private function listenGetPostponedResponse() {
if(isset($_POST[self::POST_VAR_NAME]['getPostponedResponse'])) {
header('Content-Type: application/json; charset=' . self::CLIENT_ENCODING);
echo $this->getPostponeStorage()->pop($_POST[self::POST_VAR_NAME]['getPostponedResponse']);
$this->disable();
exit;
}
} | [
"private",
"function",
"listenGetPostponedResponse",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_POST",
"[",
"self",
"::",
"POST_VAR_NAME",
"]",
"[",
"'getPostponedResponse'",
"]",
")",
")",
"{",
"header",
"(",
"'Content-Type: application/json; charset='",
".",... | Check if there is postponed response request and dispatch it | [
"Check",
"if",
"there",
"is",
"postponed",
"response",
"request",
"and",
"dispatch",
"it"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/Connector.php#L546-L553 | train |
barbushin/php-console | src/PhpConsole/Dispatcher/Evaluate.php | Evaluate.dispatchCode | public function dispatchCode($code) {
if($this->isActive()) {
$previousLastError = error_get_last();
$oldDisplayErrors = ini_set('display_errors', false);
$result = $this->evalProvider->evaluate($code);
ini_set('display_errors', $oldDisplayErrors);
$message = new EvalResultMessage();
$message->return = $this->dumper->dump($result->return);
$message->output = $this->dumper->dump($result->output);
$message->time = round($result->time, 6);
$newLastError = error_get_last();
if($newLastError && $newLastError != $previousLastError) {
$this->connector->getErrorsDispatcher()->dispatchError($newLastError ['type'], $newLastError ['message'], $newLastError ['file'], $newLastError ['line'], 999);
}
if($result->exception) {
$this->connector->getErrorsDispatcher()->dispatchException($result->exception);
}
$this->sendMessage($message);
}
} | php | public function dispatchCode($code) {
if($this->isActive()) {
$previousLastError = error_get_last();
$oldDisplayErrors = ini_set('display_errors', false);
$result = $this->evalProvider->evaluate($code);
ini_set('display_errors', $oldDisplayErrors);
$message = new EvalResultMessage();
$message->return = $this->dumper->dump($result->return);
$message->output = $this->dumper->dump($result->output);
$message->time = round($result->time, 6);
$newLastError = error_get_last();
if($newLastError && $newLastError != $previousLastError) {
$this->connector->getErrorsDispatcher()->dispatchError($newLastError ['type'], $newLastError ['message'], $newLastError ['file'], $newLastError ['line'], 999);
}
if($result->exception) {
$this->connector->getErrorsDispatcher()->dispatchException($result->exception);
}
$this->sendMessage($message);
}
} | [
"public",
"function",
"dispatchCode",
"(",
"$",
"code",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isActive",
"(",
")",
")",
"{",
"$",
"previousLastError",
"=",
"error_get_last",
"(",
")",
";",
"$",
"oldDisplayErrors",
"=",
"ini_set",
"(",
"'display_errors'"... | Execute PHP code and send result message in connector
@param $code | [
"Execute",
"PHP",
"code",
"and",
"send",
"result",
"message",
"in",
"connector"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/Dispatcher/Evaluate.php#L55-L76 | train |
barbushin/php-console | src/PhpConsole/Dispatcher/Errors.php | Errors.dispatchError | public function dispatchError($code = null, $text = null, $file = null, $line = null, $ignoreTraceCalls = 0) {
if($this->isActive()) {
$message = new ErrorMessage();
$message->code = $code;
$message->class = $this->getErrorTypeByCode($code);
$message->data = $this->dumper->dump($text);
$message->file = $file;
$message->line = $line;
if($ignoreTraceCalls !== null) {
$message->trace = $this->fetchTrace(debug_backtrace(), $file, $line, is_array($ignoreTraceCalls) ? $ignoreTraceCalls : $ignoreTraceCalls + 1);
}
$this->sendMessage($message);
}
} | php | public function dispatchError($code = null, $text = null, $file = null, $line = null, $ignoreTraceCalls = 0) {
if($this->isActive()) {
$message = new ErrorMessage();
$message->code = $code;
$message->class = $this->getErrorTypeByCode($code);
$message->data = $this->dumper->dump($text);
$message->file = $file;
$message->line = $line;
if($ignoreTraceCalls !== null) {
$message->trace = $this->fetchTrace(debug_backtrace(), $file, $line, is_array($ignoreTraceCalls) ? $ignoreTraceCalls : $ignoreTraceCalls + 1);
}
$this->sendMessage($message);
}
} | [
"public",
"function",
"dispatchError",
"(",
"$",
"code",
"=",
"null",
",",
"$",
"text",
"=",
"null",
",",
"$",
"file",
"=",
"null",
",",
"$",
"line",
"=",
"null",
",",
"$",
"ignoreTraceCalls",
"=",
"0",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"is... | Send error message to client
@param null|integer $code
@param null|string $text
@param null|string $file
@param null|integer $line
@param int|array $ignoreTraceCalls Ignore tracing classes by name prefix `array('PhpConsole')` or fixed number of calls to ignore | [
"Send",
"error",
"message",
"to",
"client"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/Dispatcher/Errors.php#L57-L70 | train |
barbushin/php-console | src/PhpConsole/Dispatcher/Errors.php | Errors.dispatchException | public function dispatchException($exception) {
if($this->isActive()) {
if($this->dispatchPreviousExceptions && $exception->getPrevious()) {
$this->dispatchException($exception->getPrevious());
}
$message = new ErrorMessage();
$message->code = $exception->getCode();
$message->class = get_class($exception);
$message->data = $this->dumper->dump($exception->getMessage());
$message->file = $exception->getFile();
$message->line = $exception->getLine();
$message->trace = self::fetchTrace($exception->getTrace(), $message->file, $message->line);
$this->sendMessage($message);
}
} | php | public function dispatchException($exception) {
if($this->isActive()) {
if($this->dispatchPreviousExceptions && $exception->getPrevious()) {
$this->dispatchException($exception->getPrevious());
}
$message = new ErrorMessage();
$message->code = $exception->getCode();
$message->class = get_class($exception);
$message->data = $this->dumper->dump($exception->getMessage());
$message->file = $exception->getFile();
$message->line = $exception->getLine();
$message->trace = self::fetchTrace($exception->getTrace(), $message->file, $message->line);
$this->sendMessage($message);
}
} | [
"public",
"function",
"dispatchException",
"(",
"$",
"exception",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isActive",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"dispatchPreviousExceptions",
"&&",
"$",
"exception",
"->",
"getPrevious",
"(",
")",
"... | Send exception message to client
@param \Exception|\Throwable $exception | [
"Send",
"exception",
"message",
"to",
"client"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/Dispatcher/Errors.php#L76-L90 | train |
barbushin/php-console | src/PhpConsole/Dispatcher/Errors.php | Errors.sendMessage | protected function sendMessage(Message $message) {
if(!$this->isIgnored($message)) {
parent::sendMessage($message);
$this->sentMessages[] = $message;
}
} | php | protected function sendMessage(Message $message) {
if(!$this->isIgnored($message)) {
parent::sendMessage($message);
$this->sentMessages[] = $message;
}
} | [
"protected",
"function",
"sendMessage",
"(",
"Message",
"$",
"message",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isIgnored",
"(",
"$",
"message",
")",
")",
"{",
"parent",
"::",
"sendMessage",
"(",
"$",
"message",
")",
";",
"$",
"this",
"->",
"se... | Send message to PHP Console connector
@param Message $message | [
"Send",
"message",
"to",
"PHP",
"Console",
"connector"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/Dispatcher/Errors.php#L96-L101 | train |
barbushin/php-console | src/PhpConsole/Dispatcher/Errors.php | Errors.getErrorTypeByCode | protected function getErrorTypeByCode($code) {
if(!static::$errorsConstantsValues) {
foreach(static::$errorsConstantsNames as $constantName) {
if(defined($constantName)) {
static::$errorsConstantsValues[constant($constantName)] = $constantName;
}
}
}
if(isset(static::$errorsConstantsValues[$code])) {
return static::$errorsConstantsValues[$code];
}
return (string)$code;
} | php | protected function getErrorTypeByCode($code) {
if(!static::$errorsConstantsValues) {
foreach(static::$errorsConstantsNames as $constantName) {
if(defined($constantName)) {
static::$errorsConstantsValues[constant($constantName)] = $constantName;
}
}
}
if(isset(static::$errorsConstantsValues[$code])) {
return static::$errorsConstantsValues[$code];
}
return (string)$code;
} | [
"protected",
"function",
"getErrorTypeByCode",
"(",
"$",
"code",
")",
"{",
"if",
"(",
"!",
"static",
"::",
"$",
"errorsConstantsValues",
")",
"{",
"foreach",
"(",
"static",
"::",
"$",
"errorsConstantsNames",
"as",
"$",
"constantName",
")",
"{",
"if",
"(",
... | Get PHP error constant name by value
@param int $code
@return string | [
"Get",
"PHP",
"error",
"constant",
"name",
"by",
"value"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/Dispatcher/Errors.php#L108-L120 | train |
barbushin/php-console | src/PhpConsole/Dispatcher/Errors.php | Errors.isIgnored | protected function isIgnored(ErrorMessage $message) {
if($this->ignoreRepeatedSource && $message->file) {
foreach($this->sentMessages as $sentMessage) {
if($message->file == $sentMessage->file && $message->line == $sentMessage->line && $message->class == $sentMessage->class) {
return true;
}
}
}
return false;
} | php | protected function isIgnored(ErrorMessage $message) {
if($this->ignoreRepeatedSource && $message->file) {
foreach($this->sentMessages as $sentMessage) {
if($message->file == $sentMessage->file && $message->line == $sentMessage->line && $message->class == $sentMessage->class) {
return true;
}
}
}
return false;
} | [
"protected",
"function",
"isIgnored",
"(",
"ErrorMessage",
"$",
"message",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"ignoreRepeatedSource",
"&&",
"$",
"message",
"->",
"file",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"sentMessages",
"as",
"$",
"sentMess... | Return true if message with same file, line & class was already sent
@param ErrorMessage $message
@return bool | [
"Return",
"true",
"if",
"message",
"with",
"same",
"file",
"line",
"&",
"class",
"was",
"already",
"sent"
] | ae5de7e4c1f78b2a6986a8f891d7b97764e931fa | https://github.com/barbushin/php-console/blob/ae5de7e4c1f78b2a6986a8f891d7b97764e931fa/src/PhpConsole/Dispatcher/Errors.php#L127-L136 | train |
psecio/iniscan | src/Psecio/Iniscan/Command/ScanCommand.php | ScanCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
$path = $input->getOption('path');
$failOnly = $input->getOption('fail-only');
$format = $input->getOption('format');
$context = $input->getOption('context');
$threshold = $input->getOption('threshold');
$version = $input->getOption('php');
$outputPath = $input->getOption('output');
if ($format === 'html' && $outputPath === null) {
throw new \InvalidArgumentException('Output path must be set for format "HTML"');
}
$context = ($context !== null)
? explode(', ', $context) : array();
// If we're not given a version, assume the current version
if ($version === null) {
$version = PHP_VERSION;
}
// if we're not given a path at all, try to figure it out
if ($path === null) {
$path = php_ini_loaded_file();
}
if (!is_file($path)) {
throw new \Exception('Path is null or not accessible: "'.$path.'"');
}
$scan = new \Psecio\Iniscan\Scan($path, $context, $threshold, $version);
$results = $scan->execute();
$deprecated = $scan->getMarked();
$options = array(
'path' => $path,
'failOnly' => $failOnly,
'deprecated' => $deprecated,
'verbose' => $input->getOption('verbose'),
'output' => $outputPath
);
$format = ($format === null) ? 'console' : $format;
$formatClass = "\\Psecio\\Iniscan\\Command\\ScanCommand\\Output\\".ucwords(strtolower($format));
if (!class_exists($formatClass)) {
throw new \Psecio\Iniscan\Exceptions\FormatNotFoundException('Output format "'.$format.'" not found');
}
$outputHandler = new $formatClass($output, $options);
return $outputHandler->render($results);
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
$path = $input->getOption('path');
$failOnly = $input->getOption('fail-only');
$format = $input->getOption('format');
$context = $input->getOption('context');
$threshold = $input->getOption('threshold');
$version = $input->getOption('php');
$outputPath = $input->getOption('output');
if ($format === 'html' && $outputPath === null) {
throw new \InvalidArgumentException('Output path must be set for format "HTML"');
}
$context = ($context !== null)
? explode(', ', $context) : array();
// If we're not given a version, assume the current version
if ($version === null) {
$version = PHP_VERSION;
}
// if we're not given a path at all, try to figure it out
if ($path === null) {
$path = php_ini_loaded_file();
}
if (!is_file($path)) {
throw new \Exception('Path is null or not accessible: "'.$path.'"');
}
$scan = new \Psecio\Iniscan\Scan($path, $context, $threshold, $version);
$results = $scan->execute();
$deprecated = $scan->getMarked();
$options = array(
'path' => $path,
'failOnly' => $failOnly,
'deprecated' => $deprecated,
'verbose' => $input->getOption('verbose'),
'output' => $outputPath
);
$format = ($format === null) ? 'console' : $format;
$formatClass = "\\Psecio\\Iniscan\\Command\\ScanCommand\\Output\\".ucwords(strtolower($format));
if (!class_exists($formatClass)) {
throw new \Psecio\Iniscan\Exceptions\FormatNotFoundException('Output format "'.$format.'" not found');
}
$outputHandler = new $formatClass($output, $options);
return $outputHandler->render($results);
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"path",
"=",
"$",
"input",
"->",
"getOption",
"(",
"'path'",
")",
";",
"$",
"failOnly",
"=",
"$",
"input",
"->",
"getOption",
"... | Execute the "scan" command
@param InputInterface $input Input object
@param OutputInterface $output Output object
@throws \Psecio\Iniscan\Exceptions\FormatNotFoundException
@throws \Exception
@return null | [
"Execute",
"the",
"scan",
"command"
] | 880dede38298adb5a23171e304fe03410260b7e3 | https://github.com/psecio/iniscan/blob/880dede38298adb5a23171e304fe03410260b7e3/src/Psecio/Iniscan/Command/ScanCommand.php#L38-L88 | train |
psecio/iniscan | src/Psecio/Iniscan/Operation/OperationGreater.php | OperationGreater.execute | public function execute($key, $value, $ini)
{
$found = $this->findValue($key, $ini);
if ($this->getCast()->castValue($found) <= $this->getCast()->castValue($value)) {
return false;
}
return true;
} | php | public function execute($key, $value, $ini)
{
$found = $this->findValue($key, $ini);
if ($this->getCast()->castValue($found) <= $this->getCast()->castValue($value)) {
return false;
}
return true;
} | [
"public",
"function",
"execute",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"ini",
")",
"{",
"$",
"found",
"=",
"$",
"this",
"->",
"findValue",
"(",
"$",
"key",
",",
"$",
"ini",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getCast",
"(",
")",
... | Execute the "greater than" operation
If the value and the ini setting isn't greater than the value
@param string $key Key name of setting
@param string $value Value to match on
@param array $ini Current php.ini settings
@return boolean Pass/fail of operation | [
"Execute",
"the",
"greater",
"than",
"operation",
"If",
"the",
"value",
"and",
"the",
"ini",
"setting",
"isn",
"t",
"greater",
"than",
"the",
"value"
] | 880dede38298adb5a23171e304fe03410260b7e3 | https://github.com/psecio/iniscan/blob/880dede38298adb5a23171e304fe03410260b7e3/src/Psecio/Iniscan/Operation/OperationGreater.php#L16-L23 | train |
psecio/iniscan | src/Psecio/Iniscan/Command/ListCommand.php | ListCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
$format = $input->getOption('format');
$scan = new \Psecio\Iniscan\Scan();
$rules = $scan->getRules();
$options = array();
$format = ($format === null) ? 'console' : $format;
$formatClass = "\\Psecio\\Iniscan\\Command\\ListCommand\\Output\\".ucwords(strtolower($format));
if (!class_exists($formatClass)) {
throw new \Psecio\Iniscan\Exceptions\FormatNotFoundException('Output format "'.$format.'" not found');
}
$outputHandler = new $formatClass($output, $options);
return $outputHandler->render($rules);
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
$format = $input->getOption('format');
$scan = new \Psecio\Iniscan\Scan();
$rules = $scan->getRules();
$options = array();
$format = ($format === null) ? 'console' : $format;
$formatClass = "\\Psecio\\Iniscan\\Command\\ListCommand\\Output\\".ucwords(strtolower($format));
if (!class_exists($formatClass)) {
throw new \Psecio\Iniscan\Exceptions\FormatNotFoundException('Output format "'.$format.'" not found');
}
$outputHandler = new $formatClass($output, $options);
return $outputHandler->render($rules);
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"format",
"=",
"$",
"input",
"->",
"getOption",
"(",
"'format'",
")",
";",
"$",
"scan",
"=",
"new",
"\\",
"Psecio",
"\\",
"Inis... | Execute the "list" command
@param InputInterface $input Input object
@param OutputInterface $output Output object
@throws \Psecio\Iniscan\Exceptions\FormatNotFoundException
@return null | [
"Execute",
"the",
"list",
"command"
] | 880dede38298adb5a23171e304fe03410260b7e3 | https://github.com/psecio/iniscan/blob/880dede38298adb5a23171e304fe03410260b7e3/src/Psecio/Iniscan/Command/ListCommand.php#L31-L45 | train |
psecio/iniscan | src/Psecio/Iniscan/Command/InfoCommand.php | InfoCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
$setting = $input->getOption('setting');
$options = array();
if ($setting === null) {
throw new \Exception('No setting provided!');
}
$scan = new \Psecio\Iniscan\Scan();
$ruleSet = $scan->getRules();
// see if we can find info about the setting
$found = array();
foreach ($ruleSet as $section => $rules) {
foreach ($rules as $rule) {
if (isset($rule->test->key) && $rule->test->key === $setting) {
if (isset($rule->info)) {
$found[] = $rule;
}
}
}
}
if (!empty($found)) {
$outputHandler = new \Psecio\Iniscan\Command\InfoCommand\Output\Console($output, $options);
return $outputHandler->render($found);
} else {
$output->writeLn('No information found for setting '.$setting);
}
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
$setting = $input->getOption('setting');
$options = array();
if ($setting === null) {
throw new \Exception('No setting provided!');
}
$scan = new \Psecio\Iniscan\Scan();
$ruleSet = $scan->getRules();
// see if we can find info about the setting
$found = array();
foreach ($ruleSet as $section => $rules) {
foreach ($rules as $rule) {
if (isset($rule->test->key) && $rule->test->key === $setting) {
if (isset($rule->info)) {
$found[] = $rule;
}
}
}
}
if (!empty($found)) {
$outputHandler = new \Psecio\Iniscan\Command\InfoCommand\Output\Console($output, $options);
return $outputHandler->render($found);
} else {
$output->writeLn('No information found for setting '.$setting);
}
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"setting",
"=",
"$",
"input",
"->",
"getOption",
"(",
"'setting'",
")",
";",
"$",
"options",
"=",
"array",
"(",
")",
";",
"if",... | Execute the "info" command
@param InputInterface $input Input object
@param OutputInterface $output Output object
@throws \Exception
@return null | [
"Execute",
"the",
"info",
"command"
] | 880dede38298adb5a23171e304fe03410260b7e3 | https://github.com/psecio/iniscan/blob/880dede38298adb5a23171e304fe03410260b7e3/src/Psecio/Iniscan/Command/InfoCommand.php#L32-L62 | train |
psecio/iniscan | src/Psecio/Iniscan/Rule/CheckSessionPath.php | CheckSessionPath.evaluateFile | protected function evaluateFile(array $ini)
{
$savePath = $this->findValue('session.save_path', $ini);
if ($savePath === '/tmp') {
$this->setDescription('Custom path not set, default (/tmp) is world writeable');
$this->fail();
return false;
}
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$this->na();
$this->setDescription('Cannot check Windows permissions. Please verify them manually');
return true;
}
$perms = substr(sprintf('%o', fileperms($savePath)), - 3);
if ($perms == 777) {
$this->fail();
$this->setDescription('Path '.$savePath.' is world writeable');
return false;
} else {
$this->pass();
return true;
}
} | php | protected function evaluateFile(array $ini)
{
$savePath = $this->findValue('session.save_path', $ini);
if ($savePath === '/tmp') {
$this->setDescription('Custom path not set, default (/tmp) is world writeable');
$this->fail();
return false;
}
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$this->na();
$this->setDescription('Cannot check Windows permissions. Please verify them manually');
return true;
}
$perms = substr(sprintf('%o', fileperms($savePath)), - 3);
if ($perms == 777) {
$this->fail();
$this->setDescription('Path '.$savePath.' is world writeable');
return false;
} else {
$this->pass();
return true;
}
} | [
"protected",
"function",
"evaluateFile",
"(",
"array",
"$",
"ini",
")",
"{",
"$",
"savePath",
"=",
"$",
"this",
"->",
"findValue",
"(",
"'session.save_path'",
",",
"$",
"ini",
")",
";",
"if",
"(",
"$",
"savePath",
"===",
"'/tmp'",
")",
"{",
"$",
"this"... | Evaluate the session handling for file-based systems
@param array $ini Configuration settings (from php.ini)
@return boolean Pass/fail of evaluation | [
"Evaluate",
"the",
"session",
"handling",
"for",
"file",
"-",
"based",
"systems"
] | 880dede38298adb5a23171e304fe03410260b7e3 | https://github.com/psecio/iniscan/blob/880dede38298adb5a23171e304fe03410260b7e3/src/Psecio/Iniscan/Rule/CheckSessionPath.php#L44-L69 | train |
psecio/iniscan | src/Psecio/Iniscan/Command/ShowCommand.php | ShowCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
$path = $input->getOption('path');
// if we're not given a path at all, try to figure it out
if ($path === null) {
$path = php_ini_loaded_file();
}
if (!is_file($path)) {
throw new \Exception('Path is null or not accessible: "'.$path.'"');
}
$ini = parse_ini_file($path, true);
$output->writeLn('Current PHP.ini settings from '.$path);
$output->writeLn('##########');
foreach ($ini as $section => $data) {
$output->writeLn('<info>:: '.$section.'</info>');
if (empty($data)) {
$output->writeLn("\t<fg=yellow>No settings</fg=yellow>");
} else {
foreach ($data as $path => $value) {
$output->writeLn("\t".$path.' => '.var_export($value, true));
}
}
$output->writeLn("-----------------\n");
}
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
$path = $input->getOption('path');
// if we're not given a path at all, try to figure it out
if ($path === null) {
$path = php_ini_loaded_file();
}
if (!is_file($path)) {
throw new \Exception('Path is null or not accessible: "'.$path.'"');
}
$ini = parse_ini_file($path, true);
$output->writeLn('Current PHP.ini settings from '.$path);
$output->writeLn('##########');
foreach ($ini as $section => $data) {
$output->writeLn('<info>:: '.$section.'</info>');
if (empty($data)) {
$output->writeLn("\t<fg=yellow>No settings</fg=yellow>");
} else {
foreach ($data as $path => $value) {
$output->writeLn("\t".$path.' => '.var_export($value, true));
}
}
$output->writeLn("-----------------\n");
}
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"path",
"=",
"$",
"input",
"->",
"getOption",
"(",
"'path'",
")",
";",
"// if we're not given a path at all, try to figure it out",
"if",
... | Execute the "show" command
@param InputInterface $input Input object
@param OutputInterface $output Output object
@throws \Exception
@return null | [
"Execute",
"the",
"show",
"command"
] | 880dede38298adb5a23171e304fe03410260b7e3 | https://github.com/psecio/iniscan/blob/880dede38298adb5a23171e304fe03410260b7e3/src/Psecio/Iniscan/Command/ShowCommand.php#L31-L60 | train |
psecio/iniscan | src/Psecio/Iniscan/Operation.php | Operation.getSection | public function getSection($path)
{
$parts = explode('.', $path);
return (count($parts) === 1)
? 'PHP' : ucwords(strtolower($parts[0]));
} | php | public function getSection($path)
{
$parts = explode('.', $path);
return (count($parts) === 1)
? 'PHP' : ucwords(strtolower($parts[0]));
} | [
"public",
"function",
"getSection",
"(",
"$",
"path",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"path",
")",
";",
"return",
"(",
"count",
"(",
"$",
"parts",
")",
"===",
"1",
")",
"?",
"'PHP'",
":",
"ucwords",
"(",
"strtolower",
... | Get the current section name
@param string $path INI "path" for settings
@return string | [
"Get",
"the",
"current",
"section",
"name"
] | 880dede38298adb5a23171e304fe03410260b7e3 | https://github.com/psecio/iniscan/blob/880dede38298adb5a23171e304fe03410260b7e3/src/Psecio/Iniscan/Operation.php#L70-L75 | train |
psecio/iniscan | src/Psecio/Iniscan/Operation.php | Operation.findValue | public function findValue($path, &$ini)
{
$value = false;
if (array_key_exists($path, $ini)) {
$value = $ini[$path];
} else {
// not in the file, pull out the default
$value = ini_get($path);
$ini[$path] = $value;
}
return $value;
} | php | public function findValue($path, &$ini)
{
$value = false;
if (array_key_exists($path, $ini)) {
$value = $ini[$path];
} else {
// not in the file, pull out the default
$value = ini_get($path);
$ini[$path] = $value;
}
return $value;
} | [
"public",
"function",
"findValue",
"(",
"$",
"path",
",",
"&",
"$",
"ini",
")",
"{",
"$",
"value",
"=",
"false",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"path",
",",
"$",
"ini",
")",
")",
"{",
"$",
"value",
"=",
"$",
"ini",
"[",
"$",
"pat... | Find the given value in the INI array
If not found, returns the currently set value
@param string $path "Path" to the value
@param array $ini Current INI settings
@return string Found INI value | [
"Find",
"the",
"given",
"value",
"in",
"the",
"INI",
"array",
"If",
"not",
"found",
"returns",
"the",
"currently",
"set",
"value"
] | 880dede38298adb5a23171e304fe03410260b7e3 | https://github.com/psecio/iniscan/blob/880dede38298adb5a23171e304fe03410260b7e3/src/Psecio/Iniscan/Operation.php#L95-L108 | train |
psecio/iniscan | src/Psecio/Iniscan/Command/Output.php | Output.setOutput | public function setOutput(\Symfony\Component\Console\Output\OutputInterface $output)
{
$this->output = $output;
} | php | public function setOutput(\Symfony\Component\Console\Output\OutputInterface $output)
{
$this->output = $output;
} | [
"public",
"function",
"setOutput",
"(",
"\\",
"Symfony",
"\\",
"Component",
"\\",
"Console",
"\\",
"Output",
"\\",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"this",
"->",
"output",
"=",
"$",
"output",
";",
"}"
] | Set the Output object instance
@param \Symfony\Component\Console\Output\OutputInterface $output Object instance | [
"Set",
"the",
"Output",
"object",
"instance"
] | 880dede38298adb5a23171e304fe03410260b7e3 | https://github.com/psecio/iniscan/blob/880dede38298adb5a23171e304fe03410260b7e3/src/Psecio/Iniscan/Command/Output.php#L39-L42 | train |
psecio/iniscan | src/Psecio/Iniscan/Rule/DisableCliFunctions.php | DisableCliFunctions.evaluate | public function evaluate(array $ini)
{
$disableFunctions = $this->findValue('disable_functions', $ini);
if (isset($disableFunctions)) {
$functions = explode(',', $disableFunctions);
foreach ($functions as $function) {
$search = array_search($function, $this->functions);
if ($search !== false) {
unset($this->functions[$search]);
}
}
}
if (!empty($this->functions)) {
$this->setDescription('Methods still enabled - '.implode(', ', $this->functions));
$this->fail();
return false;
} else {
$this->pass();
return true;
}
} | php | public function evaluate(array $ini)
{
$disableFunctions = $this->findValue('disable_functions', $ini);
if (isset($disableFunctions)) {
$functions = explode(',', $disableFunctions);
foreach ($functions as $function) {
$search = array_search($function, $this->functions);
if ($search !== false) {
unset($this->functions[$search]);
}
}
}
if (!empty($this->functions)) {
$this->setDescription('Methods still enabled - '.implode(', ', $this->functions));
$this->fail();
return false;
} else {
$this->pass();
return true;
}
} | [
"public",
"function",
"evaluate",
"(",
"array",
"$",
"ini",
")",
"{",
"$",
"disableFunctions",
"=",
"$",
"this",
"->",
"findValue",
"(",
"'disable_functions'",
",",
"$",
"ini",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"disableFunctions",
")",
")",
"{",
... | Evaluate the operation
@param array $ini
@return boolean Pass/fail result | [
"Evaluate",
"the",
"operation"
] | 880dede38298adb5a23171e304fe03410260b7e3 | https://github.com/psecio/iniscan/blob/880dede38298adb5a23171e304fe03410260b7e3/src/Psecio/Iniscan/Rule/DisableCliFunctions.php#L42-L63 | train |
psecio/iniscan | src/Psecio/Iniscan/Rule.php | Rule.setConfig | public function setConfig($config)
{
if (is_object($config)) {
$config = get_object_vars($config);
}
foreach ($config as $index => $value) {
$this->$index = $value;
}
} | php | public function setConfig($config)
{
if (is_object($config)) {
$config = get_object_vars($config);
}
foreach ($config as $index => $value) {
$this->$index = $value;
}
} | [
"public",
"function",
"setConfig",
"(",
"$",
"config",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"config",
")",
")",
"{",
"$",
"config",
"=",
"get_object_vars",
"(",
"$",
"config",
")",
";",
"}",
"foreach",
"(",
"$",
"config",
"as",
"$",
"index",
... | Set the configuration values to the class properties
@param array $config Configuration values | [
"Set",
"the",
"configuration",
"values",
"to",
"the",
"class",
"properties"
] | 880dede38298adb5a23171e304fe03410260b7e3 | https://github.com/psecio/iniscan/blob/880dede38298adb5a23171e304fe03410260b7e3/src/Psecio/Iniscan/Rule.php#L101-L109 | train |
psecio/iniscan | src/Psecio/Iniscan/Rule.php | Rule.getSection | public function getSection($path = null)
{
if ($path !== null) {
$parts = explode('.', $path);
return (count($parts) == 1) ? 'PHP' : $parts[0];
} else {
return $this->section;
}
} | php | public function getSection($path = null)
{
if ($path !== null) {
$parts = explode('.', $path);
return (count($parts) == 1) ? 'PHP' : $parts[0];
} else {
return $this->section;
}
} | [
"public",
"function",
"getSection",
"(",
"$",
"path",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"path",
"!==",
"null",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"path",
")",
";",
"return",
"(",
"count",
"(",
"$",
"parts",
")",
... | Get the current section setting
@param string $path INI "path" to setting [optional]
@return string Section name | [
"Get",
"the",
"current",
"section",
"setting"
] | 880dede38298adb5a23171e304fe03410260b7e3 | https://github.com/psecio/iniscan/blob/880dede38298adb5a23171e304fe03410260b7e3/src/Psecio/Iniscan/Rule.php#L147-L155 | train |
psecio/iniscan | src/Psecio/Iniscan/Rule.php | Rule.values | public function values()
{
return array(
'name' => $this->name,
'description' => $this->description,
'level' => $this->level,
'status' => $this->status,
'currentValue' => $this->value,
);
} | php | public function values()
{
return array(
'name' => $this->name,
'description' => $this->description,
'level' => $this->level,
'status' => $this->status,
'currentValue' => $this->value,
);
} | [
"public",
"function",
"values",
"(",
")",
"{",
"return",
"array",
"(",
"'name'",
"=>",
"$",
"this",
"->",
"name",
",",
"'description'",
"=>",
"$",
"this",
"->",
"description",
",",
"'level'",
"=>",
"$",
"this",
"->",
"level",
",",
"'status'",
"=>",
"$"... | Output the values from the current rule as an array
@return array | [
"Output",
"the",
"values",
"from",
"the",
"current",
"rule",
"as",
"an",
"array"
] | 880dede38298adb5a23171e304fe03410260b7e3 | https://github.com/psecio/iniscan/blob/880dede38298adb5a23171e304fe03410260b7e3/src/Psecio/Iniscan/Rule.php#L321-L330 | train |
psecio/iniscan | src/Psecio/Iniscan/Rule.php | Rule.evaluate | public function evaluate(array $ini)
{
$test = $this->getTest();
$evalClass = "\\Psecio\\Iniscan\\Operation\\Operation".ucwords(strtolower($test->operation));
if (!class_exists($evalClass)) {
throw new \InvalidArgumentException('Invalid operation "'.$test->operation.'"');
}
$value = (isset($test->value)) ? $test->value : null;
$this->setValue($value);
$evalInstance = new $evalClass($this->getSection());
if (isset($test->version) && !$this->isVersion($test->version)) {
$this->na();
} else {
($evalInstance->execute($test->key, $value, $ini) === false)
? $this->fail() : $this->pass();
}
} | php | public function evaluate(array $ini)
{
$test = $this->getTest();
$evalClass = "\\Psecio\\Iniscan\\Operation\\Operation".ucwords(strtolower($test->operation));
if (!class_exists($evalClass)) {
throw new \InvalidArgumentException('Invalid operation "'.$test->operation.'"');
}
$value = (isset($test->value)) ? $test->value : null;
$this->setValue($value);
$evalInstance = new $evalClass($this->getSection());
if (isset($test->version) && !$this->isVersion($test->version)) {
$this->na();
} else {
($evalInstance->execute($test->key, $value, $ini) === false)
? $this->fail() : $this->pass();
}
} | [
"public",
"function",
"evaluate",
"(",
"array",
"$",
"ini",
")",
"{",
"$",
"test",
"=",
"$",
"this",
"->",
"getTest",
"(",
")",
";",
"$",
"evalClass",
"=",
"\"\\\\Psecio\\\\Iniscan\\\\Operation\\\\Operation\"",
".",
"ucwords",
"(",
"strtolower",
"(",
"$",
"t... | Evaluate the rule and its test
@param array $ini Current php.ini configuration
@throws \InvalidArgumentException
@return null | [
"Evaluate",
"the",
"rule",
"and",
"its",
"test"
] | 880dede38298adb5a23171e304fe03410260b7e3 | https://github.com/psecio/iniscan/blob/880dede38298adb5a23171e304fe03410260b7e3/src/Psecio/Iniscan/Rule.php#L361-L380 | train |
psecio/iniscan | src/Psecio/Iniscan/Rule.php | Rule.isVersion | public function isVersion($phpVersion)
{
$compare = version_compare($this->getVersion(), $phpVersion);
return ($compare === 1 || $compare === 0) ? true : false;
} | php | public function isVersion($phpVersion)
{
$compare = version_compare($this->getVersion(), $phpVersion);
return ($compare === 1 || $compare === 0) ? true : false;
} | [
"public",
"function",
"isVersion",
"(",
"$",
"phpVersion",
")",
"{",
"$",
"compare",
"=",
"version_compare",
"(",
"$",
"this",
"->",
"getVersion",
"(",
")",
",",
"$",
"phpVersion",
")",
";",
"return",
"(",
"$",
"compare",
"===",
"1",
"||",
"$",
"compar... | Checks to see if the current version is above or the same as the one given
@param string $phpVersion PHP version string
@return boolean Valid/invalid match | [
"Checks",
"to",
"see",
"if",
"the",
"current",
"version",
"is",
"above",
"or",
"the",
"same",
"as",
"the",
"one",
"given"
] | 880dede38298adb5a23171e304fe03410260b7e3 | https://github.com/psecio/iniscan/blob/880dede38298adb5a23171e304fe03410260b7e3/src/Psecio/Iniscan/Rule.php#L388-L392 | train |
psecio/iniscan | src/Psecio/Iniscan/Rule.php | Rule.respectThreshold | public function respectThreshold($wantedLevel) {
// If not threshold is given, always display the rule
if (is_null($wantedLevel)) {
return true;
}
$currentValue = $this->getLevelNumericalValue($this->level);
$wantedValue = $this->getLevelNumericalValue($wantedLevel);
return $currentValue >= $wantedValue;
} | php | public function respectThreshold($wantedLevel) {
// If not threshold is given, always display the rule
if (is_null($wantedLevel)) {
return true;
}
$currentValue = $this->getLevelNumericalValue($this->level);
$wantedValue = $this->getLevelNumericalValue($wantedLevel);
return $currentValue >= $wantedValue;
} | [
"public",
"function",
"respectThreshold",
"(",
"$",
"wantedLevel",
")",
"{",
"// If not threshold is given, always display the rule",
"if",
"(",
"is_null",
"(",
"$",
"wantedLevel",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"currentValue",
"=",
"$",
"this",
... | Check that the rule matches the wanted security level
@param string $wantedLevel The minimum level to display
@return bool | [
"Check",
"that",
"the",
"rule",
"matches",
"the",
"wanted",
"security",
"level"
] | 880dede38298adb5a23171e304fe03410260b7e3 | https://github.com/psecio/iniscan/blob/880dede38298adb5a23171e304fe03410260b7e3/src/Psecio/Iniscan/Rule.php#L400-L410 | train |
psecio/iniscan | src/Psecio/Iniscan/Rule.php | Rule.getLevelNumericalValue | public function getLevelNumericalValue($level) {
$level = strtolower($level);
if (isset($this->levelValues[$level])) {
return $this->levelValues[$level];
}
return 0;
} | php | public function getLevelNumericalValue($level) {
$level = strtolower($level);
if (isset($this->levelValues[$level])) {
return $this->levelValues[$level];
}
return 0;
} | [
"public",
"function",
"getLevelNumericalValue",
"(",
"$",
"level",
")",
"{",
"$",
"level",
"=",
"strtolower",
"(",
"$",
"level",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"levelValues",
"[",
"$",
"level",
"]",
")",
")",
"{",
"return",
"$"... | Return a numerical value for the level
@param string $level The level to convert to a number
@return int A numerical value representing the level | [
"Return",
"a",
"numerical",
"value",
"for",
"the",
"level"
] | 880dede38298adb5a23171e304fe03410260b7e3 | https://github.com/psecio/iniscan/blob/880dede38298adb5a23171e304fe03410260b7e3/src/Psecio/Iniscan/Rule.php#L418-L425 | train |
psecio/iniscan | src/Psecio/Iniscan/Scan.php | Scan.setPath | public function setPath($path)
{
if (!is_file($path)) {
throw new \InvalidArgumentException('Path '.$path.' invalid');
}
$this->path = realpath($path);
} | php | public function setPath($path)
{
if (!is_file($path)) {
throw new \InvalidArgumentException('Path '.$path.' invalid');
}
$this->path = realpath($path);
} | [
"public",
"function",
"setPath",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"is_file",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Path '",
".",
"$",
"path",
".",
"' invalid'",
")",
";",
"}",
"$",
"this"... | Set the ini path to evaluate
@param string $path Path to php.ini
@throws \InvalidArgumentException | [
"Set",
"the",
"ini",
"path",
"to",
"evaluate"
] | 880dede38298adb5a23171e304fe03410260b7e3 | https://github.com/psecio/iniscan/blob/880dede38298adb5a23171e304fe03410260b7e3/src/Psecio/Iniscan/Scan.php#L68-L74 | train |
psecio/iniscan | src/Psecio/Iniscan/Scan.php | Scan.getRules | public function getRules()
{
$settings = $this->getSettings();
if ($settings === false || !isset($settings->rules)) {
throw new \Exception('Rule configuration not found');
}
return $settings->rules;
} | php | public function getRules()
{
$settings = $this->getSettings();
if ($settings === false || !isset($settings->rules)) {
throw new \Exception('Rule configuration not found');
}
return $settings->rules;
} | [
"public",
"function",
"getRules",
"(",
")",
"{",
"$",
"settings",
"=",
"$",
"this",
"->",
"getSettings",
"(",
")",
";",
"if",
"(",
"$",
"settings",
"===",
"false",
"||",
"!",
"isset",
"(",
"$",
"settings",
"->",
"rules",
")",
")",
"{",
"throw",
"ne... | Get the current rules to evaluate
@return array Set of rules | [
"Get",
"the",
"current",
"rules",
"to",
"evaluate"
] | 880dede38298adb5a23171e304fe03410260b7e3 | https://github.com/psecio/iniscan/blob/880dede38298adb5a23171e304fe03410260b7e3/src/Psecio/Iniscan/Scan.php#L164-L171 | train |
psecio/iniscan | src/Psecio/Iniscan/Scan.php | Scan.getDeprecated | public function getDeprecated()
{
$settings = $this->getSettings();
if ($settings === false || !isset($settings->deprecated)) {
throw new \Exception('Deprecated configuration not found');
}
return $settings->deprecated;
} | php | public function getDeprecated()
{
$settings = $this->getSettings();
if ($settings === false || !isset($settings->deprecated)) {
throw new \Exception('Deprecated configuration not found');
}
return $settings->deprecated;
} | [
"public",
"function",
"getDeprecated",
"(",
")",
"{",
"$",
"settings",
"=",
"$",
"this",
"->",
"getSettings",
"(",
")",
";",
"if",
"(",
"$",
"settings",
"===",
"false",
"||",
"!",
"isset",
"(",
"$",
"settings",
"->",
"deprecated",
")",
")",
"{",
"thr... | Get the current set of deprecated settings from the config
@throws \Exception
@return array Set of deprecated settings | [
"Get",
"the",
"current",
"set",
"of",
"deprecated",
"settings",
"from",
"the",
"config"
] | 880dede38298adb5a23171e304fe03410260b7e3 | https://github.com/psecio/iniscan/blob/880dede38298adb5a23171e304fe03410260b7e3/src/Psecio/Iniscan/Scan.php#L179-L186 | train |
psecio/iniscan | src/Psecio/Iniscan/Scan.php | Scan.isDeprecated | public function isDeprecated($key, $phpVersion = PHP_VERSION)
{
$deprecated = $this->getDeprecated();
$ini = $this->getConfig();
// loop through the versions and see if our key is in there
if (property_exists($deprecated, $key))
{
$compare = version_compare($phpVersion, $deprecated->$key);
if ($compare >= 0 && isset($ini[$key])) {
$this->markKey($key);
return true;
}
}
return false;
} | php | public function isDeprecated($key, $phpVersion = PHP_VERSION)
{
$deprecated = $this->getDeprecated();
$ini = $this->getConfig();
// loop through the versions and see if our key is in there
if (property_exists($deprecated, $key))
{
$compare = version_compare($phpVersion, $deprecated->$key);
if ($compare >= 0 && isset($ini[$key])) {
$this->markKey($key);
return true;
}
}
return false;
} | [
"public",
"function",
"isDeprecated",
"(",
"$",
"key",
",",
"$",
"phpVersion",
"=",
"PHP_VERSION",
")",
"{",
"$",
"deprecated",
"=",
"$",
"this",
"->",
"getDeprecated",
"(",
")",
";",
"$",
"ini",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
";",
"/... | See if a setting is listing as deprecated in the PHP version given
@param string $key PHP.ini settings key
@param string $phpVersion Current PHP version [optional]
@return boolean Key is deprecated/not deprecated | [
"See",
"if",
"a",
"setting",
"is",
"listing",
"as",
"deprecated",
"in",
"the",
"PHP",
"version",
"given"
] | 880dede38298adb5a23171e304fe03410260b7e3 | https://github.com/psecio/iniscan/blob/880dede38298adb5a23171e304fe03410260b7e3/src/Psecio/Iniscan/Scan.php#L235-L250 | train |
psecio/iniscan | src/Psecio/Iniscan/Scan.php | Scan.execute | public function execute()
{
$path = $this->getPath();
$ini = $this->parseConfig($path);
$rules = $this->getRules();
$version = $this->getVersion();
$ruleList = array();
foreach ($rules as $section => $ruleSet) {
foreach ($ruleSet as $type => $rule) {
if (is_string($rule->test)) {
$ruleClass = "\\Psecio\\Iniscan\\Rule\\".$rule->test;
$rule = new $ruleClass($rule, $section);
} else {
// make a rule
$rule = new \Psecio\Iniscan\Rule($rule, $section);
}
$rule->setVersion($version);
$key = $rule->getTestKey();
if ($this->isDeprecated($key) === true) {
continue;
}
if (!$rule->respectThreshold($this->threshold)) {
continue;
}
// if we have contexts, check the rule
$ruleContext = $rule->getContext();
$scanContext = $this->getContext();
if ($ruleContext !== null) {
$int = array_intersect($ruleContext, $scanContext);
if (empty($int) && !empty($scanContext)) {
continue;
}
}
// execute its test
$rule->evaluate($ini);
$ruleList[] = $rule;
}
}
return $ruleList;
} | php | public function execute()
{
$path = $this->getPath();
$ini = $this->parseConfig($path);
$rules = $this->getRules();
$version = $this->getVersion();
$ruleList = array();
foreach ($rules as $section => $ruleSet) {
foreach ($ruleSet as $type => $rule) {
if (is_string($rule->test)) {
$ruleClass = "\\Psecio\\Iniscan\\Rule\\".$rule->test;
$rule = new $ruleClass($rule, $section);
} else {
// make a rule
$rule = new \Psecio\Iniscan\Rule($rule, $section);
}
$rule->setVersion($version);
$key = $rule->getTestKey();
if ($this->isDeprecated($key) === true) {
continue;
}
if (!$rule->respectThreshold($this->threshold)) {
continue;
}
// if we have contexts, check the rule
$ruleContext = $rule->getContext();
$scanContext = $this->getContext();
if ($ruleContext !== null) {
$int = array_intersect($ruleContext, $scanContext);
if (empty($int) && !empty($scanContext)) {
continue;
}
}
// execute its test
$rule->evaluate($ini);
$ruleList[] = $rule;
}
}
return $ruleList;
} | [
"public",
"function",
"execute",
"(",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"getPath",
"(",
")",
";",
"$",
"ini",
"=",
"$",
"this",
"->",
"parseConfig",
"(",
"$",
"path",
")",
";",
"$",
"rules",
"=",
"$",
"this",
"->",
"getRules",
"(",
... | Execute the scan
@return array Set of post-evaluation rules (with pass/fail status) | [
"Execute",
"the",
"scan"
] | 880dede38298adb5a23171e304fe03410260b7e3 | https://github.com/psecio/iniscan/blob/880dede38298adb5a23171e304fe03410260b7e3/src/Psecio/Iniscan/Scan.php#L280-L325 | train |
psecio/iniscan | src/Psecio/Iniscan/Command/FixCommand.php | FixCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
$path = $input->getOption('path');
$context = array();
// if we're not given a path at all, try to figure it out
if ($path === null) {
$path = php_ini_loaded_file();
}
if (!is_file($path)) {
throw new \Exception('Path is null or not accessible: "'.$path.'"');
}
$scan = new \Psecio\Iniscan\Scan($path, $context);
$scan->execute();
$scan->getMarked();
$result = pathinfo($path);
// to start, we need a backup of the file (overwrite if there)
$backupPath = './'.$result['basename'].'-'.date('mdy');
copy($path, $backupPath);
// Now les get our rules and parse them
$scan = new \Psecio\Iniscan\Scan($path, $context);
$rules = get_object_vars($scan->getRules());
$output->writeLn($this->generateIniOutput($rules));
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
$path = $input->getOption('path');
$context = array();
// if we're not given a path at all, try to figure it out
if ($path === null) {
$path = php_ini_loaded_file();
}
if (!is_file($path)) {
throw new \Exception('Path is null or not accessible: "'.$path.'"');
}
$scan = new \Psecio\Iniscan\Scan($path, $context);
$scan->execute();
$scan->getMarked();
$result = pathinfo($path);
// to start, we need a backup of the file (overwrite if there)
$backupPath = './'.$result['basename'].'-'.date('mdy');
copy($path, $backupPath);
// Now les get our rules and parse them
$scan = new \Psecio\Iniscan\Scan($path, $context);
$rules = get_object_vars($scan->getRules());
$output->writeLn($this->generateIniOutput($rules));
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"path",
"=",
"$",
"input",
"->",
"getOption",
"(",
"'path'",
")",
";",
"$",
"context",
"=",
"array",
"(",
")",
";",
"// if we'r... | Execute the "fix" command
@param InputInterface $input Input object
@param OutputInterface $output Output object
@throws \Exception
@return null | [
"Execute",
"the",
"fix",
"command"
] | 880dede38298adb5a23171e304fe03410260b7e3 | https://github.com/psecio/iniscan/blob/880dede38298adb5a23171e304fe03410260b7e3/src/Psecio/Iniscan/Command/FixCommand.php#L31-L60 | train |
psecio/iniscan | src/Psecio/Iniscan/Command/FixCommand.php | FixCommand.generateIniOutput | public function generateIniOutput($rules)
{
$ini = '';
$config = array();
foreach ($rules as $section => $ruleSet) {
foreach ($ruleSet as $rule) {
if (isset($rule->test)) {
if (is_object($rule->test)) {
if (!in_array($rule->test->operation, array('isset'))) {
$ini .= $rule->test->key.' = '.$rule->test->value."\n";
}
} else if (is_string($rule->test)) {
// no test object defined, this is a custom test
$testPath = '\\Psecio\\Iniscan\\Rule\\'.$rule->test;
if (class_exists($testPath)) {
$test = new $testPath($config, $section);
if (method_exists($test, '__toString')) {
$ini .= $test;
}
}
}
}
}
}
$ini .= "\n";
return $ini;
} | php | public function generateIniOutput($rules)
{
$ini = '';
$config = array();
foreach ($rules as $section => $ruleSet) {
foreach ($ruleSet as $rule) {
if (isset($rule->test)) {
if (is_object($rule->test)) {
if (!in_array($rule->test->operation, array('isset'))) {
$ini .= $rule->test->key.' = '.$rule->test->value."\n";
}
} else if (is_string($rule->test)) {
// no test object defined, this is a custom test
$testPath = '\\Psecio\\Iniscan\\Rule\\'.$rule->test;
if (class_exists($testPath)) {
$test = new $testPath($config, $section);
if (method_exists($test, '__toString')) {
$ini .= $test;
}
}
}
}
}
}
$ini .= "\n";
return $ini;
} | [
"public",
"function",
"generateIniOutput",
"(",
"$",
"rules",
")",
"{",
"$",
"ini",
"=",
"''",
";",
"$",
"config",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"section",
"=>",
"$",
"ruleSet",
")",
"{",
"foreach",
"(",
"$",... | Generate the output string of the more secure ini settings
@param array $rules Set of current rules
@return string INI string | [
"Generate",
"the",
"output",
"string",
"of",
"the",
"more",
"secure",
"ini",
"settings"
] | 880dede38298adb5a23171e304fe03410260b7e3 | https://github.com/psecio/iniscan/blob/880dede38298adb5a23171e304fe03410260b7e3/src/Psecio/Iniscan/Command/FixCommand.php#L68-L95 | train |
psecio/iniscan | src/Psecio/Iniscan/Cast.php | Cast.castValue | public function castValue($value)
{
if ($value === 'Off' || $value === '' || $value === 0 || $value === '0' || $value === false) {
$casted = 0;
} elseif ($value === 'On' || $value === '1' || $value === 1) {
$casted = 1;
} else {
$casted = $value;
}
$casted = $this->castPowers($casted);
return $casted;
} | php | public function castValue($value)
{
if ($value === 'Off' || $value === '' || $value === 0 || $value === '0' || $value === false) {
$casted = 0;
} elseif ($value === 'On' || $value === '1' || $value === 1) {
$casted = 1;
} else {
$casted = $value;
}
$casted = $this->castPowers($casted);
return $casted;
} | [
"public",
"function",
"castValue",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"'Off'",
"||",
"$",
"value",
"===",
"''",
"||",
"$",
"value",
"===",
"0",
"||",
"$",
"value",
"===",
"'0'",
"||",
"$",
"value",
"===",
"false",
")",
"... | Cast the values from php.ini to a standard format
@param mixed $value php.ini setting value
@return mixed "Casted" result | [
"Cast",
"the",
"values",
"from",
"php",
".",
"ini",
"to",
"a",
"standard",
"format"
] | 880dede38298adb5a23171e304fe03410260b7e3 | https://github.com/psecio/iniscan/blob/880dede38298adb5a23171e304fe03410260b7e3/src/Psecio/Iniscan/Cast.php#L13-L26 | train |
psecio/iniscan | src/Psecio/Iniscan/Cast.php | Cast.castPowers | public function castPowers ($casted) {
$postfixes = array(
'K' => 1024,
'M' => 1024 * 1024,
'G' => 1024 * 1024 * 1024,
);
$matches = array();
if (preg_match('/^([0-9]+)([' . implode('', array_keys($postfixes)) . '])$/', $casted, $matches)) {
$casted = $matches[1] * $postfixes[$matches[2]];
}
return $casted;
} | php | public function castPowers ($casted) {
$postfixes = array(
'K' => 1024,
'M' => 1024 * 1024,
'G' => 1024 * 1024 * 1024,
);
$matches = array();
if (preg_match('/^([0-9]+)([' . implode('', array_keys($postfixes)) . '])$/', $casted, $matches)) {
$casted = $matches[1] * $postfixes[$matches[2]];
}
return $casted;
} | [
"public",
"function",
"castPowers",
"(",
"$",
"casted",
")",
"{",
"$",
"postfixes",
"=",
"array",
"(",
"'K'",
"=>",
"1024",
",",
"'M'",
"=>",
"1024",
"*",
"1024",
",",
"'G'",
"=>",
"1024",
"*",
"1024",
"*",
"1024",
",",
")",
";",
"$",
"matches",
... | Cast the byte values ending with G, M or K to full integer values
@param $casted
@internal param $value
@return mixed "Casted" result | [
"Cast",
"the",
"byte",
"values",
"ending",
"with",
"G",
"M",
"or",
"K",
"to",
"full",
"integer",
"values"
] | 880dede38298adb5a23171e304fe03410260b7e3 | https://github.com/psecio/iniscan/blob/880dede38298adb5a23171e304fe03410260b7e3/src/Psecio/Iniscan/Cast.php#L35-L46 | train |
psecio/iniscan | src/Psecio/Iniscan/Operation/OperationIsset.php | OperationIsset.execute | public function execute($key, $value, $ini)
{
$found = $this->findValue($key, $ini);
if (empty($found)) {
return false;
}
return true;
} | php | public function execute($key, $value, $ini)
{
$found = $this->findValue($key, $ini);
if (empty($found)) {
return false;
}
return true;
} | [
"public",
"function",
"execute",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"ini",
")",
"{",
"$",
"found",
"=",
"$",
"this",
"->",
"findValue",
"(",
"$",
"key",
",",
"$",
"ini",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"found",
")",
")",
"{... | Execute the "is set" operation
If the value isn't set, return false
@param string $key Key name of setting
@param string $value Value to match on
@param array $ini Current php.ini settings
@return boolean Pass/fail of operation | [
"Execute",
"the",
"is",
"set",
"operation",
"If",
"the",
"value",
"isn",
"t",
"set",
"return",
"false"
] | 880dede38298adb5a23171e304fe03410260b7e3 | https://github.com/psecio/iniscan/blob/880dede38298adb5a23171e304fe03410260b7e3/src/Psecio/Iniscan/Operation/OperationIsset.php#L16-L23 | train |
psecio/iniscan | src/Psecio/Iniscan/Command/ScanCommand/Output/Html.php | Html.getOutputFilename | public function getOutputFilename($output)
{
// default behaviour / backwards compatibility
$outputDir = $output;
$outputFilename = $this->getDefaultOutputFilename();
// Find out if a .htm(l) filename has been given in the output argument.
if ($this->endsWith($output, ".htm") || $this->endsWith($output, ".html")) {
$outputDir = dirname($output);
$outputFilename = basename($output);
}
return $outputDir . DIRECTORY_SEPARATOR . $outputFilename;
} | php | public function getOutputFilename($output)
{
// default behaviour / backwards compatibility
$outputDir = $output;
$outputFilename = $this->getDefaultOutputFilename();
// Find out if a .htm(l) filename has been given in the output argument.
if ($this->endsWith($output, ".htm") || $this->endsWith($output, ".html")) {
$outputDir = dirname($output);
$outputFilename = basename($output);
}
return $outputDir . DIRECTORY_SEPARATOR . $outputFilename;
} | [
"public",
"function",
"getOutputFilename",
"(",
"$",
"output",
")",
"{",
"// default behaviour / backwards compatibility",
"$",
"outputDir",
"=",
"$",
"output",
";",
"$",
"outputFilename",
"=",
"$",
"this",
"->",
"getDefaultOutputFilename",
"(",
")",
";",
"// Find o... | Returns path and filename for the output file.
@param $output The output path configured via its argument | [
"Returns",
"path",
"and",
"filename",
"for",
"the",
"output",
"file",
"."
] | 880dede38298adb5a23171e304fe03410260b7e3 | https://github.com/psecio/iniscan/blob/880dede38298adb5a23171e304fe03410260b7e3/src/Psecio/Iniscan/Command/ScanCommand/Output/Html.php#L55-L68 | train |
teepluss/laravel-theme | src/Compilers/TwigCompiler.php | TwigCompiler.getTwigCompiler | public function getTwigCompiler($loader)
{
$this->twig = new Twig_Environment($loader, array(
'cache' => storage_path().'/views',
'autoescape' => false,
'auto_reload' => true
));
// Hook twig to do what you want.
$hooks = $this->config->get('theme.engines.twig.hooks');
$this->twig = $hooks($this->twig);
// Get facades aliases.
$aliases = $this->config->get('app.aliases');
// Laravel alias to allow.
$allows = $this->config->get('theme.engines.twig.allows');
foreach ($aliases as $alias => $class)
{
// Nothing allow if not exists in twig config.
if ( ! in_array($alias, $allows)) continue;
// Clasname with namspacing.
$className = '\\'.$alias;
// Some method is not in facade like Str.
if ( ! method_exists($className, 'getFacadeRoot'))
{
$this->twig->addGlobal($alias, new $className());
}
// Method support real facade.
else
{
$this->twig->addGlobal($alias, $className::getFacadeRoot());
}
}
/*$function = new Twig_SimpleFunction('call', function($function)
{
$args = func_get_args();
$args = array_splice($args, 1);
return call_user_func_array($function, $args);
});
$this->twig->addFunction($function);*/
return $this->twig;
} | php | public function getTwigCompiler($loader)
{
$this->twig = new Twig_Environment($loader, array(
'cache' => storage_path().'/views',
'autoescape' => false,
'auto_reload' => true
));
// Hook twig to do what you want.
$hooks = $this->config->get('theme.engines.twig.hooks');
$this->twig = $hooks($this->twig);
// Get facades aliases.
$aliases = $this->config->get('app.aliases');
// Laravel alias to allow.
$allows = $this->config->get('theme.engines.twig.allows');
foreach ($aliases as $alias => $class)
{
// Nothing allow if not exists in twig config.
if ( ! in_array($alias, $allows)) continue;
// Clasname with namspacing.
$className = '\\'.$alias;
// Some method is not in facade like Str.
if ( ! method_exists($className, 'getFacadeRoot'))
{
$this->twig->addGlobal($alias, new $className());
}
// Method support real facade.
else
{
$this->twig->addGlobal($alias, $className::getFacadeRoot());
}
}
/*$function = new Twig_SimpleFunction('call', function($function)
{
$args = func_get_args();
$args = array_splice($args, 1);
return call_user_func_array($function, $args);
});
$this->twig->addFunction($function);*/
return $this->twig;
} | [
"public",
"function",
"getTwigCompiler",
"(",
"$",
"loader",
")",
"{",
"$",
"this",
"->",
"twig",
"=",
"new",
"Twig_Environment",
"(",
"$",
"loader",
",",
"array",
"(",
"'cache'",
"=>",
"storage_path",
"(",
")",
".",
"'/views'",
",",
"'autoescape'",
"=>",
... | Twig compiler.
@param Twig_Loader_Filesystem $loader
@return Twig_Environment | [
"Twig",
"compiler",
"."
] | 244399b8ac60086b29fd94dd9546bb635855ce8a | https://github.com/teepluss/laravel-theme/blob/244399b8ac60086b29fd94dd9546bb635855ce8a/src/Compilers/TwigCompiler.php#L84-L133 | train |
teepluss/laravel-theme | src/Widget.php | Widget.endWidget | public function endWidget()
{
$data = (array) $this->run();
$this->data = array_merge($this->attributes, $data);
} | php | public function endWidget()
{
$data = (array) $this->run();
$this->data = array_merge($this->attributes, $data);
} | [
"public",
"function",
"endWidget",
"(",
")",
"{",
"$",
"data",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"run",
"(",
")",
";",
"$",
"this",
"->",
"data",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"attributes",
",",
"$",
"data",
")",
";",
"}"
] | End widget factory.
@return void | [
"End",
"widget",
"factory",
"."
] | 244399b8ac60086b29fd94dd9546bb635855ce8a | https://github.com/teepluss/laravel-theme/blob/244399b8ac60086b29fd94dd9546bb635855ce8a/src/Widget.php#L171-L176 | train |
teepluss/laravel-theme | src/Widget.php | Widget.render | public function render()
{
if ($this->enable == false)
{
return '';
}
$widgetDir = $this->config->get('theme.containerDir.widget');
$path = $this->theme->getThemeNamespace($widgetDir.'.'.$this->template);
// If not found in theme widgets directory, try to watch in views/widgets again.
if ($this->watch === true and ! $this->view->exists($path))
{
$path = $widgetDir.'.'.$this->template;
}
// Error file not exists.
if ( ! $this->view->exists($path))
{
throw new UnknownWidgetFileException("Widget view [$this->template] not found.");
}
$widget = $this->view->make($path, $this->data)->render();
return $widget;
} | php | public function render()
{
if ($this->enable == false)
{
return '';
}
$widgetDir = $this->config->get('theme.containerDir.widget');
$path = $this->theme->getThemeNamespace($widgetDir.'.'.$this->template);
// If not found in theme widgets directory, try to watch in views/widgets again.
if ($this->watch === true and ! $this->view->exists($path))
{
$path = $widgetDir.'.'.$this->template;
}
// Error file not exists.
if ( ! $this->view->exists($path))
{
throw new UnknownWidgetFileException("Widget view [$this->template] not found.");
}
$widget = $this->view->make($path, $this->data)->render();
return $widget;
} | [
"public",
"function",
"render",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"enable",
"==",
"false",
")",
"{",
"return",
"''",
";",
"}",
"$",
"widgetDir",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'theme.containerDir.widget'",
")",
";",
"... | Render widget to HTML.
@throws UnknownWidgetFileException
@return string | [
"Render",
"widget",
"to",
"HTML",
"."
] | 244399b8ac60086b29fd94dd9546bb635855ce8a | https://github.com/teepluss/laravel-theme/blob/244399b8ac60086b29fd94dd9546bb635855ce8a/src/Widget.php#L197-L223 | train |
teepluss/laravel-theme | src/Commands/WidgetGeneratorCommand.php | WidgetGeneratorCommand.getTemplate | protected function getTemplate($template)
{
$path = realpath(__DIR__.'/../templates/'.$template.'.txt');
return $this->files->get($path);
} | php | protected function getTemplate($template)
{
$path = realpath(__DIR__.'/../templates/'.$template.'.txt');
return $this->files->get($path);
} | [
"protected",
"function",
"getTemplate",
"(",
"$",
"template",
")",
"{",
"$",
"path",
"=",
"realpath",
"(",
"__DIR__",
".",
"'/../templates/'",
".",
"$",
"template",
".",
"'.txt'",
")",
";",
"return",
"$",
"this",
"->",
"files",
"->",
"get",
"(",
"$",
"... | Get default template.
@param string $template
@return string | [
"Get",
"default",
"template",
"."
] | 244399b8ac60086b29fd94dd9546bb635855ce8a | https://github.com/teepluss/laravel-theme/blob/244399b8ac60086b29fd94dd9546bb635855ce8a/src/Commands/WidgetGeneratorCommand.php#L220-L225 | train |
teepluss/laravel-theme | src/AssetContainer.php | AssetContainer.write | protected function write($name, $type, $source, $dependencies = array())
{
$types = array(
'script' => 'script',
'style' => 'style',
'js' => 'script',
'css' => 'style'
);
if (array_key_exists($type, $types))
{
$type = $types[$type];
$this->register($type, $name, $source, $dependencies, array());
}
return $this;
} | php | protected function write($name, $type, $source, $dependencies = array())
{
$types = array(
'script' => 'script',
'style' => 'style',
'js' => 'script',
'css' => 'style'
);
if (array_key_exists($type, $types))
{
$type = $types[$type];
$this->register($type, $name, $source, $dependencies, array());
}
return $this;
} | [
"protected",
"function",
"write",
"(",
"$",
"name",
",",
"$",
"type",
",",
"$",
"source",
",",
"$",
"dependencies",
"=",
"array",
"(",
")",
")",
"{",
"$",
"types",
"=",
"array",
"(",
"'script'",
"=>",
"'script'",
",",
"'style'",
"=>",
"'style'",
",",... | Write a content to the container.
@param string $name
@param string string
@param string $source
@param array $dependencies
@return AssetContainer | [
"Write",
"a",
"content",
"to",
"the",
"container",
"."
] | 244399b8ac60086b29fd94dd9546bb635855ce8a | https://github.com/teepluss/laravel-theme/blob/244399b8ac60086b29fd94dd9546bb635855ce8a/src/AssetContainer.php#L208-L225 | train |
teepluss/laravel-theme | src/AssetContainer.php | AssetContainer.writeScript | public function writeScript($name, $source, $dependencies = array())
{
$source = '<script>'.$source.'</script>';
return $this->write($name, 'script', $source, $dependencies);
} | php | public function writeScript($name, $source, $dependencies = array())
{
$source = '<script>'.$source.'</script>';
return $this->write($name, 'script', $source, $dependencies);
} | [
"public",
"function",
"writeScript",
"(",
"$",
"name",
",",
"$",
"source",
",",
"$",
"dependencies",
"=",
"array",
"(",
")",
")",
"{",
"$",
"source",
"=",
"'<script>'",
".",
"$",
"source",
".",
"'</script>'",
";",
"return",
"$",
"this",
"->",
"write",
... | Write a script to the container.
@param string $name
@param string string
@param string $source
@param array $dependencies
@return AssetContainer | [
"Write",
"a",
"script",
"to",
"the",
"container",
"."
] | 244399b8ac60086b29fd94dd9546bb635855ce8a | https://github.com/teepluss/laravel-theme/blob/244399b8ac60086b29fd94dd9546bb635855ce8a/src/AssetContainer.php#L236-L241 | train |
teepluss/laravel-theme | src/AssetContainer.php | AssetContainer.writeStyle | public function writeStyle($name, $source, $dependencies = array())
{
$source = '<style>'.$source.'</style>';
return $this->write($name, 'style', $source, $dependencies);
} | php | public function writeStyle($name, $source, $dependencies = array())
{
$source = '<style>'.$source.'</style>';
return $this->write($name, 'style', $source, $dependencies);
} | [
"public",
"function",
"writeStyle",
"(",
"$",
"name",
",",
"$",
"source",
",",
"$",
"dependencies",
"=",
"array",
"(",
")",
")",
"{",
"$",
"source",
"=",
"'<style>'",
".",
"$",
"source",
".",
"'</style>'",
";",
"return",
"$",
"this",
"->",
"write",
"... | Write a style to the container.
@param string $name
@param string string
@param string $source
@param array $dependencies
@return AssetContainer | [
"Write",
"a",
"style",
"to",
"the",
"container",
"."
] | 244399b8ac60086b29fd94dd9546bb635855ce8a | https://github.com/teepluss/laravel-theme/blob/244399b8ac60086b29fd94dd9546bb635855ce8a/src/AssetContainer.php#L252-L257 | train |
teepluss/laravel-theme | src/AssetContainer.php | AssetContainer.writeContent | public function writeContent($name, $source, $dependencies = array())
{
$source = $source;
return $this->write($name, 'script', $source, $dependencies);
} | php | public function writeContent($name, $source, $dependencies = array())
{
$source = $source;
return $this->write($name, 'script', $source, $dependencies);
} | [
"public",
"function",
"writeContent",
"(",
"$",
"name",
",",
"$",
"source",
",",
"$",
"dependencies",
"=",
"array",
"(",
")",
")",
"{",
"$",
"source",
"=",
"$",
"source",
";",
"return",
"$",
"this",
"->",
"write",
"(",
"$",
"name",
",",
"'script'",
... | Write a content without tag wrapper.
@param string $name
@param string string
@param string $source
@param array $dependencies
@return AssetContainer | [
"Write",
"a",
"content",
"without",
"tag",
"wrapper",
"."
] | 244399b8ac60086b29fd94dd9546bb635855ce8a | https://github.com/teepluss/laravel-theme/blob/244399b8ac60086b29fd94dd9546bb635855ce8a/src/AssetContainer.php#L268-L273 | train |
teepluss/laravel-theme | src/AssetContainer.php | AssetContainer.evaluatePath | protected function evaluatePath($source)
{
static $theme;
// Make theme to use few features.
if ( ! $theme)
{
$theme = \App::make('theme');
}
// Switch path to another theme.
if ( ! is_bool($this->usePath) and $theme->exists($this->usePath))
{
$currentTheme = $theme->getThemeName();
$source = str_replace($currentTheme, $this->usePath, $source);
}
return $source;
} | php | protected function evaluatePath($source)
{
static $theme;
// Make theme to use few features.
if ( ! $theme)
{
$theme = \App::make('theme');
}
// Switch path to another theme.
if ( ! is_bool($this->usePath) and $theme->exists($this->usePath))
{
$currentTheme = $theme->getThemeName();
$source = str_replace($currentTheme, $this->usePath, $source);
}
return $source;
} | [
"protected",
"function",
"evaluatePath",
"(",
"$",
"source",
")",
"{",
"static",
"$",
"theme",
";",
"// Make theme to use few features.",
"if",
"(",
"!",
"$",
"theme",
")",
"{",
"$",
"theme",
"=",
"\\",
"App",
"::",
"make",
"(",
"'theme'",
")",
";",
"}",... | Evaluate path to current theme or force use theme.
@param string $source
@return string | [
"Evaluate",
"path",
"to",
"current",
"theme",
"or",
"force",
"use",
"theme",
"."
] | 244399b8ac60086b29fd94dd9546bb635855ce8a | https://github.com/teepluss/laravel-theme/blob/244399b8ac60086b29fd94dd9546bb635855ce8a/src/AssetContainer.php#L336-L355 | train |
teepluss/laravel-theme | src/AssetContainer.php | AssetContainer.dependecyIsValid | protected function dependecyIsValid($asset, $dependency, $original, $assets)
{
if ( ! isset($original[$dependency]))
{
return false;
}
elseif ($dependency === $asset)
{
throw new \Exception("Asset [$asset] is dependent on itself.");
}
elseif (isset($assets[$dependency]) and in_array($asset, $assets[$dependency]['dependencies']))
{
throw new \Exception("Assets [$asset] and [$dependency] have a circular dependency.");
}
return true;
} | php | protected function dependecyIsValid($asset, $dependency, $original, $assets)
{
if ( ! isset($original[$dependency]))
{
return false;
}
elseif ($dependency === $asset)
{
throw new \Exception("Asset [$asset] is dependent on itself.");
}
elseif (isset($assets[$dependency]) and in_array($asset, $assets[$dependency]['dependencies']))
{
throw new \Exception("Assets [$asset] and [$dependency] have a circular dependency.");
}
return true;
} | [
"protected",
"function",
"dependecyIsValid",
"(",
"$",
"asset",
",",
"$",
"dependency",
",",
"$",
"original",
",",
"$",
"assets",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"original",
"[",
"$",
"dependency",
"]",
")",
")",
"{",
"return",
"false",
... | Verify that an asset's dependency is valid.
A dependency is considered valid if it exists, is not a circular reference, and is
not a reference to the owning asset itself. If the dependency doesn't exist, no
error or warning will be given. For the other cases, an exception is thrown.
@param string $asset
@param string $dependency
@param array $original
@param array $assets
@throws \Exception
@return bool | [
"Verify",
"that",
"an",
"asset",
"s",
"dependency",
"is",
"valid",
".",
"A",
"dependency",
"is",
"considered",
"valid",
"if",
"it",
"exists",
"is",
"not",
"a",
"circular",
"reference",
"and",
"is",
"not",
"a",
"reference",
"to",
"the",
"owning",
"asset",
... | 244399b8ac60086b29fd94dd9546bb635855ce8a | https://github.com/teepluss/laravel-theme/blob/244399b8ac60086b29fd94dd9546bb635855ce8a/src/AssetContainer.php#L626-L642 | train |
teepluss/laravel-theme | src/Asset.php | Asset.flush | public function flush()
{
foreach ($this->stacks['serves'] as $key => $val)
{
if (array_key_exists($key, $this->stacks['cooks']))
{
$callback = $this->stacks['cooks'][$key];
if ($callback instanceof Closure)
{
$callback($this);
}
}
}
} | php | public function flush()
{
foreach ($this->stacks['serves'] as $key => $val)
{
if (array_key_exists($key, $this->stacks['cooks']))
{
$callback = $this->stacks['cooks'][$key];
if ($callback instanceof Closure)
{
$callback($this);
}
}
}
} | [
"public",
"function",
"flush",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"stacks",
"[",
"'serves'",
"]",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"stacks",
"[",
... | Flush all cooks.
@return void | [
"Flush",
"all",
"cooks",
"."
] | 244399b8ac60086b29fd94dd9546bb635855ce8a | https://github.com/teepluss/laravel-theme/blob/244399b8ac60086b29fd94dd9546bb635855ce8a/src/Asset.php#L105-L119 | train |
teepluss/laravel-theme | src/Theme.php | Theme.symlink | public function symlink($theme)
{
$trace = debug_backtrace();
if (! isset($trace[1])) return;
$link = str_replace($this->getThemeName(), $theme, array_get($trace[1], 'file'));
extract($this->arguments);
extract($this->view->getShared());
return require($link);
} | php | public function symlink($theme)
{
$trace = debug_backtrace();
if (! isset($trace[1])) return;
$link = str_replace($this->getThemeName(), $theme, array_get($trace[1], 'file'));
extract($this->arguments);
extract($this->view->getShared());
return require($link);
} | [
"public",
"function",
"symlink",
"(",
"$",
"theme",
")",
"{",
"$",
"trace",
"=",
"debug_backtrace",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"trace",
"[",
"1",
"]",
")",
")",
"return",
";",
"$",
"link",
"=",
"str_replace",
"(",
"$",
"thi... | Link to another view.
<code>
// Look up view from another view in the same place.
Theme::symlink('another')
</code>
@param string $theme
@return string | [
"Link",
"to",
"another",
"view",
"."
] | 244399b8ac60086b29fd94dd9546bb635855ce8a | https://github.com/teepluss/laravel-theme/blob/244399b8ac60086b29fd94dd9546bb635855ce8a/src/Theme.php#L235-L247 | train |
teepluss/laravel-theme | src/Theme.php | Theme.symlinkWithFindInherit | public function symlinkWithFindInherit($theme)
{
$trace = debug_backtrace();
if (! isset($trace[1])) return;
// change backslash to forward slash (for windows file system)
$path = str_replace("\\", "/", array_get($trace[1], 'file'));
$config = $this->getConfig();
$link = preg_replace("#(public/{$config['themeDir']}/)[^/]+#", "$1{$theme}", $path);
extract($this->arguments);
extract($this->view->getShared());
return require($link);
} | php | public function symlinkWithFindInherit($theme)
{
$trace = debug_backtrace();
if (! isset($trace[1])) return;
// change backslash to forward slash (for windows file system)
$path = str_replace("\\", "/", array_get($trace[1], 'file'));
$config = $this->getConfig();
$link = preg_replace("#(public/{$config['themeDir']}/)[^/]+#", "$1{$theme}", $path);
extract($this->arguments);
extract($this->view->getShared());
return require($link);
} | [
"public",
"function",
"symlinkWithFindInherit",
"(",
"$",
"theme",
")",
"{",
"$",
"trace",
"=",
"debug_backtrace",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"trace",
"[",
"1",
"]",
")",
")",
"return",
";",
"// change backslash to forward slash (for w... | Symlink with inherit.
This method is the same symlink, but try to find inherit,
from config.
@param string $theme
@return string | [
"Symlink",
"with",
"inherit",
"."
] | 244399b8ac60086b29fd94dd9546bb635855ce8a | https://github.com/teepluss/laravel-theme/blob/244399b8ac60086b29fd94dd9546bb635855ce8a/src/Theme.php#L258-L275 | train |
teepluss/laravel-theme | src/Theme.php | Theme.getConfig | public function getConfig($key = null)
{
// Main package config.
if (! $this->themeConfig) {
$this->themeConfig = $this->config->get('theme');
}
// Config inside a public theme.
// This config having buffer by array object.
if ($this->theme and ! isset($this->themeConfig['themes'][$this->theme])) {
$this->themeConfig['themes'][$this->theme] = array();
try {
// Require public theme config.
$minorConfigPath = public_path($this->themeConfig['themeDir'].'/'.$this->theme.'/config.php');
$this->themeConfig['themes'][$this->theme] = $this->files->getRequire($minorConfigPath);
} catch (\Illuminate\Filesystem\FileNotFoundException $e) {
//var_dump($e->getMessage());
}
}
// Evaluate theme config.
$this->themeConfig = $this->evaluateConfig($this->themeConfig);
return is_null($key) ? $this->themeConfig : array_get($this->themeConfig, $key);
} | php | public function getConfig($key = null)
{
// Main package config.
if (! $this->themeConfig) {
$this->themeConfig = $this->config->get('theme');
}
// Config inside a public theme.
// This config having buffer by array object.
if ($this->theme and ! isset($this->themeConfig['themes'][$this->theme])) {
$this->themeConfig['themes'][$this->theme] = array();
try {
// Require public theme config.
$minorConfigPath = public_path($this->themeConfig['themeDir'].'/'.$this->theme.'/config.php');
$this->themeConfig['themes'][$this->theme] = $this->files->getRequire($minorConfigPath);
} catch (\Illuminate\Filesystem\FileNotFoundException $e) {
//var_dump($e->getMessage());
}
}
// Evaluate theme config.
$this->themeConfig = $this->evaluateConfig($this->themeConfig);
return is_null($key) ? $this->themeConfig : array_get($this->themeConfig, $key);
} | [
"public",
"function",
"getConfig",
"(",
"$",
"key",
"=",
"null",
")",
"{",
"// Main package config.",
"if",
"(",
"!",
"$",
"this",
"->",
"themeConfig",
")",
"{",
"$",
"this",
"->",
"themeConfig",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'th... | Get theme config.
@param string $key
@return mixed | [
"Get",
"theme",
"config",
"."
] | 244399b8ac60086b29fd94dd9546bb635855ce8a | https://github.com/teepluss/laravel-theme/blob/244399b8ac60086b29fd94dd9546bb635855ce8a/src/Theme.php#L283-L309 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.