repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
mdmsoft/yii2-admin | models/searchs/Assignment.php | Assignment.search | public function search($params, $class, $usernameField)
{
$query = $class::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere(['like', $usernameField, $this->username]);
return $dataProvider;
} | php | public function search($params, $class, $usernameField)
{
$query = $class::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere(['like', $usernameField, $this->username]);
return $dataProvider;
} | [
"public",
"function",
"search",
"(",
"$",
"params",
",",
"$",
"class",
",",
"$",
"usernameField",
")",
"{",
"$",
"query",
"=",
"$",
"class",
"::",
"find",
"(",
")",
";",
"$",
"dataProvider",
"=",
"new",
"ActiveDataProvider",
"(",
"[",
"'query'",
"=>",
"$",
"query",
",",
"]",
")",
";",
"if",
"(",
"!",
"(",
"$",
"this",
"->",
"load",
"(",
"$",
"params",
")",
"&&",
"$",
"this",
"->",
"validate",
"(",
")",
")",
")",
"{",
"return",
"$",
"dataProvider",
";",
"}",
"$",
"query",
"->",
"andFilterWhere",
"(",
"[",
"'like'",
",",
"$",
"usernameField",
",",
"$",
"this",
"->",
"username",
"]",
")",
";",
"return",
"$",
"dataProvider",
";",
"}"
] | Create data provider for Assignment model.
@param array $params
@param \yii\db\ActiveRecord $class
@param string $usernameField
@return \yii\data\ActiveDataProvider | [
"Create",
"data",
"provider",
"for",
"Assignment",
"model",
"."
] | 59e65542b1dc1abcf14c62588ea4ae128e08036c | https://github.com/mdmsoft/yii2-admin/blob/59e65542b1dc1abcf14c62588ea4ae128e08036c/models/searchs/Assignment.php#L49-L63 | train |
code16/sharp | src/Form/HandleFormFields.php | HandleFormFields.fields | function fields(): array
{
$this->checkFormIsBuilt();
return collect($this->fields)->map(function($field) {
return $field->toArray();
})->keyBy("key")->all();
} | php | function fields(): array
{
$this->checkFormIsBuilt();
return collect($this->fields)->map(function($field) {
return $field->toArray();
})->keyBy("key")->all();
} | [
"function",
"fields",
"(",
")",
":",
"array",
"{",
"$",
"this",
"->",
"checkFormIsBuilt",
"(",
")",
";",
"return",
"collect",
"(",
"$",
"this",
"->",
"fields",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"field",
")",
"{",
"return",
"$",
"field",
"->",
"toArray",
"(",
")",
";",
"}",
")",
"->",
"keyBy",
"(",
"\"key\"",
")",
"->",
"all",
"(",
")",
";",
"}"
] | Get the SharpFormField array representation.
@return array | [
"Get",
"the",
"SharpFormField",
"array",
"representation",
"."
] | 6ce8f1613ed16da0564d8c63d7ebf6ae94343cca | https://github.com/code16/sharp/blob/6ce8f1613ed16da0564d8c63d7ebf6ae94343cca/src/Form/HandleFormFields.php#L25-L32 | train |
code16/sharp | src/Form/HandleFormFields.php | HandleFormFields.findFieldByKey | function findFieldByKey(string $key)
{
$this->checkFormIsBuilt();
$fields = collect($this->fields);
if(strpos($key, ".") !== false) {
list($key, $itemKey) = explode(".", $key);
$listField = $fields->where("key", $key)->first();
return $listField->findItemFormFieldByKey($itemKey);
}
return $fields->where("key", $key)->first();
} | php | function findFieldByKey(string $key)
{
$this->checkFormIsBuilt();
$fields = collect($this->fields);
if(strpos($key, ".") !== false) {
list($key, $itemKey) = explode(".", $key);
$listField = $fields->where("key", $key)->first();
return $listField->findItemFormFieldByKey($itemKey);
}
return $fields->where("key", $key)->first();
} | [
"function",
"findFieldByKey",
"(",
"string",
"$",
"key",
")",
"{",
"$",
"this",
"->",
"checkFormIsBuilt",
"(",
")",
";",
"$",
"fields",
"=",
"collect",
"(",
"$",
"this",
"->",
"fields",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"key",
",",
"\".\"",
")",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"key",
",",
"$",
"itemKey",
")",
"=",
"explode",
"(",
"\".\"",
",",
"$",
"key",
")",
";",
"$",
"listField",
"=",
"$",
"fields",
"->",
"where",
"(",
"\"key\"",
",",
"$",
"key",
")",
"->",
"first",
"(",
")",
";",
"return",
"$",
"listField",
"->",
"findItemFormFieldByKey",
"(",
"$",
"itemKey",
")",
";",
"}",
"return",
"$",
"fields",
"->",
"where",
"(",
"\"key\"",
",",
"$",
"key",
")",
"->",
"first",
"(",
")",
";",
"}"
] | Find a field by its key.
@param string $key
@return SharpFormField | [
"Find",
"a",
"field",
"by",
"its",
"key",
"."
] | 6ce8f1613ed16da0564d8c63d7ebf6ae94343cca | https://github.com/code16/sharp/blob/6ce8f1613ed16da0564d8c63d7ebf6ae94343cca/src/Form/HandleFormFields.php#L52-L66 | train |
code16/sharp | src/Form/Eloquent/WithSharpFormEloquentUpdater.php | WithSharpFormEloquentUpdater.getFormListFieldsConfiguration | protected function getFormListFieldsConfiguration()
{
return collect($this->fields)
->filter(function($field) {
return $field instanceof SharpFormListField
&& $field->isSortable();
})->map(function($listField) {
return [
"key" => $listField->key(),
"orderAttribute" => $listField->orderAttribute()
];
})->keyBy("key");
} | php | protected function getFormListFieldsConfiguration()
{
return collect($this->fields)
->filter(function($field) {
return $field instanceof SharpFormListField
&& $field->isSortable();
})->map(function($listField) {
return [
"key" => $listField->key(),
"orderAttribute" => $listField->orderAttribute()
];
})->keyBy("key");
} | [
"protected",
"function",
"getFormListFieldsConfiguration",
"(",
")",
"{",
"return",
"collect",
"(",
"$",
"this",
"->",
"fields",
")",
"->",
"filter",
"(",
"function",
"(",
"$",
"field",
")",
"{",
"return",
"$",
"field",
"instanceof",
"SharpFormListField",
"&&",
"$",
"field",
"->",
"isSortable",
"(",
")",
";",
"}",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"listField",
")",
"{",
"return",
"[",
"\"key\"",
"=>",
"$",
"listField",
"->",
"key",
"(",
")",
",",
"\"orderAttribute\"",
"=>",
"$",
"listField",
"->",
"orderAttribute",
"(",
")",
"]",
";",
"}",
")",
"->",
"keyBy",
"(",
"\"key\"",
")",
";",
"}"
] | Get all List fields which are sortable and their "orderAttribute"
configuration to be used by EloquentModelUpdater
for automatic ordering.
@return Collection | [
"Get",
"all",
"List",
"fields",
"which",
"are",
"sortable",
"and",
"their",
"orderAttribute",
"configuration",
"to",
"be",
"used",
"by",
"EloquentModelUpdater",
"for",
"automatic",
"ordering",
"."
] | 6ce8f1613ed16da0564d8c63d7ebf6ae94343cca | https://github.com/code16/sharp/blob/6ce8f1613ed16da0564d8c63d7ebf6ae94343cca/src/Form/Eloquent/WithSharpFormEloquentUpdater.php#L62-L76 | train |
code16/sharp | src/Http/Api/EntityListController.php | EntityListController.update | public function update($entityKey)
{
sharp_check_ability("update", $entityKey);
$list = $this->getListInstance($entityKey);
$list->buildListConfig();
$list->reorderHandler()->reorder(
request("instances")
);
return response()->json([
"ok" => true
]);
} | php | public function update($entityKey)
{
sharp_check_ability("update", $entityKey);
$list = $this->getListInstance($entityKey);
$list->buildListConfig();
$list->reorderHandler()->reorder(
request("instances")
);
return response()->json([
"ok" => true
]);
} | [
"public",
"function",
"update",
"(",
"$",
"entityKey",
")",
"{",
"sharp_check_ability",
"(",
"\"update\"",
",",
"$",
"entityKey",
")",
";",
"$",
"list",
"=",
"$",
"this",
"->",
"getListInstance",
"(",
"$",
"entityKey",
")",
";",
"$",
"list",
"->",
"buildListConfig",
"(",
")",
";",
"$",
"list",
"->",
"reorderHandler",
"(",
")",
"->",
"reorder",
"(",
"request",
"(",
"\"instances\"",
")",
")",
";",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"[",
"\"ok\"",
"=>",
"true",
"]",
")",
";",
"}"
] | Call for reorder instances.
@param string $entityKey
@return \Illuminate\Http\JsonResponse
@throws \Code16\Sharp\Exceptions\Auth\SharpAuthorizationException
@throws \Code16\Sharp\Exceptions\SharpInvalidEntityKeyException | [
"Call",
"for",
"reorder",
"instances",
"."
] | 6ce8f1613ed16da0564d8c63d7ebf6ae94343cca | https://github.com/code16/sharp/blob/6ce8f1613ed16da0564d8c63d7ebf6ae94343cca/src/Http/Api/EntityListController.php#L37-L51 | train |
code16/sharp | src/Console/ModelWizardCommand.php | ModelWizardCommand.parseClassname | protected function parseClassname($class, $additionalNamespace = null)
{
if (preg_match('([^A-Za-z0-9_/\\\\])', $class)) {
throw new InvalidArgumentException('Class name contains invalid characters.');
}
$class = trim(str_replace('/', '\\', $class), '\\');
if (! Str::startsWith($class, $rootNamespace = $this->laravel->getNamespace())) {
$namespace = $rootNamespace . ($additionalNamespace ? trim(str_replace('/', '\\', $additionalNamespace), '\\') . '\\' : '');
$class = $namespace.$class;
}
return $class;
} | php | protected function parseClassname($class, $additionalNamespace = null)
{
if (preg_match('([^A-Za-z0-9_/\\\\])', $class)) {
throw new InvalidArgumentException('Class name contains invalid characters.');
}
$class = trim(str_replace('/', '\\', $class), '\\');
if (! Str::startsWith($class, $rootNamespace = $this->laravel->getNamespace())) {
$namespace = $rootNamespace . ($additionalNamespace ? trim(str_replace('/', '\\', $additionalNamespace), '\\') . '\\' : '');
$class = $namespace.$class;
}
return $class;
} | [
"protected",
"function",
"parseClassname",
"(",
"$",
"class",
",",
"$",
"additionalNamespace",
"=",
"null",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'([^A-Za-z0-9_/\\\\\\\\])'",
",",
"$",
"class",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Class name contains invalid characters.'",
")",
";",
"}",
"$",
"class",
"=",
"trim",
"(",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"class",
")",
",",
"'\\\\'",
")",
";",
"if",
"(",
"!",
"Str",
"::",
"startsWith",
"(",
"$",
"class",
",",
"$",
"rootNamespace",
"=",
"$",
"this",
"->",
"laravel",
"->",
"getNamespace",
"(",
")",
")",
")",
"{",
"$",
"namespace",
"=",
"$",
"rootNamespace",
".",
"(",
"$",
"additionalNamespace",
"?",
"trim",
"(",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"additionalNamespace",
")",
",",
"'\\\\'",
")",
".",
"'\\\\'",
":",
"''",
")",
";",
"$",
"class",
"=",
"$",
"namespace",
".",
"$",
"class",
";",
"}",
"return",
"$",
"class",
";",
"}"
] | Get the fully-qualified class name.
@param string $class
@return string
@throws \InvalidArgumentException | [
"Get",
"the",
"fully",
"-",
"qualified",
"class",
"name",
"."
] | 6ce8f1613ed16da0564d8c63d7ebf6ae94343cca | https://github.com/code16/sharp/blob/6ce8f1613ed16da0564d8c63d7ebf6ae94343cca/src/Console/ModelWizardCommand.php#L81-L95 | train |
code16/sharp | src/Http/Composers/AssetViewComposer.php | AssetViewComposer.compose | public function compose(View $view)
{
$strategy = $this->getValidatedStrategyFromConfig();
$output = [];
foreach((array)config("sharp.extensions.assets") as $position => $paths) {
foreach((array)$paths as $assetPath) {
if(!isset($output[$position])) {
$output[$position] = [];
}
// Only render valid assets
if(ends_with($assetPath, $this->assetTypes)) {
// Grab the relevant template based on the filetype
$template = array_get($this->renderTemplates, $this->getAssetFileType($assetPath));
// Apply the strategy (run through asset() or mix()
$resolvedAssetPath = $this->getAssetPathWithStrategyApplied($strategy, $assetPath);
$output[$position][] = sprintf($template, $resolvedAssetPath);
}
}
}
// Build the strings to output in the blades
$toBind = [];
foreach((array)$output as $position => $toOutput) {
$toBind[$position] = implode('', $toOutput);
}
$view->with('injectedAssets', $toBind);
} | php | public function compose(View $view)
{
$strategy = $this->getValidatedStrategyFromConfig();
$output = [];
foreach((array)config("sharp.extensions.assets") as $position => $paths) {
foreach((array)$paths as $assetPath) {
if(!isset($output[$position])) {
$output[$position] = [];
}
// Only render valid assets
if(ends_with($assetPath, $this->assetTypes)) {
// Grab the relevant template based on the filetype
$template = array_get($this->renderTemplates, $this->getAssetFileType($assetPath));
// Apply the strategy (run through asset() or mix()
$resolvedAssetPath = $this->getAssetPathWithStrategyApplied($strategy, $assetPath);
$output[$position][] = sprintf($template, $resolvedAssetPath);
}
}
}
// Build the strings to output in the blades
$toBind = [];
foreach((array)$output as $position => $toOutput) {
$toBind[$position] = implode('', $toOutput);
}
$view->with('injectedAssets', $toBind);
} | [
"public",
"function",
"compose",
"(",
"View",
"$",
"view",
")",
"{",
"$",
"strategy",
"=",
"$",
"this",
"->",
"getValidatedStrategyFromConfig",
"(",
")",
";",
"$",
"output",
"=",
"[",
"]",
";",
"foreach",
"(",
"(",
"array",
")",
"config",
"(",
"\"sharp.extensions.assets\"",
")",
"as",
"$",
"position",
"=>",
"$",
"paths",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"paths",
"as",
"$",
"assetPath",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"output",
"[",
"$",
"position",
"]",
")",
")",
"{",
"$",
"output",
"[",
"$",
"position",
"]",
"=",
"[",
"]",
";",
"}",
"// Only render valid assets",
"if",
"(",
"ends_with",
"(",
"$",
"assetPath",
",",
"$",
"this",
"->",
"assetTypes",
")",
")",
"{",
"// Grab the relevant template based on the filetype",
"$",
"template",
"=",
"array_get",
"(",
"$",
"this",
"->",
"renderTemplates",
",",
"$",
"this",
"->",
"getAssetFileType",
"(",
"$",
"assetPath",
")",
")",
";",
"// Apply the strategy (run through asset() or mix()",
"$",
"resolvedAssetPath",
"=",
"$",
"this",
"->",
"getAssetPathWithStrategyApplied",
"(",
"$",
"strategy",
",",
"$",
"assetPath",
")",
";",
"$",
"output",
"[",
"$",
"position",
"]",
"[",
"]",
"=",
"sprintf",
"(",
"$",
"template",
",",
"$",
"resolvedAssetPath",
")",
";",
"}",
"}",
"}",
"// Build the strings to output in the blades",
"$",
"toBind",
"=",
"[",
"]",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"output",
"as",
"$",
"position",
"=>",
"$",
"toOutput",
")",
"{",
"$",
"toBind",
"[",
"$",
"position",
"]",
"=",
"implode",
"(",
"''",
",",
"$",
"toOutput",
")",
";",
"}",
"$",
"view",
"->",
"with",
"(",
"'injectedAssets'",
",",
"$",
"toBind",
")",
";",
"}"
] | Bind data to the view
@param View $view
@throws SharpInvalidAssetRenderStrategy | [
"Bind",
"data",
"to",
"the",
"view"
] | 6ce8f1613ed16da0564d8c63d7ebf6ae94343cca | https://github.com/code16/sharp/blob/6ce8f1613ed16da0564d8c63d7ebf6ae94343cca/src/Http/Composers/AssetViewComposer.php#L48-L79 | train |
code16/sharp | src/Http/Composers/AssetViewComposer.php | AssetViewComposer.getValidatedStrategyFromConfig | protected function getValidatedStrategyFromConfig():string
{
$strategy = config('sharp.extensions.assets.strategy', 'raw');
if(!is_string($strategy)) {
throw new SharpInvalidAssetRenderStrategy('The asset strategy defined at sharp.extensions.assets.strategy is not a string');
}
if(!in_array($strategy, $this->renderStrategies)) {
throw new SharpInvalidAssetRenderStrategy("The asset strategy [$strategy] is not raw, asset, or mix");
}
return $strategy;
} | php | protected function getValidatedStrategyFromConfig():string
{
$strategy = config('sharp.extensions.assets.strategy', 'raw');
if(!is_string($strategy)) {
throw new SharpInvalidAssetRenderStrategy('The asset strategy defined at sharp.extensions.assets.strategy is not a string');
}
if(!in_array($strategy, $this->renderStrategies)) {
throw new SharpInvalidAssetRenderStrategy("The asset strategy [$strategy] is not raw, asset, or mix");
}
return $strategy;
} | [
"protected",
"function",
"getValidatedStrategyFromConfig",
"(",
")",
":",
"string",
"{",
"$",
"strategy",
"=",
"config",
"(",
"'sharp.extensions.assets.strategy'",
",",
"'raw'",
")",
";",
"if",
"(",
"!",
"is_string",
"(",
"$",
"strategy",
")",
")",
"{",
"throw",
"new",
"SharpInvalidAssetRenderStrategy",
"(",
"'The asset strategy defined at sharp.extensions.assets.strategy is not a string'",
")",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"strategy",
",",
"$",
"this",
"->",
"renderStrategies",
")",
")",
"{",
"throw",
"new",
"SharpInvalidAssetRenderStrategy",
"(",
"\"The asset strategy [$strategy] is not raw, asset, or mix\"",
")",
";",
"}",
"return",
"$",
"strategy",
";",
"}"
] | Get the strategy to render the assets
@return string
@throws SharpInvalidAssetRenderStrategy | [
"Get",
"the",
"strategy",
"to",
"render",
"the",
"assets"
] | 6ce8f1613ed16da0564d8c63d7ebf6ae94343cca | https://github.com/code16/sharp/blob/6ce8f1613ed16da0564d8c63d7ebf6ae94343cca/src/Http/Composers/AssetViewComposer.php#L122-L135 | train |
code16/sharp | src/Dashboard/Widgets/SharpWidget.php | SharpWidget.validate | protected function validate(array $properties)
{
$validator = Validator::make($properties, [
'key' => 'required',
'type' => 'required',
] + $this->validationRules());
if ($validator->fails()) {
throw new SharpWidgetValidationException($validator->errors());
}
} | php | protected function validate(array $properties)
{
$validator = Validator::make($properties, [
'key' => 'required',
'type' => 'required',
] + $this->validationRules());
if ($validator->fails()) {
throw new SharpWidgetValidationException($validator->errors());
}
} | [
"protected",
"function",
"validate",
"(",
"array",
"$",
"properties",
")",
"{",
"$",
"validator",
"=",
"Validator",
"::",
"make",
"(",
"$",
"properties",
",",
"[",
"'key'",
"=>",
"'required'",
",",
"'type'",
"=>",
"'required'",
",",
"]",
"+",
"$",
"this",
"->",
"validationRules",
"(",
")",
")",
";",
"if",
"(",
"$",
"validator",
"->",
"fails",
"(",
")",
")",
"{",
"throw",
"new",
"SharpWidgetValidationException",
"(",
"$",
"validator",
"->",
"errors",
"(",
")",
")",
";",
"}",
"}"
] | Throw an exception in case of invalid attribute value.
@param array $properties
@throws SharpWidgetValidationException | [
"Throw",
"an",
"exception",
"in",
"case",
"of",
"invalid",
"attribute",
"value",
"."
] | 6ce8f1613ed16da0564d8c63d7ebf6ae94343cca | https://github.com/code16/sharp/blob/6ce8f1613ed16da0564d8c63d7ebf6ae94343cca/src/Dashboard/Widgets/SharpWidget.php#L80-L90 | train |
code16/sharp | src/Form/SharpForm.php | SharpForm.formLayout | function formLayout(): array
{
if(!$this->layoutBuilt) {
$this->buildFormLayout();
$this->layoutBuilt = true;
}
return [
"tabbed" => $this->tabbed,
"tabs" => collect($this->tabs)->map(function($tab) {
return $tab->toArray();
})->all()
];
} | php | function formLayout(): array
{
if(!$this->layoutBuilt) {
$this->buildFormLayout();
$this->layoutBuilt = true;
}
return [
"tabbed" => $this->tabbed,
"tabs" => collect($this->tabs)->map(function($tab) {
return $tab->toArray();
})->all()
];
} | [
"function",
"formLayout",
"(",
")",
":",
"array",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"layoutBuilt",
")",
"{",
"$",
"this",
"->",
"buildFormLayout",
"(",
")",
";",
"$",
"this",
"->",
"layoutBuilt",
"=",
"true",
";",
"}",
"return",
"[",
"\"tabbed\"",
"=>",
"$",
"this",
"->",
"tabbed",
",",
"\"tabs\"",
"=>",
"collect",
"(",
"$",
"this",
"->",
"tabs",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"tab",
")",
"{",
"return",
"$",
"tab",
"->",
"toArray",
"(",
")",
";",
"}",
")",
"->",
"all",
"(",
")",
"]",
";",
"}"
] | Return the form fields layout.
@return array | [
"Return",
"the",
"form",
"fields",
"layout",
"."
] | 6ce8f1613ed16da0564d8c63d7ebf6ae94343cca | https://github.com/code16/sharp/blob/6ce8f1613ed16da0564d8c63d7ebf6ae94343cca/src/Form/SharpForm.php#L36-L49 | train |
code16/sharp | src/Form/SharpForm.php | SharpForm.instance | function instance($id): array
{
return collect($this->find($id))
// Filter model attributes on actual form fields
->only($this->getDataKeys())
->all();
} | php | function instance($id): array
{
return collect($this->find($id))
// Filter model attributes on actual form fields
->only($this->getDataKeys())
->all();
} | [
"function",
"instance",
"(",
"$",
"id",
")",
":",
"array",
"{",
"return",
"collect",
"(",
"$",
"this",
"->",
"find",
"(",
"$",
"id",
")",
")",
"// Filter model attributes on actual form fields",
"->",
"only",
"(",
"$",
"this",
"->",
"getDataKeys",
"(",
")",
")",
"->",
"all",
"(",
")",
";",
"}"
] | Return the entity instance, as an array.
@param $id
@return array | [
"Return",
"the",
"entity",
"instance",
"as",
"an",
"array",
"."
] | 6ce8f1613ed16da0564d8c63d7ebf6ae94343cca | https://github.com/code16/sharp/blob/6ce8f1613ed16da0564d8c63d7ebf6ae94343cca/src/Form/SharpForm.php#L57-L63 | train |
code16/sharp | src/Form/SharpForm.php | SharpForm.newInstance | public function newInstance()
{
$data = collect($this->create())
// Filter model attributes on actual form fields
->only($this->getDataKeys())
->all();
return sizeof($data) ? $data : null;
} | php | public function newInstance()
{
$data = collect($this->create())
// Filter model attributes on actual form fields
->only($this->getDataKeys())
->all();
return sizeof($data) ? $data : null;
} | [
"public",
"function",
"newInstance",
"(",
")",
"{",
"$",
"data",
"=",
"collect",
"(",
"$",
"this",
"->",
"create",
"(",
")",
")",
"// Filter model attributes on actual form fields",
"->",
"only",
"(",
"$",
"this",
"->",
"getDataKeys",
"(",
")",
")",
"->",
"all",
"(",
")",
";",
"return",
"sizeof",
"(",
"$",
"data",
")",
"?",
"$",
"data",
":",
"null",
";",
"}"
] | Return a new entity instance, as an array.
@return array | [
"Return",
"a",
"new",
"entity",
"instance",
"as",
"an",
"array",
"."
] | 6ce8f1613ed16da0564d8c63d7ebf6ae94343cca | https://github.com/code16/sharp/blob/6ce8f1613ed16da0564d8c63d7ebf6ae94343cca/src/Form/SharpForm.php#L70-L78 | train |
code16/sharp | src/Form/SharpForm.php | SharpForm.create | public function create(): array
{
$attributes = collect($this->getDataKeys())
->flip()
->map(function() {
return null;
})->all();
// Build a fake Model class based on attributes
return $this->transform(new class($attributes) extends \stdClass
{
public function __construct($attributes)
{
$this->attributes = $attributes;
foreach($attributes as $name => $value) {
$this->$name = $value;
}
}
public function toArray()
{
return $this->attributes;
}
});
} | php | public function create(): array
{
$attributes = collect($this->getDataKeys())
->flip()
->map(function() {
return null;
})->all();
// Build a fake Model class based on attributes
return $this->transform(new class($attributes) extends \stdClass
{
public function __construct($attributes)
{
$this->attributes = $attributes;
foreach($attributes as $name => $value) {
$this->$name = $value;
}
}
public function toArray()
{
return $this->attributes;
}
});
} | [
"public",
"function",
"create",
"(",
")",
":",
"array",
"{",
"$",
"attributes",
"=",
"collect",
"(",
"$",
"this",
"->",
"getDataKeys",
"(",
")",
")",
"->",
"flip",
"(",
")",
"->",
"map",
"(",
"function",
"(",
")",
"{",
"return",
"null",
";",
"}",
")",
"->",
"all",
"(",
")",
";",
"// Build a fake Model class based on attributes",
"return",
"$",
"this",
"->",
"transform",
"(",
"new",
"class",
"(",
"$",
"attributes",
")",
"extends",
"\\",
"stdClass",
"{",
"public",
"function",
"__construct",
"(",
"$",
"attributes",
")",
"{",
"$",
"this",
"->",
"attributes",
"=",
"$",
"attributes",
";",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"$",
"name",
"=",
"$",
"value",
";",
"}",
"}",
"public",
"function",
"toArray",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"attributes",
";",
"}",
"}",
")",
";",
"}"
] | Pack new Model data as JSON.
@return array | [
"Pack",
"new",
"Model",
"data",
"as",
"JSON",
"."
] | 6ce8f1613ed16da0564d8c63d7ebf6ae94343cca | https://github.com/code16/sharp/blob/6ce8f1613ed16da0564d8c63d7ebf6ae94343cca/src/Form/SharpForm.php#L211-L235 | train |
code16/sharp | src/EntityList/SharpEntityList.php | SharpEntityList.dataContainers | function dataContainers(): array
{
$this->checkListIsBuilt();
return collect($this->containers)->map(function(EntityListDataContainer $container) {
return $container->toArray();
})->keyBy("key")->all();
} | php | function dataContainers(): array
{
$this->checkListIsBuilt();
return collect($this->containers)->map(function(EntityListDataContainer $container) {
return $container->toArray();
})->keyBy("key")->all();
} | [
"function",
"dataContainers",
"(",
")",
":",
"array",
"{",
"$",
"this",
"->",
"checkListIsBuilt",
"(",
")",
";",
"return",
"collect",
"(",
"$",
"this",
"->",
"containers",
")",
"->",
"map",
"(",
"function",
"(",
"EntityListDataContainer",
"$",
"container",
")",
"{",
"return",
"$",
"container",
"->",
"toArray",
"(",
")",
";",
"}",
")",
"->",
"keyBy",
"(",
"\"key\"",
")",
"->",
"all",
"(",
")",
";",
"}"
] | Get the SharpListDataContainer array representation.
@return array | [
"Get",
"the",
"SharpListDataContainer",
"array",
"representation",
"."
] | 6ce8f1613ed16da0564d8c63d7ebf6ae94343cca | https://github.com/code16/sharp/blob/6ce8f1613ed16da0564d8c63d7ebf6ae94343cca/src/EntityList/SharpEntityList.php#L63-L70 | train |
code16/sharp | src/EntityList/SharpEntityList.php | SharpEntityList.listLayout | function listLayout(): array
{
if(!$this->layoutBuilt) {
$this->buildListLayout();
$this->layoutBuilt = true;
}
return collect($this->columns)->map(function(EntityListLayoutColumn $column) {
return $column->toArray();
})->all();
} | php | function listLayout(): array
{
if(!$this->layoutBuilt) {
$this->buildListLayout();
$this->layoutBuilt = true;
}
return collect($this->columns)->map(function(EntityListLayoutColumn $column) {
return $column->toArray();
})->all();
} | [
"function",
"listLayout",
"(",
")",
":",
"array",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"layoutBuilt",
")",
"{",
"$",
"this",
"->",
"buildListLayout",
"(",
")",
";",
"$",
"this",
"->",
"layoutBuilt",
"=",
"true",
";",
"}",
"return",
"collect",
"(",
"$",
"this",
"->",
"columns",
")",
"->",
"map",
"(",
"function",
"(",
"EntityListLayoutColumn",
"$",
"column",
")",
"{",
"return",
"$",
"column",
"->",
"toArray",
"(",
")",
";",
"}",
")",
"->",
"all",
"(",
")",
";",
"}"
] | Return the list fields layout.
@return array | [
"Return",
"the",
"list",
"fields",
"layout",
"."
] | 6ce8f1613ed16da0564d8c63d7ebf6ae94343cca | https://github.com/code16/sharp/blob/6ce8f1613ed16da0564d8c63d7ebf6ae94343cca/src/EntityList/SharpEntityList.php#L77-L87 | train |
code16/sharp | src/EntityList/SharpEntityList.php | SharpEntityList.listConfig | function listConfig(): array
{
$config = [
"instanceIdAttribute" => $this->instanceIdAttribute,
"multiformAttribute" => $this->multiformAttribute,
"displayMode" => $this->displayMode,
"searchable" => $this->searchable,
"paginated" => $this->paginated,
"reorderable" => !is_null($this->reorderHandler),
"defaultSort" => $this->defaultSort,
"defaultSortDir" => $this->defaultSortDir,
];
$this->appendFiltersToConfig($config);
$this->appendEntityStateToConfig($config);
$this->appendCommandsToConfig($config);
return $config;
} | php | function listConfig(): array
{
$config = [
"instanceIdAttribute" => $this->instanceIdAttribute,
"multiformAttribute" => $this->multiformAttribute,
"displayMode" => $this->displayMode,
"searchable" => $this->searchable,
"paginated" => $this->paginated,
"reorderable" => !is_null($this->reorderHandler),
"defaultSort" => $this->defaultSort,
"defaultSortDir" => $this->defaultSortDir,
];
$this->appendFiltersToConfig($config);
$this->appendEntityStateToConfig($config);
$this->appendCommandsToConfig($config);
return $config;
} | [
"function",
"listConfig",
"(",
")",
":",
"array",
"{",
"$",
"config",
"=",
"[",
"\"instanceIdAttribute\"",
"=>",
"$",
"this",
"->",
"instanceIdAttribute",
",",
"\"multiformAttribute\"",
"=>",
"$",
"this",
"->",
"multiformAttribute",
",",
"\"displayMode\"",
"=>",
"$",
"this",
"->",
"displayMode",
",",
"\"searchable\"",
"=>",
"$",
"this",
"->",
"searchable",
",",
"\"paginated\"",
"=>",
"$",
"this",
"->",
"paginated",
",",
"\"reorderable\"",
"=>",
"!",
"is_null",
"(",
"$",
"this",
"->",
"reorderHandler",
")",
",",
"\"defaultSort\"",
"=>",
"$",
"this",
"->",
"defaultSort",
",",
"\"defaultSortDir\"",
"=>",
"$",
"this",
"->",
"defaultSortDir",
",",
"]",
";",
"$",
"this",
"->",
"appendFiltersToConfig",
"(",
"$",
"config",
")",
";",
"$",
"this",
"->",
"appendEntityStateToConfig",
"(",
"$",
"config",
")",
";",
"$",
"this",
"->",
"appendCommandsToConfig",
"(",
"$",
"config",
")",
";",
"return",
"$",
"config",
";",
"}"
] | Return the data config values.
@return array | [
"Return",
"the",
"data",
"config",
"values",
"."
] | 6ce8f1613ed16da0564d8c63d7ebf6ae94343cca | https://github.com/code16/sharp/blob/6ce8f1613ed16da0564d8c63d7ebf6ae94343cca/src/EntityList/SharpEntityList.php#L139-L159 | train |
code16/sharp | src/EntityList/SharpEntityList.php | SharpEntityList.addDataContainer | protected function addDataContainer(EntityListDataContainer $container)
{
$this->containers[] = $container;
$this->listBuilt = false;
return $this;
} | php | protected function addDataContainer(EntityListDataContainer $container)
{
$this->containers[] = $container;
$this->listBuilt = false;
return $this;
} | [
"protected",
"function",
"addDataContainer",
"(",
"EntityListDataContainer",
"$",
"container",
")",
"{",
"$",
"this",
"->",
"containers",
"[",
"]",
"=",
"$",
"container",
";",
"$",
"this",
"->",
"listBuilt",
"=",
"false",
";",
"return",
"$",
"this",
";",
"}"
] | Add a data container.
@param EntityListDataContainer $container
@return $this | [
"Add",
"a",
"data",
"container",
"."
] | 6ce8f1613ed16da0564d8c63d7ebf6ae94343cca | https://github.com/code16/sharp/blob/6ce8f1613ed16da0564d8c63d7ebf6ae94343cca/src/EntityList/SharpEntityList.php#L261-L267 | train |
code16/sharp | src/Utils/Transformers/WithCustomTransformers.php | WithCustomTransformers.transform | function transform($models)
{
if($this instanceof SharpForm || $this instanceof Command) {
// It's a Form (full entity or from a Command), there's only one model.
// We must add Form Field Formatters in the process
return $this->applyFormatters(
$this->applyTransformers($models)
);
}
// SharpEntityList case
if($models instanceof LengthAwarePaginatorContract) {
return new LengthAwarePaginator(
$this->transform($models->items()),
$models->total(),
$models->perPage(),
$models->currentPage()
);
}
return collect($models)
->map(function($model) {
return $this->applyTransformers($model);
})
->all();
} | php | function transform($models)
{
if($this instanceof SharpForm || $this instanceof Command) {
// It's a Form (full entity or from a Command), there's only one model.
// We must add Form Field Formatters in the process
return $this->applyFormatters(
$this->applyTransformers($models)
);
}
// SharpEntityList case
if($models instanceof LengthAwarePaginatorContract) {
return new LengthAwarePaginator(
$this->transform($models->items()),
$models->total(),
$models->perPage(),
$models->currentPage()
);
}
return collect($models)
->map(function($model) {
return $this->applyTransformers($model);
})
->all();
} | [
"function",
"transform",
"(",
"$",
"models",
")",
"{",
"if",
"(",
"$",
"this",
"instanceof",
"SharpForm",
"||",
"$",
"this",
"instanceof",
"Command",
")",
"{",
"// It's a Form (full entity or from a Command), there's only one model.",
"// We must add Form Field Formatters in the process",
"return",
"$",
"this",
"->",
"applyFormatters",
"(",
"$",
"this",
"->",
"applyTransformers",
"(",
"$",
"models",
")",
")",
";",
"}",
"// SharpEntityList case",
"if",
"(",
"$",
"models",
"instanceof",
"LengthAwarePaginatorContract",
")",
"{",
"return",
"new",
"LengthAwarePaginator",
"(",
"$",
"this",
"->",
"transform",
"(",
"$",
"models",
"->",
"items",
"(",
")",
")",
",",
"$",
"models",
"->",
"total",
"(",
")",
",",
"$",
"models",
"->",
"perPage",
"(",
")",
",",
"$",
"models",
"->",
"currentPage",
"(",
")",
")",
";",
"}",
"return",
"collect",
"(",
"$",
"models",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"model",
")",
"{",
"return",
"$",
"this",
"->",
"applyTransformers",
"(",
"$",
"model",
")",
";",
"}",
")",
"->",
"all",
"(",
")",
";",
"}"
] | Transforms a model or a models collection into an array.
@param $models
@return array|LengthAwarePaginator | [
"Transforms",
"a",
"model",
"or",
"a",
"models",
"collection",
"into",
"an",
"array",
"."
] | 6ce8f1613ed16da0564d8c63d7ebf6ae94343cca | https://github.com/code16/sharp/blob/6ce8f1613ed16da0564d8c63d7ebf6ae94343cca/src/Utils/Transformers/WithCustomTransformers.php#L46-L72 | train |
code16/sharp | src/Http/Composers/MenuViewComposer.php | MenuViewComposer.compose | public function compose(View $view)
{
$menuItems = new Collection;
foreach (config("sharp.menu", []) as $menuItemConfig) {
if($menuItem = MenuItem::parse($menuItemConfig)) {
$menuItems->push($menuItem);
}
}
$view->with('sharpMenu', (object)[
"name" => config("sharp.name", "Sharp"),
"user" => sharp_user()->{config("sharp.auth.display_attribute", "name")},
"menuItems" => $menuItems,
"currentEntity" => isset($view->entityKey)
? explode(':', $view->entityKey)[0]
: ($view->dashboardKey ?? null)
]);
$view->with('hasGlobalFilters', sizeof(config('sharp.global_filters') ?? []) > 0);
} | php | public function compose(View $view)
{
$menuItems = new Collection;
foreach (config("sharp.menu", []) as $menuItemConfig) {
if($menuItem = MenuItem::parse($menuItemConfig)) {
$menuItems->push($menuItem);
}
}
$view->with('sharpMenu', (object)[
"name" => config("sharp.name", "Sharp"),
"user" => sharp_user()->{config("sharp.auth.display_attribute", "name")},
"menuItems" => $menuItems,
"currentEntity" => isset($view->entityKey)
? explode(':', $view->entityKey)[0]
: ($view->dashboardKey ?? null)
]);
$view->with('hasGlobalFilters', sizeof(config('sharp.global_filters') ?? []) > 0);
} | [
"public",
"function",
"compose",
"(",
"View",
"$",
"view",
")",
"{",
"$",
"menuItems",
"=",
"new",
"Collection",
";",
"foreach",
"(",
"config",
"(",
"\"sharp.menu\"",
",",
"[",
"]",
")",
"as",
"$",
"menuItemConfig",
")",
"{",
"if",
"(",
"$",
"menuItem",
"=",
"MenuItem",
"::",
"parse",
"(",
"$",
"menuItemConfig",
")",
")",
"{",
"$",
"menuItems",
"->",
"push",
"(",
"$",
"menuItem",
")",
";",
"}",
"}",
"$",
"view",
"->",
"with",
"(",
"'sharpMenu'",
",",
"(",
"object",
")",
"[",
"\"name\"",
"=>",
"config",
"(",
"\"sharp.name\"",
",",
"\"Sharp\"",
")",
",",
"\"user\"",
"=>",
"sharp_user",
"(",
")",
"->",
"{",
"config",
"(",
"\"sharp.auth.display_attribute\"",
",",
"\"name\"",
")",
"}",
",",
"\"menuItems\"",
"=>",
"$",
"menuItems",
",",
"\"currentEntity\"",
"=>",
"isset",
"(",
"$",
"view",
"->",
"entityKey",
")",
"?",
"explode",
"(",
"':'",
",",
"$",
"view",
"->",
"entityKey",
")",
"[",
"0",
"]",
":",
"(",
"$",
"view",
"->",
"dashboardKey",
"??",
"null",
")",
"]",
")",
";",
"$",
"view",
"->",
"with",
"(",
"'hasGlobalFilters'",
",",
"sizeof",
"(",
"config",
"(",
"'sharp.global_filters'",
")",
"??",
"[",
"]",
")",
">",
"0",
")",
";",
"}"
] | Build the menu and bind it to the view.
@param View $view
@return void | [
"Build",
"the",
"menu",
"and",
"bind",
"it",
"to",
"the",
"view",
"."
] | 6ce8f1613ed16da0564d8c63d7ebf6ae94343cca | https://github.com/code16/sharp/blob/6ce8f1613ed16da0564d8c63d7ebf6ae94343cca/src/Http/Composers/MenuViewComposer.php#L18-L38 | train |
code16/sharp | src/EntityList/Commands/Command.php | Command.validate | public function validate(array $params, array $rules, array $messages = [])
{
$validator = app(Validator::class)->make($params, $rules, $messages);
if ($validator->fails()) {
throw new ValidationException(
$validator, new JsonResponse($validator->errors()->getMessages(), 422)
);
}
} | php | public function validate(array $params, array $rules, array $messages = [])
{
$validator = app(Validator::class)->make($params, $rules, $messages);
if ($validator->fails()) {
throw new ValidationException(
$validator, new JsonResponse($validator->errors()->getMessages(), 422)
);
}
} | [
"public",
"function",
"validate",
"(",
"array",
"$",
"params",
",",
"array",
"$",
"rules",
",",
"array",
"$",
"messages",
"=",
"[",
"]",
")",
"{",
"$",
"validator",
"=",
"app",
"(",
"Validator",
"::",
"class",
")",
"->",
"make",
"(",
"$",
"params",
",",
"$",
"rules",
",",
"$",
"messages",
")",
";",
"if",
"(",
"$",
"validator",
"->",
"fails",
"(",
")",
")",
"{",
"throw",
"new",
"ValidationException",
"(",
"$",
"validator",
",",
"new",
"JsonResponse",
"(",
"$",
"validator",
"->",
"errors",
"(",
")",
"->",
"getMessages",
"(",
")",
",",
"422",
")",
")",
";",
"}",
"}"
] | Validates the request in a form case.
@param array $params
@param array $rules
@param array $messages
@throws ValidationException | [
"Validates",
"the",
"request",
"in",
"a",
"form",
"case",
"."
] | 6ce8f1613ed16da0564d8c63d7ebf6ae94343cca | https://github.com/code16/sharp/blob/6ce8f1613ed16da0564d8c63d7ebf6ae94343cca/src/EntityList/Commands/Command.php#L196-L205 | train |
code16/sharp | src/EntityList/Traits/HandleCommands.php | HandleCommands.appendCommandsToConfig | protected function appendCommandsToConfig(array &$config)
{
collect($this->entityCommandHandlers)
->merge(collect($this->instanceCommandHandlers))
->each(function($handler, $commandName) use(&$config) {
$formFields = $handler->form();
$formLayout = $formFields ? $handler->formLayout() : null;
$hasFormInitialData = $formFields
? is_method_implemented_in_concrete_class($handler, 'initialData')
: false;
$config["commands"][$handler->type()][$handler->groupIndex()][] = [
"key" => $commandName,
"label" => $handler->label(),
"description" => $handler->description(),
"type" => $handler->type(),
"confirmation" => $handler->confirmationText() ?: null,
"form" => $formFields ? [
"fields" => $formFields,
"layout" => $formLayout
] : null,
"fetch_initial_data" => $hasFormInitialData,
"authorization" => $handler->getGlobalAuthorization()
];
});
} | php | protected function appendCommandsToConfig(array &$config)
{
collect($this->entityCommandHandlers)
->merge(collect($this->instanceCommandHandlers))
->each(function($handler, $commandName) use(&$config) {
$formFields = $handler->form();
$formLayout = $formFields ? $handler->formLayout() : null;
$hasFormInitialData = $formFields
? is_method_implemented_in_concrete_class($handler, 'initialData')
: false;
$config["commands"][$handler->type()][$handler->groupIndex()][] = [
"key" => $commandName,
"label" => $handler->label(),
"description" => $handler->description(),
"type" => $handler->type(),
"confirmation" => $handler->confirmationText() ?: null,
"form" => $formFields ? [
"fields" => $formFields,
"layout" => $formLayout
] : null,
"fetch_initial_data" => $hasFormInitialData,
"authorization" => $handler->getGlobalAuthorization()
];
});
} | [
"protected",
"function",
"appendCommandsToConfig",
"(",
"array",
"&",
"$",
"config",
")",
"{",
"collect",
"(",
"$",
"this",
"->",
"entityCommandHandlers",
")",
"->",
"merge",
"(",
"collect",
"(",
"$",
"this",
"->",
"instanceCommandHandlers",
")",
")",
"->",
"each",
"(",
"function",
"(",
"$",
"handler",
",",
"$",
"commandName",
")",
"use",
"(",
"&",
"$",
"config",
")",
"{",
"$",
"formFields",
"=",
"$",
"handler",
"->",
"form",
"(",
")",
";",
"$",
"formLayout",
"=",
"$",
"formFields",
"?",
"$",
"handler",
"->",
"formLayout",
"(",
")",
":",
"null",
";",
"$",
"hasFormInitialData",
"=",
"$",
"formFields",
"?",
"is_method_implemented_in_concrete_class",
"(",
"$",
"handler",
",",
"'initialData'",
")",
":",
"false",
";",
"$",
"config",
"[",
"\"commands\"",
"]",
"[",
"$",
"handler",
"->",
"type",
"(",
")",
"]",
"[",
"$",
"handler",
"->",
"groupIndex",
"(",
")",
"]",
"[",
"]",
"=",
"[",
"\"key\"",
"=>",
"$",
"commandName",
",",
"\"label\"",
"=>",
"$",
"handler",
"->",
"label",
"(",
")",
",",
"\"description\"",
"=>",
"$",
"handler",
"->",
"description",
"(",
")",
",",
"\"type\"",
"=>",
"$",
"handler",
"->",
"type",
"(",
")",
",",
"\"confirmation\"",
"=>",
"$",
"handler",
"->",
"confirmationText",
"(",
")",
"?",
":",
"null",
",",
"\"form\"",
"=>",
"$",
"formFields",
"?",
"[",
"\"fields\"",
"=>",
"$",
"formFields",
",",
"\"layout\"",
"=>",
"$",
"formLayout",
"]",
":",
"null",
",",
"\"fetch_initial_data\"",
"=>",
"$",
"hasFormInitialData",
",",
"\"authorization\"",
"=>",
"$",
"handler",
"->",
"getGlobalAuthorization",
"(",
")",
"]",
";",
"}",
")",
";",
"}"
] | Append the commands to the config returned to the front.
@param array $config | [
"Append",
"the",
"commands",
"to",
"the",
"config",
"returned",
"to",
"the",
"front",
"."
] | 6ce8f1613ed16da0564d8c63d7ebf6ae94343cca | https://github.com/code16/sharp/blob/6ce8f1613ed16da0564d8c63d7ebf6ae94343cca/src/EntityList/Traits/HandleCommands.php#L84-L109 | train |
code16/sharp | src/Dashboard/SharpDashboard.php | SharpDashboard.addWidget | protected function addWidget(SharpWidget $widget)
{
$this->widgets[] = $widget;
$this->dashboardBuilt = false;
return $this;
} | php | protected function addWidget(SharpWidget $widget)
{
$this->widgets[] = $widget;
$this->dashboardBuilt = false;
return $this;
} | [
"protected",
"function",
"addWidget",
"(",
"SharpWidget",
"$",
"widget",
")",
"{",
"$",
"this",
"->",
"widgets",
"[",
"]",
"=",
"$",
"widget",
";",
"$",
"this",
"->",
"dashboardBuilt",
"=",
"false",
";",
"return",
"$",
"this",
";",
"}"
] | Add a widget.
@param SharpWidget $widget
@return $this | [
"Add",
"a",
"widget",
"."
] | 6ce8f1613ed16da0564d8c63d7ebf6ae94343cca | https://github.com/code16/sharp/blob/6ce8f1613ed16da0564d8c63d7ebf6ae94343cca/src/Dashboard/SharpDashboard.php#L51-L57 | train |
code16/sharp | src/Dashboard/SharpDashboard.php | SharpDashboard.addFullWidthWidget | protected function addFullWidthWidget(string $widgetKey)
{
$this->layoutBuilt = false;
$this->addRow(function(DashboardLayoutRow $row) use ($widgetKey) {
$row->addWidget(12, $widgetKey);
});
return $this;
} | php | protected function addFullWidthWidget(string $widgetKey)
{
$this->layoutBuilt = false;
$this->addRow(function(DashboardLayoutRow $row) use ($widgetKey) {
$row->addWidget(12, $widgetKey);
});
return $this;
} | [
"protected",
"function",
"addFullWidthWidget",
"(",
"string",
"$",
"widgetKey",
")",
"{",
"$",
"this",
"->",
"layoutBuilt",
"=",
"false",
";",
"$",
"this",
"->",
"addRow",
"(",
"function",
"(",
"DashboardLayoutRow",
"$",
"row",
")",
"use",
"(",
"$",
"widgetKey",
")",
"{",
"$",
"row",
"->",
"addWidget",
"(",
"12",
",",
"$",
"widgetKey",
")",
";",
"}",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add a new row with a single widget.
@param string $widgetKey
@return $this | [
"Add",
"a",
"new",
"row",
"with",
"a",
"single",
"widget",
"."
] | 6ce8f1613ed16da0564d8c63d7ebf6ae94343cca | https://github.com/code16/sharp/blob/6ce8f1613ed16da0564d8c63d7ebf6ae94343cca/src/Dashboard/SharpDashboard.php#L65-L74 | train |
code16/sharp | src/Dashboard/SharpDashboard.php | SharpDashboard.addRow | protected function addRow(\Closure $callback)
{
$row = new DashboardLayoutRow();
$callback($row);
$this->rows[] = $row;
return $this;
} | php | protected function addRow(\Closure $callback)
{
$row = new DashboardLayoutRow();
$callback($row);
$this->rows[] = $row;
return $this;
} | [
"protected",
"function",
"addRow",
"(",
"\\",
"Closure",
"$",
"callback",
")",
"{",
"$",
"row",
"=",
"new",
"DashboardLayoutRow",
"(",
")",
";",
"$",
"callback",
"(",
"$",
"row",
")",
";",
"$",
"this",
"->",
"rows",
"[",
"]",
"=",
"$",
"row",
";",
"return",
"$",
"this",
";",
"}"
] | Add a new row.
@param \Closure $callback
@return $this | [
"Add",
"a",
"new",
"row",
"."
] | 6ce8f1613ed16da0564d8c63d7ebf6ae94343cca | https://github.com/code16/sharp/blob/6ce8f1613ed16da0564d8c63d7ebf6ae94343cca/src/Dashboard/SharpDashboard.php#L82-L91 | train |
code16/sharp | src/Dashboard/SharpDashboard.php | SharpDashboard.widgetsLayout | function widgetsLayout(): array
{
if(!$this->layoutBuilt) {
$this->buildWidgetsLayout();
$this->layoutBuilt = true;
}
return [
"rows" => collect($this->rows)->map(function(DashboardLayoutRow $row) {
return $row->toArray();
})->all()
];
} | php | function widgetsLayout(): array
{
if(!$this->layoutBuilt) {
$this->buildWidgetsLayout();
$this->layoutBuilt = true;
}
return [
"rows" => collect($this->rows)->map(function(DashboardLayoutRow $row) {
return $row->toArray();
})->all()
];
} | [
"function",
"widgetsLayout",
"(",
")",
":",
"array",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"layoutBuilt",
")",
"{",
"$",
"this",
"->",
"buildWidgetsLayout",
"(",
")",
";",
"$",
"this",
"->",
"layoutBuilt",
"=",
"true",
";",
"}",
"return",
"[",
"\"rows\"",
"=>",
"collect",
"(",
"$",
"this",
"->",
"rows",
")",
"->",
"map",
"(",
"function",
"(",
"DashboardLayoutRow",
"$",
"row",
")",
"{",
"return",
"$",
"row",
"->",
"toArray",
"(",
")",
";",
"}",
")",
"->",
"all",
"(",
")",
"]",
";",
"}"
] | Return the dashboard widgets layout.
@return array | [
"Return",
"the",
"dashboard",
"widgets",
"layout",
"."
] | 6ce8f1613ed16da0564d8c63d7ebf6ae94343cca | https://github.com/code16/sharp/blob/6ce8f1613ed16da0564d8c63d7ebf6ae94343cca/src/Dashboard/SharpDashboard.php#L107-L119 | train |
Art-of-WiFi/UniFi-API-client | src/Client.php | Client.process_response | protected function process_response($response_json)
{
$response = json_decode($response_json);
$this->catch_json_last_error();
$this->last_results_raw = $response;
if (isset($response->meta->rc)) {
if ($response->meta->rc === 'ok') {
$this->last_error_message = null;
if (is_array($response->data)) {
return $response->data;
}
return true;
} elseif ($response->meta->rc === 'error') {
/**
* we have an error:
* set $this->set last_error_message if the returned error message is available
*/
if (isset($response->meta->msg)) {
$this->last_error_message = $response->meta->msg;
}
if ($this->debug) {
trigger_error('Debug: Last error message: ' . $this->last_error_message);
}
}
}
return false;
} | php | protected function process_response($response_json)
{
$response = json_decode($response_json);
$this->catch_json_last_error();
$this->last_results_raw = $response;
if (isset($response->meta->rc)) {
if ($response->meta->rc === 'ok') {
$this->last_error_message = null;
if (is_array($response->data)) {
return $response->data;
}
return true;
} elseif ($response->meta->rc === 'error') {
/**
* we have an error:
* set $this->set last_error_message if the returned error message is available
*/
if (isset($response->meta->msg)) {
$this->last_error_message = $response->meta->msg;
}
if ($this->debug) {
trigger_error('Debug: Last error message: ' . $this->last_error_message);
}
}
}
return false;
} | [
"protected",
"function",
"process_response",
"(",
"$",
"response_json",
")",
"{",
"$",
"response",
"=",
"json_decode",
"(",
"$",
"response_json",
")",
";",
"$",
"this",
"->",
"catch_json_last_error",
"(",
")",
";",
"$",
"this",
"->",
"last_results_raw",
"=",
"$",
"response",
";",
"if",
"(",
"isset",
"(",
"$",
"response",
"->",
"meta",
"->",
"rc",
")",
")",
"{",
"if",
"(",
"$",
"response",
"->",
"meta",
"->",
"rc",
"===",
"'ok'",
")",
"{",
"$",
"this",
"->",
"last_error_message",
"=",
"null",
";",
"if",
"(",
"is_array",
"(",
"$",
"response",
"->",
"data",
")",
")",
"{",
"return",
"$",
"response",
"->",
"data",
";",
"}",
"return",
"true",
";",
"}",
"elseif",
"(",
"$",
"response",
"->",
"meta",
"->",
"rc",
"===",
"'error'",
")",
"{",
"/**\n * we have an error:\n * set $this->set last_error_message if the returned error message is available\n */",
"if",
"(",
"isset",
"(",
"$",
"response",
"->",
"meta",
"->",
"msg",
")",
")",
"{",
"$",
"this",
"->",
"last_error_message",
"=",
"$",
"response",
"->",
"meta",
"->",
"msg",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"debug",
")",
"{",
"trigger_error",
"(",
"'Debug: Last error message: '",
".",
"$",
"this",
"->",
"last_error_message",
")",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | Process regular responses where output is the content of the data array | [
"Process",
"regular",
"responses",
"where",
"output",
"is",
"the",
"content",
"of",
"the",
"data",
"array"
] | 09db47affd6a006d6ff71236a581e61fd7d9901b | https://github.com/Art-of-WiFi/UniFi-API-client/blob/09db47affd6a006d6ff71236a581e61fd7d9901b/src/Client.php#L3332-L3360 | train |
Art-of-WiFi/UniFi-API-client | src/Client.php | Client.check_base_url | private function check_base_url()
{
$url_valid = filter_var($this->baseurl, FILTER_VALIDATE_URL);
if (!$url_valid) {
trigger_error('The URL provided is incomplete or invalid!');
return false;
}
$base_url_components = parse_url($this->baseurl);
if (empty($base_url_components['port'])) {
trigger_error('The URL provided does not have a port suffix, normally this is :8443');
return false;
}
return true;
} | php | private function check_base_url()
{
$url_valid = filter_var($this->baseurl, FILTER_VALIDATE_URL);
if (!$url_valid) {
trigger_error('The URL provided is incomplete or invalid!');
return false;
}
$base_url_components = parse_url($this->baseurl);
if (empty($base_url_components['port'])) {
trigger_error('The URL provided does not have a port suffix, normally this is :8443');
return false;
}
return true;
} | [
"private",
"function",
"check_base_url",
"(",
")",
"{",
"$",
"url_valid",
"=",
"filter_var",
"(",
"$",
"this",
"->",
"baseurl",
",",
"FILTER_VALIDATE_URL",
")",
";",
"if",
"(",
"!",
"$",
"url_valid",
")",
"{",
"trigger_error",
"(",
"'The URL provided is incomplete or invalid!'",
")",
";",
"return",
"false",
";",
"}",
"$",
"base_url_components",
"=",
"parse_url",
"(",
"$",
"this",
"->",
"baseurl",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"base_url_components",
"[",
"'port'",
"]",
")",
")",
"{",
"trigger_error",
"(",
"'The URL provided does not have a port suffix, normally this is :8443'",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Check the submitted base URL | [
"Check",
"the",
"submitted",
"base",
"URL"
] | 09db47affd6a006d6ff71236a581e61fd7d9901b | https://github.com/Art-of-WiFi/UniFi-API-client/blob/09db47affd6a006d6ff71236a581e61fd7d9901b/src/Client.php#L3457-L3474 | train |
Art-of-WiFi/UniFi-API-client | src/Client.php | Client.get_curl_obj | protected function get_curl_obj()
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->curl_ssl_verify_peer);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $this->curl_ssl_verify_host);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connect_timeout);
if ($this->debug) {
curl_setopt($ch, CURLOPT_VERBOSE, true);
}
if ($this->cookies != '') {
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIE, $this->cookies);
}
return $ch;
} | php | protected function get_curl_obj()
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->curl_ssl_verify_peer);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $this->curl_ssl_verify_host);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connect_timeout);
if ($this->debug) {
curl_setopt($ch, CURLOPT_VERBOSE, true);
}
if ($this->cookies != '') {
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIE, $this->cookies);
}
return $ch;
} | [
"protected",
"function",
"get_curl_obj",
"(",
")",
"{",
"$",
"ch",
"=",
"curl_init",
"(",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_POST",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_SSL_VERIFYPEER",
",",
"$",
"this",
"->",
"curl_ssl_verify_peer",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_SSL_VERIFYHOST",
",",
"$",
"this",
"->",
"curl_ssl_verify_host",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_RETURNTRANSFER",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_CONNECTTIMEOUT",
",",
"$",
"this",
"->",
"connect_timeout",
")",
";",
"if",
"(",
"$",
"this",
"->",
"debug",
")",
"{",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_VERBOSE",
",",
"true",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"cookies",
"!=",
"''",
")",
"{",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_COOKIESESSION",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_COOKIE",
",",
"$",
"this",
"->",
"cookies",
")",
";",
"}",
"return",
"$",
"ch",
";",
"}"
] | Get the cURL object | [
"Get",
"the",
"cURL",
"object"
] | 09db47affd6a006d6ff71236a581e61fd7d9901b | https://github.com/Art-of-WiFi/UniFi-API-client/blob/09db47affd6a006d6ff71236a581e61fd7d9901b/src/Client.php#L3609-L3628 | train |
bitfumes/laravel-multiauth | src/Console/Commands/RollbackMultiAuthCommand.php | RollbackMultiAuthCommand.parseName | protected function parseName($name = null)
{
if (!$name) {
$name = $this->name;
}
return [
'{{pluralCamel}}' => str_plural(camel_case($name)),
'{{pluralSlug}}' => str_plural(str_slug($name)),
'{{pluralSnake}}' => str_plural(snake_case($name)),
'{{pluralClass}}' => str_plural(studly_case($name)),
'{{singularCamel}}' => str_singular(camel_case($name)),
'{{singularSlug}}' => str_singular(str_slug($name)),
'{{singularSnake}}' => str_singular(snake_case($name)),
'{{singularClass}}' => str_singular(studly_case($name)),
'{{namespace}}' => $this->getNamespace(),
];
} | php | protected function parseName($name = null)
{
if (!$name) {
$name = $this->name;
}
return [
'{{pluralCamel}}' => str_plural(camel_case($name)),
'{{pluralSlug}}' => str_plural(str_slug($name)),
'{{pluralSnake}}' => str_plural(snake_case($name)),
'{{pluralClass}}' => str_plural(studly_case($name)),
'{{singularCamel}}' => str_singular(camel_case($name)),
'{{singularSlug}}' => str_singular(str_slug($name)),
'{{singularSnake}}' => str_singular(snake_case($name)),
'{{singularClass}}' => str_singular(studly_case($name)),
'{{namespace}}' => $this->getNamespace(),
];
} | [
"protected",
"function",
"parseName",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"name",
";",
"}",
"return",
"[",
"'{{pluralCamel}}'",
"=>",
"str_plural",
"(",
"camel_case",
"(",
"$",
"name",
")",
")",
",",
"'{{pluralSlug}}'",
"=>",
"str_plural",
"(",
"str_slug",
"(",
"$",
"name",
")",
")",
",",
"'{{pluralSnake}}'",
"=>",
"str_plural",
"(",
"snake_case",
"(",
"$",
"name",
")",
")",
",",
"'{{pluralClass}}'",
"=>",
"str_plural",
"(",
"studly_case",
"(",
"$",
"name",
")",
")",
",",
"'{{singularCamel}}'",
"=>",
"str_singular",
"(",
"camel_case",
"(",
"$",
"name",
")",
")",
",",
"'{{singularSlug}}'",
"=>",
"str_singular",
"(",
"str_slug",
"(",
"$",
"name",
")",
")",
",",
"'{{singularSnake}}'",
"=>",
"str_singular",
"(",
"snake_case",
"(",
"$",
"name",
")",
")",
",",
"'{{singularClass}}'",
"=>",
"str_singular",
"(",
"studly_case",
"(",
"$",
"name",
")",
")",
",",
"'{{namespace}}'",
"=>",
"$",
"this",
"->",
"getNamespace",
"(",
")",
",",
"]",
";",
"}"
] | Parse guard name
Get the guard name in different cases.
@param string $name
@return array | [
"Parse",
"guard",
"name",
"Get",
"the",
"guard",
"name",
"in",
"different",
"cases",
"."
] | 3582a7d85e44760cf73d1f7b66e3603e853f4ff6 | https://github.com/bitfumes/laravel-multiauth/blob/3582a7d85e44760cf73d1f7b66e3603e853f4ff6/src/Console/Commands/RollbackMultiAuthCommand.php#L240-L257 | train |
stavarengo/php-sigep | src/PhpSigep/Cache/Storage/Adapter/FileSystemOptions.php | FileSystemOptions.setCacheDir | public function setCacheDir($cacheDir)
{
if ($cacheDir !== null) {
if (!is_dir($cacheDir)) {
throw new Exception\InvalidArgumentException(
"Cache directory '{$cacheDir}' not found or not a directory"
);
} elseif (!is_writable($cacheDir)) {
throw new Exception\InvalidArgumentException(
"Cache directory '{$cacheDir}' not writable"
);
} elseif (!is_readable($cacheDir)) {
throw new Exception\InvalidArgumentException(
"Cache directory '{$cacheDir}' not readable"
);
}
$cacheDir = rtrim(realpath($cacheDir), DIRECTORY_SEPARATOR);
} else {
$cacheDir = sys_get_temp_dir();
}
$this->cacheDir = $cacheDir;
return $this;
} | php | public function setCacheDir($cacheDir)
{
if ($cacheDir !== null) {
if (!is_dir($cacheDir)) {
throw new Exception\InvalidArgumentException(
"Cache directory '{$cacheDir}' not found or not a directory"
);
} elseif (!is_writable($cacheDir)) {
throw new Exception\InvalidArgumentException(
"Cache directory '{$cacheDir}' not writable"
);
} elseif (!is_readable($cacheDir)) {
throw new Exception\InvalidArgumentException(
"Cache directory '{$cacheDir}' not readable"
);
}
$cacheDir = rtrim(realpath($cacheDir), DIRECTORY_SEPARATOR);
} else {
$cacheDir = sys_get_temp_dir();
}
$this->cacheDir = $cacheDir;
return $this;
} | [
"public",
"function",
"setCacheDir",
"(",
"$",
"cacheDir",
")",
"{",
"if",
"(",
"$",
"cacheDir",
"!==",
"null",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"cacheDir",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"\"Cache directory '{$cacheDir}' not found or not a directory\"",
")",
";",
"}",
"elseif",
"(",
"!",
"is_writable",
"(",
"$",
"cacheDir",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"\"Cache directory '{$cacheDir}' not writable\"",
")",
";",
"}",
"elseif",
"(",
"!",
"is_readable",
"(",
"$",
"cacheDir",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"\"Cache directory '{$cacheDir}' not readable\"",
")",
";",
"}",
"$",
"cacheDir",
"=",
"rtrim",
"(",
"realpath",
"(",
"$",
"cacheDir",
")",
",",
"DIRECTORY_SEPARATOR",
")",
";",
"}",
"else",
"{",
"$",
"cacheDir",
"=",
"sys_get_temp_dir",
"(",
")",
";",
"}",
"$",
"this",
"->",
"cacheDir",
"=",
"$",
"cacheDir",
";",
"return",
"$",
"this",
";",
"}"
] | Set cache dir
@param string $cacheDir
@return FilesystemOptions
@throws Exception\InvalidArgumentException | [
"Set",
"cache",
"dir"
] | c765d83dc93d64ca44801de93759868770fc4733 | https://github.com/stavarengo/php-sigep/blob/c765d83dc93d64ca44801de93759868770fc4733/src/PhpSigep/Cache/Storage/Adapter/FileSystemOptions.php#L102-L127 | train |
stavarengo/php-sigep | src/PhpSigep/Cache/Storage/Adapter/FileSystemOptions.php | FileSystemOptions.setDirLevel | public function setDirLevel($dirLevel)
{
$dirLevel = (int)$dirLevel;
if ($dirLevel < 0 || $dirLevel > 16) {
throw new Exception\InvalidArgumentException(
"Directory level '{$dirLevel}' must be between 0 and 16"
);
}
$this->dirLevel = $dirLevel;
return $this;
} | php | public function setDirLevel($dirLevel)
{
$dirLevel = (int)$dirLevel;
if ($dirLevel < 0 || $dirLevel > 16) {
throw new Exception\InvalidArgumentException(
"Directory level '{$dirLevel}' must be between 0 and 16"
);
}
$this->dirLevel = $dirLevel;
return $this;
} | [
"public",
"function",
"setDirLevel",
"(",
"$",
"dirLevel",
")",
"{",
"$",
"dirLevel",
"=",
"(",
"int",
")",
"$",
"dirLevel",
";",
"if",
"(",
"$",
"dirLevel",
"<",
"0",
"||",
"$",
"dirLevel",
">",
"16",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"\"Directory level '{$dirLevel}' must be between 0 and 16\"",
")",
";",
"}",
"$",
"this",
"->",
"dirLevel",
"=",
"$",
"dirLevel",
";",
"return",
"$",
"this",
";",
"}"
] | Set dir level
@param int $dirLevel
@return FilesystemOptions
@throws Exception\InvalidArgumentException | [
"Set",
"dir",
"level"
] | c765d83dc93d64ca44801de93759868770fc4733 | https://github.com/stavarengo/php-sigep/blob/c765d83dc93d64ca44801de93759868770fc4733/src/PhpSigep/Cache/Storage/Adapter/FileSystemOptions.php#L174-L185 | train |
stavarengo/php-sigep | src/PhpSigep/Cache/Storage/Adapter/FileSystemOptions.php | FileSystemOptions.setDirPermission | public function setDirPermission($dirPermission)
{
if ($dirPermission !== false) {
if (is_string($dirPermission)) {
$dirPermission = octdec($dirPermission);
} else {
$dirPermission = (int)$dirPermission;
}
// validate
if (($dirPermission & 0700) != 0700) {
throw new Exception\InvalidArgumentException(
'Invalid directory permission: need permission to execute, read and write by owner'
);
}
}
if ($this->dirPermission !== $dirPermission) {
$this->dirPermission = $dirPermission;
}
return $this;
} | php | public function setDirPermission($dirPermission)
{
if ($dirPermission !== false) {
if (is_string($dirPermission)) {
$dirPermission = octdec($dirPermission);
} else {
$dirPermission = (int)$dirPermission;
}
// validate
if (($dirPermission & 0700) != 0700) {
throw new Exception\InvalidArgumentException(
'Invalid directory permission: need permission to execute, read and write by owner'
);
}
}
if ($this->dirPermission !== $dirPermission) {
$this->dirPermission = $dirPermission;
}
return $this;
} | [
"public",
"function",
"setDirPermission",
"(",
"$",
"dirPermission",
")",
"{",
"if",
"(",
"$",
"dirPermission",
"!==",
"false",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"dirPermission",
")",
")",
"{",
"$",
"dirPermission",
"=",
"octdec",
"(",
"$",
"dirPermission",
")",
";",
"}",
"else",
"{",
"$",
"dirPermission",
"=",
"(",
"int",
")",
"$",
"dirPermission",
";",
"}",
"// validate",
"if",
"(",
"(",
"$",
"dirPermission",
"&",
"0700",
")",
"!=",
"0700",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"'Invalid directory permission: need permission to execute, read and write by owner'",
")",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"dirPermission",
"!==",
"$",
"dirPermission",
")",
"{",
"$",
"this",
"->",
"dirPermission",
"=",
"$",
"dirPermission",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set permission to create directories on unix systems
@param false|string|int $dirPermission FALSE to disable explicit permission or an octal number
@throws Exception\InvalidArgumentException
@return FilesystemOptions
@see setUmask
@see setFilePermission
@link http://php.net/manual/function.chmod.php | [
"Set",
"permission",
"to",
"create",
"directories",
"on",
"unix",
"systems"
] | c765d83dc93d64ca44801de93759868770fc4733 | https://github.com/stavarengo/php-sigep/blob/c765d83dc93d64ca44801de93759868770fc4733/src/PhpSigep/Cache/Storage/Adapter/FileSystemOptions.php#L206-L228 | train |
stavarengo/php-sigep | src/PhpSigep/Cache/Storage/Adapter/FileSystemOptions.php | FileSystemOptions.setFilePermission | public function setFilePermission($filePermission)
{
if ($filePermission !== false) {
if (is_string($filePermission)) {
$filePermission = octdec($filePermission);
} else {
$filePermission = (int)$filePermission;
}
// validate
if (($filePermission & 0600) != 0600) {
throw new Exception\InvalidArgumentException(
'Invalid file permission: need permission to read and write by owner'
);
} elseif ($filePermission & 0111) {
throw new Exception\InvalidArgumentException(
"Invalid file permission: Cache files shoudn't be executable"
);
}
}
if ($this->filePermission !== $filePermission) {
$this->filePermission = $filePermission;
}
return $this;
} | php | public function setFilePermission($filePermission)
{
if ($filePermission !== false) {
if (is_string($filePermission)) {
$filePermission = octdec($filePermission);
} else {
$filePermission = (int)$filePermission;
}
// validate
if (($filePermission & 0600) != 0600) {
throw new Exception\InvalidArgumentException(
'Invalid file permission: need permission to read and write by owner'
);
} elseif ($filePermission & 0111) {
throw new Exception\InvalidArgumentException(
"Invalid file permission: Cache files shoudn't be executable"
);
}
}
if ($this->filePermission !== $filePermission) {
$this->filePermission = $filePermission;
}
return $this;
} | [
"public",
"function",
"setFilePermission",
"(",
"$",
"filePermission",
")",
"{",
"if",
"(",
"$",
"filePermission",
"!==",
"false",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"filePermission",
")",
")",
"{",
"$",
"filePermission",
"=",
"octdec",
"(",
"$",
"filePermission",
")",
";",
"}",
"else",
"{",
"$",
"filePermission",
"=",
"(",
"int",
")",
"$",
"filePermission",
";",
"}",
"// validate",
"if",
"(",
"(",
"$",
"filePermission",
"&",
"0600",
")",
"!=",
"0600",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"'Invalid file permission: need permission to read and write by owner'",
")",
";",
"}",
"elseif",
"(",
"$",
"filePermission",
"&",
"0111",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid file permission: Cache files shoudn't be executable\"",
")",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"filePermission",
"!==",
"$",
"filePermission",
")",
"{",
"$",
"this",
"->",
"filePermission",
"=",
"$",
"filePermission",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set permission to create files on unix systems
@param false|string|int $filePermission FALSE to disable explicit permission or an octal number
@throws Exception\InvalidArgumentException
@return FilesystemOptions
@see setUmask
@see setDirPermission
@link http://php.net/manual/function.chmod.php | [
"Set",
"permission",
"to",
"create",
"files",
"on",
"unix",
"systems"
] | c765d83dc93d64ca44801de93759868770fc4733 | https://github.com/stavarengo/php-sigep/blob/c765d83dc93d64ca44801de93759868770fc4733/src/PhpSigep/Cache/Storage/Adapter/FileSystemOptions.php#L274-L300 | train |
stavarengo/php-sigep | src/PhpSigep/Cache/Storage/Adapter/FileSystemOptions.php | FileSystemOptions.setUmask | public function setUmask($umask)
{
if ($umask !== false) {
if (is_string($umask)) {
$umask = octdec($umask);
} else {
$umask = (int)$umask;
}
// validate
if ($umask & 0700) {
throw new Exception\InvalidArgumentException(
'Invalid umask: need permission to execute, read and write by owner'
);
}
// normalize
$umask = $umask & 0777;
}
if ($this->umask !== $umask) {
$this->umask = $umask;
}
return $this;
} | php | public function setUmask($umask)
{
if ($umask !== false) {
if (is_string($umask)) {
$umask = octdec($umask);
} else {
$umask = (int)$umask;
}
// validate
if ($umask & 0700) {
throw new Exception\InvalidArgumentException(
'Invalid umask: need permission to execute, read and write by owner'
);
}
// normalize
$umask = $umask & 0777;
}
if ($this->umask !== $umask) {
$this->umask = $umask;
}
return $this;
} | [
"public",
"function",
"setUmask",
"(",
"$",
"umask",
")",
"{",
"if",
"(",
"$",
"umask",
"!==",
"false",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"umask",
")",
")",
"{",
"$",
"umask",
"=",
"octdec",
"(",
"$",
"umask",
")",
";",
"}",
"else",
"{",
"$",
"umask",
"=",
"(",
"int",
")",
"$",
"umask",
";",
"}",
"// validate",
"if",
"(",
"$",
"umask",
"&",
"0700",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"'Invalid umask: need permission to execute, read and write by owner'",
")",
";",
"}",
"// normalize",
"$",
"umask",
"=",
"$",
"umask",
"&",
"0777",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"umask",
"!==",
"$",
"umask",
")",
"{",
"$",
"this",
"->",
"umask",
"=",
"$",
"umask",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set the umask to create files and directories on unix systems
Note: On multithreaded webservers it's better to explicit set file and dir permission.
@param false|string|int $umask FALSE to disable umask or an octal number
@throws Exception\InvalidArgumentException
@return FilesystemOptions
@see setFilePermission
@see setDirPermission
@link http://php.net/manual/function.umask.php
@link http://en.wikipedia.org/wiki/Umask | [
"Set",
"the",
"umask",
"to",
"create",
"files",
"and",
"directories",
"on",
"unix",
"systems"
] | c765d83dc93d64ca44801de93759868770fc4733 | https://github.com/stavarengo/php-sigep/blob/c765d83dc93d64ca44801de93759868770fc4733/src/PhpSigep/Cache/Storage/Adapter/FileSystemOptions.php#L349-L374 | train |
stavarengo/php-sigep | src/PhpSigep/Cache/Storage/Adapter/AdapterOptions.php | AdapterOptions.setKeyPattern | public function setKeyPattern($keyPattern)
{
$keyPattern = (string)$keyPattern;
if ($this->keyPattern !== $keyPattern) {
// validate pattern
if ($keyPattern !== '') {
ErrorHandler::start(E_WARNING);
$result = preg_match($keyPattern, '');
$error = ErrorHandler::stop();
if ($result === false) {
throw new Exception\InvalidArgumentException(
sprintf(
'Invalid pattern "%s"%s',
$keyPattern,
($error ? ': ' . $error->getMessage() : '')
),
0,
$error
);
}
}
$this->keyPattern = $keyPattern;
}
return $this;
} | php | public function setKeyPattern($keyPattern)
{
$keyPattern = (string)$keyPattern;
if ($this->keyPattern !== $keyPattern) {
// validate pattern
if ($keyPattern !== '') {
ErrorHandler::start(E_WARNING);
$result = preg_match($keyPattern, '');
$error = ErrorHandler::stop();
if ($result === false) {
throw new Exception\InvalidArgumentException(
sprintf(
'Invalid pattern "%s"%s',
$keyPattern,
($error ? ': ' . $error->getMessage() : '')
),
0,
$error
);
}
}
$this->keyPattern = $keyPattern;
}
return $this;
} | [
"public",
"function",
"setKeyPattern",
"(",
"$",
"keyPattern",
")",
"{",
"$",
"keyPattern",
"=",
"(",
"string",
")",
"$",
"keyPattern",
";",
"if",
"(",
"$",
"this",
"->",
"keyPattern",
"!==",
"$",
"keyPattern",
")",
"{",
"// validate pattern",
"if",
"(",
"$",
"keyPattern",
"!==",
"''",
")",
"{",
"ErrorHandler",
"::",
"start",
"(",
"E_WARNING",
")",
";",
"$",
"result",
"=",
"preg_match",
"(",
"$",
"keyPattern",
",",
"''",
")",
";",
"$",
"error",
"=",
"ErrorHandler",
"::",
"stop",
"(",
")",
";",
"if",
"(",
"$",
"result",
"===",
"false",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid pattern \"%s\"%s'",
",",
"$",
"keyPattern",
",",
"(",
"$",
"error",
"?",
"': '",
".",
"$",
"error",
"->",
"getMessage",
"(",
")",
":",
"''",
")",
")",
",",
"0",
",",
"$",
"error",
")",
";",
"}",
"}",
"$",
"this",
"->",
"keyPattern",
"=",
"$",
"keyPattern",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set key pattern
@param null|string $keyPattern
@throws Exception\InvalidArgumentException
@return AdapterOptions | [
"Set",
"key",
"pattern"
] | c765d83dc93d64ca44801de93759868770fc4733 | https://github.com/stavarengo/php-sigep/blob/c765d83dc93d64ca44801de93759868770fc4733/src/PhpSigep/Cache/Storage/Adapter/AdapterOptions.php#L113-L139 | train |
stavarengo/php-sigep | src/PhpSigep/Cache/Storage/Adapter/AdapterOptions.php | AdapterOptions.normalizeTtl | protected function normalizeTtl(&$ttl)
{
if (!is_int($ttl)) {
$ttl = (float)$ttl;
// convert to int if possible
if ($ttl === (float)(int)$ttl) {
$ttl = (int)$ttl;
}
}
if ($ttl < 0) {
throw new InvalidArgumentException("TTL can't be negative");
}
} | php | protected function normalizeTtl(&$ttl)
{
if (!is_int($ttl)) {
$ttl = (float)$ttl;
// convert to int if possible
if ($ttl === (float)(int)$ttl) {
$ttl = (int)$ttl;
}
}
if ($ttl < 0) {
throw new InvalidArgumentException("TTL can't be negative");
}
} | [
"protected",
"function",
"normalizeTtl",
"(",
"&",
"$",
"ttl",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"ttl",
")",
")",
"{",
"$",
"ttl",
"=",
"(",
"float",
")",
"$",
"ttl",
";",
"// convert to int if possible",
"if",
"(",
"$",
"ttl",
"===",
"(",
"float",
")",
"(",
"int",
")",
"$",
"ttl",
")",
"{",
"$",
"ttl",
"=",
"(",
"int",
")",
"$",
"ttl",
";",
"}",
"}",
"if",
"(",
"$",
"ttl",
"<",
"0",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"TTL can't be negative\"",
")",
";",
"}",
"}"
] | Validates and normalize a TTL.
@param int|float $ttl
@throws InvalidArgumentException
@return void | [
"Validates",
"and",
"normalize",
"a",
"TTL",
"."
] | c765d83dc93d64ca44801de93759868770fc4733 | https://github.com/stavarengo/php-sigep/blob/c765d83dc93d64ca44801de93759868770fc4733/src/PhpSigep/Cache/Storage/Adapter/AdapterOptions.php#L174-L188 | train |
stavarengo/php-sigep | src/PhpSigep/ErrorHandler.php | ErrorHandler.stop | public static function stop($throw = false)
{
$errorException = null;
if (static::$stack) {
$errorException = array_pop(static::$stack);
if (!static::$stack) {
restore_error_handler();
}
if ($errorException && $throw) {
throw $errorException;
}
}
return $errorException;
} | php | public static function stop($throw = false)
{
$errorException = null;
if (static::$stack) {
$errorException = array_pop(static::$stack);
if (!static::$stack) {
restore_error_handler();
}
if ($errorException && $throw) {
throw $errorException;
}
}
return $errorException;
} | [
"public",
"static",
"function",
"stop",
"(",
"$",
"throw",
"=",
"false",
")",
"{",
"$",
"errorException",
"=",
"null",
";",
"if",
"(",
"static",
"::",
"$",
"stack",
")",
"{",
"$",
"errorException",
"=",
"array_pop",
"(",
"static",
"::",
"$",
"stack",
")",
";",
"if",
"(",
"!",
"static",
"::",
"$",
"stack",
")",
"{",
"restore_error_handler",
"(",
")",
";",
"}",
"if",
"(",
"$",
"errorException",
"&&",
"$",
"throw",
")",
"{",
"throw",
"$",
"errorException",
";",
"}",
"}",
"return",
"$",
"errorException",
";",
"}"
] | Stopping the error handler
@param bool $throw Throw the ErrorException if any
@return null|ErrorException
@throws ErrorException If an error has been catched and $throw is true | [
"Stopping",
"the",
"error",
"handler"
] | c765d83dc93d64ca44801de93759868770fc4733 | https://github.com/stavarengo/php-sigep/blob/c765d83dc93d64ca44801de93759868770fc4733/src/PhpSigep/ErrorHandler.php#L68-L85 | train |
stavarengo/php-sigep | src/PhpSigep/ErrorHandler.php | ErrorHandler.addError | public static function addError($errno, $errstr = '', $errfile = '', $errline = 0)
{
$stack = & static::$stack[count(static::$stack) - 1];
$stack = new ErrorException($errstr, 0, $errno, $errfile, $errline, $stack);
} | php | public static function addError($errno, $errstr = '', $errfile = '', $errline = 0)
{
$stack = & static::$stack[count(static::$stack) - 1];
$stack = new ErrorException($errstr, 0, $errno, $errfile, $errline, $stack);
} | [
"public",
"static",
"function",
"addError",
"(",
"$",
"errno",
",",
"$",
"errstr",
"=",
"''",
",",
"$",
"errfile",
"=",
"''",
",",
"$",
"errline",
"=",
"0",
")",
"{",
"$",
"stack",
"=",
"&",
"static",
"::",
"$",
"stack",
"[",
"count",
"(",
"static",
"::",
"$",
"stack",
")",
"-",
"1",
"]",
";",
"$",
"stack",
"=",
"new",
"ErrorException",
"(",
"$",
"errstr",
",",
"0",
",",
"$",
"errno",
",",
"$",
"errfile",
",",
"$",
"errline",
",",
"$",
"stack",
")",
";",
"}"
] | Add an error to the stack
@param int $errno
@param string $errstr
@param string $errfile
@param int $errline
@return void | [
"Add",
"an",
"error",
"to",
"the",
"stack"
] | c765d83dc93d64ca44801de93759868770fc4733 | https://github.com/stavarengo/php-sigep/blob/c765d83dc93d64ca44801de93759868770fc4733/src/PhpSigep/ErrorHandler.php#L110-L114 | train |
stavarengo/php-sigep | src/PhpSigep/Cache/Storage/Adapter/AbstractAdapter.php | AbstractAdapter.normalizeKey | protected function normalizeKey(&$key)
{
$key = (string)$key;
if ($key === '') {
throw new InvalidArgumentException("An empty key isn't allowed");
} elseif (($p = $this->getOptions()->getKeyPattern()) && !preg_match($p, $key)) {
throw new InvalidArgumentException(
"The key '{$key}' doesn't match against pattern '{$p}'"
);
}
} | php | protected function normalizeKey(&$key)
{
$key = (string)$key;
if ($key === '') {
throw new InvalidArgumentException("An empty key isn't allowed");
} elseif (($p = $this->getOptions()->getKeyPattern()) && !preg_match($p, $key)) {
throw new InvalidArgumentException(
"The key '{$key}' doesn't match against pattern '{$p}'"
);
}
} | [
"protected",
"function",
"normalizeKey",
"(",
"&",
"$",
"key",
")",
"{",
"$",
"key",
"=",
"(",
"string",
")",
"$",
"key",
";",
"if",
"(",
"$",
"key",
"===",
"''",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"An empty key isn't allowed\"",
")",
";",
"}",
"elseif",
"(",
"(",
"$",
"p",
"=",
"$",
"this",
"->",
"getOptions",
"(",
")",
"->",
"getKeyPattern",
"(",
")",
")",
"&&",
"!",
"preg_match",
"(",
"$",
"p",
",",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"The key '{$key}' doesn't match against pattern '{$p}'\"",
")",
";",
"}",
"}"
] | Validates and normalizes a key
@param string $key
@throws InvalidArgumentException
@return void | [
"Validates",
"and",
"normalizes",
"a",
"key"
] | c765d83dc93d64ca44801de93759868770fc4733 | https://github.com/stavarengo/php-sigep/blob/c765d83dc93d64ca44801de93759868770fc4733/src/PhpSigep/Cache/Storage/Adapter/AbstractAdapter.php#L228-L239 | train |
stavarengo/php-sigep | src/PhpSigep/Pdf/Semacode.php | Semacode.makeEncoding | function makeEncoding($height = 0, $width = 0, $data = 0, $fw = 0, $bytes = 0, $datablocks = 0, $rsblocks = 0) {
$t = array(
'height' => $height,
'width' => $width,
'data' => $data,
'fw' => $fw,
'bytes' => $bytes,
'datablocks' => $datablocks,
'rsblocks' => $rsblocks
);
return $t;
} | php | function makeEncoding($height = 0, $width = 0, $data = 0, $fw = 0, $bytes = 0, $datablocks = 0, $rsblocks = 0) {
$t = array(
'height' => $height,
'width' => $width,
'data' => $data,
'fw' => $fw,
'bytes' => $bytes,
'datablocks' => $datablocks,
'rsblocks' => $rsblocks
);
return $t;
} | [
"function",
"makeEncoding",
"(",
"$",
"height",
"=",
"0",
",",
"$",
"width",
"=",
"0",
",",
"$",
"data",
"=",
"0",
",",
"$",
"fw",
"=",
"0",
",",
"$",
"bytes",
"=",
"0",
",",
"$",
"datablocks",
"=",
"0",
",",
"$",
"rsblocks",
"=",
"0",
")",
"{",
"$",
"t",
"=",
"array",
"(",
"'height'",
"=>",
"$",
"height",
",",
"'width'",
"=>",
"$",
"width",
",",
"'data'",
"=>",
"$",
"data",
",",
"'fw'",
"=>",
"$",
"fw",
",",
"'bytes'",
"=>",
"$",
"bytes",
",",
"'datablocks'",
"=>",
"$",
"datablocks",
",",
"'rsblocks'",
"=>",
"$",
"rsblocks",
")",
";",
"return",
"$",
"t",
";",
"}"
] | from Semafox.Encoding | [
"from",
"Semafox",
".",
"Encoding"
] | c765d83dc93d64ca44801de93759868770fc4733 | https://github.com/stavarengo/php-sigep/blob/c765d83dc93d64ca44801de93759868770fc4733/src/PhpSigep/Pdf/Semacode.php#L214-L225 | train |
stavarengo/php-sigep | src/PhpSigep/Pdf/Semacode.php | Semacode.placeBit | function placeBit(&$array, $NR, $NC, $r, $c, $p, $b) {
if ($r < 0) {
$r += $NR;
$c += 4 - (($NR + 4) % 8);
}
if ($c < 0) {
$c += $NC;
$r += 4 - (($NC + 4) % 8);
}
$array[$r * $NC + $c] = ($p << 3) + $b;
} | php | function placeBit(&$array, $NR, $NC, $r, $c, $p, $b) {
if ($r < 0) {
$r += $NR;
$c += 4 - (($NR + 4) % 8);
}
if ($c < 0) {
$c += $NC;
$r += 4 - (($NC + 4) % 8);
}
$array[$r * $NC + $c] = ($p << 3) + $b;
} | [
"function",
"placeBit",
"(",
"&",
"$",
"array",
",",
"$",
"NR",
",",
"$",
"NC",
",",
"$",
"r",
",",
"$",
"c",
",",
"$",
"p",
",",
"$",
"b",
")",
"{",
"if",
"(",
"$",
"r",
"<",
"0",
")",
"{",
"$",
"r",
"+=",
"$",
"NR",
";",
"$",
"c",
"+=",
"4",
"-",
"(",
"(",
"$",
"NR",
"+",
"4",
")",
"%",
"8",
")",
";",
"}",
"if",
"(",
"$",
"c",
"<",
"0",
")",
"{",
"$",
"c",
"+=",
"$",
"NC",
";",
"$",
"r",
"+=",
"4",
"-",
"(",
"(",
"$",
"NC",
"+",
"4",
")",
"%",
"8",
")",
";",
"}",
"$",
"array",
"[",
"$",
"r",
"*",
"$",
"NC",
"+",
"$",
"c",
"]",
"=",
"(",
"$",
"p",
"<<",
"3",
")",
"+",
"$",
"b",
";",
"}"
] | Annex M placement alogorithm low level | [
"Annex",
"M",
"placement",
"alogorithm",
"low",
"level"
] | c765d83dc93d64ca44801de93759868770fc4733 | https://github.com/stavarengo/php-sigep/blob/c765d83dc93d64ca44801de93759868770fc4733/src/PhpSigep/Pdf/Semacode.php#L229-L240 | train |
stavarengo/php-sigep | src/PhpSigep/Pdf/Semacode.php | Semacode.rs | function rs(&$binary, $bytes, $datablock, $rsblock) {
$blocks = floor(($bytes + 2) / $datablock);
$rs = new ReedSolomon($rsblock);
for ($b = 0; $b < $blocks; $b++) {
$buf = array();
$p = 0;
for ($n = $b; $n < $bytes; $n += $blocks)
array_push($buf, $binary[$n]);
$enc = $rs->encodeArray($buf);
// comes back reversed
$p = $rsblock - 1;
for ($n = $b; $n < $rsblock * $blocks; $n += $blocks)
$binary[$bytes + $n] = $enc[$p--];
}
} | php | function rs(&$binary, $bytes, $datablock, $rsblock) {
$blocks = floor(($bytes + 2) / $datablock);
$rs = new ReedSolomon($rsblock);
for ($b = 0; $b < $blocks; $b++) {
$buf = array();
$p = 0;
for ($n = $b; $n < $bytes; $n += $blocks)
array_push($buf, $binary[$n]);
$enc = $rs->encodeArray($buf);
// comes back reversed
$p = $rsblock - 1;
for ($n = $b; $n < $rsblock * $blocks; $n += $blocks)
$binary[$bytes + $n] = $enc[$p--];
}
} | [
"function",
"rs",
"(",
"&",
"$",
"binary",
",",
"$",
"bytes",
",",
"$",
"datablock",
",",
"$",
"rsblock",
")",
"{",
"$",
"blocks",
"=",
"floor",
"(",
"(",
"$",
"bytes",
"+",
"2",
")",
"/",
"$",
"datablock",
")",
";",
"$",
"rs",
"=",
"new",
"ReedSolomon",
"(",
"$",
"rsblock",
")",
";",
"for",
"(",
"$",
"b",
"=",
"0",
";",
"$",
"b",
"<",
"$",
"blocks",
";",
"$",
"b",
"++",
")",
"{",
"$",
"buf",
"=",
"array",
"(",
")",
";",
"$",
"p",
"=",
"0",
";",
"for",
"(",
"$",
"n",
"=",
"$",
"b",
";",
"$",
"n",
"<",
"$",
"bytes",
";",
"$",
"n",
"+=",
"$",
"blocks",
")",
"array_push",
"(",
"$",
"buf",
",",
"$",
"binary",
"[",
"$",
"n",
"]",
")",
";",
"$",
"enc",
"=",
"$",
"rs",
"->",
"encodeArray",
"(",
"$",
"buf",
")",
";",
"// comes back reversed",
"$",
"p",
"=",
"$",
"rsblock",
"-",
"1",
";",
"for",
"(",
"$",
"n",
"=",
"$",
"b",
";",
"$",
"n",
"<",
"$",
"rsblock",
"*",
"$",
"blocks",
";",
"$",
"n",
"+=",
"$",
"blocks",
")",
"$",
"binary",
"[",
"$",
"bytes",
"+",
"$",
"n",
"]",
"=",
"$",
"enc",
"[",
"$",
"p",
"--",
"]",
";",
"}",
"}"
] | calculate and append ecc code, and if necessary interleave | [
"calculate",
"and",
"append",
"ecc",
"code",
"and",
"if",
"necessary",
"interleave"
] | c765d83dc93d64ca44801de93759868770fc4733 | https://github.com/stavarengo/php-sigep/blob/c765d83dc93d64ca44801de93759868770fc4733/src/PhpSigep/Pdf/Semacode.php#L342-L359 | train |
stavarengo/php-sigep | src/PhpSigep/Pdf/Semacode.php | Semacode.asGDImage | function asGDImage($text,$resize=160){
$barcode = $this->encode($text);
$w = $barcode['width'];
$h = $barcode['height'];
$bs = 10;
$size = $bs * $w;
$img = imagecreatetruecolor($size + 2 * $bs * 2 ,$size + 2 * $bs * 2);
$white = imagecolorallocate($img,255,255,255);
$black = imagecolorallocate($img,0,0,0);
imagefill($img,0,0,$white);
for($j=0; $j < $h; $j++){
for($i=0; $i < $w; $i++){
$x1 = ($i * $bs) + $bs * 2;
$y1 = ($size - (($j + 1) * $bs)) + $bs * 2;
$x2 = $x1 + $bs;
$y2 = $y1 + $bs;
if($barcode['data'][$j * $w + $i]){
imagefilledrectangle($img,$x1,$y1,$x2,$y2,$black);
} else {
imagefilledrectangle($img,$x1,$y1,$x2,$y2,$white);
}
}
}
if($resize == $size){
return $img;
}
$new = imagecreatetruecolor($resize,$resize);
imagecopyresized($new, $img, 0, 0, 0, 0, $resize, $resize, $size + 2 * $bs * 2, $size + 2 * $bs * 2);
imagedestroy($img);
return $new;
} | php | function asGDImage($text,$resize=160){
$barcode = $this->encode($text);
$w = $barcode['width'];
$h = $barcode['height'];
$bs = 10;
$size = $bs * $w;
$img = imagecreatetruecolor($size + 2 * $bs * 2 ,$size + 2 * $bs * 2);
$white = imagecolorallocate($img,255,255,255);
$black = imagecolorallocate($img,0,0,0);
imagefill($img,0,0,$white);
for($j=0; $j < $h; $j++){
for($i=0; $i < $w; $i++){
$x1 = ($i * $bs) + $bs * 2;
$y1 = ($size - (($j + 1) * $bs)) + $bs * 2;
$x2 = $x1 + $bs;
$y2 = $y1 + $bs;
if($barcode['data'][$j * $w + $i]){
imagefilledrectangle($img,$x1,$y1,$x2,$y2,$black);
} else {
imagefilledrectangle($img,$x1,$y1,$x2,$y2,$white);
}
}
}
if($resize == $size){
return $img;
}
$new = imagecreatetruecolor($resize,$resize);
imagecopyresized($new, $img, 0, 0, 0, 0, $resize, $resize, $size + 2 * $bs * 2, $size + 2 * $bs * 2);
imagedestroy($img);
return $new;
} | [
"function",
"asGDImage",
"(",
"$",
"text",
",",
"$",
"resize",
"=",
"160",
")",
"{",
"$",
"barcode",
"=",
"$",
"this",
"->",
"encode",
"(",
"$",
"text",
")",
";",
"$",
"w",
"=",
"$",
"barcode",
"[",
"'width'",
"]",
";",
"$",
"h",
"=",
"$",
"barcode",
"[",
"'height'",
"]",
";",
"$",
"bs",
"=",
"10",
";",
"$",
"size",
"=",
"$",
"bs",
"*",
"$",
"w",
";",
"$",
"img",
"=",
"imagecreatetruecolor",
"(",
"$",
"size",
"+",
"2",
"*",
"$",
"bs",
"*",
"2",
",",
"$",
"size",
"+",
"2",
"*",
"$",
"bs",
"*",
"2",
")",
";",
"$",
"white",
"=",
"imagecolorallocate",
"(",
"$",
"img",
",",
"255",
",",
"255",
",",
"255",
")",
";",
"$",
"black",
"=",
"imagecolorallocate",
"(",
"$",
"img",
",",
"0",
",",
"0",
",",
"0",
")",
";",
"imagefill",
"(",
"$",
"img",
",",
"0",
",",
"0",
",",
"$",
"white",
")",
";",
"for",
"(",
"$",
"j",
"=",
"0",
";",
"$",
"j",
"<",
"$",
"h",
";",
"$",
"j",
"++",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"w",
";",
"$",
"i",
"++",
")",
"{",
"$",
"x1",
"=",
"(",
"$",
"i",
"*",
"$",
"bs",
")",
"+",
"$",
"bs",
"*",
"2",
";",
"$",
"y1",
"=",
"(",
"$",
"size",
"-",
"(",
"(",
"$",
"j",
"+",
"1",
")",
"*",
"$",
"bs",
")",
")",
"+",
"$",
"bs",
"*",
"2",
";",
"$",
"x2",
"=",
"$",
"x1",
"+",
"$",
"bs",
";",
"$",
"y2",
"=",
"$",
"y1",
"+",
"$",
"bs",
";",
"if",
"(",
"$",
"barcode",
"[",
"'data'",
"]",
"[",
"$",
"j",
"*",
"$",
"w",
"+",
"$",
"i",
"]",
")",
"{",
"imagefilledrectangle",
"(",
"$",
"img",
",",
"$",
"x1",
",",
"$",
"y1",
",",
"$",
"x2",
",",
"$",
"y2",
",",
"$",
"black",
")",
";",
"}",
"else",
"{",
"imagefilledrectangle",
"(",
"$",
"img",
",",
"$",
"x1",
",",
"$",
"y1",
",",
"$",
"x2",
",",
"$",
"y2",
",",
"$",
"white",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"resize",
"==",
"$",
"size",
")",
"{",
"return",
"$",
"img",
";",
"}",
"$",
"new",
"=",
"imagecreatetruecolor",
"(",
"$",
"resize",
",",
"$",
"resize",
")",
";",
"imagecopyresized",
"(",
"$",
"new",
",",
"$",
"img",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"$",
"resize",
",",
"$",
"resize",
",",
"$",
"size",
"+",
"2",
"*",
"$",
"bs",
"*",
"2",
",",
"$",
"size",
"+",
"2",
"*",
"$",
"bs",
"*",
"2",
")",
";",
"imagedestroy",
"(",
"$",
"img",
")",
";",
"return",
"$",
"new",
";",
"}"
] | returns a libGD image ressource
You need to call imagedestroy on it your self! | [
"returns",
"a",
"libGD",
"image",
"ressource"
] | c765d83dc93d64ca44801de93759868770fc4733 | https://github.com/stavarengo/php-sigep/blob/c765d83dc93d64ca44801de93759868770fc4733/src/PhpSigep/Pdf/Semacode.php#L1107-L1142 | train |
stavarengo/php-sigep | src/PhpSigep/Cache/Storage/Adapter/FileSystem.php | FileSystem.internalHasItem | protected function internalHasItem(& $normalizedKey)
{
$file = $this->getFileSpec($normalizedKey) . '.dat';
if (!file_exists($file)) {
return false;
}
$ttl = $this->getOptions()->getTtl();
if ($ttl) {
ErrorHandler::start();
$mtime = filemtime($file);
$error = ErrorHandler::stop();
if (!$mtime) {
throw new Exception\RuntimeException(
"Error getting mtime of file '{$file}'", 0, $error
);
}
if (time() >= ($mtime + $ttl)) {
return false;
}
}
return true;
} | php | protected function internalHasItem(& $normalizedKey)
{
$file = $this->getFileSpec($normalizedKey) . '.dat';
if (!file_exists($file)) {
return false;
}
$ttl = $this->getOptions()->getTtl();
if ($ttl) {
ErrorHandler::start();
$mtime = filemtime($file);
$error = ErrorHandler::stop();
if (!$mtime) {
throw new Exception\RuntimeException(
"Error getting mtime of file '{$file}'", 0, $error
);
}
if (time() >= ($mtime + $ttl)) {
return false;
}
}
return true;
} | [
"protected",
"function",
"internalHasItem",
"(",
"&",
"$",
"normalizedKey",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"getFileSpec",
"(",
"$",
"normalizedKey",
")",
".",
"'.dat'",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"ttl",
"=",
"$",
"this",
"->",
"getOptions",
"(",
")",
"->",
"getTtl",
"(",
")",
";",
"if",
"(",
"$",
"ttl",
")",
"{",
"ErrorHandler",
"::",
"start",
"(",
")",
";",
"$",
"mtime",
"=",
"filemtime",
"(",
"$",
"file",
")",
";",
"$",
"error",
"=",
"ErrorHandler",
"::",
"stop",
"(",
")",
";",
"if",
"(",
"!",
"$",
"mtime",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"RuntimeException",
"(",
"\"Error getting mtime of file '{$file}'\"",
",",
"0",
",",
"$",
"error",
")",
";",
"}",
"if",
"(",
"time",
"(",
")",
">=",
"(",
"$",
"mtime",
"+",
"$",
"ttl",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Internal method to test if an item exists.
@param string $normalizedKey
@throws Exception\RuntimeException
@return bool | [
"Internal",
"method",
"to",
"test",
"if",
"an",
"item",
"exists",
"."
] | c765d83dc93d64ca44801de93759868770fc4733 | https://github.com/stavarengo/php-sigep/blob/c765d83dc93d64ca44801de93759868770fc4733/src/PhpSigep/Cache/Storage/Adapter/FileSystem.php#L88-L112 | train |
stavarengo/php-sigep | src/PhpSigep/Cache/Storage/Adapter/FileSystem.php | FileSystem.getFileSpec | protected function getFileSpec($normalizedKey)
{
$options = $this->getOptions();
$namespace = $options->getNamespace();
$prefix = ($namespace === '') ? '' : $namespace . $options->getNamespaceSeparator();
$path = $options->getCacheDir() . DIRECTORY_SEPARATOR;
$level = $options->getDirLevel();
$fileSpecId = $path . $prefix . $normalizedKey . '/' . $level;
if ($this->lastFileSpecId !== $fileSpecId) {
if ($level > 0) {
// create up to 256 directories per directory level
$hash = md5($normalizedKey);
for ($i = 0, $max = ($level * 2); $i < $max; $i += 2) {
$path .= $prefix . $hash[$i] . $hash[$i + 1] . DIRECTORY_SEPARATOR;
}
}
$this->lastFileSpecId = $fileSpecId;
$this->lastFileSpec = $path . $prefix . $normalizedKey;
}
return $this->lastFileSpec;
} | php | protected function getFileSpec($normalizedKey)
{
$options = $this->getOptions();
$namespace = $options->getNamespace();
$prefix = ($namespace === '') ? '' : $namespace . $options->getNamespaceSeparator();
$path = $options->getCacheDir() . DIRECTORY_SEPARATOR;
$level = $options->getDirLevel();
$fileSpecId = $path . $prefix . $normalizedKey . '/' . $level;
if ($this->lastFileSpecId !== $fileSpecId) {
if ($level > 0) {
// create up to 256 directories per directory level
$hash = md5($normalizedKey);
for ($i = 0, $max = ($level * 2); $i < $max; $i += 2) {
$path .= $prefix . $hash[$i] . $hash[$i + 1] . DIRECTORY_SEPARATOR;
}
}
$this->lastFileSpecId = $fileSpecId;
$this->lastFileSpec = $path . $prefix . $normalizedKey;
}
return $this->lastFileSpec;
} | [
"protected",
"function",
"getFileSpec",
"(",
"$",
"normalizedKey",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"getOptions",
"(",
")",
";",
"$",
"namespace",
"=",
"$",
"options",
"->",
"getNamespace",
"(",
")",
";",
"$",
"prefix",
"=",
"(",
"$",
"namespace",
"===",
"''",
")",
"?",
"''",
":",
"$",
"namespace",
".",
"$",
"options",
"->",
"getNamespaceSeparator",
"(",
")",
";",
"$",
"path",
"=",
"$",
"options",
"->",
"getCacheDir",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
";",
"$",
"level",
"=",
"$",
"options",
"->",
"getDirLevel",
"(",
")",
";",
"$",
"fileSpecId",
"=",
"$",
"path",
".",
"$",
"prefix",
".",
"$",
"normalizedKey",
".",
"'/'",
".",
"$",
"level",
";",
"if",
"(",
"$",
"this",
"->",
"lastFileSpecId",
"!==",
"$",
"fileSpecId",
")",
"{",
"if",
"(",
"$",
"level",
">",
"0",
")",
"{",
"// create up to 256 directories per directory level",
"$",
"hash",
"=",
"md5",
"(",
"$",
"normalizedKey",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"max",
"=",
"(",
"$",
"level",
"*",
"2",
")",
";",
"$",
"i",
"<",
"$",
"max",
";",
"$",
"i",
"+=",
"2",
")",
"{",
"$",
"path",
".=",
"$",
"prefix",
".",
"$",
"hash",
"[",
"$",
"i",
"]",
".",
"$",
"hash",
"[",
"$",
"i",
"+",
"1",
"]",
".",
"DIRECTORY_SEPARATOR",
";",
"}",
"}",
"$",
"this",
"->",
"lastFileSpecId",
"=",
"$",
"fileSpecId",
";",
"$",
"this",
"->",
"lastFileSpec",
"=",
"$",
"path",
".",
"$",
"prefix",
".",
"$",
"normalizedKey",
";",
"}",
"return",
"$",
"this",
"->",
"lastFileSpec",
";",
"}"
] | Get file spec of the given key and namespace
@param string $normalizedKey
@return string | [
"Get",
"file",
"spec",
"of",
"the",
"given",
"key",
"and",
"namespace"
] | c765d83dc93d64ca44801de93759868770fc4733 | https://github.com/stavarengo/php-sigep/blob/c765d83dc93d64ca44801de93759868770fc4733/src/PhpSigep/Cache/Storage/Adapter/FileSystem.php#L190-L213 | train |
stavarengo/php-sigep | src/PhpSigep/Cache/Storage/Adapter/FileSystem.php | FileSystem.getFileContent | protected function getFileContent($file, $nonBlocking = false, & $wouldblock = null)
{
$locking = $this->getOptions()->getFileLocking();
$wouldblock = null;
ErrorHandler::start();
// if file locking enabled -> file_get_contents can't be used
if ($locking) {
$fp = fopen($file, 'rb');
if ($fp === false) {
$err = ErrorHandler::stop();
throw new Exception\RuntimeException(
"Error opening file '{$file}'", 0, $err
);
}
if ($nonBlocking) {
$lock = flock($fp, LOCK_SH | LOCK_NB, $wouldblock);
if ($wouldblock) {
fclose($fp);
ErrorHandler::stop();
return;
}
} else {
$lock = flock($fp, LOCK_SH);
}
if (!$lock) {
fclose($fp);
$err = ErrorHandler::stop();
throw new Exception\RuntimeException(
"Error locking file '{$file}'", 0, $err
);
}
$res = stream_get_contents($fp);
if ($res === false) {
flock($fp, LOCK_UN);
fclose($fp);
$err = ErrorHandler::stop();
throw new Exception\RuntimeException(
'Error getting stream contents', 0, $err
);
}
flock($fp, LOCK_UN);
fclose($fp);
// if file locking disabled -> file_get_contents can be used
} else {
$res = file_get_contents($file, false);
if ($res === false) {
$err = ErrorHandler::stop();
throw new Exception\RuntimeException(
"Error getting file contents for file '{$file}'", 0, $err
);
}
}
ErrorHandler::stop();
return $res;
} | php | protected function getFileContent($file, $nonBlocking = false, & $wouldblock = null)
{
$locking = $this->getOptions()->getFileLocking();
$wouldblock = null;
ErrorHandler::start();
// if file locking enabled -> file_get_contents can't be used
if ($locking) {
$fp = fopen($file, 'rb');
if ($fp === false) {
$err = ErrorHandler::stop();
throw new Exception\RuntimeException(
"Error opening file '{$file}'", 0, $err
);
}
if ($nonBlocking) {
$lock = flock($fp, LOCK_SH | LOCK_NB, $wouldblock);
if ($wouldblock) {
fclose($fp);
ErrorHandler::stop();
return;
}
} else {
$lock = flock($fp, LOCK_SH);
}
if (!$lock) {
fclose($fp);
$err = ErrorHandler::stop();
throw new Exception\RuntimeException(
"Error locking file '{$file}'", 0, $err
);
}
$res = stream_get_contents($fp);
if ($res === false) {
flock($fp, LOCK_UN);
fclose($fp);
$err = ErrorHandler::stop();
throw new Exception\RuntimeException(
'Error getting stream contents', 0, $err
);
}
flock($fp, LOCK_UN);
fclose($fp);
// if file locking disabled -> file_get_contents can be used
} else {
$res = file_get_contents($file, false);
if ($res === false) {
$err = ErrorHandler::stop();
throw new Exception\RuntimeException(
"Error getting file contents for file '{$file}'", 0, $err
);
}
}
ErrorHandler::stop();
return $res;
} | [
"protected",
"function",
"getFileContent",
"(",
"$",
"file",
",",
"$",
"nonBlocking",
"=",
"false",
",",
"&",
"$",
"wouldblock",
"=",
"null",
")",
"{",
"$",
"locking",
"=",
"$",
"this",
"->",
"getOptions",
"(",
")",
"->",
"getFileLocking",
"(",
")",
";",
"$",
"wouldblock",
"=",
"null",
";",
"ErrorHandler",
"::",
"start",
"(",
")",
";",
"// if file locking enabled -> file_get_contents can't be used",
"if",
"(",
"$",
"locking",
")",
"{",
"$",
"fp",
"=",
"fopen",
"(",
"$",
"file",
",",
"'rb'",
")",
";",
"if",
"(",
"$",
"fp",
"===",
"false",
")",
"{",
"$",
"err",
"=",
"ErrorHandler",
"::",
"stop",
"(",
")",
";",
"throw",
"new",
"Exception",
"\\",
"RuntimeException",
"(",
"\"Error opening file '{$file}'\"",
",",
"0",
",",
"$",
"err",
")",
";",
"}",
"if",
"(",
"$",
"nonBlocking",
")",
"{",
"$",
"lock",
"=",
"flock",
"(",
"$",
"fp",
",",
"LOCK_SH",
"|",
"LOCK_NB",
",",
"$",
"wouldblock",
")",
";",
"if",
"(",
"$",
"wouldblock",
")",
"{",
"fclose",
"(",
"$",
"fp",
")",
";",
"ErrorHandler",
"::",
"stop",
"(",
")",
";",
"return",
";",
"}",
"}",
"else",
"{",
"$",
"lock",
"=",
"flock",
"(",
"$",
"fp",
",",
"LOCK_SH",
")",
";",
"}",
"if",
"(",
"!",
"$",
"lock",
")",
"{",
"fclose",
"(",
"$",
"fp",
")",
";",
"$",
"err",
"=",
"ErrorHandler",
"::",
"stop",
"(",
")",
";",
"throw",
"new",
"Exception",
"\\",
"RuntimeException",
"(",
"\"Error locking file '{$file}'\"",
",",
"0",
",",
"$",
"err",
")",
";",
"}",
"$",
"res",
"=",
"stream_get_contents",
"(",
"$",
"fp",
")",
";",
"if",
"(",
"$",
"res",
"===",
"false",
")",
"{",
"flock",
"(",
"$",
"fp",
",",
"LOCK_UN",
")",
";",
"fclose",
"(",
"$",
"fp",
")",
";",
"$",
"err",
"=",
"ErrorHandler",
"::",
"stop",
"(",
")",
";",
"throw",
"new",
"Exception",
"\\",
"RuntimeException",
"(",
"'Error getting stream contents'",
",",
"0",
",",
"$",
"err",
")",
";",
"}",
"flock",
"(",
"$",
"fp",
",",
"LOCK_UN",
")",
";",
"fclose",
"(",
"$",
"fp",
")",
";",
"// if file locking disabled -> file_get_contents can be used",
"}",
"else",
"{",
"$",
"res",
"=",
"file_get_contents",
"(",
"$",
"file",
",",
"false",
")",
";",
"if",
"(",
"$",
"res",
"===",
"false",
")",
"{",
"$",
"err",
"=",
"ErrorHandler",
"::",
"stop",
"(",
")",
";",
"throw",
"new",
"Exception",
"\\",
"RuntimeException",
"(",
"\"Error getting file contents for file '{$file}'\"",
",",
"0",
",",
"$",
"err",
")",
";",
"}",
"}",
"ErrorHandler",
"::",
"stop",
"(",
")",
";",
"return",
"$",
"res",
";",
"}"
] | Read a complete file
@param string $file File complete path
@param bool $nonBlocking Don't block script if file is locked
@param bool $wouldblock The optional argument is set to TRUE if the lock would block
@return string
@throws Exception\RuntimeException | [
"Read",
"a",
"complete",
"file"
] | c765d83dc93d64ca44801de93759868770fc4733 | https://github.com/stavarengo/php-sigep/blob/c765d83dc93d64ca44801de93759868770fc4733/src/PhpSigep/Cache/Storage/Adapter/FileSystem.php#L224-L288 | train |
mailgun/mailgun-php | src/Api/Tag.php | Tag.index | public function index(string $domain, int $limit = 100)
{
Assert::stringNotEmpty($domain);
Assert::range($limit, 1, 1000);
$params = [
'limit' => $limit,
];
$response = $this->httpGet(sprintf('/v3/%s/tags', $domain), $params);
return $this->hydrateResponse($response, IndexResponse::class);
} | php | public function index(string $domain, int $limit = 100)
{
Assert::stringNotEmpty($domain);
Assert::range($limit, 1, 1000);
$params = [
'limit' => $limit,
];
$response = $this->httpGet(sprintf('/v3/%s/tags', $domain), $params);
return $this->hydrateResponse($response, IndexResponse::class);
} | [
"public",
"function",
"index",
"(",
"string",
"$",
"domain",
",",
"int",
"$",
"limit",
"=",
"100",
")",
"{",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"domain",
")",
";",
"Assert",
"::",
"range",
"(",
"$",
"limit",
",",
"1",
",",
"1000",
")",
";",
"$",
"params",
"=",
"[",
"'limit'",
"=>",
"$",
"limit",
",",
"]",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"httpGet",
"(",
"sprintf",
"(",
"'/v3/%s/tags'",
",",
"$",
"domain",
")",
",",
"$",
"params",
")",
";",
"return",
"$",
"this",
"->",
"hydrateResponse",
"(",
"$",
"response",
",",
"IndexResponse",
"::",
"class",
")",
";",
"}"
] | Returns a list of tags.
@return IndexResponse|ResponseInterface | [
"Returns",
"a",
"list",
"of",
"tags",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/Tag.php#L38-L50 | train |
mailgun/mailgun-php | src/Api/Tag.php | Tag.update | public function update(string $domain, string $tag, string $description)
{
Assert::stringNotEmpty($domain);
Assert::stringNotEmpty($tag);
$params = [
'description' => $description,
];
$response = $this->httpPut(sprintf('/v3/%s/tags/%s', $domain, $tag), $params);
return $this->hydrateResponse($response, UpdateResponse::class);
} | php | public function update(string $domain, string $tag, string $description)
{
Assert::stringNotEmpty($domain);
Assert::stringNotEmpty($tag);
$params = [
'description' => $description,
];
$response = $this->httpPut(sprintf('/v3/%s/tags/%s', $domain, $tag), $params);
return $this->hydrateResponse($response, UpdateResponse::class);
} | [
"public",
"function",
"update",
"(",
"string",
"$",
"domain",
",",
"string",
"$",
"tag",
",",
"string",
"$",
"description",
")",
"{",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"domain",
")",
";",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"tag",
")",
";",
"$",
"params",
"=",
"[",
"'description'",
"=>",
"$",
"description",
",",
"]",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"httpPut",
"(",
"sprintf",
"(",
"'/v3/%s/tags/%s'",
",",
"$",
"domain",
",",
"$",
"tag",
")",
",",
"$",
"params",
")",
";",
"return",
"$",
"this",
"->",
"hydrateResponse",
"(",
"$",
"response",
",",
"UpdateResponse",
"::",
"class",
")",
";",
"}"
] | Update a tag.
@return UpdateResponse|ResponseInterface | [
"Update",
"a",
"tag",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/Tag.php#L73-L85 | train |
mailgun/mailgun-php | src/Api/Tag.php | Tag.stats | public function stats(string $domain, string $tag, array $params)
{
Assert::stringNotEmpty($domain);
Assert::stringNotEmpty($tag);
$response = $this->httpGet(sprintf('/v3/%s/tags/%s/stats', $domain, $tag), $params);
return $this->hydrateResponse($response, StatisticsResponse::class);
} | php | public function stats(string $domain, string $tag, array $params)
{
Assert::stringNotEmpty($domain);
Assert::stringNotEmpty($tag);
$response = $this->httpGet(sprintf('/v3/%s/tags/%s/stats', $domain, $tag), $params);
return $this->hydrateResponse($response, StatisticsResponse::class);
} | [
"public",
"function",
"stats",
"(",
"string",
"$",
"domain",
",",
"string",
"$",
"tag",
",",
"array",
"$",
"params",
")",
"{",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"domain",
")",
";",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"tag",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"httpGet",
"(",
"sprintf",
"(",
"'/v3/%s/tags/%s/stats'",
",",
"$",
"domain",
",",
"$",
"tag",
")",
",",
"$",
"params",
")",
";",
"return",
"$",
"this",
"->",
"hydrateResponse",
"(",
"$",
"response",
",",
"StatisticsResponse",
"::",
"class",
")",
";",
"}"
] | Returns statistics for a single tag.
@return StatisticsResponse|ResponseInterface | [
"Returns",
"statistics",
"for",
"a",
"single",
"tag",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/Tag.php#L93-L101 | train |
mailgun/mailgun-php | src/Api/Message.php | Message.show | public function show(string $url, bool $rawMessage = false)
{
Assert::notEmpty($url);
$headers = [];
if ($rawMessage) {
$headers['Accept'] = 'message/rfc2822';
}
$response = $this->httpGet($url, [], $headers);
return $this->hydrateResponse($response, ShowResponse::class);
} | php | public function show(string $url, bool $rawMessage = false)
{
Assert::notEmpty($url);
$headers = [];
if ($rawMessage) {
$headers['Accept'] = 'message/rfc2822';
}
$response = $this->httpGet($url, [], $headers);
return $this->hydrateResponse($response, ShowResponse::class);
} | [
"public",
"function",
"show",
"(",
"string",
"$",
"url",
",",
"bool",
"$",
"rawMessage",
"=",
"false",
")",
"{",
"Assert",
"::",
"notEmpty",
"(",
"$",
"url",
")",
";",
"$",
"headers",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"rawMessage",
")",
"{",
"$",
"headers",
"[",
"'Accept'",
"]",
"=",
"'message/rfc2822'",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"httpGet",
"(",
"$",
"url",
",",
"[",
"]",
",",
"$",
"headers",
")",
";",
"return",
"$",
"this",
"->",
"hydrateResponse",
"(",
"$",
"response",
",",
"ShowResponse",
"::",
"class",
")",
";",
"}"
] | Get stored message.
@see https://documentation.mailgun.com/en/latest/api-sending.html#retrieving-stored-messages
@param bool $rawMessage if true we will use "Accept: message/rfc2822" header
@return ShowResponse|ResponseInterface | [
"Get",
"stored",
"message",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/Message.php#L109-L121 | train |
mailgun/mailgun-php | src/Api/Message.php | Message.prepareMultipartParameters | private function prepareMultipartParameters(array $params): array
{
$postDataMultipart = [];
foreach ($params as $key => $value) {
// If $value is not an array we cast it to an array
foreach ((array) $value as $subValue) {
$postDataMultipart[] = [
'name' => $key,
'content' => $subValue,
];
}
}
return $postDataMultipart;
} | php | private function prepareMultipartParameters(array $params): array
{
$postDataMultipart = [];
foreach ($params as $key => $value) {
// If $value is not an array we cast it to an array
foreach ((array) $value as $subValue) {
$postDataMultipart[] = [
'name' => $key,
'content' => $subValue,
];
}
}
return $postDataMultipart;
} | [
"private",
"function",
"prepareMultipartParameters",
"(",
"array",
"$",
"params",
")",
":",
"array",
"{",
"$",
"postDataMultipart",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"// If $value is not an array we cast it to an array",
"foreach",
"(",
"(",
"array",
")",
"$",
"value",
"as",
"$",
"subValue",
")",
"{",
"$",
"postDataMultipart",
"[",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"key",
",",
"'content'",
"=>",
"$",
"subValue",
",",
"]",
";",
"}",
"}",
"return",
"$",
"postDataMultipart",
";",
"}"
] | Prepare multipart parameters. Make sure each POST parameter is split into an array with 'name' and 'content' keys. | [
"Prepare",
"multipart",
"parameters",
".",
"Make",
"sure",
"each",
"POST",
"parameter",
"is",
"split",
"into",
"an",
"array",
"with",
"name",
"and",
"content",
"keys",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/Message.php#L161-L175 | train |
mailgun/mailgun-php | src/Api/Message.php | Message.closeResources | private function closeResources(array $params): void
{
foreach ($params as $param) {
if (is_array($param) && array_key_exists('content', $param) && is_resource($param['content'])) {
fclose($param['content']);
}
}
} | php | private function closeResources(array $params): void
{
foreach ($params as $param) {
if (is_array($param) && array_key_exists('content', $param) && is_resource($param['content'])) {
fclose($param['content']);
}
}
} | [
"private",
"function",
"closeResources",
"(",
"array",
"$",
"params",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"params",
"as",
"$",
"param",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"param",
")",
"&&",
"array_key_exists",
"(",
"'content'",
",",
"$",
"param",
")",
"&&",
"is_resource",
"(",
"$",
"param",
"[",
"'content'",
"]",
")",
")",
"{",
"fclose",
"(",
"$",
"param",
"[",
"'content'",
"]",
")",
";",
"}",
"}",
"}"
] | Close open resources. | [
"Close",
"open",
"resources",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/Message.php#L180-L187 | train |
mailgun/mailgun-php | src/Api/Ip.php | Ip.index | public function index(bool $dedicated = false)
{
Assert::boolean($dedicated);
$params = [
'dedicated' => $dedicated,
];
$response = $this->httpGet('/v3/ips', $params);
return $this->hydrateResponse($response, IndexResponse::class);
} | php | public function index(bool $dedicated = false)
{
Assert::boolean($dedicated);
$params = [
'dedicated' => $dedicated,
];
$response = $this->httpGet('/v3/ips', $params);
return $this->hydrateResponse($response, IndexResponse::class);
} | [
"public",
"function",
"index",
"(",
"bool",
"$",
"dedicated",
"=",
"false",
")",
"{",
"Assert",
"::",
"boolean",
"(",
"$",
"dedicated",
")",
";",
"$",
"params",
"=",
"[",
"'dedicated'",
"=>",
"$",
"dedicated",
",",
"]",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"httpGet",
"(",
"'/v3/ips'",
",",
"$",
"params",
")",
";",
"return",
"$",
"this",
"->",
"hydrateResponse",
"(",
"$",
"response",
",",
"IndexResponse",
"::",
"class",
")",
";",
"}"
] | Returns a list of IPs.
@return IndexResponse|ResponseInterface | [
"Returns",
"a",
"list",
"of",
"IPs",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/Ip.php#L33-L44 | train |
mailgun/mailgun-php | src/Api/Ip.php | Ip.domainIndex | public function domainIndex(string $domain)
{
Assert::stringNotEmpty($domain);
$response = $this->httpGet(sprintf('/v3/domains/%s/ip', $domain));
return $this->hydrateResponse($response, IndexResponse::class);
} | php | public function domainIndex(string $domain)
{
Assert::stringNotEmpty($domain);
$response = $this->httpGet(sprintf('/v3/domains/%s/ip', $domain));
return $this->hydrateResponse($response, IndexResponse::class);
} | [
"public",
"function",
"domainIndex",
"(",
"string",
"$",
"domain",
")",
"{",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"domain",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"httpGet",
"(",
"sprintf",
"(",
"'/v3/domains/%s/ip'",
",",
"$",
"domain",
")",
")",
";",
"return",
"$",
"this",
"->",
"hydrateResponse",
"(",
"$",
"response",
",",
"IndexResponse",
"::",
"class",
")",
";",
"}"
] | Returns a list of IPs assigned to a domain.
@return IndexResponse|ResponseInterface | [
"Returns",
"a",
"list",
"of",
"IPs",
"assigned",
"to",
"a",
"domain",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/Ip.php#L52-L59 | train |
mailgun/mailgun-php | src/Api/Ip.php | Ip.show | public function show(string $ip)
{
Assert::ip($ip);
$response = $this->httpGet(sprintf('/v3/ips/%s', $ip));
return $this->hydrateResponse($response, ShowResponse::class);
} | php | public function show(string $ip)
{
Assert::ip($ip);
$response = $this->httpGet(sprintf('/v3/ips/%s', $ip));
return $this->hydrateResponse($response, ShowResponse::class);
} | [
"public",
"function",
"show",
"(",
"string",
"$",
"ip",
")",
"{",
"Assert",
"::",
"ip",
"(",
"$",
"ip",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"httpGet",
"(",
"sprintf",
"(",
"'/v3/ips/%s'",
",",
"$",
"ip",
")",
")",
";",
"return",
"$",
"this",
"->",
"hydrateResponse",
"(",
"$",
"response",
",",
"ShowResponse",
"::",
"class",
")",
";",
"}"
] | Returns a single ip.
@return ShowResponse|ResponseInterface | [
"Returns",
"a",
"single",
"ip",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/Ip.php#L67-L74 | train |
mailgun/mailgun-php | src/Api/Ip.php | Ip.assign | public function assign(string $domain, string $ip)
{
Assert::stringNotEmpty($domain);
Assert::ip($ip);
$params = [
'id' => $ip,
];
$response = $this->httpPost(sprintf('/v3/domains/%s/ips', $domain), $params);
return $this->hydrateResponse($response, UpdateResponse::class);
} | php | public function assign(string $domain, string $ip)
{
Assert::stringNotEmpty($domain);
Assert::ip($ip);
$params = [
'id' => $ip,
];
$response = $this->httpPost(sprintf('/v3/domains/%s/ips', $domain), $params);
return $this->hydrateResponse($response, UpdateResponse::class);
} | [
"public",
"function",
"assign",
"(",
"string",
"$",
"domain",
",",
"string",
"$",
"ip",
")",
"{",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"domain",
")",
";",
"Assert",
"::",
"ip",
"(",
"$",
"ip",
")",
";",
"$",
"params",
"=",
"[",
"'id'",
"=>",
"$",
"ip",
",",
"]",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"httpPost",
"(",
"sprintf",
"(",
"'/v3/domains/%s/ips'",
",",
"$",
"domain",
")",
",",
"$",
"params",
")",
";",
"return",
"$",
"this",
"->",
"hydrateResponse",
"(",
"$",
"response",
",",
"UpdateResponse",
"::",
"class",
")",
";",
"}"
] | Assign a dedicated IP to the domain specified.
@return UpdateResponse|ResponseInterface | [
"Assign",
"a",
"dedicated",
"IP",
"to",
"the",
"domain",
"specified",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/Ip.php#L82-L94 | train |
mailgun/mailgun-php | src/Api/Ip.php | Ip.unassign | public function unassign(string $domain, string $ip)
{
Assert::stringNotEmpty($domain);
Assert::ip($ip);
$response = $this->httpDelete(sprintf('/v3/domains/%s/ips/%s', $domain, $ip));
return $this->hydrateResponse($response, UpdateResponse::class);
} | php | public function unassign(string $domain, string $ip)
{
Assert::stringNotEmpty($domain);
Assert::ip($ip);
$response = $this->httpDelete(sprintf('/v3/domains/%s/ips/%s', $domain, $ip));
return $this->hydrateResponse($response, UpdateResponse::class);
} | [
"public",
"function",
"unassign",
"(",
"string",
"$",
"domain",
",",
"string",
"$",
"ip",
")",
"{",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"domain",
")",
";",
"Assert",
"::",
"ip",
"(",
"$",
"ip",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"httpDelete",
"(",
"sprintf",
"(",
"'/v3/domains/%s/ips/%s'",
",",
"$",
"domain",
",",
"$",
"ip",
")",
")",
";",
"return",
"$",
"this",
"->",
"hydrateResponse",
"(",
"$",
"response",
",",
"UpdateResponse",
"::",
"class",
")",
";",
"}"
] | Unassign an IP from the domain specified.
@return UpdateResponse|ResponseInterface | [
"Unassign",
"an",
"IP",
"from",
"the",
"domain",
"specified",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/Ip.php#L103-L111 | train |
mailgun/mailgun-php | src/Api/MailingList.php | MailingList.pages | public function pages(int $limit = 100)
{
Assert::range($limit, 1, 1000);
$params = [
'limit' => $limit,
];
$response = $this->httpGet('/v3/lists/pages', $params);
return $this->hydrateResponse($response, PagesResponse::class);
} | php | public function pages(int $limit = 100)
{
Assert::range($limit, 1, 1000);
$params = [
'limit' => $limit,
];
$response = $this->httpGet('/v3/lists/pages', $params);
return $this->hydrateResponse($response, PagesResponse::class);
} | [
"public",
"function",
"pages",
"(",
"int",
"$",
"limit",
"=",
"100",
")",
"{",
"Assert",
"::",
"range",
"(",
"$",
"limit",
",",
"1",
",",
"1000",
")",
";",
"$",
"params",
"=",
"[",
"'limit'",
"=>",
"$",
"limit",
",",
"]",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"httpGet",
"(",
"'/v3/lists/pages'",
",",
"$",
"params",
")",
";",
"return",
"$",
"this",
"->",
"hydrateResponse",
"(",
"$",
"response",
",",
"PagesResponse",
"::",
"class",
")",
";",
"}"
] | Returns a paginated list of mailing lists on the domain.
@param int $limit Maximum number of records to return (optional: 100 by default)
@return PagesResponse
@throws \Exception | [
"Returns",
"a",
"paginated",
"list",
"of",
"mailing",
"lists",
"on",
"the",
"domain",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/MailingList.php#L41-L52 | train |
mailgun/mailgun-php | src/Api/MailingList.php | MailingList.create | public function create(string $address, string $name = null, string $description = null, string $accessLevel = 'readonly')
{
Assert::stringNotEmpty($address);
Assert::nullOrStringNotEmpty($name);
Assert::nullOrStringNotEmpty($description);
Assert::oneOf($accessLevel, ['readonly', 'members', 'everyone']);
$params = [
'address' => $address,
'name' => $name,
'description' => $description,
'access_level' => $accessLevel,
];
$response = $this->httpPost('/v3/lists', $params);
return $this->hydrateResponse($response, CreateResponse::class);
} | php | public function create(string $address, string $name = null, string $description = null, string $accessLevel = 'readonly')
{
Assert::stringNotEmpty($address);
Assert::nullOrStringNotEmpty($name);
Assert::nullOrStringNotEmpty($description);
Assert::oneOf($accessLevel, ['readonly', 'members', 'everyone']);
$params = [
'address' => $address,
'name' => $name,
'description' => $description,
'access_level' => $accessLevel,
];
$response = $this->httpPost('/v3/lists', $params);
return $this->hydrateResponse($response, CreateResponse::class);
} | [
"public",
"function",
"create",
"(",
"string",
"$",
"address",
",",
"string",
"$",
"name",
"=",
"null",
",",
"string",
"$",
"description",
"=",
"null",
",",
"string",
"$",
"accessLevel",
"=",
"'readonly'",
")",
"{",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"address",
")",
";",
"Assert",
"::",
"nullOrStringNotEmpty",
"(",
"$",
"name",
")",
";",
"Assert",
"::",
"nullOrStringNotEmpty",
"(",
"$",
"description",
")",
";",
"Assert",
"::",
"oneOf",
"(",
"$",
"accessLevel",
",",
"[",
"'readonly'",
",",
"'members'",
",",
"'everyone'",
"]",
")",
";",
"$",
"params",
"=",
"[",
"'address'",
"=>",
"$",
"address",
",",
"'name'",
"=>",
"$",
"name",
",",
"'description'",
"=>",
"$",
"description",
",",
"'access_level'",
"=>",
"$",
"accessLevel",
",",
"]",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"httpPost",
"(",
"'/v3/lists'",
",",
"$",
"params",
")",
";",
"return",
"$",
"this",
"->",
"hydrateResponse",
"(",
"$",
"response",
",",
"CreateResponse",
"::",
"class",
")",
";",
"}"
] | Creates a new mailing list on the current domain.
@param string $address Address for the new mailing list
@param string $name Name for the new mailing list (optional)
@param string $description Description for the new mailing list (optional)
@param string $accessLevel List access level, one of: readonly (default), members, everyone
@return CreateResponse
@throws \Exception | [
"Creates",
"a",
"new",
"mailing",
"list",
"on",
"the",
"current",
"domain",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/MailingList.php#L66-L83 | train |
mailgun/mailgun-php | src/Api/MailingList.php | MailingList.update | public function update(string $address, array $parameters = [])
{
Assert::stringNotEmpty($address);
Assert::isArray($parameters);
foreach ($parameters as $field => $value) {
switch ($field) {
case 'address':
case 'name':
case 'description':
Assert::stringNotEmpty($value);
break;
case 'access_level':
Assert::oneOf($value, ['readonly', 'members', 'everyone']);
break;
}
}
$response = $this->httpPut(sprintf('/v3/lists/%s', $address), $parameters);
return $this->hydrateResponse($response, UpdateResponse::class);
} | php | public function update(string $address, array $parameters = [])
{
Assert::stringNotEmpty($address);
Assert::isArray($parameters);
foreach ($parameters as $field => $value) {
switch ($field) {
case 'address':
case 'name':
case 'description':
Assert::stringNotEmpty($value);
break;
case 'access_level':
Assert::oneOf($value, ['readonly', 'members', 'everyone']);
break;
}
}
$response = $this->httpPut(sprintf('/v3/lists/%s', $address), $parameters);
return $this->hydrateResponse($response, UpdateResponse::class);
} | [
"public",
"function",
"update",
"(",
"string",
"$",
"address",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"address",
")",
";",
"Assert",
"::",
"isArray",
"(",
"$",
"parameters",
")",
";",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"switch",
"(",
"$",
"field",
")",
"{",
"case",
"'address'",
":",
"case",
"'name'",
":",
"case",
"'description'",
":",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"value",
")",
";",
"break",
";",
"case",
"'access_level'",
":",
"Assert",
"::",
"oneOf",
"(",
"$",
"value",
",",
"[",
"'readonly'",
",",
"'members'",
",",
"'everyone'",
"]",
")",
";",
"break",
";",
"}",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"httpPut",
"(",
"sprintf",
"(",
"'/v3/lists/%s'",
",",
"$",
"address",
")",
",",
"$",
"parameters",
")",
";",
"return",
"$",
"this",
"->",
"hydrateResponse",
"(",
"$",
"response",
",",
"UpdateResponse",
"::",
"class",
")",
";",
"}"
] | Updates a mailing list.
@param string $address Address of the mailing list
@param array $parameters Array of field => value pairs to update
@return UpdateResponse
@throws \Exception | [
"Updates",
"a",
"mailing",
"list",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/MailingList.php#L113-L136 | train |
mailgun/mailgun-php | src/Api/EmailValidation.php | EmailValidation.validate | public function validate(string $address, bool $mailboxVerification = false)
{
Assert::stringNotEmpty($address);
$params = [
'address' => $address,
'mailbox_verification' => $mailboxVerification,
];
$response = $this->httpGet('/address/private/validate', $params);
return $this->hydrateResponse($response, ValidateResponse::class);
} | php | public function validate(string $address, bool $mailboxVerification = false)
{
Assert::stringNotEmpty($address);
$params = [
'address' => $address,
'mailbox_verification' => $mailboxVerification,
];
$response = $this->httpGet('/address/private/validate', $params);
return $this->hydrateResponse($response, ValidateResponse::class);
} | [
"public",
"function",
"validate",
"(",
"string",
"$",
"address",
",",
"bool",
"$",
"mailboxVerification",
"=",
"false",
")",
"{",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"address",
")",
";",
"$",
"params",
"=",
"[",
"'address'",
"=>",
"$",
"address",
",",
"'mailbox_verification'",
"=>",
"$",
"mailboxVerification",
",",
"]",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"httpGet",
"(",
"'/address/private/validate'",
",",
"$",
"params",
")",
";",
"return",
"$",
"this",
"->",
"hydrateResponse",
"(",
"$",
"response",
",",
"ValidateResponse",
"::",
"class",
")",
";",
"}"
] | Addresses are validated based off defined checks.
This operation is only accessible with the private API key and not subject to the daily usage limits.
@param string $address An email address to validate. Maximum: 512 characters.
@param bool $mailboxVerification If set to true, a mailbox verification check will be performed
against the address. The default is False.
@throws InvalidArgumentException Thrown when local validation returns an error
@throws HttpClientException Thrown when there's an error on Client side
@throws HttpServerException Thrown when there's an error on Server side
@throws \Exception Thrown when we don't catch a Client or Server side Exception
@return ValidateResponse|ResponseInterface | [
"Addresses",
"are",
"validated",
"based",
"off",
"defined",
"checks",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/EmailValidation.php#L45-L57 | train |
mailgun/mailgun-php | src/Api/Domain.php | Domain.index | public function index(int $limit = 100, int $skip = 0)
{
Assert::range($limit, 1, 1000);
$params = [
'limit' => $limit,
'skip' => $skip,
];
$response = $this->httpGet('/v3/domains', $params);
return $this->hydrateResponse($response, IndexResponse::class);
} | php | public function index(int $limit = 100, int $skip = 0)
{
Assert::range($limit, 1, 1000);
$params = [
'limit' => $limit,
'skip' => $skip,
];
$response = $this->httpGet('/v3/domains', $params);
return $this->hydrateResponse($response, IndexResponse::class);
} | [
"public",
"function",
"index",
"(",
"int",
"$",
"limit",
"=",
"100",
",",
"int",
"$",
"skip",
"=",
"0",
")",
"{",
"Assert",
"::",
"range",
"(",
"$",
"limit",
",",
"1",
",",
"1000",
")",
";",
"$",
"params",
"=",
"[",
"'limit'",
"=>",
"$",
"limit",
",",
"'skip'",
"=>",
"$",
"skip",
",",
"]",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"httpGet",
"(",
"'/v3/domains'",
",",
"$",
"params",
")",
";",
"return",
"$",
"this",
"->",
"hydrateResponse",
"(",
"$",
"response",
",",
"IndexResponse",
"::",
"class",
")",
";",
"}"
] | Returns a list of domains on the account.
@return IndexResponse | [
"Returns",
"a",
"list",
"of",
"domains",
"on",
"the",
"account",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/Domain.php#L41-L53 | train |
mailgun/mailgun-php | src/Api/Domain.php | Domain.credentials | public function credentials(string $domain, int $limit = 100, int $skip = 0)
{
Assert::stringNotEmpty($domain);
$params = [
'limit' => $limit,
'skip' => $skip,
];
$response = $this->httpGet(sprintf('/v3/domains/%s/credentials', $domain), $params);
return $this->hydrateResponse($response, CredentialResponse::class);
} | php | public function credentials(string $domain, int $limit = 100, int $skip = 0)
{
Assert::stringNotEmpty($domain);
$params = [
'limit' => $limit,
'skip' => $skip,
];
$response = $this->httpGet(sprintf('/v3/domains/%s/credentials', $domain), $params);
return $this->hydrateResponse($response, CredentialResponse::class);
} | [
"public",
"function",
"credentials",
"(",
"string",
"$",
"domain",
",",
"int",
"$",
"limit",
"=",
"100",
",",
"int",
"$",
"skip",
"=",
"0",
")",
"{",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"domain",
")",
";",
"$",
"params",
"=",
"[",
"'limit'",
"=>",
"$",
"limit",
",",
"'skip'",
"=>",
"$",
"skip",
",",
"]",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"httpGet",
"(",
"sprintf",
"(",
"'/v3/domains/%s/credentials'",
",",
"$",
"domain",
")",
",",
"$",
"params",
")",
";",
"return",
"$",
"this",
"->",
"hydrateResponse",
"(",
"$",
"response",
",",
"CredentialResponse",
"::",
"class",
")",
";",
"}"
] | Returns a list of SMTP credentials for the specified domain.
@param string $domain name of the domain
@param int $limit Number of credentials to return
@param int $skip Number of credentials to omit from the list
@return CredentialResponse | [
"Returns",
"a",
"list",
"of",
"SMTP",
"credentials",
"for",
"the",
"specified",
"domain",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/Domain.php#L132-L143 | train |
mailgun/mailgun-php | src/Api/Domain.php | Domain.createCredential | public function createCredential(string $domain, string $login, string $password)
{
Assert::stringNotEmpty($domain);
Assert::stringNotEmpty($login);
Assert::stringNotEmpty($password);
Assert::lengthBetween($password, 5, 32, 'SMTP password must be between 5 and 32 characters.');
$params = [
'login' => $login,
'password' => $password,
];
$response = $this->httpPost(sprintf('/v3/domains/%s/credentials', $domain), $params);
return $this->hydrateResponse($response, CreateCredentialResponse::class);
} | php | public function createCredential(string $domain, string $login, string $password)
{
Assert::stringNotEmpty($domain);
Assert::stringNotEmpty($login);
Assert::stringNotEmpty($password);
Assert::lengthBetween($password, 5, 32, 'SMTP password must be between 5 and 32 characters.');
$params = [
'login' => $login,
'password' => $password,
];
$response = $this->httpPost(sprintf('/v3/domains/%s/credentials', $domain), $params);
return $this->hydrateResponse($response, CreateCredentialResponse::class);
} | [
"public",
"function",
"createCredential",
"(",
"string",
"$",
"domain",
",",
"string",
"$",
"login",
",",
"string",
"$",
"password",
")",
"{",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"domain",
")",
";",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"login",
")",
";",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"password",
")",
";",
"Assert",
"::",
"lengthBetween",
"(",
"$",
"password",
",",
"5",
",",
"32",
",",
"'SMTP password must be between 5 and 32 characters.'",
")",
";",
"$",
"params",
"=",
"[",
"'login'",
"=>",
"$",
"login",
",",
"'password'",
"=>",
"$",
"password",
",",
"]",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"httpPost",
"(",
"sprintf",
"(",
"'/v3/domains/%s/credentials'",
",",
"$",
"domain",
")",
",",
"$",
"params",
")",
";",
"return",
"$",
"this",
"->",
"hydrateResponse",
"(",
"$",
"response",
",",
"CreateCredentialResponse",
"::",
"class",
")",
";",
"}"
] | Create a new SMTP credential pair for the specified domain.
@param string $domain name of the domain
@param string $login SMTP Username
@param string $password SMTP Password. Length min 5, max 32.
@return CreateCredentialResponse|array|ResponseInterface | [
"Create",
"a",
"new",
"SMTP",
"credential",
"pair",
"for",
"the",
"specified",
"domain",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/Domain.php#L154-L169 | train |
mailgun/mailgun-php | src/Api/Domain.php | Domain.updateCredential | public function updateCredential(string $domain, string $login, string $pass)
{
Assert::stringNotEmpty($domain);
Assert::stringNotEmpty($login);
Assert::stringNotEmpty($pass);
Assert::lengthBetween($pass, 5, 32, 'SMTP password must be between 5 and 32 characters.');
$params = [
'password' => $pass,
];
$response = $this->httpPut(sprintf('/v3/domains/%s/credentials/%s', $domain, $login), $params);
return $this->hydrateResponse($response, UpdateCredentialResponse::class);
} | php | public function updateCredential(string $domain, string $login, string $pass)
{
Assert::stringNotEmpty($domain);
Assert::stringNotEmpty($login);
Assert::stringNotEmpty($pass);
Assert::lengthBetween($pass, 5, 32, 'SMTP password must be between 5 and 32 characters.');
$params = [
'password' => $pass,
];
$response = $this->httpPut(sprintf('/v3/domains/%s/credentials/%s', $domain, $login), $params);
return $this->hydrateResponse($response, UpdateCredentialResponse::class);
} | [
"public",
"function",
"updateCredential",
"(",
"string",
"$",
"domain",
",",
"string",
"$",
"login",
",",
"string",
"$",
"pass",
")",
"{",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"domain",
")",
";",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"login",
")",
";",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"pass",
")",
";",
"Assert",
"::",
"lengthBetween",
"(",
"$",
"pass",
",",
"5",
",",
"32",
",",
"'SMTP password must be between 5 and 32 characters.'",
")",
";",
"$",
"params",
"=",
"[",
"'password'",
"=>",
"$",
"pass",
",",
"]",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"httpPut",
"(",
"sprintf",
"(",
"'/v3/domains/%s/credentials/%s'",
",",
"$",
"domain",
",",
"$",
"login",
")",
",",
"$",
"params",
")",
";",
"return",
"$",
"this",
"->",
"hydrateResponse",
"(",
"$",
"response",
",",
"UpdateCredentialResponse",
"::",
"class",
")",
";",
"}"
] | Update a set of SMTP credentials for the specified domain.
@param string $domain name of the domain
@param string $login SMTP Username
@param string $pass New SMTP Password. Length min 5, max 32.
@return UpdateCredentialResponse|array|ResponseInterface | [
"Update",
"a",
"set",
"of",
"SMTP",
"credentials",
"for",
"the",
"specified",
"domain",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/Domain.php#L180-L194 | train |
mailgun/mailgun-php | src/Api/Domain.php | Domain.deleteCredential | public function deleteCredential(string $domain, string $login)
{
Assert::stringNotEmpty($domain);
Assert::stringNotEmpty($login);
$response = $this->httpDelete(
sprintf(
'/v3/domains/%s/credentials/%s',
$domain,
$login
)
);
return $this->hydrateResponse($response, DeleteCredentialResponse::class);
} | php | public function deleteCredential(string $domain, string $login)
{
Assert::stringNotEmpty($domain);
Assert::stringNotEmpty($login);
$response = $this->httpDelete(
sprintf(
'/v3/domains/%s/credentials/%s',
$domain,
$login
)
);
return $this->hydrateResponse($response, DeleteCredentialResponse::class);
} | [
"public",
"function",
"deleteCredential",
"(",
"string",
"$",
"domain",
",",
"string",
"$",
"login",
")",
"{",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"domain",
")",
";",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"login",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"httpDelete",
"(",
"sprintf",
"(",
"'/v3/domains/%s/credentials/%s'",
",",
"$",
"domain",
",",
"$",
"login",
")",
")",
";",
"return",
"$",
"this",
"->",
"hydrateResponse",
"(",
"$",
"response",
",",
"DeleteCredentialResponse",
"::",
"class",
")",
";",
"}"
] | Remove a set of SMTP credentials from the specified domain.
@param string $domain name of the domain
@param string $login SMTP Username
@return DeleteCredentialResponse|array|ResponseInterface | [
"Remove",
"a",
"set",
"of",
"SMTP",
"credentials",
"from",
"the",
"specified",
"domain",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/Domain.php#L204-L218 | train |
mailgun/mailgun-php | src/Api/Domain.php | Domain.connection | public function connection(string $domain)
{
Assert::stringNotEmpty($domain);
$response = $this->httpGet(sprintf('/v3/domains/%s/connection', $domain));
return $this->hydrateResponse($response, ConnectionResponse::class);
} | php | public function connection(string $domain)
{
Assert::stringNotEmpty($domain);
$response = $this->httpGet(sprintf('/v3/domains/%s/connection', $domain));
return $this->hydrateResponse($response, ConnectionResponse::class);
} | [
"public",
"function",
"connection",
"(",
"string",
"$",
"domain",
")",
"{",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"domain",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"httpGet",
"(",
"sprintf",
"(",
"'/v3/domains/%s/connection'",
",",
"$",
"domain",
")",
")",
";",
"return",
"$",
"this",
"->",
"hydrateResponse",
"(",
"$",
"response",
",",
"ConnectionResponse",
"::",
"class",
")",
";",
"}"
] | Returns delivery connection settings for the specified domain.
@param string $domain name of the domain
@return ConnectionResponse|ResponseInterface | [
"Returns",
"delivery",
"connection",
"settings",
"for",
"the",
"specified",
"domain",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/Domain.php#L227-L234 | train |
mailgun/mailgun-php | src/Api/Domain.php | Domain.updateConnection | public function updateConnection(string $domain, ?bool $requireTLS, ?bool $noVerify)
{
Assert::stringNotEmpty($domain);
$params = [];
if (null !== $requireTLS) {
$params['require_tls'] = $requireTLS ? 'true' : 'false';
}
if (null !== $noVerify) {
$params['skip_verification'] = $noVerify ? 'true' : 'false';
}
$response = $this->httpPut(sprintf('/v3/domains/%s/connection', $domain), $params);
return $this->hydrateResponse($response, UpdateConnectionResponse::class);
} | php | public function updateConnection(string $domain, ?bool $requireTLS, ?bool $noVerify)
{
Assert::stringNotEmpty($domain);
$params = [];
if (null !== $requireTLS) {
$params['require_tls'] = $requireTLS ? 'true' : 'false';
}
if (null !== $noVerify) {
$params['skip_verification'] = $noVerify ? 'true' : 'false';
}
$response = $this->httpPut(sprintf('/v3/domains/%s/connection', $domain), $params);
return $this->hydrateResponse($response, UpdateConnectionResponse::class);
} | [
"public",
"function",
"updateConnection",
"(",
"string",
"$",
"domain",
",",
"?",
"bool",
"$",
"requireTLS",
",",
"?",
"bool",
"$",
"noVerify",
")",
"{",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"domain",
")",
";",
"$",
"params",
"=",
"[",
"]",
";",
"if",
"(",
"null",
"!==",
"$",
"requireTLS",
")",
"{",
"$",
"params",
"[",
"'require_tls'",
"]",
"=",
"$",
"requireTLS",
"?",
"'true'",
":",
"'false'",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"noVerify",
")",
"{",
"$",
"params",
"[",
"'skip_verification'",
"]",
"=",
"$",
"noVerify",
"?",
"'true'",
":",
"'false'",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"httpPut",
"(",
"sprintf",
"(",
"'/v3/domains/%s/connection'",
",",
"$",
"domain",
")",
",",
"$",
"params",
")",
";",
"return",
"$",
"this",
"->",
"hydrateResponse",
"(",
"$",
"response",
",",
"UpdateConnectionResponse",
"::",
"class",
")",
";",
"}"
] | Updates the specified delivery connection settings for the specified domain.
If a parameter is passed in as null, it will not be updated.
@param string $domain name of the domain
@param bool|null $requireTLS enforces that messages are sent only over a TLS connection
@param bool|null $noVerify disables TLS certificate and hostname verification
@return UpdateConnectionResponse|array|ResponseInterface | [
"Updates",
"the",
"specified",
"delivery",
"connection",
"settings",
"for",
"the",
"specified",
"domain",
".",
"If",
"a",
"parameter",
"is",
"passed",
"in",
"as",
"null",
"it",
"will",
"not",
"be",
"updated",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/Domain.php#L246-L262 | train |
mailgun/mailgun-php | src/Api/Domain.php | Domain.verify | public function verify(string $domain)
{
Assert::stringNotEmpty($domain);
$response = $this->httpPut(sprintf('/v3/domains/%s/verify', $domain));
return $this->hydrateResponse($response, VerifyResponse::class);
} | php | public function verify(string $domain)
{
Assert::stringNotEmpty($domain);
$response = $this->httpPut(sprintf('/v3/domains/%s/verify', $domain));
return $this->hydrateResponse($response, VerifyResponse::class);
} | [
"public",
"function",
"verify",
"(",
"string",
"$",
"domain",
")",
"{",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"domain",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"httpPut",
"(",
"sprintf",
"(",
"'/v3/domains/%s/verify'",
",",
"$",
"domain",
")",
")",
";",
"return",
"$",
"this",
"->",
"hydrateResponse",
"(",
"$",
"response",
",",
"VerifyResponse",
"::",
"class",
")",
";",
"}"
] | Returns a single domain.
@param string $domain name of the domain
@return VerifyResponse|array|ResponseInterface | [
"Returns",
"a",
"single",
"domain",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/Domain.php#L271-L278 | train |
mailgun/mailgun-php | src/Api/MailingList/Member.php | Member.index | public function index(string $address, int $limit = 100, bool $subscribed = null)
{
Assert::stringNotEmpty($address);
Assert::greaterThan($limit, 0);
$params = [
'limit' => $limit,
];
if (true === $subscribed) {
$params['subscribed'] = 'yes';
} elseif (false === $subscribed) {
$params['subscribed'] = 'no';
}
$response = $this->httpGet(sprintf('/v3/lists/%s/members/pages', $address), $params);
return $this->hydrateResponse($response, IndexResponse::class);
} | php | public function index(string $address, int $limit = 100, bool $subscribed = null)
{
Assert::stringNotEmpty($address);
Assert::greaterThan($limit, 0);
$params = [
'limit' => $limit,
];
if (true === $subscribed) {
$params['subscribed'] = 'yes';
} elseif (false === $subscribed) {
$params['subscribed'] = 'no';
}
$response = $this->httpGet(sprintf('/v3/lists/%s/members/pages', $address), $params);
return $this->hydrateResponse($response, IndexResponse::class);
} | [
"public",
"function",
"index",
"(",
"string",
"$",
"address",
",",
"int",
"$",
"limit",
"=",
"100",
",",
"bool",
"$",
"subscribed",
"=",
"null",
")",
"{",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"address",
")",
";",
"Assert",
"::",
"greaterThan",
"(",
"$",
"limit",
",",
"0",
")",
";",
"$",
"params",
"=",
"[",
"'limit'",
"=>",
"$",
"limit",
",",
"]",
";",
"if",
"(",
"true",
"===",
"$",
"subscribed",
")",
"{",
"$",
"params",
"[",
"'subscribed'",
"]",
"=",
"'yes'",
";",
"}",
"elseif",
"(",
"false",
"===",
"$",
"subscribed",
")",
"{",
"$",
"params",
"[",
"'subscribed'",
"]",
"=",
"'no'",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"httpGet",
"(",
"sprintf",
"(",
"'/v3/lists/%s/members/pages'",
",",
"$",
"address",
")",
",",
"$",
"params",
")",
";",
"return",
"$",
"this",
"->",
"hydrateResponse",
"(",
"$",
"response",
",",
"IndexResponse",
"::",
"class",
")",
";",
"}"
] | Returns a paginated list of members of the mailing list.
@param string $address Address of the mailing list
@param int $limit Maximum number of records to return (optional: 100 by default)
@param bool|null $subscribed `true` to lists subscribed, `false` for unsubscribed. list all if null
@return IndexResponse
@throws \Exception | [
"Returns",
"a",
"paginated",
"list",
"of",
"members",
"of",
"the",
"mailing",
"list",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/MailingList/Member.php#L40-L58 | train |
mailgun/mailgun-php | src/Api/Route.php | Route.show | public function show(string $routeId)
{
Assert::stringNotEmpty($routeId);
$response = $this->httpGet(sprintf('/v3/routes/%s', $routeId));
return $this->hydrateResponse($response, ShowResponse::class);
} | php | public function show(string $routeId)
{
Assert::stringNotEmpty($routeId);
$response = $this->httpGet(sprintf('/v3/routes/%s', $routeId));
return $this->hydrateResponse($response, ShowResponse::class);
} | [
"public",
"function",
"show",
"(",
"string",
"$",
"routeId",
")",
"{",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"routeId",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"httpGet",
"(",
"sprintf",
"(",
"'/v3/routes/%s'",
",",
"$",
"routeId",
")",
")",
";",
"return",
"$",
"this",
"->",
"hydrateResponse",
"(",
"$",
"response",
",",
"ShowResponse",
"::",
"class",
")",
";",
"}"
] | Returns a single Route object based on its ID.
@param string $routeId Route ID returned by the Routes::index() method
@return ShowResponse | [
"Returns",
"a",
"single",
"Route",
"object",
"based",
"on",
"its",
"ID",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/Route.php#L59-L66 | train |
mailgun/mailgun-php | src/Api/Route.php | Route.create | public function create(string $expression, array $actions, string $description, int $priority = 0)
{
Assert::isArray($actions);
$params = [
'priority' => (string) $priority,
'expression' => $expression,
'action' => $actions,
'description' => $description,
];
$response = $this->httpPost('/v3/routes', $params);
return $this->hydrateResponse($response, CreateResponse::class);
} | php | public function create(string $expression, array $actions, string $description, int $priority = 0)
{
Assert::isArray($actions);
$params = [
'priority' => (string) $priority,
'expression' => $expression,
'action' => $actions,
'description' => $description,
];
$response = $this->httpPost('/v3/routes', $params);
return $this->hydrateResponse($response, CreateResponse::class);
} | [
"public",
"function",
"create",
"(",
"string",
"$",
"expression",
",",
"array",
"$",
"actions",
",",
"string",
"$",
"description",
",",
"int",
"$",
"priority",
"=",
"0",
")",
"{",
"Assert",
"::",
"isArray",
"(",
"$",
"actions",
")",
";",
"$",
"params",
"=",
"[",
"'priority'",
"=>",
"(",
"string",
")",
"$",
"priority",
",",
"'expression'",
"=>",
"$",
"expression",
",",
"'action'",
"=>",
"$",
"actions",
",",
"'description'",
"=>",
"$",
"description",
",",
"]",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"httpPost",
"(",
"'/v3/routes'",
",",
"$",
"params",
")",
";",
"return",
"$",
"this",
"->",
"hydrateResponse",
"(",
"$",
"response",
",",
"CreateResponse",
"::",
"class",
")",
";",
"}"
] | Creates a new Route.
@param string $expression A filter expression like "match_recipient('.*@gmail.com')"
@param array $actions Route action. This action is executed when the expression evaluates to True. Example: "forward('alice@example.com')"
@param string $description An arbitrary string
@param int $priority Integer: smaller number indicates higher priority. Higher priority routes are handled first. Defaults to 0.
@return CreateResponse | [
"Creates",
"a",
"new",
"Route",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/Route.php#L78-L92 | train |
mailgun/mailgun-php | src/Api/Route.php | Route.update | public function update(
string $routeId,
string $expression = null,
array $actions = [],
string $description = null,
int $priority = null
) {
Assert::stringNotEmpty($routeId);
$params = [];
if (!empty($expression)) {
$params['expression'] = trim($expression);
}
foreach ($actions as $action) {
Assert::stringNotEmpty($action);
$params['action'] = isset($params['action']) ? $params['action'] : [];
$params['action'][] = $action;
}
if (!empty($description)) {
$params['description'] = trim($description);
}
if (!empty($priority)) {
$params['priority'] = (string) $priority;
}
$response = $this->httpPut(sprintf('/v3/routes/%s', $routeId), $params);
return $this->hydrateResponse($response, UpdateResponse::class);
} | php | public function update(
string $routeId,
string $expression = null,
array $actions = [],
string $description = null,
int $priority = null
) {
Assert::stringNotEmpty($routeId);
$params = [];
if (!empty($expression)) {
$params['expression'] = trim($expression);
}
foreach ($actions as $action) {
Assert::stringNotEmpty($action);
$params['action'] = isset($params['action']) ? $params['action'] : [];
$params['action'][] = $action;
}
if (!empty($description)) {
$params['description'] = trim($description);
}
if (!empty($priority)) {
$params['priority'] = (string) $priority;
}
$response = $this->httpPut(sprintf('/v3/routes/%s', $routeId), $params);
return $this->hydrateResponse($response, UpdateResponse::class);
} | [
"public",
"function",
"update",
"(",
"string",
"$",
"routeId",
",",
"string",
"$",
"expression",
"=",
"null",
",",
"array",
"$",
"actions",
"=",
"[",
"]",
",",
"string",
"$",
"description",
"=",
"null",
",",
"int",
"$",
"priority",
"=",
"null",
")",
"{",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"routeId",
")",
";",
"$",
"params",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"expression",
")",
")",
"{",
"$",
"params",
"[",
"'expression'",
"]",
"=",
"trim",
"(",
"$",
"expression",
")",
";",
"}",
"foreach",
"(",
"$",
"actions",
"as",
"$",
"action",
")",
"{",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"action",
")",
";",
"$",
"params",
"[",
"'action'",
"]",
"=",
"isset",
"(",
"$",
"params",
"[",
"'action'",
"]",
")",
"?",
"$",
"params",
"[",
"'action'",
"]",
":",
"[",
"]",
";",
"$",
"params",
"[",
"'action'",
"]",
"[",
"]",
"=",
"$",
"action",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"description",
")",
")",
"{",
"$",
"params",
"[",
"'description'",
"]",
"=",
"trim",
"(",
"$",
"description",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"priority",
")",
")",
"{",
"$",
"params",
"[",
"'priority'",
"]",
"=",
"(",
"string",
")",
"$",
"priority",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"httpPut",
"(",
"sprintf",
"(",
"'/v3/routes/%s'",
",",
"$",
"routeId",
")",
",",
"$",
"params",
")",
";",
"return",
"$",
"this",
"->",
"hydrateResponse",
"(",
"$",
"response",
",",
"UpdateResponse",
"::",
"class",
")",
";",
"}"
] | Updates a given Route by ID. All parameters are optional.
This API call only updates the specified fields leaving others unchanged.
@param string $routeId Route ID returned by the Routes::index() method
@param string|null $expression A filter expression like "match_recipient('.*@gmail.com')"
@param array $actions Route action. This action is executed when the expression evaluates to True. Example: "forward('alice@example.com')"
@param string|null $description An arbitrary string
@param int|null $priority Integer: smaller number indicates higher priority. Higher priority routes are handled first. Defaults to 0.
@return UpdateResponse | [
"Updates",
"a",
"given",
"Route",
"by",
"ID",
".",
"All",
"parameters",
"are",
"optional",
".",
"This",
"API",
"call",
"only",
"updates",
"the",
"specified",
"fields",
"leaving",
"others",
"unchanged",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/Route.php#L106-L138 | train |
mailgun/mailgun-php | src/Api/Route.php | Route.delete | public function delete(string $routeId)
{
Assert::stringNotEmpty($routeId);
$response = $this->httpDelete(sprintf('/v3/routes/%s', $routeId));
return $this->hydrateResponse($response, DeleteResponse::class);
} | php | public function delete(string $routeId)
{
Assert::stringNotEmpty($routeId);
$response = $this->httpDelete(sprintf('/v3/routes/%s', $routeId));
return $this->hydrateResponse($response, DeleteResponse::class);
} | [
"public",
"function",
"delete",
"(",
"string",
"$",
"routeId",
")",
"{",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"routeId",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"httpDelete",
"(",
"sprintf",
"(",
"'/v3/routes/%s'",
",",
"$",
"routeId",
")",
")",
";",
"return",
"$",
"this",
"->",
"hydrateResponse",
"(",
"$",
"response",
",",
"DeleteResponse",
"::",
"class",
")",
";",
"}"
] | Deletes a Route based on the ID.
@param string $routeId Route ID returned by the Routes::index() method
@return DeleteResponse | [
"Deletes",
"a",
"Route",
"based",
"on",
"the",
"ID",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/Route.php#L147-L154 | train |
mailgun/mailgun-php | src/Api/Webhook.php | Webhook.verifyWebhookSignature | public function verifyWebhookSignature(int $timestamp, string $token, string $signature): bool
{
if (empty($timestamp) || empty($token) || empty($signature)) {
return false;
}
$hmac = hash_hmac('sha256', $timestamp.$token, $this->apiKey);
if (function_exists('hash_equals')) {
// hash_equals is constant time, but will not be introduced until PHP 5.6
return hash_equals($hmac, $signature);
} else {
return $hmac === $signature;
}
} | php | public function verifyWebhookSignature(int $timestamp, string $token, string $signature): bool
{
if (empty($timestamp) || empty($token) || empty($signature)) {
return false;
}
$hmac = hash_hmac('sha256', $timestamp.$token, $this->apiKey);
if (function_exists('hash_equals')) {
// hash_equals is constant time, but will not be introduced until PHP 5.6
return hash_equals($hmac, $signature);
} else {
return $hmac === $signature;
}
} | [
"public",
"function",
"verifyWebhookSignature",
"(",
"int",
"$",
"timestamp",
",",
"string",
"$",
"token",
",",
"string",
"$",
"signature",
")",
":",
"bool",
"{",
"if",
"(",
"empty",
"(",
"$",
"timestamp",
")",
"||",
"empty",
"(",
"$",
"token",
")",
"||",
"empty",
"(",
"$",
"signature",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"hmac",
"=",
"hash_hmac",
"(",
"'sha256'",
",",
"$",
"timestamp",
".",
"$",
"token",
",",
"$",
"this",
"->",
"apiKey",
")",
";",
"if",
"(",
"function_exists",
"(",
"'hash_equals'",
")",
")",
"{",
"// hash_equals is constant time, but will not be introduced until PHP 5.6",
"return",
"hash_equals",
"(",
"$",
"hmac",
",",
"$",
"signature",
")",
";",
"}",
"else",
"{",
"return",
"$",
"hmac",
"===",
"$",
"signature",
";",
"}",
"}"
] | This function verifies the webhook signature with your API key to to see if it is authentic.
If this function returns FALSE, you must not process the request.
You should reject the request with status code 403 Forbidden. | [
"This",
"function",
"verifies",
"the",
"webhook",
"signature",
"with",
"your",
"API",
"key",
"to",
"to",
"see",
"if",
"it",
"is",
"authentic",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/Webhook.php#L49-L63 | train |
mailgun/mailgun-php | src/Model/Route/Action.php | Action.createMultiple | public static function createMultiple(array $data)
{
$items = [];
foreach ($data as $action) {
$items[] = new self($action);
}
return $items;
} | php | public static function createMultiple(array $data)
{
$items = [];
foreach ($data as $action) {
$items[] = new self($action);
}
return $items;
} | [
"public",
"static",
"function",
"createMultiple",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"items",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"action",
")",
"{",
"$",
"items",
"[",
"]",
"=",
"new",
"self",
"(",
"$",
"action",
")",
";",
"}",
"return",
"$",
"items",
";",
"}"
] | Action Named Constructor to build several Action DTOs provided by an Array.
@return Action[] | [
"Action",
"Named",
"Constructor",
"to",
"build",
"several",
"Action",
"DTOs",
"provided",
"by",
"an",
"Array",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Model/Route/Action.php#L26-L35 | train |
mailgun/mailgun-php | src/Api/HttpApi.php | HttpApi.handleErrors | protected function handleErrors(ResponseInterface $response)
{
$statusCode = $response->getStatusCode();
switch ($statusCode) {
case 400:
throw HttpClientException::badRequest($response);
case 401:
throw HttpClientException::unauthorized($response);
case 402:
throw HttpClientException::requestFailed($response);
case 404:
throw HttpClientException::notFound($response);
case 413:
throw HttpClientException::payloadTooLarge($response);
case 500 <= $statusCode:
throw HttpServerException::serverError($statusCode);
default:
throw new UnknownErrorException();
}
} | php | protected function handleErrors(ResponseInterface $response)
{
$statusCode = $response->getStatusCode();
switch ($statusCode) {
case 400:
throw HttpClientException::badRequest($response);
case 401:
throw HttpClientException::unauthorized($response);
case 402:
throw HttpClientException::requestFailed($response);
case 404:
throw HttpClientException::notFound($response);
case 413:
throw HttpClientException::payloadTooLarge($response);
case 500 <= $statusCode:
throw HttpServerException::serverError($statusCode);
default:
throw new UnknownErrorException();
}
} | [
"protected",
"function",
"handleErrors",
"(",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"statusCode",
"=",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
";",
"switch",
"(",
"$",
"statusCode",
")",
"{",
"case",
"400",
":",
"throw",
"HttpClientException",
"::",
"badRequest",
"(",
"$",
"response",
")",
";",
"case",
"401",
":",
"throw",
"HttpClientException",
"::",
"unauthorized",
"(",
"$",
"response",
")",
";",
"case",
"402",
":",
"throw",
"HttpClientException",
"::",
"requestFailed",
"(",
"$",
"response",
")",
";",
"case",
"404",
":",
"throw",
"HttpClientException",
"::",
"notFound",
"(",
"$",
"response",
")",
";",
"case",
"413",
":",
"throw",
"HttpClientException",
"::",
"payloadTooLarge",
"(",
"$",
"response",
")",
";",
"case",
"500",
"<=",
"$",
"statusCode",
":",
"throw",
"HttpServerException",
"::",
"serverError",
"(",
"$",
"statusCode",
")",
";",
"default",
":",
"throw",
"new",
"UnknownErrorException",
"(",
")",
";",
"}",
"}"
] | Throw the correct exception for this error.
@throws \Exception | [
"Throw",
"the",
"correct",
"exception",
"for",
"this",
"error",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/HttpApi.php#L78-L97 | train |
mailgun/mailgun-php | src/Api/HttpApi.php | HttpApi.httpPost | protected function httpPost(string $path, array $parameters = [], array $requestHeaders = []): ResponseInterface
{
return $this->httpPostRaw($path, $this->createRequestBody($parameters), $requestHeaders);
} | php | protected function httpPost(string $path, array $parameters = [], array $requestHeaders = []): ResponseInterface
{
return $this->httpPostRaw($path, $this->createRequestBody($parameters), $requestHeaders);
} | [
"protected",
"function",
"httpPost",
"(",
"string",
"$",
"path",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
",",
"array",
"$",
"requestHeaders",
"=",
"[",
"]",
")",
":",
"ResponseInterface",
"{",
"return",
"$",
"this",
"->",
"httpPostRaw",
"(",
"$",
"path",
",",
"$",
"this",
"->",
"createRequestBody",
"(",
"$",
"parameters",
")",
",",
"$",
"requestHeaders",
")",
";",
"}"
] | Send a POST request with parameters.
@param string $path Request path
@param array $parameters POST parameters
@param array $requestHeaders Request headers | [
"Send",
"a",
"POST",
"request",
"with",
"parameters",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/HttpApi.php#L130-L133 | train |
mailgun/mailgun-php | src/Api/HttpApi.php | HttpApi.httpPut | protected function httpPut(string $path, array $parameters = [], array $requestHeaders = []): ResponseInterface
{
try {
$response = $this->httpClient->sendRequest(
$this->requestBuilder->create('PUT', $path, $requestHeaders, $this->createRequestBody($parameters))
);
} catch (Psr18\NetworkExceptionInterface $e) {
throw HttpServerException::networkError($e);
}
return $response;
} | php | protected function httpPut(string $path, array $parameters = [], array $requestHeaders = []): ResponseInterface
{
try {
$response = $this->httpClient->sendRequest(
$this->requestBuilder->create('PUT', $path, $requestHeaders, $this->createRequestBody($parameters))
);
} catch (Psr18\NetworkExceptionInterface $e) {
throw HttpServerException::networkError($e);
}
return $response;
} | [
"protected",
"function",
"httpPut",
"(",
"string",
"$",
"path",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
",",
"array",
"$",
"requestHeaders",
"=",
"[",
"]",
")",
":",
"ResponseInterface",
"{",
"try",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"httpClient",
"->",
"sendRequest",
"(",
"$",
"this",
"->",
"requestBuilder",
"->",
"create",
"(",
"'PUT'",
",",
"$",
"path",
",",
"$",
"requestHeaders",
",",
"$",
"this",
"->",
"createRequestBody",
"(",
"$",
"parameters",
")",
")",
")",
";",
"}",
"catch",
"(",
"Psr18",
"\\",
"NetworkExceptionInterface",
"$",
"e",
")",
"{",
"throw",
"HttpServerException",
"::",
"networkError",
"(",
"$",
"e",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | Send a PUT request.
@param string $path Request path
@param array $parameters PUT parameters
@param array $requestHeaders Request headers | [
"Send",
"a",
"PUT",
"request",
"."
] | f30985c9258d553c4e3d0d63d38c8222f3edd110 | https://github.com/mailgun/mailgun-php/blob/f30985c9258d553c4e3d0d63d38c8222f3edd110/src/Api/HttpApi.php#L162-L173 | train |
concrete5/concrete5 | concrete/src/Page/Theme/ThemeRouteCollection.php | ThemeRouteCollection.getThemeByRoute | public function getThemeByRoute($path)
{
$text = new Text();
// there's probably a more efficient way to do this
foreach ($this->themePaths as $lp => $layout) {
if ($text->fnmatch($lp, $path)) {
return $layout;
}
}
return false;
} | php | public function getThemeByRoute($path)
{
$text = new Text();
// there's probably a more efficient way to do this
foreach ($this->themePaths as $lp => $layout) {
if ($text->fnmatch($lp, $path)) {
return $layout;
}
}
return false;
} | [
"public",
"function",
"getThemeByRoute",
"(",
"$",
"path",
")",
"{",
"$",
"text",
"=",
"new",
"Text",
"(",
")",
";",
"// there's probably a more efficient way to do this",
"foreach",
"(",
"$",
"this",
"->",
"themePaths",
"as",
"$",
"lp",
"=>",
"$",
"layout",
")",
"{",
"if",
"(",
"$",
"text",
"->",
"fnmatch",
"(",
"$",
"lp",
",",
"$",
"path",
")",
")",
"{",
"return",
"$",
"layout",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | This grabs the theme for a particular path, if one exists in the themePaths array. Returns an array with
the theme handle as the first entry and the wrapper file for views as the second.
@param string $path
@return array | [
"This",
"grabs",
"the",
"theme",
"for",
"a",
"particular",
"path",
"if",
"one",
"exists",
"in",
"the",
"themePaths",
"array",
".",
"Returns",
"an",
"array",
"with",
"the",
"theme",
"handle",
"as",
"the",
"first",
"entry",
"and",
"the",
"wrapper",
"file",
"for",
"views",
"as",
"the",
"second",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Page/Theme/ThemeRouteCollection.php#L46-L56 | train |
concrete5/concrete5 | concrete/src/File/Image/BitmapFormat.php | BitmapFormat.getAllImageFormats | public function getAllImageFormats()
{
if ($this->allImageFormats === null) {
$this->allImageFormats = [
static::FORMAT_PNG,
static::FORMAT_JPEG,
static::FORMAT_GIF,
static::FORMAT_WBMP,
static::FORMAT_XBM,
];
}
return $this->allImageFormats;
} | php | public function getAllImageFormats()
{
if ($this->allImageFormats === null) {
$this->allImageFormats = [
static::FORMAT_PNG,
static::FORMAT_JPEG,
static::FORMAT_GIF,
static::FORMAT_WBMP,
static::FORMAT_XBM,
];
}
return $this->allImageFormats;
} | [
"public",
"function",
"getAllImageFormats",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"allImageFormats",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"allImageFormats",
"=",
"[",
"static",
"::",
"FORMAT_PNG",
",",
"static",
"::",
"FORMAT_JPEG",
",",
"static",
"::",
"FORMAT_GIF",
",",
"static",
"::",
"FORMAT_WBMP",
",",
"static",
"::",
"FORMAT_XBM",
",",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"allImageFormats",
";",
"}"
] | Get all the image formats.
@return string[] | [
"Get",
"all",
"the",
"image",
"formats",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Image/BitmapFormat.php#L96-L109 | train |
concrete5/concrete5 | concrete/src/File/Image/BitmapFormat.php | BitmapFormat.getFormatMimeType | public function getFormatMimeType($format)
{
$format = $this->normalizeFormat($format);
$result = '';
switch ($format) {
case static::FORMAT_PNG:
case static::FORMAT_JPEG:
case static::FORMAT_GIF:
case static::FORMAT_XBM:
$result = 'image/' . $format;
break;
case static::FORMAT_WBMP:
$result = 'image/vnd.wap.wbmp';
break;
}
return $result;
} | php | public function getFormatMimeType($format)
{
$format = $this->normalizeFormat($format);
$result = '';
switch ($format) {
case static::FORMAT_PNG:
case static::FORMAT_JPEG:
case static::FORMAT_GIF:
case static::FORMAT_XBM:
$result = 'image/' . $format;
break;
case static::FORMAT_WBMP:
$result = 'image/vnd.wap.wbmp';
break;
}
return $result;
} | [
"public",
"function",
"getFormatMimeType",
"(",
"$",
"format",
")",
"{",
"$",
"format",
"=",
"$",
"this",
"->",
"normalizeFormat",
"(",
"$",
"format",
")",
";",
"$",
"result",
"=",
"''",
";",
"switch",
"(",
"$",
"format",
")",
"{",
"case",
"static",
"::",
"FORMAT_PNG",
":",
"case",
"static",
"::",
"FORMAT_JPEG",
":",
"case",
"static",
"::",
"FORMAT_GIF",
":",
"case",
"static",
"::",
"FORMAT_XBM",
":",
"$",
"result",
"=",
"'image/'",
".",
"$",
"format",
";",
"break",
";",
"case",
"static",
"::",
"FORMAT_WBMP",
":",
"$",
"result",
"=",
"'image/vnd.wap.wbmp'",
";",
"break",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Get the MIME type for a specific format.
@param string $format One of the BitmapFormat::FORMAT_... constants.
@return string return an empty string is $format is invalid | [
"Get",
"the",
"MIME",
"type",
"for",
"a",
"specific",
"format",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Image/BitmapFormat.php#L130-L147 | train |
concrete5/concrete5 | concrete/src/File/Image/BitmapFormat.php | BitmapFormat.getFormatFromMimeType | public function getFormatFromMimeType($mimeType, $fallback = '')
{
$mimeType = trim(strtolower((string) $mimeType));
switch ($mimeType) {
case 'image/png':
$result = static::FORMAT_PNG;
break;
case 'image/jpeg':
$result = static::FORMAT_JPEG;
break;
case 'image/gif':
$result = static::FORMAT_GIF;
break;
case 'image/vnd.wap.wbmp':
$result = static::FORMAT_WBMP;
break;
case 'image/xbm':
case 'image/x-xbm':
case 'image/x-xbitmap':
$result = static::FORMAT_XBM;
break;
default:
$result = $fallback;
break;
}
return $result;
} | php | public function getFormatFromMimeType($mimeType, $fallback = '')
{
$mimeType = trim(strtolower((string) $mimeType));
switch ($mimeType) {
case 'image/png':
$result = static::FORMAT_PNG;
break;
case 'image/jpeg':
$result = static::FORMAT_JPEG;
break;
case 'image/gif':
$result = static::FORMAT_GIF;
break;
case 'image/vnd.wap.wbmp':
$result = static::FORMAT_WBMP;
break;
case 'image/xbm':
case 'image/x-xbm':
case 'image/x-xbitmap':
$result = static::FORMAT_XBM;
break;
default:
$result = $fallback;
break;
}
return $result;
} | [
"public",
"function",
"getFormatFromMimeType",
"(",
"$",
"mimeType",
",",
"$",
"fallback",
"=",
"''",
")",
"{",
"$",
"mimeType",
"=",
"trim",
"(",
"strtolower",
"(",
"(",
"string",
")",
"$",
"mimeType",
")",
")",
";",
"switch",
"(",
"$",
"mimeType",
")",
"{",
"case",
"'image/png'",
":",
"$",
"result",
"=",
"static",
"::",
"FORMAT_PNG",
";",
"break",
";",
"case",
"'image/jpeg'",
":",
"$",
"result",
"=",
"static",
"::",
"FORMAT_JPEG",
";",
"break",
";",
"case",
"'image/gif'",
":",
"$",
"result",
"=",
"static",
"::",
"FORMAT_GIF",
";",
"break",
";",
"case",
"'image/vnd.wap.wbmp'",
":",
"$",
"result",
"=",
"static",
"::",
"FORMAT_WBMP",
";",
"break",
";",
"case",
"'image/xbm'",
":",
"case",
"'image/x-xbm'",
":",
"case",
"'image/x-xbitmap'",
":",
"$",
"result",
"=",
"static",
"::",
"FORMAT_XBM",
";",
"break",
";",
"default",
":",
"$",
"result",
"=",
"$",
"fallback",
";",
"break",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Get the bitmap format corresponding to a specific MIME type.
@param string $mimeType the MIME type to analyze
@param mixed $fallback what to return if $mimeType is not recognized
@return string|mixed | [
"Get",
"the",
"bitmap",
"format",
"corresponding",
"to",
"a",
"specific",
"MIME",
"type",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Image/BitmapFormat.php#L157-L184 | train |
concrete5/concrete5 | concrete/src/File/Image/BitmapFormat.php | BitmapFormat.getFormatImagineSaveOptions | public function getFormatImagineSaveOptions($format)
{
$format = $this->normalizeFormat($format);
$result = [
'format' => $format,
];
switch ($format) {
case static::FORMAT_PNG:
$result['png_compression_level'] = $this->getDefaultPngCompressionLevel();
break;
case static::FORMAT_JPEG:
$result['jpeg_quality'] = $this->getDefaultJpegQuality();
break;
}
return $result;
} | php | public function getFormatImagineSaveOptions($format)
{
$format = $this->normalizeFormat($format);
$result = [
'format' => $format,
];
switch ($format) {
case static::FORMAT_PNG:
$result['png_compression_level'] = $this->getDefaultPngCompressionLevel();
break;
case static::FORMAT_JPEG:
$result['jpeg_quality'] = $this->getDefaultJpegQuality();
break;
}
return $result;
} | [
"public",
"function",
"getFormatImagineSaveOptions",
"(",
"$",
"format",
")",
"{",
"$",
"format",
"=",
"$",
"this",
"->",
"normalizeFormat",
"(",
"$",
"format",
")",
";",
"$",
"result",
"=",
"[",
"'format'",
"=>",
"$",
"format",
",",
"]",
";",
"switch",
"(",
"$",
"format",
")",
"{",
"case",
"static",
"::",
"FORMAT_PNG",
":",
"$",
"result",
"[",
"'png_compression_level'",
"]",
"=",
"$",
"this",
"->",
"getDefaultPngCompressionLevel",
"(",
")",
";",
"break",
";",
"case",
"static",
"::",
"FORMAT_JPEG",
":",
"$",
"result",
"[",
"'jpeg_quality'",
"]",
"=",
"$",
"this",
"->",
"getDefaultJpegQuality",
"(",
")",
";",
"break",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Get the Imagine save options for the specified image format.
@param string $format One of the BitmapFormat::FORMAT_... constants.
@return array | [
"Get",
"the",
"Imagine",
"save",
"options",
"for",
"the",
"specified",
"image",
"format",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Image/BitmapFormat.php#L193-L209 | train |
concrete5/concrete5 | concrete/src/File/Image/BitmapFormat.php | BitmapFormat.setDefaultJpegQuality | public function setDefaultJpegQuality($value)
{
if ($this->valn->integer($value, 0, 100)) {
$value = (int) $value;
$this->config->set('concrete.misc.default_jpeg_image_compression', $value);
$this->config->save('concrete.misc.default_jpeg_image_compression', $value);
}
return $this;
} | php | public function setDefaultJpegQuality($value)
{
if ($this->valn->integer($value, 0, 100)) {
$value = (int) $value;
$this->config->set('concrete.misc.default_jpeg_image_compression', $value);
$this->config->save('concrete.misc.default_jpeg_image_compression', $value);
}
return $this;
} | [
"public",
"function",
"setDefaultJpegQuality",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"valn",
"->",
"integer",
"(",
"$",
"value",
",",
"0",
",",
"100",
")",
")",
"{",
"$",
"value",
"=",
"(",
"int",
")",
"$",
"value",
";",
"$",
"this",
"->",
"config",
"->",
"set",
"(",
"'concrete.misc.default_jpeg_image_compression'",
",",
"$",
"value",
")",
";",
"$",
"this",
"->",
"config",
"->",
"save",
"(",
"'concrete.misc.default_jpeg_image_compression'",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set the default JPEG quality.
@param int $value an integer from 0 to 100
@return $this | [
"Set",
"the",
"default",
"JPEG",
"quality",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Image/BitmapFormat.php#L253-L262 | train |
concrete5/concrete5 | concrete/src/File/Image/BitmapFormat.php | BitmapFormat.getDefaultJpegQuality | public function getDefaultJpegQuality()
{
$result = $this->config->get('concrete.misc.default_jpeg_image_compression');
if ($this->valn->integer($result, 0, 100)) {
$result = (int) $result;
} else {
$result = static::DEFAULT_JPEG_QUALITY;
}
return $result;
} | php | public function getDefaultJpegQuality()
{
$result = $this->config->get('concrete.misc.default_jpeg_image_compression');
if ($this->valn->integer($result, 0, 100)) {
$result = (int) $result;
} else {
$result = static::DEFAULT_JPEG_QUALITY;
}
return $result;
} | [
"public",
"function",
"getDefaultJpegQuality",
"(",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'concrete.misc.default_jpeg_image_compression'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"valn",
"->",
"integer",
"(",
"$",
"result",
",",
"0",
",",
"100",
")",
")",
"{",
"$",
"result",
"=",
"(",
"int",
")",
"$",
"result",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"static",
"::",
"DEFAULT_JPEG_QUALITY",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Get the default JPEG quality.
@return int an integer from 0 to 100 | [
"Get",
"the",
"default",
"JPEG",
"quality",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Image/BitmapFormat.php#L269-L279 | train |
concrete5/concrete5 | concrete/src/File/Image/BitmapFormat.php | BitmapFormat.getDefaultPngCompressionLevel | public function getDefaultPngCompressionLevel()
{
$result = $this->config->get('concrete.misc.default_png_image_compression');
if ($this->valn->integer($result, 0, 9)) {
$result = (int) $result;
} else {
$result = static::DEFAULT_PNG_COMPRESSIONLEVEL;
}
return $result;
} | php | public function getDefaultPngCompressionLevel()
{
$result = $this->config->get('concrete.misc.default_png_image_compression');
if ($this->valn->integer($result, 0, 9)) {
$result = (int) $result;
} else {
$result = static::DEFAULT_PNG_COMPRESSIONLEVEL;
}
return $result;
} | [
"public",
"function",
"getDefaultPngCompressionLevel",
"(",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'concrete.misc.default_png_image_compression'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"valn",
"->",
"integer",
"(",
"$",
"result",
",",
"0",
",",
"9",
")",
")",
"{",
"$",
"result",
"=",
"(",
"int",
")",
"$",
"result",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"static",
"::",
"DEFAULT_PNG_COMPRESSIONLEVEL",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Get the default PNG compression level.
@return int an integer from 0 to 9 | [
"Get",
"the",
"default",
"PNG",
"compression",
"level",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Image/BitmapFormat.php#L304-L314 | train |
concrete5/concrete5 | concrete/src/File/Image/BitmapFormat.php | BitmapFormat.normalizeFormat | protected function normalizeFormat($format)
{
$format = strtolower(trim((string) $format));
if ($format === 'jpg') {
$format = static::FORMAT_JPEG;
}
return $format;
} | php | protected function normalizeFormat($format)
{
$format = strtolower(trim((string) $format));
if ($format === 'jpg') {
$format = static::FORMAT_JPEG;
}
return $format;
} | [
"protected",
"function",
"normalizeFormat",
"(",
"$",
"format",
")",
"{",
"$",
"format",
"=",
"strtolower",
"(",
"trim",
"(",
"(",
"string",
")",
"$",
"format",
")",
")",
";",
"if",
"(",
"$",
"format",
"===",
"'jpg'",
")",
"{",
"$",
"format",
"=",
"static",
"::",
"FORMAT_JPEG",
";",
"}",
"return",
"$",
"format",
";",
"}"
] | Normalize a format.
@param string|mixed $format
@return string | [
"Normalize",
"a",
"format",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Image/BitmapFormat.php#L323-L331 | train |
concrete5/concrete5 | concrete/src/Http/RequestMediaTypeParser.php | RequestMediaTypeParser.isMediaTypeSupported | public function isMediaTypeSupported($mediaType, $minWeight = null)
{
$data = $this->getMediaTypeData($mediaType);
if ($minWeight === null) {
return $data !== [];
}
$minWeight = (float) $minWeight;
foreach ($data as $item) {
if ($item['q'] >= $minWeight) {
return true;
}
}
return false;
} | php | public function isMediaTypeSupported($mediaType, $minWeight = null)
{
$data = $this->getMediaTypeData($mediaType);
if ($minWeight === null) {
return $data !== [];
}
$minWeight = (float) $minWeight;
foreach ($data as $item) {
if ($item['q'] >= $minWeight) {
return true;
}
}
return false;
} | [
"public",
"function",
"isMediaTypeSupported",
"(",
"$",
"mediaType",
",",
"$",
"minWeight",
"=",
"null",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"getMediaTypeData",
"(",
"$",
"mediaType",
")",
";",
"if",
"(",
"$",
"minWeight",
"===",
"null",
")",
"{",
"return",
"$",
"data",
"!==",
"[",
"]",
";",
"}",
"$",
"minWeight",
"=",
"(",
"float",
")",
"$",
"minWeight",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"[",
"'q'",
"]",
">=",
"$",
"minWeight",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Check if the client signaled that it supports a media type.
@param string|string[] $mediaType the media type to be checked (a string like 'text/html', or an array like ['text','html'])
@param float|null $minWeight the minimum weight of the found media type (from 0 to 1); if NULL we won't check it
@return bool | [
"Check",
"if",
"the",
"client",
"signaled",
"that",
"it",
"supports",
"a",
"media",
"type",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Http/RequestMediaTypeParser.php#L98-L112 | train |
concrete5/concrete5 | concrete/src/Http/RequestMediaTypeParser.php | RequestMediaTypeParser.getMediaTypeData | public function getMediaTypeData($mediaType)
{
$map = $this->getRequestAcceptMap();
list($type, $subType) = $this->normalizeMediaType($mediaType);
$result = [];
foreach ($this->getMediaTypeAlternatives($type, $subType) as $alternative) {
if (isset($map[$alternative])) {
$result[$alternative] = $map[$alternative];
}
}
return $result;
} | php | public function getMediaTypeData($mediaType)
{
$map = $this->getRequestAcceptMap();
list($type, $subType) = $this->normalizeMediaType($mediaType);
$result = [];
foreach ($this->getMediaTypeAlternatives($type, $subType) as $alternative) {
if (isset($map[$alternative])) {
$result[$alternative] = $map[$alternative];
}
}
return $result;
} | [
"public",
"function",
"getMediaTypeData",
"(",
"$",
"mediaType",
")",
"{",
"$",
"map",
"=",
"$",
"this",
"->",
"getRequestAcceptMap",
"(",
")",
";",
"list",
"(",
"$",
"type",
",",
"$",
"subType",
")",
"=",
"$",
"this",
"->",
"normalizeMediaType",
"(",
"$",
"mediaType",
")",
";",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getMediaTypeAlternatives",
"(",
"$",
"type",
",",
"$",
"subType",
")",
"as",
"$",
"alternative",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"map",
"[",
"$",
"alternative",
"]",
")",
")",
"{",
"$",
"result",
"[",
"$",
"alternative",
"]",
"=",
"$",
"map",
"[",
"$",
"alternative",
"]",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Get the data associated to a media type.
@param string|string[] $mediaType the media type to be checked (a string like 'text/html', or an array like ['text','html'])
@return array keys are the media type; values are the associated data, sorted by the preferred type (the 'q' parameter) | [
"Get",
"the",
"data",
"associated",
"to",
"a",
"media",
"type",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Http/RequestMediaTypeParser.php#L121-L133 | train |
concrete5/concrete5 | concrete/src/Http/RequestMediaTypeParser.php | RequestMediaTypeParser.getRequestAcceptMap | public function getRequestAcceptMap()
{
if ($this->requestAcceptMap === null) {
$requestAccept = $this->getRequestAccept();
$requestAcceptMap = $this->parseRequestAccept($requestAccept);
$requestAcceptMap = $this->sortRequestAcceptMap($requestAcceptMap);
$this->requestAcceptMap = $requestAcceptMap;
}
return $this->requestAcceptMap;
} | php | public function getRequestAcceptMap()
{
if ($this->requestAcceptMap === null) {
$requestAccept = $this->getRequestAccept();
$requestAcceptMap = $this->parseRequestAccept($requestAccept);
$requestAcceptMap = $this->sortRequestAcceptMap($requestAcceptMap);
$this->requestAcceptMap = $requestAcceptMap;
}
return $this->requestAcceptMap;
} | [
"public",
"function",
"getRequestAcceptMap",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"requestAcceptMap",
"===",
"null",
")",
"{",
"$",
"requestAccept",
"=",
"$",
"this",
"->",
"getRequestAccept",
"(",
")",
";",
"$",
"requestAcceptMap",
"=",
"$",
"this",
"->",
"parseRequestAccept",
"(",
"$",
"requestAccept",
")",
";",
"$",
"requestAcceptMap",
"=",
"$",
"this",
"->",
"sortRequestAcceptMap",
"(",
"$",
"requestAcceptMap",
")",
";",
"$",
"this",
"->",
"requestAcceptMap",
"=",
"$",
"requestAcceptMap",
";",
"}",
"return",
"$",
"this",
"->",
"requestAcceptMap",
";",
"}"
] | Get the data extracted from the 'Accept' header.
@return array keys are the media type; values are the associated data, sorted by the preferred type (the 'q' parameter)
@example <code>['image/png' => ['q' => 1.0], 'image/*' => ['q' => 0.8]] | [
"Get",
"the",
"data",
"extracted",
"from",
"the",
"Accept",
"header",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Http/RequestMediaTypeParser.php#L142-L152 | train |
concrete5/concrete5 | concrete/src/Http/RequestMediaTypeParser.php | RequestMediaTypeParser.getRequestAccept | protected function getRequestAccept()
{
$accept = $this->request->headers->get('accept');
if (!is_string($accept)) {
return '';
}
return trim($accept);
} | php | protected function getRequestAccept()
{
$accept = $this->request->headers->get('accept');
if (!is_string($accept)) {
return '';
}
return trim($accept);
} | [
"protected",
"function",
"getRequestAccept",
"(",
")",
"{",
"$",
"accept",
"=",
"$",
"this",
"->",
"request",
"->",
"headers",
"->",
"get",
"(",
"'accept'",
")",
";",
"if",
"(",
"!",
"is_string",
"(",
"$",
"accept",
")",
")",
"{",
"return",
"''",
";",
"}",
"return",
"trim",
"(",
"$",
"accept",
")",
";",
"}"
] | Get the 'Accept' header of the request.
@var string empty if not available | [
"Get",
"the",
"Accept",
"header",
"of",
"the",
"request",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Http/RequestMediaTypeParser.php#L159-L167 | train |
concrete5/concrete5 | concrete/src/Feed/FeedService.php | FeedService.load | public function load($url, $cache = 3600)
{
if ($cache !== false) {
Reader::setCache(new ZendCacheDriver('cache/expensive', $cache));
}
// Load the RSS feed, either from remote URL or from cache
// (if specified above and still fresh)
$feed = Reader::import($url);
return $feed;
} | php | public function load($url, $cache = 3600)
{
if ($cache !== false) {
Reader::setCache(new ZendCacheDriver('cache/expensive', $cache));
}
// Load the RSS feed, either from remote URL or from cache
// (if specified above and still fresh)
$feed = Reader::import($url);
return $feed;
} | [
"public",
"function",
"load",
"(",
"$",
"url",
",",
"$",
"cache",
"=",
"3600",
")",
"{",
"if",
"(",
"$",
"cache",
"!==",
"false",
")",
"{",
"Reader",
"::",
"setCache",
"(",
"new",
"ZendCacheDriver",
"(",
"'cache/expensive'",
",",
"$",
"cache",
")",
")",
";",
"}",
"// Load the RSS feed, either from remote URL or from cache",
"// (if specified above and still fresh)",
"$",
"feed",
"=",
"Reader",
"::",
"import",
"(",
"$",
"url",
")",
";",
"return",
"$",
"feed",
";",
"}"
] | Loads a newsfeed object.
@param string $feedurl
@param int $cache - number of seconds to cache the RSS feed data for
@return Reader | [
"Loads",
"a",
"newsfeed",
"object",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Feed/FeedService.php#L16-L27 | train |
concrete5/concrete5 | concrete/src/Routing/Redirect.php | Redirect.createRedirectResponse | protected static function createRedirectResponse($url, $code, $headers)
{
$r = new RedirectResponse($url, $code, $headers);
$r->setRequest(Request::getInstance());
return $r;
} | php | protected static function createRedirectResponse($url, $code, $headers)
{
$r = new RedirectResponse($url, $code, $headers);
$r->setRequest(Request::getInstance());
return $r;
} | [
"protected",
"static",
"function",
"createRedirectResponse",
"(",
"$",
"url",
",",
"$",
"code",
",",
"$",
"headers",
")",
"{",
"$",
"r",
"=",
"new",
"RedirectResponse",
"(",
"$",
"url",
",",
"$",
"code",
",",
"$",
"headers",
")",
";",
"$",
"r",
"->",
"setRequest",
"(",
"Request",
"::",
"getInstance",
"(",
")",
")",
";",
"return",
"$",
"r",
";",
"}"
] | Actually sends a redirect. | [
"Actually",
"sends",
"a",
"redirect",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Routing/Redirect.php#L15-L21 | train |
concrete5/concrete5 | concrete/src/Routing/Redirect.php | Redirect.to | public static function to()
{
// Is what we're providing a URL object?
$args = func_get_args();
if (is_object($args[0]) && $args[0] instanceof UrlInterface) {
$url = $args[0];
} else {
$url = call_user_func_array('\URL::to', func_get_args());
}
$r = static::createRedirectResponse((string) $url, 302, array());
return $r;
} | php | public static function to()
{
// Is what we're providing a URL object?
$args = func_get_args();
if (is_object($args[0]) && $args[0] instanceof UrlInterface) {
$url = $args[0];
} else {
$url = call_user_func_array('\URL::to', func_get_args());
}
$r = static::createRedirectResponse((string) $url, 302, array());
return $r;
} | [
"public",
"static",
"function",
"to",
"(",
")",
"{",
"// Is what we're providing a URL object?",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"args",
"[",
"0",
"]",
")",
"&&",
"$",
"args",
"[",
"0",
"]",
"instanceof",
"UrlInterface",
")",
"{",
"$",
"url",
"=",
"$",
"args",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"$",
"url",
"=",
"call_user_func_array",
"(",
"'\\URL::to'",
",",
"func_get_args",
"(",
")",
")",
";",
"}",
"$",
"r",
"=",
"static",
"::",
"createRedirectResponse",
"(",
"(",
"string",
")",
"$",
"url",
",",
"302",
",",
"array",
"(",
")",
")",
";",
"return",
"$",
"r",
";",
"}"
] | Redirects to a concrete5 resource. | [
"Redirects",
"to",
"a",
"concrete5",
"resource",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Routing/Redirect.php#L26-L38 | train |
concrete5/concrete5 | concrete/src/Routing/Redirect.php | Redirect.page | public static function page(Page $c, $code = 302, $headers = array())
{
if ($c->getCollectionPath()) {
$url = Core::make('helper/navigation')->getLinkToCollection($c, true);
} else {
$url = \URL::to($c);
}
$r = static::createRedirectResponse((string) $url, $code, $headers);
return $r;
} | php | public static function page(Page $c, $code = 302, $headers = array())
{
if ($c->getCollectionPath()) {
$url = Core::make('helper/navigation')->getLinkToCollection($c, true);
} else {
$url = \URL::to($c);
}
$r = static::createRedirectResponse((string) $url, $code, $headers);
return $r;
} | [
"public",
"static",
"function",
"page",
"(",
"Page",
"$",
"c",
",",
"$",
"code",
"=",
"302",
",",
"$",
"headers",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"$",
"c",
"->",
"getCollectionPath",
"(",
")",
")",
"{",
"$",
"url",
"=",
"Core",
"::",
"make",
"(",
"'helper/navigation'",
")",
"->",
"getLinkToCollection",
"(",
"$",
"c",
",",
"true",
")",
";",
"}",
"else",
"{",
"$",
"url",
"=",
"\\",
"URL",
"::",
"to",
"(",
"$",
"c",
")",
";",
"}",
"$",
"r",
"=",
"static",
"::",
"createRedirectResponse",
"(",
"(",
"string",
")",
"$",
"url",
",",
"$",
"code",
",",
"$",
"headers",
")",
";",
"return",
"$",
"r",
";",
"}"
] | Redirect to a page. | [
"Redirect",
"to",
"a",
"page",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Routing/Redirect.php#L43-L53 | train |
concrete5/concrete5 | concrete/src/Legacy/ItemList.php | ItemList.getTotal | public function getTotal()
{
if ($this->total == -1) {
$this->total = count($this->items);
}
return $this->total;
} | php | public function getTotal()
{
if ($this->total == -1) {
$this->total = count($this->items);
}
return $this->total;
} | [
"public",
"function",
"getTotal",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"total",
"==",
"-",
"1",
")",
"{",
"$",
"this",
"->",
"total",
"=",
"count",
"(",
"$",
"this",
"->",
"items",
")",
";",
"}",
"return",
"$",
"this",
"->",
"total",
";",
"}"
] | Returns the total number of items found by this list. | [
"Returns",
"the",
"total",
"number",
"of",
"items",
"found",
"by",
"this",
"list",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Legacy/ItemList.php#L116-L123 | train |
concrete5/concrete5 | concrete/src/Legacy/ItemList.php | ItemList.getPage | public function getPage($page = false)
{
$this->setCurrentPage($page);
$offset = 0;
if ($this->currentPage > 1) {
$offset = min($this->itemsPerPage * ($this->currentPage - 1), 2147483647);
}
return $this->get($this->itemsPerPage, $offset);
} | php | public function getPage($page = false)
{
$this->setCurrentPage($page);
$offset = 0;
if ($this->currentPage > 1) {
$offset = min($this->itemsPerPage * ($this->currentPage - 1), 2147483647);
}
return $this->get($this->itemsPerPage, $offset);
} | [
"public",
"function",
"getPage",
"(",
"$",
"page",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"setCurrentPage",
"(",
"$",
"page",
")",
";",
"$",
"offset",
"=",
"0",
";",
"if",
"(",
"$",
"this",
"->",
"currentPage",
">",
"1",
")",
"{",
"$",
"offset",
"=",
"min",
"(",
"$",
"this",
"->",
"itemsPerPage",
"*",
"(",
"$",
"this",
"->",
"currentPage",
"-",
"1",
")",
",",
"2147483647",
")",
";",
"}",
"return",
"$",
"this",
"->",
"get",
"(",
"$",
"this",
"->",
"itemsPerPage",
",",
"$",
"offset",
")",
";",
"}"
] | Returns an array of object by "page". | [
"Returns",
"an",
"array",
"of",
"object",
"by",
"page",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Legacy/ItemList.php#L128-L137 | train |
concrete5/concrete5 | concrete/src/Legacy/ItemList.php | ItemList.displaySummary | public function displaySummary($right_content = '')
{
if ($this->getTotal() < 1) {
return false;
}
$summary = $this->getSummary();
if ($summary->currentEnd == -1) {
$html = '<div class="ccm-paging-top">'. t('Viewing <b>%s</b> to <b>%s</b> (<b>%s</b> Total)', $summary->currentStart, "<span id=\"pagingPageResults\">" . $summary->total . "</span>", "<span id=\"pagingTotalResults\">" . $this->total . "</span>") . ($right_content != '' ? '<span class="ccm-paging-top-content">'. $right_content .'</span>' : '') .'</div>';
} else {
$html = '<div class="ccm-paging-top">'. t('Viewing <b>%s</b> to <b>%s</b> (<b>%s</b> Total)', $summary->currentStart, "<span id=\"pagingPageResults\">" . $summary->currentEnd . "</span>", "<span id=\"pagingTotalResults\">" . $this->total . "</span>") . ($right_content != '' ? '<span class="ccm-paging-top-content">'. $right_content .'</span>' : '') .'</div>';
}
echo $html;
} | php | public function displaySummary($right_content = '')
{
if ($this->getTotal() < 1) {
return false;
}
$summary = $this->getSummary();
if ($summary->currentEnd == -1) {
$html = '<div class="ccm-paging-top">'. t('Viewing <b>%s</b> to <b>%s</b> (<b>%s</b> Total)', $summary->currentStart, "<span id=\"pagingPageResults\">" . $summary->total . "</span>", "<span id=\"pagingTotalResults\">" . $this->total . "</span>") . ($right_content != '' ? '<span class="ccm-paging-top-content">'. $right_content .'</span>' : '') .'</div>';
} else {
$html = '<div class="ccm-paging-top">'. t('Viewing <b>%s</b> to <b>%s</b> (<b>%s</b> Total)', $summary->currentStart, "<span id=\"pagingPageResults\">" . $summary->currentEnd . "</span>", "<span id=\"pagingTotalResults\">" . $this->total . "</span>") . ($right_content != '' ? '<span class="ccm-paging-top-content">'. $right_content .'</span>' : '') .'</div>';
}
echo $html;
} | [
"public",
"function",
"displaySummary",
"(",
"$",
"right_content",
"=",
"''",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getTotal",
"(",
")",
"<",
"1",
")",
"{",
"return",
"false",
";",
"}",
"$",
"summary",
"=",
"$",
"this",
"->",
"getSummary",
"(",
")",
";",
"if",
"(",
"$",
"summary",
"->",
"currentEnd",
"==",
"-",
"1",
")",
"{",
"$",
"html",
"=",
"'<div class=\"ccm-paging-top\">'",
".",
"t",
"(",
"'Viewing <b>%s</b> to <b>%s</b> (<b>%s</b> Total)'",
",",
"$",
"summary",
"->",
"currentStart",
",",
"\"<span id=\\\"pagingPageResults\\\">\"",
".",
"$",
"summary",
"->",
"total",
".",
"\"</span>\"",
",",
"\"<span id=\\\"pagingTotalResults\\\">\"",
".",
"$",
"this",
"->",
"total",
".",
"\"</span>\"",
")",
".",
"(",
"$",
"right_content",
"!=",
"''",
"?",
"'<span class=\"ccm-paging-top-content\">'",
".",
"$",
"right_content",
".",
"'</span>'",
":",
"''",
")",
".",
"'</div>'",
";",
"}",
"else",
"{",
"$",
"html",
"=",
"'<div class=\"ccm-paging-top\">'",
".",
"t",
"(",
"'Viewing <b>%s</b> to <b>%s</b> (<b>%s</b> Total)'",
",",
"$",
"summary",
"->",
"currentStart",
",",
"\"<span id=\\\"pagingPageResults\\\">\"",
".",
"$",
"summary",
"->",
"currentEnd",
".",
"\"</span>\"",
",",
"\"<span id=\\\"pagingTotalResults\\\">\"",
".",
"$",
"this",
"->",
"total",
".",
"\"</span>\"",
")",
".",
"(",
"$",
"right_content",
"!=",
"''",
"?",
"'<span class=\"ccm-paging-top-content\">'",
".",
"$",
"right_content",
".",
"'</span>'",
":",
"''",
")",
".",
"'</div>'",
";",
"}",
"echo",
"$",
"html",
";",
"}"
] | Displays summary text about a list. | [
"Displays",
"summary",
"text",
"about",
"a",
"list",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Legacy/ItemList.php#L165-L177 | train |
concrete5/concrete5 | concrete/src/Legacy/ItemList.php | ItemList.displayPagingV2 | public function displayPagingV2($script = false, $return = false, $additionalVars = array())
{
$summary = $this->getSummary();
$paginator = $this->getPagination($script, $additionalVars);
if ($summary->pages > 1) {
$html = '';
$html .= '<div class="ccm-search-results-pagination"><ul class="pagination">';
$prevClass = 'prev';
$nextClass = 'next';
if (!$paginator->hasPreviousPage()) {
$prevClass = 'prev disabled';
}
if (!$paginator->hasNextPage()) {
$nextClass = 'next disabled';
}
$html .= '<li class="' . $prevClass . '">' . $paginator->getPrevious(false, 'a') . '</li>';
$html .= $paginator->getPages('li');
$html .= '<li class="' . $nextClass . '">' . $paginator->getNext(false, 'a') . '</li>';
$html .= '</ul></div>';
}
if (isset($html)) {
if ($return) {
return $html;
} else {
echo $html;
}
}
} | php | public function displayPagingV2($script = false, $return = false, $additionalVars = array())
{
$summary = $this->getSummary();
$paginator = $this->getPagination($script, $additionalVars);
if ($summary->pages > 1) {
$html = '';
$html .= '<div class="ccm-search-results-pagination"><ul class="pagination">';
$prevClass = 'prev';
$nextClass = 'next';
if (!$paginator->hasPreviousPage()) {
$prevClass = 'prev disabled';
}
if (!$paginator->hasNextPage()) {
$nextClass = 'next disabled';
}
$html .= '<li class="' . $prevClass . '">' . $paginator->getPrevious(false, 'a') . '</li>';
$html .= $paginator->getPages('li');
$html .= '<li class="' . $nextClass . '">' . $paginator->getNext(false, 'a') . '</li>';
$html .= '</ul></div>';
}
if (isset($html)) {
if ($return) {
return $html;
} else {
echo $html;
}
}
} | [
"public",
"function",
"displayPagingV2",
"(",
"$",
"script",
"=",
"false",
",",
"$",
"return",
"=",
"false",
",",
"$",
"additionalVars",
"=",
"array",
"(",
")",
")",
"{",
"$",
"summary",
"=",
"$",
"this",
"->",
"getSummary",
"(",
")",
";",
"$",
"paginator",
"=",
"$",
"this",
"->",
"getPagination",
"(",
"$",
"script",
",",
"$",
"additionalVars",
")",
";",
"if",
"(",
"$",
"summary",
"->",
"pages",
">",
"1",
")",
"{",
"$",
"html",
"=",
"''",
";",
"$",
"html",
".=",
"'<div class=\"ccm-search-results-pagination\"><ul class=\"pagination\">'",
";",
"$",
"prevClass",
"=",
"'prev'",
";",
"$",
"nextClass",
"=",
"'next'",
";",
"if",
"(",
"!",
"$",
"paginator",
"->",
"hasPreviousPage",
"(",
")",
")",
"{",
"$",
"prevClass",
"=",
"'prev disabled'",
";",
"}",
"if",
"(",
"!",
"$",
"paginator",
"->",
"hasNextPage",
"(",
")",
")",
"{",
"$",
"nextClass",
"=",
"'next disabled'",
";",
"}",
"$",
"html",
".=",
"'<li class=\"'",
".",
"$",
"prevClass",
".",
"'\">'",
".",
"$",
"paginator",
"->",
"getPrevious",
"(",
"false",
",",
"'a'",
")",
".",
"'</li>'",
";",
"$",
"html",
".=",
"$",
"paginator",
"->",
"getPages",
"(",
"'li'",
")",
";",
"$",
"html",
".=",
"'<li class=\"'",
".",
"$",
"nextClass",
".",
"'\">'",
".",
"$",
"paginator",
"->",
"getNext",
"(",
"false",
",",
"'a'",
")",
".",
"'</li>'",
";",
"$",
"html",
".=",
"'</ul></div>'",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"html",
")",
")",
"{",
"if",
"(",
"$",
"return",
")",
"{",
"return",
"$",
"html",
";",
"}",
"else",
"{",
"echo",
"$",
"html",
";",
"}",
"}",
"}"
] | Gets paging that works in our new format | [
"Gets",
"paging",
"that",
"works",
"in",
"our",
"new",
"format"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Legacy/ItemList.php#L257-L284 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.