repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
liip/DataAggregator | src/Liip/DataAggregator/DataAggregatorBatch.php | DataAggregatorBatch.setLimit | public function setLimit($limit)
{
$message = 'Given limit must be a positive number.';
Assertion::numeric($limit, $message);
Assertion::min($limit, 0, $message);
$this->limit = $limit;
} | php | public function setLimit($limit)
{
$message = 'Given limit must be a positive number.';
Assertion::numeric($limit, $message);
Assertion::min($limit, 0, $message);
$this->limit = $limit;
} | [
"public",
"function",
"setLimit",
"(",
"$",
"limit",
")",
"{",
"$",
"message",
"=",
"'Given limit must be a positive number.'",
";",
"Assertion",
"::",
"numeric",
"(",
"$",
"limit",
",",
"$",
"message",
")",
";",
"Assertion",
"::",
"min",
"(",
"$",
"limit",
",",
"0",
",",
"$",
"message",
")",
";",
"$",
"this",
"->",
"limit",
"=",
"$",
"limit",
";",
"}"
] | Defines the amount of entities to be fetched from the information provider.
@param integer $limit Positive integer defining the amount of records to be return in max. Zero (0) defines an unlimited amount.
@throws \Assert\InvalidArgumentException in case the provided argument does not meet expectations. | [
"Defines",
"the",
"amount",
"of",
"entities",
"to",
"be",
"fetched",
"from",
"the",
"information",
"provider",
"."
] | 53da08ed3f5f24597be9f40ecf8ec44da7765e47 | https://github.com/liip/DataAggregator/blob/53da08ed3f5f24597be9f40ecf8ec44da7765e47/src/Liip/DataAggregator/DataAggregatorBatch.php#L101-L108 | train |
liip/DataAggregator | src/Liip/DataAggregator/DataAggregatorBatch.php | DataAggregatorBatch.persist | protected function persist(array $data)
{
Assertion::notEmpty(
$this->persistors,
'No persistor attached.',
DataAggregatorException::NO_PERSISTOR_ATTACHED
);
foreach ($this->persistors as $persistor) {
try {
$persistor->persist($data);
} catch (PersistorException $e) {
$this->getLogger()->error($e->getMessage());
}
}
} | php | protected function persist(array $data)
{
Assertion::notEmpty(
$this->persistors,
'No persistor attached.',
DataAggregatorException::NO_PERSISTOR_ATTACHED
);
foreach ($this->persistors as $persistor) {
try {
$persistor->persist($data);
} catch (PersistorException $e) {
$this->getLogger()->error($e->getMessage());
}
}
} | [
"protected",
"function",
"persist",
"(",
"array",
"$",
"data",
")",
"{",
"Assertion",
"::",
"notEmpty",
"(",
"$",
"this",
"->",
"persistors",
",",
"'No persistor attached.'",
",",
"DataAggregatorException",
"::",
"NO_PERSISTOR_ATTACHED",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"persistors",
"as",
"$",
"persistor",
")",
"{",
"try",
"{",
"$",
"persistor",
"->",
"persist",
"(",
"$",
"data",
")",
";",
"}",
"catch",
"(",
"PersistorException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"error",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"}"
] | Forwards the gathered data to every registered output handler.
@param array $data
@throws InvalidArgumentException in case no persistor has been attached. | [
"Forwards",
"the",
"gathered",
"data",
"to",
"every",
"registered",
"output",
"handler",
"."
] | 53da08ed3f5f24597be9f40ecf8ec44da7765e47 | https://github.com/liip/DataAggregator/blob/53da08ed3f5f24597be9f40ecf8ec44da7765e47/src/Liip/DataAggregator/DataAggregatorBatch.php#L127-L143 | train |
liip/DataAggregator | src/Liip/DataAggregator/DataAggregatorBatch.php | DataAggregatorBatch.attachLoader | public function attachLoader(LoaderInterface $loader, $key = '')
{
if (empty($key)) {
$this->loaders[] = $loader;
} else {
$this->loaders[$key] = $loader;
}
} | php | public function attachLoader(LoaderInterface $loader, $key = '')
{
if (empty($key)) {
$this->loaders[] = $loader;
} else {
$this->loaders[$key] = $loader;
}
} | [
"public",
"function",
"attachLoader",
"(",
"LoaderInterface",
"$",
"loader",
",",
"$",
"key",
"=",
"''",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"key",
")",
")",
"{",
"$",
"this",
"->",
"loaders",
"[",
"]",
"=",
"$",
"loader",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"loaders",
"[",
"$",
"key",
"]",
"=",
"$",
"loader",
";",
"}",
"}"
] | Adds given loader to registry.
@param LoaderInterface $loader
@param string $key | [
"Adds",
"given",
"loader",
"to",
"registry",
"."
] | 53da08ed3f5f24597be9f40ecf8ec44da7765e47 | https://github.com/liip/DataAggregator/blob/53da08ed3f5f24597be9f40ecf8ec44da7765e47/src/Liip/DataAggregator/DataAggregatorBatch.php#L151-L158 | train |
liip/DataAggregator | src/Liip/DataAggregator/DataAggregatorBatch.php | DataAggregatorBatch.attachPersistor | public function attachPersistor(PersistorInterface $persistor, $key = '')
{
if (empty($key)) {
$this->persistors[] = $persistor;
} else {
$this->persistors[$key] = $persistor;
}
} | php | public function attachPersistor(PersistorInterface $persistor, $key = '')
{
if (empty($key)) {
$this->persistors[] = $persistor;
} else {
$this->persistors[$key] = $persistor;
}
} | [
"public",
"function",
"attachPersistor",
"(",
"PersistorInterface",
"$",
"persistor",
",",
"$",
"key",
"=",
"''",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"key",
")",
")",
"{",
"$",
"this",
"->",
"persistors",
"[",
"]",
"=",
"$",
"persistor",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"persistors",
"[",
"$",
"key",
"]",
"=",
"$",
"persistor",
";",
"}",
"}"
] | Adds the given persistor to the collection of output handlers
@param PersistorInterface $persistor
@param string $key | [
"Adds",
"the",
"given",
"persistor",
"to",
"the",
"collection",
"of",
"output",
"handlers"
] | 53da08ed3f5f24597be9f40ecf8ec44da7765e47 | https://github.com/liip/DataAggregator/blob/53da08ed3f5f24597be9f40ecf8ec44da7765e47/src/Liip/DataAggregator/DataAggregatorBatch.php#L185-L192 | train |
AlexyaFramework/FileSystem | Alexya/FileSystem/File.php | File.make | public static function make(string $path, int $ifExists = File::MAKE_FILE_EXISTS_THROW_EXCEPTION) : File
{
$exists = File::exists($path);
if($exists) {
if($ifExists === File::MAKE_FILE_EXISTS_OVERWRITE) {
unlink($path);
} else if($ifExists === File::MAKE_FILE_EXISTS_OPEN) {
return new File($path);
} else {
throw new FileAlreadyExists($path);
}
}
if(!fopen($path, "c")) {
throw new CouldntCreateFile($path);
}
return new File($path);
} | php | public static function make(string $path, int $ifExists = File::MAKE_FILE_EXISTS_THROW_EXCEPTION) : File
{
$exists = File::exists($path);
if($exists) {
if($ifExists === File::MAKE_FILE_EXISTS_OVERWRITE) {
unlink($path);
} else if($ifExists === File::MAKE_FILE_EXISTS_OPEN) {
return new File($path);
} else {
throw new FileAlreadyExists($path);
}
}
if(!fopen($path, "c")) {
throw new CouldntCreateFile($path);
}
return new File($path);
} | [
"public",
"static",
"function",
"make",
"(",
"string",
"$",
"path",
",",
"int",
"$",
"ifExists",
"=",
"File",
"::",
"MAKE_FILE_EXISTS_THROW_EXCEPTION",
")",
":",
"File",
"{",
"$",
"exists",
"=",
"File",
"::",
"exists",
"(",
"$",
"path",
")",
";",
"if",
"(",
"$",
"exists",
")",
"{",
"if",
"(",
"$",
"ifExists",
"===",
"File",
"::",
"MAKE_FILE_EXISTS_OVERWRITE",
")",
"{",
"unlink",
"(",
"$",
"path",
")",
";",
"}",
"else",
"if",
"(",
"$",
"ifExists",
"===",
"File",
"::",
"MAKE_FILE_EXISTS_OPEN",
")",
"{",
"return",
"new",
"File",
"(",
"$",
"path",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"FileAlreadyExists",
"(",
"$",
"path",
")",
";",
"}",
"}",
"if",
"(",
"!",
"fopen",
"(",
"$",
"path",
",",
"\"c\"",
")",
")",
"{",
"throw",
"new",
"CouldntCreateFile",
"(",
"$",
"path",
")",
";",
"}",
"return",
"new",
"File",
"(",
"$",
"path",
")",
";",
"}"
] | Makes a file.
The second parameter specifies what to do in case file already exists:
* `\Alexya\FileSystem\File::MAKE_FILE_EXISTS_THROW_EXCEPTION`, throws an exception (default).
* `\Alexya\FileSystem\File::MAKE_FILE_EXISTS_OVERWRITE`, deletes the file and recreates it.
* `\Alexya\FileSystem\File::MAKE_FILE_EXISTS_OPEN`, opens the file.
@param string $path Path to the file.
@param int $ifExists What to do if file exists.
@return File File object.
@throws FileAlreadyExists If $path already exists as a file.
@throws CouldntCreateFile If the file can't be created. | [
"Makes",
"a",
"file",
"."
] | 1f2a848c4bd508c0ce0e14f49e231522cc059424 | https://github.com/AlexyaFramework/FileSystem/blob/1f2a848c4bd508c0ce0e14f49e231522cc059424/Alexya/FileSystem/File.php#L81-L100 | train |
AlexyaFramework/FileSystem | Alexya/FileSystem/File.php | File.write | public function write(string $str)
{
$handler = fopen($this->_path, "w");
fwrite($handler, $str);
fclose($handler);
} | php | public function write(string $str)
{
$handler = fopen($this->_path, "w");
fwrite($handler, $str);
fclose($handler);
} | [
"public",
"function",
"write",
"(",
"string",
"$",
"str",
")",
"{",
"$",
"handler",
"=",
"fopen",
"(",
"$",
"this",
"->",
"_path",
",",
"\"w\"",
")",
";",
"fwrite",
"(",
"$",
"handler",
",",
"$",
"str",
")",
";",
"fclose",
"(",
"$",
"handler",
")",
";",
"}"
] | Writes a string to the file.
@param string $str String to write. | [
"Writes",
"a",
"string",
"to",
"the",
"file",
"."
] | 1f2a848c4bd508c0ce0e14f49e231522cc059424 | https://github.com/AlexyaFramework/FileSystem/blob/1f2a848c4bd508c0ce0e14f49e231522cc059424/Alexya/FileSystem/File.php#L235-L240 | train |
AlexyaFramework/FileSystem | Alexya/FileSystem/File.php | File.read | public function read(int $length = 1, int $offset = 0) : string
{
return substr($this->getContent(), $offset, $length);
} | php | public function read(int $length = 1, int $offset = 0) : string
{
return substr($this->getContent(), $offset, $length);
} | [
"public",
"function",
"read",
"(",
"int",
"$",
"length",
"=",
"1",
",",
"int",
"$",
"offset",
"=",
"0",
")",
":",
"string",
"{",
"return",
"substr",
"(",
"$",
"this",
"->",
"getContent",
"(",
")",
",",
"$",
"offset",
",",
"$",
"length",
")",
";",
"}"
] | Returns a string of specified length from file.
@param int $length Length to read.
@param int $offset Length to skip before reading.
@return string String from file of given length. | [
"Returns",
"a",
"string",
"of",
"specified",
"length",
"from",
"file",
"."
] | 1f2a848c4bd508c0ce0e14f49e231522cc059424 | https://github.com/AlexyaFramework/FileSystem/blob/1f2a848c4bd508c0ce0e14f49e231522cc059424/Alexya/FileSystem/File.php#L272-L275 | train |
AlexyaFramework/FileSystem | Alexya/FileSystem/File.php | File.readLine | public function readLine(int $line = 1) : string
{
$lines = file($this->_path);
if($line > count($lines)) {
throw new LineNumberAboveFileLines($this->_path, $line, count($lines));
}
if($line <= 0) {
$line = 1;
}
return $lines[($line - 1)];
} | php | public function readLine(int $line = 1) : string
{
$lines = file($this->_path);
if($line > count($lines)) {
throw new LineNumberAboveFileLines($this->_path, $line, count($lines));
}
if($line <= 0) {
$line = 1;
}
return $lines[($line - 1)];
} | [
"public",
"function",
"readLine",
"(",
"int",
"$",
"line",
"=",
"1",
")",
":",
"string",
"{",
"$",
"lines",
"=",
"file",
"(",
"$",
"this",
"->",
"_path",
")",
";",
"if",
"(",
"$",
"line",
">",
"count",
"(",
"$",
"lines",
")",
")",
"{",
"throw",
"new",
"LineNumberAboveFileLines",
"(",
"$",
"this",
"->",
"_path",
",",
"$",
"line",
",",
"count",
"(",
"$",
"lines",
")",
")",
";",
"}",
"if",
"(",
"$",
"line",
"<=",
"0",
")",
"{",
"$",
"line",
"=",
"1",
";",
"}",
"return",
"$",
"lines",
"[",
"(",
"$",
"line",
"-",
"1",
")",
"]",
";",
"}"
] | Returns a single line from file.
@param int $line Line number.
@return string Line as string.
@throws LineNumberAboveFileLines If the line number is bigger than the total number of lines | [
"Returns",
"a",
"single",
"line",
"from",
"file",
"."
] | 1f2a848c4bd508c0ce0e14f49e231522cc059424 | https://github.com/AlexyaFramework/FileSystem/blob/1f2a848c4bd508c0ce0e14f49e231522cc059424/Alexya/FileSystem/File.php#L299-L312 | train |
AlexyaFramework/FileSystem | Alexya/FileSystem/File.php | File.setExtension | public function setExtension(string $extension)
{
$old = $this->getPath();
$new = $this->getLocation().DIRECTORY_SEPARATOR.$this->getName();
if(!empty($extension)) {
$new .= ".{$extension}";
}
if(rename($old, $new)) {
$this->_extension = $extension;
}
} | php | public function setExtension(string $extension)
{
$old = $this->getPath();
$new = $this->getLocation().DIRECTORY_SEPARATOR.$this->getName();
if(!empty($extension)) {
$new .= ".{$extension}";
}
if(rename($old, $new)) {
$this->_extension = $extension;
}
} | [
"public",
"function",
"setExtension",
"(",
"string",
"$",
"extension",
")",
"{",
"$",
"old",
"=",
"$",
"this",
"->",
"getPath",
"(",
")",
";",
"$",
"new",
"=",
"$",
"this",
"->",
"getLocation",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"this",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"extension",
")",
")",
"{",
"$",
"new",
".=",
"\".{$extension}\"",
";",
"}",
"if",
"(",
"rename",
"(",
"$",
"old",
",",
"$",
"new",
")",
")",
"{",
"$",
"this",
"->",
"_extension",
"=",
"$",
"extension",
";",
"}",
"}"
] | Renames file extension.
@param string $extension New file extension. | [
"Renames",
"file",
"extension",
"."
] | 1f2a848c4bd508c0ce0e14f49e231522cc059424 | https://github.com/AlexyaFramework/FileSystem/blob/1f2a848c4bd508c0ce0e14f49e231522cc059424/Alexya/FileSystem/File.php#L380-L392 | train |
shadowfax/zf2-asset-manager | src/AssetManager/Mvc/AssetRouteListener.php | AssetRouteListener.onPreRoute | public function onPreRoute(MvcEvent $event)
{
// Get the router object
$serviceManager = $event->getApplication()->getServiceManager();
$router = $event->getRouter();
// Load the route configuration
$config = $serviceManager->get('Config');
$config = isset($config['asset_manager']) && (is_array($config['asset_manager']) || $config['asset_manager'] instanceof ArrayAccess)
? $config['asset_manager']
: array();
$config = isset($config['routes']) && (is_array($config['routes']) || $config['routes'] instanceof ArrayAccess)
? $config['routes']
: array();
// There can be special routes defined:
// /css
// /js
// ...
// This way the asset manager can be hidden
if (!empty($config)) {
// Rename all routes so I get an easy base route
// name called 'asset_manager'
$keys = array_keys($config);
array_walk($keys, function($n) {
$n = 'asset_manager/' . $n;
});
$config = array_combine($keys, array_values($config));
// Add the routes
$router->addRoutes($config);
} else {
// No routes have been configured!
// So I need to create my own
$router->addRoute(
'asset_manager',
array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/assets',
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Wildcard'
)
)
)
);
}
} | php | public function onPreRoute(MvcEvent $event)
{
// Get the router object
$serviceManager = $event->getApplication()->getServiceManager();
$router = $event->getRouter();
// Load the route configuration
$config = $serviceManager->get('Config');
$config = isset($config['asset_manager']) && (is_array($config['asset_manager']) || $config['asset_manager'] instanceof ArrayAccess)
? $config['asset_manager']
: array();
$config = isset($config['routes']) && (is_array($config['routes']) || $config['routes'] instanceof ArrayAccess)
? $config['routes']
: array();
// There can be special routes defined:
// /css
// /js
// ...
// This way the asset manager can be hidden
if (!empty($config)) {
// Rename all routes so I get an easy base route
// name called 'asset_manager'
$keys = array_keys($config);
array_walk($keys, function($n) {
$n = 'asset_manager/' . $n;
});
$config = array_combine($keys, array_values($config));
// Add the routes
$router->addRoutes($config);
} else {
// No routes have been configured!
// So I need to create my own
$router->addRoute(
'asset_manager',
array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/assets',
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Wildcard'
)
)
)
);
}
} | [
"public",
"function",
"onPreRoute",
"(",
"MvcEvent",
"$",
"event",
")",
"{",
"// Get the router object",
"$",
"serviceManager",
"=",
"$",
"event",
"->",
"getApplication",
"(",
")",
"->",
"getServiceManager",
"(",
")",
";",
"$",
"router",
"=",
"$",
"event",
"->",
"getRouter",
"(",
")",
";",
"// Load the route configuration",
"$",
"config",
"=",
"$",
"serviceManager",
"->",
"get",
"(",
"'Config'",
")",
";",
"$",
"config",
"=",
"isset",
"(",
"$",
"config",
"[",
"'asset_manager'",
"]",
")",
"&&",
"(",
"is_array",
"(",
"$",
"config",
"[",
"'asset_manager'",
"]",
")",
"||",
"$",
"config",
"[",
"'asset_manager'",
"]",
"instanceof",
"ArrayAccess",
")",
"?",
"$",
"config",
"[",
"'asset_manager'",
"]",
":",
"array",
"(",
")",
";",
"$",
"config",
"=",
"isset",
"(",
"$",
"config",
"[",
"'routes'",
"]",
")",
"&&",
"(",
"is_array",
"(",
"$",
"config",
"[",
"'routes'",
"]",
")",
"||",
"$",
"config",
"[",
"'routes'",
"]",
"instanceof",
"ArrayAccess",
")",
"?",
"$",
"config",
"[",
"'routes'",
"]",
":",
"array",
"(",
")",
";",
"// There can be special routes defined:",
"// /css",
"// /js",
"// ...",
"// This way the asset manager can be hidden",
"if",
"(",
"!",
"empty",
"(",
"$",
"config",
")",
")",
"{",
"// Rename all routes so I get an easy base route ",
"// name called 'asset_manager'",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"config",
")",
";",
"array_walk",
"(",
"$",
"keys",
",",
"function",
"(",
"$",
"n",
")",
"{",
"$",
"n",
"=",
"'asset_manager/'",
".",
"$",
"n",
";",
"}",
")",
";",
"$",
"config",
"=",
"array_combine",
"(",
"$",
"keys",
",",
"array_values",
"(",
"$",
"config",
")",
")",
";",
"// Add the routes",
"$",
"router",
"->",
"addRoutes",
"(",
"$",
"config",
")",
";",
"}",
"else",
"{",
"// No routes have been configured!",
"// So I need to create my own",
"$",
"router",
"->",
"addRoute",
"(",
"'asset_manager'",
",",
"array",
"(",
"'type'",
"=>",
"'Zend\\Mvc\\Router\\Http\\Literal'",
",",
"'options'",
"=>",
"array",
"(",
"'route'",
"=>",
"'/assets'",
",",
")",
",",
"'may_terminate'",
"=>",
"true",
",",
"'child_routes'",
"=>",
"array",
"(",
"'default'",
"=>",
"array",
"(",
"'type'",
"=>",
"'Wildcard'",
")",
")",
")",
")",
";",
"}",
"}"
] | Late-binding asset routes.
@param MvcEvent $event | [
"Late",
"-",
"binding",
"asset",
"routes",
"."
] | adbdc40417c6fddbba1a8c8b675e59ce1a25ad65 | https://github.com/shadowfax/zf2-asset-manager/blob/adbdc40417c6fddbba1a8c8b675e59ce1a25ad65/src/AssetManager/Mvc/AssetRouteListener.php#L65-L115 | train |
shadowfax/zf2-asset-manager | src/AssetManager/Mvc/AssetRouteListener.php | AssetRouteListener.onPostRoute | public function onPostRoute(MvcEvent $e)
{
$matches = $e->getRouteMatch();
if (!$matches instanceof Router\RouteMatch) {
// Can't do anything without a route match
return;
}
// Check for 'asset_manager' route
$routeName = $matches->getMatchedRouteName();
$routeName = explode('/', $routeName, 2);
$routeName = $routeName[0];
if ($routeName !== 'asset_manager') {
// Not an asset request
return;
}
// TODO: Take care of grouped assets (Merged assets)
// Right now only direct access
$serviceManager = $e->getApplication()->getServiceManager();
$router = $e->getRouter();
$assetManager = $serviceManager->get('AssetManager');
$requestPath = $e->getRequest()->getUri()->getPath();
$requestBasePath = $router->assemble(array(), array('name' => 'asset_manager'));
$requestBasePath = $requestBasePath . '/';
if (strlen($requestPath) <= strlen($requestBasePath)) {
// Not enough data!
return;
}
$requestPath = substr($requestPath, strlen($requestBasePath) - 1);
$assetPathStack = $serviceManager->get('AssetPathStack');
$content = $assetPathStack->resolve($requestPath);
if (!empty($content)) {
$response = $e->getResponse();
$headers = $response->getHeaders();
$headers->addHeaderLine('Content-Type', MimeResolver::getMimeType($requestPath));
$response->setContent($content);
return $response;
}
} | php | public function onPostRoute(MvcEvent $e)
{
$matches = $e->getRouteMatch();
if (!$matches instanceof Router\RouteMatch) {
// Can't do anything without a route match
return;
}
// Check for 'asset_manager' route
$routeName = $matches->getMatchedRouteName();
$routeName = explode('/', $routeName, 2);
$routeName = $routeName[0];
if ($routeName !== 'asset_manager') {
// Not an asset request
return;
}
// TODO: Take care of grouped assets (Merged assets)
// Right now only direct access
$serviceManager = $e->getApplication()->getServiceManager();
$router = $e->getRouter();
$assetManager = $serviceManager->get('AssetManager');
$requestPath = $e->getRequest()->getUri()->getPath();
$requestBasePath = $router->assemble(array(), array('name' => 'asset_manager'));
$requestBasePath = $requestBasePath . '/';
if (strlen($requestPath) <= strlen($requestBasePath)) {
// Not enough data!
return;
}
$requestPath = substr($requestPath, strlen($requestBasePath) - 1);
$assetPathStack = $serviceManager->get('AssetPathStack');
$content = $assetPathStack->resolve($requestPath);
if (!empty($content)) {
$response = $e->getResponse();
$headers = $response->getHeaders();
$headers->addHeaderLine('Content-Type', MimeResolver::getMimeType($requestPath));
$response->setContent($content);
return $response;
}
} | [
"public",
"function",
"onPostRoute",
"(",
"MvcEvent",
"$",
"e",
")",
"{",
"$",
"matches",
"=",
"$",
"e",
"->",
"getRouteMatch",
"(",
")",
";",
"if",
"(",
"!",
"$",
"matches",
"instanceof",
"Router",
"\\",
"RouteMatch",
")",
"{",
"// Can't do anything without a route match",
"return",
";",
"}",
"// Check for 'asset_manager' route",
"$",
"routeName",
"=",
"$",
"matches",
"->",
"getMatchedRouteName",
"(",
")",
";",
"$",
"routeName",
"=",
"explode",
"(",
"'/'",
",",
"$",
"routeName",
",",
"2",
")",
";",
"$",
"routeName",
"=",
"$",
"routeName",
"[",
"0",
"]",
";",
"if",
"(",
"$",
"routeName",
"!==",
"'asset_manager'",
")",
"{",
"// Not an asset request",
"return",
";",
"}",
"// TODO: Take care of grouped assets (Merged assets)",
"// Right now only direct access",
"$",
"serviceManager",
"=",
"$",
"e",
"->",
"getApplication",
"(",
")",
"->",
"getServiceManager",
"(",
")",
";",
"$",
"router",
"=",
"$",
"e",
"->",
"getRouter",
"(",
")",
";",
"$",
"assetManager",
"=",
"$",
"serviceManager",
"->",
"get",
"(",
"'AssetManager'",
")",
";",
"$",
"requestPath",
"=",
"$",
"e",
"->",
"getRequest",
"(",
")",
"->",
"getUri",
"(",
")",
"->",
"getPath",
"(",
")",
";",
"$",
"requestBasePath",
"=",
"$",
"router",
"->",
"assemble",
"(",
"array",
"(",
")",
",",
"array",
"(",
"'name'",
"=>",
"'asset_manager'",
")",
")",
";",
"$",
"requestBasePath",
"=",
"$",
"requestBasePath",
".",
"'/'",
";",
"if",
"(",
"strlen",
"(",
"$",
"requestPath",
")",
"<=",
"strlen",
"(",
"$",
"requestBasePath",
")",
")",
"{",
"// Not enough data!",
"return",
";",
"}",
"$",
"requestPath",
"=",
"substr",
"(",
"$",
"requestPath",
",",
"strlen",
"(",
"$",
"requestBasePath",
")",
"-",
"1",
")",
";",
"$",
"assetPathStack",
"=",
"$",
"serviceManager",
"->",
"get",
"(",
"'AssetPathStack'",
")",
";",
"$",
"content",
"=",
"$",
"assetPathStack",
"->",
"resolve",
"(",
"$",
"requestPath",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"content",
")",
")",
"{",
"$",
"response",
"=",
"$",
"e",
"->",
"getResponse",
"(",
")",
";",
"$",
"headers",
"=",
"$",
"response",
"->",
"getHeaders",
"(",
")",
";",
"$",
"headers",
"->",
"addHeaderLine",
"(",
"'Content-Type'",
",",
"MimeResolver",
"::",
"getMimeType",
"(",
"$",
"requestPath",
")",
")",
";",
"$",
"response",
"->",
"setContent",
"(",
"$",
"content",
")",
";",
"return",
"$",
"response",
";",
"}",
"}"
] | Listen to the "route" event and determine if an asset should be loaded.
@param MvcEvent $e
@return Response|null | [
"Listen",
"to",
"the",
"route",
"event",
"and",
"determine",
"if",
"an",
"asset",
"should",
"be",
"loaded",
"."
] | adbdc40417c6fddbba1a8c8b675e59ce1a25ad65 | https://github.com/shadowfax/zf2-asset-manager/blob/adbdc40417c6fddbba1a8c8b675e59ce1a25ad65/src/AssetManager/Mvc/AssetRouteListener.php#L123-L169 | train |
linpax/microphp-framework | src/base/Application.php | Application.doRun | private function doRun()
{
$dispatcher = (new DispatcherInjector)->build();
//покажем событие Request
if (($response = $dispatcher->signal('kernel.request')) instanceof ResponseInterface) {
return $response; // событие завершило очередь
}
$resolver = $this->getResolver();
//покажем событие Route
if (($response = $dispatcher->signal('kernel.route', ['resolver' => $resolver])) instanceof ResponseInterface) {
return $response; // событие завершило очередь
}
/** @var Console|IController $controller */
$controller = $resolver->getApp();
$action = $resolver->getAction();
//покажем событие Controller
if (($response = $dispatcher->signal('kernel.controller',
['controller' => $controller, 'action' => $action])) instanceof ResponseInterface
) {
return $response; // событие завершило очередь
}
$response = $controller->action((string)$action);
if (!($response instanceof ResponseInterface)) {
$responser = (new ResponseInjector)->build();
$stream = $responser->getBody();
$stream->write((string)$response);
$response = $responser->withBody($stream);
}
$dispatcher->signal('kernel.response', ['response' => $response]);
return $response;
} | php | private function doRun()
{
$dispatcher = (new DispatcherInjector)->build();
//покажем событие Request
if (($response = $dispatcher->signal('kernel.request')) instanceof ResponseInterface) {
return $response; // событие завершило очередь
}
$resolver = $this->getResolver();
//покажем событие Route
if (($response = $dispatcher->signal('kernel.route', ['resolver' => $resolver])) instanceof ResponseInterface) {
return $response; // событие завершило очередь
}
/** @var Console|IController $controller */
$controller = $resolver->getApp();
$action = $resolver->getAction();
//покажем событие Controller
if (($response = $dispatcher->signal('kernel.controller',
['controller' => $controller, 'action' => $action])) instanceof ResponseInterface
) {
return $response; // событие завершило очередь
}
$response = $controller->action((string)$action);
if (!($response instanceof ResponseInterface)) {
$responser = (new ResponseInjector)->build();
$stream = $responser->getBody();
$stream->write((string)$response);
$response = $responser->withBody($stream);
}
$dispatcher->signal('kernel.response', ['response' => $response]);
return $response;
} | [
"private",
"function",
"doRun",
"(",
")",
"{",
"$",
"dispatcher",
"=",
"(",
"new",
"DispatcherInjector",
")",
"->",
"build",
"(",
")",
";",
"//покажем событие Request",
"if",
"(",
"(",
"$",
"response",
"=",
"$",
"dispatcher",
"->",
"signal",
"(",
"'kernel.request'",
")",
")",
"instanceof",
"ResponseInterface",
")",
"{",
"return",
"$",
"response",
";",
"// событие завершило очередь",
"}",
"$",
"resolver",
"=",
"$",
"this",
"->",
"getResolver",
"(",
")",
";",
"//покажем событие Route",
"if",
"(",
"(",
"$",
"response",
"=",
"$",
"dispatcher",
"->",
"signal",
"(",
"'kernel.route'",
",",
"[",
"'resolver'",
"=>",
"$",
"resolver",
"]",
")",
")",
"instanceof",
"ResponseInterface",
")",
"{",
"return",
"$",
"response",
";",
"// событие завершило очередь",
"}",
"/** @var Console|IController $controller */",
"$",
"controller",
"=",
"$",
"resolver",
"->",
"getApp",
"(",
")",
";",
"$",
"action",
"=",
"$",
"resolver",
"->",
"getAction",
"(",
")",
";",
"//покажем событие Controller",
"if",
"(",
"(",
"$",
"response",
"=",
"$",
"dispatcher",
"->",
"signal",
"(",
"'kernel.controller'",
",",
"[",
"'controller'",
"=>",
"$",
"controller",
",",
"'action'",
"=>",
"$",
"action",
"]",
")",
")",
"instanceof",
"ResponseInterface",
")",
"{",
"return",
"$",
"response",
";",
"// событие завершило очередь",
"}",
"$",
"response",
"=",
"$",
"controller",
"->",
"action",
"(",
"(",
"string",
")",
"$",
"action",
")",
";",
"if",
"(",
"!",
"(",
"$",
"response",
"instanceof",
"ResponseInterface",
")",
")",
"{",
"$",
"responser",
"=",
"(",
"new",
"ResponseInjector",
")",
"->",
"build",
"(",
")",
";",
"$",
"stream",
"=",
"$",
"responser",
"->",
"getBody",
"(",
")",
";",
"$",
"stream",
"->",
"write",
"(",
"(",
"string",
")",
"$",
"response",
")",
";",
"$",
"response",
"=",
"$",
"responser",
"->",
"withBody",
"(",
"$",
"stream",
")",
";",
"}",
"$",
"dispatcher",
"->",
"signal",
"(",
"'kernel.response'",
",",
"[",
"'response'",
"=>",
"$",
"response",
"]",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Real run application
@return ResponseInterface | [
"Real",
"run",
"application"
] | 11f3370f3f64c516cce9b84ecd8276c6e9ae8df9 | https://github.com/linpax/microphp-framework/blob/11f3370f3f64c516cce9b84ecd8276c6e9ae8df9/src/base/Application.php#L70-L110 | train |
dms-org/common.structure | src/FileSystem/Image.php | Image.getWidth | public function getWidth() : int
{
if (!$this->loadImageInfo()) {
throw InvalidOperationException::format(
'Invalid call to %s: file \'%s\' is not a valid image',
__METHOD__,
$this->fullPath
);
}
return $this->width;
} | php | public function getWidth() : int
{
if (!$this->loadImageInfo()) {
throw InvalidOperationException::format(
'Invalid call to %s: file \'%s\' is not a valid image',
__METHOD__,
$this->fullPath
);
}
return $this->width;
} | [
"public",
"function",
"getWidth",
"(",
")",
":",
"int",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"loadImageInfo",
"(",
")",
")",
"{",
"throw",
"InvalidOperationException",
"::",
"format",
"(",
"'Invalid call to %s: file \\'%s\\' is not a valid image'",
",",
"__METHOD__",
",",
"$",
"this",
"->",
"fullPath",
")",
";",
"}",
"return",
"$",
"this",
"->",
"width",
";",
"}"
] | Gets the image width in pixels.
@return int
@throws InvalidOperationException | [
"Gets",
"the",
"image",
"width",
"in",
"pixels",
"."
] | 23f122182f60df5ec847047a81a39c8aab019ff1 | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/FileSystem/Image.php#L89-L100 | train |
dms-org/common.structure | src/FileSystem/Image.php | Image.getHeight | public function getHeight() : int
{
if (!$this->loadImageInfo()) {
throw InvalidOperationException::format(
'Invalid call to %s: file \'%s\' is not a valid image',
__METHOD__,
$this->fullPath
);
}
return $this->height;
} | php | public function getHeight() : int
{
if (!$this->loadImageInfo()) {
throw InvalidOperationException::format(
'Invalid call to %s: file \'%s\' is not a valid image',
__METHOD__,
$this->fullPath
);
}
return $this->height;
} | [
"public",
"function",
"getHeight",
"(",
")",
":",
"int",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"loadImageInfo",
"(",
")",
")",
"{",
"throw",
"InvalidOperationException",
"::",
"format",
"(",
"'Invalid call to %s: file \\'%s\\' is not a valid image'",
",",
"__METHOD__",
",",
"$",
"this",
"->",
"fullPath",
")",
";",
"}",
"return",
"$",
"this",
"->",
"height",
";",
"}"
] | Gets the image height in pixels.
@return int
@throws InvalidOperationException | [
"Gets",
"the",
"image",
"height",
"in",
"pixels",
"."
] | 23f122182f60df5ec847047a81a39c8aab019ff1 | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/FileSystem/Image.php#L108-L119 | train |
jenskooij/cloudcontrol | src/storage/factories/ImageSetFactory.php | ImageSetFactory.createImageSetFromPostValues | public static function createImageSetFromPostValues($postValues)
{
if (isset($postValues['title'], $postValues['width'], $postValues['height'], $postValues['method'])) {
$imageSetObject = new \stdClass();
$imageSetObject->title = $postValues['title'];
$imageSetObject->slug = StringUtil::slugify($postValues['title']);
$imageSetObject->width = $postValues['width'];
$imageSetObject->height = $postValues['height'];
$imageSetObject->method = $postValues['method'];
return $imageSetObject;
} else {
throw new \Exception('Trying to create image set with invalid data.');
}
} | php | public static function createImageSetFromPostValues($postValues)
{
if (isset($postValues['title'], $postValues['width'], $postValues['height'], $postValues['method'])) {
$imageSetObject = new \stdClass();
$imageSetObject->title = $postValues['title'];
$imageSetObject->slug = StringUtil::slugify($postValues['title']);
$imageSetObject->width = $postValues['width'];
$imageSetObject->height = $postValues['height'];
$imageSetObject->method = $postValues['method'];
return $imageSetObject;
} else {
throw new \Exception('Trying to create image set with invalid data.');
}
} | [
"public",
"static",
"function",
"createImageSetFromPostValues",
"(",
"$",
"postValues",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"postValues",
"[",
"'title'",
"]",
",",
"$",
"postValues",
"[",
"'width'",
"]",
",",
"$",
"postValues",
"[",
"'height'",
"]",
",",
"$",
"postValues",
"[",
"'method'",
"]",
")",
")",
"{",
"$",
"imageSetObject",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"imageSetObject",
"->",
"title",
"=",
"$",
"postValues",
"[",
"'title'",
"]",
";",
"$",
"imageSetObject",
"->",
"slug",
"=",
"StringUtil",
"::",
"slugify",
"(",
"$",
"postValues",
"[",
"'title'",
"]",
")",
";",
"$",
"imageSetObject",
"->",
"width",
"=",
"$",
"postValues",
"[",
"'width'",
"]",
";",
"$",
"imageSetObject",
"->",
"height",
"=",
"$",
"postValues",
"[",
"'height'",
"]",
";",
"$",
"imageSetObject",
"->",
"method",
"=",
"$",
"postValues",
"[",
"'method'",
"]",
";",
"return",
"$",
"imageSetObject",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Trying to create image set with invalid data.'",
")",
";",
"}",
"}"
] | Ceate image set from post values
@param $postValues
@return \stdClass
@throws \Exception | [
"Ceate",
"image",
"set",
"from",
"post",
"values"
] | 76e5d9ac8f9c50d06d39a995d13cc03742536548 | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/storage/factories/ImageSetFactory.php#L23-L38 | train |
AltCtrlSupr/ACSPanel-Settings | Model/SettingManager.php | SettingManager.isUpdateAvailable | public function isUpdateAvailable($user, $version_key, $schema_version)
{
$user_fields_version = $this->getSetting($version_key, 'user_internal', $user);
if (!$user_fields_version) {
$user_fields_version = 0;
}
if ($user_fields_version < $schema_version) {
return true;
}
return false;
} | php | public function isUpdateAvailable($user, $version_key, $schema_version)
{
$user_fields_version = $this->getSetting($version_key, 'user_internal', $user);
if (!$user_fields_version) {
$user_fields_version = 0;
}
if ($user_fields_version < $schema_version) {
return true;
}
return false;
} | [
"public",
"function",
"isUpdateAvailable",
"(",
"$",
"user",
",",
"$",
"version_key",
",",
"$",
"schema_version",
")",
"{",
"$",
"user_fields_version",
"=",
"$",
"this",
"->",
"getSetting",
"(",
"$",
"version_key",
",",
"'user_internal'",
",",
"$",
"user",
")",
";",
"if",
"(",
"!",
"$",
"user_fields_version",
")",
"{",
"$",
"user_fields_version",
"=",
"0",
";",
"}",
"if",
"(",
"$",
"user_fields_version",
"<",
"$",
"schema_version",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Returns true if there is a update of the user fields | [
"Returns",
"true",
"if",
"there",
"is",
"a",
"update",
"of",
"the",
"user",
"fields"
] | b1e363bf98d4c74368b3063abba0c77bb3a61230 | https://github.com/AltCtrlSupr/ACSPanel-Settings/blob/b1e363bf98d4c74368b3063abba0c77bb3a61230/Model/SettingManager.php#L25-L37 | train |
AltCtrlSupr/ACSPanel-Settings | Model/SettingManager.php | SettingManager.loadSettingDefaults | public function loadSettingDefaults(array $fields, $user)
{
$user = $this->container->get('security.context')->getToken()->getUser();
foreach($fields as $field){
if (!$this->getSetting($field['setting_key'], $field['focus'], $user)) {
if(!isset($field['default_value'])) {
$field['default_value'] = '';
}
$this->setSetting($field['setting_key'], $field['focus'], $field['default_value'], $field['context'], $user);
}
}
//TODO: Increment schema_version setting
} | php | public function loadSettingDefaults(array $fields, $user)
{
$user = $this->container->get('security.context')->getToken()->getUser();
foreach($fields as $field){
if (!$this->getSetting($field['setting_key'], $field['focus'], $user)) {
if(!isset($field['default_value'])) {
$field['default_value'] = '';
}
$this->setSetting($field['setting_key'], $field['focus'], $field['default_value'], $field['context'], $user);
}
}
//TODO: Increment schema_version setting
} | [
"public",
"function",
"loadSettingDefaults",
"(",
"array",
"$",
"fields",
",",
"$",
"user",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'security.context'",
")",
"->",
"getToken",
"(",
")",
"->",
"getUser",
"(",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getSetting",
"(",
"$",
"field",
"[",
"'setting_key'",
"]",
",",
"$",
"field",
"[",
"'focus'",
"]",
",",
"$",
"user",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"field",
"[",
"'default_value'",
"]",
")",
")",
"{",
"$",
"field",
"[",
"'default_value'",
"]",
"=",
"''",
";",
"}",
"$",
"this",
"->",
"setSetting",
"(",
"$",
"field",
"[",
"'setting_key'",
"]",
",",
"$",
"field",
"[",
"'focus'",
"]",
",",
"$",
"field",
"[",
"'default_value'",
"]",
",",
"$",
"field",
"[",
"'context'",
"]",
",",
"$",
"user",
")",
";",
"}",
"}",
"//TODO: Increment schema_version setting",
"}"
] | Loading of settings needed for the app
Called if it's the first time or user need update of settings | [
"Loading",
"of",
"settings",
"needed",
"for",
"the",
"app",
"Called",
"if",
"it",
"s",
"the",
"first",
"time",
"or",
"user",
"need",
"update",
"of",
"settings"
] | b1e363bf98d4c74368b3063abba0c77bb3a61230 | https://github.com/AltCtrlSupr/ACSPanel-Settings/blob/b1e363bf98d4c74368b3063abba0c77bb3a61230/Model/SettingManager.php#L43-L57 | train |
AltCtrlSupr/ACSPanel-Settings | Model/SettingManager.php | SettingManager.loadObjectSettingsDefaults | public function loadObjectSettingsDefaults($object_id)
{
$em = $this->getEntityManager();
$object = $em->getRepository('ACSACSPanelBundle:Service')->find($object_id);
$object_fields = $object->getType()->getFieldTypes();
return $object_fields;
} | php | public function loadObjectSettingsDefaults($object_id)
{
$em = $this->getEntityManager();
$object = $em->getRepository('ACSACSPanelBundle:Service')->find($object_id);
$object_fields = $object->getType()->getFieldTypes();
return $object_fields;
} | [
"public",
"function",
"loadObjectSettingsDefaults",
"(",
"$",
"object_id",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
";",
"$",
"object",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"'ACSACSPanelBundle:Service'",
")",
"->",
"find",
"(",
"$",
"object_id",
")",
";",
"$",
"object_fields",
"=",
"$",
"object",
"->",
"getType",
"(",
")",
"->",
"getFieldTypes",
"(",
")",
";",
"return",
"$",
"object_fields",
";",
"}"
] | Create the settings configured for specified object | [
"Create",
"the",
"settings",
"configured",
"for",
"specified",
"object"
] | b1e363bf98d4c74368b3063abba0c77bb3a61230 | https://github.com/AltCtrlSupr/ACSPanel-Settings/blob/b1e363bf98d4c74368b3063abba0c77bb3a61230/Model/SettingManager.php#L90-L98 | train |
AltCtrlSupr/ACSPanel-Settings | Model/SettingManager.php | SettingManager.getSetting | public function getSetting($setting_key, $focus = null, $user = null)
{
$params = array();
$params['setting_key'] = $setting_key;
if ($focus) {
$params['focus'] = $focus;
}
if ($user) {
$params['user'] = $user;
}
$setting = $this->findOneBy($params);
if ($setting) {
return $setting->getValue();
}
return null;
} | php | public function getSetting($setting_key, $focus = null, $user = null)
{
$params = array();
$params['setting_key'] = $setting_key;
if ($focus) {
$params['focus'] = $focus;
}
if ($user) {
$params['user'] = $user;
}
$setting = $this->findOneBy($params);
if ($setting) {
return $setting->getValue();
}
return null;
} | [
"public",
"function",
"getSetting",
"(",
"$",
"setting_key",
",",
"$",
"focus",
"=",
"null",
",",
"$",
"user",
"=",
"null",
")",
"{",
"$",
"params",
"=",
"array",
"(",
")",
";",
"$",
"params",
"[",
"'setting_key'",
"]",
"=",
"$",
"setting_key",
";",
"if",
"(",
"$",
"focus",
")",
"{",
"$",
"params",
"[",
"'focus'",
"]",
"=",
"$",
"focus",
";",
"}",
"if",
"(",
"$",
"user",
")",
"{",
"$",
"params",
"[",
"'user'",
"]",
"=",
"$",
"user",
";",
"}",
"$",
"setting",
"=",
"$",
"this",
"->",
"findOneBy",
"(",
"$",
"params",
")",
";",
"if",
"(",
"$",
"setting",
")",
"{",
"return",
"$",
"setting",
"->",
"getValue",
"(",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Get setting by parameters | [
"Get",
"setting",
"by",
"parameters"
] | b1e363bf98d4c74368b3063abba0c77bb3a61230 | https://github.com/AltCtrlSupr/ACSPanel-Settings/blob/b1e363bf98d4c74368b3063abba0c77bb3a61230/Model/SettingManager.php#L103-L123 | train |
AltCtrlSupr/ACSPanel-Settings | Model/SettingManager.php | SettingManager.setSetting | public function setSetting($setting_key, $focus, $value, $context = '', $user = null)
{
$em = $this->getEntityManager();
$params = array();
$params['setting_key'] = $setting_key;
$params['focus'] = $focus;
if ($context) {
$params['context'] = $context;
}
if ($user) {
$params['user'] = $user;
}
$setting = $this->findOneBy($params);
// We create the new setting if it not exists
if (!$setting) {
$class_name = $this->container->getParameter('acs_settings.setting_class');
$setting = new $class_name;
$setting->setSettingKey($setting_key);
$setting->setFocus($focus);
$setting->setContext($context);
}
$setting->setValue($value);
$em->persist($setting);
$em->flush();
return $setting;
} | php | public function setSetting($setting_key, $focus, $value, $context = '', $user = null)
{
$em = $this->getEntityManager();
$params = array();
$params['setting_key'] = $setting_key;
$params['focus'] = $focus;
if ($context) {
$params['context'] = $context;
}
if ($user) {
$params['user'] = $user;
}
$setting = $this->findOneBy($params);
// We create the new setting if it not exists
if (!$setting) {
$class_name = $this->container->getParameter('acs_settings.setting_class');
$setting = new $class_name;
$setting->setSettingKey($setting_key);
$setting->setFocus($focus);
$setting->setContext($context);
}
$setting->setValue($value);
$em->persist($setting);
$em->flush();
return $setting;
} | [
"public",
"function",
"setSetting",
"(",
"$",
"setting_key",
",",
"$",
"focus",
",",
"$",
"value",
",",
"$",
"context",
"=",
"''",
",",
"$",
"user",
"=",
"null",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
";",
"$",
"params",
"=",
"array",
"(",
")",
";",
"$",
"params",
"[",
"'setting_key'",
"]",
"=",
"$",
"setting_key",
";",
"$",
"params",
"[",
"'focus'",
"]",
"=",
"$",
"focus",
";",
"if",
"(",
"$",
"context",
")",
"{",
"$",
"params",
"[",
"'context'",
"]",
"=",
"$",
"context",
";",
"}",
"if",
"(",
"$",
"user",
")",
"{",
"$",
"params",
"[",
"'user'",
"]",
"=",
"$",
"user",
";",
"}",
"$",
"setting",
"=",
"$",
"this",
"->",
"findOneBy",
"(",
"$",
"params",
")",
";",
"// We create the new setting if it not exists",
"if",
"(",
"!",
"$",
"setting",
")",
"{",
"$",
"class_name",
"=",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'acs_settings.setting_class'",
")",
";",
"$",
"setting",
"=",
"new",
"$",
"class_name",
";",
"$",
"setting",
"->",
"setSettingKey",
"(",
"$",
"setting_key",
")",
";",
"$",
"setting",
"->",
"setFocus",
"(",
"$",
"focus",
")",
";",
"$",
"setting",
"->",
"setContext",
"(",
"$",
"context",
")",
";",
"}",
"$",
"setting",
"->",
"setValue",
"(",
"$",
"value",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"setting",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"setting",
";",
"}"
] | Sets a setting value | [
"Sets",
"a",
"setting",
"value"
] | b1e363bf98d4c74368b3063abba0c77bb3a61230 | https://github.com/AltCtrlSupr/ACSPanel-Settings/blob/b1e363bf98d4c74368b3063abba0c77bb3a61230/Model/SettingManager.php#L128-L160 | train |
AltCtrlSupr/ACSPanel-Settings | Model/SettingManager.php | SettingManager.getContexts | public function getContexts($user)
{
$em = $this->getEntityManager();
$contexts_rep = $em->getRepository('ACSACSPanelBundle:PanelSetting');
$query = $contexts_rep->createQueryBuilder('ps')
->select('ps.context')
->where('ps.user = ?1')
->andWhere('ps.context NOT LIKE ?2')
->andWhere('ps.context NOT LIKE ?3')
->andWhere('ps.context NOT LIKE ?4')
->groupBy('ps.context')
->orderBy('ps.context')
->setParameter('1', $user)
->setParameter('2', 'internal')
->setParameter('3', 'user_internal')
->setParameter('4', 'system_internal')
->getQuery()
;
$contexts = $query->execute();
return $contexts;
} | php | public function getContexts($user)
{
$em = $this->getEntityManager();
$contexts_rep = $em->getRepository('ACSACSPanelBundle:PanelSetting');
$query = $contexts_rep->createQueryBuilder('ps')
->select('ps.context')
->where('ps.user = ?1')
->andWhere('ps.context NOT LIKE ?2')
->andWhere('ps.context NOT LIKE ?3')
->andWhere('ps.context NOT LIKE ?4')
->groupBy('ps.context')
->orderBy('ps.context')
->setParameter('1', $user)
->setParameter('2', 'internal')
->setParameter('3', 'user_internal')
->setParameter('4', 'system_internal')
->getQuery()
;
$contexts = $query->execute();
return $contexts;
} | [
"public",
"function",
"getContexts",
"(",
"$",
"user",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
";",
"$",
"contexts_rep",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"'ACSACSPanelBundle:PanelSetting'",
")",
";",
"$",
"query",
"=",
"$",
"contexts_rep",
"->",
"createQueryBuilder",
"(",
"'ps'",
")",
"->",
"select",
"(",
"'ps.context'",
")",
"->",
"where",
"(",
"'ps.user = ?1'",
")",
"->",
"andWhere",
"(",
"'ps.context NOT LIKE ?2'",
")",
"->",
"andWhere",
"(",
"'ps.context NOT LIKE ?3'",
")",
"->",
"andWhere",
"(",
"'ps.context NOT LIKE ?4'",
")",
"->",
"groupBy",
"(",
"'ps.context'",
")",
"->",
"orderBy",
"(",
"'ps.context'",
")",
"->",
"setParameter",
"(",
"'1'",
",",
"$",
"user",
")",
"->",
"setParameter",
"(",
"'2'",
",",
"'internal'",
")",
"->",
"setParameter",
"(",
"'3'",
",",
"'user_internal'",
")",
"->",
"setParameter",
"(",
"'4'",
",",
"'system_internal'",
")",
"->",
"getQuery",
"(",
")",
";",
"$",
"contexts",
"=",
"$",
"query",
"->",
"execute",
"(",
")",
";",
"return",
"$",
"contexts",
";",
"}"
] | Returns the context used to organize the settings view | [
"Returns",
"the",
"context",
"used",
"to",
"organize",
"the",
"settings",
"view"
] | b1e363bf98d4c74368b3063abba0c77bb3a61230 | https://github.com/AltCtrlSupr/ACSPanel-Settings/blob/b1e363bf98d4c74368b3063abba0c77bb3a61230/Model/SettingManager.php#L206-L229 | train |
AltCtrlSupr/ACSPanel-Settings | Model/SettingManager.php | SettingManager.loadUserFields | function loadUserFields()
{
$user_fields = array();
$this->container->get('event_dispatcher')->dispatch(SettingsEvents::BEFORE_LOAD_USERFIELDS, new FilterUserFieldsEvent($user_fields, $this->container));
array_merge($user_fields, $user_fields = $this->container->getParameter("acs_settings.user_fields"));
$user = $this->container->get('security.context')->getToken()->getUser();
// If is admins we load the global system settings
if (true === $this->container->get('security.context')->isGranted('ROLE_SUPER_ADMIN')) {
$user_fields = array_merge($user_fields, $system_fields = $this->container->getParameter("acs_settings.system_fields"));
}
$object_settings = $this->container->get('acs.setting_manager')->getObjectSettingsPrototype($user);
$user_fields = array_merge($user_fields, $object_settings);
$this->container->get('event_dispatcher')->dispatch(SettingsEvents::AFTER_LOAD_USERFIELDS, new FilterUserFieldsEvent($user_fields,$this->container));
return $user_fields;
} | php | function loadUserFields()
{
$user_fields = array();
$this->container->get('event_dispatcher')->dispatch(SettingsEvents::BEFORE_LOAD_USERFIELDS, new FilterUserFieldsEvent($user_fields, $this->container));
array_merge($user_fields, $user_fields = $this->container->getParameter("acs_settings.user_fields"));
$user = $this->container->get('security.context')->getToken()->getUser();
// If is admins we load the global system settings
if (true === $this->container->get('security.context')->isGranted('ROLE_SUPER_ADMIN')) {
$user_fields = array_merge($user_fields, $system_fields = $this->container->getParameter("acs_settings.system_fields"));
}
$object_settings = $this->container->get('acs.setting_manager')->getObjectSettingsPrototype($user);
$user_fields = array_merge($user_fields, $object_settings);
$this->container->get('event_dispatcher')->dispatch(SettingsEvents::AFTER_LOAD_USERFIELDS, new FilterUserFieldsEvent($user_fields,$this->container));
return $user_fields;
} | [
"function",
"loadUserFields",
"(",
")",
"{",
"$",
"user_fields",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'event_dispatcher'",
")",
"->",
"dispatch",
"(",
"SettingsEvents",
"::",
"BEFORE_LOAD_USERFIELDS",
",",
"new",
"FilterUserFieldsEvent",
"(",
"$",
"user_fields",
",",
"$",
"this",
"->",
"container",
")",
")",
";",
"array_merge",
"(",
"$",
"user_fields",
",",
"$",
"user_fields",
"=",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"\"acs_settings.user_fields\"",
")",
")",
";",
"$",
"user",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'security.context'",
")",
"->",
"getToken",
"(",
")",
"->",
"getUser",
"(",
")",
";",
"// If is admins we load the global system settings",
"if",
"(",
"true",
"===",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'security.context'",
")",
"->",
"isGranted",
"(",
"'ROLE_SUPER_ADMIN'",
")",
")",
"{",
"$",
"user_fields",
"=",
"array_merge",
"(",
"$",
"user_fields",
",",
"$",
"system_fields",
"=",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"\"acs_settings.system_fields\"",
")",
")",
";",
"}",
"$",
"object_settings",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'acs.setting_manager'",
")",
"->",
"getObjectSettingsPrototype",
"(",
"$",
"user",
")",
";",
"$",
"user_fields",
"=",
"array_merge",
"(",
"$",
"user_fields",
",",
"$",
"object_settings",
")",
";",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'event_dispatcher'",
")",
"->",
"dispatch",
"(",
"SettingsEvents",
"::",
"AFTER_LOAD_USERFIELDS",
",",
"new",
"FilterUserFieldsEvent",
"(",
"$",
"user_fields",
",",
"$",
"this",
"->",
"container",
")",
")",
";",
"return",
"$",
"user_fields",
";",
"}"
] | Load the settings array to pass to form | [
"Load",
"the",
"settings",
"array",
"to",
"pass",
"to",
"form"
] | b1e363bf98d4c74368b3063abba0c77bb3a61230 | https://github.com/AltCtrlSupr/ACSPanel-Settings/blob/b1e363bf98d4c74368b3063abba0c77bb3a61230/Model/SettingManager.php#L234-L256 | train |
t-kanstantsin/fileupload | src/config/Alias.php | Alias.getFilePath | public function getFilePath(IFile $file): ?string
{
if ($this->filePathClosure !== null) {
return \call_user_func($this->filePathClosure, $file);
}
if ($file instanceof ExternalFile) {
return $file->getActualPath();
}
return $file->getId() !== null
? $this->getFileDirectory($file) . DIRECTORY_SEPARATOR . $this->getFileName($file)
: null;
} | php | public function getFilePath(IFile $file): ?string
{
if ($this->filePathClosure !== null) {
return \call_user_func($this->filePathClosure, $file);
}
if ($file instanceof ExternalFile) {
return $file->getActualPath();
}
return $file->getId() !== null
? $this->getFileDirectory($file) . DIRECTORY_SEPARATOR . $this->getFileName($file)
: null;
} | [
"public",
"function",
"getFilePath",
"(",
"IFile",
"$",
"file",
")",
":",
"?",
"string",
"{",
"if",
"(",
"$",
"this",
"->",
"filePathClosure",
"!==",
"null",
")",
"{",
"return",
"\\",
"call_user_func",
"(",
"$",
"this",
"->",
"filePathClosure",
",",
"$",
"file",
")",
";",
"}",
"if",
"(",
"$",
"file",
"instanceof",
"ExternalFile",
")",
"{",
"return",
"$",
"file",
"->",
"getActualPath",
"(",
")",
";",
"}",
"return",
"$",
"file",
"->",
"getId",
"(",
")",
"!==",
"null",
"?",
"$",
"this",
"->",
"getFileDirectory",
"(",
"$",
"file",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"this",
"->",
"getFileName",
"(",
"$",
"file",
")",
":",
"null",
";",
"}"
] | Returns file path in contentFS
@param IFile $file
@return string|null | [
"Returns",
"file",
"path",
"in",
"contentFS"
] | d6317a9b9b36d992f09affe3900ef7d7ddfd855f | https://github.com/t-kanstantsin/fileupload/blob/d6317a9b9b36d992f09affe3900ef7d7ddfd855f/src/config/Alias.php#L115-L128 | train |
t-kanstantsin/fileupload | src/config/Alias.php | Alias.getAssetPath | public function getAssetPath(IFile $file, string $formatName): string
{
return implode('/', array_filter([
Type::$folderPrefix[$file->getType()] . '_' . $formatName,
$file->getModelAlias(),
mb_substr($file->getHash(), 0, $this->cacheHashLength),
$this->getAssetName($file),
]));
} | php | public function getAssetPath(IFile $file, string $formatName): string
{
return implode('/', array_filter([
Type::$folderPrefix[$file->getType()] . '_' . $formatName,
$file->getModelAlias(),
mb_substr($file->getHash(), 0, $this->cacheHashLength),
$this->getAssetName($file),
]));
} | [
"public",
"function",
"getAssetPath",
"(",
"IFile",
"$",
"file",
",",
"string",
"$",
"formatName",
")",
":",
"string",
"{",
"return",
"implode",
"(",
"'/'",
",",
"array_filter",
"(",
"[",
"Type",
"::",
"$",
"folderPrefix",
"[",
"$",
"file",
"->",
"getType",
"(",
")",
"]",
".",
"'_'",
".",
"$",
"formatName",
",",
"$",
"file",
"->",
"getModelAlias",
"(",
")",
",",
"mb_substr",
"(",
"$",
"file",
"->",
"getHash",
"(",
")",
",",
"0",
",",
"$",
"this",
"->",
"cacheHashLength",
")",
",",
"$",
"this",
"->",
"getAssetName",
"(",
"$",
"file",
")",
",",
"]",
")",
")",
";",
"}"
] | Returns path in asset filesystem
@param IFile $file
@param string $formatName
@return string | [
"Returns",
"path",
"in",
"asset",
"filesystem"
] | d6317a9b9b36d992f09affe3900ef7d7ddfd855f | https://github.com/t-kanstantsin/fileupload/blob/d6317a9b9b36d992f09affe3900ef7d7ddfd855f/src/config/Alias.php#L136-L144 | train |
t-kanstantsin/fileupload | src/config/Alias.php | Alias.getAssetName | public function getAssetName(IFile $file): string
{
if ($this->assetNameClosure !== null) {
return \call_user_func($this->assetNameClosure, $file);
}
return $file->getId() . '_' . $file->getFullName();
} | php | public function getAssetName(IFile $file): string
{
if ($this->assetNameClosure !== null) {
return \call_user_func($this->assetNameClosure, $file);
}
return $file->getId() . '_' . $file->getFullName();
} | [
"public",
"function",
"getAssetName",
"(",
"IFile",
"$",
"file",
")",
":",
"string",
"{",
"if",
"(",
"$",
"this",
"->",
"assetNameClosure",
"!==",
"null",
")",
"{",
"return",
"\\",
"call_user_func",
"(",
"$",
"this",
"->",
"assetNameClosure",
",",
"$",
"file",
")",
";",
"}",
"return",
"$",
"file",
"->",
"getId",
"(",
")",
".",
"'_'",
".",
"$",
"file",
"->",
"getFullName",
"(",
")",
";",
"}"
] | File name in asset directory
@param IFile $file
@return string | [
"File",
"name",
"in",
"asset",
"directory"
] | d6317a9b9b36d992f09affe3900ef7d7ddfd855f | https://github.com/t-kanstantsin/fileupload/blob/d6317a9b9b36d992f09affe3900ef7d7ddfd855f/src/config/Alias.php#L151-L158 | train |
t-kanstantsin/fileupload | src/config/Alias.php | Alias.getFileDirectory | public function getFileDirectory(IFile $file): string
{
return implode(DIRECTORY_SEPARATOR, array_filter([
$this->directory,
// TODO: check if used correct hash.
// Which value should be passed into getDirectoryHash? Directory name or file id?
$this->getDirectoryHash((string) $file->getId()),
]));
} | php | public function getFileDirectory(IFile $file): string
{
return implode(DIRECTORY_SEPARATOR, array_filter([
$this->directory,
// TODO: check if used correct hash.
// Which value should be passed into getDirectoryHash? Directory name or file id?
$this->getDirectoryHash((string) $file->getId()),
]));
} | [
"public",
"function",
"getFileDirectory",
"(",
"IFile",
"$",
"file",
")",
":",
"string",
"{",
"return",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"array_filter",
"(",
"[",
"$",
"this",
"->",
"directory",
",",
"// TODO: check if used correct hash.",
"// Which value should be passed into getDirectoryHash? Directory name or file id?",
"$",
"this",
"->",
"getDirectoryHash",
"(",
"(",
"string",
")",
"$",
"file",
"->",
"getId",
"(",
")",
")",
",",
"]",
")",
")",
";",
"}"
] | Returns target directory for uploaded file
@param IFile $file
@return string | [
"Returns",
"target",
"directory",
"for",
"uploaded",
"file"
] | d6317a9b9b36d992f09affe3900ef7d7ddfd855f | https://github.com/t-kanstantsin/fileupload/blob/d6317a9b9b36d992f09affe3900ef7d7ddfd855f/src/config/Alias.php#L174-L182 | train |
anime-db/catalog-bundle | src/Controller/InstallController.php | InstallController.whatYouWantAction | public function whatYouWantAction(Request $request)
{
// app already installed
if ($this->container->getParameter('anime_db.catalog.installed')) {
return $this->redirect($this->generateUrl('home'));
}
$response = $this->getCacheTimeKeeper()->getResponse();
// response was not modified for this request
if ($response->isNotModified($request)) {
return $response;
}
if ($request->isMethod('POST')) {
$storage = $this->getRepository()->getLast();
$this->get('event_dispatcher')->dispatch(StoreEvents::INSTALL_SAMPLES, new SamplesInstall($storage));
return $this->redirect($this->generateUrl('install_end_skip', ['from' => 'install_sample']));
}
return $this->render('AnimeDbCatalogBundle:Install:what_you_want.html.twig', [
'guide' => $this->get('anime_db.api.client')->getSiteUrl(self::GUIDE_LINK_SCAN),
], $response);
} | php | public function whatYouWantAction(Request $request)
{
// app already installed
if ($this->container->getParameter('anime_db.catalog.installed')) {
return $this->redirect($this->generateUrl('home'));
}
$response = $this->getCacheTimeKeeper()->getResponse();
// response was not modified for this request
if ($response->isNotModified($request)) {
return $response;
}
if ($request->isMethod('POST')) {
$storage = $this->getRepository()->getLast();
$this->get('event_dispatcher')->dispatch(StoreEvents::INSTALL_SAMPLES, new SamplesInstall($storage));
return $this->redirect($this->generateUrl('install_end_skip', ['from' => 'install_sample']));
}
return $this->render('AnimeDbCatalogBundle:Install:what_you_want.html.twig', [
'guide' => $this->get('anime_db.api.client')->getSiteUrl(self::GUIDE_LINK_SCAN),
], $response);
} | [
"public",
"function",
"whatYouWantAction",
"(",
"Request",
"$",
"request",
")",
"{",
"// app already installed",
"if",
"(",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'anime_db.catalog.installed'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'home'",
")",
")",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"getCacheTimeKeeper",
"(",
")",
"->",
"getResponse",
"(",
")",
";",
"// response was not modified for this request",
"if",
"(",
"$",
"response",
"->",
"isNotModified",
"(",
"$",
"request",
")",
")",
"{",
"return",
"$",
"response",
";",
"}",
"if",
"(",
"$",
"request",
"->",
"isMethod",
"(",
"'POST'",
")",
")",
"{",
"$",
"storage",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"getLast",
"(",
")",
";",
"$",
"this",
"->",
"get",
"(",
"'event_dispatcher'",
")",
"->",
"dispatch",
"(",
"StoreEvents",
"::",
"INSTALL_SAMPLES",
",",
"new",
"SamplesInstall",
"(",
"$",
"storage",
")",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'install_end_skip'",
",",
"[",
"'from'",
"=>",
"'install_sample'",
"]",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'AnimeDbCatalogBundle:Install:what_you_want.html.twig'",
",",
"[",
"'guide'",
"=>",
"$",
"this",
"->",
"get",
"(",
"'anime_db.api.client'",
")",
"->",
"getSiteUrl",
"(",
"self",
"::",
"GUIDE_LINK_SCAN",
")",
",",
"]",
",",
"$",
"response",
")",
";",
"}"
] | What you want.
@param Request $request
@return Response | [
"What",
"you",
"want",
"."
] | 631b6f92a654e91bee84f46218c52cf42bdb8606 | https://github.com/anime-db/catalog-bundle/blob/631b6f92a654e91bee84f46218c52cf42bdb8606/src/Controller/InstallController.php#L131-L154 | train |
AeonDigital/PHP-Numbers | src/RealNumber.php | RealNumber.pow | public function pow($v, int $dPlaces = 0) : RealNumber
{
$d = new RealNumber($v);
return new RealNumber(bcpow($this->value(), $d->value(), $this->useDecimalPlaces($dPlaces)));
} | php | public function pow($v, int $dPlaces = 0) : RealNumber
{
$d = new RealNumber($v);
return new RealNumber(bcpow($this->value(), $d->value(), $this->useDecimalPlaces($dPlaces)));
} | [
"public",
"function",
"pow",
"(",
"$",
"v",
",",
"int",
"$",
"dPlaces",
"=",
"0",
")",
":",
"RealNumber",
"{",
"$",
"d",
"=",
"new",
"RealNumber",
"(",
"$",
"v",
")",
";",
"return",
"new",
"RealNumber",
"(",
"bcpow",
"(",
"$",
"this",
"->",
"value",
"(",
")",
",",
"$",
"d",
"->",
"value",
"(",
")",
",",
"$",
"this",
"->",
"useDecimalPlaces",
"(",
"$",
"dPlaces",
")",
")",
")",
";",
"}"
] | Eleva o valor atual pelo expoente indicado.
@param mixed $v
É esperado valores "RealNumber", "int", "float"
ou uma string numérica.
@param int $dPlaces
Total de casas decimais a serem levadas em conta.
@return RealNumber | [
"Eleva",
"o",
"valor",
"atual",
"pelo",
"expoente",
"indicado",
"."
] | 0fdb05807e72191278fc794484bf491c1307f644 | https://github.com/AeonDigital/PHP-Numbers/blob/0fdb05807e72191278fc794484bf491c1307f644/src/RealNumber.php#L639-L643 | train |
AeonDigital/PHP-Numbers | src/RealNumber.php | RealNumber.sqrt | public function sqrt(int $dPlaces = 0) : RealNumber
{
return new RealNumber(bcsqrt($this->value(), $this->useDecimalPlaces($dPlaces)));
} | php | public function sqrt(int $dPlaces = 0) : RealNumber
{
return new RealNumber(bcsqrt($this->value(), $this->useDecimalPlaces($dPlaces)));
} | [
"public",
"function",
"sqrt",
"(",
"int",
"$",
"dPlaces",
"=",
"0",
")",
":",
"RealNumber",
"{",
"return",
"new",
"RealNumber",
"(",
"bcsqrt",
"(",
"$",
"this",
"->",
"value",
"(",
")",
",",
"$",
"this",
"->",
"useDecimalPlaces",
"(",
"$",
"dPlaces",
")",
")",
")",
";",
"}"
] | Retorna a raiz do valor atual pelo operando indicado.
@param int $dPlaces
Total de casas decimais a serem levadas em conta.
@return RealNumber | [
"Retorna",
"a",
"raiz",
"do",
"valor",
"atual",
"pelo",
"operando",
"indicado",
"."
] | 0fdb05807e72191278fc794484bf491c1307f644 | https://github.com/AeonDigital/PHP-Numbers/blob/0fdb05807e72191278fc794484bf491c1307f644/src/RealNumber.php#L657-L660 | train |
jabernardo/console.php | src/Console/Application.php | Application.add | public function add($name, callable $command, $default = false) {
// Make sure to unify command name
$commandName = strtolower($name);
if (isset($this->_command[$commandName])) {
throw new \Console\Exception\Runtime('Duplicated command.');
}
if (!is_null($this->_default) && $default) {
throw new \Console\Exception\Runtime('Default command was already declared.');
}
if ($default) {
$this->_default = $command;
}
// Add command
$this->_commands[$commandName] = $command;
} | php | public function add($name, callable $command, $default = false) {
// Make sure to unify command name
$commandName = strtolower($name);
if (isset($this->_command[$commandName])) {
throw new \Console\Exception\Runtime('Duplicated command.');
}
if (!is_null($this->_default) && $default) {
throw new \Console\Exception\Runtime('Default command was already declared.');
}
if ($default) {
$this->_default = $command;
}
// Add command
$this->_commands[$commandName] = $command;
} | [
"public",
"function",
"add",
"(",
"$",
"name",
",",
"callable",
"$",
"command",
",",
"$",
"default",
"=",
"false",
")",
"{",
"// Make sure to unify command name",
"$",
"commandName",
"=",
"strtolower",
"(",
"$",
"name",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_command",
"[",
"$",
"commandName",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Console",
"\\",
"Exception",
"\\",
"Runtime",
"(",
"'Duplicated command.'",
")",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"_default",
")",
"&&",
"$",
"default",
")",
"{",
"throw",
"new",
"\\",
"Console",
"\\",
"Exception",
"\\",
"Runtime",
"(",
"'Default command was already declared.'",
")",
";",
"}",
"if",
"(",
"$",
"default",
")",
"{",
"$",
"this",
"->",
"_default",
"=",
"$",
"command",
";",
"}",
"// Add command",
"$",
"this",
"->",
"_commands",
"[",
"$",
"commandName",
"]",
"=",
"$",
"command",
";",
"}"
] | Add console command
@param string $name Command Name
@param callable $command Callable command
@param boolean $default Use as default command (false)
@return void
@throws \Console\Exception\Runtime Duplicated command registered | [
"Add",
"console",
"command"
] | a526458f4d1a525d0ccff62cd9cfcfbc5526bc9c | https://github.com/jabernardo/console.php/blob/a526458f4d1a525d0ccff62cd9cfcfbc5526bc9c/src/Console/Application.php#L73-L91 | train |
jabernardo/console.php | src/Console/Application.php | Application.get | public function get($command) {
return isset($this->_commands[$command]) ?
$this->_commands[$command] :
null;
} | php | public function get($command) {
return isset($this->_commands[$command]) ?
$this->_commands[$command] :
null;
} | [
"public",
"function",
"get",
"(",
"$",
"command",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"_commands",
"[",
"$",
"command",
"]",
")",
"?",
"$",
"this",
"->",
"_commands",
"[",
"$",
"command",
"]",
":",
"null",
";",
"}"
] | Get command callback
@access public
@param string $command
@return mixed | [
"Get",
"command",
"callback"
] | a526458f4d1a525d0ccff62cd9cfcfbc5526bc9c | https://github.com/jabernardo/console.php/blob/a526458f4d1a525d0ccff62cd9cfcfbc5526bc9c/src/Console/Application.php#L101-L105 | train |
Kris-Kuiper/sFire-Framework | src/System/Directory.php | Directory.move | public function move($directory) {
if(false === is_string($directory)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($directory)), E_USER_ERROR);
}
if(false === is_dir($directory)) {
return trigger_error(sprintf('Directory "%s" passed to %s is not an existing directory', $directory, __METHOD__), E_USER_ERROR);
}
if(false === is_writable($directory)) {
return trigger_error(sprintf('Directory "%s" passed to %s is not writable', $directory, __METHOD__), E_USER_ERROR);
}
//Add directory seperator to directory
$directory = rtrim($directory, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
if(false !== $this -> directory -> getExists()) {
if(rename($this -> directory -> getPath(), $directory . $this -> directory -> getName())) {
$this -> directory -> setPath($directory);
$this -> directory -> setBasepath($directory . $this -> directory -> getName());
}
}
return $this;
} | php | public function move($directory) {
if(false === is_string($directory)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($directory)), E_USER_ERROR);
}
if(false === is_dir($directory)) {
return trigger_error(sprintf('Directory "%s" passed to %s is not an existing directory', $directory, __METHOD__), E_USER_ERROR);
}
if(false === is_writable($directory)) {
return trigger_error(sprintf('Directory "%s" passed to %s is not writable', $directory, __METHOD__), E_USER_ERROR);
}
//Add directory seperator to directory
$directory = rtrim($directory, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
if(false !== $this -> directory -> getExists()) {
if(rename($this -> directory -> getPath(), $directory . $this -> directory -> getName())) {
$this -> directory -> setPath($directory);
$this -> directory -> setBasepath($directory . $this -> directory -> getName());
}
}
return $this;
} | [
"public",
"function",
"move",
"(",
"$",
"directory",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"directory",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"directory",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"is_dir",
"(",
"$",
"directory",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Directory \"%s\" passed to %s is not an existing directory'",
",",
"$",
"directory",
",",
"__METHOD__",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"is_writable",
"(",
"$",
"directory",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Directory \"%s\" passed to %s is not writable'",
",",
"$",
"directory",
",",
"__METHOD__",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"//Add directory seperator to directory\r",
"$",
"directory",
"=",
"rtrim",
"(",
"$",
"directory",
",",
"DIRECTORY_SEPARATOR",
")",
".",
"DIRECTORY_SEPARATOR",
";",
"if",
"(",
"false",
"!==",
"$",
"this",
"->",
"directory",
"->",
"getExists",
"(",
")",
")",
"{",
"if",
"(",
"rename",
"(",
"$",
"this",
"->",
"directory",
"->",
"getPath",
"(",
")",
",",
"$",
"directory",
".",
"$",
"this",
"->",
"directory",
"->",
"getName",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"directory",
"->",
"setPath",
"(",
"$",
"directory",
")",
";",
"$",
"this",
"->",
"directory",
"->",
"setBasepath",
"(",
"$",
"directory",
".",
"$",
"this",
"->",
"directory",
"->",
"getName",
"(",
")",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Move the current directory to a new directory including its content
@param string $directory
@return sFire\System\Directory | [
"Move",
"the",
"current",
"directory",
"to",
"a",
"new",
"directory",
"including",
"its",
"content"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/Directory.php#L83-L110 | train |
Kris-Kuiper/sFire-Framework | src/System/Directory.php | Directory.delete | public function delete() {
if(false !== $this -> directory -> getExists()) {
if(rmdir($this -> directory -> getBasepath())) {
$this -> refresh();
}
}
return $this;
} | php | public function delete() {
if(false !== $this -> directory -> getExists()) {
if(rmdir($this -> directory -> getBasepath())) {
$this -> refresh();
}
}
return $this;
} | [
"public",
"function",
"delete",
"(",
")",
"{",
"if",
"(",
"false",
"!==",
"$",
"this",
"->",
"directory",
"->",
"getExists",
"(",
")",
")",
"{",
"if",
"(",
"rmdir",
"(",
"$",
"this",
"->",
"directory",
"->",
"getBasepath",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"refresh",
"(",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Delete the current directory
@return sFire\System\Directory | [
"Delete",
"the",
"current",
"directory"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/Directory.php#L117-L127 | train |
Kris-Kuiper/sFire-Framework | src/System/Directory.php | Directory.copy | public function copy($directory) {
if(false === is_dir($directory)) {
return trigger_error(sprintf('Directory "%s" passed to %s is not an existing directory', $directory, __METHOD__), E_USER_ERROR);
}
if(false === is_writable($directory)) {
return trigger_error(sprintf('Directory "%s" passed to %s is not writable', $directory, __METHOD__), E_USER_ERROR);
}
if(false !== $this -> directory -> getExists()) {
$this -> rcopy($this -> directory -> getPath(), $directory);
}
return $this;
} | php | public function copy($directory) {
if(false === is_dir($directory)) {
return trigger_error(sprintf('Directory "%s" passed to %s is not an existing directory', $directory, __METHOD__), E_USER_ERROR);
}
if(false === is_writable($directory)) {
return trigger_error(sprintf('Directory "%s" passed to %s is not writable', $directory, __METHOD__), E_USER_ERROR);
}
if(false !== $this -> directory -> getExists()) {
$this -> rcopy($this -> directory -> getPath(), $directory);
}
return $this;
} | [
"public",
"function",
"copy",
"(",
"$",
"directory",
")",
"{",
"if",
"(",
"false",
"===",
"is_dir",
"(",
"$",
"directory",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Directory \"%s\" passed to %s is not an existing directory'",
",",
"$",
"directory",
",",
"__METHOD__",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"is_writable",
"(",
"$",
"directory",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Directory \"%s\" passed to %s is not writable'",
",",
"$",
"directory",
",",
"__METHOD__",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"!==",
"$",
"this",
"->",
"directory",
"->",
"getExists",
"(",
")",
")",
"{",
"$",
"this",
"->",
"rcopy",
"(",
"$",
"this",
"->",
"directory",
"->",
"getPath",
"(",
")",
",",
"$",
"directory",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Copy the current directory contents to a new directory including its content
@param string $directory
@return sFire\System\Directory | [
"Copy",
"the",
"current",
"directory",
"contents",
"to",
"a",
"new",
"directory",
"including",
"its",
"content"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/Directory.php#L135-L150 | train |
Kris-Kuiper/sFire-Framework | src/System/Directory.php | Directory.rename | public function rename($name) {
if(false === is_string($name)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($name)), E_USER_ERROR);
}
if(false !== $this -> directory -> getExists()) {
if(rename($this -> directory -> getPath(), $this -> directory -> getBasepath() . $name)) {
$this -> directory -> setName($name);
$this -> directory -> setPath($this -> directory -> getBasepath() . $name);
}
}
return $this;
} | php | public function rename($name) {
if(false === is_string($name)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($name)), E_USER_ERROR);
}
if(false !== $this -> directory -> getExists()) {
if(rename($this -> directory -> getPath(), $this -> directory -> getBasepath() . $name)) {
$this -> directory -> setName($name);
$this -> directory -> setPath($this -> directory -> getBasepath() . $name);
}
}
return $this;
} | [
"public",
"function",
"rename",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"name",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"name",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"!==",
"$",
"this",
"->",
"directory",
"->",
"getExists",
"(",
")",
")",
"{",
"if",
"(",
"rename",
"(",
"$",
"this",
"->",
"directory",
"->",
"getPath",
"(",
")",
",",
"$",
"this",
"->",
"directory",
"->",
"getBasepath",
"(",
")",
".",
"$",
"name",
")",
")",
"{",
"$",
"this",
"->",
"directory",
"->",
"setName",
"(",
"$",
"name",
")",
";",
"$",
"this",
"->",
"directory",
"->",
"setPath",
"(",
"$",
"this",
"->",
"directory",
"->",
"getBasepath",
"(",
")",
".",
"$",
"name",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Rename the current directory
@param string $name
@return sFire\System\Directory | [
"Rename",
"the",
"current",
"directory"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/Directory.php#L158-L174 | train |
Kris-Kuiper/sFire-Framework | src/System/Directory.php | Directory.getContent | public function getContent($type = 'default') {
if(false === is_string($type)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($type)), E_USER_ERROR);
}
if(false === is_dir($this -> directory -> getPath())) {
return trigger_error(sprintf('Directory "%s" does not exists', $this -> directory -> getPath()), E_USER_ERROR);
}
$files = array_values(array_diff(scandir($this -> directory -> getPath()), ['.', '..']));
switch($type) {
case 'array' :
return $files;
case 'object' :
return (object) $files;
case 'json' :
return json_encode($files);
default :
$content = [];
foreach($files as $file) {
if(is_dir($this -> directory -> getPath() . $file)) {
$content[] = new Directory($file);
continue;
}
$content[] = new File($file);
}
return $content;
}
} | php | public function getContent($type = 'default') {
if(false === is_string($type)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($type)), E_USER_ERROR);
}
if(false === is_dir($this -> directory -> getPath())) {
return trigger_error(sprintf('Directory "%s" does not exists', $this -> directory -> getPath()), E_USER_ERROR);
}
$files = array_values(array_diff(scandir($this -> directory -> getPath()), ['.', '..']));
switch($type) {
case 'array' :
return $files;
case 'object' :
return (object) $files;
case 'json' :
return json_encode($files);
default :
$content = [];
foreach($files as $file) {
if(is_dir($this -> directory -> getPath() . $file)) {
$content[] = new Directory($file);
continue;
}
$content[] = new File($file);
}
return $content;
}
} | [
"public",
"function",
"getContent",
"(",
"$",
"type",
"=",
"'default'",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"type",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"type",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"is_dir",
"(",
"$",
"this",
"->",
"directory",
"->",
"getPath",
"(",
")",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Directory \"%s\" does not exists'",
",",
"$",
"this",
"->",
"directory",
"->",
"getPath",
"(",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"files",
"=",
"array_values",
"(",
"array_diff",
"(",
"scandir",
"(",
"$",
"this",
"->",
"directory",
"->",
"getPath",
"(",
")",
")",
",",
"[",
"'.'",
",",
"'..'",
"]",
")",
")",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'array'",
":",
"return",
"$",
"files",
";",
"case",
"'object'",
":",
"return",
"(",
"object",
")",
"$",
"files",
";",
"case",
"'json'",
":",
"return",
"json_encode",
"(",
"$",
"files",
")",
";",
"default",
":",
"$",
"content",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"this",
"->",
"directory",
"->",
"getPath",
"(",
")",
".",
"$",
"file",
")",
")",
"{",
"$",
"content",
"[",
"]",
"=",
"new",
"Directory",
"(",
"$",
"file",
")",
";",
"continue",
";",
"}",
"$",
"content",
"[",
"]",
"=",
"new",
"File",
"(",
"$",
"file",
")",
";",
"}",
"return",
"$",
"content",
";",
"}",
"}"
] | Returns files and folders about the current directory
@param string $type
@return array|object|string | [
"Returns",
"files",
"and",
"folders",
"about",
"the",
"current",
"directory"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/Directory.php#L214-L254 | train |
Kris-Kuiper/sFire-Framework | src/System/Directory.php | Directory.chmod | public function chmod($type) {
if(false !== $this -> directory -> getExists()) {
return chmod($this -> directory -> getPath(), $type);
}
return false;
} | php | public function chmod($type) {
if(false !== $this -> directory -> getExists()) {
return chmod($this -> directory -> getPath(), $type);
}
return false;
} | [
"public",
"function",
"chmod",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"false",
"!==",
"$",
"this",
"->",
"directory",
"->",
"getExists",
"(",
")",
")",
"{",
"return",
"chmod",
"(",
"$",
"this",
"->",
"directory",
"->",
"getPath",
"(",
")",
",",
"$",
"type",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Returns true if current directory has successfully changed file mode, otherwise false
@param int|string $type
@return boolean | [
"Returns",
"true",
"if",
"current",
"directory",
"has",
"successfully",
"changed",
"file",
"mode",
"otherwise",
"false"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/Directory.php#L302-L309 | train |
Kris-Kuiper/sFire-Framework | src/System/Directory.php | Directory.chown | public function chown($username) {
if(false === is_string($username)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($username)), E_USER_ERROR);
}
if(false !== $this -> directory -> getExists()) {
return chown($this -> directory -> getPath(), $username);
}
return false;
} | php | public function chown($username) {
if(false === is_string($username)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($username)), E_USER_ERROR);
}
if(false !== $this -> directory -> getExists()) {
return chown($this -> directory -> getPath(), $username);
}
return false;
} | [
"public",
"function",
"chown",
"(",
"$",
"username",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"username",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"username",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"!==",
"$",
"this",
"->",
"directory",
"->",
"getExists",
"(",
")",
")",
"{",
"return",
"chown",
"(",
"$",
"this",
"->",
"directory",
"->",
"getPath",
"(",
")",
",",
"$",
"username",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Returns true if current directory has successfully changed owner, otherwise false
@param string $username
@return boolean | [
"Returns",
"true",
"if",
"current",
"directory",
"has",
"successfully",
"changed",
"owner",
"otherwise",
"false"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/Directory.php#L317-L328 | train |
Kris-Kuiper/sFire-Framework | src/System/Directory.php | Directory.isReadable | public function isReadable() {
if(false !== $this -> directory -> getExists()) {
$this -> refresh();
return $this -> directory -> getReadable();
}
return false;
} | php | public function isReadable() {
if(false !== $this -> directory -> getExists()) {
$this -> refresh();
return $this -> directory -> getReadable();
}
return false;
} | [
"public",
"function",
"isReadable",
"(",
")",
"{",
"if",
"(",
"false",
"!==",
"$",
"this",
"->",
"directory",
"->",
"getExists",
"(",
")",
")",
"{",
"$",
"this",
"->",
"refresh",
"(",
")",
";",
"return",
"$",
"this",
"->",
"directory",
"->",
"getReadable",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Returns boolean if the current directory is readable
@return boolean | [
"Returns",
"boolean",
"if",
"the",
"current",
"directory",
"is",
"readable"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/Directory.php#L335-L345 | train |
Kris-Kuiper/sFire-Framework | src/System/Directory.php | Directory.isWritable | public function isWritable() {
if(false !== $this -> directory -> getExists()) {
$this -> refresh();
return $this -> directory -> getWritable();
}
return false;
} | php | public function isWritable() {
if(false !== $this -> directory -> getExists()) {
$this -> refresh();
return $this -> directory -> getWritable();
}
return false;
} | [
"public",
"function",
"isWritable",
"(",
")",
"{",
"if",
"(",
"false",
"!==",
"$",
"this",
"->",
"directory",
"->",
"getExists",
"(",
")",
")",
"{",
"$",
"this",
"->",
"refresh",
"(",
")",
";",
"return",
"$",
"this",
"->",
"directory",
"->",
"getWritable",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Returns boolean if the current directory is writable
@return boolean | [
"Returns",
"boolean",
"if",
"the",
"current",
"directory",
"is",
"writable"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/Directory.php#L352-L362 | train |
Kris-Kuiper/sFire-Framework | src/System/Directory.php | Directory.refresh | public function refresh() {
$directory = new Directory($this -> directory -> getPath());
$this -> directory = $directory -> entity();
return $this;
} | php | public function refresh() {
$directory = new Directory($this -> directory -> getPath());
$this -> directory = $directory -> entity();
return $this;
} | [
"public",
"function",
"refresh",
"(",
")",
"{",
"$",
"directory",
"=",
"new",
"Directory",
"(",
"$",
"this",
"->",
"directory",
"->",
"getPath",
"(",
")",
")",
";",
"$",
"this",
"->",
"directory",
"=",
"$",
"directory",
"->",
"entity",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Drop old and create new directory entity to update information about current directory
@return sFire\System\Directory | [
"Drop",
"old",
"and",
"create",
"new",
"directory",
"entity",
"to",
"update",
"information",
"about",
"current",
"directory"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/Directory.php#L369-L375 | train |
Kris-Kuiper/sFire-Framework | src/System/Directory.php | Directory.rcopy | private function rcopy($source, $destination) {
if(false === is_string($source)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($source)), E_USER_ERROR);
}
if(false === is_string($destination)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($destination)), E_USER_ERROR);
}
if(false === is_dir($destination)) {
$tmp = new Directory($destination);
$tmp -> create();
}
$directory = opendir($source);
while(false !== ($file = readdir($directory))) {
if(false === in_array($file, ['.', '..'])) {
if(is_dir($source . DIRECTORY_SEPARATOR . $file) ) {
$this -> rcopy($source . DIRECTORY_SEPARATOR . $file, $destination . DIRECTORY_SEPARATOR . $file);
}
else {
copy($source . DIRECTORY_SEPARATOR . $file, $destination . DIRECTORY_SEPARATOR . $file);
}
}
}
closedir($directory);
} | php | private function rcopy($source, $destination) {
if(false === is_string($source)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($source)), E_USER_ERROR);
}
if(false === is_string($destination)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($destination)), E_USER_ERROR);
}
if(false === is_dir($destination)) {
$tmp = new Directory($destination);
$tmp -> create();
}
$directory = opendir($source);
while(false !== ($file = readdir($directory))) {
if(false === in_array($file, ['.', '..'])) {
if(is_dir($source . DIRECTORY_SEPARATOR . $file) ) {
$this -> rcopy($source . DIRECTORY_SEPARATOR . $file, $destination . DIRECTORY_SEPARATOR . $file);
}
else {
copy($source . DIRECTORY_SEPARATOR . $file, $destination . DIRECTORY_SEPARATOR . $file);
}
}
}
closedir($directory);
} | [
"private",
"function",
"rcopy",
"(",
"$",
"source",
",",
"$",
"destination",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"source",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"source",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"destination",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 2 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"destination",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"is_dir",
"(",
"$",
"destination",
")",
")",
"{",
"$",
"tmp",
"=",
"new",
"Directory",
"(",
"$",
"destination",
")",
";",
"$",
"tmp",
"->",
"create",
"(",
")",
";",
"}",
"$",
"directory",
"=",
"opendir",
"(",
"$",
"source",
")",
";",
"while",
"(",
"false",
"!==",
"(",
"$",
"file",
"=",
"readdir",
"(",
"$",
"directory",
")",
")",
")",
"{",
"if",
"(",
"false",
"===",
"in_array",
"(",
"$",
"file",
",",
"[",
"'.'",
",",
"'..'",
"]",
")",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"source",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
")",
")",
"{",
"$",
"this",
"->",
"rcopy",
"(",
"$",
"source",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
",",
"$",
"destination",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
")",
";",
"}",
"else",
"{",
"copy",
"(",
"$",
"source",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
",",
"$",
"destination",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
")",
";",
"}",
"}",
"}",
"closedir",
"(",
"$",
"directory",
")",
";",
"}"
] | Copy all contens of directory to an existing directory
@param string $source
@param string $destination | [
"Copy",
"all",
"contens",
"of",
"directory",
"to",
"an",
"existing",
"directory"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/Directory.php#L383-L415 | train |
Kris-Kuiper/sFire-Framework | src/Entity/Entity.php | Entity.toArray | public function toArray($set = [], $convert = true) {
$methods = get_class_methods($this);
$array = [];
if(true === is_string($set)) {
$set = [$set];
}
$set = array_flip($set);
$amount = count($set);
foreach($methods as $method) {
$chunks = explode('get', $method);
if(count($chunks) == 2) {
$key = (true === $convert) ? strtolower($chunks[1]) : $chunks[1];
if($amount === 0 || ($amount > 0 && true === isset($set[$key]))) {
$value = call_user_func_array([$this, $method], []);
if($value instanceof Container) {
$value = $value -> all();
}
if(0 === strlen(trim($key)) && ($value === null || 0 === strlen(trim($value)))) {
continue;
}
$array[$key] = $value;
}
}
}
return json_decode(json_encode($array), true);
} | php | public function toArray($set = [], $convert = true) {
$methods = get_class_methods($this);
$array = [];
if(true === is_string($set)) {
$set = [$set];
}
$set = array_flip($set);
$amount = count($set);
foreach($methods as $method) {
$chunks = explode('get', $method);
if(count($chunks) == 2) {
$key = (true === $convert) ? strtolower($chunks[1]) : $chunks[1];
if($amount === 0 || ($amount > 0 && true === isset($set[$key]))) {
$value = call_user_func_array([$this, $method], []);
if($value instanceof Container) {
$value = $value -> all();
}
if(0 === strlen(trim($key)) && ($value === null || 0 === strlen(trim($value)))) {
continue;
}
$array[$key] = $value;
}
}
}
return json_decode(json_encode($array), true);
} | [
"public",
"function",
"toArray",
"(",
"$",
"set",
"=",
"[",
"]",
",",
"$",
"convert",
"=",
"true",
")",
"{",
"$",
"methods",
"=",
"get_class_methods",
"(",
"$",
"this",
")",
";",
"$",
"array",
"=",
"[",
"]",
";",
"if",
"(",
"true",
"===",
"is_string",
"(",
"$",
"set",
")",
")",
"{",
"$",
"set",
"=",
"[",
"$",
"set",
"]",
";",
"}",
"$",
"set",
"=",
"array_flip",
"(",
"$",
"set",
")",
";",
"$",
"amount",
"=",
"count",
"(",
"$",
"set",
")",
";",
"foreach",
"(",
"$",
"methods",
"as",
"$",
"method",
")",
"{",
"$",
"chunks",
"=",
"explode",
"(",
"'get'",
",",
"$",
"method",
")",
";",
"if",
"(",
"count",
"(",
"$",
"chunks",
")",
"==",
"2",
")",
"{",
"$",
"key",
"=",
"(",
"true",
"===",
"$",
"convert",
")",
"?",
"strtolower",
"(",
"$",
"chunks",
"[",
"1",
"]",
")",
":",
"$",
"chunks",
"[",
"1",
"]",
";",
"if",
"(",
"$",
"amount",
"===",
"0",
"||",
"(",
"$",
"amount",
">",
"0",
"&&",
"true",
"===",
"isset",
"(",
"$",
"set",
"[",
"$",
"key",
"]",
")",
")",
")",
"{",
"$",
"value",
"=",
"call_user_func_array",
"(",
"[",
"$",
"this",
",",
"$",
"method",
"]",
",",
"[",
"]",
")",
";",
"if",
"(",
"$",
"value",
"instanceof",
"Container",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"->",
"all",
"(",
")",
";",
"}",
"if",
"(",
"0",
"===",
"strlen",
"(",
"trim",
"(",
"$",
"key",
")",
")",
"&&",
"(",
"$",
"value",
"===",
"null",
"||",
"0",
"===",
"strlen",
"(",
"trim",
"(",
"$",
"value",
")",
")",
")",
")",
"{",
"continue",
";",
"}",
"$",
"array",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"return",
"json_decode",
"(",
"json_encode",
"(",
"$",
"array",
")",
",",
"true",
")",
";",
"}"
] | Converts all getters to an Array
@param array $set
@param boolean $convert
@return array | [
"Converts",
"all",
"getters",
"to",
"an",
"Array"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Entity/Entity.php#L23-L61 | train |
Linkvalue-Interne/MajoraFrameworkExtraBundle | src/Majora/Framework/Date/Clock.php | Clock.now | public function now($format = null)
{
$date = $this->currentDate
? clone $this->currentDate
: ($this->currentDate = new \DateTime())
;
return empty($format) ?
$date :
$date->format($format)
;
} | php | public function now($format = null)
{
$date = $this->currentDate
? clone $this->currentDate
: ($this->currentDate = new \DateTime())
;
return empty($format) ?
$date :
$date->format($format)
;
} | [
"public",
"function",
"now",
"(",
"$",
"format",
"=",
"null",
")",
"{",
"$",
"date",
"=",
"$",
"this",
"->",
"currentDate",
"?",
"clone",
"$",
"this",
"->",
"currentDate",
":",
"(",
"$",
"this",
"->",
"currentDate",
"=",
"new",
"\\",
"DateTime",
"(",
")",
")",
";",
"return",
"empty",
"(",
"$",
"format",
")",
"?",
"$",
"date",
":",
"$",
"date",
"->",
"format",
"(",
"$",
"format",
")",
";",
"}"
] | return current date
@param string $format optionnal date format
@return \DateTime | [
"return",
"current",
"date"
] | 6f368380cfc39d27fafb0844e9a53b4d86d7c034 | https://github.com/Linkvalue-Interne/MajoraFrameworkExtraBundle/blob/6f368380cfc39d27fafb0844e9a53b4d86d7c034/src/Majora/Framework/Date/Clock.php#L44-L55 | train |
gplcart/cli | controllers/commands/Currency.php | Currency.cmdUpdateCurrency | public function cmdUpdateCurrency()
{
$params = $this->getParam();
if (empty($params[0]) || count($params) < 2) {
$this->errorAndExit($this->text('Invalid command'));
}
$this->setSubmitted(null, $params);
$this->setSubmitted('update', $params[0]);
$this->validateComponent('currency');
$this->updateCurrency($params[0]);
$this->output();
} | php | public function cmdUpdateCurrency()
{
$params = $this->getParam();
if (empty($params[0]) || count($params) < 2) {
$this->errorAndExit($this->text('Invalid command'));
}
$this->setSubmitted(null, $params);
$this->setSubmitted('update', $params[0]);
$this->validateComponent('currency');
$this->updateCurrency($params[0]);
$this->output();
} | [
"public",
"function",
"cmdUpdateCurrency",
"(",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"getParam",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"params",
"[",
"0",
"]",
")",
"||",
"count",
"(",
"$",
"params",
")",
"<",
"2",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid command'",
")",
")",
";",
"}",
"$",
"this",
"->",
"setSubmitted",
"(",
"null",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"setSubmitted",
"(",
"'update'",
",",
"$",
"params",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'currency'",
")",
";",
"$",
"this",
"->",
"updateCurrency",
"(",
"$",
"params",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "currency-update" | [
"Callback",
"for",
"currency",
"-",
"update"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Currency.php#L40-L53 | train |
gplcart/cli | controllers/commands/Currency.php | Currency.cmdGetCurrency | public function cmdGetCurrency()
{
$list = $this->getListCurrency();
$this->outputFormat($list);
$this->outputFormatTableCurrency($list);
$this->output();
} | php | public function cmdGetCurrency()
{
$list = $this->getListCurrency();
$this->outputFormat($list);
$this->outputFormatTableCurrency($list);
$this->output();
} | [
"public",
"function",
"cmdGetCurrency",
"(",
")",
"{",
"$",
"list",
"=",
"$",
"this",
"->",
"getListCurrency",
"(",
")",
";",
"$",
"this",
"->",
"outputFormat",
"(",
"$",
"list",
")",
";",
"$",
"this",
"->",
"outputFormatTableCurrency",
"(",
"$",
"list",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "currency-get" command | [
"Callback",
"for",
"currency",
"-",
"get",
"command"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Currency.php#L72-L78 | train |
gplcart/cli | controllers/commands/Currency.php | Currency.cmdDeleteCurrency | public function cmdDeleteCurrency()
{
$id = $this->getParam(0);
$all = $this->getParam('all');
if (empty($id) && empty($all)) {
$this->errorAndExit($this->text('Invalid command'));
}
$result = false;
if (!empty($id)) {
$result = $this->currency->delete($id);
} else if (!empty($all)) {
$deleted = $count = 0;
foreach ($this->currency->getList(array('in_database' => true)) as $currency) {
$count++;
$deleted += (int) $this->currency->delete($currency['code']);
}
$result = ($count == $deleted);
}
if (empty($result)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->output();
} | php | public function cmdDeleteCurrency()
{
$id = $this->getParam(0);
$all = $this->getParam('all');
if (empty($id) && empty($all)) {
$this->errorAndExit($this->text('Invalid command'));
}
$result = false;
if (!empty($id)) {
$result = $this->currency->delete($id);
} else if (!empty($all)) {
$deleted = $count = 0;
foreach ($this->currency->getList(array('in_database' => true)) as $currency) {
$count++;
$deleted += (int) $this->currency->delete($currency['code']);
}
$result = ($count == $deleted);
}
if (empty($result)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->output();
} | [
"public",
"function",
"cmdDeleteCurrency",
"(",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"getParam",
"(",
"0",
")",
";",
"$",
"all",
"=",
"$",
"this",
"->",
"getParam",
"(",
"'all'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
"&&",
"empty",
"(",
"$",
"all",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid command'",
")",
")",
";",
"}",
"$",
"result",
"=",
"false",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"id",
")",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"currency",
"->",
"delete",
"(",
"$",
"id",
")",
";",
"}",
"else",
"if",
"(",
"!",
"empty",
"(",
"$",
"all",
")",
")",
"{",
"$",
"deleted",
"=",
"$",
"count",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"currency",
"->",
"getList",
"(",
"array",
"(",
"'in_database'",
"=>",
"true",
")",
")",
"as",
"$",
"currency",
")",
"{",
"$",
"count",
"++",
";",
"$",
"deleted",
"+=",
"(",
"int",
")",
"$",
"this",
"->",
"currency",
"->",
"delete",
"(",
"$",
"currency",
"[",
"'code'",
"]",
")",
";",
"}",
"$",
"result",
"=",
"(",
"$",
"count",
"==",
"$",
"deleted",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"result",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Unexpected result'",
")",
")",
";",
"}",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "currency-delete" command | [
"Callback",
"for",
"currency",
"-",
"delete",
"command"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Currency.php#L83-L110 | train |
gplcart/cli | controllers/commands/Currency.php | Currency.outputFormatTableCurrency | protected function outputFormatTableCurrency(array $items)
{
$header = array(
$this->text('Code'),
$this->text('Name'),
$this->text('Symbol'),
$this->text('Conversion rate'),
$this->text('In database'),
$this->text('Enabled')
);
$rows = array();
foreach ($items as $item) {
$rows[] = array(
$item['code'],
$this->text($item['name']),
$item['symbol'],
$item['conversion_rate'],
empty($item['in_database']) ? $this->text('No') : $this->text('Yes'),
empty($item['status']) ? $this->text('No') : $this->text('Yes'),
);
}
$this->outputFormatTable($rows, $header);
} | php | protected function outputFormatTableCurrency(array $items)
{
$header = array(
$this->text('Code'),
$this->text('Name'),
$this->text('Symbol'),
$this->text('Conversion rate'),
$this->text('In database'),
$this->text('Enabled')
);
$rows = array();
foreach ($items as $item) {
$rows[] = array(
$item['code'],
$this->text($item['name']),
$item['symbol'],
$item['conversion_rate'],
empty($item['in_database']) ? $this->text('No') : $this->text('Yes'),
empty($item['status']) ? $this->text('No') : $this->text('Yes'),
);
}
$this->outputFormatTable($rows, $header);
} | [
"protected",
"function",
"outputFormatTableCurrency",
"(",
"array",
"$",
"items",
")",
"{",
"$",
"header",
"=",
"array",
"(",
"$",
"this",
"->",
"text",
"(",
"'Code'",
")",
",",
"$",
"this",
"->",
"text",
"(",
"'Name'",
")",
",",
"$",
"this",
"->",
"text",
"(",
"'Symbol'",
")",
",",
"$",
"this",
"->",
"text",
"(",
"'Conversion rate'",
")",
",",
"$",
"this",
"->",
"text",
"(",
"'In database'",
")",
",",
"$",
"this",
"->",
"text",
"(",
"'Enabled'",
")",
")",
";",
"$",
"rows",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"$",
"rows",
"[",
"]",
"=",
"array",
"(",
"$",
"item",
"[",
"'code'",
"]",
",",
"$",
"this",
"->",
"text",
"(",
"$",
"item",
"[",
"'name'",
"]",
")",
",",
"$",
"item",
"[",
"'symbol'",
"]",
",",
"$",
"item",
"[",
"'conversion_rate'",
"]",
",",
"empty",
"(",
"$",
"item",
"[",
"'in_database'",
"]",
")",
"?",
"$",
"this",
"->",
"text",
"(",
"'No'",
")",
":",
"$",
"this",
"->",
"text",
"(",
"'Yes'",
")",
",",
"empty",
"(",
"$",
"item",
"[",
"'status'",
"]",
")",
"?",
"$",
"this",
"->",
"text",
"(",
"'No'",
")",
":",
"$",
"this",
"->",
"text",
"(",
"'Yes'",
")",
",",
")",
";",
"}",
"$",
"this",
"->",
"outputFormatTable",
"(",
"$",
"rows",
",",
"$",
"header",
")",
";",
"}"
] | Output formatted table
@param array $items | [
"Output",
"formatted",
"table"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Currency.php#L139-L164 | train |
gplcart/cli | controllers/commands/Currency.php | Currency.submitAddCurrency | protected function submitAddCurrency()
{
$this->setSubmitted(null, $this->getParam());
$this->validateComponent('currency');
$this->addCurrency();
} | php | protected function submitAddCurrency()
{
$this->setSubmitted(null, $this->getParam());
$this->validateComponent('currency');
$this->addCurrency();
} | [
"protected",
"function",
"submitAddCurrency",
"(",
")",
"{",
"$",
"this",
"->",
"setSubmitted",
"(",
"null",
",",
"$",
"this",
"->",
"getParam",
"(",
")",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'currency'",
")",
";",
"$",
"this",
"->",
"addCurrency",
"(",
")",
";",
"}"
] | Add a currency at once | [
"Add",
"a",
"currency",
"at",
"once"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Currency.php#L190-L195 | train |
gplcart/cli | controllers/commands/Currency.php | Currency.wizardAddCurrency | protected function wizardAddCurrency()
{
// Required
$this->validatePrompt('code', $this->text('Code'), 'currency');
$this->validatePrompt('name', $this->text('Name'), 'currency');
$this->validatePrompt('symbol', $this->text('Symbol'), 'currency');
$this->validatePrompt('major_unit', $this->text('Major unit'), 'currency');
$this->validatePrompt('minor_unit', $this->text('Minor unit'), 'currency');
$this->validatePrompt('numeric_code', $this->text('Numeric code'), 'currency');
// Optional
$this->validatePrompt('status', $this->text('Status'), 'currency', 0);
$this->validatePrompt('default', $this->text('Default'), 'currency', 0);
$this->validatePrompt('decimals', $this->text('Decimals'), 'currency', 2);
$this->validatePrompt('rounding_step', $this->text('Rounding step'), 'currency', 0);
$this->validatePrompt('conversion_rate', $this->text('Conversion rate'), 'currency', 1);
$this->validatePrompt('decimal_separator', $this->text('Decimal separator'), 'currency', '.');
$this->validatePrompt('thousands_separator', $this->text('Thousands separator'), 'currency', ',');
$this->validatePrompt('template', $this->text('Template'), 'currency', '%symbol%price');
$this->validateComponent('currency');
$this->addCurrency();
} | php | protected function wizardAddCurrency()
{
// Required
$this->validatePrompt('code', $this->text('Code'), 'currency');
$this->validatePrompt('name', $this->text('Name'), 'currency');
$this->validatePrompt('symbol', $this->text('Symbol'), 'currency');
$this->validatePrompt('major_unit', $this->text('Major unit'), 'currency');
$this->validatePrompt('minor_unit', $this->text('Minor unit'), 'currency');
$this->validatePrompt('numeric_code', $this->text('Numeric code'), 'currency');
// Optional
$this->validatePrompt('status', $this->text('Status'), 'currency', 0);
$this->validatePrompt('default', $this->text('Default'), 'currency', 0);
$this->validatePrompt('decimals', $this->text('Decimals'), 'currency', 2);
$this->validatePrompt('rounding_step', $this->text('Rounding step'), 'currency', 0);
$this->validatePrompt('conversion_rate', $this->text('Conversion rate'), 'currency', 1);
$this->validatePrompt('decimal_separator', $this->text('Decimal separator'), 'currency', '.');
$this->validatePrompt('thousands_separator', $this->text('Thousands separator'), 'currency', ',');
$this->validatePrompt('template', $this->text('Template'), 'currency', '%symbol%price');
$this->validateComponent('currency');
$this->addCurrency();
} | [
"protected",
"function",
"wizardAddCurrency",
"(",
")",
"{",
"// Required",
"$",
"this",
"->",
"validatePrompt",
"(",
"'code'",
",",
"$",
"this",
"->",
"text",
"(",
"'Code'",
")",
",",
"'currency'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'name'",
",",
"$",
"this",
"->",
"text",
"(",
"'Name'",
")",
",",
"'currency'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'symbol'",
",",
"$",
"this",
"->",
"text",
"(",
"'Symbol'",
")",
",",
"'currency'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'major_unit'",
",",
"$",
"this",
"->",
"text",
"(",
"'Major unit'",
")",
",",
"'currency'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'minor_unit'",
",",
"$",
"this",
"->",
"text",
"(",
"'Minor unit'",
")",
",",
"'currency'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'numeric_code'",
",",
"$",
"this",
"->",
"text",
"(",
"'Numeric code'",
")",
",",
"'currency'",
")",
";",
"// Optional",
"$",
"this",
"->",
"validatePrompt",
"(",
"'status'",
",",
"$",
"this",
"->",
"text",
"(",
"'Status'",
")",
",",
"'currency'",
",",
"0",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'default'",
",",
"$",
"this",
"->",
"text",
"(",
"'Default'",
")",
",",
"'currency'",
",",
"0",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'decimals'",
",",
"$",
"this",
"->",
"text",
"(",
"'Decimals'",
")",
",",
"'currency'",
",",
"2",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'rounding_step'",
",",
"$",
"this",
"->",
"text",
"(",
"'Rounding step'",
")",
",",
"'currency'",
",",
"0",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'conversion_rate'",
",",
"$",
"this",
"->",
"text",
"(",
"'Conversion rate'",
")",
",",
"'currency'",
",",
"1",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'decimal_separator'",
",",
"$",
"this",
"->",
"text",
"(",
"'Decimal separator'",
")",
",",
"'currency'",
",",
"'.'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'thousands_separator'",
",",
"$",
"this",
"->",
"text",
"(",
"'Thousands separator'",
")",
",",
"'currency'",
",",
"','",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'template'",
",",
"$",
"this",
"->",
"text",
"(",
"'Template'",
")",
",",
"'currency'",
",",
"'%symbol%price'",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'currency'",
")",
";",
"$",
"this",
"->",
"addCurrency",
"(",
")",
";",
"}"
] | Adds a currency step by step | [
"Adds",
"a",
"currency",
"step",
"by",
"step"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Currency.php#L200-L222 | train |
dittertp/Puzzle | src/Puzzle/Client.php | Client.init | protected function init()
{
$handle = curl_init();
$this->handle = $handle;
$this->setSerializer(new DefaultSerializer());
$this->scheme = self::SCHEME_PLAIN;
$this->httpOptions = array();
$this->httpOptions[CURLOPT_RETURNTRANSFER] = true;
$this->httpOptions[CURLOPT_FOLLOWLOCATION] = false;
} | php | protected function init()
{
$handle = curl_init();
$this->handle = $handle;
$this->setSerializer(new DefaultSerializer());
$this->scheme = self::SCHEME_PLAIN;
$this->httpOptions = array();
$this->httpOptions[CURLOPT_RETURNTRANSFER] = true;
$this->httpOptions[CURLOPT_FOLLOWLOCATION] = false;
} | [
"protected",
"function",
"init",
"(",
")",
"{",
"$",
"handle",
"=",
"curl_init",
"(",
")",
";",
"$",
"this",
"->",
"handle",
"=",
"$",
"handle",
";",
"$",
"this",
"->",
"setSerializer",
"(",
"new",
"DefaultSerializer",
"(",
")",
")",
";",
"$",
"this",
"->",
"scheme",
"=",
"self",
"::",
"SCHEME_PLAIN",
";",
"$",
"this",
"->",
"httpOptions",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"httpOptions",
"[",
"CURLOPT_RETURNTRANSFER",
"]",
"=",
"true",
";",
"$",
"this",
"->",
"httpOptions",
"[",
"CURLOPT_FOLLOWLOCATION",
"]",
"=",
"false",
";",
"}"
] | initialize default values
@return void
@throws Exceptions\ServerErrorException | [
"initialize",
"default",
"values"
] | cb3dfd64b0df8610c054dbb43b242fbf2cf668a0 | https://github.com/dittertp/Puzzle/blob/cb3dfd64b0df8610c054dbb43b242fbf2cf668a0/src/Puzzle/Client.php#L125-L136 | train |
dittertp/Puzzle | src/Puzzle/Client.php | Client.setHost | protected function setHost($host, $port = null)
{
$this->host = $host;
if ($port !== null) {
if (is_numeric($port)) {
$this->port = (int) $port;
} else {
throw new ConfigurationException("Port '{$port}' is not numeric");
}
}
} | php | protected function setHost($host, $port = null)
{
$this->host = $host;
if ($port !== null) {
if (is_numeric($port)) {
$this->port = (int) $port;
} else {
throw new ConfigurationException("Port '{$port}' is not numeric");
}
}
} | [
"protected",
"function",
"setHost",
"(",
"$",
"host",
",",
"$",
"port",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"host",
"=",
"$",
"host",
";",
"if",
"(",
"$",
"port",
"!==",
"null",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"port",
")",
")",
"{",
"$",
"this",
"->",
"port",
"=",
"(",
"int",
")",
"$",
"port",
";",
"}",
"else",
"{",
"throw",
"new",
"ConfigurationException",
"(",
"\"Port '{$port}' is not numeric\"",
")",
";",
"}",
"}",
"}"
] | Sets hostname and optional port
@param string $host the hostname
@param mixed $port the port
@return void
@throws \Puzzle\Exceptions\ConfigurationException | [
"Sets",
"hostname",
"and",
"optional",
"port"
] | cb3dfd64b0df8610c054dbb43b242fbf2cf668a0 | https://github.com/dittertp/Puzzle/blob/cb3dfd64b0df8610c054dbb43b242fbf2cf668a0/src/Puzzle/Client.php#L192-L202 | train |
dittertp/Puzzle | src/Puzzle/Client.php | Client.performRequest | public function performRequest($method, $uri, $params = null, $body = null)
{
try {
// serialize(json) body if it's not already a string
if ($body !== null) {
$body = $this->getSerializer()->serialize($body);
}
return $this->processRequest(
$method,
$uri,
$params,
$body
);
} catch (ClientErrorResponseException $exception) {
throw $exception;
} catch (ServerErrorResponseException $exception) {
throw $exception;
}
} | php | public function performRequest($method, $uri, $params = null, $body = null)
{
try {
// serialize(json) body if it's not already a string
if ($body !== null) {
$body = $this->getSerializer()->serialize($body);
}
return $this->processRequest(
$method,
$uri,
$params,
$body
);
} catch (ClientErrorResponseException $exception) {
throw $exception;
} catch (ServerErrorResponseException $exception) {
throw $exception;
}
} | [
"public",
"function",
"performRequest",
"(",
"$",
"method",
",",
"$",
"uri",
",",
"$",
"params",
"=",
"null",
",",
"$",
"body",
"=",
"null",
")",
"{",
"try",
"{",
"// serialize(json) body if it's not already a string",
"if",
"(",
"$",
"body",
"!==",
"null",
")",
"{",
"$",
"body",
"=",
"$",
"this",
"->",
"getSerializer",
"(",
")",
"->",
"serialize",
"(",
"$",
"body",
")",
";",
"}",
"return",
"$",
"this",
"->",
"processRequest",
"(",
"$",
"method",
",",
"$",
"uri",
",",
"$",
"params",
",",
"$",
"body",
")",
";",
"}",
"catch",
"(",
"ClientErrorResponseException",
"$",
"exception",
")",
"{",
"throw",
"$",
"exception",
";",
"}",
"catch",
"(",
"ServerErrorResponseException",
"$",
"exception",
")",
"{",
"throw",
"$",
"exception",
";",
"}",
"}"
] | performs the request
@param string $method request method
@param string $uri uri string
@param mixed $params optional query string parameters
@param mixed $body "post" body
@return mixed
@throws \Puzzle\Exceptions\ServerErrorResponseException
@throws \Puzzle\Exceptions\ClientErrorResponseException | [
"performs",
"the",
"request"
] | cb3dfd64b0df8610c054dbb43b242fbf2cf668a0 | https://github.com/dittertp/Puzzle/blob/cb3dfd64b0df8610c054dbb43b242fbf2cf668a0/src/Puzzle/Client.php#L236-L255 | train |
dittertp/Puzzle | src/Puzzle/Client.php | Client.get | public function get($uri, $params = null, $body = null)
{
return $this->performRequest("get", $uri, $params, $body);
} | php | public function get($uri, $params = null, $body = null)
{
return $this->performRequest("get", $uri, $params, $body);
} | [
"public",
"function",
"get",
"(",
"$",
"uri",
",",
"$",
"params",
"=",
"null",
",",
"$",
"body",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"performRequest",
"(",
"\"get\"",
",",
"$",
"uri",
",",
"$",
"params",
",",
"$",
"body",
")",
";",
"}"
] | perform a get request
@param string $uri uri string
@param mixed $params optional query string parameters
@param mixed $body the "post" body
@return mixed
@throws ClientErrorResponseException
@throws ServerErrorResponseException
@throws \Exception | [
"perform",
"a",
"get",
"request"
] | cb3dfd64b0df8610c054dbb43b242fbf2cf668a0 | https://github.com/dittertp/Puzzle/blob/cb3dfd64b0df8610c054dbb43b242fbf2cf668a0/src/Puzzle/Client.php#L269-L272 | train |
dittertp/Puzzle | src/Puzzle/Client.php | Client.put | public function put($uri, $params = null, $body = null)
{
return $this->performRequest("put", $uri, $params, $body);
} | php | public function put($uri, $params = null, $body = null)
{
return $this->performRequest("put", $uri, $params, $body);
} | [
"public",
"function",
"put",
"(",
"$",
"uri",
",",
"$",
"params",
"=",
"null",
",",
"$",
"body",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"performRequest",
"(",
"\"put\"",
",",
"$",
"uri",
",",
"$",
"params",
",",
"$",
"body",
")",
";",
"}"
] | perform a put request
@param string $uri uri string
@param mixed $params optional query string parameters
@param mixed $body the "post" body
@return mixed
@throws ClientErrorResponseException
@throws ServerErrorResponseException
@throws \Exception | [
"perform",
"a",
"put",
"request"
] | cb3dfd64b0df8610c054dbb43b242fbf2cf668a0 | https://github.com/dittertp/Puzzle/blob/cb3dfd64b0df8610c054dbb43b242fbf2cf668a0/src/Puzzle/Client.php#L286-L289 | train |
dittertp/Puzzle | src/Puzzle/Client.php | Client.post | public function post($uri, $params = null, $body = null)
{
return $this->performRequest("post", $uri, $params, $body);
} | php | public function post($uri, $params = null, $body = null)
{
return $this->performRequest("post", $uri, $params, $body);
} | [
"public",
"function",
"post",
"(",
"$",
"uri",
",",
"$",
"params",
"=",
"null",
",",
"$",
"body",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"performRequest",
"(",
"\"post\"",
",",
"$",
"uri",
",",
"$",
"params",
",",
"$",
"body",
")",
";",
"}"
] | perform a post request
@param string $uri uri string
@param mixed $params optional query string parameters
@param mixed $body the "post" body
@return mixed
@throws ClientErrorResponseException
@throws ServerErrorResponseException
@throws \Exception | [
"perform",
"a",
"post",
"request"
] | cb3dfd64b0df8610c054dbb43b242fbf2cf668a0 | https://github.com/dittertp/Puzzle/blob/cb3dfd64b0df8610c054dbb43b242fbf2cf668a0/src/Puzzle/Client.php#L303-L306 | train |
dittertp/Puzzle | src/Puzzle/Client.php | Client.patch | public function patch($uri, $params = null, $body = null)
{
return $this->performRequest("patch", $uri, $params, $body);
} | php | public function patch($uri, $params = null, $body = null)
{
return $this->performRequest("patch", $uri, $params, $body);
} | [
"public",
"function",
"patch",
"(",
"$",
"uri",
",",
"$",
"params",
"=",
"null",
",",
"$",
"body",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"performRequest",
"(",
"\"patch\"",
",",
"$",
"uri",
",",
"$",
"params",
",",
"$",
"body",
")",
";",
"}"
] | perform a patch
@param string $uri uri string
@param mixed $params optional query string parameters
@param mixed $body the "post" body
@return mixed
@throws ClientErrorResponseException
@throws ServerErrorResponseException
@throws \Exception | [
"perform",
"a",
"patch"
] | cb3dfd64b0df8610c054dbb43b242fbf2cf668a0 | https://github.com/dittertp/Puzzle/blob/cb3dfd64b0df8610c054dbb43b242fbf2cf668a0/src/Puzzle/Client.php#L320-L323 | train |
dittertp/Puzzle | src/Puzzle/Client.php | Client.head | public function head($uri, $params = null, $body = null)
{
return $this->performRequest("head", $uri, $params, $body);
} | php | public function head($uri, $params = null, $body = null)
{
return $this->performRequest("head", $uri, $params, $body);
} | [
"public",
"function",
"head",
"(",
"$",
"uri",
",",
"$",
"params",
"=",
"null",
",",
"$",
"body",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"performRequest",
"(",
"\"head\"",
",",
"$",
"uri",
",",
"$",
"params",
",",
"$",
"body",
")",
";",
"}"
] | perform a head request
@param string $uri uri string
@param mixed $params optional query string parameters
@param mixed $body the "post" body
@return mixed
@throws ClientErrorResponseException
@throws ServerErrorResponseException
@throws \Exception | [
"perform",
"a",
"head",
"request"
] | cb3dfd64b0df8610c054dbb43b242fbf2cf668a0 | https://github.com/dittertp/Puzzle/blob/cb3dfd64b0df8610c054dbb43b242fbf2cf668a0/src/Puzzle/Client.php#L337-L340 | train |
dittertp/Puzzle | src/Puzzle/Client.php | Client.delete | public function delete($uri, $params = null, $body = null)
{
return $this->performRequest("delete", $uri, $params, $body);
} | php | public function delete($uri, $params = null, $body = null)
{
return $this->performRequest("delete", $uri, $params, $body);
} | [
"public",
"function",
"delete",
"(",
"$",
"uri",
",",
"$",
"params",
"=",
"null",
",",
"$",
"body",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"performRequest",
"(",
"\"delete\"",
",",
"$",
"uri",
",",
"$",
"params",
",",
"$",
"body",
")",
";",
"}"
] | perform a delete request
@param string $uri uri string
@param mixed $params optional query string parameters
@param mixed $body the "post" body
@return mixed
@throws ClientErrorResponseException
@throws ServerErrorResponseException
@throws \Exception | [
"perform",
"a",
"delete",
"request"
] | cb3dfd64b0df8610c054dbb43b242fbf2cf668a0 | https://github.com/dittertp/Puzzle/blob/cb3dfd64b0df8610c054dbb43b242fbf2cf668a0/src/Puzzle/Client.php#L354-L357 | train |
dittertp/Puzzle | src/Puzzle/Client.php | Client.processRequest | protected function processRequest($method, $uri, $params = null, $body = null)
{
$methodString = $this->getMethod($method);
if (method_exists($this, $methodString)) {
return $this->$methodString($method, $uri, $params, $body);
} else {
throw new InvalidRequestMethodException("request method '{$method}' not implemented");
}
} | php | protected function processRequest($method, $uri, $params = null, $body = null)
{
$methodString = $this->getMethod($method);
if (method_exists($this, $methodString)) {
return $this->$methodString($method, $uri, $params, $body);
} else {
throw new InvalidRequestMethodException("request method '{$method}' not implemented");
}
} | [
"protected",
"function",
"processRequest",
"(",
"$",
"method",
",",
"$",
"uri",
",",
"$",
"params",
"=",
"null",
",",
"$",
"body",
"=",
"null",
")",
"{",
"$",
"methodString",
"=",
"$",
"this",
"->",
"getMethod",
"(",
"$",
"method",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"methodString",
")",
")",
"{",
"return",
"$",
"this",
"->",
"$",
"methodString",
"(",
"$",
"method",
",",
"$",
"uri",
",",
"$",
"params",
",",
"$",
"body",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"InvalidRequestMethodException",
"(",
"\"request method '{$method}' not implemented\"",
")",
";",
"}",
"}"
] | precess the request
@param string $method the request method
@param string $uri the uri string
@param mixed $params the optional query string parameters
@param string $body the (post) body
@return mixed
@throws Exceptions\InvalidRequestMethodException | [
"precess",
"the",
"request"
] | cb3dfd64b0df8610c054dbb43b242fbf2cf668a0 | https://github.com/dittertp/Puzzle/blob/cb3dfd64b0df8610c054dbb43b242fbf2cf668a0/src/Puzzle/Client.php#L370-L379 | train |
dittertp/Puzzle | src/Puzzle/Client.php | Client.getRequest | protected function getRequest($method, $uri, $params, $body)
{
// get requests has no specific necessary requirements
return $this->execute($method, $uri, $params, $body);
} | php | protected function getRequest($method, $uri, $params, $body)
{
// get requests has no specific necessary requirements
return $this->execute($method, $uri, $params, $body);
} | [
"protected",
"function",
"getRequest",
"(",
"$",
"method",
",",
"$",
"uri",
",",
"$",
"params",
",",
"$",
"body",
")",
"{",
"// get requests has no specific necessary requirements",
"return",
"$",
"this",
"->",
"execute",
"(",
"$",
"method",
",",
"$",
"uri",
",",
"$",
"params",
",",
"$",
"body",
")",
";",
"}"
] | get request implementation
@param string $method the request method
@param string $uri the uri
@param mixed $params optional query string parameters
@param string $body body/post parameters
@return string
@throws \Puzzle\Exceptions\InvalidRequestException | [
"get",
"request",
"implementation"
] | cb3dfd64b0df8610c054dbb43b242fbf2cf668a0 | https://github.com/dittertp/Puzzle/blob/cb3dfd64b0df8610c054dbb43b242fbf2cf668a0/src/Puzzle/Client.php#L410-L415 | train |
dittertp/Puzzle | src/Puzzle/Client.php | Client.deleteRequest | protected function deleteRequest($method, $uri, $params, $body)
{
return $this->execute($method, $uri, $params, $body);
} | php | protected function deleteRequest($method, $uri, $params, $body)
{
return $this->execute($method, $uri, $params, $body);
} | [
"protected",
"function",
"deleteRequest",
"(",
"$",
"method",
",",
"$",
"uri",
",",
"$",
"params",
",",
"$",
"body",
")",
"{",
"return",
"$",
"this",
"->",
"execute",
"(",
"$",
"method",
",",
"$",
"uri",
",",
"$",
"params",
",",
"$",
"body",
")",
";",
"}"
] | delete request implementation
@param string $method the request method
@param string $uri the uri
@param mixed $params optional query string parameters
@param string $body body/post parameters
@return string
@throws \Puzzle\Exceptions\InvalidRequestException | [
"delete",
"request",
"implementation"
] | cb3dfd64b0df8610c054dbb43b242fbf2cf668a0 | https://github.com/dittertp/Puzzle/blob/cb3dfd64b0df8610c054dbb43b242fbf2cf668a0/src/Puzzle/Client.php#L428-L431 | train |
dittertp/Puzzle | src/Puzzle/Client.php | Client.headRequest | protected function headRequest($method, $uri, $params, $body)
{
// head requests has no specific necessary requirements
return $this->execute($method, $uri, $params, $body);
} | php | protected function headRequest($method, $uri, $params, $body)
{
// head requests has no specific necessary requirements
return $this->execute($method, $uri, $params, $body);
} | [
"protected",
"function",
"headRequest",
"(",
"$",
"method",
",",
"$",
"uri",
",",
"$",
"params",
",",
"$",
"body",
")",
"{",
"// head requests has no specific necessary requirements",
"return",
"$",
"this",
"->",
"execute",
"(",
"$",
"method",
",",
"$",
"uri",
",",
"$",
"params",
",",
"$",
"body",
")",
";",
"}"
] | head request implementation
@param string $method the request method
@param string $uri the uri
@param mixed $params optional query string parameters
@param string $body body/post parameters
@return string
@throws \Puzzle\Exceptions\InvalidRequestException | [
"head",
"request",
"implementation"
] | cb3dfd64b0df8610c054dbb43b242fbf2cf668a0 | https://github.com/dittertp/Puzzle/blob/cb3dfd64b0df8610c054dbb43b242fbf2cf668a0/src/Puzzle/Client.php#L444-L449 | train |
dittertp/Puzzle | src/Puzzle/Client.php | Client.postRequest | protected function postRequest($method, $uri, $params, $body)
{
// post requests has no specific necessary requirements
return $this->execute($method, $uri, $params, $body);
} | php | protected function postRequest($method, $uri, $params, $body)
{
// post requests has no specific necessary requirements
return $this->execute($method, $uri, $params, $body);
} | [
"protected",
"function",
"postRequest",
"(",
"$",
"method",
",",
"$",
"uri",
",",
"$",
"params",
",",
"$",
"body",
")",
"{",
"// post requests has no specific necessary requirements",
"return",
"$",
"this",
"->",
"execute",
"(",
"$",
"method",
",",
"$",
"uri",
",",
"$",
"params",
",",
"$",
"body",
")",
";",
"}"
] | post request implementation
@param string $method the request method
@param string $uri the uri
@param mixed $params optional query string parameters
@param string $body body/post parameters
@return string
@throws \Puzzle\Exceptions\InvalidRequestException | [
"post",
"request",
"implementation"
] | cb3dfd64b0df8610c054dbb43b242fbf2cf668a0 | https://github.com/dittertp/Puzzle/blob/cb3dfd64b0df8610c054dbb43b242fbf2cf668a0/src/Puzzle/Client.php#L462-L467 | train |
dittertp/Puzzle | src/Puzzle/Client.php | Client.putRequest | protected function putRequest($method, $uri, $params, $body)
{
$this->checkBody($body, $method);
// put requests requires content-length header
$this->setHttpHeader('Content-Length: ' . strlen($body));
return $this->execute($method, $uri, $params, $body);
} | php | protected function putRequest($method, $uri, $params, $body)
{
$this->checkBody($body, $method);
// put requests requires content-length header
$this->setHttpHeader('Content-Length: ' . strlen($body));
return $this->execute($method, $uri, $params, $body);
} | [
"protected",
"function",
"putRequest",
"(",
"$",
"method",
",",
"$",
"uri",
",",
"$",
"params",
",",
"$",
"body",
")",
"{",
"$",
"this",
"->",
"checkBody",
"(",
"$",
"body",
",",
"$",
"method",
")",
";",
"// put requests requires content-length header",
"$",
"this",
"->",
"setHttpHeader",
"(",
"'Content-Length: '",
".",
"strlen",
"(",
"$",
"body",
")",
")",
";",
"return",
"$",
"this",
"->",
"execute",
"(",
"$",
"method",
",",
"$",
"uri",
",",
"$",
"params",
",",
"$",
"body",
")",
";",
"}"
] | put request implementation
@param string $method the request method
@param string $uri the uri
@param mixed $params optional query string parameters
@param string $body body/post parameters
@return string
@throws \Puzzle\Exceptions\InvalidRequestException | [
"put",
"request",
"implementation"
] | cb3dfd64b0df8610c054dbb43b242fbf2cf668a0 | https://github.com/dittertp/Puzzle/blob/cb3dfd64b0df8610c054dbb43b242fbf2cf668a0/src/Puzzle/Client.php#L480-L488 | train |
dittertp/Puzzle | src/Puzzle/Client.php | Client.prepareResponse | protected function prepareResponse($result)
{
$this->checkForCurlErrors();
$response = array();
$response["data"] = $this->getSerializer()->deserialize($result);
$response["status"] = $this->getStatusCode();
if ($response['status'] >= 400 && $response['status'] < 500) {
$statusCode = $response['status'];
$exceptionText = "{$statusCode} Client Exception: {$result}";
throw new ClientErrorException($exceptionText, $statusCode);
} else if ($response['status'] >= 500) {
$statusCode = $response['status'];
$exceptionText = "{$statusCode} Server Exception: {$result}";
throw new ServerErrorException($exceptionText, $statusCode);
}
return $response;
} | php | protected function prepareResponse($result)
{
$this->checkForCurlErrors();
$response = array();
$response["data"] = $this->getSerializer()->deserialize($result);
$response["status"] = $this->getStatusCode();
if ($response['status'] >= 400 && $response['status'] < 500) {
$statusCode = $response['status'];
$exceptionText = "{$statusCode} Client Exception: {$result}";
throw new ClientErrorException($exceptionText, $statusCode);
} else if ($response['status'] >= 500) {
$statusCode = $response['status'];
$exceptionText = "{$statusCode} Server Exception: {$result}";
throw new ServerErrorException($exceptionText, $statusCode);
}
return $response;
} | [
"protected",
"function",
"prepareResponse",
"(",
"$",
"result",
")",
"{",
"$",
"this",
"->",
"checkForCurlErrors",
"(",
")",
";",
"$",
"response",
"=",
"array",
"(",
")",
";",
"$",
"response",
"[",
"\"data\"",
"]",
"=",
"$",
"this",
"->",
"getSerializer",
"(",
")",
"->",
"deserialize",
"(",
"$",
"result",
")",
";",
"$",
"response",
"[",
"\"status\"",
"]",
"=",
"$",
"this",
"->",
"getStatusCode",
"(",
")",
";",
"if",
"(",
"$",
"response",
"[",
"'status'",
"]",
">=",
"400",
"&&",
"$",
"response",
"[",
"'status'",
"]",
"<",
"500",
")",
"{",
"$",
"statusCode",
"=",
"$",
"response",
"[",
"'status'",
"]",
";",
"$",
"exceptionText",
"=",
"\"{$statusCode} Client Exception: {$result}\"",
";",
"throw",
"new",
"ClientErrorException",
"(",
"$",
"exceptionText",
",",
"$",
"statusCode",
")",
";",
"}",
"else",
"if",
"(",
"$",
"response",
"[",
"'status'",
"]",
">=",
"500",
")",
"{",
"$",
"statusCode",
"=",
"$",
"response",
"[",
"'status'",
"]",
";",
"$",
"exceptionText",
"=",
"\"{$statusCode} Server Exception: {$result}\"",
";",
"throw",
"new",
"ServerErrorException",
"(",
"$",
"exceptionText",
",",
"$",
"statusCode",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | prepares the response
@param string $result the curl result
@return array
@throws ClientErrorException
@throws ConnectionException
@throws ServerErrorException | [
"prepares",
"the",
"response"
] | cb3dfd64b0df8610c054dbb43b242fbf2cf668a0 | https://github.com/dittertp/Puzzle/blob/cb3dfd64b0df8610c054dbb43b242fbf2cf668a0/src/Puzzle/Client.php#L550-L572 | train |
dittertp/Puzzle | src/Puzzle/Client.php | Client.checkForCurlErrors | protected function checkForCurlErrors()
{
if (curl_errno($this->getHandle())) {
$exceptionText = "Connection Error: " . curl_error($this->getHandle());
throw new ConnectionException($exceptionText);
}
} | php | protected function checkForCurlErrors()
{
if (curl_errno($this->getHandle())) {
$exceptionText = "Connection Error: " . curl_error($this->getHandle());
throw new ConnectionException($exceptionText);
}
} | [
"protected",
"function",
"checkForCurlErrors",
"(",
")",
"{",
"if",
"(",
"curl_errno",
"(",
"$",
"this",
"->",
"getHandle",
"(",
")",
")",
")",
"{",
"$",
"exceptionText",
"=",
"\"Connection Error: \"",
".",
"curl_error",
"(",
"$",
"this",
"->",
"getHandle",
"(",
")",
")",
";",
"throw",
"new",
"ConnectionException",
"(",
"$",
"exceptionText",
")",
";",
"}",
"}"
] | checks if a curl error occurred
@return void
@throws ConnectionException | [
"checks",
"if",
"a",
"curl",
"error",
"occurred"
] | cb3dfd64b0df8610c054dbb43b242fbf2cf668a0 | https://github.com/dittertp/Puzzle/blob/cb3dfd64b0df8610c054dbb43b242fbf2cf668a0/src/Puzzle/Client.php#L590-L596 | train |
dittertp/Puzzle | src/Puzzle/Client.php | Client.enableSSL | public function enableSSL($strict = false)
{
$this->setScheme(self::SCHEME_SSL);
if ($strict === false) {
$this->setOption(CURLOPT_SSL_VERIFYPEER, 0);
$this->setOption(CURLOPT_SSL_VERIFYHOST, 0);
} else {
$this->setOption(CURLOPT_SSL_VERIFYPEER, 0);
$this->setOption(CURLOPT_SSL_VERIFYHOST, 1);
}
} | php | public function enableSSL($strict = false)
{
$this->setScheme(self::SCHEME_SSL);
if ($strict === false) {
$this->setOption(CURLOPT_SSL_VERIFYPEER, 0);
$this->setOption(CURLOPT_SSL_VERIFYHOST, 0);
} else {
$this->setOption(CURLOPT_SSL_VERIFYPEER, 0);
$this->setOption(CURLOPT_SSL_VERIFYHOST, 1);
}
} | [
"public",
"function",
"enableSSL",
"(",
"$",
"strict",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"setScheme",
"(",
"self",
"::",
"SCHEME_SSL",
")",
";",
"if",
"(",
"$",
"strict",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"setOption",
"(",
"CURLOPT_SSL_VERIFYPEER",
",",
"0",
")",
";",
"$",
"this",
"->",
"setOption",
"(",
"CURLOPT_SSL_VERIFYHOST",
",",
"0",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setOption",
"(",
"CURLOPT_SSL_VERIFYPEER",
",",
"0",
")",
";",
"$",
"this",
"->",
"setOption",
"(",
"CURLOPT_SSL_VERIFYHOST",
",",
"1",
")",
";",
"}",
"}"
] | Enables ssl for the connection
@param bool $strict optional value if ssl should be strict (check server certificate)
@return void | [
"Enables",
"ssl",
"for",
"the",
"connection"
] | cb3dfd64b0df8610c054dbb43b242fbf2cf668a0 | https://github.com/dittertp/Puzzle/blob/cb3dfd64b0df8610c054dbb43b242fbf2cf668a0/src/Puzzle/Client.php#L605-L615 | train |
dittertp/Puzzle | src/Puzzle/Client.php | Client.buildUrl | protected function buildUrl($uri, $params)
{
$host = $this->buildHostString();
if (strpos($uri, "/") !== 0) {
$uri = "/" . $uri;
}
$url = $host . $uri;
if ($params === null) {
$params = array();
}
$url .= $this->buildQueryString($params);
return $url;
} | php | protected function buildUrl($uri, $params)
{
$host = $this->buildHostString();
if (strpos($uri, "/") !== 0) {
$uri = "/" . $uri;
}
$url = $host . $uri;
if ($params === null) {
$params = array();
}
$url .= $this->buildQueryString($params);
return $url;
} | [
"protected",
"function",
"buildUrl",
"(",
"$",
"uri",
",",
"$",
"params",
")",
"{",
"$",
"host",
"=",
"$",
"this",
"->",
"buildHostString",
"(",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"uri",
",",
"\"/\"",
")",
"!==",
"0",
")",
"{",
"$",
"uri",
"=",
"\"/\"",
".",
"$",
"uri",
";",
"}",
"$",
"url",
"=",
"$",
"host",
".",
"$",
"uri",
";",
"if",
"(",
"$",
"params",
"===",
"null",
")",
"{",
"$",
"params",
"=",
"array",
"(",
")",
";",
"}",
"$",
"url",
".=",
"$",
"this",
"->",
"buildQueryString",
"(",
"$",
"params",
")",
";",
"return",
"$",
"url",
";",
"}"
] | build complete url
@param string $uri uri string
@param mixed $params query string parameters
@return string | [
"build",
"complete",
"url"
] | cb3dfd64b0df8610c054dbb43b242fbf2cf668a0 | https://github.com/dittertp/Puzzle/blob/cb3dfd64b0df8610c054dbb43b242fbf2cf668a0/src/Puzzle/Client.php#L670-L688 | train |
dittertp/Puzzle | src/Puzzle/Client.php | Client.buildQueryString | protected function buildQueryString(array $params)
{
$qs = "";
foreach ($params as $key => $value) {
if ($qs === "") {
$qs = "?";
} else {
$qs .= "&&";
}
$qs .= $key . "=" . $value;
}
return $qs;
} | php | protected function buildQueryString(array $params)
{
$qs = "";
foreach ($params as $key => $value) {
if ($qs === "") {
$qs = "?";
} else {
$qs .= "&&";
}
$qs .= $key . "=" . $value;
}
return $qs;
} | [
"protected",
"function",
"buildQueryString",
"(",
"array",
"$",
"params",
")",
"{",
"$",
"qs",
"=",
"\"\"",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"qs",
"===",
"\"\"",
")",
"{",
"$",
"qs",
"=",
"\"?\"",
";",
"}",
"else",
"{",
"$",
"qs",
".=",
"\"&&\"",
";",
"}",
"$",
"qs",
".=",
"$",
"key",
".",
"\"=\"",
".",
"$",
"value",
";",
"}",
"return",
"$",
"qs",
";",
"}"
] | build the query string
@param array $params query string parameters
@return string | [
"build",
"the",
"query",
"string"
] | cb3dfd64b0df8610c054dbb43b242fbf2cf668a0 | https://github.com/dittertp/Puzzle/blob/cb3dfd64b0df8610c054dbb43b242fbf2cf668a0/src/Puzzle/Client.php#L697-L709 | train |
dittertp/Puzzle | src/Puzzle/Client.php | Client.prepareHost | protected function prepareHost($scheme, $host)
{
$host = $this->stripScheme($host);
if (substr($host, -1) === "/") {
$host = substr($host, 0, -1);
}
return $scheme . $host;
} | php | protected function prepareHost($scheme, $host)
{
$host = $this->stripScheme($host);
if (substr($host, -1) === "/") {
$host = substr($host, 0, -1);
}
return $scheme . $host;
} | [
"protected",
"function",
"prepareHost",
"(",
"$",
"scheme",
",",
"$",
"host",
")",
"{",
"$",
"host",
"=",
"$",
"this",
"->",
"stripScheme",
"(",
"$",
"host",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"host",
",",
"-",
"1",
")",
"===",
"\"/\"",
")",
"{",
"$",
"host",
"=",
"substr",
"(",
"$",
"host",
",",
"0",
",",
"-",
"1",
")",
";",
"}",
"return",
"$",
"scheme",
".",
"$",
"host",
";",
"}"
] | Adds given scheme to hostname
@param string $scheme the http scheme
@param string $host the hostname
@return string
@throws Exceptions\ConfigurationException | [
"Adds",
"given",
"scheme",
"to",
"hostname"
] | cb3dfd64b0df8610c054dbb43b242fbf2cf668a0 | https://github.com/dittertp/Puzzle/blob/cb3dfd64b0df8610c054dbb43b242fbf2cf668a0/src/Puzzle/Client.php#L742-L751 | train |
dittertp/Puzzle | src/Puzzle/Client.php | Client.setHttpHeader | public function setHttpHeader($header)
{
$headers = $this->getHttpHeaders();
$headers[] = $header;
$this->setHttpHeaders($headers);
} | php | public function setHttpHeader($header)
{
$headers = $this->getHttpHeaders();
$headers[] = $header;
$this->setHttpHeaders($headers);
} | [
"public",
"function",
"setHttpHeader",
"(",
"$",
"header",
")",
"{",
"$",
"headers",
"=",
"$",
"this",
"->",
"getHttpHeaders",
"(",
")",
";",
"$",
"headers",
"[",
"]",
"=",
"$",
"header",
";",
"$",
"this",
"->",
"setHttpHeaders",
"(",
"$",
"headers",
")",
";",
"}"
] | Adds a new http header to header list
@param string $header http header to set
@return void | [
"Adds",
"a",
"new",
"http",
"header",
"to",
"header",
"list"
] | cb3dfd64b0df8610c054dbb43b242fbf2cf668a0 | https://github.com/dittertp/Puzzle/blob/cb3dfd64b0df8610c054dbb43b242fbf2cf668a0/src/Puzzle/Client.php#L838-L844 | train |
agentmedia/phine-builtin | src/BuiltIn/Modules/Frontend/HtmlWrap.php | HtmlWrap.Html | function Html()
{
$text = $this->html;
$pos = strpos($text, self::$placeholder);
$phLength = strlen(self::$placeholder);
while ($pos !== false && $this->currentChild)
{
$replacement = $this->RenderCurrentChild();
$text = substr($text, 0, $pos) . $replacement . substr($text, $pos + $phLength);
$this->currentChild = $this->tree->NextOf($this->currentChild);
$pos = strpos($text, self::$placeholder, $pos + strlen($replacement));
}
return $text;
} | php | function Html()
{
$text = $this->html;
$pos = strpos($text, self::$placeholder);
$phLength = strlen(self::$placeholder);
while ($pos !== false && $this->currentChild)
{
$replacement = $this->RenderCurrentChild();
$text = substr($text, 0, $pos) . $replacement . substr($text, $pos + $phLength);
$this->currentChild = $this->tree->NextOf($this->currentChild);
$pos = strpos($text, self::$placeholder, $pos + strlen($replacement));
}
return $text;
} | [
"function",
"Html",
"(",
")",
"{",
"$",
"text",
"=",
"$",
"this",
"->",
"html",
";",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"text",
",",
"self",
"::",
"$",
"placeholder",
")",
";",
"$",
"phLength",
"=",
"strlen",
"(",
"self",
"::",
"$",
"placeholder",
")",
";",
"while",
"(",
"$",
"pos",
"!==",
"false",
"&&",
"$",
"this",
"->",
"currentChild",
")",
"{",
"$",
"replacement",
"=",
"$",
"this",
"->",
"RenderCurrentChild",
"(",
")",
";",
"$",
"text",
"=",
"substr",
"(",
"$",
"text",
",",
"0",
",",
"$",
"pos",
")",
".",
"$",
"replacement",
".",
"substr",
"(",
"$",
"text",
",",
"$",
"pos",
"+",
"$",
"phLength",
")",
";",
"$",
"this",
"->",
"currentChild",
"=",
"$",
"this",
"->",
"tree",
"->",
"NextOf",
"(",
"$",
"this",
"->",
"currentChild",
")",
";",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"text",
",",
"self",
"::",
"$",
"placeholder",
",",
"$",
"pos",
"+",
"strlen",
"(",
"$",
"replacement",
")",
")",
";",
"}",
"return",
"$",
"text",
";",
"}"
] | Gathers the html | [
"Gathers",
"the",
"html"
] | 4dd05bc406a71e997bd4eaa16b12e23dbe62a456 | https://github.com/agentmedia/phine-builtin/blob/4dd05bc406a71e997bd4eaa16b12e23dbe62a456/src/BuiltIn/Modules/Frontend/HtmlWrap.php#L93-L108 | train |
PhoxPHP/Console | src/Command/Uses/RunnableBuilder.php | RunnableBuilder.buildRunnable | protected function buildRunnable(StdClass $runnable)
{
$template = __DIR__ . '/template' . '/RunnableTemplate.phx';
if (!file_exists($template)) {
$this->cmd->error(sprinf('Template file [%s] does not exist', $template), 'red');
exit;
}
$content = file_get_contents($template);
$hasLang = $this->hasLang($content);
$hasName = $this->hasName($content);
$hasId = $this->hasId($content);
$hasRunnableCommands = $this->hasRunnableCommands($content);
$hasNamespace = $this->hasNamespace($content);
if (!$hasLang || !$hasName || !$hasId || !$hasRunnableCommands | !$hasNamespace) {
$this->cmd->error('Cannot build runnable from invalid template.');
}
$runnableCommands = '[]';
$location = $this->cmd->getConfigOpt('runnables_path');
$namespace = '';
if ($runnable->namespace !== '') {
$namespace = 'namespace ' . $runnable->namespace . ';';
}
if ($runnable->runnableCommands !== '') {
$runnableCommands = "[";
$commands = explode(',', $runnable->runnableCommands);
foreach($commands as $commandString) {
$cmdArray = explode(':', $commandString);
$command = ltrim(rtrim($cmdArray[0]));
$commandArgumentLength = $this->validateArgumentLengthType($cmdArray[1]);
$runnableCommands .= "\n" . $this->env->addTab() . "\"" . $command . "\"" . ' => ' . $commandArgumentLength . ',';
}
$runnableCommands .= "\n]";
}
$replaces = [
'[phx:lang]' => '<?php',
'[phx:name]' => $runnable->name,
'[phx:id]' => $runnable->id,
'[phx:commands]' => $runnableCommands,
'[phx:namespace]' => $namespace
];
$runnableContent = str_replace(
array_keys($replaces),
array_values($replaces),
$content
);
if ($runnable->location !== '') {
$location = $runnable->location;
}
$fileLocation = $location . '/' . $runnable->name . '.php';
file_put_contents($fileLocation, $runnableContent);
return true;
} | php | protected function buildRunnable(StdClass $runnable)
{
$template = __DIR__ . '/template' . '/RunnableTemplate.phx';
if (!file_exists($template)) {
$this->cmd->error(sprinf('Template file [%s] does not exist', $template), 'red');
exit;
}
$content = file_get_contents($template);
$hasLang = $this->hasLang($content);
$hasName = $this->hasName($content);
$hasId = $this->hasId($content);
$hasRunnableCommands = $this->hasRunnableCommands($content);
$hasNamespace = $this->hasNamespace($content);
if (!$hasLang || !$hasName || !$hasId || !$hasRunnableCommands | !$hasNamespace) {
$this->cmd->error('Cannot build runnable from invalid template.');
}
$runnableCommands = '[]';
$location = $this->cmd->getConfigOpt('runnables_path');
$namespace = '';
if ($runnable->namespace !== '') {
$namespace = 'namespace ' . $runnable->namespace . ';';
}
if ($runnable->runnableCommands !== '') {
$runnableCommands = "[";
$commands = explode(',', $runnable->runnableCommands);
foreach($commands as $commandString) {
$cmdArray = explode(':', $commandString);
$command = ltrim(rtrim($cmdArray[0]));
$commandArgumentLength = $this->validateArgumentLengthType($cmdArray[1]);
$runnableCommands .= "\n" . $this->env->addTab() . "\"" . $command . "\"" . ' => ' . $commandArgumentLength . ',';
}
$runnableCommands .= "\n]";
}
$replaces = [
'[phx:lang]' => '<?php',
'[phx:name]' => $runnable->name,
'[phx:id]' => $runnable->id,
'[phx:commands]' => $runnableCommands,
'[phx:namespace]' => $namespace
];
$runnableContent = str_replace(
array_keys($replaces),
array_values($replaces),
$content
);
if ($runnable->location !== '') {
$location = $runnable->location;
}
$fileLocation = $location . '/' . $runnable->name . '.php';
file_put_contents($fileLocation, $runnableContent);
return true;
} | [
"protected",
"function",
"buildRunnable",
"(",
"StdClass",
"$",
"runnable",
")",
"{",
"$",
"template",
"=",
"__DIR__",
".",
"'/template'",
".",
"'/RunnableTemplate.phx'",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"template",
")",
")",
"{",
"$",
"this",
"->",
"cmd",
"->",
"error",
"(",
"sprinf",
"(",
"'Template file [%s] does not exist'",
",",
"$",
"template",
")",
",",
"'red'",
")",
";",
"exit",
";",
"}",
"$",
"content",
"=",
"file_get_contents",
"(",
"$",
"template",
")",
";",
"$",
"hasLang",
"=",
"$",
"this",
"->",
"hasLang",
"(",
"$",
"content",
")",
";",
"$",
"hasName",
"=",
"$",
"this",
"->",
"hasName",
"(",
"$",
"content",
")",
";",
"$",
"hasId",
"=",
"$",
"this",
"->",
"hasId",
"(",
"$",
"content",
")",
";",
"$",
"hasRunnableCommands",
"=",
"$",
"this",
"->",
"hasRunnableCommands",
"(",
"$",
"content",
")",
";",
"$",
"hasNamespace",
"=",
"$",
"this",
"->",
"hasNamespace",
"(",
"$",
"content",
")",
";",
"if",
"(",
"!",
"$",
"hasLang",
"||",
"!",
"$",
"hasName",
"||",
"!",
"$",
"hasId",
"||",
"!",
"$",
"hasRunnableCommands",
"|",
"!",
"$",
"hasNamespace",
")",
"{",
"$",
"this",
"->",
"cmd",
"->",
"error",
"(",
"'Cannot build runnable from invalid template.'",
")",
";",
"}",
"$",
"runnableCommands",
"=",
"'[]'",
";",
"$",
"location",
"=",
"$",
"this",
"->",
"cmd",
"->",
"getConfigOpt",
"(",
"'runnables_path'",
")",
";",
"$",
"namespace",
"=",
"''",
";",
"if",
"(",
"$",
"runnable",
"->",
"namespace",
"!==",
"''",
")",
"{",
"$",
"namespace",
"=",
"'namespace '",
".",
"$",
"runnable",
"->",
"namespace",
".",
"';'",
";",
"}",
"if",
"(",
"$",
"runnable",
"->",
"runnableCommands",
"!==",
"''",
")",
"{",
"$",
"runnableCommands",
"=",
"\"[\"",
";",
"$",
"commands",
"=",
"explode",
"(",
"','",
",",
"$",
"runnable",
"->",
"runnableCommands",
")",
";",
"foreach",
"(",
"$",
"commands",
"as",
"$",
"commandString",
")",
"{",
"$",
"cmdArray",
"=",
"explode",
"(",
"':'",
",",
"$",
"commandString",
")",
";",
"$",
"command",
"=",
"ltrim",
"(",
"rtrim",
"(",
"$",
"cmdArray",
"[",
"0",
"]",
")",
")",
";",
"$",
"commandArgumentLength",
"=",
"$",
"this",
"->",
"validateArgumentLengthType",
"(",
"$",
"cmdArray",
"[",
"1",
"]",
")",
";",
"$",
"runnableCommands",
".=",
"\"\\n\"",
".",
"$",
"this",
"->",
"env",
"->",
"addTab",
"(",
")",
".",
"\"\\\"\"",
".",
"$",
"command",
".",
"\"\\\"\"",
".",
"' => '",
".",
"$",
"commandArgumentLength",
".",
"','",
";",
"}",
"$",
"runnableCommands",
".=",
"\"\\n]\"",
";",
"}",
"$",
"replaces",
"=",
"[",
"'[phx:lang]'",
"=>",
"'<?php'",
",",
"'[phx:name]'",
"=>",
"$",
"runnable",
"->",
"name",
",",
"'[phx:id]'",
"=>",
"$",
"runnable",
"->",
"id",
",",
"'[phx:commands]'",
"=>",
"$",
"runnableCommands",
",",
"'[phx:namespace]'",
"=>",
"$",
"namespace",
"]",
";",
"$",
"runnableContent",
"=",
"str_replace",
"(",
"array_keys",
"(",
"$",
"replaces",
")",
",",
"array_values",
"(",
"$",
"replaces",
")",
",",
"$",
"content",
")",
";",
"if",
"(",
"$",
"runnable",
"->",
"location",
"!==",
"''",
")",
"{",
"$",
"location",
"=",
"$",
"runnable",
"->",
"location",
";",
"}",
"$",
"fileLocation",
"=",
"$",
"location",
".",
"'/'",
".",
"$",
"runnable",
"->",
"name",
".",
"'.php'",
";",
"file_put_contents",
"(",
"$",
"fileLocation",
",",
"$",
"runnableContent",
")",
";",
"return",
"true",
";",
"}"
] | Creates a new runnable object.
@param $runnable <StdClass>
@access protected
@return <void> | [
"Creates",
"a",
"new",
"runnable",
"object",
"."
] | fee1238cfdb3592964bb5d5a2336e70b8ffd20e9 | https://github.com/PhoxPHP/Console/blob/fee1238cfdb3592964bb5d5a2336e70b8ffd20e9/src/Command/Uses/RunnableBuilder.php#L38-L100 | train |
PhoxPHP/Console | src/Command/Uses/RunnableBuilder.php | RunnableBuilder.validateArgumentLengthType | protected function validateArgumentLengthType(String $argument)
{
if (!is_numeric($argument) && !in_array($argument, ['none', 'i'])) {
$this->cmd->error(sprintf('Failed to create runnable. [%s] is not a valid argument length type.', $argument));
}
if (in_array($argument, ['none', 'i'])) {
return "\":" . $argument . "\"";
}
return $argument;
} | php | protected function validateArgumentLengthType(String $argument)
{
if (!is_numeric($argument) && !in_array($argument, ['none', 'i'])) {
$this->cmd->error(sprintf('Failed to create runnable. [%s] is not a valid argument length type.', $argument));
}
if (in_array($argument, ['none', 'i'])) {
return "\":" . $argument . "\"";
}
return $argument;
} | [
"protected",
"function",
"validateArgumentLengthType",
"(",
"String",
"$",
"argument",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"argument",
")",
"&&",
"!",
"in_array",
"(",
"$",
"argument",
",",
"[",
"'none'",
",",
"'i'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"cmd",
"->",
"error",
"(",
"sprintf",
"(",
"'Failed to create runnable. [%s] is not a valid argument length type.'",
",",
"$",
"argument",
")",
")",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"argument",
",",
"[",
"'none'",
",",
"'i'",
"]",
")",
")",
"{",
"return",
"\"\\\":\"",
".",
"$",
"argument",
".",
"\"\\\"\"",
";",
"}",
"return",
"$",
"argument",
";",
"}"
] | Checks and validates the argument type returned.
@param $argument <String>
@access protected
@return <String> | [
"Checks",
"and",
"validates",
"the",
"argument",
"type",
"returned",
"."
] | fee1238cfdb3592964bb5d5a2336e70b8ffd20e9 | https://github.com/PhoxPHP/Console/blob/fee1238cfdb3592964bb5d5a2336e70b8ffd20e9/src/Command/Uses/RunnableBuilder.php#L189-L200 | train |
Raphhh/puppy-application | src/Route/Router.php | Router.find | public function find(Request $request)
{
$route = $this->getRouteFinder()->find($request, $this->getRoutes());
$this->setCurrentRoute($route);
return $route;
} | php | public function find(Request $request)
{
$route = $this->getRouteFinder()->find($request, $this->getRoutes());
$this->setCurrentRoute($route);
return $route;
} | [
"public",
"function",
"find",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"route",
"=",
"$",
"this",
"->",
"getRouteFinder",
"(",
")",
"->",
"find",
"(",
"$",
"request",
",",
"$",
"this",
"->",
"getRoutes",
"(",
")",
")",
";",
"$",
"this",
"->",
"setCurrentRoute",
"(",
"$",
"route",
")",
";",
"return",
"$",
"route",
";",
"}"
] | Finds a route from a uri.
@param Request $request
@return Route | [
"Finds",
"a",
"route",
"from",
"a",
"uri",
"."
] | 9291543cd28e19a2986abd7fb146898ca5f5f5da | https://github.com/Raphhh/puppy-application/blob/9291543cd28e19a2986abd7fb146898ca5f5f5da/src/Route/Router.php#L59-L64 | train |
OpenConext-Attic/OpenConext-engineblock-metadata | src/JanusRestV1/CacheProxyClient.php | CacheProxyClient.getAllowedIdps | public function getAllowedIdps($spEntityId)
{
if (isset($this->allowedIdpsPerSp[$spEntityId])) {
return $this->allowedIdpsPerSp[$spEntityId];
}
$this->allowedIdpsPerSp[$spEntityId] = $this->client->getAllowedIdps($spEntityId);
return $this->allowedIdpsPerSp[$spEntityId];
} | php | public function getAllowedIdps($spEntityId)
{
if (isset($this->allowedIdpsPerSp[$spEntityId])) {
return $this->allowedIdpsPerSp[$spEntityId];
}
$this->allowedIdpsPerSp[$spEntityId] = $this->client->getAllowedIdps($spEntityId);
return $this->allowedIdpsPerSp[$spEntityId];
} | [
"public",
"function",
"getAllowedIdps",
"(",
"$",
"spEntityId",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"allowedIdpsPerSp",
"[",
"$",
"spEntityId",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"allowedIdpsPerSp",
"[",
"$",
"spEntityId",
"]",
";",
"}",
"$",
"this",
"->",
"allowedIdpsPerSp",
"[",
"$",
"spEntityId",
"]",
"=",
"$",
"this",
"->",
"client",
"->",
"getAllowedIdps",
"(",
"$",
"spEntityId",
")",
";",
"return",
"$",
"this",
"->",
"allowedIdpsPerSp",
"[",
"$",
"spEntityId",
"]",
";",
"}"
] | Retrieve the allowed IDPs for an SP. The SP is only
allowed to make connections to the retrieved IDP's.
@param string $spEntityId the URN of the SP entity.
@return array containing the URN's of the IDP's that this SP is allowed to make a connection to. | [
"Retrieve",
"the",
"allowed",
"IDPs",
"for",
"an",
"SP",
".",
"The",
"SP",
"is",
"only",
"allowed",
"to",
"make",
"connections",
"to",
"the",
"retrieved",
"IDP",
"s",
"."
] | 236e2f52ef9cf28e71404544a1c4388f63ee535d | https://github.com/OpenConext-Attic/OpenConext-engineblock-metadata/blob/236e2f52ef9cf28e71404544a1c4388f63ee535d/src/JanusRestV1/CacheProxyClient.php#L51-L60 | train |
OpenConext-Attic/OpenConext-engineblock-metadata | src/JanusRestV1/CacheProxyClient.php | CacheProxyClient.getEntity | public function getEntity($entityId)
{
if (isset($this->entities[$entityId])) {
return $this->entities[$entityId];
}
$this->entities[$entityId] = $this->client->getEntity($entityId);
return $this->entities[$entityId];
} | php | public function getEntity($entityId)
{
if (isset($this->entities[$entityId])) {
return $this->entities[$entityId];
}
$this->entities[$entityId] = $this->client->getEntity($entityId);
return $this->entities[$entityId];
} | [
"public",
"function",
"getEntity",
"(",
"$",
"entityId",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"entities",
"[",
"$",
"entityId",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"entities",
"[",
"$",
"entityId",
"]",
";",
"}",
"$",
"this",
"->",
"entities",
"[",
"$",
"entityId",
"]",
"=",
"$",
"this",
"->",
"client",
"->",
"getEntity",
"(",
"$",
"entityId",
")",
";",
"return",
"$",
"this",
"->",
"entities",
"[",
"$",
"entityId",
"]",
";",
"}"
] | Get full information for a given entity.
@param $entityId
@return array | [
"Get",
"full",
"information",
"for",
"a",
"given",
"entity",
"."
] | 236e2f52ef9cf28e71404544a1c4388f63ee535d | https://github.com/OpenConext-Attic/OpenConext-engineblock-metadata/blob/236e2f52ef9cf28e71404544a1c4388f63ee535d/src/JanusRestV1/CacheProxyClient.php#L68-L77 | train |
OpenConext-Attic/OpenConext-engineblock-metadata | src/JanusRestV1/CacheProxyClient.php | CacheProxyClient.getIdpList | public function getIdpList($keys = array(), $forSpEntityId = null)
{
sort($keys);
$keysString = implode(',', $keys);
if (isset($this->identityProvidersMetadata[$keysString][$forSpEntityId])) {
return $this->identityProvidersMetadata[$keysString][$forSpEntityId];
}
if (!isset($this->identityProvidersMetadata[$keysString])) {
$this->identityProvidersMetadata[$keysString] = array();
}
$this->identityProvidersMetadata[$keysString][$forSpEntityId] = $this->client->getIdpList();
return $this->identityProvidersMetadata;
} | php | public function getIdpList($keys = array(), $forSpEntityId = null)
{
sort($keys);
$keysString = implode(',', $keys);
if (isset($this->identityProvidersMetadata[$keysString][$forSpEntityId])) {
return $this->identityProvidersMetadata[$keysString][$forSpEntityId];
}
if (!isset($this->identityProvidersMetadata[$keysString])) {
$this->identityProvidersMetadata[$keysString] = array();
}
$this->identityProvidersMetadata[$keysString][$forSpEntityId] = $this->client->getIdpList();
return $this->identityProvidersMetadata;
} | [
"public",
"function",
"getIdpList",
"(",
"$",
"keys",
"=",
"array",
"(",
")",
",",
"$",
"forSpEntityId",
"=",
"null",
")",
"{",
"sort",
"(",
"$",
"keys",
")",
";",
"$",
"keysString",
"=",
"implode",
"(",
"','",
",",
"$",
"keys",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"identityProvidersMetadata",
"[",
"$",
"keysString",
"]",
"[",
"$",
"forSpEntityId",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"identityProvidersMetadata",
"[",
"$",
"keysString",
"]",
"[",
"$",
"forSpEntityId",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"identityProvidersMetadata",
"[",
"$",
"keysString",
"]",
")",
")",
"{",
"$",
"this",
"->",
"identityProvidersMetadata",
"[",
"$",
"keysString",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"this",
"->",
"identityProvidersMetadata",
"[",
"$",
"keysString",
"]",
"[",
"$",
"forSpEntityId",
"]",
"=",
"$",
"this",
"->",
"client",
"->",
"getIdpList",
"(",
")",
";",
"return",
"$",
"this",
"->",
"identityProvidersMetadata",
";",
"}"
] | Retrieve a list of metadata values of all available
IDP entities.
@param array $keys An array of keys to retrieve. Retrieves
all available keys if omited or empty
@param String $forSpEntityId An optional identifier of an SP
If present, idplist will return a list of only the
idps that this sp is allowed to authenticate against.
@return array An associative array of values, indexed by IDP
identifier. Each value is another associative
array with key/value pairs containing the metadata. | [
"Retrieve",
"a",
"list",
"of",
"metadata",
"values",
"of",
"all",
"available",
"IDP",
"entities",
"."
] | 236e2f52ef9cf28e71404544a1c4388f63ee535d | https://github.com/OpenConext-Attic/OpenConext-engineblock-metadata/blob/236e2f52ef9cf28e71404544a1c4388f63ee535d/src/JanusRestV1/CacheProxyClient.php#L91-L106 | train |
OpenConext-Attic/OpenConext-engineblock-metadata | src/JanusRestV1/CacheProxyClient.php | CacheProxyClient.getSpList | public function getSpList($keys = array())
{
sort($keys);
$keysString = implode(',', $keys);
if (isset($this->serviceProvidersMetadata[$keysString])) {
return $this->serviceProvidersMetadata[$keysString];
}
$this->serviceProvidersMetadata[$keysString] = $this->client->getSpList();
return $this->serviceProvidersMetadata;
} | php | public function getSpList($keys = array())
{
sort($keys);
$keysString = implode(',', $keys);
if (isset($this->serviceProvidersMetadata[$keysString])) {
return $this->serviceProvidersMetadata[$keysString];
}
$this->serviceProvidersMetadata[$keysString] = $this->client->getSpList();
return $this->serviceProvidersMetadata;
} | [
"public",
"function",
"getSpList",
"(",
"$",
"keys",
"=",
"array",
"(",
")",
")",
"{",
"sort",
"(",
"$",
"keys",
")",
";",
"$",
"keysString",
"=",
"implode",
"(",
"','",
",",
"$",
"keys",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"serviceProvidersMetadata",
"[",
"$",
"keysString",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"serviceProvidersMetadata",
"[",
"$",
"keysString",
"]",
";",
"}",
"$",
"this",
"->",
"serviceProvidersMetadata",
"[",
"$",
"keysString",
"]",
"=",
"$",
"this",
"->",
"client",
"->",
"getSpList",
"(",
")",
";",
"return",
"$",
"this",
"->",
"serviceProvidersMetadata",
";",
"}"
] | Retrieve a list of metadata values of all available
SP entities.
@param array $keys An array of keys to retrieve. Retrieves
all available keys if omited or empty
@return array An associative array of values, indexed by SP
identifier. Each value is another associative
array with key/value pairs containing the metadata. | [
"Retrieve",
"a",
"list",
"of",
"metadata",
"values",
"of",
"all",
"available",
"SP",
"entities",
"."
] | 236e2f52ef9cf28e71404544a1c4388f63ee535d | https://github.com/OpenConext-Attic/OpenConext-engineblock-metadata/blob/236e2f52ef9cf28e71404544a1c4388f63ee535d/src/JanusRestV1/CacheProxyClient.php#L135-L146 | train |
jabernardo/lollipop-php | Library/Benchmark.php | Benchmark.elapsed | static public function elapsed($start, $end) {
return [
'time_elapsed' => self::elapsedTime($start, $end),
'memory_usage_gap' => self::elapsedMemory($start, $end),
'real_memory_usage' => self::elapsedMemory($start, $end, true)
];
} | php | static public function elapsed($start, $end) {
return [
'time_elapsed' => self::elapsedTime($start, $end),
'memory_usage_gap' => self::elapsedMemory($start, $end),
'real_memory_usage' => self::elapsedMemory($start, $end, true)
];
} | [
"static",
"public",
"function",
"elapsed",
"(",
"$",
"start",
",",
"$",
"end",
")",
"{",
"return",
"[",
"'time_elapsed'",
"=>",
"self",
"::",
"elapsedTime",
"(",
"$",
"start",
",",
"$",
"end",
")",
",",
"'memory_usage_gap'",
"=>",
"self",
"::",
"elapsedMemory",
"(",
"$",
"start",
",",
"$",
"end",
")",
",",
"'real_memory_usage'",
"=>",
"self",
"::",
"elapsedMemory",
"(",
"$",
"start",
",",
"$",
"end",
",",
"true",
")",
"]",
";",
"}"
] | Get detailed benchmark
@access public
@param string $start Start mark
@param string $end End mark
@return array | [
"Get",
"detailed",
"benchmark"
] | 004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5 | https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/Benchmark.php#L45-L51 | train |
jabernardo/lollipop-php | Library/Benchmark.php | Benchmark.elapsedMemory | static public function elapsedMemory($start, $end, $real_usage = false, $inMB = true) {
$start = isset(self::$_marks[$start]) ? self::$_marks[$start]['memory_usage'] : 0;
$end = isset(self::$_marks[$end]) ? self::$_marks[$end]['memory_usage'] : 0;
$elapsed = !$real_usage ? ($end - $start) : $end;
return $start ? ($inMB ? (($elapsed / 1024 / 1024) . ' MB') : $elapsed) : null;
} | php | static public function elapsedMemory($start, $end, $real_usage = false, $inMB = true) {
$start = isset(self::$_marks[$start]) ? self::$_marks[$start]['memory_usage'] : 0;
$end = isset(self::$_marks[$end]) ? self::$_marks[$end]['memory_usage'] : 0;
$elapsed = !$real_usage ? ($end - $start) : $end;
return $start ? ($inMB ? (($elapsed / 1024 / 1024) . ' MB') : $elapsed) : null;
} | [
"static",
"public",
"function",
"elapsedMemory",
"(",
"$",
"start",
",",
"$",
"end",
",",
"$",
"real_usage",
"=",
"false",
",",
"$",
"inMB",
"=",
"true",
")",
"{",
"$",
"start",
"=",
"isset",
"(",
"self",
"::",
"$",
"_marks",
"[",
"$",
"start",
"]",
")",
"?",
"self",
"::",
"$",
"_marks",
"[",
"$",
"start",
"]",
"[",
"'memory_usage'",
"]",
":",
"0",
";",
"$",
"end",
"=",
"isset",
"(",
"self",
"::",
"$",
"_marks",
"[",
"$",
"end",
"]",
")",
"?",
"self",
"::",
"$",
"_marks",
"[",
"$",
"end",
"]",
"[",
"'memory_usage'",
"]",
":",
"0",
";",
"$",
"elapsed",
"=",
"!",
"$",
"real_usage",
"?",
"(",
"$",
"end",
"-",
"$",
"start",
")",
":",
"$",
"end",
";",
"return",
"$",
"start",
"?",
"(",
"$",
"inMB",
"?",
"(",
"(",
"$",
"elapsed",
"/",
"1024",
"/",
"1024",
")",
".",
"' MB'",
")",
":",
"$",
"elapsed",
")",
":",
"null",
";",
"}"
] | Get elapsed memory between two marks
@access public
@param string $start Start mark
@param string $end End mark
@param bool $real_usage Get real memory usage
@param bool $inMB Show output in MB instead of Bytes
@return mixed <string> if $inMB is <true>, <longint> if on <false> | [
"Get",
"elapsed",
"memory",
"between",
"two",
"marks"
] | 004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5 | https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/Benchmark.php#L64-L71 | train |
jabernardo/lollipop-php | Library/Benchmark.php | Benchmark.elapsedTime | static public function elapsedTime($start, $end) {
$start = isset(self::$_marks[$start]) ? self::$_marks[$start]['time'] : 0;
$end = isset(self::$_marks[$end]) ? self::$_marks[$end]['time'] : 0;
return $start ? round($end - $start, 10) : null;
} | php | static public function elapsedTime($start, $end) {
$start = isset(self::$_marks[$start]) ? self::$_marks[$start]['time'] : 0;
$end = isset(self::$_marks[$end]) ? self::$_marks[$end]['time'] : 0;
return $start ? round($end - $start, 10) : null;
} | [
"static",
"public",
"function",
"elapsedTime",
"(",
"$",
"start",
",",
"$",
"end",
")",
"{",
"$",
"start",
"=",
"isset",
"(",
"self",
"::",
"$",
"_marks",
"[",
"$",
"start",
"]",
")",
"?",
"self",
"::",
"$",
"_marks",
"[",
"$",
"start",
"]",
"[",
"'time'",
"]",
":",
"0",
";",
"$",
"end",
"=",
"isset",
"(",
"self",
"::",
"$",
"_marks",
"[",
"$",
"end",
"]",
")",
"?",
"self",
"::",
"$",
"_marks",
"[",
"$",
"end",
"]",
"[",
"'time'",
"]",
":",
"0",
";",
"return",
"$",
"start",
"?",
"round",
"(",
"$",
"end",
"-",
"$",
"start",
",",
"10",
")",
":",
"null",
";",
"}"
] | Compute the elapsed time of two marks
@param string $start Keyname 1
@param string $end Keyname 2
@return mixed | [
"Compute",
"the",
"elapsed",
"time",
"of",
"two",
"marks"
] | 004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5 | https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/Benchmark.php#L82-L87 | train |
Kris-Kuiper/sFire-Framework | src/Validator/Validator.php | Validator.field | public function field($fieldnames) {
$fieldnames = func_get_args();
foreach($fieldnames as $fieldname) {
if(false === is_string($fieldname)) {
return trigger_error(sprintf('All fieldnames used in "%s"() must be of the type string, "%s" given', __METHOD__, gettype($fieldname)), E_USER_ERROR);
}
}
$this -> setFieldnames($fieldnames);
return $this;
} | php | public function field($fieldnames) {
$fieldnames = func_get_args();
foreach($fieldnames as $fieldname) {
if(false === is_string($fieldname)) {
return trigger_error(sprintf('All fieldnames used in "%s"() must be of the type string, "%s" given', __METHOD__, gettype($fieldname)), E_USER_ERROR);
}
}
$this -> setFieldnames($fieldnames);
return $this;
} | [
"public",
"function",
"field",
"(",
"$",
"fieldnames",
")",
"{",
"$",
"fieldnames",
"=",
"func_get_args",
"(",
")",
";",
"foreach",
"(",
"$",
"fieldnames",
"as",
"$",
"fieldname",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"fieldname",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'All fieldnames used in \"%s\"() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"fieldname",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"}",
"$",
"this",
"->",
"setFieldnames",
"(",
"$",
"fieldnames",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add one or multiple validation rules to one or multiple fields
@param string|array $fieldnames
@return sFire\Validator\Validator | [
"Add",
"one",
"or",
"multiple",
"validation",
"rules",
"to",
"one",
"or",
"multiple",
"fields"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Validator/Validator.php#L113-L127 | train |
Kris-Kuiper/sFire-Framework | src/Validator/Validator.php | Validator.required | public function required($required = null) {
if(false === is_bool($required) && null !== $required) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type boolean, "%s" given', __METHOD__, gettype($required)), E_USER_ERROR);
}
if(null === $required) {
$required = true;
}
foreach($this -> getFieldnames() as $field) {
$this -> required[$field] = $required;
}
return $this;
} | php | public function required($required = null) {
if(false === is_bool($required) && null !== $required) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type boolean, "%s" given', __METHOD__, gettype($required)), E_USER_ERROR);
}
if(null === $required) {
$required = true;
}
foreach($this -> getFieldnames() as $field) {
$this -> required[$field] = $required;
}
return $this;
} | [
"public",
"function",
"required",
"(",
"$",
"required",
"=",
"null",
")",
"{",
"if",
"(",
"false",
"===",
"is_bool",
"(",
"$",
"required",
")",
"&&",
"null",
"!==",
"$",
"required",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type boolean, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"required",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"required",
")",
"{",
"$",
"required",
"=",
"true",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"getFieldnames",
"(",
")",
"as",
"$",
"field",
")",
"{",
"$",
"this",
"->",
"required",
"[",
"$",
"field",
"]",
"=",
"$",
"required",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set a rule that a field value can be empty or not
@param boolean|null $required
@return sFire\Validator | [
"Set",
"a",
"rule",
"that",
"a",
"field",
"value",
"can",
"be",
"empty",
"or",
"not"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Validator/Validator.php#L159-L174 | train |
Kris-Kuiper/sFire-Framework | src/Validator/Validator.php | Validator.load | public function load($classname, $name = null) {
if(false === is_string($classname)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($classname)), E_USER_ERROR);
}
if(null !== $name && false === is_string($name)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($name)), E_USER_ERROR);
}
$directories = explode('.', $classname); //Convert dots to directory seperators
$amount = count($directories) - 1;
$namespace = Router :: getRoute() -> getModule() . '\\' . str_replace(DIRECTORY_SEPARATOR, '\\', Application :: get(['directory', 'validator']));
foreach($directories as $index => $directory) {
if($amount === $index) {
$namespace .= Application :: get(['prefix', 'validator']) . ucfirst($directory);
break;
}
$namespace .= $directory . '\\';
}
if(false === class_exists($namespace)) {
return trigger_error(sprintf('Class "%s" does not exists or is not a valid validator rule', $namespace), E_USER_ERROR);
}
$name = (null !== $name ? $name : $directory);
$this -> custom[$name] = $namespace;
$instance = $this -> getMessageInstance();
$instance :: loadCustom($directory, $namespace, $name);
return $this;
} | php | public function load($classname, $name = null) {
if(false === is_string($classname)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($classname)), E_USER_ERROR);
}
if(null !== $name && false === is_string($name)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($name)), E_USER_ERROR);
}
$directories = explode('.', $classname); //Convert dots to directory seperators
$amount = count($directories) - 1;
$namespace = Router :: getRoute() -> getModule() . '\\' . str_replace(DIRECTORY_SEPARATOR, '\\', Application :: get(['directory', 'validator']));
foreach($directories as $index => $directory) {
if($amount === $index) {
$namespace .= Application :: get(['prefix', 'validator']) . ucfirst($directory);
break;
}
$namespace .= $directory . '\\';
}
if(false === class_exists($namespace)) {
return trigger_error(sprintf('Class "%s" does not exists or is not a valid validator rule', $namespace), E_USER_ERROR);
}
$name = (null !== $name ? $name : $directory);
$this -> custom[$name] = $namespace;
$instance = $this -> getMessageInstance();
$instance :: loadCustom($directory, $namespace, $name);
return $this;
} | [
"public",
"function",
"load",
"(",
"$",
"classname",
",",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"classname",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"classname",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"name",
"&&",
"false",
"===",
"is_string",
"(",
"$",
"name",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 2 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"name",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"directories",
"=",
"explode",
"(",
"'.'",
",",
"$",
"classname",
")",
";",
"//Convert dots to directory seperators\r",
"$",
"amount",
"=",
"count",
"(",
"$",
"directories",
")",
"-",
"1",
";",
"$",
"namespace",
"=",
"Router",
"::",
"getRoute",
"(",
")",
"->",
"getModule",
"(",
")",
".",
"'\\\\'",
".",
"str_replace",
"(",
"DIRECTORY_SEPARATOR",
",",
"'\\\\'",
",",
"Application",
"::",
"get",
"(",
"[",
"'directory'",
",",
"'validator'",
"]",
")",
")",
";",
"foreach",
"(",
"$",
"directories",
"as",
"$",
"index",
"=>",
"$",
"directory",
")",
"{",
"if",
"(",
"$",
"amount",
"===",
"$",
"index",
")",
"{",
"$",
"namespace",
".=",
"Application",
"::",
"get",
"(",
"[",
"'prefix'",
",",
"'validator'",
"]",
")",
".",
"ucfirst",
"(",
"$",
"directory",
")",
";",
"break",
";",
"}",
"$",
"namespace",
".=",
"$",
"directory",
".",
"'\\\\'",
";",
"}",
"if",
"(",
"false",
"===",
"class_exists",
"(",
"$",
"namespace",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Class \"%s\" does not exists or is not a valid validator rule'",
",",
"$",
"namespace",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"name",
"=",
"(",
"null",
"!==",
"$",
"name",
"?",
"$",
"name",
":",
"$",
"directory",
")",
";",
"$",
"this",
"->",
"custom",
"[",
"$",
"name",
"]",
"=",
"$",
"namespace",
";",
"$",
"instance",
"=",
"$",
"this",
"->",
"getMessageInstance",
"(",
")",
";",
"$",
"instance",
"::",
"loadCustom",
"(",
"$",
"directory",
",",
"$",
"namespace",
",",
"$",
"name",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Loads a custom validator rule with optional validator name
@param string $classname
@param string $name
@return sFire\Validator | [
"Loads",
"a",
"custom",
"validator",
"rule",
"with",
"optional",
"validator",
"name"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Validator/Validator.php#L183-L219 | train |
Kris-Kuiper/sFire-Framework | src/Validator/Validator.php | Validator.extend | public function extend($fields, $closure, $message) {
if(false === is_array($fields)) {
$fields = [(string) $fields];
}
if(false === (gettype($closure) === 'object')) {
return trigger_error(sprintf('Argument 2 passed to %s() must be a valid callback function, "%s" given', __METHOD__, gettype($closure)), E_USER_ERROR);
}
if(false === is_string($message)) {
return trigger_error(sprintf('Argument 3 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($message)), E_USER_ERROR);
}
foreach($fields as $field) {
$this -> addRule(null, $field, null, $closure, $message);
}
} | php | public function extend($fields, $closure, $message) {
if(false === is_array($fields)) {
$fields = [(string) $fields];
}
if(false === (gettype($closure) === 'object')) {
return trigger_error(sprintf('Argument 2 passed to %s() must be a valid callback function, "%s" given', __METHOD__, gettype($closure)), E_USER_ERROR);
}
if(false === is_string($message)) {
return trigger_error(sprintf('Argument 3 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($message)), E_USER_ERROR);
}
foreach($fields as $field) {
$this -> addRule(null, $field, null, $closure, $message);
}
} | [
"public",
"function",
"extend",
"(",
"$",
"fields",
",",
"$",
"closure",
",",
"$",
"message",
")",
"{",
"if",
"(",
"false",
"===",
"is_array",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"fields",
"=",
"[",
"(",
"string",
")",
"$",
"fields",
"]",
";",
"}",
"if",
"(",
"false",
"===",
"(",
"gettype",
"(",
"$",
"closure",
")",
"===",
"'object'",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 2 passed to %s() must be a valid callback function, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"closure",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"message",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 3 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"message",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"$",
"this",
"->",
"addRule",
"(",
"null",
",",
"$",
"field",
",",
"null",
",",
"$",
"closure",
",",
"$",
"message",
")",
";",
"}",
"}"
] | Add custom validation rule to one or multiple fields
@param string|array $field
@param function $closure
@param string $message | [
"Add",
"custom",
"validation",
"rule",
"to",
"one",
"or",
"multiple",
"fields"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Validator/Validator.php#L228-L245 | train |
Kris-Kuiper/sFire-Framework | src/Validator/Validator.php | Validator.getMessages | public function getMessages($fullnames = false) {
if(false === is_bool($fullnames)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type boolean, "%s" given', __METHOD__, gettype($fullnames)), E_USER_ERROR);
}
$instance = $this -> getMessageInstance();
return $instance :: getErrors($fullnames);
} | php | public function getMessages($fullnames = false) {
if(false === is_bool($fullnames)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type boolean, "%s" given', __METHOD__, gettype($fullnames)), E_USER_ERROR);
}
$instance = $this -> getMessageInstance();
return $instance :: getErrors($fullnames);
} | [
"public",
"function",
"getMessages",
"(",
"$",
"fullnames",
"=",
"false",
")",
"{",
"if",
"(",
"false",
"===",
"is_bool",
"(",
"$",
"fullnames",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type boolean, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"fullnames",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"instance",
"=",
"$",
"this",
"->",
"getMessageInstance",
"(",
")",
";",
"return",
"$",
"instance",
"::",
"getErrors",
"(",
"$",
"fullnames",
")",
";",
"}"
] | Returns all the messages
@param boolean $fullname
@return array | [
"Returns",
"all",
"the",
"messages"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Validator/Validator.php#L253-L261 | train |
Kris-Kuiper/sFire-Framework | src/Validator/Validator.php | Validator.getMessage | public function getMessage($fieldname) {
if(false === is_string($fieldname)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($fieldname)), E_USER_ERROR);
}
$instance = $this -> getMessageInstance();
$short = $instance :: getErrors();
$full = $instance :: getErrors(true);
if(true === isset($short[$fieldname])) {
return $short[$fieldname];
}
if(true === isset($full[$fieldname])) {
return $full[$fieldname];
}
} | php | public function getMessage($fieldname) {
if(false === is_string($fieldname)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($fieldname)), E_USER_ERROR);
}
$instance = $this -> getMessageInstance();
$short = $instance :: getErrors();
$full = $instance :: getErrors(true);
if(true === isset($short[$fieldname])) {
return $short[$fieldname];
}
if(true === isset($full[$fieldname])) {
return $full[$fieldname];
}
} | [
"public",
"function",
"getMessage",
"(",
"$",
"fieldname",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"fieldname",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"fieldname",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"instance",
"=",
"$",
"this",
"->",
"getMessageInstance",
"(",
")",
";",
"$",
"short",
"=",
"$",
"instance",
"::",
"getErrors",
"(",
")",
";",
"$",
"full",
"=",
"$",
"instance",
"::",
"getErrors",
"(",
"true",
")",
";",
"if",
"(",
"true",
"===",
"isset",
"(",
"$",
"short",
"[",
"$",
"fieldname",
"]",
")",
")",
"{",
"return",
"$",
"short",
"[",
"$",
"fieldname",
"]",
";",
"}",
"if",
"(",
"true",
"===",
"isset",
"(",
"$",
"full",
"[",
"$",
"fieldname",
"]",
")",
")",
"{",
"return",
"$",
"full",
"[",
"$",
"fieldname",
"]",
";",
"}",
"}"
] | Returns messages by fieldname
@param string $fiedlname
@return string | [
"Returns",
"messages",
"by",
"fieldname"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Validator/Validator.php#L269-L286 | train |
Kris-Kuiper/sFire-Framework | src/Validator/Validator.php | Validator.setPrefix | public function setPrefix($prefix = null) {
if(null !== $prefix) {
if(false === is_string($prefix)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($prefix)), E_USER_ERROR);
}
$this -> prefix = $prefix;
}
return $this;
} | php | public function setPrefix($prefix = null) {
if(null !== $prefix) {
if(false === is_string($prefix)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($prefix)), E_USER_ERROR);
}
$this -> prefix = $prefix;
}
return $this;
} | [
"public",
"function",
"setPrefix",
"(",
"$",
"prefix",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"prefix",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"prefix",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"prefix",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"this",
"->",
"prefix",
"=",
"$",
"prefix",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Sets the prefix
@param string $prefix
@return sFire\Validator\Validator | [
"Sets",
"the",
"prefix"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Validator/Validator.php#L294-L306 | train |
Kris-Kuiper/sFire-Framework | src/Validator/Validator.php | Validator.addRule | private function addRule($rule, $field, $parameters, $closue = null, $message = null) {
$this -> rules[] = (object) [
'rule' => $rule,
'field' => $field,
'parameters' => $parameters,
'closure' => $closue,
'prefix' => $this -> getPrefix(),
'message' => $message,
'required' => true
];
} | php | private function addRule($rule, $field, $parameters, $closue = null, $message = null) {
$this -> rules[] = (object) [
'rule' => $rule,
'field' => $field,
'parameters' => $parameters,
'closure' => $closue,
'prefix' => $this -> getPrefix(),
'message' => $message,
'required' => true
];
} | [
"private",
"function",
"addRule",
"(",
"$",
"rule",
",",
"$",
"field",
",",
"$",
"parameters",
",",
"$",
"closue",
"=",
"null",
",",
"$",
"message",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"rules",
"[",
"]",
"=",
"(",
"object",
")",
"[",
"'rule'",
"=>",
"$",
"rule",
",",
"'field'",
"=>",
"$",
"field",
",",
"'parameters'",
"=>",
"$",
"parameters",
",",
"'closure'",
"=>",
"$",
"closue",
",",
"'prefix'",
"=>",
"$",
"this",
"->",
"getPrefix",
"(",
")",
",",
"'message'",
"=>",
"$",
"message",
",",
"'required'",
"=>",
"true",
"]",
";",
"}"
] | Add rule to validation
@param string $rule
@param string $field
@param array $parameters | [
"Add",
"rule",
"to",
"validation"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Validator/Validator.php#L393-L405 | train |
codemojo-dr/startkit-php-sdk | src/CodeMojo/OAuth2/Client.php | Client.setAccessTokenType | public function setAccessTokenType($type, $secret = null, $algorithm = null)
{
$this->access_token_type = $type;
$this->access_token_secret = $secret;
$this->access_token_algorithm = $algorithm;
} | php | public function setAccessTokenType($type, $secret = null, $algorithm = null)
{
$this->access_token_type = $type;
$this->access_token_secret = $secret;
$this->access_token_algorithm = $algorithm;
} | [
"public",
"function",
"setAccessTokenType",
"(",
"$",
"type",
",",
"$",
"secret",
"=",
"null",
",",
"$",
"algorithm",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"access_token_type",
"=",
"$",
"type",
";",
"$",
"this",
"->",
"access_token_secret",
"=",
"$",
"secret",
";",
"$",
"this",
"->",
"access_token_algorithm",
"=",
"$",
"algorithm",
";",
"}"
] | Set the access token type
@param int $type Access token type (ACCESS_TOKEN_BEARER, ACCESS_TOKEN_MAC, ACCESS_TOKEN_URI)
@param string $secret The secret key used to encrypt the MAC header
@param string $algorithm Algorithm used to encrypt the signature
@return void | [
"Set",
"the",
"access",
"token",
"type"
] | cd2227e1a221be2cd75dc96d1c9e0acfda936fb3 | https://github.com/codemojo-dr/startkit-php-sdk/blob/cd2227e1a221be2cd75dc96d1c9e0acfda936fb3/src/CodeMojo/OAuth2/Client.php#L309-L314 | train |
codemojo-dr/startkit-php-sdk | src/CodeMojo/OAuth2/Client.php | Client.generateMACSignature | private function generateMACSignature($url, $parameters, $http_method)
{
$timestamp = time();
$nonce = uniqid();
$parsed_url = parse_url($url);
if (!isset($parsed_url['port']))
{
$parsed_url['port'] = ($parsed_url['scheme'] == 'https') ? 443 : 80;
}
if ($http_method == self::HTTP_METHOD_GET) {
if (is_array($parameters)) {
$parsed_url['path'] .= '?' . http_build_query($parameters, null, '&');
} elseif ($parameters) {
$parsed_url['path'] .= '?' . $parameters;
}
}
$signature = base64_encode(hash_hmac($this->access_token_algorithm,
$timestamp . "\n"
. $nonce . "\n"
. $http_method . "\n"
. $parsed_url['path'] . "\n"
. $parsed_url['host'] . "\n"
. $parsed_url['port'] . "\n\n"
, $this->access_token_secret, true));
return 'id="' . $this->access_token . '", ts="' . $timestamp . '", nonce="' . $nonce . '", mac="' . $signature . '"';
} | php | private function generateMACSignature($url, $parameters, $http_method)
{
$timestamp = time();
$nonce = uniqid();
$parsed_url = parse_url($url);
if (!isset($parsed_url['port']))
{
$parsed_url['port'] = ($parsed_url['scheme'] == 'https') ? 443 : 80;
}
if ($http_method == self::HTTP_METHOD_GET) {
if (is_array($parameters)) {
$parsed_url['path'] .= '?' . http_build_query($parameters, null, '&');
} elseif ($parameters) {
$parsed_url['path'] .= '?' . $parameters;
}
}
$signature = base64_encode(hash_hmac($this->access_token_algorithm,
$timestamp . "\n"
. $nonce . "\n"
. $http_method . "\n"
. $parsed_url['path'] . "\n"
. $parsed_url['host'] . "\n"
. $parsed_url['port'] . "\n\n"
, $this->access_token_secret, true));
return 'id="' . $this->access_token . '", ts="' . $timestamp . '", nonce="' . $nonce . '", mac="' . $signature . '"';
} | [
"private",
"function",
"generateMACSignature",
"(",
"$",
"url",
",",
"$",
"parameters",
",",
"$",
"http_method",
")",
"{",
"$",
"timestamp",
"=",
"time",
"(",
")",
";",
"$",
"nonce",
"=",
"uniqid",
"(",
")",
";",
"$",
"parsed_url",
"=",
"parse_url",
"(",
"$",
"url",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"parsed_url",
"[",
"'port'",
"]",
")",
")",
"{",
"$",
"parsed_url",
"[",
"'port'",
"]",
"=",
"(",
"$",
"parsed_url",
"[",
"'scheme'",
"]",
"==",
"'https'",
")",
"?",
"443",
":",
"80",
";",
"}",
"if",
"(",
"$",
"http_method",
"==",
"self",
"::",
"HTTP_METHOD_GET",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"parameters",
")",
")",
"{",
"$",
"parsed_url",
"[",
"'path'",
"]",
".=",
"'?'",
".",
"http_build_query",
"(",
"$",
"parameters",
",",
"null",
",",
"'&'",
")",
";",
"}",
"elseif",
"(",
"$",
"parameters",
")",
"{",
"$",
"parsed_url",
"[",
"'path'",
"]",
".=",
"'?'",
".",
"$",
"parameters",
";",
"}",
"}",
"$",
"signature",
"=",
"base64_encode",
"(",
"hash_hmac",
"(",
"$",
"this",
"->",
"access_token_algorithm",
",",
"$",
"timestamp",
".",
"\"\\n\"",
".",
"$",
"nonce",
".",
"\"\\n\"",
".",
"$",
"http_method",
".",
"\"\\n\"",
".",
"$",
"parsed_url",
"[",
"'path'",
"]",
".",
"\"\\n\"",
".",
"$",
"parsed_url",
"[",
"'host'",
"]",
".",
"\"\\n\"",
".",
"$",
"parsed_url",
"[",
"'port'",
"]",
".",
"\"\\n\\n\"",
",",
"$",
"this",
"->",
"access_token_secret",
",",
"true",
")",
")",
";",
"return",
"'id=\"'",
".",
"$",
"this",
"->",
"access_token",
".",
"'\", ts=\"'",
".",
"$",
"timestamp",
".",
"'\", nonce=\"'",
".",
"$",
"nonce",
".",
"'\", mac=\"'",
".",
"$",
"signature",
".",
"'\"'",
";",
"}"
] | Generate the MAC signature
@param string $url Called URL
@param array $parameters Parameters
@param string $http_method Http Method
@return string | [
"Generate",
"the",
"MAC",
"signature"
] | cd2227e1a221be2cd75dc96d1c9e0acfda936fb3 | https://github.com/codemojo-dr/startkit-php-sdk/blob/cd2227e1a221be2cd75dc96d1c9e0acfda936fb3/src/CodeMojo/OAuth2/Client.php#L365-L392 | train |
codemojo-dr/startkit-php-sdk | src/CodeMojo/OAuth2/Client.php | Client.convertToCamelCase | private function convertToCamelCase($grant_type)
{
$parts = explode('_', $grant_type);
array_walk($parts, function(&$item) { $item = ucfirst($item);});
return implode('', $parts);
} | php | private function convertToCamelCase($grant_type)
{
$parts = explode('_', $grant_type);
array_walk($parts, function(&$item) { $item = ucfirst($item);});
return implode('', $parts);
} | [
"private",
"function",
"convertToCamelCase",
"(",
"$",
"grant_type",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'_'",
",",
"$",
"grant_type",
")",
";",
"array_walk",
"(",
"$",
"parts",
",",
"function",
"(",
"&",
"$",
"item",
")",
"{",
"$",
"item",
"=",
"ucfirst",
"(",
"$",
"item",
")",
";",
"}",
")",
";",
"return",
"implode",
"(",
"''",
",",
"$",
"parts",
")",
";",
"}"
] | Converts the class name to camel case
@param mixed $grant_type the grant type
@return string | [
"Converts",
"the",
"class",
"name",
"to",
"camel",
"case"
] | cd2227e1a221be2cd75dc96d1c9e0acfda936fb3 | https://github.com/codemojo-dr/startkit-php-sdk/blob/cd2227e1a221be2cd75dc96d1c9e0acfda936fb3/src/CodeMojo/OAuth2/Client.php#L503-L508 | train |
vanilla/garden-daemon | src/Lock.php | Lock.isLocked | public function isLocked($recover = true) {
$myPid = getmypid();
if (!file_exists($this->pidFile)) {
return false;
}
$lockPid = trim(file_get_contents($this->pidFile));
// This is my lockfile, nothing to do
if ($myPid == $lockPid) {
return false;
}
// Is the PID running?
$isRunning = $this->isProcessRunning($lockPid);
// No? Unlock and return Locked=false
if (!$isRunning) {
if ($recover) {
$this->unlock($this->pidFile);
}
return false;
}
// Someone else is already running
return true;
} | php | public function isLocked($recover = true) {
$myPid = getmypid();
if (!file_exists($this->pidFile)) {
return false;
}
$lockPid = trim(file_get_contents($this->pidFile));
// This is my lockfile, nothing to do
if ($myPid == $lockPid) {
return false;
}
// Is the PID running?
$isRunning = $this->isProcessRunning($lockPid);
// No? Unlock and return Locked=false
if (!$isRunning) {
if ($recover) {
$this->unlock($this->pidFile);
}
return false;
}
// Someone else is already running
return true;
} | [
"public",
"function",
"isLocked",
"(",
"$",
"recover",
"=",
"true",
")",
"{",
"$",
"myPid",
"=",
"getmypid",
"(",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"pidFile",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"lockPid",
"=",
"trim",
"(",
"file_get_contents",
"(",
"$",
"this",
"->",
"pidFile",
")",
")",
";",
"// This is my lockfile, nothing to do",
"if",
"(",
"$",
"myPid",
"==",
"$",
"lockPid",
")",
"{",
"return",
"false",
";",
"}",
"// Is the PID running?",
"$",
"isRunning",
"=",
"$",
"this",
"->",
"isProcessRunning",
"(",
"$",
"lockPid",
")",
";",
"// No? Unlock and return Locked=false",
"if",
"(",
"!",
"$",
"isRunning",
")",
"{",
"if",
"(",
"$",
"recover",
")",
"{",
"$",
"this",
"->",
"unlock",
"(",
"$",
"this",
"->",
"pidFile",
")",
";",
"}",
"return",
"false",
";",
"}",
"// Someone else is already running",
"return",
"true",
";",
"}"
] | Check if this lockFile corresponds to a locked process
@param boolean $recover
@return boolean | [
"Check",
"if",
"this",
"lockFile",
"corresponds",
"to",
"a",
"locked",
"process"
] | 13a5cbbac08ab6473e4b11bf00179fe1e26235a6 | https://github.com/vanilla/garden-daemon/blob/13a5cbbac08ab6473e4b11bf00179fe1e26235a6/src/Lock.php#L60-L86 | train |
vanilla/garden-daemon | src/Lock.php | Lock.isProcessRunning | public function isProcessRunning($pid) {
if (!$pid) {
return false;
}
// Is the PID running?
$running = posix_kill($pid, 0);
if (!$running) {
return false;
}
// Did we have trouble pinging that PID?
$psExists = !(bool)posix_get_last_error();
return $psExists;
} | php | public function isProcessRunning($pid) {
if (!$pid) {
return false;
}
// Is the PID running?
$running = posix_kill($pid, 0);
if (!$running) {
return false;
}
// Did we have trouble pinging that PID?
$psExists = !(bool)posix_get_last_error();
return $psExists;
} | [
"public",
"function",
"isProcessRunning",
"(",
"$",
"pid",
")",
"{",
"if",
"(",
"!",
"$",
"pid",
")",
"{",
"return",
"false",
";",
"}",
"// Is the PID running?",
"$",
"running",
"=",
"posix_kill",
"(",
"$",
"pid",
",",
"0",
")",
";",
"if",
"(",
"!",
"$",
"running",
")",
"{",
"return",
"false",
";",
"}",
"// Did we have trouble pinging that PID?",
"$",
"psExists",
"=",
"!",
"(",
"bool",
")",
"posix_get_last_error",
"(",
")",
";",
"return",
"$",
"psExists",
";",
"}"
] | Check if a pid is running
@param string $pid
@return boolean | [
"Check",
"if",
"a",
"pid",
"is",
"running"
] | 13a5cbbac08ab6473e4b11bf00179fe1e26235a6 | https://github.com/vanilla/garden-daemon/blob/13a5cbbac08ab6473e4b11bf00179fe1e26235a6/src/Lock.php#L94-L109 | train |
vanilla/garden-daemon | src/Lock.php | Lock.getRunningPID | public function getRunningPID() {
if (!file_exists($this->pidFile)) {
return false;
}
$runPid = trim(file_get_contents($this->pidFile));
if (!$runPid) {
return false;
}
return $runPid;
} | php | public function getRunningPID() {
if (!file_exists($this->pidFile)) {
return false;
}
$runPid = trim(file_get_contents($this->pidFile));
if (!$runPid) {
return false;
}
return $runPid;
} | [
"public",
"function",
"getRunningPID",
"(",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"pidFile",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"runPid",
"=",
"trim",
"(",
"file_get_contents",
"(",
"$",
"this",
"->",
"pidFile",
")",
")",
";",
"if",
"(",
"!",
"$",
"runPid",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"runPid",
";",
"}"
] | Get agent pid
@return integer|false | [
"Get",
"agent",
"pid"
] | 13a5cbbac08ab6473e4b11bf00179fe1e26235a6 | https://github.com/vanilla/garden-daemon/blob/13a5cbbac08ab6473e4b11bf00179fe1e26235a6/src/Lock.php#L116-L127 | train |
ekyna/MediaBundle | Model/MediaTypes.php | MediaTypes.guessByMimeType | static public function guessByMimeType($mimeType)
{
switch (substr($mimeType, 0, strpos($mimeType, '/'))) {
case 'audio' : return self::AUDIO; break;
case 'image' : return self::IMAGE; break;
case 'video' : return self::VIDEO; break;
}
if (preg_match('~zip|rar|compress~', $mimeType)) {
return self::ARCHIVE;
}
if ($mimeType === 'application/x-shockwave-flash') {
return self::FLASH;
}
return self::FILE;
} | php | static public function guessByMimeType($mimeType)
{
switch (substr($mimeType, 0, strpos($mimeType, '/'))) {
case 'audio' : return self::AUDIO; break;
case 'image' : return self::IMAGE; break;
case 'video' : return self::VIDEO; break;
}
if (preg_match('~zip|rar|compress~', $mimeType)) {
return self::ARCHIVE;
}
if ($mimeType === 'application/x-shockwave-flash') {
return self::FLASH;
}
return self::FILE;
} | [
"static",
"public",
"function",
"guessByMimeType",
"(",
"$",
"mimeType",
")",
"{",
"switch",
"(",
"substr",
"(",
"$",
"mimeType",
",",
"0",
",",
"strpos",
"(",
"$",
"mimeType",
",",
"'/'",
")",
")",
")",
"{",
"case",
"'audio'",
":",
"return",
"self",
"::",
"AUDIO",
";",
"break",
";",
"case",
"'image'",
":",
"return",
"self",
"::",
"IMAGE",
";",
"break",
";",
"case",
"'video'",
":",
"return",
"self",
"::",
"VIDEO",
";",
"break",
";",
"}",
"if",
"(",
"preg_match",
"(",
"'~zip|rar|compress~'",
",",
"$",
"mimeType",
")",
")",
"{",
"return",
"self",
"::",
"ARCHIVE",
";",
"}",
"if",
"(",
"$",
"mimeType",
"===",
"'application/x-shockwave-flash'",
")",
"{",
"return",
"self",
"::",
"FLASH",
";",
"}",
"return",
"self",
"::",
"FILE",
";",
"}"
] | Guess the type by mime type.
@param $mimeType
@return string | [
"Guess",
"the",
"type",
"by",
"mime",
"type",
"."
] | 512cf86c801a130a9f17eba8b48d646d23acdbab | https://github.com/ekyna/MediaBundle/blob/512cf86c801a130a9f17eba8b48d646d23acdbab/Model/MediaTypes.php#L43-L60 | train |
linpax/microphp-framework | src/filter/CsrfFilter.php | CsrfFilter.insertProtect | public function insertProtect(array $matches = [])
{
$gen = md5(mt_rand());
/** @var ISession $s */
$s = (new SessionInjector)->build();
$s->csrf = array_merge(is_array($s->csrf) ? $s->csrf : [], [md5($gen)]);
return $matches[1].'<input type="hidden" name="csrf" value="'.$gen.'" />'.$matches[2].$matches[3];
} | php | public function insertProtect(array $matches = [])
{
$gen = md5(mt_rand());
/** @var ISession $s */
$s = (new SessionInjector)->build();
$s->csrf = array_merge(is_array($s->csrf) ? $s->csrf : [], [md5($gen)]);
return $matches[1].'<input type="hidden" name="csrf" value="'.$gen.'" />'.$matches[2].$matches[3];
} | [
"public",
"function",
"insertProtect",
"(",
"array",
"$",
"matches",
"=",
"[",
"]",
")",
"{",
"$",
"gen",
"=",
"md5",
"(",
"mt_rand",
"(",
")",
")",
";",
"/** @var ISession $s */",
"$",
"s",
"=",
"(",
"new",
"SessionInjector",
")",
"->",
"build",
"(",
")",
";",
"$",
"s",
"->",
"csrf",
"=",
"array_merge",
"(",
"is_array",
"(",
"$",
"s",
"->",
"csrf",
")",
"?",
"$",
"s",
"->",
"csrf",
":",
"[",
"]",
",",
"[",
"md5",
"(",
"$",
"gen",
")",
"]",
")",
";",
"return",
"$",
"matches",
"[",
"1",
"]",
".",
"'<input type=\"hidden\" name=\"csrf\" value=\"'",
".",
"$",
"gen",
".",
"'\" />'",
".",
"$",
"matches",
"[",
"2",
"]",
".",
"$",
"matches",
"[",
"3",
"]",
";",
"}"
] | Insert CSRF protect into forms
@access public
@param array $matches Form
@return string
@throws Exception | [
"Insert",
"CSRF",
"protect",
"into",
"forms"
] | 11f3370f3f64c516cce9b84ecd8276c6e9ae8df9 | https://github.com/linpax/microphp-framework/blob/11f3370f3f64c516cce9b84ecd8276c6e9ae8df9/src/filter/CsrfFilter.php#L94-L103 | train |
larapulse/support | src/Handlers/Str.php | Str.pop | public static function pop(string &$str, string $encoding = null)
{
$encoding = $encoding ?: mb_internal_encoding();
$last = mb_substr($str, -1, null, $encoding);
$str = mb_substr($str, 0, -1, $encoding);
return $last;
} | php | public static function pop(string &$str, string $encoding = null)
{
$encoding = $encoding ?: mb_internal_encoding();
$last = mb_substr($str, -1, null, $encoding);
$str = mb_substr($str, 0, -1, $encoding);
return $last;
} | [
"public",
"static",
"function",
"pop",
"(",
"string",
"&",
"$",
"str",
",",
"string",
"$",
"encoding",
"=",
"null",
")",
"{",
"$",
"encoding",
"=",
"$",
"encoding",
"?",
":",
"mb_internal_encoding",
"(",
")",
";",
"$",
"last",
"=",
"mb_substr",
"(",
"$",
"str",
",",
"-",
"1",
",",
"null",
",",
"$",
"encoding",
")",
";",
"$",
"str",
"=",
"mb_substr",
"(",
"$",
"str",
",",
"0",
",",
"-",
"1",
",",
"$",
"encoding",
")",
";",
"return",
"$",
"last",
";",
"}"
] | Pop the character off the end of string
@param string $str
@param string $encoding
@return bool|string | [
"Pop",
"the",
"character",
"off",
"the",
"end",
"of",
"string"
] | 601ee3fd6967be669afe081322340c82c7edf32d | https://github.com/larapulse/support/blob/601ee3fd6967be669afe081322340c82c7edf32d/src/Handlers/Str.php#L17-L25 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.