repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
153
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
sequence | func_documentation_string
stringlengths 1
46.9k
| func_documentation_tokens
sequence | split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
Hexmedia/Administrator-Bundle | EventListener/ToolbarListener.php | ToolbarListener.injectToolbar | protected function injectToolbar(Response $response, Request $request)
{
if (function_exists('mb_stripos')) {
$posrFunction = 'mb_strripos';
$substrFunction = 'mb_substr';
} else {
$posrFunction = 'strripos';
$substrFunction = 'substr';
}
$content = $response->getContent();
$pos = $posrFunction($content, '</body>');
if ($pos !== false) {
$session = $request->getSession();
$editMode = $session->get('hexmedia_content_edit_mode') === true;
$toolbar = $this->twig->render(
"HexmediaAdministratorBundle:Toolbar:toolbar.html.twig",
[
'edit_mode' => $editMode,
'edit_mode_class' => $editMode ? 'in-edit-mode' : ''
]
);
$content = $substrFunction($content, 0, $pos) . $toolbar . $substrFunction($content, $pos);
$response->setContent($content);
}
} | php | protected function injectToolbar(Response $response, Request $request)
{
if (function_exists('mb_stripos')) {
$posrFunction = 'mb_strripos';
$substrFunction = 'mb_substr';
} else {
$posrFunction = 'strripos';
$substrFunction = 'substr';
}
$content = $response->getContent();
$pos = $posrFunction($content, '</body>');
if ($pos !== false) {
$session = $request->getSession();
$editMode = $session->get('hexmedia_content_edit_mode') === true;
$toolbar = $this->twig->render(
"HexmediaAdministratorBundle:Toolbar:toolbar.html.twig",
[
'edit_mode' => $editMode,
'edit_mode_class' => $editMode ? 'in-edit-mode' : ''
]
);
$content = $substrFunction($content, 0, $pos) . $toolbar . $substrFunction($content, $pos);
$response->setContent($content);
}
} | [
"protected",
"function",
"injectToolbar",
"(",
"Response",
"$",
"response",
",",
"Request",
"$",
"request",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'mb_stripos'",
")",
")",
"{",
"$",
"posrFunction",
"=",
"'mb_strripos'",
";",
"$",
"substrFunction",
"=",
"'mb_substr'",
";",
"}",
"else",
"{",
"$",
"posrFunction",
"=",
"'strripos'",
";",
"$",
"substrFunction",
"=",
"'substr'",
";",
"}",
"$",
"content",
"=",
"$",
"response",
"->",
"getContent",
"(",
")",
";",
"$",
"pos",
"=",
"$",
"posrFunction",
"(",
"$",
"content",
",",
"'</body>'",
")",
";",
"if",
"(",
"$",
"pos",
"!==",
"false",
")",
"{",
"$",
"session",
"=",
"$",
"request",
"->",
"getSession",
"(",
")",
";",
"$",
"editMode",
"=",
"$",
"session",
"->",
"get",
"(",
"'hexmedia_content_edit_mode'",
")",
"===",
"true",
";",
"$",
"toolbar",
"=",
"$",
"this",
"->",
"twig",
"->",
"render",
"(",
"\"HexmediaAdministratorBundle:Toolbar:toolbar.html.twig\"",
",",
"[",
"'edit_mode'",
"=>",
"$",
"editMode",
",",
"'edit_mode_class'",
"=>",
"$",
"editMode",
"?",
"'in-edit-mode'",
":",
"''",
"]",
")",
";",
"$",
"content",
"=",
"$",
"substrFunction",
"(",
"$",
"content",
",",
"0",
",",
"$",
"pos",
")",
".",
"$",
"toolbar",
".",
"$",
"substrFunction",
"(",
"$",
"content",
",",
"$",
"pos",
")",
";",
"$",
"response",
"->",
"setContent",
"(",
"$",
"content",
")",
";",
"}",
"}"
] | Injects the web debug toolbar into the given Response.
@param Response $response A Response instance | [
"Injects",
"the",
"web",
"debug",
"toolbar",
"into",
"the",
"given",
"Response",
"."
] | train | https://github.com/Hexmedia/Administrator-Bundle/blob/ac76cf3d226cd645a0976cfb6f3e6b058fa89890/EventListener/ToolbarListener.php#L85-L115 |
owenwilljones/Tadpole-Components | conf_class.php | conf.init | public function init($vars) {
foreach($vars as $n => $v) {
if($n == 'db') self::$db = $v;
else if($n == 'error') self::$e = $v;
else self::$add[$n] = $v;
}
} | php | public function init($vars) {
foreach($vars as $n => $v) {
if($n == 'db') self::$db = $v;
else if($n == 'error') self::$e = $v;
else self::$add[$n] = $v;
}
} | [
"public",
"function",
"init",
"(",
"$",
"vars",
")",
"{",
"foreach",
"(",
"$",
"vars",
"as",
"$",
"n",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"$",
"n",
"==",
"'db'",
")",
"self",
"::",
"$",
"db",
"=",
"$",
"v",
";",
"else",
"if",
"(",
"$",
"n",
"==",
"'error'",
")",
"self",
"::",
"$",
"e",
"=",
"$",
"v",
";",
"else",
"self",
"::",
"$",
"add",
"[",
"$",
"n",
"]",
"=",
"$",
"v",
";",
"}",
"}"
] | Any settings/vars added to the config array are stored here | [
"Any",
"settings",
"/",
"vars",
"added",
"to",
"the",
"config",
"array",
"are",
"stored",
"here"
] | train | https://github.com/owenwilljones/Tadpole-Components/blob/ff63ce220c673cdec7d8cfd643cca1a32ca34f4c/conf_class.php#L11-L17 |
unyx/utils | Math.php | Math.countDecimals | public static function countDecimals(float $value)
{
// When the value when cast to an integer is about the same, return 0 decimal places. Otherwise count them.
return (int) $value == $value ? 0 : (strlen($value) - strrpos($value, '.') - 1);
} | php | public static function countDecimals(float $value)
{
// When the value when cast to an integer is about the same, return 0 decimal places. Otherwise count them.
return (int) $value == $value ? 0 : (strlen($value) - strrpos($value, '.') - 1);
} | [
"public",
"static",
"function",
"countDecimals",
"(",
"float",
"$",
"value",
")",
"{",
"// When the value when cast to an integer is about the same, return 0 decimal places. Otherwise count them.",
"return",
"(",
"int",
")",
"$",
"value",
"==",
"$",
"value",
"?",
"0",
":",
"(",
"strlen",
"(",
"$",
"value",
")",
"-",
"strrpos",
"(",
"$",
"value",
",",
"'.'",
")",
"-",
"1",
")",
";",
"}"
] | Returns the number of decimal places contained in the given number.
@param float $value The number to count the decimal places of.
@return int|bool The number of decimal places or false if the given $value was not numeric. | [
"Returns",
"the",
"number",
"of",
"decimal",
"places",
"contained",
"in",
"the",
"given",
"number",
"."
] | train | https://github.com/unyx/utils/blob/503a3dd46fd2216024ab771b6e830be16d36b358/Math.php#L44-L48 |
unyx/utils | Math.php | Math.detectConstant | public static function detectConstant(float $value, int $precision = 6)
{
foreach (static::CONSTANTS as $name => $constant) {
if (0 === bccomp($value, $constant, max($precision - 1, 4))) {
return $name;
}
}
return null;
} | php | public static function detectConstant(float $value, int $precision = 6)
{
foreach (static::CONSTANTS as $name => $constant) {
if (0 === bccomp($value, $constant, max($precision - 1, 4))) {
return $name;
}
}
return null;
} | [
"public",
"static",
"function",
"detectConstant",
"(",
"float",
"$",
"value",
",",
"int",
"$",
"precision",
"=",
"6",
")",
"{",
"foreach",
"(",
"static",
"::",
"CONSTANTS",
"as",
"$",
"name",
"=>",
"$",
"constant",
")",
"{",
"if",
"(",
"0",
"===",
"bccomp",
"(",
"$",
"value",
",",
"$",
"constant",
",",
"max",
"(",
"$",
"precision",
"-",
"1",
",",
"4",
")",
")",
")",
"{",
"return",
"$",
"name",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Checks whether the given value is a mathematical constant (one of self::$constants) and returns its name
when it is.
@param float $value The number to check.
@param int $precision The decimal precision of the check, 4 at minimum.
@return string The name of the constant (one of the keys of self::$constants) or null if
the given value is not a constant. | [
"Checks",
"whether",
"the",
"given",
"value",
"is",
"a",
"mathematical",
"constant",
"(",
"one",
"of",
"self",
"::",
"$constants",
")",
"and",
"returns",
"its",
"name",
"when",
"it",
"is",
"."
] | train | https://github.com/unyx/utils/blob/503a3dd46fd2216024ab771b6e830be16d36b358/Math.php#L59-L68 |
phpservicebus/core | src/MessageMutation/IncomingMessageMutationFeature.php | IncomingMessageMutationFeature.setup | public function setup(Settings $settings, BuilderInterface $builder, PipelineModifications $pipelineModifications)
{
$pipelineModifications->registerStep(
'IncomingLogicalMessageMutation',
IncomingLogicalMessageMutationPipelineStep::class,
function () use ($builder) {
return new IncomingLogicalMessageMutationPipelineStep(
$builder->build(MessageMutatorRegistry::class),
$builder->build(IncomingLogicalMessageFactory::class)
);
}
);
$pipelineModifications->registerStep(
'IncomingPhysicalMessageMutation',
IncomingPhysicalMessageMutationPipelineStep::class,
function () use ($builder) {
return new IncomingPhysicalMessageMutationPipelineStep($builder->build(MessageMutatorRegistry::class));
}
);
} | php | public function setup(Settings $settings, BuilderInterface $builder, PipelineModifications $pipelineModifications)
{
$pipelineModifications->registerStep(
'IncomingLogicalMessageMutation',
IncomingLogicalMessageMutationPipelineStep::class,
function () use ($builder) {
return new IncomingLogicalMessageMutationPipelineStep(
$builder->build(MessageMutatorRegistry::class),
$builder->build(IncomingLogicalMessageFactory::class)
);
}
);
$pipelineModifications->registerStep(
'IncomingPhysicalMessageMutation',
IncomingPhysicalMessageMutationPipelineStep::class,
function () use ($builder) {
return new IncomingPhysicalMessageMutationPipelineStep($builder->build(MessageMutatorRegistry::class));
}
);
} | [
"public",
"function",
"setup",
"(",
"Settings",
"$",
"settings",
",",
"BuilderInterface",
"$",
"builder",
",",
"PipelineModifications",
"$",
"pipelineModifications",
")",
"{",
"$",
"pipelineModifications",
"->",
"registerStep",
"(",
"'IncomingLogicalMessageMutation'",
",",
"IncomingLogicalMessageMutationPipelineStep",
"::",
"class",
",",
"function",
"(",
")",
"use",
"(",
"$",
"builder",
")",
"{",
"return",
"new",
"IncomingLogicalMessageMutationPipelineStep",
"(",
"$",
"builder",
"->",
"build",
"(",
"MessageMutatorRegistry",
"::",
"class",
")",
",",
"$",
"builder",
"->",
"build",
"(",
"IncomingLogicalMessageFactory",
"::",
"class",
")",
")",
";",
"}",
")",
";",
"$",
"pipelineModifications",
"->",
"registerStep",
"(",
"'IncomingPhysicalMessageMutation'",
",",
"IncomingPhysicalMessageMutationPipelineStep",
"::",
"class",
",",
"function",
"(",
")",
"use",
"(",
"$",
"builder",
")",
"{",
"return",
"new",
"IncomingPhysicalMessageMutationPipelineStep",
"(",
"$",
"builder",
"->",
"build",
"(",
"MessageMutatorRegistry",
"::",
"class",
")",
")",
";",
"}",
")",
";",
"}"
] | Method is called if all defined conditions are met and the feature is marked as enabled.
Use this method to configure and initialize all required components for the feature like
the steps in the pipeline or the instances/factories in the container.
@param Settings $settings
@param BuilderInterface $builder
@param PipelineModifications $pipelineModifications | [
"Method",
"is",
"called",
"if",
"all",
"defined",
"conditions",
"are",
"met",
"and",
"the",
"feature",
"is",
"marked",
"as",
"enabled",
".",
"Use",
"this",
"method",
"to",
"configure",
"and",
"initialize",
"all",
"required",
"components",
"for",
"the",
"feature",
"like",
"the",
"steps",
"in",
"the",
"pipeline",
"or",
"the",
"instances",
"/",
"factories",
"in",
"the",
"container",
"."
] | train | https://github.com/phpservicebus/core/blob/adbcf94be1e022120ede0c5aafa8a4f7900b0a6c/src/MessageMutation/IncomingMessageMutationFeature.php#L35-L55 |
sellerlabs/nucleus | src/SellerLabs/Nucleus/Data/IterableType.php | IterableType.takeUntil | public function takeUntil(callable $predicate)
{
return $this->takeWhile(
function ($value, $key, $iterable) use ($predicate) {
return !$predicate($value, $key, $iterable);
}
);
} | php | public function takeUntil(callable $predicate)
{
return $this->takeWhile(
function ($value, $key, $iterable) use ($predicate) {
return !$predicate($value, $key, $iterable);
}
);
} | [
"public",
"function",
"takeUntil",
"(",
"callable",
"$",
"predicate",
")",
"{",
"return",
"$",
"this",
"->",
"takeWhile",
"(",
"function",
"(",
"$",
"value",
",",
"$",
"key",
",",
"$",
"iterable",
")",
"use",
"(",
"$",
"predicate",
")",
"{",
"return",
"!",
"$",
"predicate",
"(",
"$",
"value",
",",
"$",
"key",
",",
"$",
"iterable",
")",
";",
"}",
")",
";",
"}"
] | @param callable $predicate
@return IterableType | [
"@param",
"callable",
"$predicate"
] | train | https://github.com/sellerlabs/nucleus/blob/c05d9c23d424a6bd5ab2e29140805cc6e37e4623/src/SellerLabs/Nucleus/Data/IterableType.php#L234-L241 |
sellerlabs/nucleus | src/SellerLabs/Nucleus/Data/IterableType.php | IterableType.find | public function find(callable $predicate)
{
$result = Maybe::nothing();
$this->each(
function ($value, $key) use (
$predicate,
&$result
) {
if ($predicate($value, $key, $this)) {
$result = Maybe::just($value);
return false;
}
return true;
}
);
return $result;
} | php | public function find(callable $predicate)
{
$result = Maybe::nothing();
$this->each(
function ($value, $key) use (
$predicate,
&$result
) {
if ($predicate($value, $key, $this)) {
$result = Maybe::just($value);
return false;
}
return true;
}
);
return $result;
} | [
"public",
"function",
"find",
"(",
"callable",
"$",
"predicate",
")",
"{",
"$",
"result",
"=",
"Maybe",
"::",
"nothing",
"(",
")",
";",
"$",
"this",
"->",
"each",
"(",
"function",
"(",
"$",
"value",
",",
"$",
"key",
")",
"use",
"(",
"$",
"predicate",
",",
"&",
"$",
"result",
")",
"{",
"if",
"(",
"$",
"predicate",
"(",
"$",
"value",
",",
"$",
"key",
",",
"$",
"this",
")",
")",
"{",
"$",
"result",
"=",
"Maybe",
"::",
"just",
"(",
"$",
"value",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}",
")",
";",
"return",
"$",
"result",
";",
"}"
] | @param callable $predicate
@return Maybe | [
"@param",
"callable",
"$predicate"
] | train | https://github.com/sellerlabs/nucleus/blob/c05d9c23d424a6bd5ab2e29140805cc6e37e4623/src/SellerLabs/Nucleus/Data/IterableType.php#L256-L276 |
lexide/reposition | src/Repository/RepositoryManager.php | RepositoryManager.getEntityMetadata | public function getEntityMetadata($entity)
{
if (is_object($entity)) {
$entity = get_class($entity);
}
try {
$repository = $this->getRepositoryFor($entity);
} catch (RepositoryException $e) {
// check for base classes
$parent = $entity;
while($parent = get_parent_class($parent)) {
try {
$repository = $this->getRepositoryFor($parent);
break;
} catch (RepositoryException $e) {
}
}
if (empty($repository)) {
throw new MetadataException("Cannot get metadata, no repository class exists for '$entity'");
}
}
if (!$repository instanceof MetadataRepositoryInterface) {
throw new MetadataException("Cannot get metadata for '$entity', the repository class for the entity does not supply metadata information.");
}
return $repository->getEntityMetadata();
} | php | public function getEntityMetadata($entity)
{
if (is_object($entity)) {
$entity = get_class($entity);
}
try {
$repository = $this->getRepositoryFor($entity);
} catch (RepositoryException $e) {
// check for base classes
$parent = $entity;
while($parent = get_parent_class($parent)) {
try {
$repository = $this->getRepositoryFor($parent);
break;
} catch (RepositoryException $e) {
}
}
if (empty($repository)) {
throw new MetadataException("Cannot get metadata, no repository class exists for '$entity'");
}
}
if (!$repository instanceof MetadataRepositoryInterface) {
throw new MetadataException("Cannot get metadata for '$entity', the repository class for the entity does not supply metadata information.");
}
return $repository->getEntityMetadata();
} | [
"public",
"function",
"getEntityMetadata",
"(",
"$",
"entity",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"entity",
")",
")",
"{",
"$",
"entity",
"=",
"get_class",
"(",
"$",
"entity",
")",
";",
"}",
"try",
"{",
"$",
"repository",
"=",
"$",
"this",
"->",
"getRepositoryFor",
"(",
"$",
"entity",
")",
";",
"}",
"catch",
"(",
"RepositoryException",
"$",
"e",
")",
"{",
"// check for base classes",
"$",
"parent",
"=",
"$",
"entity",
";",
"while",
"(",
"$",
"parent",
"=",
"get_parent_class",
"(",
"$",
"parent",
")",
")",
"{",
"try",
"{",
"$",
"repository",
"=",
"$",
"this",
"->",
"getRepositoryFor",
"(",
"$",
"parent",
")",
";",
"break",
";",
"}",
"catch",
"(",
"RepositoryException",
"$",
"e",
")",
"{",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"repository",
")",
")",
"{",
"throw",
"new",
"MetadataException",
"(",
"\"Cannot get metadata, no repository class exists for '$entity'\"",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"repository",
"instanceof",
"MetadataRepositoryInterface",
")",
"{",
"throw",
"new",
"MetadataException",
"(",
"\"Cannot get metadata for '$entity', the repository class for the entity does not supply metadata information.\"",
")",
";",
"}",
"return",
"$",
"repository",
"->",
"getEntityMetadata",
"(",
")",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/lexide/reposition/blob/aa02735271f0c0ee4a3fb679093d4d3823963b3a/src/Repository/RepositoryManager.php#L112-L140 |
lexide/reposition | src/Repository/RepositoryManager.php | RepositoryManager.getEntityMetadataForIntermediary | public function getEntityMetadataForIntermediary($collection)
{
$metadata = $this->metadataFactory->createEmptyMetadata();
$metadata->setCollection($collection);
return $metadata;
} | php | public function getEntityMetadataForIntermediary($collection)
{
$metadata = $this->metadataFactory->createEmptyMetadata();
$metadata->setCollection($collection);
return $metadata;
} | [
"public",
"function",
"getEntityMetadataForIntermediary",
"(",
"$",
"collection",
")",
"{",
"$",
"metadata",
"=",
"$",
"this",
"->",
"metadataFactory",
"->",
"createEmptyMetadata",
"(",
")",
";",
"$",
"metadata",
"->",
"setCollection",
"(",
"$",
"collection",
")",
";",
"return",
"$",
"metadata",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/lexide/reposition/blob/aa02735271f0c0ee4a3fb679093d4d3823963b3a/src/Repository/RepositoryManager.php#L145-L150 |
emaphp/eMapper | lib/eMapper/Query/Schema.php | Schema.translate | public function translate(Field $field, $alias, \Closure $callback = null) {
if ($field instanceof Attr) { //entity attribute
if (empty($this->profile))
throw new \RuntimeException("No entity profile has been set. Attr instance could not be resolved");
//check if field refers to an associated entity
$path = $field->getPath();
if (empty($path)) { //obtain column name from current profile
$expression = empty($alias) ? $field->getColumnName($this->profile) : $alias . '.' . $field->getColumnName($this->profile);
if ($field->getType() == null)
$field->type($this->profile->getProperty($field->getName())->getType());
return isset($callback) ? $callback->__invoke($expression, $field) : $expression;
}
//get attribute alias + referred profile
list($attrAlias, $profile) = $this->getAttrAlias($field);
$expression = $attrAlias . '.' . $field->getColumnName($profile);
//set attribute type
if ($field->getType() == null)
$field->type($profile->getProperty($field->getName())->getType());
return isset($callback) ? $callback->__invoke($expression, $field) : $expression;
}
elseif ($field instanceof Column) { //column
$path = $field->getPath();
$columnAlias = $field->getColumnAlias();
if (empty($path)) { // no alias
$expression = empty($alias) ? $field->getName() : $alias . '.' . $field->getName();
return isset($callback) ? $callback->__invoke($expression, $field) : $expression;
}
$expression = $field->getPath()[0] . '.' . $field->getName();
return isset($callback) ? $callback->__invoke($expression, $field) : $expression;
}
elseif ($field instanceof Func) { //function
$args = $field->getArguments();
$list = [];
foreach ($args as $arg)
$list[] = $arg instanceof Field ? $this->translate($arg, $alias) : $arg;
$funcAlias = $field->getColumnAlias();
return !empty($funcAlias) ? $field->getName() . '(' . implode(',', $list) . ') AS ' . $funcAlias : $field->getName() . '(' . implode(',', $list) . ')';
}
} | php | public function translate(Field $field, $alias, \Closure $callback = null) {
if ($field instanceof Attr) { //entity attribute
if (empty($this->profile))
throw new \RuntimeException("No entity profile has been set. Attr instance could not be resolved");
//check if field refers to an associated entity
$path = $field->getPath();
if (empty($path)) { //obtain column name from current profile
$expression = empty($alias) ? $field->getColumnName($this->profile) : $alias . '.' . $field->getColumnName($this->profile);
if ($field->getType() == null)
$field->type($this->profile->getProperty($field->getName())->getType());
return isset($callback) ? $callback->__invoke($expression, $field) : $expression;
}
//get attribute alias + referred profile
list($attrAlias, $profile) = $this->getAttrAlias($field);
$expression = $attrAlias . '.' . $field->getColumnName($profile);
//set attribute type
if ($field->getType() == null)
$field->type($profile->getProperty($field->getName())->getType());
return isset($callback) ? $callback->__invoke($expression, $field) : $expression;
}
elseif ($field instanceof Column) { //column
$path = $field->getPath();
$columnAlias = $field->getColumnAlias();
if (empty($path)) { // no alias
$expression = empty($alias) ? $field->getName() : $alias . '.' . $field->getName();
return isset($callback) ? $callback->__invoke($expression, $field) : $expression;
}
$expression = $field->getPath()[0] . '.' . $field->getName();
return isset($callback) ? $callback->__invoke($expression, $field) : $expression;
}
elseif ($field instanceof Func) { //function
$args = $field->getArguments();
$list = [];
foreach ($args as $arg)
$list[] = $arg instanceof Field ? $this->translate($arg, $alias) : $arg;
$funcAlias = $field->getColumnAlias();
return !empty($funcAlias) ? $field->getName() . '(' . implode(',', $list) . ') AS ' . $funcAlias : $field->getName() . '(' . implode(',', $list) . ')';
}
} | [
"public",
"function",
"translate",
"(",
"Field",
"$",
"field",
",",
"$",
"alias",
",",
"\\",
"Closure",
"$",
"callback",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"field",
"instanceof",
"Attr",
")",
"{",
"//entity attribute",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"profile",
")",
")",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"No entity profile has been set. Attr instance could not be resolved\"",
")",
";",
"//check if field refers to an associated entity",
"$",
"path",
"=",
"$",
"field",
"->",
"getPath",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"path",
")",
")",
"{",
"//obtain column name from current profile",
"$",
"expression",
"=",
"empty",
"(",
"$",
"alias",
")",
"?",
"$",
"field",
"->",
"getColumnName",
"(",
"$",
"this",
"->",
"profile",
")",
":",
"$",
"alias",
".",
"'.'",
".",
"$",
"field",
"->",
"getColumnName",
"(",
"$",
"this",
"->",
"profile",
")",
";",
"if",
"(",
"$",
"field",
"->",
"getType",
"(",
")",
"==",
"null",
")",
"$",
"field",
"->",
"type",
"(",
"$",
"this",
"->",
"profile",
"->",
"getProperty",
"(",
"$",
"field",
"->",
"getName",
"(",
")",
")",
"->",
"getType",
"(",
")",
")",
";",
"return",
"isset",
"(",
"$",
"callback",
")",
"?",
"$",
"callback",
"->",
"__invoke",
"(",
"$",
"expression",
",",
"$",
"field",
")",
":",
"$",
"expression",
";",
"}",
"//get attribute alias + referred profile",
"list",
"(",
"$",
"attrAlias",
",",
"$",
"profile",
")",
"=",
"$",
"this",
"->",
"getAttrAlias",
"(",
"$",
"field",
")",
";",
"$",
"expression",
"=",
"$",
"attrAlias",
".",
"'.'",
".",
"$",
"field",
"->",
"getColumnName",
"(",
"$",
"profile",
")",
";",
"//set attribute type",
"if",
"(",
"$",
"field",
"->",
"getType",
"(",
")",
"==",
"null",
")",
"$",
"field",
"->",
"type",
"(",
"$",
"profile",
"->",
"getProperty",
"(",
"$",
"field",
"->",
"getName",
"(",
")",
")",
"->",
"getType",
"(",
")",
")",
";",
"return",
"isset",
"(",
"$",
"callback",
")",
"?",
"$",
"callback",
"->",
"__invoke",
"(",
"$",
"expression",
",",
"$",
"field",
")",
":",
"$",
"expression",
";",
"}",
"elseif",
"(",
"$",
"field",
"instanceof",
"Column",
")",
"{",
"//column",
"$",
"path",
"=",
"$",
"field",
"->",
"getPath",
"(",
")",
";",
"$",
"columnAlias",
"=",
"$",
"field",
"->",
"getColumnAlias",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"path",
")",
")",
"{",
"// no alias",
"$",
"expression",
"=",
"empty",
"(",
"$",
"alias",
")",
"?",
"$",
"field",
"->",
"getName",
"(",
")",
":",
"$",
"alias",
".",
"'.'",
".",
"$",
"field",
"->",
"getName",
"(",
")",
";",
"return",
"isset",
"(",
"$",
"callback",
")",
"?",
"$",
"callback",
"->",
"__invoke",
"(",
"$",
"expression",
",",
"$",
"field",
")",
":",
"$",
"expression",
";",
"}",
"$",
"expression",
"=",
"$",
"field",
"->",
"getPath",
"(",
")",
"[",
"0",
"]",
".",
"'.'",
".",
"$",
"field",
"->",
"getName",
"(",
")",
";",
"return",
"isset",
"(",
"$",
"callback",
")",
"?",
"$",
"callback",
"->",
"__invoke",
"(",
"$",
"expression",
",",
"$",
"field",
")",
":",
"$",
"expression",
";",
"}",
"elseif",
"(",
"$",
"field",
"instanceof",
"Func",
")",
"{",
"//function",
"$",
"args",
"=",
"$",
"field",
"->",
"getArguments",
"(",
")",
";",
"$",
"list",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"args",
"as",
"$",
"arg",
")",
"$",
"list",
"[",
"]",
"=",
"$",
"arg",
"instanceof",
"Field",
"?",
"$",
"this",
"->",
"translate",
"(",
"$",
"arg",
",",
"$",
"alias",
")",
":",
"$",
"arg",
";",
"$",
"funcAlias",
"=",
"$",
"field",
"->",
"getColumnAlias",
"(",
")",
";",
"return",
"!",
"empty",
"(",
"$",
"funcAlias",
")",
"?",
"$",
"field",
"->",
"getName",
"(",
")",
".",
"'('",
".",
"implode",
"(",
"','",
",",
"$",
"list",
")",
".",
"') AS '",
".",
"$",
"funcAlias",
":",
"$",
"field",
"->",
"getName",
"(",
")",
".",
"'('",
".",
"implode",
"(",
"','",
",",
"$",
"list",
")",
".",
"')'",
";",
"}",
"}"
] | Translates a Field instance to the corresponding column
@param \eMapper\Query\Field $field
@param string $alias
@param \Closure $callback
@throws \RuntimeException
@return string | [
"Translates",
"a",
"Field",
"instance",
"to",
"the",
"corresponding",
"column"
] | train | https://github.com/emaphp/eMapper/blob/df7100e601d2a1363d07028a786b6ceb22271829/lib/eMapper/Query/Schema.php#L114-L161 |
emaphp/eMapper | lib/eMapper/Query/Schema.php | Schema.getAttrAlias | protected function getAttrAlias(Attr $attr) {
//check if join is already created
$stringPath = $attr->getStringPath();
if (array_key_exists($stringPath, $this->joins))
return [$this->joins[$stringPath]->getAlias(), $this->joins[$stringPath]->getProfile()];
//
$path = $attr->getPath();
$current = $this->profile;
$parent = null;
for ($i = 0; $i < count($path); $i++) {
//build join name
$joinPath = array_slice($path, 0, $i + 1);
$name = implode('__', $joinPath);
//check association
if (!$current->hasAssociation($path[$i]))
throw new \RuntimeException(sprintf("Association '%s' not found in class %s", $path[$i], $current->getReflectionClass()->getName()));
//build join instance
$association = $current->getAssociation($path[$i]);
$related = Profiler::getClassProfile($association->getEntityClass());
if (!array_key_exists($name, $this->joins))
$this->joins[$name] = new Join($association, $related, $this->getJoinAlias(), $parent);
//prepare next iteration
$current = $related;
$parent = $name;
}
return [$this->joins[$parent]->getAlias(), $this->joins[$parent]->getProfile()];
} | php | protected function getAttrAlias(Attr $attr) {
//check if join is already created
$stringPath = $attr->getStringPath();
if (array_key_exists($stringPath, $this->joins))
return [$this->joins[$stringPath]->getAlias(), $this->joins[$stringPath]->getProfile()];
//
$path = $attr->getPath();
$current = $this->profile;
$parent = null;
for ($i = 0; $i < count($path); $i++) {
//build join name
$joinPath = array_slice($path, 0, $i + 1);
$name = implode('__', $joinPath);
//check association
if (!$current->hasAssociation($path[$i]))
throw new \RuntimeException(sprintf("Association '%s' not found in class %s", $path[$i], $current->getReflectionClass()->getName()));
//build join instance
$association = $current->getAssociation($path[$i]);
$related = Profiler::getClassProfile($association->getEntityClass());
if (!array_key_exists($name, $this->joins))
$this->joins[$name] = new Join($association, $related, $this->getJoinAlias(), $parent);
//prepare next iteration
$current = $related;
$parent = $name;
}
return [$this->joins[$parent]->getAlias(), $this->joins[$parent]->getProfile()];
} | [
"protected",
"function",
"getAttrAlias",
"(",
"Attr",
"$",
"attr",
")",
"{",
"//check if join is already created",
"$",
"stringPath",
"=",
"$",
"attr",
"->",
"getStringPath",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"stringPath",
",",
"$",
"this",
"->",
"joins",
")",
")",
"return",
"[",
"$",
"this",
"->",
"joins",
"[",
"$",
"stringPath",
"]",
"->",
"getAlias",
"(",
")",
",",
"$",
"this",
"->",
"joins",
"[",
"$",
"stringPath",
"]",
"->",
"getProfile",
"(",
")",
"]",
";",
"//",
"$",
"path",
"=",
"$",
"attr",
"->",
"getPath",
"(",
")",
";",
"$",
"current",
"=",
"$",
"this",
"->",
"profile",
";",
"$",
"parent",
"=",
"null",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"path",
")",
";",
"$",
"i",
"++",
")",
"{",
"//build join name",
"$",
"joinPath",
"=",
"array_slice",
"(",
"$",
"path",
",",
"0",
",",
"$",
"i",
"+",
"1",
")",
";",
"$",
"name",
"=",
"implode",
"(",
"'__'",
",",
"$",
"joinPath",
")",
";",
"//check association",
"if",
"(",
"!",
"$",
"current",
"->",
"hasAssociation",
"(",
"$",
"path",
"[",
"$",
"i",
"]",
")",
")",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"\"Association '%s' not found in class %s\"",
",",
"$",
"path",
"[",
"$",
"i",
"]",
",",
"$",
"current",
"->",
"getReflectionClass",
"(",
")",
"->",
"getName",
"(",
")",
")",
")",
";",
"//build join instance",
"$",
"association",
"=",
"$",
"current",
"->",
"getAssociation",
"(",
"$",
"path",
"[",
"$",
"i",
"]",
")",
";",
"$",
"related",
"=",
"Profiler",
"::",
"getClassProfile",
"(",
"$",
"association",
"->",
"getEntityClass",
"(",
")",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"joins",
")",
")",
"$",
"this",
"->",
"joins",
"[",
"$",
"name",
"]",
"=",
"new",
"Join",
"(",
"$",
"association",
",",
"$",
"related",
",",
"$",
"this",
"->",
"getJoinAlias",
"(",
")",
",",
"$",
"parent",
")",
";",
"//prepare next iteration",
"$",
"current",
"=",
"$",
"related",
";",
"$",
"parent",
"=",
"$",
"name",
";",
"}",
"return",
"[",
"$",
"this",
"->",
"joins",
"[",
"$",
"parent",
"]",
"->",
"getAlias",
"(",
")",
",",
"$",
"this",
"->",
"joins",
"[",
"$",
"parent",
"]",
"->",
"getProfile",
"(",
")",
"]",
";",
"}"
] | Obtains an alias for a given Attr instance used in a sql predicate
@param \eMapper\Query\Attr $attr
@throws \RuntimeException
@return array | [
"Obtains",
"an",
"alias",
"for",
"a",
"given",
"Attr",
"instance",
"used",
"in",
"a",
"sql",
"predicate"
] | train | https://github.com/emaphp/eMapper/blob/df7100e601d2a1363d07028a786b6ceb22271829/lib/eMapper/Query/Schema.php#L169-L202 |
xpl-php/Common | src/Storage/Config.php | Config.setParent | public function setParent($object) {
if (! is_object($object)) {
throw new \InvalidArgumentException("Expecting object, given: ".gettype($object));
}
$this->parent = $object;
return $this;
} | php | public function setParent($object) {
if (! is_object($object)) {
throw new \InvalidArgumentException("Expecting object, given: ".gettype($object));
}
$this->parent = $object;
return $this;
} | [
"public",
"function",
"setParent",
"(",
"$",
"object",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"object",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Expecting object, given: \"",
".",
"gettype",
"(",
"$",
"object",
")",
")",
";",
"}",
"$",
"this",
"->",
"parent",
"=",
"$",
"object",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the config parent object.
@param object $object
@return $this
@throws \InvalidArgumentException if given a non-object. | [
"Sets",
"the",
"config",
"parent",
"object",
"."
] | train | https://github.com/xpl-php/Common/blob/0669bdcca29f1f8835297c2397c62fee3be5dce3/src/Storage/Config.php#L32-L40 |
xpl-php/Common | src/Storage/Config.php | Config.set | public function set($key, $value) {
$previous = $this->get($key);
parent::set($key, $value);
return $previous;
} | php | public function set($key, $value) {
$previous = $this->get($key);
parent::set($key, $value);
return $previous;
} | [
"public",
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"previous",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"key",
")",
";",
"parent",
"::",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"return",
"$",
"previous",
";",
"}"
] | Set method returns the previous value.
@param string $key Item key.
@param mixed $value New value.
@return mixed Previous item value. | [
"Set",
"method",
"returns",
"the",
"previous",
"value",
"."
] | train | https://github.com/xpl-php/Common/blob/0669bdcca29f1f8835297c2397c62fee3be5dce3/src/Storage/Config.php#L59-L66 |
ehough/shortstop | src/main/php/ehough/shortstop/impl/exec/DefaultHttpMessageParser.php | ehough_shortstop_impl_exec_DefaultHttpMessageParser.getHeaderArrayAsString | public final function getHeaderArrayAsString(ehough_shortstop_api_HttpMessage $message)
{
$headers = $message->getAllHeaders();
if (! is_array($headers)) {
return '';
}
$toReturn = '';
foreach ($headers as $name => $value) {
$toReturn .= "$name: $value\r\n";
}
return $toReturn;
} | php | public final function getHeaderArrayAsString(ehough_shortstop_api_HttpMessage $message)
{
$headers = $message->getAllHeaders();
if (! is_array($headers)) {
return '';
}
$toReturn = '';
foreach ($headers as $name => $value) {
$toReturn .= "$name: $value\r\n";
}
return $toReturn;
} | [
"public",
"final",
"function",
"getHeaderArrayAsString",
"(",
"ehough_shortstop_api_HttpMessage",
"$",
"message",
")",
"{",
"$",
"headers",
"=",
"$",
"message",
"->",
"getAllHeaders",
"(",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"headers",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"toReturn",
"=",
"''",
";",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"toReturn",
".=",
"\"$name: $value\\r\\n\"",
";",
"}",
"return",
"$",
"toReturn",
";",
"}"
] | Gets a string representation of the headers of the given HTTP message.
@param ehough_shortstop_api_HttpMessage $message The HTTP message.
@return string The string representation of the HTTP headers. May be null or empty. | [
"Gets",
"a",
"string",
"representation",
"of",
"the",
"headers",
"of",
"the",
"given",
"HTTP",
"message",
"."
] | train | https://github.com/ehough/shortstop/blob/4cef21457741347546c70e8e5c0cef6d3162b257/src/main/php/ehough/shortstop/impl/exec/DefaultHttpMessageParser.php#L24-L41 |
ehough/shortstop | src/main/php/ehough/shortstop/impl/exec/DefaultHttpMessageParser.php | ehough_shortstop_impl_exec_DefaultHttpMessageParser.getArrayOfHeadersFromRawHeaderString | public final function getArrayOfHeadersFromRawHeaderString($rawHeaderString)
{
// split headers, one per array element
if (is_string($rawHeaderString)) {
// tolerate line terminator: CRLF = LF (RFC 2616 19.3)
$rawHeaderString = str_replace("\r\n", "\n", $rawHeaderString);
// unfold folded header fields. LWS = [CRLF] 1*(SP | HT) <US-ASCII SP, space (32)>, <US-ASCII HT, horizontal-tab (9)> (RFC 2616 2.2)
$rawHeaderString = preg_replace('/\n[ \t]/', ' ', $rawHeaderString);
// create the headers array
$headers = explode("\n", $rawHeaderString);
} else {
$headers = array();
}
$toReturn = array();
foreach ($headers as $header) {
if (empty($header) || strpos($header, ':') === false) {
continue;
}
list($headerName, $headerValue) = explode(':', $header, 2);
if (empty($headerValue)) {
continue;
}
if (isset($toReturn[$headerName])) {
if (!is_array($toReturn[$headerName])) {
$toReturn[$headerName] = array($toReturn[$headerName]);
}
$toReturn[$headerName][] = trim($headerValue);
} else {
$toReturn[$headerName] = trim($headerValue);
}
}
return $toReturn;
} | php | public final function getArrayOfHeadersFromRawHeaderString($rawHeaderString)
{
// split headers, one per array element
if (is_string($rawHeaderString)) {
// tolerate line terminator: CRLF = LF (RFC 2616 19.3)
$rawHeaderString = str_replace("\r\n", "\n", $rawHeaderString);
// unfold folded header fields. LWS = [CRLF] 1*(SP | HT) <US-ASCII SP, space (32)>, <US-ASCII HT, horizontal-tab (9)> (RFC 2616 2.2)
$rawHeaderString = preg_replace('/\n[ \t]/', ' ', $rawHeaderString);
// create the headers array
$headers = explode("\n", $rawHeaderString);
} else {
$headers = array();
}
$toReturn = array();
foreach ($headers as $header) {
if (empty($header) || strpos($header, ':') === false) {
continue;
}
list($headerName, $headerValue) = explode(':', $header, 2);
if (empty($headerValue)) {
continue;
}
if (isset($toReturn[$headerName])) {
if (!is_array($toReturn[$headerName])) {
$toReturn[$headerName] = array($toReturn[$headerName]);
}
$toReturn[$headerName][] = trim($headerValue);
} else {
$toReturn[$headerName] = trim($headerValue);
}
}
return $toReturn;
} | [
"public",
"final",
"function",
"getArrayOfHeadersFromRawHeaderString",
"(",
"$",
"rawHeaderString",
")",
"{",
"// split headers, one per array element",
"if",
"(",
"is_string",
"(",
"$",
"rawHeaderString",
")",
")",
"{",
"// tolerate line terminator: CRLF = LF (RFC 2616 19.3)",
"$",
"rawHeaderString",
"=",
"str_replace",
"(",
"\"\\r\\n\"",
",",
"\"\\n\"",
",",
"$",
"rawHeaderString",
")",
";",
"// unfold folded header fields. LWS = [CRLF] 1*(SP | HT) <US-ASCII SP, space (32)>, <US-ASCII HT, horizontal-tab (9)> (RFC 2616 2.2)",
"$",
"rawHeaderString",
"=",
"preg_replace",
"(",
"'/\\n[ \\t]/'",
",",
"' '",
",",
"$",
"rawHeaderString",
")",
";",
"// create the headers array",
"$",
"headers",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"rawHeaderString",
")",
";",
"}",
"else",
"{",
"$",
"headers",
"=",
"array",
"(",
")",
";",
"}",
"$",
"toReturn",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"header",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"header",
")",
"||",
"strpos",
"(",
"$",
"header",
",",
"':'",
")",
"===",
"false",
")",
"{",
"continue",
";",
"}",
"list",
"(",
"$",
"headerName",
",",
"$",
"headerValue",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"header",
",",
"2",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"headerValue",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"toReturn",
"[",
"$",
"headerName",
"]",
")",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"toReturn",
"[",
"$",
"headerName",
"]",
")",
")",
"{",
"$",
"toReturn",
"[",
"$",
"headerName",
"]",
"=",
"array",
"(",
"$",
"toReturn",
"[",
"$",
"headerName",
"]",
")",
";",
"}",
"$",
"toReturn",
"[",
"$",
"headerName",
"]",
"[",
"]",
"=",
"trim",
"(",
"$",
"headerValue",
")",
";",
"}",
"else",
"{",
"$",
"toReturn",
"[",
"$",
"headerName",
"]",
"=",
"trim",
"(",
"$",
"headerValue",
")",
";",
"}",
"}",
"return",
"$",
"toReturn",
";",
"}"
] | Given a raw string of headers, return an associative array of the headers.
@param string $rawHeaderString The header string.
@return array An associative array of headers with name => value. Maybe null or empty. | [
"Given",
"a",
"raw",
"string",
"of",
"headers",
"return",
"an",
"associative",
"array",
"of",
"the",
"headers",
"."
] | train | https://github.com/ehough/shortstop/blob/4cef21457741347546c70e8e5c0cef6d3162b257/src/main/php/ehough/shortstop/impl/exec/DefaultHttpMessageParser.php#L50-L101 |
gossi/trixionary | src/domain/base/KstrukturDomainTrait.php | KstrukturDomainTrait.addRootSkills | public function addRootSkills($id, $data) {
// find
$model = $this->get($id);
if ($model === null) {
return new NotFound(['message' => 'Kstruktur not found.']);
}
// pass add to internal logic
try {
$this->doAddRootSkills($model, $data);
} catch (ErrorsException $e) {
return new NotValid(['errors' => $e->getErrors()]);
}
// save and dispatch events
$this->dispatch(KstrukturEvent::PRE_ROOT_SKILLS_ADD, $model, $data);
$this->dispatch(KstrukturEvent::PRE_SAVE, $model, $data);
$rows = $model->save();
$this->dispatch(KstrukturEvent::POST_ROOT_SKILLS_ADD, $model, $data);
$this->dispatch(KstrukturEvent::POST_SAVE, $model, $data);
if ($rows > 0) {
return Updated(['model' => $model]);
}
return NotUpdated(['model' => $model]);
} | php | public function addRootSkills($id, $data) {
// find
$model = $this->get($id);
if ($model === null) {
return new NotFound(['message' => 'Kstruktur not found.']);
}
// pass add to internal logic
try {
$this->doAddRootSkills($model, $data);
} catch (ErrorsException $e) {
return new NotValid(['errors' => $e->getErrors()]);
}
// save and dispatch events
$this->dispatch(KstrukturEvent::PRE_ROOT_SKILLS_ADD, $model, $data);
$this->dispatch(KstrukturEvent::PRE_SAVE, $model, $data);
$rows = $model->save();
$this->dispatch(KstrukturEvent::POST_ROOT_SKILLS_ADD, $model, $data);
$this->dispatch(KstrukturEvent::POST_SAVE, $model, $data);
if ($rows > 0) {
return Updated(['model' => $model]);
}
return NotUpdated(['model' => $model]);
} | [
"public",
"function",
"addRootSkills",
"(",
"$",
"id",
",",
"$",
"data",
")",
"{",
"// find",
"$",
"model",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"id",
")",
";",
"if",
"(",
"$",
"model",
"===",
"null",
")",
"{",
"return",
"new",
"NotFound",
"(",
"[",
"'message'",
"=>",
"'Kstruktur not found.'",
"]",
")",
";",
"}",
"// pass add to internal logic",
"try",
"{",
"$",
"this",
"->",
"doAddRootSkills",
"(",
"$",
"model",
",",
"$",
"data",
")",
";",
"}",
"catch",
"(",
"ErrorsException",
"$",
"e",
")",
"{",
"return",
"new",
"NotValid",
"(",
"[",
"'errors'",
"=>",
"$",
"e",
"->",
"getErrors",
"(",
")",
"]",
")",
";",
"}",
"// save and dispatch events",
"$",
"this",
"->",
"dispatch",
"(",
"KstrukturEvent",
"::",
"PRE_ROOT_SKILLS_ADD",
",",
"$",
"model",
",",
"$",
"data",
")",
";",
"$",
"this",
"->",
"dispatch",
"(",
"KstrukturEvent",
"::",
"PRE_SAVE",
",",
"$",
"model",
",",
"$",
"data",
")",
";",
"$",
"rows",
"=",
"$",
"model",
"->",
"save",
"(",
")",
";",
"$",
"this",
"->",
"dispatch",
"(",
"KstrukturEvent",
"::",
"POST_ROOT_SKILLS_ADD",
",",
"$",
"model",
",",
"$",
"data",
")",
";",
"$",
"this",
"->",
"dispatch",
"(",
"KstrukturEvent",
"::",
"POST_SAVE",
",",
"$",
"model",
",",
"$",
"data",
")",
";",
"if",
"(",
"$",
"rows",
">",
"0",
")",
"{",
"return",
"Updated",
"(",
"[",
"'model'",
"=>",
"$",
"model",
"]",
")",
";",
"}",
"return",
"NotUpdated",
"(",
"[",
"'model'",
"=>",
"$",
"model",
"]",
")",
";",
"}"
] | Adds RootSkills to Kstruktur
@param mixed $id
@param mixed $data
@return PayloadInterface | [
"Adds",
"RootSkills",
"to",
"Kstruktur"
] | train | https://github.com/gossi/trixionary/blob/221a6c5322473d7d7f8e322958a3ee46d87da150/src/domain/base/KstrukturDomainTrait.php#L39-L66 |
gossi/trixionary | src/domain/base/KstrukturDomainTrait.php | KstrukturDomainTrait.create | public function create($data) {
// hydrate
$serializer = Kstruktur::getSerializer();
$model = $serializer->hydrate(new Kstruktur(), $data);
$this->hydrateRelationships($model, $data);
// dispatch pre save hooks
$this->dispatch(KstrukturEvent::PRE_CREATE, $model, $data);
$this->dispatch(KstrukturEvent::PRE_SAVE, $model, $data);
// validate
$validator = $this->getValidator();
if ($validator !== null && !$validator->validate($model)) {
return new NotValid([
'errors' => $validator->getValidationFailures()
]);
}
// save and dispatch post save hooks
$model->save();
$this->dispatch(KstrukturEvent::POST_CREATE, $model, $data);
$this->dispatch(KstrukturEvent::POST_SAVE, $model, $data);
return new Created(['model' => $model]);
} | php | public function create($data) {
// hydrate
$serializer = Kstruktur::getSerializer();
$model = $serializer->hydrate(new Kstruktur(), $data);
$this->hydrateRelationships($model, $data);
// dispatch pre save hooks
$this->dispatch(KstrukturEvent::PRE_CREATE, $model, $data);
$this->dispatch(KstrukturEvent::PRE_SAVE, $model, $data);
// validate
$validator = $this->getValidator();
if ($validator !== null && !$validator->validate($model)) {
return new NotValid([
'errors' => $validator->getValidationFailures()
]);
}
// save and dispatch post save hooks
$model->save();
$this->dispatch(KstrukturEvent::POST_CREATE, $model, $data);
$this->dispatch(KstrukturEvent::POST_SAVE, $model, $data);
return new Created(['model' => $model]);
} | [
"public",
"function",
"create",
"(",
"$",
"data",
")",
"{",
"// hydrate",
"$",
"serializer",
"=",
"Kstruktur",
"::",
"getSerializer",
"(",
")",
";",
"$",
"model",
"=",
"$",
"serializer",
"->",
"hydrate",
"(",
"new",
"Kstruktur",
"(",
")",
",",
"$",
"data",
")",
";",
"$",
"this",
"->",
"hydrateRelationships",
"(",
"$",
"model",
",",
"$",
"data",
")",
";",
"// dispatch pre save hooks",
"$",
"this",
"->",
"dispatch",
"(",
"KstrukturEvent",
"::",
"PRE_CREATE",
",",
"$",
"model",
",",
"$",
"data",
")",
";",
"$",
"this",
"->",
"dispatch",
"(",
"KstrukturEvent",
"::",
"PRE_SAVE",
",",
"$",
"model",
",",
"$",
"data",
")",
";",
"// validate",
"$",
"validator",
"=",
"$",
"this",
"->",
"getValidator",
"(",
")",
";",
"if",
"(",
"$",
"validator",
"!==",
"null",
"&&",
"!",
"$",
"validator",
"->",
"validate",
"(",
"$",
"model",
")",
")",
"{",
"return",
"new",
"NotValid",
"(",
"[",
"'errors'",
"=>",
"$",
"validator",
"->",
"getValidationFailures",
"(",
")",
"]",
")",
";",
"}",
"// save and dispatch post save hooks",
"$",
"model",
"->",
"save",
"(",
")",
";",
"$",
"this",
"->",
"dispatch",
"(",
"KstrukturEvent",
"::",
"POST_CREATE",
",",
"$",
"model",
",",
"$",
"data",
")",
";",
"$",
"this",
"->",
"dispatch",
"(",
"KstrukturEvent",
"::",
"POST_SAVE",
",",
"$",
"model",
",",
"$",
"data",
")",
";",
"return",
"new",
"Created",
"(",
"[",
"'model'",
"=>",
"$",
"model",
"]",
")",
";",
"}"
] | Creates a new Kstruktur with the provided data
@param mixed $data
@return PayloadInterface | [
"Creates",
"a",
"new",
"Kstruktur",
"with",
"the",
"provided",
"data"
] | train | https://github.com/gossi/trixionary/blob/221a6c5322473d7d7f8e322958a3ee46d87da150/src/domain/base/KstrukturDomainTrait.php#L74-L98 |
gossi/trixionary | src/domain/base/KstrukturDomainTrait.php | KstrukturDomainTrait.removeRootSkills | public function removeRootSkills($id, $data) {
// find
$model = $this->get($id);
if ($model === null) {
return new NotFound(['message' => 'Kstruktur not found.']);
}
// pass remove to internal logic
try {
$this->doRemoveRootSkills($model, $data);
} catch (ErrorsException $e) {
return new NotValid(['errors' => $e->getErrors()]);
}
// save and dispatch events
$this->dispatch(KstrukturEvent::PRE_ROOT_SKILLS_REMOVE, $model, $data);
$this->dispatch(KstrukturEvent::PRE_SAVE, $model, $data);
$rows = $model->save();
$this->dispatch(KstrukturEvent::POST_ROOT_SKILLS_REMOVE, $model, $data);
$this->dispatch(KstrukturEvent::POST_SAVE, $model, $data);
if ($rows > 0) {
return Updated(['model' => $model]);
}
return NotUpdated(['model' => $model]);
} | php | public function removeRootSkills($id, $data) {
// find
$model = $this->get($id);
if ($model === null) {
return new NotFound(['message' => 'Kstruktur not found.']);
}
// pass remove to internal logic
try {
$this->doRemoveRootSkills($model, $data);
} catch (ErrorsException $e) {
return new NotValid(['errors' => $e->getErrors()]);
}
// save and dispatch events
$this->dispatch(KstrukturEvent::PRE_ROOT_SKILLS_REMOVE, $model, $data);
$this->dispatch(KstrukturEvent::PRE_SAVE, $model, $data);
$rows = $model->save();
$this->dispatch(KstrukturEvent::POST_ROOT_SKILLS_REMOVE, $model, $data);
$this->dispatch(KstrukturEvent::POST_SAVE, $model, $data);
if ($rows > 0) {
return Updated(['model' => $model]);
}
return NotUpdated(['model' => $model]);
} | [
"public",
"function",
"removeRootSkills",
"(",
"$",
"id",
",",
"$",
"data",
")",
"{",
"// find",
"$",
"model",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"id",
")",
";",
"if",
"(",
"$",
"model",
"===",
"null",
")",
"{",
"return",
"new",
"NotFound",
"(",
"[",
"'message'",
"=>",
"'Kstruktur not found.'",
"]",
")",
";",
"}",
"// pass remove to internal logic",
"try",
"{",
"$",
"this",
"->",
"doRemoveRootSkills",
"(",
"$",
"model",
",",
"$",
"data",
")",
";",
"}",
"catch",
"(",
"ErrorsException",
"$",
"e",
")",
"{",
"return",
"new",
"NotValid",
"(",
"[",
"'errors'",
"=>",
"$",
"e",
"->",
"getErrors",
"(",
")",
"]",
")",
";",
"}",
"// save and dispatch events",
"$",
"this",
"->",
"dispatch",
"(",
"KstrukturEvent",
"::",
"PRE_ROOT_SKILLS_REMOVE",
",",
"$",
"model",
",",
"$",
"data",
")",
";",
"$",
"this",
"->",
"dispatch",
"(",
"KstrukturEvent",
"::",
"PRE_SAVE",
",",
"$",
"model",
",",
"$",
"data",
")",
";",
"$",
"rows",
"=",
"$",
"model",
"->",
"save",
"(",
")",
";",
"$",
"this",
"->",
"dispatch",
"(",
"KstrukturEvent",
"::",
"POST_ROOT_SKILLS_REMOVE",
",",
"$",
"model",
",",
"$",
"data",
")",
";",
"$",
"this",
"->",
"dispatch",
"(",
"KstrukturEvent",
"::",
"POST_SAVE",
",",
"$",
"model",
",",
"$",
"data",
")",
";",
"if",
"(",
"$",
"rows",
">",
"0",
")",
"{",
"return",
"Updated",
"(",
"[",
"'model'",
"=>",
"$",
"model",
"]",
")",
";",
"}",
"return",
"NotUpdated",
"(",
"[",
"'model'",
"=>",
"$",
"model",
"]",
")",
";",
"}"
] | Removes RootSkills from Kstruktur
@param mixed $id
@param mixed $data
@return PayloadInterface | [
"Removes",
"RootSkills",
"from",
"Kstruktur"
] | train | https://github.com/gossi/trixionary/blob/221a6c5322473d7d7f8e322958a3ee46d87da150/src/domain/base/KstrukturDomainTrait.php#L189-L216 |
gossi/trixionary | src/domain/base/KstrukturDomainTrait.php | KstrukturDomainTrait.updateRootSkills | public function updateRootSkills($id, $data) {
// find
$model = $this->get($id);
if ($model === null) {
return new NotFound(['message' => 'Kstruktur not found.']);
}
// pass update to internal logic
try {
$this->doUpdateRootSkills($model, $data);
} catch (ErrorsException $e) {
return new NotValid(['errors' => $e->getErrors()]);
}
// save and dispatch events
$this->dispatch(KstrukturEvent::PRE_ROOT_SKILLS_UPDATE, $model, $data);
$this->dispatch(KstrukturEvent::PRE_SAVE, $model, $data);
$rows = $model->save();
$this->dispatch(KstrukturEvent::POST_ROOT_SKILLS_UPDATE, $model, $data);
$this->dispatch(KstrukturEvent::POST_SAVE, $model, $data);
if ($rows > 0) {
return Updated(['model' => $model]);
}
return NotUpdated(['model' => $model]);
} | php | public function updateRootSkills($id, $data) {
// find
$model = $this->get($id);
if ($model === null) {
return new NotFound(['message' => 'Kstruktur not found.']);
}
// pass update to internal logic
try {
$this->doUpdateRootSkills($model, $data);
} catch (ErrorsException $e) {
return new NotValid(['errors' => $e->getErrors()]);
}
// save and dispatch events
$this->dispatch(KstrukturEvent::PRE_ROOT_SKILLS_UPDATE, $model, $data);
$this->dispatch(KstrukturEvent::PRE_SAVE, $model, $data);
$rows = $model->save();
$this->dispatch(KstrukturEvent::POST_ROOT_SKILLS_UPDATE, $model, $data);
$this->dispatch(KstrukturEvent::POST_SAVE, $model, $data);
if ($rows > 0) {
return Updated(['model' => $model]);
}
return NotUpdated(['model' => $model]);
} | [
"public",
"function",
"updateRootSkills",
"(",
"$",
"id",
",",
"$",
"data",
")",
"{",
"// find",
"$",
"model",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"id",
")",
";",
"if",
"(",
"$",
"model",
"===",
"null",
")",
"{",
"return",
"new",
"NotFound",
"(",
"[",
"'message'",
"=>",
"'Kstruktur not found.'",
"]",
")",
";",
"}",
"// pass update to internal logic",
"try",
"{",
"$",
"this",
"->",
"doUpdateRootSkills",
"(",
"$",
"model",
",",
"$",
"data",
")",
";",
"}",
"catch",
"(",
"ErrorsException",
"$",
"e",
")",
"{",
"return",
"new",
"NotValid",
"(",
"[",
"'errors'",
"=>",
"$",
"e",
"->",
"getErrors",
"(",
")",
"]",
")",
";",
"}",
"// save and dispatch events",
"$",
"this",
"->",
"dispatch",
"(",
"KstrukturEvent",
"::",
"PRE_ROOT_SKILLS_UPDATE",
",",
"$",
"model",
",",
"$",
"data",
")",
";",
"$",
"this",
"->",
"dispatch",
"(",
"KstrukturEvent",
"::",
"PRE_SAVE",
",",
"$",
"model",
",",
"$",
"data",
")",
";",
"$",
"rows",
"=",
"$",
"model",
"->",
"save",
"(",
")",
";",
"$",
"this",
"->",
"dispatch",
"(",
"KstrukturEvent",
"::",
"POST_ROOT_SKILLS_UPDATE",
",",
"$",
"model",
",",
"$",
"data",
")",
";",
"$",
"this",
"->",
"dispatch",
"(",
"KstrukturEvent",
"::",
"POST_SAVE",
",",
"$",
"model",
",",
"$",
"data",
")",
";",
"if",
"(",
"$",
"rows",
">",
"0",
")",
"{",
"return",
"Updated",
"(",
"[",
"'model'",
"=>",
"$",
"model",
"]",
")",
";",
"}",
"return",
"NotUpdated",
"(",
"[",
"'model'",
"=>",
"$",
"model",
"]",
")",
";",
"}"
] | Updates RootSkills on Kstruktur
@param mixed $id
@param mixed $data
@return PayloadInterface | [
"Updates",
"RootSkills",
"on",
"Kstruktur"
] | train | https://github.com/gossi/trixionary/blob/221a6c5322473d7d7f8e322958a3ee46d87da150/src/domain/base/KstrukturDomainTrait.php#L300-L327 |
gossi/trixionary | src/domain/base/KstrukturDomainTrait.php | KstrukturDomainTrait.doRemoveRootSkills | protected function doRemoveRootSkills(Kstruktur $model, $data) {
$errors = [];
foreach ($data as $entry) {
if (!isset($entry['id'])) {
$errors[] = 'Missing id for Skill';
} else {
$related = SkillQuery::create()->findOneById($entry['id']);
$model->removeRootSkill($related);
}
}
if (count($errors) > 0) {
return new ErrorsException($errors);
}
} | php | protected function doRemoveRootSkills(Kstruktur $model, $data) {
$errors = [];
foreach ($data as $entry) {
if (!isset($entry['id'])) {
$errors[] = 'Missing id for Skill';
} else {
$related = SkillQuery::create()->findOneById($entry['id']);
$model->removeRootSkill($related);
}
}
if (count($errors) > 0) {
return new ErrorsException($errors);
}
} | [
"protected",
"function",
"doRemoveRootSkills",
"(",
"Kstruktur",
"$",
"model",
",",
"$",
"data",
")",
"{",
"$",
"errors",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"entry",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"entry",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"errors",
"[",
"]",
"=",
"'Missing id for Skill'",
";",
"}",
"else",
"{",
"$",
"related",
"=",
"SkillQuery",
"::",
"create",
"(",
")",
"->",
"findOneById",
"(",
"$",
"entry",
"[",
"'id'",
"]",
")",
";",
"$",
"model",
"->",
"removeRootSkill",
"(",
"$",
"related",
")",
";",
"}",
"}",
"if",
"(",
"count",
"(",
"$",
"errors",
")",
">",
"0",
")",
"{",
"return",
"new",
"ErrorsException",
"(",
"$",
"errors",
")",
";",
"}",
"}"
] | Interal mechanism to remove RootSkills from Kstruktur
@param Kstruktur $model
@param mixed $data | [
"Interal",
"mechanism",
"to",
"remove",
"RootSkills",
"from",
"Kstruktur"
] | train | https://github.com/gossi/trixionary/blob/221a6c5322473d7d7f8e322958a3ee46d87da150/src/domain/base/KstrukturDomainTrait.php#L429-L443 |
gossi/trixionary | src/domain/base/KstrukturDomainTrait.php | KstrukturDomainTrait.doSetSkillId | protected function doSetSkillId(Kstruktur $model, $relatedId) {
if ($model->getSkillId() !== $relatedId) {
$model->setSkillId($relatedId);
return true;
}
return false;
} | php | protected function doSetSkillId(Kstruktur $model, $relatedId) {
if ($model->getSkillId() !== $relatedId) {
$model->setSkillId($relatedId);
return true;
}
return false;
} | [
"protected",
"function",
"doSetSkillId",
"(",
"Kstruktur",
"$",
"model",
",",
"$",
"relatedId",
")",
"{",
"if",
"(",
"$",
"model",
"->",
"getSkillId",
"(",
")",
"!==",
"$",
"relatedId",
")",
"{",
"$",
"model",
"->",
"setSkillId",
"(",
"$",
"relatedId",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Internal mechanism to set the Skill id
@param Kstruktur $model
@param mixed $relatedId | [
"Internal",
"mechanism",
"to",
"set",
"the",
"Skill",
"id"
] | train | https://github.com/gossi/trixionary/blob/221a6c5322473d7d7f8e322958a3ee46d87da150/src/domain/base/KstrukturDomainTrait.php#L451-L459 |
gossi/trixionary | src/domain/base/KstrukturDomainTrait.php | KstrukturDomainTrait.doUpdateRootSkills | protected function doUpdateRootSkills(Kstruktur $model, $data) {
// remove all relationships before
SkillQuery::create()->filterByKstrukturRoot($model)->delete();
// add them
$errors = [];
foreach ($data as $entry) {
if (!isset($entry['id'])) {
$errors[] = 'Missing id for Skill';
} else {
$related = SkillQuery::create()->findOneById($entry['id']);
$model->addRootSkill($related);
}
}
if (count($errors) > 0) {
throw new ErrorsException($errors);
}
} | php | protected function doUpdateRootSkills(Kstruktur $model, $data) {
// remove all relationships before
SkillQuery::create()->filterByKstrukturRoot($model)->delete();
// add them
$errors = [];
foreach ($data as $entry) {
if (!isset($entry['id'])) {
$errors[] = 'Missing id for Skill';
} else {
$related = SkillQuery::create()->findOneById($entry['id']);
$model->addRootSkill($related);
}
}
if (count($errors) > 0) {
throw new ErrorsException($errors);
}
} | [
"protected",
"function",
"doUpdateRootSkills",
"(",
"Kstruktur",
"$",
"model",
",",
"$",
"data",
")",
"{",
"// remove all relationships before",
"SkillQuery",
"::",
"create",
"(",
")",
"->",
"filterByKstrukturRoot",
"(",
"$",
"model",
")",
"->",
"delete",
"(",
")",
";",
"// add them",
"$",
"errors",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"entry",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"entry",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"errors",
"[",
"]",
"=",
"'Missing id for Skill'",
";",
"}",
"else",
"{",
"$",
"related",
"=",
"SkillQuery",
"::",
"create",
"(",
")",
"->",
"findOneById",
"(",
"$",
"entry",
"[",
"'id'",
"]",
")",
";",
"$",
"model",
"->",
"addRootSkill",
"(",
"$",
"related",
")",
";",
"}",
"}",
"if",
"(",
"count",
"(",
"$",
"errors",
")",
">",
"0",
")",
"{",
"throw",
"new",
"ErrorsException",
"(",
"$",
"errors",
")",
";",
"}",
"}"
] | Internal update mechanism of RootSkills on Kstruktur
@param Kstruktur $model
@param mixed $data | [
"Internal",
"update",
"mechanism",
"of",
"RootSkills",
"on",
"Kstruktur"
] | train | https://github.com/gossi/trixionary/blob/221a6c5322473d7d7f8e322958a3ee46d87da150/src/domain/base/KstrukturDomainTrait.php#L467-L485 |
bishopb/vanilla | library/core/class.url.php | Gdn_Url.WebRoot | public static function WebRoot($WithDomain = FALSE) {
$WebRoot = Gdn::Request()->WebRoot();
if ($WithDomain)
$Result = Gdn::Request()->Domain().'/'.$WebRoot;
else
$Result = $WebRoot;
return $Result;
} | php | public static function WebRoot($WithDomain = FALSE) {
$WebRoot = Gdn::Request()->WebRoot();
if ($WithDomain)
$Result = Gdn::Request()->Domain().'/'.$WebRoot;
else
$Result = $WebRoot;
return $Result;
} | [
"public",
"static",
"function",
"WebRoot",
"(",
"$",
"WithDomain",
"=",
"FALSE",
")",
"{",
"$",
"WebRoot",
"=",
"Gdn",
"::",
"Request",
"(",
")",
"->",
"WebRoot",
"(",
")",
";",
"if",
"(",
"$",
"WithDomain",
")",
"$",
"Result",
"=",
"Gdn",
"::",
"Request",
"(",
")",
"->",
"Domain",
"(",
")",
".",
"'/'",
".",
"$",
"WebRoot",
";",
"else",
"$",
"Result",
"=",
"$",
"WebRoot",
";",
"return",
"$",
"Result",
";",
"}"
] | Returns the path to the application's dispatcher. Optionally with the
domain prepended.
ie. http://domain.com/[web_root]/index.php?/request
@param boolean $WithDomain Should it include the domain with the WebRoot? Default is FALSE.
@return string | [
"Returns",
"the",
"path",
"to",
"the",
"application",
"s",
"dispatcher",
".",
"Optionally",
"with",
"the",
"domain",
"prepended",
".",
"ie",
".",
"http",
":",
"//",
"domain",
".",
"com",
"/",
"[",
"web_root",
"]",
"/",
"index",
".",
"php?",
"/",
"request"
] | train | https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/library/core/class.url.php#L24-L33 |
bishopb/vanilla | library/core/class.url.php | Gdn_Url.Request | public static function Request($WithWebRoot = FALSE, $WithDomain = FALSE, $RemoveSyndication = FALSE) {
$Result = Gdn::Request()->Path();
if($WithWebRoot)
$Result = self::WebRoot($WithDomain).'/'.$Result;
return $Result;
} | php | public static function Request($WithWebRoot = FALSE, $WithDomain = FALSE, $RemoveSyndication = FALSE) {
$Result = Gdn::Request()->Path();
if($WithWebRoot)
$Result = self::WebRoot($WithDomain).'/'.$Result;
return $Result;
} | [
"public",
"static",
"function",
"Request",
"(",
"$",
"WithWebRoot",
"=",
"FALSE",
",",
"$",
"WithDomain",
"=",
"FALSE",
",",
"$",
"RemoveSyndication",
"=",
"FALSE",
")",
"{",
"$",
"Result",
"=",
"Gdn",
"::",
"Request",
"(",
")",
"->",
"Path",
"(",
")",
";",
"if",
"(",
"$",
"WithWebRoot",
")",
"$",
"Result",
"=",
"self",
"::",
"WebRoot",
"(",
"$",
"WithDomain",
")",
".",
"'/'",
".",
"$",
"Result",
";",
"return",
"$",
"Result",
";",
"}"
] | Returns the Request part of the current url. ie. "/controller/action/" in
"http://localhost/garden/index.php?/controller/action/".
@param boolean $WithWebRoot
@param boolean $WithDomain
@param boolean $RemoveSyndication
@return string | [
"Returns",
"the",
"Request",
"part",
"of",
"the",
"current",
"url",
".",
"ie",
".",
"/",
"controller",
"/",
"action",
"/",
"in",
"http",
":",
"//",
"localhost",
"/",
"garden",
"/",
"index",
".",
"php?",
"/",
"controller",
"/",
"action",
"/",
"."
] | train | https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/library/core/class.url.php#L79-L84 |
marando/phpSOFA | src/Marando/IAU/iauTttai.php | iauTttai.Tttai | public static function Tttai($tt1, $tt2, &$tai1, &$tai2) {
/* TT minus TAI (days). */
$dtat = TTMTAI / DAYSEC;
/* Result, safeguarding precision. */
if ($tt1 > $tt2) {
$tai1 = $tt1;
$tai2 = $tt2 - $dtat;
}
else {
$tai1 = $tt1 - $dtat;
$tai2 = $tt2;
}
/* Status (always OK). */
return 0;
} | php | public static function Tttai($tt1, $tt2, &$tai1, &$tai2) {
/* TT minus TAI (days). */
$dtat = TTMTAI / DAYSEC;
/* Result, safeguarding precision. */
if ($tt1 > $tt2) {
$tai1 = $tt1;
$tai2 = $tt2 - $dtat;
}
else {
$tai1 = $tt1 - $dtat;
$tai2 = $tt2;
}
/* Status (always OK). */
return 0;
} | [
"public",
"static",
"function",
"Tttai",
"(",
"$",
"tt1",
",",
"$",
"tt2",
",",
"&",
"$",
"tai1",
",",
"&",
"$",
"tai2",
")",
"{",
"/* TT minus TAI (days). */",
"$",
"dtat",
"=",
"TTMTAI",
"/",
"DAYSEC",
";",
"/* Result, safeguarding precision. */",
"if",
"(",
"$",
"tt1",
">",
"$",
"tt2",
")",
"{",
"$",
"tai1",
"=",
"$",
"tt1",
";",
"$",
"tai2",
"=",
"$",
"tt2",
"-",
"$",
"dtat",
";",
"}",
"else",
"{",
"$",
"tai1",
"=",
"$",
"tt1",
"-",
"$",
"dtat",
";",
"$",
"tai2",
"=",
"$",
"tt2",
";",
"}",
"/* Status (always OK). */",
"return",
"0",
";",
"}"
] | - - - - - - - - -
i a u T t t a i
- - - - - - - - -
Time scale transformation: Terrestrial Time, TT, to International
Atomic Time, TAI.
This function is part of the International Astronomical Union's
SOFA (Standards of Fundamental Astronomy) software collection.
Status: canonical.
Given:
tt1,tt2 double TT as a 2-part Julian Date
Returned:
tai1,tai2 double TAI as a 2-part Julian Date
Returned (function value):
int status: 0 = OK
Note:
tt1+tt2 is Julian Date, apportioned in any convenient way between
the two arguments, for example where tt1 is the Julian Day Number
and tt2 is the fraction of a day. The returned tai1,tai2 follow
suit.
References:
McCarthy, D. D., Petit, G. (eds.), IERS Conventions (2003),
IERS Technical Note No. 32, BKG (2004)
Explanatory Supplement to the Astronomical Almanac,
P. Kenneth Seidelmann (ed), University Science Books (1992)
This revision: 2013 June 18
SOFA release 2015-02-09
Copyright (C) 2015 IAU SOFA Board. See notes at end. | [
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"i",
"a",
"u",
"T",
"t",
"t",
"a",
"i",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-"
] | train | https://github.com/marando/phpSOFA/blob/757fa49fe335ae1210eaa7735473fd4388b13f07/src/Marando/IAU/iauTttai.php#L50-L66 |
sellerlabs/nucleus | src/SellerLabs/Nucleus/Meditation/Constraints/LeftFoldableOfConstraint.php | LeftFoldableOfConstraint.check | public function check($value, array $context = [])
{
if ($this->checkContainerType($value, $context) === false) {
return false;
}
foreach ($value as $item) {
if ($this->valueConstraint->check($item, $context) === false) {
return false;
}
}
return true;
} | php | public function check($value, array $context = [])
{
if ($this->checkContainerType($value, $context) === false) {
return false;
}
foreach ($value as $item) {
if ($this->valueConstraint->check($item, $context) === false) {
return false;
}
}
return true;
} | [
"public",
"function",
"check",
"(",
"$",
"value",
",",
"array",
"$",
"context",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"checkContainerType",
"(",
"$",
"value",
",",
"$",
"context",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"value",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"valueConstraint",
"->",
"check",
"(",
"$",
"item",
",",
"$",
"context",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Check if the constraint is met.
@param mixed $value
@param array $context
@return mixed | [
"Check",
"if",
"the",
"constraint",
"is",
"met",
"."
] | train | https://github.com/sellerlabs/nucleus/blob/c05d9c23d424a6bd5ab2e29140805cc6e37e4623/src/SellerLabs/Nucleus/Meditation/Constraints/LeftFoldableOfConstraint.php#L60-L73 |
dreadlokeur/Midi-ChloriansPHP | src/utility/Validate.php | Validate.isInt | public static function isInt($number, $gt = false, $lt = false) {
if (is_string($number)) {
if (trim($number) == '')
return false;
// Extract sign if exist
$sign = '';
if ($number[0] == '+' || $number[0] == '-') {
$sign = $number[0];
$number = substr($number, 1);
}
$number = ($sign == '-' ? '-' . $number : $number);
if ($number !== (string) (int) $number)
return false;
$number = (int) $number;
}elseif (((int) $number) !== $number)
return false;
if (!$lt && !$gt || $lt && $number <= $lt && $gt && $number >= $gt || !$lt && $gt && $number >= $gt || !$gt && $lt && $number <= $lt)
return true;
return false;
} | php | public static function isInt($number, $gt = false, $lt = false) {
if (is_string($number)) {
if (trim($number) == '')
return false;
// Extract sign if exist
$sign = '';
if ($number[0] == '+' || $number[0] == '-') {
$sign = $number[0];
$number = substr($number, 1);
}
$number = ($sign == '-' ? '-' . $number : $number);
if ($number !== (string) (int) $number)
return false;
$number = (int) $number;
}elseif (((int) $number) !== $number)
return false;
if (!$lt && !$gt || $lt && $number <= $lt && $gt && $number >= $gt || !$lt && $gt && $number >= $gt || !$gt && $lt && $number <= $lt)
return true;
return false;
} | [
"public",
"static",
"function",
"isInt",
"(",
"$",
"number",
",",
"$",
"gt",
"=",
"false",
",",
"$",
"lt",
"=",
"false",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"number",
")",
")",
"{",
"if",
"(",
"trim",
"(",
"$",
"number",
")",
"==",
"''",
")",
"return",
"false",
";",
"// Extract sign if exist\r",
"$",
"sign",
"=",
"''",
";",
"if",
"(",
"$",
"number",
"[",
"0",
"]",
"==",
"'+'",
"||",
"$",
"number",
"[",
"0",
"]",
"==",
"'-'",
")",
"{",
"$",
"sign",
"=",
"$",
"number",
"[",
"0",
"]",
";",
"$",
"number",
"=",
"substr",
"(",
"$",
"number",
",",
"1",
")",
";",
"}",
"$",
"number",
"=",
"(",
"$",
"sign",
"==",
"'-'",
"?",
"'-'",
".",
"$",
"number",
":",
"$",
"number",
")",
";",
"if",
"(",
"$",
"number",
"!==",
"(",
"string",
")",
"(",
"int",
")",
"$",
"number",
")",
"return",
"false",
";",
"$",
"number",
"=",
"(",
"int",
")",
"$",
"number",
";",
"}",
"elseif",
"(",
"(",
"(",
"int",
")",
"$",
"number",
")",
"!==",
"$",
"number",
")",
"return",
"false",
";",
"if",
"(",
"!",
"$",
"lt",
"&&",
"!",
"$",
"gt",
"||",
"$",
"lt",
"&&",
"$",
"number",
"<=",
"$",
"lt",
"&&",
"$",
"gt",
"&&",
"$",
"number",
">=",
"$",
"gt",
"||",
"!",
"$",
"lt",
"&&",
"$",
"gt",
"&&",
"$",
"number",
">=",
"$",
"gt",
"||",
"!",
"$",
"gt",
"&&",
"$",
"lt",
"&&",
"$",
"number",
"<=",
"$",
"lt",
")",
"return",
"true",
";",
"return",
"false",
";",
"}"
] | Checks if the number is an int, and can be check the range
@param Mixed $number
@param Integer $gt Check if greater than $gt
@param Integer $lt Check if lower than $lt
@return Boolean | [
"Checks",
"if",
"the",
"number",
"is",
"an",
"int",
"and",
"can",
"be",
"check",
"the",
"range"
] | train | https://github.com/dreadlokeur/Midi-ChloriansPHP/blob/4842e0a662c8b9448e69c8e5da35f55066f3bd9e/src/utility/Validate.php#L46-L65 |
dreadlokeur/Midi-ChloriansPHP | src/utility/Validate.php | Validate.isFloat | public static function isFloat($number, $gt = false, $lt = false) {
if (is_string($number)) {
if (trim($number) == '')
return false;
// Extract sign if exist
$sign = '';
if ($number[0] == '+' || $number[0] == '-') {
$sign = $number[0];
$number = substr($number, 1);
}
$number = ($sign == '-' ? '-' . $number : $number);
if (!\is_numeric($number))
return false;
$number = (float) $number;
}elseif (is_int($number)) {
$number = (float) $number;
}
if (!\is_float($number))
return false;
if (!$lt && !$gt || $lt && $number <= $lt && $gt && $number >= $gt || !$lt && $gt && $number >= $gt || !$gt && $lt && $number <= $lt)
return true;
return false;
} | php | public static function isFloat($number, $gt = false, $lt = false) {
if (is_string($number)) {
if (trim($number) == '')
return false;
// Extract sign if exist
$sign = '';
if ($number[0] == '+' || $number[0] == '-') {
$sign = $number[0];
$number = substr($number, 1);
}
$number = ($sign == '-' ? '-' . $number : $number);
if (!\is_numeric($number))
return false;
$number = (float) $number;
}elseif (is_int($number)) {
$number = (float) $number;
}
if (!\is_float($number))
return false;
if (!$lt && !$gt || $lt && $number <= $lt && $gt && $number >= $gt || !$lt && $gt && $number >= $gt || !$gt && $lt && $number <= $lt)
return true;
return false;
} | [
"public",
"static",
"function",
"isFloat",
"(",
"$",
"number",
",",
"$",
"gt",
"=",
"false",
",",
"$",
"lt",
"=",
"false",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"number",
")",
")",
"{",
"if",
"(",
"trim",
"(",
"$",
"number",
")",
"==",
"''",
")",
"return",
"false",
";",
"// Extract sign if exist\r",
"$",
"sign",
"=",
"''",
";",
"if",
"(",
"$",
"number",
"[",
"0",
"]",
"==",
"'+'",
"||",
"$",
"number",
"[",
"0",
"]",
"==",
"'-'",
")",
"{",
"$",
"sign",
"=",
"$",
"number",
"[",
"0",
"]",
";",
"$",
"number",
"=",
"substr",
"(",
"$",
"number",
",",
"1",
")",
";",
"}",
"$",
"number",
"=",
"(",
"$",
"sign",
"==",
"'-'",
"?",
"'-'",
".",
"$",
"number",
":",
"$",
"number",
")",
";",
"if",
"(",
"!",
"\\",
"is_numeric",
"(",
"$",
"number",
")",
")",
"return",
"false",
";",
"$",
"number",
"=",
"(",
"float",
")",
"$",
"number",
";",
"}",
"elseif",
"(",
"is_int",
"(",
"$",
"number",
")",
")",
"{",
"$",
"number",
"=",
"(",
"float",
")",
"$",
"number",
";",
"}",
"if",
"(",
"!",
"\\",
"is_float",
"(",
"$",
"number",
")",
")",
"return",
"false",
";",
"if",
"(",
"!",
"$",
"lt",
"&&",
"!",
"$",
"gt",
"||",
"$",
"lt",
"&&",
"$",
"number",
"<=",
"$",
"lt",
"&&",
"$",
"gt",
"&&",
"$",
"number",
">=",
"$",
"gt",
"||",
"!",
"$",
"lt",
"&&",
"$",
"gt",
"&&",
"$",
"number",
">=",
"$",
"gt",
"||",
"!",
"$",
"gt",
"&&",
"$",
"lt",
"&&",
"$",
"number",
"<=",
"$",
"lt",
")",
"return",
"true",
";",
"return",
"false",
";",
"}"
] | Checks if the number is a float and if is in the range of the given values.
@param Mixed $number Number to check
@param int $from Beginning of the range
@param int $to Ending of the range
@return boolean | [
"Checks",
"if",
"the",
"number",
"is",
"a",
"float",
"and",
"if",
"is",
"in",
"the",
"range",
"of",
"the",
"given",
"values",
"."
] | train | https://github.com/dreadlokeur/Midi-ChloriansPHP/blob/4842e0a662c8b9448e69c8e5da35f55066f3bd9e/src/utility/Validate.php#L76-L98 |
dreadlokeur/Midi-ChloriansPHP | src/utility/Validate.php | Validate.isString | public static function isString($var, $minLenght = false, $maxLenght = false) {
if (!is_string($var))
return false;
if ($minLenght && strlen($var) < $minLenght)
return false;
if ($maxLenght && strlen($var) > $maxLenght)
return false;
return true;
} | php | public static function isString($var, $minLenght = false, $maxLenght = false) {
if (!is_string($var))
return false;
if ($minLenght && strlen($var) < $minLenght)
return false;
if ($maxLenght && strlen($var) > $maxLenght)
return false;
return true;
} | [
"public",
"static",
"function",
"isString",
"(",
"$",
"var",
",",
"$",
"minLenght",
"=",
"false",
",",
"$",
"maxLenght",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"var",
")",
")",
"return",
"false",
";",
"if",
"(",
"$",
"minLenght",
"&&",
"strlen",
"(",
"$",
"var",
")",
"<",
"$",
"minLenght",
")",
"return",
"false",
";",
"if",
"(",
"$",
"maxLenght",
"&&",
"strlen",
"(",
"$",
"var",
")",
">",
"$",
"maxLenght",
")",
"return",
"false",
";",
"return",
"true",
";",
"}"
] | Check if a var is a string and can be check the size of it
@param Mixed $data
@param Integer $minLenght
@param Integer $maxLenght | [
"Check",
"if",
"a",
"var",
"is",
"a",
"string",
"and",
"can",
"be",
"check",
"the",
"size",
"of",
"it"
] | train | https://github.com/dreadlokeur/Midi-ChloriansPHP/blob/4842e0a662c8b9448e69c8e5da35f55066f3bd9e/src/utility/Validate.php#L106-L114 |
dreadlokeur/Midi-ChloriansPHP | src/utility/Validate.php | Validate.isEmail | public static function isEmail($email) {
if (!is_string($email) || strlen($email) > 255)
return false;
if (Tools::phpVersionCompareTo('5.3.3') >= 0)
return (boolean) filter_var($email, FILTER_VALIDATE_EMAIL);
else
return (boolean) preg_match('`^(?!\.)[.\w!#$%&\'*+/=?^_\`{|}~-]+@(?!-)[\w-]+\.\w+$`i', $email);
} | php | public static function isEmail($email) {
if (!is_string($email) || strlen($email) > 255)
return false;
if (Tools::phpVersionCompareTo('5.3.3') >= 0)
return (boolean) filter_var($email, FILTER_VALIDATE_EMAIL);
else
return (boolean) preg_match('`^(?!\.)[.\w!#$%&\'*+/=?^_\`{|}~-]+@(?!-)[\w-]+\.\w+$`i', $email);
} | [
"public",
"static",
"function",
"isEmail",
"(",
"$",
"email",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"email",
")",
"||",
"strlen",
"(",
"$",
"email",
")",
">",
"255",
")",
"return",
"false",
";",
"if",
"(",
"Tools",
"::",
"phpVersionCompareTo",
"(",
"'5.3.3'",
")",
">=",
"0",
")",
"return",
"(",
"boolean",
")",
"filter_var",
"(",
"$",
"email",
",",
"FILTER_VALIDATE_EMAIL",
")",
";",
"else",
"return",
"(",
"boolean",
")",
"preg_match",
"(",
"'`^(?!\\.)[.\\w!#$%&\\'*+/=?^_\\`{|}~-]+@(?!-)[\\w-]+\\.\\w+$`i'",
",",
"$",
"email",
")",
";",
"}"
] | Checks if the string is a well formed email address..
@param string $string
@return boolean | [
"Checks",
"if",
"the",
"string",
"is",
"a",
"well",
"formed",
"email",
"address",
".."
] | train | https://github.com/dreadlokeur/Midi-ChloriansPHP/blob/4842e0a662c8b9448e69c8e5da35f55066f3bd9e/src/utility/Validate.php#L133-L140 |
dreadlokeur/Midi-ChloriansPHP | src/utility/Validate.php | Validate.isIp | public static function isIp($ip, $allowIpV4 = true, $allowIpV6 = true) {
if ($allowIpV6 && $allowIpV4)
return \filter_var($ip, FILTER_VALIDATE_IP) !== false;
if (!$allowIpV6 && $allowIpV4)
return \filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false;
if ($allowIpV6 && !$allowIpV4)
return \filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false;
} | php | public static function isIp($ip, $allowIpV4 = true, $allowIpV6 = true) {
if ($allowIpV6 && $allowIpV4)
return \filter_var($ip, FILTER_VALIDATE_IP) !== false;
if (!$allowIpV6 && $allowIpV4)
return \filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false;
if ($allowIpV6 && !$allowIpV4)
return \filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false;
} | [
"public",
"static",
"function",
"isIp",
"(",
"$",
"ip",
",",
"$",
"allowIpV4",
"=",
"true",
",",
"$",
"allowIpV6",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"allowIpV6",
"&&",
"$",
"allowIpV4",
")",
"return",
"\\",
"filter_var",
"(",
"$",
"ip",
",",
"FILTER_VALIDATE_IP",
")",
"!==",
"false",
";",
"if",
"(",
"!",
"$",
"allowIpV6",
"&&",
"$",
"allowIpV4",
")",
"return",
"\\",
"filter_var",
"(",
"$",
"ip",
",",
"FILTER_VALIDATE_IP",
",",
"FILTER_FLAG_IPV4",
")",
"!==",
"false",
";",
"if",
"(",
"$",
"allowIpV6",
"&&",
"!",
"$",
"allowIpV4",
")",
"return",
"\\",
"filter_var",
"(",
"$",
"ip",
",",
"FILTER_VALIDATE_IP",
",",
"FILTER_FLAG_IPV6",
")",
"!==",
"false",
";",
"}"
] | Check if the variable is a representation of ip
@param String $ip
@param Boolean $allowIpV4 allow ipv4 (true by default)
@param Boolean $allowIpV6 allow ipv6 (true by default)
@return Boolean | [
"Check",
"if",
"the",
"variable",
"is",
"a",
"representation",
"of",
"ip"
] | train | https://github.com/dreadlokeur/Midi-ChloriansPHP/blob/4842e0a662c8b9448e69c8e5da35f55066f3bd9e/src/utility/Validate.php#L149-L156 |
dreadlokeur/Midi-ChloriansPHP | src/utility/Validate.php | Validate.isFileMimeType | public static function isFileMimeType($mimetype, $file) {
if (!extension_loaded('fileinfo'))
throw new \Exception('fileinfo extension not loaded try change your PHP configuration');
if (!is_file(realpath($file)) || !file_exists(realpath($file)) || !is_readable(realpath($file)))
throw new \Exception('La vérification du mimetype du fichier "' . $file . '" à échoué, le fichier n\'existe pas ou est invalid');
$finfo = new \finfo(FILEINFO_MIME_TYPE);
return (strpos($finfo->file(realpath($file)), $mimetype) !== false) ? true : false;
} | php | public static function isFileMimeType($mimetype, $file) {
if (!extension_loaded('fileinfo'))
throw new \Exception('fileinfo extension not loaded try change your PHP configuration');
if (!is_file(realpath($file)) || !file_exists(realpath($file)) || !is_readable(realpath($file)))
throw new \Exception('La vérification du mimetype du fichier "' . $file . '" à échoué, le fichier n\'existe pas ou est invalid');
$finfo = new \finfo(FILEINFO_MIME_TYPE);
return (strpos($finfo->file(realpath($file)), $mimetype) !== false) ? true : false;
} | [
"public",
"static",
"function",
"isFileMimeType",
"(",
"$",
"mimetype",
",",
"$",
"file",
")",
"{",
"if",
"(",
"!",
"extension_loaded",
"(",
"'fileinfo'",
")",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"'fileinfo extension not loaded try change your PHP configuration'",
")",
";",
"if",
"(",
"!",
"is_file",
"(",
"realpath",
"(",
"$",
"file",
")",
")",
"||",
"!",
"file_exists",
"(",
"realpath",
"(",
"$",
"file",
")",
")",
"||",
"!",
"is_readable",
"(",
"realpath",
"(",
"$",
"file",
")",
")",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"'La vérification du mimetype du fichier \"' ",
" ",
"f",
"ile ",
" ",
"\" à échoué, le fichier n\\'existe pas ou est invalid');\r",
"",
"",
"$",
"finfo",
"=",
"new",
"\\",
"finfo",
"(",
"FILEINFO_MIME_TYPE",
")",
";",
"return",
"(",
"strpos",
"(",
"$",
"finfo",
"->",
"file",
"(",
"realpath",
"(",
"$",
"file",
")",
")",
",",
"$",
"mimetype",
")",
"!==",
"false",
")",
"?",
"true",
":",
"false",
";",
"}"
] | Permet de verifier si un fichier est de mimetype voulut
@access public
@static
@param <string> $mimetype: le mimetype voulut
@param <string> $file: le fichier
@return <bool> | [
"Permet",
"de",
"verifier",
"si",
"un",
"fichier",
"est",
"de",
"mimetype",
"voulut"
] | train | https://github.com/dreadlokeur/Midi-ChloriansPHP/blob/4842e0a662c8b9448e69c8e5da35f55066f3bd9e/src/utility/Validate.php#L167-L176 |
FlexPress/component-taxonomy | src/FlexPress/Components/Taxonomy/AbstractTaxonomy.php | AbstractTaxonomy.getLabels | protected function getLabels()
{
$pluralName = $this->getPluralName();
$singularName = $this->getSingularName();
return array(
'name' => _x($pluralName, strtolower($pluralName)),
'singular_name' => _x($singularName, strtolower($singularName)),
'search_items' => __('Search ' . $pluralName),
'all_items' => __('All ' . $pluralName),
'parent_item' => __('Parent ' . $singularName),
'parent_item_colon' => __('Parent ' . $singularName . ":"),
'edit_item' => __('Edit ' . $singularName),
'update_item' => __('Update ' . $singularName),
'add_new_item' => __('Add New ' . $singularName),
'new_item_name' => __('New ' . $singularName),
'menu_name' => __($pluralName)
);
} | php | protected function getLabels()
{
$pluralName = $this->getPluralName();
$singularName = $this->getSingularName();
return array(
'name' => _x($pluralName, strtolower($pluralName)),
'singular_name' => _x($singularName, strtolower($singularName)),
'search_items' => __('Search ' . $pluralName),
'all_items' => __('All ' . $pluralName),
'parent_item' => __('Parent ' . $singularName),
'parent_item_colon' => __('Parent ' . $singularName . ":"),
'edit_item' => __('Edit ' . $singularName),
'update_item' => __('Update ' . $singularName),
'add_new_item' => __('Add New ' . $singularName),
'new_item_name' => __('New ' . $singularName),
'menu_name' => __($pluralName)
);
} | [
"protected",
"function",
"getLabels",
"(",
")",
"{",
"$",
"pluralName",
"=",
"$",
"this",
"->",
"getPluralName",
"(",
")",
";",
"$",
"singularName",
"=",
"$",
"this",
"->",
"getSingularName",
"(",
")",
";",
"return",
"array",
"(",
"'name'",
"=>",
"_x",
"(",
"$",
"pluralName",
",",
"strtolower",
"(",
"$",
"pluralName",
")",
")",
",",
"'singular_name'",
"=>",
"_x",
"(",
"$",
"singularName",
",",
"strtolower",
"(",
"$",
"singularName",
")",
")",
",",
"'search_items'",
"=>",
"__",
"(",
"'Search '",
".",
"$",
"pluralName",
")",
",",
"'all_items'",
"=>",
"__",
"(",
"'All '",
".",
"$",
"pluralName",
")",
",",
"'parent_item'",
"=>",
"__",
"(",
"'Parent '",
".",
"$",
"singularName",
")",
",",
"'parent_item_colon'",
"=>",
"__",
"(",
"'Parent '",
".",
"$",
"singularName",
".",
"\":\"",
")",
",",
"'edit_item'",
"=>",
"__",
"(",
"'Edit '",
".",
"$",
"singularName",
")",
",",
"'update_item'",
"=>",
"__",
"(",
"'Update '",
".",
"$",
"singularName",
")",
",",
"'add_new_item'",
"=>",
"__",
"(",
"'Add New '",
".",
"$",
"singularName",
")",
",",
"'new_item_name'",
"=>",
"__",
"(",
"'New '",
".",
"$",
"singularName",
")",
",",
"'menu_name'",
"=>",
"__",
"(",
"$",
"pluralName",
")",
")",
";",
"}"
] | Gets the labels used in the args
@return array
@author Tim Perry | [
"Gets",
"the",
"labels",
"used",
"in",
"the",
"args"
] | train | https://github.com/FlexPress/component-taxonomy/blob/e917246c2b2837f5db2b8d0ec191d434e658d806/src/FlexPress/Components/Taxonomy/AbstractTaxonomy.php#L55-L73 |
wearenolte/wp-endpoints-collection | src/Collection/Post.php | Post.get_thumbnail | public static function get_thumbnail( $the_post, $args ) {
$thumbnail = [
'src' => '',
'width' => '',
'height' => '',
'alt' => '',
];
if ( has_post_thumbnail( $the_post->ID ) ) {
$size = apply_filters( Filter::THUMBNAIL_SIZE, 'thumbnail', $the_post, $args );
$attachment_id = get_post_thumbnail_id( $the_post->ID );
$src = wp_get_attachment_image_src( $attachment_id, $size );
$alt = get_post_meta( $attachment_id, '_wp_attachment_image_alt', true );
$thumbnail = [
'src' => $src[0],
'width' => $src[1],
'height' => $src[2],
'alt' => $alt ? $alt : $the_post->post_title,
];
}
return $thumbnail;
} | php | public static function get_thumbnail( $the_post, $args ) {
$thumbnail = [
'src' => '',
'width' => '',
'height' => '',
'alt' => '',
];
if ( has_post_thumbnail( $the_post->ID ) ) {
$size = apply_filters( Filter::THUMBNAIL_SIZE, 'thumbnail', $the_post, $args );
$attachment_id = get_post_thumbnail_id( $the_post->ID );
$src = wp_get_attachment_image_src( $attachment_id, $size );
$alt = get_post_meta( $attachment_id, '_wp_attachment_image_alt', true );
$thumbnail = [
'src' => $src[0],
'width' => $src[1],
'height' => $src[2],
'alt' => $alt ? $alt : $the_post->post_title,
];
}
return $thumbnail;
} | [
"public",
"static",
"function",
"get_thumbnail",
"(",
"$",
"the_post",
",",
"$",
"args",
")",
"{",
"$",
"thumbnail",
"=",
"[",
"'src'",
"=>",
"''",
",",
"'width'",
"=>",
"''",
",",
"'height'",
"=>",
"''",
",",
"'alt'",
"=>",
"''",
",",
"]",
";",
"if",
"(",
"has_post_thumbnail",
"(",
"$",
"the_post",
"->",
"ID",
")",
")",
"{",
"$",
"size",
"=",
"apply_filters",
"(",
"Filter",
"::",
"THUMBNAIL_SIZE",
",",
"'thumbnail'",
",",
"$",
"the_post",
",",
"$",
"args",
")",
";",
"$",
"attachment_id",
"=",
"get_post_thumbnail_id",
"(",
"$",
"the_post",
"->",
"ID",
")",
";",
"$",
"src",
"=",
"wp_get_attachment_image_src",
"(",
"$",
"attachment_id",
",",
"$",
"size",
")",
";",
"$",
"alt",
"=",
"get_post_meta",
"(",
"$",
"attachment_id",
",",
"'_wp_attachment_image_alt'",
",",
"true",
")",
";",
"$",
"thumbnail",
"=",
"[",
"'src'",
"=>",
"$",
"src",
"[",
"0",
"]",
",",
"'width'",
"=>",
"$",
"src",
"[",
"1",
"]",
",",
"'height'",
"=>",
"$",
"src",
"[",
"2",
"]",
",",
"'alt'",
"=>",
"$",
"alt",
"?",
"$",
"alt",
":",
"$",
"the_post",
"->",
"post_title",
",",
"]",
";",
"}",
"return",
"$",
"thumbnail",
";",
"}"
] | Get the thumbnail
@param \WP_Post $the_post The post.
@param array $args The query args.
@return array | [
"Get",
"the",
"thumbnail"
] | train | https://github.com/wearenolte/wp-endpoints-collection/blob/39b62efb3fc507b19b6dd47c0d6fb99e74717e9c/src/Collection/Post.php#L17-L43 |
wearenolte/wp-endpoints-collection | src/Collection/Post.php | Post.get_terms | public static function get_terms( $the_post ) {
$taxonomies = get_object_taxonomies( $the_post );
$post_terms = [];
foreach ( $taxonomies as $taxonomy ) {
$post_terms[ $taxonomy ] = [];
$terms = wp_get_post_terms( $the_post->ID, $taxonomy );
foreach ( $terms as $term ) {
$post_terms[ $taxonomy ][] = [
'id' => $term->term_id,
'name' => $term->name,
'slug' => $term->slug,
'description' => $term->description,
];
}
}
return $post_terms;
} | php | public static function get_terms( $the_post ) {
$taxonomies = get_object_taxonomies( $the_post );
$post_terms = [];
foreach ( $taxonomies as $taxonomy ) {
$post_terms[ $taxonomy ] = [];
$terms = wp_get_post_terms( $the_post->ID, $taxonomy );
foreach ( $terms as $term ) {
$post_terms[ $taxonomy ][] = [
'id' => $term->term_id,
'name' => $term->name,
'slug' => $term->slug,
'description' => $term->description,
];
}
}
return $post_terms;
} | [
"public",
"static",
"function",
"get_terms",
"(",
"$",
"the_post",
")",
"{",
"$",
"taxonomies",
"=",
"get_object_taxonomies",
"(",
"$",
"the_post",
")",
";",
"$",
"post_terms",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"taxonomies",
"as",
"$",
"taxonomy",
")",
"{",
"$",
"post_terms",
"[",
"$",
"taxonomy",
"]",
"=",
"[",
"]",
";",
"$",
"terms",
"=",
"wp_get_post_terms",
"(",
"$",
"the_post",
"->",
"ID",
",",
"$",
"taxonomy",
")",
";",
"foreach",
"(",
"$",
"terms",
"as",
"$",
"term",
")",
"{",
"$",
"post_terms",
"[",
"$",
"taxonomy",
"]",
"[",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"term",
"->",
"term_id",
",",
"'name'",
"=>",
"$",
"term",
"->",
"name",
",",
"'slug'",
"=>",
"$",
"term",
"->",
"slug",
",",
"'description'",
"=>",
"$",
"term",
"->",
"description",
",",
"]",
";",
"}",
"}",
"return",
"$",
"post_terms",
";",
"}"
] | Get all taxonomies and terms for this post.
@param \WP_Post $the_post The post.
@return array | [
"Get",
"all",
"taxonomies",
"and",
"terms",
"for",
"this",
"post",
"."
] | train | https://github.com/wearenolte/wp-endpoints-collection/blob/39b62efb3fc507b19b6dd47c0d6fb99e74717e9c/src/Collection/Post.php#L51-L72 |
coolms/authentication | src/Factory/Validator/CredentialValidatorFactory.php | CredentialValidatorFactory.createService | public function createService(ServiceLocatorInterface $validators)
{
/* @var $options InputFilterOptionsInterface */
$options = $validators->getServiceLocator()->get(ModuleOptions::class);
$chain = new ValidatorChain;
$chain->attachByName('StringLength', [
'min' => $options->getMinCredentialLength(),
'max' => $options->getMaxCredentialLength(),
], true);
return $chain;
} | php | public function createService(ServiceLocatorInterface $validators)
{
/* @var $options InputFilterOptionsInterface */
$options = $validators->getServiceLocator()->get(ModuleOptions::class);
$chain = new ValidatorChain;
$chain->attachByName('StringLength', [
'min' => $options->getMinCredentialLength(),
'max' => $options->getMaxCredentialLength(),
], true);
return $chain;
} | [
"public",
"function",
"createService",
"(",
"ServiceLocatorInterface",
"$",
"validators",
")",
"{",
"/* @var $options InputFilterOptionsInterface */",
"$",
"options",
"=",
"$",
"validators",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"ModuleOptions",
"::",
"class",
")",
";",
"$",
"chain",
"=",
"new",
"ValidatorChain",
";",
"$",
"chain",
"->",
"attachByName",
"(",
"'StringLength'",
",",
"[",
"'min'",
"=>",
"$",
"options",
"->",
"getMinCredentialLength",
"(",
")",
",",
"'max'",
"=>",
"$",
"options",
"->",
"getMaxCredentialLength",
"(",
")",
",",
"]",
",",
"true",
")",
";",
"return",
"$",
"chain",
";",
"}"
] | {@inheritDoc}
@return ValidatorChain | [
"{",
"@inheritDoc",
"}"
] | train | https://github.com/coolms/authentication/blob/4563cc4cc3a4d777db45977bd179cc5bd3f57cd8/src/Factory/Validator/CredentialValidatorFactory.php#L26-L39 |
getui-sdk/php | src/protobuf/type/PBSignedInt.php | PBSignedInt.ParseFromArray | public function ParseFromArray()
{
parent::ParseFromArray();
$saved = $this->value;
$this->value = round($this->value / 2);
if ($saved % 2 == 1)
{
$this->value = -($this->value);
}
} | php | public function ParseFromArray()
{
parent::ParseFromArray();
$saved = $this->value;
$this->value = round($this->value / 2);
if ($saved % 2 == 1)
{
$this->value = -($this->value);
}
} | [
"public",
"function",
"ParseFromArray",
"(",
")",
"{",
"parent",
"::",
"ParseFromArray",
"(",
")",
";",
"$",
"saved",
"=",
"$",
"this",
"->",
"value",
";",
"$",
"this",
"->",
"value",
"=",
"round",
"(",
"$",
"this",
"->",
"value",
"/",
"2",
")",
";",
"if",
"(",
"$",
"saved",
"%",
"2",
"==",
"1",
")",
"{",
"$",
"this",
"->",
"value",
"=",
"-",
"(",
"$",
"this",
"->",
"value",
")",
";",
"}",
"}"
] | Parses the message for this type
@param array | [
"Parses",
"the",
"message",
"for",
"this",
"type"
] | train | https://github.com/getui-sdk/php/blob/919ff9e3446fe4e8cac171891e11568bbf423f1c/src/protobuf/type/PBSignedInt.php#L18-L28 |
getui-sdk/php | src/protobuf/type/PBSignedInt.php | PBSignedInt.SerializeToString | public function SerializeToString($rec=-1)
{
// now convert signed int to int
$save = $this->value;
if ($this->value < 0)
{
$this->value = abs($this->value)*2-1;
}
else
{
$this->value = $this->value*2;
}
$string = parent::SerializeToString($rec);
// restore value
$this->value = $save;
return $string;
} | php | public function SerializeToString($rec=-1)
{
// now convert signed int to int
$save = $this->value;
if ($this->value < 0)
{
$this->value = abs($this->value)*2-1;
}
else
{
$this->value = $this->value*2;
}
$string = parent::SerializeToString($rec);
// restore value
$this->value = $save;
return $string;
} | [
"public",
"function",
"SerializeToString",
"(",
"$",
"rec",
"=",
"-",
"1",
")",
"{",
"// now convert signed int to int",
"$",
"save",
"=",
"$",
"this",
"->",
"value",
";",
"if",
"(",
"$",
"this",
"->",
"value",
"<",
"0",
")",
"{",
"$",
"this",
"->",
"value",
"=",
"abs",
"(",
"$",
"this",
"->",
"value",
")",
"*",
"2",
"-",
"1",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"value",
"=",
"$",
"this",
"->",
"value",
"*",
"2",
";",
"}",
"$",
"string",
"=",
"parent",
"::",
"SerializeToString",
"(",
"$",
"rec",
")",
";",
"// restore value",
"$",
"this",
"->",
"value",
"=",
"$",
"save",
";",
"return",
"$",
"string",
";",
"}"
] | Serializes type | [
"Serializes",
"type"
] | train | https://github.com/getui-sdk/php/blob/919ff9e3446fe4e8cac171891e11568bbf423f1c/src/protobuf/type/PBSignedInt.php#L33-L50 |
jooorooo/embed | src/Providers/TwitterCards.php | TwitterCards.getCode | public function getCode()
{
if ($this->bag->has('player')) {
return Utils::iframe($this->bag->get('player'), $this->getWidth(), $this->getHeight());
}
} | php | public function getCode()
{
if ($this->bag->has('player')) {
return Utils::iframe($this->bag->get('player'), $this->getWidth(), $this->getHeight());
}
} | [
"public",
"function",
"getCode",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"bag",
"->",
"has",
"(",
"'player'",
")",
")",
"{",
"return",
"Utils",
"::",
"iframe",
"(",
"$",
"this",
"->",
"bag",
"->",
"get",
"(",
"'player'",
")",
",",
"$",
"this",
"->",
"getWidth",
"(",
")",
",",
"$",
"this",
"->",
"getHeight",
"(",
")",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/jooorooo/embed/blob/078e70a093f246dc8e10b92f909f9166932c4106/src/Providers/TwitterCards.php#L79-L84 |
blenderdeluxe/khipu | src/KhipuService/KhipuServiceVerifyPaymentNotification.php | KhipuServiceVerifyPaymentNotification.verify | public function verify() {
// Pasamos los datos a string
$data = $this->dataToString();
// Iniciamos CURL
$ch = curl_init($this->apiUrl);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
// @TODO: que hacer en caso de error del servidor?
$info = curl_getinfo($ch);
curl_close($ch);
return array(
'response' => $response,
'info' => $info,
);
} | php | public function verify() {
// Pasamos los datos a string
$data = $this->dataToString();
// Iniciamos CURL
$ch = curl_init($this->apiUrl);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
// @TODO: que hacer en caso de error del servidor?
$info = curl_getinfo($ch);
curl_close($ch);
return array(
'response' => $response,
'info' => $info,
);
} | [
"public",
"function",
"verify",
"(",
")",
"{",
"// Pasamos los datos a string",
"$",
"data",
"=",
"$",
"this",
"->",
"dataToString",
"(",
")",
";",
"// Iniciamos CURL",
"$",
"ch",
"=",
"curl_init",
"(",
"$",
"this",
"->",
"apiUrl",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_HEADER",
",",
"0",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_POST",
",",
"1",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_RETURNTRANSFER",
",",
"1",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_POSTFIELDS",
",",
"$",
"data",
")",
";",
"$",
"response",
"=",
"curl_exec",
"(",
"$",
"ch",
")",
";",
"// @TODO: que hacer en caso de error del servidor?",
"$",
"info",
"=",
"curl_getinfo",
"(",
"$",
"ch",
")",
";",
"curl_close",
"(",
"$",
"ch",
")",
";",
"return",
"array",
"(",
"'response'",
"=>",
"$",
"response",
",",
"'info'",
"=>",
"$",
"info",
",",
")",
";",
"}"
] | Método que envía a Khipu los datos para verificar si fueron enviados
por ellos mismos. | [
"Método",
"que",
"envía",
"a",
"Khipu",
"los",
"datos",
"para",
"verificar",
"si",
"fueron",
"enviados",
"por",
"ellos",
"mismos",
"."
] | train | https://github.com/blenderdeluxe/khipu/blob/ef78fa8ba372c7784936ce95a3d0bd46a35e0143/src/KhipuService/KhipuServiceVerifyPaymentNotification.php#L61-L78 |
mosiyash/taisiya-propel-bundle | src/Database/IndexTrait.php | IndexTrait.addColumn | final public function addColumn(Column $column, int $size = null): Index
{
if ($this->hasColumn($column::getName())) {
throw new InvalidArgumentException('Column '.$column::getName().' already added to the index');
}
$this->columns[] = new IndexColumn($column, $size);
return $this;
} | php | final public function addColumn(Column $column, int $size = null): Index
{
if ($this->hasColumn($column::getName())) {
throw new InvalidArgumentException('Column '.$column::getName().' already added to the index');
}
$this->columns[] = new IndexColumn($column, $size);
return $this;
} | [
"final",
"public",
"function",
"addColumn",
"(",
"Column",
"$",
"column",
",",
"int",
"$",
"size",
"=",
"null",
")",
":",
"Index",
"{",
"if",
"(",
"$",
"this",
"->",
"hasColumn",
"(",
"$",
"column",
"::",
"getName",
"(",
")",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Column '",
".",
"$",
"column",
"::",
"getName",
"(",
")",
".",
"' already added to the index'",
")",
";",
"}",
"$",
"this",
"->",
"columns",
"[",
"]",
"=",
"new",
"IndexColumn",
"(",
"$",
"column",
",",
"$",
"size",
")",
";",
"return",
"$",
"this",
";",
"}"
] | @param Column $column
@param int|null $size
@return Index | [
"@param",
"Column",
"$column",
"@param",
"int|null",
"$size"
] | train | https://github.com/mosiyash/taisiya-propel-bundle/blob/a56f3245cc8f6a20143f812d814d05699807285c/src/Database/IndexTrait.php#L20-L29 |
mosiyash/taisiya-propel-bundle | src/Database/IndexTrait.php | IndexTrait.addColumnIfNotExists | final public function addColumnIfNotExists(Column $column, int $size = null): Index
{
if (!$this->hasColumn($column::getName())) {
$this->addColumn($column, $size);
} else {
$indexColumn = $this->findIndexColumnByName($column::getName());
if ($indexColumn->getSize() !== $size) {
$indexColumn->setSize($size);
}
}
return $this;
} | php | final public function addColumnIfNotExists(Column $column, int $size = null): Index
{
if (!$this->hasColumn($column::getName())) {
$this->addColumn($column, $size);
} else {
$indexColumn = $this->findIndexColumnByName($column::getName());
if ($indexColumn->getSize() !== $size) {
$indexColumn->setSize($size);
}
}
return $this;
} | [
"final",
"public",
"function",
"addColumnIfNotExists",
"(",
"Column",
"$",
"column",
",",
"int",
"$",
"size",
"=",
"null",
")",
":",
"Index",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasColumn",
"(",
"$",
"column",
"::",
"getName",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"addColumn",
"(",
"$",
"column",
",",
"$",
"size",
")",
";",
"}",
"else",
"{",
"$",
"indexColumn",
"=",
"$",
"this",
"->",
"findIndexColumnByName",
"(",
"$",
"column",
"::",
"getName",
"(",
")",
")",
";",
"if",
"(",
"$",
"indexColumn",
"->",
"getSize",
"(",
")",
"!==",
"$",
"size",
")",
"{",
"$",
"indexColumn",
"->",
"setSize",
"(",
"$",
"size",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | @param Column $column
@param int|null $size
@return Index | [
"@param",
"Column",
"$column",
"@param",
"int|null",
"$size"
] | train | https://github.com/mosiyash/taisiya-propel-bundle/blob/a56f3245cc8f6a20143f812d814d05699807285c/src/Database/IndexTrait.php#L37-L49 |
mosiyash/taisiya-propel-bundle | src/Database/IndexTrait.php | IndexTrait.removeColumn | final public function removeColumn(string $name): Index
{
if (!$this->hasColumn($name)) {
throw new InvalidArgumentException('Index not contains the column '.$name);
}
$this->columns = array_filter(
$this->columns,
function (IndexColumn $indexColumn) use ($name) {
$column = $indexColumn->getColumn();
return (bool) ($column::getName() !== $name);
}
);
return $this;
} | php | final public function removeColumn(string $name): Index
{
if (!$this->hasColumn($name)) {
throw new InvalidArgumentException('Index not contains the column '.$name);
}
$this->columns = array_filter(
$this->columns,
function (IndexColumn $indexColumn) use ($name) {
$column = $indexColumn->getColumn();
return (bool) ($column::getName() !== $name);
}
);
return $this;
} | [
"final",
"public",
"function",
"removeColumn",
"(",
"string",
"$",
"name",
")",
":",
"Index",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasColumn",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Index not contains the column '",
".",
"$",
"name",
")",
";",
"}",
"$",
"this",
"->",
"columns",
"=",
"array_filter",
"(",
"$",
"this",
"->",
"columns",
",",
"function",
"(",
"IndexColumn",
"$",
"indexColumn",
")",
"use",
"(",
"$",
"name",
")",
"{",
"$",
"column",
"=",
"$",
"indexColumn",
"->",
"getColumn",
"(",
")",
";",
"return",
"(",
"bool",
")",
"(",
"$",
"column",
"::",
"getName",
"(",
")",
"!==",
"$",
"name",
")",
";",
"}",
")",
";",
"return",
"$",
"this",
";",
"}"
] | @param string $name
@return Index | [
"@param",
"string",
"$name"
] | train | https://github.com/mosiyash/taisiya-propel-bundle/blob/a56f3245cc8f6a20143f812d814d05699807285c/src/Database/IndexTrait.php#L74-L90 |
mosiyash/taisiya-propel-bundle | src/Database/IndexTrait.php | IndexTrait.findIndexColumnByName | final public function findIndexColumnByName(string $name): ? IndexColumn
{
/** @var IndexColumn $indexColumn */
foreach ($this->columns as $indexColumn) {
$column = $indexColumn->getColumn();
if ($column::getName() === $name) {
return $indexColumn;
}
}
return null;
} | php | final public function findIndexColumnByName(string $name): ? IndexColumn
{
/** @var IndexColumn $indexColumn */
foreach ($this->columns as $indexColumn) {
$column = $indexColumn->getColumn();
if ($column::getName() === $name) {
return $indexColumn;
}
}
return null;
} | [
"final",
"public",
"function",
"findIndexColumnByName",
"(",
"string",
"$",
"name",
")",
":",
"?",
"IndexColumn",
"{",
"/** @var IndexColumn $indexColumn */",
"foreach",
"(",
"$",
"this",
"->",
"columns",
"as",
"$",
"indexColumn",
")",
"{",
"$",
"column",
"=",
"$",
"indexColumn",
"->",
"getColumn",
"(",
")",
";",
"if",
"(",
"$",
"column",
"::",
"getName",
"(",
")",
"===",
"$",
"name",
")",
"{",
"return",
"$",
"indexColumn",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | @param string $name
@return null|IndexColumn | [
"@param",
"string",
"$name"
] | train | https://github.com/mosiyash/taisiya-propel-bundle/blob/a56f3245cc8f6a20143f812d814d05699807285c/src/Database/IndexTrait.php#L97-L108 |
jagilpe/entity-list-bundle | EntityList/EntityListFactory.php | EntityListFactory.createListColumn | public function createListColumn($columnName, $listColumnTypeClass = ColumnType::class, array $options = array())
{
$listColumnBuilder = $this->createListColumnBuilder($columnName, $listColumnTypeClass, $options);
return $listColumnBuilder->getListColumn();
} | php | public function createListColumn($columnName, $listColumnTypeClass = ColumnType::class, array $options = array())
{
$listColumnBuilder = $this->createListColumnBuilder($columnName, $listColumnTypeClass, $options);
return $listColumnBuilder->getListColumn();
} | [
"public",
"function",
"createListColumn",
"(",
"$",
"columnName",
",",
"$",
"listColumnTypeClass",
"=",
"ColumnType",
"::",
"class",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"listColumnBuilder",
"=",
"$",
"this",
"->",
"createListColumnBuilder",
"(",
"$",
"columnName",
",",
"$",
"listColumnTypeClass",
",",
"$",
"options",
")",
";",
"return",
"$",
"listColumnBuilder",
"->",
"getListColumn",
"(",
")",
";",
"}"
] | {@inheritDoc}
@see \Jagilpe\EntityListBundle\EntityList\EntityListFactoryInterface::createListColumn() | [
"{"
] | train | https://github.com/jagilpe/entity-list-bundle/blob/54331a4de7e7916894fb4a7a3156d8e7c1b0e0dc/EntityList/EntityListFactory.php#L80-L84 |
jagilpe/entity-list-bundle | EntityList/EntityListFactory.php | EntityListFactory.getEntityListColumnType | public function getEntityListColumnType($columnTypeClass)
{
if (isset($this->columnTypes[$columnTypeClass])) {
return $this->columnTypes[$columnTypeClass];
}
elseif (class_exists($columnTypeClass)) {
return new $columnTypeClass();
}
} | php | public function getEntityListColumnType($columnTypeClass)
{
if (isset($this->columnTypes[$columnTypeClass])) {
return $this->columnTypes[$columnTypeClass];
}
elseif (class_exists($columnTypeClass)) {
return new $columnTypeClass();
}
} | [
"public",
"function",
"getEntityListColumnType",
"(",
"$",
"columnTypeClass",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"columnTypes",
"[",
"$",
"columnTypeClass",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"columnTypes",
"[",
"$",
"columnTypeClass",
"]",
";",
"}",
"elseif",
"(",
"class_exists",
"(",
"$",
"columnTypeClass",
")",
")",
"{",
"return",
"new",
"$",
"columnTypeClass",
"(",
")",
";",
"}",
"}"
] | {@inheritDoc}
@see \Jagilpe\EntityListBundle\EntityList\EntityListFactoryInterface::getEntityListColumnType() | [
"{"
] | train | https://github.com/jagilpe/entity-list-bundle/blob/54331a4de7e7916894fb4a7a3156d8e7c1b0e0dc/EntityList/EntityListFactory.php#L90-L98 |
jakecleary/ultrapress-library | src/Ultra/Helpers/AcfHelpers.php | AcfHelper.loadRepeater | public static function loadRepeater($repeater, $itemId, $mapping)
{
if(have_rows($repeater, $itemId))
{
$data = [];
$n = 0;
while(have_rows($repeater, $itemId))
{
the_row();
$data[$n] = [];
foreach($mapping as $key => $value)
{
$data[$n][$key] = get_sub_field($value);
}
$n++;
}
return $data;
}
return false;
} | php | public static function loadRepeater($repeater, $itemId, $mapping)
{
if(have_rows($repeater, $itemId))
{
$data = [];
$n = 0;
while(have_rows($repeater, $itemId))
{
the_row();
$data[$n] = [];
foreach($mapping as $key => $value)
{
$data[$n][$key] = get_sub_field($value);
}
$n++;
}
return $data;
}
return false;
} | [
"public",
"static",
"function",
"loadRepeater",
"(",
"$",
"repeater",
",",
"$",
"itemId",
",",
"$",
"mapping",
")",
"{",
"if",
"(",
"have_rows",
"(",
"$",
"repeater",
",",
"$",
"itemId",
")",
")",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"$",
"n",
"=",
"0",
";",
"while",
"(",
"have_rows",
"(",
"$",
"repeater",
",",
"$",
"itemId",
")",
")",
"{",
"the_row",
"(",
")",
";",
"$",
"data",
"[",
"$",
"n",
"]",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"mapping",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"data",
"[",
"$",
"n",
"]",
"[",
"$",
"key",
"]",
"=",
"get_sub_field",
"(",
"$",
"value",
")",
";",
"}",
"$",
"n",
"++",
";",
"}",
"return",
"$",
"data",
";",
"}",
"return",
"false",
";",
"}"
] | Build an array from an ACF repeater's data
@param string $repeater The name of the repeater
@param array $mapping And array mapping out the structure of the data | [
"Build",
"an",
"array",
"from",
"an",
"ACF",
"repeater",
"s",
"data"
] | train | https://github.com/jakecleary/ultrapress-library/blob/84ca5d1dae8eb16de8c886787575ea41f9332ae2/src/Ultra/Helpers/AcfHelpers.php#L17-L41 |
jakecleary/ultrapress-library | src/Ultra/Helpers/AcfHelpers.php | AcfHelper.getImage | public static function getImage($post, $name, $size, $dimensions = false)
{
if(get_field($name, $post))
{
$data = get_field($name, $post);
return getAcfImageFromArray($data, $size, $dimensions);
}
else
{
return false;
}
} | php | public static function getImage($post, $name, $size, $dimensions = false)
{
if(get_field($name, $post))
{
$data = get_field($name, $post);
return getAcfImageFromArray($data, $size, $dimensions);
}
else
{
return false;
}
} | [
"public",
"static",
"function",
"getImage",
"(",
"$",
"post",
",",
"$",
"name",
",",
"$",
"size",
",",
"$",
"dimensions",
"=",
"false",
")",
"{",
"if",
"(",
"get_field",
"(",
"$",
"name",
",",
"$",
"post",
")",
")",
"{",
"$",
"data",
"=",
"get_field",
"(",
"$",
"name",
",",
"$",
"post",
")",
";",
"return",
"getAcfImageFromArray",
"(",
"$",
"data",
",",
"$",
"size",
",",
"$",
"dimensions",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Get an acf image array, with optional dimentions
@param integer $post The post id the image belongs to
@param string $name The name of the field the image is stored in
@param string $size The 'image_size' to retrieve it in
@param boolean $dimensions whether to output the dimensions
@return mixed $image The image (string or array) | [
"Get",
"an",
"acf",
"image",
"array",
"with",
"optional",
"dimentions"
] | train | https://github.com/jakecleary/ultrapress-library/blob/84ca5d1dae8eb16de8c886787575ea41f9332ae2/src/Ultra/Helpers/AcfHelpers.php#L52-L64 |
jakecleary/ultrapress-library | src/Ultra/Helpers/AcfHelpers.php | AcfHelper.getImageFromArray | public static function getImageFromArray($data, $size, $dimensions = false)
{
if($dimensions === true)
{
$image = (object) [
'url' => $data['sizes'][$size],
'width' => $data['sizes'][$size . '-width'],
'height' => $data['sizes'][$size . '-height']
];
}
else
{
$image = $data['sizes'][$size];
}
return $image;
} | php | public static function getImageFromArray($data, $size, $dimensions = false)
{
if($dimensions === true)
{
$image = (object) [
'url' => $data['sizes'][$size],
'width' => $data['sizes'][$size . '-width'],
'height' => $data['sizes'][$size . '-height']
];
}
else
{
$image = $data['sizes'][$size];
}
return $image;
} | [
"public",
"static",
"function",
"getImageFromArray",
"(",
"$",
"data",
",",
"$",
"size",
",",
"$",
"dimensions",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"dimensions",
"===",
"true",
")",
"{",
"$",
"image",
"=",
"(",
"object",
")",
"[",
"'url'",
"=>",
"$",
"data",
"[",
"'sizes'",
"]",
"[",
"$",
"size",
"]",
",",
"'width'",
"=>",
"$",
"data",
"[",
"'sizes'",
"]",
"[",
"$",
"size",
".",
"'-width'",
"]",
",",
"'height'",
"=>",
"$",
"data",
"[",
"'sizes'",
"]",
"[",
"$",
"size",
".",
"'-height'",
"]",
"]",
";",
"}",
"else",
"{",
"$",
"image",
"=",
"$",
"data",
"[",
"'sizes'",
"]",
"[",
"$",
"size",
"]",
";",
"}",
"return",
"$",
"image",
";",
"}"
] | Build a simplified array of ACF image data
@param array $data The raw image array
@param string $size The desired size
@param boolean $dimensions Whether to return the dimensions aswell
@return string/array The image url/data | [
"Build",
"a",
"simplified",
"array",
"of",
"ACF",
"image",
"data"
] | train | https://github.com/jakecleary/ultrapress-library/blob/84ca5d1dae8eb16de8c886787575ea41f9332ae2/src/Ultra/Helpers/AcfHelpers.php#L74-L89 |
frostnode/frostnode-cms | modules/User/Database/Seeders/UserDatabaseSeeder.php | UserDatabaseSeeder.run | public function run()
{
Model::unguard();
$role_admin = Role::where('name', 'admin')->first();
$role_editor = Role::where('name', 'editor')->first();
$admin = new User();
$admin->uuid = (string) Str::uuid();
$admin->name = 'Admin';
$admin->email = 'admin@example.com';
$admin->password = bcrypt('Secret1');
$admin->save();
$admin->roles()->attach($role_admin);
$editor = new User();
$editor->uuid = (string) Str::uuid();
$editor->name = 'Editor';
$editor->email = 'editor@example.com';
$editor->password = bcrypt('Secret1');
$editor->save();
$editor->roles()->attach($role_editor);
} | php | public function run()
{
Model::unguard();
$role_admin = Role::where('name', 'admin')->first();
$role_editor = Role::where('name', 'editor')->first();
$admin = new User();
$admin->uuid = (string) Str::uuid();
$admin->name = 'Admin';
$admin->email = 'admin@example.com';
$admin->password = bcrypt('Secret1');
$admin->save();
$admin->roles()->attach($role_admin);
$editor = new User();
$editor->uuid = (string) Str::uuid();
$editor->name = 'Editor';
$editor->email = 'editor@example.com';
$editor->password = bcrypt('Secret1');
$editor->save();
$editor->roles()->attach($role_editor);
} | [
"public",
"function",
"run",
"(",
")",
"{",
"Model",
"::",
"unguard",
"(",
")",
";",
"$",
"role_admin",
"=",
"Role",
"::",
"where",
"(",
"'name'",
",",
"'admin'",
")",
"->",
"first",
"(",
")",
";",
"$",
"role_editor",
"=",
"Role",
"::",
"where",
"(",
"'name'",
",",
"'editor'",
")",
"->",
"first",
"(",
")",
";",
"$",
"admin",
"=",
"new",
"User",
"(",
")",
";",
"$",
"admin",
"->",
"uuid",
"=",
"(",
"string",
")",
"Str",
"::",
"uuid",
"(",
")",
";",
"$",
"admin",
"->",
"name",
"=",
"'Admin'",
";",
"$",
"admin",
"->",
"email",
"=",
"'admin@example.com'",
";",
"$",
"admin",
"->",
"password",
"=",
"bcrypt",
"(",
"'Secret1'",
")",
";",
"$",
"admin",
"->",
"save",
"(",
")",
";",
"$",
"admin",
"->",
"roles",
"(",
")",
"->",
"attach",
"(",
"$",
"role_admin",
")",
";",
"$",
"editor",
"=",
"new",
"User",
"(",
")",
";",
"$",
"editor",
"->",
"uuid",
"=",
"(",
"string",
")",
"Str",
"::",
"uuid",
"(",
")",
";",
"$",
"editor",
"->",
"name",
"=",
"'Editor'",
";",
"$",
"editor",
"->",
"email",
"=",
"'editor@example.com'",
";",
"$",
"editor",
"->",
"password",
"=",
"bcrypt",
"(",
"'Secret1'",
")",
";",
"$",
"editor",
"->",
"save",
"(",
")",
";",
"$",
"editor",
"->",
"roles",
"(",
")",
"->",
"attach",
"(",
"$",
"role_editor",
")",
";",
"}"
] | Run the database seeds.
@return void | [
"Run",
"the",
"database",
"seeds",
"."
] | train | https://github.com/frostnode/frostnode-cms/blob/486db24bb8ebd73dcc1ef71f79509817d23fbf45/modules/User/Database/Seeders/UserDatabaseSeeder.php#L18-L40 |
deasilworks/cef | src/CEF.php | CEF.dependencyDefs | private function dependencyDefs()
{
return [
Logger::class => function () {
$level = $this->getCfgValue('deasilworks.log.level', 10);
$gelfHandler = new GelfHandler(
new Publisher(
new UdpTransport(
$this->getCfgValue('deasilworks.log.host', '4klift-graylog'),
$this->getCfgValue('deasilworks.log.port', 12201)
)
),
$level
);
$nullHandler = new NullHandler($level);
$logger = new Logger($this->getCfgValue('deasilworks.log.name', '4klift'));
$wfgh = new WhatFailureGroupHandler([
$gelfHandler,
$nullHandler,
]);
$logger->pushHandler($wfgh);
return $logger;
},
CFG::class => function () {
return $this->config->getCfg();
},
];
} | php | private function dependencyDefs()
{
return [
Logger::class => function () {
$level = $this->getCfgValue('deasilworks.log.level', 10);
$gelfHandler = new GelfHandler(
new Publisher(
new UdpTransport(
$this->getCfgValue('deasilworks.log.host', '4klift-graylog'),
$this->getCfgValue('deasilworks.log.port', 12201)
)
),
$level
);
$nullHandler = new NullHandler($level);
$logger = new Logger($this->getCfgValue('deasilworks.log.name', '4klift'));
$wfgh = new WhatFailureGroupHandler([
$gelfHandler,
$nullHandler,
]);
$logger->pushHandler($wfgh);
return $logger;
},
CFG::class => function () {
return $this->config->getCfg();
},
];
} | [
"private",
"function",
"dependencyDefs",
"(",
")",
"{",
"return",
"[",
"Logger",
"::",
"class",
"=>",
"function",
"(",
")",
"{",
"$",
"level",
"=",
"$",
"this",
"->",
"getCfgValue",
"(",
"'deasilworks.log.level'",
",",
"10",
")",
";",
"$",
"gelfHandler",
"=",
"new",
"GelfHandler",
"(",
"new",
"Publisher",
"(",
"new",
"UdpTransport",
"(",
"$",
"this",
"->",
"getCfgValue",
"(",
"'deasilworks.log.host'",
",",
"'4klift-graylog'",
")",
",",
"$",
"this",
"->",
"getCfgValue",
"(",
"'deasilworks.log.port'",
",",
"12201",
")",
")",
")",
",",
"$",
"level",
")",
";",
"$",
"nullHandler",
"=",
"new",
"NullHandler",
"(",
"$",
"level",
")",
";",
"$",
"logger",
"=",
"new",
"Logger",
"(",
"$",
"this",
"->",
"getCfgValue",
"(",
"'deasilworks.log.name'",
",",
"'4klift'",
")",
")",
";",
"$",
"wfgh",
"=",
"new",
"WhatFailureGroupHandler",
"(",
"[",
"$",
"gelfHandler",
",",
"$",
"nullHandler",
",",
"]",
")",
";",
"$",
"logger",
"->",
"pushHandler",
"(",
"$",
"wfgh",
")",
";",
"return",
"$",
"logger",
";",
"}",
",",
"CFG",
"::",
"class",
"=>",
"function",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"config",
"->",
"getCfg",
"(",
")",
";",
"}",
",",
"]",
";",
"}"
] | Dependency Definitions.
@return array | [
"Dependency",
"Definitions",
"."
] | train | https://github.com/deasilworks/cef/blob/18c65f2b123512bba2208975dc655354f57670be/src/CEF.php#L80-L113 |
deasilworks/cef | src/CEF.php | CEF.getCfgValue | public function getCfgValue($key, $default = null)
{
$value = $default;
$cfg = $this->config->getCfg();
if ($cfg) {
$value = $cfg->get($key, $default);
}
return $value;
} | php | public function getCfgValue($key, $default = null)
{
$value = $default;
$cfg = $this->config->getCfg();
if ($cfg) {
$value = $cfg->get($key, $default);
}
return $value;
} | [
"public",
"function",
"getCfgValue",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"value",
"=",
"$",
"default",
";",
"$",
"cfg",
"=",
"$",
"this",
"->",
"config",
"->",
"getCfg",
"(",
")",
";",
"if",
"(",
"$",
"cfg",
")",
"{",
"$",
"value",
"=",
"$",
"cfg",
"->",
"get",
"(",
"$",
"key",
",",
"$",
"default",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Get a value from the CFG Config if one exists,
if not return the provided default, otherwise null.
@param string $key
@param null $default
@return mixed $value | [
"Get",
"a",
"value",
"from",
"the",
"CFG",
"Config",
"if",
"one",
"exists",
"if",
"not",
"return",
"the",
"provided",
"default",
"otherwise",
"null",
"."
] | train | https://github.com/deasilworks/cef/blob/18c65f2b123512bba2208975dc655354f57670be/src/CEF.php#L124-L135 |
deasilworks/cef | src/CEF.php | CEF.classGetter | private function classGetter($className, $types)
{
if (!class_exists($className)) {
return;
}
$obj = $this->get($className);
foreach ($types as $type) {
if ($obj instanceof $type) {
return $obj;
}
}
} | php | private function classGetter($className, $types)
{
if (!class_exists($className)) {
return;
}
$obj = $this->get($className);
foreach ($types as $type) {
if ($obj instanceof $type) {
return $obj;
}
}
} | [
"private",
"function",
"classGetter",
"(",
"$",
"className",
",",
"$",
"types",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"return",
";",
"}",
"$",
"obj",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"className",
")",
";",
"foreach",
"(",
"$",
"types",
"as",
"$",
"type",
")",
"{",
"if",
"(",
"$",
"obj",
"instanceof",
"$",
"type",
")",
"{",
"return",
"$",
"obj",
";",
"}",
"}",
"}"
] | @param string $className
@param array $types
@return mixed | [
"@param",
"string",
"$className",
"@param",
"array",
"$types"
] | train | https://github.com/deasilworks/cef/blob/18c65f2b123512bba2208975dc655354f57670be/src/CEF.php#L211-L224 |
neonbug/meexo-common | src/Http/Middleware/Online.php | Online.handle | public function handle($request, Closure $next)
{
if (env('APP_ONLINE', true) === false)
{
return response()->view('offline');
}
return $next($request);
} | php | public function handle($request, Closure $next)
{
if (env('APP_ONLINE', true) === false)
{
return response()->view('offline');
}
return $next($request);
} | [
"public",
"function",
"handle",
"(",
"$",
"request",
",",
"Closure",
"$",
"next",
")",
"{",
"if",
"(",
"env",
"(",
"'APP_ONLINE'",
",",
"true",
")",
"===",
"false",
")",
"{",
"return",
"response",
"(",
")",
"->",
"view",
"(",
"'offline'",
")",
";",
"}",
"return",
"$",
"next",
"(",
"$",
"request",
")",
";",
"}"
] | Handle an incoming request.
@param \Illuminate\Http\Request $request
@param \Closure $next
@return mixed | [
"Handle",
"an",
"incoming",
"request",
"."
] | train | https://github.com/neonbug/meexo-common/blob/8fe9a5d1b73311c65a7c5a0ce8a4e859d39351c6/src/Http/Middleware/Online.php#L14-L22 |
flywheel2/io | sdf/SDFI.php | SDFI.CreateSecurePassword | public static function CreateSecurePassword ($password, $key, $algorithm = self::PASSWORD_HASH_ALGORITHM) {
return hash_hmac($algorithm, $password, $key);
} | php | public static function CreateSecurePassword ($password, $key, $algorithm = self::PASSWORD_HASH_ALGORITHM) {
return hash_hmac($algorithm, $password, $key);
} | [
"public",
"static",
"function",
"CreateSecurePassword",
"(",
"$",
"password",
",",
"$",
"key",
",",
"$",
"algorithm",
"=",
"self",
"::",
"PASSWORD_HASH_ALGORITHM",
")",
"{",
"return",
"hash_hmac",
"(",
"$",
"algorithm",
",",
"$",
"password",
",",
"$",
"key",
")",
";",
"}"
] | 安全なパスワードハッシュを構築します。
@param string $password パスワード
@param string $key キー
@param string $algorithm ハッシュアルゴリズム
@return string 安全なパスワードハッシュ | [
"安全なパスワードハッシュを構築します。"
] | train | https://github.com/flywheel2/io/blob/e022411aa42cfd24772c0bb80cddfa952946d5fb/sdf/SDFI.php#L89-L91 |
flywheel2/io | sdf/SDFI.php | SDFI.GetConnection | public static function GetConnection ($options) {
$connection_name = static::AdjustConnectionName($options);
if (!isset(static::$_connectionList[$connection_name])) {
static::_Connect($options);
}
return static::$_connectionList[$connection_name];
} | php | public static function GetConnection ($options) {
$connection_name = static::AdjustConnectionName($options);
if (!isset(static::$_connectionList[$connection_name])) {
static::_Connect($options);
}
return static::$_connectionList[$connection_name];
} | [
"public",
"static",
"function",
"GetConnection",
"(",
"$",
"options",
")",
"{",
"$",
"connection_name",
"=",
"static",
"::",
"AdjustConnectionName",
"(",
"$",
"options",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
"$",
"_connectionList",
"[",
"$",
"connection_name",
"]",
")",
")",
"{",
"static",
"::",
"_Connect",
"(",
"$",
"options",
")",
";",
"}",
"return",
"static",
"::",
"$",
"_connectionList",
"[",
"$",
"connection_name",
"]",
";",
"}"
] | コネクションを取得します。
@param array $options オプション
@return ¥PDO PDOインスタンス | [
"コネクションを取得します。"
] | train | https://github.com/flywheel2/io/blob/e022411aa42cfd24772c0bb80cddfa952946d5fb/sdf/SDFI.php#L167-L174 |
flywheel2/io | sdf/SDFI.php | SDFI._Connect | protected static function _Connect ($options) {
$connection_name = static::AdjustConnectionName($options);
if (!isset(static::$_dsnList[$connection_name])) {
throw CoreException::RaiseSystemError('未定義のファイル設定を用いて接続しようとしています。connection_name:%s', [$connection_name]);
}
$dsn = static::$_dsnList[$connection_name];
$driver_class_name = sprintf('%s\drivers\%s%s', __NAMESPACE__, Strings::ToUpperCamelCase($dsn['driver']), static::DRIVER_CLASS_NAME_SAFIX);
static::$_connectionList[$connection_name] = $driver_class_name::Connect($dsn);
} | php | protected static function _Connect ($options) {
$connection_name = static::AdjustConnectionName($options);
if (!isset(static::$_dsnList[$connection_name])) {
throw CoreException::RaiseSystemError('未定義のファイル設定を用いて接続しようとしています。connection_name:%s', [$connection_name]);
}
$dsn = static::$_dsnList[$connection_name];
$driver_class_name = sprintf('%s\drivers\%s%s', __NAMESPACE__, Strings::ToUpperCamelCase($dsn['driver']), static::DRIVER_CLASS_NAME_SAFIX);
static::$_connectionList[$connection_name] = $driver_class_name::Connect($dsn);
} | [
"protected",
"static",
"function",
"_Connect",
"(",
"$",
"options",
")",
"{",
"$",
"connection_name",
"=",
"static",
"::",
"AdjustConnectionName",
"(",
"$",
"options",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
"$",
"_dsnList",
"[",
"$",
"connection_name",
"]",
")",
")",
"{",
"throw",
"CoreException",
"::",
"RaiseSystemError",
"(",
"'未定義のファイル設定を用いて接続しようとしています。connection_name:%s', [$connection_name]);",
"",
"",
"",
"",
"",
"",
"",
"}",
"$",
"dsn",
"=",
"static",
"::",
"$",
"_dsnList",
"[",
"$",
"connection_name",
"]",
";",
"$",
"driver_class_name",
"=",
"sprintf",
"(",
"'%s\\drivers\\%s%s'",
",",
"__NAMESPACE__",
",",
"Strings",
"::",
"ToUpperCamelCase",
"(",
"$",
"dsn",
"[",
"'driver'",
"]",
")",
",",
"static",
"::",
"DRIVER_CLASS_NAME_SAFIX",
")",
";",
"static",
"::",
"$",
"_connectionList",
"[",
"$",
"connection_name",
"]",
"=",
"$",
"driver_class_name",
"::",
"Connect",
"(",
"$",
"dsn",
")",
";",
"}"
] | コネクションを確立します。
@param array $options オプション
@return ¥PDO PDOインスタンス | [
"コネクションを確立します。"
] | train | https://github.com/flywheel2/io/blob/e022411aa42cfd24772c0bb80cddfa952946d5fb/sdf/SDFI.php#L182-L192 |
aedart/model | src/Traits/Strings/BuildingNumberTrait.php | BuildingNumberTrait.getBuildingNumber | public function getBuildingNumber() : ?string
{
if ( ! $this->hasBuildingNumber()) {
$this->setBuildingNumber($this->getDefaultBuildingNumber());
}
return $this->buildingNumber;
} | php | public function getBuildingNumber() : ?string
{
if ( ! $this->hasBuildingNumber()) {
$this->setBuildingNumber($this->getDefaultBuildingNumber());
}
return $this->buildingNumber;
} | [
"public",
"function",
"getBuildingNumber",
"(",
")",
":",
"?",
"string",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasBuildingNumber",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setBuildingNumber",
"(",
"$",
"this",
"->",
"getDefaultBuildingNumber",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"buildingNumber",
";",
"}"
] | Get building number
If no "building number" value has been set, this method will
set and return a default "building number" value,
if any such value is available
@see getDefaultBuildingNumber()
@return string|null building number or null if no building number has been set | [
"Get",
"building",
"number"
] | train | https://github.com/aedart/model/blob/9a562c1c53a276d01ace0ab71f5305458bea542f/src/Traits/Strings/BuildingNumberTrait.php#L48-L54 |
fabsgc/framework | Core/Controller/Injector/Form.php | Form.get | public static function get($object) {
/** @var \Gcs\Framework\Core\Http\Request\Form $class */
$class = $object->name;
$class = new $class();
$class->init();
$request = Request::instance();
if (($class->getForm() == '' && $request->data->form == true) || isset($request->data->post[$class->getForm()])) {
switch ($request->data->method) {
case 'get' :
$class->get();
break;
case 'post' :
$class->post();
break;
case 'put' :
$class->put();
break;
case 'patch' :
$class->patch();
break;
case 'delete' :
$class->delete();
break;
}
$class->check();
}
return $class;
} | php | public static function get($object) {
/** @var \Gcs\Framework\Core\Http\Request\Form $class */
$class = $object->name;
$class = new $class();
$class->init();
$request = Request::instance();
if (($class->getForm() == '' && $request->data->form == true) || isset($request->data->post[$class->getForm()])) {
switch ($request->data->method) {
case 'get' :
$class->get();
break;
case 'post' :
$class->post();
break;
case 'put' :
$class->put();
break;
case 'patch' :
$class->patch();
break;
case 'delete' :
$class->delete();
break;
}
$class->check();
}
return $class;
} | [
"public",
"static",
"function",
"get",
"(",
"$",
"object",
")",
"{",
"/** @var \\Gcs\\Framework\\Core\\Http\\Request\\Form $class */",
"$",
"class",
"=",
"$",
"object",
"->",
"name",
";",
"$",
"class",
"=",
"new",
"$",
"class",
"(",
")",
";",
"$",
"class",
"->",
"init",
"(",
")",
";",
"$",
"request",
"=",
"Request",
"::",
"instance",
"(",
")",
";",
"if",
"(",
"(",
"$",
"class",
"->",
"getForm",
"(",
")",
"==",
"''",
"&&",
"$",
"request",
"->",
"data",
"->",
"form",
"==",
"true",
")",
"||",
"isset",
"(",
"$",
"request",
"->",
"data",
"->",
"post",
"[",
"$",
"class",
"->",
"getForm",
"(",
")",
"]",
")",
")",
"{",
"switch",
"(",
"$",
"request",
"->",
"data",
"->",
"method",
")",
"{",
"case",
"'get'",
":",
"$",
"class",
"->",
"get",
"(",
")",
";",
"break",
";",
"case",
"'post'",
":",
"$",
"class",
"->",
"post",
"(",
")",
";",
"break",
";",
"case",
"'put'",
":",
"$",
"class",
"->",
"put",
"(",
")",
";",
"break",
";",
"case",
"'patch'",
":",
"$",
"class",
"->",
"patch",
"(",
")",
";",
"break",
";",
"case",
"'delete'",
":",
"$",
"class",
"->",
"delete",
"(",
")",
";",
"break",
";",
"}",
"$",
"class",
"->",
"check",
"(",
")",
";",
"}",
"return",
"$",
"class",
";",
"}"
] | Return a fully completed Request Object
@access public
@param \ReflectionClass $object
@return \Gcs\Framework\Core\Http\Request\Form
@since 3.0
@package Gcs\Framework\Core\Controller\Injector | [
"Return",
"a",
"fully",
"completed",
"Request",
"Object"
] | train | https://github.com/fabsgc/framework/blob/45e58182aba6a3c6381970a1fd3c17662cff2168/Core/Controller/Injector/Form.php#L57-L92 |
City-of-Mikkeli/kunta-api-php-client | lib/Api/BannersApi.php | BannersApi.findOrganizationBanner | public function findOrganizationBanner($organizationId, $bannerId)
{
list($response) = $this->findOrganizationBannerWithHttpInfo($organizationId, $bannerId);
return $response;
} | php | public function findOrganizationBanner($organizationId, $bannerId)
{
list($response) = $this->findOrganizationBannerWithHttpInfo($organizationId, $bannerId);
return $response;
} | [
"public",
"function",
"findOrganizationBanner",
"(",
"$",
"organizationId",
",",
"$",
"bannerId",
")",
"{",
"list",
"(",
"$",
"response",
")",
"=",
"$",
"this",
"->",
"findOrganizationBannerWithHttpInfo",
"(",
"$",
"organizationId",
",",
"$",
"bannerId",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Operation findOrganizationBanner
Finds organizations banner
@param string $organizationId Organization id (required)
@param string $bannerId banner id (required)
@return \KuntaAPI\Model\NewsArticle
@throws \KuntaAPI\ApiException on non-2xx response | [
"Operation",
"findOrganizationBanner"
] | train | https://github.com/City-of-Mikkeli/kunta-api-php-client/blob/e7f05f5e2c27d3b367cf6261df4ef74b9531da94/lib/Api/BannersApi.php#L115-L119 |
City-of-Mikkeli/kunta-api-php-client | lib/Api/BannersApi.php | BannersApi.listOrganizationBannerImages | public function listOrganizationBannerImages($organizationId, $bannerId)
{
list($response) = $this->listOrganizationBannerImagesWithHttpInfo($organizationId, $bannerId);
return $response;
} | php | public function listOrganizationBannerImages($organizationId, $bannerId)
{
list($response) = $this->listOrganizationBannerImagesWithHttpInfo($organizationId, $bannerId);
return $response;
} | [
"public",
"function",
"listOrganizationBannerImages",
"(",
"$",
"organizationId",
",",
"$",
"bannerId",
")",
"{",
"list",
"(",
"$",
"response",
")",
"=",
"$",
"this",
"->",
"listOrganizationBannerImagesWithHttpInfo",
"(",
"$",
"organizationId",
",",
"$",
"bannerId",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Operation listOrganizationBannerImages
Returns a list of organization banner images
@param string $organizationId Organization id (required)
@param string $bannerId Banner id (required)
@return \KuntaAPI\Model\Attachment[]
@throws \KuntaAPI\ApiException on non-2xx response | [
"Operation",
"listOrganizationBannerImages"
] | train | https://github.com/City-of-Mikkeli/kunta-api-php-client/blob/e7f05f5e2c27d3b367cf6261df4ef74b9531da94/lib/Api/BannersApi.php#L226-L230 |
atelierspierrot/library | src/Library/Command.php | Command.run | public function run($command, $path = null, $force = false)
{
if (true!==$force && $this->isCached($command, $path)) {
$cached = $this->getCached($command, $path);
return array($cached['result'], $cached['status'], $cached['error']);
}
return $this->runCommand($command, $path);
} | php | public function run($command, $path = null, $force = false)
{
if (true!==$force && $this->isCached($command, $path)) {
$cached = $this->getCached($command, $path);
return array($cached['result'], $cached['status'], $cached['error']);
}
return $this->runCommand($command, $path);
} | [
"public",
"function",
"run",
"(",
"$",
"command",
",",
"$",
"path",
"=",
"null",
",",
"$",
"force",
"=",
"false",
")",
"{",
"if",
"(",
"true",
"!==",
"$",
"force",
"&&",
"$",
"this",
"->",
"isCached",
"(",
"$",
"command",
",",
"$",
"path",
")",
")",
"{",
"$",
"cached",
"=",
"$",
"this",
"->",
"getCached",
"(",
"$",
"command",
",",
"$",
"path",
")",
";",
"return",
"array",
"(",
"$",
"cached",
"[",
"'result'",
"]",
",",
"$",
"cached",
"[",
"'status'",
"]",
",",
"$",
"cached",
"[",
"'error'",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"runCommand",
"(",
"$",
"command",
",",
"$",
"path",
")",
";",
"}"
] | Run a command on a Linux/UNIX system reading it from cache if so
@param string $command The command to run
@param string $path The path to go to
@param bool $force Force the command to really run (avoid caching)
@return array An array like ( stdout , status , stderr ) | [
"Run",
"a",
"command",
"on",
"a",
"Linux",
"/",
"UNIX",
"system",
"reading",
"it",
"from",
"cache",
"if",
"so"
] | train | https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/Command.php#L92-L99 |
atelierspierrot/library | src/Library/Command.php | Command.runCommand | public function runCommand($command, $path = null)
{
$descriptorspec = array(
1 => array('pipe', 'w'),
2 => array('pipe', 'a'),
);
$pipes = array();
$resource = proc_open($command, $descriptorspec, $pipes, $path);
$stdout = stream_get_contents($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
foreach ($pipes as $pipe) {
fclose($pipe);
}
$status = trim(proc_close($resource));
$stdout = rtrim($stdout, PHP_EOL);
$this->addCache($command, $stdout, $stderr, $status, $path);
return array( $stdout, $status, $stderr );
} | php | public function runCommand($command, $path = null)
{
$descriptorspec = array(
1 => array('pipe', 'w'),
2 => array('pipe', 'a'),
);
$pipes = array();
$resource = proc_open($command, $descriptorspec, $pipes, $path);
$stdout = stream_get_contents($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
foreach ($pipes as $pipe) {
fclose($pipe);
}
$status = trim(proc_close($resource));
$stdout = rtrim($stdout, PHP_EOL);
$this->addCache($command, $stdout, $stderr, $status, $path);
return array( $stdout, $status, $stderr );
} | [
"public",
"function",
"runCommand",
"(",
"$",
"command",
",",
"$",
"path",
"=",
"null",
")",
"{",
"$",
"descriptorspec",
"=",
"array",
"(",
"1",
"=>",
"array",
"(",
"'pipe'",
",",
"'w'",
")",
",",
"2",
"=>",
"array",
"(",
"'pipe'",
",",
"'a'",
")",
",",
")",
";",
"$",
"pipes",
"=",
"array",
"(",
")",
";",
"$",
"resource",
"=",
"proc_open",
"(",
"$",
"command",
",",
"$",
"descriptorspec",
",",
"$",
"pipes",
",",
"$",
"path",
")",
";",
"$",
"stdout",
"=",
"stream_get_contents",
"(",
"$",
"pipes",
"[",
"1",
"]",
")",
";",
"$",
"stderr",
"=",
"stream_get_contents",
"(",
"$",
"pipes",
"[",
"2",
"]",
")",
";",
"foreach",
"(",
"$",
"pipes",
"as",
"$",
"pipe",
")",
"{",
"fclose",
"(",
"$",
"pipe",
")",
";",
"}",
"$",
"status",
"=",
"trim",
"(",
"proc_close",
"(",
"$",
"resource",
")",
")",
";",
"$",
"stdout",
"=",
"rtrim",
"(",
"$",
"stdout",
",",
"PHP_EOL",
")",
";",
"$",
"this",
"->",
"addCache",
"(",
"$",
"command",
",",
"$",
"stdout",
",",
"$",
"stderr",
",",
"$",
"status",
",",
"$",
"path",
")",
";",
"return",
"array",
"(",
"$",
"stdout",
",",
"$",
"status",
",",
"$",
"stderr",
")",
";",
"}"
] | Run a command on a Linux/UNIX system
Accepts a shell command to run
@param string $command The command to run
@param string $path The path to go to
@return array An array like ( stdout , status , stderr ) | [
"Run",
"a",
"command",
"on",
"a",
"Linux",
"/",
"UNIX",
"system"
] | train | https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/Command.php#L110-L129 |
atelierspierrot/library | src/Library/Command.php | Command.getCommandPath | public static function getCommandPath($cmd)
{
$os_cmd = exec('which '.$cmd);
if (empty($os_cmd)) {
throw new CommandNotFoundException($cmd);
}
return $os_cmd;
} | php | public static function getCommandPath($cmd)
{
$os_cmd = exec('which '.$cmd);
if (empty($os_cmd)) {
throw new CommandNotFoundException($cmd);
}
return $os_cmd;
} | [
"public",
"static",
"function",
"getCommandPath",
"(",
"$",
"cmd",
")",
"{",
"$",
"os_cmd",
"=",
"exec",
"(",
"'which '",
".",
"$",
"cmd",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"os_cmd",
")",
")",
"{",
"throw",
"new",
"CommandNotFoundException",
"(",
"$",
"cmd",
")",
";",
"}",
"return",
"$",
"os_cmd",
";",
"}"
] | Get the system path of a command
@param string $cmd The command name to retrieve
@return string The realpath of the command in the system
@throws \Library\CommandNotFoundException if the command doesn't exist | [
"Get",
"the",
"system",
"path",
"of",
"a",
"command"
] | train | https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/Command.php#L138-L145 |
x2ts/model-init | src/ModelInit.php | ModelInit.createModelClass | private function createModelClass($tableName, $dbId, $namespace) {
/** @var MySQLTableSchema $tableSchema */
$tableSchema = X::getInstance(
MySQLTableSchema::class,
[$tableName, X::$dbId()],
[],
Toolkit::randomChars(10)
);
$phpDoc = $this->createDocComment($tableSchema);
$namespacePath = str_replace('\\', DIRECTORY_SEPARATOR, $namespace);
$modelName = Toolkit::toCamelCase($tableSchema->name, true);
$modelFile = X_PROJECT_ROOT . "/protected/{$namespacePath}/{$modelName}.php";
if (is_readable($modelFile)) {
$phpCode = file_get_contents($modelFile);
$newPhpCode = preg_replace_callback(
'#(/\*\*[^/]*\*/)(\s+class\s+)#m',
function ($m) use ($phpDoc) {
return $phpDoc . $m[2];
},
$phpCode
);
} else {
$date = date('Y/m/d');
$time = date('H:i:s');
$newPhpCode = <<<PHP
<?php
/**
* Created by x2ts model generator.
* Date: {$date}
* Time: {$time}
*/
namespace {$namespace};
use x2ts\db\orm\Model;
{$phpDoc}
class {$modelName} extends Model {}
PHP;
}
$dir = dirname($modelFile);
if (!@mkdir($dir, 0755, true) !== false && !is_dir($dir)) {
throw new Exception('Cannot create directory');
}
file_put_contents($modelFile, $newPhpCode);
} | php | private function createModelClass($tableName, $dbId, $namespace) {
/** @var MySQLTableSchema $tableSchema */
$tableSchema = X::getInstance(
MySQLTableSchema::class,
[$tableName, X::$dbId()],
[],
Toolkit::randomChars(10)
);
$phpDoc = $this->createDocComment($tableSchema);
$namespacePath = str_replace('\\', DIRECTORY_SEPARATOR, $namespace);
$modelName = Toolkit::toCamelCase($tableSchema->name, true);
$modelFile = X_PROJECT_ROOT . "/protected/{$namespacePath}/{$modelName}.php";
if (is_readable($modelFile)) {
$phpCode = file_get_contents($modelFile);
$newPhpCode = preg_replace_callback(
'#(/\*\*[^/]*\*/)(\s+class\s+)#m',
function ($m) use ($phpDoc) {
return $phpDoc . $m[2];
},
$phpCode
);
} else {
$date = date('Y/m/d');
$time = date('H:i:s');
$newPhpCode = <<<PHP
<?php
/**
* Created by x2ts model generator.
* Date: {$date}
* Time: {$time}
*/
namespace {$namespace};
use x2ts\db\orm\Model;
{$phpDoc}
class {$modelName} extends Model {}
PHP;
}
$dir = dirname($modelFile);
if (!@mkdir($dir, 0755, true) !== false && !is_dir($dir)) {
throw new Exception('Cannot create directory');
}
file_put_contents($modelFile, $newPhpCode);
} | [
"private",
"function",
"createModelClass",
"(",
"$",
"tableName",
",",
"$",
"dbId",
",",
"$",
"namespace",
")",
"{",
"/** @var MySQLTableSchema $tableSchema */",
"$",
"tableSchema",
"=",
"X",
"::",
"getInstance",
"(",
"MySQLTableSchema",
"::",
"class",
",",
"[",
"$",
"tableName",
",",
"X",
"::",
"$",
"dbId",
"(",
")",
"]",
",",
"[",
"]",
",",
"Toolkit",
"::",
"randomChars",
"(",
"10",
")",
")",
";",
"$",
"phpDoc",
"=",
"$",
"this",
"->",
"createDocComment",
"(",
"$",
"tableSchema",
")",
";",
"$",
"namespacePath",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"DIRECTORY_SEPARATOR",
",",
"$",
"namespace",
")",
";",
"$",
"modelName",
"=",
"Toolkit",
"::",
"toCamelCase",
"(",
"$",
"tableSchema",
"->",
"name",
",",
"true",
")",
";",
"$",
"modelFile",
"=",
"X_PROJECT_ROOT",
".",
"\"/protected/{$namespacePath}/{$modelName}.php\"",
";",
"if",
"(",
"is_readable",
"(",
"$",
"modelFile",
")",
")",
"{",
"$",
"phpCode",
"=",
"file_get_contents",
"(",
"$",
"modelFile",
")",
";",
"$",
"newPhpCode",
"=",
"preg_replace_callback",
"(",
"'#(/\\*\\*[^/]*\\*/)(\\s+class\\s+)#m'",
",",
"function",
"(",
"$",
"m",
")",
"use",
"(",
"$",
"phpDoc",
")",
"{",
"return",
"$",
"phpDoc",
".",
"$",
"m",
"[",
"2",
"]",
";",
"}",
",",
"$",
"phpCode",
")",
";",
"}",
"else",
"{",
"$",
"date",
"=",
"date",
"(",
"'Y/m/d'",
")",
";",
"$",
"time",
"=",
"date",
"(",
"'H:i:s'",
")",
";",
"$",
"newPhpCode",
"=",
" <<<PHP\n<?php\n/**\n * Created by x2ts model generator.\n * Date: {$date}\n * Time: {$time}\n */\n\nnamespace {$namespace};\n\n\nuse x2ts\\db\\orm\\Model;\n\n{$phpDoc}\nclass {$modelName} extends Model {}\nPHP",
";",
"}",
"$",
"dir",
"=",
"dirname",
"(",
"$",
"modelFile",
")",
";",
"if",
"(",
"!",
"@",
"mkdir",
"(",
"$",
"dir",
",",
"0755",
",",
"true",
")",
"!==",
"false",
"&&",
"!",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Cannot create directory'",
")",
";",
"}",
"file_put_contents",
"(",
"$",
"modelFile",
",",
"$",
"newPhpCode",
")",
";",
"}"
] | @param $tableName
@param $dbId
@param $namespace
@throws Exception | [
"@param",
"$tableName",
"@param",
"$dbId",
"@param",
"$namespace"
] | train | https://github.com/x2ts/model-init/blob/144f718186ab0d5e34b0fbf9d19e76d0be736e19/src/ModelInit.php#L73-L120 |
phpservicebus/core | src/Transport/ReceivingFeature.php | ReceivingFeature.setup | public function setup(Settings $settings, BuilderInterface $builder, PipelineModifications $pipelineModifications)
{
/** @var QueueBindings $queueBindings */
$queueBindings = $settings->get(QueueBindings::class);
$queueBindings->bindReceiving($settings->get(KnownSettingsEnum::LOCAL_ADDRESS));
/** @var InboundTransport $inboundTransport */
$inboundTransport = $settings->get(InboundTransport::class);
$receiveInfrastructure = $inboundTransport->configure($settings);
$builder->defineSingleton(MessagePusherInterface::class, $receiveInfrastructure->getMessagePusherFactory());
$builder->defineSingleton(QueueCreatorInterface::class, $receiveInfrastructure->getQueueCreatorFactory());
$this->registerInstallTask(
function () use ($builder, $settings) {
return new QueueCreatorFeatureInstallTask($builder->build(QueueCreatorInterface::class), $settings);
}
);
} | php | public function setup(Settings $settings, BuilderInterface $builder, PipelineModifications $pipelineModifications)
{
/** @var QueueBindings $queueBindings */
$queueBindings = $settings->get(QueueBindings::class);
$queueBindings->bindReceiving($settings->get(KnownSettingsEnum::LOCAL_ADDRESS));
/** @var InboundTransport $inboundTransport */
$inboundTransport = $settings->get(InboundTransport::class);
$receiveInfrastructure = $inboundTransport->configure($settings);
$builder->defineSingleton(MessagePusherInterface::class, $receiveInfrastructure->getMessagePusherFactory());
$builder->defineSingleton(QueueCreatorInterface::class, $receiveInfrastructure->getQueueCreatorFactory());
$this->registerInstallTask(
function () use ($builder, $settings) {
return new QueueCreatorFeatureInstallTask($builder->build(QueueCreatorInterface::class), $settings);
}
);
} | [
"public",
"function",
"setup",
"(",
"Settings",
"$",
"settings",
",",
"BuilderInterface",
"$",
"builder",
",",
"PipelineModifications",
"$",
"pipelineModifications",
")",
"{",
"/** @var QueueBindings $queueBindings */",
"$",
"queueBindings",
"=",
"$",
"settings",
"->",
"get",
"(",
"QueueBindings",
"::",
"class",
")",
";",
"$",
"queueBindings",
"->",
"bindReceiving",
"(",
"$",
"settings",
"->",
"get",
"(",
"KnownSettingsEnum",
"::",
"LOCAL_ADDRESS",
")",
")",
";",
"/** @var InboundTransport $inboundTransport */",
"$",
"inboundTransport",
"=",
"$",
"settings",
"->",
"get",
"(",
"InboundTransport",
"::",
"class",
")",
";",
"$",
"receiveInfrastructure",
"=",
"$",
"inboundTransport",
"->",
"configure",
"(",
"$",
"settings",
")",
";",
"$",
"builder",
"->",
"defineSingleton",
"(",
"MessagePusherInterface",
"::",
"class",
",",
"$",
"receiveInfrastructure",
"->",
"getMessagePusherFactory",
"(",
")",
")",
";",
"$",
"builder",
"->",
"defineSingleton",
"(",
"QueueCreatorInterface",
"::",
"class",
",",
"$",
"receiveInfrastructure",
"->",
"getQueueCreatorFactory",
"(",
")",
")",
";",
"$",
"this",
"->",
"registerInstallTask",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"builder",
",",
"$",
"settings",
")",
"{",
"return",
"new",
"QueueCreatorFeatureInstallTask",
"(",
"$",
"builder",
"->",
"build",
"(",
"QueueCreatorInterface",
"::",
"class",
")",
",",
"$",
"settings",
")",
";",
"}",
")",
";",
"}"
] | Method is called if all defined conditions are met and the feature is marked as enabled.
Use this method to configure and initialize all required components for the feature like
the steps in the pipeline or the instances/factories in the container.
@param Settings $settings
@param BuilderInterface $builder
@param PipelineModifications $pipelineModifications | [
"Method",
"is",
"called",
"if",
"all",
"defined",
"conditions",
"are",
"met",
"and",
"the",
"feature",
"is",
"marked",
"as",
"enabled",
".",
"Use",
"this",
"method",
"to",
"configure",
"and",
"initialize",
"all",
"required",
"components",
"for",
"the",
"feature",
"like",
"the",
"steps",
"in",
"the",
"pipeline",
"or",
"the",
"instances",
"/",
"factories",
"in",
"the",
"container",
"."
] | train | https://github.com/phpservicebus/core/blob/adbcf94be1e022120ede0c5aafa8a4f7900b0a6c/src/Transport/ReceivingFeature.php#L39-L57 |
hash-bang/Joyst | Joyst_Controller.php | Joyst_Controller.RequesterWants | function RequesterWants($type) {
switch ($type) {
case 'html':
return !$this->Want('json');
case 'json':
if (isset($_GET['json'])) {
if ($_GET['json'] == 'nice' && version_compare(PHP_VERSION, '5.4.0') >= 0)
$this->JSONOptions = JSON_PRETTY_PRINT;
return TRUE;
}
if (
isset($_SERVER['HTTP_ACCEPT']) &&
preg_match('!application/json!', $_SERVER['HTTP_ACCEPT'])
)
return TRUE;
return FALSE;
case 'put-json': // Being passed IN a JSON blob (also converts incomming JSON into $_POST variables)
if (!$this->RequesterWants('json')) // Not wanting JSON
return FALSE;
$in = file_get_contents('php://input');
if (!$in) // Nothing in raw POST
return FALSE;
$json = json_decode($in, true);
if ($json === null) // Not JSON
return FALSE;
$_POST = $json;
return TRUE;
default:
trigger_error("Unknown want type: '$type'");
}
} | php | function RequesterWants($type) {
switch ($type) {
case 'html':
return !$this->Want('json');
case 'json':
if (isset($_GET['json'])) {
if ($_GET['json'] == 'nice' && version_compare(PHP_VERSION, '5.4.0') >= 0)
$this->JSONOptions = JSON_PRETTY_PRINT;
return TRUE;
}
if (
isset($_SERVER['HTTP_ACCEPT']) &&
preg_match('!application/json!', $_SERVER['HTTP_ACCEPT'])
)
return TRUE;
return FALSE;
case 'put-json': // Being passed IN a JSON blob (also converts incomming JSON into $_POST variables)
if (!$this->RequesterWants('json')) // Not wanting JSON
return FALSE;
$in = file_get_contents('php://input');
if (!$in) // Nothing in raw POST
return FALSE;
$json = json_decode($in, true);
if ($json === null) // Not JSON
return FALSE;
$_POST = $json;
return TRUE;
default:
trigger_error("Unknown want type: '$type'");
}
} | [
"function",
"RequesterWants",
"(",
"$",
"type",
")",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'html'",
":",
"return",
"!",
"$",
"this",
"->",
"Want",
"(",
"'json'",
")",
";",
"case",
"'json'",
":",
"if",
"(",
"isset",
"(",
"$",
"_GET",
"[",
"'json'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"_GET",
"[",
"'json'",
"]",
"==",
"'nice'",
"&&",
"version_compare",
"(",
"PHP_VERSION",
",",
"'5.4.0'",
")",
">=",
"0",
")",
"$",
"this",
"->",
"JSONOptions",
"=",
"JSON_PRETTY_PRINT",
";",
"return",
"TRUE",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT'",
"]",
")",
"&&",
"preg_match",
"(",
"'!application/json!'",
",",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT'",
"]",
")",
")",
"return",
"TRUE",
";",
"return",
"FALSE",
";",
"case",
"'put-json'",
":",
"// Being passed IN a JSON blob (also converts incomming JSON into $_POST variables)",
"if",
"(",
"!",
"$",
"this",
"->",
"RequesterWants",
"(",
"'json'",
")",
")",
"// Not wanting JSON",
"return",
"FALSE",
";",
"$",
"in",
"=",
"file_get_contents",
"(",
"'php://input'",
")",
";",
"if",
"(",
"!",
"$",
"in",
")",
"// Nothing in raw POST",
"return",
"FALSE",
";",
"$",
"json",
"=",
"json_decode",
"(",
"$",
"in",
",",
"true",
")",
";",
"if",
"(",
"$",
"json",
"===",
"null",
")",
"// Not JSON",
"return",
"FALSE",
";",
"$",
"_POST",
"=",
"$",
"json",
";",
"return",
"TRUE",
";",
"default",
":",
"trigger_error",
"(",
"\"Unknown want type: '$type'\"",
")",
";",
"}",
"}"
] | Convenience wrapper to return if the client is asking for some specific type of output
There is a special _GET variable called 'json' which if set forces JSON mode. If set to 'nice' this can also pretty print on JSON() calls
@param $type A type which corresponds to a known data type e.g. 'html', 'json'
@return bool True if the client is asking for that given data type | [
"Convenience",
"wrapper",
"to",
"return",
"if",
"the",
"client",
"is",
"asking",
"for",
"some",
"specific",
"type",
"of",
"output",
"There",
"is",
"a",
"special",
"_GET",
"variable",
"called",
"json",
"which",
"if",
"set",
"forces",
"JSON",
"mode",
".",
"If",
"set",
"to",
"nice",
"this",
"can",
"also",
"pretty",
"print",
"on",
"JSON",
"()",
"calls"
] | train | https://github.com/hash-bang/Joyst/blob/f8bcf396120884c5c77e3e8f016b8472e2cc2fb0/Joyst_Controller.php#L69-L99 |
hash-bang/Joyst | Joyst_Controller.php | Joyst_Controller.JoystModel | function JoystModel($model, $routes = null) {
$gotJSON = FALSE; // Are we being passed a JSON object?
if (!$this->RequesterWants('json')) // Not wanting JSON - fall though to regular controller which should handle base HTML requests
return;
// Process incomming raw JSON {{{
$in = file_get_contents('php://input');
if ($in) { // Something in raw POST
$json = json_decode($in, true);
if ($json !== null) { // Looks like JSON
$_POST = $json;
$gotJSON = TRUE;
}
}
// }}}
if (!$routes)
$routes = $this->defaultRoutes;
$segments = $this->uri->segments;
array_shift($segments); // Shift first segment - assuming its the controller name
$segment = $segments ? array_shift($segments) : ''; // Retrieve argument if any
// Determine the route to use
foreach ($routes as $routeKey => $dest) {
$route = $routeKey;
if (preg_match('!^(.*)\[(.+?)\](.*)$!', $route, $matches)) { // Has a method in the form '[SOMETHING]'
$blockMatch = false; // Continue executing (set to false to stop)
foreach (preg_split('/\s*,\s*/', $matches[2]) as $block) { // Split CSV into bits
switch ($block) {
// Incomming HTTP methods
case 'GET':
case 'PUT':
case 'DELETE':
case 'POST':
if ($_SERVER['REQUEST_METHOD'] == $block) // Found route method does not match this one
$blockMatch = true;
break;
case 'JSON':
if ($gotJSON)
$blockMatch = true;
break;
default:
die("Joyst_Controller> Unsupported route query type: $block");
}
}
if (!$blockMatch)
continue;
$route = "{$matches[1]}{$matches[3]}"; // Delete from route and continue
}
switch ($route) {
case '':
if (!$segment) {
$matchingRoute = $routeKey;
break 2;
}
break;
case ':num':
if (is_numeric($segment)) {
$matchingRoute = $routeKey;
array_unshift($segments, $segment); // Put the segment back
break 2;
}
break;
default:
if ($segment == $route) {
$matchingRoute = $routeKey;
break 2;
}
}
}
if (!isset($matchingRoute)) // Didn't find anything matching in routes
return;
$rawfunc = $routes[$matchingRoute];
// Extract any additional parameters
$params = array_merge($_POST, $_GET);
if (!preg_match('/^(.+?)\((.*)\)$/', $rawfunc, $matches))
die('Joyst_Controller: Invalid routing function format. Should be in the format func(), func(a), func(*), func(1) or similar. Given: ' . $func);
$func = $matches[1];
// Determine the arguments to be passed to the routing function {{{
$args = array();
foreach (explode(',', $matches[2]) as $arg)
switch ($arg) {
case '#':
$args[] = $params;
break;
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if (!$segments)
$this->JSONError('Invalid URL format');
$args[] = $segments[$arg-1];
break;
case '*':
$args = $segments;
$segments = array();
break;
}
// }}}
// Call function {{{
// Check the model is loaded and call the function
$this->load->model($model);
if (!is_subclass_of($this->$model, 'Joyst_Model'))
die("Use of \$this->JoystModel('$model') on a model that does not extend Joyst_Model");
$this->$model->source = 'controller'; // Tell the model how its been invoked
// echo "Call \$this->$model->$func(" . json_encode($args) . ")<br/>";
$this->$model->returnRow = $this->returnRow; // Carry returnRow over into the Model
$return = call_user_func_array(array($this->$model, $func), $args);
// }}}
// Return output {{{
if (!$this->$model->continue) {
header('HTTP/1.1 400 Bad Request', true, 400);
header('X-Error: ' . $this->$model->_EscapeHeader($this->$model->joystError));
die();
} else {
$this->JSON($return);
}
// }}}
} | php | function JoystModel($model, $routes = null) {
$gotJSON = FALSE; // Are we being passed a JSON object?
if (!$this->RequesterWants('json')) // Not wanting JSON - fall though to regular controller which should handle base HTML requests
return;
// Process incomming raw JSON {{{
$in = file_get_contents('php://input');
if ($in) { // Something in raw POST
$json = json_decode($in, true);
if ($json !== null) { // Looks like JSON
$_POST = $json;
$gotJSON = TRUE;
}
}
// }}}
if (!$routes)
$routes = $this->defaultRoutes;
$segments = $this->uri->segments;
array_shift($segments); // Shift first segment - assuming its the controller name
$segment = $segments ? array_shift($segments) : ''; // Retrieve argument if any
// Determine the route to use
foreach ($routes as $routeKey => $dest) {
$route = $routeKey;
if (preg_match('!^(.*)\[(.+?)\](.*)$!', $route, $matches)) { // Has a method in the form '[SOMETHING]'
$blockMatch = false; // Continue executing (set to false to stop)
foreach (preg_split('/\s*,\s*/', $matches[2]) as $block) { // Split CSV into bits
switch ($block) {
// Incomming HTTP methods
case 'GET':
case 'PUT':
case 'DELETE':
case 'POST':
if ($_SERVER['REQUEST_METHOD'] == $block) // Found route method does not match this one
$blockMatch = true;
break;
case 'JSON':
if ($gotJSON)
$blockMatch = true;
break;
default:
die("Joyst_Controller> Unsupported route query type: $block");
}
}
if (!$blockMatch)
continue;
$route = "{$matches[1]}{$matches[3]}"; // Delete from route and continue
}
switch ($route) {
case '':
if (!$segment) {
$matchingRoute = $routeKey;
break 2;
}
break;
case ':num':
if (is_numeric($segment)) {
$matchingRoute = $routeKey;
array_unshift($segments, $segment); // Put the segment back
break 2;
}
break;
default:
if ($segment == $route) {
$matchingRoute = $routeKey;
break 2;
}
}
}
if (!isset($matchingRoute)) // Didn't find anything matching in routes
return;
$rawfunc = $routes[$matchingRoute];
// Extract any additional parameters
$params = array_merge($_POST, $_GET);
if (!preg_match('/^(.+?)\((.*)\)$/', $rawfunc, $matches))
die('Joyst_Controller: Invalid routing function format. Should be in the format func(), func(a), func(*), func(1) or similar. Given: ' . $func);
$func = $matches[1];
// Determine the arguments to be passed to the routing function {{{
$args = array();
foreach (explode(',', $matches[2]) as $arg)
switch ($arg) {
case '#':
$args[] = $params;
break;
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if (!$segments)
$this->JSONError('Invalid URL format');
$args[] = $segments[$arg-1];
break;
case '*':
$args = $segments;
$segments = array();
break;
}
// }}}
// Call function {{{
// Check the model is loaded and call the function
$this->load->model($model);
if (!is_subclass_of($this->$model, 'Joyst_Model'))
die("Use of \$this->JoystModel('$model') on a model that does not extend Joyst_Model");
$this->$model->source = 'controller'; // Tell the model how its been invoked
// echo "Call \$this->$model->$func(" . json_encode($args) . ")<br/>";
$this->$model->returnRow = $this->returnRow; // Carry returnRow over into the Model
$return = call_user_func_array(array($this->$model, $func), $args);
// }}}
// Return output {{{
if (!$this->$model->continue) {
header('HTTP/1.1 400 Bad Request', true, 400);
header('X-Error: ' . $this->$model->_EscapeHeader($this->$model->joystError));
die();
} else {
$this->JSON($return);
}
// }}}
} | [
"function",
"JoystModel",
"(",
"$",
"model",
",",
"$",
"routes",
"=",
"null",
")",
"{",
"$",
"gotJSON",
"=",
"FALSE",
";",
"// Are we being passed a JSON object?",
"if",
"(",
"!",
"$",
"this",
"->",
"RequesterWants",
"(",
"'json'",
")",
")",
"// Not wanting JSON - fall though to regular controller which should handle base HTML requests",
"return",
";",
"// Process incomming raw JSON {{{",
"$",
"in",
"=",
"file_get_contents",
"(",
"'php://input'",
")",
";",
"if",
"(",
"$",
"in",
")",
"{",
"// Something in raw POST",
"$",
"json",
"=",
"json_decode",
"(",
"$",
"in",
",",
"true",
")",
";",
"if",
"(",
"$",
"json",
"!==",
"null",
")",
"{",
"// Looks like JSON",
"$",
"_POST",
"=",
"$",
"json",
";",
"$",
"gotJSON",
"=",
"TRUE",
";",
"}",
"}",
"// }}}",
"if",
"(",
"!",
"$",
"routes",
")",
"$",
"routes",
"=",
"$",
"this",
"->",
"defaultRoutes",
";",
"$",
"segments",
"=",
"$",
"this",
"->",
"uri",
"->",
"segments",
";",
"array_shift",
"(",
"$",
"segments",
")",
";",
"// Shift first segment - assuming its the controller name",
"$",
"segment",
"=",
"$",
"segments",
"?",
"array_shift",
"(",
"$",
"segments",
")",
":",
"''",
";",
"// Retrieve argument if any",
"// Determine the route to use",
"foreach",
"(",
"$",
"routes",
"as",
"$",
"routeKey",
"=>",
"$",
"dest",
")",
"{",
"$",
"route",
"=",
"$",
"routeKey",
";",
"if",
"(",
"preg_match",
"(",
"'!^(.*)\\[(.+?)\\](.*)$!'",
",",
"$",
"route",
",",
"$",
"matches",
")",
")",
"{",
"// Has a method in the form '[SOMETHING]'",
"$",
"blockMatch",
"=",
"false",
";",
"// Continue executing (set to false to stop)",
"foreach",
"(",
"preg_split",
"(",
"'/\\s*,\\s*/'",
",",
"$",
"matches",
"[",
"2",
"]",
")",
"as",
"$",
"block",
")",
"{",
"// Split CSV into bits",
"switch",
"(",
"$",
"block",
")",
"{",
"// Incomming HTTP methods",
"case",
"'GET'",
":",
"case",
"'PUT'",
":",
"case",
"'DELETE'",
":",
"case",
"'POST'",
":",
"if",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
"==",
"$",
"block",
")",
"// Found route method does not match this one",
"$",
"blockMatch",
"=",
"true",
";",
"break",
";",
"case",
"'JSON'",
":",
"if",
"(",
"$",
"gotJSON",
")",
"$",
"blockMatch",
"=",
"true",
";",
"break",
";",
"default",
":",
"die",
"(",
"\"Joyst_Controller> Unsupported route query type: $block\"",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"blockMatch",
")",
"continue",
";",
"$",
"route",
"=",
"\"{$matches[1]}{$matches[3]}\"",
";",
"// Delete from route and continue",
"}",
"switch",
"(",
"$",
"route",
")",
"{",
"case",
"''",
":",
"if",
"(",
"!",
"$",
"segment",
")",
"{",
"$",
"matchingRoute",
"=",
"$",
"routeKey",
";",
"break",
"2",
";",
"}",
"break",
";",
"case",
"':num'",
":",
"if",
"(",
"is_numeric",
"(",
"$",
"segment",
")",
")",
"{",
"$",
"matchingRoute",
"=",
"$",
"routeKey",
";",
"array_unshift",
"(",
"$",
"segments",
",",
"$",
"segment",
")",
";",
"// Put the segment back",
"break",
"2",
";",
"}",
"break",
";",
"default",
":",
"if",
"(",
"$",
"segment",
"==",
"$",
"route",
")",
"{",
"$",
"matchingRoute",
"=",
"$",
"routeKey",
";",
"break",
"2",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"matchingRoute",
")",
")",
"// Didn't find anything matching in routes",
"return",
";",
"$",
"rawfunc",
"=",
"$",
"routes",
"[",
"$",
"matchingRoute",
"]",
";",
"// Extract any additional parameters",
"$",
"params",
"=",
"array_merge",
"(",
"$",
"_POST",
",",
"$",
"_GET",
")",
";",
"if",
"(",
"!",
"preg_match",
"(",
"'/^(.+?)\\((.*)\\)$/'",
",",
"$",
"rawfunc",
",",
"$",
"matches",
")",
")",
"die",
"(",
"'Joyst_Controller: Invalid routing function format. Should be in the format func(), func(a), func(*), func(1) or similar. Given: '",
".",
"$",
"func",
")",
";",
"$",
"func",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"// Determine the arguments to be passed to the routing function {{{",
"$",
"args",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"explode",
"(",
"','",
",",
"$",
"matches",
"[",
"2",
"]",
")",
"as",
"$",
"arg",
")",
"switch",
"(",
"$",
"arg",
")",
"{",
"case",
"'#'",
":",
"$",
"args",
"[",
"]",
"=",
"$",
"params",
";",
"break",
";",
"case",
"'1'",
":",
"case",
"'2'",
":",
"case",
"'3'",
":",
"case",
"'4'",
":",
"case",
"'5'",
":",
"case",
"'6'",
":",
"case",
"'7'",
":",
"case",
"'8'",
":",
"case",
"'9'",
":",
"if",
"(",
"!",
"$",
"segments",
")",
"$",
"this",
"->",
"JSONError",
"(",
"'Invalid URL format'",
")",
";",
"$",
"args",
"[",
"]",
"=",
"$",
"segments",
"[",
"$",
"arg",
"-",
"1",
"]",
";",
"break",
";",
"case",
"'*'",
":",
"$",
"args",
"=",
"$",
"segments",
";",
"$",
"segments",
"=",
"array",
"(",
")",
";",
"break",
";",
"}",
"// }}}",
"// Call function {{{",
"// Check the model is loaded and call the function",
"$",
"this",
"->",
"load",
"->",
"model",
"(",
"$",
"model",
")",
";",
"if",
"(",
"!",
"is_subclass_of",
"(",
"$",
"this",
"->",
"$",
"model",
",",
"'Joyst_Model'",
")",
")",
"die",
"(",
"\"Use of \\$this->JoystModel('$model') on a model that does not extend Joyst_Model\"",
")",
";",
"$",
"this",
"->",
"$",
"model",
"->",
"source",
"=",
"'controller'",
";",
"// Tell the model how its been invoked",
"// echo \"Call \\$this->$model->$func(\" . json_encode($args) . \")<br/>\";",
"$",
"this",
"->",
"$",
"model",
"->",
"returnRow",
"=",
"$",
"this",
"->",
"returnRow",
";",
"// Carry returnRow over into the Model",
"$",
"return",
"=",
"call_user_func_array",
"(",
"array",
"(",
"$",
"this",
"->",
"$",
"model",
",",
"$",
"func",
")",
",",
"$",
"args",
")",
";",
"// }}}",
"// Return output {{{",
"if",
"(",
"!",
"$",
"this",
"->",
"$",
"model",
"->",
"continue",
")",
"{",
"header",
"(",
"'HTTP/1.1 400 Bad Request'",
",",
"true",
",",
"400",
")",
";",
"header",
"(",
"'X-Error: '",
".",
"$",
"this",
"->",
"$",
"model",
"->",
"_EscapeHeader",
"(",
"$",
"this",
"->",
"$",
"model",
"->",
"joystError",
")",
")",
";",
"die",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"JSON",
"(",
"$",
"return",
")",
";",
"}",
"// }}}",
"}"
] | Connect to a Joyst_Model and automatically route requests into various model functions
Routing is specified in the form 'path' => 'function(parameters...)'
Path can be composed of:
* [method] - e.g. '[POST]'. It can also be compound: '[POST,GET]'
* url - Any url
Parameters can be one or more of the following seperated by commas:
* `#` - All remaining parameters as a hash
* `1..9` - A specific numbered parameter from the input
* `*` - All left over parameters in the parameter order
@param string $model The name of the CI model (extending Joyst_Model) to use
@param array $routes The routing array to use. If unspecified $defaultRoutes will be substituted | [
"Connect",
"to",
"a",
"Joyst_Model",
"and",
"automatically",
"route",
"requests",
"into",
"various",
"model",
"functions"
] | train | https://github.com/hash-bang/Joyst/blob/f8bcf396120884c5c77e3e8f016b8472e2cc2fb0/Joyst_Controller.php#L118-L254 |
hash-bang/Joyst | Joyst_Controller.php | Joyst_Controller.JSON | function JSON($object = null) {
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header('Content-type: application/json');
if (is_array($object)) {
echo json_encode($object, $this->JSONOptions);
} else if (is_bool($object)) {
echo 0;
} else if (is_string($object)) {
echo $object;
} else if (is_null($object)) {
echo 'null';
} else {
die('Unknown object type to convert into JSON: ' . gettype($object));
}
if ($this->fatal)
exit;
} | php | function JSON($object = null) {
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header('Content-type: application/json');
if (is_array($object)) {
echo json_encode($object, $this->JSONOptions);
} else if (is_bool($object)) {
echo 0;
} else if (is_string($object)) {
echo $object;
} else if (is_null($object)) {
echo 'null';
} else {
die('Unknown object type to convert into JSON: ' . gettype($object));
}
if ($this->fatal)
exit;
} | [
"function",
"JSON",
"(",
"$",
"object",
"=",
"null",
")",
"{",
"header",
"(",
"\"Expires: Mon, 26 Jul 1997 05:00:00 GMT\"",
")",
";",
"header",
"(",
"\"Last-Modified: \"",
".",
"gmdate",
"(",
"\"D, d M Y H:i:s\"",
")",
".",
"\"GMT\"",
")",
";",
"header",
"(",
"\"Cache-Control: no-cache, must-revalidate\"",
")",
";",
"header",
"(",
"\"Pragma: no-cache\"",
")",
";",
"header",
"(",
"'Content-type: application/json'",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"object",
")",
")",
"{",
"echo",
"json_encode",
"(",
"$",
"object",
",",
"$",
"this",
"->",
"JSONOptions",
")",
";",
"}",
"else",
"if",
"(",
"is_bool",
"(",
"$",
"object",
")",
")",
"{",
"echo",
"0",
";",
"}",
"else",
"if",
"(",
"is_string",
"(",
"$",
"object",
")",
")",
"{",
"echo",
"$",
"object",
";",
"}",
"else",
"if",
"(",
"is_null",
"(",
"$",
"object",
")",
")",
"{",
"echo",
"'null'",
";",
"}",
"else",
"{",
"die",
"(",
"'Unknown object type to convert into JSON: '",
".",
"gettype",
"(",
"$",
"object",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"fatal",
")",
"exit",
";",
"}"
] | Output an object or string as JSON
@param string|array $object The sting or object to be output as JSON
@return null If $this->fatal is TRUE this function will stop execution immediately | [
"Output",
"an",
"object",
"or",
"string",
"as",
"JSON"
] | train | https://github.com/hash-bang/Joyst/blob/f8bcf396120884c5c77e3e8f016b8472e2cc2fb0/Joyst_Controller.php#L261-L282 |
guru-digital/framework-types | GDM/Framework/Types/String.php | String.clean | function clean($separator = '-', $length = -1)
{
// replace non alphanumeric and non underscore charachters by separator
$this->replace('/[^a-z0-9]/i', $separator);
if (!empty($separator)) {
// replace multiple occurences of separator by one instance
$this->replace('/'.preg_quote($separator).'['.preg_quote($separator).']*/', $separator);
}
// cut off to maximum length
if ($length > -1 && $this->length() > $length) {
$this->truncate($length, '');
}
// remove separator from start and end of string
$this->trim($separator);
return $this;
} | php | function clean($separator = '-', $length = -1)
{
// replace non alphanumeric and non underscore charachters by separator
$this->replace('/[^a-z0-9]/i', $separator);
if (!empty($separator)) {
// replace multiple occurences of separator by one instance
$this->replace('/'.preg_quote($separator).'['.preg_quote($separator).']*/', $separator);
}
// cut off to maximum length
if ($length > -1 && $this->length() > $length) {
$this->truncate($length, '');
}
// remove separator from start and end of string
$this->trim($separator);
return $this;
} | [
"function",
"clean",
"(",
"$",
"separator",
"=",
"'-'",
",",
"$",
"length",
"=",
"-",
"1",
")",
"{",
"// replace non alphanumeric and non underscore charachters by separator",
"$",
"this",
"->",
"replace",
"(",
"'/[^a-z0-9]/i'",
",",
"$",
"separator",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"separator",
")",
")",
"{",
"// replace multiple occurences of separator by one instance",
"$",
"this",
"->",
"replace",
"(",
"'/'",
".",
"preg_quote",
"(",
"$",
"separator",
")",
".",
"'['",
".",
"preg_quote",
"(",
"$",
"separator",
")",
".",
"']*/'",
",",
"$",
"separator",
")",
";",
"}",
"// cut off to maximum length",
"if",
"(",
"$",
"length",
">",
"-",
"1",
"&&",
"$",
"this",
"->",
"length",
"(",
")",
">",
"$",
"length",
")",
"{",
"$",
"this",
"->",
"truncate",
"(",
"$",
"length",
",",
"''",
")",
";",
"}",
"// remove separator from start and end of string",
"$",
"this",
"->",
"trim",
"(",
"$",
"separator",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Strip non alpha numeric characters form the string
@param string $separator [optional] <p>
Replace all non alpha numeric characters with this.</p>
<p>Default is <b>-</b>
</p>
@param string $length [optional] <p>
Optionally, truncate the string to this length
</p>
@return self | [
"Strip",
"non",
"alpha",
"numeric",
"characters",
"form",
"the",
"string"
] | train | https://github.com/guru-digital/framework-types/blob/f14e9b1e6cc2571414ba7d561bb205644e28e17d/GDM/Framework/Types/String.php#L26-L42 |
guru-digital/framework-types | GDM/Framework/Types/String.php | String.compareTo | public function compareTo($str2, $caseSensitive = true)
{
$str2 = $caseSensitive ? $str2 : strtolower($str2);
$string = $caseSensitive ? $this->returnValue : strtolower($this->returnValue);
return ($string == $str2);
} | php | public function compareTo($str2, $caseSensitive = true)
{
$str2 = $caseSensitive ? $str2 : strtolower($str2);
$string = $caseSensitive ? $this->returnValue : strtolower($this->returnValue);
return ($string == $str2);
} | [
"public",
"function",
"compareTo",
"(",
"$",
"str2",
",",
"$",
"caseSensitive",
"=",
"true",
")",
"{",
"$",
"str2",
"=",
"$",
"caseSensitive",
"?",
"$",
"str2",
":",
"strtolower",
"(",
"$",
"str2",
")",
";",
"$",
"string",
"=",
"$",
"caseSensitive",
"?",
"$",
"this",
"->",
"returnValue",
":",
"strtolower",
"(",
"$",
"this",
"->",
"returnValue",
")",
";",
"return",
"(",
"$",
"string",
"==",
"$",
"str2",
")",
";",
"}"
] | Checks if this string object is equal to another.
@param string $str2 <p>
The string to compare against
</p>
@param bool $caseSensitive [optional] <p>
If true the string comparision is case sensitive
</p>
@return boolean true if matched false otherwise. | [
"Checks",
"if",
"this",
"string",
"object",
"is",
"equal",
"to",
"another",
"."
] | train | https://github.com/guru-digital/framework-types/blob/f14e9b1e6cc2571414ba7d561bb205644e28e17d/GDM/Framework/Types/String.php#L54-L59 |
guru-digital/framework-types | GDM/Framework/Types/String.php | String.contains | public function contains($needle, $caseSensitive = true)
{
$needle = $caseSensitive ? $needle : strtolower($needle);
$string = $caseSensitive ? $this->returnValue : strtolower($this->returnValue);
return (!(strpos($string, $needle) === false));
} | php | public function contains($needle, $caseSensitive = true)
{
$needle = $caseSensitive ? $needle : strtolower($needle);
$string = $caseSensitive ? $this->returnValue : strtolower($this->returnValue);
return (!(strpos($string, $needle) === false));
} | [
"public",
"function",
"contains",
"(",
"$",
"needle",
",",
"$",
"caseSensitive",
"=",
"true",
")",
"{",
"$",
"needle",
"=",
"$",
"caseSensitive",
"?",
"$",
"needle",
":",
"strtolower",
"(",
"$",
"needle",
")",
";",
"$",
"string",
"=",
"$",
"caseSensitive",
"?",
"$",
"this",
"->",
"returnValue",
":",
"strtolower",
"(",
"$",
"this",
"->",
"returnValue",
")",
";",
"return",
"(",
"!",
"(",
"strpos",
"(",
"$",
"string",
",",
"$",
"needle",
")",
"===",
"false",
")",
")",
";",
"}"
] | Checks if this string contains another.
@param string $needle <p>
The string to compare against
</p>
@param bool $caseSensitive [optional] <p>
If true the string comparision is case sensitive
</p>
@return boolean true if needle is found in this string. | [
"Checks",
"if",
"this",
"string",
"contains",
"another",
"."
] | train | https://github.com/guru-digital/framework-types/blob/f14e9b1e6cc2571414ba7d561bb205644e28e17d/GDM/Framework/Types/String.php#L71-L76 |
guru-digital/framework-types | GDM/Framework/Types/String.php | String.stripLineBreak | public function stripLineBreak($replacement = '')
{
$this->returnValue = str_replace($this->lineBreaks, $replacement, $this->returnValue);
return $this;
} | php | public function stripLineBreak($replacement = '')
{
$this->returnValue = str_replace($this->lineBreaks, $replacement, $this->returnValue);
return $this;
} | [
"public",
"function",
"stripLineBreak",
"(",
"$",
"replacement",
"=",
"''",
")",
"{",
"$",
"this",
"->",
"returnValue",
"=",
"str_replace",
"(",
"$",
"this",
"->",
"lineBreaks",
",",
"$",
"replacement",
",",
"$",
"this",
"->",
"returnValue",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Strip all linebreack characters from this string
@param strig $replacement [optional] <p>
Optionally, replace linebreaks with the character
</p>
@return self | [
"Strip",
"all",
"linebreack",
"characters",
"from",
"this",
"string"
] | train | https://github.com/guru-digital/framework-types/blob/f14e9b1e6cc2571414ba7d561bb205644e28e17d/GDM/Framework/Types/String.php#L116-L120 |
guru-digital/framework-types | GDM/Framework/Types/String.php | String.isEmail | public function isEmail($checkDNS = true)
{
$isValid = filter_var($this->returnValue, FILTER_VALIDATE_EMAIL) !== false;
if ($isValid && $checkDNS) {
$domain = substr(strrchr($this->returnValue, "@"), 1);
// domain not found in DNS
$isValid = checkdnsrr($domain, "MX") && checkdnsrr($domain, "A");
}
return $isValid;
} | php | public function isEmail($checkDNS = true)
{
$isValid = filter_var($this->returnValue, FILTER_VALIDATE_EMAIL) !== false;
if ($isValid && $checkDNS) {
$domain = substr(strrchr($this->returnValue, "@"), 1);
// domain not found in DNS
$isValid = checkdnsrr($domain, "MX") && checkdnsrr($domain, "A");
}
return $isValid;
} | [
"public",
"function",
"isEmail",
"(",
"$",
"checkDNS",
"=",
"true",
")",
"{",
"$",
"isValid",
"=",
"filter_var",
"(",
"$",
"this",
"->",
"returnValue",
",",
"FILTER_VALIDATE_EMAIL",
")",
"!==",
"false",
";",
"if",
"(",
"$",
"isValid",
"&&",
"$",
"checkDNS",
")",
"{",
"$",
"domain",
"=",
"substr",
"(",
"strrchr",
"(",
"$",
"this",
"->",
"returnValue",
",",
"\"@\"",
")",
",",
"1",
")",
";",
"// domain not found in DNS",
"$",
"isValid",
"=",
"checkdnsrr",
"(",
"$",
"domain",
",",
"\"MX\"",
")",
"&&",
"checkdnsrr",
"(",
"$",
"domain",
",",
"\"A\"",
")",
";",
"}",
"return",
"$",
"isValid",
";",
"}"
] | Valid if the string is an email address
@param string $checkDNS [optional] <p>
If true, this method will use checkdnsrr and validate if the domain part of the email address is a valid domain.
</p>
@return bool | [
"Valid",
"if",
"the",
"string",
"is",
"an",
"email",
"address"
] | train | https://github.com/guru-digital/framework-types/blob/f14e9b1e6cc2571414ba7d561bb205644e28e17d/GDM/Framework/Types/String.php#L241-L250 |
guru-digital/framework-types | GDM/Framework/Types/String.php | String.neatTruncate | public function neatTruncate($length, $marker = '...')
{
$length = $length - (strlen($marker));
$len = $this->length();
if ($len > $length) {
$matches = array();
preg_match('/(.{'.$length.'}.*?)\b/', $this->returnValue, $matches);
$result = end($matches);
$this->returnValue = rtrim($result).$marker;
}
return $this;
} | php | public function neatTruncate($length, $marker = '...')
{
$length = $length - (strlen($marker));
$len = $this->length();
if ($len > $length) {
$matches = array();
preg_match('/(.{'.$length.'}.*?)\b/', $this->returnValue, $matches);
$result = end($matches);
$this->returnValue = rtrim($result).$marker;
}
return $this;
} | [
"public",
"function",
"neatTruncate",
"(",
"$",
"length",
",",
"$",
"marker",
"=",
"'...'",
")",
"{",
"$",
"length",
"=",
"$",
"length",
"-",
"(",
"strlen",
"(",
"$",
"marker",
")",
")",
";",
"$",
"len",
"=",
"$",
"this",
"->",
"length",
"(",
")",
";",
"if",
"(",
"$",
"len",
">",
"$",
"length",
")",
"{",
"$",
"matches",
"=",
"array",
"(",
")",
";",
"preg_match",
"(",
"'/(.{'",
".",
"$",
"length",
".",
"'}.*?)\\b/'",
",",
"$",
"this",
"->",
"returnValue",
",",
"$",
"matches",
")",
";",
"$",
"result",
"=",
"end",
"(",
"$",
"matches",
")",
";",
"$",
"this",
"->",
"returnValue",
"=",
"rtrim",
"(",
"$",
"result",
")",
".",
"$",
"marker",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Truncates a string to a maximum length neatly and adds a truncation marker
when this happens. The maximum length of the string returned will be the
maxlength of the string - the truncation marker length.
It will not truncate the string in the middle of a word. Insead it will
truncate to the next blank space.
@param string $length <p>
The amount of chracters to truncate to ($marker is included in the length).
</p>
@param string $marker [optional] <p>
Appended to the end of the truncated string. (default = ...)
</p>
@return bool | [
"Truncates",
"a",
"string",
"to",
"a",
"maximum",
"length",
"neatly",
"and",
"adds",
"a",
"truncation",
"marker",
"when",
"this",
"happens",
".",
"The",
"maximum",
"length",
"of",
"the",
"string",
"returned",
"will",
"be",
"the",
"maxlength",
"of",
"the",
"string",
"-",
"the",
"truncation",
"marker",
"length",
".",
"It",
"will",
"not",
"truncate",
"the",
"string",
"in",
"the",
"middle",
"of",
"a",
"word",
".",
"Insead",
"it",
"will",
"truncate",
"to",
"the",
"next",
"blank",
"space",
"."
] | train | https://github.com/guru-digital/framework-types/blob/f14e9b1e6cc2571414ba7d561bb205644e28e17d/GDM/Framework/Types/String.php#L266-L277 |
guru-digital/framework-types | GDM/Framework/Types/String.php | String.truncate | public function truncate($length, $marker = '...')
{
if ($this->length() > $length) {
$this->returnValue = substr($this->returnValue, 0, ($length - strlen($marker))).$marker;
}
return $this;
} | php | public function truncate($length, $marker = '...')
{
if ($this->length() > $length) {
$this->returnValue = substr($this->returnValue, 0, ($length - strlen($marker))).$marker;
}
return $this;
} | [
"public",
"function",
"truncate",
"(",
"$",
"length",
",",
"$",
"marker",
"=",
"'...'",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"length",
"(",
")",
">",
"$",
"length",
")",
"{",
"$",
"this",
"->",
"returnValue",
"=",
"substr",
"(",
"$",
"this",
"->",
"returnValue",
",",
"0",
",",
"(",
"$",
"length",
"-",
"strlen",
"(",
"$",
"marker",
")",
")",
")",
".",
"$",
"marker",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Truncates a string to a maximum length and adds a truncation marker
when this happens. The maximum length of the string returned will be the
maxlength of the string - the truncation marker length.
@param string $length <p>
The amount of chracters to truncate to ($marker is included in the length).
</p>
@param string $marker [optional] <p>
@return self | [
"Truncates",
"a",
"string",
"to",
"a",
"maximum",
"length",
"and",
"adds",
"a",
"truncation",
"marker",
"when",
"this",
"happens",
".",
"The",
"maximum",
"length",
"of",
"the",
"string",
"returned",
"will",
"be",
"the",
"maxlength",
"of",
"the",
"string",
"-",
"the",
"truncation",
"marker",
"length",
"."
] | train | https://github.com/guru-digital/framework-types/blob/f14e9b1e6cc2571414ba7d561bb205644e28e17d/GDM/Framework/Types/String.php#L289-L296 |
guru-digital/framework-types | GDM/Framework/Types/String.php | String.longestWord | public function longestWord()
{
$words = str_word_count($this->returnValue, 1);
$longestWordLength = 0;
$longestWord = "";
foreach ($words as $word) {
if (strlen($word) > $longestWordLength) {
$longestWordLength = strlen($word);
$longestWord = $word;
}
}
return self::create($longestWord);
} | php | public function longestWord()
{
$words = str_word_count($this->returnValue, 1);
$longestWordLength = 0;
$longestWord = "";
foreach ($words as $word) {
if (strlen($word) > $longestWordLength) {
$longestWordLength = strlen($word);
$longestWord = $word;
}
}
return self::create($longestWord);
} | [
"public",
"function",
"longestWord",
"(",
")",
"{",
"$",
"words",
"=",
"str_word_count",
"(",
"$",
"this",
"->",
"returnValue",
",",
"1",
")",
";",
"$",
"longestWordLength",
"=",
"0",
";",
"$",
"longestWord",
"=",
"\"\"",
";",
"foreach",
"(",
"$",
"words",
"as",
"$",
"word",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"word",
")",
">",
"$",
"longestWordLength",
")",
"{",
"$",
"longestWordLength",
"=",
"strlen",
"(",
"$",
"word",
")",
";",
"$",
"longestWord",
"=",
"$",
"word",
";",
"}",
"}",
"return",
"self",
"::",
"create",
"(",
"$",
"longestWord",
")",
";",
"}"
] | Get the longest word in a sring
@return String The longest word in the current string | [
"Get",
"the",
"longest",
"word",
"in",
"a",
"sring"
] | train | https://github.com/guru-digital/framework-types/blob/f14e9b1e6cc2571414ba7d561bb205644e28e17d/GDM/Framework/Types/String.php#L313-L328 |
guru-digital/framework-types | GDM/Framework/Types/String.php | String.subString | public function subString($start, $length = null)
{
$length = is_null($length) ? $this->length() : $length;
$this->returnValue = substr($this->returnValue, $start, $length);
return $this;
} | php | public function subString($start, $length = null)
{
$length = is_null($length) ? $this->length() : $length;
$this->returnValue = substr($this->returnValue, $start, $length);
return $this;
} | [
"public",
"function",
"subString",
"(",
"$",
"start",
",",
"$",
"length",
"=",
"null",
")",
"{",
"$",
"length",
"=",
"is_null",
"(",
"$",
"length",
")",
"?",
"$",
"this",
"->",
"length",
"(",
")",
":",
"$",
"length",
";",
"$",
"this",
"->",
"returnValue",
"=",
"substr",
"(",
"$",
"this",
"->",
"returnValue",
",",
"$",
"start",
",",
"$",
"length",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Return part of a string
@link http://php.net/manual/en/function.substr.php
@param int $start <p>
If <i>start</i> is non-negative, the returned string
will start at the <i>start</i>'th position in
<i>string</i>, counting from zero. For instance,
in the string 'abcdef', the character at
position 0 is 'a', the
character at position 2 is
'c', and so forth.
</p>
<p>
If <i>start</i> is negative, the returned string
will start at the <i>start</i>'th character
from the end of <i>string</i>.
</p>
<p>
If <i>string</i> is less than or equal to
<i>start</i> characters long, <b>FALSE</b> will be returned.
</p>
<p>
Using a negative <i>start</i>
<code>
$rest = (string)(new String("abcdef"))->subString(-1); // returns "f"
$rest = (string)(new String("abcdef"))->subString(-2); // returns "ef"
$rest = (string)(new String("abcdef"))->subString(-3, 1); // returns "d"
</code>
</p>
@param int $length [optional] <p>
If <i>length</i> is given and is positive, the string
returned will contain at most <i>length</i> characters
beginning from <i>start</i> (depending on the length of
<i>string</i>).
</p>
<p>
If <i>length</i> is given and is negative, then that many
characters will be omitted from the end of <i>string</i>
(after the start position has been calculated when a
<i>start</i> is negative). If
<i>start</i> denotes the position of this truncation or
beyond, false will be returned.
</p>
<p>
If <i>length</i> is given and is 0,
<b>FALSE</b> or <b>NULL</b> an empty string will be returned.
</p>
<p>
If <i>length</i> is omitted, the substring starting from
<i>start</i> until the end of the string will be
returned.
</p>
Using a negative <i>length</i>
<code>
$rest = (string)(new String("abcdef"))->subString(0, -1); // returns "abcde"
$rest = (string)(new String("abcdef"))->subString(2, -1); // returns "cde"
$rest = (string)(new String("abcdef"))->subString(4, -4); // returns false
$rest = (string)(new String("abcdef"))->subString(-3, -1); // returns "de"
</code>
@return self | [
"Return",
"part",
"of",
"a",
"string",
"@link",
"http",
":",
"//",
"php",
".",
"net",
"/",
"manual",
"/",
"en",
"/",
"function",
".",
"substr",
".",
"php",
"@param",
"int",
"$start",
"<p",
">",
"If",
"<i",
">",
"start<",
"/",
"i",
">",
"is",
"non",
"-",
"negative",
"the",
"returned",
"string",
"will",
"start",
"at",
"the",
"<i",
">",
"start<",
"/",
"i",
">",
"th",
"position",
"in",
"<i",
">",
"string<",
"/",
"i",
">",
"counting",
"from",
"zero",
".",
"For",
"instance",
"in",
"the",
"string",
"abcdef",
"the",
"character",
"at",
"position",
"0",
"is",
"a",
"the",
"character",
"at",
"position",
"2",
"is",
"c",
"and",
"so",
"forth",
".",
"<",
"/",
"p",
">",
"<p",
">",
"If",
"<i",
">",
"start<",
"/",
"i",
">",
"is",
"negative",
"the",
"returned",
"string",
"will",
"start",
"at",
"the",
"<i",
">",
"start<",
"/",
"i",
">",
"th",
"character",
"from",
"the",
"end",
"of",
"<i",
">",
"string<",
"/",
"i",
">",
".",
"<",
"/",
"p",
">",
"<p",
">",
"If",
"<i",
">",
"string<",
"/",
"i",
">",
"is",
"less",
"than",
"or",
"equal",
"to",
"<i",
">",
"start<",
"/",
"i",
">",
"characters",
"long",
"<b",
">",
"FALSE<",
"/",
"b",
">",
"will",
"be",
"returned",
".",
"<",
"/",
"p",
">",
"<p",
">",
"Using",
"a",
"negative",
"<i",
">",
"start<",
"/",
"i",
">",
"<code",
">",
"$rest",
"=",
"(",
"string",
")",
"(",
"new",
"String",
"(",
"abcdef",
"))",
"-",
">",
"subString",
"(",
"-",
"1",
")",
";",
"//",
"returns",
"f",
"$rest",
"=",
"(",
"string",
")",
"(",
"new",
"String",
"(",
"abcdef",
"))",
"-",
">",
"subString",
"(",
"-",
"2",
")",
";",
"//",
"returns",
"ef",
"$rest",
"=",
"(",
"string",
")",
"(",
"new",
"String",
"(",
"abcdef",
"))",
"-",
">",
"subString",
"(",
"-",
"3",
"1",
")",
";",
"//",
"returns",
"d",
"<",
"/",
"code",
">",
"<",
"/",
"p",
">",
"@param",
"int",
"$length",
"[",
"optional",
"]",
"<p",
">",
"If",
"<i",
">",
"length<",
"/",
"i",
">",
"is",
"given",
"and",
"is",
"positive",
"the",
"string",
"returned",
"will",
"contain",
"at",
"most",
"<i",
">",
"length<",
"/",
"i",
">",
"characters",
"beginning",
"from",
"<i",
">",
"start<",
"/",
"i",
">",
"(",
"depending",
"on",
"the",
"length",
"of",
"<i",
">",
"string<",
"/",
"i",
">",
")",
".",
"<",
"/",
"p",
">",
"<p",
">",
"If",
"<i",
">",
"length<",
"/",
"i",
">",
"is",
"given",
"and",
"is",
"negative",
"then",
"that",
"many",
"characters",
"will",
"be",
"omitted",
"from",
"the",
"end",
"of",
"<i",
">",
"string<",
"/",
"i",
">",
"(",
"after",
"the",
"start",
"position",
"has",
"been",
"calculated",
"when",
"a",
"<i",
">",
"start<",
"/",
"i",
">",
"is",
"negative",
")",
".",
"If",
"<i",
">",
"start<",
"/",
"i",
">",
"denotes",
"the",
"position",
"of",
"this",
"truncation",
"or",
"beyond",
"false",
"will",
"be",
"returned",
".",
"<",
"/",
"p",
">",
"<p",
">",
"If",
"<i",
">",
"length<",
"/",
"i",
">",
"is",
"given",
"and",
"is",
"0",
"<b",
">",
"FALSE<",
"/",
"b",
">",
"or",
"<b",
">",
"NULL<",
"/",
"b",
">",
"an",
"empty",
"string",
"will",
"be",
"returned",
".",
"<",
"/",
"p",
">",
"<p",
">",
"If",
"<i",
">",
"length<",
"/",
"i",
">",
"is",
"omitted",
"the",
"substring",
"starting",
"from",
"<i",
">",
"start<",
"/",
"i",
">",
"until",
"the",
"end",
"of",
"the",
"string",
"will",
"be",
"returned",
".",
"<",
"/",
"p",
">",
"Using",
"a",
"negative",
"<i",
">",
"length<",
"/",
"i",
">",
"<code",
">"
] | train | https://github.com/guru-digital/framework-types/blob/f14e9b1e6cc2571414ba7d561bb205644e28e17d/GDM/Framework/Types/String.php#L392-L397 |
guru-digital/framework-types | GDM/Framework/Types/String.php | String.replace | public function replace($pattern, $replacement, $limit = -1, &$count = null)
{
$this->returnValue = preg_replace($pattern, $replacement, $this->returnValue, $limit, $count);
return $this;
} | php | public function replace($pattern, $replacement, $limit = -1, &$count = null)
{
$this->returnValue = preg_replace($pattern, $replacement, $this->returnValue, $limit, $count);
return $this;
} | [
"public",
"function",
"replace",
"(",
"$",
"pattern",
",",
"$",
"replacement",
",",
"$",
"limit",
"=",
"-",
"1",
",",
"&",
"$",
"count",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"returnValue",
"=",
"preg_replace",
"(",
"$",
"pattern",
",",
"$",
"replacement",
",",
"$",
"this",
"->",
"returnValue",
",",
"$",
"limit",
",",
"$",
"count",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Perform a regular expression search and replace
@link http://php.net/manual/en/function.preg-replace.php
@param mixed $pattern <p>
The pattern to search for. It can be either a string or an array with
strings.
</p>
<p>
Several PCRE modifiers
are also available, including the deprecated 'e'
(PREG_REPLACE_EVAL), which is specific to this function.
</p>
@param mixed $replacement <p>
The string or an array with strings to replace. If this parameter is a
string and the <i>pattern</i> parameter is an array,
all patterns will be replaced by that string. If both
<i>pattern</i> and <i>replacement</i>
parameters are arrays, each <i>pattern</i> will be
replaced by the <i>replacement</i> counterpart. If
there are fewer elements in the <i>replacement</i>
array than in the <i>pattern</i> array, any extra
<i>pattern</i>s will be replaced by an empty string.
</p>
<p>
<i>replacement</i> may contain references of the form
\\n or (since PHP 4.0.4)
$n, with the latter form
being the preferred one. Every such reference will be replaced by the text
captured by the n'th parenthesized pattern.
n can be from 0 to 99, and
\\0 or $0 refers to the text matched
by the whole pattern. Opening parentheses are counted from left to right
(starting from 1) to obtain the number of the capturing subpattern.
To use backslash in replacement, it must be doubled
("\\\\" PHP string).
</p>
<p>
When working with a replacement pattern where a backreference is
immediately followed by another number (i.e.: placing a literal number
immediately after a matched pattern), you cannot use the familiar
\\1 notation for your backreference.
\\11, for example, would confuse
<b>replace</b> since it does not know whether you
want the \\1 backreference followed by a literal
1, or the \\11 backreference
followed by nothing. In this case the solution is to use
\${1}1. This creates an isolated
$1 backreference, leaving the 1
as a literal.
</p>
<p>
When using the deprecated e modifier, this function escapes
some characters (namely ', ",
\ and NULL) in the strings that replace the
backreferences. This is done to ensure that no syntax errors arise
from backreference usage with either single or double quotes (e.g.
'strlen(\'$1\')+strlen("$2")'). Make sure you are
aware of PHP's string
syntax to know exactly how the interpreted string will look.
</p>
@param int $limit [optional] <p>
The maximum possible replacements for each pattern in each
<i>subject</i> string. Defaults to
-1 (no limit).
</p>
@param int $count [optional] <p>
If specified, this variable will be filled with the number of
replacements done.
</p>
@return self | [
"Perform",
"a",
"regular",
"expression",
"search",
"and",
"replace",
"@link",
"http",
":",
"//",
"php",
".",
"net",
"/",
"manual",
"/",
"en",
"/",
"function",
".",
"preg",
"-",
"replace",
".",
"php",
"@param",
"mixed",
"$pattern",
"<p",
">",
"The",
"pattern",
"to",
"search",
"for",
".",
"It",
"can",
"be",
"either",
"a",
"string",
"or",
"an",
"array",
"with",
"strings",
".",
"<",
"/",
"p",
">",
"<p",
">",
"Several",
"PCRE",
"modifiers",
"are",
"also",
"available",
"including",
"the",
"deprecated",
"e",
"(",
"PREG_REPLACE_EVAL",
")",
"which",
"is",
"specific",
"to",
"this",
"function",
".",
"<",
"/",
"p",
">",
"@param",
"mixed",
"$replacement",
"<p",
">",
"The",
"string",
"or",
"an",
"array",
"with",
"strings",
"to",
"replace",
".",
"If",
"this",
"parameter",
"is",
"a",
"string",
"and",
"the",
"<i",
">",
"pattern<",
"/",
"i",
">",
"parameter",
"is",
"an",
"array",
"all",
"patterns",
"will",
"be",
"replaced",
"by",
"that",
"string",
".",
"If",
"both",
"<i",
">",
"pattern<",
"/",
"i",
">",
"and",
"<i",
">",
"replacement<",
"/",
"i",
">",
"parameters",
"are",
"arrays",
"each",
"<i",
">",
"pattern<",
"/",
"i",
">",
"will",
"be",
"replaced",
"by",
"the",
"<i",
">",
"replacement<",
"/",
"i",
">",
"counterpart",
".",
"If",
"there",
"are",
"fewer",
"elements",
"in",
"the",
"<i",
">",
"replacement<",
"/",
"i",
">",
"array",
"than",
"in",
"the",
"<i",
">",
"pattern<",
"/",
"i",
">",
"array",
"any",
"extra",
"<i",
">",
"pattern<",
"/",
"i",
">",
"s",
"will",
"be",
"replaced",
"by",
"an",
"empty",
"string",
".",
"<",
"/",
"p",
">",
"<p",
">",
"<i",
">",
"replacement<",
"/",
"i",
">",
"may",
"contain",
"references",
"of",
"the",
"form",
"\\\\",
"n",
"or",
"(",
"since",
"PHP",
"4",
".",
"0",
".",
"4",
")",
"$n",
"with",
"the",
"latter",
"form",
"being",
"the",
"preferred",
"one",
".",
"Every",
"such",
"reference",
"will",
"be",
"replaced",
"by",
"the",
"text",
"captured",
"by",
"the",
"n",
"th",
"parenthesized",
"pattern",
".",
"n",
"can",
"be",
"from",
"0",
"to",
"99",
"and",
"\\\\",
"0",
"or",
"$0",
"refers",
"to",
"the",
"text",
"matched",
"by",
"the",
"whole",
"pattern",
".",
"Opening",
"parentheses",
"are",
"counted",
"from",
"left",
"to",
"right",
"(",
"starting",
"from",
"1",
")",
"to",
"obtain",
"the",
"number",
"of",
"the",
"capturing",
"subpattern",
".",
"To",
"use",
"backslash",
"in",
"replacement",
"it",
"must",
"be",
"doubled",
"(",
"\\\\\\\\",
"PHP",
"string",
")",
".",
"<",
"/",
"p",
">",
"<p",
">",
"When",
"working",
"with",
"a",
"replacement",
"pattern",
"where",
"a",
"backreference",
"is",
"immediately",
"followed",
"by",
"another",
"number",
"(",
"i",
".",
"e",
".",
":",
"placing",
"a",
"literal",
"number",
"immediately",
"after",
"a",
"matched",
"pattern",
")",
"you",
"cannot",
"use",
"the",
"familiar",
"\\\\",
"1",
"notation",
"for",
"your",
"backreference",
".",
"\\\\",
"11",
"for",
"example",
"would",
"confuse",
"<b",
">",
"replace<",
"/",
"b",
">",
"since",
"it",
"does",
"not",
"know",
"whether",
"you",
"want",
"the",
"\\\\",
"1",
"backreference",
"followed",
"by",
"a",
"literal",
"1",
"or",
"the",
"\\\\",
"11",
"backreference",
"followed",
"by",
"nothing",
".",
"In",
"this",
"case",
"the",
"solution",
"is",
"to",
"use",
"\\",
"$",
"{",
"1",
"}",
"1",
".",
"This",
"creates",
"an",
"isolated",
"$1",
"backreference",
"leaving",
"the",
"1",
"as",
"a",
"literal",
".",
"<",
"/",
"p",
">",
"<p",
">",
"When",
"using",
"the",
"deprecated",
"e",
"modifier",
"this",
"function",
"escapes",
"some",
"characters",
"(",
"namely",
"\\",
"and",
"NULL",
")",
"in",
"the",
"strings",
"that",
"replace",
"the",
"backreferences",
".",
"This",
"is",
"done",
"to",
"ensure",
"that",
"no",
"syntax",
"errors",
"arise",
"from",
"backreference",
"usage",
"with",
"either",
"single",
"or",
"double",
"quotes",
"(",
"e",
".",
"g",
".",
"strlen",
"(",
"\\",
"$1",
"\\",
")",
"+",
"strlen",
"(",
"$2",
")",
")",
".",
"Make",
"sure",
"you",
"are",
"aware",
"of",
"PHP",
"s",
"string",
"syntax",
"to",
"know",
"exactly",
"how",
"the",
"interpreted",
"string",
"will",
"look",
".",
"<",
"/",
"p",
">",
"@param",
"int",
"$limit",
"[",
"optional",
"]",
"<p",
">",
"The",
"maximum",
"possible",
"replacements",
"for",
"each",
"pattern",
"in",
"each",
"<i",
">",
"subject<",
"/",
"i",
">",
"string",
".",
"Defaults",
"to",
"-",
"1",
"(",
"no",
"limit",
")",
".",
"<",
"/",
"p",
">",
"@param",
"int",
"$count",
"[",
"optional",
"]",
"<p",
">",
"If",
"specified",
"this",
"variable",
"will",
"be",
"filled",
"with",
"the",
"number",
"of",
"replacements",
"done",
".",
"<",
"/",
"p",
">"
] | train | https://github.com/guru-digital/framework-types/blob/f14e9b1e6cc2571414ba7d561bb205644e28e17d/GDM/Framework/Types/String.php#L516-L520 |
guru-digital/framework-types | GDM/Framework/Types/String.php | String.simpleReplace | public function simpleReplace($search, $replace, &$count = null)
{
$this->returnValue = str_replace($search, $replace, $this->returnValue, $count);
return $this;
} | php | public function simpleReplace($search, $replace, &$count = null)
{
$this->returnValue = str_replace($search, $replace, $this->returnValue, $count);
return $this;
} | [
"public",
"function",
"simpleReplace",
"(",
"$",
"search",
",",
"$",
"replace",
",",
"&",
"$",
"count",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"returnValue",
"=",
"str_replace",
"(",
"$",
"search",
",",
"$",
"replace",
",",
"$",
"this",
"->",
"returnValue",
",",
"$",
"count",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Replace all occurrences of the search string with the replacement string
@link http://php.net/manual/en/function.str-replace.php
@param mixed $search <p>
The value being searched for, otherwise known as the needle.
An array may be used to designate multiple needles.
</p>
@param mixed $replace <p>
The replacement value that replaces found <i>search</i>
values. An array may be used to designate multiple replacements.
</p>
@param int $count [optional] <p>
If passed, this will be set to the number of replacements performed.
</p>
@return self | [
"Replace",
"all",
"occurrences",
"of",
"the",
"search",
"string",
"with",
"the",
"replacement",
"string"
] | train | https://github.com/guru-digital/framework-types/blob/f14e9b1e6cc2571414ba7d561bb205644e28e17d/GDM/Framework/Types/String.php#L538-L542 |
guru-digital/framework-types | GDM/Framework/Types/String.php | String.stripSpecialChars | public function stripSpecialChars($replacement)
{
$this->returnValue = preg_replace('/[^A-Za-z0-9]/', $replacement, $this->returnValue);
$this->returnValue = preg_replace('/ +/', $replacement, $this->returnValue);
return $this;
} | php | public function stripSpecialChars($replacement)
{
$this->returnValue = preg_replace('/[^A-Za-z0-9]/', $replacement, $this->returnValue);
$this->returnValue = preg_replace('/ +/', $replacement, $this->returnValue);
return $this;
} | [
"public",
"function",
"stripSpecialChars",
"(",
"$",
"replacement",
")",
"{",
"$",
"this",
"->",
"returnValue",
"=",
"preg_replace",
"(",
"'/[^A-Za-z0-9]/'",
",",
"$",
"replacement",
",",
"$",
"this",
"->",
"returnValue",
")",
";",
"$",
"this",
"->",
"returnValue",
"=",
"preg_replace",
"(",
"'/ +/'",
",",
"$",
"replacement",
",",
"$",
"this",
"->",
"returnValue",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Removes all non alpha numberical characters
@param string $replacement the string to replace non alpha numeric characters
@return self | [
"Removes",
"all",
"non",
"alpha",
"numberical",
"characters"
] | train | https://github.com/guru-digital/framework-types/blob/f14e9b1e6cc2571414ba7d561bb205644e28e17d/GDM/Framework/Types/String.php#L553-L558 |
guru-digital/framework-types | GDM/Framework/Types/String.php | String.split | public function split($delimiter, $limit = null)
{
return is_null($limit) ? explode($delimiter, $this->returnValue) : explode($delimiter, $this->returnValue, $limit);
} | php | public function split($delimiter, $limit = null)
{
return is_null($limit) ? explode($delimiter, $this->returnValue) : explode($delimiter, $this->returnValue, $limit);
} | [
"public",
"function",
"split",
"(",
"$",
"delimiter",
",",
"$",
"limit",
"=",
"null",
")",
"{",
"return",
"is_null",
"(",
"$",
"limit",
")",
"?",
"explode",
"(",
"$",
"delimiter",
",",
"$",
"this",
"->",
"returnValue",
")",
":",
"explode",
"(",
"$",
"delimiter",
",",
"$",
"this",
"->",
"returnValue",
",",
"$",
"limit",
")",
";",
"}"
] | Split a string by string
@link http://php.net/manual/en/function.explode.php
@param string $delimiter <p>
The boundary string.
</p>
@param int $limit [optional] <p>
If <i>limit</i> is set and positive, the returned array will contain
a maximum of <i>limit</i> elements with the last
element containing the rest of <i>string</i>.
</p>
<p>
If the <i>limit</i> parameter is negative, all components
except the last -<i>limit</i> are returned.
</p>
<p>
If the <i>limit</i> parameter is zero, then this is treated as 1.
</p>
@return array an array of strings
created by splitting the <i>string</i> parameter on
boundaries formed by the <i>delimiter</i>.
</p>
<p>
If <i>delimiter</i> is an empty string (""),
<b>explode</b> will return <b>FALSE</b>.
If <i>delimiter</i> contains a value that is not
contained in <i>string</i> and a negative
<i>limit</i> is used, then an empty array will be
returned, otherwise an array containing
<i>string</i> will be returned. | [
"Split",
"a",
"string",
"by",
"string"
] | train | https://github.com/guru-digital/framework-types/blob/f14e9b1e6cc2571414ba7d561bb205644e28e17d/GDM/Framework/Types/String.php#L591-L594 |
guru-digital/framework-types | GDM/Framework/Types/String.php | String.toBool | public function toBool()
{
return (!is_null($this->returnValue)) &&
(!empty($this->returnValue)) &&
(!in_array(strtolower($this->returnValue), $this->falseStrings));
} | php | public function toBool()
{
return (!is_null($this->returnValue)) &&
(!empty($this->returnValue)) &&
(!in_array(strtolower($this->returnValue), $this->falseStrings));
} | [
"public",
"function",
"toBool",
"(",
")",
"{",
"return",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"returnValue",
")",
")",
"&&",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"returnValue",
")",
")",
"&&",
"(",
"!",
"in_array",
"(",
"strtolower",
"(",
"$",
"this",
"->",
"returnValue",
")",
",",
"$",
"this",
"->",
"falseStrings",
")",
")",
";",
"}"
] | Converts this string to a boolean.
@return self | [
"Converts",
"this",
"string",
"to",
"a",
"boolean",
"."
] | train | https://github.com/guru-digital/framework-types/blob/f14e9b1e6cc2571414ba7d561bb205644e28e17d/GDM/Framework/Types/String.php#L612-L617 |
guru-digital/framework-types | GDM/Framework/Types/String.php | String.toComment | public function toComment($mime)
{
$commentStart = "<!--";
$commentEnd = "-->";
switch ($mime) {
case "text/javascript":
case "text/css":
case "application/x-javascript":
$commentStart = "/**";
$commentEnd = "**/";
break;
default:
break;
}
$this->returnValue = $commentStart." ".$this->returnValue." ".$commentEnd;
return $this;
} | php | public function toComment($mime)
{
$commentStart = "<!--";
$commentEnd = "-->";
switch ($mime) {
case "text/javascript":
case "text/css":
case "application/x-javascript":
$commentStart = "/**";
$commentEnd = "**/";
break;
default:
break;
}
$this->returnValue = $commentStart." ".$this->returnValue." ".$commentEnd;
return $this;
} | [
"public",
"function",
"toComment",
"(",
"$",
"mime",
")",
"{",
"$",
"commentStart",
"=",
"\"<!--\"",
";",
"$",
"commentEnd",
"=",
"\"-->\"",
";",
"switch",
"(",
"$",
"mime",
")",
"{",
"case",
"\"text/javascript\"",
":",
"case",
"\"text/css\"",
":",
"case",
"\"application/x-javascript\"",
":",
"$",
"commentStart",
"=",
"\"/**\"",
";",
"$",
"commentEnd",
"=",
"\"**/\"",
";",
"break",
";",
"default",
":",
"break",
";",
"}",
"$",
"this",
"->",
"returnValue",
"=",
"$",
"commentStart",
".",
"\" \"",
".",
"$",
"this",
"->",
"returnValue",
".",
"\" \"",
".",
"$",
"commentEnd",
";",
"return",
"$",
"this",
";",
"}"
] | Wrap this string in a comment block
@param string $mime <p>The mime type of comment type<br>
e.g. <br>
"text/javascript" will be wrapped in /** <i>string</i> **/<br>
"text/html" will be wrapped in <!-- <i>string</i> --><br><br>
Current support mimetypes are text/html, text/javascript, text/css and application/x-javascript </p>
@return self | [
"Wrap",
"this",
"string",
"in",
"a",
"comment",
"block"
] | train | https://github.com/guru-digital/framework-types/blob/f14e9b1e6cc2571414ba7d561bb205644e28e17d/GDM/Framework/Types/String.php#L648-L664 |
guru-digital/framework-types | GDM/Framework/Types/String.php | String.createUUID | public static function createUUID()
{
return self::create(
sprintf(
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
// 32 bits for "time_low"
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
// 16 bits for "time_mid"
mt_rand(0, 0xffff),
// 16 bits for "time_hi_and_version",
// four most significant bits holds version number 4
mt_rand(0, 0x0fff) | 0x4000,
// 16 bits, 8 bits for "clk_seq_hi_res",
// 8 bits for "clk_seq_low",
// two most significant bits holds zero and one for variant DCE1.1
mt_rand(0, 0x3fff) | 0x8000,
// 48 bits for "node"
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
)
);
} | php | public static function createUUID()
{
return self::create(
sprintf(
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
// 32 bits for "time_low"
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
// 16 bits for "time_mid"
mt_rand(0, 0xffff),
// 16 bits for "time_hi_and_version",
// four most significant bits holds version number 4
mt_rand(0, 0x0fff) | 0x4000,
// 16 bits, 8 bits for "clk_seq_hi_res",
// 8 bits for "clk_seq_low",
// two most significant bits holds zero and one for variant DCE1.1
mt_rand(0, 0x3fff) | 0x8000,
// 48 bits for "node"
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
)
);
} | [
"public",
"static",
"function",
"createUUID",
"(",
")",
"{",
"return",
"self",
"::",
"create",
"(",
"sprintf",
"(",
"'%04x%04x-%04x-%04x-%04x-%04x%04x%04x'",
",",
"// 32 bits for \"time_low\"",
"mt_rand",
"(",
"0",
",",
"0xffff",
")",
",",
"mt_rand",
"(",
"0",
",",
"0xffff",
")",
",",
"// 16 bits for \"time_mid\"",
"mt_rand",
"(",
"0",
",",
"0xffff",
")",
",",
"// 16 bits for \"time_hi_and_version\",",
"// four most significant bits holds version number 4",
"mt_rand",
"(",
"0",
",",
"0x0fff",
")",
"|",
"0x4000",
",",
"// 16 bits, 8 bits for \"clk_seq_hi_res\",",
"// 8 bits for \"clk_seq_low\",",
"// two most significant bits holds zero and one for variant DCE1.1",
"mt_rand",
"(",
"0",
",",
"0x3fff",
")",
"|",
"0x8000",
",",
"// 48 bits for \"node\"",
"mt_rand",
"(",
"0",
",",
"0xffff",
")",
",",
"mt_rand",
"(",
"0",
",",
"0xffff",
")",
",",
"mt_rand",
"(",
"0",
",",
"0xffff",
")",
")",
")",
";",
"}"
] | Generates a VALID RFC 4211 COMPLIANT Universally Unique IDentifier (UUID) 4.
@see http://www.php.net/manual/en/function.uniqid.php#94959
@return static | [
"Generates",
"a",
"VALID",
"RFC",
"4211",
"COMPLIANT",
"Universally",
"Unique",
"IDentifier",
"(",
"UUID",
")",
"4",
"."
] | train | https://github.com/guru-digital/framework-types/blob/f14e9b1e6cc2571414ba7d561bb205644e28e17d/GDM/Framework/Types/String.php#L671-L691 |
guru-digital/framework-types | GDM/Framework/Types/String.php | String.createRandomAlphaNumeric | public static function createRandomAlphaNumeric($length = 8)
{
$chars = array("abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", "123456789");
$count = array((strlen($chars[0]) - 1), (strlen($chars[1]) - 1));
$prefix = "";
for ($i = 0; $i < $length; $i++) {
$type = mt_rand(0, 1);
$prefix .= substr($chars[$type], mt_rand(0, $count[$type]), 1);
}
return self::create($prefix);
} | php | public static function createRandomAlphaNumeric($length = 8)
{
$chars = array("abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", "123456789");
$count = array((strlen($chars[0]) - 1), (strlen($chars[1]) - 1));
$prefix = "";
for ($i = 0; $i < $length; $i++) {
$type = mt_rand(0, 1);
$prefix .= substr($chars[$type], mt_rand(0, $count[$type]), 1);
}
return self::create($prefix);
} | [
"public",
"static",
"function",
"createRandomAlphaNumeric",
"(",
"$",
"length",
"=",
"8",
")",
"{",
"$",
"chars",
"=",
"array",
"(",
"\"abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\"",
",",
"\"123456789\"",
")",
";",
"$",
"count",
"=",
"array",
"(",
"(",
"strlen",
"(",
"$",
"chars",
"[",
"0",
"]",
")",
"-",
"1",
")",
",",
"(",
"strlen",
"(",
"$",
"chars",
"[",
"1",
"]",
")",
"-",
"1",
")",
")",
";",
"$",
"prefix",
"=",
"\"\"",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"length",
";",
"$",
"i",
"++",
")",
"{",
"$",
"type",
"=",
"mt_rand",
"(",
"0",
",",
"1",
")",
";",
"$",
"prefix",
".=",
"substr",
"(",
"$",
"chars",
"[",
"$",
"type",
"]",
",",
"mt_rand",
"(",
"0",
",",
"$",
"count",
"[",
"$",
"type",
"]",
")",
",",
"1",
")",
";",
"}",
"return",
"self",
"::",
"create",
"(",
"$",
"prefix",
")",
";",
"}"
] | Generatesa random string
@param int $length [optional] <p>The length of the random string to generate
</p>
@return self | [
"Generatesa",
"random",
"string"
] | train | https://github.com/guru-digital/framework-types/blob/f14e9b1e6cc2571414ba7d561bb205644e28e17d/GDM/Framework/Types/String.php#L699-L709 |
ellipsephp/http | src/Error/ErrorHandler.php | ErrorHandler.register | public function register()
{
set_exception_handler(new ExceptionHandler($this->request, $this->factory));
register_shutdown_function(new ShutdownHandler($this->request, $this->factory));
} | php | public function register()
{
set_exception_handler(new ExceptionHandler($this->request, $this->factory));
register_shutdown_function(new ShutdownHandler($this->request, $this->factory));
} | [
"public",
"function",
"register",
"(",
")",
"{",
"set_exception_handler",
"(",
"new",
"ExceptionHandler",
"(",
"$",
"this",
"->",
"request",
",",
"$",
"this",
"->",
"factory",
")",
")",
";",
"register_shutdown_function",
"(",
"new",
"ShutdownHandler",
"(",
"$",
"this",
"->",
"request",
",",
"$",
"this",
"->",
"factory",
")",
")",
";",
"}"
] | Register the exception handler and the shutdown handler.
@return void | [
"Register",
"the",
"exception",
"handler",
"and",
"the",
"shutdown",
"handler",
"."
] | train | https://github.com/ellipsephp/http/blob/20a2b0ae1d3a149a905b93ae0993203eb7d414e1/src/Error/ErrorHandler.php#L42-L46 |
loopsframework/base | src/Loops/Application/LoopsAdmin/Cache.php | Cache.clear | public function clear() {
$loops = $this->getLoops();
if($loops->getService("cache")->flushAll()) {
$loops->getService("logger")->info("Clearing cache was successful.");
return 0;
}
else {
$loops->getService("logger")->err("Clearing cache failed.");
return 1;
}
} | php | public function clear() {
$loops = $this->getLoops();
if($loops->getService("cache")->flushAll()) {
$loops->getService("logger")->info("Clearing cache was successful.");
return 0;
}
else {
$loops->getService("logger")->err("Clearing cache failed.");
return 1;
}
} | [
"public",
"function",
"clear",
"(",
")",
"{",
"$",
"loops",
"=",
"$",
"this",
"->",
"getLoops",
"(",
")",
";",
"if",
"(",
"$",
"loops",
"->",
"getService",
"(",
"\"cache\"",
")",
"->",
"flushAll",
"(",
")",
")",
"{",
"$",
"loops",
"->",
"getService",
"(",
"\"logger\"",
")",
"->",
"info",
"(",
"\"Clearing cache was successful.\"",
")",
";",
"return",
"0",
";",
"}",
"else",
"{",
"$",
"loops",
"->",
"getService",
"(",
"\"logger\"",
")",
"->",
"err",
"(",
"\"Clearing cache failed.\"",
")",
";",
"return",
"1",
";",
"}",
"}"
] | Calls flushAll on cache
@Action("Clears the Loops cache via the flushAll call.") | [
"Calls",
"flushAll",
"on",
"cache"
] | train | https://github.com/loopsframework/base/blob/5a15172ed4e543d7d5ecd8bd65e31f26bab3d192/src/Loops/Application/LoopsAdmin/Cache.php#L29-L40 |
delznet/phalcon-plus | Delz/PhalconPlus/ServiceProvider/Providers/Url.php | Url.register | public function register()
{
$self = $this;
$this->di->setShared(
$this->serviceName,
function () use ($self) {
/** @var IApp $app */
$app = $self->di->getShared('app');
/** @var IConfig $config */
$config = $self->di->getShared('config');
$url = new BaseUrl();
$url->setBaseUri($config->get('url.' . $app->getModule() . '.base_path', ''));
$url->setStaticVersion($config->get('url.' . $app->getModule() . '.static.version', $app->getVersion()));
$url->setStaticBaseUri($config->get('url.' . $app->getModule() . '.static.base_uri', ''));
return $url;
}
);
} | php | public function register()
{
$self = $this;
$this->di->setShared(
$this->serviceName,
function () use ($self) {
/** @var IApp $app */
$app = $self->di->getShared('app');
/** @var IConfig $config */
$config = $self->di->getShared('config');
$url = new BaseUrl();
$url->setBaseUri($config->get('url.' . $app->getModule() . '.base_path', ''));
$url->setStaticVersion($config->get('url.' . $app->getModule() . '.static.version', $app->getVersion()));
$url->setStaticBaseUri($config->get('url.' . $app->getModule() . '.static.base_uri', ''));
return $url;
}
);
} | [
"public",
"function",
"register",
"(",
")",
"{",
"$",
"self",
"=",
"$",
"this",
";",
"$",
"this",
"->",
"di",
"->",
"setShared",
"(",
"$",
"this",
"->",
"serviceName",
",",
"function",
"(",
")",
"use",
"(",
"$",
"self",
")",
"{",
"/** @var IApp $app */",
"$",
"app",
"=",
"$",
"self",
"->",
"di",
"->",
"getShared",
"(",
"'app'",
")",
";",
"/** @var IConfig $config */",
"$",
"config",
"=",
"$",
"self",
"->",
"di",
"->",
"getShared",
"(",
"'config'",
")",
";",
"$",
"url",
"=",
"new",
"BaseUrl",
"(",
")",
";",
"$",
"url",
"->",
"setBaseUri",
"(",
"$",
"config",
"->",
"get",
"(",
"'url.'",
".",
"$",
"app",
"->",
"getModule",
"(",
")",
".",
"'.base_path'",
",",
"''",
")",
")",
";",
"$",
"url",
"->",
"setStaticVersion",
"(",
"$",
"config",
"->",
"get",
"(",
"'url.'",
".",
"$",
"app",
"->",
"getModule",
"(",
")",
".",
"'.static.version'",
",",
"$",
"app",
"->",
"getVersion",
"(",
")",
")",
")",
";",
"$",
"url",
"->",
"setStaticBaseUri",
"(",
"$",
"config",
"->",
"get",
"(",
"'url.'",
".",
"$",
"app",
"->",
"getModule",
"(",
")",
".",
"'.static.base_uri'",
",",
"''",
")",
")",
";",
"return",
"$",
"url",
";",
"}",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/delznet/phalcon-plus/blob/d7c118929bdaeeb63ce404ba72095397a39f82fe/Delz/PhalconPlus/ServiceProvider/Providers/Url.php#L29-L46 |
liverbool/dos-resource-bundle | Twig/Extension/Generic.php | Generic.getSettingsParameter | public function getSettingsParameter($key, $default = null)
{
list($alias, $key) = explode('.', $key);
$settings = $this->container->get('sylius.templating.helper.settings')
->getSettings($alias)
;
if (array_key_exists($key, $settings)) {
return $settings[$key];
}
return $default;
} | php | public function getSettingsParameter($key, $default = null)
{
list($alias, $key) = explode('.', $key);
$settings = $this->container->get('sylius.templating.helper.settings')
->getSettings($alias)
;
if (array_key_exists($key, $settings)) {
return $settings[$key];
}
return $default;
} | [
"public",
"function",
"getSettingsParameter",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"list",
"(",
"$",
"alias",
",",
"$",
"key",
")",
"=",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
";",
"$",
"settings",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'sylius.templating.helper.settings'",
")",
"->",
"getSettings",
"(",
"$",
"alias",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"settings",
")",
")",
"{",
"return",
"$",
"settings",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"$",
"default",
";",
"}"
] | @param $key
@param string $default
@return null|mixed | [
"@param",
"$key",
"@param",
"string",
"$default"
] | train | https://github.com/liverbool/dos-resource-bundle/blob/c8607a46c2cea80cc138994be74f4dea3c197abc/Twig/Extension/Generic.php#L75-L88 |
liverbool/dos-resource-bundle | Twig/Extension/Generic.php | Generic.calculatePercent | public function calculatePercent($total, $pie)
{
if (empty($total)) {
return '0%';
}
$total = ($pie / $total) * 100;
if (is_float($total)) {
return number_format($total, 1).'%';
}
return $total.'%';
} | php | public function calculatePercent($total, $pie)
{
if (empty($total)) {
return '0%';
}
$total = ($pie / $total) * 100;
if (is_float($total)) {
return number_format($total, 1).'%';
}
return $total.'%';
} | [
"public",
"function",
"calculatePercent",
"(",
"$",
"total",
",",
"$",
"pie",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"total",
")",
")",
"{",
"return",
"'0%'",
";",
"}",
"$",
"total",
"=",
"(",
"$",
"pie",
"/",
"$",
"total",
")",
"*",
"100",
";",
"if",
"(",
"is_float",
"(",
"$",
"total",
")",
")",
"{",
"return",
"number_format",
"(",
"$",
"total",
",",
"1",
")",
".",
"'%'",
";",
"}",
"return",
"$",
"total",
".",
"'%'",
";",
"}"
] | @param $total
@param $pie
@return string | [
"@param",
"$total",
"@param",
"$pie"
] | train | https://github.com/liverbool/dos-resource-bundle/blob/c8607a46c2cea80cc138994be74f4dea3c197abc/Twig/Extension/Generic.php#L108-L121 |
liverbool/dos-resource-bundle | Twig/Extension/Generic.php | Generic.getObfuscatedEmail | public function getObfuscatedEmail($email)
{
if (false !== $pos = strpos($email, '@')) {
$email = '...'.substr($email, $pos);
}
return $email;
} | php | public function getObfuscatedEmail($email)
{
if (false !== $pos = strpos($email, '@')) {
$email = '...'.substr($email, $pos);
}
return $email;
} | [
"public",
"function",
"getObfuscatedEmail",
"(",
"$",
"email",
")",
"{",
"if",
"(",
"false",
"!==",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"email",
",",
"'@'",
")",
")",
"{",
"$",
"email",
"=",
"'...'",
".",
"substr",
"(",
"$",
"email",
",",
"$",
"pos",
")",
";",
"}",
"return",
"$",
"email",
";",
"}"
] | @param $email
@return string | [
"@param",
"$email"
] | train | https://github.com/liverbool/dos-resource-bundle/blob/c8607a46c2cea80cc138994be74f4dea3c197abc/Twig/Extension/Generic.php#L128-L135 |
liverbool/dos-resource-bundle | Twig/Extension/Generic.php | Generic.getContextValue | public function getContextValue($context, $path)
{
$accessor = PropertyAccess::createPropertyAccessor();
return $accessor->getValue($context, $path);
} | php | public function getContextValue($context, $path)
{
$accessor = PropertyAccess::createPropertyAccessor();
return $accessor->getValue($context, $path);
} | [
"public",
"function",
"getContextValue",
"(",
"$",
"context",
",",
"$",
"path",
")",
"{",
"$",
"accessor",
"=",
"PropertyAccess",
"::",
"createPropertyAccessor",
"(",
")",
";",
"return",
"$",
"accessor",
"->",
"getValue",
"(",
"$",
"context",
",",
"$",
"path",
")",
";",
"}"
] | @param $context
@param $path
@return mixed | [
"@param",
"$context",
"@param",
"$path"
] | train | https://github.com/liverbool/dos-resource-bundle/blob/c8607a46c2cea80cc138994be74f4dea3c197abc/Twig/Extension/Generic.php#L143-L148 |
Evozon-PHP/TissueClamavAdapter | ClamAvAdapter.php | ClamAvAdapter.detect | protected function detect(string $path): ?Detection
{
$process = $this->createProcess($path);
$returnCode = $process->run();
$output = trim($process->getOutput());
if (0 !== $returnCode && false === strpos($output, ' FOUND')) {
throw AdapterException::fromProcess($process);
}
foreach (explode("\n", $output) as $line) {
if (substr($line, -6) === ' FOUND') {
$file = substr($line, 0, strrpos($line, ':'));
$description = substr(substr($line, strrpos($line, ':') + 2), 0, -6);
return $this->createDetection($file, Detection::TYPE_VIRUS, $description);
}
}
return null;
} | php | protected function detect(string $path): ?Detection
{
$process = $this->createProcess($path);
$returnCode = $process->run();
$output = trim($process->getOutput());
if (0 !== $returnCode && false === strpos($output, ' FOUND')) {
throw AdapterException::fromProcess($process);
}
foreach (explode("\n", $output) as $line) {
if (substr($line, -6) === ' FOUND') {
$file = substr($line, 0, strrpos($line, ':'));
$description = substr(substr($line, strrpos($line, ':') + 2), 0, -6);
return $this->createDetection($file, Detection::TYPE_VIRUS, $description);
}
}
return null;
} | [
"protected",
"function",
"detect",
"(",
"string",
"$",
"path",
")",
":",
"?",
"Detection",
"{",
"$",
"process",
"=",
"$",
"this",
"->",
"createProcess",
"(",
"$",
"path",
")",
";",
"$",
"returnCode",
"=",
"$",
"process",
"->",
"run",
"(",
")",
";",
"$",
"output",
"=",
"trim",
"(",
"$",
"process",
"->",
"getOutput",
"(",
")",
")",
";",
"if",
"(",
"0",
"!==",
"$",
"returnCode",
"&&",
"false",
"===",
"strpos",
"(",
"$",
"output",
",",
"' FOUND'",
")",
")",
"{",
"throw",
"AdapterException",
"::",
"fromProcess",
"(",
"$",
"process",
")",
";",
"}",
"foreach",
"(",
"explode",
"(",
"\"\\n\"",
",",
"$",
"output",
")",
"as",
"$",
"line",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"line",
",",
"-",
"6",
")",
"===",
"' FOUND'",
")",
"{",
"$",
"file",
"=",
"substr",
"(",
"$",
"line",
",",
"0",
",",
"strrpos",
"(",
"$",
"line",
",",
"':'",
")",
")",
";",
"$",
"description",
"=",
"substr",
"(",
"substr",
"(",
"$",
"line",
",",
"strrpos",
"(",
"$",
"line",
",",
"':'",
")",
"+",
"2",
")",
",",
"0",
",",
"-",
"6",
")",
";",
"return",
"$",
"this",
"->",
"createDetection",
"(",
"$",
"file",
",",
"Detection",
"::",
"TYPE_VIRUS",
",",
"$",
"description",
")",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | {@inheritdoc}
@throws \CL\Tissue\Exception\AdapterException | [
"{"
] | train | https://github.com/Evozon-PHP/TissueClamavAdapter/blob/d489e7324ca6082d0a32c103acd621d7af488119/ClamAvAdapter.php#L45-L64 |
Evozon-PHP/TissueClamavAdapter | ClamAvAdapter.php | ClamAvAdapter.createProcess | private function createProcess(string $path): Process
{
$pb = $this->createProcessBuilder([$this->clamScanPath]);
$pb->add('--no-summary');
if ($this->usesDaemon($this->clamScanPath)) {
// Pass filedescriptor to clamd (useful if clamd is running as a different user)
$pb->add('--fdpass');
} elseif ($this->databasePath !== null) {
// Only the (isolated) binary version can change the signature-database used
$pb->add(sprintf('--database=%s', $this->databasePath));
}
$pb->add($path);
return $pb->getProcess();
} | php | private function createProcess(string $path): Process
{
$pb = $this->createProcessBuilder([$this->clamScanPath]);
$pb->add('--no-summary');
if ($this->usesDaemon($this->clamScanPath)) {
// Pass filedescriptor to clamd (useful if clamd is running as a different user)
$pb->add('--fdpass');
} elseif ($this->databasePath !== null) {
// Only the (isolated) binary version can change the signature-database used
$pb->add(sprintf('--database=%s', $this->databasePath));
}
$pb->add($path);
return $pb->getProcess();
} | [
"private",
"function",
"createProcess",
"(",
"string",
"$",
"path",
")",
":",
"Process",
"{",
"$",
"pb",
"=",
"$",
"this",
"->",
"createProcessBuilder",
"(",
"[",
"$",
"this",
"->",
"clamScanPath",
"]",
")",
";",
"$",
"pb",
"->",
"add",
"(",
"'--no-summary'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"usesDaemon",
"(",
"$",
"this",
"->",
"clamScanPath",
")",
")",
"{",
"// Pass filedescriptor to clamd (useful if clamd is running as a different user)",
"$",
"pb",
"->",
"add",
"(",
"'--fdpass'",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"databasePath",
"!==",
"null",
")",
"{",
"// Only the (isolated) binary version can change the signature-database used",
"$",
"pb",
"->",
"add",
"(",
"sprintf",
"(",
"'--database=%s'",
",",
"$",
"this",
"->",
"databasePath",
")",
")",
";",
"}",
"$",
"pb",
"->",
"add",
"(",
"$",
"path",
")",
";",
"return",
"$",
"pb",
"->",
"getProcess",
"(",
")",
";",
"}"
] | @param string $path
@return Process | [
"@param",
"string",
"$path"
] | train | https://github.com/Evozon-PHP/TissueClamavAdapter/blob/d489e7324ca6082d0a32c103acd621d7af488119/ClamAvAdapter.php#L71-L87 |
headzoo/core | src/Headzoo/Core/Strings.php | Strings.setUseMultiByte | public static function setUseMultiByte($use_mbstring)
{
if ($use_mbstring) {
if (!extension_loaded(self::$__mbstring_extension_name)) {
self::toss(
"RuntimeException",
"The '{0}' extension must be enabled.",
self::$__mbstring_extension_name
);
}
self::$use_mbstring = true;
if (!self::$char_set) {
self::$char_set = self::getDefaultCharacterSet();
}
} else {
self::$use_mbstring = false;
}
} | php | public static function setUseMultiByte($use_mbstring)
{
if ($use_mbstring) {
if (!extension_loaded(self::$__mbstring_extension_name)) {
self::toss(
"RuntimeException",
"The '{0}' extension must be enabled.",
self::$__mbstring_extension_name
);
}
self::$use_mbstring = true;
if (!self::$char_set) {
self::$char_set = self::getDefaultCharacterSet();
}
} else {
self::$use_mbstring = false;
}
} | [
"public",
"static",
"function",
"setUseMultiByte",
"(",
"$",
"use_mbstring",
")",
"{",
"if",
"(",
"$",
"use_mbstring",
")",
"{",
"if",
"(",
"!",
"extension_loaded",
"(",
"self",
"::",
"$",
"__mbstring_extension_name",
")",
")",
"{",
"self",
"::",
"toss",
"(",
"\"RuntimeException\"",
",",
"\"The '{0}' extension must be enabled.\"",
",",
"self",
"::",
"$",
"__mbstring_extension_name",
")",
";",
"}",
"self",
"::",
"$",
"use_mbstring",
"=",
"true",
";",
"if",
"(",
"!",
"self",
"::",
"$",
"char_set",
")",
"{",
"self",
"::",
"$",
"char_set",
"=",
"self",
"::",
"getDefaultCharacterSet",
"(",
")",
";",
"}",
"}",
"else",
"{",
"self",
"::",
"$",
"use_mbstring",
"=",
"false",
";",
"}",
"}"
] | Sets whether to use the "mbstring" extension for string operations
The "mbstring" extension must be loaded when set to true. An exception is thrown if the extension
is not loaded. When set to false, the mbstring extension will not be used even if the
extension is loaded.
When turned on with true, the character set used by methods of this class will be set to the return
value of ::getDefaultCharacterSet(). Use the ::setCharacterSet() method to set a different character set.
See the ::getDefaultCharacterSet() method for more information.
@param bool $use_mbstring Whether to use the multi-byte extension
@throws \Headzoo\Core\Exceptions\RuntimeException If the "mbstring" extension is not loaded | [
"Sets",
"whether",
"to",
"use",
"the",
"mbstring",
"extension",
"for",
"string",
"operations"
] | train | https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/Strings.php#L147-L164 |
headzoo/core | src/Headzoo/Core/Strings.php | Strings.setCharacterSet | public static function setCharacterSet($char_set)
{
$default = self::getDefaultCharacterSet();
$char_set = $char_set ? strtoupper($char_set) : $default;
$available = array_map("strtoupper", mb_list_encodings());
$is_valid = false;
foreach($available as $a) {
if ($a === $char_set) {
$is_valid = true;
break;
} else if (str_replace("-", "", $a) === $char_set) {
$char_set = $a;
$is_valid = true;
break;
}
}
if (!$is_valid) {
self::toss(
"InvalidArgumentException",
"Value '{0}' is not a valid character set name.",
$char_set
);
}
$mb_required = ["ASCII", "ISO-8859-1", $default];
if (!self::$use_mbstring && !in_array($char_set, $mb_required)) {
self::setUseMultiByte(true);
}
self::$char_set = $char_set;
} | php | public static function setCharacterSet($char_set)
{
$default = self::getDefaultCharacterSet();
$char_set = $char_set ? strtoupper($char_set) : $default;
$available = array_map("strtoupper", mb_list_encodings());
$is_valid = false;
foreach($available as $a) {
if ($a === $char_set) {
$is_valid = true;
break;
} else if (str_replace("-", "", $a) === $char_set) {
$char_set = $a;
$is_valid = true;
break;
}
}
if (!$is_valid) {
self::toss(
"InvalidArgumentException",
"Value '{0}' is not a valid character set name.",
$char_set
);
}
$mb_required = ["ASCII", "ISO-8859-1", $default];
if (!self::$use_mbstring && !in_array($char_set, $mb_required)) {
self::setUseMultiByte(true);
}
self::$char_set = $char_set;
} | [
"public",
"static",
"function",
"setCharacterSet",
"(",
"$",
"char_set",
")",
"{",
"$",
"default",
"=",
"self",
"::",
"getDefaultCharacterSet",
"(",
")",
";",
"$",
"char_set",
"=",
"$",
"char_set",
"?",
"strtoupper",
"(",
"$",
"char_set",
")",
":",
"$",
"default",
";",
"$",
"available",
"=",
"array_map",
"(",
"\"strtoupper\"",
",",
"mb_list_encodings",
"(",
")",
")",
";",
"$",
"is_valid",
"=",
"false",
";",
"foreach",
"(",
"$",
"available",
"as",
"$",
"a",
")",
"{",
"if",
"(",
"$",
"a",
"===",
"$",
"char_set",
")",
"{",
"$",
"is_valid",
"=",
"true",
";",
"break",
";",
"}",
"else",
"if",
"(",
"str_replace",
"(",
"\"-\"",
",",
"\"\"",
",",
"$",
"a",
")",
"===",
"$",
"char_set",
")",
"{",
"$",
"char_set",
"=",
"$",
"a",
";",
"$",
"is_valid",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"is_valid",
")",
"{",
"self",
"::",
"toss",
"(",
"\"InvalidArgumentException\"",
",",
"\"Value '{0}' is not a valid character set name.\"",
",",
"$",
"char_set",
")",
";",
"}",
"$",
"mb_required",
"=",
"[",
"\"ASCII\"",
",",
"\"ISO-8859-1\"",
",",
"$",
"default",
"]",
";",
"if",
"(",
"!",
"self",
"::",
"$",
"use_mbstring",
"&&",
"!",
"in_array",
"(",
"$",
"char_set",
",",
"$",
"mb_required",
")",
")",
"{",
"self",
"::",
"setUseMultiByte",
"(",
"true",
")",
";",
"}",
"self",
"::",
"$",
"char_set",
"=",
"$",
"char_set",
";",
"}"
] | Sets the character set this class uses for string operations
The value of $char_set must be a valid character set name as defined by mb_list_encodings(), but the
name may use any case and omit dashes. For example these are all valid character set
names: "UTF-8", "utf-8", "UTF8", "utf8". The name of the encoding will be converted to it's proper
name.
Note: The return value from ::getDefaultCharSet() will be used when $char_set is empty. See that method
for more information.
Calling this method with any value other than "ASCII", "ISO-8859-1", empty, or the return value
from ::getDefaultCharacterSet() will automatically call ::setUseMultiByte(true) to turn on the use of
the "mbstring" extension. See the documentation on ::setUseMultiByte() for more information.
Note: This method does not change php's default internal encoding, eg by calling mb_internal_encoding().
It only affects the encoding used when calling methods of this class.
@param string $char_set The name of the character encoding
@throws \Headzoo\Core\Exceptions\InvalidArgumentException If $encoding is not a valid encoding name
@throws \Headzoo\Core\Exceptions\RuntimeException If the "mbstring" extension is not loaded | [
"Sets",
"the",
"character",
"set",
"this",
"class",
"uses",
"for",
"string",
"operations"
] | train | https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/Strings.php#L188-L218 |
headzoo/core | src/Headzoo/Core/Strings.php | Strings.random | public static function random($len, $char_class = null)
{
if (null === $char_class) {
$char_class = self::CHARS_LOWER | self::CHARS_UPPER | self::CHARS_NUMBERS;
}
$chars = null;
if ($char_class & self::CHARS_LOWER) {
$chars .= self::$chars_lower;
}
if ($char_class & self::CHARS_UPPER) {
$chars .= self::$chars_upper;
}
if ($char_class & self::CHARS_NUMBERS) {
$chars .= self::$chars_numbers;
}
if ($char_class & self::CHARS_PUNCTUATION) {
$chars .= self::$chars_punctuation;
}
$char_count = strlen($chars) - 1;
$str = null;
for($i = 0; $i < $len; $i++) {
$rand = mt_rand(0, $char_count);
$str .= $chars[$rand];
}
return $str;
} | php | public static function random($len, $char_class = null)
{
if (null === $char_class) {
$char_class = self::CHARS_LOWER | self::CHARS_UPPER | self::CHARS_NUMBERS;
}
$chars = null;
if ($char_class & self::CHARS_LOWER) {
$chars .= self::$chars_lower;
}
if ($char_class & self::CHARS_UPPER) {
$chars .= self::$chars_upper;
}
if ($char_class & self::CHARS_NUMBERS) {
$chars .= self::$chars_numbers;
}
if ($char_class & self::CHARS_PUNCTUATION) {
$chars .= self::$chars_punctuation;
}
$char_count = strlen($chars) - 1;
$str = null;
for($i = 0; $i < $len; $i++) {
$rand = mt_rand(0, $char_count);
$str .= $chars[$rand];
}
return $str;
} | [
"public",
"static",
"function",
"random",
"(",
"$",
"len",
",",
"$",
"char_class",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"char_class",
")",
"{",
"$",
"char_class",
"=",
"self",
"::",
"CHARS_LOWER",
"|",
"self",
"::",
"CHARS_UPPER",
"|",
"self",
"::",
"CHARS_NUMBERS",
";",
"}",
"$",
"chars",
"=",
"null",
";",
"if",
"(",
"$",
"char_class",
"&",
"self",
"::",
"CHARS_LOWER",
")",
"{",
"$",
"chars",
".=",
"self",
"::",
"$",
"chars_lower",
";",
"}",
"if",
"(",
"$",
"char_class",
"&",
"self",
"::",
"CHARS_UPPER",
")",
"{",
"$",
"chars",
".=",
"self",
"::",
"$",
"chars_upper",
";",
"}",
"if",
"(",
"$",
"char_class",
"&",
"self",
"::",
"CHARS_NUMBERS",
")",
"{",
"$",
"chars",
".=",
"self",
"::",
"$",
"chars_numbers",
";",
"}",
"if",
"(",
"$",
"char_class",
"&",
"self",
"::",
"CHARS_PUNCTUATION",
")",
"{",
"$",
"chars",
".=",
"self",
"::",
"$",
"chars_punctuation",
";",
"}",
"$",
"char_count",
"=",
"strlen",
"(",
"$",
"chars",
")",
"-",
"1",
";",
"$",
"str",
"=",
"null",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"len",
";",
"$",
"i",
"++",
")",
"{",
"$",
"rand",
"=",
"mt_rand",
"(",
"0",
",",
"$",
"char_count",
")",
";",
"$",
"str",
".=",
"$",
"chars",
"[",
"$",
"rand",
"]",
";",
"}",
"return",
"$",
"str",
";",
"}"
] | Returns a completely random string $len characters long
The $char_class argument controls which class of characters will be used
in the random string: lower case letters, upper case letters, numbers,
and punctuation. Use the self::CHARS constants and bitwise OR to
specify several character classes.
Example:
```php
Strings::random(10, Strings::CHARS_LOWER | Strings::CHARS_UPPER);
```
The return value will container lower case and upper case letters. By
default the character class used is
(Strings::CHARS_LOWER | Strings::CHARS_UPPER | Strings::CHARS_NUMBERS),
which is every character except punctuation.
The return value will never contain characters "i", "I", "l", "L", "O", 0 and
"1".
@param int $len Length of the string to return
@param int $char_class Class of characters to use
@return string | [
"Returns",
"a",
"completely",
"random",
"string",
"$len",
"characters",
"long"
] | train | https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/Strings.php#L286-L314 |
headzoo/core | src/Headzoo/Core/Strings.php | Strings.camelCaseToUnderscore | public static function camelCaseToUnderscore($str)
{
$under = "";
$chars = self::chars($str);
$lower = false;
$upper = false;
foreach($chars as $char) {
if ("_" !== $char && "-" !== $char) {
if (self::startsUpper($char)) {
$under .= ($lower || $upper) ? "_{$char}" : $char;
$lower = false;
$upper = true;
} else {
$under .= $char;
$lower = true;
$upper = false;
}
}
}
return self::toLower($under);
} | php | public static function camelCaseToUnderscore($str)
{
$under = "";
$chars = self::chars($str);
$lower = false;
$upper = false;
foreach($chars as $char) {
if ("_" !== $char && "-" !== $char) {
if (self::startsUpper($char)) {
$under .= ($lower || $upper) ? "_{$char}" : $char;
$lower = false;
$upper = true;
} else {
$under .= $char;
$lower = true;
$upper = false;
}
}
}
return self::toLower($under);
} | [
"public",
"static",
"function",
"camelCaseToUnderscore",
"(",
"$",
"str",
")",
"{",
"$",
"under",
"=",
"\"\"",
";",
"$",
"chars",
"=",
"self",
"::",
"chars",
"(",
"$",
"str",
")",
";",
"$",
"lower",
"=",
"false",
";",
"$",
"upper",
"=",
"false",
";",
"foreach",
"(",
"$",
"chars",
"as",
"$",
"char",
")",
"{",
"if",
"(",
"\"_\"",
"!==",
"$",
"char",
"&&",
"\"-\"",
"!==",
"$",
"char",
")",
"{",
"if",
"(",
"self",
"::",
"startsUpper",
"(",
"$",
"char",
")",
")",
"{",
"$",
"under",
".=",
"(",
"$",
"lower",
"||",
"$",
"upper",
")",
"?",
"\"_{$char}\"",
":",
"$",
"char",
";",
"$",
"lower",
"=",
"false",
";",
"$",
"upper",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"under",
".=",
"$",
"char",
";",
"$",
"lower",
"=",
"true",
";",
"$",
"upper",
"=",
"false",
";",
"}",
"}",
"}",
"return",
"self",
"::",
"toLower",
"(",
"$",
"under",
")",
";",
"}"
] | Transforms a string with CamelCaseText into a string with underscore_text
Note: The method also treats dashes "-" as underscores.
Example:
```php
echo Strings::camelCaseToUnderscore("CamelCaseString");
// Outputs: "camel_case_string"
echo Strings::camelCaseToUnderscore("MaryHadALittleLamb");
// Outputs: "mary_had_a_little_lamb"
```
@param string $str The string to transform
@return string | [
"Transforms",
"a",
"string",
"with",
"CamelCaseText",
"into",
"a",
"string",
"with",
"underscore_text"
] | train | https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/Strings.php#L333-L354 |
headzoo/core | src/Headzoo/Core/Strings.php | Strings.underscoreToCamelCase | public static function underscoreToCamelCase($str)
{
$str = self::replace($str, "_", " ");
$str = self::replace($str, "-", " ");
$str = self::title($str);
return self::replace($str, " ", "");
} | php | public static function underscoreToCamelCase($str)
{
$str = self::replace($str, "_", " ");
$str = self::replace($str, "-", " ");
$str = self::title($str);
return self::replace($str, " ", "");
} | [
"public",
"static",
"function",
"underscoreToCamelCase",
"(",
"$",
"str",
")",
"{",
"$",
"str",
"=",
"self",
"::",
"replace",
"(",
"$",
"str",
",",
"\"_\"",
",",
"\" \"",
")",
";",
"$",
"str",
"=",
"self",
"::",
"replace",
"(",
"$",
"str",
",",
"\"-\"",
",",
"\" \"",
")",
";",
"$",
"str",
"=",
"self",
"::",
"title",
"(",
"$",
"str",
")",
";",
"return",
"self",
"::",
"replace",
"(",
"$",
"str",
",",
"\" \"",
",",
"\"\"",
")",
";",
"}"
] | Transforms a string with underscore_text into a string with CamelCaseText
Note: The method also treats dashes "-" as underscores.
Example:
```php
echo Strings::underscoreToCamelCase("camel_case_string");
// Outputs: "CamelCaseString"
$str = Strings::underscoreToCamelCase("camel-case-string");
// Outputs: "CamelCaseString"
```
@param string $str The string to transform
@return string | [
"Transforms",
"a",
"string",
"with",
"underscore_text",
"into",
"a",
"string",
"with",
"CamelCaseText"
] | train | https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/Strings.php#L373-L379 |