repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6
values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1
value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
llaville/php-reflect | src/Bartlett/Reflect/Model/ClassModel.php | ClassModel.getStaticProperties | public function getStaticProperties()
{
if ($this->staticProperties === null) {
// lazy load class properties list
foreach ($this->node->stmts as $stmt) {
if ($stmt instanceof Node\Stmt\Property) {
if ($stmt->isStatic() === false) {
continue;
}
foreach ($stmt->props as $prop) {
$this->staticProperties[] = new PropertyModel($this, $prop);
}
}
}
}
return $this->staticProperties;
} | php | public function getStaticProperties()
{
if ($this->staticProperties === null) {
// lazy load class properties list
foreach ($this->node->stmts as $stmt) {
if ($stmt instanceof Node\Stmt\Property) {
if ($stmt->isStatic() === false) {
continue;
}
foreach ($stmt->props as $prop) {
$this->staticProperties[] = new PropertyModel($this, $prop);
}
}
}
}
return $this->staticProperties;
} | [
"public",
"function",
"getStaticProperties",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"staticProperties",
"===",
"null",
")",
"{",
"// lazy load class properties list",
"foreach",
"(",
"$",
"this",
"->",
"node",
"->",
"stmts",
"as",
"$",
"stmt",
")",
"{"... | Gets the static properties.
@return array An array of static properties. Property name in key, property value in value. | [
"Gets",
"the",
"static",
"properties",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Model/ClassModel.php#L259-L275 |
llaville/php-reflect | src/Bartlett/Reflect/Model/ClassModel.php | ClassModel.getStaticPropertyValue | public function getStaticPropertyValue($name)
{
$properties = $this->getStaticProperties();
if (array_key_exists($name, $properties)) {
return $properties[$name];
}
throw new ModelException(
'Property ' . $name . ' does not exist or is not static.'
);
} | php | public function getStaticPropertyValue($name)
{
$properties = $this->getStaticProperties();
if (array_key_exists($name, $properties)) {
return $properties[$name];
}
throw new ModelException(
'Property ' . $name . ' does not exist or is not static.'
);
} | [
"public",
"function",
"getStaticPropertyValue",
"(",
"$",
"name",
")",
"{",
"$",
"properties",
"=",
"$",
"this",
"->",
"getStaticProperties",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"properties",
")",
")",
"{",
"return",
... | Gets static property value.
@param string Name of static property
@return mixed
@throws ModelException if the property does not exist or is not static | [
"Gets",
"static",
"property",
"value",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Model/ClassModel.php#L285-L295 |
llaville/php-reflect | src/Bartlett/Reflect/Model/ClassModel.php | ClassModel.getProperties | public function getProperties()
{
if ($this->properties === null) {
// lazy load class properties list
$this->properties = array();
foreach ($this->node->stmts as $stmt) {
if ($stmt instanceof Node\Stmt\Property) {
$this->properties[] = new PropertyModel($this, $stmt);
}
}
}
return array_values($this->properties);
} | php | public function getProperties()
{
if ($this->properties === null) {
// lazy load class properties list
$this->properties = array();
foreach ($this->node->stmts as $stmt) {
if ($stmt instanceof Node\Stmt\Property) {
$this->properties[] = new PropertyModel($this, $stmt);
}
}
}
return array_values($this->properties);
} | [
"public",
"function",
"getProperties",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"properties",
"===",
"null",
")",
"{",
"// lazy load class properties list",
"$",
"this",
"->",
"properties",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->"... | Gets the properties.
@return array An array of PropertyModel objects reflecting each property. | [
"Gets",
"the",
"properties",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Model/ClassModel.php#L302-L314 |
llaville/php-reflect | src/Bartlett/Reflect/Model/ClassModel.php | ClassModel.getProperty | public function getProperty($name)
{
if ($this->hasProperty($name)) {
return $this->properties[$name];
}
throw new ModelException(
'Property ' . $name . ' does not exist.'
);
} | php | public function getProperty($name)
{
if ($this->hasProperty($name)) {
return $this->properties[$name];
}
throw new ModelException(
'Property ' . $name . ' does not exist.'
);
} | [
"public",
"function",
"getProperty",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasProperty",
"(",
"$",
"name",
")",
")",
"{",
"return",
"$",
"this",
"->",
"properties",
"[",
"$",
"name",
"]",
";",
"}",
"throw",
"new",
"ModelException... | Gets a PropertyModel for a class property.
@param string $name Property name to reflect.
@return PropertyModel
@throws ModelException if the property does not exist. | [
"Gets",
"a",
"PropertyModel",
"for",
"a",
"class",
"property",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Model/ClassModel.php#L337-L345 |
llaville/php-reflect | src/Bartlett/Reflect/Model/ClassModel.php | ClassModel.isFinal | public function isFinal()
{
if ($this->node instanceof Node\Stmt\Class_) {
return $this->node->isFinal();
}
return false;
} | php | public function isFinal()
{
if ($this->node instanceof Node\Stmt\Class_) {
return $this->node->isFinal();
}
return false;
} | [
"public",
"function",
"isFinal",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"node",
"instanceof",
"Node",
"\\",
"Stmt",
"\\",
"Class_",
")",
"{",
"return",
"$",
"this",
"->",
"node",
"->",
"isFinal",
"(",
")",
";",
"}",
"return",
"false",
";",
"}... | Checks whether this class is final.
@return bool TRUE if the class is final, FALSE otherwise. | [
"Checks",
"whether",
"this",
"class",
"is",
"final",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Model/ClassModel.php#L448-L454 |
llaville/php-reflect | src/Bartlett/Reflect/Model/ClassModel.php | ClassModel.isInstantiable | public function isInstantiable()
{
if ($this->isTrait() || $this->isInterface() || $this->isAbstract()) {
return false;
}
foreach (array('__construct', $this->getShortName()) as $method) {
if ($this->hasMethod($method)) {
return $this->getMethod($method)->isPublic();
}
}
return true;
} | php | public function isInstantiable()
{
if ($this->isTrait() || $this->isInterface() || $this->isAbstract()) {
return false;
}
foreach (array('__construct', $this->getShortName()) as $method) {
if ($this->hasMethod($method)) {
return $this->getMethod($method)->isPublic();
}
}
return true;
} | [
"public",
"function",
"isInstantiable",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isTrait",
"(",
")",
"||",
"$",
"this",
"->",
"isInterface",
"(",
")",
"||",
"$",
"this",
"->",
"isAbstract",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"for... | Checks whether this class is instantiable.
@return bool TRUE if the class is instantiable, FALSE otherwise. | [
"Checks",
"whether",
"this",
"class",
"is",
"instantiable",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Model/ClassModel.php#L461-L473 |
llaville/php-reflect | src/Bartlett/Reflect/Model/ClassModel.php | ClassModel.isSubclassOf | public function isSubclassOf($class)
{
return false; // @FIXME see unit tests
if (in_array($class, $this->struct['interfaces'])) {
// checks first if implement a specified interface
return true;
}
$parent = $this->getParentClass();
if (!empty($parent)) {
// checks second inheritance
if ($parent->getName() === $class) {
// checks class name
return true;
}
// then checks interfaces implemented
return in_array($class, $parent->getInterfaceNames());
}
return false;
} | php | public function isSubclassOf($class)
{
return false; // @FIXME see unit tests
if (in_array($class, $this->struct['interfaces'])) {
// checks first if implement a specified interface
return true;
}
$parent = $this->getParentClass();
if (!empty($parent)) {
// checks second inheritance
if ($parent->getName() === $class) {
// checks class name
return true;
}
// then checks interfaces implemented
return in_array($class, $parent->getInterfaceNames());
}
return false;
} | [
"public",
"function",
"isSubclassOf",
"(",
"$",
"class",
")",
"{",
"return",
"false",
";",
"// @FIXME see unit tests",
"if",
"(",
"in_array",
"(",
"$",
"class",
",",
"$",
"this",
"->",
"struct",
"[",
"'interfaces'",
"]",
")",
")",
"{",
"// checks first if im... | Checks if the class is a subclass of a specified class
or implements a specified interface.
@param string $class The class name being checked against.
@return bool TRUE if the class is a subclass, FALSE otherwise. | [
"Checks",
"if",
"the",
"class",
"is",
"a",
"subclass",
"of",
"a",
"specified",
"class",
"or",
"implements",
"a",
"specified",
"interface",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Model/ClassModel.php#L483-L504 |
llaville/php-reflect | src/Bartlett/Reflect/Plugin/LogPlugin.php | LogPlugin.getSubscribedEvents | public static function getSubscribedEvents()
{
return array(
Reflect\Events::PROGRESS => 'onReflectProgress',
Reflect\Events::SUCCESS => 'onReflectSuccess',
Reflect\Events::ERROR => 'onReflectError',
Reflect\Events::COMPLETE => 'onReflectComplete',
Reflect\Events::BUILD => 'onAstBuild',
Reflect\Events::SNIFF => 'onSniff',
);
} | php | public static function getSubscribedEvents()
{
return array(
Reflect\Events::PROGRESS => 'onReflectProgress',
Reflect\Events::SUCCESS => 'onReflectSuccess',
Reflect\Events::ERROR => 'onReflectError',
Reflect\Events::COMPLETE => 'onReflectComplete',
Reflect\Events::BUILD => 'onAstBuild',
Reflect\Events::SNIFF => 'onSniff',
);
} | [
"public",
"static",
"function",
"getSubscribedEvents",
"(",
")",
"{",
"return",
"array",
"(",
"Reflect",
"\\",
"Events",
"::",
"PROGRESS",
"=>",
"'onReflectProgress'",
",",
"Reflect",
"\\",
"Events",
"::",
"SUCCESS",
"=>",
"'onReflectSuccess'",
",",
"Reflect",
"... | {@inheritdoc} | [
"{"
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Plugin/LogPlugin.php#L69-L79 |
llaville/php-reflect | src/Bartlett/Reflect/Plugin/LogPlugin.php | LogPlugin.onReflectProgress | public function onReflectProgress(GenericEvent $event)
{
$context = $event->getArguments();
$this->logger->info('Parsing file "{file}" in progress.', $context);
} | php | public function onReflectProgress(GenericEvent $event)
{
$context = $event->getArguments();
$this->logger->info('Parsing file "{file}" in progress.', $context);
} | [
"public",
"function",
"onReflectProgress",
"(",
"GenericEvent",
"$",
"event",
")",
"{",
"$",
"context",
"=",
"$",
"event",
"->",
"getArguments",
"(",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"'Parsing file \"{file}\" in progress.'",
",",
"$",
... | Logs PROGRESS event.
@param Event $event Current event emitted by the manager (Reflect class)
@return void | [
"Logs",
"PROGRESS",
"event",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Plugin/LogPlugin.php#L88-L92 |
llaville/php-reflect | src/Bartlett/Reflect/Plugin/LogPlugin.php | LogPlugin.onReflectSuccess | public function onReflectSuccess(GenericEvent $event)
{
$context = $event->getArguments();
$this->logger->info('Analyze file "{file}" successful.', $context);
} | php | public function onReflectSuccess(GenericEvent $event)
{
$context = $event->getArguments();
$this->logger->info('Analyze file "{file}" successful.', $context);
} | [
"public",
"function",
"onReflectSuccess",
"(",
"GenericEvent",
"$",
"event",
")",
"{",
"$",
"context",
"=",
"$",
"event",
"->",
"getArguments",
"(",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"'Analyze file \"{file}\" successful.'",
",",
"$",
... | Logs SUCCESS event.
@param Event $event Current event emitted by the manager (Reflect class)
@return void | [
"Logs",
"SUCCESS",
"event",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Plugin/LogPlugin.php#L101-L105 |
llaville/php-reflect | src/Bartlett/Reflect/Plugin/LogPlugin.php | LogPlugin.onReflectError | public function onReflectError(GenericEvent $event)
{
$context = $event->getArguments();
$this->logger->error('Parser has detected an error on file "{file}". {error}', $context);
} | php | public function onReflectError(GenericEvent $event)
{
$context = $event->getArguments();
$this->logger->error('Parser has detected an error on file "{file}". {error}', $context);
} | [
"public",
"function",
"onReflectError",
"(",
"GenericEvent",
"$",
"event",
")",
"{",
"$",
"context",
"=",
"$",
"event",
"->",
"getArguments",
"(",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"error",
"(",
"'Parser has detected an error on file \"{file}\". {error}... | Logs ERROR event.
@param Event $event Current event emitted by the manager (Reflect class)
@return void | [
"Logs",
"ERROR",
"event",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Plugin/LogPlugin.php#L114-L118 |
llaville/php-reflect | src/Bartlett/Reflect/Plugin/LogPlugin.php | LogPlugin.onReflectComplete | public function onReflectComplete(GenericEvent $event)
{
$context = $event->getArguments();
unset($context['extra']);
$this->logger->notice('Parsing data source "{source}" completed.', $context);
} | php | public function onReflectComplete(GenericEvent $event)
{
$context = $event->getArguments();
unset($context['extra']);
$this->logger->notice('Parsing data source "{source}" completed.', $context);
} | [
"public",
"function",
"onReflectComplete",
"(",
"GenericEvent",
"$",
"event",
")",
"{",
"$",
"context",
"=",
"$",
"event",
"->",
"getArguments",
"(",
")",
";",
"unset",
"(",
"$",
"context",
"[",
"'extra'",
"]",
")",
";",
"$",
"this",
"->",
"logger",
"-... | Logs COMPLETE event.
@param Event $event Current event emitted by the manager (Reflect class)
@return void | [
"Logs",
"COMPLETE",
"event",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Plugin/LogPlugin.php#L127-L132 |
llaville/php-reflect | src/Bartlett/Reflect/Plugin/LogPlugin.php | LogPlugin.onAstBuild | public function onAstBuild(GenericEvent $event)
{
$context = $event->getArguments();
if (isset($context['node'])) {
$context['node'] = sprintf(
'%s with attributes %s',
$context['node']->getType(),
json_encode($context['node']->getAttributes())
);
}
$this->logger->debug('Building AST, process {method} {node}', $context);
} | php | public function onAstBuild(GenericEvent $event)
{
$context = $event->getArguments();
if (isset($context['node'])) {
$context['node'] = sprintf(
'%s with attributes %s',
$context['node']->getType(),
json_encode($context['node']->getAttributes())
);
}
$this->logger->debug('Building AST, process {method} {node}', $context);
} | [
"public",
"function",
"onAstBuild",
"(",
"GenericEvent",
"$",
"event",
")",
"{",
"$",
"context",
"=",
"$",
"event",
"->",
"getArguments",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"context",
"[",
"'node'",
"]",
")",
")",
"{",
"$",
"context",
"[",
... | Logs BUILD event.
@param Event $event Current event emitted by the builder
@return void | [
"Logs",
"BUILD",
"event",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Plugin/LogPlugin.php#L141-L153 |
llaville/php-reflect | src/Bartlett/Reflect/Plugin/LogPlugin.php | LogPlugin.onSniff | public function onSniff(GenericEvent $event)
{
$context = $event->getArguments();
$this->logger->debug('Visiting SNIFF, process {method} {sniff}', $context);
} | php | public function onSniff(GenericEvent $event)
{
$context = $event->getArguments();
$this->logger->debug('Visiting SNIFF, process {method} {sniff}', $context);
} | [
"public",
"function",
"onSniff",
"(",
"GenericEvent",
"$",
"event",
")",
"{",
"$",
"context",
"=",
"$",
"event",
"->",
"getArguments",
"(",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'Visiting SNIFF, process {method} {sniff}'",
",",
"$",
"co... | Logs SNIFF event.
@param Event $event Current event emitted by the sniffer
@return void | [
"Logs",
"SNIFF",
"event",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Plugin/LogPlugin.php#L162-L167 |
llaville/php-reflect | src/Bartlett/Reflect/Model/PropertyModel.php | PropertyModel.getValue | public function getValue()
{
if (!empty($this->node->props[0]->default->value)) {
return $this->node->props[0]->default->value;
}
return;
} | php | public function getValue()
{
if (!empty($this->node->props[0]->default->value)) {
return $this->node->props[0]->default->value;
}
return;
} | [
"public",
"function",
"getValue",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"node",
"->",
"props",
"[",
"0",
"]",
"->",
"default",
"->",
"value",
")",
")",
"{",
"return",
"$",
"this",
"->",
"node",
"->",
"props",
"[",
"0",
... | Gets the property value.
@return mixed | [
"Gets",
"the",
"property",
"value",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Model/PropertyModel.php#L67-L73 |
llaville/php-reflect | src/Bartlett/Reflect/Api/V3/Cache.php | Cache.clear | public function clear($source, $alias = null)
{
$source = trim($source);
if ($alias) {
$alias = $source;
} else {
$alias = false;
}
$finder = $this->findProvider($source, $alias);
if ($finder === false) {
throw new \RuntimeException(
'None data source matching'
);
}
$pm = new PluginManager($this->eventDispatcher);
if (!$this->registerPlugins) {
return 0;
}
$pm->registerPlugins();
foreach ($pm->getPlugins() as $plugin) {
if ($plugin instanceof CachePlugin) {
$cache = $plugin->getCacheStorage();
break;
}
}
$entriesCleared = $cache->purge($this->dataSourceId);
return $entriesCleared;
} | php | public function clear($source, $alias = null)
{
$source = trim($source);
if ($alias) {
$alias = $source;
} else {
$alias = false;
}
$finder = $this->findProvider($source, $alias);
if ($finder === false) {
throw new \RuntimeException(
'None data source matching'
);
}
$pm = new PluginManager($this->eventDispatcher);
if (!$this->registerPlugins) {
return 0;
}
$pm->registerPlugins();
foreach ($pm->getPlugins() as $plugin) {
if ($plugin instanceof CachePlugin) {
$cache = $plugin->getCacheStorage();
break;
}
}
$entriesCleared = $cache->purge($this->dataSourceId);
return $entriesCleared;
} | [
"public",
"function",
"clear",
"(",
"$",
"source",
",",
"$",
"alias",
"=",
"null",
")",
"{",
"$",
"source",
"=",
"trim",
"(",
"$",
"source",
")",
";",
"if",
"(",
"$",
"alias",
")",
"{",
"$",
"alias",
"=",
"$",
"source",
";",
"}",
"else",
"{",
... | Clear cache (any adapter and backend).
@param string $source Path to the data source or its alias.
@param string $alias If set, the source refers to its alias.
@return int Number of entries cleared in cache
@throws \Exception if data source provider is unknown
@throws \RuntimeException if cache plugin is not installed | [
"Clear",
"cache",
"(",
"any",
"adapter",
"and",
"backend",
")",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Api/V3/Cache.php#L41-L73 |
llaville/php-reflect | src/Bartlett/Reflect/Model/MethodModel.php | MethodModel.isConstructor | public function isConstructor()
{
$name = explode('\\', $this->declaringClass->getName());
$name = array_pop($name);
return in_array($this->getShortName(), array('__construct', $name));
} | php | public function isConstructor()
{
$name = explode('\\', $this->declaringClass->getName());
$name = array_pop($name);
return in_array($this->getShortName(), array('__construct', $name));
} | [
"public",
"function",
"isConstructor",
"(",
")",
"{",
"$",
"name",
"=",
"explode",
"(",
"'\\\\'",
",",
"$",
"this",
"->",
"declaringClass",
"->",
"getName",
"(",
")",
")",
";",
"$",
"name",
"=",
"array_pop",
"(",
"$",
"name",
")",
";",
"return",
"in_... | Checks if the method is a constructor.
@return bool TRUE if the method is a constructor, otherwise FALSE | [
"Checks",
"if",
"the",
"method",
"is",
"a",
"constructor",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Model/MethodModel.php#L77-L83 |
llaville/php-reflect | src/Bartlett/Reflect/Api/V3/Diagram.php | Diagram.package | public function package($argument, $source, $alias = null, $engine = 'plantuml')
{
return $this->getDiagram(
$engine,
$source,
__FUNCTION__,
$argument
);
} | php | public function package($argument, $source, $alias = null, $engine = 'plantuml')
{
return $this->getDiagram(
$engine,
$source,
__FUNCTION__,
$argument
);
} | [
"public",
"function",
"package",
"(",
"$",
"argument",
",",
"$",
"source",
",",
"$",
"alias",
"=",
"null",
",",
"$",
"engine",
"=",
"'plantuml'",
")",
"{",
"return",
"$",
"this",
"->",
"getDiagram",
"(",
"$",
"engine",
",",
"$",
"source",
",",
"__FUN... | Generates diagram about namespaces in a data source.
@param string $argument Name of the namespace to inspect.
@param string $source Path to the data source or its alias.
@param mixed $alias If set, the source refers to its alias.
@param string $engine Graphical syntax.
@return mixed | [
"Generates",
"diagram",
"about",
"namespaces",
"in",
"a",
"data",
"source",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Api/V3/Diagram.php#L48-L56 |
llaville/php-reflect | src/Bartlett/Reflect/Event/AbstractDispatcher.php | AbstractDispatcher.dispatch | public function dispatch($eventName, array $context = array())
{
return $this->getEventDispatcher()->dispatch(
$eventName,
new GenericEvent($this, $context)
);
} | php | public function dispatch($eventName, array $context = array())
{
return $this->getEventDispatcher()->dispatch(
$eventName,
new GenericEvent($this, $context)
);
} | [
"public",
"function",
"dispatch",
"(",
"$",
"eventName",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getEventDispatcher",
"(",
")",
"->",
"dispatch",
"(",
"$",
"eventName",
",",
"new",
"GenericEvent",
"("... | Dispatches an event to all registered listeners.
@param string $eventName The name of the event to dispatch
@param array $context (optional) Contextual event data
@return Symfony\Component\EventDispatcher\GenericEvent
@disabled | [
"Dispatches",
"an",
"event",
"to",
"all",
"registered",
"listeners",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Event/AbstractDispatcher.php#L76-L82 |
llaville/php-reflect | src/Bartlett/Reflect/Model/ParameterModel.php | ParameterModel.getTypeHint | public function getTypeHint()
{
$typeHint = $this->node->type;
if ($typeHint instanceof Node\Name) {
$typeHint = (string) $typeHint;
}
return $typeHint;
} | php | public function getTypeHint()
{
$typeHint = $this->node->type;
if ($typeHint instanceof Node\Name) {
$typeHint = (string) $typeHint;
}
return $typeHint;
} | [
"public",
"function",
"getTypeHint",
"(",
")",
"{",
"$",
"typeHint",
"=",
"$",
"this",
"->",
"node",
"->",
"type",
";",
"if",
"(",
"$",
"typeHint",
"instanceof",
"Node",
"\\",
"Name",
")",
"{",
"$",
"typeHint",
"=",
"(",
"string",
")",
"$",
"typeHint... | Gets the type of the parameter.
@return mixed Blank when none, 'Closure', 'callable', 'array', or class name. | [
"Gets",
"the",
"type",
"of",
"the",
"parameter",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Model/ParameterModel.php#L72-L79 |
llaville/php-reflect | src/Bartlett/Reflect/Model/ParameterModel.php | ParameterModel.allowsNull | public function allowsNull()
{
if (!empty($this->node->type)) {
// with type hint, checks if NULL constant provided
if ($this->node->default instanceof Node\Expr\ConstFetch
&& $this->node->default->name instanceof Node\Name
&& strcasecmp('null', (string)$this->node->default->name) === 0
) {
return true;
}
return false;
}
return true;
} | php | public function allowsNull()
{
if (!empty($this->node->type)) {
// with type hint, checks if NULL constant provided
if ($this->node->default instanceof Node\Expr\ConstFetch
&& $this->node->default->name instanceof Node\Name
&& strcasecmp('null', (string)$this->node->default->name) === 0
) {
return true;
}
return false;
}
return true;
} | [
"public",
"function",
"allowsNull",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"node",
"->",
"type",
")",
")",
"{",
"// with type hint, checks if NULL constant provided",
"if",
"(",
"$",
"this",
"->",
"node",
"->",
"default",
"instanceof... | Checks whether the parameter allows NULL.
If a type is defined, null is allowed only if default value is null.
@return bool TRUE if NULL is allowed, otherwise FALSE | [
"Checks",
"whether",
"the",
"parameter",
"allows",
"NULL",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Model/ParameterModel.php#L88-L101 |
llaville/php-reflect | src/Bartlett/Reflect/Model/ParameterModel.php | ParameterModel.getDefaultValue | public function getDefaultValue()
{
if ($this->isDefaultValueAvailable()) {
$prettyPrinter = new PrettyPrinter\Standard;
return $prettyPrinter->prettyPrintExpr($this->node->default);
}
throw new ModelException(
sprintf(
'Parameter #%d [$%s] is not optional.',
$this->getPosition(),
$this->getName()
)
);
} | php | public function getDefaultValue()
{
if ($this->isDefaultValueAvailable()) {
$prettyPrinter = new PrettyPrinter\Standard;
return $prettyPrinter->prettyPrintExpr($this->node->default);
}
throw new ModelException(
sprintf(
'Parameter #%d [$%s] is not optional.',
$this->getPosition(),
$this->getName()
)
);
} | [
"public",
"function",
"getDefaultValue",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isDefaultValueAvailable",
"(",
")",
")",
"{",
"$",
"prettyPrinter",
"=",
"new",
"PrettyPrinter",
"\\",
"Standard",
";",
"return",
"$",
"prettyPrinter",
"->",
"prettyPrintExp... | Gets the default value of the parameter for a user-defined function or method.
If the parameter is not optional a ModelException will be thrown.
@return mixed
@throws ModelException if the parameter is not optional | [
"Gets",
"the",
"default",
"value",
"of",
"the",
"parameter",
"for",
"a",
"user",
"-",
"defined",
"function",
"or",
"method",
".",
"If",
"the",
"parameter",
"is",
"not",
"optional",
"a",
"ModelException",
"will",
"be",
"thrown",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Model/ParameterModel.php#L170-L183 |
llaville/php-reflect | src/Bartlett/Reflect/Api/V3/Common.php | Common.findProvider | protected function findProvider($source, $alias)
{
if (!$alias) {
$src = realpath($source);
if (PATH_SEPARATOR == ';') {
// on windows platform, remove the drive identifier
$src = substr($src, 2);
}
if (is_dir($src)) {
$provider = array('in' => $src);
} elseif (is_file($src)) {
$ext = pathinfo($src, PATHINFO_EXTENSION);
if (in_array($ext, array('phar', 'zip', 'gz', 'tar', 'tgz', 'rar'))) {
// archive file
$provider = array('in' => 'phar://' . $src);
} else {
$provider = array('in' => dirname($src), 'name' => basename($src));
$this->dataSourceId = $src;
}
}
}
if (!isset($provider)) {
// when $source identify an entry of a json config file
$filename = Environment::getJsonConfigFilename();
if ($filename === false) {
return false;
}
// try to validate syntax and content of this json config file
$config = new Config();
$var = $config->validate($filename);
foreach ($var['source-providers'] as $provider) {
$in = trim($provider['in']);
if (empty($in)) {
// this source provider is incomplete: empty "in" key
return false;
}
$src = explode(' as ', $in);
$src = array_map('trim', $src);
if (!empty($alias) && count($src) < 2) {
// searching on alias, which is not provided
continue;
}
$i = empty($alias) ? 0 : 1;
// search on data source path ($i = 0) or alias ($i = 1)
if ($src[$i] == $source) {
$provider['in'] = $src[0];
break;
}
unset($provider);
}
if (!isset($provider)) {
// data source not found
return false;
}
}
if (substr($provider['in'], 0, 1) == '.') {
// relative local file
$provider['in'] = realpath($provider['in']);
}
if (PATH_SEPARATOR == ';') {
// normalizes path to unix format
$provider['in'] = str_replace(DIRECTORY_SEPARATOR, '/', $provider['in']);
}
if (!isset($provider['name'])) {
// default file extensions to scan
$provider['name'] = '/\\.(php|inc|phtml)$/';
}
if (!isset($this->dataSourceId)) {
$this->dataSourceId = $provider['in'];
}
$finder = new Finder();
$finder->files();
$constraints = array(
'in', // Location
'exclude', // Exclude directories
'name', 'notName', // File name constraints
'path', 'notPath', // Path constraints
'size', // File size constraints
'date', // File date constraints
'depth', // Directory depth constraints
'contains', 'notContains', // File contents constraints
);
foreach ($constraints as $constraint) {
if (isset($provider[$constraint])) {
if (is_array($provider[$constraint])) {
$args = $provider[$constraint];
} else {
$args = array($provider[$constraint]);
}
foreach ($args as $arg) {
$finder->{$constraint}($arg);
}
}
}
$this->provider = $provider;
return $finder;
} | php | protected function findProvider($source, $alias)
{
if (!$alias) {
$src = realpath($source);
if (PATH_SEPARATOR == ';') {
// on windows platform, remove the drive identifier
$src = substr($src, 2);
}
if (is_dir($src)) {
$provider = array('in' => $src);
} elseif (is_file($src)) {
$ext = pathinfo($src, PATHINFO_EXTENSION);
if (in_array($ext, array('phar', 'zip', 'gz', 'tar', 'tgz', 'rar'))) {
// archive file
$provider = array('in' => 'phar://' . $src);
} else {
$provider = array('in' => dirname($src), 'name' => basename($src));
$this->dataSourceId = $src;
}
}
}
if (!isset($provider)) {
// when $source identify an entry of a json config file
$filename = Environment::getJsonConfigFilename();
if ($filename === false) {
return false;
}
// try to validate syntax and content of this json config file
$config = new Config();
$var = $config->validate($filename);
foreach ($var['source-providers'] as $provider) {
$in = trim($provider['in']);
if (empty($in)) {
// this source provider is incomplete: empty "in" key
return false;
}
$src = explode(' as ', $in);
$src = array_map('trim', $src);
if (!empty($alias) && count($src) < 2) {
// searching on alias, which is not provided
continue;
}
$i = empty($alias) ? 0 : 1;
// search on data source path ($i = 0) or alias ($i = 1)
if ($src[$i] == $source) {
$provider['in'] = $src[0];
break;
}
unset($provider);
}
if (!isset($provider)) {
// data source not found
return false;
}
}
if (substr($provider['in'], 0, 1) == '.') {
// relative local file
$provider['in'] = realpath($provider['in']);
}
if (PATH_SEPARATOR == ';') {
// normalizes path to unix format
$provider['in'] = str_replace(DIRECTORY_SEPARATOR, '/', $provider['in']);
}
if (!isset($provider['name'])) {
// default file extensions to scan
$provider['name'] = '/\\.(php|inc|phtml)$/';
}
if (!isset($this->dataSourceId)) {
$this->dataSourceId = $provider['in'];
}
$finder = new Finder();
$finder->files();
$constraints = array(
'in', // Location
'exclude', // Exclude directories
'name', 'notName', // File name constraints
'path', 'notPath', // Path constraints
'size', // File size constraints
'date', // File date constraints
'depth', // Directory depth constraints
'contains', 'notContains', // File contents constraints
);
foreach ($constraints as $constraint) {
if (isset($provider[$constraint])) {
if (is_array($provider[$constraint])) {
$args = $provider[$constraint];
} else {
$args = array($provider[$constraint]);
}
foreach ($args as $arg) {
$finder->{$constraint}($arg);
}
}
}
$this->provider = $provider;
return $finder;
} | [
"protected",
"function",
"findProvider",
"(",
"$",
"source",
",",
"$",
"alias",
")",
"{",
"if",
"(",
"!",
"$",
"alias",
")",
"{",
"$",
"src",
"=",
"realpath",
"(",
"$",
"source",
")",
";",
"if",
"(",
"PATH_SEPARATOR",
"==",
"';'",
")",
"{",
"// on ... | Global identification of the data source
@param string $source Path to the data source (dir, file, archive)
@param string $alias Shortcut that referenced the data source
@return Finder|boolean | [
"Global",
"identification",
"of",
"the",
"data",
"source"
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Api/V3/Common.php#L74-L181 |
llaville/php-reflect | src/Bartlett/Reflect/Api/V3/Common.php | Common.transformToComposer | protected function transformToComposer($response)
{
$analyserId = 'Bartlett\CompatInfo\Analyser\CompatibilityAnalyser';
if (!isset($response[$analyserId])) {
throw new \RuntimeException('Could not render result to Composer format');
}
$compatinfo = $response[$analyserId];
// include PHP version
$composer = array(
'php' => '>= ' . $compatinfo['versions']['php.min']
);
// include extensions
foreach ($compatinfo['extensions'] as $key => $val) {
if (in_array($key, array('standard', 'Core'))) {
continue;
}
$composer['ext-' . $key] = '*';
}
// final result
$composer = array('require' => $composer);
return $this->transformToJson($composer);
} | php | protected function transformToComposer($response)
{
$analyserId = 'Bartlett\CompatInfo\Analyser\CompatibilityAnalyser';
if (!isset($response[$analyserId])) {
throw new \RuntimeException('Could not render result to Composer format');
}
$compatinfo = $response[$analyserId];
// include PHP version
$composer = array(
'php' => '>= ' . $compatinfo['versions']['php.min']
);
// include extensions
foreach ($compatinfo['extensions'] as $key => $val) {
if (in_array($key, array('standard', 'Core'))) {
continue;
}
$composer['ext-' . $key] = '*';
}
// final result
$composer = array('require' => $composer);
return $this->transformToJson($composer);
} | [
"protected",
"function",
"transformToComposer",
"(",
"$",
"response",
")",
"{",
"$",
"analyserId",
"=",
"'Bartlett\\CompatInfo\\Analyser\\CompatibilityAnalyser'",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"response",
"[",
"$",
"analyserId",
"]",
")",
")",
"{",
"th... | Transforms compatibility analyser results to Composer json format.
@param mixed $response Compatibility Analyser metrics
@return string JSON formatted
@throws \RuntimeException | [
"Transforms",
"compatibility",
"analyser",
"results",
"to",
"Composer",
"json",
"format",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Api/V3/Common.php#L203-L228 |
llaville/php-reflect | src/Bartlett/Reflect/Api/V3/Config.php | Config.getJsonConfigFile | protected function getJsonConfigFile($file)
{
$json = $this->validateSyntax($file);
$schemaFile = dirname(dirname(dirname(dirname(dirname(__DIR__))))) . '/bin/'
. basename($file) . '-schema';
if (file_exists($schemaFile)) {
// validate against schema only if available
$this->validateSchema($json, $schemaFile, $file);
}
$var = json_decode($json, true);
if (!is_array($var['source-providers'])) {
$var['source-providers'] = array($var['source-providers']);
}
if (!is_array($var['analysers'])) {
$var['analysers'] = array($var['analysers']);
}
if (!is_array($var['plugins'])) {
$var['plugins'] = array($var['plugins']);
}
return $var;
} | php | protected function getJsonConfigFile($file)
{
$json = $this->validateSyntax($file);
$schemaFile = dirname(dirname(dirname(dirname(dirname(__DIR__))))) . '/bin/'
. basename($file) . '-schema';
if (file_exists($schemaFile)) {
// validate against schema only if available
$this->validateSchema($json, $schemaFile, $file);
}
$var = json_decode($json, true);
if (!is_array($var['source-providers'])) {
$var['source-providers'] = array($var['source-providers']);
}
if (!is_array($var['analysers'])) {
$var['analysers'] = array($var['analysers']);
}
if (!is_array($var['plugins'])) {
$var['plugins'] = array($var['plugins']);
}
return $var;
} | [
"protected",
"function",
"getJsonConfigFile",
"(",
"$",
"file",
")",
"{",
"$",
"json",
"=",
"$",
"this",
"->",
"validateSyntax",
"(",
"$",
"file",
")",
";",
"$",
"schemaFile",
"=",
"dirname",
"(",
"dirname",
"(",
"dirname",
"(",
"dirname",
"(",
"dirname"... | Gets the contents of a JSON configuration file.
@param string $file (optional) Path to a JSON file
@return array
@throws \RuntimeException if configuration file
does not exists or not readable
@throws ParsingException if configuration file is invalid format | [
"Gets",
"the",
"contents",
"of",
"a",
"JSON",
"configuration",
"file",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Api/V3/Config.php#L58-L82 |
llaville/php-reflect | src/Bartlett/Reflect/Api/V3/Config.php | Config.validateSyntax | protected function validateSyntax($file)
{
/**
* This is a currently known PHP bug, but has not yet been fixed
* @link http://bugs.php.net/bug.php?id=52769
*/
$fname = realpath($file);
if ($fname === false) {
$fname = $file;
}
if (!file_exists($fname)) {
throw new \RuntimeException('File "' . $file . '" not found.');
}
if (!is_readable($fname)) {
throw new \RuntimeException('File "' . $file . '" is not readable.');
}
$json = file_get_contents($fname);
$parser = new JsonParser();
$result = $parser->lint($json);
if (null === $result) {
if (defined('JSON_ERROR_UTF8')
&& JSON_ERROR_UTF8 === json_last_error()
) {
throw new ParsingException(
'"' . $file . '" is not UTF-8, could not parse as JSON'
);
}
return $json;
}
throw $result;
} | php | protected function validateSyntax($file)
{
/**
* This is a currently known PHP bug, but has not yet been fixed
* @link http://bugs.php.net/bug.php?id=52769
*/
$fname = realpath($file);
if ($fname === false) {
$fname = $file;
}
if (!file_exists($fname)) {
throw new \RuntimeException('File "' . $file . '" not found.');
}
if (!is_readable($fname)) {
throw new \RuntimeException('File "' . $file . '" is not readable.');
}
$json = file_get_contents($fname);
$parser = new JsonParser();
$result = $parser->lint($json);
if (null === $result) {
if (defined('JSON_ERROR_UTF8')
&& JSON_ERROR_UTF8 === json_last_error()
) {
throw new ParsingException(
'"' . $file . '" is not UTF-8, could not parse as JSON'
);
}
return $json;
}
throw $result;
} | [
"protected",
"function",
"validateSyntax",
"(",
"$",
"file",
")",
"{",
"/**\n * This is a currently known PHP bug, but has not yet been fixed\n * @link http://bugs.php.net/bug.php?id=52769\n */",
"$",
"fname",
"=",
"realpath",
"(",
"$",
"file",
")",
";",
"... | Validates the syntax of a JSON file
@param string $file The JSON file to check
@return string JSON string if no error found
@throws ParsingException containing all details of JSON error syntax
@throws \RuntimeException if file not found or not readable | [
"Validates",
"the",
"syntax",
"of",
"a",
"JSON",
"file"
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Api/V3/Config.php#L94-L127 |
llaville/php-reflect | src/Bartlett/Reflect/Api/V3/Config.php | Config.validateSchema | protected function validateSchema($data, $schemaFile, $configFile)
{
$schemaData = $this->validateSyntax($schemaFile);
$validator = new Validator();
$validator->check(json_decode($data), json_decode($schemaData));
if (!$validator->isValid()) {
$errors = '"' . $configFile . '" is invalid, '
. 'the following errors were found :' . "\n";
foreach ($validator->getErrors() as $error) {
$errors .= sprintf("- [%s] %s\n", $error['property'], $error['message']);
}
throw new ParsingException($errors);
}
} | php | protected function validateSchema($data, $schemaFile, $configFile)
{
$schemaData = $this->validateSyntax($schemaFile);
$validator = new Validator();
$validator->check(json_decode($data), json_decode($schemaData));
if (!$validator->isValid()) {
$errors = '"' . $configFile . '" is invalid, '
. 'the following errors were found :' . "\n";
foreach ($validator->getErrors() as $error) {
$errors .= sprintf("- [%s] %s\n", $error['property'], $error['message']);
}
throw new ParsingException($errors);
}
} | [
"protected",
"function",
"validateSchema",
"(",
"$",
"data",
",",
"$",
"schemaFile",
",",
"$",
"configFile",
")",
"{",
"$",
"schemaData",
"=",
"$",
"this",
"->",
"validateSyntax",
"(",
"$",
"schemaFile",
")",
";",
"$",
"validator",
"=",
"new",
"Validator",... | Validates the schema of a JSON data structure according to
static::JSON_SCHEMA file rules
@param string $data The JSON data
@param string $schemaFile The JSON schema file
@param string $configFile The JSON config file
@return void
@throws ParsingException containing all errors that does not match json schema | [
"Validates",
"the",
"schema",
"of",
"a",
"JSON",
"data",
"structure",
"according",
"to",
"static",
"::",
"JSON_SCHEMA",
"file",
"rules"
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Api/V3/Config.php#L141-L156 |
llaville/php-reflect | src/Bartlett/Reflect/Util/Timer.php | Timer.toTimeString | public static function toTimeString($time)
{
$times = array(
'hour' => 3600000,
'minute' => 60000,
'second' => 1000
);
$ms = $time;
foreach ($times as $unit => $value) {
if ($ms >= $value) {
$time = floor($ms / $value * 100.0) / 100.0;
return $time . ' ' . ($time == 1 ? $unit : $unit . 's');
}
}
return $ms . ' ms';
} | php | public static function toTimeString($time)
{
$times = array(
'hour' => 3600000,
'minute' => 60000,
'second' => 1000
);
$ms = $time;
foreach ($times as $unit => $value) {
if ($ms >= $value) {
$time = floor($ms / $value * 100.0) / 100.0;
return $time . ' ' . ($time == 1 ? $unit : $unit . 's');
}
}
return $ms . ' ms';
} | [
"public",
"static",
"function",
"toTimeString",
"(",
"$",
"time",
")",
"{",
"$",
"times",
"=",
"array",
"(",
"'hour'",
"=>",
"3600000",
",",
"'minute'",
"=>",
"60000",
",",
"'second'",
"=>",
"1000",
")",
";",
"$",
"ms",
"=",
"$",
"time",
";",
"foreac... | Formats the elapsed time as a string.
This code has been copied and adapted from phpunit/php-timer
@param int $time The period duration (in milliseconds)
@return string | [
"Formats",
"the",
"elapsed",
"time",
"as",
"a",
"string",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Util/Timer.php#L37-L54 |
llaville/php-reflect | src/Bartlett/Reflect/Output/Analyser.php | Analyser.dir | public function dir(OutputInterface $output, $response)
{
if (empty($response)) {
$output->writeln('<error>No analysers detected.</error>');
} else {
$headers = array('Analyser Name', 'Analyser Class');
$rows = array();
foreach ($response as $name => $class) {
$rows[] = array($name, $class);
}
$this->tableHelper($output, $headers, $rows);
}
} | php | public function dir(OutputInterface $output, $response)
{
if (empty($response)) {
$output->writeln('<error>No analysers detected.</error>');
} else {
$headers = array('Analyser Name', 'Analyser Class');
$rows = array();
foreach ($response as $name => $class) {
$rows[] = array($name, $class);
}
$this->tableHelper($output, $headers, $rows);
}
} | [
"public",
"function",
"dir",
"(",
"OutputInterface",
"$",
"output",
",",
"$",
"response",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"response",
")",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"'<error>No analysers detected.</error>'",
")",
";",
"}",
"els... | Results of analysers available
@param OutputInterface $output Console Output concrete instance
@param array $response Analysers list | [
"Results",
"of",
"analysers",
"available"
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Output/Analyser.php#L36-L50 |
llaville/php-reflect | src/Bartlett/Reflect/Output/Analyser.php | Analyser.run | public function run(OutputInterface $output, $response)
{
if (empty($response)) {
// No reports printed if there are no metrics.
$output->writeln('<info>No metrics.</info>');
return;
}
$output->writeln('<info>Data Source Analysed</info>');
$directories = array();
foreach ($response['files'] as $file) {
$directories[] = dirname($file);
}
$directories = array_unique($directories);
// print Data Source summaries
if (count($response['files']) > 0) {
$text = sprintf(
"%s" .
"Directories %10d%s" .
"Files %10d%s" .
"Errors %10d%s",
PHP_EOL,
count($directories),
PHP_EOL,
count($response['files']),
PHP_EOL,
count($response['errors']),
PHP_EOL
);
$output->writeln($text);
}
if (count($response['errors'])) {
$output->writeln('<info>Errors found</info>');
foreach ($response['errors'] as $file => $msg) {
$text = sprintf(
'%s <info>></info> %s in file %s',
PHP_EOL,
$msg,
$file
);
$output->writeln($text);
}
}
// print each analyser results
foreach ($response as $analyserName => $analyserResults) {
if (substr($analyserName, -8) !== 'Analyser') {
continue;
}
$baseNamespace = str_replace(
'Analyser\\' . basename(str_replace('\\', '/', $analyserName)),
'',
$analyserName
);
$outputFormatter = $baseNamespace . 'Console\Formatter\\' .
substr(basename(str_replace('\\', '/', $analyserName)), 0, -8) . 'OutputFormatter';
if (class_exists($outputFormatter)) {
$obj = new $outputFormatter();
$obj($output, $analyserResults);
}
}
if (isset($response['extra']['cache'])) {
$stats = $response['extra']['cache'];
$output->writeln(
sprintf(
'%s<info>Cache: %d hits, %d misses</info>',
PHP_EOL,
$stats['hits'],
$stats['misses']
)
);
}
} | php | public function run(OutputInterface $output, $response)
{
if (empty($response)) {
// No reports printed if there are no metrics.
$output->writeln('<info>No metrics.</info>');
return;
}
$output->writeln('<info>Data Source Analysed</info>');
$directories = array();
foreach ($response['files'] as $file) {
$directories[] = dirname($file);
}
$directories = array_unique($directories);
// print Data Source summaries
if (count($response['files']) > 0) {
$text = sprintf(
"%s" .
"Directories %10d%s" .
"Files %10d%s" .
"Errors %10d%s",
PHP_EOL,
count($directories),
PHP_EOL,
count($response['files']),
PHP_EOL,
count($response['errors']),
PHP_EOL
);
$output->writeln($text);
}
if (count($response['errors'])) {
$output->writeln('<info>Errors found</info>');
foreach ($response['errors'] as $file => $msg) {
$text = sprintf(
'%s <info>></info> %s in file %s',
PHP_EOL,
$msg,
$file
);
$output->writeln($text);
}
}
// print each analyser results
foreach ($response as $analyserName => $analyserResults) {
if (substr($analyserName, -8) !== 'Analyser') {
continue;
}
$baseNamespace = str_replace(
'Analyser\\' . basename(str_replace('\\', '/', $analyserName)),
'',
$analyserName
);
$outputFormatter = $baseNamespace . 'Console\Formatter\\' .
substr(basename(str_replace('\\', '/', $analyserName)), 0, -8) . 'OutputFormatter';
if (class_exists($outputFormatter)) {
$obj = new $outputFormatter();
$obj($output, $analyserResults);
}
}
if (isset($response['extra']['cache'])) {
$stats = $response['extra']['cache'];
$output->writeln(
sprintf(
'%s<info>Cache: %d hits, %d misses</info>',
PHP_EOL,
$stats['hits'],
$stats['misses']
)
);
}
} | [
"public",
"function",
"run",
"(",
"OutputInterface",
"$",
"output",
",",
"$",
"response",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"response",
")",
")",
"{",
"// No reports printed if there are no metrics.",
"$",
"output",
"->",
"writeln",
"(",
"'<info>No metrics... | Results of analysers metrics
@param OutputInterface $output Console Output concrete instance
@param array $response Analyser metrics | [
"Results",
"of",
"analysers",
"metrics"
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Output/Analyser.php#L58-L137 |
llaville/php-reflect | src/Bartlett/Reflect/Event/CacheAwareEventDispatcher.php | CacheAwareEventDispatcher.doDispatch | protected function doDispatch($listeners, $eventName, Event $event)
{
foreach ($listeners as $listener) {
$evt = $this->preNotify($listener, $eventName, clone($event));
call_user_func($listener, $evt, $eventName, $this);
if ($evt->isPropagationStopped()) {
break;
}
}
} | php | protected function doDispatch($listeners, $eventName, Event $event)
{
foreach ($listeners as $listener) {
$evt = $this->preNotify($listener, $eventName, clone($event));
call_user_func($listener, $evt, $eventName, $this);
if ($evt->isPropagationStopped()) {
break;
}
}
} | [
"protected",
"function",
"doDispatch",
"(",
"$",
"listeners",
",",
"$",
"eventName",
",",
"Event",
"$",
"event",
")",
"{",
"foreach",
"(",
"$",
"listeners",
"as",
"$",
"listener",
")",
"{",
"$",
"evt",
"=",
"$",
"this",
"->",
"preNotify",
"(",
"$",
"... | {@inheritdoc} | [
"{"
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Event/CacheAwareEventDispatcher.php#L37-L46 |
llaville/php-reflect | src/Bartlett/Reflect/Event/CacheAwareEventDispatcher.php | CacheAwareEventDispatcher.preNotify | protected function preNotify($listener, $eventName, Event $event)
{
if (Events::SUCCESS == $eventName
&& $event instanceof GenericEvent
) {
/*
* 'ast' argument of 'reflect.success' event is used only by the cache plugin.
* Remove it improve performance.
*/
if (is_array($listener)
&& !$listener[0] instanceof \Bartlett\Reflect\Plugin\CachePlugin
) {
unset($event['ast']);
}
}
return $event;
} | php | protected function preNotify($listener, $eventName, Event $event)
{
if (Events::SUCCESS == $eventName
&& $event instanceof GenericEvent
) {
/*
* 'ast' argument of 'reflect.success' event is used only by the cache plugin.
* Remove it improve performance.
*/
if (is_array($listener)
&& !$listener[0] instanceof \Bartlett\Reflect\Plugin\CachePlugin
) {
unset($event['ast']);
}
}
return $event;
} | [
"protected",
"function",
"preNotify",
"(",
"$",
"listener",
",",
"$",
"eventName",
",",
"Event",
"$",
"event",
")",
"{",
"if",
"(",
"Events",
"::",
"SUCCESS",
"==",
"$",
"eventName",
"&&",
"$",
"event",
"instanceof",
"GenericEvent",
")",
"{",
"/*\n ... | Called before notify a listener about the event.
@param mixed $listener The listener to notify with that $event
@param string $eventName The event name
@param Event $event The event
@return Event | [
"Called",
"before",
"notify",
"a",
"listener",
"about",
"the",
"event",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Event/CacheAwareEventDispatcher.php#L57-L73 |
llaville/php-reflect | src/Bartlett/Reflect/Sniffer/SniffAbstract.php | SniffAbstract.setUpBeforeSniff | public function setUpBeforeSniff()
{
$this->visitor->getSubject()->dispatch(
Reflect\Events::SNIFF,
array(
'method' => get_class($this) . '::' . __FUNCTION__,
'node' => null,
'sniff' => get_class($this),
)
);
} | php | public function setUpBeforeSniff()
{
$this->visitor->getSubject()->dispatch(
Reflect\Events::SNIFF,
array(
'method' => get_class($this) . '::' . __FUNCTION__,
'node' => null,
'sniff' => get_class($this),
)
);
} | [
"public",
"function",
"setUpBeforeSniff",
"(",
")",
"{",
"$",
"this",
"->",
"visitor",
"->",
"getSubject",
"(",
")",
"->",
"dispatch",
"(",
"Reflect",
"\\",
"Events",
"::",
"SNIFF",
",",
"array",
"(",
"'method'",
"=>",
"get_class",
"(",
"$",
"this",
")",... | SniffInterface implements | [
"SniffInterface",
"implements"
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Sniffer/SniffAbstract.php#L39-L49 |
llaville/php-reflect | src/Bartlett/Reflect/Model/AbstractFunctionModel.php | AbstractFunctionModel.getName | public function getName()
{
if ($this->isClosure()) {
return '{closure}';
}
if (isset($this->node->namespacedName)) {
return $this->node->namespacedName;
}
return $this->node->name;
} | php | public function getName()
{
if ($this->isClosure()) {
return '{closure}';
}
if (isset($this->node->namespacedName)) {
return $this->node->namespacedName;
}
return $this->node->name;
} | [
"public",
"function",
"getName",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isClosure",
"(",
")",
")",
"{",
"return",
"'{closure}'",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"node",
"->",
"namespacedName",
")",
")",
"{",
"return",
"... | Get the name of the function.
@return string | [
"Get",
"the",
"name",
"of",
"the",
"function",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Model/AbstractFunctionModel.php#L53-L62 |
llaville/php-reflect | src/Bartlett/Reflect/Model/AbstractFunctionModel.php | AbstractFunctionModel.getNumberOfRequiredParameters | public function getNumberOfRequiredParameters()
{
$parameters = $this->getParameters();
$required = 0;
foreach ($parameters as $param) {
if (!$param->isOptional()) {
$required++;
}
}
return $required;
} | php | public function getNumberOfRequiredParameters()
{
$parameters = $this->getParameters();
$required = 0;
foreach ($parameters as $param) {
if (!$param->isOptional()) {
$required++;
}
}
return $required;
} | [
"public",
"function",
"getNumberOfRequiredParameters",
"(",
")",
"{",
"$",
"parameters",
"=",
"$",
"this",
"->",
"getParameters",
"(",
")",
";",
"$",
"required",
"=",
"0",
";",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"param",
")",
"{",
"if",
"(",
... | Get the number of required parameters that a function defines.
@return int The number of required parameters | [
"Get",
"the",
"number",
"of",
"required",
"parameters",
"that",
"a",
"function",
"defines",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Model/AbstractFunctionModel.php#L103-L114 |
llaville/php-reflect | src/Bartlett/Reflect/Model/AbstractFunctionModel.php | AbstractFunctionModel.getParameters | public function getParameters()
{
if ($this->parameters === null) {
// lazy load function parameters list
$this->parameters = array();
foreach ($this->node->params as $pos => $param) {
if ($param instanceof Node\Param) {
$this->parameters[] = new ParameterModel($param, $pos);
}
}
}
return $this->parameters;
} | php | public function getParameters()
{
if ($this->parameters === null) {
// lazy load function parameters list
$this->parameters = array();
foreach ($this->node->params as $pos => $param) {
if ($param instanceof Node\Param) {
$this->parameters[] = new ParameterModel($param, $pos);
}
}
}
return $this->parameters;
} | [
"public",
"function",
"getParameters",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"parameters",
"===",
"null",
")",
"{",
"// lazy load function parameters list",
"$",
"this",
"->",
"parameters",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"... | Get the parameters.
@return array of ParameterModel | [
"Get",
"the",
"parameters",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Model/AbstractFunctionModel.php#L121-L133 |
llaville/php-reflect | src/Bartlett/Reflect/Client.php | Client.api | public function api($name)
{
$classes = array(
'Bartlett\Reflect\Api\\' => array(
'Analyser',
'Cache',
'Config',
'Diagnose',
'Diagram',
'Plugin',
'Reflection',
),
'Bartlett\CompatInfo\Api\\' => array(
'Reference'
),
);
$class = false;
foreach ($classes as $ns => $basename) {
if (in_array(ucfirst($name), $basename)) {
$class = $ns . ucfirst($name);
break;
}
}
if (!$class || !class_exists($class)) {
throw new \InvalidArgumentException(
sprintf('Unknown Api "%s" requested', $name)
);
}
if ($this->client instanceof LocalClient) {
$this->client->setNamespace($ns . 'V3');
}
return new $class($this->client, $this->token);
} | php | public function api($name)
{
$classes = array(
'Bartlett\Reflect\Api\\' => array(
'Analyser',
'Cache',
'Config',
'Diagnose',
'Diagram',
'Plugin',
'Reflection',
),
'Bartlett\CompatInfo\Api\\' => array(
'Reference'
),
);
$class = false;
foreach ($classes as $ns => $basename) {
if (in_array(ucfirst($name), $basename)) {
$class = $ns . ucfirst($name);
break;
}
}
if (!$class || !class_exists($class)) {
throw new \InvalidArgumentException(
sprintf('Unknown Api "%s" requested', $name)
);
}
if ($this->client instanceof LocalClient) {
$this->client->setNamespace($ns . 'V3');
}
return new $class($this->client, $this->token);
} | [
"public",
"function",
"api",
"(",
"$",
"name",
")",
"{",
"$",
"classes",
"=",
"array",
"(",
"'Bartlett\\Reflect\\Api\\\\'",
"=>",
"array",
"(",
"'Analyser'",
",",
"'Cache'",
",",
"'Config'",
",",
"'Diagnose'",
",",
"'Diagram'",
",",
"'Plugin'",
",",
"'Reflec... | Returns an Api
@param string $name Api method to perform
@return Api
@throws \InvalidArgumentException | [
"Returns",
"an",
"Api"
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Client.php#L56-L91 |
llaville/php-reflect | src/Bartlett/Reflect/Client.php | Client.initializeClient | private function initializeClient($url, ClientInterface $client = null)
{
if ($client) {
$this->client = $client;
} else {
$this->client = new LocalClient($url);
}
} | php | private function initializeClient($url, ClientInterface $client = null)
{
if ($client) {
$this->client = $client;
} else {
$this->client = new LocalClient($url);
}
} | [
"private",
"function",
"initializeClient",
"(",
"$",
"url",
",",
"ClientInterface",
"$",
"client",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"client",
")",
"{",
"$",
"this",
"->",
"client",
"=",
"$",
"client",
";",
"}",
"else",
"{",
"$",
"this",
"->",
... | Initializes a http or local client
@param string $url Base URL of endpoints
@param ClientInterface $client (optional) client to use
@return void | [
"Initializes",
"a",
"http",
"or",
"local",
"client"
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Client.php#L111-L118 |
llaville/php-reflect | src/Bartlett/Reflect/Api/V3/Diagnose.php | Diagnose.run | public function run()
{
$response = array();
if (version_compare(PHP_VERSION, self::PHP_MIN, '<')) {
$response['php_version'] = false;
} else {
$response['php_version'] = PHP_VERSION;
}
$response['php_ini'] = php_ini_loaded_file();
$extensions = array(
'date',
'json',
'pcre',
'phar',
'reflection',
'spl',
'tokenizer',
);
foreach ($extensions as $extension) {
$response[$extension . '_loaded'] = extension_loaded($extension);
}
if (extension_loaded('xdebug')) {
$response['xdebug_loaded'] = true;
$response['xdebug_profiler_enable'] = ini_get('xdebug.profiler_enable');
}
return $response;
} | php | public function run()
{
$response = array();
if (version_compare(PHP_VERSION, self::PHP_MIN, '<')) {
$response['php_version'] = false;
} else {
$response['php_version'] = PHP_VERSION;
}
$response['php_ini'] = php_ini_loaded_file();
$extensions = array(
'date',
'json',
'pcre',
'phar',
'reflection',
'spl',
'tokenizer',
);
foreach ($extensions as $extension) {
$response[$extension . '_loaded'] = extension_loaded($extension);
}
if (extension_loaded('xdebug')) {
$response['xdebug_loaded'] = true;
$response['xdebug_profiler_enable'] = ini_get('xdebug.profiler_enable');
}
return $response;
} | [
"public",
"function",
"run",
"(",
")",
"{",
"$",
"response",
"=",
"array",
"(",
")",
";",
"if",
"(",
"version_compare",
"(",
"PHP_VERSION",
",",
"self",
"::",
"PHP_MIN",
",",
"'<'",
")",
")",
"{",
"$",
"response",
"[",
"'php_version'",
"]",
"=",
"fal... | Diagnoses the system to identify common errors.
@return array | [
"Diagnoses",
"the",
"system",
"to",
"identify",
"common",
"errors",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Api/V3/Diagnose.php#L36-L68 |
llaville/php-reflect | src/Bartlett/Reflect/Api/V3/Analyser.php | Analyser.run | public function run($source, array $analysers, $alias, $format, $filter)
{
$finder = $this->findProvider($source, $alias);
if ($finder === false) {
throw new \RuntimeException(
'None data source matching'
);
}
if ($filter === false) {
// filter feature is not possible on reflection:* commands
$filter = function ($data) {
return $data;
};
}
$reflect = new Reflect();
$reflect->setEventDispatcher($this->eventDispatcher);
$reflect->setDataSourceId($this->dataSourceId);
$am = $this->registerAnalysers();
$analysersAvailable = array();
foreach ($am->getAnalysers() as $analyser) {
$analysersAvailable[$analyser->getShortName()] = $analyser;
}
// attach valid analysers only
foreach ($analysers as $analyserName) {
if (!array_key_exists(strtolower($analyserName), $analysersAvailable)) {
throw new \InvalidArgumentException(
sprintf(
'"%s" Analyser is not installed.',
$analyserName
)
);
}
$reflect->addAnalyser($analysersAvailable[$analyserName]);
}
$pm = new PluginManager($this->eventDispatcher);
if ($this->registerPlugins) {
$pm->registerPlugins();
}
$response = $reflect->parse($finder);
$response = $filter($response);
if (!empty($format)) {
$transformMethod = sprintf('transformTo%s', ucfirst($format));
if (!method_exists($this, $transformMethod)) {
throw new \InvalidArgumentException(
'Could not render result in this format (not implemented).'
);
}
$response = $this->$transformMethod($response);
}
return $response;
} | php | public function run($source, array $analysers, $alias, $format, $filter)
{
$finder = $this->findProvider($source, $alias);
if ($finder === false) {
throw new \RuntimeException(
'None data source matching'
);
}
if ($filter === false) {
// filter feature is not possible on reflection:* commands
$filter = function ($data) {
return $data;
};
}
$reflect = new Reflect();
$reflect->setEventDispatcher($this->eventDispatcher);
$reflect->setDataSourceId($this->dataSourceId);
$am = $this->registerAnalysers();
$analysersAvailable = array();
foreach ($am->getAnalysers() as $analyser) {
$analysersAvailable[$analyser->getShortName()] = $analyser;
}
// attach valid analysers only
foreach ($analysers as $analyserName) {
if (!array_key_exists(strtolower($analyserName), $analysersAvailable)) {
throw new \InvalidArgumentException(
sprintf(
'"%s" Analyser is not installed.',
$analyserName
)
);
}
$reflect->addAnalyser($analysersAvailable[$analyserName]);
}
$pm = new PluginManager($this->eventDispatcher);
if ($this->registerPlugins) {
$pm->registerPlugins();
}
$response = $reflect->parse($finder);
$response = $filter($response);
if (!empty($format)) {
$transformMethod = sprintf('transformTo%s', ucfirst($format));
if (!method_exists($this, $transformMethod)) {
throw new \InvalidArgumentException(
'Could not render result in this format (not implemented).'
);
}
$response = $this->$transformMethod($response);
}
return $response;
} | [
"public",
"function",
"run",
"(",
"$",
"source",
",",
"array",
"$",
"analysers",
",",
"$",
"alias",
",",
"$",
"format",
",",
"$",
"filter",
")",
"{",
"$",
"finder",
"=",
"$",
"this",
"->",
"findProvider",
"(",
"$",
"source",
",",
"$",
"alias",
")",... | Analyse a data source and display results.
@param string $source Path to the data source or its alias
@param array $analysers One or more analyser to perform (case insensitive).
@param mixed $alias If set, the source refers to its alias
@param string $format If set, convert result to a specific format.
@param mixed $filter (optional) Function used to filter results
@return array metrics
@throws \InvalidArgumentException if an analyser required is not installed | [
"Analyse",
"a",
"data",
"source",
"and",
"display",
"results",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Api/V3/Analyser.php#L62-L123 |
llaville/php-reflect | src/Bartlett/Reflect/Api/V3/Analyser.php | Analyser.registerAnalysers | protected function registerAnalysers()
{
$file = 'Bartlett/CompatInfo/Analyser/CompatibilityAnalyser.php';
$reflectBaseDir = dirname(dirname(dirname(dirname(dirname(__DIR__)))));
$baseDir = dirname(dirname(dirname($reflectBaseDir)));
$vendorDir = $baseDir . '/vendor';
$baseAnalyser = $baseDir . '/src/Bartlett/CompatInfo/Analyser';
$vendorAnalyser = $vendorDir . '/bartlett/php-compatinfo/src/Bartlett/CompatInfo/Analyser';
$namespaces = array();
if (file_exists($vendorDir) && is_dir($vendorDir)
&& (file_exists($baseAnalyser) || file_exists($vendorAnalyser))
) {
// CompatInfo only
$namespaces['Bartlett\CompatInfo\Analyser']
= file_exists($baseAnalyser) ? $baseAnalyser : $vendorAnalyser
;
} elseif ($path = stream_resolve_include_path($file)) {
// CompatInfo only, without composer
$namespaces['Bartlett\CompatInfo\Analyser'] = dirname($path);
}
$am = new AnalyserManager($namespaces);
$am->registerAnalysers();
return $am;
} | php | protected function registerAnalysers()
{
$file = 'Bartlett/CompatInfo/Analyser/CompatibilityAnalyser.php';
$reflectBaseDir = dirname(dirname(dirname(dirname(dirname(__DIR__)))));
$baseDir = dirname(dirname(dirname($reflectBaseDir)));
$vendorDir = $baseDir . '/vendor';
$baseAnalyser = $baseDir . '/src/Bartlett/CompatInfo/Analyser';
$vendorAnalyser = $vendorDir . '/bartlett/php-compatinfo/src/Bartlett/CompatInfo/Analyser';
$namespaces = array();
if (file_exists($vendorDir) && is_dir($vendorDir)
&& (file_exists($baseAnalyser) || file_exists($vendorAnalyser))
) {
// CompatInfo only
$namespaces['Bartlett\CompatInfo\Analyser']
= file_exists($baseAnalyser) ? $baseAnalyser : $vendorAnalyser
;
} elseif ($path = stream_resolve_include_path($file)) {
// CompatInfo only, without composer
$namespaces['Bartlett\CompatInfo\Analyser'] = dirname($path);
}
$am = new AnalyserManager($namespaces);
$am->registerAnalysers();
return $am;
} | [
"protected",
"function",
"registerAnalysers",
"(",
")",
"{",
"$",
"file",
"=",
"'Bartlett/CompatInfo/Analyser/CompatibilityAnalyser.php'",
";",
"$",
"reflectBaseDir",
"=",
"dirname",
"(",
"dirname",
"(",
"dirname",
"(",
"dirname",
"(",
"dirname",
"(",
"__DIR__",
")"... | Registers all analysers
bundled with distribution and declared by user in the JSON config file.
@return AnalyserManager | [
"Registers",
"all",
"analysers",
"bundled",
"with",
"distribution",
"and",
"declared",
"by",
"user",
"in",
"the",
"JSON",
"config",
"file",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Api/V3/Analyser.php#L131-L160 |
llaville/php-reflect | src/Bartlett/Reflect/Api/Reflection.php | Reflection.class_ | public function class_($argument, $source, $alias = null, $format = 'txt')
{
return $this->request('reflection/class', 'POST', array($argument, $source, $alias, $format));
} | php | public function class_($argument, $source, $alias = null, $format = 'txt')
{
return $this->request('reflection/class', 'POST', array($argument, $source, $alias, $format));
} | [
"public",
"function",
"class_",
"(",
"$",
"argument",
",",
"$",
"source",
",",
"$",
"alias",
"=",
"null",
",",
"$",
"format",
"=",
"'txt'",
")",
"{",
"return",
"$",
"this",
"->",
"request",
"(",
"'reflection/class'",
",",
"'POST'",
",",
"array",
"(",
... | Reports information about a user class present in a data source.
@param string $argument Name of the class to reflect.
@param string $source Path to the data source or its alias.
@param mixed $alias If set, the source refers to its alias.
@param string $format To ouput results in other formats.
@return mixed
@alias class | [
"Reports",
"information",
"about",
"a",
"user",
"class",
"present",
"in",
"a",
"data",
"source",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Api/Reflection.php#L48-L51 |
llaville/php-reflect | src/Bartlett/Reflect/Api/Reflection.php | Reflection.function_ | public function function_($argument, $source, $alias = null, $format = 'txt')
{
return $this->request('reflection/function', 'POST', array($argument, $source, $alias, $format));
} | php | public function function_($argument, $source, $alias = null, $format = 'txt')
{
return $this->request('reflection/function', 'POST', array($argument, $source, $alias, $format));
} | [
"public",
"function",
"function_",
"(",
"$",
"argument",
",",
"$",
"source",
",",
"$",
"alias",
"=",
"null",
",",
"$",
"format",
"=",
"'txt'",
")",
"{",
"return",
"$",
"this",
"->",
"request",
"(",
"'reflection/function'",
",",
"'POST'",
",",
"array",
... | Reports information about a user function present in a data source.
@param string $argument Name of the function to reflect.
@param string $source Path to the data source or its alias.
@param mixed $alias If set, the source refers to its alias.
@param string $format To ouput results in other formats.
@return mixed
@alias function | [
"Reports",
"information",
"about",
"a",
"user",
"function",
"present",
"in",
"a",
"data",
"source",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Api/Reflection.php#L64-L67 |
llaville/php-reflect | src/Bartlett/Reflect/Plugin/NotifierPlugin.php | NotifierPlugin.onNotification | public function onNotification(GenericEvent $event, $eventName)
{
static $start = false;
switch ($eventName) {
case Events::PROGRESS:
if (!$start) {
$this->stopwatch->start($event['source']);
$start = true;
}
return;
case Events::ERROR:
$message = 'Parser has detected an error on file "%filename%". %error%';
break;
case Events::COMPLETE:
$message = "Parsing data source \"%source%\" completed.";
$appEvent = $this->stopwatch->stop($event['source']);
$time = $appEvent->getDuration();
$memory = $appEvent->getMemory();
$event['profile'] = sprintf(
'Time: %s, Memory: %4.2fMb',
Timer::toTimeString($time),
$memory / (1024 * 1024)
);
break;
}
$format = $this->notifier->getMessageFormat();
$event['eventname'] = $eventName;
$event['message'] = strtr($message, $this->getPlaceholders($event));
$event['formatted'] = strtr($format, $this->getPlaceholders($event));
$this->notifier->notify($event);
} | php | public function onNotification(GenericEvent $event, $eventName)
{
static $start = false;
switch ($eventName) {
case Events::PROGRESS:
if (!$start) {
$this->stopwatch->start($event['source']);
$start = true;
}
return;
case Events::ERROR:
$message = 'Parser has detected an error on file "%filename%". %error%';
break;
case Events::COMPLETE:
$message = "Parsing data source \"%source%\" completed.";
$appEvent = $this->stopwatch->stop($event['source']);
$time = $appEvent->getDuration();
$memory = $appEvent->getMemory();
$event['profile'] = sprintf(
'Time: %s, Memory: %4.2fMb',
Timer::toTimeString($time),
$memory / (1024 * 1024)
);
break;
}
$format = $this->notifier->getMessageFormat();
$event['eventname'] = $eventName;
$event['message'] = strtr($message, $this->getPlaceholders($event));
$event['formatted'] = strtr($format, $this->getPlaceholders($event));
$this->notifier->notify($event);
} | [
"public",
"function",
"onNotification",
"(",
"GenericEvent",
"$",
"event",
",",
"$",
"eventName",
")",
"{",
"static",
"$",
"start",
"=",
"false",
";",
"switch",
"(",
"$",
"eventName",
")",
"{",
"case",
"Events",
"::",
"PROGRESS",
":",
"if",
"(",
"!",
"... | Notifies all important application events
@param GenericEvent $event Any event
@param string $eventName Name of event dispatched
@return void | [
"Notifies",
"all",
"important",
"application",
"events"
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Plugin/NotifierPlugin.php#L80-L114 |
llaville/php-reflect | src/Bartlett/Reflect/Plugin/NotifierPlugin.php | NotifierPlugin.getPlaceholders | protected function getPlaceholders(GenericEvent $event)
{
return array(
'%eventname%' => $event['eventname'],
'%source%' => $event['source'],
'%filename%' => $event->hasArgument('file') ? $event['file'] : '',
'%error%' => $event->hasArgument('error') ? $event['error'] : '',
'%profile%' => $event->hasArgument('profile') ? $event['profile'] : '',
'%message%' => $event->hasArgument('message') ? $event['message'] : '',
);
} | php | protected function getPlaceholders(GenericEvent $event)
{
return array(
'%eventname%' => $event['eventname'],
'%source%' => $event['source'],
'%filename%' => $event->hasArgument('file') ? $event['file'] : '',
'%error%' => $event->hasArgument('error') ? $event['error'] : '',
'%profile%' => $event->hasArgument('profile') ? $event['profile'] : '',
'%message%' => $event->hasArgument('message') ? $event['message'] : '',
);
} | [
"protected",
"function",
"getPlaceholders",
"(",
"GenericEvent",
"$",
"event",
")",
"{",
"return",
"array",
"(",
"'%eventname%'",
"=>",
"$",
"event",
"[",
"'eventname'",
"]",
",",
"'%source%'",
"=>",
"$",
"event",
"[",
"'source'",
"]",
",",
"'%filename%'",
"... | Gets each place holders of event's arguments
@param GenericEvent $event Any event
@return array | [
"Gets",
"each",
"place",
"holders",
"of",
"event",
"s",
"arguments"
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Plugin/NotifierPlugin.php#L123-L133 |
llaville/php-reflect | src/Bartlett/Reflect/Plugin/ProfilerPlugin.php | ProfilerPlugin.getSubscribedEvents | public static function getSubscribedEvents()
{
$events = array(
Reflect\Events::PROGRESS => 'onReflectProgress',
Reflect\Events::SUCCESS => 'onReflectSuccess',
Reflect\Events::ERROR => 'onReflectError',
Reflect\Events::COMPLETE => 'onReflectComplete',
);
return $events;
} | php | public static function getSubscribedEvents()
{
$events = array(
Reflect\Events::PROGRESS => 'onReflectProgress',
Reflect\Events::SUCCESS => 'onReflectSuccess',
Reflect\Events::ERROR => 'onReflectError',
Reflect\Events::COMPLETE => 'onReflectComplete',
);
return $events;
} | [
"public",
"static",
"function",
"getSubscribedEvents",
"(",
")",
"{",
"$",
"events",
"=",
"array",
"(",
"Reflect",
"\\",
"Events",
"::",
"PROGRESS",
"=>",
"'onReflectProgress'",
",",
"Reflect",
"\\",
"Events",
"::",
"SUCCESS",
"=>",
"'onReflectSuccess'",
",",
... | {@inheritdoc} | [
"{"
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Plugin/ProfilerPlugin.php#L76-L85 |
llaville/php-reflect | src/Bartlett/Reflect/Plugin/ProfilerPlugin.php | ProfilerPlugin.onReflectProgress | public function onReflectProgress(GenericEvent $event)
{
static $start = false;
if (!$start) {
$this->stopwatch->start($event['source']);
$start = true;
}
$this->stopwatch->start($event['file']->getPathname());
} | php | public function onReflectProgress(GenericEvent $event)
{
static $start = false;
if (!$start) {
$this->stopwatch->start($event['source']);
$start = true;
}
$this->stopwatch->start($event['file']->getPathname());
} | [
"public",
"function",
"onReflectProgress",
"(",
"GenericEvent",
"$",
"event",
")",
"{",
"static",
"$",
"start",
"=",
"false",
";",
"if",
"(",
"!",
"$",
"start",
")",
"{",
"$",
"this",
"->",
"stopwatch",
"->",
"start",
"(",
"$",
"event",
"[",
"'source'"... | Just before parsing a new file of the data source.
@param GenericEvent $event A 'reflect.progress' event
@return void | [
"Just",
"before",
"parsing",
"a",
"new",
"file",
"of",
"the",
"data",
"source",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Plugin/ProfilerPlugin.php#L94-L103 |
llaville/php-reflect | src/Bartlett/Reflect/Plugin/ProfilerPlugin.php | ProfilerPlugin.onReflectSuccess | public function onReflectSuccess($event)
{
$filename = $event['file']->getPathname();
$appEvent = $this->stopwatch->stop($filename);
$time = $appEvent->getDuration();
self::$logger->info(
'AST built in {time} on file "{file}"',
array('time' => Timer::toTimeString($time), 'file' => $filename)
);
} | php | public function onReflectSuccess($event)
{
$filename = $event['file']->getPathname();
$appEvent = $this->stopwatch->stop($filename);
$time = $appEvent->getDuration();
self::$logger->info(
'AST built in {time} on file "{file}"',
array('time' => Timer::toTimeString($time), 'file' => $filename)
);
} | [
"public",
"function",
"onReflectSuccess",
"(",
"$",
"event",
")",
"{",
"$",
"filename",
"=",
"$",
"event",
"[",
"'file'",
"]",
"->",
"getPathname",
"(",
")",
";",
"$",
"appEvent",
"=",
"$",
"this",
"->",
"stopwatch",
"->",
"stop",
"(",
"$",
"filename",... | After parsing a file of the data source.
@param GenericEvent $event A 'reflect.success' event
@return void | [
"After",
"parsing",
"a",
"file",
"of",
"the",
"data",
"source",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Plugin/ProfilerPlugin.php#L112-L122 |
llaville/php-reflect | src/Bartlett/Reflect/Plugin/ProfilerPlugin.php | ProfilerPlugin.onReflectError | public function onReflectError($event)
{
$filename = $event['file']->getPathname();
$this->stopwatch->stop($filename);
self::$logger->error(
'Parse error in {time} on file "{file"}: {error}',
array(
'time' => Timer::toTimeString($time),
'file' => $filename,
'error' => $event['error']
)
);
} | php | public function onReflectError($event)
{
$filename = $event['file']->getPathname();
$this->stopwatch->stop($filename);
self::$logger->error(
'Parse error in {time} on file "{file"}: {error}',
array(
'time' => Timer::toTimeString($time),
'file' => $filename,
'error' => $event['error']
)
);
} | [
"public",
"function",
"onReflectError",
"(",
"$",
"event",
")",
"{",
"$",
"filename",
"=",
"$",
"event",
"[",
"'file'",
"]",
"->",
"getPathname",
"(",
")",
";",
"$",
"this",
"->",
"stopwatch",
"->",
"stop",
"(",
"$",
"filename",
")",
";",
"self",
"::... | PHP-Parser raised an error.
@param GenericEvent $event A 'reflect.error' event
@return void | [
"PHP",
"-",
"Parser",
"raised",
"an",
"error",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Plugin/ProfilerPlugin.php#L131-L144 |
llaville/php-reflect | src/Bartlett/Reflect/Plugin/ProfilerPlugin.php | ProfilerPlugin.onReflectComplete | public function onReflectComplete($event)
{
$appEvent = $this->stopwatch->stop($event['source']);
$time = $appEvent->getDuration();
self::$logger->notice(
'Parsing data source {source} completed in {time}',
array('time' => Timer::toTimeString($time), 'source' => $event['source'])
);
} | php | public function onReflectComplete($event)
{
$appEvent = $this->stopwatch->stop($event['source']);
$time = $appEvent->getDuration();
self::$logger->notice(
'Parsing data source {source} completed in {time}',
array('time' => Timer::toTimeString($time), 'source' => $event['source'])
);
} | [
"public",
"function",
"onReflectComplete",
"(",
"$",
"event",
")",
"{",
"$",
"appEvent",
"=",
"$",
"this",
"->",
"stopwatch",
"->",
"stop",
"(",
"$",
"event",
"[",
"'source'",
"]",
")",
";",
"$",
"time",
"=",
"$",
"appEvent",
"->",
"getDuration",
"(",
... | A parse request is over.
@param GenericEvent $event A 'reflect.complete' event
@return void | [
"A",
"parse",
"request",
"is",
"over",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Plugin/ProfilerPlugin.php#L153-L162 |
llaville/php-reflect | src/Bartlett/Reflect/Output/Plugin.php | Plugin.dir | public function dir(OutputInterface $output, $response)
{
if (empty($response)) {
$output->writeln('<info>No plugin installed</info>');
} else {
$headers = array('Plugin Class', 'Events Subscribed');
$rows = array();
foreach ($response as $pluginClass => $events) {
$first = true;
foreach ($events as $event) {
if (!$first) {
$rows[] = array('', $event);
} else {
$rows[] = array($pluginClass, $event);
$first = false;
}
}
}
$this->tableHelper($output, $headers, $rows);
}
} | php | public function dir(OutputInterface $output, $response)
{
if (empty($response)) {
$output->writeln('<info>No plugin installed</info>');
} else {
$headers = array('Plugin Class', 'Events Subscribed');
$rows = array();
foreach ($response as $pluginClass => $events) {
$first = true;
foreach ($events as $event) {
if (!$first) {
$rows[] = array('', $event);
} else {
$rows[] = array($pluginClass, $event);
$first = false;
}
}
}
$this->tableHelper($output, $headers, $rows);
}
} | [
"public",
"function",
"dir",
"(",
"OutputInterface",
"$",
"output",
",",
"$",
"response",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"response",
")",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"'<info>No plugin installed</info>'",
")",
";",
"}",
"else",
... | Plugin list results
@param OutputInterface $output Console Output concrete instance
@param array $response Available plugins list | [
"Plugin",
"list",
"results"
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Output/Plugin.php#L36-L57 |
llaville/php-reflect | src/Bartlett/Reflect/Environment.php | Environment.getJsonConfigFilename | public static function getJsonConfigFilename()
{
$scanDir = getenv('BARTLETT_SCAN_DIR');
if ($scanDir) {
$dirs = explode(PATH_SEPARATOR, $scanDir);
foreach ($dirs as $scanDir) {
$filename = $scanDir . DIRECTORY_SEPARATOR . getenv('BARTLETTRC');
if (file_exists($filename) && is_file($filename)) {
return realpath($filename);
}
}
}
return false;
} | php | public static function getJsonConfigFilename()
{
$scanDir = getenv('BARTLETT_SCAN_DIR');
if ($scanDir) {
$dirs = explode(PATH_SEPARATOR, $scanDir);
foreach ($dirs as $scanDir) {
$filename = $scanDir . DIRECTORY_SEPARATOR . getenv('BARTLETTRC');
if (file_exists($filename) && is_file($filename)) {
return realpath($filename);
}
}
}
return false;
} | [
"public",
"static",
"function",
"getJsonConfigFilename",
"(",
")",
"{",
"$",
"scanDir",
"=",
"getenv",
"(",
"'BARTLETT_SCAN_DIR'",
")",
";",
"if",
"(",
"$",
"scanDir",
")",
"{",
"$",
"dirs",
"=",
"explode",
"(",
"PATH_SEPARATOR",
",",
"$",
"scanDir",
")",
... | Search a json file on a list of scan directory pointed by
the BARTLETT_SCAN_DIR env var.
Config filename is identify by the BARTLETTRC env var.
@return string|boolean FALSE if not found, otherwise its location | [
"Search",
"a",
"json",
"file",
"on",
"a",
"list",
"of",
"scan",
"directory",
"pointed",
"by",
"the",
"BARTLETT_SCAN_DIR",
"env",
"var",
".",
"Config",
"filename",
"is",
"identify",
"by",
"the",
"BARTLETTRC",
"env",
"var",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Environment.php#L39-L53 |
llaville/php-reflect | src/Bartlett/Reflect/Environment.php | Environment.setScanDir | public static function setScanDir()
{
if (!getenv("BARTLETT_SCAN_DIR")) {
$home = defined('PHP_WINDOWS_VERSION_BUILD') ? 'USERPROFILE' : 'HOME';
$dirs = array(
realpath('.'),
getenv($home) . DIRECTORY_SEPARATOR . '.config',
DIRECTORY_SEPARATOR . 'etc',
);
putenv("BARTLETT_SCAN_DIR=" . implode(PATH_SEPARATOR, $dirs));
}
} | php | public static function setScanDir()
{
if (!getenv("BARTLETT_SCAN_DIR")) {
$home = defined('PHP_WINDOWS_VERSION_BUILD') ? 'USERPROFILE' : 'HOME';
$dirs = array(
realpath('.'),
getenv($home) . DIRECTORY_SEPARATOR . '.config',
DIRECTORY_SEPARATOR . 'etc',
);
putenv("BARTLETT_SCAN_DIR=" . implode(PATH_SEPARATOR, $dirs));
}
} | [
"public",
"static",
"function",
"setScanDir",
"(",
")",
"{",
"if",
"(",
"!",
"getenv",
"(",
"\"BARTLETT_SCAN_DIR\"",
")",
")",
"{",
"$",
"home",
"=",
"defined",
"(",
"'PHP_WINDOWS_VERSION_BUILD'",
")",
"?",
"'USERPROFILE'",
":",
"'HOME'",
";",
"$",
"dirs",
... | Defines the scan directories where to search for a json config file.
@return void
@see getJsonConfigFilename() | [
"Defines",
"the",
"scan",
"directories",
"where",
"to",
"search",
"for",
"a",
"json",
"config",
"file",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Environment.php#L61-L72 |
llaville/php-reflect | src/Bartlett/Reflect/Analyser/LocAnalyser.php | LocAnalyser.visitClass | protected function visitClass(Node\Stmt\Class_ $class)
{
$this->metrics['classes']++;
$this->metrics['llocClasses'] += $this->llocClasses;
} | php | protected function visitClass(Node\Stmt\Class_ $class)
{
$this->metrics['classes']++;
$this->metrics['llocClasses'] += $this->llocClasses;
} | [
"protected",
"function",
"visitClass",
"(",
"Node",
"\\",
"Stmt",
"\\",
"Class_",
"$",
"class",
")",
"{",
"$",
"this",
"->",
"metrics",
"[",
"'classes'",
"]",
"++",
";",
"$",
"this",
"->",
"metrics",
"[",
"'llocClasses'",
"]",
"+=",
"$",
"this",
"->",
... | Explore each user classes found in the current namespace.
@param Node\Stmt\Class_ $class The current user class explored
@return void | [
"Explore",
"each",
"user",
"classes",
"found",
"in",
"the",
"current",
"namespace",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Analyser/LocAnalyser.php#L121-L125 |
llaville/php-reflect | src/Bartlett/Reflect/Analyser/LocAnalyser.php | LocAnalyser.visitMethod | protected function visitMethod(Node\Stmt\ClassMethod $method)
{
$this->metrics['methods']++;
if (count($method->stmts) === 0) {
// abstract or interface methods (without implementation)
return;
}
$lines = $this->getLinesOfCode($method->stmts);
foreach ($lines as $key => $count) {
$this->metrics[$key] += $count;
}
$this->llocClasses += $lines['lloc'];
$this->metrics['ccnMethods'] += $lines['ccn'];
} | php | protected function visitMethod(Node\Stmt\ClassMethod $method)
{
$this->metrics['methods']++;
if (count($method->stmts) === 0) {
// abstract or interface methods (without implementation)
return;
}
$lines = $this->getLinesOfCode($method->stmts);
foreach ($lines as $key => $count) {
$this->metrics[$key] += $count;
}
$this->llocClasses += $lines['lloc'];
$this->metrics['ccnMethods'] += $lines['ccn'];
} | [
"protected",
"function",
"visitMethod",
"(",
"Node",
"\\",
"Stmt",
"\\",
"ClassMethod",
"$",
"method",
")",
"{",
"$",
"this",
"->",
"metrics",
"[",
"'methods'",
"]",
"++",
";",
"if",
"(",
"count",
"(",
"$",
"method",
"->",
"stmts",
")",
"===",
"0",
"... | Explore methods of each user classes
found in the current namespace.
@param Node\Stmt\ClassMethod $method The current method explored
@return void | [
"Explore",
"methods",
"of",
"each",
"user",
"classes",
"found",
"in",
"the",
"current",
"namespace",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Analyser/LocAnalyser.php#L135-L153 |
llaville/php-reflect | src/Bartlett/Reflect/Analyser/LocAnalyser.php | LocAnalyser.visitFunction | protected function visitFunction(Node $function)
{
$this->metrics['functions']++;
if (count($function->stmts) === 0) {
// without implementation
return;
}
$lines = $this->getLinesOfCode($function->stmts);
foreach ($lines as $key => $count) {
$this->metrics[$key] += $count;
}
$this->metrics['llocFunctions'] += $lines['lloc'];
} | php | protected function visitFunction(Node $function)
{
$this->metrics['functions']++;
if (count($function->stmts) === 0) {
// without implementation
return;
}
$lines = $this->getLinesOfCode($function->stmts);
foreach ($lines as $key => $count) {
$this->metrics[$key] += $count;
}
$this->metrics['llocFunctions'] += $lines['lloc'];
} | [
"protected",
"function",
"visitFunction",
"(",
"Node",
"$",
"function",
")",
"{",
"$",
"this",
"->",
"metrics",
"[",
"'functions'",
"]",
"++",
";",
"if",
"(",
"count",
"(",
"$",
"function",
"->",
"stmts",
")",
"===",
"0",
")",
"{",
"// without implementa... | Explore user functions found in the current namespace.
@param Node $function The current user function explored
@return void | [
"Explore",
"user",
"functions",
"found",
"in",
"the",
"current",
"namespace",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Analyser/LocAnalyser.php#L162-L178 |
llaville/php-reflect | src/Bartlett/Reflect/Analyser/LocAnalyser.php | LocAnalyser.getLinesOfCode | private function getLinesOfCode(array $nodes)
{
$length = $nodes[count($nodes)-1]->getAttribute('endTokenPos')
- $nodes[0]->getAttribute('startTokenPos')
+ 1
;
$tokens = array_slice(
$this->tokens,
$nodes[0]->getAttribute('startTokenPos'),
$length
);
$tokenizer = new DefaultTokenizer();
// normalize the raw token stream
$tokenizer->setTokens($tokens);
$tokens = $tokenizer->getTokens();
$loc = $nodes[count($nodes)-1]->getAttribute('endLine')
- $nodes[0]->getAttribute('startLine')
+ 1
;
$clines = 0;
$llines = 0;
$wlines = 0;
$ccn = 0;
for ($i = 0, $max = count($tokens); $i < $max; $i++) {
if ($tokens[$i][0] === 'T_COMMENT') {
++$clines;
} elseif ($tokens[$i][0] === 'T_DOC_COMMENT') {
$clines += substr_count($tokens[$i][1], "\n") + 1;
} elseif ($tokens[$i][0] == 'T_WHITESPACE') {
$lines = substr_count($tokens[$i][1], "\n");
if ($lines > 0) {
$wlines += --$lines;
}
}
switch ($tokens[$i][0]) {
case 'T_QUESTION_MARK':
case 'T_IF':
case 'T_ELSEIF':
case 'T_FOR':
case 'T_FOREACH':
case 'T_WHILE':
case 'T_SWITCH':
case 'T_CASE':
case 'T_DEFAULT':
case 'T_TRY':
case 'T_CATCH':
case 'T_BOOLEAN_AND':
case 'T_LOGICAL_AND':
case 'T_BOOLEAN_OR':
case 'T_LOGICAL_OR':
case 'T_GOTO':
case 'T_FUNCTION':
++$ccn;
break;
case 'T_SEMICOLON':
++$llines;
break;
}
}
$lines = array(
'cloc' => $clines,
'eloc' => $loc - $wlines - $clines,
'lloc' => $llines,
'wloc' => $wlines,
'loc' => $loc,
'ccn' => $ccn,
);
return $lines;
} | php | private function getLinesOfCode(array $nodes)
{
$length = $nodes[count($nodes)-1]->getAttribute('endTokenPos')
- $nodes[0]->getAttribute('startTokenPos')
+ 1
;
$tokens = array_slice(
$this->tokens,
$nodes[0]->getAttribute('startTokenPos'),
$length
);
$tokenizer = new DefaultTokenizer();
// normalize the raw token stream
$tokenizer->setTokens($tokens);
$tokens = $tokenizer->getTokens();
$loc = $nodes[count($nodes)-1]->getAttribute('endLine')
- $nodes[0]->getAttribute('startLine')
+ 1
;
$clines = 0;
$llines = 0;
$wlines = 0;
$ccn = 0;
for ($i = 0, $max = count($tokens); $i < $max; $i++) {
if ($tokens[$i][0] === 'T_COMMENT') {
++$clines;
} elseif ($tokens[$i][0] === 'T_DOC_COMMENT') {
$clines += substr_count($tokens[$i][1], "\n") + 1;
} elseif ($tokens[$i][0] == 'T_WHITESPACE') {
$lines = substr_count($tokens[$i][1], "\n");
if ($lines > 0) {
$wlines += --$lines;
}
}
switch ($tokens[$i][0]) {
case 'T_QUESTION_MARK':
case 'T_IF':
case 'T_ELSEIF':
case 'T_FOR':
case 'T_FOREACH':
case 'T_WHILE':
case 'T_SWITCH':
case 'T_CASE':
case 'T_DEFAULT':
case 'T_TRY':
case 'T_CATCH':
case 'T_BOOLEAN_AND':
case 'T_LOGICAL_AND':
case 'T_BOOLEAN_OR':
case 'T_LOGICAL_OR':
case 'T_GOTO':
case 'T_FUNCTION':
++$ccn;
break;
case 'T_SEMICOLON':
++$llines;
break;
}
}
$lines = array(
'cloc' => $clines,
'eloc' => $loc - $wlines - $clines,
'lloc' => $llines,
'wloc' => $wlines,
'loc' => $loc,
'ccn' => $ccn,
);
return $lines;
} | [
"private",
"function",
"getLinesOfCode",
"(",
"array",
"$",
"nodes",
")",
"{",
"$",
"length",
"=",
"$",
"nodes",
"[",
"count",
"(",
"$",
"nodes",
")",
"-",
"1",
"]",
"->",
"getAttribute",
"(",
"'endTokenPos'",
")",
"-",
"$",
"nodes",
"[",
"0",
"]",
... | Counts the Comment Lines Of Code (CLOC) and a pseudo Executable Lines Of
Code (ELOC) values.
ELOC = Non Whitespace Lines + Non Comment Lines
<code>
array(
cloc => 23, // Comment Lines Of Code
eloc => 42 // Executable Lines Of Code
lloc => 57 // Logical Lines Of Code
)
</code>
This code has been copied and adapted from pdepende/pdepend
@param array $nodes AST of the current chunk of code
@return array | [
"Counts",
"the",
"Comment",
"Lines",
"Of",
"Code",
"(",
"CLOC",
")",
"and",
"a",
"pseudo",
"Executable",
"Lines",
"Of",
"Code",
"(",
"ELOC",
")",
"values",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Analyser/LocAnalyser.php#L200-L276 |
llaville/php-reflect | src/Bartlett/Reflect/Output/Diagnose.php | Diagnose.run | public function run(OutputInterface $output, $response)
{
$output->writeln('<comment>Diagnostics:</comment>');
foreach ($response as $key => $value) {
if (strcasecmp('php_version', $key) == 0) {
$output->writeln('Checking php settings:');
$output->writeln(
sprintf(
'- Requires PHP ' . ApiDiagnose::PHP_MIN . ' or better %s',
is_bool($value) ? '<error>FAIL</error>' : '<info>OK</info>'
)
);
if ($output->isVeryVerbose() && is_bool($value)) {
$this->writeComment(
$output,
'Upgrading to PHP ' .
ApiDiagnose::PHP_RECOMMANDED . ' or higher is recommended.'
);
}
}
if (strcasecmp('php_ini', $key) == 0) {
$output->writeln(
sprintf(
'- php.ini file loaded <info>%s</info>',
is_bool($value) ? 'NONE' : $value
)
);
}
if (preg_match('/^(.*)_loaded$/', $key, $matches)) {
// checks extensions loaded
if (strcasecmp('xdebug', $matches[1]) == 0) {
// Xdebug is special case (performance issue)
$output->writeln(
sprintf(
'- Xdebug extension loaded %s',
$value ? '<warning>YES</warning>' : '<info>NO</info>'
)
);
if ($output->isVeryVerbose()) {
$this->writeComment(
$output,
'You are encouraged to unload xdebug extension' .
' to speed up execution.'
);
}
if ($output->isVeryVerbose() && $response['xdebug_profiler_enable']) {
$this->writeComment(
$output,
'The xdebug.profiler_enable setting is enabled,' .
' this can slow down execution a lot.'
);
}
} else {
$output->writeln(
sprintf(
'- %s extension loaded %s',
$matches[1],
$value ? '<info>YES</info>' : '<error>FAIL</error>'
)
);
}
}
}
} | php | public function run(OutputInterface $output, $response)
{
$output->writeln('<comment>Diagnostics:</comment>');
foreach ($response as $key => $value) {
if (strcasecmp('php_version', $key) == 0) {
$output->writeln('Checking php settings:');
$output->writeln(
sprintf(
'- Requires PHP ' . ApiDiagnose::PHP_MIN . ' or better %s',
is_bool($value) ? '<error>FAIL</error>' : '<info>OK</info>'
)
);
if ($output->isVeryVerbose() && is_bool($value)) {
$this->writeComment(
$output,
'Upgrading to PHP ' .
ApiDiagnose::PHP_RECOMMANDED . ' or higher is recommended.'
);
}
}
if (strcasecmp('php_ini', $key) == 0) {
$output->writeln(
sprintf(
'- php.ini file loaded <info>%s</info>',
is_bool($value) ? 'NONE' : $value
)
);
}
if (preg_match('/^(.*)_loaded$/', $key, $matches)) {
// checks extensions loaded
if (strcasecmp('xdebug', $matches[1]) == 0) {
// Xdebug is special case (performance issue)
$output->writeln(
sprintf(
'- Xdebug extension loaded %s',
$value ? '<warning>YES</warning>' : '<info>NO</info>'
)
);
if ($output->isVeryVerbose()) {
$this->writeComment(
$output,
'You are encouraged to unload xdebug extension' .
' to speed up execution.'
);
}
if ($output->isVeryVerbose() && $response['xdebug_profiler_enable']) {
$this->writeComment(
$output,
'The xdebug.profiler_enable setting is enabled,' .
' this can slow down execution a lot.'
);
}
} else {
$output->writeln(
sprintf(
'- %s extension loaded %s',
$matches[1],
$value ? '<info>YES</info>' : '<error>FAIL</error>'
)
);
}
}
}
} | [
"public",
"function",
"run",
"(",
"OutputInterface",
"$",
"output",
",",
"$",
"response",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"'<comment>Diagnostics:</comment>'",
")",
";",
"foreach",
"(",
"$",
"response",
"as",
"$",
"key",
"=>",
"$",
"value",
"... | Diagnose run results
@param OutputInterface $output Console Output concrete instance
@param array $response Render config:validate command | [
"Diagnose",
"run",
"results"
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Output/Diagnose.php#L37-L104 |
llaville/php-reflect | src/Bartlett/Reflect/Api/Analyser.php | Analyser.run | public function run($source, array $analysers, $alias = null, $format = false, $filter = false)
{
$source = trim($source);
if ($alias) {
$alias = $source;
} else {
$alias = false;
}
if ($filter instanceof \Closure
|| $filter === false
) {
$closure = $filter;
} else {
if ($filterRes = stream_resolve_include_path($filter)) {
include_once $filterRes;
}
if (!isset($closure) || !is_callable($closure)) {
throw new \RuntimeException(
sprintf(
'Invalid filter provided by file "%s"',
$filterRes ? : $filter
)
);
}
}
return $this->request('analyser/run', 'POST', array($source, $analysers, $alias, $format, $closure));
} | php | public function run($source, array $analysers, $alias = null, $format = false, $filter = false)
{
$source = trim($source);
if ($alias) {
$alias = $source;
} else {
$alias = false;
}
if ($filter instanceof \Closure
|| $filter === false
) {
$closure = $filter;
} else {
if ($filterRes = stream_resolve_include_path($filter)) {
include_once $filterRes;
}
if (!isset($closure) || !is_callable($closure)) {
throw new \RuntimeException(
sprintf(
'Invalid filter provided by file "%s"',
$filterRes ? : $filter
)
);
}
}
return $this->request('analyser/run', 'POST', array($source, $analysers, $alias, $format, $closure));
} | [
"public",
"function",
"run",
"(",
"$",
"source",
",",
"array",
"$",
"analysers",
",",
"$",
"alias",
"=",
"null",
",",
"$",
"format",
"=",
"false",
",",
"$",
"filter",
"=",
"false",
")",
"{",
"$",
"source",
"=",
"trim",
"(",
"$",
"source",
")",
";... | Analyse a data source and display results.
@param string $source Path to the data source or its alias
@param array $analysers One or more analyser to perform (case insensitive).
@param mixed $alias If set, the source refers to its alias
@param string $format If set, convert result to a specific format.
@param mixed $filter Resource that provide a closure to filter results.
@return array metrics
@throws \InvalidArgumentException if an analyser required is not installed
@throws \RuntimeException if filter provided is not a closure | [
"Analyse",
"a",
"data",
"source",
"and",
"display",
"results",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Api/Analyser.php#L52-L80 |
llaville/php-reflect | src/Bartlett/Reflect/Client/LocalClient.php | LocalClient.request | public function request($method, $url, array $params = array())
{
$parts = explode('/', $url);
$className = $this->namespace . '\\' . ucfirst($parts[0]);
$methodName = count($parts) > 1 ? $parts[1] : 'invoke';
$api = new $className;
$api->setEventDispatcher($this->eventDispatcher);
$api->activatePlugins($this->registerPlugins);
try {
if (!class_exists($className)) {
throw new \BadFunctionCallException(
sprintf('API class endpoint %s does not exist.', $className)
);
}
$response = call_user_func_array(
array($api, $methodName),
$params
);
} catch (\Exception $e) {
$response = $e;
}
return $response;
} | php | public function request($method, $url, array $params = array())
{
$parts = explode('/', $url);
$className = $this->namespace . '\\' . ucfirst($parts[0]);
$methodName = count($parts) > 1 ? $parts[1] : 'invoke';
$api = new $className;
$api->setEventDispatcher($this->eventDispatcher);
$api->activatePlugins($this->registerPlugins);
try {
if (!class_exists($className)) {
throw new \BadFunctionCallException(
sprintf('API class endpoint %s does not exist.', $className)
);
}
$response = call_user_func_array(
array($api, $methodName),
$params
);
} catch (\Exception $e) {
$response = $e;
}
return $response;
} | [
"public",
"function",
"request",
"(",
"$",
"method",
",",
"$",
"url",
",",
"array",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'/'",
",",
"$",
"url",
")",
";",
"$",
"className",
"=",
"$",
"this",
"->",
... | {@inheritDoc} | [
"{"
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Client/LocalClient.php#L70-L96 |
llaville/php-reflect | src/Bartlett/Reflect/Analyser/AbstractAnalyser.php | AbstractAnalyser.visitClass | protected function visitClass(Node\Stmt\Class_ $class)
{
$this->testClass = false;
$parent = $class->extends;
if (empty($parent)) {
// No ancestry
// Treat the class as a test case class if the name
// of the parent class ends with "TestCase".
if (substr($class->name, -8) == 'TestCase') {
$this->testClass = true;
}
} else {
// Ancestry
// Treat the class as a test case class if the name
// of the parent class equals to "PHPUnit_Framework_TestCase".
if ((string) $parent === 'PHPUnit_Framework_TestCase') {
$this->testClass = true;
}
}
} | php | protected function visitClass(Node\Stmt\Class_ $class)
{
$this->testClass = false;
$parent = $class->extends;
if (empty($parent)) {
// No ancestry
// Treat the class as a test case class if the name
// of the parent class ends with "TestCase".
if (substr($class->name, -8) == 'TestCase') {
$this->testClass = true;
}
} else {
// Ancestry
// Treat the class as a test case class if the name
// of the parent class equals to "PHPUnit_Framework_TestCase".
if ((string) $parent === 'PHPUnit_Framework_TestCase') {
$this->testClass = true;
}
}
} | [
"protected",
"function",
"visitClass",
"(",
"Node",
"\\",
"Stmt",
"\\",
"Class_",
"$",
"class",
")",
"{",
"$",
"this",
"->",
"testClass",
"=",
"false",
";",
"$",
"parent",
"=",
"$",
"class",
"->",
"extends",
";",
"if",
"(",
"empty",
"(",
"$",
"parent... | Visits a class node.
@param Node\Stmt\Class_ $class Represents a class in the namespace
@return void | [
"Visits",
"a",
"class",
"node",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Analyser/AbstractAnalyser.php#L155-L178 |
llaville/php-reflect | src/Bartlett/Reflect/Analyser/AbstractAnalyser.php | AbstractAnalyser.isImplicitlyPublicProperty | protected function isImplicitlyPublicProperty(array $tokens, Node\Stmt\Property $prop)
{
$i = $prop->getAttribute('startTokenPos');
return (isset($tokens[$i]) && $tokens[$i][0] == T_VAR);
} | php | protected function isImplicitlyPublicProperty(array $tokens, Node\Stmt\Property $prop)
{
$i = $prop->getAttribute('startTokenPos');
return (isset($tokens[$i]) && $tokens[$i][0] == T_VAR);
} | [
"protected",
"function",
"isImplicitlyPublicProperty",
"(",
"array",
"$",
"tokens",
",",
"Node",
"\\",
"Stmt",
"\\",
"Property",
"$",
"prop",
")",
"{",
"$",
"i",
"=",
"$",
"prop",
"->",
"getAttribute",
"(",
"'startTokenPos'",
")",
";",
"return",
"(",
"isse... | Checks if a property is implicitly public (PHP 4 syntax)
@param array $tokens
@param Node\Stmt\Property $prop
@return boolean | [
"Checks",
"if",
"a",
"property",
"is",
"implicitly",
"public",
"(",
"PHP",
"4",
"syntax",
")"
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Analyser/AbstractAnalyser.php#L188-L192 |
llaville/php-reflect | src/Bartlett/Reflect/Analyser/AbstractAnalyser.php | AbstractAnalyser.isImplicitlyPublicFunction | protected function isImplicitlyPublicFunction(array $tokens, Node\Stmt\ClassMethod $method)
{
$i = $method->getAttribute('startTokenPos');
for ($c = count($tokens); $i < $c; ++$i) {
$t = $tokens[$i];
if ($t[0] == T_PUBLIC || $t[0] == T_PROTECTED || $t[0] == T_PRIVATE) {
return false;
}
if ($t[0] == T_FUNCTION) {
break;
}
}
return true;
} | php | protected function isImplicitlyPublicFunction(array $tokens, Node\Stmt\ClassMethod $method)
{
$i = $method->getAttribute('startTokenPos');
for ($c = count($tokens); $i < $c; ++$i) {
$t = $tokens[$i];
if ($t[0] == T_PUBLIC || $t[0] == T_PROTECTED || $t[0] == T_PRIVATE) {
return false;
}
if ($t[0] == T_FUNCTION) {
break;
}
}
return true;
} | [
"protected",
"function",
"isImplicitlyPublicFunction",
"(",
"array",
"$",
"tokens",
",",
"Node",
"\\",
"Stmt",
"\\",
"ClassMethod",
"$",
"method",
")",
"{",
"$",
"i",
"=",
"$",
"method",
"->",
"getAttribute",
"(",
"'startTokenPos'",
")",
";",
"for",
"(",
"... | Checks if a method is implicitly public (PHP 4 syntax)
@param array $tokens
@param Node\Stmt\ClassMethod $method
@return boolean | [
"Checks",
"if",
"a",
"method",
"is",
"implicitly",
"public",
"(",
"PHP",
"4",
"syntax",
")"
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Analyser/AbstractAnalyser.php#L202-L215 |
llaville/php-reflect | src/Bartlett/Reflect/Analyser/AbstractAnalyser.php | AbstractAnalyser.isShortArraySyntax | protected function isShortArraySyntax(array $tokens, Node\Expr\Array_ $array)
{
$i = $array->getAttribute('startTokenPos');
return is_string($tokens[$i]);
} | php | protected function isShortArraySyntax(array $tokens, Node\Expr\Array_ $array)
{
$i = $array->getAttribute('startTokenPos');
return is_string($tokens[$i]);
} | [
"protected",
"function",
"isShortArraySyntax",
"(",
"array",
"$",
"tokens",
",",
"Node",
"\\",
"Expr",
"\\",
"Array_",
"$",
"array",
")",
"{",
"$",
"i",
"=",
"$",
"array",
"->",
"getAttribute",
"(",
"'startTokenPos'",
")",
";",
"return",
"is_string",
"(",
... | Checks if array syntax is normal or short (PHP 5.4+ feature)
@param array $tokens
@param Node\Expr\Array_ $array
@return boolean | [
"Checks",
"if",
"array",
"syntax",
"is",
"normal",
"or",
"short",
"(",
"PHP",
"5",
".",
"4",
"+",
"feature",
")"
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Analyser/AbstractAnalyser.php#L225-L229 |
llaville/php-reflect | src/Bartlett/Reflect/Plugin/Log/DefaultLogger.php | DefaultLogger.isHandling | public function isHandling(array $record)
{
$level = array_search($record['level'], self::$levels);
return $level >= $this->level;
} | php | public function isHandling(array $record)
{
$level = array_search($record['level'], self::$levels);
return $level >= $this->level;
} | [
"public",
"function",
"isHandling",
"(",
"array",
"$",
"record",
")",
"{",
"$",
"level",
"=",
"array_search",
"(",
"$",
"record",
"[",
"'level'",
"]",
",",
"self",
"::",
"$",
"levels",
")",
";",
"return",
"$",
"level",
">=",
"$",
"this",
"->",
"level... | Checks whether the given record will be handled by this handler.
@param array $record The record to handle
@return bool | [
"Checks",
"whether",
"the",
"given",
"record",
"will",
"be",
"handled",
"by",
"this",
"handler",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Plugin/Log/DefaultLogger.php#L84-L88 |
llaville/php-reflect | src/Bartlett/Reflect/Plugin/Log/DefaultLogger.php | DefaultLogger.log | public function log($level, $message, array $context = array())
{
$record = array(
'channel' => $this->channel,
'level' => $level,
'message' => $message,
'context' => $context,
'extra' => array(),
'datetime' => new \DateTime(),
);
if ($this->isHandling($record)) {
foreach ($this->processors as $processor) {
$record = call_user_func($processor, $record);
}
$this->handler->handle($record);
}
} | php | public function log($level, $message, array $context = array())
{
$record = array(
'channel' => $this->channel,
'level' => $level,
'message' => $message,
'context' => $context,
'extra' => array(),
'datetime' => new \DateTime(),
);
if ($this->isHandling($record)) {
foreach ($this->processors as $processor) {
$record = call_user_func($processor, $record);
}
$this->handler->handle($record);
}
} | [
"public",
"function",
"log",
"(",
"$",
"level",
",",
"$",
"message",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"$",
"record",
"=",
"array",
"(",
"'channel'",
"=>",
"$",
"this",
"->",
"channel",
",",
"'level'",
"=>",
"$",
"leve... | Adds a log record at an arbitrary level.
@param mixed $level The log level
@param string $message The log message
@param array $context The log context
@return void | [
"Adds",
"a",
"log",
"record",
"at",
"an",
"arbitrary",
"level",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Plugin/Log/DefaultLogger.php#L99-L116 |
llaville/php-reflect | src/Bartlett/Reflect/Plugin/Log/DefaultLogger.php | DefaultLogger.interpolate | public function interpolate(array $record)
{
if (false === strpos($record['message'], '{')) {
return $record;
}
$replacements = array();
foreach ($record['context'] as $key => $val) {
if (is_null($val)
|| is_scalar($val)
|| (is_object($val) && method_exists($val, "__toString"))
) {
$replacements['{'.$key.'}'] = $val;
} elseif (is_object($val)) {
$replacements['{'.$key.'}'] = '[object '.get_class($val).']';
} else {
$replacements['{'.$key.'}'] = '['.gettype($val).']';
}
}
$record['message'] = strtr($record['message'], $replacements);
return $record;
} | php | public function interpolate(array $record)
{
if (false === strpos($record['message'], '{')) {
return $record;
}
$replacements = array();
foreach ($record['context'] as $key => $val) {
if (is_null($val)
|| is_scalar($val)
|| (is_object($val) && method_exists($val, "__toString"))
) {
$replacements['{'.$key.'}'] = $val;
} elseif (is_object($val)) {
$replacements['{'.$key.'}'] = '[object '.get_class($val).']';
} else {
$replacements['{'.$key.'}'] = '['.gettype($val).']';
}
}
$record['message'] = strtr($record['message'], $replacements);
return $record;
} | [
"public",
"function",
"interpolate",
"(",
"array",
"$",
"record",
")",
"{",
"if",
"(",
"false",
"===",
"strpos",
"(",
"$",
"record",
"[",
"'message'",
"]",
",",
"'{'",
")",
")",
"{",
"return",
"$",
"record",
";",
"}",
"$",
"replacements",
"=",
"array... | Processes a record's message according to PSR-3 rules
It replaces {foo} with the value from $context['foo']
This code was copied from Monolog\Processor\PsrLogMessageProcessor
@author Jordi Boggiano <j.boggiano@seld.be> | [
"Processes",
"a",
"record",
"s",
"message",
"according",
"to",
"PSR",
"-",
"3",
"rules"
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Plugin/Log/DefaultLogger.php#L146-L169 |
llaville/php-reflect | src/Bartlett/Reflect/Api/Diagram.php | Diagram.package | public function package($argument, $source, $alias = null, $engine = 'plantuml')
{
return $this->request('diagram/package', 'POST', array($argument, $source, $alias, $engine));
} | php | public function package($argument, $source, $alias = null, $engine = 'plantuml')
{
return $this->request('diagram/package', 'POST', array($argument, $source, $alias, $engine));
} | [
"public",
"function",
"package",
"(",
"$",
"argument",
",",
"$",
"source",
",",
"$",
"alias",
"=",
"null",
",",
"$",
"engine",
"=",
"'plantuml'",
")",
"{",
"return",
"$",
"this",
"->",
"request",
"(",
"'diagram/package'",
",",
"'POST'",
",",
"array",
"... | Generates diagram about namespaces in a data source.
@param string $argument Name of the namespace to inspect.
@param string $source Path to the data source or its alias.
@param mixed $alias If set, the source refers to its alias.
@param string $engine Graphical syntax.
@return mixed | [
"Generates",
"diagram",
"about",
"namespaces",
"in",
"a",
"data",
"source",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Api/Diagram.php#L38-L41 |
llaville/php-reflect | src/Bartlett/Reflect/Api/Diagram.php | Diagram.class_ | public function class_($argument, $source, $alias = null, $engine = 'plantuml')
{
return $this->request('diagram/class', 'POST', array($argument, $source, $alias, $engine));
} | php | public function class_($argument, $source, $alias = null, $engine = 'plantuml')
{
return $this->request('diagram/class', 'POST', array($argument, $source, $alias, $engine));
} | [
"public",
"function",
"class_",
"(",
"$",
"argument",
",",
"$",
"source",
",",
"$",
"alias",
"=",
"null",
",",
"$",
"engine",
"=",
"'plantuml'",
")",
"{",
"return",
"$",
"this",
"->",
"request",
"(",
"'diagram/class'",
",",
"'POST'",
",",
"array",
"(",... | Generates diagram about a user class present in a data source.
@param string $argument Name of the class to inspect.
@param string $source Path to the data source or its alias.
@param mixed $alias If set, the source refers to its alias.
@param string $engine Graphical syntax.
@return mixed
@alias class | [
"Generates",
"diagram",
"about",
"a",
"user",
"class",
"present",
"in",
"a",
"data",
"source",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Api/Diagram.php#L54-L57 |
llaville/php-reflect | src/Bartlett/Reflect/Plugin/Cache/DoctrineCacheAdapter.php | DoctrineCacheAdapter.save | public function save($id, $data, $lifeTime = false, array $options = null)
{
return $this->cache->save($id, $data, $lifeTime);
} | php | public function save($id, $data, $lifeTime = false, array $options = null)
{
return $this->cache->save($id, $data, $lifeTime);
} | [
"public",
"function",
"save",
"(",
"$",
"id",
",",
"$",
"data",
",",
"$",
"lifeTime",
"=",
"false",
",",
"array",
"$",
"options",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"cache",
"->",
"save",
"(",
"$",
"id",
",",
"$",
"data",
",",
... | Puts data into the cache.
@param string $id The cache id of the new entry to store.
@param string $data The cache entry/data
@param mixed $lifeTime (optional) Sets a specific lifetime for this cache entry
@param array $options (optional) Array of cache adapter options
@return bool TRUE if the entry was successfully stored in the cache, FALSE otherwise. | [
"Puts",
"data",
"into",
"the",
"cache",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Plugin/Cache/DoctrineCacheAdapter.php#L98-L101 |
llaville/php-reflect | src/Bartlett/Reflect/Collection/ReflectionCollection.php | ReflectionCollection.add | public function add($node)
{
if ($node instanceof Node\Stmt\Class_
|| $node instanceof Node\Stmt\Interface_
|| $node instanceof Node\Stmt\Trait_
) {
$model = new ClassModel($node);
} elseif ($node instanceof Node\Stmt\Function_
|| $node instanceof Node\Expr\Closure
) {
$model = new FunctionModel($node);
} elseif ($node instanceof Node\Stmt\Const_) {
$model = new ConstantModel($node);
}
parent::add($model);
} | php | public function add($node)
{
if ($node instanceof Node\Stmt\Class_
|| $node instanceof Node\Stmt\Interface_
|| $node instanceof Node\Stmt\Trait_
) {
$model = new ClassModel($node);
} elseif ($node instanceof Node\Stmt\Function_
|| $node instanceof Node\Expr\Closure
) {
$model = new FunctionModel($node);
} elseif ($node instanceof Node\Stmt\Const_) {
$model = new ConstantModel($node);
}
parent::add($model);
} | [
"public",
"function",
"add",
"(",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"node",
"instanceof",
"Node",
"\\",
"Stmt",
"\\",
"Class_",
"||",
"$",
"node",
"instanceof",
"Node",
"\\",
"Stmt",
"\\",
"Interface_",
"||",
"$",
"node",
"instanceof",
"Node",
"\\... | {@inheritDoc} | [
"{"
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Collection/ReflectionCollection.php#L37-L52 |
llaville/php-reflect | src/Bartlett/Reflect/Api/Cache.php | Cache.clear | public function clear($source, $alias = null)
{
$source = trim($source);
if ($alias) {
$alias = $source;
} else {
$alias = false;
}
return $this->request('cache/clear', 'POST', array($source, $alias));
} | php | public function clear($source, $alias = null)
{
$source = trim($source);
if ($alias) {
$alias = $source;
} else {
$alias = false;
}
return $this->request('cache/clear', 'POST', array($source, $alias));
} | [
"public",
"function",
"clear",
"(",
"$",
"source",
",",
"$",
"alias",
"=",
"null",
")",
"{",
"$",
"source",
"=",
"trim",
"(",
"$",
"source",
")",
";",
"if",
"(",
"$",
"alias",
")",
"{",
"$",
"alias",
"=",
"$",
"source",
";",
"}",
"else",
"{",
... | Clear cache (any adapter and backend).
@param string $source Path to the data source or its alias.
@param string $alias If set, the source refers to its alias.
@return int Number of entries cleared in cache
@throws \Exception if data source provider is unknown
@throws \RuntimeException if cache plugin is not installed | [
"Clear",
"cache",
"(",
"any",
"adapter",
"and",
"backend",
")",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Api/Cache.php#L38-L47 |
llaville/php-reflect | src/Bartlett/Reflect/Plugin/Cache/DefaultCacheStorage.php | DefaultCacheStorage.exists | public function exists($request)
{
// Hash a request data source into a string that returns cache metadata
$this->key = $request['source'];
if ($this->entries = $this->cache->fetch($this->key)) {
return true;
}
return false;
} | php | public function exists($request)
{
// Hash a request data source into a string that returns cache metadata
$this->key = $request['source'];
if ($this->entries = $this->cache->fetch($this->key)) {
return true;
}
return false;
} | [
"public",
"function",
"exists",
"(",
"$",
"request",
")",
"{",
"// Hash a request data source into a string that returns cache metadata",
"$",
"this",
"->",
"key",
"=",
"$",
"request",
"[",
"'source'",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"entries",
"=",
"$",... | Checks if cache exists for a request.
@param array $request Request data to check for
@return bool TRUE if a response exists in cache, FALSE otherwise | [
"Checks",
"if",
"cache",
"exists",
"for",
"a",
"request",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Plugin/Cache/DefaultCacheStorage.php#L71-L80 |
llaville/php-reflect | src/Bartlett/Reflect/Plugin/Cache/DefaultCacheStorage.php | DefaultCacheStorage.fetch | public function fetch($request)
{
if (!$this->exists($request)) {
return;
}
$manifest = null;
foreach ($this->entries as $index => $entry) {
if ($entry['sourceFile'] === $request['file']->getPathname()) {
$manifest = $entry;
break; // we found entry in cache corresponding to current filename
}
}
if (!isset($manifest)) {
// no cache results for this filename
return;
}
// Ensure that the response is not expired
if ($manifest['expiration'] < time()
|| $manifest['cacheData'] !== sha1_file($request['file']->getPathname())
) {
// results have expired
$response = false;
} else {
$response = $this->cache->fetch($manifest['cacheData']);
}
if ($response === false) {
// Remove the entry from the metadata and update the cache
unset($this->entries[$index]);
if (count($this->entries)) {
$this->cache->save($this->key, $this->entries);
} else {
$this->cache->delete($this->key);
}
}
return $response;
} | php | public function fetch($request)
{
if (!$this->exists($request)) {
return;
}
$manifest = null;
foreach ($this->entries as $index => $entry) {
if ($entry['sourceFile'] === $request['file']->getPathname()) {
$manifest = $entry;
break; // we found entry in cache corresponding to current filename
}
}
if (!isset($manifest)) {
// no cache results for this filename
return;
}
// Ensure that the response is not expired
if ($manifest['expiration'] < time()
|| $manifest['cacheData'] !== sha1_file($request['file']->getPathname())
) {
// results have expired
$response = false;
} else {
$response = $this->cache->fetch($manifest['cacheData']);
}
if ($response === false) {
// Remove the entry from the metadata and update the cache
unset($this->entries[$index]);
if (count($this->entries)) {
$this->cache->save($this->key, $this->entries);
} else {
$this->cache->delete($this->key);
}
}
return $response;
} | [
"public",
"function",
"fetch",
"(",
"$",
"request",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"exists",
"(",
"$",
"request",
")",
")",
"{",
"return",
";",
"}",
"$",
"manifest",
"=",
"null",
";",
"foreach",
"(",
"$",
"this",
"->",
"entries",
"a... | Get a response from the cache for a request.
@param array $request Request data to read from cache
@return mixed | [
"Get",
"a",
"response",
"from",
"the",
"cache",
"for",
"a",
"request",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Plugin/Cache/DefaultCacheStorage.php#L89-L129 |
llaville/php-reflect | src/Bartlett/Reflect/Plugin/Cache/DefaultCacheStorage.php | DefaultCacheStorage.cache | public function cache($request)
{
$currentTime = time();
$entries = array();
if ($this->exists($request)) {
foreach ($this->entries as $entry) {
if ($entry['expiration'] < $currentTime) {
// remove expired entry from the metadata
continue;
}
if ($entry['sourceFile'] === $request['file']->getPathname()) {
// remove old cached content
$this->cache->delete($entry['cacheData']);
} else {
$entries[] = $entry;
}
}
}
// update the manifest
$key = sha1_file($request['file']->getPathname());
array_push(
$entries,
array(
'expiration' => $currentTime + $this->maxlifetime,
'cacheData' => $key,
'sourceFile' => $request['file']->getPathname()
)
);
$this->cache->save($this->key, $entries);
// save user data
$this->cache->save($key, $request['ast']);
} | php | public function cache($request)
{
$currentTime = time();
$entries = array();
if ($this->exists($request)) {
foreach ($this->entries as $entry) {
if ($entry['expiration'] < $currentTime) {
// remove expired entry from the metadata
continue;
}
if ($entry['sourceFile'] === $request['file']->getPathname()) {
// remove old cached content
$this->cache->delete($entry['cacheData']);
} else {
$entries[] = $entry;
}
}
}
// update the manifest
$key = sha1_file($request['file']->getPathname());
array_push(
$entries,
array(
'expiration' => $currentTime + $this->maxlifetime,
'cacheData' => $key,
'sourceFile' => $request['file']->getPathname()
)
);
$this->cache->save($this->key, $entries);
// save user data
$this->cache->save($key, $request['ast']);
} | [
"public",
"function",
"cache",
"(",
"$",
"request",
")",
"{",
"$",
"currentTime",
"=",
"time",
"(",
")",
";",
"$",
"entries",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"exists",
"(",
"$",
"request",
")",
")",
"{",
"foreach",
"(",... | Cache a FILE parse.
@param array $request Request being cached
@return void | [
"Cache",
"a",
"FILE",
"parse",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Plugin/Cache/DefaultCacheStorage.php#L138-L172 |
llaville/php-reflect | src/Bartlett/Reflect/Plugin/Cache/DefaultCacheStorage.php | DefaultCacheStorage.delete | public function delete($request)
{
$entriesCleared = 0;
if ($this->exists($request)) {
foreach ($this->entries as $entry) {
if ($entry['cacheData']) {
// delete each results of the manifest
if ($this->cache->delete($entry['cacheData'])) {
$entriesCleared++;
}
}
}
// delete the manifest of data source
$this->cache->delete($this->key);
}
return $entriesCleared;
} | php | public function delete($request)
{
$entriesCleared = 0;
if ($this->exists($request)) {
foreach ($this->entries as $entry) {
if ($entry['cacheData']) {
// delete each results of the manifest
if ($this->cache->delete($entry['cacheData'])) {
$entriesCleared++;
}
}
}
// delete the manifest of data source
$this->cache->delete($this->key);
}
return $entriesCleared;
} | [
"public",
"function",
"delete",
"(",
"$",
"request",
")",
"{",
"$",
"entriesCleared",
"=",
"0",
";",
"if",
"(",
"$",
"this",
"->",
"exists",
"(",
"$",
"request",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"entries",
"as",
"$",
"entry",
")",
... | Deletes cache entries that match a request.
@param array $request Request to delete from cache
@return int | [
"Deletes",
"cache",
"entries",
"that",
"match",
"a",
"request",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Plugin/Cache/DefaultCacheStorage.php#L181-L198 |
llaville/php-reflect | src/Bartlett/Reflect/Plugin/CachePlugin.php | CachePlugin.getSubscribedEvents | public static function getSubscribedEvents()
{
return array(
Reflect\Events::PROGRESS => 'onReflectProgress',
Reflect\Events::SUCCESS => 'onReflectSuccess',
Reflect\Events::COMPLETE => 'onReflectComplete',
);
} | php | public static function getSubscribedEvents()
{
return array(
Reflect\Events::PROGRESS => 'onReflectProgress',
Reflect\Events::SUCCESS => 'onReflectSuccess',
Reflect\Events::COMPLETE => 'onReflectComplete',
);
} | [
"public",
"static",
"function",
"getSubscribedEvents",
"(",
")",
"{",
"return",
"array",
"(",
"Reflect",
"\\",
"Events",
"::",
"PROGRESS",
"=>",
"'onReflectProgress'",
",",
"Reflect",
"\\",
"Events",
"::",
"SUCCESS",
"=>",
"'onReflectSuccess'",
",",
"Reflect",
"... | {@inheritdoc} | [
"{"
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Plugin/CachePlugin.php#L82-L89 |
llaville/php-reflect | src/Bartlett/Reflect/Plugin/CachePlugin.php | CachePlugin.onReflectProgress | public function onReflectProgress(GenericEvent $event)
{
if ($response = $this->storage->fetch($event)) {
++$this->stats[self::STATS_HITS];
$this->hashUserData = sha1(serialize($response));
$event['notModified'] = $response;
} else {
$this->hashUserData = null;
}
} | php | public function onReflectProgress(GenericEvent $event)
{
if ($response = $this->storage->fetch($event)) {
++$this->stats[self::STATS_HITS];
$this->hashUserData = sha1(serialize($response));
$event['notModified'] = $response;
} else {
$this->hashUserData = null;
}
} | [
"public",
"function",
"onReflectProgress",
"(",
"GenericEvent",
"$",
"event",
")",
"{",
"if",
"(",
"$",
"response",
"=",
"$",
"this",
"->",
"storage",
"->",
"fetch",
"(",
"$",
"event",
")",
")",
"{",
"++",
"$",
"this",
"->",
"stats",
"[",
"self",
"::... | Checks if results in cache will satisfy the source before parsing.
@param Event $event Current event emitted by the manager (Reflect class)
@return void | [
"Checks",
"if",
"results",
"in",
"cache",
"will",
"satisfy",
"the",
"source",
"before",
"parsing",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Plugin/CachePlugin.php#L98-L107 |
llaville/php-reflect | src/Bartlett/Reflect/Plugin/CachePlugin.php | CachePlugin.onReflectSuccess | public function onReflectSuccess(GenericEvent $event)
{
if (sha1(serialize($event['ast'])) !== $this->hashUserData) {
// cache need to be refresh
++$this->stats[self::STATS_MISSES];
$this->storage->cache($event);
}
} | php | public function onReflectSuccess(GenericEvent $event)
{
if (sha1(serialize($event['ast'])) !== $this->hashUserData) {
// cache need to be refresh
++$this->stats[self::STATS_MISSES];
$this->storage->cache($event);
}
} | [
"public",
"function",
"onReflectSuccess",
"(",
"GenericEvent",
"$",
"event",
")",
"{",
"if",
"(",
"sha1",
"(",
"serialize",
"(",
"$",
"event",
"[",
"'ast'",
"]",
")",
")",
"!==",
"$",
"this",
"->",
"hashUserData",
")",
"{",
"// cache need to be refresh",
"... | If possible, store results in cache after source parsing.
@param Event $event Current event emitted by the manager (Reflect class)
@return void | [
"If",
"possible",
"store",
"results",
"in",
"cache",
"after",
"source",
"parsing",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Plugin/CachePlugin.php#L116-L123 |
llaville/php-reflect | src/Bartlett/Reflect/Plugin/CachePlugin.php | CachePlugin.createCacheStorage | private static function createCacheStorage($options)
{
$options = array_merge(
array(
'adapter' => 'DoctrineCacheAdapter',
'backend' => array(
'class' => 'Doctrine\Common\Cache\FilesystemCache',
'args' => array('%{TEMP}/bartlett/cache'),
),
),
$options
);
if (!isset($options['adapter'])) {
throw new \InvalidArgumentException('Adapter is missing');
}
$adapterClass = $options['adapter'];
if (strpos($adapterClass, '\\') === false) {
// add default namespace
$adapterClass = __NAMESPACE__ . '\Cache\\' . $adapterClass;
}
if (!class_exists($adapterClass)) {
throw new \InvalidArgumentException(
sprintf(
'Adapter "%s" cannot be loaded.',
$adapterClass
)
);
}
if (!isset($options['backend']['class'])) {
throw new \InvalidArgumentException(
sprintf(
'Backend is missing for %s',
$adapterClass
)
);
}
$backendClass = $options['backend']['class'];
if (!class_exists($backendClass)) {
throw new \InvalidArgumentException(
sprintf(
'Backend "%s" cannot be loaded.',
$backendClass
)
);
}
$rc = new \ReflectionClass($backendClass);
if (isset($options['backend']['args'])) {
$args = self::replaceTokens($options['backend']['args']);
} else {
$args = array();
}
$backend = $rc->newInstanceArgs($args);
$cacheAdapter = new $adapterClass($backend);
$cache = new DefaultCacheStorage($cacheAdapter);
return $cache;
} | php | private static function createCacheStorage($options)
{
$options = array_merge(
array(
'adapter' => 'DoctrineCacheAdapter',
'backend' => array(
'class' => 'Doctrine\Common\Cache\FilesystemCache',
'args' => array('%{TEMP}/bartlett/cache'),
),
),
$options
);
if (!isset($options['adapter'])) {
throw new \InvalidArgumentException('Adapter is missing');
}
$adapterClass = $options['adapter'];
if (strpos($adapterClass, '\\') === false) {
// add default namespace
$adapterClass = __NAMESPACE__ . '\Cache\\' . $adapterClass;
}
if (!class_exists($adapterClass)) {
throw new \InvalidArgumentException(
sprintf(
'Adapter "%s" cannot be loaded.',
$adapterClass
)
);
}
if (!isset($options['backend']['class'])) {
throw new \InvalidArgumentException(
sprintf(
'Backend is missing for %s',
$adapterClass
)
);
}
$backendClass = $options['backend']['class'];
if (!class_exists($backendClass)) {
throw new \InvalidArgumentException(
sprintf(
'Backend "%s" cannot be loaded.',
$backendClass
)
);
}
$rc = new \ReflectionClass($backendClass);
if (isset($options['backend']['args'])) {
$args = self::replaceTokens($options['backend']['args']);
} else {
$args = array();
}
$backend = $rc->newInstanceArgs($args);
$cacheAdapter = new $adapterClass($backend);
$cache = new DefaultCacheStorage($cacheAdapter);
return $cache;
} | [
"private",
"static",
"function",
"createCacheStorage",
"(",
"$",
"options",
")",
"{",
"$",
"options",
"=",
"array_merge",
"(",
"array",
"(",
"'adapter'",
"=>",
"'DoctrineCacheAdapter'",
",",
"'backend'",
"=>",
"array",
"(",
"'class'",
"=>",
"'Doctrine\\Common\\Cac... | Creates a default cache storage corresponding to $options
@param array $options Cache configuration
@return DefaultCacheStorage
@throws \InvalidArgumentException | [
"Creates",
"a",
"default",
"cache",
"storage",
"corresponding",
"to",
"$options"
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Plugin/CachePlugin.php#L153-L216 |
llaville/php-reflect | src/Bartlett/Reflect/Api/V3/Reflection.php | Reflection.class_ | public function class_($argument, $source, $alias = null, $format = 'txt')
{
$api = new Analyser();
$api->setEventDispatcher($this->eventDispatcher);
$metrics = $api->run($source, array('reflection'), $alias, false, false);
$collect = $metrics['Bartlett\Reflect\Analyser\ReflectionAnalyser']->filter(
function ($element) use ($argument) {
return $element instanceof Model\ClassModel
&& $element->getName() === $argument;
}
);
if (count($collect) === 0) {
throw new \Exception(
sprintf('Class "%s" not found.', $argument)
);
}
return $collect->first();
} | php | public function class_($argument, $source, $alias = null, $format = 'txt')
{
$api = new Analyser();
$api->setEventDispatcher($this->eventDispatcher);
$metrics = $api->run($source, array('reflection'), $alias, false, false);
$collect = $metrics['Bartlett\Reflect\Analyser\ReflectionAnalyser']->filter(
function ($element) use ($argument) {
return $element instanceof Model\ClassModel
&& $element->getName() === $argument;
}
);
if (count($collect) === 0) {
throw new \Exception(
sprintf('Class "%s" not found.', $argument)
);
}
return $collect->first();
} | [
"public",
"function",
"class_",
"(",
"$",
"argument",
",",
"$",
"source",
",",
"$",
"alias",
"=",
"null",
",",
"$",
"format",
"=",
"'txt'",
")",
"{",
"$",
"api",
"=",
"new",
"Analyser",
"(",
")",
";",
"$",
"api",
"->",
"setEventDispatcher",
"(",
"$... | Reports information about a user class present in a data source.
@param string $argument Name of the class to reflect.
@param string $source Path to the data source or its alias.
@param mixed $alias If set, the source refers to its alias.
@param string $format To ouput results in other formats.
@return mixed | [
"Reports",
"information",
"about",
"a",
"user",
"class",
"present",
"in",
"a",
"data",
"source",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Api/V3/Reflection.php#L49-L68 |
llaville/php-reflect | src/Bartlett/Reflect/Console/CommandFactory.php | CommandFactory.generateCommands | public function generateCommands(array $classes = null)
{
if (!isset($classes)) {
$classes = array();
}
$path = dirname(__DIR__) . '/Api';
if (\Phar::running(false)) {
$iterator = new \Phar($path);
} else {
$iterator = new \DirectoryIterator($path);
}
foreach ($iterator as $file) {
if (fnmatch('*.php', $file->getPathName())) {
$classes[] = Application::API_NAMESPACE . basename($file, '.php');
}
}
$commands = array();
foreach ($classes as $class) {
$api = new \ReflectionClass($class);
if ($api->isAbstract()) {
// skip abtract classes
continue;
}
foreach ($api->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
if (strstr($method->getName(), '__')) {
// skip magics
continue;
}
$commands[] = $this->generateCommand(strtolower($api->getShortName()), $method);
}
}
return $commands;
} | php | public function generateCommands(array $classes = null)
{
if (!isset($classes)) {
$classes = array();
}
$path = dirname(__DIR__) . '/Api';
if (\Phar::running(false)) {
$iterator = new \Phar($path);
} else {
$iterator = new \DirectoryIterator($path);
}
foreach ($iterator as $file) {
if (fnmatch('*.php', $file->getPathName())) {
$classes[] = Application::API_NAMESPACE . basename($file, '.php');
}
}
$commands = array();
foreach ($classes as $class) {
$api = new \ReflectionClass($class);
if ($api->isAbstract()) {
// skip abtract classes
continue;
}
foreach ($api->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
if (strstr($method->getName(), '__')) {
// skip magics
continue;
}
$commands[] = $this->generateCommand(strtolower($api->getShortName()), $method);
}
}
return $commands;
} | [
"public",
"function",
"generateCommands",
"(",
"array",
"$",
"classes",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"classes",
")",
")",
"{",
"$",
"classes",
"=",
"array",
"(",
")",
";",
"}",
"$",
"path",
"=",
"dirname",
"(",
"__DIR__... | Generates Commands from all Api Methods or a predefined set.
@param array $classes (optional) Api classes to lookup for commands
@return Command[] | [
"Generates",
"Commands",
"from",
"all",
"Api",
"Methods",
"or",
"a",
"predefined",
"set",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Console/CommandFactory.php#L68-L105 |
llaville/php-reflect | src/Bartlett/Reflect/Console/CommandFactory.php | CommandFactory.generateCommand | private function generateCommand($namespace, \ReflectionMethod $method)
{
$factory = DocBlockFactory::createInstance();
$docBlock = $factory->create($method->getDocComment());
$methodShortName = $method->getShortName();
$command = new Command($namespace . ':' . $this->dash($methodShortName));
$cmdExceptions = array();
if (isset($this->cmdExceptions[$namespace])) {
if (isset($this->cmdExceptions[$namespace][$methodShortName])) {
$cmdExceptions = $this->cmdExceptions[$namespace][$methodShortName];
}
}
$params = $docBlock->getTagsByName('param');
$aliases = $docBlock->getTagsByName('alias');
$disabled = $docBlock->getTagsByName('disabled');
if (!empty($disabled)) {
// restrict some public Api methods
$command->disable();
} else {
if (!empty($aliases)) {
$names = array();
foreach ($aliases as $aliasTag) {
$names[] = $namespace . ':' . (string) $aliasTag->getDescription();
}
$name = array_shift($names);
// rename command with the first alias
$command->setName($name);
// others @alias are really some command aliases
$command->setAliases($names);
}
$command->setDefinition(
$this->buildDefinition($namespace, $method, $params, $cmdExceptions)
);
$command->setDescription($docBlock->getSummary());
$command->setCode($this->createCode($namespace, $method));
}
return $command;
} | php | private function generateCommand($namespace, \ReflectionMethod $method)
{
$factory = DocBlockFactory::createInstance();
$docBlock = $factory->create($method->getDocComment());
$methodShortName = $method->getShortName();
$command = new Command($namespace . ':' . $this->dash($methodShortName));
$cmdExceptions = array();
if (isset($this->cmdExceptions[$namespace])) {
if (isset($this->cmdExceptions[$namespace][$methodShortName])) {
$cmdExceptions = $this->cmdExceptions[$namespace][$methodShortName];
}
}
$params = $docBlock->getTagsByName('param');
$aliases = $docBlock->getTagsByName('alias');
$disabled = $docBlock->getTagsByName('disabled');
if (!empty($disabled)) {
// restrict some public Api methods
$command->disable();
} else {
if (!empty($aliases)) {
$names = array();
foreach ($aliases as $aliasTag) {
$names[] = $namespace . ':' . (string) $aliasTag->getDescription();
}
$name = array_shift($names);
// rename command with the first alias
$command->setName($name);
// others @alias are really some command aliases
$command->setAliases($names);
}
$command->setDefinition(
$this->buildDefinition($namespace, $method, $params, $cmdExceptions)
);
$command->setDescription($docBlock->getSummary());
$command->setCode($this->createCode($namespace, $method));
}
return $command;
} | [
"private",
"function",
"generateCommand",
"(",
"$",
"namespace",
",",
"\\",
"ReflectionMethod",
"$",
"method",
")",
"{",
"$",
"factory",
"=",
"DocBlockFactory",
"::",
"createInstance",
"(",
")",
";",
"$",
"docBlock",
"=",
"$",
"factory",
"->",
"create",
"(",... | Creates a Command based on an Api Method
@param string $namespace Command namespace
@param \ReflectionMethod $method
@return Command | [
"Creates",
"a",
"Command",
"based",
"on",
"an",
"Api",
"Method"
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Console/CommandFactory.php#L115-L160 |
llaville/php-reflect | src/Bartlett/Reflect/Console/CommandFactory.php | CommandFactory.buildDefinition | private function buildDefinition($namespace, \ReflectionMethod $method, $params, $cmdExceptions)
{
$definition = new InputDefinition();
foreach ($method->getParameters() as $pos => $parameter) {
$name = $parameter->getName();
$description = null;
if (isset($params[$pos])) {
if (ltrim($params[$pos]->getVariableName(), '$') == $name) {
$description = $params[$pos]->getDescription();
// replace tokens if available
if (isset($cmdExceptions[$name]['replaceTokens'])) {
$description = strtr(
$description,
$cmdExceptions[$name]['replaceTokens']
);
}
}
}
if ($parameter->isOptional()) {
$shortcut = null;
$default = $parameter->isDefaultValueAvailable()
? $parameter->getDefaultValue() : null;
// option
if ($default === null) {
$mode = InputOption::VALUE_NONE;
} else {
$mode = InputOption::VALUE_OPTIONAL;
}
if (isset($params[$pos])
&& strcasecmp($params[$pos]->getType(), 'array') === 0
) {
$mode = InputOption::VALUE_IS_ARRAY | $mode;
}
$definition->addOption(
new InputOption($name, $shortcut, $mode, $description, $default)
);
} else {
if (isset($cmdExceptions[$name]['default'])) {
$default = $cmdExceptions[$name]['default'];
$mode = InputArgument::OPTIONAL;
} else {
$default = null;
$mode = InputArgument::REQUIRED;
}
if (isset($params[$pos])
&& strcasecmp($params[$pos]->getType(), 'array') === 0
) {
$mode = InputArgument::IS_ARRAY | $mode;
}
// argument
$definition->addArgument(
new InputArgument($name, $mode, $description, $default)
);
}
}
return $definition;
} | php | private function buildDefinition($namespace, \ReflectionMethod $method, $params, $cmdExceptions)
{
$definition = new InputDefinition();
foreach ($method->getParameters() as $pos => $parameter) {
$name = $parameter->getName();
$description = null;
if (isset($params[$pos])) {
if (ltrim($params[$pos]->getVariableName(), '$') == $name) {
$description = $params[$pos]->getDescription();
// replace tokens if available
if (isset($cmdExceptions[$name]['replaceTokens'])) {
$description = strtr(
$description,
$cmdExceptions[$name]['replaceTokens']
);
}
}
}
if ($parameter->isOptional()) {
$shortcut = null;
$default = $parameter->isDefaultValueAvailable()
? $parameter->getDefaultValue() : null;
// option
if ($default === null) {
$mode = InputOption::VALUE_NONE;
} else {
$mode = InputOption::VALUE_OPTIONAL;
}
if (isset($params[$pos])
&& strcasecmp($params[$pos]->getType(), 'array') === 0
) {
$mode = InputOption::VALUE_IS_ARRAY | $mode;
}
$definition->addOption(
new InputOption($name, $shortcut, $mode, $description, $default)
);
} else {
if (isset($cmdExceptions[$name]['default'])) {
$default = $cmdExceptions[$name]['default'];
$mode = InputArgument::OPTIONAL;
} else {
$default = null;
$mode = InputArgument::REQUIRED;
}
if (isset($params[$pos])
&& strcasecmp($params[$pos]->getType(), 'array') === 0
) {
$mode = InputArgument::IS_ARRAY | $mode;
}
// argument
$definition->addArgument(
new InputArgument($name, $mode, $description, $default)
);
}
}
return $definition;
} | [
"private",
"function",
"buildDefinition",
"(",
"$",
"namespace",
",",
"\\",
"ReflectionMethod",
"$",
"method",
",",
"$",
"params",
",",
"$",
"cmdExceptions",
")",
"{",
"$",
"definition",
"=",
"new",
"InputDefinition",
"(",
")",
";",
"foreach",
"(",
"$",
"m... | Builds the Input Definition based upon Api Method Parameters
@param string $namespace Command namespace
@param \ReflectionMethod $method Api Method
@param array $params Command arguments and options
@param array $cmdExceptions Command specific values
@return InputDefinition | [
"Builds",
"the",
"Input",
"Definition",
"based",
"upon",
"Api",
"Method",
"Parameters"
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Console/CommandFactory.php#L172-L231 |
llaville/php-reflect | src/Bartlett/Reflect/Console/CommandFactory.php | CommandFactory.createCode | private function createCode($namespace, \ReflectionMethod $method)
{
$app = $this->application;
return function (InputInterface $input, OutputInterface $output) use ($namespace, $method, $app) {
$methodName = $method->getName();
$client = new Client(Environment::getClient());
$api = $client->api(strtolower($namespace));
$api->setEventDispatcher($app->getDispatcher());
if (true === $input->hasParameterOption('--no-plugins')) {
// tells to Api, do not use any plugins
$api->activatePlugins(false);
}
if (true === $input->hasParameterOption('--progress')) {
$formats = array(
'very_verbose' => ' %current%/%max% %percent:3s%% %elapsed:6s% %message%',
'very_verbose_nomax' => ' %current% %elapsed:6s% %message%',
'debug' => ' %current%/%max% %percent:3s%% %elapsed:6s% %memory:6s% %message%',
'debug_nomax' => ' %current% %elapsed:6s% %memory:6s% %message%',
);
foreach ($formats as $name => $format) {
ProgressBar::setFormatDefinition($name, $format);
}
$progress = new ProgressBar($output);
$progress->setMessage('');
$api->getEventDispatcher()->addListener(
Events::PROGRESS,
function (GenericEvent $event) use ($progress) {
if ($progress instanceof ProgressBar) {
$progress->setMessage(
sprintf(
'File %s in progress...',
$event['file']->getRelativePathname()
)
);
$progress->advance();
}
}
);
}
$args = array();
foreach ($method->getParameters() as $parameter) {
if ($parameter->isOptional()) {
// option
$args[$parameter->getName()] = $input->getOption($parameter->getName());
} else {
// argument
$args[$parameter->getName()] = $input->getArgument($parameter->getName());
}
}
if (isset($progress) && $progress instanceof ProgressBar) {
$progress->start();
}
// calls the Api method
try {
$response = call_user_func_array(
array($api, $methodName),
$args
);
} catch (\Exception $e) {
$response = $e;
}
if (isset($progress) && $progress instanceof ProgressBar) {
$progress->finish();
$progress->clear();
}
$output->writeln('');
// prints response returned
$classParts = explode('\\', get_class($api));
$class = array_pop($classParts);
$outputFormatter = str_replace("\\Api\\$class", "\\Output\\$class", get_class($api));
// handle all Api exceptions when occured
if ($response instanceof \Exception) {
if (substr_count($response->getMessage(), "\n") > 0) {
// message on multiple lines
$fmt = new FormatterHelper;
$output->writeln(
$fmt->formatBlock(
explode("\n", $response->getMessage()),
'error'
)
);
} else {
// message on single line
$output->writeln('<error>' . $response->getMessage() . '</error>');
}
return;
}
if (!method_exists($outputFormatter, $methodName)
|| !is_callable(array($outputFormatter, $methodName))
|| $output->isDebug()
) {
$output->writeln('<debug>Raw response</debug>');
$output->writeln(print_r($response, true), OutputInterface::OUTPUT_RAW);
return;
}
$result = new $outputFormatter();
if ($input->hasParameterOption('--format')) {
return $output->write($response, OutputInterface::OUTPUT_RAW);
}
$result->$methodName($output, $response);
};
} | php | private function createCode($namespace, \ReflectionMethod $method)
{
$app = $this->application;
return function (InputInterface $input, OutputInterface $output) use ($namespace, $method, $app) {
$methodName = $method->getName();
$client = new Client(Environment::getClient());
$api = $client->api(strtolower($namespace));
$api->setEventDispatcher($app->getDispatcher());
if (true === $input->hasParameterOption('--no-plugins')) {
// tells to Api, do not use any plugins
$api->activatePlugins(false);
}
if (true === $input->hasParameterOption('--progress')) {
$formats = array(
'very_verbose' => ' %current%/%max% %percent:3s%% %elapsed:6s% %message%',
'very_verbose_nomax' => ' %current% %elapsed:6s% %message%',
'debug' => ' %current%/%max% %percent:3s%% %elapsed:6s% %memory:6s% %message%',
'debug_nomax' => ' %current% %elapsed:6s% %memory:6s% %message%',
);
foreach ($formats as $name => $format) {
ProgressBar::setFormatDefinition($name, $format);
}
$progress = new ProgressBar($output);
$progress->setMessage('');
$api->getEventDispatcher()->addListener(
Events::PROGRESS,
function (GenericEvent $event) use ($progress) {
if ($progress instanceof ProgressBar) {
$progress->setMessage(
sprintf(
'File %s in progress...',
$event['file']->getRelativePathname()
)
);
$progress->advance();
}
}
);
}
$args = array();
foreach ($method->getParameters() as $parameter) {
if ($parameter->isOptional()) {
// option
$args[$parameter->getName()] = $input->getOption($parameter->getName());
} else {
// argument
$args[$parameter->getName()] = $input->getArgument($parameter->getName());
}
}
if (isset($progress) && $progress instanceof ProgressBar) {
$progress->start();
}
// calls the Api method
try {
$response = call_user_func_array(
array($api, $methodName),
$args
);
} catch (\Exception $e) {
$response = $e;
}
if (isset($progress) && $progress instanceof ProgressBar) {
$progress->finish();
$progress->clear();
}
$output->writeln('');
// prints response returned
$classParts = explode('\\', get_class($api));
$class = array_pop($classParts);
$outputFormatter = str_replace("\\Api\\$class", "\\Output\\$class", get_class($api));
// handle all Api exceptions when occured
if ($response instanceof \Exception) {
if (substr_count($response->getMessage(), "\n") > 0) {
// message on multiple lines
$fmt = new FormatterHelper;
$output->writeln(
$fmt->formatBlock(
explode("\n", $response->getMessage()),
'error'
)
);
} else {
// message on single line
$output->writeln('<error>' . $response->getMessage() . '</error>');
}
return;
}
if (!method_exists($outputFormatter, $methodName)
|| !is_callable(array($outputFormatter, $methodName))
|| $output->isDebug()
) {
$output->writeln('<debug>Raw response</debug>');
$output->writeln(print_r($response, true), OutputInterface::OUTPUT_RAW);
return;
}
$result = new $outputFormatter();
if ($input->hasParameterOption('--format')) {
return $output->write($response, OutputInterface::OUTPUT_RAW);
}
$result->$methodName($output, $response);
};
} | [
"private",
"function",
"createCode",
"(",
"$",
"namespace",
",",
"\\",
"ReflectionMethod",
"$",
"method",
")",
"{",
"$",
"app",
"=",
"$",
"this",
"->",
"application",
";",
"return",
"function",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$"... | Creates the Command execution code
@param string $namespace Command namespace
@param \ReflectionMethod $method
@return \Closure | [
"Creates",
"the",
"Command",
"execution",
"code"
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Console/CommandFactory.php#L241-L357 |
llaville/php-reflect | src/Bartlett/Reflect/Analyser/StructureAnalyser.php | StructureAnalyser.visitMethod | protected function visitMethod(Node\Stmt\ClassMethod $method)
{
if ($this->testClass) {
if (strpos($method->name, 'test') === 0) {
$this->metrics['testMethods']++;
} elseif (strpos($method->getDocComment(), '@test')) {
$this->metrics['testMethods']++;
}
return;
}
$this->metrics['methods']++;
if ($method->isPrivate()) {
$this->metrics['privateMethods']++;
} elseif ($method->isProtected()) {
$this->metrics['protectedMethods']++;
} else {
$this->metrics['publicMethods']++;
}
if ($method->isStatic()) {
$this->metrics['staticMethods']++;
} else {
$this->metrics['nonStaticMethods']++;
}
} | php | protected function visitMethod(Node\Stmt\ClassMethod $method)
{
if ($this->testClass) {
if (strpos($method->name, 'test') === 0) {
$this->metrics['testMethods']++;
} elseif (strpos($method->getDocComment(), '@test')) {
$this->metrics['testMethods']++;
}
return;
}
$this->metrics['methods']++;
if ($method->isPrivate()) {
$this->metrics['privateMethods']++;
} elseif ($method->isProtected()) {
$this->metrics['protectedMethods']++;
} else {
$this->metrics['publicMethods']++;
}
if ($method->isStatic()) {
$this->metrics['staticMethods']++;
} else {
$this->metrics['nonStaticMethods']++;
}
} | [
"protected",
"function",
"visitMethod",
"(",
"Node",
"\\",
"Stmt",
"\\",
"ClassMethod",
"$",
"method",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"testClass",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"method",
"->",
"name",
",",
"'test'",
")",
"===",
"0... | Explore methods of each user classes
found in the current namespace.
@param Node\Stmt\ClassMethod $method The current method explored
@return void | [
"Explore",
"methods",
"of",
"each",
"user",
"classes",
"found",
"in",
"the",
"current",
"namespace",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Analyser/StructureAnalyser.php#L181-L206 |
llaville/php-reflect | src/Bartlett/Reflect/Analyser/StructureAnalyser.php | StructureAnalyser.visitFunction | protected function visitFunction(Node $function)
{
$this->metrics['functions']++;
if ($function instanceof Node\Expr\Closure) {
$this->metrics['anonymousFunctions']++;
} else {
$this->metrics['namedFunctions']++;
}
} | php | protected function visitFunction(Node $function)
{
$this->metrics['functions']++;
if ($function instanceof Node\Expr\Closure) {
$this->metrics['anonymousFunctions']++;
} else {
$this->metrics['namedFunctions']++;
}
} | [
"protected",
"function",
"visitFunction",
"(",
"Node",
"$",
"function",
")",
"{",
"$",
"this",
"->",
"metrics",
"[",
"'functions'",
"]",
"++",
";",
"if",
"(",
"$",
"function",
"instanceof",
"Node",
"\\",
"Expr",
"\\",
"Closure",
")",
"{",
"$",
"this",
... | Explore user functions found in the current namespace.
@param Node $function The current user function explored
@return void | [
"Explore",
"user",
"functions",
"found",
"in",
"the",
"current",
"namespace",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Analyser/StructureAnalyser.php#L215-L224 |
llaville/php-reflect | src/Bartlett/Reflect/Plugin/PluginManager.php | PluginManager.registerPlugins | public function registerPlugins()
{
$jsonFile = Environment::getJsonConfigFilename();
if (!$jsonFile) {
return;
}
$config = new Config;
$var = $config->validate($jsonFile);
foreach ($var['plugins'] as $plugin) {
if (class_exists($plugin['class'])) {
if (isset($plugin['options'])) {
$options = $plugin['options'];
if (is_string($options)) {
if (class_exists($options)) {
$options = new $options;
} else {
$options = null;
}
}
} else {
$options = null;
}
$plugin = new $plugin['class']($options);
if ($plugin instanceof PluginInterface) {
$this->addPlugin($plugin);
}
}
}
} | php | public function registerPlugins()
{
$jsonFile = Environment::getJsonConfigFilename();
if (!$jsonFile) {
return;
}
$config = new Config;
$var = $config->validate($jsonFile);
foreach ($var['plugins'] as $plugin) {
if (class_exists($plugin['class'])) {
if (isset($plugin['options'])) {
$options = $plugin['options'];
if (is_string($options)) {
if (class_exists($options)) {
$options = new $options;
} else {
$options = null;
}
}
} else {
$options = null;
}
$plugin = new $plugin['class']($options);
if ($plugin instanceof PluginInterface) {
$this->addPlugin($plugin);
}
}
}
} | [
"public",
"function",
"registerPlugins",
"(",
")",
"{",
"$",
"jsonFile",
"=",
"Environment",
"::",
"getJsonConfigFilename",
"(",
")",
";",
"if",
"(",
"!",
"$",
"jsonFile",
")",
"{",
"return",
";",
"}",
"$",
"config",
"=",
"new",
"Config",
";",
"$",
"va... | Loads all plugins declared in the JSON config file.
@return void | [
"Loads",
"all",
"plugins",
"declared",
"in",
"the",
"JSON",
"config",
"file",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Plugin/PluginManager.php#L55-L86 |
llaville/php-reflect | src/Bartlett/Reflect/Plugin/PluginManager.php | PluginManager.addPlugin | public function addPlugin(PluginInterface $plugin)
{
$this->plugins[] = $plugin;
$plugin->activate($this->eventDispatcher);
if ($plugin instanceof EventSubscriberInterface) {
$this->eventDispatcher->addSubscriber($plugin);
}
} | php | public function addPlugin(PluginInterface $plugin)
{
$this->plugins[] = $plugin;
$plugin->activate($this->eventDispatcher);
if ($plugin instanceof EventSubscriberInterface) {
$this->eventDispatcher->addSubscriber($plugin);
}
} | [
"public",
"function",
"addPlugin",
"(",
"PluginInterface",
"$",
"plugin",
")",
"{",
"$",
"this",
"->",
"plugins",
"[",
"]",
"=",
"$",
"plugin",
";",
"$",
"plugin",
"->",
"activate",
"(",
"$",
"this",
"->",
"eventDispatcher",
")",
";",
"if",
"(",
"$",
... | Adds a plugin, activates it and registers it with the event dispatcher
@param PluginInterface $plugin Plugin instance
@return void | [
"Adds",
"a",
"plugin",
"activates",
"it",
"and",
"registers",
"it",
"with",
"the",
"event",
"dispatcher"
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Plugin/PluginManager.php#L95-L104 |
llaville/php-reflect | src/Bartlett/Reflect/Console/Formatter/OutputFormatter.php | OutputFormatter.printFormattedLines | protected function printFormattedLines(OutputInterface $output, array $lines)
{
foreach ($lines as $ident => $contents) {
list ($format, $args) = $contents;
$output->writeln(vsprintf($format, $args));
}
} | php | protected function printFormattedLines(OutputInterface $output, array $lines)
{
foreach ($lines as $ident => $contents) {
list ($format, $args) = $contents;
$output->writeln(vsprintf($format, $args));
}
} | [
"protected",
"function",
"printFormattedLines",
"(",
"OutputInterface",
"$",
"output",
",",
"array",
"$",
"lines",
")",
"{",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"ident",
"=>",
"$",
"contents",
")",
"{",
"list",
"(",
"$",
"format",
",",
"$",
"args",
... | Helper that convert an array key-value pairs to a console report.
See Structure and Loc analysers for implementation examples
@param OutputInterface $output Console Output concrete instance
@param array $lines Any analyser formatted metrics
@return void | [
"Helper",
"that",
"convert",
"an",
"array",
"key",
"-",
"value",
"pairs",
"to",
"a",
"console",
"report",
"."
] | train | https://github.com/llaville/php-reflect/blob/6609c40a1695ce5bcbaa814214cf4e8d88e21569/src/Bartlett/Reflect/Console/Formatter/OutputFormatter.php#L62-L68 |
nezamy/route | system/App.php | App.autoload | public function autoload()
{
spl_autoload_register(function($className)
{
$className = str_replace("\\", DS, $className);
$classNameOnly = basename($className);
$namespace = substr($className, 0, -strlen($classNameOnly));
if (is_file($class = BASE_PATH . "{$className}.php")) {
return include_once($class);
} elseif (is_file($class = BASE_PATH . strtolower($namespace). $classNameOnly . '.php')) {
return include_once($class);
} elseif (is_file($class = BASE_PATH . strtolower($className).'.php')) {
return include_once($class);
} elseif (is_file($class = BASE_PATH . $namespace . lcfirst($classNameOnly) . '.php')) {
return include_once($class);
}elseif (is_file($class = BASE_PATH . strtolower($namespace) . lcfirst($classNameOnly) . '.php')) {
return include_once($class);
}
return false;
});
} | php | public function autoload()
{
spl_autoload_register(function($className)
{
$className = str_replace("\\", DS, $className);
$classNameOnly = basename($className);
$namespace = substr($className, 0, -strlen($classNameOnly));
if (is_file($class = BASE_PATH . "{$className}.php")) {
return include_once($class);
} elseif (is_file($class = BASE_PATH . strtolower($namespace). $classNameOnly . '.php')) {
return include_once($class);
} elseif (is_file($class = BASE_PATH . strtolower($className).'.php')) {
return include_once($class);
} elseif (is_file($class = BASE_PATH . $namespace . lcfirst($classNameOnly) . '.php')) {
return include_once($class);
}elseif (is_file($class = BASE_PATH . strtolower($namespace) . lcfirst($classNameOnly) . '.php')) {
return include_once($class);
}
return false;
});
} | [
"public",
"function",
"autoload",
"(",
")",
"{",
"spl_autoload_register",
"(",
"function",
"(",
"$",
"className",
")",
"{",
"$",
"className",
"=",
"str_replace",
"(",
"\"\\\\\"",
",",
"DS",
",",
"$",
"className",
")",
";",
"$",
"classNameOnly",
"=",
"basen... | Magic autoload. | [
"Magic",
"autoload",
"."
] | train | https://github.com/nezamy/route/blob/de0d5133530117b6999e6e0955138dc3bd3c66b5/system/App.php#L47-L67 |
nezamy/route | system/Request.php | Request.ip | public function ip()
{
if (isset($_SERVER["HTTP_CLIENT_IP"])) {
$ip = $_SERVER["HTTP_CLIENT_IP"];
} elseif (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
} elseif (isset($_SERVER["HTTP_X_FORWARDED"])) {
$ip = $_SERVER["HTTP_X_FORWARDED"];
} elseif (isset($_SERVER["HTTP_FORWARDED_FOR"])) {
$ip = $_SERVER["HTTP_FORWARDED_FOR"];
} elseif (isset($_SERVER["HTTP_FORWARDED"])) {
$ip = $_SERVER["HTTP_FORWARDED"];
} elseif (isset($_SERVER["REMOTE_ADDR"])) {
$ip = $_SERVER["REMOTE_ADDR"];
} else {
$ip = getenv("REMOTE_ADDR");
}
if(strpos($ip, ',') !== false){
$ip = explode(',', $ip)[0];
}
if (!filter_var($ip, FILTER_VALIDATE_IP)) {
return 'unknown';
}
return $ip;
} | php | public function ip()
{
if (isset($_SERVER["HTTP_CLIENT_IP"])) {
$ip = $_SERVER["HTTP_CLIENT_IP"];
} elseif (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
} elseif (isset($_SERVER["HTTP_X_FORWARDED"])) {
$ip = $_SERVER["HTTP_X_FORWARDED"];
} elseif (isset($_SERVER["HTTP_FORWARDED_FOR"])) {
$ip = $_SERVER["HTTP_FORWARDED_FOR"];
} elseif (isset($_SERVER["HTTP_FORWARDED"])) {
$ip = $_SERVER["HTTP_FORWARDED"];
} elseif (isset($_SERVER["REMOTE_ADDR"])) {
$ip = $_SERVER["REMOTE_ADDR"];
} else {
$ip = getenv("REMOTE_ADDR");
}
if(strpos($ip, ',') !== false){
$ip = explode(',', $ip)[0];
}
if (!filter_var($ip, FILTER_VALIDATE_IP)) {
return 'unknown';
}
return $ip;
} | [
"public",
"function",
"ip",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"\"HTTP_CLIENT_IP\"",
"]",
")",
")",
"{",
"$",
"ip",
"=",
"$",
"_SERVER",
"[",
"\"HTTP_CLIENT_IP\"",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"_SERVER",
... | Get user IP.
@return string | [
"Get",
"user",
"IP",
"."
] | train | https://github.com/nezamy/route/blob/de0d5133530117b6999e6e0955138dc3bd3c66b5/system/Request.php#L109-L136 |
nezamy/route | system/Request.php | Request.browser | public function browser()
{
if (strpos($this->server['HTTP_USER_AGENT'], 'Opera') || strpos($this->server['HTTP_USER_AGENT'], 'OPR/')) {
return 'Opera';
} elseif (strpos($this->server['HTTP_USER_AGENT'], 'Edge')) {
return 'Edge';
} elseif (strpos($this->server['HTTP_USER_AGENT'], 'Chrome')) {
return 'Chrome';
} elseif (strpos($this->server['HTTP_USER_AGENT'], 'Safari')) {
return 'Safari';
} elseif (strpos($this->server['HTTP_USER_AGENT'], 'Firefox')) {
return 'Firefox';
} elseif (strpos($this->server['HTTP_USER_AGENT'], 'MSIE') || strpos($this->server['HTTP_USER_AGENT'], 'Trident/7')) {
return 'Internet Explorer';
}
return 'unknown';
} | php | public function browser()
{
if (strpos($this->server['HTTP_USER_AGENT'], 'Opera') || strpos($this->server['HTTP_USER_AGENT'], 'OPR/')) {
return 'Opera';
} elseif (strpos($this->server['HTTP_USER_AGENT'], 'Edge')) {
return 'Edge';
} elseif (strpos($this->server['HTTP_USER_AGENT'], 'Chrome')) {
return 'Chrome';
} elseif (strpos($this->server['HTTP_USER_AGENT'], 'Safari')) {
return 'Safari';
} elseif (strpos($this->server['HTTP_USER_AGENT'], 'Firefox')) {
return 'Firefox';
} elseif (strpos($this->server['HTTP_USER_AGENT'], 'MSIE') || strpos($this->server['HTTP_USER_AGENT'], 'Trident/7')) {
return 'Internet Explorer';
}
return 'unknown';
} | [
"public",
"function",
"browser",
"(",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"this",
"->",
"server",
"[",
"'HTTP_USER_AGENT'",
"]",
",",
"'Opera'",
")",
"||",
"strpos",
"(",
"$",
"this",
"->",
"server",
"[",
"'HTTP_USER_AGENT'",
"]",
",",
"'OPR/'",
"... | Get user browser.
@return string | [
"Get",
"user",
"browser",
"."
] | train | https://github.com/nezamy/route/blob/de0d5133530117b6999e6e0955138dc3bd3c66b5/system/Request.php#L143-L159 |
nezamy/route | system/Request.php | Request.platform | public function platform()
{
if (preg_match('/linux/i', $this->server['HTTP_USER_AGENT'])) {
return 'linux';
} elseif (preg_match('/macintosh|mac os x/i', $this->server['HTTP_USER_AGENT'])) {
return 'mac';
} elseif (preg_match('/windows|win32/i', $this->server['HTTP_USER_AGENT'])) {
return 'windows';
}
return 'unknown';
} | php | public function platform()
{
if (preg_match('/linux/i', $this->server['HTTP_USER_AGENT'])) {
return 'linux';
} elseif (preg_match('/macintosh|mac os x/i', $this->server['HTTP_USER_AGENT'])) {
return 'mac';
} elseif (preg_match('/windows|win32/i', $this->server['HTTP_USER_AGENT'])) {
return 'windows';
}
return 'unknown';
} | [
"public",
"function",
"platform",
"(",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/linux/i'",
",",
"$",
"this",
"->",
"server",
"[",
"'HTTP_USER_AGENT'",
"]",
")",
")",
"{",
"return",
"'linux'",
";",
"}",
"elseif",
"(",
"preg_match",
"(",
"'/macintosh|mac o... | Get user platform.
@return string | [
"Get",
"user",
"platform",
"."
] | train | https://github.com/nezamy/route/blob/de0d5133530117b6999e6e0955138dc3bd3c66b5/system/Request.php#L166-L176 |
nezamy/route | system/Request.php | Request.isMobile | public function isMobile()
{
$aMobileUA = array(
'/iphone/i' => 'iPhone',
'/ipod/i' => 'iPod',
'/ipad/i' => 'iPad',
'/android/i' => 'Android',
'/blackberry/i' => 'BlackBerry',
'/webos/i' => 'Mobile'
);
// Return true if mobile User Agent is detected.
foreach ($aMobileUA as $sMobileKey => $sMobileOS) {
if (preg_match($sMobileKey, $_SERVER['HTTP_USER_AGENT'])) {
return true;
}
}
// Otherwise, return false.
return false;
} | php | public function isMobile()
{
$aMobileUA = array(
'/iphone/i' => 'iPhone',
'/ipod/i' => 'iPod',
'/ipad/i' => 'iPad',
'/android/i' => 'Android',
'/blackberry/i' => 'BlackBerry',
'/webos/i' => 'Mobile'
);
// Return true if mobile User Agent is detected.
foreach ($aMobileUA as $sMobileKey => $sMobileOS) {
if (preg_match($sMobileKey, $_SERVER['HTTP_USER_AGENT'])) {
return true;
}
}
// Otherwise, return false.
return false;
} | [
"public",
"function",
"isMobile",
"(",
")",
"{",
"$",
"aMobileUA",
"=",
"array",
"(",
"'/iphone/i'",
"=>",
"'iPhone'",
",",
"'/ipod/i'",
"=>",
"'iPod'",
",",
"'/ipad/i'",
"=>",
"'iPad'",
",",
"'/android/i'",
"=>",
"'Android'",
",",
"'/blackberry/i'",
"=>",
"... | Check whether user has connected from a mobile device (tablet, etc).
@return bool | [
"Check",
"whether",
"user",
"has",
"connected",
"from",
"a",
"mobile",
"device",
"(",
"tablet",
"etc",
")",
"."
] | train | https://github.com/nezamy/route/blob/de0d5133530117b6999e6e0955138dc3bd3c66b5/system/Request.php#L183-L202 |
nezamy/route | system/Route.php | Route.route | public function route(array $method, $uri, $callback, $options = [])
{
if (is_array($uri)) {
foreach ($uri as $u) {
$this->route($method, $u, $callback, $options);
}
return $this;
}
$options = array_merge(['ajaxOnly' => false, 'continue' => false], (array)$options);
if ($uri != '/') {
$uri = $this->removeDuplSlash($uri) . '/';
}
// Replace named uri param to regex pattern.
$pattern = $this->namedParameters($uri);
$this->currentUri = $pattern;
if ($options['ajaxOnly'] == false || $options['ajaxOnly'] && $this->req->ajax) {
// If matched before, skip this.
if ($this->matched === false) {
// Prepare.
$pattern = $this->prepare(
str_replace(['/?', '/*'], [$this->pattern['/?'], $this->pattern['/*']], $this->removeDuplSlash($this->group . $pattern))
);
// If matched.
$method = count($method) > 0 ? in_array($this->req->method, $method) : true;
if ($method && $this->matched($pattern)) {
if ($this->isGroup) {
$this->prams = array_merge($this->pramsGroup, $this->prams);
}
$this->req->args = $this->bindArgs($this->prams, $this->matchedArgs);
$this->matchedPath = $this->currentUri;
$this->routeCallback[] = $callback;
if ($options['continue']) {
$this->matched = false;
}
}
}
}
$this->_as($this->removeParameters($this->trimSlash($uri)));
return $this;
} | php | public function route(array $method, $uri, $callback, $options = [])
{
if (is_array($uri)) {
foreach ($uri as $u) {
$this->route($method, $u, $callback, $options);
}
return $this;
}
$options = array_merge(['ajaxOnly' => false, 'continue' => false], (array)$options);
if ($uri != '/') {
$uri = $this->removeDuplSlash($uri) . '/';
}
// Replace named uri param to regex pattern.
$pattern = $this->namedParameters($uri);
$this->currentUri = $pattern;
if ($options['ajaxOnly'] == false || $options['ajaxOnly'] && $this->req->ajax) {
// If matched before, skip this.
if ($this->matched === false) {
// Prepare.
$pattern = $this->prepare(
str_replace(['/?', '/*'], [$this->pattern['/?'], $this->pattern['/*']], $this->removeDuplSlash($this->group . $pattern))
);
// If matched.
$method = count($method) > 0 ? in_array($this->req->method, $method) : true;
if ($method && $this->matched($pattern)) {
if ($this->isGroup) {
$this->prams = array_merge($this->pramsGroup, $this->prams);
}
$this->req->args = $this->bindArgs($this->prams, $this->matchedArgs);
$this->matchedPath = $this->currentUri;
$this->routeCallback[] = $callback;
if ($options['continue']) {
$this->matched = false;
}
}
}
}
$this->_as($this->removeParameters($this->trimSlash($uri)));
return $this;
} | [
"public",
"function",
"route",
"(",
"array",
"$",
"method",
",",
"$",
"uri",
",",
"$",
"callback",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"uri",
")",
")",
"{",
"foreach",
"(",
"$",
"uri",
"as",
"$",
"u",
... | Register a route with callback.
@param array $method
@param string|array $uri
@param callable $callback
@param array $options
@return $this | [
"Register",
"a",
"route",
"with",
"callback",
"."
] | train | https://github.com/nezamy/route/blob/de0d5133530117b6999e6e0955138dc3bd3c66b5/system/Route.php#L99-L145 |
nezamy/route | system/Route.php | Route.group | public function group($group, callable $callback, array $options = [])
{
$options = array_merge([
'as' => $group,
'namespace' => $group
], $options);
if (is_array($group)) {
foreach ($group as $k => $p) {
$this->group($p, $callback, [
'as' => $options['as'][$k],
'namespace' => $options['namespace'][$k]
]);
}
return $this;
}
$this->setGroupAs($options['as']);
$group = $this->removeDuplSlash($group . '/');
$group = $this->namedParameters($group, true);
$this->matched($this->prepare($group, false), false);
$this->currentGroup = $group;
// Add this group and sub-groups to append to route uri.
$this->group .= $group;
// Bind to Route Class.
// $callback = $callback->bindTo($this);
$callback = Closure::bind($callback, $this, get_class());
// Call with args.
call_user_func_array($callback, $this->bindArgs($this->pramsGroup, $this->matchedArgs));
$this->isGroup = false;
$this->pramsGroup = $this->pattGroup = [];
$this->group = substr($this->group, 0, -strlen($group));
$this->setGroupAs(substr($this->getGroupAs(), 0, -(strlen($options['as']) + 2)), true);
return $this;
} | php | public function group($group, callable $callback, array $options = [])
{
$options = array_merge([
'as' => $group,
'namespace' => $group
], $options);
if (is_array($group)) {
foreach ($group as $k => $p) {
$this->group($p, $callback, [
'as' => $options['as'][$k],
'namespace' => $options['namespace'][$k]
]);
}
return $this;
}
$this->setGroupAs($options['as']);
$group = $this->removeDuplSlash($group . '/');
$group = $this->namedParameters($group, true);
$this->matched($this->prepare($group, false), false);
$this->currentGroup = $group;
// Add this group and sub-groups to append to route uri.
$this->group .= $group;
// Bind to Route Class.
// $callback = $callback->bindTo($this);
$callback = Closure::bind($callback, $this, get_class());
// Call with args.
call_user_func_array($callback, $this->bindArgs($this->pramsGroup, $this->matchedArgs));
$this->isGroup = false;
$this->pramsGroup = $this->pattGroup = [];
$this->group = substr($this->group, 0, -strlen($group));
$this->setGroupAs(substr($this->getGroupAs(), 0, -(strlen($options['as']) + 2)), true);
return $this;
} | [
"public",
"function",
"group",
"(",
"$",
"group",
",",
"callable",
"$",
"callback",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"=",
"array_merge",
"(",
"[",
"'as'",
"=>",
"$",
"group",
",",
"'namespace'",
"=>",
"$",
"group... | Group of routes.
@param string|array $group
@param callable $callback
@param array $options
@return $this | [
"Group",
"of",
"routes",
"."
] | train | https://github.com/nezamy/route/blob/de0d5133530117b6999e6e0955138dc3bd3c66b5/system/Route.php#L156-L193 |
nezamy/route | system/Route.php | Route.bindArgs | protected function bindArgs(array $pram, array $args)
{
if (count($pram) == count($args)) {
$newArgs = array_combine($pram, $args);
} else {
$newArgs = [];
foreach ($pram as $p) {
$newArgs[$p] = array_shift($args);
}
if (isset($args[0]) && count($args) == 1) {
foreach (explode('/', '/' . $args[0]) as $arg) {
$newArgs[] = $arg;
}
$this->fullArg = $newArgs[0] = $args[0];
}
// pre($args);
if (count($args)) {
$newArgs = array_merge($newArgs, $args);
}
}
return $newArgs;
} | php | protected function bindArgs(array $pram, array $args)
{
if (count($pram) == count($args)) {
$newArgs = array_combine($pram, $args);
} else {
$newArgs = [];
foreach ($pram as $p) {
$newArgs[$p] = array_shift($args);
}
if (isset($args[0]) && count($args) == 1) {
foreach (explode('/', '/' . $args[0]) as $arg) {
$newArgs[] = $arg;
}
$this->fullArg = $newArgs[0] = $args[0];
}
// pre($args);
if (count($args)) {
$newArgs = array_merge($newArgs, $args);
}
}
return $newArgs;
} | [
"protected",
"function",
"bindArgs",
"(",
"array",
"$",
"pram",
",",
"array",
"$",
"args",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"pram",
")",
"==",
"count",
"(",
"$",
"args",
")",
")",
"{",
"$",
"newArgs",
"=",
"array_combine",
"(",
"$",
"pram",
... | Bind args and parameters.
@param array $pram
@param array $args
@return array | [
"Bind",
"args",
"and",
"parameters",
"."
] | train | https://github.com/nezamy/route/blob/de0d5133530117b6999e6e0955138dc3bd3c66b5/system/Route.php#L282-L304 |
nezamy/route | system/Route.php | Route.namedParameters | protected function namedParameters($uri, $isGroup = false)
{
// Reset pattern and parameters to empty array.
$this->patt = [];
$this->prams = [];
// Replace named parameters to regex pattern.
return preg_replace_callback('/\/\{([a-z-0-9]+)\}\??(:\(?[^\/]+\)?)?/i', function ($m) use ($isGroup) {
// Check whether validation has been set and whether it exists.
if (isset($m[2])) {
$rep = substr($m[2], 1);
$patt = isset($this->pattern[$rep]) ? $this->pattern[$rep] : '/' . $rep;
} else {
$patt = $this->pattern['/?'];
}
// Check whether parameter is optional.
if (strpos($m[0], '?') !== false) {
$patt = str_replace('/(', '(/', $patt) . '?';
}
if ($isGroup) {
$this->isGroup = true;
$this->pramsGroup[] = $m[1];
$this->pattGroup[] = $patt;
} else {
$this->prams[] = $m[1];
$this->patt[] = $patt;
}
return $patt;
}, trim($uri));
} | php | protected function namedParameters($uri, $isGroup = false)
{
// Reset pattern and parameters to empty array.
$this->patt = [];
$this->prams = [];
// Replace named parameters to regex pattern.
return preg_replace_callback('/\/\{([a-z-0-9]+)\}\??(:\(?[^\/]+\)?)?/i', function ($m) use ($isGroup) {
// Check whether validation has been set and whether it exists.
if (isset($m[2])) {
$rep = substr($m[2], 1);
$patt = isset($this->pattern[$rep]) ? $this->pattern[$rep] : '/' . $rep;
} else {
$patt = $this->pattern['/?'];
}
// Check whether parameter is optional.
if (strpos($m[0], '?') !== false) {
$patt = str_replace('/(', '(/', $patt) . '?';
}
if ($isGroup) {
$this->isGroup = true;
$this->pramsGroup[] = $m[1];
$this->pattGroup[] = $patt;
} else {
$this->prams[] = $m[1];
$this->patt[] = $patt;
}
return $patt;
}, trim($uri));
} | [
"protected",
"function",
"namedParameters",
"(",
"$",
"uri",
",",
"$",
"isGroup",
"=",
"false",
")",
"{",
"// Reset pattern and parameters to empty array.\r",
"$",
"this",
"->",
"patt",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"prams",
"=",
"[",
"]",
";",
"/... | Register a parameter name with validation from route uri.
@param string $uri
@param bool $isGroup
@return mixed | [
"Register",
"a",
"parameter",
"name",
"with",
"validation",
"from",
"route",
"uri",
"."
] | train | https://github.com/nezamy/route/blob/de0d5133530117b6999e6e0955138dc3bd3c66b5/system/Route.php#L314-L345 |
nezamy/route | system/Route.php | Route.prepare | protected function prepare($patt, $strict = true)
{
// Fix group if it has an optional path on start
if (substr($patt, 0, 3) == '/(/') {
$patt = substr($patt, 1);
}
return '~^' . $patt . ($strict ? '$' : '') . '~i';
} | php | protected function prepare($patt, $strict = true)
{
// Fix group if it has an optional path on start
if (substr($patt, 0, 3) == '/(/') {
$patt = substr($patt, 1);
}
return '~^' . $patt . ($strict ? '$' : '') . '~i';
} | [
"protected",
"function",
"prepare",
"(",
"$",
"patt",
",",
"$",
"strict",
"=",
"true",
")",
"{",
"// Fix group if it has an optional path on start\r",
"if",
"(",
"substr",
"(",
"$",
"patt",
",",
"0",
",",
"3",
")",
"==",
"'/(/'",
")",
"{",
"$",
"patt",
"... | Prepare a regex pattern.
@param string $patt
@param bool $strict
@return string | [
"Prepare",
"a",
"regex",
"pattern",
"."
] | train | https://github.com/nezamy/route/blob/de0d5133530117b6999e6e0955138dc3bd3c66b5/system/Route.php#L355-L363 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.