repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
opis-colibri/core | src/Module.php | Module.resolveInstaller | protected function resolveInstaller(): ?string
{
$value = $this->getModuleInfo()['installer'] ?? null;
return is_string($value) ? $value : null;
} | php | protected function resolveInstaller(): ?string
{
$value = $this->getModuleInfo()['installer'] ?? null;
return is_string($value) ? $value : null;
} | [
"protected",
"function",
"resolveInstaller",
"(",
")",
":",
"?",
"string",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"getModuleInfo",
"(",
")",
"[",
"'installer'",
"]",
"??",
"null",
";",
"return",
"is_string",
"(",
"$",
"value",
")",
"?",
"$",
"value",
":",
"null",
";",
"}"
] | Resolve installer class
@return string|null | [
"Resolve",
"installer",
"class"
] | 77efaf8e2034293588d3759e0b8711e96757d954 | https://github.com/opis-colibri/core/blob/77efaf8e2034293588d3759e0b8711e96757d954/src/Module.php#L399-L404 | train |
opis-colibri/core | src/Module.php | Module.resolveAssets | protected function resolveAssets(): ?string
{
$module = $this->getModuleInfo();
if (!isset($module['assets'])) {
return null;
}
$directory = $this->directory() . DIRECTORY_SEPARATOR . trim($module['assets'], DIRECTORY_SEPARATOR);
return is_dir($directory) ? realpath($directory) : null;
} | php | protected function resolveAssets(): ?string
{
$module = $this->getModuleInfo();
if (!isset($module['assets'])) {
return null;
}
$directory = $this->directory() . DIRECTORY_SEPARATOR . trim($module['assets'], DIRECTORY_SEPARATOR);
return is_dir($directory) ? realpath($directory) : null;
} | [
"protected",
"function",
"resolveAssets",
"(",
")",
":",
"?",
"string",
"{",
"$",
"module",
"=",
"$",
"this",
"->",
"getModuleInfo",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"module",
"[",
"'assets'",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"directory",
"=",
"$",
"this",
"->",
"directory",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"trim",
"(",
"$",
"module",
"[",
"'assets'",
"]",
",",
"DIRECTORY_SEPARATOR",
")",
";",
"return",
"is_dir",
"(",
"$",
"directory",
")",
"?",
"realpath",
"(",
"$",
"directory",
")",
":",
"null",
";",
"}"
] | Resolve assets dir
@return string|null | [
"Resolve",
"assets",
"dir"
] | 77efaf8e2034293588d3759e0b8711e96757d954 | https://github.com/opis-colibri/core/blob/77efaf8e2034293588d3759e0b8711e96757d954/src/Module.php#L411-L419 | train |
ekyna/Table | Extension/AbstractTableExtension.php | AbstractTableExtension.initTableTypes | private function initTableTypes()
{
$this->tableTypes = [];
foreach ($this->loadTableTypes() as $type) {
if (!$type instanceof TableTypeInterface) {
throw new UnexpectedTypeException($type, TableTypeInterface::class);
}
$this->tableTypes[get_class($type)] = $type;
}
} | php | private function initTableTypes()
{
$this->tableTypes = [];
foreach ($this->loadTableTypes() as $type) {
if (!$type instanceof TableTypeInterface) {
throw new UnexpectedTypeException($type, TableTypeInterface::class);
}
$this->tableTypes[get_class($type)] = $type;
}
} | [
"private",
"function",
"initTableTypes",
"(",
")",
"{",
"$",
"this",
"->",
"tableTypes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"loadTableTypes",
"(",
")",
"as",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"$",
"type",
"instanceof",
"TableTypeInterface",
")",
"{",
"throw",
"new",
"UnexpectedTypeException",
"(",
"$",
"type",
",",
"TableTypeInterface",
"::",
"class",
")",
";",
"}",
"$",
"this",
"->",
"tableTypes",
"[",
"get_class",
"(",
"$",
"type",
")",
"]",
"=",
"$",
"type",
";",
"}",
"}"
] | Initializes the table types.
@throws UnexpectedTypeException if any registered type is not an instance of TableTypeInterface | [
"Initializes",
"the",
"table",
"types",
"."
] | 6f06e8fd8a3248d52f3a91f10508471344db311a | https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/Extension/AbstractTableExtension.php#L432-L443 | train |
ekyna/Table | Extension/AbstractTableExtension.php | AbstractTableExtension.initTableTypeExtensions | private function initTableTypeExtensions()
{
$this->tableTypeExtensions = [];
foreach ($this->loadTableTypeExtensions() as $extension) {
if (!$extension instanceof TableTypeExtensionInterface) {
throw new UnexpectedTypeException($extension, TableTypeExtensionInterface::class);
}
$type = $extension->getExtendedType();
$this->tableTypeExtensions[$type][] = $extension;
}
} | php | private function initTableTypeExtensions()
{
$this->tableTypeExtensions = [];
foreach ($this->loadTableTypeExtensions() as $extension) {
if (!$extension instanceof TableTypeExtensionInterface) {
throw new UnexpectedTypeException($extension, TableTypeExtensionInterface::class);
}
$type = $extension->getExtendedType();
$this->tableTypeExtensions[$type][] = $extension;
}
} | [
"private",
"function",
"initTableTypeExtensions",
"(",
")",
"{",
"$",
"this",
"->",
"tableTypeExtensions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"loadTableTypeExtensions",
"(",
")",
"as",
"$",
"extension",
")",
"{",
"if",
"(",
"!",
"$",
"extension",
"instanceof",
"TableTypeExtensionInterface",
")",
"{",
"throw",
"new",
"UnexpectedTypeException",
"(",
"$",
"extension",
",",
"TableTypeExtensionInterface",
"::",
"class",
")",
";",
"}",
"$",
"type",
"=",
"$",
"extension",
"->",
"getExtendedType",
"(",
")",
";",
"$",
"this",
"->",
"tableTypeExtensions",
"[",
"$",
"type",
"]",
"[",
"]",
"=",
"$",
"extension",
";",
"}",
"}"
] | Initializes the table type extensions.
@throws UnexpectedTypeException if any registered type extension is not
an instance of FormTypeExtensionInterface | [
"Initializes",
"the",
"table",
"type",
"extensions",
"."
] | 6f06e8fd8a3248d52f3a91f10508471344db311a | https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/Extension/AbstractTableExtension.php#L451-L464 | train |
ekyna/Table | Extension/AbstractTableExtension.php | AbstractTableExtension.initColumnTypes | private function initColumnTypes()
{
$this->columnTypes = [];
foreach ($this->loadColumnTypes() as $type) {
if (!$type instanceof ColumnTypeInterface) {
throw new UnexpectedTypeException($type, ColumnTypeInterface::class);
}
$this->columnTypes[get_class($type)] = $type;
}
} | php | private function initColumnTypes()
{
$this->columnTypes = [];
foreach ($this->loadColumnTypes() as $type) {
if (!$type instanceof ColumnTypeInterface) {
throw new UnexpectedTypeException($type, ColumnTypeInterface::class);
}
$this->columnTypes[get_class($type)] = $type;
}
} | [
"private",
"function",
"initColumnTypes",
"(",
")",
"{",
"$",
"this",
"->",
"columnTypes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"loadColumnTypes",
"(",
")",
"as",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"$",
"type",
"instanceof",
"ColumnTypeInterface",
")",
"{",
"throw",
"new",
"UnexpectedTypeException",
"(",
"$",
"type",
",",
"ColumnTypeInterface",
"::",
"class",
")",
";",
"}",
"$",
"this",
"->",
"columnTypes",
"[",
"get_class",
"(",
"$",
"type",
")",
"]",
"=",
"$",
"type",
";",
"}",
"}"
] | Initializes the column types.
@throws UnexpectedTypeException if any registered type is not an instance of ColumnTypeInterface | [
"Initializes",
"the",
"column",
"types",
"."
] | 6f06e8fd8a3248d52f3a91f10508471344db311a | https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/Extension/AbstractTableExtension.php#L471-L482 | train |
ekyna/Table | Extension/AbstractTableExtension.php | AbstractTableExtension.initColumnTypeExtensions | private function initColumnTypeExtensions()
{
$this->columnTypeExtensions = [];
foreach ($this->loadColumnTypeExtensions() as $extension) {
if (!$extension instanceof ColumnTypeExtensionInterface) {
throw new UnexpectedTypeException($extension, ColumnTypeExtensionInterface::class);
}
$type = $extension->getExtendedType();
$this->columnTypeExtensions[$type][] = $extension;
}
} | php | private function initColumnTypeExtensions()
{
$this->columnTypeExtensions = [];
foreach ($this->loadColumnTypeExtensions() as $extension) {
if (!$extension instanceof ColumnTypeExtensionInterface) {
throw new UnexpectedTypeException($extension, ColumnTypeExtensionInterface::class);
}
$type = $extension->getExtendedType();
$this->columnTypeExtensions[$type][] = $extension;
}
} | [
"private",
"function",
"initColumnTypeExtensions",
"(",
")",
"{",
"$",
"this",
"->",
"columnTypeExtensions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"loadColumnTypeExtensions",
"(",
")",
"as",
"$",
"extension",
")",
"{",
"if",
"(",
"!",
"$",
"extension",
"instanceof",
"ColumnTypeExtensionInterface",
")",
"{",
"throw",
"new",
"UnexpectedTypeException",
"(",
"$",
"extension",
",",
"ColumnTypeExtensionInterface",
"::",
"class",
")",
";",
"}",
"$",
"type",
"=",
"$",
"extension",
"->",
"getExtendedType",
"(",
")",
";",
"$",
"this",
"->",
"columnTypeExtensions",
"[",
"$",
"type",
"]",
"[",
"]",
"=",
"$",
"extension",
";",
"}",
"}"
] | Initializes the column type extensions.
@throws UnexpectedTypeException if any registered type extension is not
an instance of FormTypeExtensionInterface | [
"Initializes",
"the",
"column",
"type",
"extensions",
"."
] | 6f06e8fd8a3248d52f3a91f10508471344db311a | https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/Extension/AbstractTableExtension.php#L490-L503 | train |
ekyna/Table | Extension/AbstractTableExtension.php | AbstractTableExtension.initFilterTypes | private function initFilterTypes()
{
$this->filterTypes = [];
foreach ($this->loadFilterTypes() as $type) {
if (!$type instanceof FilterTypeInterface) {
throw new UnexpectedTypeException($type, FilterTypeInterface::class);
}
$this->filterTypes[get_class($type)] = $type;
}
} | php | private function initFilterTypes()
{
$this->filterTypes = [];
foreach ($this->loadFilterTypes() as $type) {
if (!$type instanceof FilterTypeInterface) {
throw new UnexpectedTypeException($type, FilterTypeInterface::class);
}
$this->filterTypes[get_class($type)] = $type;
}
} | [
"private",
"function",
"initFilterTypes",
"(",
")",
"{",
"$",
"this",
"->",
"filterTypes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"loadFilterTypes",
"(",
")",
"as",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"$",
"type",
"instanceof",
"FilterTypeInterface",
")",
"{",
"throw",
"new",
"UnexpectedTypeException",
"(",
"$",
"type",
",",
"FilterTypeInterface",
"::",
"class",
")",
";",
"}",
"$",
"this",
"->",
"filterTypes",
"[",
"get_class",
"(",
"$",
"type",
")",
"]",
"=",
"$",
"type",
";",
"}",
"}"
] | Initializes the filter types.
@throws UnexpectedTypeException if any registered type is not an instance of FilterTypeInterface | [
"Initializes",
"the",
"filter",
"types",
"."
] | 6f06e8fd8a3248d52f3a91f10508471344db311a | https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/Extension/AbstractTableExtension.php#L510-L521 | train |
ekyna/Table | Extension/AbstractTableExtension.php | AbstractTableExtension.initFilterTypeExtensions | private function initFilterTypeExtensions()
{
$this->filterTypeExtensions = [];
foreach ($this->loadFilterTypeExtensions() as $extension) {
if (!$extension instanceof FilterTypeExtensionInterface) {
throw new UnexpectedTypeException($extension, FilterTypeExtensionInterface::class);
}
$type = $extension->getExtendedType();
$this->filterTypeExtensions[$type][] = $extension;
}
} | php | private function initFilterTypeExtensions()
{
$this->filterTypeExtensions = [];
foreach ($this->loadFilterTypeExtensions() as $extension) {
if (!$extension instanceof FilterTypeExtensionInterface) {
throw new UnexpectedTypeException($extension, FilterTypeExtensionInterface::class);
}
$type = $extension->getExtendedType();
$this->filterTypeExtensions[$type][] = $extension;
}
} | [
"private",
"function",
"initFilterTypeExtensions",
"(",
")",
"{",
"$",
"this",
"->",
"filterTypeExtensions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"loadFilterTypeExtensions",
"(",
")",
"as",
"$",
"extension",
")",
"{",
"if",
"(",
"!",
"$",
"extension",
"instanceof",
"FilterTypeExtensionInterface",
")",
"{",
"throw",
"new",
"UnexpectedTypeException",
"(",
"$",
"extension",
",",
"FilterTypeExtensionInterface",
"::",
"class",
")",
";",
"}",
"$",
"type",
"=",
"$",
"extension",
"->",
"getExtendedType",
"(",
")",
";",
"$",
"this",
"->",
"filterTypeExtensions",
"[",
"$",
"type",
"]",
"[",
"]",
"=",
"$",
"extension",
";",
"}",
"}"
] | Initializes the filter type extensions.
@throws UnexpectedTypeException if any registered type extension is not
an instance of FormTypeExtensionInterface | [
"Initializes",
"the",
"filter",
"type",
"extensions",
"."
] | 6f06e8fd8a3248d52f3a91f10508471344db311a | https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/Extension/AbstractTableExtension.php#L529-L542 | train |
ekyna/Table | Extension/AbstractTableExtension.php | AbstractTableExtension.initActionTypes | private function initActionTypes()
{
$this->actionTypes = [];
foreach ($this->loadActionTypes() as $type) {
if (!$type instanceof ActionTypeInterface) {
throw new UnexpectedTypeException($type, ActionTypeInterface::class);
}
$this->actionTypes[get_class($type)] = $type;
}
} | php | private function initActionTypes()
{
$this->actionTypes = [];
foreach ($this->loadActionTypes() as $type) {
if (!$type instanceof ActionTypeInterface) {
throw new UnexpectedTypeException($type, ActionTypeInterface::class);
}
$this->actionTypes[get_class($type)] = $type;
}
} | [
"private",
"function",
"initActionTypes",
"(",
")",
"{",
"$",
"this",
"->",
"actionTypes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"loadActionTypes",
"(",
")",
"as",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"$",
"type",
"instanceof",
"ActionTypeInterface",
")",
"{",
"throw",
"new",
"UnexpectedTypeException",
"(",
"$",
"type",
",",
"ActionTypeInterface",
"::",
"class",
")",
";",
"}",
"$",
"this",
"->",
"actionTypes",
"[",
"get_class",
"(",
"$",
"type",
")",
"]",
"=",
"$",
"type",
";",
"}",
"}"
] | Initializes the action types.
@throws UnexpectedTypeException if any registered type is not an instance of ActionTypeInterface | [
"Initializes",
"the",
"action",
"types",
"."
] | 6f06e8fd8a3248d52f3a91f10508471344db311a | https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/Extension/AbstractTableExtension.php#L549-L560 | train |
ekyna/Table | Extension/AbstractTableExtension.php | AbstractTableExtension.initActionTypeExtensions | private function initActionTypeExtensions()
{
$this->actionTypeExtensions = [];
foreach ($this->loadActionTypeExtensions() as $extension) {
if (!$extension instanceof ActionTypeExtensionInterface) {
throw new UnexpectedTypeException($extension, ActionTypeExtensionInterface::class);
}
$type = $extension->getExtendedType();
$this->actionTypeExtensions[$type][] = $extension;
}
} | php | private function initActionTypeExtensions()
{
$this->actionTypeExtensions = [];
foreach ($this->loadActionTypeExtensions() as $extension) {
if (!$extension instanceof ActionTypeExtensionInterface) {
throw new UnexpectedTypeException($extension, ActionTypeExtensionInterface::class);
}
$type = $extension->getExtendedType();
$this->actionTypeExtensions[$type][] = $extension;
}
} | [
"private",
"function",
"initActionTypeExtensions",
"(",
")",
"{",
"$",
"this",
"->",
"actionTypeExtensions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"loadActionTypeExtensions",
"(",
")",
"as",
"$",
"extension",
")",
"{",
"if",
"(",
"!",
"$",
"extension",
"instanceof",
"ActionTypeExtensionInterface",
")",
"{",
"throw",
"new",
"UnexpectedTypeException",
"(",
"$",
"extension",
",",
"ActionTypeExtensionInterface",
"::",
"class",
")",
";",
"}",
"$",
"type",
"=",
"$",
"extension",
"->",
"getExtendedType",
"(",
")",
";",
"$",
"this",
"->",
"actionTypeExtensions",
"[",
"$",
"type",
"]",
"[",
"]",
"=",
"$",
"extension",
";",
"}",
"}"
] | Initializes the action type extensions.
@throws UnexpectedTypeException if any registered type extension is not
an instance of FormTypeExtensionInterface | [
"Initializes",
"the",
"action",
"type",
"extensions",
"."
] | 6f06e8fd8a3248d52f3a91f10508471344db311a | https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/Extension/AbstractTableExtension.php#L568-L581 | train |
ekyna/Table | Extension/AbstractTableExtension.php | AbstractTableExtension.initAdapterFactories | private function initAdapterFactories()
{
$this->adapterFactories = [];
foreach ($this->loadAdapterFactories() as $adapter) {
if (!$adapter instanceof AdapterFactoryInterface) {
throw new UnexpectedTypeException($adapter, AdapterFactoryInterface::class);
}
$this->adapterFactories[get_class($adapter)] = $adapter;
}
} | php | private function initAdapterFactories()
{
$this->adapterFactories = [];
foreach ($this->loadAdapterFactories() as $adapter) {
if (!$adapter instanceof AdapterFactoryInterface) {
throw new UnexpectedTypeException($adapter, AdapterFactoryInterface::class);
}
$this->adapterFactories[get_class($adapter)] = $adapter;
}
} | [
"private",
"function",
"initAdapterFactories",
"(",
")",
"{",
"$",
"this",
"->",
"adapterFactories",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"loadAdapterFactories",
"(",
")",
"as",
"$",
"adapter",
")",
"{",
"if",
"(",
"!",
"$",
"adapter",
"instanceof",
"AdapterFactoryInterface",
")",
"{",
"throw",
"new",
"UnexpectedTypeException",
"(",
"$",
"adapter",
",",
"AdapterFactoryInterface",
"::",
"class",
")",
";",
"}",
"$",
"this",
"->",
"adapterFactories",
"[",
"get_class",
"(",
"$",
"adapter",
")",
"]",
"=",
"$",
"adapter",
";",
"}",
"}"
] | Initializes the adapter factories.
@throws UnexpectedTypeException if any registered adapter factory is not an instance of AdapterFactoryInterface | [
"Initializes",
"the",
"adapter",
"factories",
"."
] | 6f06e8fd8a3248d52f3a91f10508471344db311a | https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/Extension/AbstractTableExtension.php#L588-L599 | train |
squareproton/Bond | src/Bond/Pg/Catalog/Repository/Type.php | Type.getEnumOptions | public function getEnumOptions( $oid )
{
$query = new Query(
"SELECT enumlabel FROM pg_enum WHERE enumtypid = %oid:int%",
array(
'oid' => $oid
)
);
return $this->db->query( $query )->fetch();
} | php | public function getEnumOptions( $oid )
{
$query = new Query(
"SELECT enumlabel FROM pg_enum WHERE enumtypid = %oid:int%",
array(
'oid' => $oid
)
);
return $this->db->query( $query )->fetch();
} | [
"public",
"function",
"getEnumOptions",
"(",
"$",
"oid",
")",
"{",
"$",
"query",
"=",
"new",
"Query",
"(",
"\"SELECT enumlabel FROM pg_enum WHERE enumtypid = %oid:int%\"",
",",
"array",
"(",
"'oid'",
"=>",
"$",
"oid",
")",
")",
";",
"return",
"$",
"this",
"->",
"db",
"->",
"query",
"(",
"$",
"query",
")",
"->",
"fetch",
"(",
")",
";",
"}"
] | Get array of enum options
@return array() | [
"Get",
"array",
"of",
"enum",
"options"
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Pg/Catalog/Repository/Type.php#L96-L108 | train |
squareproton/Bond | src/Bond/Pg/Catalog/Repository/Type.php | Type.findByName | public function findByName( $name )
{
$result = $this->db->query(
new Query( <<<SQL
SELECT
t.oid AS oid,
t.typname AS name,
n.nspname as "schema",
t.typlen AS length,
t.typtype AS type,
t.typcategory AS category,
t.typarray AS "arrayType",
t.typdefault AS default,
t.typdefaultbin AS "defaultBin"
FROM
pg_type AS t
INNER JOIN
pg_namespace AS n ON n.oid = t.typnamespace
WHERE
typname = %name:text% OR
( n.nspname || '.' || t.typname ) = %name:text%
SQL
,
array(
'name' => $name
)
)
)->fetch( Result::FETCH_SINGLE );
return $this->initByData( $result );
} | php | public function findByName( $name )
{
$result = $this->db->query(
new Query( <<<SQL
SELECT
t.oid AS oid,
t.typname AS name,
n.nspname as "schema",
t.typlen AS length,
t.typtype AS type,
t.typcategory AS category,
t.typarray AS "arrayType",
t.typdefault AS default,
t.typdefaultbin AS "defaultBin"
FROM
pg_type AS t
INNER JOIN
pg_namespace AS n ON n.oid = t.typnamespace
WHERE
typname = %name:text% OR
( n.nspname || '.' || t.typname ) = %name:text%
SQL
,
array(
'name' => $name
)
)
)->fetch( Result::FETCH_SINGLE );
return $this->initByData( $result );
} | [
"public",
"function",
"findByName",
"(",
"$",
"name",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"db",
"->",
"query",
"(",
"new",
"Query",
"(",
" <<<SQL\nSELECT\n t.oid AS oid,\n t.typname AS name,\n n.nspname as \"schema\",\n t.typlen AS length,\n t.typtype AS type,\n t.typcategory AS category,\n t.typarray AS \"arrayType\",\n t.typdefault AS default,\n t.typdefaultbin AS \"defaultBin\"\nFROM\n pg_type AS t\nINNER JOIN\n pg_namespace AS n ON n.oid = t.typnamespace\nWHERE\n typname = %name:text% OR\n ( n.nspname || '.' || t.typname ) = %name:text%\nSQL",
",",
"array",
"(",
"'name'",
"=>",
"$",
"name",
")",
")",
")",
"->",
"fetch",
"(",
"Result",
"::",
"FETCH_SINGLE",
")",
";",
"return",
"$",
"this",
"->",
"initByData",
"(",
"$",
"result",
")",
";",
"}"
] | Init a type by it's name. Most likely used for enum types
@return Type|null | [
"Init",
"a",
"type",
"by",
"it",
"s",
"name",
".",
"Most",
"likely",
"used",
"for",
"enum",
"types"
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Pg/Catalog/Repository/Type.php#L114-L146 | train |
ornament-orm/core | src/State.php | State.isDirty | public function isDirty() : bool
{
foreach ($this->__state as $prop => $val) {
if ($this->isModified($prop)) {
return true;
}
}
return false;
} | php | public function isDirty() : bool
{
foreach ($this->__state as $prop => $val) {
if ($this->isModified($prop)) {
return true;
}
}
return false;
} | [
"public",
"function",
"isDirty",
"(",
")",
":",
"bool",
"{",
"foreach",
"(",
"$",
"this",
"->",
"__state",
"as",
"$",
"prop",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isModified",
"(",
"$",
"prop",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Returns true if any of the model's properties was modified.
@return bool | [
"Returns",
"true",
"if",
"any",
"of",
"the",
"model",
"s",
"properties",
"was",
"modified",
"."
] | b573c89d11a183c2e0e11afe8b6fdd56b2cd5ba8 | https://github.com/ornament-orm/core/blob/b573c89d11a183c2e0e11afe8b6fdd56b2cd5ba8/src/State.php#L14-L22 | train |
linpax/microphp-framework | src/file/FileHelper.php | FileHelper.removeDir | public static function removeDir($path)
{
if (is_file($path)) {
unlink($path);
} else {
foreach (scandir($path) as $dir) {
if ($dir === '.' || $dir === '..') {
continue;
}
static::removeDir($path.'/'.$dir);
}
rmdir($path);
}
} | php | public static function removeDir($path)
{
if (is_file($path)) {
unlink($path);
} else {
foreach (scandir($path) as $dir) {
if ($dir === '.' || $dir === '..') {
continue;
}
static::removeDir($path.'/'.$dir);
}
rmdir($path);
}
} | [
"public",
"static",
"function",
"removeDir",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"path",
")",
")",
"{",
"unlink",
"(",
"$",
"path",
")",
";",
"}",
"else",
"{",
"foreach",
"(",
"scandir",
"(",
"$",
"path",
")",
"as",
"$",
"dir",
")",
"{",
"if",
"(",
"$",
"dir",
"===",
"'.'",
"||",
"$",
"dir",
"===",
"'..'",
")",
"{",
"continue",
";",
"}",
"static",
"::",
"removeDir",
"(",
"$",
"path",
".",
"'/'",
".",
"$",
"dir",
")",
";",
"}",
"rmdir",
"(",
"$",
"path",
")",
";",
"}",
"}"
] | Recursive remove dir
@access public
@param string $path path to remove
@return void
@static | [
"Recursive",
"remove",
"dir"
] | 11f3370f3f64c516cce9b84ecd8276c6e9ae8df9 | https://github.com/linpax/microphp-framework/blob/11f3370f3f64c516cce9b84ecd8276c6e9ae8df9/src/file/FileHelper.php#L63-L78 | train |
linpax/microphp-framework | src/file/FileHelper.php | FileHelper.recurseCopyIfEdited | public static function recurseCopyIfEdited($src = '', $dst = '', array $excludes = ['php'])
{
if (!is_dir($dst) && (!mkdir($dst) && !is_dir($dst))) {
throw new Exception('Copy dir error, access denied for path: '.$dst);
}
$dir = opendir($src);
if (!$dir) {
throw new Exception('Unable to read dir: '.$src);
}
while (false !== ($file = readdir($dir))) {
if ($file === '.' || $file === '..') {
continue;
}
if (is_dir($src.'/'.$file)) {
self::recurseCopyIfEdited($src.'/'.$file, $dst.'/'.$file, $excludes);
continue;
}
if (in_array(substr($file, strrpos($file, '.') + 1), $excludes, null)) {
continue;
}
if (file_exists($dst.'/'.$file) && (filemtime($src.'/'.$file) === filemtime($dst.'/'.$file))) {
continue;
}
copy($src.'/'.$file, $dst.'/'.$file);
chmod($dst.'/'.$file, 0666);
}
closedir($dir);
} | php | public static function recurseCopyIfEdited($src = '', $dst = '', array $excludes = ['php'])
{
if (!is_dir($dst) && (!mkdir($dst) && !is_dir($dst))) {
throw new Exception('Copy dir error, access denied for path: '.$dst);
}
$dir = opendir($src);
if (!$dir) {
throw new Exception('Unable to read dir: '.$src);
}
while (false !== ($file = readdir($dir))) {
if ($file === '.' || $file === '..') {
continue;
}
if (is_dir($src.'/'.$file)) {
self::recurseCopyIfEdited($src.'/'.$file, $dst.'/'.$file, $excludes);
continue;
}
if (in_array(substr($file, strrpos($file, '.') + 1), $excludes, null)) {
continue;
}
if (file_exists($dst.'/'.$file) && (filemtime($src.'/'.$file) === filemtime($dst.'/'.$file))) {
continue;
}
copy($src.'/'.$file, $dst.'/'.$file);
chmod($dst.'/'.$file, 0666);
}
closedir($dir);
} | [
"public",
"static",
"function",
"recurseCopyIfEdited",
"(",
"$",
"src",
"=",
"''",
",",
"$",
"dst",
"=",
"''",
",",
"array",
"$",
"excludes",
"=",
"[",
"'php'",
"]",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dst",
")",
"&&",
"(",
"!",
"mkdir",
"(",
"$",
"dst",
")",
"&&",
"!",
"is_dir",
"(",
"$",
"dst",
")",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Copy dir error, access denied for path: '",
".",
"$",
"dst",
")",
";",
"}",
"$",
"dir",
"=",
"opendir",
"(",
"$",
"src",
")",
";",
"if",
"(",
"!",
"$",
"dir",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Unable to read dir: '",
".",
"$",
"src",
")",
";",
"}",
"while",
"(",
"false",
"!==",
"(",
"$",
"file",
"=",
"readdir",
"(",
"$",
"dir",
")",
")",
")",
"{",
"if",
"(",
"$",
"file",
"===",
"'.'",
"||",
"$",
"file",
"===",
"'..'",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"is_dir",
"(",
"$",
"src",
".",
"'/'",
".",
"$",
"file",
")",
")",
"{",
"self",
"::",
"recurseCopyIfEdited",
"(",
"$",
"src",
".",
"'/'",
".",
"$",
"file",
",",
"$",
"dst",
".",
"'/'",
".",
"$",
"file",
",",
"$",
"excludes",
")",
";",
"continue",
";",
"}",
"if",
"(",
"in_array",
"(",
"substr",
"(",
"$",
"file",
",",
"strrpos",
"(",
"$",
"file",
",",
"'.'",
")",
"+",
"1",
")",
",",
"$",
"excludes",
",",
"null",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"file_exists",
"(",
"$",
"dst",
".",
"'/'",
".",
"$",
"file",
")",
"&&",
"(",
"filemtime",
"(",
"$",
"src",
".",
"'/'",
".",
"$",
"file",
")",
"===",
"filemtime",
"(",
"$",
"dst",
".",
"'/'",
".",
"$",
"file",
")",
")",
")",
"{",
"continue",
";",
"}",
"copy",
"(",
"$",
"src",
".",
"'/'",
".",
"$",
"file",
",",
"$",
"dst",
".",
"'/'",
".",
"$",
"file",
")",
";",
"chmod",
"(",
"$",
"dst",
".",
"'/'",
".",
"$",
"file",
",",
"0666",
")",
";",
"}",
"closedir",
"(",
"$",
"dir",
")",
";",
"}"
] | Recursive copy files if edited
@access public
@param string $src source path
@param string $dst destination path
@param array $excludes excludes extensions
@return void
@throws Exception
@static | [
"Recursive",
"copy",
"files",
"if",
"edited"
] | 11f3370f3f64c516cce9b84ecd8276c6e9ae8df9 | https://github.com/linpax/microphp-framework/blob/11f3370f3f64c516cce9b84ecd8276c6e9ae8df9/src/file/FileHelper.php#L125-L159 | train |
Wedeto/HTTP | src/Session.php | Session.start | public function start()
{
if ($this->active)
return $this;
if (PHP_SAPI === "cli")
{
$this->startCLISession();
}
else
{
// @codeCoverageIgnoreStart
$this->startHTTPSession();
// @codeCoverageIgnoreEnd
}
if (!$this->has('session_mgmt', 'start_time'))
$this->set('session_mgmt', 'start_time', time());
return $this;
} | php | public function start()
{
if ($this->active)
return $this;
if (PHP_SAPI === "cli")
{
$this->startCLISession();
}
else
{
// @codeCoverageIgnoreStart
$this->startHTTPSession();
// @codeCoverageIgnoreEnd
}
if (!$this->has('session_mgmt', 'start_time'))
$this->set('session_mgmt', 'start_time', time());
return $this;
} | [
"public",
"function",
"start",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"active",
")",
"return",
"$",
"this",
";",
"if",
"(",
"PHP_SAPI",
"===",
"\"cli\"",
")",
"{",
"$",
"this",
"->",
"startCLISession",
"(",
")",
";",
"}",
"else",
"{",
"// @codeCoverageIgnoreStart",
"$",
"this",
"->",
"startHTTPSession",
"(",
")",
";",
"// @codeCoverageIgnoreEnd",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"has",
"(",
"'session_mgmt'",
",",
"'start_time'",
")",
")",
"$",
"this",
"->",
"set",
"(",
"'session_mgmt'",
",",
"'start_time'",
",",
"time",
"(",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Actually start the session
@return Session Provide fluent interface | [
"Actually",
"start",
"the",
"session"
] | 7318eff1b81a3c103c4263466d09b7f3593b70b9 | https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Session.php#L130-L150 | train |
Wedeto/HTTP | src/Session.php | Session.setSessionID | public function setSessionID(string $session_id)
{
if (!defined('WEDETO_TEST') || WEDETO_TEST === 0)
throw new \RuntimeException("Cannot change the session ID");
$this->session_id = $session_id;
return $this;
} | php | public function setSessionID(string $session_id)
{
if (!defined('WEDETO_TEST') || WEDETO_TEST === 0)
throw new \RuntimeException("Cannot change the session ID");
$this->session_id = $session_id;
return $this;
} | [
"public",
"function",
"setSessionID",
"(",
"string",
"$",
"session_id",
")",
"{",
"if",
"(",
"!",
"defined",
"(",
"'WEDETO_TEST'",
")",
"||",
"WEDETO_TEST",
"===",
"0",
")",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Cannot change the session ID\"",
")",
";",
"$",
"this",
"->",
"session_id",
"=",
"$",
"session_id",
";",
"return",
"$",
"this",
";",
"}"
] | Change the session ID, useful for tests. Disallowed in normal operation.
@return Session Provide fluent interface
@codeCoverageIgnore | [
"Change",
"the",
"session",
"ID",
"useful",
"for",
"tests",
".",
"Disallowed",
"in",
"normal",
"operation",
"."
] | 7318eff1b81a3c103c4263466d09b7f3593b70b9 | https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Session.php#L175-L182 | train |
Wedeto/HTTP | src/Session.php | Session.startHTTPSession | public function startHTTPSession()
{
// @codeCoverageIgnoreStart
// Safety measure - can't test this without replacing PHP
if (session_status() === PHP_SESSION_DISABLED)
throw new \RuntimeException("Sesssions are disabled");
// @codeCoverageIgnoreEnd
if (session_status() === PHP_SESSION_ACTIVE)
throw new \LogicException("Repeated session initialization");
// Now do the PHP session magic to initialize the $_SESSION array
session_set_cookie_params(
$this->lifetime,
$this->session_cookie->getPath(),
$this->session_cookie->getDomain(),
$this->session_cookie->getSecure(),
$this->session_cookie->getHTTPOnly()
);
session_name($this->session_cookie->getName());
$custom_session_id = defined('WEDETO_TEST') && WEDETO_TEST === 1 && $this->session_id !== null;
if ($custom_session_id)
{
ini_set('session.use_strict_mode', 0);
session_id($this->session_id);
}
session_start();
if ($custom_session_id)
ini_set('session.use_strict_mode', 1);
// Store the session ID
$this->session_id = session_id();
// Make sure the session data is accessible through this object
$this->values = &$_SESSION;
// Check if session was regenerated
$this->secureSession();
// PHPs sessions do not renew the cookie, so it will expire after the
// period set when the session was first created. We want to postpone
// the session expiry at every request, so force a cookie to be sent.
// As the session_id is available after the session started, we need to
// update the cookie that was generated in the constructor.
$this->session_cookie->setValue(session_id());
// Session has been started
$this->active = true;
return $this;
} | php | public function startHTTPSession()
{
// @codeCoverageIgnoreStart
// Safety measure - can't test this without replacing PHP
if (session_status() === PHP_SESSION_DISABLED)
throw new \RuntimeException("Sesssions are disabled");
// @codeCoverageIgnoreEnd
if (session_status() === PHP_SESSION_ACTIVE)
throw new \LogicException("Repeated session initialization");
// Now do the PHP session magic to initialize the $_SESSION array
session_set_cookie_params(
$this->lifetime,
$this->session_cookie->getPath(),
$this->session_cookie->getDomain(),
$this->session_cookie->getSecure(),
$this->session_cookie->getHTTPOnly()
);
session_name($this->session_cookie->getName());
$custom_session_id = defined('WEDETO_TEST') && WEDETO_TEST === 1 && $this->session_id !== null;
if ($custom_session_id)
{
ini_set('session.use_strict_mode', 0);
session_id($this->session_id);
}
session_start();
if ($custom_session_id)
ini_set('session.use_strict_mode', 1);
// Store the session ID
$this->session_id = session_id();
// Make sure the session data is accessible through this object
$this->values = &$_SESSION;
// Check if session was regenerated
$this->secureSession();
// PHPs sessions do not renew the cookie, so it will expire after the
// period set when the session was first created. We want to postpone
// the session expiry at every request, so force a cookie to be sent.
// As the session_id is available after the session started, we need to
// update the cookie that was generated in the constructor.
$this->session_cookie->setValue(session_id());
// Session has been started
$this->active = true;
return $this;
} | [
"public",
"function",
"startHTTPSession",
"(",
")",
"{",
"// @codeCoverageIgnoreStart",
"// Safety measure - can't test this without replacing PHP",
"if",
"(",
"session_status",
"(",
")",
"===",
"PHP_SESSION_DISABLED",
")",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Sesssions are disabled\"",
")",
";",
"// @codeCoverageIgnoreEnd",
"if",
"(",
"session_status",
"(",
")",
"===",
"PHP_SESSION_ACTIVE",
")",
"throw",
"new",
"\\",
"LogicException",
"(",
"\"Repeated session initialization\"",
")",
";",
"// Now do the PHP session magic to initialize the $_SESSION array",
"session_set_cookie_params",
"(",
"$",
"this",
"->",
"lifetime",
",",
"$",
"this",
"->",
"session_cookie",
"->",
"getPath",
"(",
")",
",",
"$",
"this",
"->",
"session_cookie",
"->",
"getDomain",
"(",
")",
",",
"$",
"this",
"->",
"session_cookie",
"->",
"getSecure",
"(",
")",
",",
"$",
"this",
"->",
"session_cookie",
"->",
"getHTTPOnly",
"(",
")",
")",
";",
"session_name",
"(",
"$",
"this",
"->",
"session_cookie",
"->",
"getName",
"(",
")",
")",
";",
"$",
"custom_session_id",
"=",
"defined",
"(",
"'WEDETO_TEST'",
")",
"&&",
"WEDETO_TEST",
"===",
"1",
"&&",
"$",
"this",
"->",
"session_id",
"!==",
"null",
";",
"if",
"(",
"$",
"custom_session_id",
")",
"{",
"ini_set",
"(",
"'session.use_strict_mode'",
",",
"0",
")",
";",
"session_id",
"(",
"$",
"this",
"->",
"session_id",
")",
";",
"}",
"session_start",
"(",
")",
";",
"if",
"(",
"$",
"custom_session_id",
")",
"ini_set",
"(",
"'session.use_strict_mode'",
",",
"1",
")",
";",
"// Store the session ID",
"$",
"this",
"->",
"session_id",
"=",
"session_id",
"(",
")",
";",
"// Make sure the session data is accessible through this object",
"$",
"this",
"->",
"values",
"=",
"&",
"$",
"_SESSION",
";",
"// Check if session was regenerated",
"$",
"this",
"->",
"secureSession",
"(",
")",
";",
"// PHPs sessions do not renew the cookie, so it will expire after the",
"// period set when the session was first created. We want to postpone",
"// the session expiry at every request, so force a cookie to be sent.",
"// As the session_id is available after the session started, we need to",
"// update the cookie that was generated in the constructor.",
"$",
"this",
"->",
"session_cookie",
"->",
"setValue",
"(",
"session_id",
"(",
")",
")",
";",
"// Session has been started",
"$",
"this",
"->",
"active",
"=",
"true",
";",
"return",
"$",
"this",
";",
"}"
] | Set up a HTTP session using cookies and the PHP session machinery
@return Session Provides fluent interface | [
"Set",
"up",
"a",
"HTTP",
"session",
"using",
"cookies",
"and",
"the",
"PHP",
"session",
"machinery"
] | 7318eff1b81a3c103c4263466d09b7f3593b70b9 | https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Session.php#L204-L257 | train |
Wedeto/HTTP | src/Session.php | Session.secureSession | private function secureSession()
{
$expired = false;
if ($this->has('session_mgmt', 'destroyed'))
{
$when = $this->get('session_mgmt', 'destroyed');
$ua = $this->get('session_mgmt', 'last_ua');
$ip = $this->get('session_mgmt', 'last_ip');
$now = time();
$diff = $now - $when;
if ($diff > Date::SECONDS_IN_MINUTE)
{
// The session exists, but it was expired more than 1 minute ago,
// so its ready to be deleted.
// @codeCoverageIgnoreStart
// Testing this would increase the test duration by 1 minute.
$expired = true;
// @codeCoverageIgnoreEnd
}
elseif ($ua === $this->server_vars['HTTP_USER_AGENT'] && $ip === $this->server_vars['REMOTE_ADDR'])
{
// If UA and IP match, we can redirect to the new sesssion
// within 1 minute to avoid session loss on bad connections.
$new_session = $this->get('session_mgmt', 'new_session_id');
if (!empty($new_session))
{
session_commit();
ini_set('session.use_strict_mode', 0);
session_id($new_session);
session_start();
ini_set('session.use_strict_mode', 1);
$this->session_id = session_id();
}
else
{
// The old session does not contain redirect information,
// so it was closed, not changed. Destroy it now.
$expired = true;
}
}
else
{
// This seems like a hi-jack attempt, make sure to destroy the old session
$expired = true;
}
}
if ($expired)
{
// Shut down expired session completely
$this->clear();
$this->resetID();
}
// Check if it's time to regenerate the session ID
if ($this->has('session_mgmt', 'start_time'))
{
$start = $this->getInt('session_mgmt', 'start_time');
$now = time();
$elapsed = $now - $start;
$interval = Date::SECONDS_IN_DAY * 5;
if ($elapsed > $interval)
$this->resetID();
}
else
$this->set('session_mgmt', 'start_time', time());
// Store the current user agent and IP address to prevent session hijacking
$this->set('session_mgmt', 'last_ip', $this->server_vars['REMOTE_ADDR']);
$this->set('session_mgmt', 'last_ua', $this->server_vars['HTTP_USER_AGENT']);
} | php | private function secureSession()
{
$expired = false;
if ($this->has('session_mgmt', 'destroyed'))
{
$when = $this->get('session_mgmt', 'destroyed');
$ua = $this->get('session_mgmt', 'last_ua');
$ip = $this->get('session_mgmt', 'last_ip');
$now = time();
$diff = $now - $when;
if ($diff > Date::SECONDS_IN_MINUTE)
{
// The session exists, but it was expired more than 1 minute ago,
// so its ready to be deleted.
// @codeCoverageIgnoreStart
// Testing this would increase the test duration by 1 minute.
$expired = true;
// @codeCoverageIgnoreEnd
}
elseif ($ua === $this->server_vars['HTTP_USER_AGENT'] && $ip === $this->server_vars['REMOTE_ADDR'])
{
// If UA and IP match, we can redirect to the new sesssion
// within 1 minute to avoid session loss on bad connections.
$new_session = $this->get('session_mgmt', 'new_session_id');
if (!empty($new_session))
{
session_commit();
ini_set('session.use_strict_mode', 0);
session_id($new_session);
session_start();
ini_set('session.use_strict_mode', 1);
$this->session_id = session_id();
}
else
{
// The old session does not contain redirect information,
// so it was closed, not changed. Destroy it now.
$expired = true;
}
}
else
{
// This seems like a hi-jack attempt, make sure to destroy the old session
$expired = true;
}
}
if ($expired)
{
// Shut down expired session completely
$this->clear();
$this->resetID();
}
// Check if it's time to regenerate the session ID
if ($this->has('session_mgmt', 'start_time'))
{
$start = $this->getInt('session_mgmt', 'start_time');
$now = time();
$elapsed = $now - $start;
$interval = Date::SECONDS_IN_DAY * 5;
if ($elapsed > $interval)
$this->resetID();
}
else
$this->set('session_mgmt', 'start_time', time());
// Store the current user agent and IP address to prevent session hijacking
$this->set('session_mgmt', 'last_ip', $this->server_vars['REMOTE_ADDR']);
$this->set('session_mgmt', 'last_ua', $this->server_vars['HTTP_USER_AGENT']);
} | [
"private",
"function",
"secureSession",
"(",
")",
"{",
"$",
"expired",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"has",
"(",
"'session_mgmt'",
",",
"'destroyed'",
")",
")",
"{",
"$",
"when",
"=",
"$",
"this",
"->",
"get",
"(",
"'session_mgmt'",
",",
"'destroyed'",
")",
";",
"$",
"ua",
"=",
"$",
"this",
"->",
"get",
"(",
"'session_mgmt'",
",",
"'last_ua'",
")",
";",
"$",
"ip",
"=",
"$",
"this",
"->",
"get",
"(",
"'session_mgmt'",
",",
"'last_ip'",
")",
";",
"$",
"now",
"=",
"time",
"(",
")",
";",
"$",
"diff",
"=",
"$",
"now",
"-",
"$",
"when",
";",
"if",
"(",
"$",
"diff",
">",
"Date",
"::",
"SECONDS_IN_MINUTE",
")",
"{",
"// The session exists, but it was expired more than 1 minute ago,",
"// so its ready to be deleted.",
"// @codeCoverageIgnoreStart",
"// Testing this would increase the test duration by 1 minute.",
"$",
"expired",
"=",
"true",
";",
"// @codeCoverageIgnoreEnd",
"}",
"elseif",
"(",
"$",
"ua",
"===",
"$",
"this",
"->",
"server_vars",
"[",
"'HTTP_USER_AGENT'",
"]",
"&&",
"$",
"ip",
"===",
"$",
"this",
"->",
"server_vars",
"[",
"'REMOTE_ADDR'",
"]",
")",
"{",
"// If UA and IP match, we can redirect to the new sesssion",
"// within 1 minute to avoid session loss on bad connections.",
"$",
"new_session",
"=",
"$",
"this",
"->",
"get",
"(",
"'session_mgmt'",
",",
"'new_session_id'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"new_session",
")",
")",
"{",
"session_commit",
"(",
")",
";",
"ini_set",
"(",
"'session.use_strict_mode'",
",",
"0",
")",
";",
"session_id",
"(",
"$",
"new_session",
")",
";",
"session_start",
"(",
")",
";",
"ini_set",
"(",
"'session.use_strict_mode'",
",",
"1",
")",
";",
"$",
"this",
"->",
"session_id",
"=",
"session_id",
"(",
")",
";",
"}",
"else",
"{",
"// The old session does not contain redirect information,",
"// so it was closed, not changed. Destroy it now.",
"$",
"expired",
"=",
"true",
";",
"}",
"}",
"else",
"{",
"// This seems like a hi-jack attempt, make sure to destroy the old session",
"$",
"expired",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"$",
"expired",
")",
"{",
"// Shut down expired session completely",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"$",
"this",
"->",
"resetID",
"(",
")",
";",
"}",
"// Check if it's time to regenerate the session ID",
"if",
"(",
"$",
"this",
"->",
"has",
"(",
"'session_mgmt'",
",",
"'start_time'",
")",
")",
"{",
"$",
"start",
"=",
"$",
"this",
"->",
"getInt",
"(",
"'session_mgmt'",
",",
"'start_time'",
")",
";",
"$",
"now",
"=",
"time",
"(",
")",
";",
"$",
"elapsed",
"=",
"$",
"now",
"-",
"$",
"start",
";",
"$",
"interval",
"=",
"Date",
"::",
"SECONDS_IN_DAY",
"*",
"5",
";",
"if",
"(",
"$",
"elapsed",
">",
"$",
"interval",
")",
"$",
"this",
"->",
"resetID",
"(",
")",
";",
"}",
"else",
"$",
"this",
"->",
"set",
"(",
"'session_mgmt'",
",",
"'start_time'",
",",
"time",
"(",
")",
")",
";",
"// Store the current user agent and IP address to prevent session hijacking",
"$",
"this",
"->",
"set",
"(",
"'session_mgmt'",
",",
"'last_ip'",
",",
"$",
"this",
"->",
"server_vars",
"[",
"'REMOTE_ADDR'",
"]",
")",
";",
"$",
"this",
"->",
"set",
"(",
"'session_mgmt'",
",",
"'last_ua'",
",",
"$",
"this",
"->",
"server_vars",
"[",
"'HTTP_USER_AGENT'",
"]",
")",
";",
"}"
] | Secure the session
This method checks if the session was destroyed, and if so, if a redirect to a new
session should be done. The new session ID is stored and will be sent to the client iff:
- Less than 1 minute has passed since the previous session was destroyed
- The client has the same user agent and IP-address as when the session was destroyed
If this is not the case, a new session is started and sent to the client. This method
also stores the current User Agent and IP address to the session. | [
"Secure",
"the",
"session"
] | 7318eff1b81a3c103c4263466d09b7f3593b70b9 | https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Session.php#L271-L344 | train |
Wedeto/HTTP | src/Session.php | Session.resetID | public function resetID()
{
if (session_status() === PHP_SESSION_ACTIVE)
{
$this->set('session_mgmt', 'destroyed', time());
$auth = $this->get('authentication');
if ($auth)
unset($this['authentication']);
$new_session_id = self::create_new_id();
$this->set('session_mgmt', 'new_session_id', $new_session_id);
session_commit();
ini_set('session.use_strict_mode', 0);
session_id($new_session_id);
session_start();
ini_set('session.use_strict_mode', 1);
$this->session_id = session_id();
$this->values = &$_SESSION;
$this->session_cookie->setValue($new_session_id);
// Force destroyed to be empty
$this->set('session_mgmt', 'destroyed', null);
if ($auth)
$this['authentication'] = $auth;
// Store the start time of the new session
$this->set('session_mgmt', 'start_time', time());
}
} | php | public function resetID()
{
if (session_status() === PHP_SESSION_ACTIVE)
{
$this->set('session_mgmt', 'destroyed', time());
$auth = $this->get('authentication');
if ($auth)
unset($this['authentication']);
$new_session_id = self::create_new_id();
$this->set('session_mgmt', 'new_session_id', $new_session_id);
session_commit();
ini_set('session.use_strict_mode', 0);
session_id($new_session_id);
session_start();
ini_set('session.use_strict_mode', 1);
$this->session_id = session_id();
$this->values = &$_SESSION;
$this->session_cookie->setValue($new_session_id);
// Force destroyed to be empty
$this->set('session_mgmt', 'destroyed', null);
if ($auth)
$this['authentication'] = $auth;
// Store the start time of the new session
$this->set('session_mgmt', 'start_time', time());
}
} | [
"public",
"function",
"resetID",
"(",
")",
"{",
"if",
"(",
"session_status",
"(",
")",
"===",
"PHP_SESSION_ACTIVE",
")",
"{",
"$",
"this",
"->",
"set",
"(",
"'session_mgmt'",
",",
"'destroyed'",
",",
"time",
"(",
")",
")",
";",
"$",
"auth",
"=",
"$",
"this",
"->",
"get",
"(",
"'authentication'",
")",
";",
"if",
"(",
"$",
"auth",
")",
"unset",
"(",
"$",
"this",
"[",
"'authentication'",
"]",
")",
";",
"$",
"new_session_id",
"=",
"self",
"::",
"create_new_id",
"(",
")",
";",
"$",
"this",
"->",
"set",
"(",
"'session_mgmt'",
",",
"'new_session_id'",
",",
"$",
"new_session_id",
")",
";",
"session_commit",
"(",
")",
";",
"ini_set",
"(",
"'session.use_strict_mode'",
",",
"0",
")",
";",
"session_id",
"(",
"$",
"new_session_id",
")",
";",
"session_start",
"(",
")",
";",
"ini_set",
"(",
"'session.use_strict_mode'",
",",
"1",
")",
";",
"$",
"this",
"->",
"session_id",
"=",
"session_id",
"(",
")",
";",
"$",
"this",
"->",
"values",
"=",
"&",
"$",
"_SESSION",
";",
"$",
"this",
"->",
"session_cookie",
"->",
"setValue",
"(",
"$",
"new_session_id",
")",
";",
"// Force destroyed to be empty ",
"$",
"this",
"->",
"set",
"(",
"'session_mgmt'",
",",
"'destroyed'",
",",
"null",
")",
";",
"if",
"(",
"$",
"auth",
")",
"$",
"this",
"[",
"'authentication'",
"]",
"=",
"$",
"auth",
";",
"// Store the start time of the new session",
"$",
"this",
"->",
"set",
"(",
"'session_mgmt'",
",",
"'start_time'",
",",
"time",
"(",
")",
")",
";",
"}",
"}"
] | Should be called when the session ID should be changed, for example
after logging in or out.
@return Session Provides fluent interface | [
"Should",
"be",
"called",
"when",
"the",
"session",
"ID",
"should",
"be",
"changed",
"for",
"example",
"after",
"logging",
"in",
"or",
"out",
"."
] | 7318eff1b81a3c103c4263466d09b7f3593b70b9 | https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Session.php#L351-L382 | train |
Wedeto/HTTP | src/Session.php | Session.create_new_id | private static function create_new_id(string $prefix = "Wedeto")
{
if (version_compare(PHP_VERSION, '7.1.0') > 0)
return session_create_id($prefix);
return $prefix . bin2hex(random_bytes(16));
} | php | private static function create_new_id(string $prefix = "Wedeto")
{
if (version_compare(PHP_VERSION, '7.1.0') > 0)
return session_create_id($prefix);
return $prefix . bin2hex(random_bytes(16));
} | [
"private",
"static",
"function",
"create_new_id",
"(",
"string",
"$",
"prefix",
"=",
"\"Wedeto\"",
")",
"{",
"if",
"(",
"version_compare",
"(",
"PHP_VERSION",
",",
"'7.1.0'",
")",
">",
"0",
")",
"return",
"session_create_id",
"(",
"$",
"prefix",
")",
";",
"return",
"$",
"prefix",
".",
"bin2hex",
"(",
"random_bytes",
"(",
"16",
")",
")",
";",
"}"
] | Helper function. PHP 7.1 introduces session_create_id function. This
is used in PHP 7.1 but a fallback using random_bytes is used on
PHP 7.0.
@param string $prefix A prefix to prepend to the session ID
@return string A hexadecimal session ID | [
"Helper",
"function",
".",
"PHP",
"7",
".",
"1",
"introduces",
"session_create_id",
"function",
".",
"This",
"is",
"used",
"in",
"PHP",
"7",
".",
"1",
"but",
"a",
"fallback",
"using",
"random_bytes",
"is",
"used",
"on",
"PHP",
"7",
".",
"0",
"."
] | 7318eff1b81a3c103c4263466d09b7f3593b70b9 | https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Session.php#L392-L397 | train |
Wedeto/HTTP | src/Session.php | Session.destroy | public function destroy()
{
if ($this->active)
{
$this->clear();
if (session_status() === PHP_SESSION_ACTIVE)
session_commit();
$this->active = false;
}
return $this;
} | php | public function destroy()
{
if ($this->active)
{
$this->clear();
if (session_status() === PHP_SESSION_ACTIVE)
session_commit();
$this->active = false;
}
return $this;
} | [
"public",
"function",
"destroy",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"active",
")",
"{",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"if",
"(",
"session_status",
"(",
")",
"===",
"PHP_SESSION_ACTIVE",
")",
"session_commit",
"(",
")",
";",
"$",
"this",
"->",
"active",
"=",
"false",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Should be called when the session should be cleared and destroyed.
@return Wedeto\HTTP\Session Provides fluent interface | [
"Should",
"be",
"called",
"when",
"the",
"session",
"should",
"be",
"cleared",
"and",
"destroyed",
"."
] | 7318eff1b81a3c103c4263466d09b7f3593b70b9 | https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Session.php#L450-L460 | train |
jenskooij/cloudcontrol | src/cc/ResponseHeaders.php | ResponseHeaders.init | public static function init()
{
self::add(self::HEADER_SET_COOKIE, '__Host-sess=' . session_id() . '; path=' . Request::$subfolders . '; Secure; HttpOnly; SameSite;');
if (Request::isSecure()) {
self::add(self::HEADER_CONTENT_SECURITY_POLICY, self::HEADER_CONTENT_SECURITY_POLICY_CONTENT_SECURE);
self::add(self::HEADER_STRICT_TRANSPORT_SECURITY, self::HEADER_STRICT_TRANSPORT_SECURITY_CONTENT);
self::add(self::HEADER_X_CONTENT_SECURITY_POLICY, self::HEADER_CONTENT_SECURITY_POLICY_CONTENT_SECURE);
} elseif (Request::isLocalhost()) {
self::add(self::HEADER_CONTENT_SECURITY_POLICY, self::HEADER_CONTENT_SECURITY_POLICY_CONTENT_LOCALHOST);
self::add(self::HEADER_X_CONTENT_SECURITY_POLICY, self::HEADER_CONTENT_SECURITY_POLICY_CONTENT_LOCALHOST);
} else {
self::add(self::HEADER_CONTENT_SECURITY_POLICY, self::HEADER_CONTENT_SECURITY_POLICY_CONTENT_INSECURE);
self::add(self::HEADER_X_CONTENT_SECURITY_POLICY, self::HEADER_CONTENT_SECURITY_POLICY_CONTENT_INSECURE);
}
self::$initialized = true;
} | php | public static function init()
{
self::add(self::HEADER_SET_COOKIE, '__Host-sess=' . session_id() . '; path=' . Request::$subfolders . '; Secure; HttpOnly; SameSite;');
if (Request::isSecure()) {
self::add(self::HEADER_CONTENT_SECURITY_POLICY, self::HEADER_CONTENT_SECURITY_POLICY_CONTENT_SECURE);
self::add(self::HEADER_STRICT_TRANSPORT_SECURITY, self::HEADER_STRICT_TRANSPORT_SECURITY_CONTENT);
self::add(self::HEADER_X_CONTENT_SECURITY_POLICY, self::HEADER_CONTENT_SECURITY_POLICY_CONTENT_SECURE);
} elseif (Request::isLocalhost()) {
self::add(self::HEADER_CONTENT_SECURITY_POLICY, self::HEADER_CONTENT_SECURITY_POLICY_CONTENT_LOCALHOST);
self::add(self::HEADER_X_CONTENT_SECURITY_POLICY, self::HEADER_CONTENT_SECURITY_POLICY_CONTENT_LOCALHOST);
} else {
self::add(self::HEADER_CONTENT_SECURITY_POLICY, self::HEADER_CONTENT_SECURITY_POLICY_CONTENT_INSECURE);
self::add(self::HEADER_X_CONTENT_SECURITY_POLICY, self::HEADER_CONTENT_SECURITY_POLICY_CONTENT_INSECURE);
}
self::$initialized = true;
} | [
"public",
"static",
"function",
"init",
"(",
")",
"{",
"self",
"::",
"add",
"(",
"self",
"::",
"HEADER_SET_COOKIE",
",",
"'__Host-sess='",
".",
"session_id",
"(",
")",
".",
"'; path='",
".",
"Request",
"::",
"$",
"subfolders",
".",
"'; Secure; HttpOnly; SameSite;'",
")",
";",
"if",
"(",
"Request",
"::",
"isSecure",
"(",
")",
")",
"{",
"self",
"::",
"add",
"(",
"self",
"::",
"HEADER_CONTENT_SECURITY_POLICY",
",",
"self",
"::",
"HEADER_CONTENT_SECURITY_POLICY_CONTENT_SECURE",
")",
";",
"self",
"::",
"add",
"(",
"self",
"::",
"HEADER_STRICT_TRANSPORT_SECURITY",
",",
"self",
"::",
"HEADER_STRICT_TRANSPORT_SECURITY_CONTENT",
")",
";",
"self",
"::",
"add",
"(",
"self",
"::",
"HEADER_X_CONTENT_SECURITY_POLICY",
",",
"self",
"::",
"HEADER_CONTENT_SECURITY_POLICY_CONTENT_SECURE",
")",
";",
"}",
"elseif",
"(",
"Request",
"::",
"isLocalhost",
"(",
")",
")",
"{",
"self",
"::",
"add",
"(",
"self",
"::",
"HEADER_CONTENT_SECURITY_POLICY",
",",
"self",
"::",
"HEADER_CONTENT_SECURITY_POLICY_CONTENT_LOCALHOST",
")",
";",
"self",
"::",
"add",
"(",
"self",
"::",
"HEADER_X_CONTENT_SECURITY_POLICY",
",",
"self",
"::",
"HEADER_CONTENT_SECURITY_POLICY_CONTENT_LOCALHOST",
")",
";",
"}",
"else",
"{",
"self",
"::",
"add",
"(",
"self",
"::",
"HEADER_CONTENT_SECURITY_POLICY",
",",
"self",
"::",
"HEADER_CONTENT_SECURITY_POLICY_CONTENT_INSECURE",
")",
";",
"self",
"::",
"add",
"(",
"self",
"::",
"HEADER_X_CONTENT_SECURITY_POLICY",
",",
"self",
"::",
"HEADER_CONTENT_SECURITY_POLICY_CONTENT_INSECURE",
")",
";",
"}",
"self",
"::",
"$",
"initialized",
"=",
"true",
";",
"}"
] | Adds content security policy headers | [
"Adds",
"content",
"security",
"policy",
"headers"
] | 76e5d9ac8f9c50d06d39a995d13cc03742536548 | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/cc/ResponseHeaders.php#L79-L94 | train |
phata/widgetfy | src/Site/Youtube.php | Youtube.parseParams | public static function parseParams($url_parsed) {
$vid = FALSE; $url_seperator = FALSE;
if (preg_match('/^\/watch$/', $url_parsed['path'])) {
// new Youtube utilizes fragment part instead of query
$fragment_regex = '/^\!v\=([a-zA-Z0-9]+).*$/';
if (isset($url_parsed['fragment']) && preg_match($fragment_regex, $url_parsed['fragment'])) {
$vid = preg_replace($fragment_regex, '$1', $url_parsed['fragment']);
$url_seperator = '#!';
} else {
// parse fragment parameters into query string
if (!empty($url_parsed['fragment'])) {
if (!empty($url_parsed['query'])) {
$url_parsed['query'] = $url_parsed['query'].'&'.$url_parsed['fragment'];
} else {
$url_parsed['query'] = $url_parsed['fragment'];
}
}
// backward compatibility
parse_str($url_parsed['query'], $args);
if (isset($args['v'])) {
$vid = $args['v'];
$t = isset($args['t']) ? $args['t'] : '';
$t_fragment = !empty($t) ? '&t='.$t : '';
$url_seperator = '?';
}
}
$location = preg_replace('/([a-z]+?)\.youtube\.com/', '$1', strtolower($url_parsed['host']));
$string = 'http://'.$location.'.youtube.com/watch'.$url_seperator.'v='.$vid.$t_fragment;
} elseif (preg_match('/^\/user\/[a-zA-Z0-9_\-]+$/', $url_parsed['path'])){
$fragment_regex = '/^p\/u\/[0-9]+\/([a-zA-Z0-9]+)/';
if (preg_match($fragment_regex, $url_parsed['fragment'])) {
$vid = preg_replace($fragment_regex, '$1', $url_parsed['fragment']);
}
$location = preg_replace('/([a-z]+?)\.youtube\.com/', '$1', strtolower($url_parsed['host']));
$string = 'http://'.$url_parsed['host'].'/'.$url_parsed["path"].'#'.$url_parsed['fragment'];
}
return ($vid === FALSE) ? FALSE : array(
'vid' => $vid,
'url_seperator' => $url_seperator,
'location' => $location,
'string' => $string,
't' => $t,
);
} | php | public static function parseParams($url_parsed) {
$vid = FALSE; $url_seperator = FALSE;
if (preg_match('/^\/watch$/', $url_parsed['path'])) {
// new Youtube utilizes fragment part instead of query
$fragment_regex = '/^\!v\=([a-zA-Z0-9]+).*$/';
if (isset($url_parsed['fragment']) && preg_match($fragment_regex, $url_parsed['fragment'])) {
$vid = preg_replace($fragment_regex, '$1', $url_parsed['fragment']);
$url_seperator = '#!';
} else {
// parse fragment parameters into query string
if (!empty($url_parsed['fragment'])) {
if (!empty($url_parsed['query'])) {
$url_parsed['query'] = $url_parsed['query'].'&'.$url_parsed['fragment'];
} else {
$url_parsed['query'] = $url_parsed['fragment'];
}
}
// backward compatibility
parse_str($url_parsed['query'], $args);
if (isset($args['v'])) {
$vid = $args['v'];
$t = isset($args['t']) ? $args['t'] : '';
$t_fragment = !empty($t) ? '&t='.$t : '';
$url_seperator = '?';
}
}
$location = preg_replace('/([a-z]+?)\.youtube\.com/', '$1', strtolower($url_parsed['host']));
$string = 'http://'.$location.'.youtube.com/watch'.$url_seperator.'v='.$vid.$t_fragment;
} elseif (preg_match('/^\/user\/[a-zA-Z0-9_\-]+$/', $url_parsed['path'])){
$fragment_regex = '/^p\/u\/[0-9]+\/([a-zA-Z0-9]+)/';
if (preg_match($fragment_regex, $url_parsed['fragment'])) {
$vid = preg_replace($fragment_regex, '$1', $url_parsed['fragment']);
}
$location = preg_replace('/([a-z]+?)\.youtube\.com/', '$1', strtolower($url_parsed['host']));
$string = 'http://'.$url_parsed['host'].'/'.$url_parsed["path"].'#'.$url_parsed['fragment'];
}
return ($vid === FALSE) ? FALSE : array(
'vid' => $vid,
'url_seperator' => $url_seperator,
'location' => $location,
'string' => $string,
't' => $t,
);
} | [
"public",
"static",
"function",
"parseParams",
"(",
"$",
"url_parsed",
")",
"{",
"$",
"vid",
"=",
"FALSE",
";",
"$",
"url_seperator",
"=",
"FALSE",
";",
"if",
"(",
"preg_match",
"(",
"'/^\\/watch$/'",
",",
"$",
"url_parsed",
"[",
"'path'",
"]",
")",
")",
"{",
"// new Youtube utilizes fragment part instead of query",
"$",
"fragment_regex",
"=",
"'/^\\!v\\=([a-zA-Z0-9]+).*$/'",
";",
"if",
"(",
"isset",
"(",
"$",
"url_parsed",
"[",
"'fragment'",
"]",
")",
"&&",
"preg_match",
"(",
"$",
"fragment_regex",
",",
"$",
"url_parsed",
"[",
"'fragment'",
"]",
")",
")",
"{",
"$",
"vid",
"=",
"preg_replace",
"(",
"$",
"fragment_regex",
",",
"'$1'",
",",
"$",
"url_parsed",
"[",
"'fragment'",
"]",
")",
";",
"$",
"url_seperator",
"=",
"'#!'",
";",
"}",
"else",
"{",
"// parse fragment parameters into query string",
"if",
"(",
"!",
"empty",
"(",
"$",
"url_parsed",
"[",
"'fragment'",
"]",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"url_parsed",
"[",
"'query'",
"]",
")",
")",
"{",
"$",
"url_parsed",
"[",
"'query'",
"]",
"=",
"$",
"url_parsed",
"[",
"'query'",
"]",
".",
"'&'",
".",
"$",
"url_parsed",
"[",
"'fragment'",
"]",
";",
"}",
"else",
"{",
"$",
"url_parsed",
"[",
"'query'",
"]",
"=",
"$",
"url_parsed",
"[",
"'fragment'",
"]",
";",
"}",
"}",
"// backward compatibility",
"parse_str",
"(",
"$",
"url_parsed",
"[",
"'query'",
"]",
",",
"$",
"args",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"args",
"[",
"'v'",
"]",
")",
")",
"{",
"$",
"vid",
"=",
"$",
"args",
"[",
"'v'",
"]",
";",
"$",
"t",
"=",
"isset",
"(",
"$",
"args",
"[",
"'t'",
"]",
")",
"?",
"$",
"args",
"[",
"'t'",
"]",
":",
"''",
";",
"$",
"t_fragment",
"=",
"!",
"empty",
"(",
"$",
"t",
")",
"?",
"'&t='",
".",
"$",
"t",
":",
"''",
";",
"$",
"url_seperator",
"=",
"'?'",
";",
"}",
"}",
"$",
"location",
"=",
"preg_replace",
"(",
"'/([a-z]+?)\\.youtube\\.com/'",
",",
"'$1'",
",",
"strtolower",
"(",
"$",
"url_parsed",
"[",
"'host'",
"]",
")",
")",
";",
"$",
"string",
"=",
"'http://'",
".",
"$",
"location",
".",
"'.youtube.com/watch'",
".",
"$",
"url_seperator",
".",
"'v='",
".",
"$",
"vid",
".",
"$",
"t_fragment",
";",
"}",
"elseif",
"(",
"preg_match",
"(",
"'/^\\/user\\/[a-zA-Z0-9_\\-]+$/'",
",",
"$",
"url_parsed",
"[",
"'path'",
"]",
")",
")",
"{",
"$",
"fragment_regex",
"=",
"'/^p\\/u\\/[0-9]+\\/([a-zA-Z0-9]+)/'",
";",
"if",
"(",
"preg_match",
"(",
"$",
"fragment_regex",
",",
"$",
"url_parsed",
"[",
"'fragment'",
"]",
")",
")",
"{",
"$",
"vid",
"=",
"preg_replace",
"(",
"$",
"fragment_regex",
",",
"'$1'",
",",
"$",
"url_parsed",
"[",
"'fragment'",
"]",
")",
";",
"}",
"$",
"location",
"=",
"preg_replace",
"(",
"'/([a-z]+?)\\.youtube\\.com/'",
",",
"'$1'",
",",
"strtolower",
"(",
"$",
"url_parsed",
"[",
"'host'",
"]",
")",
")",
";",
"$",
"string",
"=",
"'http://'",
".",
"$",
"url_parsed",
"[",
"'host'",
"]",
".",
"'/'",
".",
"$",
"url_parsed",
"[",
"\"path\"",
"]",
".",
"'#'",
".",
"$",
"url_parsed",
"[",
"'fragment'",
"]",
";",
"}",
"return",
"(",
"$",
"vid",
"===",
"FALSE",
")",
"?",
"FALSE",
":",
"array",
"(",
"'vid'",
"=>",
"$",
"vid",
",",
"'url_seperator'",
"=>",
"$",
"url_seperator",
",",
"'location'",
"=>",
"$",
"location",
",",
"'string'",
"=>",
"$",
"string",
",",
"'t'",
"=>",
"$",
"t",
",",
")",
";",
"}"
] | helper function
extract video id and other parameters from url
@param string[] $url_parsed result of parse_url($url) | [
"helper",
"function",
"extract",
"video",
"id",
"and",
"other",
"parameters",
"from",
"url"
] | 00102c35ec5267b42c627f1e34b8e64a7dd3590c | https://github.com/phata/widgetfy/blob/00102c35ec5267b42c627f1e34b8e64a7dd3590c/src/Site/Youtube.php#L200-L255 | train |
PageBoost/hipchat-php-v2 | src/PageBoost/HipChatV2/Resources/Rooms.php | Rooms.update | public function update($name, $is_public, $is_archived, $is_guest_accessible, $topic, $owner_user_id)
{
$queryParams = array(
'name' => $name,
'privacy' => (($is_public === true) ? 'public' : 'private' ),
'is_archived' => $is_archived,
'is_guest_accessible' => $is_guest_accessible,
'topic' => $topic,
'owner' => array(
'id' => $owner_user_id,
),
);
$room_id_or_name = $this->getId();
$response = $this->request->put('room/'.$room_id_or_name.'', $queryParams);
return $this->request->returnResponseObject($response);
} | php | public function update($name, $is_public, $is_archived, $is_guest_accessible, $topic, $owner_user_id)
{
$queryParams = array(
'name' => $name,
'privacy' => (($is_public === true) ? 'public' : 'private' ),
'is_archived' => $is_archived,
'is_guest_accessible' => $is_guest_accessible,
'topic' => $topic,
'owner' => array(
'id' => $owner_user_id,
),
);
$room_id_or_name = $this->getId();
$response = $this->request->put('room/'.$room_id_or_name.'', $queryParams);
return $this->request->returnResponseObject($response);
} | [
"public",
"function",
"update",
"(",
"$",
"name",
",",
"$",
"is_public",
",",
"$",
"is_archived",
",",
"$",
"is_guest_accessible",
",",
"$",
"topic",
",",
"$",
"owner_user_id",
")",
"{",
"$",
"queryParams",
"=",
"array",
"(",
"'name'",
"=>",
"$",
"name",
",",
"'privacy'",
"=>",
"(",
"(",
"$",
"is_public",
"===",
"true",
")",
"?",
"'public'",
":",
"'private'",
")",
",",
"'is_archived'",
"=>",
"$",
"is_archived",
",",
"'is_guest_accessible'",
"=>",
"$",
"is_guest_accessible",
",",
"'topic'",
"=>",
"$",
"topic",
",",
"'owner'",
"=>",
"array",
"(",
"'id'",
"=>",
"$",
"owner_user_id",
",",
")",
",",
")",
";",
"$",
"room_id_or_name",
"=",
"$",
"this",
"->",
"getId",
"(",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"request",
"->",
"put",
"(",
"'room/'",
".",
"$",
"room_id_or_name",
".",
"''",
",",
"$",
"queryParams",
")",
";",
"return",
"$",
"this",
"->",
"request",
"->",
"returnResponseObject",
"(",
"$",
"response",
")",
";",
"}"
] | Update room
All values are required!
@param string $name
@param bool $is_public
@param bool $is_archived
@param bool $is_guest_accessible
@param string $topic
@param int|string $owner_user_id | [
"Update",
"room",
"All",
"values",
"are",
"required!"
] | 47625e17fba273b7cc916268d972b4ca8cc48c0c | https://github.com/PageBoost/hipchat-php-v2/blob/47625e17fba273b7cc916268d972b4ca8cc48c0c/src/PageBoost/HipChatV2/Resources/Rooms.php#L89-L106 | train |
PageBoost/hipchat-php-v2 | src/PageBoost/HipChatV2/Resources/Rooms.php | Rooms.setTopic | public function setTopic($topic)
{
$queryParams = array(
'topic' => $topic,
);
$room_id_or_name = $this->getId();
$response = $this->request->put('room/'.$room_id_or_name.'/topic', $queryParams);
return $this->request->returnResponseObject($response);
} | php | public function setTopic($topic)
{
$queryParams = array(
'topic' => $topic,
);
$room_id_or_name = $this->getId();
$response = $this->request->put('room/'.$room_id_or_name.'/topic', $queryParams);
return $this->request->returnResponseObject($response);
} | [
"public",
"function",
"setTopic",
"(",
"$",
"topic",
")",
"{",
"$",
"queryParams",
"=",
"array",
"(",
"'topic'",
"=>",
"$",
"topic",
",",
")",
";",
"$",
"room_id_or_name",
"=",
"$",
"this",
"->",
"getId",
"(",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"request",
"->",
"put",
"(",
"'room/'",
".",
"$",
"room_id_or_name",
".",
"'/topic'",
",",
"$",
"queryParams",
")",
";",
"return",
"$",
"this",
"->",
"request",
"->",
"returnResponseObject",
"(",
"$",
"response",
")",
";",
"}"
] | Set room topic
@param string $topic | [
"Set",
"room",
"topic"
] | 47625e17fba273b7cc916268d972b4ca8cc48c0c | https://github.com/PageBoost/hipchat-php-v2/blob/47625e17fba273b7cc916268d972b4ca8cc48c0c/src/PageBoost/HipChatV2/Resources/Rooms.php#L123-L133 | train |
netlogix/Netlogix.Crud | Classes/Netlogix/Crud/Controller/RestController.php | RestController.errorAction | public function errorAction() {
$validationResults = $this->arguments->getValidationResults()->getFlattenedErrors();
$result = array();
/** @var \Neos\Error\Messages\Error $validationResult */
foreach ($validationResults as $key => $validationResult) {
/** @var \Neos\Flow\Validation\Error $error */
foreach ($validationResult as $error) {
// Check Current Package Validation Errors
$translatedMessage = $this->translator->translateById($error->getCode(), $error->getArguments(), NULL, NULL, 'ValidationErrors', $this->request->getControllerPackageKey());
// Check Flow Validation Errors
if ($translatedMessage === $error->getCode()) {
$translatedMessage = $this->translator->translateById($error->getCode(), $error->getArguments(), NULL, NULL, 'ValidationErrors', 'Neos.Flow');
}
// Use default error message
if ($translatedMessage === $error->getCode()) {
$translatedMessage = $error->render();
}
$result['errors'][$key][] = array(
'code' => $error->getCode(),
'message' => $translatedMessage
);
}
}
$result['success'] = FALSE;
$this->view->assign('value', $result);
$this->response->setStatus(400);
} | php | public function errorAction() {
$validationResults = $this->arguments->getValidationResults()->getFlattenedErrors();
$result = array();
/** @var \Neos\Error\Messages\Error $validationResult */
foreach ($validationResults as $key => $validationResult) {
/** @var \Neos\Flow\Validation\Error $error */
foreach ($validationResult as $error) {
// Check Current Package Validation Errors
$translatedMessage = $this->translator->translateById($error->getCode(), $error->getArguments(), NULL, NULL, 'ValidationErrors', $this->request->getControllerPackageKey());
// Check Flow Validation Errors
if ($translatedMessage === $error->getCode()) {
$translatedMessage = $this->translator->translateById($error->getCode(), $error->getArguments(), NULL, NULL, 'ValidationErrors', 'Neos.Flow');
}
// Use default error message
if ($translatedMessage === $error->getCode()) {
$translatedMessage = $error->render();
}
$result['errors'][$key][] = array(
'code' => $error->getCode(),
'message' => $translatedMessage
);
}
}
$result['success'] = FALSE;
$this->view->assign('value', $result);
$this->response->setStatus(400);
} | [
"public",
"function",
"errorAction",
"(",
")",
"{",
"$",
"validationResults",
"=",
"$",
"this",
"->",
"arguments",
"->",
"getValidationResults",
"(",
")",
"->",
"getFlattenedErrors",
"(",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"/** @var \\Neos\\Error\\Messages\\Error $validationResult */",
"foreach",
"(",
"$",
"validationResults",
"as",
"$",
"key",
"=>",
"$",
"validationResult",
")",
"{",
"/** @var \\Neos\\Flow\\Validation\\Error $error */",
"foreach",
"(",
"$",
"validationResult",
"as",
"$",
"error",
")",
"{",
"// Check Current Package Validation Errors",
"$",
"translatedMessage",
"=",
"$",
"this",
"->",
"translator",
"->",
"translateById",
"(",
"$",
"error",
"->",
"getCode",
"(",
")",
",",
"$",
"error",
"->",
"getArguments",
"(",
")",
",",
"NULL",
",",
"NULL",
",",
"'ValidationErrors'",
",",
"$",
"this",
"->",
"request",
"->",
"getControllerPackageKey",
"(",
")",
")",
";",
"// Check Flow Validation Errors",
"if",
"(",
"$",
"translatedMessage",
"===",
"$",
"error",
"->",
"getCode",
"(",
")",
")",
"{",
"$",
"translatedMessage",
"=",
"$",
"this",
"->",
"translator",
"->",
"translateById",
"(",
"$",
"error",
"->",
"getCode",
"(",
")",
",",
"$",
"error",
"->",
"getArguments",
"(",
")",
",",
"NULL",
",",
"NULL",
",",
"'ValidationErrors'",
",",
"'Neos.Flow'",
")",
";",
"}",
"// Use default error message",
"if",
"(",
"$",
"translatedMessage",
"===",
"$",
"error",
"->",
"getCode",
"(",
")",
")",
"{",
"$",
"translatedMessage",
"=",
"$",
"error",
"->",
"render",
"(",
")",
";",
"}",
"$",
"result",
"[",
"'errors'",
"]",
"[",
"$",
"key",
"]",
"[",
"]",
"=",
"array",
"(",
"'code'",
"=>",
"$",
"error",
"->",
"getCode",
"(",
")",
",",
"'message'",
"=>",
"$",
"translatedMessage",
")",
";",
"}",
"}",
"$",
"result",
"[",
"'success'",
"]",
"=",
"FALSE",
";",
"$",
"this",
"->",
"view",
"->",
"assign",
"(",
"'value'",
",",
"$",
"result",
")",
";",
"$",
"this",
"->",
"response",
"->",
"setStatus",
"(",
"400",
")",
";",
"}"
] | Return validation results as json | [
"Return",
"validation",
"results",
"as",
"json"
] | 61438827ba6b0a7a63cd2f08a294967ed5928144 | https://github.com/netlogix/Netlogix.Crud/blob/61438827ba6b0a7a63cd2f08a294967ed5928144/Classes/Netlogix/Crud/Controller/RestController.php#L252-L281 | train |
chalasr/RCHCapistranoBundle | Command/Deploy/SetupCommand.php | SetupCommand.interact | protected function interact(InputInterface $input, OutputInterface $output)
{
$questionHelper = $this->getHelper('question');
$formatter = $this->getHelper('formatter');
$rootDir = $this->getRootDir();
$fs = new Filesystem();
$appPath = explode('/', $rootDir);
$appName = $appPath[count($appPath) - 2];
$this->initConfig($fs, $rootDir);
$output->writeln([$formatter->formatSection('SETUP', 'Project settings'), '']);
$deployData = $this->configureDeploy($input, $output, $questionHelper, $appName);
$deploy = new DeployGenerator($deployData, $rootDir);
$this->generate($deploy);
$output->writeln(['', " > generating <comment>{$appName}/config/deploy.rb</comment>"]);
$output->writeln(['<info>Successfully created.</info>', '']);
$output->writeln([$formatter->formatSection('PRODUCTION', 'Remote server / SSH settings'), '']);
$sshProps = $this->configureSSH($input, $output, $questionHelper, $deployData);
$staging = new StagingGenerator($sshProps, $this->getCapistranoDeployDir());
$yamlStaging = new YamlStagingGenerator($sshProps, $this->getStagingsConfigDir());
$this->generateMany([$staging, $yamlStaging]);
return $output->writeln('<comment>Remote server successfully configured</comment>');
} | php | protected function interact(InputInterface $input, OutputInterface $output)
{
$questionHelper = $this->getHelper('question');
$formatter = $this->getHelper('formatter');
$rootDir = $this->getRootDir();
$fs = new Filesystem();
$appPath = explode('/', $rootDir);
$appName = $appPath[count($appPath) - 2];
$this->initConfig($fs, $rootDir);
$output->writeln([$formatter->formatSection('SETUP', 'Project settings'), '']);
$deployData = $this->configureDeploy($input, $output, $questionHelper, $appName);
$deploy = new DeployGenerator($deployData, $rootDir);
$this->generate($deploy);
$output->writeln(['', " > generating <comment>{$appName}/config/deploy.rb</comment>"]);
$output->writeln(['<info>Successfully created.</info>', '']);
$output->writeln([$formatter->formatSection('PRODUCTION', 'Remote server / SSH settings'), '']);
$sshProps = $this->configureSSH($input, $output, $questionHelper, $deployData);
$staging = new StagingGenerator($sshProps, $this->getCapistranoDeployDir());
$yamlStaging = new YamlStagingGenerator($sshProps, $this->getStagingsConfigDir());
$this->generateMany([$staging, $yamlStaging]);
return $output->writeln('<comment>Remote server successfully configured</comment>');
} | [
"protected",
"function",
"interact",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"questionHelper",
"=",
"$",
"this",
"->",
"getHelper",
"(",
"'question'",
")",
";",
"$",
"formatter",
"=",
"$",
"this",
"->",
"getHelper",
"(",
"'formatter'",
")",
";",
"$",
"rootDir",
"=",
"$",
"this",
"->",
"getRootDir",
"(",
")",
";",
"$",
"fs",
"=",
"new",
"Filesystem",
"(",
")",
";",
"$",
"appPath",
"=",
"explode",
"(",
"'/'",
",",
"$",
"rootDir",
")",
";",
"$",
"appName",
"=",
"$",
"appPath",
"[",
"count",
"(",
"$",
"appPath",
")",
"-",
"2",
"]",
";",
"$",
"this",
"->",
"initConfig",
"(",
"$",
"fs",
",",
"$",
"rootDir",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"[",
"$",
"formatter",
"->",
"formatSection",
"(",
"'SETUP'",
",",
"'Project settings'",
")",
",",
"''",
"]",
")",
";",
"$",
"deployData",
"=",
"$",
"this",
"->",
"configureDeploy",
"(",
"$",
"input",
",",
"$",
"output",
",",
"$",
"questionHelper",
",",
"$",
"appName",
")",
";",
"$",
"deploy",
"=",
"new",
"DeployGenerator",
"(",
"$",
"deployData",
",",
"$",
"rootDir",
")",
";",
"$",
"this",
"->",
"generate",
"(",
"$",
"deploy",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"[",
"''",
",",
"\" > generating <comment>{$appName}/config/deploy.rb</comment>\"",
"]",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"[",
"'<info>Successfully created.</info>'",
",",
"''",
"]",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"[",
"$",
"formatter",
"->",
"formatSection",
"(",
"'PRODUCTION'",
",",
"'Remote server / SSH settings'",
")",
",",
"''",
"]",
")",
";",
"$",
"sshProps",
"=",
"$",
"this",
"->",
"configureSSH",
"(",
"$",
"input",
",",
"$",
"output",
",",
"$",
"questionHelper",
",",
"$",
"deployData",
")",
";",
"$",
"staging",
"=",
"new",
"StagingGenerator",
"(",
"$",
"sshProps",
",",
"$",
"this",
"->",
"getCapistranoDeployDir",
"(",
")",
")",
";",
"$",
"yamlStaging",
"=",
"new",
"YamlStagingGenerator",
"(",
"$",
"sshProps",
",",
"$",
"this",
"->",
"getStagingsConfigDir",
"(",
")",
")",
";",
"$",
"this",
"->",
"generateMany",
"(",
"[",
"$",
"staging",
",",
"$",
"yamlStaging",
"]",
")",
";",
"return",
"$",
"output",
"->",
"writeln",
"(",
"'<comment>Remote server successfully configured</comment>'",
")",
";",
"}"
] | Configures deployment.
@param InputInterface $input
@param OutputInterface $output
@return OutputInterface | [
"Configures",
"deployment",
"."
] | c4a4cbaa2bc05f33bf431fd3afe6cac39947640e | https://github.com/chalasr/RCHCapistranoBundle/blob/c4a4cbaa2bc05f33bf431fd3afe6cac39947640e/Command/Deploy/SetupCommand.php#L62-L89 | train |
chalasr/RCHCapistranoBundle | Command/Deploy/SetupCommand.php | SetupCommand.initConfig | protected function initConfig(Filesystem $fs, $rootDir)
{
$bundleDir = $this->getBundleVendorDir();
$path = $this->getCapistranoDir();
if (!$fs->exists($path.'/deploy.rb') || !$fs->exists($path.'/deploy/production.rb')) {
return $fs->mirror($bundleDir.'/Resources/config/capistrano', $path);
}
$fs->remove($path.'/deploy.rb');
$fs->remove($path.'/deploy');
$fs->remove($path);
return $fs->mirror($bundleDir.'/Resources/config/capistrano', $path);
} | php | protected function initConfig(Filesystem $fs, $rootDir)
{
$bundleDir = $this->getBundleVendorDir();
$path = $this->getCapistranoDir();
if (!$fs->exists($path.'/deploy.rb') || !$fs->exists($path.'/deploy/production.rb')) {
return $fs->mirror($bundleDir.'/Resources/config/capistrano', $path);
}
$fs->remove($path.'/deploy.rb');
$fs->remove($path.'/deploy');
$fs->remove($path);
return $fs->mirror($bundleDir.'/Resources/config/capistrano', $path);
} | [
"protected",
"function",
"initConfig",
"(",
"Filesystem",
"$",
"fs",
",",
"$",
"rootDir",
")",
"{",
"$",
"bundleDir",
"=",
"$",
"this",
"->",
"getBundleVendorDir",
"(",
")",
";",
"$",
"path",
"=",
"$",
"this",
"->",
"getCapistranoDir",
"(",
")",
";",
"if",
"(",
"!",
"$",
"fs",
"->",
"exists",
"(",
"$",
"path",
".",
"'/deploy.rb'",
")",
"||",
"!",
"$",
"fs",
"->",
"exists",
"(",
"$",
"path",
".",
"'/deploy/production.rb'",
")",
")",
"{",
"return",
"$",
"fs",
"->",
"mirror",
"(",
"$",
"bundleDir",
".",
"'/Resources/config/capistrano'",
",",
"$",
"path",
")",
";",
"}",
"$",
"fs",
"->",
"remove",
"(",
"$",
"path",
".",
"'/deploy.rb'",
")",
";",
"$",
"fs",
"->",
"remove",
"(",
"$",
"path",
".",
"'/deploy'",
")",
";",
"$",
"fs",
"->",
"remove",
"(",
"$",
"path",
")",
";",
"return",
"$",
"fs",
"->",
"mirror",
"(",
"$",
"bundleDir",
".",
"'/Resources/config/capistrano'",
",",
"$",
"path",
")",
";",
"}"
] | Dump capistrano configuration skin from Resources directory.
@param Filesystem $fs
@param string $rootDir Application root dir | [
"Dump",
"capistrano",
"configuration",
"skin",
"from",
"Resources",
"directory",
"."
] | c4a4cbaa2bc05f33bf431fd3afe6cac39947640e | https://github.com/chalasr/RCHCapistranoBundle/blob/c4a4cbaa2bc05f33bf431fd3afe6cac39947640e/Command/Deploy/SetupCommand.php#L97-L111 | train |
chalasr/RCHCapistranoBundle | Command/Deploy/SetupCommand.php | SetupCommand.configureDeploy | protected function configureDeploy(InputInterface $input, OutputInterface $output, QuestionHelper $questionHelper, $appName)
{
$data = [];
$properties = array(
'application' => array(
'helper' => $appName,
'label' => 'Application',
'autocomplete' => [$appName],
),
'repo_url' => array(
'helper' => '[email protected]:{user}/{repo}.git',
'label' => 'Repository',
'autocomplete' => [sprintf('[email protected]:chalasr/%s.git', $appName)],
),
);
$properties += Yaml::parse(file_get_contents($this->getBundleVendorDir().'/Resources/config/setup_dialog.yml'));
foreach ($properties as $key => $property) {
if ('deploy_to' == $key && null !== $data['ssh_user']) {
$property['helper'] = "/home/{$data['ssh_user']}/public_html";
}
$question = new Question("<info>{$property['label']}</info> [<comment>{$property['helper']}</comment>]: ", $property['helper']);
if (isset($property['autocomplete'])) {
$question->setAutocompleterValues($property['autocomplete']);
}
$data[$key] = $questionHelper->ask($input, $output, $question);
}
$data['composer'] = $this->checkComposer($input, $output, $questionHelper, $data);
$data['schemadb'] = $this->checkSchemaUpdate($input, $output, $questionHelper, $data);
return $data;
} | php | protected function configureDeploy(InputInterface $input, OutputInterface $output, QuestionHelper $questionHelper, $appName)
{
$data = [];
$properties = array(
'application' => array(
'helper' => $appName,
'label' => 'Application',
'autocomplete' => [$appName],
),
'repo_url' => array(
'helper' => '[email protected]:{user}/{repo}.git',
'label' => 'Repository',
'autocomplete' => [sprintf('[email protected]:chalasr/%s.git', $appName)],
),
);
$properties += Yaml::parse(file_get_contents($this->getBundleVendorDir().'/Resources/config/setup_dialog.yml'));
foreach ($properties as $key => $property) {
if ('deploy_to' == $key && null !== $data['ssh_user']) {
$property['helper'] = "/home/{$data['ssh_user']}/public_html";
}
$question = new Question("<info>{$property['label']}</info> [<comment>{$property['helper']}</comment>]: ", $property['helper']);
if (isset($property['autocomplete'])) {
$question->setAutocompleterValues($property['autocomplete']);
}
$data[$key] = $questionHelper->ask($input, $output, $question);
}
$data['composer'] = $this->checkComposer($input, $output, $questionHelper, $data);
$data['schemadb'] = $this->checkSchemaUpdate($input, $output, $questionHelper, $data);
return $data;
} | [
"protected",
"function",
"configureDeploy",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
",",
"QuestionHelper",
"$",
"questionHelper",
",",
"$",
"appName",
")",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"$",
"properties",
"=",
"array",
"(",
"'application'",
"=>",
"array",
"(",
"'helper'",
"=>",
"$",
"appName",
",",
"'label'",
"=>",
"'Application'",
",",
"'autocomplete'",
"=>",
"[",
"$",
"appName",
"]",
",",
")",
",",
"'repo_url'",
"=>",
"array",
"(",
"'helper'",
"=>",
"'[email protected]:{user}/{repo}.git'",
",",
"'label'",
"=>",
"'Repository'",
",",
"'autocomplete'",
"=>",
"[",
"sprintf",
"(",
"'[email protected]:chalasr/%s.git'",
",",
"$",
"appName",
")",
"]",
",",
")",
",",
")",
";",
"$",
"properties",
"+=",
"Yaml",
"::",
"parse",
"(",
"file_get_contents",
"(",
"$",
"this",
"->",
"getBundleVendorDir",
"(",
")",
".",
"'/Resources/config/setup_dialog.yml'",
")",
")",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"key",
"=>",
"$",
"property",
")",
"{",
"if",
"(",
"'deploy_to'",
"==",
"$",
"key",
"&&",
"null",
"!==",
"$",
"data",
"[",
"'ssh_user'",
"]",
")",
"{",
"$",
"property",
"[",
"'helper'",
"]",
"=",
"\"/home/{$data['ssh_user']}/public_html\"",
";",
"}",
"$",
"question",
"=",
"new",
"Question",
"(",
"\"<info>{$property['label']}</info> [<comment>{$property['helper']}</comment>]: \"",
",",
"$",
"property",
"[",
"'helper'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"property",
"[",
"'autocomplete'",
"]",
")",
")",
"{",
"$",
"question",
"->",
"setAutocompleterValues",
"(",
"$",
"property",
"[",
"'autocomplete'",
"]",
")",
";",
"}",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"questionHelper",
"->",
"ask",
"(",
"$",
"input",
",",
"$",
"output",
",",
"$",
"question",
")",
";",
"}",
"$",
"data",
"[",
"'composer'",
"]",
"=",
"$",
"this",
"->",
"checkComposer",
"(",
"$",
"input",
",",
"$",
"output",
",",
"$",
"questionHelper",
",",
"$",
"data",
")",
";",
"$",
"data",
"[",
"'schemadb'",
"]",
"=",
"$",
"this",
"->",
"checkSchemaUpdate",
"(",
"$",
"input",
",",
"$",
"output",
",",
"$",
"questionHelper",
",",
"$",
"data",
")",
";",
"return",
"$",
"data",
";",
"}"
] | Configure deploy.rb capistrano file.
@param InputInterface $input
@param OutputInterface $output
@param QuestionHelper $questionHelper
@param string $appName
@return array | [
"Configure",
"deploy",
".",
"rb",
"capistrano",
"file",
"."
] | c4a4cbaa2bc05f33bf431fd3afe6cac39947640e | https://github.com/chalasr/RCHCapistranoBundle/blob/c4a4cbaa2bc05f33bf431fd3afe6cac39947640e/Command/Deploy/SetupCommand.php#L123-L159 | train |
chalasr/RCHCapistranoBundle | Command/Deploy/SetupCommand.php | SetupCommand.checkComposer | protected function checkComposer(InputInterface $input, OutputInterface $output, QuestionHelper $questionHelper, $deployData)
{
$question = new Question('<info>Download composer</info> [<comment>yes</comment>]: ', 'yes');
$question->setAutocompleterValues(['yes', 'no']);
$downloadComposer = $questionHelper->ask($input, $output, $question);
$deployData['composer'] = $downloadComposer == 'yes' ? true : false;
return $deployData['composer'];
} | php | protected function checkComposer(InputInterface $input, OutputInterface $output, QuestionHelper $questionHelper, $deployData)
{
$question = new Question('<info>Download composer</info> [<comment>yes</comment>]: ', 'yes');
$question->setAutocompleterValues(['yes', 'no']);
$downloadComposer = $questionHelper->ask($input, $output, $question);
$deployData['composer'] = $downloadComposer == 'yes' ? true : false;
return $deployData['composer'];
} | [
"protected",
"function",
"checkComposer",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
",",
"QuestionHelper",
"$",
"questionHelper",
",",
"$",
"deployData",
")",
"{",
"$",
"question",
"=",
"new",
"Question",
"(",
"'<info>Download composer</info> [<comment>yes</comment>]: '",
",",
"'yes'",
")",
";",
"$",
"question",
"->",
"setAutocompleterValues",
"(",
"[",
"'yes'",
",",
"'no'",
"]",
")",
";",
"$",
"downloadComposer",
"=",
"$",
"questionHelper",
"->",
"ask",
"(",
"$",
"input",
",",
"$",
"output",
",",
"$",
"question",
")",
";",
"$",
"deployData",
"[",
"'composer'",
"]",
"=",
"$",
"downloadComposer",
"==",
"'yes'",
"?",
"true",
":",
"false",
";",
"return",
"$",
"deployData",
"[",
"'composer'",
"]",
";",
"}"
] | Check need of composer.
@param InputInterface $input
@param OutputInterface $output
@param QuestionHelper $questionHelper
@param array $deployData
@return bool | [
"Check",
"need",
"of",
"composer",
"."
] | c4a4cbaa2bc05f33bf431fd3afe6cac39947640e | https://github.com/chalasr/RCHCapistranoBundle/blob/c4a4cbaa2bc05f33bf431fd3afe6cac39947640e/Command/Deploy/SetupCommand.php#L171-L179 | train |
chalasr/RCHCapistranoBundle | Command/Deploy/SetupCommand.php | SetupCommand.checkSchemaUpdate | protected function checkSchemaUpdate(InputInterface $input, OutputInterface $output, QuestionHelper $questionHelper, $deployData)
{
$question = new Question('<info>Update database schema</info> [<comment>yes</comment>]: ', 'yes');
$question->setAutocompleterValues(['yes', 'no']);
$wantDump = $questionHelper->ask($input, $output, $question);
$deployData['schemadb'] = $wantDump == 'yes' ? true : false;
return $deployData['schemadb'];
} | php | protected function checkSchemaUpdate(InputInterface $input, OutputInterface $output, QuestionHelper $questionHelper, $deployData)
{
$question = new Question('<info>Update database schema</info> [<comment>yes</comment>]: ', 'yes');
$question->setAutocompleterValues(['yes', 'no']);
$wantDump = $questionHelper->ask($input, $output, $question);
$deployData['schemadb'] = $wantDump == 'yes' ? true : false;
return $deployData['schemadb'];
} | [
"protected",
"function",
"checkSchemaUpdate",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
",",
"QuestionHelper",
"$",
"questionHelper",
",",
"$",
"deployData",
")",
"{",
"$",
"question",
"=",
"new",
"Question",
"(",
"'<info>Update database schema</info> [<comment>yes</comment>]: '",
",",
"'yes'",
")",
";",
"$",
"question",
"->",
"setAutocompleterValues",
"(",
"[",
"'yes'",
",",
"'no'",
"]",
")",
";",
"$",
"wantDump",
"=",
"$",
"questionHelper",
"->",
"ask",
"(",
"$",
"input",
",",
"$",
"output",
",",
"$",
"question",
")",
";",
"$",
"deployData",
"[",
"'schemadb'",
"]",
"=",
"$",
"wantDump",
"==",
"'yes'",
"?",
"true",
":",
"false",
";",
"return",
"$",
"deployData",
"[",
"'schemadb'",
"]",
";",
"}"
] | Check for database schema update.
@param InputInterface $input
@param OutputInterface $output
@param QuestionHelper $questionHelper
@param array $deployData
@return bool | [
"Check",
"for",
"database",
"schema",
"update",
"."
] | c4a4cbaa2bc05f33bf431fd3afe6cac39947640e | https://github.com/chalasr/RCHCapistranoBundle/blob/c4a4cbaa2bc05f33bf431fd3afe6cac39947640e/Command/Deploy/SetupCommand.php#L191-L199 | train |
chalasr/RCHCapistranoBundle | Command/Deploy/SetupCommand.php | SetupCommand.configureSSH | protected function configureSSH(InputInterface $input, OutputInterface $output, QuestionHelper $questionHelper, $deployData)
{
$serverOptions = [
'domain' => [
'helper' => $deployData['ssh_user'],
'label' => 'Domain name',
],
];
$sshOptions = [
'forwardAgent' => [
'label' => 'SSH forward agent',
'helper' => 'false',
],
'authMethods' => [
'label' => 'SSH auth method',
'helper' => 'publickey password',
],
'keys' => [
'label' => 'Remote SSH key',
'helper' => sprintf('/home/%s/.ssh/id_rsa', $deployData['ssh_user']),
],
];
$sshProps = [
'user' => $deployData['ssh_user'],
'keys' => '',
'forwardAgent' => false,
'authMethods' => 'publickey password',
'deployTo' => $deployData['deploy_to'],
'repoUrl' => $deployData['repo_url'],
];
$question = new Question("<info>{$serverOptions['domain']['label']}</info> [<comment>{$serverOptions['domain']['helper']}</comment>]: ", $serverOptions['domain']['helper']);
$sshProps['domain'] = $questionHelper->ask($input, $output, $question);
foreach ($sshOptions as $key => $property) {
$question = new Question("<info>{$property['label']}</info> [<comment>{$property['helper']}</comment>]: ", $property['helper']);
if (isset($property['autocomplete'])) {
$question->setAutocompleterValues($property['autocomplete']);
}
$sshProps[$key] = $questionHelper->ask($input, $output, $question);
}
return $sshProps;
} | php | protected function configureSSH(InputInterface $input, OutputInterface $output, QuestionHelper $questionHelper, $deployData)
{
$serverOptions = [
'domain' => [
'helper' => $deployData['ssh_user'],
'label' => 'Domain name',
],
];
$sshOptions = [
'forwardAgent' => [
'label' => 'SSH forward agent',
'helper' => 'false',
],
'authMethods' => [
'label' => 'SSH auth method',
'helper' => 'publickey password',
],
'keys' => [
'label' => 'Remote SSH key',
'helper' => sprintf('/home/%s/.ssh/id_rsa', $deployData['ssh_user']),
],
];
$sshProps = [
'user' => $deployData['ssh_user'],
'keys' => '',
'forwardAgent' => false,
'authMethods' => 'publickey password',
'deployTo' => $deployData['deploy_to'],
'repoUrl' => $deployData['repo_url'],
];
$question = new Question("<info>{$serverOptions['domain']['label']}</info> [<comment>{$serverOptions['domain']['helper']}</comment>]: ", $serverOptions['domain']['helper']);
$sshProps['domain'] = $questionHelper->ask($input, $output, $question);
foreach ($sshOptions as $key => $property) {
$question = new Question("<info>{$property['label']}</info> [<comment>{$property['helper']}</comment>]: ", $property['helper']);
if (isset($property['autocomplete'])) {
$question->setAutocompleterValues($property['autocomplete']);
}
$sshProps[$key] = $questionHelper->ask($input, $output, $question);
}
return $sshProps;
} | [
"protected",
"function",
"configureSSH",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
",",
"QuestionHelper",
"$",
"questionHelper",
",",
"$",
"deployData",
")",
"{",
"$",
"serverOptions",
"=",
"[",
"'domain'",
"=>",
"[",
"'helper'",
"=>",
"$",
"deployData",
"[",
"'ssh_user'",
"]",
",",
"'label'",
"=>",
"'Domain name'",
",",
"]",
",",
"]",
";",
"$",
"sshOptions",
"=",
"[",
"'forwardAgent'",
"=>",
"[",
"'label'",
"=>",
"'SSH forward agent'",
",",
"'helper'",
"=>",
"'false'",
",",
"]",
",",
"'authMethods'",
"=>",
"[",
"'label'",
"=>",
"'SSH auth method'",
",",
"'helper'",
"=>",
"'publickey password'",
",",
"]",
",",
"'keys'",
"=>",
"[",
"'label'",
"=>",
"'Remote SSH key'",
",",
"'helper'",
"=>",
"sprintf",
"(",
"'/home/%s/.ssh/id_rsa'",
",",
"$",
"deployData",
"[",
"'ssh_user'",
"]",
")",
",",
"]",
",",
"]",
";",
"$",
"sshProps",
"=",
"[",
"'user'",
"=>",
"$",
"deployData",
"[",
"'ssh_user'",
"]",
",",
"'keys'",
"=>",
"''",
",",
"'forwardAgent'",
"=>",
"false",
",",
"'authMethods'",
"=>",
"'publickey password'",
",",
"'deployTo'",
"=>",
"$",
"deployData",
"[",
"'deploy_to'",
"]",
",",
"'repoUrl'",
"=>",
"$",
"deployData",
"[",
"'repo_url'",
"]",
",",
"]",
";",
"$",
"question",
"=",
"new",
"Question",
"(",
"\"<info>{$serverOptions['domain']['label']}</info> [<comment>{$serverOptions['domain']['helper']}</comment>]: \"",
",",
"$",
"serverOptions",
"[",
"'domain'",
"]",
"[",
"'helper'",
"]",
")",
";",
"$",
"sshProps",
"[",
"'domain'",
"]",
"=",
"$",
"questionHelper",
"->",
"ask",
"(",
"$",
"input",
",",
"$",
"output",
",",
"$",
"question",
")",
";",
"foreach",
"(",
"$",
"sshOptions",
"as",
"$",
"key",
"=>",
"$",
"property",
")",
"{",
"$",
"question",
"=",
"new",
"Question",
"(",
"\"<info>{$property['label']}</info> [<comment>{$property['helper']}</comment>]: \"",
",",
"$",
"property",
"[",
"'helper'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"property",
"[",
"'autocomplete'",
"]",
")",
")",
"{",
"$",
"question",
"->",
"setAutocompleterValues",
"(",
"$",
"property",
"[",
"'autocomplete'",
"]",
")",
";",
"}",
"$",
"sshProps",
"[",
"$",
"key",
"]",
"=",
"$",
"questionHelper",
"->",
"ask",
"(",
"$",
"input",
",",
"$",
"output",
",",
"$",
"question",
")",
";",
"}",
"return",
"$",
"sshProps",
";",
"}"
] | Configure SSH options for production staging.
@param InputInterface $input
@param OutputInterface $output
@param QuestionHelper $questionHelper
@param array $deployData
@return array The production staging configuration | [
"Configure",
"SSH",
"options",
"for",
"production",
"staging",
"."
] | c4a4cbaa2bc05f33bf431fd3afe6cac39947640e | https://github.com/chalasr/RCHCapistranoBundle/blob/c4a4cbaa2bc05f33bf431fd3afe6cac39947640e/Command/Deploy/SetupCommand.php#L211-L256 | train |
PenoaksDev/Milky-Framework | src/Milky/Helpers/Func.php | Func.randomStr | public static function randomStr( $base )
{
$result = "";
if ( is_int( $base ) )
for ( $i = 0; $i < $base; $i++ )
$result .= static::$randomCharMap[random_int( 0, count( static::$randomCharMap ) )];
else
for ( $i = 0; $i < strlen( $base ); $i++ )
$result .= static::randomChar( $base[$i] );
return $result;
} | php | public static function randomStr( $base )
{
$result = "";
if ( is_int( $base ) )
for ( $i = 0; $i < $base; $i++ )
$result .= static::$randomCharMap[random_int( 0, count( static::$randomCharMap ) )];
else
for ( $i = 0; $i < strlen( $base ); $i++ )
$result .= static::randomChar( $base[$i] );
return $result;
} | [
"public",
"static",
"function",
"randomStr",
"(",
"$",
"base",
")",
"{",
"$",
"result",
"=",
"\"\"",
";",
"if",
"(",
"is_int",
"(",
"$",
"base",
")",
")",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"base",
";",
"$",
"i",
"++",
")",
"$",
"result",
".=",
"static",
"::",
"$",
"randomCharMap",
"[",
"random_int",
"(",
"0",
",",
"count",
"(",
"static",
"::",
"$",
"randomCharMap",
")",
")",
"]",
";",
"else",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"strlen",
"(",
"$",
"base",
")",
";",
"$",
"i",
"++",
")",
"$",
"result",
".=",
"static",
"::",
"randomChar",
"(",
"$",
"base",
"[",
"$",
"i",
"]",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Scrambles of string of characters but keeps the results either uppercase, lowercase, or numeric
@param string|int $base | [
"Scrambles",
"of",
"string",
"of",
"characters",
"but",
"keeps",
"the",
"results",
"either",
"uppercase",
"lowercase",
"or",
"numeric"
] | 8afd7156610a70371aa5b1df50b8a212bf7b142c | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Helpers/Func.php#L106-L118 | train |
PenoaksDev/Milky-Framework | src/Milky/Helpers/Func.php | Func.randomChars | public static function randomChars( $seed, $len )
{
$result = '';
for ( $i = 0; $i < $len; $i++ )
$result .= $seed[random_int( 0, strlen( $seed ) )];
return $result;
} | php | public static function randomChars( $seed, $len )
{
$result = '';
for ( $i = 0; $i < $len; $i++ )
$result .= $seed[random_int( 0, strlen( $seed ) )];
return $result;
} | [
"public",
"static",
"function",
"randomChars",
"(",
"$",
"seed",
",",
"$",
"len",
")",
"{",
"$",
"result",
"=",
"''",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"len",
";",
"$",
"i",
"++",
")",
"$",
"result",
".=",
"$",
"seed",
"[",
"random_int",
"(",
"0",
",",
"strlen",
"(",
"$",
"seed",
")",
")",
"]",
";",
"return",
"$",
"result",
";",
"}"
] | Randomizes from the provided seed
@param string $seed
@param int $len
@return string | [
"Randomizes",
"from",
"the",
"provided",
"seed"
] | 8afd7156610a70371aa5b1df50b8a212bf7b142c | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Helpers/Func.php#L127-L135 | train |
PenoaksDev/Milky-Framework | src/Milky/Helpers/Func.php | Func.randomChar | public static function randomChar( $char )
{
if ( strlen( $char ) == 0 )
return '';
$char = ord( $char );
if ( $char > 64 && $char < 91 ) // Uppercase
return static::randomCharRange( 65, 90 );
if ( $char > 96 && $char < 123 ) // Lowercase
return static::randomCharRange( 97, 122 );
if ( $char > 47 && $char < 58 ) // Numeric
return static::randomCharRange( 48, 57 );
return static::$randomCharMap[random_int( 0, count( static::$randomCharMap ) )];
} | php | public static function randomChar( $char )
{
if ( strlen( $char ) == 0 )
return '';
$char = ord( $char );
if ( $char > 64 && $char < 91 ) // Uppercase
return static::randomCharRange( 65, 90 );
if ( $char > 96 && $char < 123 ) // Lowercase
return static::randomCharRange( 97, 122 );
if ( $char > 47 && $char < 58 ) // Numeric
return static::randomCharRange( 48, 57 );
return static::$randomCharMap[random_int( 0, count( static::$randomCharMap ) )];
} | [
"public",
"static",
"function",
"randomChar",
"(",
"$",
"char",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"char",
")",
"==",
"0",
")",
"return",
"''",
";",
"$",
"char",
"=",
"ord",
"(",
"$",
"char",
")",
";",
"if",
"(",
"$",
"char",
">",
"64",
"&&",
"$",
"char",
"<",
"91",
")",
"// Uppercase",
"return",
"static",
"::",
"randomCharRange",
"(",
"65",
",",
"90",
")",
";",
"if",
"(",
"$",
"char",
">",
"96",
"&&",
"$",
"char",
"<",
"123",
")",
"// Lowercase",
"return",
"static",
"::",
"randomCharRange",
"(",
"97",
",",
"122",
")",
";",
"if",
"(",
"$",
"char",
">",
"47",
"&&",
"$",
"char",
"<",
"58",
")",
"// Numeric",
"return",
"static",
"::",
"randomCharRange",
"(",
"48",
",",
"57",
")",
";",
"return",
"static",
"::",
"$",
"randomCharMap",
"[",
"random_int",
"(",
"0",
",",
"count",
"(",
"static",
"::",
"$",
"randomCharMap",
")",
")",
"]",
";",
"}"
] | Randomizes the first character of string, preserves uppercase, lowercase, and numeric.
@param string $char
@return string | [
"Randomizes",
"the",
"first",
"character",
"of",
"string",
"preserves",
"uppercase",
"lowercase",
"and",
"numeric",
"."
] | 8afd7156610a70371aa5b1df50b8a212bf7b142c | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Helpers/Func.php#L143-L160 | train |
PenoaksDev/Milky-Framework | src/Milky/Helpers/Func.php | Func.randomCharRange | public static function randomCharRange( $start, $end )
{
if ( count( static::$randomCharMap ) == 0 )
static::populate();
return chr( random_int( $start, $end ) );
} | php | public static function randomCharRange( $start, $end )
{
if ( count( static::$randomCharMap ) == 0 )
static::populate();
return chr( random_int( $start, $end ) );
} | [
"public",
"static",
"function",
"randomCharRange",
"(",
"$",
"start",
",",
"$",
"end",
")",
"{",
"if",
"(",
"count",
"(",
"static",
"::",
"$",
"randomCharMap",
")",
"==",
"0",
")",
"static",
"::",
"populate",
"(",
")",
";",
"return",
"chr",
"(",
"random_int",
"(",
"$",
"start",
",",
"$",
"end",
")",
")",
";",
"}"
] | Returns a random character within the specified range
@param int $start
@param int $end
@return string | [
"Returns",
"a",
"random",
"character",
"within",
"the",
"specified",
"range"
] | 8afd7156610a70371aa5b1df50b8a212bf7b142c | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Helpers/Func.php#L169-L175 | train |
PenoaksDev/Milky-Framework | src/Milky/Helpers/Func.php | Func.stacktrace | public static function stacktrace( $stack = null, $withPre = false )
{
if ( is_null( $stack ) )
$stack = debug_backtrace();
$output = $withPre ? '<pre>' : '';
$stackLen = count( $stack );
for ( $i = 1; $i < $stackLen; $i++ )
{
$entry = $stack[$i];
$func = $entry['function'] . '(';
$argsLen = count( $entry['args'] );
for ( $j = 0; $j < $argsLen; $j++ )
{
$my_entry = $entry['args'][$j];
if ( is_string( $my_entry ) )
$func .= $my_entry;
if ( $j < $argsLen - 1 )
$func .= ', ';
}
$func .= ')';
$entry_file = 'NO_FILE';
if ( array_key_exists( 'file', $entry ) )
$entry_file = $entry['file'];
$entry_line = 'NO_LINE';
if ( array_key_exists( 'line', $entry ) )
$entry_line = $entry['line'];
$output .= $entry_file . ':' . $entry_line . ' - ' . $func . PHP_EOL;
}
if ( $withPre )
$output .= $output . '</pre>';
return $output;
} | php | public static function stacktrace( $stack = null, $withPre = false )
{
if ( is_null( $stack ) )
$stack = debug_backtrace();
$output = $withPre ? '<pre>' : '';
$stackLen = count( $stack );
for ( $i = 1; $i < $stackLen; $i++ )
{
$entry = $stack[$i];
$func = $entry['function'] . '(';
$argsLen = count( $entry['args'] );
for ( $j = 0; $j < $argsLen; $j++ )
{
$my_entry = $entry['args'][$j];
if ( is_string( $my_entry ) )
$func .= $my_entry;
if ( $j < $argsLen - 1 )
$func .= ', ';
}
$func .= ')';
$entry_file = 'NO_FILE';
if ( array_key_exists( 'file', $entry ) )
$entry_file = $entry['file'];
$entry_line = 'NO_LINE';
if ( array_key_exists( 'line', $entry ) )
$entry_line = $entry['line'];
$output .= $entry_file . ':' . $entry_line . ' - ' . $func . PHP_EOL;
}
if ( $withPre )
$output .= $output . '</pre>';
return $output;
} | [
"public",
"static",
"function",
"stacktrace",
"(",
"$",
"stack",
"=",
"null",
",",
"$",
"withPre",
"=",
"false",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"stack",
")",
")",
"$",
"stack",
"=",
"debug_backtrace",
"(",
")",
";",
"$",
"output",
"=",
"$",
"withPre",
"?",
"'<pre>'",
":",
"''",
";",
"$",
"stackLen",
"=",
"count",
"(",
"$",
"stack",
")",
";",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<",
"$",
"stackLen",
";",
"$",
"i",
"++",
")",
"{",
"$",
"entry",
"=",
"$",
"stack",
"[",
"$",
"i",
"]",
";",
"$",
"func",
"=",
"$",
"entry",
"[",
"'function'",
"]",
".",
"'('",
";",
"$",
"argsLen",
"=",
"count",
"(",
"$",
"entry",
"[",
"'args'",
"]",
")",
";",
"for",
"(",
"$",
"j",
"=",
"0",
";",
"$",
"j",
"<",
"$",
"argsLen",
";",
"$",
"j",
"++",
")",
"{",
"$",
"my_entry",
"=",
"$",
"entry",
"[",
"'args'",
"]",
"[",
"$",
"j",
"]",
";",
"if",
"(",
"is_string",
"(",
"$",
"my_entry",
")",
")",
"$",
"func",
".=",
"$",
"my_entry",
";",
"if",
"(",
"$",
"j",
"<",
"$",
"argsLen",
"-",
"1",
")",
"$",
"func",
".=",
"', '",
";",
"}",
"$",
"func",
".=",
"')'",
";",
"$",
"entry_file",
"=",
"'NO_FILE'",
";",
"if",
"(",
"array_key_exists",
"(",
"'file'",
",",
"$",
"entry",
")",
")",
"$",
"entry_file",
"=",
"$",
"entry",
"[",
"'file'",
"]",
";",
"$",
"entry_line",
"=",
"'NO_LINE'",
";",
"if",
"(",
"array_key_exists",
"(",
"'line'",
",",
"$",
"entry",
")",
")",
"$",
"entry_line",
"=",
"$",
"entry",
"[",
"'line'",
"]",
";",
"$",
"output",
".=",
"$",
"entry_file",
".",
"':'",
".",
"$",
"entry_line",
".",
"' - '",
".",
"$",
"func",
".",
"PHP_EOL",
";",
"}",
"if",
"(",
"$",
"withPre",
")",
"$",
"output",
".=",
"$",
"output",
".",
"'</pre>'",
";",
"return",
"$",
"output",
";",
"}"
] | Creates a human readable stack trace
@param null $stack
@return string | [
"Creates",
"a",
"human",
"readable",
"stack",
"trace"
] | 8afd7156610a70371aa5b1df50b8a212bf7b142c | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Helpers/Func.php#L183-L226 | train |
kambalabs/KmbPuppetDb | src/KmbPuppetDb/Service/NodeStatistics.php | NodeStatistics.processStatistics | protected function processStatistics($query = null)
{
$this->unchangedCount = 0;
$this->changedCount = 0;
$this->failedCount = 0;
$this->nodesCountByOS = [];
$this->nodesPercentageByOS = [];
$this->recentlyRebootedNodes = [];
$nodes = $this->getNodeService()->getAll($query);
$this->nodesCount = count($nodes);
foreach ($nodes as $node) {
/** @var Model\Node $node */
if ($node->getStatus() == Model\NodeInterface::UNCHANGED) {
$this->unchangedCount++;
} elseif ($node->getStatus() == Model\NodeInterface::CHANGED) {
$this->changedCount++;
} elseif ($node->getStatus() == Model\NodeInterface::FAILED) {
$this->failedCount++;
}
if ($node->getFact('uptime_days') < 1) {
$this->recentlyRebootedNodes[$node->getName()] = $node->getFact('uptime');
}
$osName = $node->hasFact('lsbdistdescription') ? $node->getFact('lsbdistdescription') : $node->getFact('operatingsystem');
if (!array_key_exists($osName, $this->nodesCountByOS)) {
$this->nodesCountByOS[$osName] = 0;
}
$this->nodesCountByOS[$osName]++;
$this->nodesPercentageByOS[$osName] = round($this->nodesCountByOS[$osName] / $this->nodesCount, 2);
}
arsort($this->nodesCountByOS);
arsort($this->nodesPercentageByOS);
$this->osCount = count($this->nodesCountByOS);
} | php | protected function processStatistics($query = null)
{
$this->unchangedCount = 0;
$this->changedCount = 0;
$this->failedCount = 0;
$this->nodesCountByOS = [];
$this->nodesPercentageByOS = [];
$this->recentlyRebootedNodes = [];
$nodes = $this->getNodeService()->getAll($query);
$this->nodesCount = count($nodes);
foreach ($nodes as $node) {
/** @var Model\Node $node */
if ($node->getStatus() == Model\NodeInterface::UNCHANGED) {
$this->unchangedCount++;
} elseif ($node->getStatus() == Model\NodeInterface::CHANGED) {
$this->changedCount++;
} elseif ($node->getStatus() == Model\NodeInterface::FAILED) {
$this->failedCount++;
}
if ($node->getFact('uptime_days') < 1) {
$this->recentlyRebootedNodes[$node->getName()] = $node->getFact('uptime');
}
$osName = $node->hasFact('lsbdistdescription') ? $node->getFact('lsbdistdescription') : $node->getFact('operatingsystem');
if (!array_key_exists($osName, $this->nodesCountByOS)) {
$this->nodesCountByOS[$osName] = 0;
}
$this->nodesCountByOS[$osName]++;
$this->nodesPercentageByOS[$osName] = round($this->nodesCountByOS[$osName] / $this->nodesCount, 2);
}
arsort($this->nodesCountByOS);
arsort($this->nodesPercentageByOS);
$this->osCount = count($this->nodesCountByOS);
} | [
"protected",
"function",
"processStatistics",
"(",
"$",
"query",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"unchangedCount",
"=",
"0",
";",
"$",
"this",
"->",
"changedCount",
"=",
"0",
";",
"$",
"this",
"->",
"failedCount",
"=",
"0",
";",
"$",
"this",
"->",
"nodesCountByOS",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"nodesPercentageByOS",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"recentlyRebootedNodes",
"=",
"[",
"]",
";",
"$",
"nodes",
"=",
"$",
"this",
"->",
"getNodeService",
"(",
")",
"->",
"getAll",
"(",
"$",
"query",
")",
";",
"$",
"this",
"->",
"nodesCount",
"=",
"count",
"(",
"$",
"nodes",
")",
";",
"foreach",
"(",
"$",
"nodes",
"as",
"$",
"node",
")",
"{",
"/** @var Model\\Node $node */",
"if",
"(",
"$",
"node",
"->",
"getStatus",
"(",
")",
"==",
"Model",
"\\",
"NodeInterface",
"::",
"UNCHANGED",
")",
"{",
"$",
"this",
"->",
"unchangedCount",
"++",
";",
"}",
"elseif",
"(",
"$",
"node",
"->",
"getStatus",
"(",
")",
"==",
"Model",
"\\",
"NodeInterface",
"::",
"CHANGED",
")",
"{",
"$",
"this",
"->",
"changedCount",
"++",
";",
"}",
"elseif",
"(",
"$",
"node",
"->",
"getStatus",
"(",
")",
"==",
"Model",
"\\",
"NodeInterface",
"::",
"FAILED",
")",
"{",
"$",
"this",
"->",
"failedCount",
"++",
";",
"}",
"if",
"(",
"$",
"node",
"->",
"getFact",
"(",
"'uptime_days'",
")",
"<",
"1",
")",
"{",
"$",
"this",
"->",
"recentlyRebootedNodes",
"[",
"$",
"node",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"node",
"->",
"getFact",
"(",
"'uptime'",
")",
";",
"}",
"$",
"osName",
"=",
"$",
"node",
"->",
"hasFact",
"(",
"'lsbdistdescription'",
")",
"?",
"$",
"node",
"->",
"getFact",
"(",
"'lsbdistdescription'",
")",
":",
"$",
"node",
"->",
"getFact",
"(",
"'operatingsystem'",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"osName",
",",
"$",
"this",
"->",
"nodesCountByOS",
")",
")",
"{",
"$",
"this",
"->",
"nodesCountByOS",
"[",
"$",
"osName",
"]",
"=",
"0",
";",
"}",
"$",
"this",
"->",
"nodesCountByOS",
"[",
"$",
"osName",
"]",
"++",
";",
"$",
"this",
"->",
"nodesPercentageByOS",
"[",
"$",
"osName",
"]",
"=",
"round",
"(",
"$",
"this",
"->",
"nodesCountByOS",
"[",
"$",
"osName",
"]",
"/",
"$",
"this",
"->",
"nodesCount",
",",
"2",
")",
";",
"}",
"arsort",
"(",
"$",
"this",
"->",
"nodesCountByOS",
")",
";",
"arsort",
"(",
"$",
"this",
"->",
"nodesPercentageByOS",
")",
";",
"$",
"this",
"->",
"osCount",
"=",
"count",
"(",
"$",
"this",
"->",
"nodesCountByOS",
")",
";",
"}"
] | Browse all nodes and process all the statistics
@param \KmbPuppetDb\Query\Query|array $query | [
"Browse",
"all",
"nodes",
"and",
"process",
"all",
"the",
"statistics"
] | df56a275cf00f4402cf121a2e99149168f1f8b2d | https://github.com/kambalabs/KmbPuppetDb/blob/df56a275cf00f4402cf121a2e99149168f1f8b2d/src/KmbPuppetDb/Service/NodeStatistics.php#L221-L253 | train |
AlexanderPoellmann/Laravel-Settings | src/Driver/FileDriver.php | FileDriver.setPath | public function setPath($path)
{
if ( ! $this->files->exists($path) ) {
$result = $this->files->put($path, '{}');
if ( $result === false ) {
throw new NotWritableException("Could not write to $path.");
}
}
if ( ! $this->files->isWritable($path) ) {
throw new NotWritableException("$path is not writable.");
}
$this->path = $path;
} | php | public function setPath($path)
{
if ( ! $this->files->exists($path) ) {
$result = $this->files->put($path, '{}');
if ( $result === false ) {
throw new NotWritableException("Could not write to $path.");
}
}
if ( ! $this->files->isWritable($path) ) {
throw new NotWritableException("$path is not writable.");
}
$this->path = $path;
} | [
"public",
"function",
"setPath",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"files",
"->",
"exists",
"(",
"$",
"path",
")",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"files",
"->",
"put",
"(",
"$",
"path",
",",
"'{}'",
")",
";",
"if",
"(",
"$",
"result",
"===",
"false",
")",
"{",
"throw",
"new",
"NotWritableException",
"(",
"\"Could not write to $path.\"",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"files",
"->",
"isWritable",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"NotWritableException",
"(",
"\"$path is not writable.\"",
")",
";",
"}",
"$",
"this",
"->",
"path",
"=",
"$",
"path",
";",
"}"
] | Set the path for the JSON file.
@param string $path
@throws NotWritableException | [
"Set",
"the",
"path",
"for",
"the",
"JSON",
"file",
"."
] | bf06f78cbbf86adb8576a29caae496d1e03b32ab | https://github.com/AlexanderPoellmann/Laravel-Settings/blob/bf06f78cbbf86adb8576a29caae496d1e03b32ab/src/Driver/FileDriver.php#L38-L52 | train |
Torann/skosh-generator | src/Twig/AbstractExtension.php | AbstractExtension.isCurrent | public function isCurrent($page, $pattern)
{
// Remove site URL from string
$page = str_replace($this->getBuilder()->app->getSetting('url'), '', $page);
return str_is($pattern, $page);
} | php | public function isCurrent($page, $pattern)
{
// Remove site URL from string
$page = str_replace($this->getBuilder()->app->getSetting('url'), '', $page);
return str_is($pattern, $page);
} | [
"public",
"function",
"isCurrent",
"(",
"$",
"page",
",",
"$",
"pattern",
")",
"{",
"// Remove site URL from string",
"$",
"page",
"=",
"str_replace",
"(",
"$",
"this",
"->",
"getBuilder",
"(",
")",
"->",
"app",
"->",
"getSetting",
"(",
"'url'",
")",
",",
"''",
",",
"$",
"page",
")",
";",
"return",
"str_is",
"(",
"$",
"pattern",
",",
"$",
"page",
")",
";",
"}"
] | Is given URL the current page?
@param $page
@param $pattern
@return bool | [
"Is",
"given",
"URL",
"the",
"current",
"page?"
] | ea60e037d92398d7c146eb2349735d5692e3c48c | https://github.com/Torann/skosh-generator/blob/ea60e037d92398d7c146eb2349735d5692e3c48c/src/Twig/AbstractExtension.php#L43-L49 | train |
mmethner/engine | src/Core/Exception.php | Exception.collect | private static function collect()
{
$message = '';
$message .= sprintf("\r\nURL: %s\r\n", $_SERVER['REQUEST_URI']);
if (!empty($_POST)) {
$message .= "\r\n";
foreach ($_POST as $key => $value) {
if (in_array($key, [
'password',
'password2'
])) {
continue;
}
$message .= 'post #' . $key . ': ' . (is_array($value) ? serialize($value) : $value) . "\r\n";
}
}
if (!empty($_GET)) {
$message .= "\r\n";
foreach ($_GET as $key => $value) {
if (in_array($key, [
'password',
'password2'
])) {
continue;
}
$message .= 'get #' . $key . ': ' . $value . "\r\n";
}
}
if (!empty($_COOKIE)) {
$message .= "\r\n";
foreach ($_COOKIE as $key => $value) {
$message .= 'cookie #' . $key . ': ' . $value . "\r\n";
}
}
if (!empty($_SERVER)) {
$message .= "\r\n";
foreach ($_SERVER as $key => $value) {
if (is_array($value)) {
continue;
}
$message .= 'server #' . $key . ': ' . $value . "\r\n";
}
}
if (!empty($_SESSION)) {
$message .= "\r\n";
foreach ($_SESSION as $key => $value) {
$message .= 'session #' . $key . ': ' . (is_array($value) ?
serialize($value) : print_r($value,1)) . "\r\n";
}
}
return $message;
} | php | private static function collect()
{
$message = '';
$message .= sprintf("\r\nURL: %s\r\n", $_SERVER['REQUEST_URI']);
if (!empty($_POST)) {
$message .= "\r\n";
foreach ($_POST as $key => $value) {
if (in_array($key, [
'password',
'password2'
])) {
continue;
}
$message .= 'post #' . $key . ': ' . (is_array($value) ? serialize($value) : $value) . "\r\n";
}
}
if (!empty($_GET)) {
$message .= "\r\n";
foreach ($_GET as $key => $value) {
if (in_array($key, [
'password',
'password2'
])) {
continue;
}
$message .= 'get #' . $key . ': ' . $value . "\r\n";
}
}
if (!empty($_COOKIE)) {
$message .= "\r\n";
foreach ($_COOKIE as $key => $value) {
$message .= 'cookie #' . $key . ': ' . $value . "\r\n";
}
}
if (!empty($_SERVER)) {
$message .= "\r\n";
foreach ($_SERVER as $key => $value) {
if (is_array($value)) {
continue;
}
$message .= 'server #' . $key . ': ' . $value . "\r\n";
}
}
if (!empty($_SESSION)) {
$message .= "\r\n";
foreach ($_SESSION as $key => $value) {
$message .= 'session #' . $key . ': ' . (is_array($value) ?
serialize($value) : print_r($value,1)) . "\r\n";
}
}
return $message;
} | [
"private",
"static",
"function",
"collect",
"(",
")",
"{",
"$",
"message",
"=",
"''",
";",
"$",
"message",
".=",
"sprintf",
"(",
"\"\\r\\nURL: %s\\r\\n\"",
",",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"_POST",
")",
")",
"{",
"$",
"message",
".=",
"\"\\r\\n\"",
";",
"foreach",
"(",
"$",
"_POST",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"key",
",",
"[",
"'password'",
",",
"'password2'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"message",
".=",
"'post #'",
".",
"$",
"key",
".",
"': '",
".",
"(",
"is_array",
"(",
"$",
"value",
")",
"?",
"serialize",
"(",
"$",
"value",
")",
":",
"$",
"value",
")",
".",
"\"\\r\\n\"",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"_GET",
")",
")",
"{",
"$",
"message",
".=",
"\"\\r\\n\"",
";",
"foreach",
"(",
"$",
"_GET",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"key",
",",
"[",
"'password'",
",",
"'password2'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"message",
".=",
"'get #'",
".",
"$",
"key",
".",
"': '",
".",
"$",
"value",
".",
"\"\\r\\n\"",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"_COOKIE",
")",
")",
"{",
"$",
"message",
".=",
"\"\\r\\n\"",
";",
"foreach",
"(",
"$",
"_COOKIE",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"message",
".=",
"'cookie #'",
".",
"$",
"key",
".",
"': '",
".",
"$",
"value",
".",
"\"\\r\\n\"",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"_SERVER",
")",
")",
"{",
"$",
"message",
".=",
"\"\\r\\n\"",
";",
"foreach",
"(",
"$",
"_SERVER",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"continue",
";",
"}",
"$",
"message",
".=",
"'server #'",
".",
"$",
"key",
".",
"': '",
".",
"$",
"value",
".",
"\"\\r\\n\"",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"_SESSION",
")",
")",
"{",
"$",
"message",
".=",
"\"\\r\\n\"",
";",
"foreach",
"(",
"$",
"_SESSION",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"message",
".=",
"'session #'",
".",
"$",
"key",
".",
"': '",
".",
"(",
"is_array",
"(",
"$",
"value",
")",
"?",
"serialize",
"(",
"$",
"value",
")",
":",
"print_r",
"(",
"$",
"value",
",",
"1",
")",
")",
".",
"\"\\r\\n\"",
";",
"}",
"}",
"return",
"$",
"message",
";",
"}"
] | collects data for current request
@return string | [
"collects",
"data",
"for",
"current",
"request"
] | 89e1bcc644cf8cc3712a67ef1697da2ca4008f74 | https://github.com/mmethner/engine/blob/89e1bcc644cf8cc3712a67ef1697da2ca4008f74/src/Core/Exception.php#L53-L111 | train |
Stinger-Soft/TwigExtensions | src/StingerSoft/TwigExtensions/DoctrineExtensions.php | DoctrineExtensions.setDoctrineFunctions | public function setDoctrineFunctions(\StingerSoft\DoctrineCommons\Utils\DoctrineFunctionsInterface $doctrineFunctions = null) {
$this->doctrineFunctions = $doctrineFunctions;
} | php | public function setDoctrineFunctions(\StingerSoft\DoctrineCommons\Utils\DoctrineFunctionsInterface $doctrineFunctions = null) {
$this->doctrineFunctions = $doctrineFunctions;
} | [
"public",
"function",
"setDoctrineFunctions",
"(",
"\\",
"StingerSoft",
"\\",
"DoctrineCommons",
"\\",
"Utils",
"\\",
"DoctrineFunctionsInterface",
"$",
"doctrineFunctions",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"doctrineFunctions",
"=",
"$",
"doctrineFunctions",
";",
"}"
] | Set the doctrine commons functions to be used by the twig extension.
@param \StingerSoft\DoctrineCommons\Utils\DoctrineFunctionsInterface $doctrineFunctions | [
"Set",
"the",
"doctrine",
"commons",
"functions",
"to",
"be",
"used",
"by",
"the",
"twig",
"extension",
"."
] | 7bfce337b0dd33106e22f80b221338451a02d7c5 | https://github.com/Stinger-Soft/TwigExtensions/blob/7bfce337b0dd33106e22f80b221338451a02d7c5/src/StingerSoft/TwigExtensions/DoctrineExtensions.php#L23-L25 | train |
Stinger-Soft/TwigExtensions | src/StingerSoft/TwigExtensions/DoctrineExtensions.php | DoctrineExtensions.unproxifyFilter | public function unproxifyFilter($object) {
if($this->hasDoctrineFunctions() && method_exists($this->doctrineFunctions, 'unproxifyFilter')) {
return $this->doctrineFunctions->unproxifyFilter($object);
}
return $object;
} | php | public function unproxifyFilter($object) {
if($this->hasDoctrineFunctions() && method_exists($this->doctrineFunctions, 'unproxifyFilter')) {
return $this->doctrineFunctions->unproxifyFilter($object);
}
return $object;
} | [
"public",
"function",
"unproxifyFilter",
"(",
"$",
"object",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasDoctrineFunctions",
"(",
")",
"&&",
"method_exists",
"(",
"$",
"this",
"->",
"doctrineFunctions",
",",
"'unproxifyFilter'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"doctrineFunctions",
"->",
"unproxifyFilter",
"(",
"$",
"object",
")",
";",
"}",
"return",
"$",
"object",
";",
"}"
] | Transforms the given doctrine proxy object into a 'real' entity
@param object $object
@return object|NULL | [
"Transforms",
"the",
"given",
"doctrine",
"proxy",
"object",
"into",
"a",
"real",
"entity"
] | 7bfce337b0dd33106e22f80b221338451a02d7c5 | https://github.com/Stinger-Soft/TwigExtensions/blob/7bfce337b0dd33106e22f80b221338451a02d7c5/src/StingerSoft/TwigExtensions/DoctrineExtensions.php#L70-L75 | train |
Soneritics/Database | Soneritics/Database/DatabaseConnectionFactory.php | DatabaseConnectionFactory.create | public static function create($id, array $config)
{
static::$databaseConnections[$id] = static::createDatabaseConnection($config);
if (static::$activeDatabaseConnection === null) {
static::select($id);
}
} | php | public static function create($id, array $config)
{
static::$databaseConnections[$id] = static::createDatabaseConnection($config);
if (static::$activeDatabaseConnection === null) {
static::select($id);
}
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"id",
",",
"array",
"$",
"config",
")",
"{",
"static",
"::",
"$",
"databaseConnections",
"[",
"$",
"id",
"]",
"=",
"static",
"::",
"createDatabaseConnection",
"(",
"$",
"config",
")",
";",
"if",
"(",
"static",
"::",
"$",
"activeDatabaseConnection",
"===",
"null",
")",
"{",
"static",
"::",
"select",
"(",
"$",
"id",
")",
";",
"}",
"}"
] | Set a database connection.
@param string $id
@param array $config | [
"Set",
"a",
"database",
"connection",
"."
] | 20cb74f2a2ee8d9161d3144b5c061a6da11cd066 | https://github.com/Soneritics/Database/blob/20cb74f2a2ee8d9161d3144b5c061a6da11cd066/Soneritics/Database/DatabaseConnectionFactory.php#L53-L60 | train |
Soneritics/Database | Soneritics/Database/DatabaseConnectionFactory.php | DatabaseConnectionFactory.get | public static function get($id = null)
{
if ($id === null && static::$activeDatabaseConnection === null) {
throw new MissingDatabaseConnectionException('No databases defined.');
}
if ($id === null) {
return static::$databaseConnections[static::$activeDatabaseConnection];
} else {
return static::$databaseConnections[$id];
}
} | php | public static function get($id = null)
{
if ($id === null && static::$activeDatabaseConnection === null) {
throw new MissingDatabaseConnectionException('No databases defined.');
}
if ($id === null) {
return static::$databaseConnections[static::$activeDatabaseConnection];
} else {
return static::$databaseConnections[$id];
}
} | [
"public",
"static",
"function",
"get",
"(",
"$",
"id",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"id",
"===",
"null",
"&&",
"static",
"::",
"$",
"activeDatabaseConnection",
"===",
"null",
")",
"{",
"throw",
"new",
"MissingDatabaseConnectionException",
"(",
"'No databases defined.'",
")",
";",
"}",
"if",
"(",
"$",
"id",
"===",
"null",
")",
"{",
"return",
"static",
"::",
"$",
"databaseConnections",
"[",
"static",
"::",
"$",
"activeDatabaseConnection",
"]",
";",
"}",
"else",
"{",
"return",
"static",
"::",
"$",
"databaseConnections",
"[",
"$",
"id",
"]",
";",
"}",
"}"
] | Get a database connection.
@param null $id
@return IDatabaseConnection
@throws MissingDatabaseConnectionException | [
"Get",
"a",
"database",
"connection",
"."
] | 20cb74f2a2ee8d9161d3144b5c061a6da11cd066 | https://github.com/Soneritics/Database/blob/20cb74f2a2ee8d9161d3144b5c061a6da11cd066/Soneritics/Database/DatabaseConnectionFactory.php#L68-L79 | train |
jenskooij/cloudcontrol | src/components/MultiComponent.php | MultiComponent.run | public function run(Storage $storage)
{
parent::run($storage);
$components = $this->getParametersWithoutNamespace();
foreach ($components as $namespace => $component) {
$this->loadComponent($namespace, $component);
}
} | php | public function run(Storage $storage)
{
parent::run($storage);
$components = $this->getParametersWithoutNamespace();
foreach ($components as $namespace => $component) {
$this->loadComponent($namespace, $component);
}
} | [
"public",
"function",
"run",
"(",
"Storage",
"$",
"storage",
")",
"{",
"parent",
"::",
"run",
"(",
"$",
"storage",
")",
";",
"$",
"components",
"=",
"$",
"this",
"->",
"getParametersWithoutNamespace",
"(",
")",
";",
"foreach",
"(",
"$",
"components",
"as",
"$",
"namespace",
"=>",
"$",
"component",
")",
"{",
"$",
"this",
"->",
"loadComponent",
"(",
"$",
"namespace",
",",
"$",
"component",
")",
";",
"}",
"}"
] | Runs all components that are set
@param Storage $storage | [
"Runs",
"all",
"components",
"that",
"are",
"set"
] | 76e5d9ac8f9c50d06d39a995d13cc03742536548 | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/components/MultiComponent.php#L40-L49 | train |
jenskooij/cloudcontrol | src/components/MultiComponent.php | MultiComponent.loadComponent | private function loadComponent($namespace, $component)
{
$fullyQualifiedCloudControlComponent = '\\CloudControl\\Cms\\components\\' . $component;
$fullyQualifiedComponent = '\\components\\' . $component;
if (class_exists($fullyQualifiedCloudControlComponent, true)) {
$this->runComponent($namespace, $fullyQualifiedCloudControlComponent);
} elseif (class_exists($fullyQualifiedComponent, true)) {
$this->runComponent($namespace, $fullyQualifiedComponent);
}
} | php | private function loadComponent($namespace, $component)
{
$fullyQualifiedCloudControlComponent = '\\CloudControl\\Cms\\components\\' . $component;
$fullyQualifiedComponent = '\\components\\' . $component;
if (class_exists($fullyQualifiedCloudControlComponent, true)) {
$this->runComponent($namespace, $fullyQualifiedCloudControlComponent);
} elseif (class_exists($fullyQualifiedComponent, true)) {
$this->runComponent($namespace, $fullyQualifiedComponent);
}
} | [
"private",
"function",
"loadComponent",
"(",
"$",
"namespace",
",",
"$",
"component",
")",
"{",
"$",
"fullyQualifiedCloudControlComponent",
"=",
"'\\\\CloudControl\\\\Cms\\\\components\\\\'",
".",
"$",
"component",
";",
"$",
"fullyQualifiedComponent",
"=",
"'\\\\components\\\\'",
".",
"$",
"component",
";",
"if",
"(",
"class_exists",
"(",
"$",
"fullyQualifiedCloudControlComponent",
",",
"true",
")",
")",
"{",
"$",
"this",
"->",
"runComponent",
"(",
"$",
"namespace",
",",
"$",
"fullyQualifiedCloudControlComponent",
")",
";",
"}",
"elseif",
"(",
"class_exists",
"(",
"$",
"fullyQualifiedComponent",
",",
"true",
")",
")",
"{",
"$",
"this",
"->",
"runComponent",
"(",
"$",
"namespace",
",",
"$",
"fullyQualifiedComponent",
")",
";",
"}",
"}"
] | Tries to determine component class name and wheter it exists
@param $namespace String
@param $component String | [
"Tries",
"to",
"determine",
"component",
"class",
"name",
"and",
"wheter",
"it",
"exists"
] | 76e5d9ac8f9c50d06d39a995d13cc03742536548 | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/components/MultiComponent.php#L57-L66 | train |
jenskooij/cloudcontrol | src/components/MultiComponent.php | MultiComponent.runComponent | private function runComponent($namespace, $fullyQualifiedComponent)
{
$parameters = $this->getParametersForNameSpace($namespace);
$parameters[self::PARAMETER_MULTI_COMPONENT] = $this;
$component = new $fullyQualifiedComponent('', $this->request, $parameters, $this->matchedSitemapItem);
if ($component instanceof components\Component) {
$component->run($this->storage);
$parameters = $component->getParameters();
foreach ($parameters as $name => $value) {
$this->parameters[$namespace . '_' . $name] = $value;
}
}
} | php | private function runComponent($namespace, $fullyQualifiedComponent)
{
$parameters = $this->getParametersForNameSpace($namespace);
$parameters[self::PARAMETER_MULTI_COMPONENT] = $this;
$component = new $fullyQualifiedComponent('', $this->request, $parameters, $this->matchedSitemapItem);
if ($component instanceof components\Component) {
$component->run($this->storage);
$parameters = $component->getParameters();
foreach ($parameters as $name => $value) {
$this->parameters[$namespace . '_' . $name] = $value;
}
}
} | [
"private",
"function",
"runComponent",
"(",
"$",
"namespace",
",",
"$",
"fullyQualifiedComponent",
")",
"{",
"$",
"parameters",
"=",
"$",
"this",
"->",
"getParametersForNameSpace",
"(",
"$",
"namespace",
")",
";",
"$",
"parameters",
"[",
"self",
"::",
"PARAMETER_MULTI_COMPONENT",
"]",
"=",
"$",
"this",
";",
"$",
"component",
"=",
"new",
"$",
"fullyQualifiedComponent",
"(",
"''",
",",
"$",
"this",
"->",
"request",
",",
"$",
"parameters",
",",
"$",
"this",
"->",
"matchedSitemapItem",
")",
";",
"if",
"(",
"$",
"component",
"instanceof",
"components",
"\\",
"Component",
")",
"{",
"$",
"component",
"->",
"run",
"(",
"$",
"this",
"->",
"storage",
")",
";",
"$",
"parameters",
"=",
"$",
"component",
"->",
"getParameters",
"(",
")",
";",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"parameters",
"[",
"$",
"namespace",
".",
"'_'",
".",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}"
] | Instantiates the component and runs it
@param $namespace String
@param $fullyQualifiedComponent String | [
"Instantiates",
"the",
"component",
"and",
"runs",
"it"
] | 76e5d9ac8f9c50d06d39a995d13cc03742536548 | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/components/MultiComponent.php#L74-L86 | train |
jenskooij/cloudcontrol | src/components/MultiComponent.php | MultiComponent.getParametersForNameSpace | private function getParametersForNameSpace($namespace)
{
$parameters = array();
foreach ($this->parameters as $key => $value) {
if (0 === strpos($key, $namespace . ':')) {
$parameters[substr($key, strlen($namespace) + 1)] = $value;
}
}
return $parameters;
} | php | private function getParametersForNameSpace($namespace)
{
$parameters = array();
foreach ($this->parameters as $key => $value) {
if (0 === strpos($key, $namespace . ':')) {
$parameters[substr($key, strlen($namespace) + 1)] = $value;
}
}
return $parameters;
} | [
"private",
"function",
"getParametersForNameSpace",
"(",
"$",
"namespace",
")",
"{",
"$",
"parameters",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"parameters",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"0",
"===",
"strpos",
"(",
"$",
"key",
",",
"$",
"namespace",
".",
"':'",
")",
")",
"{",
"$",
"parameters",
"[",
"substr",
"(",
"$",
"key",
",",
"strlen",
"(",
"$",
"namespace",
")",
"+",
"1",
")",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"parameters",
";",
"}"
] | Retrieves all parameters for the given namespace
@param $namespace
@return array | [
"Retrieves",
"all",
"parameters",
"for",
"the",
"given",
"namespace"
] | 76e5d9ac8f9c50d06d39a995d13cc03742536548 | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/components/MultiComponent.php#L94-L103 | train |
jenskooij/cloudcontrol | src/components/MultiComponent.php | MultiComponent.getParametersWithoutNamespace | private function getParametersWithoutNamespace()
{
$parameters = array();
foreach ($this->parameters as $key => $value) {
if (strpos($key, ':') === false) {
$parameters[$key] = $value;
}
}
return $parameters;
} | php | private function getParametersWithoutNamespace()
{
$parameters = array();
foreach ($this->parameters as $key => $value) {
if (strpos($key, ':') === false) {
$parameters[$key] = $value;
}
}
return $parameters;
} | [
"private",
"function",
"getParametersWithoutNamespace",
"(",
")",
"{",
"$",
"parameters",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"parameters",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"key",
",",
"':'",
")",
"===",
"false",
")",
"{",
"$",
"parameters",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"parameters",
";",
"}"
] | Retrieves all parameters that have no namespace
@return array | [
"Retrieves",
"all",
"parameters",
"that",
"have",
"no",
"namespace"
] | 76e5d9ac8f9c50d06d39a995d13cc03742536548 | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/components/MultiComponent.php#L110-L119 | train |
Mandarin-Medien/MMCmfRoutingBundle | Resolver/NodeResolver.php | NodeResolver.resolve | public function resolve(NodeRouteInterface $route)
{
foreach($this->classes as $class) {
$qb = $this->manager->createQueryBuilder()
->select('n')
->from($class, 'n')
->join('n.routes', 'r')
->where('r.id = :route')
->setParameter('route', $route->getId());
$node = $qb->getQuery()->getResult();
if($node) return $node[0];
}
return null;
} | php | public function resolve(NodeRouteInterface $route)
{
foreach($this->classes as $class) {
$qb = $this->manager->createQueryBuilder()
->select('n')
->from($class, 'n')
->join('n.routes', 'r')
->where('r.id = :route')
->setParameter('route', $route->getId());
$node = $qb->getQuery()->getResult();
if($node) return $node[0];
}
return null;
} | [
"public",
"function",
"resolve",
"(",
"NodeRouteInterface",
"$",
"route",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"classes",
"as",
"$",
"class",
")",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"manager",
"->",
"createQueryBuilder",
"(",
")",
"->",
"select",
"(",
"'n'",
")",
"->",
"from",
"(",
"$",
"class",
",",
"'n'",
")",
"->",
"join",
"(",
"'n.routes'",
",",
"'r'",
")",
"->",
"where",
"(",
"'r.id = :route'",
")",
"->",
"setParameter",
"(",
"'route'",
",",
"$",
"route",
"->",
"getId",
"(",
")",
")",
";",
"$",
"node",
"=",
"$",
"qb",
"->",
"getQuery",
"(",
")",
"->",
"getResult",
"(",
")",
";",
"if",
"(",
"$",
"node",
")",
"return",
"$",
"node",
"[",
"0",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | loads the Node by the given NodeRouteInterface
@param NodeRouteInterface $route
@return mixed|null | [
"loads",
"the",
"Node",
"by",
"the",
"given",
"NodeRouteInterface"
] | 7db1b03f5e120bd473486c0be6ab76c6146cd2d0 | https://github.com/Mandarin-Medien/MMCmfRoutingBundle/blob/7db1b03f5e120bd473486c0be6ab76c6146cd2d0/Resolver/NodeResolver.php#L43-L60 | train |
Mandarin-Medien/MMCmfRoutingBundle | Resolver/NodeResolver.php | NodeResolver.getRoutableNodeClasses | protected function getRoutableNodeClasses()
{
$metadata = $this->manager->getClassMetadata(Node::class);
$routables = array_values(array_filter($metadata->subClasses, function($subNode) {
$reflection = new \ReflectionClass($subNode);
return $reflection->implementsInterface(RoutableNodeInterface::class);
}));
return $routables;
} | php | protected function getRoutableNodeClasses()
{
$metadata = $this->manager->getClassMetadata(Node::class);
$routables = array_values(array_filter($metadata->subClasses, function($subNode) {
$reflection = new \ReflectionClass($subNode);
return $reflection->implementsInterface(RoutableNodeInterface::class);
}));
return $routables;
} | [
"protected",
"function",
"getRoutableNodeClasses",
"(",
")",
"{",
"$",
"metadata",
"=",
"$",
"this",
"->",
"manager",
"->",
"getClassMetadata",
"(",
"Node",
"::",
"class",
")",
";",
"$",
"routables",
"=",
"array_values",
"(",
"array_filter",
"(",
"$",
"metadata",
"->",
"subClasses",
",",
"function",
"(",
"$",
"subNode",
")",
"{",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"subNode",
")",
";",
"return",
"$",
"reflection",
"->",
"implementsInterface",
"(",
"RoutableNodeInterface",
"::",
"class",
")",
";",
"}",
")",
")",
";",
"return",
"$",
"routables",
";",
"}"
] | builds a list of all classes implementing RoutableNodeInterface
@return array | [
"builds",
"a",
"list",
"of",
"all",
"classes",
"implementing",
"RoutableNodeInterface"
] | 7db1b03f5e120bd473486c0be6ab76c6146cd2d0 | https://github.com/Mandarin-Medien/MMCmfRoutingBundle/blob/7db1b03f5e120bd473486c0be6ab76c6146cd2d0/Resolver/NodeResolver.php#L67-L76 | train |
wb-crowdfusion/crowdfusion | system/core/classes/mvc/filters/DateFilterer.php | DateFilterer.format | protected function format()
{
if (($this->getParameter('value') == null || $this->getParameter('value') == "0"))
return '';
elseif (($this->getParameter('value') != null) && $this->getParameter('value') instanceof Meta) {
$dateTime = $this->getParameter('value');
$dateTime = $dateTime->MetaValue;
} elseif (($this->getParameter('value') != null) && $this->getParameter('value') instanceof Date)
$dateTime = $this->getParameter('value');
elseif (($this->getParameter('value') == null) || $this->getParameter('value') == 'now')
$dateTime = $this->DateFactory->newLocalDate('@'.time());
else {
try {
$dateTime = $this->DateFactory->newLocalDate($this->getParameter('value'));
}catch(DateException $e)
{
return '';
}
}
if($this->getParameter('storage'))
$datetime = $this->DateFactory->toStorageDate($dateTime);
else
$datetime = $this->DateFactory->toLocalDate($dateTime);
if ($this->getParameter('nonbreaking') == 'true')
return str_replace(' ', ' ', $dateTime->format($this->getParameter('format')));
return $dateTime->format($this->getParameter('format'));
} | php | protected function format()
{
if (($this->getParameter('value') == null || $this->getParameter('value') == "0"))
return '';
elseif (($this->getParameter('value') != null) && $this->getParameter('value') instanceof Meta) {
$dateTime = $this->getParameter('value');
$dateTime = $dateTime->MetaValue;
} elseif (($this->getParameter('value') != null) && $this->getParameter('value') instanceof Date)
$dateTime = $this->getParameter('value');
elseif (($this->getParameter('value') == null) || $this->getParameter('value') == 'now')
$dateTime = $this->DateFactory->newLocalDate('@'.time());
else {
try {
$dateTime = $this->DateFactory->newLocalDate($this->getParameter('value'));
}catch(DateException $e)
{
return '';
}
}
if($this->getParameter('storage'))
$datetime = $this->DateFactory->toStorageDate($dateTime);
else
$datetime = $this->DateFactory->toLocalDate($dateTime);
if ($this->getParameter('nonbreaking') == 'true')
return str_replace(' ', ' ', $dateTime->format($this->getParameter('format')));
return $dateTime->format($this->getParameter('format'));
} | [
"protected",
"function",
"format",
"(",
")",
"{",
"if",
"(",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'value'",
")",
"==",
"null",
"||",
"$",
"this",
"->",
"getParameter",
"(",
"'value'",
")",
"==",
"\"0\"",
")",
")",
"return",
"''",
";",
"elseif",
"(",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'value'",
")",
"!=",
"null",
")",
"&&",
"$",
"this",
"->",
"getParameter",
"(",
"'value'",
")",
"instanceof",
"Meta",
")",
"{",
"$",
"dateTime",
"=",
"$",
"this",
"->",
"getParameter",
"(",
"'value'",
")",
";",
"$",
"dateTime",
"=",
"$",
"dateTime",
"->",
"MetaValue",
";",
"}",
"elseif",
"(",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'value'",
")",
"!=",
"null",
")",
"&&",
"$",
"this",
"->",
"getParameter",
"(",
"'value'",
")",
"instanceof",
"Date",
")",
"$",
"dateTime",
"=",
"$",
"this",
"->",
"getParameter",
"(",
"'value'",
")",
";",
"elseif",
"(",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'value'",
")",
"==",
"null",
")",
"||",
"$",
"this",
"->",
"getParameter",
"(",
"'value'",
")",
"==",
"'now'",
")",
"$",
"dateTime",
"=",
"$",
"this",
"->",
"DateFactory",
"->",
"newLocalDate",
"(",
"'@'",
".",
"time",
"(",
")",
")",
";",
"else",
"{",
"try",
"{",
"$",
"dateTime",
"=",
"$",
"this",
"->",
"DateFactory",
"->",
"newLocalDate",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'value'",
")",
")",
";",
"}",
"catch",
"(",
"DateException",
"$",
"e",
")",
"{",
"return",
"''",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'storage'",
")",
")",
"$",
"datetime",
"=",
"$",
"this",
"->",
"DateFactory",
"->",
"toStorageDate",
"(",
"$",
"dateTime",
")",
";",
"else",
"$",
"datetime",
"=",
"$",
"this",
"->",
"DateFactory",
"->",
"toLocalDate",
"(",
"$",
"dateTime",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'nonbreaking'",
")",
"==",
"'true'",
")",
"return",
"str_replace",
"(",
"' '",
",",
"' '",
",",
"$",
"dateTime",
"->",
"format",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'format'",
")",
")",
")",
";",
"return",
"$",
"dateTime",
"->",
"format",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'format'",
")",
")",
";",
"}"
] | Returns the date in a specified format
Expected Params:
value integer (optional) If specified, we'll use this as the date value. Can also be 'now' to use the current time
nonbreaking string (optional) If 'true', then the resultant string will contain 's instead of spaces
format string The format for the date to use
@return string | [
"Returns",
"the",
"date",
"in",
"a",
"specified",
"format"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/filters/DateFilterer.php#L68-L105 | train |
wb-crowdfusion/crowdfusion | system/core/classes/mvc/filters/DateFilterer.php | DateFilterer.ago | protected function ago()
{
$threshold = $this->getParameter('threshold');
if (($this->getParameter('value') == null || $this->getParameter('value') == "0"))
return '';
elseif (($this->getParameter('value') != null) && $this->getParameter('value') instanceof Meta) {
$dateTime = $this->getParameter('value');
$dateTime = $dateTime->MetaValue;
} elseif (($this->getParameter('value') != null) && $this->getParameter('value') instanceof Date)
$dateTime = $this->getParameter('value');
elseif (($this->getParameter('value') == null) || $this->getParameter('value') == 'now')
$dateTime = $this->DateFactory->newLocalDate('@'.time());
else{
try {
$dateTime = $this->DateFactory->newLocalDate($this->getParameter('value'));
}catch(DateException $e)
{
return '';
}
}
$datetime = $this->DateFactory->toLocalDate($dateTime);
$now = time();
if($now >= $datetime->toUnix())
{
$ago = $now - $datetime->toUnix();
} else {
$ago = $datetime->toUnix() - $now;
}
if($threshold != null && $ago > (intval($threshold)*60)) {
return $this->format();
}
$text = '';
if ($ago < 60)
$text .= 'less than a minute';
elseif ($ago < 120)
$text .= 'about a minute';
elseif ($ago < (60*60))
$text .= ceil($ago/60) . ' minutes';
elseif ($ago < (120*60))
$text .= 'about an hour';
elseif ($ago < (24*60*60))
$text .= ceil($ago/(60*60)) . ' hours';
elseif ($ago < (48*60*60))
$text .= '1 day';
else
$text .= ceil($ago / (24*60*60)).' days';
if($now >= $datetime->toUnix())
{
$text .= ' ago';
} else {
$text .= ' from now';
}
return $text;
} | php | protected function ago()
{
$threshold = $this->getParameter('threshold');
if (($this->getParameter('value') == null || $this->getParameter('value') == "0"))
return '';
elseif (($this->getParameter('value') != null) && $this->getParameter('value') instanceof Meta) {
$dateTime = $this->getParameter('value');
$dateTime = $dateTime->MetaValue;
} elseif (($this->getParameter('value') != null) && $this->getParameter('value') instanceof Date)
$dateTime = $this->getParameter('value');
elseif (($this->getParameter('value') == null) || $this->getParameter('value') == 'now')
$dateTime = $this->DateFactory->newLocalDate('@'.time());
else{
try {
$dateTime = $this->DateFactory->newLocalDate($this->getParameter('value'));
}catch(DateException $e)
{
return '';
}
}
$datetime = $this->DateFactory->toLocalDate($dateTime);
$now = time();
if($now >= $datetime->toUnix())
{
$ago = $now - $datetime->toUnix();
} else {
$ago = $datetime->toUnix() - $now;
}
if($threshold != null && $ago > (intval($threshold)*60)) {
return $this->format();
}
$text = '';
if ($ago < 60)
$text .= 'less than a minute';
elseif ($ago < 120)
$text .= 'about a minute';
elseif ($ago < (60*60))
$text .= ceil($ago/60) . ' minutes';
elseif ($ago < (120*60))
$text .= 'about an hour';
elseif ($ago < (24*60*60))
$text .= ceil($ago/(60*60)) . ' hours';
elseif ($ago < (48*60*60))
$text .= '1 day';
else
$text .= ceil($ago / (24*60*60)).' days';
if($now >= $datetime->toUnix())
{
$text .= ' ago';
} else {
$text .= ' from now';
}
return $text;
} | [
"protected",
"function",
"ago",
"(",
")",
"{",
"$",
"threshold",
"=",
"$",
"this",
"->",
"getParameter",
"(",
"'threshold'",
")",
";",
"if",
"(",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'value'",
")",
"==",
"null",
"||",
"$",
"this",
"->",
"getParameter",
"(",
"'value'",
")",
"==",
"\"0\"",
")",
")",
"return",
"''",
";",
"elseif",
"(",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'value'",
")",
"!=",
"null",
")",
"&&",
"$",
"this",
"->",
"getParameter",
"(",
"'value'",
")",
"instanceof",
"Meta",
")",
"{",
"$",
"dateTime",
"=",
"$",
"this",
"->",
"getParameter",
"(",
"'value'",
")",
";",
"$",
"dateTime",
"=",
"$",
"dateTime",
"->",
"MetaValue",
";",
"}",
"elseif",
"(",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'value'",
")",
"!=",
"null",
")",
"&&",
"$",
"this",
"->",
"getParameter",
"(",
"'value'",
")",
"instanceof",
"Date",
")",
"$",
"dateTime",
"=",
"$",
"this",
"->",
"getParameter",
"(",
"'value'",
")",
";",
"elseif",
"(",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'value'",
")",
"==",
"null",
")",
"||",
"$",
"this",
"->",
"getParameter",
"(",
"'value'",
")",
"==",
"'now'",
")",
"$",
"dateTime",
"=",
"$",
"this",
"->",
"DateFactory",
"->",
"newLocalDate",
"(",
"'@'",
".",
"time",
"(",
")",
")",
";",
"else",
"{",
"try",
"{",
"$",
"dateTime",
"=",
"$",
"this",
"->",
"DateFactory",
"->",
"newLocalDate",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'value'",
")",
")",
";",
"}",
"catch",
"(",
"DateException",
"$",
"e",
")",
"{",
"return",
"''",
";",
"}",
"}",
"$",
"datetime",
"=",
"$",
"this",
"->",
"DateFactory",
"->",
"toLocalDate",
"(",
"$",
"dateTime",
")",
";",
"$",
"now",
"=",
"time",
"(",
")",
";",
"if",
"(",
"$",
"now",
">=",
"$",
"datetime",
"->",
"toUnix",
"(",
")",
")",
"{",
"$",
"ago",
"=",
"$",
"now",
"-",
"$",
"datetime",
"->",
"toUnix",
"(",
")",
";",
"}",
"else",
"{",
"$",
"ago",
"=",
"$",
"datetime",
"->",
"toUnix",
"(",
")",
"-",
"$",
"now",
";",
"}",
"if",
"(",
"$",
"threshold",
"!=",
"null",
"&&",
"$",
"ago",
">",
"(",
"intval",
"(",
"$",
"threshold",
")",
"*",
"60",
")",
")",
"{",
"return",
"$",
"this",
"->",
"format",
"(",
")",
";",
"}",
"$",
"text",
"=",
"''",
";",
"if",
"(",
"$",
"ago",
"<",
"60",
")",
"$",
"text",
".=",
"'less than a minute'",
";",
"elseif",
"(",
"$",
"ago",
"<",
"120",
")",
"$",
"text",
".=",
"'about a minute'",
";",
"elseif",
"(",
"$",
"ago",
"<",
"(",
"60",
"*",
"60",
")",
")",
"$",
"text",
".=",
"ceil",
"(",
"$",
"ago",
"/",
"60",
")",
".",
"' minutes'",
";",
"elseif",
"(",
"$",
"ago",
"<",
"(",
"120",
"*",
"60",
")",
")",
"$",
"text",
".=",
"'about an hour'",
";",
"elseif",
"(",
"$",
"ago",
"<",
"(",
"24",
"*",
"60",
"*",
"60",
")",
")",
"$",
"text",
".=",
"ceil",
"(",
"$",
"ago",
"/",
"(",
"60",
"*",
"60",
")",
")",
".",
"' hours'",
";",
"elseif",
"(",
"$",
"ago",
"<",
"(",
"48",
"*",
"60",
"*",
"60",
")",
")",
"$",
"text",
".=",
"'1 day'",
";",
"else",
"$",
"text",
".=",
"ceil",
"(",
"$",
"ago",
"/",
"(",
"24",
"*",
"60",
"*",
"60",
")",
")",
".",
"' days'",
";",
"if",
"(",
"$",
"now",
">=",
"$",
"datetime",
"->",
"toUnix",
"(",
")",
")",
"{",
"$",
"text",
".=",
"' ago'",
";",
"}",
"else",
"{",
"$",
"text",
".=",
"' from now'",
";",
"}",
"return",
"$",
"text",
";",
"}"
] | Displays a short text description of how long ago the specified timestamp was current.
Expected Params:
value LocalDate (optional) If specified and 'strdate' is null, use this as the timestamp
strdate string (optional) A string to use to create the timestamp
threshold integer (optional) If the value is older than now - threshold (in minutes), display the timestamp using format
format string (optional) The format for the date to use
@return string | [
"Displays",
"a",
"short",
"text",
"description",
"of",
"how",
"long",
"ago",
"the",
"specified",
"timestamp",
"was",
"current",
"."
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/filters/DateFilterer.php#L118-L183 | train |
wb-crowdfusion/crowdfusion | system/core/classes/mvc/filters/DateFilterer.php | DateFilterer.heartbeatAgo | protected function heartbeatAgo()
{
if ($this->getParameter('value') != null) {
$min = $this->getParameter('value');
if ($min < 60)
return $min.' min ago';
elseif ($min < 1440)
return floor($min / 60).' hrs '.($min % 60 > 0 ? floor($min % 60) .' min ' : '').'ago';
else
return floor($min / (24*60)).' days '.($min % (24*60) > 0 ? floor($min % (24*60) / 60).' hrs ' : '').'ago';
}
} | php | protected function heartbeatAgo()
{
if ($this->getParameter('value') != null) {
$min = $this->getParameter('value');
if ($min < 60)
return $min.' min ago';
elseif ($min < 1440)
return floor($min / 60).' hrs '.($min % 60 > 0 ? floor($min % 60) .' min ' : '').'ago';
else
return floor($min / (24*60)).' days '.($min % (24*60) > 0 ? floor($min % (24*60) / 60).' hrs ' : '').'ago';
}
} | [
"protected",
"function",
"heartbeatAgo",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'value'",
")",
"!=",
"null",
")",
"{",
"$",
"min",
"=",
"$",
"this",
"->",
"getParameter",
"(",
"'value'",
")",
";",
"if",
"(",
"$",
"min",
"<",
"60",
")",
"return",
"$",
"min",
".",
"' min ago'",
";",
"elseif",
"(",
"$",
"min",
"<",
"1440",
")",
"return",
"floor",
"(",
"$",
"min",
"/",
"60",
")",
".",
"' hrs '",
".",
"(",
"$",
"min",
"%",
"60",
">",
"0",
"?",
"floor",
"(",
"$",
"min",
"%",
"60",
")",
".",
"' min '",
":",
"''",
")",
".",
"'ago'",
";",
"else",
"return",
"floor",
"(",
"$",
"min",
"/",
"(",
"24",
"*",
"60",
")",
")",
".",
"' days '",
".",
"(",
"$",
"min",
"%",
"(",
"24",
"*",
"60",
")",
">",
"0",
"?",
"floor",
"(",
"$",
"min",
"%",
"(",
"24",
"*",
"60",
")",
"/",
"60",
")",
".",
"' hrs '",
":",
"''",
")",
".",
"'ago'",
";",
"}",
"}"
] | Displays the specified minutes in a logical format
Example:
for 'value' = 1586 => '1 days 2 hours ago'
Expected Params:
value string The number of minutes ago
@return string | [
"Displays",
"the",
"specified",
"minutes",
"in",
"a",
"logical",
"format"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/filters/DateFilterer.php#L196-L208 | train |
fridge-project/dbal | src/Fridge/DBAL/Query/Rewriter/NamedQueryRewriter.php | NamedQueryRewriter.determinePlaceholderPositions | private static function determinePlaceholderPositions($query, $placeholder)
{
// Placeholder positions.
$placeholderPositions = array();
// TRUE if we are in an escaped section else FALSE.
$escaped = false;
// The placeholder length.
$placeholderLength = strlen($placeholder);
// The placeholder position limit before which it can be found.
$placeolderPositionLimit = strlen($query) - $placeholderLength + 1;
// Iterache each query char to find the placeholder.
for ($placeholderPosition = 0; $placeholderPosition < $placeolderPositionLimit; $placeholderPosition++) {
// Switch the escaped flag if the current query char is a escape delimiter.
if (in_array($query[$placeholderPosition], array('\'', '"'))) {
$escaped = !$escaped;
}
// Collect the placeholder position if we are not in an escaped section and there is the placeholder at the
// current position.
if (!$escaped && (substr($query, $placeholderPosition, $placeholderLength) === $placeholder)) {
$placeholderPositions[] = $placeholderPosition;
}
}
// Check if the placeholder has been found.
if (empty($placeholderPositions)) {
throw QueryRewriterException::namedPlaceholderDoesNotExist($placeholder, $query);
}
return $placeholderPositions;
} | php | private static function determinePlaceholderPositions($query, $placeholder)
{
// Placeholder positions.
$placeholderPositions = array();
// TRUE if we are in an escaped section else FALSE.
$escaped = false;
// The placeholder length.
$placeholderLength = strlen($placeholder);
// The placeholder position limit before which it can be found.
$placeolderPositionLimit = strlen($query) - $placeholderLength + 1;
// Iterache each query char to find the placeholder.
for ($placeholderPosition = 0; $placeholderPosition < $placeolderPositionLimit; $placeholderPosition++) {
// Switch the escaped flag if the current query char is a escape delimiter.
if (in_array($query[$placeholderPosition], array('\'', '"'))) {
$escaped = !$escaped;
}
// Collect the placeholder position if we are not in an escaped section and there is the placeholder at the
// current position.
if (!$escaped && (substr($query, $placeholderPosition, $placeholderLength) === $placeholder)) {
$placeholderPositions[] = $placeholderPosition;
}
}
// Check if the placeholder has been found.
if (empty($placeholderPositions)) {
throw QueryRewriterException::namedPlaceholderDoesNotExist($placeholder, $query);
}
return $placeholderPositions;
} | [
"private",
"static",
"function",
"determinePlaceholderPositions",
"(",
"$",
"query",
",",
"$",
"placeholder",
")",
"{",
"// Placeholder positions.",
"$",
"placeholderPositions",
"=",
"array",
"(",
")",
";",
"// TRUE if we are in an escaped section else FALSE.",
"$",
"escaped",
"=",
"false",
";",
"// The placeholder length.",
"$",
"placeholderLength",
"=",
"strlen",
"(",
"$",
"placeholder",
")",
";",
"// The placeholder position limit before which it can be found.",
"$",
"placeolderPositionLimit",
"=",
"strlen",
"(",
"$",
"query",
")",
"-",
"$",
"placeholderLength",
"+",
"1",
";",
"// Iterache each query char to find the placeholder.",
"for",
"(",
"$",
"placeholderPosition",
"=",
"0",
";",
"$",
"placeholderPosition",
"<",
"$",
"placeolderPositionLimit",
";",
"$",
"placeholderPosition",
"++",
")",
"{",
"// Switch the escaped flag if the current query char is a escape delimiter.",
"if",
"(",
"in_array",
"(",
"$",
"query",
"[",
"$",
"placeholderPosition",
"]",
",",
"array",
"(",
"'\\''",
",",
"'\"'",
")",
")",
")",
"{",
"$",
"escaped",
"=",
"!",
"$",
"escaped",
";",
"}",
"// Collect the placeholder position if we are not in an escaped section and there is the placeholder at the",
"// current position.",
"if",
"(",
"!",
"$",
"escaped",
"&&",
"(",
"substr",
"(",
"$",
"query",
",",
"$",
"placeholderPosition",
",",
"$",
"placeholderLength",
")",
"===",
"$",
"placeholder",
")",
")",
"{",
"$",
"placeholderPositions",
"[",
"]",
"=",
"$",
"placeholderPosition",
";",
"}",
"}",
"// Check if the placeholder has been found.",
"if",
"(",
"empty",
"(",
"$",
"placeholderPositions",
")",
")",
"{",
"throw",
"QueryRewriterException",
"::",
"namedPlaceholderDoesNotExist",
"(",
"$",
"placeholder",
",",
"$",
"query",
")",
";",
"}",
"return",
"$",
"placeholderPositions",
";",
"}"
] | Determines the placeholder positions in the query.
Example:
- parameters:
- query: SELECT * FROM foo WHERE foo IN (:foo) AND bar IN (:foo)
^ (32) ^ (50)
- placeholder: :foo
- result:
- placeholderPositions: array(32, 50)
@param string $query The query.
@param string $placeholder The placeholder.
@throws \Fridge\DBAL\Exception\QueryRewriterException If the placeholder does not exist.
@return array The placeholder positions. | [
"Determines",
"the",
"placeholder",
"positions",
"in",
"the",
"query",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Query/Rewriter/NamedQueryRewriter.php#L108-L143 | train |
fridge-project/dbal | src/Fridge/DBAL/Query/Rewriter/NamedQueryRewriter.php | NamedQueryRewriter.generateNewPlaceholders | private static function generateNewPlaceholders($placeholder, $count)
{
$newPlaceholders = array();
for ($index = 1; $index <= $count; $index++) {
$newPlaceholders[] = $placeholder.$index;
}
return $newPlaceholders;
} | php | private static function generateNewPlaceholders($placeholder, $count)
{
$newPlaceholders = array();
for ($index = 1; $index <= $count; $index++) {
$newPlaceholders[] = $placeholder.$index;
}
return $newPlaceholders;
} | [
"private",
"static",
"function",
"generateNewPlaceholders",
"(",
"$",
"placeholder",
",",
"$",
"count",
")",
"{",
"$",
"newPlaceholders",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"index",
"=",
"1",
";",
"$",
"index",
"<=",
"$",
"count",
";",
"$",
"index",
"++",
")",
"{",
"$",
"newPlaceholders",
"[",
"]",
"=",
"$",
"placeholder",
".",
"$",
"index",
";",
"}",
"return",
"$",
"newPlaceholders",
";",
"}"
] | Generates the new placeholders according to the placeholder and the number of parameter.
Example:
- parameters:
- placeholder: :foo
- count: 3
- result:
- newPlaceholders: array(':foo1', ':foo2', ':foo3')
@param string $placeholder The placeholder.
@param integer $count The number of parameter.
@return array The new placeholders. | [
"Generates",
"the",
"new",
"placeholders",
"according",
"to",
"the",
"placeholder",
"and",
"the",
"number",
"of",
"parameter",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Query/Rewriter/NamedQueryRewriter.php#L160-L169 | train |
fridge-project/dbal | src/Fridge/DBAL/Query/Rewriter/NamedQueryRewriter.php | NamedQueryRewriter.rewriteQuery | private static function rewriteQuery(
$query,
array $placeholderPositions,
$placeholderLength,
array $newPlaceholders
) {
// The position gap produced by the rewrite.
$positionGap = 0;
// Generates new placeholders and his length.
$placeholders = implode(', ', $newPlaceholders);
$placeholdersLength = strlen($placeholders);
// Iterate placeholder positions to rewrite each one.
foreach ($placeholderPositions as $placeholderPosition) {
// Rewrite the query.
$query = substr($query, 0, $placeholderPosition + $positionGap).
$placeholders.
substr($query, $placeholderPosition + $positionGap + $placeholderLength);
// Increase the position gap.
$positionGap += $placeholdersLength - $placeholderLength;
}
return $query;
} | php | private static function rewriteQuery(
$query,
array $placeholderPositions,
$placeholderLength,
array $newPlaceholders
) {
// The position gap produced by the rewrite.
$positionGap = 0;
// Generates new placeholders and his length.
$placeholders = implode(', ', $newPlaceholders);
$placeholdersLength = strlen($placeholders);
// Iterate placeholder positions to rewrite each one.
foreach ($placeholderPositions as $placeholderPosition) {
// Rewrite the query.
$query = substr($query, 0, $placeholderPosition + $positionGap).
$placeholders.
substr($query, $placeholderPosition + $positionGap + $placeholderLength);
// Increase the position gap.
$positionGap += $placeholdersLength - $placeholderLength;
}
return $query;
} | [
"private",
"static",
"function",
"rewriteQuery",
"(",
"$",
"query",
",",
"array",
"$",
"placeholderPositions",
",",
"$",
"placeholderLength",
",",
"array",
"$",
"newPlaceholders",
")",
"{",
"// The position gap produced by the rewrite.",
"$",
"positionGap",
"=",
"0",
";",
"// Generates new placeholders and his length.",
"$",
"placeholders",
"=",
"implode",
"(",
"', '",
",",
"$",
"newPlaceholders",
")",
";",
"$",
"placeholdersLength",
"=",
"strlen",
"(",
"$",
"placeholders",
")",
";",
"// Iterate placeholder positions to rewrite each one.",
"foreach",
"(",
"$",
"placeholderPositions",
"as",
"$",
"placeholderPosition",
")",
"{",
"// Rewrite the query.",
"$",
"query",
"=",
"substr",
"(",
"$",
"query",
",",
"0",
",",
"$",
"placeholderPosition",
"+",
"$",
"positionGap",
")",
".",
"$",
"placeholders",
".",
"substr",
"(",
"$",
"query",
",",
"$",
"placeholderPosition",
"+",
"$",
"positionGap",
"+",
"$",
"placeholderLength",
")",
";",
"// Increase the position gap.",
"$",
"positionGap",
"+=",
"$",
"placeholdersLength",
"-",
"$",
"placeholderLength",
";",
"}",
"return",
"$",
"query",
";",
"}"
] | Rewrites the named query according to the placeholder length and positions and the new placeholders.
Example:
- parameters:
- query; SELECT * FROM foo WHERE foo IN (:foo) AND bar IN (:foo)
- placeholderPositions: array(32, 50)
- placeholderLength: 4
- newPlaceholders: array(':foo1', ':foo2', ':foo3')
- result:
- rewrittenQuery: SELECT * FROM foo WHERE foo IN (:foo1, :foo2, :foo3) AND bar IN (:foo1, :foo2, :foo3)
@param string $query The query.
@param array $placeholderPositions The placeholder positions.
@param integer $placeholderLength The placeholder length.
@param array $newPlaceholders The new placeholders.
@return string The rewritten query. | [
"Rewrites",
"the",
"named",
"query",
"according",
"to",
"the",
"placeholder",
"length",
"and",
"positions",
"and",
"the",
"new",
"placeholders",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Query/Rewriter/NamedQueryRewriter.php#L190-L216 | train |
fridge-project/dbal | src/Fridge/DBAL/Query/Rewriter/NamedQueryRewriter.php | NamedQueryRewriter.rewriteParameterAndType | private static function rewriteParameterAndType(
array $parameters,
array $types,
$parameter,
array $newPlaceholders
) {
// Extract the fridge type.
$type = static::extractType($types[$parameter]);
// Iterate new placeholders to rewrite each one.
foreach ($newPlaceholders as $newPlaceholderIndex => $newPlaceholder) {
// Determine the new parameter.
$newParameter = substr($newPlaceholder, 1);
// Rewrites parameters and types.
$parameters[$newParameter] = $parameters[$parameter][$newPlaceholderIndex];
$types[$newParameter] = $type;
}
// Remove rewritten parameter and type.
unset($parameters[$parameter]);
unset($types[$parameter]);
return array($parameters, $types);
} | php | private static function rewriteParameterAndType(
array $parameters,
array $types,
$parameter,
array $newPlaceholders
) {
// Extract the fridge type.
$type = static::extractType($types[$parameter]);
// Iterate new placeholders to rewrite each one.
foreach ($newPlaceholders as $newPlaceholderIndex => $newPlaceholder) {
// Determine the new parameter.
$newParameter = substr($newPlaceholder, 1);
// Rewrites parameters and types.
$parameters[$newParameter] = $parameters[$parameter][$newPlaceholderIndex];
$types[$newParameter] = $type;
}
// Remove rewritten parameter and type.
unset($parameters[$parameter]);
unset($types[$parameter]);
return array($parameters, $types);
} | [
"private",
"static",
"function",
"rewriteParameterAndType",
"(",
"array",
"$",
"parameters",
",",
"array",
"$",
"types",
",",
"$",
"parameter",
",",
"array",
"$",
"newPlaceholders",
")",
"{",
"// Extract the fridge type.",
"$",
"type",
"=",
"static",
"::",
"extractType",
"(",
"$",
"types",
"[",
"$",
"parameter",
"]",
")",
";",
"// Iterate new placeholders to rewrite each one.",
"foreach",
"(",
"$",
"newPlaceholders",
"as",
"$",
"newPlaceholderIndex",
"=>",
"$",
"newPlaceholder",
")",
"{",
"// Determine the new parameter.",
"$",
"newParameter",
"=",
"substr",
"(",
"$",
"newPlaceholder",
",",
"1",
")",
";",
"// Rewrites parameters and types.",
"$",
"parameters",
"[",
"$",
"newParameter",
"]",
"=",
"$",
"parameters",
"[",
"$",
"parameter",
"]",
"[",
"$",
"newPlaceholderIndex",
"]",
";",
"$",
"types",
"[",
"$",
"newParameter",
"]",
"=",
"$",
"type",
";",
"}",
"// Remove rewritten parameter and type.",
"unset",
"(",
"$",
"parameters",
"[",
"$",
"parameter",
"]",
")",
";",
"unset",
"(",
"$",
"types",
"[",
"$",
"parameter",
"]",
")",
";",
"return",
"array",
"(",
"$",
"parameters",
",",
"$",
"types",
")",
";",
"}"
] | Rewrites the query parameter & type by expanding them according to the parameter and the new placeholders.
Example:
- parameters:
- parameters: array('foo' => array(1, 3, 5))
- types: array('foo' => 'integer[]')
- parameter: foo
- newPlaceholders: array(':foo1', ':foo2', ':foo3')
- result:
- rewrittenParameters: array('foo1' => 1, 'foo2' => 3, 'foo3' => 5)
- rewrittenTypes: array('foo1' => 'integer', 'foo2' => 'integer', 'foo3' => 'integer')
@param array $parameters The query parameters.
@param array $types The query types.
@param string $parameter The query parameter to rewrite.
@param array $newPlaceholders The new placeholders.
@return array 0 => The rewritten parameters, 1 => The rewritten types. | [
"Rewrites",
"the",
"query",
"parameter",
"&",
"type",
"by",
"expanding",
"them",
"according",
"to",
"the",
"parameter",
"and",
"the",
"new",
"placeholders",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Query/Rewriter/NamedQueryRewriter.php#L238-L263 | train |
nice-php/benchmark | src/ResultPrinter/MarkdownPrinter.php | MarkdownPrinter.printBenchmarkIntro | public function printBenchmarkIntro(Benchmark $benchmark)
{
printf("## %s\n", $benchmark->getName());
if ($description = $benchmark->getDescription()) {
printf("%s\n", $description);
}
print("\n");
printf(
"This benchmark consists of %s tests. Each test is executed %s times, the results pruned, and then averaged. %s\n\n\n",
number_format(count($benchmark->getTests())),
number_format($benchmark->getIterations()),
$benchmark->getResultPruner()->getDescription()
);
} | php | public function printBenchmarkIntro(Benchmark $benchmark)
{
printf("## %s\n", $benchmark->getName());
if ($description = $benchmark->getDescription()) {
printf("%s\n", $description);
}
print("\n");
printf(
"This benchmark consists of %s tests. Each test is executed %s times, the results pruned, and then averaged. %s\n\n\n",
number_format(count($benchmark->getTests())),
number_format($benchmark->getIterations()),
$benchmark->getResultPruner()->getDescription()
);
} | [
"public",
"function",
"printBenchmarkIntro",
"(",
"Benchmark",
"$",
"benchmark",
")",
"{",
"printf",
"(",
"\"## %s\\n\"",
",",
"$",
"benchmark",
"->",
"getName",
"(",
")",
")",
";",
"if",
"(",
"$",
"description",
"=",
"$",
"benchmark",
"->",
"getDescription",
"(",
")",
")",
"{",
"printf",
"(",
"\"%s\\n\"",
",",
"$",
"description",
")",
";",
"}",
"print",
"(",
"\"\\n\"",
")",
";",
"printf",
"(",
"\"This benchmark consists of %s tests. Each test is executed %s times, the results pruned, and then averaged. %s\\n\\n\\n\"",
",",
"number_format",
"(",
"count",
"(",
"$",
"benchmark",
"->",
"getTests",
"(",
")",
")",
")",
",",
"number_format",
"(",
"$",
"benchmark",
"->",
"getIterations",
"(",
")",
")",
",",
"$",
"benchmark",
"->",
"getResultPruner",
"(",
")",
"->",
"getDescription",
"(",
")",
")",
";",
"}"
] | Outputs an introduction prior to test execution
@param Benchmark $benchmark | [
"Outputs",
"an",
"introduction",
"prior",
"to",
"test",
"execution"
] | 2084c77dbb88cd76006abbfe85b2b704f6bbd1cf | https://github.com/nice-php/benchmark/blob/2084c77dbb88cd76006abbfe85b2b704f6bbd1cf/src/ResultPrinter/MarkdownPrinter.php#L28-L41 | train |
spiffyjr/spiffy-package | src/PackageManager.php | PackageManager.writeCache | public function writeCache()
{
$cacheFile = $this->getCacheFile();
if (!$cacheFile) {
return;
}
if (is_writeable(dirname($cacheFile))) {
file_put_contents(
$cacheFile,
sprintf(
'<?php return %s;',
var_export($this->mergedConfig, true)
)
);
}
} | php | public function writeCache()
{
$cacheFile = $this->getCacheFile();
if (!$cacheFile) {
return;
}
if (is_writeable(dirname($cacheFile))) {
file_put_contents(
$cacheFile,
sprintf(
'<?php return %s;',
var_export($this->mergedConfig, true)
)
);
}
} | [
"public",
"function",
"writeCache",
"(",
")",
"{",
"$",
"cacheFile",
"=",
"$",
"this",
"->",
"getCacheFile",
"(",
")",
";",
"if",
"(",
"!",
"$",
"cacheFile",
")",
"{",
"return",
";",
"}",
"if",
"(",
"is_writeable",
"(",
"dirname",
"(",
"$",
"cacheFile",
")",
")",
")",
"{",
"file_put_contents",
"(",
"$",
"cacheFile",
",",
"sprintf",
"(",
"'<?php return %s;'",
",",
"var_export",
"(",
"$",
"this",
"->",
"mergedConfig",
",",
"true",
")",
")",
")",
";",
"}",
"}"
] | Writes config to filesystem. | [
"Writes",
"config",
"to",
"filesystem",
"."
] | 42ca8a687efb2d06ecb3d4e0c09456d938a2bc09 | https://github.com/spiffyjr/spiffy-package/blob/42ca8a687efb2d06ecb3d4e0c09456d938a2bc09/src/PackageManager.php#L183-L199 | train |
TiMESPLiNTER/tsFramework | src/ch/timesplinter/controller/StaticPageController.php | StaticPageController.getPage | public function getPage()
{
$pageData = $this->core->getSettings()->pagedata;
$routeID = $this->route->id;
$this->logger->info('Requested route: ' . $routeID);
$this->logger->debug('Route info', array($this->route));
if(isset($pageData->$routeID->active))
$this->view->addActiveHtmlId($pageData->$routeID->active);
$html = $this->view->render($routeID . '.html', array(
'siteTitle' => isset($pageData->$routeID->title)?$pageData->$routeID->title:null,
'runtime' => round(microtime(true) - REQUEST_TIME,3) ,
'locale' => $this->core->getLocaleHandler()->getLocale(),
'timezone' => date_default_timezone_get(),
'base_path' => StringUtils::afterFirst(getcwd(), $_SERVER['DOCUMENT_ROOT'])
));
return new HttpResponse(200, $html, $this->headers);
} | php | public function getPage()
{
$pageData = $this->core->getSettings()->pagedata;
$routeID = $this->route->id;
$this->logger->info('Requested route: ' . $routeID);
$this->logger->debug('Route info', array($this->route));
if(isset($pageData->$routeID->active))
$this->view->addActiveHtmlId($pageData->$routeID->active);
$html = $this->view->render($routeID . '.html', array(
'siteTitle' => isset($pageData->$routeID->title)?$pageData->$routeID->title:null,
'runtime' => round(microtime(true) - REQUEST_TIME,3) ,
'locale' => $this->core->getLocaleHandler()->getLocale(),
'timezone' => date_default_timezone_get(),
'base_path' => StringUtils::afterFirst(getcwd(), $_SERVER['DOCUMENT_ROOT'])
));
return new HttpResponse(200, $html, $this->headers);
} | [
"public",
"function",
"getPage",
"(",
")",
"{",
"$",
"pageData",
"=",
"$",
"this",
"->",
"core",
"->",
"getSettings",
"(",
")",
"->",
"pagedata",
";",
"$",
"routeID",
"=",
"$",
"this",
"->",
"route",
"->",
"id",
";",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"'Requested route: '",
".",
"$",
"routeID",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'Route info'",
",",
"array",
"(",
"$",
"this",
"->",
"route",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"pageData",
"->",
"$",
"routeID",
"->",
"active",
")",
")",
"$",
"this",
"->",
"view",
"->",
"addActiveHtmlId",
"(",
"$",
"pageData",
"->",
"$",
"routeID",
"->",
"active",
")",
";",
"$",
"html",
"=",
"$",
"this",
"->",
"view",
"->",
"render",
"(",
"$",
"routeID",
".",
"'.html'",
",",
"array",
"(",
"'siteTitle'",
"=>",
"isset",
"(",
"$",
"pageData",
"->",
"$",
"routeID",
"->",
"title",
")",
"?",
"$",
"pageData",
"->",
"$",
"routeID",
"->",
"title",
":",
"null",
",",
"'runtime'",
"=>",
"round",
"(",
"microtime",
"(",
"true",
")",
"-",
"REQUEST_TIME",
",",
"3",
")",
",",
"'locale'",
"=>",
"$",
"this",
"->",
"core",
"->",
"getLocaleHandler",
"(",
")",
"->",
"getLocale",
"(",
")",
",",
"'timezone'",
"=>",
"date_default_timezone_get",
"(",
")",
",",
"'base_path'",
"=>",
"StringUtils",
"::",
"afterFirst",
"(",
"getcwd",
"(",
")",
",",
"$",
"_SERVER",
"[",
"'DOCUMENT_ROOT'",
"]",
")",
")",
")",
";",
"return",
"new",
"HttpResponse",
"(",
"200",
",",
"$",
"html",
",",
"$",
"this",
"->",
"headers",
")",
";",
"}"
] | Displays a template based page by rendering a template file which is generated by route name plus .html ending
@throws \UnexpectedValueException
@return \HttpResponse The response object with content, headers, HTTP status code, etc. | [
"Displays",
"a",
"template",
"based",
"page",
"by",
"rendering",
"a",
"template",
"file",
"which",
"is",
"generated",
"by",
"route",
"name",
"plus",
".",
"html",
"ending"
] | b3b9fd98f6d456a9e571015877ecca203786fd0c | https://github.com/TiMESPLiNTER/tsFramework/blob/b3b9fd98f6d456a9e571015877ecca203786fd0c/src/ch/timesplinter/controller/StaticPageController.php#L49-L69 | train |
ZendExperts/phpids | lib/IDS/Log/File.php | IDS_Log_File.execute | public function execute(IDS_Report $data)
{
/*
* In case the data has been modified before it might be necessary
* to convert it to string since we can't store array or object
* into a file
*/
$data = $this->prepareData($data);
if (is_string($data)) {
if (file_exists($this->logfile)) {
$data = trim($data);
if (!empty($data)) {
if (is_writable($this->logfile)) {
$handle = fopen($this->logfile, 'a');
fwrite($handle, trim($data) . "\n");
fclose($handle);
} else {
throw new Exception(
'Please make sure that ' . $this->logfile .
' is writeable.'
);
}
}
} else {
throw new Exception(
'Given file does not exist. Please make sure the
logfile is present in the given directory.'
);
}
} else {
throw new Exception(
'Please make sure that data returned by
IDS_Log_File::prepareData() is a string.'
);
}
return true;
} | php | public function execute(IDS_Report $data)
{
/*
* In case the data has been modified before it might be necessary
* to convert it to string since we can't store array or object
* into a file
*/
$data = $this->prepareData($data);
if (is_string($data)) {
if (file_exists($this->logfile)) {
$data = trim($data);
if (!empty($data)) {
if (is_writable($this->logfile)) {
$handle = fopen($this->logfile, 'a');
fwrite($handle, trim($data) . "\n");
fclose($handle);
} else {
throw new Exception(
'Please make sure that ' . $this->logfile .
' is writeable.'
);
}
}
} else {
throw new Exception(
'Given file does not exist. Please make sure the
logfile is present in the given directory.'
);
}
} else {
throw new Exception(
'Please make sure that data returned by
IDS_Log_File::prepareData() is a string.'
);
}
return true;
} | [
"public",
"function",
"execute",
"(",
"IDS_Report",
"$",
"data",
")",
"{",
"/*\n * In case the data has been modified before it might be necessary \n * to convert it to string since we can't store array or object \n * into a file\n */",
"$",
"data",
"=",
"$",
"this",
"->",
"prepareData",
"(",
"$",
"data",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"data",
")",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"logfile",
")",
")",
"{",
"$",
"data",
"=",
"trim",
"(",
"$",
"data",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"if",
"(",
"is_writable",
"(",
"$",
"this",
"->",
"logfile",
")",
")",
"{",
"$",
"handle",
"=",
"fopen",
"(",
"$",
"this",
"->",
"logfile",
",",
"'a'",
")",
";",
"fwrite",
"(",
"$",
"handle",
",",
"trim",
"(",
"$",
"data",
")",
".",
"\"\\n\"",
")",
";",
"fclose",
"(",
"$",
"handle",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"'Please make sure that '",
".",
"$",
"this",
"->",
"logfile",
".",
"' is writeable.'",
")",
";",
"}",
"}",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"'Given file does not exist. Please make sure the\n logfile is present in the given directory.'",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"'Please make sure that data returned by\n IDS_Log_File::prepareData() is a string.'",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Stores given data into a file
@param object $data IDS_Report
@throws Exception if the logfile isn't writeable
@return boolean | [
"Stores",
"given",
"data",
"into",
"a",
"file"
] | f30df04eea47b94d056e2ae9ec8fea1c626f1c03 | https://github.com/ZendExperts/phpids/blob/f30df04eea47b94d056e2ae9ec8fea1c626f1c03/lib/IDS/Log/File.php#L177-L220 | train |
modulusphp/utility | View.php | View.isCalledByWhoops | public static function isCalledByWhoops() : bool
{
/**
* Get trace
*/
$trace = debug_backtrace();
$trace = end($trace);
return isset($trace['class']) && $trace['class'] == 'Whoops\Run';
} | php | public static function isCalledByWhoops() : bool
{
/**
* Get trace
*/
$trace = debug_backtrace();
$trace = end($trace);
return isset($trace['class']) && $trace['class'] == 'Whoops\Run';
} | [
"public",
"static",
"function",
"isCalledByWhoops",
"(",
")",
":",
"bool",
"{",
"/**\n * Get trace\n */",
"$",
"trace",
"=",
"debug_backtrace",
"(",
")",
";",
"$",
"trace",
"=",
"end",
"(",
"$",
"trace",
")",
";",
"return",
"isset",
"(",
"$",
"trace",
"[",
"'class'",
"]",
")",
"&&",
"$",
"trace",
"[",
"'class'",
"]",
"==",
"'Whoops\\Run'",
";",
"}"
] | Check if this is an exception
@return bool | [
"Check",
"if",
"this",
"is",
"an",
"exception"
] | c1e127539b13d3ec8381e41c64b881e0701807f5 | https://github.com/modulusphp/utility/blob/c1e127539b13d3ec8381e41c64b881e0701807f5/View.php#L46-L56 | train |
Hnto/nuki | src/Skeletons/Processes/Event.php | Event.notify | public function notify() {
foreach($this->watchers as $watcher) {
if ($this->stopNotify === true) {
break;
}
$watcher->update($this);
}
} | php | public function notify() {
foreach($this->watchers as $watcher) {
if ($this->stopNotify === true) {
break;
}
$watcher->update($this);
}
} | [
"public",
"function",
"notify",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"watchers",
"as",
"$",
"watcher",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"stopNotify",
"===",
"true",
")",
"{",
"break",
";",
"}",
"$",
"watcher",
"->",
"update",
"(",
"$",
"this",
")",
";",
"}",
"}"
] | Notify all available watchers | [
"Notify",
"all",
"available",
"watchers"
] | c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c | https://github.com/Hnto/nuki/blob/c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c/src/Skeletons/Processes/Event.php#L102-L110 | train |
Kris-Kuiper/sFire-Framework | src/Validator/File/Validator.php | Validator.isRequired | private function isRequired($field, $file) {
if(true === isset($this -> required[$field])) {
if(false === $this -> required[$field] && (null === $file || trim($file['tmp_name']) === '')) {
return true;
}
}
return false;
} | php | private function isRequired($field, $file) {
if(true === isset($this -> required[$field])) {
if(false === $this -> required[$field] && (null === $file || trim($file['tmp_name']) === '')) {
return true;
}
}
return false;
} | [
"private",
"function",
"isRequired",
"(",
"$",
"field",
",",
"$",
"file",
")",
"{",
"if",
"(",
"true",
"===",
"isset",
"(",
"$",
"this",
"->",
"required",
"[",
"$",
"field",
"]",
")",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"required",
"[",
"$",
"field",
"]",
"&&",
"(",
"null",
"===",
"$",
"file",
"||",
"trim",
"(",
"$",
"file",
"[",
"'tmp_name'",
"]",
")",
"===",
"''",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Evaluates if file is required or not
@param $field string
@param $file null | string
@return boolean | [
"Evaluates",
"if",
"file",
"is",
"required",
"or",
"not"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Validator/File/Validator.php#L141-L151 | train |
Kris-Kuiper/sFire-Framework | src/Validator/File/Validator.php | Validator.getFile | private function getFile($field, $prefix) {
//Prefix
if(null !== $prefix) {
$field = $prefix . '[' . $field . ']';
}
//Get the value
$helper = new StringToArray();
$data = $helper -> execute($field, null, $this -> getData());
return $data;
} | php | private function getFile($field, $prefix) {
//Prefix
if(null !== $prefix) {
$field = $prefix . '[' . $field . ']';
}
//Get the value
$helper = new StringToArray();
$data = $helper -> execute($field, null, $this -> getData());
return $data;
} | [
"private",
"function",
"getFile",
"(",
"$",
"field",
",",
"$",
"prefix",
")",
"{",
"//Prefix\r",
"if",
"(",
"null",
"!==",
"$",
"prefix",
")",
"{",
"$",
"field",
"=",
"$",
"prefix",
".",
"'['",
".",
"$",
"field",
".",
"']'",
";",
"}",
"//Get the value\r",
"$",
"helper",
"=",
"new",
"StringToArray",
"(",
")",
";",
"$",
"data",
"=",
"$",
"helper",
"->",
"execute",
"(",
"$",
"field",
",",
"null",
",",
"$",
"this",
"->",
"getData",
"(",
")",
")",
";",
"return",
"$",
"data",
";",
"}"
] | Returns the file array for a given field
@param string $field
@param string $prefix
@return mixed | [
"Returns",
"the",
"file",
"array",
"for",
"a",
"given",
"field"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Validator/File/Validator.php#L215-L227 | train |
Wedeto/FileFormats | src/INI/Writer.php | Writer.writeParameter | private static function writeParameter($file_handle, $name, $parameter, $depth = 0)
{
if ($depth > 1)
throw new \DomainException("Cannot nest arrays more than once in INI-file");
$str = "";
if (WF::is_array_like($parameter))
{
foreach ($parameter as $key => $val)
{
$prefix = $name . "[" . $key . "]";
self::writeParameter($file_handle, $prefix, $val, $depth + 1);
}
}
elseif (is_bool($parameter))
fwrite($file_handle, "$name = " . ($parameter ? "true" : "false") . "\n");
elseif (is_null($parameter))
fwrite($file_handle, "$name = null\n");
elseif (is_float($parameter) && WF::is_int_val((string)$parameter))
fwrite($file_handle, "$name = " . sprintf("%.1f", $parameter) . "\n");
elseif (is_float($parameter))
fwrite($file_handle, "$name = " . $parameter . "\n");
elseif (is_numeric($parameter))
fwrite($file_handle, "$name = " . $parameter . "\n");
else
fwrite($file_handle, "$name = \"" . str_replace('"', '\\"', $parameter) . "\"\n");
} | php | private static function writeParameter($file_handle, $name, $parameter, $depth = 0)
{
if ($depth > 1)
throw new \DomainException("Cannot nest arrays more than once in INI-file");
$str = "";
if (WF::is_array_like($parameter))
{
foreach ($parameter as $key => $val)
{
$prefix = $name . "[" . $key . "]";
self::writeParameter($file_handle, $prefix, $val, $depth + 1);
}
}
elseif (is_bool($parameter))
fwrite($file_handle, "$name = " . ($parameter ? "true" : "false") . "\n");
elseif (is_null($parameter))
fwrite($file_handle, "$name = null\n");
elseif (is_float($parameter) && WF::is_int_val((string)$parameter))
fwrite($file_handle, "$name = " . sprintf("%.1f", $parameter) . "\n");
elseif (is_float($parameter))
fwrite($file_handle, "$name = " . $parameter . "\n");
elseif (is_numeric($parameter))
fwrite($file_handle, "$name = " . $parameter . "\n");
else
fwrite($file_handle, "$name = \"" . str_replace('"', '\\"', $parameter) . "\"\n");
} | [
"private",
"static",
"function",
"writeParameter",
"(",
"$",
"file_handle",
",",
"$",
"name",
",",
"$",
"parameter",
",",
"$",
"depth",
"=",
"0",
")",
"{",
"if",
"(",
"$",
"depth",
">",
"1",
")",
"throw",
"new",
"\\",
"DomainException",
"(",
"\"Cannot nest arrays more than once in INI-file\"",
")",
";",
"$",
"str",
"=",
"\"\"",
";",
"if",
"(",
"WF",
"::",
"is_array_like",
"(",
"$",
"parameter",
")",
")",
"{",
"foreach",
"(",
"$",
"parameter",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"prefix",
"=",
"$",
"name",
".",
"\"[\"",
".",
"$",
"key",
".",
"\"]\"",
";",
"self",
"::",
"writeParameter",
"(",
"$",
"file_handle",
",",
"$",
"prefix",
",",
"$",
"val",
",",
"$",
"depth",
"+",
"1",
")",
";",
"}",
"}",
"elseif",
"(",
"is_bool",
"(",
"$",
"parameter",
")",
")",
"fwrite",
"(",
"$",
"file_handle",
",",
"\"$name = \"",
".",
"(",
"$",
"parameter",
"?",
"\"true\"",
":",
"\"false\"",
")",
".",
"\"\\n\"",
")",
";",
"elseif",
"(",
"is_null",
"(",
"$",
"parameter",
")",
")",
"fwrite",
"(",
"$",
"file_handle",
",",
"\"$name = null\\n\"",
")",
";",
"elseif",
"(",
"is_float",
"(",
"$",
"parameter",
")",
"&&",
"WF",
"::",
"is_int_val",
"(",
"(",
"string",
")",
"$",
"parameter",
")",
")",
"fwrite",
"(",
"$",
"file_handle",
",",
"\"$name = \"",
".",
"sprintf",
"(",
"\"%.1f\"",
",",
"$",
"parameter",
")",
".",
"\"\\n\"",
")",
";",
"elseif",
"(",
"is_float",
"(",
"$",
"parameter",
")",
")",
"fwrite",
"(",
"$",
"file_handle",
",",
"\"$name = \"",
".",
"$",
"parameter",
".",
"\"\\n\"",
")",
";",
"elseif",
"(",
"is_numeric",
"(",
"$",
"parameter",
")",
")",
"fwrite",
"(",
"$",
"file_handle",
",",
"\"$name = \"",
".",
"$",
"parameter",
".",
"\"\\n\"",
")",
";",
"else",
"fwrite",
"(",
"$",
"file_handle",
",",
"\"$name = \\\"\"",
".",
"str_replace",
"(",
"'\"'",
",",
"'\\\\\"'",
",",
"$",
"parameter",
")",
".",
"\"\\\"\\n\"",
")",
";",
"}"
] | Recursive function that writes a parameter or a series of parameters
to the INI file
@param $name string The name of the parameter
@param $parameter mixed The parameter to write | [
"Recursive",
"function",
"that",
"writes",
"a",
"parameter",
"or",
"a",
"series",
"of",
"parameters",
"to",
"the",
"INI",
"file"
] | 65b71fbd38a2ee6b504622aca4f4047ce9d31e9f | https://github.com/Wedeto/FileFormats/blob/65b71fbd38a2ee6b504622aca4f4047ce9d31e9f/src/INI/Writer.php#L167-L193 | train |
wb-crowdfusion/crowdfusion | system/core/classes/mvc/http/Request.php | Request.getAcceptedEncodings | public function getAcceptedEncodings()
{
if (null === $this->encodings) {
if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
$this->encodings = strtolower(trim($_SERVER['HTTP_ACCEPT_ENCODING']));
} else {
$this->encodings = '';
}
}
return $this->encodings;
} | php | public function getAcceptedEncodings()
{
if (null === $this->encodings) {
if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
$this->encodings = strtolower(trim($_SERVER['HTTP_ACCEPT_ENCODING']));
} else {
$this->encodings = '';
}
}
return $this->encodings;
} | [
"public",
"function",
"getAcceptedEncodings",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"encodings",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_ENCODING'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"encodings",
"=",
"strtolower",
"(",
"trim",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_ENCODING'",
"]",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"encodings",
"=",
"''",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"encodings",
";",
"}"
] | Returns the encodings the client accepts.
from HTTP_ACCEPT_ENCODING
@return string | [
"Returns",
"the",
"encodings",
"the",
"client",
"accepts",
".",
"from",
"HTTP_ACCEPT_ENCODING"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/http/Request.php#L231-L242 | train |
byjg/serializer | src/BinderObject.php | BinderObject.toArrayFrom | public static function toArrayFrom($source, $firstLevel = false, $excludeClasses = [], $propertyPattern = null)
{
// Prepare the source object type
$object = new SerializerObject($source);
$object->setStopFirstLevel($firstLevel);
$object->setDoNotParse($excludeClasses);
if (!is_null($propertyPattern)) {
if (!is_array($propertyPattern)) {
throw new InvalidArgumentException(
'Property pattern must be an array with 2 regex elements (Search and Replace)'
);
}
$object->setMethodPattern($propertyPattern[0], $propertyPattern[1]);
}
return $object->build();
} | php | public static function toArrayFrom($source, $firstLevel = false, $excludeClasses = [], $propertyPattern = null)
{
// Prepare the source object type
$object = new SerializerObject($source);
$object->setStopFirstLevel($firstLevel);
$object->setDoNotParse($excludeClasses);
if (!is_null($propertyPattern)) {
if (!is_array($propertyPattern)) {
throw new InvalidArgumentException(
'Property pattern must be an array with 2 regex elements (Search and Replace)'
);
}
$object->setMethodPattern($propertyPattern[0], $propertyPattern[1]);
}
return $object->build();
} | [
"public",
"static",
"function",
"toArrayFrom",
"(",
"$",
"source",
",",
"$",
"firstLevel",
"=",
"false",
",",
"$",
"excludeClasses",
"=",
"[",
"]",
",",
"$",
"propertyPattern",
"=",
"null",
")",
"{",
"// Prepare the source object type",
"$",
"object",
"=",
"new",
"SerializerObject",
"(",
"$",
"source",
")",
";",
"$",
"object",
"->",
"setStopFirstLevel",
"(",
"$",
"firstLevel",
")",
";",
"$",
"object",
"->",
"setDoNotParse",
"(",
"$",
"excludeClasses",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"propertyPattern",
")",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"propertyPattern",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Property pattern must be an array with 2 regex elements (Search and Replace)'",
")",
";",
"}",
"$",
"object",
"->",
"setMethodPattern",
"(",
"$",
"propertyPattern",
"[",
"0",
"]",
",",
"$",
"propertyPattern",
"[",
"1",
"]",
")",
";",
"}",
"return",
"$",
"object",
"->",
"build",
"(",
")",
";",
"}"
] | Get all properties from a source object as an associative array
@param mixed $source
@param bool $firstLevel
@param array $excludeClasses
@param array|null $propertyPattern
@return array
@throws \ByJG\Serializer\Exception\InvalidArgumentException | [
"Get",
"all",
"properties",
"from",
"a",
"source",
"object",
"as",
"an",
"associative",
"array"
] | 035f9df69b3ad8af6fbe737da25d70d84b358f0f | https://github.com/byjg/serializer/blob/035f9df69b3ad8af6fbe737da25d70d84b358f0f/src/BinderObject.php#L78-L93 | train |
byjg/serializer | src/BinderObject.php | BinderObject.setPropValue | protected function setPropValue($obj, $propName, $value)
{
if (method_exists($obj, 'set' . $propName)) {
$obj->{'set' . $propName}($value);
} elseif (isset($obj->{$propName}) || $obj instanceof stdClass) {
$obj->{$propName} = $value;
} else {
// Check if source property have property case name different from target
$className = get_class($obj);
if (!isset($this->propNameLower[$className])) {
$this->propNameLower[$className] = [];
$classVars = get_class_vars($className);
foreach ($classVars as $varKey => $varValue) {
$this->propNameLower[$className][strtolower($varKey)] = $varKey;
}
}
$propLower = strtolower($propName);
if (isset($this->propNameLower[$className][$propLower])) {
$obj->{$this->propNameLower[$className][$propLower]} = $value;
}
}
} | php | protected function setPropValue($obj, $propName, $value)
{
if (method_exists($obj, 'set' . $propName)) {
$obj->{'set' . $propName}($value);
} elseif (isset($obj->{$propName}) || $obj instanceof stdClass) {
$obj->{$propName} = $value;
} else {
// Check if source property have property case name different from target
$className = get_class($obj);
if (!isset($this->propNameLower[$className])) {
$this->propNameLower[$className] = [];
$classVars = get_class_vars($className);
foreach ($classVars as $varKey => $varValue) {
$this->propNameLower[$className][strtolower($varKey)] = $varKey;
}
}
$propLower = strtolower($propName);
if (isset($this->propNameLower[$className][$propLower])) {
$obj->{$this->propNameLower[$className][$propLower]} = $value;
}
}
} | [
"protected",
"function",
"setPropValue",
"(",
"$",
"obj",
",",
"$",
"propName",
",",
"$",
"value",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"obj",
",",
"'set'",
".",
"$",
"propName",
")",
")",
"{",
"$",
"obj",
"->",
"{",
"'set'",
".",
"$",
"propName",
"}",
"(",
"$",
"value",
")",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"obj",
"->",
"{",
"$",
"propName",
"}",
")",
"||",
"$",
"obj",
"instanceof",
"stdClass",
")",
"{",
"$",
"obj",
"->",
"{",
"$",
"propName",
"}",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"// Check if source property have property case name different from target",
"$",
"className",
"=",
"get_class",
"(",
"$",
"obj",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"propNameLower",
"[",
"$",
"className",
"]",
")",
")",
"{",
"$",
"this",
"->",
"propNameLower",
"[",
"$",
"className",
"]",
"=",
"[",
"]",
";",
"$",
"classVars",
"=",
"get_class_vars",
"(",
"$",
"className",
")",
";",
"foreach",
"(",
"$",
"classVars",
"as",
"$",
"varKey",
"=>",
"$",
"varValue",
")",
"{",
"$",
"this",
"->",
"propNameLower",
"[",
"$",
"className",
"]",
"[",
"strtolower",
"(",
"$",
"varKey",
")",
"]",
"=",
"$",
"varKey",
";",
"}",
"}",
"$",
"propLower",
"=",
"strtolower",
"(",
"$",
"propName",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"propNameLower",
"[",
"$",
"className",
"]",
"[",
"$",
"propLower",
"]",
")",
")",
"{",
"$",
"obj",
"->",
"{",
"$",
"this",
"->",
"propNameLower",
"[",
"$",
"className",
"]",
"[",
"$",
"propLower",
"]",
"}",
"=",
"$",
"value",
";",
"}",
"}",
"}"
] | Set the property value
@param mixed $obj
@param string $propName
@param string $value | [
"Set",
"the",
"property",
"value"
] | 035f9df69b3ad8af6fbe737da25d70d84b358f0f | https://github.com/byjg/serializer/blob/035f9df69b3ad8af6fbe737da25d70d84b358f0f/src/BinderObject.php#L102-L125 | train |
zhaoxianfang/tools | src/Symfony/Component/Config/Util/XmlUtils.php | XmlUtils.convertDomElementToArray | public static function convertDomElementToArray(\DOMElement $element, $checkPrefix = true)
{
$prefix = (string) $element->prefix;
$empty = true;
$config = array();
foreach ($element->attributes as $name => $node) {
if ($checkPrefix && !in_array((string) $node->prefix, array('', $prefix), true)) {
continue;
}
$config[$name] = static::phpize($node->value);
$empty = false;
}
$nodeValue = false;
foreach ($element->childNodes as $node) {
if ($node instanceof \DOMText) {
if ('' !== trim($node->nodeValue)) {
$nodeValue = trim($node->nodeValue);
$empty = false;
}
} elseif ($checkPrefix && $prefix != (string) $node->prefix) {
continue;
} elseif (!$node instanceof \DOMComment) {
$value = static::convertDomElementToArray($node, $checkPrefix);
$key = $node->localName;
if (isset($config[$key])) {
if (!is_array($config[$key]) || !is_int(key($config[$key]))) {
$config[$key] = array($config[$key]);
}
$config[$key][] = $value;
} else {
$config[$key] = $value;
}
$empty = false;
}
}
if (false !== $nodeValue) {
$value = static::phpize($nodeValue);
if (count($config)) {
$config['value'] = $value;
} else {
$config = $value;
}
}
return !$empty ? $config : null;
} | php | public static function convertDomElementToArray(\DOMElement $element, $checkPrefix = true)
{
$prefix = (string) $element->prefix;
$empty = true;
$config = array();
foreach ($element->attributes as $name => $node) {
if ($checkPrefix && !in_array((string) $node->prefix, array('', $prefix), true)) {
continue;
}
$config[$name] = static::phpize($node->value);
$empty = false;
}
$nodeValue = false;
foreach ($element->childNodes as $node) {
if ($node instanceof \DOMText) {
if ('' !== trim($node->nodeValue)) {
$nodeValue = trim($node->nodeValue);
$empty = false;
}
} elseif ($checkPrefix && $prefix != (string) $node->prefix) {
continue;
} elseif (!$node instanceof \DOMComment) {
$value = static::convertDomElementToArray($node, $checkPrefix);
$key = $node->localName;
if (isset($config[$key])) {
if (!is_array($config[$key]) || !is_int(key($config[$key]))) {
$config[$key] = array($config[$key]);
}
$config[$key][] = $value;
} else {
$config[$key] = $value;
}
$empty = false;
}
}
if (false !== $nodeValue) {
$value = static::phpize($nodeValue);
if (count($config)) {
$config['value'] = $value;
} else {
$config = $value;
}
}
return !$empty ? $config : null;
} | [
"public",
"static",
"function",
"convertDomElementToArray",
"(",
"\\",
"DOMElement",
"$",
"element",
",",
"$",
"checkPrefix",
"=",
"true",
")",
"{",
"$",
"prefix",
"=",
"(",
"string",
")",
"$",
"element",
"->",
"prefix",
";",
"$",
"empty",
"=",
"true",
";",
"$",
"config",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"element",
"->",
"attributes",
"as",
"$",
"name",
"=>",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"checkPrefix",
"&&",
"!",
"in_array",
"(",
"(",
"string",
")",
"$",
"node",
"->",
"prefix",
",",
"array",
"(",
"''",
",",
"$",
"prefix",
")",
",",
"true",
")",
")",
"{",
"continue",
";",
"}",
"$",
"config",
"[",
"$",
"name",
"]",
"=",
"static",
"::",
"phpize",
"(",
"$",
"node",
"->",
"value",
")",
";",
"$",
"empty",
"=",
"false",
";",
"}",
"$",
"nodeValue",
"=",
"false",
";",
"foreach",
"(",
"$",
"element",
"->",
"childNodes",
"as",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"node",
"instanceof",
"\\",
"DOMText",
")",
"{",
"if",
"(",
"''",
"!==",
"trim",
"(",
"$",
"node",
"->",
"nodeValue",
")",
")",
"{",
"$",
"nodeValue",
"=",
"trim",
"(",
"$",
"node",
"->",
"nodeValue",
")",
";",
"$",
"empty",
"=",
"false",
";",
"}",
"}",
"elseif",
"(",
"$",
"checkPrefix",
"&&",
"$",
"prefix",
"!=",
"(",
"string",
")",
"$",
"node",
"->",
"prefix",
")",
"{",
"continue",
";",
"}",
"elseif",
"(",
"!",
"$",
"node",
"instanceof",
"\\",
"DOMComment",
")",
"{",
"$",
"value",
"=",
"static",
"::",
"convertDomElementToArray",
"(",
"$",
"node",
",",
"$",
"checkPrefix",
")",
";",
"$",
"key",
"=",
"$",
"node",
"->",
"localName",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"$",
"key",
"]",
")",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"config",
"[",
"$",
"key",
"]",
")",
"||",
"!",
"is_int",
"(",
"key",
"(",
"$",
"config",
"[",
"$",
"key",
"]",
")",
")",
")",
"{",
"$",
"config",
"[",
"$",
"key",
"]",
"=",
"array",
"(",
"$",
"config",
"[",
"$",
"key",
"]",
")",
";",
"}",
"$",
"config",
"[",
"$",
"key",
"]",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"config",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"$",
"empty",
"=",
"false",
";",
"}",
"}",
"if",
"(",
"false",
"!==",
"$",
"nodeValue",
")",
"{",
"$",
"value",
"=",
"static",
"::",
"phpize",
"(",
"$",
"nodeValue",
")",
";",
"if",
"(",
"count",
"(",
"$",
"config",
")",
")",
"{",
"$",
"config",
"[",
"'value'",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"config",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"!",
"$",
"empty",
"?",
"$",
"config",
":",
"null",
";",
"}"
] | Converts a \DOMElement object to a PHP array.
The following rules applies during the conversion:
* Each tag is converted to a key value or an array
if there is more than one "value"
* The content of a tag is set under a "value" key (<foo>bar</foo>)
if the tag also has some nested tags
* The attributes are converted to keys (<foo foo="bar"/>)
* The nested-tags are converted to keys (<foo><foo>bar</foo></foo>)
@param \DOMElement $element A \DOMElement instance
@param bool $checkPrefix Check prefix in an element or an attribute name
@return array A PHP array | [
"Converts",
"a",
"\\",
"DOMElement",
"object",
"to",
"a",
"PHP",
"array",
"."
] | d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7 | https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/Config/Util/XmlUtils.php#L157-L206 | train |
zhaoxianfang/tools | src/Symfony/Component/Config/Util/XmlUtils.php | XmlUtils.phpize | public static function phpize($value)
{
$value = (string) $value;
$lowercaseValue = strtolower($value);
switch (true) {
case 'null' === $lowercaseValue:
return;
case ctype_digit($value):
$raw = $value;
$cast = (int) $value;
return '0' == $value[0] ? octdec($value) : (((string) $raw === (string) $cast) ? $cast : $raw);
case isset($value[1]) && '-' === $value[0] && ctype_digit(substr($value, 1)):
$raw = $value;
$cast = (int) $value;
return '0' == $value[1] ? octdec($value) : (((string) $raw === (string) $cast) ? $cast : $raw);
case 'true' === $lowercaseValue:
return true;
case 'false' === $lowercaseValue:
return false;
case isset($value[1]) && '0b' == $value[0].$value[1]:
return bindec($value);
case is_numeric($value):
return '0x' === $value[0].$value[1] ? hexdec($value) : (float) $value;
case preg_match('/^0x[0-9a-f]++$/i', $value):
return hexdec($value);
case preg_match('/^(-|\+)?[0-9]+(\.[0-9]+)?$/', $value):
return (float) $value;
default:
return $value;
}
} | php | public static function phpize($value)
{
$value = (string) $value;
$lowercaseValue = strtolower($value);
switch (true) {
case 'null' === $lowercaseValue:
return;
case ctype_digit($value):
$raw = $value;
$cast = (int) $value;
return '0' == $value[0] ? octdec($value) : (((string) $raw === (string) $cast) ? $cast : $raw);
case isset($value[1]) && '-' === $value[0] && ctype_digit(substr($value, 1)):
$raw = $value;
$cast = (int) $value;
return '0' == $value[1] ? octdec($value) : (((string) $raw === (string) $cast) ? $cast : $raw);
case 'true' === $lowercaseValue:
return true;
case 'false' === $lowercaseValue:
return false;
case isset($value[1]) && '0b' == $value[0].$value[1]:
return bindec($value);
case is_numeric($value):
return '0x' === $value[0].$value[1] ? hexdec($value) : (float) $value;
case preg_match('/^0x[0-9a-f]++$/i', $value):
return hexdec($value);
case preg_match('/^(-|\+)?[0-9]+(\.[0-9]+)?$/', $value):
return (float) $value;
default:
return $value;
}
} | [
"public",
"static",
"function",
"phpize",
"(",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"(",
"string",
")",
"$",
"value",
";",
"$",
"lowercaseValue",
"=",
"strtolower",
"(",
"$",
"value",
")",
";",
"switch",
"(",
"true",
")",
"{",
"case",
"'null'",
"===",
"$",
"lowercaseValue",
":",
"return",
";",
"case",
"ctype_digit",
"(",
"$",
"value",
")",
":",
"$",
"raw",
"=",
"$",
"value",
";",
"$",
"cast",
"=",
"(",
"int",
")",
"$",
"value",
";",
"return",
"'0'",
"==",
"$",
"value",
"[",
"0",
"]",
"?",
"octdec",
"(",
"$",
"value",
")",
":",
"(",
"(",
"(",
"string",
")",
"$",
"raw",
"===",
"(",
"string",
")",
"$",
"cast",
")",
"?",
"$",
"cast",
":",
"$",
"raw",
")",
";",
"case",
"isset",
"(",
"$",
"value",
"[",
"1",
"]",
")",
"&&",
"'-'",
"===",
"$",
"value",
"[",
"0",
"]",
"&&",
"ctype_digit",
"(",
"substr",
"(",
"$",
"value",
",",
"1",
")",
")",
":",
"$",
"raw",
"=",
"$",
"value",
";",
"$",
"cast",
"=",
"(",
"int",
")",
"$",
"value",
";",
"return",
"'0'",
"==",
"$",
"value",
"[",
"1",
"]",
"?",
"octdec",
"(",
"$",
"value",
")",
":",
"(",
"(",
"(",
"string",
")",
"$",
"raw",
"===",
"(",
"string",
")",
"$",
"cast",
")",
"?",
"$",
"cast",
":",
"$",
"raw",
")",
";",
"case",
"'true'",
"===",
"$",
"lowercaseValue",
":",
"return",
"true",
";",
"case",
"'false'",
"===",
"$",
"lowercaseValue",
":",
"return",
"false",
";",
"case",
"isset",
"(",
"$",
"value",
"[",
"1",
"]",
")",
"&&",
"'0b'",
"==",
"$",
"value",
"[",
"0",
"]",
".",
"$",
"value",
"[",
"1",
"]",
":",
"return",
"bindec",
"(",
"$",
"value",
")",
";",
"case",
"is_numeric",
"(",
"$",
"value",
")",
":",
"return",
"'0x'",
"===",
"$",
"value",
"[",
"0",
"]",
".",
"$",
"value",
"[",
"1",
"]",
"?",
"hexdec",
"(",
"$",
"value",
")",
":",
"(",
"float",
")",
"$",
"value",
";",
"case",
"preg_match",
"(",
"'/^0x[0-9a-f]++$/i'",
",",
"$",
"value",
")",
":",
"return",
"hexdec",
"(",
"$",
"value",
")",
";",
"case",
"preg_match",
"(",
"'/^(-|\\+)?[0-9]+(\\.[0-9]+)?$/'",
",",
"$",
"value",
")",
":",
"return",
"(",
"float",
")",
"$",
"value",
";",
"default",
":",
"return",
"$",
"value",
";",
"}",
"}"
] | Converts an xml value to a PHP type.
@param mixed $value
@return mixed | [
"Converts",
"an",
"xml",
"value",
"to",
"a",
"PHP",
"type",
"."
] | d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7 | https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/Config/Util/XmlUtils.php#L215-L248 | train |
AltCtrlSupr/ACSPanel-Wordpress | Controller/WPSetupController.php | WPSetupController.indexAction | public function indexAction()
{
$em = $this->getDoctrine()->getManager();
//
// IF is admin can see all the hosts, if is user only their ones...
if (true === $this->get('security.context')->isGranted('ROLE_SUPER_ADMIN')) {
$entities = $em->getRepository('ACSACSPanelWordpressBundle:WPSetup')->findAll();
}elseif(true === $this->get('security.context')->isGranted('ROLE_RESELLER')){
$entities = $em->getRepository('ACSACSPanelWordpressBundle:WPSetup')->findByUsers($this->get('security.context')->getToken()->getUser()->getIdChildIds());
}elseif(true === $this->get('security.context')->isGranted('ROLE_USER')){
$entities = $em->getRepository('ACSACSPanelWordpressBundle:WPSetup')->findByUser($this->get('security.context')->getToken()->getUser());
}
$paginator = $this->get('knp_paginator');
$entities = $paginator->paginate(
$entities,
$this->get('request')->query->get('page', 1)/*page number*/
);
return $this->render('ACSACSPanelWordpressBundle:WPSetup:index.html.twig', array(
'entities' => $entities,
));
} | php | public function indexAction()
{
$em = $this->getDoctrine()->getManager();
//
// IF is admin can see all the hosts, if is user only their ones...
if (true === $this->get('security.context')->isGranted('ROLE_SUPER_ADMIN')) {
$entities = $em->getRepository('ACSACSPanelWordpressBundle:WPSetup')->findAll();
}elseif(true === $this->get('security.context')->isGranted('ROLE_RESELLER')){
$entities = $em->getRepository('ACSACSPanelWordpressBundle:WPSetup')->findByUsers($this->get('security.context')->getToken()->getUser()->getIdChildIds());
}elseif(true === $this->get('security.context')->isGranted('ROLE_USER')){
$entities = $em->getRepository('ACSACSPanelWordpressBundle:WPSetup')->findByUser($this->get('security.context')->getToken()->getUser());
}
$paginator = $this->get('knp_paginator');
$entities = $paginator->paginate(
$entities,
$this->get('request')->query->get('page', 1)/*page number*/
);
return $this->render('ACSACSPanelWordpressBundle:WPSetup:index.html.twig', array(
'entities' => $entities,
));
} | [
"public",
"function",
"indexAction",
"(",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"//",
"// IF is admin can see all the hosts, if is user only their ones...",
"if",
"(",
"true",
"===",
"$",
"this",
"->",
"get",
"(",
"'security.context'",
")",
"->",
"isGranted",
"(",
"'ROLE_SUPER_ADMIN'",
")",
")",
"{",
"$",
"entities",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"'ACSACSPanelWordpressBundle:WPSetup'",
")",
"->",
"findAll",
"(",
")",
";",
"}",
"elseif",
"(",
"true",
"===",
"$",
"this",
"->",
"get",
"(",
"'security.context'",
")",
"->",
"isGranted",
"(",
"'ROLE_RESELLER'",
")",
")",
"{",
"$",
"entities",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"'ACSACSPanelWordpressBundle:WPSetup'",
")",
"->",
"findByUsers",
"(",
"$",
"this",
"->",
"get",
"(",
"'security.context'",
")",
"->",
"getToken",
"(",
")",
"->",
"getUser",
"(",
")",
"->",
"getIdChildIds",
"(",
")",
")",
";",
"}",
"elseif",
"(",
"true",
"===",
"$",
"this",
"->",
"get",
"(",
"'security.context'",
")",
"->",
"isGranted",
"(",
"'ROLE_USER'",
")",
")",
"{",
"$",
"entities",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"'ACSACSPanelWordpressBundle:WPSetup'",
")",
"->",
"findByUser",
"(",
"$",
"this",
"->",
"get",
"(",
"'security.context'",
")",
"->",
"getToken",
"(",
")",
"->",
"getUser",
"(",
")",
")",
";",
"}",
"$",
"paginator",
"=",
"$",
"this",
"->",
"get",
"(",
"'knp_paginator'",
")",
";",
"$",
"entities",
"=",
"$",
"paginator",
"->",
"paginate",
"(",
"$",
"entities",
",",
"$",
"this",
"->",
"get",
"(",
"'request'",
")",
"->",
"query",
"->",
"get",
"(",
"'page'",
",",
"1",
")",
"/*page number*/",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'ACSACSPanelWordpressBundle:WPSetup:index.html.twig'",
",",
"array",
"(",
"'entities'",
"=>",
"$",
"entities",
",",
")",
")",
";",
"}"
] | Lists all WPSetup entities. | [
"Lists",
"all",
"WPSetup",
"entities",
"."
] | b8d1daff071d8dd51afa24813162b37548610041 | https://github.com/AltCtrlSupr/ACSPanel-Wordpress/blob/b8d1daff071d8dd51afa24813162b37548610041/Controller/WPSetupController.php#L25-L47 | train |
AltCtrlSupr/ACSPanel-Wordpress | Controller/WPSetupController.php | WPSetupController.newAction | public function newAction()
{
$entity = new WPSetup();
$form = $this->createForm(new WPSetupType($this->container), $entity);
return $this->render('ACSACSPanelWordpressBundle:WPSetup:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
} | php | public function newAction()
{
$entity = new WPSetup();
$form = $this->createForm(new WPSetupType($this->container), $entity);
return $this->render('ACSACSPanelWordpressBundle:WPSetup:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
} | [
"public",
"function",
"newAction",
"(",
")",
"{",
"$",
"entity",
"=",
"new",
"WPSetup",
"(",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"WPSetupType",
"(",
"$",
"this",
"->",
"container",
")",
",",
"$",
"entity",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'ACSACSPanelWordpressBundle:WPSetup:new.html.twig'",
",",
"array",
"(",
"'entity'",
"=>",
"$",
"entity",
",",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
")",
")",
";",
"}"
] | Displays a form to create a new WPSetup entity. | [
"Displays",
"a",
"form",
"to",
"create",
"a",
"new",
"WPSetup",
"entity",
"."
] | b8d1daff071d8dd51afa24813162b37548610041 | https://github.com/AltCtrlSupr/ACSPanel-Wordpress/blob/b8d1daff071d8dd51afa24813162b37548610041/Controller/WPSetupController.php#L74-L83 | train |
AltCtrlSupr/ACSPanel-Wordpress | Controller/WPSetupController.php | WPSetupController.createAction | public function createAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$entity = new WPSetup();
$form = $this->createForm(new WPSetupType($this->container), $entity);
$form->bind($request);
if ($form->isValid()) {
$user = $this->get('security.context')->getToken()->getUser();
$domain = $form['domain']->getData();
if(isset($form['user']))
$domain->setUser($form['user']->getData());
$em->persist($domain);
$httpdhost = new HttpdHost();
$httpdhost->setDomain($domain);
// Add open_basedir wordpress directory
$configuration = "
<Directory '/home/$user/web/$domain/httpdocs'>
php_admin_value open_basedir '/home/$user/web/$domain:/srv/httpd/error:/tmp:/var/www/source'
</Directory>";
$httpdhost->setConfiguration($configuration);
$em->persist($httpdhost);
$validator = $this->get('validator');
// Add database and user
$wpdb = new DB();
$wpdb->setName($user->getUsername().'_wp_'.$httpdhost->getId());
$em->persist($wpdb);
$dbuser = new DatabaseUser();
$dbuser->setUsername($user->getId().'_wp_'.$httpdhost->getId());
$dbuser->setDb($wpdb);
$dbuser->setPassword('');
$em->persist($dbuser);
$entity->setHttpdHost($httpdhost);
$entity->setDatabaseUser($dbuser);
$entity->setEnabled(true);
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('wpsetup_show', array('id' => $entity->getId())));
}
return $this->render('ACSACSPanelWordpressBundle:WPSetup:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
} | php | public function createAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$entity = new WPSetup();
$form = $this->createForm(new WPSetupType($this->container), $entity);
$form->bind($request);
if ($form->isValid()) {
$user = $this->get('security.context')->getToken()->getUser();
$domain = $form['domain']->getData();
if(isset($form['user']))
$domain->setUser($form['user']->getData());
$em->persist($domain);
$httpdhost = new HttpdHost();
$httpdhost->setDomain($domain);
// Add open_basedir wordpress directory
$configuration = "
<Directory '/home/$user/web/$domain/httpdocs'>
php_admin_value open_basedir '/home/$user/web/$domain:/srv/httpd/error:/tmp:/var/www/source'
</Directory>";
$httpdhost->setConfiguration($configuration);
$em->persist($httpdhost);
$validator = $this->get('validator');
// Add database and user
$wpdb = new DB();
$wpdb->setName($user->getUsername().'_wp_'.$httpdhost->getId());
$em->persist($wpdb);
$dbuser = new DatabaseUser();
$dbuser->setUsername($user->getId().'_wp_'.$httpdhost->getId());
$dbuser->setDb($wpdb);
$dbuser->setPassword('');
$em->persist($dbuser);
$entity->setHttpdHost($httpdhost);
$entity->setDatabaseUser($dbuser);
$entity->setEnabled(true);
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('wpsetup_show', array('id' => $entity->getId())));
}
return $this->render('ACSACSPanelWordpressBundle:WPSetup:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
} | [
"public",
"function",
"createAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"entity",
"=",
"new",
"WPSetup",
"(",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"WPSetupType",
"(",
"$",
"this",
"->",
"container",
")",
",",
"$",
"entity",
")",
";",
"$",
"form",
"->",
"bind",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"form",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"get",
"(",
"'security.context'",
")",
"->",
"getToken",
"(",
")",
"->",
"getUser",
"(",
")",
";",
"$",
"domain",
"=",
"$",
"form",
"[",
"'domain'",
"]",
"->",
"getData",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"form",
"[",
"'user'",
"]",
")",
")",
"$",
"domain",
"->",
"setUser",
"(",
"$",
"form",
"[",
"'user'",
"]",
"->",
"getData",
"(",
")",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"domain",
")",
";",
"$",
"httpdhost",
"=",
"new",
"HttpdHost",
"(",
")",
";",
"$",
"httpdhost",
"->",
"setDomain",
"(",
"$",
"domain",
")",
";",
"// Add open_basedir wordpress directory",
"$",
"configuration",
"=",
"\"\n <Directory '/home/$user/web/$domain/httpdocs'>\n php_admin_value open_basedir '/home/$user/web/$domain:/srv/httpd/error:/tmp:/var/www/source'\n </Directory>\"",
";",
"$",
"httpdhost",
"->",
"setConfiguration",
"(",
"$",
"configuration",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"httpdhost",
")",
";",
"$",
"validator",
"=",
"$",
"this",
"->",
"get",
"(",
"'validator'",
")",
";",
"// Add database and user",
"$",
"wpdb",
"=",
"new",
"DB",
"(",
")",
";",
"$",
"wpdb",
"->",
"setName",
"(",
"$",
"user",
"->",
"getUsername",
"(",
")",
".",
"'_wp_'",
".",
"$",
"httpdhost",
"->",
"getId",
"(",
")",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"wpdb",
")",
";",
"$",
"dbuser",
"=",
"new",
"DatabaseUser",
"(",
")",
";",
"$",
"dbuser",
"->",
"setUsername",
"(",
"$",
"user",
"->",
"getId",
"(",
")",
".",
"'_wp_'",
".",
"$",
"httpdhost",
"->",
"getId",
"(",
")",
")",
";",
"$",
"dbuser",
"->",
"setDb",
"(",
"$",
"wpdb",
")",
";",
"$",
"dbuser",
"->",
"setPassword",
"(",
"''",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"dbuser",
")",
";",
"$",
"entity",
"->",
"setHttpdHost",
"(",
"$",
"httpdhost",
")",
";",
"$",
"entity",
"->",
"setDatabaseUser",
"(",
"$",
"dbuser",
")",
";",
"$",
"entity",
"->",
"setEnabled",
"(",
"true",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"entity",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'wpsetup_show'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"entity",
"->",
"getId",
"(",
")",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'ACSACSPanelWordpressBundle:WPSetup:new.html.twig'",
",",
"array",
"(",
"'entity'",
"=>",
"$",
"entity",
",",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
")",
")",
";",
"}"
] | Creates a new WPSetup entity. | [
"Creates",
"a",
"new",
"WPSetup",
"entity",
"."
] | b8d1daff071d8dd51afa24813162b37548610041 | https://github.com/AltCtrlSupr/ACSPanel-Wordpress/blob/b8d1daff071d8dd51afa24813162b37548610041/Controller/WPSetupController.php#L89-L144 | train |
AltCtrlSupr/ACSPanel-Wordpress | Controller/WPSetupController.php | WPSetupController.editAction | public function editAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ACSACSPanelWordpressBundle:WPSetup')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find WPSetup entity.');
}
$editForm = $this->createForm(new WPSetupType($this->container), $entity);
$deleteForm = $this->createDeleteForm($id);
return $this->render('ACSACSPanelWordpressBundle:WPSetup:edit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
} | php | public function editAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ACSACSPanelWordpressBundle:WPSetup')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find WPSetup entity.');
}
$editForm = $this->createForm(new WPSetupType($this->container), $entity);
$deleteForm = $this->createDeleteForm($id);
return $this->render('ACSACSPanelWordpressBundle:WPSetup:edit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
} | [
"public",
"function",
"editAction",
"(",
"$",
"id",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"entity",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"'ACSACSPanelWordpressBundle:WPSetup'",
")",
"->",
"find",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"entity",
")",
"{",
"throw",
"$",
"this",
"->",
"createNotFoundException",
"(",
"'Unable to find WPSetup entity.'",
")",
";",
"}",
"$",
"editForm",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"WPSetupType",
"(",
"$",
"this",
"->",
"container",
")",
",",
"$",
"entity",
")",
";",
"$",
"deleteForm",
"=",
"$",
"this",
"->",
"createDeleteForm",
"(",
"$",
"id",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'ACSACSPanelWordpressBundle:WPSetup:edit.html.twig'",
",",
"array",
"(",
"'entity'",
"=>",
"$",
"entity",
",",
"'edit_form'",
"=>",
"$",
"editForm",
"->",
"createView",
"(",
")",
",",
"'delete_form'",
"=>",
"$",
"deleteForm",
"->",
"createView",
"(",
")",
",",
")",
")",
";",
"}"
] | Displays a form to edit an existing WPSetup entity. | [
"Displays",
"a",
"form",
"to",
"edit",
"an",
"existing",
"WPSetup",
"entity",
"."
] | b8d1daff071d8dd51afa24813162b37548610041 | https://github.com/AltCtrlSupr/ACSPanel-Wordpress/blob/b8d1daff071d8dd51afa24813162b37548610041/Controller/WPSetupController.php#L150-L168 | train |
AltCtrlSupr/ACSPanel-Wordpress | Controller/WPSetupController.php | WPSetupController.updateAction | public function updateAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ACSACSPanelWordpressBundle:WPSetup')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find WPSetup entity.');
}
$deleteForm = $this->createDeleteForm($id);
$editForm = $this->createForm(new WPSetupType($this->container), $entity);
$editForm->bind($request);
if ($editForm->isValid()) {
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('wpsetup_edit', array('id' => $id)));
}
return $this->render('ACSACSPanelWordpressBundle:WPSetup:edit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
} | php | public function updateAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ACSACSPanelWordpressBundle:WPSetup')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find WPSetup entity.');
}
$deleteForm = $this->createDeleteForm($id);
$editForm = $this->createForm(new WPSetupType($this->container), $entity);
$editForm->bind($request);
if ($editForm->isValid()) {
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('wpsetup_edit', array('id' => $id)));
}
return $this->render('ACSACSPanelWordpressBundle:WPSetup:edit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
} | [
"public",
"function",
"updateAction",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"entity",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"'ACSACSPanelWordpressBundle:WPSetup'",
")",
"->",
"find",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"entity",
")",
"{",
"throw",
"$",
"this",
"->",
"createNotFoundException",
"(",
"'Unable to find WPSetup entity.'",
")",
";",
"}",
"$",
"deleteForm",
"=",
"$",
"this",
"->",
"createDeleteForm",
"(",
"$",
"id",
")",
";",
"$",
"editForm",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"WPSetupType",
"(",
"$",
"this",
"->",
"container",
")",
",",
"$",
"entity",
")",
";",
"$",
"editForm",
"->",
"bind",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"editForm",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"em",
"->",
"persist",
"(",
"$",
"entity",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'wpsetup_edit'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"id",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'ACSACSPanelWordpressBundle:WPSetup:edit.html.twig'",
",",
"array",
"(",
"'entity'",
"=>",
"$",
"entity",
",",
"'edit_form'",
"=>",
"$",
"editForm",
"->",
"createView",
"(",
")",
",",
"'delete_form'",
"=>",
"$",
"deleteForm",
"->",
"createView",
"(",
")",
",",
")",
")",
";",
"}"
] | Edits an existing WPSetup entity. | [
"Edits",
"an",
"existing",
"WPSetup",
"entity",
"."
] | b8d1daff071d8dd51afa24813162b37548610041 | https://github.com/AltCtrlSupr/ACSPanel-Wordpress/blob/b8d1daff071d8dd51afa24813162b37548610041/Controller/WPSetupController.php#L174-L200 | train |
aztech-digital/phinject | src/ParameterContainer.php | ParameterContainer.validateParameter | protected function validateParameter($key, $value)
{
if ($this->isSafeValue($value)) {
return true;
}
$this->enforceNonObjectValue($key, $value);
$this->enforceMultidimensionalArrayOfScalars($key, $value);
return true;
} | php | protected function validateParameter($key, $value)
{
if ($this->isSafeValue($value)) {
return true;
}
$this->enforceNonObjectValue($key, $value);
$this->enforceMultidimensionalArrayOfScalars($key, $value);
return true;
} | [
"protected",
"function",
"validateParameter",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isSafeValue",
"(",
"$",
"value",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"enforceNonObjectValue",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"$",
"this",
"->",
"enforceMultidimensionalArrayOfScalars",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"return",
"true",
";",
"}"
] | Check that the value to bind is a scalar, or an array multi-dimensional of scalars
@param string $key
@param mixed $value
@return boolean
@throws IllegalTypeException | [
"Check",
"that",
"the",
"value",
"to",
"bind",
"is",
"a",
"scalar",
"or",
"an",
"array",
"multi",
"-",
"dimensional",
"of",
"scalars"
] | 1bb2fb3b5ef44e62f168af71134c613c48b58d95 | https://github.com/aztech-digital/phinject/blob/1bb2fb3b5ef44e62f168af71134c613c48b58d95/src/ParameterContainer.php#L112-L122 | train |
nails/module-geo-ip | src/Service/GeoIp.php | GeoIp.getDriverInstance | public function getDriverInstance($sSlug = null)
{
$oDriverService = Factory::service('Driver', 'nails/module-geo-ip');
$sEnabledDriver = appSetting($oDriverService->getSettingKey(), 'nails/module-geo-ip');
$oEnabledDriver = $oDriverService->getEnabled();
if (empty($sEnabledDriver) && empty($oEnabledDriver)) {
// No configured driver, default to first available driver and hope for the best
$aDrivers = $oDriverService->getAll();
$oEnabledDriver = reset($aDrivers);
}
if (empty($sEnabledDriver) && empty($oEnabledDriver)) {
throw new GeoIpDriverException('No Geo-IP drivers are available.');
} elseif (empty($oEnabledDriver)) {
throw new GeoIpDriverException('Driver "' . $sEnabledDriver . '" is not installed');
}
$oDriver = $oDriverService->getInstance($oEnabledDriver->slug);
// Ensure driver implements the correct interface
$sInterfaceName = 'Nails\GeoIp\Interfaces\Driver';
if (!classImplements($oDriver, $sInterfaceName)) {
throw new GeoIpDriverException(
'"' . get_class($oDriver) . '" must implement "' . $sInterfaceName . '"'
);
}
return $oDriver;
} | php | public function getDriverInstance($sSlug = null)
{
$oDriverService = Factory::service('Driver', 'nails/module-geo-ip');
$sEnabledDriver = appSetting($oDriverService->getSettingKey(), 'nails/module-geo-ip');
$oEnabledDriver = $oDriverService->getEnabled();
if (empty($sEnabledDriver) && empty($oEnabledDriver)) {
// No configured driver, default to first available driver and hope for the best
$aDrivers = $oDriverService->getAll();
$oEnabledDriver = reset($aDrivers);
}
if (empty($sEnabledDriver) && empty($oEnabledDriver)) {
throw new GeoIpDriverException('No Geo-IP drivers are available.');
} elseif (empty($oEnabledDriver)) {
throw new GeoIpDriverException('Driver "' . $sEnabledDriver . '" is not installed');
}
$oDriver = $oDriverService->getInstance($oEnabledDriver->slug);
// Ensure driver implements the correct interface
$sInterfaceName = 'Nails\GeoIp\Interfaces\Driver';
if (!classImplements($oDriver, $sInterfaceName)) {
throw new GeoIpDriverException(
'"' . get_class($oDriver) . '" must implement "' . $sInterfaceName . '"'
);
}
return $oDriver;
} | [
"public",
"function",
"getDriverInstance",
"(",
"$",
"sSlug",
"=",
"null",
")",
"{",
"$",
"oDriverService",
"=",
"Factory",
"::",
"service",
"(",
"'Driver'",
",",
"'nails/module-geo-ip'",
")",
";",
"$",
"sEnabledDriver",
"=",
"appSetting",
"(",
"$",
"oDriverService",
"->",
"getSettingKey",
"(",
")",
",",
"'nails/module-geo-ip'",
")",
";",
"$",
"oEnabledDriver",
"=",
"$",
"oDriverService",
"->",
"getEnabled",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"sEnabledDriver",
")",
"&&",
"empty",
"(",
"$",
"oEnabledDriver",
")",
")",
"{",
"// No configured driver, default to first available driver and hope for the best",
"$",
"aDrivers",
"=",
"$",
"oDriverService",
"->",
"getAll",
"(",
")",
";",
"$",
"oEnabledDriver",
"=",
"reset",
"(",
"$",
"aDrivers",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"sEnabledDriver",
")",
"&&",
"empty",
"(",
"$",
"oEnabledDriver",
")",
")",
"{",
"throw",
"new",
"GeoIpDriverException",
"(",
"'No Geo-IP drivers are available.'",
")",
";",
"}",
"elseif",
"(",
"empty",
"(",
"$",
"oEnabledDriver",
")",
")",
"{",
"throw",
"new",
"GeoIpDriverException",
"(",
"'Driver \"'",
".",
"$",
"sEnabledDriver",
".",
"'\" is not installed'",
")",
";",
"}",
"$",
"oDriver",
"=",
"$",
"oDriverService",
"->",
"getInstance",
"(",
"$",
"oEnabledDriver",
"->",
"slug",
")",
";",
"// Ensure driver implements the correct interface",
"$",
"sInterfaceName",
"=",
"'Nails\\GeoIp\\Interfaces\\Driver'",
";",
"if",
"(",
"!",
"classImplements",
"(",
"$",
"oDriver",
",",
"$",
"sInterfaceName",
")",
")",
"{",
"throw",
"new",
"GeoIpDriverException",
"(",
"'\"'",
".",
"get_class",
"(",
"$",
"oDriver",
")",
".",
"'\" must implement \"'",
".",
"$",
"sInterfaceName",
".",
"'\"'",
")",
";",
"}",
"return",
"$",
"oDriver",
";",
"}"
] | Returns an instance of the driver
@param string $sSlug The driver's slug
@throws GeoIpDriverException
@return \Nails\GeoIp\Interfaces\Driver | [
"Returns",
"an",
"instance",
"of",
"the",
"driver"
] | 1c73513e18ae490c37d4e5f5fddd071c95d850ce | https://github.com/nails/module-geo-ip/blob/1c73513e18ae490c37d4e5f5fddd071c95d850ce/src/Service/GeoIp.php#L54-L83 | train |
nails/module-geo-ip | src/Service/GeoIp.php | GeoIp.lookup | public function lookup($sIp = '')
{
$sIp = trim($sIp);
if (empty($sIp) && !empty($_SERVER['REMOTE_ADDR'])) {
$sIp = $_SERVER['REMOTE_ADDR'];
}
$oCache = $this->getCache($sIp);
if (!empty($oCache)) {
return $oCache;
}
$oIp = $this->oDriver->lookup($sIp);
if (!($oIp instanceof Ip)) {
throw new GeoIpException('Geo IP Driver did not return a \Nails\GeoIp\Result\Ip result');
}
$this->setCache($sIp, $oIp);
return $oIp;
} | php | public function lookup($sIp = '')
{
$sIp = trim($sIp);
if (empty($sIp) && !empty($_SERVER['REMOTE_ADDR'])) {
$sIp = $_SERVER['REMOTE_ADDR'];
}
$oCache = $this->getCache($sIp);
if (!empty($oCache)) {
return $oCache;
}
$oIp = $this->oDriver->lookup($sIp);
if (!($oIp instanceof Ip)) {
throw new GeoIpException('Geo IP Driver did not return a \Nails\GeoIp\Result\Ip result');
}
$this->setCache($sIp, $oIp);
return $oIp;
} | [
"public",
"function",
"lookup",
"(",
"$",
"sIp",
"=",
"''",
")",
"{",
"$",
"sIp",
"=",
"trim",
"(",
"$",
"sIp",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"sIp",
")",
"&&",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'REMOTE_ADDR'",
"]",
")",
")",
"{",
"$",
"sIp",
"=",
"$",
"_SERVER",
"[",
"'REMOTE_ADDR'",
"]",
";",
"}",
"$",
"oCache",
"=",
"$",
"this",
"->",
"getCache",
"(",
"$",
"sIp",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"oCache",
")",
")",
"{",
"return",
"$",
"oCache",
";",
"}",
"$",
"oIp",
"=",
"$",
"this",
"->",
"oDriver",
"->",
"lookup",
"(",
"$",
"sIp",
")",
";",
"if",
"(",
"!",
"(",
"$",
"oIp",
"instanceof",
"Ip",
")",
")",
"{",
"throw",
"new",
"GeoIpException",
"(",
"'Geo IP Driver did not return a \\Nails\\GeoIp\\Result\\Ip result'",
")",
";",
"}",
"$",
"this",
"->",
"setCache",
"(",
"$",
"sIp",
",",
"$",
"oIp",
")",
";",
"return",
"$",
"oIp",
";",
"}"
] | Return all information about a given IP
@param string $sIp The IP to get details for
@throws GeoIpException
@return \Nails\GeoIp\Result\Ip | [
"Return",
"all",
"information",
"about",
"a",
"given",
"IP"
] | 1c73513e18ae490c37d4e5f5fddd071c95d850ce | https://github.com/nails/module-geo-ip/blob/1c73513e18ae490c37d4e5f5fddd071c95d850ce/src/Service/GeoIp.php#L95-L118 | train |
phpgears/event | src/Time/FixedTimeProvider.php | FixedTimeProvider.setCurrentTime | public function setCurrentTime(\DateTimeImmutable $fixedTime): void
{
$this->fixedTime = $fixedTime->setTimezone($this->timeZone);
} | php | public function setCurrentTime(\DateTimeImmutable $fixedTime): void
{
$this->fixedTime = $fixedTime->setTimezone($this->timeZone);
} | [
"public",
"function",
"setCurrentTime",
"(",
"\\",
"DateTimeImmutable",
"$",
"fixedTime",
")",
":",
"void",
"{",
"$",
"this",
"->",
"fixedTime",
"=",
"$",
"fixedTime",
"->",
"setTimezone",
"(",
"$",
"this",
"->",
"timeZone",
")",
";",
"}"
] | Set fixed date.
@param \DateTimeImmutable $fixedTime | [
"Set",
"fixed",
"date",
"."
] | 9b25301837748a67b3b48cc46ad837c859c4522d | https://github.com/phpgears/event/blob/9b25301837748a67b3b48cc46ad837c859c4522d/src/Time/FixedTimeProvider.php#L50-L53 | train |
eureka-framework/component-config | src/Config/Config.php | Config.load | public function load($file, $namespace = '', $parser = null, $env = null)
{
$config = [];
$this->currentFile = $file;
//~ Check in cache
if (is_object($this->cache)) {
$config = $this->cache->get('Eureka.Component.Config.Test.' . $env . '.' . md5($file) . '.cache');
}
//~ If not in cache or cache object not defined
if (empty($config)) {
if (!file_exists($file)) {
throw new \Exception('Configuration file does not exists !');
}
$config = $parser->load($file);
if ($env !== null) {
$configTmp = [];
//~ Firstable, pick section 'all' from config if section exists.
if (isset($config['all']) && is_array($config['all'])) {
$configTmp = $config['all'];
}
//~ Secondly, merge recursively with section corresponding with environment if section exists.
if (isset($config[$env]) && is_array($config[$env])) {
$configTmp = array_replace_recursive($configTmp, $config[$env]);
}
//~ Set merged configurations into main array.
$config = $configTmp;
}
if (is_object($this->cache)) {
$this->cache->set('Eureka.Component.Config.Test.' . $env . '.' . md5($file) . '.cache', $config);
}
}
$this->add($namespace, $config);
$this->currentFile = '';
return $this;
} | php | public function load($file, $namespace = '', $parser = null, $env = null)
{
$config = [];
$this->currentFile = $file;
//~ Check in cache
if (is_object($this->cache)) {
$config = $this->cache->get('Eureka.Component.Config.Test.' . $env . '.' . md5($file) . '.cache');
}
//~ If not in cache or cache object not defined
if (empty($config)) {
if (!file_exists($file)) {
throw new \Exception('Configuration file does not exists !');
}
$config = $parser->load($file);
if ($env !== null) {
$configTmp = [];
//~ Firstable, pick section 'all' from config if section exists.
if (isset($config['all']) && is_array($config['all'])) {
$configTmp = $config['all'];
}
//~ Secondly, merge recursively with section corresponding with environment if section exists.
if (isset($config[$env]) && is_array($config[$env])) {
$configTmp = array_replace_recursive($configTmp, $config[$env]);
}
//~ Set merged configurations into main array.
$config = $configTmp;
}
if (is_object($this->cache)) {
$this->cache->set('Eureka.Component.Config.Test.' . $env . '.' . md5($file) . '.cache', $config);
}
}
$this->add($namespace, $config);
$this->currentFile = '';
return $this;
} | [
"public",
"function",
"load",
"(",
"$",
"file",
",",
"$",
"namespace",
"=",
"''",
",",
"$",
"parser",
"=",
"null",
",",
"$",
"env",
"=",
"null",
")",
"{",
"$",
"config",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"currentFile",
"=",
"$",
"file",
";",
"//~ Check in cache",
"if",
"(",
"is_object",
"(",
"$",
"this",
"->",
"cache",
")",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"cache",
"->",
"get",
"(",
"'Eureka.Component.Config.Test.'",
".",
"$",
"env",
".",
"'.'",
".",
"md5",
"(",
"$",
"file",
")",
".",
"'.cache'",
")",
";",
"}",
"//~ If not in cache or cache object not defined",
"if",
"(",
"empty",
"(",
"$",
"config",
")",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Configuration file does not exists !'",
")",
";",
"}",
"$",
"config",
"=",
"$",
"parser",
"->",
"load",
"(",
"$",
"file",
")",
";",
"if",
"(",
"$",
"env",
"!==",
"null",
")",
"{",
"$",
"configTmp",
"=",
"[",
"]",
";",
"//~ Firstable, pick section 'all' from config if section exists.",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'all'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"config",
"[",
"'all'",
"]",
")",
")",
"{",
"$",
"configTmp",
"=",
"$",
"config",
"[",
"'all'",
"]",
";",
"}",
"//~ Secondly, merge recursively with section corresponding with environment if section exists.",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"$",
"env",
"]",
")",
"&&",
"is_array",
"(",
"$",
"config",
"[",
"$",
"env",
"]",
")",
")",
"{",
"$",
"configTmp",
"=",
"array_replace_recursive",
"(",
"$",
"configTmp",
",",
"$",
"config",
"[",
"$",
"env",
"]",
")",
";",
"}",
"//~ Set merged configurations into main array.",
"$",
"config",
"=",
"$",
"configTmp",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"this",
"->",
"cache",
")",
")",
"{",
"$",
"this",
"->",
"cache",
"->",
"set",
"(",
"'Eureka.Component.Config.Test.'",
".",
"$",
"env",
".",
"'.'",
".",
"md5",
"(",
"$",
"file",
")",
".",
"'.cache'",
",",
"$",
"config",
")",
";",
"}",
"}",
"$",
"this",
"->",
"add",
"(",
"$",
"namespace",
",",
"$",
"config",
")",
";",
"$",
"this",
"->",
"currentFile",
"=",
"''",
";",
"return",
"$",
"this",
";",
"}"
] | Get config value for config var specified.
@param string $file
@param string $namespace
@param object $parser File parser
@param string $env
@return $this
@throws \Exception | [
"Get",
"config",
"value",
"for",
"config",
"var",
"specified",
"."
] | ae3f17683fb3e96641b65375c6cca6a3139ae85e | https://github.com/eureka-framework/component-config/blob/ae3f17683fb3e96641b65375c6cca6a3139ae85e/src/Config/Config.php#L294-L341 | train |
eureka-framework/component-config | src/Config/Config.php | Config.loadYamlFromDirectory | public function loadYamlFromDirectory($directory, $namespace = 'global.', $environment = null)
{
if ($environment === null) {
$environment = $this->environment;
}
foreach (glob($directory . '/*.yml') as $filename) {
$this->load($filename, $namespace . basename($filename, '.yml'), new Yaml(), $environment);
}
return $this;
} | php | public function loadYamlFromDirectory($directory, $namespace = 'global.', $environment = null)
{
if ($environment === null) {
$environment = $this->environment;
}
foreach (glob($directory . '/*.yml') as $filename) {
$this->load($filename, $namespace . basename($filename, '.yml'), new Yaml(), $environment);
}
return $this;
} | [
"public",
"function",
"loadYamlFromDirectory",
"(",
"$",
"directory",
",",
"$",
"namespace",
"=",
"'global.'",
",",
"$",
"environment",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"environment",
"===",
"null",
")",
"{",
"$",
"environment",
"=",
"$",
"this",
"->",
"environment",
";",
"}",
"foreach",
"(",
"glob",
"(",
"$",
"directory",
".",
"'/*.yml'",
")",
"as",
"$",
"filename",
")",
"{",
"$",
"this",
"->",
"load",
"(",
"$",
"filename",
",",
"$",
"namespace",
".",
"basename",
"(",
"$",
"filename",
",",
"'.yml'",
")",
",",
"new",
"Yaml",
"(",
")",
",",
"$",
"environment",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Load yaml files froem given directory.
@param string $directory
@param string $namespace
@param null|string $environment
@return $this | [
"Load",
"yaml",
"files",
"froem",
"given",
"directory",
"."
] | ae3f17683fb3e96641b65375c6cca6a3139ae85e | https://github.com/eureka-framework/component-config/blob/ae3f17683fb3e96641b65375c6cca6a3139ae85e/src/Config/Config.php#L351-L362 | train |
eureka-framework/component-config | src/Config/Config.php | Config.replaceReferences | private function replaceReferences(array &$config)
{
foreach ($config as $key => &$value) {
if (is_array($value)) {
$this->replaceReferences($value);
continue;
}
//~ Not string, skip
if (!is_string($value)) {
continue;
}
//~ Value not %my.reference.config%, skip
if (!(bool) preg_match('`%(.*?)%`', $value, $matches)) {
continue;
}
$referenceValue = $this->get($matches[1]);
if ($referenceValue !== null) {
$value = $referenceValue;
}
}
} | php | private function replaceReferences(array &$config)
{
foreach ($config as $key => &$value) {
if (is_array($value)) {
$this->replaceReferences($value);
continue;
}
//~ Not string, skip
if (!is_string($value)) {
continue;
}
//~ Value not %my.reference.config%, skip
if (!(bool) preg_match('`%(.*?)%`', $value, $matches)) {
continue;
}
$referenceValue = $this->get($matches[1]);
if ($referenceValue !== null) {
$value = $referenceValue;
}
}
} | [
"private",
"function",
"replaceReferences",
"(",
"array",
"&",
"$",
"config",
")",
"{",
"foreach",
"(",
"$",
"config",
"as",
"$",
"key",
"=>",
"&",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"this",
"->",
"replaceReferences",
"(",
"$",
"value",
")",
";",
"continue",
";",
"}",
"//~ Not string, skip",
"if",
"(",
"!",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"continue",
";",
"}",
"//~ Value not %my.reference.config%, skip",
"if",
"(",
"!",
"(",
"bool",
")",
"preg_match",
"(",
"'`%(.*?)%`'",
",",
"$",
"value",
",",
"$",
"matches",
")",
")",
"{",
"continue",
";",
"}",
"$",
"referenceValue",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"if",
"(",
"$",
"referenceValue",
"!==",
"null",
")",
"{",
"$",
"value",
"=",
"$",
"referenceValue",
";",
"}",
"}",
"}"
] | Replace references values in all configurations.
@param array $config
@return void | [
"Replace",
"references",
"values",
"in",
"all",
"configurations",
"."
] | ae3f17683fb3e96641b65375c6cca6a3139ae85e | https://github.com/eureka-framework/component-config/blob/ae3f17683fb3e96641b65375c6cca6a3139ae85e/src/Config/Config.php#L370-L394 | train |
nattreid/tracking | src/Model/TrackingPages/TrackingPagesMapper.php | TrackingPagesMapper.findCalculateDate | public function findCalculateDate(Range $interval): array
{
$result = [];
if (!isset($this->isCalculated[(string) $interval])) {
$this->isCalculated[(string) $interval] = true;
// dopocita posledni den
if ($interval->to->format('Y-m-d') >= (new DateTime)->format('Y-m-d')) {
$last = $this->connection->query('SELECT MAX([datefield]) datefield FROM %table', $this->getTableName())->fetch();
if ($last) {
$result[] = $last->datefield;
}
}
// chybejici dny
$dates = 'SELECT DATE_ADD(DATE(%dt), INTERVAL t4 + t16 + t64 + t256 + t1024 DAY) missingDate
FROM
(SELECT 0 t4 UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 ) t4,
(SELECT 0 t16 UNION ALL SELECT 4 UNION ALL SELECT 8 UNION ALL SELECT 12 ) t16,
(SELECT 0 t64 UNION ALL SELECT 16 UNION ALL SELECT 32 UNION ALL SELECT 48 ) t64,
(SELECT 0 t256 UNION ALL SELECT 64 UNION ALL SELECT 128 UNION ALL SELECT 192) t256,
(SELECT 0 t1024 UNION ALL SELECT 256 UNION ALL SELECT 512 UNION ALL SELECT 768) t1024';
$visits = 'SELECT DATE([datefield]) '
. 'FROM %table '
. 'WHERE DATE([datefield]) BETWEEN DATE(%dt) AND DATE(%dt)';
$calculateDates = $this->connection->query('SELECT DATE([missingDate]) date FROM (' . $dates . ') dates '
. 'WHERE [missingDate] NOT IN (' . $visits . ') '
. 'AND [missingDate] <= DATE(%dt)', $interval->from, $this->getTableName(), $interval->from, $interval->to, $interval->to);
if ($calculateDates) {
foreach ($calculateDates as $date) {
$result[] = $date->date;
}
}
}
return $result;
} | php | public function findCalculateDate(Range $interval): array
{
$result = [];
if (!isset($this->isCalculated[(string) $interval])) {
$this->isCalculated[(string) $interval] = true;
// dopocita posledni den
if ($interval->to->format('Y-m-d') >= (new DateTime)->format('Y-m-d')) {
$last = $this->connection->query('SELECT MAX([datefield]) datefield FROM %table', $this->getTableName())->fetch();
if ($last) {
$result[] = $last->datefield;
}
}
// chybejici dny
$dates = 'SELECT DATE_ADD(DATE(%dt), INTERVAL t4 + t16 + t64 + t256 + t1024 DAY) missingDate
FROM
(SELECT 0 t4 UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 ) t4,
(SELECT 0 t16 UNION ALL SELECT 4 UNION ALL SELECT 8 UNION ALL SELECT 12 ) t16,
(SELECT 0 t64 UNION ALL SELECT 16 UNION ALL SELECT 32 UNION ALL SELECT 48 ) t64,
(SELECT 0 t256 UNION ALL SELECT 64 UNION ALL SELECT 128 UNION ALL SELECT 192) t256,
(SELECT 0 t1024 UNION ALL SELECT 256 UNION ALL SELECT 512 UNION ALL SELECT 768) t1024';
$visits = 'SELECT DATE([datefield]) '
. 'FROM %table '
. 'WHERE DATE([datefield]) BETWEEN DATE(%dt) AND DATE(%dt)';
$calculateDates = $this->connection->query('SELECT DATE([missingDate]) date FROM (' . $dates . ') dates '
. 'WHERE [missingDate] NOT IN (' . $visits . ') '
. 'AND [missingDate] <= DATE(%dt)', $interval->from, $this->getTableName(), $interval->from, $interval->to, $interval->to);
if ($calculateDates) {
foreach ($calculateDates as $date) {
$result[] = $date->date;
}
}
}
return $result;
} | [
"public",
"function",
"findCalculateDate",
"(",
"Range",
"$",
"interval",
")",
":",
"array",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"isCalculated",
"[",
"(",
"string",
")",
"$",
"interval",
"]",
")",
")",
"{",
"$",
"this",
"->",
"isCalculated",
"[",
"(",
"string",
")",
"$",
"interval",
"]",
"=",
"true",
";",
"// dopocita posledni den",
"if",
"(",
"$",
"interval",
"->",
"to",
"->",
"format",
"(",
"'Y-m-d'",
")",
">=",
"(",
"new",
"DateTime",
")",
"->",
"format",
"(",
"'Y-m-d'",
")",
")",
"{",
"$",
"last",
"=",
"$",
"this",
"->",
"connection",
"->",
"query",
"(",
"'SELECT MAX([datefield]) datefield FROM %table'",
",",
"$",
"this",
"->",
"getTableName",
"(",
")",
")",
"->",
"fetch",
"(",
")",
";",
"if",
"(",
"$",
"last",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"last",
"->",
"datefield",
";",
"}",
"}",
"// chybejici dny",
"$",
"dates",
"=",
"'SELECT DATE_ADD(DATE(%dt), INTERVAL t4 + t16 + t64 + t256 + t1024 DAY) missingDate \n FROM \n (SELECT 0 t4 UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 ) t4,\n (SELECT 0 t16 UNION ALL SELECT 4 UNION ALL SELECT 8 UNION ALL SELECT 12 ) t16, \n (SELECT 0 t64 UNION ALL SELECT 16 UNION ALL SELECT 32 UNION ALL SELECT 48 ) t64, \n (SELECT 0 t256 UNION ALL SELECT 64 UNION ALL SELECT 128 UNION ALL SELECT 192) t256, \n (SELECT 0 t1024 UNION ALL SELECT 256 UNION ALL SELECT 512 UNION ALL SELECT 768) t1024'",
";",
"$",
"visits",
"=",
"'SELECT DATE([datefield]) '",
".",
"'FROM %table '",
".",
"'WHERE DATE([datefield]) BETWEEN DATE(%dt) AND DATE(%dt)'",
";",
"$",
"calculateDates",
"=",
"$",
"this",
"->",
"connection",
"->",
"query",
"(",
"'SELECT DATE([missingDate]) date FROM ('",
".",
"$",
"dates",
".",
"') dates '",
".",
"'WHERE [missingDate] NOT IN ('",
".",
"$",
"visits",
".",
"') '",
".",
"'AND [missingDate] <= DATE(%dt)'",
",",
"$",
"interval",
"->",
"from",
",",
"$",
"this",
"->",
"getTableName",
"(",
")",
",",
"$",
"interval",
"->",
"from",
",",
"$",
"interval",
"->",
"to",
",",
"$",
"interval",
"->",
"to",
")",
";",
"if",
"(",
"$",
"calculateDates",
")",
"{",
"foreach",
"(",
"$",
"calculateDates",
"as",
"$",
"date",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"date",
"->",
"date",
";",
"}",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Vrati datum, ktere je treba prepocitat
@param Range $interval
@return DateTime[]
@throws QueryException | [
"Vrati",
"datum",
"ktere",
"je",
"treba",
"prepocitat"
] | 5fc7c993c08774945405c79a393584ef2ed589f7 | https://github.com/nattreid/tracking/blob/5fc7c993c08774945405c79a393584ef2ed589f7/src/Model/TrackingPages/TrackingPagesMapper.php#L62-L100 | train |
phpffcms/ffcms-core | src/Helper/Type/Any.php | Any.isBool | public static function isBool(&$var = null): bool
{
// will return true for "1", true, "on", "yes", false for 0, "false", "off", 'no', '', NULL FOR ANY OTHER VALUE!!!
$parse = filter_var($var, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
if ($parse !== null) {
$var = $parse;
return true;
}
return false;
} | php | public static function isBool(&$var = null): bool
{
// will return true for "1", true, "on", "yes", false for 0, "false", "off", 'no', '', NULL FOR ANY OTHER VALUE!!!
$parse = filter_var($var, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
if ($parse !== null) {
$var = $parse;
return true;
}
return false;
} | [
"public",
"static",
"function",
"isBool",
"(",
"&",
"$",
"var",
"=",
"null",
")",
":",
"bool",
"{",
"// will return true for \"1\", true, \"on\", \"yes\", false for 0, \"false\", \"off\", 'no', '', NULL FOR ANY OTHER VALUE!!!",
"$",
"parse",
"=",
"filter_var",
"(",
"$",
"var",
",",
"FILTER_VALIDATE_BOOLEAN",
",",
"FILTER_NULL_ON_FAILURE",
")",
";",
"if",
"(",
"$",
"parse",
"!==",
"null",
")",
"{",
"$",
"var",
"=",
"$",
"parse",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Check if var is boolean and parseBool by ref
@param mixed $var
@return bool | [
"Check",
"if",
"var",
"is",
"boolean",
"and",
"parseBool",
"by",
"ref"
] | 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Helper/Type/Any.php#L93-L102 | train |
VTacius/ldapPM | src/Controlador/ldapAccess.php | ldapAccess.obtenerConfiguracionDominio | protected function obtenerConfiguracionDominio($destino, $fichero){
$yaml = new \Symfony\Component\Yaml\Parser();
$valor = $yaml->parse(file_get_contents($fichero));
$parametros = $valor['ldapPM'];
if ($parametros['solo_default']) {
// TODO: Implementar esto
}else{
return $parametros['servidores'][$destino]['configuracion'];
}
} | php | protected function obtenerConfiguracionDominio($destino, $fichero){
$yaml = new \Symfony\Component\Yaml\Parser();
$valor = $yaml->parse(file_get_contents($fichero));
$parametros = $valor['ldapPM'];
if ($parametros['solo_default']) {
// TODO: Implementar esto
}else{
return $parametros['servidores'][$destino]['configuracion'];
}
} | [
"protected",
"function",
"obtenerConfiguracionDominio",
"(",
"$",
"destino",
",",
"$",
"fichero",
")",
"{",
"$",
"yaml",
"=",
"new",
"\\",
"Symfony",
"\\",
"Component",
"\\",
"Yaml",
"\\",
"Parser",
"(",
")",
";",
"$",
"valor",
"=",
"$",
"yaml",
"->",
"parse",
"(",
"file_get_contents",
"(",
"$",
"fichero",
")",
")",
";",
"$",
"parametros",
"=",
"$",
"valor",
"[",
"'ldapPM'",
"]",
";",
"if",
"(",
"$",
"parametros",
"[",
"'solo_default'",
"]",
")",
"{",
"// TODO: Implementar esto",
"}",
"else",
"{",
"return",
"$",
"parametros",
"[",
"'servidores'",
"]",
"[",
"$",
"destino",
"]",
"[",
"'configuracion'",
"]",
";",
"}",
"}"
] | Recoge la configuracion del dominio dado
@param string $destino
@param string $fichero
@return array | [
"Recoge",
"la",
"configuracion",
"del",
"dominio",
"dado"
] | 728af24cd0a5ca4fbed76ffb52aa4800b118879f | https://github.com/VTacius/ldapPM/blob/728af24cd0a5ca4fbed76ffb52aa4800b118879f/src/Controlador/ldapAccess.php#L129-L138 | train |
rougin/blueprint | src/Application.php | Application.run | public function run($console = false)
{
$commands = $this->commands;
is_string($commands) && $commands = $this->classes();
foreach ((array) $commands as $command) {
$item = $this->container->get($command);
$this->console->add($instance = $item);
}
$console === false && $this->console->run();
return $this->console;
} | php | public function run($console = false)
{
$commands = $this->commands;
is_string($commands) && $commands = $this->classes();
foreach ((array) $commands as $command) {
$item = $this->container->get($command);
$this->console->add($instance = $item);
}
$console === false && $this->console->run();
return $this->console;
} | [
"public",
"function",
"run",
"(",
"$",
"console",
"=",
"false",
")",
"{",
"$",
"commands",
"=",
"$",
"this",
"->",
"commands",
";",
"is_string",
"(",
"$",
"commands",
")",
"&&",
"$",
"commands",
"=",
"$",
"this",
"->",
"classes",
"(",
")",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"commands",
"as",
"$",
"command",
")",
"{",
"$",
"item",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"$",
"command",
")",
";",
"$",
"this",
"->",
"console",
"->",
"add",
"(",
"$",
"instance",
"=",
"$",
"item",
")",
";",
"}",
"$",
"console",
"===",
"false",
"&&",
"$",
"this",
"->",
"console",
"->",
"run",
"(",
")",
";",
"return",
"$",
"this",
"->",
"console",
";",
"}"
] | Runs the console instance.
@param boolean $console
@return \Symfony\Component\Console\Application | [
"Runs",
"the",
"console",
"instance",
"."
] | 02dab857b0fab60e060632f11f73e24467483e5b | https://github.com/rougin/blueprint/blob/02dab857b0fab60e060632f11f73e24467483e5b/src/Application.php#L164-L179 | train |
rougin/blueprint | src/Application.php | Application.classes | protected function classes()
{
list($items, $pattern) = array(array(), '/\\.[^.\\s]{3,4}$/');
$files = glob($this->commands . '/*.php');
$path = strlen($this->commands . DIRECTORY_SEPARATOR);
foreach ((array) $files as $file) {
$substring = substr($file, $path);
$class = preg_replace($pattern, '', $substring);
$class = $this->namespace . '\\' . $class;
$reflection = new \ReflectionClass($class);
$reflection->isAbstract() || $items[] = $class;
}
return $items;
} | php | protected function classes()
{
list($items, $pattern) = array(array(), '/\\.[^.\\s]{3,4}$/');
$files = glob($this->commands . '/*.php');
$path = strlen($this->commands . DIRECTORY_SEPARATOR);
foreach ((array) $files as $file) {
$substring = substr($file, $path);
$class = preg_replace($pattern, '', $substring);
$class = $this->namespace . '\\' . $class;
$reflection = new \ReflectionClass($class);
$reflection->isAbstract() || $items[] = $class;
}
return $items;
} | [
"protected",
"function",
"classes",
"(",
")",
"{",
"list",
"(",
"$",
"items",
",",
"$",
"pattern",
")",
"=",
"array",
"(",
"array",
"(",
")",
",",
"'/\\\\.[^.\\\\s]{3,4}$/'",
")",
";",
"$",
"files",
"=",
"glob",
"(",
"$",
"this",
"->",
"commands",
".",
"'/*.php'",
")",
";",
"$",
"path",
"=",
"strlen",
"(",
"$",
"this",
"->",
"commands",
".",
"DIRECTORY_SEPARATOR",
")",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"substring",
"=",
"substr",
"(",
"$",
"file",
",",
"$",
"path",
")",
";",
"$",
"class",
"=",
"preg_replace",
"(",
"$",
"pattern",
",",
"''",
",",
"$",
"substring",
")",
";",
"$",
"class",
"=",
"$",
"this",
"->",
"namespace",
".",
"'\\\\'",
".",
"$",
"class",
";",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"$",
"reflection",
"->",
"isAbstract",
"(",
")",
"||",
"$",
"items",
"[",
"]",
"=",
"$",
"class",
";",
"}",
"return",
"$",
"items",
";",
"}"
] | Returns an array of command classes.
@return string[] | [
"Returns",
"an",
"array",
"of",
"command",
"classes",
"."
] | 02dab857b0fab60e060632f11f73e24467483e5b | https://github.com/rougin/blueprint/blob/02dab857b0fab60e060632f11f73e24467483e5b/src/Application.php#L186-L207 | train |
rougin/blueprint | src/Application.php | Application.parse | protected function parse($file)
{
$search = '%%CURRENT_DIRECTORY%%';
$yaml = file_get_contents($file);
$yaml = str_replace($search, $this->root, $yaml);
$result = Yaml::parse($yaml);
$this->commands = $result['paths']['commands'];
$this->namespace = $result['namespaces']['commands'];
$this->templates = $result['paths']['templates'];
} | php | protected function parse($file)
{
$search = '%%CURRENT_DIRECTORY%%';
$yaml = file_get_contents($file);
$yaml = str_replace($search, $this->root, $yaml);
$result = Yaml::parse($yaml);
$this->commands = $result['paths']['commands'];
$this->namespace = $result['namespaces']['commands'];
$this->templates = $result['paths']['templates'];
} | [
"protected",
"function",
"parse",
"(",
"$",
"file",
")",
"{",
"$",
"search",
"=",
"'%%CURRENT_DIRECTORY%%'",
";",
"$",
"yaml",
"=",
"file_get_contents",
"(",
"$",
"file",
")",
";",
"$",
"yaml",
"=",
"str_replace",
"(",
"$",
"search",
",",
"$",
"this",
"->",
"root",
",",
"$",
"yaml",
")",
";",
"$",
"result",
"=",
"Yaml",
"::",
"parse",
"(",
"$",
"yaml",
")",
";",
"$",
"this",
"->",
"commands",
"=",
"$",
"result",
"[",
"'paths'",
"]",
"[",
"'commands'",
"]",
";",
"$",
"this",
"->",
"namespace",
"=",
"$",
"result",
"[",
"'namespaces'",
"]",
"[",
"'commands'",
"]",
";",
"$",
"this",
"->",
"templates",
"=",
"$",
"result",
"[",
"'paths'",
"]",
"[",
"'templates'",
"]",
";",
"}"
] | Parses the YAML file.
@param string $file
@return void | [
"Parses",
"the",
"YAML",
"file",
"."
] | 02dab857b0fab60e060632f11f73e24467483e5b | https://github.com/rougin/blueprint/blob/02dab857b0fab60e060632f11f73e24467483e5b/src/Application.php#L215-L230 | train |
DreadLabs/app-migration-migrator-phinx | src/Migrator.php | Migrator.needsToRun | public function needsToRun()
{
$this->initializeVersions();
if (empty($this->migratedVersions) && empty($this->availableVersions)) {
return false;
}
$needsToRun = $this->hasUnmigratedVersions();
return $needsToRun;
} | php | public function needsToRun()
{
$this->initializeVersions();
if (empty($this->migratedVersions) && empty($this->availableVersions)) {
return false;
}
$needsToRun = $this->hasUnmigratedVersions();
return $needsToRun;
} | [
"public",
"function",
"needsToRun",
"(",
")",
"{",
"$",
"this",
"->",
"initializeVersions",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"migratedVersions",
")",
"&&",
"empty",
"(",
"$",
"this",
"->",
"availableVersions",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"needsToRun",
"=",
"$",
"this",
"->",
"hasUnmigratedVersions",
"(",
")",
";",
"return",
"$",
"needsToRun",
";",
"}"
] | Flags if migrations need to be executed
@return bool | [
"Flags",
"if",
"migrations",
"need",
"to",
"be",
"executed"
] | a43e437fcc4e3dff7becf7114bc65b78099d0977 | https://github.com/DreadLabs/app-migration-migrator-phinx/blob/a43e437fcc4e3dff7becf7114bc65b78099d0977/src/Migrator.php#L74-L85 | train |
DreadLabs/app-migration-migrator-phinx | src/Migrator.php | Migrator.initializeVersions | private function initializeVersions()
{
$env = $this->manager->getEnvironment($this->environment);
$this->migratedVersions = $env->getVersions();
$this->availableVersions = $this->manager->getMigrations();
$this->currentVersion = $env->getCurrentVersion();
} | php | private function initializeVersions()
{
$env = $this->manager->getEnvironment($this->environment);
$this->migratedVersions = $env->getVersions();
$this->availableVersions = $this->manager->getMigrations();
$this->currentVersion = $env->getCurrentVersion();
} | [
"private",
"function",
"initializeVersions",
"(",
")",
"{",
"$",
"env",
"=",
"$",
"this",
"->",
"manager",
"->",
"getEnvironment",
"(",
"$",
"this",
"->",
"environment",
")",
";",
"$",
"this",
"->",
"migratedVersions",
"=",
"$",
"env",
"->",
"getVersions",
"(",
")",
";",
"$",
"this",
"->",
"availableVersions",
"=",
"$",
"this",
"->",
"manager",
"->",
"getMigrations",
"(",
")",
";",
"$",
"this",
"->",
"currentVersion",
"=",
"$",
"env",
"->",
"getCurrentVersion",
"(",
")",
";",
"}"
] | Initializes the migrated, available and current versions
@return void | [
"Initializes",
"the",
"migrated",
"available",
"and",
"current",
"versions"
] | a43e437fcc4e3dff7becf7114bc65b78099d0977 | https://github.com/DreadLabs/app-migration-migrator-phinx/blob/a43e437fcc4e3dff7becf7114bc65b78099d0977/src/Migrator.php#L92-L99 | train |
DreadLabs/app-migration-migrator-phinx | src/Migrator.php | Migrator.hasUnmigratedVersions | private function hasUnmigratedVersions()
{
$needsToRun = false;
foreach ($this->availableVersions as $migration) {
$isTargetMigrated = in_array($migration->getVersion(), $this->migratedVersions);
if ($isTargetMigrated) {
continue;
}
$needsToRun = true;
break;
}
return $needsToRun;
} | php | private function hasUnmigratedVersions()
{
$needsToRun = false;
foreach ($this->availableVersions as $migration) {
$isTargetMigrated = in_array($migration->getVersion(), $this->migratedVersions);
if ($isTargetMigrated) {
continue;
}
$needsToRun = true;
break;
}
return $needsToRun;
} | [
"private",
"function",
"hasUnmigratedVersions",
"(",
")",
"{",
"$",
"needsToRun",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"availableVersions",
"as",
"$",
"migration",
")",
"{",
"$",
"isTargetMigrated",
"=",
"in_array",
"(",
"$",
"migration",
"->",
"getVersion",
"(",
")",
",",
"$",
"this",
"->",
"migratedVersions",
")",
";",
"if",
"(",
"$",
"isTargetMigrated",
")",
"{",
"continue",
";",
"}",
"$",
"needsToRun",
"=",
"true",
";",
"break",
";",
"}",
"return",
"$",
"needsToRun",
";",
"}"
] | Flags if unmigrated versions exists
@return bool | [
"Flags",
"if",
"unmigrated",
"versions",
"exists"
] | a43e437fcc4e3dff7becf7114bc65b78099d0977 | https://github.com/DreadLabs/app-migration-migrator-phinx/blob/a43e437fcc4e3dff7becf7114bc65b78099d0977/src/Migrator.php#L106-L122 | train |
agentmedia/phine-core | src/Core/Modules/Backend/UserForm.php | UserForm.AddPasswordField | private function AddPasswordField()
{
$name = 'Password';
$this->AddField(Input::Password($name));
//Password needs contain lower case letter, upper case letter, and a digit
//$validator = new RegExp('/((?=.*\d)(?=.*[a-z])(?=.*[A-Z]))/');
//$this->AddValidator($name, $validator);
$this->AddValidator($name, new StringLength(6, 20));
if (Request::PostData('PasswordRepeat') || !$this->user->Exists())
{
$this->SetRequired($name);
}
} | php | private function AddPasswordField()
{
$name = 'Password';
$this->AddField(Input::Password($name));
//Password needs contain lower case letter, upper case letter, and a digit
//$validator = new RegExp('/((?=.*\d)(?=.*[a-z])(?=.*[A-Z]))/');
//$this->AddValidator($name, $validator);
$this->AddValidator($name, new StringLength(6, 20));
if (Request::PostData('PasswordRepeat') || !$this->user->Exists())
{
$this->SetRequired($name);
}
} | [
"private",
"function",
"AddPasswordField",
"(",
")",
"{",
"$",
"name",
"=",
"'Password'",
";",
"$",
"this",
"->",
"AddField",
"(",
"Input",
"::",
"Password",
"(",
"$",
"name",
")",
")",
";",
"//Password needs contain lower case letter, upper case letter, and a digit",
"//$validator = new RegExp('/((?=.*\\d)(?=.*[a-z])(?=.*[A-Z]))/');",
"//$this->AddValidator($name, $validator);",
"$",
"this",
"->",
"AddValidator",
"(",
"$",
"name",
",",
"new",
"StringLength",
"(",
"6",
",",
"20",
")",
")",
";",
"if",
"(",
"Request",
"::",
"PostData",
"(",
"'PasswordRepeat'",
")",
"||",
"!",
"$",
"this",
"->",
"user",
"->",
"Exists",
"(",
")",
")",
"{",
"$",
"this",
"->",
"SetRequired",
"(",
"$",
"name",
")",
";",
"}",
"}"
] | Adds the password field | [
"Adds",
"the",
"password",
"field"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/UserForm.php#L104-L117 | train |
stubbles/stubbles-webapp-session | src/main/php/WebSession.php | WebSession.removeValue | public function removeValue($key)
{
if (!$this->isValid()) {
throw new \LogicException('Session is in an invalid state.');
}
if ($this->storage->hasValue($key)) {
$this->storage->removeValue($key);
return true;
}
return false;
} | php | public function removeValue($key)
{
if (!$this->isValid()) {
throw new \LogicException('Session is in an invalid state.');
}
if ($this->storage->hasValue($key)) {
$this->storage->removeValue($key);
return true;
}
return false;
} | [
"public",
"function",
"removeValue",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isValid",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Session is in an invalid state.'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"storage",
"->",
"hasValue",
"(",
"$",
"key",
")",
")",
"{",
"$",
"this",
"->",
"storage",
"->",
"removeValue",
"(",
"$",
"key",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | removes a value from the session
@param string $key key where value is stored under
@return bool true if value existed and was removed, else false
@throws \LogicException | [
"removes",
"a",
"value",
"from",
"the",
"session"
] | 2976fa28995bfb6ad00e3eac59ad689dd7892450 | https://github.com/stubbles/stubbles-webapp-session/blob/2976fa28995bfb6ad00e3eac59ad689dd7892450/src/main/php/WebSession.php#L223-L235 | train |
stubbles/stubbles-webapp-session | src/main/php/WebSession.php | WebSession.valueKeys | public function valueKeys()
{
if (!$this->isValid()) {
throw new \LogicException('Session is in an invalid state.');
}
return array_values(
array_filter(
$this->storage->valueKeys(),
function($valueKey)
{
return substr($valueKey, 0, 11) !== '__stubbles_';
}
)
);
} | php | public function valueKeys()
{
if (!$this->isValid()) {
throw new \LogicException('Session is in an invalid state.');
}
return array_values(
array_filter(
$this->storage->valueKeys(),
function($valueKey)
{
return substr($valueKey, 0, 11) !== '__stubbles_';
}
)
);
} | [
"public",
"function",
"valueKeys",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isValid",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Session is in an invalid state.'",
")",
";",
"}",
"return",
"array_values",
"(",
"array_filter",
"(",
"$",
"this",
"->",
"storage",
"->",
"valueKeys",
"(",
")",
",",
"function",
"(",
"$",
"valueKey",
")",
"{",
"return",
"substr",
"(",
"$",
"valueKey",
",",
"0",
",",
"11",
")",
"!==",
"'__stubbles_'",
";",
"}",
")",
")",
";",
"}"
] | return an array of all keys registered in this session
@return string[]
@throws \LogicException | [
"return",
"an",
"array",
"of",
"all",
"keys",
"registered",
"in",
"this",
"session"
] | 2976fa28995bfb6ad00e3eac59ad689dd7892450 | https://github.com/stubbles/stubbles-webapp-session/blob/2976fa28995bfb6ad00e3eac59ad689dd7892450/src/main/php/WebSession.php#L243-L258 | train |
stubbles/stubbles-dbal | src/main/php/Databases.php | Databases.get | public function get(string $name = null): Database
{
return new Database($this->connections->get($name));
} | php | public function get(string $name = null): Database
{
return new Database($this->connections->get($name));
} | [
"public",
"function",
"get",
"(",
"string",
"$",
"name",
"=",
"null",
")",
":",
"Database",
"{",
"return",
"new",
"Database",
"(",
"$",
"this",
"->",
"connections",
"->",
"get",
"(",
"$",
"name",
")",
")",
";",
"}"
] | returns the database
If a name is provided and a connection with this name exists this
connection will be used. If fallback is enabled and the named
connection does not exist the default connection will be used, if
fallback is disabled a DatabaseException will be thrown.
If no name is provided the default connection will be used.
@param string $name
@return \stubbles\db\Database | [
"returns",
"the",
"database"
] | b42a589025a9e511b40a2798ac84df94d6451c36 | https://github.com/stubbles/stubbles-dbal/blob/b42a589025a9e511b40a2798ac84df94d6451c36/src/main/php/Databases.php#L51-L54 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.