repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
sequencelengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
sequencelengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
libreworks/caridea-acl
src/Rule.php
Rule.deny
public static function deny(Subject $subject, array $verbs = null): Rule { return new self($subject, false, $verbs); }
php
public static function deny(Subject $subject, array $verbs = null): Rule { return new self($subject, false, $verbs); }
[ "public", "static", "function", "deny", "(", "Subject", "$", "subject", ",", "array", "$", "verbs", "=", "null", ")", ":", "Rule", "{", "return", "new", "self", "(", "$", "subject", ",", "false", ",", "$", "verbs", ")", ";", "}" ]
Creates an denying Rule. @param \Caridea\Acl\Subject $subject The subject to allow access @param array<string>|null $verbs Optional list of denied verbs. Empty or `null` means *all*. @return Rule The denying Rule
[ "Creates", "an", "denying", "Rule", "." ]
train
https://github.com/libreworks/caridea-acl/blob/64ff8f2e29926acc67b9fc4a8a9ea7bcc50e4916/src/Rule.php#L103-L106
goulaheau/symfony-rest-bundle
Core/RestSerializer.php
RestSerializer.denormalize
public function denormalize($data, $entityClass, $factory = null, $toEntity = null) { $context = $this->getDenormalizeContext($this->denormalizeContext, $toEntity); if ($factory) { $entityClass = $entityClass::$factory($data); } $entity = $this->serializer->denormalize($data, $entityClass, null, $context); // TODO: Ameliorer ce mechanisme EntityNormalizer::$isFirstCall = true; return $entity; }
php
public function denormalize($data, $entityClass, $factory = null, $toEntity = null) { $context = $this->getDenormalizeContext($this->denormalizeContext, $toEntity); if ($factory) { $entityClass = $entityClass::$factory($data); } $entity = $this->serializer->denormalize($data, $entityClass, null, $context); // TODO: Ameliorer ce mechanisme EntityNormalizer::$isFirstCall = true; return $entity; }
[ "public", "function", "denormalize", "(", "$", "data", ",", "$", "entityClass", ",", "$", "factory", "=", "null", ",", "$", "toEntity", "=", "null", ")", "{", "$", "context", "=", "$", "this", "->", "getDenormalizeContext", "(", "$", "this", "->", "denormalizeContext", ",", "$", "toEntity", ")", ";", "if", "(", "$", "factory", ")", "{", "$", "entityClass", "=", "$", "entityClass", "::", "$", "factory", "(", "$", "data", ")", ";", "}", "$", "entity", "=", "$", "this", "->", "serializer", "->", "denormalize", "(", "$", "data", ",", "$", "entityClass", ",", "null", ",", "$", "context", ")", ";", "// TODO: Ameliorer ce mechanisme", "EntityNormalizer", "::", "$", "isFirstCall", "=", "true", ";", "return", "$", "entity", ";", "}" ]
@param mixed $data @param string $entityClass @param callable | null $factory @param null $toEntity @return object
[ "@param", "mixed", "$data", "@param", "string", "$entityClass", "@param", "callable", "|", "null", "$factory", "@param", "null", "$toEntity" ]
train
https://github.com/goulaheau/symfony-rest-bundle/blob/688a120540f144aa1033a72b75803fae34ba3953/Core/RestSerializer.php#L36-L50
goulaheau/symfony-rest-bundle
Core/RestSerializer.php
RestSerializer.normalize
public function normalize($data, $attributes = null, $groups = null, $entityMethods = null) { $context = $this->getNormalizeContext($this->normalizeContext, $attributes, $groups); $dataNormalized = $this->serializer->normalize($data, null, $context); if ($entityMethods && count($entityMethods) > 0) { $dataNormalized = $this->mergeEntitiesMethods($data, $dataNormalized, $entityMethods); } return $dataNormalized; }
php
public function normalize($data, $attributes = null, $groups = null, $entityMethods = null) { $context = $this->getNormalizeContext($this->normalizeContext, $attributes, $groups); $dataNormalized = $this->serializer->normalize($data, null, $context); if ($entityMethods && count($entityMethods) > 0) { $dataNormalized = $this->mergeEntitiesMethods($data, $dataNormalized, $entityMethods); } return $dataNormalized; }
[ "public", "function", "normalize", "(", "$", "data", ",", "$", "attributes", "=", "null", ",", "$", "groups", "=", "null", ",", "$", "entityMethods", "=", "null", ")", "{", "$", "context", "=", "$", "this", "->", "getNormalizeContext", "(", "$", "this", "->", "normalizeContext", ",", "$", "attributes", ",", "$", "groups", ")", ";", "$", "dataNormalized", "=", "$", "this", "->", "serializer", "->", "normalize", "(", "$", "data", ",", "null", ",", "$", "context", ")", ";", "if", "(", "$", "entityMethods", "&&", "count", "(", "$", "entityMethods", ")", ">", "0", ")", "{", "$", "dataNormalized", "=", "$", "this", "->", "mergeEntitiesMethods", "(", "$", "data", ",", "$", "dataNormalized", ",", "$", "entityMethods", ")", ";", "}", "return", "$", "dataNormalized", ";", "}" ]
@param mixed $data @param array $groups @param array $attributes @param Method[] $entityMethods @return array|bool|float|int|mixed|string
[ "@param", "mixed", "$data", "@param", "array", "$groups", "@param", "array", "$attributes", "@param", "Method", "[]", "$entityMethods" ]
train
https://github.com/goulaheau/symfony-rest-bundle/blob/688a120540f144aa1033a72b75803fae34ba3953/Core/RestSerializer.php#L60-L71
goulaheau/symfony-rest-bundle
Core/RestSerializer.php
RestSerializer.mergeEntityMethods
protected function mergeEntityMethods($entity, $entityNormalized, $entityMethods, $key = '_entityMethods') { if (!is_array($entityNormalized)) { return $entityNormalized; } foreach ($entityMethods as $entityMethod) { $methodEntity = $entity; $name = $entityMethod->getName(); $params = $entityMethod->getParams(); $attributes = $entityMethod->getAttributes(); $subEntities = $entityMethod->getSubEntities(); foreach ($subEntities as $subEntity) { $methodEntity = $methodEntity->{"get${subEntity}"}(); } if (count($subEntities) === 0) { if (!isset($entityNormalized[$key])) { $entityNormalized[$key] = []; } $data = $methodEntity->$name(...$params); if ($attributes) { $data = $this->serializer->normalize( $data, null, $this->getNormalizeContext($this->normalizeContext, $attributes) ); } $entityNormalized[$key][$name] = $data; continue; } foreach ($subEntities as $i => $subEntity) { if (!isset($entityNormalized[$subEntity])) { $entityNormalized[$subEntity] = []; } $subEntityNormalized = &$entityNormalized[$subEntity]; if ($i === count($subEntities) - 1) { if (!isset($subEntityNormalized[$key])) { $subEntityNormalized[$key] = []; } $data = $methodEntity->$name(...$params); if ($attributes) { $data = $this->serializer->normalize( $data, null, $this->getNormalizeContext($this->normalizeContext, $attributes) ); } $subEntityNormalized[$key][$name] = $data; } } } return $entityNormalized; }
php
protected function mergeEntityMethods($entity, $entityNormalized, $entityMethods, $key = '_entityMethods') { if (!is_array($entityNormalized)) { return $entityNormalized; } foreach ($entityMethods as $entityMethod) { $methodEntity = $entity; $name = $entityMethod->getName(); $params = $entityMethod->getParams(); $attributes = $entityMethod->getAttributes(); $subEntities = $entityMethod->getSubEntities(); foreach ($subEntities as $subEntity) { $methodEntity = $methodEntity->{"get${subEntity}"}(); } if (count($subEntities) === 0) { if (!isset($entityNormalized[$key])) { $entityNormalized[$key] = []; } $data = $methodEntity->$name(...$params); if ($attributes) { $data = $this->serializer->normalize( $data, null, $this->getNormalizeContext($this->normalizeContext, $attributes) ); } $entityNormalized[$key][$name] = $data; continue; } foreach ($subEntities as $i => $subEntity) { if (!isset($entityNormalized[$subEntity])) { $entityNormalized[$subEntity] = []; } $subEntityNormalized = &$entityNormalized[$subEntity]; if ($i === count($subEntities) - 1) { if (!isset($subEntityNormalized[$key])) { $subEntityNormalized[$key] = []; } $data = $methodEntity->$name(...$params); if ($attributes) { $data = $this->serializer->normalize( $data, null, $this->getNormalizeContext($this->normalizeContext, $attributes) ); } $subEntityNormalized[$key][$name] = $data; } } } return $entityNormalized; }
[ "protected", "function", "mergeEntityMethods", "(", "$", "entity", ",", "$", "entityNormalized", ",", "$", "entityMethods", ",", "$", "key", "=", "'_entityMethods'", ")", "{", "if", "(", "!", "is_array", "(", "$", "entityNormalized", ")", ")", "{", "return", "$", "entityNormalized", ";", "}", "foreach", "(", "$", "entityMethods", "as", "$", "entityMethod", ")", "{", "$", "methodEntity", "=", "$", "entity", ";", "$", "name", "=", "$", "entityMethod", "->", "getName", "(", ")", ";", "$", "params", "=", "$", "entityMethod", "->", "getParams", "(", ")", ";", "$", "attributes", "=", "$", "entityMethod", "->", "getAttributes", "(", ")", ";", "$", "subEntities", "=", "$", "entityMethod", "->", "getSubEntities", "(", ")", ";", "foreach", "(", "$", "subEntities", "as", "$", "subEntity", ")", "{", "$", "methodEntity", "=", "$", "methodEntity", "->", "{", "\"get${subEntity}\"", "}", "(", ")", ";", "}", "if", "(", "count", "(", "$", "subEntities", ")", "===", "0", ")", "{", "if", "(", "!", "isset", "(", "$", "entityNormalized", "[", "$", "key", "]", ")", ")", "{", "$", "entityNormalized", "[", "$", "key", "]", "=", "[", "]", ";", "}", "$", "data", "=", "$", "methodEntity", "->", "$", "name", "(", "...", "$", "params", ")", ";", "if", "(", "$", "attributes", ")", "{", "$", "data", "=", "$", "this", "->", "serializer", "->", "normalize", "(", "$", "data", ",", "null", ",", "$", "this", "->", "getNormalizeContext", "(", "$", "this", "->", "normalizeContext", ",", "$", "attributes", ")", ")", ";", "}", "$", "entityNormalized", "[", "$", "key", "]", "[", "$", "name", "]", "=", "$", "data", ";", "continue", ";", "}", "foreach", "(", "$", "subEntities", "as", "$", "i", "=>", "$", "subEntity", ")", "{", "if", "(", "!", "isset", "(", "$", "entityNormalized", "[", "$", "subEntity", "]", ")", ")", "{", "$", "entityNormalized", "[", "$", "subEntity", "]", "=", "[", "]", ";", "}", "$", "subEntityNormalized", "=", "&", "$", "entityNormalized", "[", "$", "subEntity", "]", ";", "if", "(", "$", "i", "===", "count", "(", "$", "subEntities", ")", "-", "1", ")", "{", "if", "(", "!", "isset", "(", "$", "subEntityNormalized", "[", "$", "key", "]", ")", ")", "{", "$", "subEntityNormalized", "[", "$", "key", "]", "=", "[", "]", ";", "}", "$", "data", "=", "$", "methodEntity", "->", "$", "name", "(", "...", "$", "params", ")", ";", "if", "(", "$", "attributes", ")", "{", "$", "data", "=", "$", "this", "->", "serializer", "->", "normalize", "(", "$", "data", ",", "null", ",", "$", "this", "->", "getNormalizeContext", "(", "$", "this", "->", "normalizeContext", ",", "$", "attributes", ")", ")", ";", "}", "$", "subEntityNormalized", "[", "$", "key", "]", "[", "$", "name", "]", "=", "$", "data", ";", "}", "}", "}", "return", "$", "entityNormalized", ";", "}" ]
@param $entity @param $entityNormalized @param Method[] $entityMethods @return array
[ "@param", "$entity", "@param", "$entityNormalized", "@param", "Method", "[]", "$entityMethods" ]
train
https://github.com/goulaheau/symfony-rest-bundle/blob/688a120540f144aa1033a72b75803fae34ba3953/Core/RestSerializer.php#L97-L161
gplcart/cli
controllers/commands/Page.php
Page.cmdGetPage
public function cmdGetPage() { $result = $this->getListPage(); $this->outputFormat($result); $this->outputFormatTablePage($result); $this->output(); }
php
public function cmdGetPage() { $result = $this->getListPage(); $this->outputFormat($result); $this->outputFormatTablePage($result); $this->output(); }
[ "public", "function", "cmdGetPage", "(", ")", "{", "$", "result", "=", "$", "this", "->", "getListPage", "(", ")", ";", "$", "this", "->", "outputFormat", "(", "$", "result", ")", ";", "$", "this", "->", "outputFormatTablePage", "(", "$", "result", ")", ";", "$", "this", "->", "output", "(", ")", ";", "}" ]
Callback for "page-get" command
[ "Callback", "for", "page", "-", "get", "command" ]
train
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Page.php#L40-L46
gplcart/cli
controllers/commands/Page.php
Page.cmdDeletePage
public function cmdDeletePage() { $id = $this->getParam(0); $all = $this->getParam('all'); $blog = $this->getParam('blog'); if (empty($id) && empty($all) && empty($blog)) { $this->errorAndExit($this->text('Invalid command')); } if (isset($id) && (empty($id) || !is_numeric($id))) { $this->errorAndExit($this->text('Invalid argument')); } $options = null; if (isset($id)) { if ($this->getParam('store')) { $options = array('store_id' => $id); } else if ($this->getParam('category')) { $options = array('category_id' => $id); } else if ($this->getParam('user')) { $options = array('user_id' => $id); } } else if ($blog) { $options = array('blog_post' => true); } else if ($all) { $options = array(); } if (isset($options)) { $deleted = $count = 0; foreach ($this->page->getList($options) as $item) { $count++; $deleted += (int) $this->page->delete($item['page_id']); } $result = $count && $count == $deleted; } else { $result = $this->page->delete($id); } if (empty($result)) { $this->errorAndExit($this->text('Unexpected result')); } $this->output(); }
php
public function cmdDeletePage() { $id = $this->getParam(0); $all = $this->getParam('all'); $blog = $this->getParam('blog'); if (empty($id) && empty($all) && empty($blog)) { $this->errorAndExit($this->text('Invalid command')); } if (isset($id) && (empty($id) || !is_numeric($id))) { $this->errorAndExit($this->text('Invalid argument')); } $options = null; if (isset($id)) { if ($this->getParam('store')) { $options = array('store_id' => $id); } else if ($this->getParam('category')) { $options = array('category_id' => $id); } else if ($this->getParam('user')) { $options = array('user_id' => $id); } } else if ($blog) { $options = array('blog_post' => true); } else if ($all) { $options = array(); } if (isset($options)) { $deleted = $count = 0; foreach ($this->page->getList($options) as $item) { $count++; $deleted += (int) $this->page->delete($item['page_id']); } $result = $count && $count == $deleted; } else { $result = $this->page->delete($id); } if (empty($result)) { $this->errorAndExit($this->text('Unexpected result')); } $this->output(); }
[ "public", "function", "cmdDeletePage", "(", ")", "{", "$", "id", "=", "$", "this", "->", "getParam", "(", "0", ")", ";", "$", "all", "=", "$", "this", "->", "getParam", "(", "'all'", ")", ";", "$", "blog", "=", "$", "this", "->", "getParam", "(", "'blog'", ")", ";", "if", "(", "empty", "(", "$", "id", ")", "&&", "empty", "(", "$", "all", ")", "&&", "empty", "(", "$", "blog", ")", ")", "{", "$", "this", "->", "errorAndExit", "(", "$", "this", "->", "text", "(", "'Invalid command'", ")", ")", ";", "}", "if", "(", "isset", "(", "$", "id", ")", "&&", "(", "empty", "(", "$", "id", ")", "||", "!", "is_numeric", "(", "$", "id", ")", ")", ")", "{", "$", "this", "->", "errorAndExit", "(", "$", "this", "->", "text", "(", "'Invalid argument'", ")", ")", ";", "}", "$", "options", "=", "null", ";", "if", "(", "isset", "(", "$", "id", ")", ")", "{", "if", "(", "$", "this", "->", "getParam", "(", "'store'", ")", ")", "{", "$", "options", "=", "array", "(", "'store_id'", "=>", "$", "id", ")", ";", "}", "else", "if", "(", "$", "this", "->", "getParam", "(", "'category'", ")", ")", "{", "$", "options", "=", "array", "(", "'category_id'", "=>", "$", "id", ")", ";", "}", "else", "if", "(", "$", "this", "->", "getParam", "(", "'user'", ")", ")", "{", "$", "options", "=", "array", "(", "'user_id'", "=>", "$", "id", ")", ";", "}", "}", "else", "if", "(", "$", "blog", ")", "{", "$", "options", "=", "array", "(", "'blog_post'", "=>", "true", ")", ";", "}", "else", "if", "(", "$", "all", ")", "{", "$", "options", "=", "array", "(", ")", ";", "}", "if", "(", "isset", "(", "$", "options", ")", ")", "{", "$", "deleted", "=", "$", "count", "=", "0", ";", "foreach", "(", "$", "this", "->", "page", "->", "getList", "(", "$", "options", ")", "as", "$", "item", ")", "{", "$", "count", "++", ";", "$", "deleted", "+=", "(", "int", ")", "$", "this", "->", "page", "->", "delete", "(", "$", "item", "[", "'page_id'", "]", ")", ";", "}", "$", "result", "=", "$", "count", "&&", "$", "count", "==", "$", "deleted", ";", "}", "else", "{", "$", "result", "=", "$", "this", "->", "page", "->", "delete", "(", "$", "id", ")", ";", "}", "if", "(", "empty", "(", "$", "result", ")", ")", "{", "$", "this", "->", "errorAndExit", "(", "$", "this", "->", "text", "(", "'Unexpected result'", ")", ")", ";", "}", "$", "this", "->", "output", "(", ")", ";", "}" ]
Callback for "page-delete" command
[ "Callback", "for", "page", "-", "delete", "command" ]
train
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Page.php#L51-L102
gplcart/cli
controllers/commands/Page.php
Page.cmdUpdatePage
public function cmdUpdatePage() { $params = $this->getParam(); if (empty($params[0]) || count($params) < 2) { $this->errorAndExit($this->text('Invalid command')); } if (!is_numeric($params[0])) { $this->errorAndExit($this->text('Invalid argument')); } $this->setSubmitted(null, $params); $this->setSubmitted('update', $params[0]); $this->validateComponent('page'); $this->updatePage($params[0]); $this->output(); }
php
public function cmdUpdatePage() { $params = $this->getParam(); if (empty($params[0]) || count($params) < 2) { $this->errorAndExit($this->text('Invalid command')); } if (!is_numeric($params[0])) { $this->errorAndExit($this->text('Invalid argument')); } $this->setSubmitted(null, $params); $this->setSubmitted('update', $params[0]); $this->validateComponent('page'); $this->updatePage($params[0]); $this->output(); }
[ "public", "function", "cmdUpdatePage", "(", ")", "{", "$", "params", "=", "$", "this", "->", "getParam", "(", ")", ";", "if", "(", "empty", "(", "$", "params", "[", "0", "]", ")", "||", "count", "(", "$", "params", ")", "<", "2", ")", "{", "$", "this", "->", "errorAndExit", "(", "$", "this", "->", "text", "(", "'Invalid command'", ")", ")", ";", "}", "if", "(", "!", "is_numeric", "(", "$", "params", "[", "0", "]", ")", ")", "{", "$", "this", "->", "errorAndExit", "(", "$", "this", "->", "text", "(", "'Invalid argument'", ")", ")", ";", "}", "$", "this", "->", "setSubmitted", "(", "null", ",", "$", "params", ")", ";", "$", "this", "->", "setSubmitted", "(", "'update'", ",", "$", "params", "[", "0", "]", ")", ";", "$", "this", "->", "validateComponent", "(", "'page'", ")", ";", "$", "this", "->", "updatePage", "(", "$", "params", "[", "0", "]", ")", ";", "$", "this", "->", "output", "(", ")", ";", "}" ]
Callback for "page-update" command
[ "Callback", "for", "page", "-", "update", "command" ]
train
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Page.php#L121-L139
gplcart/cli
controllers/commands/Page.php
Page.getListPage
protected function getListPage() { $id = $this->getParam(0); if (!isset($id)) { return $this->page->getList(array('limit' => $this->getLimit())); } if (!is_numeric($id)) { $this->errorAndExit($this->text('Invalid argument')); } if ($this->getParam('user')) { return $this->page->getList(array('user_id' => $id, 'limit' => $this->getLimit())); } if ($this->getParam('category')) { return $this->page->getList(array('category_id' => $id, 'limit' => $this->getLimit())); } if ($this->getParam('store')) { return $this->page->getList(array('store_id' => $id, 'limit' => $this->getLimit())); } $result = $this->page->get($id); if (empty($result)) { $this->errorAndExit($this->text('Unexpected result')); } return array($result); }
php
protected function getListPage() { $id = $this->getParam(0); if (!isset($id)) { return $this->page->getList(array('limit' => $this->getLimit())); } if (!is_numeric($id)) { $this->errorAndExit($this->text('Invalid argument')); } if ($this->getParam('user')) { return $this->page->getList(array('user_id' => $id, 'limit' => $this->getLimit())); } if ($this->getParam('category')) { return $this->page->getList(array('category_id' => $id, 'limit' => $this->getLimit())); } if ($this->getParam('store')) { return $this->page->getList(array('store_id' => $id, 'limit' => $this->getLimit())); } $result = $this->page->get($id); if (empty($result)) { $this->errorAndExit($this->text('Unexpected result')); } return array($result); }
[ "protected", "function", "getListPage", "(", ")", "{", "$", "id", "=", "$", "this", "->", "getParam", "(", "0", ")", ";", "if", "(", "!", "isset", "(", "$", "id", ")", ")", "{", "return", "$", "this", "->", "page", "->", "getList", "(", "array", "(", "'limit'", "=>", "$", "this", "->", "getLimit", "(", ")", ")", ")", ";", "}", "if", "(", "!", "is_numeric", "(", "$", "id", ")", ")", "{", "$", "this", "->", "errorAndExit", "(", "$", "this", "->", "text", "(", "'Invalid argument'", ")", ")", ";", "}", "if", "(", "$", "this", "->", "getParam", "(", "'user'", ")", ")", "{", "return", "$", "this", "->", "page", "->", "getList", "(", "array", "(", "'user_id'", "=>", "$", "id", ",", "'limit'", "=>", "$", "this", "->", "getLimit", "(", ")", ")", ")", ";", "}", "if", "(", "$", "this", "->", "getParam", "(", "'category'", ")", ")", "{", "return", "$", "this", "->", "page", "->", "getList", "(", "array", "(", "'category_id'", "=>", "$", "id", ",", "'limit'", "=>", "$", "this", "->", "getLimit", "(", ")", ")", ")", ";", "}", "if", "(", "$", "this", "->", "getParam", "(", "'store'", ")", ")", "{", "return", "$", "this", "->", "page", "->", "getList", "(", "array", "(", "'store_id'", "=>", "$", "id", ",", "'limit'", "=>", "$", "this", "->", "getLimit", "(", ")", ")", ")", ";", "}", "$", "result", "=", "$", "this", "->", "page", "->", "get", "(", "$", "id", ")", ";", "if", "(", "empty", "(", "$", "result", ")", ")", "{", "$", "this", "->", "errorAndExit", "(", "$", "this", "->", "text", "(", "'Unexpected result'", ")", ")", ";", "}", "return", "array", "(", "$", "result", ")", ";", "}" ]
Returns an array of pages @return array
[ "Returns", "an", "array", "of", "pages" ]
train
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Page.php#L145-L176
gplcart/cli
controllers/commands/Page.php
Page.addPage
protected function addPage() { if (!$this->isError()) { $id = $this->page->add($this->getSubmitted()); if (empty($id)) { $this->errorAndExit($this->text('Unexpected result')); } $this->line($id); } }
php
protected function addPage() { if (!$this->isError()) { $id = $this->page->add($this->getSubmitted()); if (empty($id)) { $this->errorAndExit($this->text('Unexpected result')); } $this->line($id); } }
[ "protected", "function", "addPage", "(", ")", "{", "if", "(", "!", "$", "this", "->", "isError", "(", ")", ")", "{", "$", "id", "=", "$", "this", "->", "page", "->", "add", "(", "$", "this", "->", "getSubmitted", "(", ")", ")", ";", "if", "(", "empty", "(", "$", "id", ")", ")", "{", "$", "this", "->", "errorAndExit", "(", "$", "this", "->", "text", "(", "'Unexpected result'", ")", ")", ";", "}", "$", "this", "->", "line", "(", "$", "id", ")", ";", "}", "}" ]
Add a new page
[ "Add", "a", "new", "page" ]
train
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Page.php#L212-L221
gplcart/cli
controllers/commands/Page.php
Page.updatePage
protected function updatePage($page_id) { if (!$this->isError() && !$this->page->update($page_id, $this->getSubmitted())) { $this->errorAndExit($this->text('Unexpected result')); } }
php
protected function updatePage($page_id) { if (!$this->isError() && !$this->page->update($page_id, $this->getSubmitted())) { $this->errorAndExit($this->text('Unexpected result')); } }
[ "protected", "function", "updatePage", "(", "$", "page_id", ")", "{", "if", "(", "!", "$", "this", "->", "isError", "(", ")", "&&", "!", "$", "this", "->", "page", "->", "update", "(", "$", "page_id", ",", "$", "this", "->", "getSubmitted", "(", ")", ")", ")", "{", "$", "this", "->", "errorAndExit", "(", "$", "this", "->", "text", "(", "'Unexpected result'", ")", ")", ";", "}", "}" ]
Updates a page @param string $page_id
[ "Updates", "a", "page" ]
train
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Page.php#L227-L232
gplcart/cli
controllers/commands/Page.php
Page.submitAddPage
protected function submitAddPage() { $this->setSubmitted(null, $this->getParam()); $this->validateComponent('page'); $this->addPage(); }
php
protected function submitAddPage() { $this->setSubmitted(null, $this->getParam()); $this->validateComponent('page'); $this->addPage(); }
[ "protected", "function", "submitAddPage", "(", ")", "{", "$", "this", "->", "setSubmitted", "(", "null", ",", "$", "this", "->", "getParam", "(", ")", ")", ";", "$", "this", "->", "validateComponent", "(", "'page'", ")", ";", "$", "this", "->", "addPage", "(", ")", ";", "}" ]
Add a new page at once
[ "Add", "a", "new", "page", "at", "once" ]
train
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Page.php#L237-L242
gplcart/cli
controllers/commands/Page.php
Page.wizardAddPage
protected function wizardAddPage() { // Required $this->validatePrompt('title', $this->text('Title'), 'page'); $this->validatePrompt('description', $this->text('Description'), 'page'); $this->validatePrompt('store_id', $this->text('Store ID'), 'page'); // Optional $this->validatePrompt('user_id', $this->text('User ID'), 'page', 0); $this->validatePrompt('meta_title', $this->text('Meta title'), 'page', ''); $this->validatePrompt('meta_description', $this->text('Meta description'), 'page', ''); $this->validatePrompt('category_id', $this->text('Category ID'), 'page', 0); $this->validatePrompt('blog_post', $this->text('Blog post'), 'page', 0); $this->validatePrompt('status', $this->text('Status'), 'page', 0); $this->validateComponent('page'); $this->addPage(); }
php
protected function wizardAddPage() { // Required $this->validatePrompt('title', $this->text('Title'), 'page'); $this->validatePrompt('description', $this->text('Description'), 'page'); $this->validatePrompt('store_id', $this->text('Store ID'), 'page'); // Optional $this->validatePrompt('user_id', $this->text('User ID'), 'page', 0); $this->validatePrompt('meta_title', $this->text('Meta title'), 'page', ''); $this->validatePrompt('meta_description', $this->text('Meta description'), 'page', ''); $this->validatePrompt('category_id', $this->text('Category ID'), 'page', 0); $this->validatePrompt('blog_post', $this->text('Blog post'), 'page', 0); $this->validatePrompt('status', $this->text('Status'), 'page', 0); $this->validateComponent('page'); $this->addPage(); }
[ "protected", "function", "wizardAddPage", "(", ")", "{", "// Required", "$", "this", "->", "validatePrompt", "(", "'title'", ",", "$", "this", "->", "text", "(", "'Title'", ")", ",", "'page'", ")", ";", "$", "this", "->", "validatePrompt", "(", "'description'", ",", "$", "this", "->", "text", "(", "'Description'", ")", ",", "'page'", ")", ";", "$", "this", "->", "validatePrompt", "(", "'store_id'", ",", "$", "this", "->", "text", "(", "'Store ID'", ")", ",", "'page'", ")", ";", "// Optional", "$", "this", "->", "validatePrompt", "(", "'user_id'", ",", "$", "this", "->", "text", "(", "'User ID'", ")", ",", "'page'", ",", "0", ")", ";", "$", "this", "->", "validatePrompt", "(", "'meta_title'", ",", "$", "this", "->", "text", "(", "'Meta title'", ")", ",", "'page'", ",", "''", ")", ";", "$", "this", "->", "validatePrompt", "(", "'meta_description'", ",", "$", "this", "->", "text", "(", "'Meta description'", ")", ",", "'page'", ",", "''", ")", ";", "$", "this", "->", "validatePrompt", "(", "'category_id'", ",", "$", "this", "->", "text", "(", "'Category ID'", ")", ",", "'page'", ",", "0", ")", ";", "$", "this", "->", "validatePrompt", "(", "'blog_post'", ",", "$", "this", "->", "text", "(", "'Blog post'", ")", ",", "'page'", ",", "0", ")", ";", "$", "this", "->", "validatePrompt", "(", "'status'", ",", "$", "this", "->", "text", "(", "'Status'", ")", ",", "'page'", ",", "0", ")", ";", "$", "this", "->", "validateComponent", "(", "'page'", ")", ";", "$", "this", "->", "addPage", "(", ")", ";", "}" ]
Add a new page step by step
[ "Add", "a", "new", "page", "step", "by", "step" ]
train
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Page.php#L247-L264
peterfox/behat-resources-extension
src/ResourceExtension.php
ResourceExtension.configure
public function configure(ArrayNodeDefinition $builder) { $paths = $builder->children()->arrayNode('path')->children(); foreach (array('resources', 'base') as $namespaceType) { $paths->scalarNode($namespaceType); } $builder->children()->variableNode('resource_map'); $builder->children()->scalarNode('factory_class'); }
php
public function configure(ArrayNodeDefinition $builder) { $paths = $builder->children()->arrayNode('path')->children(); foreach (array('resources', 'base') as $namespaceType) { $paths->scalarNode($namespaceType); } $builder->children()->variableNode('resource_map'); $builder->children()->scalarNode('factory_class'); }
[ "public", "function", "configure", "(", "ArrayNodeDefinition", "$", "builder", ")", "{", "$", "paths", "=", "$", "builder", "->", "children", "(", ")", "->", "arrayNode", "(", "'path'", ")", "->", "children", "(", ")", ";", "foreach", "(", "array", "(", "'resources'", ",", "'base'", ")", "as", "$", "namespaceType", ")", "{", "$", "paths", "->", "scalarNode", "(", "$", "namespaceType", ")", ";", "}", "$", "builder", "->", "children", "(", ")", "->", "variableNode", "(", "'resource_map'", ")", ";", "$", "builder", "->", "children", "(", ")", "->", "scalarNode", "(", "'factory_class'", ")", ";", "}" ]
Setups configuration for the extension. @param ArrayNodeDefinition $builder
[ "Setups", "configuration", "for", "the", "extension", "." ]
train
https://github.com/peterfox/behat-resources-extension/blob/85fc1c306867a1f141050b43651290245d81b51c/src/ResourceExtension.php#L55-L63
peterfox/behat-resources-extension
src/ResourceExtension.php
ResourceExtension.load
public function load(ContainerBuilder $container, array $config) { $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/config')); $loader->load('services.xml'); if (!empty($config['path'])) { if (isset($config['path']['resources'])) { $container->setParameter('paths.resources.resource', $config['path']['resources']); } if (isset($config['path']['base'])) { $container->setParameter('paths.resources.base', $config['path']['base']); } } if (!empty($config['resource_map'])) { $container->setParameter('resource.map', $config['resource_map']); } }
php
public function load(ContainerBuilder $container, array $config) { $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/config')); $loader->load('services.xml'); if (!empty($config['path'])) { if (isset($config['path']['resources'])) { $container->setParameter('paths.resources.resource', $config['path']['resources']); } if (isset($config['path']['base'])) { $container->setParameter('paths.resources.base', $config['path']['base']); } } if (!empty($config['resource_map'])) { $container->setParameter('resource.map', $config['resource_map']); } }
[ "public", "function", "load", "(", "ContainerBuilder", "$", "container", ",", "array", "$", "config", ")", "{", "$", "loader", "=", "new", "XmlFileLoader", "(", "$", "container", ",", "new", "FileLocator", "(", "__DIR__", ".", "'/config'", ")", ")", ";", "$", "loader", "->", "load", "(", "'services.xml'", ")", ";", "if", "(", "!", "empty", "(", "$", "config", "[", "'path'", "]", ")", ")", "{", "if", "(", "isset", "(", "$", "config", "[", "'path'", "]", "[", "'resources'", "]", ")", ")", "{", "$", "container", "->", "setParameter", "(", "'paths.resources.resource'", ",", "$", "config", "[", "'path'", "]", "[", "'resources'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "config", "[", "'path'", "]", "[", "'base'", "]", ")", ")", "{", "$", "container", "->", "setParameter", "(", "'paths.resources.base'", ",", "$", "config", "[", "'path'", "]", "[", "'base'", "]", ")", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "config", "[", "'resource_map'", "]", ")", ")", "{", "$", "container", "->", "setParameter", "(", "'resource.map'", ",", "$", "config", "[", "'resource_map'", "]", ")", ";", "}", "}" ]
Loads extension services into temporary container. @param ContainerBuilder $container @param array $config
[ "Loads", "extension", "services", "into", "temporary", "container", "." ]
train
https://github.com/peterfox/behat-resources-extension/blob/85fc1c306867a1f141050b43651290245d81b51c/src/ResourceExtension.php#L71-L89
eclipxe13/engineworks-progress-status
src/EngineWorks/ProgressStatus/Status.php
Status.make
public static function make($total = 0, $message = '', $value = 0, $startTime = null, $current = null) { $now = time(); return new self($current ? : $now, $startTime ? : $now, $value, $total, $message); }
php
public static function make($total = 0, $message = '', $value = 0, $startTime = null, $current = null) { $now = time(); return new self($current ? : $now, $startTime ? : $now, $value, $total, $message); }
[ "public", "static", "function", "make", "(", "$", "total", "=", "0", ",", "$", "message", "=", "''", ",", "$", "value", "=", "0", ",", "$", "startTime", "=", "null", ",", "$", "current", "=", "null", ")", "{", "$", "now", "=", "time", "(", ")", ";", "return", "new", "self", "(", "$", "current", "?", ":", "$", "now", ",", "$", "startTime", "?", ":", "$", "now", ",", "$", "value", ",", "$", "total", ",", "$", "message", ")", ";", "}" ]
Helper function to create a new object @param int $total @param string $message @param int $value @param int|null $startTime if null then uses the value of time() @param int|null $current if null then uses the value of time() @return Status
[ "Helper", "function", "to", "create", "a", "new", "object" ]
train
https://github.com/eclipxe13/engineworks-progress-status/blob/2eda8e17ba10ff93ca206ffa8039c38acac17bcd/src/EngineWorks/ProgressStatus/Status.php#L49-L53
Wedeto/Auth
src/ACL/ACL.php
ACL.registerClass
public function registerClass(string $class, string $name) { if (isset($this->classes[$name])) throw new Exception("Cannot register the same name twice"); if (!is_a($class, ACLModel::class, true)) throw new TypeError("Class must be subclass of ACLModel"); $this->classes[$name] = $class; $this->classes_names[$class] = $name; return $this; }
php
public function registerClass(string $class, string $name) { if (isset($this->classes[$name])) throw new Exception("Cannot register the same name twice"); if (!is_a($class, ACLModel::class, true)) throw new TypeError("Class must be subclass of ACLModel"); $this->classes[$name] = $class; $this->classes_names[$class] = $name; return $this; }
[ "public", "function", "registerClass", "(", "string", "$", "class", ",", "string", "$", "name", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "classes", "[", "$", "name", "]", ")", ")", "throw", "new", "Exception", "(", "\"Cannot register the same name twice\"", ")", ";", "if", "(", "!", "is_a", "(", "$", "class", ",", "ACLModel", "::", "class", ",", "true", ")", ")", "throw", "new", "TypeError", "(", "\"Class must be subclass of ACLModel\"", ")", ";", "$", "this", "->", "classes", "[", "$", "name", "]", "=", "$", "class", ";", "$", "this", "->", "classes_names", "[", "$", "class", "]", "=", "$", "name", ";", "return", "$", "this", ";", "}" ]
Register the name of the object class to be used in ACL entity naming. @param string $class The name of the class @param string $name The name of the ACL objects @return $this Provides fluent interface
[ "Register", "the", "name", "of", "the", "object", "class", "to", "be", "used", "in", "ACL", "entity", "naming", "." ]
train
https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/ACL/ACL.php#L92-L102
Wedeto/Auth
src/ACL/ACL.php
ACL.loadByACLID
public function loadByACLID($id) { $parts = explode("#", $id); if (count($parts) !== 2) throw new Exception("Invalid DAO ID: {$id}"); if (!isset($this->classes[$parts[0]])) throw new Exception("Invalid DAO type: {$parts[0]}"); $classname = $this->classes[$parts[0]]; $pkey_values = explode("-", $parts[1]); $db = DB::getInstance(); $dao = $db->getDAO($classname); return call_user_func(array($dao, "get"), $pkey_values); }
php
public function loadByACLID($id) { $parts = explode("#", $id); if (count($parts) !== 2) throw new Exception("Invalid DAO ID: {$id}"); if (!isset($this->classes[$parts[0]])) throw new Exception("Invalid DAO type: {$parts[0]}"); $classname = $this->classes[$parts[0]]; $pkey_values = explode("-", $parts[1]); $db = DB::getInstance(); $dao = $db->getDAO($classname); return call_user_func(array($dao, "get"), $pkey_values); }
[ "public", "function", "loadByACLID", "(", "$", "id", ")", "{", "$", "parts", "=", "explode", "(", "\"#\"", ",", "$", "id", ")", ";", "if", "(", "count", "(", "$", "parts", ")", "!==", "2", ")", "throw", "new", "Exception", "(", "\"Invalid DAO ID: {$id}\"", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "classes", "[", "$", "parts", "[", "0", "]", "]", ")", ")", "throw", "new", "Exception", "(", "\"Invalid DAO type: {$parts[0]}\"", ")", ";", "$", "classname", "=", "$", "this", "->", "classes", "[", "$", "parts", "[", "0", "]", "]", ";", "$", "pkey_values", "=", "explode", "(", "\"-\"", ",", "$", "parts", "[", "1", "]", ")", ";", "$", "db", "=", "DB", "::", "getInstance", "(", ")", ";", "$", "dao", "=", "$", "db", "->", "getDAO", "(", "$", "classname", ")", ";", "return", "call_user_func", "(", "array", "(", "$", "dao", ",", "\"get\"", ")", ",", "$", "pkey_values", ")", ";", "}" ]
This method will load a new instance to be used in ACL inheritance
[ "This", "method", "will", "load", "a", "new", "instance", "to", "be", "used", "in", "ACL", "inheritance" ]
train
https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/ACL/ACL.php#L165-L181
Wedeto/Auth
src/ACL/ACL.php
ACL.getInstance
public function getInstance(string $class, $element_id) { if (!is_a($class, Hierarchy::class, true)) throw new TypeError("Not a subclass of Hierarchy: $class"); if (is_object($element_id) && get_class($element_id) === $class) return $element_id; if (!is_scalar($element_id)) throw new TypeError("Element-ID must be a scalar"); if (!$this->hasInstance($class, $element_id)) { $root = $class::getRootName(); if ($element_id === $root) $this->hierarchy[$class][$root] = new $class($this, $root); else throw new Exception("Element-ID '{$element_id}' is unknown for {$class}"); } return $this->hierarchy[$class][$element_id]; }
php
public function getInstance(string $class, $element_id) { if (!is_a($class, Hierarchy::class, true)) throw new TypeError("Not a subclass of Hierarchy: $class"); if (is_object($element_id) && get_class($element_id) === $class) return $element_id; if (!is_scalar($element_id)) throw new TypeError("Element-ID must be a scalar"); if (!$this->hasInstance($class, $element_id)) { $root = $class::getRootName(); if ($element_id === $root) $this->hierarchy[$class][$root] = new $class($this, $root); else throw new Exception("Element-ID '{$element_id}' is unknown for {$class}"); } return $this->hierarchy[$class][$element_id]; }
[ "public", "function", "getInstance", "(", "string", "$", "class", ",", "$", "element_id", ")", "{", "if", "(", "!", "is_a", "(", "$", "class", ",", "Hierarchy", "::", "class", ",", "true", ")", ")", "throw", "new", "TypeError", "(", "\"Not a subclass of Hierarchy: $class\"", ")", ";", "if", "(", "is_object", "(", "$", "element_id", ")", "&&", "get_class", "(", "$", "element_id", ")", "===", "$", "class", ")", "return", "$", "element_id", ";", "if", "(", "!", "is_scalar", "(", "$", "element_id", ")", ")", "throw", "new", "TypeError", "(", "\"Element-ID must be a scalar\"", ")", ";", "if", "(", "!", "$", "this", "->", "hasInstance", "(", "$", "class", ",", "$", "element_id", ")", ")", "{", "$", "root", "=", "$", "class", "::", "getRootName", "(", ")", ";", "if", "(", "$", "element_id", "===", "$", "root", ")", "$", "this", "->", "hierarchy", "[", "$", "class", "]", "[", "$", "root", "]", "=", "new", "$", "class", "(", "$", "this", ",", "$", "root", ")", ";", "else", "throw", "new", "Exception", "(", "\"Element-ID '{$element_id}' is unknown for {$class}\"", ")", ";", "}", "return", "$", "this", "->", "hierarchy", "[", "$", "class", "]", "[", "$", "element_id", "]", ";", "}" ]
Get an hierarchy element by specifying its ID
[ "Get", "an", "hierarchy", "element", "by", "specifying", "its", "ID" ]
train
https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/ACL/ACL.php#L186-L207
Wedeto/Auth
src/ACL/ACL.php
ACL.getRoot
public function getRoot(string $class) { if (!is_a($class, Hierarchy::class, true)) throw new TypeError("Not a subclass of Hierarchy: $class"); $root = $class::getRootName(); return $this->getInstance($class, $root); }
php
public function getRoot(string $class) { if (!is_a($class, Hierarchy::class, true)) throw new TypeError("Not a subclass of Hierarchy: $class"); $root = $class::getRootName(); return $this->getInstance($class, $root); }
[ "public", "function", "getRoot", "(", "string", "$", "class", ")", "{", "if", "(", "!", "is_a", "(", "$", "class", ",", "Hierarchy", "::", "class", ",", "true", ")", ")", "throw", "new", "TypeError", "(", "\"Not a subclass of Hierarchy: $class\"", ")", ";", "$", "root", "=", "$", "class", "::", "getRootName", "(", ")", ";", "return", "$", "this", "->", "getInstance", "(", "$", "class", ",", "$", "root", ")", ";", "}" ]
Return the root element for a certain hierarchy @param string $class The class name @return Hierarchy The root element of the hierarchy @throws Wedeto\Auth\ACL\Exception When an invalid class is passed
[ "Return", "the", "root", "element", "for", "a", "certain", "hierarchy" ]
train
https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/ACL/ACL.php#L216-L223
Wedeto/Auth
src/ACL/ACL.php
ACL.createEntity
public function createEntity(string $entity_id, array $parents) { $entity = new Entity($this, $entity_id, $parents); return $entity; }
php
public function createEntity(string $entity_id, array $parents) { $entity = new Entity($this, $entity_id, $parents); return $entity; }
[ "public", "function", "createEntity", "(", "string", "$", "entity_id", ",", "array", "$", "parents", ")", "{", "$", "entity", "=", "new", "Entity", "(", "$", "this", ",", "$", "entity_id", ",", "$", "parents", ")", ";", "return", "$", "entity", ";", "}" ]
Create a new entity and store it. @param string $entity_id The ID of the entity @param array $parents The parents of the entity @throws Exception When the entity_id has already been created for this class
[ "Create", "a", "new", "entity", "and", "store", "it", "." ]
train
https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/ACL/ACL.php#L231-L235
Wedeto/Auth
src/ACL/ACL.php
ACL.setInstance
public function setInstance(Hierarchy $element) { $class = get_class($element); $this->hierarchy[$class][$element->getID()] = $element; return $this; }
php
public function setInstance(Hierarchy $element) { $class = get_class($element); $this->hierarchy[$class][$element->getID()] = $element; return $this; }
[ "public", "function", "setInstance", "(", "Hierarchy", "$", "element", ")", "{", "$", "class", "=", "get_class", "(", "$", "element", ")", ";", "$", "this", "->", "hierarchy", "[", "$", "class", "]", "[", "$", "element", "->", "getID", "(", ")", "]", "=", "$", "element", ";", "return", "$", "this", ";", "}" ]
Set the instance of a specific ID. @param scalar $id The ID to set the instance for @return $this Provides fluent interface
[ "Set", "the", "instance", "of", "a", "specific", "ID", "." ]
train
https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/ACL/ACL.php#L273-L278
itkg/core
src/Itkg/Core/Command/DatabaseUpdate/Template/Loader.php
Loader.load
public function load($file, array $data = array()) { $this->queries = array(); $this->data = $data; include $file; return $this; }
php
public function load($file, array $data = array()) { $this->queries = array(); $this->data = $data; include $file; return $this; }
[ "public", "function", "load", "(", "$", "file", ",", "array", "$", "data", "=", "array", "(", ")", ")", "{", "$", "this", "->", "queries", "=", "array", "(", ")", ";", "$", "this", "->", "data", "=", "$", "data", ";", "include", "$", "file", ";", "return", "$", "this", ";", "}" ]
Load script file @param $file @return $this
[ "Load", "script", "file" ]
train
https://github.com/itkg/core/blob/e5e4efb05feb4d23b0df41f2b21fd095103e593b/src/Itkg/Core/Command/DatabaseUpdate/Template/Loader.php#L49-L57
itkg/core
src/Itkg/Core/Command/DatabaseUpdate/Template/Loader.php
Loader.override
public function override($query) { foreach ($this->data as $key => $value) { $query = str_replace( sprintf('{%s}', $key), $value, $query ); } return $query; }
php
public function override($query) { foreach ($this->data as $key => $value) { $query = str_replace( sprintf('{%s}', $key), $value, $query ); } return $query; }
[ "public", "function", "override", "(", "$", "query", ")", "{", "foreach", "(", "$", "this", "->", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "query", "=", "str_replace", "(", "sprintf", "(", "'{%s}'", ",", "$", "key", ")", ",", "$", "value", ",", "$", "query", ")", ";", "}", "return", "$", "query", ";", "}" ]
Replace some parameters with value parameter looks like {key} @param $query @return string
[ "Replace", "some", "parameters", "with", "value", "parameter", "looks", "like", "{", "key", "}" ]
train
https://github.com/itkg/core/blob/e5e4efb05feb4d23b0df41f2b21fd095103e593b/src/Itkg/Core/Command/DatabaseUpdate/Template/Loader.php#L65-L76
beMang/phpgone
core/Core/BackController.php
BackController.execute
public function execute() { if (method_exists($this, 'setUp')) { call_user_func_array([$this, 'setUp'], [$this->request]); } call_user_func_array([$this, $this->action], [$this->request]); }
php
public function execute() { if (method_exists($this, 'setUp')) { call_user_func_array([$this, 'setUp'], [$this->request]); } call_user_func_array([$this, $this->action], [$this->request]); }
[ "public", "function", "execute", "(", ")", "{", "if", "(", "method_exists", "(", "$", "this", ",", "'setUp'", ")", ")", "{", "call_user_func_array", "(", "[", "$", "this", ",", "'setUp'", "]", ",", "[", "$", "this", "->", "request", "]", ")", ";", "}", "call_user_func_array", "(", "[", "$", "this", ",", "$", "this", "->", "action", "]", ",", "[", "$", "this", "->", "request", "]", ")", ";", "}" ]
Execute la bonne fonction enfante en fonction de l'action @return void
[ "Execute", "la", "bonne", "fonction", "enfante", "en", "fonction", "de", "l", "action" ]
train
https://github.com/beMang/phpgone/blob/6da468283880b7f5b28dc3735f8f13c97382710b/core/Core/BackController.php#L34-L40
devlabmtl/haven-cms
Controller/WizardController.php
WizardController.getWizard
private function getWizard() { $wizId = $this->container->get("request")->get('wizard_id'); $stId = $this->container->get("request")->get('step_id'); // echo "<p>-->" . print_r("<p>" . $wizId, 1) . "<--</p>"; // echo "<p>-->" . print_r("<p>" . $stId, 1) . "<--</p>"; $wizard = $this->get('haven_cms.wizards_chain')->get($wizId); return $wizard; }
php
private function getWizard() { $wizId = $this->container->get("request")->get('wizard_id'); $stId = $this->container->get("request")->get('step_id'); // echo "<p>-->" . print_r("<p>" . $wizId, 1) . "<--</p>"; // echo "<p>-->" . print_r("<p>" . $stId, 1) . "<--</p>"; $wizard = $this->get('haven_cms.wizards_chain')->get($wizId); return $wizard; }
[ "private", "function", "getWizard", "(", ")", "{", "$", "wizId", "=", "$", "this", "->", "container", "->", "get", "(", "\"request\"", ")", "->", "get", "(", "'wizard_id'", ")", ";", "$", "stId", "=", "$", "this", "->", "container", "->", "get", "(", "\"request\"", ")", "->", "get", "(", "'step_id'", ")", ";", "// echo \"<p>-->\" . print_r(\"<p>\" . $wizId, 1) . \"<--</p>\";", "// echo \"<p>-->\" . print_r(\"<p>\" . $stId, 1) . \"<--</p>\";", "$", "wizard", "=", "$", "this", "->", "get", "(", "'haven_cms.wizards_chain'", ")", "->", "get", "(", "$", "wizId", ")", ";", "return", "$", "wizard", ";", "}" ]
}
[ "}" ]
train
https://github.com/devlabmtl/haven-cms/blob/c20761a07c201a966dbda1f3eae33617f80e1ece/Controller/WizardController.php#L76-L84
devlabmtl/haven-cms
Controller/WizardController.php
WizardController.wizardAction
public function wizardAction($wizard_id, $step_id) { /** * get request * validate request * not valide getView for error * valide * handle request and get aggregate * choose view to display * */ // should I use a manager (pageManager) $edit_form = $this->getCreateNewForm(); $template = $this->getCreateTemplate(); $params = array( 'edit_form' => $edit_form->createView() ); return new Response($this->container->get('templating')->render($template, $params)); }
php
public function wizardAction($wizard_id, $step_id) { /** * get request * validate request * not valide getView for error * valide * handle request and get aggregate * choose view to display * */ // should I use a manager (pageManager) $edit_form = $this->getCreateNewForm(); $template = $this->getCreateTemplate(); $params = array( 'edit_form' => $edit_form->createView() ); return new Response($this->container->get('templating')->render($template, $params)); }
[ "public", "function", "wizardAction", "(", "$", "wizard_id", ",", "$", "step_id", ")", "{", "/**\n * get request\n * validate request\n * not valide getView for error\n * valide \n * handle request and get aggregate\n * choose view to display\n * \n */", "// should I use a manager (pageManager)", "$", "edit_form", "=", "$", "this", "->", "getCreateNewForm", "(", ")", ";", "$", "template", "=", "$", "this", "->", "getCreateTemplate", "(", ")", ";", "$", "params", "=", "array", "(", "'edit_form'", "=>", "$", "edit_form", "->", "createView", "(", ")", ")", ";", "return", "new", "Response", "(", "$", "this", "->", "container", "->", "get", "(", "'templating'", ")", "->", "render", "(", "$", "template", ",", "$", "params", ")", ")", ";", "}" ]
@Route("/") @Method({"GET"}) @param type $wizard_id @param type $step_id
[ "@Route", "(", "/", ")", "@Method", "(", "{", "GET", "}", ")" ]
train
https://github.com/devlabmtl/haven-cms/blob/c20761a07c201a966dbda1f3eae33617f80e1ece/Controller/WizardController.php#L94-L114
cmsgears/module-community
admin/controllers/group/CategoryController.php
CategoryController.init
public function init() { parent::init(); // Permission $this->crudPermission = CmnGlobal::PERM_GROUP_ADMIN; // Config $this->title = 'Group'; $this->type = CmnGlobal::TYPE_GROUP; $this->templateType = CmnGlobal::TYPE_GROUP; $this->apixBase = 'community/group/category'; $this->parentPath = '/community/group/category'; // Sidebar $this->sidebar = [ 'parent' => 'sidebar-community', 'child' => 'group-category' ]; // Return Url $this->returnUrl = Url::previous( 'group-categories' ); $this->returnUrl = isset( $this->returnUrl ) ? $this->returnUrl : Url::toRoute( [ '/community/group/category/all' ], true ); // Breadcrumbs $this->breadcrumbs = [ 'base' => [ [ 'label' => 'Home', 'url' => Url::toRoute( '/dashboard' ) ] ], 'all' => [ [ 'label' => 'Group Categories' ] ], 'create' => [ [ 'label' => 'Group Categories', 'url' => $this->returnUrl ], [ 'label' => 'Add' ] ], 'update' => [ [ 'label' => 'Group Categories', 'url' => $this->returnUrl ], [ 'label' => 'Update' ] ], 'delete' => [ [ 'label' => 'Group Categories', 'url' => $this->returnUrl ], [ 'label' => 'Delete' ] ], 'gallery' => [ [ 'label' => 'Group Categories', 'url' => $this->returnUrl ], [ 'label' => 'Gallery' ] ], 'data' => [ [ 'label' => 'Group Categories', 'url' => $this->returnUrl ], [ 'label' => 'Data' ] ], 'config' => [ [ 'label' => 'Group Categories', 'url' => $this->returnUrl ], [ 'label' => 'Config' ] ], 'settings' => [ [ 'label' => 'Group Categories', 'url' => $this->returnUrl ], [ 'label' => 'Settings' ] ] ]; }
php
public function init() { parent::init(); // Permission $this->crudPermission = CmnGlobal::PERM_GROUP_ADMIN; // Config $this->title = 'Group'; $this->type = CmnGlobal::TYPE_GROUP; $this->templateType = CmnGlobal::TYPE_GROUP; $this->apixBase = 'community/group/category'; $this->parentPath = '/community/group/category'; // Sidebar $this->sidebar = [ 'parent' => 'sidebar-community', 'child' => 'group-category' ]; // Return Url $this->returnUrl = Url::previous( 'group-categories' ); $this->returnUrl = isset( $this->returnUrl ) ? $this->returnUrl : Url::toRoute( [ '/community/group/category/all' ], true ); // Breadcrumbs $this->breadcrumbs = [ 'base' => [ [ 'label' => 'Home', 'url' => Url::toRoute( '/dashboard' ) ] ], 'all' => [ [ 'label' => 'Group Categories' ] ], 'create' => [ [ 'label' => 'Group Categories', 'url' => $this->returnUrl ], [ 'label' => 'Add' ] ], 'update' => [ [ 'label' => 'Group Categories', 'url' => $this->returnUrl ], [ 'label' => 'Update' ] ], 'delete' => [ [ 'label' => 'Group Categories', 'url' => $this->returnUrl ], [ 'label' => 'Delete' ] ], 'gallery' => [ [ 'label' => 'Group Categories', 'url' => $this->returnUrl ], [ 'label' => 'Gallery' ] ], 'data' => [ [ 'label' => 'Group Categories', 'url' => $this->returnUrl ], [ 'label' => 'Data' ] ], 'config' => [ [ 'label' => 'Group Categories', 'url' => $this->returnUrl ], [ 'label' => 'Config' ] ], 'settings' => [ [ 'label' => 'Group Categories', 'url' => $this->returnUrl ], [ 'label' => 'Settings' ] ] ]; }
[ "public", "function", "init", "(", ")", "{", "parent", "::", "init", "(", ")", ";", "// Permission", "$", "this", "->", "crudPermission", "=", "CmnGlobal", "::", "PERM_GROUP_ADMIN", ";", "// Config", "$", "this", "->", "title", "=", "'Group'", ";", "$", "this", "->", "type", "=", "CmnGlobal", "::", "TYPE_GROUP", ";", "$", "this", "->", "templateType", "=", "CmnGlobal", "::", "TYPE_GROUP", ";", "$", "this", "->", "apixBase", "=", "'community/group/category'", ";", "$", "this", "->", "parentPath", "=", "'/community/group/category'", ";", "// Sidebar", "$", "this", "->", "sidebar", "=", "[", "'parent'", "=>", "'sidebar-community'", ",", "'child'", "=>", "'group-category'", "]", ";", "// Return Url", "$", "this", "->", "returnUrl", "=", "Url", "::", "previous", "(", "'group-categories'", ")", ";", "$", "this", "->", "returnUrl", "=", "isset", "(", "$", "this", "->", "returnUrl", ")", "?", "$", "this", "->", "returnUrl", ":", "Url", "::", "toRoute", "(", "[", "'/community/group/category/all'", "]", ",", "true", ")", ";", "// Breadcrumbs", "$", "this", "->", "breadcrumbs", "=", "[", "'base'", "=>", "[", "[", "'label'", "=>", "'Home'", ",", "'url'", "=>", "Url", "::", "toRoute", "(", "'/dashboard'", ")", "]", "]", ",", "'all'", "=>", "[", "[", "'label'", "=>", "'Group Categories'", "]", "]", ",", "'create'", "=>", "[", "[", "'label'", "=>", "'Group Categories'", ",", "'url'", "=>", "$", "this", "->", "returnUrl", "]", ",", "[", "'label'", "=>", "'Add'", "]", "]", ",", "'update'", "=>", "[", "[", "'label'", "=>", "'Group Categories'", ",", "'url'", "=>", "$", "this", "->", "returnUrl", "]", ",", "[", "'label'", "=>", "'Update'", "]", "]", ",", "'delete'", "=>", "[", "[", "'label'", "=>", "'Group Categories'", ",", "'url'", "=>", "$", "this", "->", "returnUrl", "]", ",", "[", "'label'", "=>", "'Delete'", "]", "]", ",", "'gallery'", "=>", "[", "[", "'label'", "=>", "'Group Categories'", ",", "'url'", "=>", "$", "this", "->", "returnUrl", "]", ",", "[", "'label'", "=>", "'Gallery'", "]", "]", ",", "'data'", "=>", "[", "[", "'label'", "=>", "'Group Categories'", ",", "'url'", "=>", "$", "this", "->", "returnUrl", "]", ",", "[", "'label'", "=>", "'Data'", "]", "]", ",", "'config'", "=>", "[", "[", "'label'", "=>", "'Group Categories'", ",", "'url'", "=>", "$", "this", "->", "returnUrl", "]", ",", "[", "'label'", "=>", "'Config'", "]", "]", ",", "'settings'", "=>", "[", "[", "'label'", "=>", "'Group Categories'", ",", "'url'", "=>", "$", "this", "->", "returnUrl", "]", ",", "[", "'label'", "=>", "'Settings'", "]", "]", "]", ";", "}" ]
Constructor and Initialisation ------------------------------
[ "Constructor", "and", "Initialisation", "------------------------------" ]
train
https://github.com/cmsgears/module-community/blob/0ca9cf0aa0cee395a4788bd6085f291e10728555/admin/controllers/group/CategoryController.php#L38-L73
stubbles/stubbles-webapp-session
src/main/php/storage/ArraySessionStorage.php
ArraySessionStorage.value
public function value($key) { if (isset($this->data[$key])) { return $this->data[$key]; } return null; }
php
public function value($key) { if (isset($this->data[$key])) { return $this->data[$key]; } return null; }
[ "public", "function", "value", "(", "$", "key", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "data", "[", "$", "key", "]", ")", ")", "{", "return", "$", "this", "->", "data", "[", "$", "key", "]", ";", "}", "return", "null", ";", "}" ]
returns a value associated with the key or the default value @param string $key key where value is stored under @return mixed
[ "returns", "a", "value", "associated", "with", "the", "key", "or", "the", "default", "value" ]
train
https://github.com/stubbles/stubbles-webapp-session/blob/2976fa28995bfb6ad00e3eac59ad689dd7892450/src/main/php/storage/ArraySessionStorage.php#L62-L69
Rudloff/php-dicollecte-lexicon
classes/Lexicon.php
Lexicon.getBy
private function getBy($search, $column) { $search = mb_strtolower($search, mb_detect_encoding($search)); $this->procBuilder->setArguments(['-e', "\t$search\t"]); $process = $this->procBuilder->getProcess(); $process->run(); $csv = Csv\Reader::createFromString($process->getOutput()); $csv->setDelimiter($this->delimiter); $results = []; foreach ($csv->fetchAssoc(['id', 'inflection', 'lemma', 'tags']) as $row) { if ($row[$column] == $search) { $results[] = new Inflection($row['id'], $row['inflection'], $row['lemma'], explode(' ', $row['tags'])); } } return $results; }
php
private function getBy($search, $column) { $search = mb_strtolower($search, mb_detect_encoding($search)); $this->procBuilder->setArguments(['-e', "\t$search\t"]); $process = $this->procBuilder->getProcess(); $process->run(); $csv = Csv\Reader::createFromString($process->getOutput()); $csv->setDelimiter($this->delimiter); $results = []; foreach ($csv->fetchAssoc(['id', 'inflection', 'lemma', 'tags']) as $row) { if ($row[$column] == $search) { $results[] = new Inflection($row['id'], $row['inflection'], $row['lemma'], explode(' ', $row['tags'])); } } return $results; }
[ "private", "function", "getBy", "(", "$", "search", ",", "$", "column", ")", "{", "$", "search", "=", "mb_strtolower", "(", "$", "search", ",", "mb_detect_encoding", "(", "$", "search", ")", ")", ";", "$", "this", "->", "procBuilder", "->", "setArguments", "(", "[", "'-e'", ",", "\"\\t$search\\t\"", "]", ")", ";", "$", "process", "=", "$", "this", "->", "procBuilder", "->", "getProcess", "(", ")", ";", "$", "process", "->", "run", "(", ")", ";", "$", "csv", "=", "Csv", "\\", "Reader", "::", "createFromString", "(", "$", "process", "->", "getOutput", "(", ")", ")", ";", "$", "csv", "->", "setDelimiter", "(", "$", "this", "->", "delimiter", ")", ";", "$", "results", "=", "[", "]", ";", "foreach", "(", "$", "csv", "->", "fetchAssoc", "(", "[", "'id'", ",", "'inflection'", ",", "'lemma'", ",", "'tags'", "]", ")", "as", "$", "row", ")", "{", "if", "(", "$", "row", "[", "$", "column", "]", "==", "$", "search", ")", "{", "$", "results", "[", "]", "=", "new", "Inflection", "(", "$", "row", "[", "'id'", "]", ",", "$", "row", "[", "'inflection'", "]", ",", "$", "row", "[", "'lemma'", "]", ",", "explode", "(", "' '", ",", "$", "row", "[", "'tags'", "]", ")", ")", ";", "}", "}", "return", "$", "results", ";", "}" ]
Get inflections by searching in a specific column. @param string $search String to search @param string $column Column name @return Inflection[] Search results
[ "Get", "inflections", "by", "searching", "in", "a", "specific", "column", "." ]
train
https://github.com/Rudloff/php-dicollecte-lexicon/blob/d868c1ef8d844edfdd012a7ef051cf9a2ca69f9e/classes/Lexicon.php#L57-L73
koolkode/security
src/Authentication/EntryPoint/HttpDigest.php
HttpDigest.startAuthentication
public function startAuthentication(TokenInterface $token, HttpRequest $request, HttpResponse $response) { if(!$token instanceof HttpDigestToken) { throw new SecurityException(sprintf('Invalid token %s passed to %s', get_class($token), get_class($this))); } $params = [ 'realm' => $this->auth->getRealm(), 'qop' => $this->auth->getQualityOfProtection(), 'opaque' => $this->auth->getOpaque(), 'nonce' => $this->auth->createNonce($this->securityContext), ]; if($token->isStale()) { $params['stale'] = true; } $authString = 'Digest '; $i = 0; foreach($params as $name => $value) { if($i++ > 0) { $authString .= ','; } if(is_bool($value)) { $authString .= sprintf('%s=%s', $name, $value ? 'true' : 'false'); } elseif(is_numeric($value)) { $authString .= sprintf('%s=%s', $name, $value); } else { $authString .= sprintf('%s="%s"', $name, str_replace('"', '\\"', trim($value))); } } $response->setStatus(Http::CODE_UNAUTHORIZED); $response->setReason(Http::getReason(Http::CODE_UNAUTHORIZED)); $response->addHeader('WWW-Authenticate', $authString); }
php
public function startAuthentication(TokenInterface $token, HttpRequest $request, HttpResponse $response) { if(!$token instanceof HttpDigestToken) { throw new SecurityException(sprintf('Invalid token %s passed to %s', get_class($token), get_class($this))); } $params = [ 'realm' => $this->auth->getRealm(), 'qop' => $this->auth->getQualityOfProtection(), 'opaque' => $this->auth->getOpaque(), 'nonce' => $this->auth->createNonce($this->securityContext), ]; if($token->isStale()) { $params['stale'] = true; } $authString = 'Digest '; $i = 0; foreach($params as $name => $value) { if($i++ > 0) { $authString .= ','; } if(is_bool($value)) { $authString .= sprintf('%s=%s', $name, $value ? 'true' : 'false'); } elseif(is_numeric($value)) { $authString .= sprintf('%s=%s', $name, $value); } else { $authString .= sprintf('%s="%s"', $name, str_replace('"', '\\"', trim($value))); } } $response->setStatus(Http::CODE_UNAUTHORIZED); $response->setReason(Http::getReason(Http::CODE_UNAUTHORIZED)); $response->addHeader('WWW-Authenticate', $authString); }
[ "public", "function", "startAuthentication", "(", "TokenInterface", "$", "token", ",", "HttpRequest", "$", "request", ",", "HttpResponse", "$", "response", ")", "{", "if", "(", "!", "$", "token", "instanceof", "HttpDigestToken", ")", "{", "throw", "new", "SecurityException", "(", "sprintf", "(", "'Invalid token %s passed to %s'", ",", "get_class", "(", "$", "token", ")", ",", "get_class", "(", "$", "this", ")", ")", ")", ";", "}", "$", "params", "=", "[", "'realm'", "=>", "$", "this", "->", "auth", "->", "getRealm", "(", ")", ",", "'qop'", "=>", "$", "this", "->", "auth", "->", "getQualityOfProtection", "(", ")", ",", "'opaque'", "=>", "$", "this", "->", "auth", "->", "getOpaque", "(", ")", ",", "'nonce'", "=>", "$", "this", "->", "auth", "->", "createNonce", "(", "$", "this", "->", "securityContext", ")", ",", "]", ";", "if", "(", "$", "token", "->", "isStale", "(", ")", ")", "{", "$", "params", "[", "'stale'", "]", "=", "true", ";", "}", "$", "authString", "=", "'Digest '", ";", "$", "i", "=", "0", ";", "foreach", "(", "$", "params", "as", "$", "name", "=>", "$", "value", ")", "{", "if", "(", "$", "i", "++", ">", "0", ")", "{", "$", "authString", ".=", "','", ";", "}", "if", "(", "is_bool", "(", "$", "value", ")", ")", "{", "$", "authString", ".=", "sprintf", "(", "'%s=%s'", ",", "$", "name", ",", "$", "value", "?", "'true'", ":", "'false'", ")", ";", "}", "elseif", "(", "is_numeric", "(", "$", "value", ")", ")", "{", "$", "authString", ".=", "sprintf", "(", "'%s=%s'", ",", "$", "name", ",", "$", "value", ")", ";", "}", "else", "{", "$", "authString", ".=", "sprintf", "(", "'%s=\"%s\"'", ",", "$", "name", ",", "str_replace", "(", "'\"'", ",", "'\\\\\"'", ",", "trim", "(", "$", "value", ")", ")", ")", ";", "}", "}", "$", "response", "->", "setStatus", "(", "Http", "::", "CODE_UNAUTHORIZED", ")", ";", "$", "response", "->", "setReason", "(", "Http", "::", "getReason", "(", "Http", "::", "CODE_UNAUTHORIZED", ")", ")", ";", "$", "response", "->", "addHeader", "(", "'WWW-Authenticate'", ",", "$", "authString", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/koolkode/security/blob/d3d8d42392f520754847d29b6df19aaa38c79e8e/src/Authentication/EntryPoint/HttpDigest.php#L43-L90
SimplyCodedSoftware/integration-messaging-cqrs
src/CallAggregateService.php
CallAggregateService.call
public function call(Message $message) : Message { $aggregate = $message->getHeaders()->containsKey(CqrsMessagingModule::INTEGRATION_MESSAGING_CQRS_AGGREGATE_HEADER) ? $message->getHeaders()->get(CqrsMessagingModule::INTEGRATION_MESSAGING_CQRS_AGGREGATE_HEADER) : null; $methodInvoker = MethodInvoker::createWith( $aggregate ? $aggregate : $message->getHeaders()->get(CqrsMessagingModule::INTEGRATION_MESSAGING_CQRS_AGGREGATE_CLASS_NAME_HEADER), $message->getHeaders()->get(CqrsMessagingModule::INTEGRATION_MESSAGING_CQRS_AGGREGATE_METHOD_HEADER), $this->messageToParameterConverters ); $resultMessage = MessageBuilder::fromMessage($message); try { $result = $methodInvoker->processMessage($message); if (!$aggregate) { $resultMessage = $resultMessage ->setHeader(CqrsMessagingModule::INTEGRATION_MESSAGING_CQRS_AGGREGATE_HEADER, $result); } } catch (\Throwable $e) { throw MessageHandlingException::fromOtherException($e, $message); } if (!is_null($result)) { $resultMessage = $resultMessage ->setPayload($result); } return $resultMessage ->build(); }
php
public function call(Message $message) : Message { $aggregate = $message->getHeaders()->containsKey(CqrsMessagingModule::INTEGRATION_MESSAGING_CQRS_AGGREGATE_HEADER) ? $message->getHeaders()->get(CqrsMessagingModule::INTEGRATION_MESSAGING_CQRS_AGGREGATE_HEADER) : null; $methodInvoker = MethodInvoker::createWith( $aggregate ? $aggregate : $message->getHeaders()->get(CqrsMessagingModule::INTEGRATION_MESSAGING_CQRS_AGGREGATE_CLASS_NAME_HEADER), $message->getHeaders()->get(CqrsMessagingModule::INTEGRATION_MESSAGING_CQRS_AGGREGATE_METHOD_HEADER), $this->messageToParameterConverters ); $resultMessage = MessageBuilder::fromMessage($message); try { $result = $methodInvoker->processMessage($message); if (!$aggregate) { $resultMessage = $resultMessage ->setHeader(CqrsMessagingModule::INTEGRATION_MESSAGING_CQRS_AGGREGATE_HEADER, $result); } } catch (\Throwable $e) { throw MessageHandlingException::fromOtherException($e, $message); } if (!is_null($result)) { $resultMessage = $resultMessage ->setPayload($result); } return $resultMessage ->build(); }
[ "public", "function", "call", "(", "Message", "$", "message", ")", ":", "Message", "{", "$", "aggregate", "=", "$", "message", "->", "getHeaders", "(", ")", "->", "containsKey", "(", "CqrsMessagingModule", "::", "INTEGRATION_MESSAGING_CQRS_AGGREGATE_HEADER", ")", "?", "$", "message", "->", "getHeaders", "(", ")", "->", "get", "(", "CqrsMessagingModule", "::", "INTEGRATION_MESSAGING_CQRS_AGGREGATE_HEADER", ")", ":", "null", ";", "$", "methodInvoker", "=", "MethodInvoker", "::", "createWith", "(", "$", "aggregate", "?", "$", "aggregate", ":", "$", "message", "->", "getHeaders", "(", ")", "->", "get", "(", "CqrsMessagingModule", "::", "INTEGRATION_MESSAGING_CQRS_AGGREGATE_CLASS_NAME_HEADER", ")", ",", "$", "message", "->", "getHeaders", "(", ")", "->", "get", "(", "CqrsMessagingModule", "::", "INTEGRATION_MESSAGING_CQRS_AGGREGATE_METHOD_HEADER", ")", ",", "$", "this", "->", "messageToParameterConverters", ")", ";", "$", "resultMessage", "=", "MessageBuilder", "::", "fromMessage", "(", "$", "message", ")", ";", "try", "{", "$", "result", "=", "$", "methodInvoker", "->", "processMessage", "(", "$", "message", ")", ";", "if", "(", "!", "$", "aggregate", ")", "{", "$", "resultMessage", "=", "$", "resultMessage", "->", "setHeader", "(", "CqrsMessagingModule", "::", "INTEGRATION_MESSAGING_CQRS_AGGREGATE_HEADER", ",", "$", "result", ")", ";", "}", "}", "catch", "(", "\\", "Throwable", "$", "e", ")", "{", "throw", "MessageHandlingException", "::", "fromOtherException", "(", "$", "e", ",", "$", "message", ")", ";", "}", "if", "(", "!", "is_null", "(", "$", "result", ")", ")", "{", "$", "resultMessage", "=", "$", "resultMessage", "->", "setPayload", "(", "$", "result", ")", ";", "}", "return", "$", "resultMessage", "->", "build", "(", ")", ";", "}" ]
@param Message $message @return Message @throws MessageHandlingException
[ "@param", "Message", "$message" ]
train
https://github.com/SimplyCodedSoftware/integration-messaging-cqrs/blob/c59407d61ffbb29a1fdf5b363ca654d541482a2c/src/CallAggregateService.php#L51-L81
reliv/rcm-config
src/Factory/ConfigModel.php
ConfigModel.createService
public function createService(ServiceLocatorInterface $serviceLocator) { $config = $serviceLocator->get('config'); return new \Reliv\RcmConfig\Model\ConfigModel($config, null); }
php
public function createService(ServiceLocatorInterface $serviceLocator) { $config = $serviceLocator->get('config'); return new \Reliv\RcmConfig\Model\ConfigModel($config, null); }
[ "public", "function", "createService", "(", "ServiceLocatorInterface", "$", "serviceLocator", ")", "{", "$", "config", "=", "$", "serviceLocator", "->", "get", "(", "'config'", ")", ";", "return", "new", "\\", "Reliv", "\\", "RcmConfig", "\\", "Model", "\\", "ConfigModel", "(", "$", "config", ",", "null", ")", ";", "}" ]
Creates Service @param ServiceLocatorInterface $serviceLocator Zend Service Locator @return \Reliv\RcmConfig\Model\ConfigModel
[ "Creates", "Service" ]
train
https://github.com/reliv/rcm-config/blob/3e8cdea57a8688b06997ce1b167b8410bccac09e/src/Factory/ConfigModel.php#L30-L35
ScaraMVC/Framework
src/Scara/Http/Groups/Groupable.php
Groupable.finalize
public function finalize() { $gen = new UrlGenerator(); if (!empty($this->redirect)) { $gen->redirect($this->redirect); } }
php
public function finalize() { $gen = new UrlGenerator(); if (!empty($this->redirect)) { $gen->redirect($this->redirect); } }
[ "public", "function", "finalize", "(", ")", "{", "$", "gen", "=", "new", "UrlGenerator", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "redirect", ")", ")", "{", "$", "gen", "->", "redirect", "(", "$", "this", "->", "redirect", ")", ";", "}", "}" ]
Finalize groups that implement the Groupable trait. @return void
[ "Finalize", "groups", "that", "implement", "the", "Groupable", "trait", "." ]
train
https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Http/Groups/Groupable.php#L24-L30
cmsgears/module-community
common/components/Factory.php
Factory.registerEntityAliases
public function registerEntityAliases() { $factory = Yii::$app->factory->getContainer(); $factory->set( 'chatService', 'cmsgears\community\common\services\entities\ChatService' ); $factory->set( 'groupService', 'cmsgears\community\common\services\entities\GroupService' ); }
php
public function registerEntityAliases() { $factory = Yii::$app->factory->getContainer(); $factory->set( 'chatService', 'cmsgears\community\common\services\entities\ChatService' ); $factory->set( 'groupService', 'cmsgears\community\common\services\entities\GroupService' ); }
[ "public", "function", "registerEntityAliases", "(", ")", "{", "$", "factory", "=", "Yii", "::", "$", "app", "->", "factory", "->", "getContainer", "(", ")", ";", "$", "factory", "->", "set", "(", "'chatService'", ",", "'cmsgears\\community\\common\\services\\entities\\ChatService'", ")", ";", "$", "factory", "->", "set", "(", "'groupService'", ",", "'cmsgears\\community\\common\\services\\entities\\GroupService'", ")", ";", "}" ]
Registers entity aliases.
[ "Registers", "entity", "aliases", "." ]
train
https://github.com/cmsgears/module-community/blob/0ca9cf0aa0cee395a4788bd6085f291e10728555/common/components/Factory.php#L150-L157
lightwerk/SurfCaptain
Classes/Lightwerk/SurfCaptain/Controller/AbstractRestController.php
AbstractRestController.initializeController
protected function initializeController( \TYPO3\Flow\Mvc\RequestInterface $request, \TYPO3\Flow\Mvc\ResponseInterface $response ) { $this->parentInitializeController($request, $response); // override request.format with NegotiatedMediaType aka HTTP-Request // Content-Type and set Content-Type to response $this->mediaType = $this->request->getHttpRequest()->getNegotiatedMediaType($this->supportedMediaTypes); if (in_array($this->mediaType, $this->supportedMediaTypes) === false) { $this->throwStatus(406); } else { // convert negotiatedMediaType to Flow format $this->request->setFormat(preg_replace('/.*\/(.*)/', '$1', $this->mediaType)); // sets the Content-Type to the response $this->response->setHeader('Content-Type', $this->mediaType . '; charset=UTF-8', true); } }
php
protected function initializeController( \TYPO3\Flow\Mvc\RequestInterface $request, \TYPO3\Flow\Mvc\ResponseInterface $response ) { $this->parentInitializeController($request, $response); // override request.format with NegotiatedMediaType aka HTTP-Request // Content-Type and set Content-Type to response $this->mediaType = $this->request->getHttpRequest()->getNegotiatedMediaType($this->supportedMediaTypes); if (in_array($this->mediaType, $this->supportedMediaTypes) === false) { $this->throwStatus(406); } else { // convert negotiatedMediaType to Flow format $this->request->setFormat(preg_replace('/.*\/(.*)/', '$1', $this->mediaType)); // sets the Content-Type to the response $this->response->setHeader('Content-Type', $this->mediaType . '; charset=UTF-8', true); } }
[ "protected", "function", "initializeController", "(", "\\", "TYPO3", "\\", "Flow", "\\", "Mvc", "\\", "RequestInterface", "$", "request", ",", "\\", "TYPO3", "\\", "Flow", "\\", "Mvc", "\\", "ResponseInterface", "$", "response", ")", "{", "$", "this", "->", "parentInitializeController", "(", "$", "request", ",", "$", "response", ")", ";", "// override request.format with NegotiatedMediaType aka HTTP-Request", "// Content-Type and set Content-Type to response", "$", "this", "->", "mediaType", "=", "$", "this", "->", "request", "->", "getHttpRequest", "(", ")", "->", "getNegotiatedMediaType", "(", "$", "this", "->", "supportedMediaTypes", ")", ";", "if", "(", "in_array", "(", "$", "this", "->", "mediaType", ",", "$", "this", "->", "supportedMediaTypes", ")", "===", "false", ")", "{", "$", "this", "->", "throwStatus", "(", "406", ")", ";", "}", "else", "{", "// convert negotiatedMediaType to Flow format", "$", "this", "->", "request", "->", "setFormat", "(", "preg_replace", "(", "'/.*\\/(.*)/'", ",", "'$1'", ",", "$", "this", "->", "mediaType", ")", ")", ";", "// sets the Content-Type to the response", "$", "this", "->", "response", "->", "setHeader", "(", "'Content-Type'", ",", "$", "this", "->", "mediaType", ".", "'; charset=UTF-8'", ",", "true", ")", ";", "}", "}" ]
Initializes the controller This method should be called by the concrete processRequest() method. @param \TYPO3\Flow\Mvc\RequestInterface $request @param \TYPO3\Flow\Mvc\ResponseInterface $response @throws \TYPO3\Flow\Mvc\Exception\UnsupportedRequestTypeException @return void
[ "Initializes", "the", "controller" ]
train
https://github.com/lightwerk/SurfCaptain/blob/2865e963fd634504d8923902cf422873749a0940/Classes/Lightwerk/SurfCaptain/Controller/AbstractRestController.php#L53-L69
lightwerk/SurfCaptain
Classes/Lightwerk/SurfCaptain/Controller/AbstractRestController.php
AbstractRestController.errorAction
protected function errorAction() { // we like to have a 400 status $this->response->setStatus(400); if ($this->mediaType === 'application/json') { $this->addErrorFlashMessage(); } else { parent::errorAction(); } }
php
protected function errorAction() { // we like to have a 400 status $this->response->setStatus(400); if ($this->mediaType === 'application/json') { $this->addErrorFlashMessage(); } else { parent::errorAction(); } }
[ "protected", "function", "errorAction", "(", ")", "{", "// we like to have a 400 status", "$", "this", "->", "response", "->", "setStatus", "(", "400", ")", ";", "if", "(", "$", "this", "->", "mediaType", "===", "'application/json'", ")", "{", "$", "this", "->", "addErrorFlashMessage", "(", ")", ";", "}", "else", "{", "parent", "::", "errorAction", "(", ")", ";", "}", "}" ]
Error Action @return void
[ "Error", "Action" ]
train
https://github.com/lightwerk/SurfCaptain/blob/2865e963fd634504d8923902cf422873749a0940/Classes/Lightwerk/SurfCaptain/Controller/AbstractRestController.php#L89-L98
lightwerk/SurfCaptain
Classes/Lightwerk/SurfCaptain/Controller/AbstractRestController.php
AbstractRestController.handleException
protected function handleException(\Exception $exception) { $this->response->setStatus(500); // may be we want also an exceptionHandler e.g. to notify somebody, ... $this->addFlashMessage( $exception->getMessage(), get_class($exception), Message::SEVERITY_ERROR, [], $exception->getCode() ); }
php
protected function handleException(\Exception $exception) { $this->response->setStatus(500); // may be we want also an exceptionHandler e.g. to notify somebody, ... $this->addFlashMessage( $exception->getMessage(), get_class($exception), Message::SEVERITY_ERROR, [], $exception->getCode() ); }
[ "protected", "function", "handleException", "(", "\\", "Exception", "$", "exception", ")", "{", "$", "this", "->", "response", "->", "setStatus", "(", "500", ")", ";", "// may be we want also an exceptionHandler e.g. to notify somebody, ...", "$", "this", "->", "addFlashMessage", "(", "$", "exception", "->", "getMessage", "(", ")", ",", "get_class", "(", "$", "exception", ")", ",", "Message", "::", "SEVERITY_ERROR", ",", "[", "]", ",", "$", "exception", "->", "getCode", "(", ")", ")", ";", "}" ]
Handle Exception @param \Exception $exception @return void
[ "Handle", "Exception" ]
train
https://github.com/lightwerk/SurfCaptain/blob/2865e963fd634504d8923902cf422873749a0940/Classes/Lightwerk/SurfCaptain/Controller/AbstractRestController.php#L106-L117
lightwerk/SurfCaptain
Classes/Lightwerk/SurfCaptain/Controller/AbstractRestController.php
AbstractRestController.redirect
protected function redirect( $actionName, $controllerName = null, $packageKey = null, array $arguments = null, $delay = 0, $statusCode = 303, $format = null ) { if ($this->mediaType === 'application/json') { // render all arguments if (!empty($arguments)) { foreach ($arguments as $key => $value) { $this->view->assign($key, $value); } } // get uri (like AbstractController->redirect()) // do we need/want the uri? if ($packageKey !== null && strpos($packageKey, '\\') !== false) { list($packageKey, $subpackageKey) = explode('\\', $packageKey, 2); } else { $subpackageKey = null; } $this->uriBuilder->reset(); if ($format === null) { $this->uriBuilder->setFormat($this->request->getFormat()); } else { $this->uriBuilder->setFormat($format); } $uri = $this->uriBuilder ->setCreateAbsoluteUri(true) ->uriFor($actionName, $arguments, $controllerName, $packageKey, $subpackageKey); $this->view->assign('see', $uri); } else { parent::redirect($actionName, $controllerName, $packageKey, $arguments, $delay, $statusCode, $format); } }
php
protected function redirect( $actionName, $controllerName = null, $packageKey = null, array $arguments = null, $delay = 0, $statusCode = 303, $format = null ) { if ($this->mediaType === 'application/json') { // render all arguments if (!empty($arguments)) { foreach ($arguments as $key => $value) { $this->view->assign($key, $value); } } // get uri (like AbstractController->redirect()) // do we need/want the uri? if ($packageKey !== null && strpos($packageKey, '\\') !== false) { list($packageKey, $subpackageKey) = explode('\\', $packageKey, 2); } else { $subpackageKey = null; } $this->uriBuilder->reset(); if ($format === null) { $this->uriBuilder->setFormat($this->request->getFormat()); } else { $this->uriBuilder->setFormat($format); } $uri = $this->uriBuilder ->setCreateAbsoluteUri(true) ->uriFor($actionName, $arguments, $controllerName, $packageKey, $subpackageKey); $this->view->assign('see', $uri); } else { parent::redirect($actionName, $controllerName, $packageKey, $arguments, $delay, $statusCode, $format); } }
[ "protected", "function", "redirect", "(", "$", "actionName", ",", "$", "controllerName", "=", "null", ",", "$", "packageKey", "=", "null", ",", "array", "$", "arguments", "=", "null", ",", "$", "delay", "=", "0", ",", "$", "statusCode", "=", "303", ",", "$", "format", "=", "null", ")", "{", "if", "(", "$", "this", "->", "mediaType", "===", "'application/json'", ")", "{", "// render all arguments", "if", "(", "!", "empty", "(", "$", "arguments", ")", ")", "{", "foreach", "(", "$", "arguments", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "this", "->", "view", "->", "assign", "(", "$", "key", ",", "$", "value", ")", ";", "}", "}", "// get uri (like AbstractController->redirect())", "// do we need/want the uri?", "if", "(", "$", "packageKey", "!==", "null", "&&", "strpos", "(", "$", "packageKey", ",", "'\\\\'", ")", "!==", "false", ")", "{", "list", "(", "$", "packageKey", ",", "$", "subpackageKey", ")", "=", "explode", "(", "'\\\\'", ",", "$", "packageKey", ",", "2", ")", ";", "}", "else", "{", "$", "subpackageKey", "=", "null", ";", "}", "$", "this", "->", "uriBuilder", "->", "reset", "(", ")", ";", "if", "(", "$", "format", "===", "null", ")", "{", "$", "this", "->", "uriBuilder", "->", "setFormat", "(", "$", "this", "->", "request", "->", "getFormat", "(", ")", ")", ";", "}", "else", "{", "$", "this", "->", "uriBuilder", "->", "setFormat", "(", "$", "format", ")", ";", "}", "$", "uri", "=", "$", "this", "->", "uriBuilder", "->", "setCreateAbsoluteUri", "(", "true", ")", "->", "uriFor", "(", "$", "actionName", ",", "$", "arguments", ",", "$", "controllerName", ",", "$", "packageKey", ",", "$", "subpackageKey", ")", ";", "$", "this", "->", "view", "->", "assign", "(", "'see'", ",", "$", "uri", ")", ";", "}", "else", "{", "parent", "::", "redirect", "(", "$", "actionName", ",", "$", "controllerName", ",", "$", "packageKey", ",", "$", "arguments", ",", "$", "delay", ",", "$", "statusCode", ",", "$", "format", ")", ";", "}", "}" ]
Redirects the request to another action and / or controller. @param string $actionName Name of the action to forward to @param string $controllerName Unqualified object name of the controller to forward to. If not specified, the current controller is used. @param string $packageKey Key of the package containing the controller to forward to. If not specified, the current package is assumed. @param array $arguments Array of arguments for the target action @param integer $delay (optional) The delay in seconds. Default is no delay. @param integer $statusCode (optional) The HTTP status code for the redirect. Default is "303 See Other" @param string $format The format to use for the redirect URI @return void @throws \TYPO3\Flow\Mvc\Exception\StopActionException @see forward() @api
[ "Redirects", "the", "request", "to", "another", "action", "and", "/", "or", "controller", "." ]
train
https://github.com/lightwerk/SurfCaptain/blob/2865e963fd634504d8923902cf422873749a0940/Classes/Lightwerk/SurfCaptain/Controller/AbstractRestController.php#L134-L171
haggertypat/DirectoryBundle
Helper/Geocoder.php
Geocoder.distanceBetween
public function distanceBetween($latA, $lngA, $latB, $lngB) { $R = 6371; // earth's mean radius in km $dLat = $this->rad($latB - $latA); $dLong = $this->rad($lngB - $lngA); $a = \sin($dLat/2) * \sin($dLat/2) + \cos($this->rad($latA)) * \cos($this->rad($latB)) * \sin($dLong/2) * \sin($dLong/2); $c = 2 * \atan2(\sqrt($a), \sqrt(1-$a)); $d = $R * $c; return $d; }
php
public function distanceBetween($latA, $lngA, $latB, $lngB) { $R = 6371; // earth's mean radius in km $dLat = $this->rad($latB - $latA); $dLong = $this->rad($lngB - $lngA); $a = \sin($dLat/2) * \sin($dLat/2) + \cos($this->rad($latA)) * \cos($this->rad($latB)) * \sin($dLong/2) * \sin($dLong/2); $c = 2 * \atan2(\sqrt($a), \sqrt(1-$a)); $d = $R * $c; return $d; }
[ "public", "function", "distanceBetween", "(", "$", "latA", ",", "$", "lngA", ",", "$", "latB", ",", "$", "lngB", ")", "{", "$", "R", "=", "6371", ";", "// earth's mean radius in km", "$", "dLat", "=", "$", "this", "->", "rad", "(", "$", "latB", "-", "$", "latA", ")", ";", "$", "dLong", "=", "$", "this", "->", "rad", "(", "$", "lngB", "-", "$", "lngA", ")", ";", "$", "a", "=", "\\", "sin", "(", "$", "dLat", "/", "2", ")", "*", "\\", "sin", "(", "$", "dLat", "/", "2", ")", "+", "\\", "cos", "(", "$", "this", "->", "rad", "(", "$", "latA", ")", ")", "*", "\\", "cos", "(", "$", "this", "->", "rad", "(", "$", "latB", ")", ")", "*", "\\", "sin", "(", "$", "dLong", "/", "2", ")", "*", "\\", "sin", "(", "$", "dLong", "/", "2", ")", ";", "$", "c", "=", "2", "*", "\\", "atan2", "(", "\\", "sqrt", "(", "$", "a", ")", ",", "\\", "sqrt", "(", "1", "-", "$", "a", ")", ")", ";", "$", "d", "=", "$", "R", "*", "$", "c", ";", "return", "$", "d", ";", "}" ]
/* From http://stackoverflow.com/q/1502590
[ "/", "*", "From", "http", ":", "//", "stackoverflow", ".", "com", "/", "q", "/", "1502590" ]
train
https://github.com/haggertypat/DirectoryBundle/blob/ed2ee4a1a00d39df81d88eca7ef98dcf958da618/Helper/Geocoder.php#L46-L58
congraphcms/core
Helpers/StringHelper.php
StringHelper.createSlug
public static function createSlug($string) { // remove all accent characters $string = self::remove_accents($string); // lowercase $string = strtolower($string); // replace all characters except letters and numbers to dashes $slug = preg_replace('/[^A-Za-z0-9-]+/', '-', $string); // deep replace double dashes while(strpos('--', $slug)) { $slug = str_replace('--', '-', $slug); } // trim dashes at start and end $slug = trim($slug, '-'); return $slug; }
php
public static function createSlug($string) { // remove all accent characters $string = self::remove_accents($string); // lowercase $string = strtolower($string); // replace all characters except letters and numbers to dashes $slug = preg_replace('/[^A-Za-z0-9-]+/', '-', $string); // deep replace double dashes while(strpos('--', $slug)) { $slug = str_replace('--', '-', $slug); } // trim dashes at start and end $slug = trim($slug, '-'); return $slug; }
[ "public", "static", "function", "createSlug", "(", "$", "string", ")", "{", "// remove all accent characters", "$", "string", "=", "self", "::", "remove_accents", "(", "$", "string", ")", ";", "// lowercase", "$", "string", "=", "strtolower", "(", "$", "string", ")", ";", "// replace all characters except letters and numbers to dashes", "$", "slug", "=", "preg_replace", "(", "'/[^A-Za-z0-9-]+/'", ",", "'-'", ",", "$", "string", ")", ";", "// deep replace double dashes", "while", "(", "strpos", "(", "'--'", ",", "$", "slug", ")", ")", "{", "$", "slug", "=", "str_replace", "(", "'--'", ",", "'-'", ",", "$", "slug", ")", ";", "}", "// trim dashes at start and end", "$", "slug", "=", "trim", "(", "$", "slug", ",", "'-'", ")", ";", "return", "$", "slug", ";", "}" ]
Creates slug from any string @param string $string @return string
[ "Creates", "slug", "from", "any", "string" ]
train
https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Helpers/StringHelper.php#L38-L59
congraphcms/core
Helpers/StringHelper.php
StringHelper.remove_accents
public static function remove_accents( $string ) { if ( !preg_match('/[\x80-\xff]/', $string) ) return $string; if (self::seems_utf8($string)) { $chars = array( // Decompositions for Latin-1 Supplement chr(194).chr(170) => 'a', chr(194).chr(186) => 'o', chr(195).chr(128) => 'A', chr(195).chr(129) => 'A', chr(195).chr(130) => 'A', chr(195).chr(131) => 'A', chr(195).chr(132) => 'A', chr(195).chr(133) => 'A', chr(195).chr(134) => 'AE',chr(195).chr(135) => 'C', chr(195).chr(136) => 'E', chr(195).chr(137) => 'E', chr(195).chr(138) => 'E', chr(195).chr(139) => 'E', chr(195).chr(140) => 'I', chr(195).chr(141) => 'I', chr(195).chr(142) => 'I', chr(195).chr(143) => 'I', chr(195).chr(144) => 'D', chr(195).chr(145) => 'N', chr(195).chr(146) => 'O', chr(195).chr(147) => 'O', chr(195).chr(148) => 'O', chr(195).chr(149) => 'O', chr(195).chr(150) => 'O', chr(195).chr(153) => 'U', chr(195).chr(154) => 'U', chr(195).chr(155) => 'U', chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y', chr(195).chr(158) => 'TH',chr(195).chr(159) => 's', chr(195).chr(160) => 'a', chr(195).chr(161) => 'a', chr(195).chr(162) => 'a', chr(195).chr(163) => 'a', chr(195).chr(164) => 'a', chr(195).chr(165) => 'a', chr(195).chr(166) => 'ae',chr(195).chr(167) => 'c', chr(195).chr(168) => 'e', chr(195).chr(169) => 'e', chr(195).chr(170) => 'e', chr(195).chr(171) => 'e', chr(195).chr(172) => 'i', chr(195).chr(173) => 'i', chr(195).chr(174) => 'i', chr(195).chr(175) => 'i', chr(195).chr(176) => 'd', chr(195).chr(177) => 'n', chr(195).chr(178) => 'o', chr(195).chr(179) => 'o', chr(195).chr(180) => 'o', chr(195).chr(181) => 'o', chr(195).chr(182) => 'o', chr(195).chr(184) => 'o', chr(195).chr(185) => 'u', chr(195).chr(186) => 'u', chr(195).chr(187) => 'u', chr(195).chr(188) => 'u', chr(195).chr(189) => 'y', chr(195).chr(190) => 'th', chr(195).chr(191) => 'y', chr(195).chr(152) => 'O', // Decompositions for Latin Extended-A chr(196).chr(128) => 'A', chr(196).chr(129) => 'a', chr(196).chr(130) => 'A', chr(196).chr(131) => 'a', chr(196).chr(132) => 'A', chr(196).chr(133) => 'a', chr(196).chr(134) => 'C', chr(196).chr(135) => 'c', chr(196).chr(136) => 'C', chr(196).chr(137) => 'c', chr(196).chr(138) => 'C', chr(196).chr(139) => 'c', chr(196).chr(140) => 'C', chr(196).chr(141) => 'c', chr(196).chr(142) => 'D', chr(196).chr(143) => 'd', chr(196).chr(144) => 'D', chr(196).chr(145) => 'd', chr(196).chr(146) => 'E', chr(196).chr(147) => 'e', chr(196).chr(148) => 'E', chr(196).chr(149) => 'e', chr(196).chr(150) => 'E', chr(196).chr(151) => 'e', chr(196).chr(152) => 'E', chr(196).chr(153) => 'e', chr(196).chr(154) => 'E', chr(196).chr(155) => 'e', chr(196).chr(156) => 'G', chr(196).chr(157) => 'g', chr(196).chr(158) => 'G', chr(196).chr(159) => 'g', chr(196).chr(160) => 'G', chr(196).chr(161) => 'g', chr(196).chr(162) => 'G', chr(196).chr(163) => 'g', chr(196).chr(164) => 'H', chr(196).chr(165) => 'h', chr(196).chr(166) => 'H', chr(196).chr(167) => 'h', chr(196).chr(168) => 'I', chr(196).chr(169) => 'i', chr(196).chr(170) => 'I', chr(196).chr(171) => 'i', chr(196).chr(172) => 'I', chr(196).chr(173) => 'i', chr(196).chr(174) => 'I', chr(196).chr(175) => 'i', chr(196).chr(176) => 'I', chr(196).chr(177) => 'i', chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij', chr(196).chr(180) => 'J', chr(196).chr(181) => 'j', chr(196).chr(182) => 'K', chr(196).chr(183) => 'k', chr(196).chr(184) => 'k', chr(196).chr(185) => 'L', chr(196).chr(186) => 'l', chr(196).chr(187) => 'L', chr(196).chr(188) => 'l', chr(196).chr(189) => 'L', chr(196).chr(190) => 'l', chr(196).chr(191) => 'L', chr(197).chr(128) => 'l', chr(197).chr(129) => 'L', chr(197).chr(130) => 'l', chr(197).chr(131) => 'N', chr(197).chr(132) => 'n', chr(197).chr(133) => 'N', chr(197).chr(134) => 'n', chr(197).chr(135) => 'N', chr(197).chr(136) => 'n', chr(197).chr(137) => 'N', chr(197).chr(138) => 'n', chr(197).chr(139) => 'N', chr(197).chr(140) => 'O', chr(197).chr(141) => 'o', chr(197).chr(142) => 'O', chr(197).chr(143) => 'o', chr(197).chr(144) => 'O', chr(197).chr(145) => 'o', chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe', chr(197).chr(148) => 'R',chr(197).chr(149) => 'r', chr(197).chr(150) => 'R',chr(197).chr(151) => 'r', chr(197).chr(152) => 'R',chr(197).chr(153) => 'r', chr(197).chr(154) => 'S',chr(197).chr(155) => 's', chr(197).chr(156) => 'S',chr(197).chr(157) => 's', chr(197).chr(158) => 'S',chr(197).chr(159) => 's', chr(197).chr(160) => 'S', chr(197).chr(161) => 's', chr(197).chr(162) => 'T', chr(197).chr(163) => 't', chr(197).chr(164) => 'T', chr(197).chr(165) => 't', chr(197).chr(166) => 'T', chr(197).chr(167) => 't', chr(197).chr(168) => 'U', chr(197).chr(169) => 'u', chr(197).chr(170) => 'U', chr(197).chr(171) => 'u', chr(197).chr(172) => 'U', chr(197).chr(173) => 'u', chr(197).chr(174) => 'U', chr(197).chr(175) => 'u', chr(197).chr(176) => 'U', chr(197).chr(177) => 'u', chr(197).chr(178) => 'U', chr(197).chr(179) => 'u', chr(197).chr(180) => 'W', chr(197).chr(181) => 'w', chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y', chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z', chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z', chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z', chr(197).chr(190) => 'z', chr(197).chr(191) => 's', // Decompositions for Latin Extended-B chr(200).chr(152) => 'S', chr(200).chr(153) => 's', chr(200).chr(154) => 'T', chr(200).chr(155) => 't', // Euro Sign chr(226).chr(130).chr(172) => 'E', // GBP (Pound) Sign chr(194).chr(163) => '', // Vowels with diacritic (Vietnamese) // unmarked chr(198).chr(160) => 'O', chr(198).chr(161) => 'o', chr(198).chr(175) => 'U', chr(198).chr(176) => 'u', // grave accent chr(225).chr(186).chr(166) => 'A', chr(225).chr(186).chr(167) => 'a', chr(225).chr(186).chr(176) => 'A', chr(225).chr(186).chr(177) => 'a', chr(225).chr(187).chr(128) => 'E', chr(225).chr(187).chr(129) => 'e', chr(225).chr(187).chr(146) => 'O', chr(225).chr(187).chr(147) => 'o', chr(225).chr(187).chr(156) => 'O', chr(225).chr(187).chr(157) => 'o', chr(225).chr(187).chr(170) => 'U', chr(225).chr(187).chr(171) => 'u', chr(225).chr(187).chr(178) => 'Y', chr(225).chr(187).chr(179) => 'y', // hook chr(225).chr(186).chr(162) => 'A', chr(225).chr(186).chr(163) => 'a', chr(225).chr(186).chr(168) => 'A', chr(225).chr(186).chr(169) => 'a', chr(225).chr(186).chr(178) => 'A', chr(225).chr(186).chr(179) => 'a', chr(225).chr(186).chr(186) => 'E', chr(225).chr(186).chr(187) => 'e', chr(225).chr(187).chr(130) => 'E', chr(225).chr(187).chr(131) => 'e', chr(225).chr(187).chr(136) => 'I', chr(225).chr(187).chr(137) => 'i', chr(225).chr(187).chr(142) => 'O', chr(225).chr(187).chr(143) => 'o', chr(225).chr(187).chr(148) => 'O', chr(225).chr(187).chr(149) => 'o', chr(225).chr(187).chr(158) => 'O', chr(225).chr(187).chr(159) => 'o', chr(225).chr(187).chr(166) => 'U', chr(225).chr(187).chr(167) => 'u', chr(225).chr(187).chr(172) => 'U', chr(225).chr(187).chr(173) => 'u', chr(225).chr(187).chr(182) => 'Y', chr(225).chr(187).chr(183) => 'y', // tilde chr(225).chr(186).chr(170) => 'A', chr(225).chr(186).chr(171) => 'a', chr(225).chr(186).chr(180) => 'A', chr(225).chr(186).chr(181) => 'a', chr(225).chr(186).chr(188) => 'E', chr(225).chr(186).chr(189) => 'e', chr(225).chr(187).chr(132) => 'E', chr(225).chr(187).chr(133) => 'e', chr(225).chr(187).chr(150) => 'O', chr(225).chr(187).chr(151) => 'o', chr(225).chr(187).chr(160) => 'O', chr(225).chr(187).chr(161) => 'o', chr(225).chr(187).chr(174) => 'U', chr(225).chr(187).chr(175) => 'u', chr(225).chr(187).chr(184) => 'Y', chr(225).chr(187).chr(185) => 'y', // acute accent chr(225).chr(186).chr(164) => 'A', chr(225).chr(186).chr(165) => 'a', chr(225).chr(186).chr(174) => 'A', chr(225).chr(186).chr(175) => 'a', chr(225).chr(186).chr(190) => 'E', chr(225).chr(186).chr(191) => 'e', chr(225).chr(187).chr(144) => 'O', chr(225).chr(187).chr(145) => 'o', chr(225).chr(187).chr(154) => 'O', chr(225).chr(187).chr(155) => 'o', chr(225).chr(187).chr(168) => 'U', chr(225).chr(187).chr(169) => 'u', // dot below chr(225).chr(186).chr(160) => 'A', chr(225).chr(186).chr(161) => 'a', chr(225).chr(186).chr(172) => 'A', chr(225).chr(186).chr(173) => 'a', chr(225).chr(186).chr(182) => 'A', chr(225).chr(186).chr(183) => 'a', chr(225).chr(186).chr(184) => 'E', chr(225).chr(186).chr(185) => 'e', chr(225).chr(187).chr(134) => 'E', chr(225).chr(187).chr(135) => 'e', chr(225).chr(187).chr(138) => 'I', chr(225).chr(187).chr(139) => 'i', chr(225).chr(187).chr(140) => 'O', chr(225).chr(187).chr(141) => 'o', chr(225).chr(187).chr(152) => 'O', chr(225).chr(187).chr(153) => 'o', chr(225).chr(187).chr(162) => 'O', chr(225).chr(187).chr(163) => 'o', chr(225).chr(187).chr(164) => 'U', chr(225).chr(187).chr(165) => 'u', chr(225).chr(187).chr(176) => 'U', chr(225).chr(187).chr(177) => 'u', chr(225).chr(187).chr(180) => 'Y', chr(225).chr(187).chr(181) => 'y', // Vowels with diacritic (Chinese, Hanyu Pinyin) chr(201).chr(145) => 'a', // macron chr(199).chr(149) => 'U', chr(199).chr(150) => 'u', // acute accent chr(199).chr(151) => 'U', chr(199).chr(152) => 'u', // caron chr(199).chr(141) => 'A', chr(199).chr(142) => 'a', chr(199).chr(143) => 'I', chr(199).chr(144) => 'i', chr(199).chr(145) => 'O', chr(199).chr(146) => 'o', chr(199).chr(147) => 'U', chr(199).chr(148) => 'u', chr(199).chr(153) => 'U', chr(199).chr(154) => 'u', // grave accent chr(199).chr(155) => 'U', chr(199).chr(156) => 'u', ); $string = strtr($string, $chars); } else { $chars = array(); // Assume ISO-8859-1 if not UTF-8 $chars['in'] = chr(128).chr(131).chr(138).chr(142).chr(154).chr(158) .chr(159).chr(162).chr(165).chr(181).chr(192).chr(193).chr(194) .chr(195).chr(196).chr(197).chr(199).chr(200).chr(201).chr(202) .chr(203).chr(204).chr(205).chr(206).chr(207).chr(209).chr(210) .chr(211).chr(212).chr(213).chr(214).chr(216).chr(217).chr(218) .chr(219).chr(220).chr(221).chr(224).chr(225).chr(226).chr(227) .chr(228).chr(229).chr(231).chr(232).chr(233).chr(234).chr(235) .chr(236).chr(237).chr(238).chr(239).chr(241).chr(242).chr(243) .chr(244).chr(245).chr(246).chr(248).chr(249).chr(250).chr(251) .chr(252).chr(253).chr(255); $chars['out'] = "EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy"; $string = strtr($string, $chars['in'], $chars['out']); $double_chars = array(); $double_chars['in'] = array(chr(140), chr(156), chr(198), chr(208), chr(222), chr(223), chr(230), chr(240), chr(254)); $double_chars['out'] = array('OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th'); $string = str_replace($double_chars['in'], $double_chars['out'], $string); } return $string; }
php
public static function remove_accents( $string ) { if ( !preg_match('/[\x80-\xff]/', $string) ) return $string; if (self::seems_utf8($string)) { $chars = array( // Decompositions for Latin-1 Supplement chr(194).chr(170) => 'a', chr(194).chr(186) => 'o', chr(195).chr(128) => 'A', chr(195).chr(129) => 'A', chr(195).chr(130) => 'A', chr(195).chr(131) => 'A', chr(195).chr(132) => 'A', chr(195).chr(133) => 'A', chr(195).chr(134) => 'AE',chr(195).chr(135) => 'C', chr(195).chr(136) => 'E', chr(195).chr(137) => 'E', chr(195).chr(138) => 'E', chr(195).chr(139) => 'E', chr(195).chr(140) => 'I', chr(195).chr(141) => 'I', chr(195).chr(142) => 'I', chr(195).chr(143) => 'I', chr(195).chr(144) => 'D', chr(195).chr(145) => 'N', chr(195).chr(146) => 'O', chr(195).chr(147) => 'O', chr(195).chr(148) => 'O', chr(195).chr(149) => 'O', chr(195).chr(150) => 'O', chr(195).chr(153) => 'U', chr(195).chr(154) => 'U', chr(195).chr(155) => 'U', chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y', chr(195).chr(158) => 'TH',chr(195).chr(159) => 's', chr(195).chr(160) => 'a', chr(195).chr(161) => 'a', chr(195).chr(162) => 'a', chr(195).chr(163) => 'a', chr(195).chr(164) => 'a', chr(195).chr(165) => 'a', chr(195).chr(166) => 'ae',chr(195).chr(167) => 'c', chr(195).chr(168) => 'e', chr(195).chr(169) => 'e', chr(195).chr(170) => 'e', chr(195).chr(171) => 'e', chr(195).chr(172) => 'i', chr(195).chr(173) => 'i', chr(195).chr(174) => 'i', chr(195).chr(175) => 'i', chr(195).chr(176) => 'd', chr(195).chr(177) => 'n', chr(195).chr(178) => 'o', chr(195).chr(179) => 'o', chr(195).chr(180) => 'o', chr(195).chr(181) => 'o', chr(195).chr(182) => 'o', chr(195).chr(184) => 'o', chr(195).chr(185) => 'u', chr(195).chr(186) => 'u', chr(195).chr(187) => 'u', chr(195).chr(188) => 'u', chr(195).chr(189) => 'y', chr(195).chr(190) => 'th', chr(195).chr(191) => 'y', chr(195).chr(152) => 'O', // Decompositions for Latin Extended-A chr(196).chr(128) => 'A', chr(196).chr(129) => 'a', chr(196).chr(130) => 'A', chr(196).chr(131) => 'a', chr(196).chr(132) => 'A', chr(196).chr(133) => 'a', chr(196).chr(134) => 'C', chr(196).chr(135) => 'c', chr(196).chr(136) => 'C', chr(196).chr(137) => 'c', chr(196).chr(138) => 'C', chr(196).chr(139) => 'c', chr(196).chr(140) => 'C', chr(196).chr(141) => 'c', chr(196).chr(142) => 'D', chr(196).chr(143) => 'd', chr(196).chr(144) => 'D', chr(196).chr(145) => 'd', chr(196).chr(146) => 'E', chr(196).chr(147) => 'e', chr(196).chr(148) => 'E', chr(196).chr(149) => 'e', chr(196).chr(150) => 'E', chr(196).chr(151) => 'e', chr(196).chr(152) => 'E', chr(196).chr(153) => 'e', chr(196).chr(154) => 'E', chr(196).chr(155) => 'e', chr(196).chr(156) => 'G', chr(196).chr(157) => 'g', chr(196).chr(158) => 'G', chr(196).chr(159) => 'g', chr(196).chr(160) => 'G', chr(196).chr(161) => 'g', chr(196).chr(162) => 'G', chr(196).chr(163) => 'g', chr(196).chr(164) => 'H', chr(196).chr(165) => 'h', chr(196).chr(166) => 'H', chr(196).chr(167) => 'h', chr(196).chr(168) => 'I', chr(196).chr(169) => 'i', chr(196).chr(170) => 'I', chr(196).chr(171) => 'i', chr(196).chr(172) => 'I', chr(196).chr(173) => 'i', chr(196).chr(174) => 'I', chr(196).chr(175) => 'i', chr(196).chr(176) => 'I', chr(196).chr(177) => 'i', chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij', chr(196).chr(180) => 'J', chr(196).chr(181) => 'j', chr(196).chr(182) => 'K', chr(196).chr(183) => 'k', chr(196).chr(184) => 'k', chr(196).chr(185) => 'L', chr(196).chr(186) => 'l', chr(196).chr(187) => 'L', chr(196).chr(188) => 'l', chr(196).chr(189) => 'L', chr(196).chr(190) => 'l', chr(196).chr(191) => 'L', chr(197).chr(128) => 'l', chr(197).chr(129) => 'L', chr(197).chr(130) => 'l', chr(197).chr(131) => 'N', chr(197).chr(132) => 'n', chr(197).chr(133) => 'N', chr(197).chr(134) => 'n', chr(197).chr(135) => 'N', chr(197).chr(136) => 'n', chr(197).chr(137) => 'N', chr(197).chr(138) => 'n', chr(197).chr(139) => 'N', chr(197).chr(140) => 'O', chr(197).chr(141) => 'o', chr(197).chr(142) => 'O', chr(197).chr(143) => 'o', chr(197).chr(144) => 'O', chr(197).chr(145) => 'o', chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe', chr(197).chr(148) => 'R',chr(197).chr(149) => 'r', chr(197).chr(150) => 'R',chr(197).chr(151) => 'r', chr(197).chr(152) => 'R',chr(197).chr(153) => 'r', chr(197).chr(154) => 'S',chr(197).chr(155) => 's', chr(197).chr(156) => 'S',chr(197).chr(157) => 's', chr(197).chr(158) => 'S',chr(197).chr(159) => 's', chr(197).chr(160) => 'S', chr(197).chr(161) => 's', chr(197).chr(162) => 'T', chr(197).chr(163) => 't', chr(197).chr(164) => 'T', chr(197).chr(165) => 't', chr(197).chr(166) => 'T', chr(197).chr(167) => 't', chr(197).chr(168) => 'U', chr(197).chr(169) => 'u', chr(197).chr(170) => 'U', chr(197).chr(171) => 'u', chr(197).chr(172) => 'U', chr(197).chr(173) => 'u', chr(197).chr(174) => 'U', chr(197).chr(175) => 'u', chr(197).chr(176) => 'U', chr(197).chr(177) => 'u', chr(197).chr(178) => 'U', chr(197).chr(179) => 'u', chr(197).chr(180) => 'W', chr(197).chr(181) => 'w', chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y', chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z', chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z', chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z', chr(197).chr(190) => 'z', chr(197).chr(191) => 's', // Decompositions for Latin Extended-B chr(200).chr(152) => 'S', chr(200).chr(153) => 's', chr(200).chr(154) => 'T', chr(200).chr(155) => 't', // Euro Sign chr(226).chr(130).chr(172) => 'E', // GBP (Pound) Sign chr(194).chr(163) => '', // Vowels with diacritic (Vietnamese) // unmarked chr(198).chr(160) => 'O', chr(198).chr(161) => 'o', chr(198).chr(175) => 'U', chr(198).chr(176) => 'u', // grave accent chr(225).chr(186).chr(166) => 'A', chr(225).chr(186).chr(167) => 'a', chr(225).chr(186).chr(176) => 'A', chr(225).chr(186).chr(177) => 'a', chr(225).chr(187).chr(128) => 'E', chr(225).chr(187).chr(129) => 'e', chr(225).chr(187).chr(146) => 'O', chr(225).chr(187).chr(147) => 'o', chr(225).chr(187).chr(156) => 'O', chr(225).chr(187).chr(157) => 'o', chr(225).chr(187).chr(170) => 'U', chr(225).chr(187).chr(171) => 'u', chr(225).chr(187).chr(178) => 'Y', chr(225).chr(187).chr(179) => 'y', // hook chr(225).chr(186).chr(162) => 'A', chr(225).chr(186).chr(163) => 'a', chr(225).chr(186).chr(168) => 'A', chr(225).chr(186).chr(169) => 'a', chr(225).chr(186).chr(178) => 'A', chr(225).chr(186).chr(179) => 'a', chr(225).chr(186).chr(186) => 'E', chr(225).chr(186).chr(187) => 'e', chr(225).chr(187).chr(130) => 'E', chr(225).chr(187).chr(131) => 'e', chr(225).chr(187).chr(136) => 'I', chr(225).chr(187).chr(137) => 'i', chr(225).chr(187).chr(142) => 'O', chr(225).chr(187).chr(143) => 'o', chr(225).chr(187).chr(148) => 'O', chr(225).chr(187).chr(149) => 'o', chr(225).chr(187).chr(158) => 'O', chr(225).chr(187).chr(159) => 'o', chr(225).chr(187).chr(166) => 'U', chr(225).chr(187).chr(167) => 'u', chr(225).chr(187).chr(172) => 'U', chr(225).chr(187).chr(173) => 'u', chr(225).chr(187).chr(182) => 'Y', chr(225).chr(187).chr(183) => 'y', // tilde chr(225).chr(186).chr(170) => 'A', chr(225).chr(186).chr(171) => 'a', chr(225).chr(186).chr(180) => 'A', chr(225).chr(186).chr(181) => 'a', chr(225).chr(186).chr(188) => 'E', chr(225).chr(186).chr(189) => 'e', chr(225).chr(187).chr(132) => 'E', chr(225).chr(187).chr(133) => 'e', chr(225).chr(187).chr(150) => 'O', chr(225).chr(187).chr(151) => 'o', chr(225).chr(187).chr(160) => 'O', chr(225).chr(187).chr(161) => 'o', chr(225).chr(187).chr(174) => 'U', chr(225).chr(187).chr(175) => 'u', chr(225).chr(187).chr(184) => 'Y', chr(225).chr(187).chr(185) => 'y', // acute accent chr(225).chr(186).chr(164) => 'A', chr(225).chr(186).chr(165) => 'a', chr(225).chr(186).chr(174) => 'A', chr(225).chr(186).chr(175) => 'a', chr(225).chr(186).chr(190) => 'E', chr(225).chr(186).chr(191) => 'e', chr(225).chr(187).chr(144) => 'O', chr(225).chr(187).chr(145) => 'o', chr(225).chr(187).chr(154) => 'O', chr(225).chr(187).chr(155) => 'o', chr(225).chr(187).chr(168) => 'U', chr(225).chr(187).chr(169) => 'u', // dot below chr(225).chr(186).chr(160) => 'A', chr(225).chr(186).chr(161) => 'a', chr(225).chr(186).chr(172) => 'A', chr(225).chr(186).chr(173) => 'a', chr(225).chr(186).chr(182) => 'A', chr(225).chr(186).chr(183) => 'a', chr(225).chr(186).chr(184) => 'E', chr(225).chr(186).chr(185) => 'e', chr(225).chr(187).chr(134) => 'E', chr(225).chr(187).chr(135) => 'e', chr(225).chr(187).chr(138) => 'I', chr(225).chr(187).chr(139) => 'i', chr(225).chr(187).chr(140) => 'O', chr(225).chr(187).chr(141) => 'o', chr(225).chr(187).chr(152) => 'O', chr(225).chr(187).chr(153) => 'o', chr(225).chr(187).chr(162) => 'O', chr(225).chr(187).chr(163) => 'o', chr(225).chr(187).chr(164) => 'U', chr(225).chr(187).chr(165) => 'u', chr(225).chr(187).chr(176) => 'U', chr(225).chr(187).chr(177) => 'u', chr(225).chr(187).chr(180) => 'Y', chr(225).chr(187).chr(181) => 'y', // Vowels with diacritic (Chinese, Hanyu Pinyin) chr(201).chr(145) => 'a', // macron chr(199).chr(149) => 'U', chr(199).chr(150) => 'u', // acute accent chr(199).chr(151) => 'U', chr(199).chr(152) => 'u', // caron chr(199).chr(141) => 'A', chr(199).chr(142) => 'a', chr(199).chr(143) => 'I', chr(199).chr(144) => 'i', chr(199).chr(145) => 'O', chr(199).chr(146) => 'o', chr(199).chr(147) => 'U', chr(199).chr(148) => 'u', chr(199).chr(153) => 'U', chr(199).chr(154) => 'u', // grave accent chr(199).chr(155) => 'U', chr(199).chr(156) => 'u', ); $string = strtr($string, $chars); } else { $chars = array(); // Assume ISO-8859-1 if not UTF-8 $chars['in'] = chr(128).chr(131).chr(138).chr(142).chr(154).chr(158) .chr(159).chr(162).chr(165).chr(181).chr(192).chr(193).chr(194) .chr(195).chr(196).chr(197).chr(199).chr(200).chr(201).chr(202) .chr(203).chr(204).chr(205).chr(206).chr(207).chr(209).chr(210) .chr(211).chr(212).chr(213).chr(214).chr(216).chr(217).chr(218) .chr(219).chr(220).chr(221).chr(224).chr(225).chr(226).chr(227) .chr(228).chr(229).chr(231).chr(232).chr(233).chr(234).chr(235) .chr(236).chr(237).chr(238).chr(239).chr(241).chr(242).chr(243) .chr(244).chr(245).chr(246).chr(248).chr(249).chr(250).chr(251) .chr(252).chr(253).chr(255); $chars['out'] = "EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy"; $string = strtr($string, $chars['in'], $chars['out']); $double_chars = array(); $double_chars['in'] = array(chr(140), chr(156), chr(198), chr(208), chr(222), chr(223), chr(230), chr(240), chr(254)); $double_chars['out'] = array('OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th'); $string = str_replace($double_chars['in'], $double_chars['out'], $string); } return $string; }
[ "public", "static", "function", "remove_accents", "(", "$", "string", ")", "{", "if", "(", "!", "preg_match", "(", "'/[\\x80-\\xff]/'", ",", "$", "string", ")", ")", "return", "$", "string", ";", "if", "(", "self", "::", "seems_utf8", "(", "$", "string", ")", ")", "{", "$", "chars", "=", "array", "(", "// Decompositions for Latin-1 Supplement", "chr", "(", "194", ")", ".", "chr", "(", "170", ")", "=>", "'a'", ",", "chr", "(", "194", ")", ".", "chr", "(", "186", ")", "=>", "'o'", ",", "chr", "(", "195", ")", ".", "chr", "(", "128", ")", "=>", "'A'", ",", "chr", "(", "195", ")", ".", "chr", "(", "129", ")", "=>", "'A'", ",", "chr", "(", "195", ")", ".", "chr", "(", "130", ")", "=>", "'A'", ",", "chr", "(", "195", ")", ".", "chr", "(", "131", ")", "=>", "'A'", ",", "chr", "(", "195", ")", ".", "chr", "(", "132", ")", "=>", "'A'", ",", "chr", "(", "195", ")", ".", "chr", "(", "133", ")", "=>", "'A'", ",", "chr", "(", "195", ")", ".", "chr", "(", "134", ")", "=>", "'AE'", ",", "chr", "(", "195", ")", ".", "chr", "(", "135", ")", "=>", "'C'", ",", "chr", "(", "195", ")", ".", "chr", "(", "136", ")", "=>", "'E'", ",", "chr", "(", "195", ")", ".", "chr", "(", "137", ")", "=>", "'E'", ",", "chr", "(", "195", ")", ".", "chr", "(", "138", ")", "=>", "'E'", ",", "chr", "(", "195", ")", ".", "chr", "(", "139", ")", "=>", "'E'", ",", "chr", "(", "195", ")", ".", "chr", "(", "140", ")", "=>", "'I'", ",", "chr", "(", "195", ")", ".", "chr", "(", "141", ")", "=>", "'I'", ",", "chr", "(", "195", ")", ".", "chr", "(", "142", ")", "=>", "'I'", ",", "chr", "(", "195", ")", ".", "chr", "(", "143", ")", "=>", "'I'", ",", "chr", "(", "195", ")", ".", "chr", "(", "144", ")", "=>", "'D'", ",", "chr", "(", "195", ")", ".", "chr", "(", "145", ")", "=>", "'N'", ",", "chr", "(", "195", ")", ".", "chr", "(", "146", ")", "=>", "'O'", ",", "chr", "(", "195", ")", ".", "chr", "(", "147", ")", "=>", "'O'", ",", "chr", "(", "195", ")", ".", "chr", "(", "148", ")", "=>", "'O'", ",", "chr", "(", "195", ")", ".", "chr", "(", "149", ")", "=>", "'O'", ",", "chr", "(", "195", ")", ".", "chr", "(", "150", ")", "=>", "'O'", ",", "chr", "(", "195", ")", ".", "chr", "(", "153", ")", "=>", "'U'", ",", "chr", "(", "195", ")", ".", "chr", "(", "154", ")", "=>", "'U'", ",", "chr", "(", "195", ")", ".", "chr", "(", "155", ")", "=>", "'U'", ",", "chr", "(", "195", ")", ".", "chr", "(", "156", ")", "=>", "'U'", ",", "chr", "(", "195", ")", ".", "chr", "(", "157", ")", "=>", "'Y'", ",", "chr", "(", "195", ")", ".", "chr", "(", "158", ")", "=>", "'TH'", ",", "chr", "(", "195", ")", ".", "chr", "(", "159", ")", "=>", "'s'", ",", "chr", "(", "195", ")", ".", "chr", "(", "160", ")", "=>", "'a'", ",", "chr", "(", "195", ")", ".", "chr", "(", "161", ")", "=>", "'a'", ",", "chr", "(", "195", ")", ".", "chr", "(", "162", ")", "=>", "'a'", ",", "chr", "(", "195", ")", ".", "chr", "(", "163", ")", "=>", "'a'", ",", "chr", "(", "195", ")", ".", "chr", "(", "164", ")", "=>", "'a'", ",", "chr", "(", "195", ")", ".", "chr", "(", "165", ")", "=>", "'a'", ",", "chr", "(", "195", ")", ".", "chr", "(", "166", ")", "=>", "'ae'", ",", "chr", "(", "195", ")", ".", "chr", "(", "167", ")", "=>", "'c'", ",", "chr", "(", "195", ")", ".", "chr", "(", "168", ")", "=>", "'e'", ",", "chr", "(", "195", ")", ".", "chr", "(", "169", ")", "=>", "'e'", ",", "chr", "(", "195", ")", ".", "chr", "(", "170", ")", "=>", "'e'", ",", "chr", "(", "195", ")", ".", "chr", "(", "171", ")", "=>", "'e'", ",", "chr", "(", "195", ")", ".", "chr", "(", "172", ")", "=>", "'i'", ",", "chr", "(", "195", ")", ".", "chr", "(", "173", ")", "=>", "'i'", ",", "chr", "(", "195", ")", ".", "chr", "(", "174", ")", "=>", "'i'", ",", "chr", "(", "195", ")", ".", "chr", "(", "175", ")", "=>", "'i'", ",", "chr", "(", "195", ")", ".", "chr", "(", "176", ")", "=>", "'d'", ",", "chr", "(", "195", ")", ".", "chr", "(", "177", ")", "=>", "'n'", ",", "chr", "(", "195", ")", ".", "chr", "(", "178", ")", "=>", "'o'", ",", "chr", "(", "195", ")", ".", "chr", "(", "179", ")", "=>", "'o'", ",", "chr", "(", "195", ")", ".", "chr", "(", "180", ")", "=>", "'o'", ",", "chr", "(", "195", ")", ".", "chr", "(", "181", ")", "=>", "'o'", ",", "chr", "(", "195", ")", ".", "chr", "(", "182", ")", "=>", "'o'", ",", "chr", "(", "195", ")", ".", "chr", "(", "184", ")", "=>", "'o'", ",", "chr", "(", "195", ")", ".", "chr", "(", "185", ")", "=>", "'u'", ",", "chr", "(", "195", ")", ".", "chr", "(", "186", ")", "=>", "'u'", ",", "chr", "(", "195", ")", ".", "chr", "(", "187", ")", "=>", "'u'", ",", "chr", "(", "195", ")", ".", "chr", "(", "188", ")", "=>", "'u'", ",", "chr", "(", "195", ")", ".", "chr", "(", "189", ")", "=>", "'y'", ",", "chr", "(", "195", ")", ".", "chr", "(", "190", ")", "=>", "'th'", ",", "chr", "(", "195", ")", ".", "chr", "(", "191", ")", "=>", "'y'", ",", "chr", "(", "195", ")", ".", "chr", "(", "152", ")", "=>", "'O'", ",", "// Decompositions for Latin Extended-A", "chr", "(", "196", ")", ".", "chr", "(", "128", ")", "=>", "'A'", ",", "chr", "(", "196", ")", ".", "chr", "(", "129", ")", "=>", "'a'", ",", "chr", "(", "196", ")", ".", "chr", "(", "130", ")", "=>", "'A'", ",", "chr", "(", "196", ")", ".", "chr", "(", "131", ")", "=>", "'a'", ",", "chr", "(", "196", ")", ".", "chr", "(", "132", ")", "=>", "'A'", ",", "chr", "(", "196", ")", ".", "chr", "(", "133", ")", "=>", "'a'", ",", "chr", "(", "196", ")", ".", "chr", "(", "134", ")", "=>", "'C'", ",", "chr", "(", "196", ")", ".", "chr", "(", "135", ")", "=>", "'c'", ",", "chr", "(", "196", ")", ".", "chr", "(", "136", ")", "=>", "'C'", ",", "chr", "(", "196", ")", ".", "chr", "(", "137", ")", "=>", "'c'", ",", "chr", "(", "196", ")", ".", "chr", "(", "138", ")", "=>", "'C'", ",", "chr", "(", "196", ")", ".", "chr", "(", "139", ")", "=>", "'c'", ",", "chr", "(", "196", ")", ".", "chr", "(", "140", ")", "=>", "'C'", ",", "chr", "(", "196", ")", ".", "chr", "(", "141", ")", "=>", "'c'", ",", "chr", "(", "196", ")", ".", "chr", "(", "142", ")", "=>", "'D'", ",", "chr", "(", "196", ")", ".", "chr", "(", "143", ")", "=>", "'d'", ",", "chr", "(", "196", ")", ".", "chr", "(", "144", ")", "=>", "'D'", ",", "chr", "(", "196", ")", ".", "chr", "(", "145", ")", "=>", "'d'", ",", "chr", "(", "196", ")", ".", "chr", "(", "146", ")", "=>", "'E'", ",", "chr", "(", "196", ")", ".", "chr", "(", "147", ")", "=>", "'e'", ",", "chr", "(", "196", ")", ".", "chr", "(", "148", ")", "=>", "'E'", ",", "chr", "(", "196", ")", ".", "chr", "(", "149", ")", "=>", "'e'", ",", "chr", "(", "196", ")", ".", "chr", "(", "150", ")", "=>", "'E'", ",", "chr", "(", "196", ")", ".", "chr", "(", "151", ")", "=>", "'e'", ",", "chr", "(", "196", ")", ".", "chr", "(", "152", ")", "=>", "'E'", ",", "chr", "(", "196", ")", ".", "chr", "(", "153", ")", "=>", "'e'", ",", "chr", "(", "196", ")", ".", "chr", "(", "154", ")", "=>", "'E'", ",", "chr", "(", "196", ")", ".", "chr", "(", "155", ")", "=>", "'e'", ",", "chr", "(", "196", ")", ".", "chr", "(", "156", ")", "=>", "'G'", ",", "chr", "(", "196", ")", ".", "chr", "(", "157", ")", "=>", "'g'", ",", "chr", "(", "196", ")", ".", "chr", "(", "158", ")", "=>", "'G'", ",", "chr", "(", "196", ")", ".", "chr", "(", "159", ")", "=>", "'g'", ",", "chr", "(", "196", ")", ".", "chr", "(", "160", ")", "=>", "'G'", ",", "chr", "(", "196", ")", ".", "chr", "(", "161", ")", "=>", "'g'", ",", "chr", "(", "196", ")", ".", "chr", "(", "162", ")", "=>", "'G'", ",", "chr", "(", "196", ")", ".", "chr", "(", "163", ")", "=>", "'g'", ",", "chr", "(", "196", ")", ".", "chr", "(", "164", ")", "=>", "'H'", ",", "chr", "(", "196", ")", ".", "chr", "(", "165", ")", "=>", "'h'", ",", "chr", "(", "196", ")", ".", "chr", "(", "166", ")", "=>", "'H'", ",", "chr", "(", "196", ")", ".", "chr", "(", "167", ")", "=>", "'h'", ",", "chr", "(", "196", ")", ".", "chr", "(", "168", ")", "=>", "'I'", ",", "chr", "(", "196", ")", ".", "chr", "(", "169", ")", "=>", "'i'", ",", "chr", "(", "196", ")", ".", "chr", "(", "170", ")", "=>", "'I'", ",", "chr", "(", "196", ")", ".", "chr", "(", "171", ")", "=>", "'i'", ",", "chr", "(", "196", ")", ".", "chr", "(", "172", ")", "=>", "'I'", ",", "chr", "(", "196", ")", ".", "chr", "(", "173", ")", "=>", "'i'", ",", "chr", "(", "196", ")", ".", "chr", "(", "174", ")", "=>", "'I'", ",", "chr", "(", "196", ")", ".", "chr", "(", "175", ")", "=>", "'i'", ",", "chr", "(", "196", ")", ".", "chr", "(", "176", ")", "=>", "'I'", ",", "chr", "(", "196", ")", ".", "chr", "(", "177", ")", "=>", "'i'", ",", "chr", "(", "196", ")", ".", "chr", "(", "178", ")", "=>", "'IJ'", ",", "chr", "(", "196", ")", ".", "chr", "(", "179", ")", "=>", "'ij'", ",", "chr", "(", "196", ")", ".", "chr", "(", "180", ")", "=>", "'J'", ",", "chr", "(", "196", ")", ".", "chr", "(", "181", ")", "=>", "'j'", ",", "chr", "(", "196", ")", ".", "chr", "(", "182", ")", "=>", "'K'", ",", "chr", "(", "196", ")", ".", "chr", "(", "183", ")", "=>", "'k'", ",", "chr", "(", "196", ")", ".", "chr", "(", "184", ")", "=>", "'k'", ",", "chr", "(", "196", ")", ".", "chr", "(", "185", ")", "=>", "'L'", ",", "chr", "(", "196", ")", ".", "chr", "(", "186", ")", "=>", "'l'", ",", "chr", "(", "196", ")", ".", "chr", "(", "187", ")", "=>", "'L'", ",", "chr", "(", "196", ")", ".", "chr", "(", "188", ")", "=>", "'l'", ",", "chr", "(", "196", ")", ".", "chr", "(", "189", ")", "=>", "'L'", ",", "chr", "(", "196", ")", ".", "chr", "(", "190", ")", "=>", "'l'", ",", "chr", "(", "196", ")", ".", "chr", "(", "191", ")", "=>", "'L'", ",", "chr", "(", "197", ")", ".", "chr", "(", "128", ")", "=>", "'l'", ",", "chr", "(", "197", ")", ".", "chr", "(", "129", ")", "=>", "'L'", ",", "chr", "(", "197", ")", ".", "chr", "(", "130", ")", "=>", "'l'", ",", "chr", "(", "197", ")", ".", "chr", "(", "131", ")", "=>", "'N'", ",", "chr", "(", "197", ")", ".", "chr", "(", "132", ")", "=>", "'n'", ",", "chr", "(", "197", ")", ".", "chr", "(", "133", ")", "=>", "'N'", ",", "chr", "(", "197", ")", ".", "chr", "(", "134", ")", "=>", "'n'", ",", "chr", "(", "197", ")", ".", "chr", "(", "135", ")", "=>", "'N'", ",", "chr", "(", "197", ")", ".", "chr", "(", "136", ")", "=>", "'n'", ",", "chr", "(", "197", ")", ".", "chr", "(", "137", ")", "=>", "'N'", ",", "chr", "(", "197", ")", ".", "chr", "(", "138", ")", "=>", "'n'", ",", "chr", "(", "197", ")", ".", "chr", "(", "139", ")", "=>", "'N'", ",", "chr", "(", "197", ")", ".", "chr", "(", "140", ")", "=>", "'O'", ",", "chr", "(", "197", ")", ".", "chr", "(", "141", ")", "=>", "'o'", ",", "chr", "(", "197", ")", ".", "chr", "(", "142", ")", "=>", "'O'", ",", "chr", "(", "197", ")", ".", "chr", "(", "143", ")", "=>", "'o'", ",", "chr", "(", "197", ")", ".", "chr", "(", "144", ")", "=>", "'O'", ",", "chr", "(", "197", ")", ".", "chr", "(", "145", ")", "=>", "'o'", ",", "chr", "(", "197", ")", ".", "chr", "(", "146", ")", "=>", "'OE'", ",", "chr", "(", "197", ")", ".", "chr", "(", "147", ")", "=>", "'oe'", ",", "chr", "(", "197", ")", ".", "chr", "(", "148", ")", "=>", "'R'", ",", "chr", "(", "197", ")", ".", "chr", "(", "149", ")", "=>", "'r'", ",", "chr", "(", "197", ")", ".", "chr", "(", "150", ")", "=>", "'R'", ",", "chr", "(", "197", ")", ".", "chr", "(", "151", ")", "=>", "'r'", ",", "chr", "(", "197", ")", ".", "chr", "(", "152", ")", "=>", "'R'", ",", "chr", "(", "197", ")", ".", "chr", "(", "153", ")", "=>", "'r'", ",", "chr", "(", "197", ")", ".", "chr", "(", "154", ")", "=>", "'S'", ",", "chr", "(", "197", ")", ".", "chr", "(", "155", ")", "=>", "'s'", ",", "chr", "(", "197", ")", ".", "chr", "(", "156", ")", "=>", "'S'", ",", "chr", "(", "197", ")", ".", "chr", "(", "157", ")", "=>", "'s'", ",", "chr", "(", "197", ")", ".", "chr", "(", "158", ")", "=>", "'S'", ",", "chr", "(", "197", ")", ".", "chr", "(", "159", ")", "=>", "'s'", ",", "chr", "(", "197", ")", ".", "chr", "(", "160", ")", "=>", "'S'", ",", "chr", "(", "197", ")", ".", "chr", "(", "161", ")", "=>", "'s'", ",", "chr", "(", "197", ")", ".", "chr", "(", "162", ")", "=>", "'T'", ",", "chr", "(", "197", ")", ".", "chr", "(", "163", ")", "=>", "'t'", ",", "chr", "(", "197", ")", ".", "chr", "(", "164", ")", "=>", "'T'", ",", "chr", "(", "197", ")", ".", "chr", "(", "165", ")", "=>", "'t'", ",", "chr", "(", "197", ")", ".", "chr", "(", "166", ")", "=>", "'T'", ",", "chr", "(", "197", ")", ".", "chr", "(", "167", ")", "=>", "'t'", ",", "chr", "(", "197", ")", ".", "chr", "(", "168", ")", "=>", "'U'", ",", "chr", "(", "197", ")", ".", "chr", "(", "169", ")", "=>", "'u'", ",", "chr", "(", "197", ")", ".", "chr", "(", "170", ")", "=>", "'U'", ",", "chr", "(", "197", ")", ".", "chr", "(", "171", ")", "=>", "'u'", ",", "chr", "(", "197", ")", ".", "chr", "(", "172", ")", "=>", "'U'", ",", "chr", "(", "197", ")", ".", "chr", "(", "173", ")", "=>", "'u'", ",", "chr", "(", "197", ")", ".", "chr", "(", "174", ")", "=>", "'U'", ",", "chr", "(", "197", ")", ".", "chr", "(", "175", ")", "=>", "'u'", ",", "chr", "(", "197", ")", ".", "chr", "(", "176", ")", "=>", "'U'", ",", "chr", "(", "197", ")", ".", "chr", "(", "177", ")", "=>", "'u'", ",", "chr", "(", "197", ")", ".", "chr", "(", "178", ")", "=>", "'U'", ",", "chr", "(", "197", ")", ".", "chr", "(", "179", ")", "=>", "'u'", ",", "chr", "(", "197", ")", ".", "chr", "(", "180", ")", "=>", "'W'", ",", "chr", "(", "197", ")", ".", "chr", "(", "181", ")", "=>", "'w'", ",", "chr", "(", "197", ")", ".", "chr", "(", "182", ")", "=>", "'Y'", ",", "chr", "(", "197", ")", ".", "chr", "(", "183", ")", "=>", "'y'", ",", "chr", "(", "197", ")", ".", "chr", "(", "184", ")", "=>", "'Y'", ",", "chr", "(", "197", ")", ".", "chr", "(", "185", ")", "=>", "'Z'", ",", "chr", "(", "197", ")", ".", "chr", "(", "186", ")", "=>", "'z'", ",", "chr", "(", "197", ")", ".", "chr", "(", "187", ")", "=>", "'Z'", ",", "chr", "(", "197", ")", ".", "chr", "(", "188", ")", "=>", "'z'", ",", "chr", "(", "197", ")", ".", "chr", "(", "189", ")", "=>", "'Z'", ",", "chr", "(", "197", ")", ".", "chr", "(", "190", ")", "=>", "'z'", ",", "chr", "(", "197", ")", ".", "chr", "(", "191", ")", "=>", "'s'", ",", "// Decompositions for Latin Extended-B", "chr", "(", "200", ")", ".", "chr", "(", "152", ")", "=>", "'S'", ",", "chr", "(", "200", ")", ".", "chr", "(", "153", ")", "=>", "'s'", ",", "chr", "(", "200", ")", ".", "chr", "(", "154", ")", "=>", "'T'", ",", "chr", "(", "200", ")", ".", "chr", "(", "155", ")", "=>", "'t'", ",", "// Euro Sign", "chr", "(", "226", ")", ".", "chr", "(", "130", ")", ".", "chr", "(", "172", ")", "=>", "'E'", ",", "// GBP (Pound) Sign", "chr", "(", "194", ")", ".", "chr", "(", "163", ")", "=>", "''", ",", "// Vowels with diacritic (Vietnamese)", "// unmarked", "chr", "(", "198", ")", ".", "chr", "(", "160", ")", "=>", "'O'", ",", "chr", "(", "198", ")", ".", "chr", "(", "161", ")", "=>", "'o'", ",", "chr", "(", "198", ")", ".", "chr", "(", "175", ")", "=>", "'U'", ",", "chr", "(", "198", ")", ".", "chr", "(", "176", ")", "=>", "'u'", ",", "// grave accent", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "166", ")", "=>", "'A'", ",", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "167", ")", "=>", "'a'", ",", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "176", ")", "=>", "'A'", ",", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "177", ")", "=>", "'a'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "128", ")", "=>", "'E'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "129", ")", "=>", "'e'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "146", ")", "=>", "'O'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "147", ")", "=>", "'o'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "156", ")", "=>", "'O'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "157", ")", "=>", "'o'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "170", ")", "=>", "'U'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "171", ")", "=>", "'u'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "178", ")", "=>", "'Y'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "179", ")", "=>", "'y'", ",", "// hook", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "162", ")", "=>", "'A'", ",", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "163", ")", "=>", "'a'", ",", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "168", ")", "=>", "'A'", ",", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "169", ")", "=>", "'a'", ",", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "178", ")", "=>", "'A'", ",", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "179", ")", "=>", "'a'", ",", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "186", ")", "=>", "'E'", ",", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "187", ")", "=>", "'e'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "130", ")", "=>", "'E'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "131", ")", "=>", "'e'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "136", ")", "=>", "'I'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "137", ")", "=>", "'i'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "142", ")", "=>", "'O'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "143", ")", "=>", "'o'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "148", ")", "=>", "'O'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "149", ")", "=>", "'o'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "158", ")", "=>", "'O'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "159", ")", "=>", "'o'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "166", ")", "=>", "'U'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "167", ")", "=>", "'u'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "172", ")", "=>", "'U'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "173", ")", "=>", "'u'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "182", ")", "=>", "'Y'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "183", ")", "=>", "'y'", ",", "// tilde", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "170", ")", "=>", "'A'", ",", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "171", ")", "=>", "'a'", ",", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "180", ")", "=>", "'A'", ",", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "181", ")", "=>", "'a'", ",", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "188", ")", "=>", "'E'", ",", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "189", ")", "=>", "'e'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "132", ")", "=>", "'E'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "133", ")", "=>", "'e'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "150", ")", "=>", "'O'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "151", ")", "=>", "'o'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "160", ")", "=>", "'O'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "161", ")", "=>", "'o'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "174", ")", "=>", "'U'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "175", ")", "=>", "'u'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "184", ")", "=>", "'Y'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "185", ")", "=>", "'y'", ",", "// acute accent", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "164", ")", "=>", "'A'", ",", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "165", ")", "=>", "'a'", ",", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "174", ")", "=>", "'A'", ",", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "175", ")", "=>", "'a'", ",", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "190", ")", "=>", "'E'", ",", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "191", ")", "=>", "'e'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "144", ")", "=>", "'O'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "145", ")", "=>", "'o'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "154", ")", "=>", "'O'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "155", ")", "=>", "'o'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "168", ")", "=>", "'U'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "169", ")", "=>", "'u'", ",", "// dot below", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "160", ")", "=>", "'A'", ",", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "161", ")", "=>", "'a'", ",", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "172", ")", "=>", "'A'", ",", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "173", ")", "=>", "'a'", ",", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "182", ")", "=>", "'A'", ",", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "183", ")", "=>", "'a'", ",", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "184", ")", "=>", "'E'", ",", "chr", "(", "225", ")", ".", "chr", "(", "186", ")", ".", "chr", "(", "185", ")", "=>", "'e'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "134", ")", "=>", "'E'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "135", ")", "=>", "'e'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "138", ")", "=>", "'I'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "139", ")", "=>", "'i'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "140", ")", "=>", "'O'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "141", ")", "=>", "'o'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "152", ")", "=>", "'O'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "153", ")", "=>", "'o'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "162", ")", "=>", "'O'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "163", ")", "=>", "'o'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "164", ")", "=>", "'U'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "165", ")", "=>", "'u'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "176", ")", "=>", "'U'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "177", ")", "=>", "'u'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "180", ")", "=>", "'Y'", ",", "chr", "(", "225", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "181", ")", "=>", "'y'", ",", "// Vowels with diacritic (Chinese, Hanyu Pinyin)", "chr", "(", "201", ")", ".", "chr", "(", "145", ")", "=>", "'a'", ",", "// macron", "chr", "(", "199", ")", ".", "chr", "(", "149", ")", "=>", "'U'", ",", "chr", "(", "199", ")", ".", "chr", "(", "150", ")", "=>", "'u'", ",", "// acute accent", "chr", "(", "199", ")", ".", "chr", "(", "151", ")", "=>", "'U'", ",", "chr", "(", "199", ")", ".", "chr", "(", "152", ")", "=>", "'u'", ",", "// caron", "chr", "(", "199", ")", ".", "chr", "(", "141", ")", "=>", "'A'", ",", "chr", "(", "199", ")", ".", "chr", "(", "142", ")", "=>", "'a'", ",", "chr", "(", "199", ")", ".", "chr", "(", "143", ")", "=>", "'I'", ",", "chr", "(", "199", ")", ".", "chr", "(", "144", ")", "=>", "'i'", ",", "chr", "(", "199", ")", ".", "chr", "(", "145", ")", "=>", "'O'", ",", "chr", "(", "199", ")", ".", "chr", "(", "146", ")", "=>", "'o'", ",", "chr", "(", "199", ")", ".", "chr", "(", "147", ")", "=>", "'U'", ",", "chr", "(", "199", ")", ".", "chr", "(", "148", ")", "=>", "'u'", ",", "chr", "(", "199", ")", ".", "chr", "(", "153", ")", "=>", "'U'", ",", "chr", "(", "199", ")", ".", "chr", "(", "154", ")", "=>", "'u'", ",", "// grave accent", "chr", "(", "199", ")", ".", "chr", "(", "155", ")", "=>", "'U'", ",", "chr", "(", "199", ")", ".", "chr", "(", "156", ")", "=>", "'u'", ",", ")", ";", "$", "string", "=", "strtr", "(", "$", "string", ",", "$", "chars", ")", ";", "}", "else", "{", "$", "chars", "=", "array", "(", ")", ";", "// Assume ISO-8859-1 if not UTF-8", "$", "chars", "[", "'in'", "]", "=", "chr", "(", "128", ")", ".", "chr", "(", "131", ")", ".", "chr", "(", "138", ")", ".", "chr", "(", "142", ")", ".", "chr", "(", "154", ")", ".", "chr", "(", "158", ")", ".", "chr", "(", "159", ")", ".", "chr", "(", "162", ")", ".", "chr", "(", "165", ")", ".", "chr", "(", "181", ")", ".", "chr", "(", "192", ")", ".", "chr", "(", "193", ")", ".", "chr", "(", "194", ")", ".", "chr", "(", "195", ")", ".", "chr", "(", "196", ")", ".", "chr", "(", "197", ")", ".", "chr", "(", "199", ")", ".", "chr", "(", "200", ")", ".", "chr", "(", "201", ")", ".", "chr", "(", "202", ")", ".", "chr", "(", "203", ")", ".", "chr", "(", "204", ")", ".", "chr", "(", "205", ")", ".", "chr", "(", "206", ")", ".", "chr", "(", "207", ")", ".", "chr", "(", "209", ")", ".", "chr", "(", "210", ")", ".", "chr", "(", "211", ")", ".", "chr", "(", "212", ")", ".", "chr", "(", "213", ")", ".", "chr", "(", "214", ")", ".", "chr", "(", "216", ")", ".", "chr", "(", "217", ")", ".", "chr", "(", "218", ")", ".", "chr", "(", "219", ")", ".", "chr", "(", "220", ")", ".", "chr", "(", "221", ")", ".", "chr", "(", "224", ")", ".", "chr", "(", "225", ")", ".", "chr", "(", "226", ")", ".", "chr", "(", "227", ")", ".", "chr", "(", "228", ")", ".", "chr", "(", "229", ")", ".", "chr", "(", "231", ")", ".", "chr", "(", "232", ")", ".", "chr", "(", "233", ")", ".", "chr", "(", "234", ")", ".", "chr", "(", "235", ")", ".", "chr", "(", "236", ")", ".", "chr", "(", "237", ")", ".", "chr", "(", "238", ")", ".", "chr", "(", "239", ")", ".", "chr", "(", "241", ")", ".", "chr", "(", "242", ")", ".", "chr", "(", "243", ")", ".", "chr", "(", "244", ")", ".", "chr", "(", "245", ")", ".", "chr", "(", "246", ")", ".", "chr", "(", "248", ")", ".", "chr", "(", "249", ")", ".", "chr", "(", "250", ")", ".", "chr", "(", "251", ")", ".", "chr", "(", "252", ")", ".", "chr", "(", "253", ")", ".", "chr", "(", "255", ")", ";", "$", "chars", "[", "'out'", "]", "=", "\"EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy\"", ";", "$", "string", "=", "strtr", "(", "$", "string", ",", "$", "chars", "[", "'in'", "]", ",", "$", "chars", "[", "'out'", "]", ")", ";", "$", "double_chars", "=", "array", "(", ")", ";", "$", "double_chars", "[", "'in'", "]", "=", "array", "(", "chr", "(", "140", ")", ",", "chr", "(", "156", ")", ",", "chr", "(", "198", ")", ",", "chr", "(", "208", ")", ",", "chr", "(", "222", ")", ",", "chr", "(", "223", ")", ",", "chr", "(", "230", ")", ",", "chr", "(", "240", ")", ",", "chr", "(", "254", ")", ")", ";", "$", "double_chars", "[", "'out'", "]", "=", "array", "(", "'OE'", ",", "'oe'", ",", "'AE'", ",", "'DH'", ",", "'TH'", ",", "'ss'", ",", "'ae'", ",", "'dh'", ",", "'th'", ")", ";", "$", "string", "=", "str_replace", "(", "$", "double_chars", "[", "'in'", "]", ",", "$", "double_chars", "[", "'out'", "]", ",", "$", "string", ")", ";", "}", "return", "$", "string", ";", "}" ]
Converts all accent characters to ASCII characters. (Wordpress function) If there are no accent characters, then the string given is just returned. @param string $string Text that might have accent characters @return string Filtered string with replaced "nice" characters.
[ "Converts", "all", "accent", "characters", "to", "ASCII", "characters", ".", "(", "Wordpress", "function", ")" ]
train
https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Helpers/StringHelper.php#L70-L272
congraphcms/core
Helpers/StringHelper.php
StringHelper.seems_utf8
protected static function seems_utf8($str) { mbstring_binary_safe_encoding(); $length = strlen($str); reset_mbstring_encoding(); for ($i = 0; $i < $length; $i++) { $c = ord($str[$i]); if ($c < 0x80) $n = 0; // 0bbbbbbb elseif (($c & 0xE0) == 0xC0) $n = 1; // 110bbbbb elseif (($c & 0xF0) == 0xE0) $n = 2; // 1110bbbb elseif (($c & 0xF8) == 0xF0) $n = 3; // 11110bbb elseif (($c & 0xFC) == 0xF8) $n = 4; // 111110bb elseif (($c & 0xFE) == 0xFC) $n = 5; // 1111110b else return false; // Does not match any model for ($j = 0; $j < $n; $j++) { // n bytes matching 10bbbbbb follow ? if ((++$i == $length) || ((ord($str[$i]) & 0xC0) != 0x80)) return false; } } return true; }
php
protected static function seems_utf8($str) { mbstring_binary_safe_encoding(); $length = strlen($str); reset_mbstring_encoding(); for ($i = 0; $i < $length; $i++) { $c = ord($str[$i]); if ($c < 0x80) $n = 0; // 0bbbbbbb elseif (($c & 0xE0) == 0xC0) $n = 1; // 110bbbbb elseif (($c & 0xF0) == 0xE0) $n = 2; // 1110bbbb elseif (($c & 0xF8) == 0xF0) $n = 3; // 11110bbb elseif (($c & 0xFC) == 0xF8) $n = 4; // 111110bb elseif (($c & 0xFE) == 0xFC) $n = 5; // 1111110b else return false; // Does not match any model for ($j = 0; $j < $n; $j++) { // n bytes matching 10bbbbbb follow ? if ((++$i == $length) || ((ord($str[$i]) & 0xC0) != 0x80)) return false; } } return true; }
[ "protected", "static", "function", "seems_utf8", "(", "$", "str", ")", "{", "mbstring_binary_safe_encoding", "(", ")", ";", "$", "length", "=", "strlen", "(", "$", "str", ")", ";", "reset_mbstring_encoding", "(", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "length", ";", "$", "i", "++", ")", "{", "$", "c", "=", "ord", "(", "$", "str", "[", "$", "i", "]", ")", ";", "if", "(", "$", "c", "<", "0x80", ")", "$", "n", "=", "0", ";", "// 0bbbbbbb", "elseif", "(", "(", "$", "c", "&", "0xE0", ")", "==", "0xC0", ")", "$", "n", "=", "1", ";", "// 110bbbbb", "elseif", "(", "(", "$", "c", "&", "0xF0", ")", "==", "0xE0", ")", "$", "n", "=", "2", ";", "// 1110bbbb", "elseif", "(", "(", "$", "c", "&", "0xF8", ")", "==", "0xF0", ")", "$", "n", "=", "3", ";", "// 11110bbb", "elseif", "(", "(", "$", "c", "&", "0xFC", ")", "==", "0xF8", ")", "$", "n", "=", "4", ";", "// 111110bb", "elseif", "(", "(", "$", "c", "&", "0xFE", ")", "==", "0xFC", ")", "$", "n", "=", "5", ";", "// 1111110b", "else", "return", "false", ";", "// Does not match any model", "for", "(", "$", "j", "=", "0", ";", "$", "j", "<", "$", "n", ";", "$", "j", "++", ")", "{", "// n bytes matching 10bbbbbb follow ?", "if", "(", "(", "++", "$", "i", "==", "$", "length", ")", "||", "(", "(", "ord", "(", "$", "str", "[", "$", "i", "]", ")", "&", "0xC0", ")", "!=", "0x80", ")", ")", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Checks to see if a string is utf8 encoded. NOTE: This function checks for 5-Byte sequences, UTF8 has Bytes Sequences with a maximum length of 4. @author bmorel at ssi dot fr (modified) @since 1.2.1 @param string $str The string to be checked @return bool True if $str fits a UTF-8 model, false otherwise.
[ "Checks", "to", "see", "if", "a", "string", "is", "utf8", "encoded", "." ]
train
https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Helpers/StringHelper.php#L286-L306
WellCommerce/CategoryBundle
Form/Admin/CategoryFormBuilder.php
CategoryFormBuilder.buildForm
public function buildForm(FormInterface $form) { $requiredData = $form->addChild($this->getElement('nested_fieldset', [ 'name' => 'required_data', 'label' => $this->trans('common.fieldset.general') ])); $languageData = $requiredData->addChild($this->getElement('language_fieldset', [ 'name' => 'translations', 'label' => $this->trans('common.fieldset.translations'), 'transformer' => $this->getRepositoryTransformer('translation', $this->get('category.repository')) ])); $name = $languageData->addChild($this->getElement('text_field', [ 'name' => 'name', 'label' => $this->trans('common.label.name'), 'rules' => [ $this->getRule('required') ] ])); $languageData->addChild($this->getElement('slug_field', [ 'name' => 'slug', 'label' => $this->trans('category.label.slug'), 'name_field' => $name, 'generate_route' => 'admin.routing.generate', 'translatable_id' => $this->getRequestHelper()->getAttributesBagParam('id'), 'rules' => [ $this->getRule('required') ] ])); $requiredData->addChild($this->getElement('checkbox', [ 'name' => 'enabled', 'label' => $this->trans('category.label.enabled'), 'comment' => $this->trans('category.comment.enabled'), ])); $requiredData->addChild($this->getElement('text_field', [ 'name' => 'hierarchy', 'label' => $this->trans('common.label.hierarchy'), 'rules' => [ $this->getRule('required') ], ])); $requiredData->addChild($this->getElement('text_field', [ 'name' => 'symbol', 'label' => $this->trans('common.label.symbol'), ])); $requiredData->addChild($this->getElement('tree', [ 'name' => 'parent', 'label' => $this->trans('category.label.parent'), 'choosable' => true, 'selectable' => false, 'sortable' => false, 'clickable' => false, 'items' => $this->get('category.dataset.admin')->getResult('flat_tree'), 'restrict' => $this->getRequestHelper()->getAttributesBagParam('id'), 'transformer' => $this->getRepositoryTransformer('entity', $this->get('category.repository')) ])); $descriptionData = $form->addChild($this->getElement('nested_fieldset', [ 'name' => 'description_data', 'label' => $this->trans('category.form.fieldset.description') ])); $languageData = $descriptionData->addChild($this->getElement('language_fieldset', [ 'name' => 'translations', 'label' => $this->trans('common.fieldset.translations'), 'transformer' => $this->getRepositoryTransformer('translation', $this->get('category.repository')) ])); $languageData->addChild($this->getElement('rich_text_editor', [ 'name' => 'shortDescription', 'label' => $this->trans('common.label.short_description') ])); $languageData->addChild($this->getElement('rich_text_editor', [ 'name' => 'description', 'label' => $this->trans('common.label.description'), ])); $this->addMetadataFieldset($form, $this->get('category.repository')); $this->addShopsFieldset($form); $form->addFilter($this->getFilter('trim')); $form->addFilter($this->getFilter('secure')); }
php
public function buildForm(FormInterface $form) { $requiredData = $form->addChild($this->getElement('nested_fieldset', [ 'name' => 'required_data', 'label' => $this->trans('common.fieldset.general') ])); $languageData = $requiredData->addChild($this->getElement('language_fieldset', [ 'name' => 'translations', 'label' => $this->trans('common.fieldset.translations'), 'transformer' => $this->getRepositoryTransformer('translation', $this->get('category.repository')) ])); $name = $languageData->addChild($this->getElement('text_field', [ 'name' => 'name', 'label' => $this->trans('common.label.name'), 'rules' => [ $this->getRule('required') ] ])); $languageData->addChild($this->getElement('slug_field', [ 'name' => 'slug', 'label' => $this->trans('category.label.slug'), 'name_field' => $name, 'generate_route' => 'admin.routing.generate', 'translatable_id' => $this->getRequestHelper()->getAttributesBagParam('id'), 'rules' => [ $this->getRule('required') ] ])); $requiredData->addChild($this->getElement('checkbox', [ 'name' => 'enabled', 'label' => $this->trans('category.label.enabled'), 'comment' => $this->trans('category.comment.enabled'), ])); $requiredData->addChild($this->getElement('text_field', [ 'name' => 'hierarchy', 'label' => $this->trans('common.label.hierarchy'), 'rules' => [ $this->getRule('required') ], ])); $requiredData->addChild($this->getElement('text_field', [ 'name' => 'symbol', 'label' => $this->trans('common.label.symbol'), ])); $requiredData->addChild($this->getElement('tree', [ 'name' => 'parent', 'label' => $this->trans('category.label.parent'), 'choosable' => true, 'selectable' => false, 'sortable' => false, 'clickable' => false, 'items' => $this->get('category.dataset.admin')->getResult('flat_tree'), 'restrict' => $this->getRequestHelper()->getAttributesBagParam('id'), 'transformer' => $this->getRepositoryTransformer('entity', $this->get('category.repository')) ])); $descriptionData = $form->addChild($this->getElement('nested_fieldset', [ 'name' => 'description_data', 'label' => $this->trans('category.form.fieldset.description') ])); $languageData = $descriptionData->addChild($this->getElement('language_fieldset', [ 'name' => 'translations', 'label' => $this->trans('common.fieldset.translations'), 'transformer' => $this->getRepositoryTransformer('translation', $this->get('category.repository')) ])); $languageData->addChild($this->getElement('rich_text_editor', [ 'name' => 'shortDescription', 'label' => $this->trans('common.label.short_description') ])); $languageData->addChild($this->getElement('rich_text_editor', [ 'name' => 'description', 'label' => $this->trans('common.label.description'), ])); $this->addMetadataFieldset($form, $this->get('category.repository')); $this->addShopsFieldset($form); $form->addFilter($this->getFilter('trim')); $form->addFilter($this->getFilter('secure')); }
[ "public", "function", "buildForm", "(", "FormInterface", "$", "form", ")", "{", "$", "requiredData", "=", "$", "form", "->", "addChild", "(", "$", "this", "->", "getElement", "(", "'nested_fieldset'", ",", "[", "'name'", "=>", "'required_data'", ",", "'label'", "=>", "$", "this", "->", "trans", "(", "'common.fieldset.general'", ")", "]", ")", ")", ";", "$", "languageData", "=", "$", "requiredData", "->", "addChild", "(", "$", "this", "->", "getElement", "(", "'language_fieldset'", ",", "[", "'name'", "=>", "'translations'", ",", "'label'", "=>", "$", "this", "->", "trans", "(", "'common.fieldset.translations'", ")", ",", "'transformer'", "=>", "$", "this", "->", "getRepositoryTransformer", "(", "'translation'", ",", "$", "this", "->", "get", "(", "'category.repository'", ")", ")", "]", ")", ")", ";", "$", "name", "=", "$", "languageData", "->", "addChild", "(", "$", "this", "->", "getElement", "(", "'text_field'", ",", "[", "'name'", "=>", "'name'", ",", "'label'", "=>", "$", "this", "->", "trans", "(", "'common.label.name'", ")", ",", "'rules'", "=>", "[", "$", "this", "->", "getRule", "(", "'required'", ")", "]", "]", ")", ")", ";", "$", "languageData", "->", "addChild", "(", "$", "this", "->", "getElement", "(", "'slug_field'", ",", "[", "'name'", "=>", "'slug'", ",", "'label'", "=>", "$", "this", "->", "trans", "(", "'category.label.slug'", ")", ",", "'name_field'", "=>", "$", "name", ",", "'generate_route'", "=>", "'admin.routing.generate'", ",", "'translatable_id'", "=>", "$", "this", "->", "getRequestHelper", "(", ")", "->", "getAttributesBagParam", "(", "'id'", ")", ",", "'rules'", "=>", "[", "$", "this", "->", "getRule", "(", "'required'", ")", "]", "]", ")", ")", ";", "$", "requiredData", "->", "addChild", "(", "$", "this", "->", "getElement", "(", "'checkbox'", ",", "[", "'name'", "=>", "'enabled'", ",", "'label'", "=>", "$", "this", "->", "trans", "(", "'category.label.enabled'", ")", ",", "'comment'", "=>", "$", "this", "->", "trans", "(", "'category.comment.enabled'", ")", ",", "]", ")", ")", ";", "$", "requiredData", "->", "addChild", "(", "$", "this", "->", "getElement", "(", "'text_field'", ",", "[", "'name'", "=>", "'hierarchy'", ",", "'label'", "=>", "$", "this", "->", "trans", "(", "'common.label.hierarchy'", ")", ",", "'rules'", "=>", "[", "$", "this", "->", "getRule", "(", "'required'", ")", "]", ",", "]", ")", ")", ";", "$", "requiredData", "->", "addChild", "(", "$", "this", "->", "getElement", "(", "'text_field'", ",", "[", "'name'", "=>", "'symbol'", ",", "'label'", "=>", "$", "this", "->", "trans", "(", "'common.label.symbol'", ")", ",", "]", ")", ")", ";", "$", "requiredData", "->", "addChild", "(", "$", "this", "->", "getElement", "(", "'tree'", ",", "[", "'name'", "=>", "'parent'", ",", "'label'", "=>", "$", "this", "->", "trans", "(", "'category.label.parent'", ")", ",", "'choosable'", "=>", "true", ",", "'selectable'", "=>", "false", ",", "'sortable'", "=>", "false", ",", "'clickable'", "=>", "false", ",", "'items'", "=>", "$", "this", "->", "get", "(", "'category.dataset.admin'", ")", "->", "getResult", "(", "'flat_tree'", ")", ",", "'restrict'", "=>", "$", "this", "->", "getRequestHelper", "(", ")", "->", "getAttributesBagParam", "(", "'id'", ")", ",", "'transformer'", "=>", "$", "this", "->", "getRepositoryTransformer", "(", "'entity'", ",", "$", "this", "->", "get", "(", "'category.repository'", ")", ")", "]", ")", ")", ";", "$", "descriptionData", "=", "$", "form", "->", "addChild", "(", "$", "this", "->", "getElement", "(", "'nested_fieldset'", ",", "[", "'name'", "=>", "'description_data'", ",", "'label'", "=>", "$", "this", "->", "trans", "(", "'category.form.fieldset.description'", ")", "]", ")", ")", ";", "$", "languageData", "=", "$", "descriptionData", "->", "addChild", "(", "$", "this", "->", "getElement", "(", "'language_fieldset'", ",", "[", "'name'", "=>", "'translations'", ",", "'label'", "=>", "$", "this", "->", "trans", "(", "'common.fieldset.translations'", ")", ",", "'transformer'", "=>", "$", "this", "->", "getRepositoryTransformer", "(", "'translation'", ",", "$", "this", "->", "get", "(", "'category.repository'", ")", ")", "]", ")", ")", ";", "$", "languageData", "->", "addChild", "(", "$", "this", "->", "getElement", "(", "'rich_text_editor'", ",", "[", "'name'", "=>", "'shortDescription'", ",", "'label'", "=>", "$", "this", "->", "trans", "(", "'common.label.short_description'", ")", "]", ")", ")", ";", "$", "languageData", "->", "addChild", "(", "$", "this", "->", "getElement", "(", "'rich_text_editor'", ",", "[", "'name'", "=>", "'description'", ",", "'label'", "=>", "$", "this", "->", "trans", "(", "'common.label.description'", ")", ",", "]", ")", ")", ";", "$", "this", "->", "addMetadataFieldset", "(", "$", "form", ",", "$", "this", "->", "get", "(", "'category.repository'", ")", ")", ";", "$", "this", "->", "addShopsFieldset", "(", "$", "form", ")", ";", "$", "form", "->", "addFilter", "(", "$", "this", "->", "getFilter", "(", "'trim'", ")", ")", ";", "$", "form", "->", "addFilter", "(", "$", "this", "->", "getFilter", "(", "'secure'", ")", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/WellCommerce/CategoryBundle/blob/7a23ac678f91d15e86bdff624c4799be7b076e1a/Form/Admin/CategoryFormBuilder.php#L27-L117
phossa/phossa-route
src/Phossa/Route/Regex/ParserStd.php
ParserStd.match
public function match(/*# string */ $url) { $matches = []; foreach ($this->getRegexData() as $regex) { if (preg_match($regex, $url, $matches)) { return $this->fixMatches($matches); } } return false; }
php
public function match(/*# string */ $url) { $matches = []; foreach ($this->getRegexData() as $regex) { if (preg_match($regex, $url, $matches)) { return $this->fixMatches($matches); } } return false; }
[ "public", "function", "match", "(", "/*# string */", "$", "url", ")", "{", "$", "matches", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "getRegexData", "(", ")", "as", "$", "regex", ")", "{", "if", "(", "preg_match", "(", "$", "regex", ",", "$", "url", ",", "$", "matches", ")", ")", "{", "return", "$", "this", "->", "fixMatches", "(", "$", "matches", ")", ";", "}", "}", "return", "false", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/phossa/phossa-route/blob/fdcc1c814b8b1692a60d433d3c085e6c7a923acc/src/Phossa/Route/Regex/ParserStd.php#L86-L95
phossa/phossa-route
src/Phossa/Route/Regex/ParserStd.php
ParserStd.convert
protected function convert( /*# string */ $name, /*# string */ $pattern )/*# : string */ { // regex $groupname = "\s*([a-zA-Z][a-zA-Z0-9_]*)\s*"; $grouptype = ":\s*([^{}]*(?:\{(?-1)\}[^{}]*)*)"; $placeholder = sprintf("\{%s(?:%s)?\}", $groupname, $grouptype); $segmenttype = "[^/]++"; $result = preg_replace([ '~' . $placeholder . '(*SKIP)(*FAIL) | \[~x', '~' . $placeholder . '(*SKIP)(*FAIL) | \]~x', '~\{' . $groupname . '\}~x', '~' . $placeholder . '~x', ], [ '(?:', // replace '[' ')?', // replace ']' '{\\1:' . $segmenttype . '}', // add segementtype '(?<${1}'. $name . '>${2})' // replace groupname ], strtr('/' . trim($pattern, '/'), $this->shortcuts) ); return empty($name) ? $result : ("(?<$name>" . $result . ")"); }
php
protected function convert( /*# string */ $name, /*# string */ $pattern )/*# : string */ { // regex $groupname = "\s*([a-zA-Z][a-zA-Z0-9_]*)\s*"; $grouptype = ":\s*([^{}]*(?:\{(?-1)\}[^{}]*)*)"; $placeholder = sprintf("\{%s(?:%s)?\}", $groupname, $grouptype); $segmenttype = "[^/]++"; $result = preg_replace([ '~' . $placeholder . '(*SKIP)(*FAIL) | \[~x', '~' . $placeholder . '(*SKIP)(*FAIL) | \]~x', '~\{' . $groupname . '\}~x', '~' . $placeholder . '~x', ], [ '(?:', // replace '[' ')?', // replace ']' '{\\1:' . $segmenttype . '}', // add segementtype '(?<${1}'. $name . '>${2})' // replace groupname ], strtr('/' . trim($pattern, '/'), $this->shortcuts) ); return empty($name) ? $result : ("(?<$name>" . $result . ")"); }
[ "protected", "function", "convert", "(", "/*# string */", "$", "name", ",", "/*# string */", "$", "pattern", ")", "/*# : string */", "{", "// regex", "$", "groupname", "=", "\"\\s*([a-zA-Z][a-zA-Z0-9_]*)\\s*\"", ";", "$", "grouptype", "=", "\":\\s*([^{}]*(?:\\{(?-1)\\}[^{}]*)*)\"", ";", "$", "placeholder", "=", "sprintf", "(", "\"\\{%s(?:%s)?\\}\"", ",", "$", "groupname", ",", "$", "grouptype", ")", ";", "$", "segmenttype", "=", "\"[^/]++\"", ";", "$", "result", "=", "preg_replace", "(", "[", "'~'", ".", "$", "placeholder", ".", "'(*SKIP)(*FAIL) | \\[~x'", ",", "'~'", ".", "$", "placeholder", ".", "'(*SKIP)(*FAIL) | \\]~x'", ",", "'~\\{'", ".", "$", "groupname", ".", "'\\}~x'", ",", "'~'", ".", "$", "placeholder", ".", "'~x'", ",", "]", ",", "[", "'(?:'", ",", "// replace '['", "')?'", ",", "// replace ']'", "'{\\\\1:'", ".", "$", "segmenttype", ".", "'}'", ",", "// add segementtype", "'(?<${1}'", ".", "$", "name", ".", "'>${2})'", "// replace groupname", "]", ",", "strtr", "(", "'/'", ".", "trim", "(", "$", "pattern", ",", "'/'", ")", ",", "$", "this", "->", "shortcuts", ")", ")", ";", "return", "empty", "(", "$", "name", ")", "?", "$", "result", ":", "(", "\"(?<$name>\"", ".", "$", "result", ".", "\")\"", ")", ";", "}" ]
Convert to regex @param string $name regex name @param string $pattern pattern to parse @return self @access protected
[ "Convert", "to", "regex" ]
train
https://github.com/phossa/phossa-route/blob/fdcc1c814b8b1692a60d433d3c085e6c7a923acc/src/Phossa/Route/Regex/ParserStd.php#L105-L129
phossa/phossa-route
src/Phossa/Route/Regex/ParserStd.php
ParserStd.getRegexData
protected function getRegexData()/*# : array */ { // load from cache if (empty($this->regex) || !$this->modified) { return $this->data; } // chunk size $this->data = array_chunk($this->regex, $this->chunk); // join in chunks foreach ($this->data as $i => $reg) { $this->data[$i] = '~^(?:' . implode('|', $reg) . ')$~x'; } // save to cache here $this->modified = false; return $this->data; }
php
protected function getRegexData()/*# : array */ { // load from cache if (empty($this->regex) || !$this->modified) { return $this->data; } // chunk size $this->data = array_chunk($this->regex, $this->chunk); // join in chunks foreach ($this->data as $i => $reg) { $this->data[$i] = '~^(?:' . implode('|', $reg) . ')$~x'; } // save to cache here $this->modified = false; return $this->data; }
[ "protected", "function", "getRegexData", "(", ")", "/*# : array */", "{", "// load from cache", "if", "(", "empty", "(", "$", "this", "->", "regex", ")", "||", "!", "$", "this", "->", "modified", ")", "{", "return", "$", "this", "->", "data", ";", "}", "// chunk size", "$", "this", "->", "data", "=", "array_chunk", "(", "$", "this", "->", "regex", ",", "$", "this", "->", "chunk", ")", ";", "// join in chunks", "foreach", "(", "$", "this", "->", "data", "as", "$", "i", "=>", "$", "reg", ")", "{", "$", "this", "->", "data", "[", "$", "i", "]", "=", "'~^(?:'", ".", "implode", "(", "'|'", ",", "$", "reg", ")", ".", "')$~x'", ";", "}", "// save to cache here", "$", "this", "->", "modified", "=", "false", ";", "return", "$", "this", "->", "data", ";", "}" ]
Merge several (chunk size) regex into one @return array @access protected
[ "Merge", "several", "(", "chunk", "size", ")", "regex", "into", "one" ]
train
https://github.com/phossa/phossa-route/blob/fdcc1c814b8b1692a60d433d3c085e6c7a923acc/src/Phossa/Route/Regex/ParserStd.php#L137-L156
phossa/phossa-route
src/Phossa/Route/Regex/ParserStd.php
ParserStd.fixMatches
protected function fixMatches($matches)/*# : array */ { // remove numeric keys and empty group match foreach ($matches as $idx => $val) { if (is_int($idx) || '' === $val) { unset($matches[$idx]); } } // get route key/name $routeKey = array_keys($matches)[0]; $len = strlen($routeKey); // fix remainging match key $res = []; foreach ($matches as $key => $val) { if ($key != $routeKey) { $res[substr($key, 0, -$len)] = $val; } } // debug $this->debug(Message::get( Message::DEBUG_MATCH_REGEX, $this->regex[$routeKey] )); return [ $routeKey, $res ]; }
php
protected function fixMatches($matches)/*# : array */ { // remove numeric keys and empty group match foreach ($matches as $idx => $val) { if (is_int($idx) || '' === $val) { unset($matches[$idx]); } } // get route key/name $routeKey = array_keys($matches)[0]; $len = strlen($routeKey); // fix remainging match key $res = []; foreach ($matches as $key => $val) { if ($key != $routeKey) { $res[substr($key, 0, -$len)] = $val; } } // debug $this->debug(Message::get( Message::DEBUG_MATCH_REGEX, $this->regex[$routeKey] )); return [ $routeKey, $res ]; }
[ "protected", "function", "fixMatches", "(", "$", "matches", ")", "/*# : array */", "{", "// remove numeric keys and empty group match", "foreach", "(", "$", "matches", "as", "$", "idx", "=>", "$", "val", ")", "{", "if", "(", "is_int", "(", "$", "idx", ")", "||", "''", "===", "$", "val", ")", "{", "unset", "(", "$", "matches", "[", "$", "idx", "]", ")", ";", "}", "}", "// get route key/name", "$", "routeKey", "=", "array_keys", "(", "$", "matches", ")", "[", "0", "]", ";", "$", "len", "=", "strlen", "(", "$", "routeKey", ")", ";", "// fix remainging match key", "$", "res", "=", "[", "]", ";", "foreach", "(", "$", "matches", "as", "$", "key", "=>", "$", "val", ")", "{", "if", "(", "$", "key", "!=", "$", "routeKey", ")", "{", "$", "res", "[", "substr", "(", "$", "key", ",", "0", ",", "-", "$", "len", ")", "]", "=", "$", "val", ";", "}", "}", "// debug", "$", "this", "->", "debug", "(", "Message", "::", "get", "(", "Message", "::", "DEBUG_MATCH_REGEX", ",", "$", "this", "->", "regex", "[", "$", "routeKey", "]", ")", ")", ";", "return", "[", "$", "routeKey", ",", "$", "res", "]", ";", "}" ]
Fix matched placeholders, return with unique route key @param array $matches desc @return array [ $name, $matches ] @access protected
[ "Fix", "matched", "placeholders", "return", "with", "unique", "route", "key" ]
train
https://github.com/phossa/phossa-route/blob/fdcc1c814b8b1692a60d433d3c085e6c7a923acc/src/Phossa/Route/Regex/ParserStd.php#L165-L193
nemundo/core
src/Date/DateTimeDifference.php
DateTimeDifference.getDifferenceInMinute
public function getDifferenceInMinute() { $difference = $this->getDifference(); $differenceInMinute = 0; if ($difference !== 0) { $differenceInMinute = ($difference->d * 1440) + ($difference->h * 60) + $difference->i; } //if ($difference->invert = 1) { $differenceInMinute = abs($differenceInMinute); //} return $differenceInMinute; }
php
public function getDifferenceInMinute() { $difference = $this->getDifference(); $differenceInMinute = 0; if ($difference !== 0) { $differenceInMinute = ($difference->d * 1440) + ($difference->h * 60) + $difference->i; } //if ($difference->invert = 1) { $differenceInMinute = abs($differenceInMinute); //} return $differenceInMinute; }
[ "public", "function", "getDifferenceInMinute", "(", ")", "{", "$", "difference", "=", "$", "this", "->", "getDifference", "(", ")", ";", "$", "differenceInMinute", "=", "0", ";", "if", "(", "$", "difference", "!==", "0", ")", "{", "$", "differenceInMinute", "=", "(", "$", "difference", "->", "d", "*", "1440", ")", "+", "(", "$", "difference", "->", "h", "*", "60", ")", "+", "$", "difference", "->", "i", ";", "}", "//if ($difference->invert = 1) {", "$", "differenceInMinute", "=", "abs", "(", "$", "differenceInMinute", ")", ";", "//}", "return", "$", "differenceInMinute", ";", "}" ]
dateTill
[ "dateTill" ]
train
https://github.com/nemundo/core/blob/5ca14889fdfb9155b52fedb364b34502d14e21ed/src/Date/DateTimeDifference.php#L26-L43
vainproject/vain-site
src/Site/Http/Requests/PageFormRequest.php
PageFormRequest.rules
public function rules() { $attributes = [ 'title' => 'required', 'text' => 'required', ]; $rules = $this->buildLocalizedRules($attributes); return array_merge($rules, [ 'id' => 'exists:site_pages,id', 'slug' => 'required|alpha_dash|unique:site_pages,slug,'.$this->route('sites'), 'published_at' => 'date', 'concealed_at' => 'date', ]); }
php
public function rules() { $attributes = [ 'title' => 'required', 'text' => 'required', ]; $rules = $this->buildLocalizedRules($attributes); return array_merge($rules, [ 'id' => 'exists:site_pages,id', 'slug' => 'required|alpha_dash|unique:site_pages,slug,'.$this->route('sites'), 'published_at' => 'date', 'concealed_at' => 'date', ]); }
[ "public", "function", "rules", "(", ")", "{", "$", "attributes", "=", "[", "'title'", "=>", "'required'", ",", "'text'", "=>", "'required'", ",", "]", ";", "$", "rules", "=", "$", "this", "->", "buildLocalizedRules", "(", "$", "attributes", ")", ";", "return", "array_merge", "(", "$", "rules", ",", "[", "'id'", "=>", "'exists:site_pages,id'", ",", "'slug'", "=>", "'required|alpha_dash|unique:site_pages,slug,'", ".", "$", "this", "->", "route", "(", "'sites'", ")", ",", "'published_at'", "=>", "'date'", ",", "'concealed_at'", "=>", "'date'", ",", "]", ")", ";", "}" ]
validation that has to pass. @return array
[ "validation", "that", "has", "to", "pass", "." ]
train
https://github.com/vainproject/vain-site/blob/d5560df68264f7ac1692c3dcfebc40500148dd56/src/Site/Http/Requests/PageFormRequest.php#L16-L31
vainproject/vain-site
src/Site/Http/Requests/PageFormRequest.php
PageFormRequest.buildLocalizedRules
protected function buildLocalizedRules($attributes) { $rules = []; $locales = config('app.locales'); foreach ($locales as $locale => $name) { foreach ($attributes as $attribute => $rule) { $rules[$attribute.'_'.$locale] = $rule; } } return $rules; }
php
protected function buildLocalizedRules($attributes) { $rules = []; $locales = config('app.locales'); foreach ($locales as $locale => $name) { foreach ($attributes as $attribute => $rule) { $rules[$attribute.'_'.$locale] = $rule; } } return $rules; }
[ "protected", "function", "buildLocalizedRules", "(", "$", "attributes", ")", "{", "$", "rules", "=", "[", "]", ";", "$", "locales", "=", "config", "(", "'app.locales'", ")", ";", "foreach", "(", "$", "locales", "as", "$", "locale", "=>", "$", "name", ")", "{", "foreach", "(", "$", "attributes", "as", "$", "attribute", "=>", "$", "rule", ")", "{", "$", "rules", "[", "$", "attribute", ".", "'_'", ".", "$", "locale", "]", "=", "$", "rule", ";", "}", "}", "return", "$", "rules", ";", "}" ]
builds localized suffixed rules for validation. @param $attributes @return array
[ "builds", "localized", "suffixed", "rules", "for", "validation", "." ]
train
https://github.com/vainproject/vain-site/blob/d5560df68264f7ac1692c3dcfebc40500148dd56/src/Site/Http/Requests/PageFormRequest.php#L48-L60
nochso/ORM2
src/Model.php
Model.getPrimaryKeyValue
public function getPrimaryKeyValue() { $primaryKey = $this->getPrimaryKey(); if (isset($this->$primaryKey)) { return $this->$primaryKey; } else { return null; } }
php
public function getPrimaryKeyValue() { $primaryKey = $this->getPrimaryKey(); if (isset($this->$primaryKey)) { return $this->$primaryKey; } else { return null; } }
[ "public", "function", "getPrimaryKeyValue", "(", ")", "{", "$", "primaryKey", "=", "$", "this", "->", "getPrimaryKey", "(", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "$", "primaryKey", ")", ")", "{", "return", "$", "this", "->", "$", "primaryKey", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
Returns the value of the primary key @return null
[ "Returns", "the", "value", "of", "the", "primary", "key" ]
train
https://github.com/nochso/ORM2/blob/89f9a5c61ad5f575fbdd52990171b52d54f8bfbc/src/Model.php#L105-L113
nochso/ORM2
src/Model.php
Model.toAssoc
public function toAssoc() { $params = []; foreach (Extract::getObjectVars($this) as $key => $value) { if (!$value instanceof Relation) { $params[$key] = $value; } } if ($this->getPrimaryKeyValue() === null) { unset($params[$this->getPrimaryKey()]); } return $params; }
php
public function toAssoc() { $params = []; foreach (Extract::getObjectVars($this) as $key => $value) { if (!$value instanceof Relation) { $params[$key] = $value; } } if ($this->getPrimaryKeyValue() === null) { unset($params[$this->getPrimaryKey()]); } return $params; }
[ "public", "function", "toAssoc", "(", ")", "{", "$", "params", "=", "[", "]", ";", "foreach", "(", "Extract", "::", "getObjectVars", "(", "$", "this", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "!", "$", "value", "instanceof", "Relation", ")", "{", "$", "params", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "if", "(", "$", "this", "->", "getPrimaryKeyValue", "(", ")", "===", "null", ")", "{", "unset", "(", "$", "params", "[", "$", "this", "->", "getPrimaryKey", "(", ")", "]", ")", ";", "}", "return", "$", "params", ";", "}" ]
Returns an associative array from this object excluding private variables and Relation objects @return array
[ "Returns", "an", "associative", "array", "from", "this", "object", "excluding", "private", "variables", "and", "Relation", "objects" ]
train
https://github.com/nochso/ORM2/blob/89f9a5c61ad5f575fbdd52990171b52d54f8bfbc/src/Model.php#L268-L280
nochso/ORM2
src/Model.php
Model.hydrate
public function hydrate($data, $removePrimaryKey = false) { foreach ($data as $key => $value) { if (property_exists($this, $key)) { $this->$key = $value; } else { $this->extra[$key] = $value; } } if ($removePrimaryKey) { $key = $this->getPrimaryKey(); $this->$key = null; } return $this; }
php
public function hydrate($data, $removePrimaryKey = false) { foreach ($data as $key => $value) { if (property_exists($this, $key)) { $this->$key = $value; } else { $this->extra[$key] = $value; } } if ($removePrimaryKey) { $key = $this->getPrimaryKey(); $this->$key = null; } return $this; }
[ "public", "function", "hydrate", "(", "$", "data", ",", "$", "removePrimaryKey", "=", "false", ")", "{", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "property_exists", "(", "$", "this", ",", "$", "key", ")", ")", "{", "$", "this", "->", "$", "key", "=", "$", "value", ";", "}", "else", "{", "$", "this", "->", "extra", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "if", "(", "$", "removePrimaryKey", ")", "{", "$", "key", "=", "$", "this", "->", "getPrimaryKey", "(", ")", ";", "$", "this", "->", "$", "key", "=", "null", ";", "}", "return", "$", "this", ";", "}" ]
Sets the properties of this object using an associative array, where key is the property name and value is the property value. Properties that do not exist in the current context are ignored. @param array $data Associative array @param bool $removePrimaryKey Optional: If true, the primary key of the model will be unset. This is useful for hydrating a new object and the source ($_POST) erroneously supplies a primary key. Default: false @return static
[ "Sets", "the", "properties", "of", "this", "object", "using", "an", "associative", "array", "where", "key", "is", "the", "property", "name", "and", "value", "is", "the", "property", "value", "." ]
train
https://github.com/nochso/ORM2/blob/89f9a5c61ad5f575fbdd52990171b52d54f8bfbc/src/Model.php#L296-L310
nochso/ORM2
src/Model.php
Model.createFromData
private function createFromData($data) { $model = $this->dispense()->hydrate($data); $model->isNew = false; return $model; }
php
private function createFromData($data) { $model = $this->dispense()->hydrate($data); $model->isNew = false; return $model; }
[ "private", "function", "createFromData", "(", "$", "data", ")", "{", "$", "model", "=", "$", "this", "->", "dispense", "(", ")", "->", "hydrate", "(", "$", "data", ")", ";", "$", "model", "->", "isNew", "=", "false", ";", "return", "$", "model", ";", "}" ]
Dispenses a hydrated model that is known to exist in a database (i.e. is not new) @param array $data @return static
[ "Dispenses", "a", "hydrated", "model", "that", "is", "known", "to", "exist", "in", "a", "database", "(", "i", ".", "e", ".", "is", "not", "new", ")" ]
train
https://github.com/nochso/ORM2/blob/89f9a5c61ad5f575fbdd52990171b52d54f8bfbc/src/Model.php#L318-L323
nochso/ORM2
src/Model.php
Model.limit
public function limit($limit, $offset = null) { $this->queryBuilder->setLimit($limit, $offset); return $this; }
php
public function limit($limit, $offset = null) { $this->queryBuilder->setLimit($limit, $offset); return $this; }
[ "public", "function", "limit", "(", "$", "limit", ",", "$", "offset", "=", "null", ")", "{", "$", "this", "->", "queryBuilder", "->", "setLimit", "(", "$", "limit", ",", "$", "offset", ")", ";", "return", "$", "this", ";", "}" ]
Limit the amount of maximum rows returned @param int $limit @param int $offset @return static
[ "Limit", "the", "amount", "of", "maximum", "rows", "returned" ]
train
https://github.com/nochso/ORM2/blob/89f9a5c61ad5f575fbdd52990171b52d54f8bfbc/src/Model.php#L503-L507
Wedeto/Auth
src/ACL/DBRuleLoader.php
DBRuleLoader.loadRules
public function loadRules(string $entity_id) { $records = ACLRule::get(["entity_id" => $entity_id]); $rules = array(); foreach ($records as $record) { $rule = new Rule($record->entity_id, $record->role_id, $record->action, $record->policy); $rule->setRecord($record); $rules[] = $rule; } return $rules; }
php
public function loadRules(string $entity_id) { $records = ACLRule::get(["entity_id" => $entity_id]); $rules = array(); foreach ($records as $record) { $rule = new Rule($record->entity_id, $record->role_id, $record->action, $record->policy); $rule->setRecord($record); $rules[] = $rule; } return $rules; }
[ "public", "function", "loadRules", "(", "string", "$", "entity_id", ")", "{", "$", "records", "=", "ACLRule", "::", "get", "(", "[", "\"entity_id\"", "=>", "$", "entity_id", "]", ")", ";", "$", "rules", "=", "array", "(", ")", ";", "foreach", "(", "$", "records", "as", "$", "record", ")", "{", "$", "rule", "=", "new", "Rule", "(", "$", "record", "->", "entity_id", ",", "$", "record", "->", "role_id", ",", "$", "record", "->", "action", ",", "$", "record", "->", "policy", ")", ";", "$", "rule", "->", "setRecord", "(", "$", "record", ")", ";", "$", "rules", "[", "]", "=", "$", "rule", ";", "}", "return", "$", "rules", ";", "}" ]
Loads the rules for the specified entity from the database.
[ "Loads", "the", "rules", "for", "the", "specified", "entity", "from", "the", "database", "." ]
train
https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/ACL/DBRuleLoader.php#L38-L50
randomhost/image
src/php/Text/Generic.php
Generic.setTextFont
public function setTextFont($path) { if (!is_file($path) || !is_readable($path)) { throw new \InvalidArgumentException( 'Unable to load font file at ' . $path ); } $this->textFontPath = realpath($path); return $this; }
php
public function setTextFont($path) { if (!is_file($path) || !is_readable($path)) { throw new \InvalidArgumentException( 'Unable to load font file at ' . $path ); } $this->textFontPath = realpath($path); return $this; }
[ "public", "function", "setTextFont", "(", "$", "path", ")", "{", "if", "(", "!", "is_file", "(", "$", "path", ")", "||", "!", "is_readable", "(", "$", "path", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Unable to load font file at '", ".", "$", "path", ")", ";", "}", "$", "this", "->", "textFontPath", "=", "realpath", "(", "$", "path", ")", ";", "return", "$", "this", ";", "}" ]
Sets the path to the font file used for rendering text overlays onto the image. @param string $path File system path to TTF font file to be used. @return $this @throws \InvalidArgumentException Thrown if the font file could not be loaded.
[ "Sets", "the", "path", "to", "the", "font", "file", "used", "for", "rendering", "text", "overlays", "onto", "the", "image", "." ]
train
https://github.com/randomhost/image/blob/bd669ba6b50fd2bbbe50c4ef06235b111a8a30b0/src/php/Text/Generic.php#L121-L132
randomhost/image
src/php/Text/Generic.php
Generic.insertText
public function insertText($xPosition, $yPosition, $text) { if (!$this->getImage() instanceof Image\Image || !is_resource($this->getImage()->image) ) { throw new \RuntimeException( 'Attempt to render text onto invalid image resource' ); } if (!$this->textColor instanceof Image\Color) { throw new \RuntimeException( 'Attempt to render text without setting a color' ); } if (empty($this->textFontPath)) { throw new \RuntimeException( 'No font file selected for rendering text overlay' ); } if (!is_file($this->textFontPath) || !is_readable( $this->textFontPath ) ) { throw new \RuntimeException( sprintf( 'Failed to read font file \'%1$s\'', $this->textFontPath ) ); } $color = imagecolorallocatealpha( $this->getImage()->image, $this->textColor->getRed(), $this->textColor->getGreen(), $this->textColor->getBlue(), $this->textColor->getAlpha() ); imagettftext( $this->getImage()->image, $this->textSize, $this->textAngle, $xPosition, $yPosition, $color, $this->textFontPath, $text ); return $this; }
php
public function insertText($xPosition, $yPosition, $text) { if (!$this->getImage() instanceof Image\Image || !is_resource($this->getImage()->image) ) { throw new \RuntimeException( 'Attempt to render text onto invalid image resource' ); } if (!$this->textColor instanceof Image\Color) { throw new \RuntimeException( 'Attempt to render text without setting a color' ); } if (empty($this->textFontPath)) { throw new \RuntimeException( 'No font file selected for rendering text overlay' ); } if (!is_file($this->textFontPath) || !is_readable( $this->textFontPath ) ) { throw new \RuntimeException( sprintf( 'Failed to read font file \'%1$s\'', $this->textFontPath ) ); } $color = imagecolorallocatealpha( $this->getImage()->image, $this->textColor->getRed(), $this->textColor->getGreen(), $this->textColor->getBlue(), $this->textColor->getAlpha() ); imagettftext( $this->getImage()->image, $this->textSize, $this->textAngle, $xPosition, $yPosition, $color, $this->textFontPath, $text ); return $this; }
[ "public", "function", "insertText", "(", "$", "xPosition", ",", "$", "yPosition", ",", "$", "text", ")", "{", "if", "(", "!", "$", "this", "->", "getImage", "(", ")", "instanceof", "Image", "\\", "Image", "||", "!", "is_resource", "(", "$", "this", "->", "getImage", "(", ")", "->", "image", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Attempt to render text onto invalid image resource'", ")", ";", "}", "if", "(", "!", "$", "this", "->", "textColor", "instanceof", "Image", "\\", "Color", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Attempt to render text without setting a color'", ")", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "textFontPath", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'No font file selected for rendering text overlay'", ")", ";", "}", "if", "(", "!", "is_file", "(", "$", "this", "->", "textFontPath", ")", "||", "!", "is_readable", "(", "$", "this", "->", "textFontPath", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'Failed to read font file \\'%1$s\\''", ",", "$", "this", "->", "textFontPath", ")", ")", ";", "}", "$", "color", "=", "imagecolorallocatealpha", "(", "$", "this", "->", "getImage", "(", ")", "->", "image", ",", "$", "this", "->", "textColor", "->", "getRed", "(", ")", ",", "$", "this", "->", "textColor", "->", "getGreen", "(", ")", ",", "$", "this", "->", "textColor", "->", "getBlue", "(", ")", ",", "$", "this", "->", "textColor", "->", "getAlpha", "(", ")", ")", ";", "imagettftext", "(", "$", "this", "->", "getImage", "(", ")", "->", "image", ",", "$", "this", "->", "textSize", ",", "$", "this", "->", "textAngle", ",", "$", "xPosition", ",", "$", "yPosition", ",", "$", "color", ",", "$", "this", "->", "textFontPath", ",", "$", "text", ")", ";", "return", "$", "this", ";", "}" ]
Renders the given text onto the image resource, using the given coordinates. @param int $xPosition The x-ordinate. @param int $yPosition The y-ordinate position of the fonts baseline. @param string $text The text string in UTF-8 encoding. @return $this; @throws \RuntimeException Thrown if $this->image is not a valid image resource or the font file isn't set.
[ "Renders", "the", "given", "text", "onto", "the", "image", "resource", "using", "the", "given", "coordinates", "." ]
train
https://github.com/randomhost/image/blob/bd669ba6b50fd2bbbe50c4ef06235b111a8a30b0/src/php/Text/Generic.php#L181-L236
bearframework/localization-addon
classes/Localization.php
Localization.addDictionary
public function addDictionary(string $locale, $callbackOrArray): \BearFramework\Localization { if (!isset($this->dictionaries[$locale])) { $this->dictionaries[$locale] = []; } $this->dictionaries[$locale][] = $callbackOrArray; return $this; }
php
public function addDictionary(string $locale, $callbackOrArray): \BearFramework\Localization { if (!isset($this->dictionaries[$locale])) { $this->dictionaries[$locale] = []; } $this->dictionaries[$locale][] = $callbackOrArray; return $this; }
[ "public", "function", "addDictionary", "(", "string", "$", "locale", ",", "$", "callbackOrArray", ")", ":", "\\", "BearFramework", "\\", "Localization", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "dictionaries", "[", "$", "locale", "]", ")", ")", "{", "$", "this", "->", "dictionaries", "[", "$", "locale", "]", "=", "[", "]", ";", "}", "$", "this", "->", "dictionaries", "[", "$", "locale", "]", "[", "]", "=", "$", "callbackOrArray", ";", "return", "$", "this", ";", "}" ]
Adds a new dictionary. @param string $locale A locale code. @param type $callbackOrArray An array containing dictionary data (in key=>value format) or a callback that returns such array. @return \BearFramework\Localization Returns a instance to itself.
[ "Adds", "a", "new", "dictionary", "." ]
train
https://github.com/bearframework/localization-addon/blob/7feb1b85bf5b808a1883f98bbfb40c4eb83bb139/classes/Localization.php#L86-L93
bearframework/localization-addon
classes/Localization.php
Localization.getText
public function getText(string $id): ?string { $getText = function(string $id, string $locale) { if (isset($this->defaultLocales[$locale]) && $this->defaultLocales[$locale] === 0) { $app = App::get(); $context = $app->contexts->get(__FILE__); $this->defaultLocales[$locale] = 1; $filename = $context->dir . '/locales/' . $locale . '.php'; if (is_file($filename)) { $data = include $filename; if (is_array($data)) { $this->addDictionary($locale, $data); } } } if (isset($this->dictionaries[$locale])) { foreach ($this->dictionaries[$locale] as $i => $dictionary) { if (is_callable($dictionary)) { $dictionary = call_user_func($dictionary); $this->dictionaries[$locale][$i] = $dictionary; } if (is_array($dictionary)) { foreach ($dictionary as $_id => $text) { if ($id === $_id) { return (string) $text; } } } } } return null; }; $text = $getText($id, $this->locale); if ($text === null || !isset($text[0])) { $text = $getText($id, $this->backupLocale); } return $text; }
php
public function getText(string $id): ?string { $getText = function(string $id, string $locale) { if (isset($this->defaultLocales[$locale]) && $this->defaultLocales[$locale] === 0) { $app = App::get(); $context = $app->contexts->get(__FILE__); $this->defaultLocales[$locale] = 1; $filename = $context->dir . '/locales/' . $locale . '.php'; if (is_file($filename)) { $data = include $filename; if (is_array($data)) { $this->addDictionary($locale, $data); } } } if (isset($this->dictionaries[$locale])) { foreach ($this->dictionaries[$locale] as $i => $dictionary) { if (is_callable($dictionary)) { $dictionary = call_user_func($dictionary); $this->dictionaries[$locale][$i] = $dictionary; } if (is_array($dictionary)) { foreach ($dictionary as $_id => $text) { if ($id === $_id) { return (string) $text; } } } } } return null; }; $text = $getText($id, $this->locale); if ($text === null || !isset($text[0])) { $text = $getText($id, $this->backupLocale); } return $text; }
[ "public", "function", "getText", "(", "string", "$", "id", ")", ":", "?", "string", "{", "$", "getText", "=", "function", "(", "string", "$", "id", ",", "string", "$", "locale", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "defaultLocales", "[", "$", "locale", "]", ")", "&&", "$", "this", "->", "defaultLocales", "[", "$", "locale", "]", "===", "0", ")", "{", "$", "app", "=", "App", "::", "get", "(", ")", ";", "$", "context", "=", "$", "app", "->", "contexts", "->", "get", "(", "__FILE__", ")", ";", "$", "this", "->", "defaultLocales", "[", "$", "locale", "]", "=", "1", ";", "$", "filename", "=", "$", "context", "->", "dir", ".", "'/locales/'", ".", "$", "locale", ".", "'.php'", ";", "if", "(", "is_file", "(", "$", "filename", ")", ")", "{", "$", "data", "=", "include", "$", "filename", ";", "if", "(", "is_array", "(", "$", "data", ")", ")", "{", "$", "this", "->", "addDictionary", "(", "$", "locale", ",", "$", "data", ")", ";", "}", "}", "}", "if", "(", "isset", "(", "$", "this", "->", "dictionaries", "[", "$", "locale", "]", ")", ")", "{", "foreach", "(", "$", "this", "->", "dictionaries", "[", "$", "locale", "]", "as", "$", "i", "=>", "$", "dictionary", ")", "{", "if", "(", "is_callable", "(", "$", "dictionary", ")", ")", "{", "$", "dictionary", "=", "call_user_func", "(", "$", "dictionary", ")", ";", "$", "this", "->", "dictionaries", "[", "$", "locale", "]", "[", "$", "i", "]", "=", "$", "dictionary", ";", "}", "if", "(", "is_array", "(", "$", "dictionary", ")", ")", "{", "foreach", "(", "$", "dictionary", "as", "$", "_id", "=>", "$", "text", ")", "{", "if", "(", "$", "id", "===", "$", "_id", ")", "{", "return", "(", "string", ")", "$", "text", ";", "}", "}", "}", "}", "}", "return", "null", ";", "}", ";", "$", "text", "=", "$", "getText", "(", "$", "id", ",", "$", "this", "->", "locale", ")", ";", "if", "(", "$", "text", "===", "null", "||", "!", "isset", "(", "$", "text", "[", "0", "]", ")", ")", "{", "$", "text", "=", "$", "getText", "(", "$", "id", ",", "$", "this", "->", "backupLocale", ")", ";", "}", "return", "$", "text", ";", "}" ]
Returns a text from the dictionary for the current locale. @param string $id The ID of the text. @return string A text from the dictionary for the current locale. Returns null if no text is found.
[ "Returns", "a", "text", "from", "the", "dictionary", "for", "the", "current", "locale", "." ]
train
https://github.com/bearframework/localization-addon/blob/7feb1b85bf5b808a1883f98bbfb40c4eb83bb139/classes/Localization.php#L100-L137
bearframework/localization-addon
classes/Localization.php
Localization.formatDate
public function formatDate($date, array $options = []): string { if (is_int($date) || is_numeric($date)) { $timestamp = (int) $date; } elseif ($date instanceof \DateTime) { $timestamp = $date->getTimestamp(); } else { $timestamp = (new \DateTime($date))->getTimestamp(); } if (empty($options)) { $options = ['dateAutoYear']; } $result = []; $hasDateOption = array_search('date', $options) !== false; $hasDateAutoYearOption = array_search('dateAutoYear', $options) !== false; $hasTimeOption = array_search('time', $options) !== false; $hasTimeAgoOption = array_search('timeAgo', $options) !== false; if ($hasTimeAgoOption) { $secondsAgo = time() - $timestamp; if ($secondsAgo < 60) { $result[] = __('bearframework-localization-addon.moment_ago'); } elseif ($secondsAgo < 60 * 60) { $minutes = floor($secondsAgo / 60); $result[] = $minutes > 1 ? sprintf(__('bearframework-localization-addon.minutes_ago'), $minutes) : __('bearframework-localization-addon.minute_ago'); } elseif ($secondsAgo < 60 * 60 * 24) { $hours = floor($secondsAgo / (60 * 60)); $result[] = $hours > 1 ? sprintf(__('bearframework-localization-addon.hours_ago'), $hours) : __('bearframework-localization-addon.hour_ago'); } else { $hasDateAutoYearOption = true; } } if ($hasDateOption || $hasDateAutoYearOption) { $day = date('j', $timestamp); $month = __('bearframework-localization-addon.month_' . date('n', $timestamp)); $year = date('Y', $timestamp); $showYear = $hasDateOption || ($hasDateAutoYearOption && $year !== date('Y', time())); if ($this->locale === 'bg') { $result[] = $day . ' ' . $month . ($showYear ? ' ' . $year . 'г.' : ''); } elseif ($this->locale === 'ru') { $result[] = $day . ' ' . $month . ($showYear ? ' ' . $year : ''); } else { $result[] = $month . ' ' . $day . ($showYear ? ', ' . $year : ''); } } if ($hasTimeOption) { $result[] = date('G:i', $timestamp); } return implode(' ', $result); }
php
public function formatDate($date, array $options = []): string { if (is_int($date) || is_numeric($date)) { $timestamp = (int) $date; } elseif ($date instanceof \DateTime) { $timestamp = $date->getTimestamp(); } else { $timestamp = (new \DateTime($date))->getTimestamp(); } if (empty($options)) { $options = ['dateAutoYear']; } $result = []; $hasDateOption = array_search('date', $options) !== false; $hasDateAutoYearOption = array_search('dateAutoYear', $options) !== false; $hasTimeOption = array_search('time', $options) !== false; $hasTimeAgoOption = array_search('timeAgo', $options) !== false; if ($hasTimeAgoOption) { $secondsAgo = time() - $timestamp; if ($secondsAgo < 60) { $result[] = __('bearframework-localization-addon.moment_ago'); } elseif ($secondsAgo < 60 * 60) { $minutes = floor($secondsAgo / 60); $result[] = $minutes > 1 ? sprintf(__('bearframework-localization-addon.minutes_ago'), $minutes) : __('bearframework-localization-addon.minute_ago'); } elseif ($secondsAgo < 60 * 60 * 24) { $hours = floor($secondsAgo / (60 * 60)); $result[] = $hours > 1 ? sprintf(__('bearframework-localization-addon.hours_ago'), $hours) : __('bearframework-localization-addon.hour_ago'); } else { $hasDateAutoYearOption = true; } } if ($hasDateOption || $hasDateAutoYearOption) { $day = date('j', $timestamp); $month = __('bearframework-localization-addon.month_' . date('n', $timestamp)); $year = date('Y', $timestamp); $showYear = $hasDateOption || ($hasDateAutoYearOption && $year !== date('Y', time())); if ($this->locale === 'bg') { $result[] = $day . ' ' . $month . ($showYear ? ' ' . $year . 'г.' : ''); } elseif ($this->locale === 'ru') { $result[] = $day . ' ' . $month . ($showYear ? ' ' . $year : ''); } else { $result[] = $month . ' ' . $day . ($showYear ? ', ' . $year : ''); } } if ($hasTimeOption) { $result[] = date('G:i', $timestamp); } return implode(' ', $result); }
[ "public", "function", "formatDate", "(", "$", "date", ",", "array", "$", "options", "=", "[", "]", ")", ":", "string", "{", "if", "(", "is_int", "(", "$", "date", ")", "||", "is_numeric", "(", "$", "date", ")", ")", "{", "$", "timestamp", "=", "(", "int", ")", "$", "date", ";", "}", "elseif", "(", "$", "date", "instanceof", "\\", "DateTime", ")", "{", "$", "timestamp", "=", "$", "date", "->", "getTimestamp", "(", ")", ";", "}", "else", "{", "$", "timestamp", "=", "(", "new", "\\", "DateTime", "(", "$", "date", ")", ")", "->", "getTimestamp", "(", ")", ";", "}", "if", "(", "empty", "(", "$", "options", ")", ")", "{", "$", "options", "=", "[", "'dateAutoYear'", "]", ";", "}", "$", "result", "=", "[", "]", ";", "$", "hasDateOption", "=", "array_search", "(", "'date'", ",", "$", "options", ")", "!==", "false", ";", "$", "hasDateAutoYearOption", "=", "array_search", "(", "'dateAutoYear'", ",", "$", "options", ")", "!==", "false", ";", "$", "hasTimeOption", "=", "array_search", "(", "'time'", ",", "$", "options", ")", "!==", "false", ";", "$", "hasTimeAgoOption", "=", "array_search", "(", "'timeAgo'", ",", "$", "options", ")", "!==", "false", ";", "if", "(", "$", "hasTimeAgoOption", ")", "{", "$", "secondsAgo", "=", "time", "(", ")", "-", "$", "timestamp", ";", "if", "(", "$", "secondsAgo", "<", "60", ")", "{", "$", "result", "[", "]", "=", "__", "(", "'bearframework-localization-addon.moment_ago'", ")", ";", "}", "elseif", "(", "$", "secondsAgo", "<", "60", "*", "60", ")", "{", "$", "minutes", "=", "floor", "(", "$", "secondsAgo", "/", "60", ")", ";", "$", "result", "[", "]", "=", "$", "minutes", ">", "1", "?", "sprintf", "(", "__", "(", "'bearframework-localization-addon.minutes_ago'", ")", ",", "$", "minutes", ")", ":", "__", "(", "'bearframework-localization-addon.minute_ago'", ")", ";", "}", "elseif", "(", "$", "secondsAgo", "<", "60", "*", "60", "*", "24", ")", "{", "$", "hours", "=", "floor", "(", "$", "secondsAgo", "/", "(", "60", "*", "60", ")", ")", ";", "$", "result", "[", "]", "=", "$", "hours", ">", "1", "?", "sprintf", "(", "__", "(", "'bearframework-localization-addon.hours_ago'", ")", ",", "$", "hours", ")", ":", "__", "(", "'bearframework-localization-addon.hour_ago'", ")", ";", "}", "else", "{", "$", "hasDateAutoYearOption", "=", "true", ";", "}", "}", "if", "(", "$", "hasDateOption", "||", "$", "hasDateAutoYearOption", ")", "{", "$", "day", "=", "date", "(", "'j'", ",", "$", "timestamp", ")", ";", "$", "month", "=", "__", "(", "'bearframework-localization-addon.month_'", ".", "date", "(", "'n'", ",", "$", "timestamp", ")", ")", ";", "$", "year", "=", "date", "(", "'Y'", ",", "$", "timestamp", ")", ";", "$", "showYear", "=", "$", "hasDateOption", "||", "(", "$", "hasDateAutoYearOption", "&&", "$", "year", "!==", "date", "(", "'Y'", ",", "time", "(", ")", ")", ")", ";", "if", "(", "$", "this", "->", "locale", "===", "'bg'", ")", "{", "$", "result", "[", "]", "=", "$", "day", ".", "' '", ".", "$", "month", ".", "(", "$", "showYear", "?", "' '", ".", "$", "year", ".", "'г.' ", " ", "')", ";", "", "}", "elseif", "(", "$", "this", "->", "locale", "===", "'ru'", ")", "{", "$", "result", "[", "]", "=", "$", "day", ".", "' '", ".", "$", "month", ".", "(", "$", "showYear", "?", "' '", ".", "$", "year", ":", "''", ")", ";", "}", "else", "{", "$", "result", "[", "]", "=", "$", "month", ".", "' '", ".", "$", "day", ".", "(", "$", "showYear", "?", "', '", ".", "$", "year", ":", "''", ")", ";", "}", "}", "if", "(", "$", "hasTimeOption", ")", "{", "$", "result", "[", "]", "=", "date", "(", "'G:i'", ",", "$", "timestamp", ")", ";", "}", "return", "implode", "(", "' '", ",", "$", "result", ")", ";", "}" ]
Returns a text representation of the date provided that contains the elements listed. @param int|DateTime $date The date to format. @param array $options The elements that the text representation of the date must contain. Available values: date, dateAutoYear, time, timeAgo. @todo Additional options: timeAutoDate, day, month, year, autoYear, hours, minutes, seconds.
[ "Returns", "a", "text", "representation", "of", "the", "date", "provided", "that", "contains", "the", "elements", "listed", "." ]
train
https://github.com/bearframework/localization-addon/blob/7feb1b85bf5b808a1883f98bbfb40c4eb83bb139/classes/Localization.php#L145-L200
wb-crowdfusion/crowdfusion
system/core/classes/libraries/database/AbstractMySQLDataSource.php
AbstractMySQLDataSource.getNewConnection
protected function getNewConnection($connections) { $connection = $this->ApplicationContext->object($this->DatabaseServiceName); $connection->setConnectionInfo($connections); return $connection; }
php
protected function getNewConnection($connections) { $connection = $this->ApplicationContext->object($this->DatabaseServiceName); $connection->setConnectionInfo($connections); return $connection; }
[ "protected", "function", "getNewConnection", "(", "$", "connections", ")", "{", "$", "connection", "=", "$", "this", "->", "ApplicationContext", "->", "object", "(", "$", "this", "->", "DatabaseServiceName", ")", ";", "$", "connection", "->", "setConnectionInfo", "(", "$", "connections", ")", ";", "return", "$", "connection", ";", "}" ]
Gets a new connection using the connection info given @param array $connectionInfo An array of connection info @return DatabaseInterface
[ "Gets", "a", "new", "connection", "using", "the", "connection", "info", "given" ]
train
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/database/AbstractMySQLDataSource.php#L52-L57
SlaxWeb/Config
src/XmlHandler.php
XmlHandler.load
public function load(string $config, bool $prependResourceName = false): int { // obtain absolute path to configuration resource if (($config = $this->_getAbsPath($config)) === "") { return static::CONFIG_RESOURCE_NOT_FOUND; } $configContents = file_get_contents($config); if (($configuration = $this->_xml->processConvert($configContents)) === []) { return static::CONFIG_PARSE_ERROR; } if ($prependResourceName === true) { $filename = basename($config, ".xml"); $configuration = $this->prependResourceName( $configuration, $filename ); } $this->_configValues = array_merge_recursive( $this->_configValues, $configuration ); return static::CONFIG_LOADED; }
php
public function load(string $config, bool $prependResourceName = false): int { // obtain absolute path to configuration resource if (($config = $this->_getAbsPath($config)) === "") { return static::CONFIG_RESOURCE_NOT_FOUND; } $configContents = file_get_contents($config); if (($configuration = $this->_xml->processConvert($configContents)) === []) { return static::CONFIG_PARSE_ERROR; } if ($prependResourceName === true) { $filename = basename($config, ".xml"); $configuration = $this->prependResourceName( $configuration, $filename ); } $this->_configValues = array_merge_recursive( $this->_configValues, $configuration ); return static::CONFIG_LOADED; }
[ "public", "function", "load", "(", "string", "$", "config", ",", "bool", "$", "prependResourceName", "=", "false", ")", ":", "int", "{", "// obtain absolute path to configuration resource", "if", "(", "(", "$", "config", "=", "$", "this", "->", "_getAbsPath", "(", "$", "config", ")", ")", "===", "\"\"", ")", "{", "return", "static", "::", "CONFIG_RESOURCE_NOT_FOUND", ";", "}", "$", "configContents", "=", "file_get_contents", "(", "$", "config", ")", ";", "if", "(", "(", "$", "configuration", "=", "$", "this", "->", "_xml", "->", "processConvert", "(", "$", "configContents", ")", ")", "===", "[", "]", ")", "{", "return", "static", "::", "CONFIG_PARSE_ERROR", ";", "}", "if", "(", "$", "prependResourceName", "===", "true", ")", "{", "$", "filename", "=", "basename", "(", "$", "config", ",", "\".xml\"", ")", ";", "$", "configuration", "=", "$", "this", "->", "prependResourceName", "(", "$", "configuration", ",", "$", "filename", ")", ";", "}", "$", "this", "->", "_configValues", "=", "array_merge_recursive", "(", "$", "this", "->", "_configValues", ",", "$", "configuration", ")", ";", "return", "static", "::", "CONFIG_LOADED", ";", "}" ]
Load the Config File Check if the file exists, load it, and parse the containing array into the the internal container array. Return 'CONFIG_LOADED' constant on success. If the file is not found, return 'CONFIG_RESOURCE_NOT_FOUND' constant, and 'CONFIG_PARSE_ERROR' if the contants could not have been parsed. @param string $config Path to the config resource @param bool $prependResourceName If the resource name should be prepended to each config key @return int
[ "Load", "the", "Config", "File" ]
train
https://github.com/SlaxWeb/Config/blob/92e75c3538d3903e00f5c52507bc0a322c4d1f11/src/XmlHandler.php#L55-L82
LpFactory/NestedSetRoutingBundle
Configuration/AbstractPageRouteConfiguration.php
AbstractPageRouteConfiguration.isMatching
public function isMatching($url) { if ($this->getRegex() === null) { return true; } if (preg_match($this->getRegex(), $url)) { return true; } return false; }
php
public function isMatching($url) { if ($this->getRegex() === null) { return true; } if (preg_match($this->getRegex(), $url)) { return true; } return false; }
[ "public", "function", "isMatching", "(", "$", "url", ")", "{", "if", "(", "$", "this", "->", "getRegex", "(", ")", "===", "null", ")", "{", "return", "true", ";", "}", "if", "(", "preg_match", "(", "$", "this", "->", "getRegex", "(", ")", ",", "$", "url", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Check if route configuration matches url @param string $url @return null|string
[ "Check", "if", "route", "configuration", "matches", "url" ]
train
https://github.com/LpFactory/NestedSetRoutingBundle/blob/dc07227a6764e657b7b321827a18127ec18ba214/Configuration/AbstractPageRouteConfiguration.php#L29-L40
LpFactory/NestedSetRoutingBundle
Configuration/AbstractPageRouteConfiguration.php
AbstractPageRouteConfiguration.extractPathInfo
public function extractPathInfo($pathInfo) { if ($this->getRegex() === null) { return $pathInfo; } preg_match($this->getRegex(), $pathInfo, $matches); if (isset($matches[1])) { return $matches[1]; } else { // Empty then root node ("/" or "/edit) return "/"; } }
php
public function extractPathInfo($pathInfo) { if ($this->getRegex() === null) { return $pathInfo; } preg_match($this->getRegex(), $pathInfo, $matches); if (isset($matches[1])) { return $matches[1]; } else { // Empty then root node ("/" or "/edit) return "/"; } }
[ "public", "function", "extractPathInfo", "(", "$", "pathInfo", ")", "{", "if", "(", "$", "this", "->", "getRegex", "(", ")", "===", "null", ")", "{", "return", "$", "pathInfo", ";", "}", "preg_match", "(", "$", "this", "->", "getRegex", "(", ")", ",", "$", "pathInfo", ",", "$", "matches", ")", ";", "if", "(", "isset", "(", "$", "matches", "[", "1", "]", ")", ")", "{", "return", "$", "matches", "[", "1", "]", ";", "}", "else", "{", "// Empty then root node (\"/\" or \"/edit)", "return", "\"/\"", ";", "}", "}" ]
Extract page pathinfo Call isMatching before to be sure regex matches @param $pathInfo @return string
[ "Extract", "page", "pathinfo", "Call", "isMatching", "before", "to", "be", "sure", "regex", "matches" ]
train
https://github.com/LpFactory/NestedSetRoutingBundle/blob/dc07227a6764e657b7b321827a18127ec18ba214/Configuration/AbstractPageRouteConfiguration.php#L50-L64
LpFactory/NestedSetRoutingBundle
Configuration/AbstractPageRouteConfiguration.php
AbstractPageRouteConfiguration.extractId
public function extractId($routeName) { if (!$this->supports($routeName)) { return null; } return (int) str_replace($this->getPrefix(), '', $routeName); }
php
public function extractId($routeName) { if (!$this->supports($routeName)) { return null; } return (int) str_replace($this->getPrefix(), '', $routeName); }
[ "public", "function", "extractId", "(", "$", "routeName", ")", "{", "if", "(", "!", "$", "this", "->", "supports", "(", "$", "routeName", ")", ")", "{", "return", "null", ";", "}", "return", "(", "int", ")", "str_replace", "(", "$", "this", "->", "getPrefix", "(", ")", ",", "''", ",", "$", "routeName", ")", ";", "}" ]
Extract a page id from the route name @param string $routeName @return int|null
[ "Extract", "a", "page", "id", "from", "the", "route", "name" ]
train
https://github.com/LpFactory/NestedSetRoutingBundle/blob/dc07227a6764e657b7b321827a18127ec18ba214/Configuration/AbstractPageRouteConfiguration.php#L85-L92
LpFactory/NestedSetRoutingBundle
Configuration/AbstractPageRouteConfiguration.php
AbstractPageRouteConfiguration.buildPath
public function buildPath($pathInfo) { if (null === $this->getPath()) { return $pathInfo; } return sprintf($this->getPath(), rtrim($pathInfo, '/')); }
php
public function buildPath($pathInfo) { if (null === $this->getPath()) { return $pathInfo; } return sprintf($this->getPath(), rtrim($pathInfo, '/')); }
[ "public", "function", "buildPath", "(", "$", "pathInfo", ")", "{", "if", "(", "null", "===", "$", "this", "->", "getPath", "(", ")", ")", "{", "return", "$", "pathInfo", ";", "}", "return", "sprintf", "(", "$", "this", "->", "getPath", "(", ")", ",", "rtrim", "(", "$", "pathInfo", ",", "'/'", ")", ")", ";", "}" ]
Build a path @param string $pathInfo @return string
[ "Build", "a", "path" ]
train
https://github.com/LpFactory/NestedSetRoutingBundle/blob/dc07227a6764e657b7b321827a18127ec18ba214/Configuration/AbstractPageRouteConfiguration.php#L101-L108
openWorkers/RedObject
src/RedObject/HashSet.php
HashSet.offsetGet
public function offsetGet($offset) { $output = $this->redis->hGet($this->key, $offset); return $this->ioHandler->handleOutput($output); }
php
public function offsetGet($offset) { $output = $this->redis->hGet($this->key, $offset); return $this->ioHandler->handleOutput($output); }
[ "public", "function", "offsetGet", "(", "$", "offset", ")", "{", "$", "output", "=", "$", "this", "->", "redis", "->", "hGet", "(", "$", "this", "->", "key", ",", "$", "offset", ")", ";", "return", "$", "this", "->", "ioHandler", "->", "handleOutput", "(", "$", "output", ")", ";", "}" ]
(PHP 5 &gt;= 5.0.0)<br/> Offset to retrieve @link http://php.net/manual/en/arrayaccess.offsetget.php @param mixed $offset <p> The offset to retrieve. </p> @return mixed Can return all value types.
[ "(", "PHP", "5", "&gt", ";", "=", "5", ".", "0", ".", "0", ")", "<br", "/", ">", "Offset", "to", "retrieve" ]
train
https://github.com/openWorkers/RedObject/blob/ce60d782352f97154294d7d200e7c87df80aa41a/src/RedObject/HashSet.php#L54-L58
openWorkers/RedObject
src/RedObject/HashSet.php
HashSet.offsetSet
public function offsetSet($offset, $value) { if ($offset === null) { $offset = uniqid('uid'); } if (is_string($value)) { $this->redis->hSet($this->key, $offset, "!".$value); } else { $this->redis->hSet($this->key, $offset, serialize($value)); } }
php
public function offsetSet($offset, $value) { if ($offset === null) { $offset = uniqid('uid'); } if (is_string($value)) { $this->redis->hSet($this->key, $offset, "!".$value); } else { $this->redis->hSet($this->key, $offset, serialize($value)); } }
[ "public", "function", "offsetSet", "(", "$", "offset", ",", "$", "value", ")", "{", "if", "(", "$", "offset", "===", "null", ")", "{", "$", "offset", "=", "uniqid", "(", "'uid'", ")", ";", "}", "if", "(", "is_string", "(", "$", "value", ")", ")", "{", "$", "this", "->", "redis", "->", "hSet", "(", "$", "this", "->", "key", ",", "$", "offset", ",", "\"!\"", ".", "$", "value", ")", ";", "}", "else", "{", "$", "this", "->", "redis", "->", "hSet", "(", "$", "this", "->", "key", ",", "$", "offset", ",", "serialize", "(", "$", "value", ")", ")", ";", "}", "}" ]
(PHP 5 &gt;= 5.0.0)<br/> Offset to set @link http://php.net/manual/en/arrayaccess.offsetset.php @param mixed $offset <p> The offset to assign the value to. </p> @param mixed $value <p> The value to set. </p> @return void
[ "(", "PHP", "5", "&gt", ";", "=", "5", ".", "0", ".", "0", ")", "<br", "/", ">", "Offset", "to", "set" ]
train
https://github.com/openWorkers/RedObject/blob/ce60d782352f97154294d7d200e7c87df80aa41a/src/RedObject/HashSet.php#L72-L82
openWorkers/RedObject
src/RedObject/HashSet.php
HashSet.toArray
public function toArray() { $keys = $this->redis->hKeys($this->key); $result = array(); foreach ($keys as $key) { $result[$key] = $this->offsetGet($key); } return $result; }
php
public function toArray() { $keys = $this->redis->hKeys($this->key); $result = array(); foreach ($keys as $key) { $result[$key] = $this->offsetGet($key); } return $result; }
[ "public", "function", "toArray", "(", ")", "{", "$", "keys", "=", "$", "this", "->", "redis", "->", "hKeys", "(", "$", "this", "->", "key", ")", ";", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "$", "result", "[", "$", "key", "]", "=", "$", "this", "->", "offsetGet", "(", "$", "key", ")", ";", "}", "return", "$", "result", ";", "}" ]
Converts the hashset to an php-array @return array
[ "Converts", "the", "hashset", "to", "an", "php", "-", "array" ]
train
https://github.com/openWorkers/RedObject/blob/ce60d782352f97154294d7d200e7c87df80aa41a/src/RedObject/HashSet.php#L114-L122
fond-of/spryker-companies-rest-api
src/FondOfSpryker/Glue/CompaniesRestApi/Controller/CompaniesResourceController.php
CompaniesResourceController.postAction
public function postAction( RestRequestInterface $restRequest, RestCompaniesRequestAttributesTransfer $restCompaniesRequestAttributesTransfer ): RestResponseInterface { return $this->getFactory()->createCompaniesWriter() ->createCompany($restRequest, $restCompaniesRequestAttributesTransfer); }
php
public function postAction( RestRequestInterface $restRequest, RestCompaniesRequestAttributesTransfer $restCompaniesRequestAttributesTransfer ): RestResponseInterface { return $this->getFactory()->createCompaniesWriter() ->createCompany($restRequest, $restCompaniesRequestAttributesTransfer); }
[ "public", "function", "postAction", "(", "RestRequestInterface", "$", "restRequest", ",", "RestCompaniesRequestAttributesTransfer", "$", "restCompaniesRequestAttributesTransfer", ")", ":", "RestResponseInterface", "{", "return", "$", "this", "->", "getFactory", "(", ")", "->", "createCompaniesWriter", "(", ")", "->", "createCompany", "(", "$", "restRequest", ",", "$", "restCompaniesRequestAttributesTransfer", ")", ";", "}" ]
@param \Spryker\Glue\GlueApplication\Rest\Request\Data\RestRequestInterface $restRequest @param \Generated\Shared\Transfer\RestCompaniesRequestAttributesTransfer $restCompaniesRequestAttributesTransfer @return \Spryker\Glue\GlueApplication\Rest\JsonApi\RestResponseInterface
[ "@param", "\\", "Spryker", "\\", "Glue", "\\", "GlueApplication", "\\", "Rest", "\\", "Request", "\\", "Data", "\\", "RestRequestInterface", "$restRequest", "@param", "\\", "Generated", "\\", "Shared", "\\", "Transfer", "\\", "RestCompaniesRequestAttributesTransfer", "$restCompaniesRequestAttributesTransfer" ]
train
https://github.com/fond-of/spryker-companies-rest-api/blob/0df688aa37cd6d18f90ac2af0a1cbc39357d94d7/src/FondOfSpryker/Glue/CompaniesRestApi/Controller/CompaniesResourceController.php#L32-L38
fond-of/spryker-companies-rest-api
src/FondOfSpryker/Glue/CompaniesRestApi/Controller/CompaniesResourceController.php
CompaniesResourceController.patchAction
public function patchAction( RestRequestInterface $restRequest, RestCompaniesRequestAttributesTransfer $restCompaniesRequestAttributesTransfer ): RestResponseInterface { return $this->getFactory()->createCompaniesWriter() ->updateCompany($restRequest, $restCompaniesRequestAttributesTransfer); }
php
public function patchAction( RestRequestInterface $restRequest, RestCompaniesRequestAttributesTransfer $restCompaniesRequestAttributesTransfer ): RestResponseInterface { return $this->getFactory()->createCompaniesWriter() ->updateCompany($restRequest, $restCompaniesRequestAttributesTransfer); }
[ "public", "function", "patchAction", "(", "RestRequestInterface", "$", "restRequest", ",", "RestCompaniesRequestAttributesTransfer", "$", "restCompaniesRequestAttributesTransfer", ")", ":", "RestResponseInterface", "{", "return", "$", "this", "->", "getFactory", "(", ")", "->", "createCompaniesWriter", "(", ")", "->", "updateCompany", "(", "$", "restRequest", ",", "$", "restCompaniesRequestAttributesTransfer", ")", ";", "}" ]
@param \Spryker\Glue\GlueApplication\Rest\Request\Data\RestRequestInterface $restRequest @param \Generated\Shared\Transfer\RestCompaniesRequestAttributesTransfer $restCompaniesRequestAttributesTransfer @return \Spryker\Glue\GlueApplication\Rest\JsonApi\RestResponseInterface
[ "@param", "\\", "Spryker", "\\", "Glue", "\\", "GlueApplication", "\\", "Rest", "\\", "Request", "\\", "Data", "\\", "RestRequestInterface", "$restRequest", "@param", "\\", "Generated", "\\", "Shared", "\\", "Transfer", "\\", "RestCompaniesRequestAttributesTransfer", "$restCompaniesRequestAttributesTransfer" ]
train
https://github.com/fond-of/spryker-companies-rest-api/blob/0df688aa37cd6d18f90ac2af0a1cbc39357d94d7/src/FondOfSpryker/Glue/CompaniesRestApi/Controller/CompaniesResourceController.php#L46-L52
Vectrex/vxPHP
src/Http/Response.php
Response.sendHeaders
public function sendHeaders() { // headers have already been sent by the developer if (headers_sent()) { return $this; } if (!$this->headers->has('Date')) { $this->setDate(\DateTime::createFromFormat('U', time())); } // headers foreach ($this->headers->allPreserveCase() as $name => $values) { foreach ($values as $value) { header($name . ': ' . $value, FALSE); } } // status header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText), TRUE, $this->statusCode); // cookies foreach ($this->headers->getCookies() as $cookie) { setcookie($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly()); } return $this; }
php
public function sendHeaders() { // headers have already been sent by the developer if (headers_sent()) { return $this; } if (!$this->headers->has('Date')) { $this->setDate(\DateTime::createFromFormat('U', time())); } // headers foreach ($this->headers->allPreserveCase() as $name => $values) { foreach ($values as $value) { header($name . ': ' . $value, FALSE); } } // status header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText), TRUE, $this->statusCode); // cookies foreach ($this->headers->getCookies() as $cookie) { setcookie($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly()); } return $this; }
[ "public", "function", "sendHeaders", "(", ")", "{", "// headers have already been sent by the developer", "if", "(", "headers_sent", "(", ")", ")", "{", "return", "$", "this", ";", "}", "if", "(", "!", "$", "this", "->", "headers", "->", "has", "(", "'Date'", ")", ")", "{", "$", "this", "->", "setDate", "(", "\\", "DateTime", "::", "createFromFormat", "(", "'U'", ",", "time", "(", ")", ")", ")", ";", "}", "// headers", "foreach", "(", "$", "this", "->", "headers", "->", "allPreserveCase", "(", ")", "as", "$", "name", "=>", "$", "values", ")", "{", "foreach", "(", "$", "values", "as", "$", "value", ")", "{", "header", "(", "$", "name", ".", "': '", ".", "$", "value", ",", "FALSE", ")", ";", "}", "}", "// status", "header", "(", "sprintf", "(", "'HTTP/%s %s %s'", ",", "$", "this", "->", "version", ",", "$", "this", "->", "statusCode", ",", "$", "this", "->", "statusText", ")", ",", "TRUE", ",", "$", "this", "->", "statusCode", ")", ";", "// cookies", "foreach", "(", "$", "this", "->", "headers", "->", "getCookies", "(", ")", "as", "$", "cookie", ")", "{", "setcookie", "(", "$", "cookie", "->", "getName", "(", ")", ",", "$", "cookie", "->", "getValue", "(", ")", ",", "$", "cookie", "->", "getExpiresTime", "(", ")", ",", "$", "cookie", "->", "getPath", "(", ")", ",", "$", "cookie", "->", "getDomain", "(", ")", ",", "$", "cookie", "->", "isSecure", "(", ")", ",", "$", "cookie", "->", "isHttpOnly", "(", ")", ")", ";", "}", "return", "$", "this", ";", "}" ]
Sends HTTP headers. @return Response
[ "Sends", "HTTP", "headers", "." ]
train
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Http/Response.php#L347-L378
Vectrex/vxPHP
src/Http/Response.php
Response.isCacheable
public function isCacheable() { if (!in_array( $this->statusCode, [ self::HTTP_OK, self::HTTP_NON_AUTHORITATIVE_INFORMATION, self::HTTP_MULTIPLE_CHOICES, self::HTTP_MOVED_PERMANENTLY, self::HTTP_FOUND, self::HTTP_NOT_FOUND, self::HTTP_GONE ] )) { return FALSE; } if ($this->headers->hasCacheControlDirective('no-store') || $this->headers->getCacheControlDirective('private')) { return FALSE; } return $this->isValidateable() || $this->isFresh(); }
php
public function isCacheable() { if (!in_array( $this->statusCode, [ self::HTTP_OK, self::HTTP_NON_AUTHORITATIVE_INFORMATION, self::HTTP_MULTIPLE_CHOICES, self::HTTP_MOVED_PERMANENTLY, self::HTTP_FOUND, self::HTTP_NOT_FOUND, self::HTTP_GONE ] )) { return FALSE; } if ($this->headers->hasCacheControlDirective('no-store') || $this->headers->getCacheControlDirective('private')) { return FALSE; } return $this->isValidateable() || $this->isFresh(); }
[ "public", "function", "isCacheable", "(", ")", "{", "if", "(", "!", "in_array", "(", "$", "this", "->", "statusCode", ",", "[", "self", "::", "HTTP_OK", ",", "self", "::", "HTTP_NON_AUTHORITATIVE_INFORMATION", ",", "self", "::", "HTTP_MULTIPLE_CHOICES", ",", "self", "::", "HTTP_MOVED_PERMANENTLY", ",", "self", "::", "HTTP_FOUND", ",", "self", "::", "HTTP_NOT_FOUND", ",", "self", "::", "HTTP_GONE", "]", ")", ")", "{", "return", "FALSE", ";", "}", "if", "(", "$", "this", "->", "headers", "->", "hasCacheControlDirective", "(", "'no-store'", ")", "||", "$", "this", "->", "headers", "->", "getCacheControlDirective", "(", "'private'", ")", ")", "{", "return", "FALSE", ";", "}", "return", "$", "this", "->", "isValidateable", "(", ")", "||", "$", "this", "->", "isFresh", "(", ")", ";", "}" ]
Returns true if the response is worth caching under any circumstance. Responses marked "private" with an explicit Cache-Control directive are considered uncacheable. Responses with neither a freshness lifetime (Expires, max-age) nor cache validator (Last-Modified, ETag) are considered uncacheable. @return Boolean true if the response is worth caching, false otherwise
[ "Returns", "true", "if", "the", "response", "is", "worth", "caching", "under", "any", "circumstance", "." ]
train
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Http/Response.php#L552-L575
Vectrex/vxPHP
src/Http/Response.php
Response.getMaxAge
public function getMaxAge() { if ($this->headers->hasCacheControlDirective('s-maxage')) { return (int) $this->headers->getCacheControlDirective('s-maxage'); } if ($this->headers->hasCacheControlDirective('max-age')) { return (int) $this->headers->getCacheControlDirective('max-age'); } if (NULL !== $this->getExpires()) { return $this->getExpires()->format('U') - $this->getDate()->format('U'); } return NULL; }
php
public function getMaxAge() { if ($this->headers->hasCacheControlDirective('s-maxage')) { return (int) $this->headers->getCacheControlDirective('s-maxage'); } if ($this->headers->hasCacheControlDirective('max-age')) { return (int) $this->headers->getCacheControlDirective('max-age'); } if (NULL !== $this->getExpires()) { return $this->getExpires()->format('U') - $this->getDate()->format('U'); } return NULL; }
[ "public", "function", "getMaxAge", "(", ")", "{", "if", "(", "$", "this", "->", "headers", "->", "hasCacheControlDirective", "(", "'s-maxage'", ")", ")", "{", "return", "(", "int", ")", "$", "this", "->", "headers", "->", "getCacheControlDirective", "(", "'s-maxage'", ")", ";", "}", "if", "(", "$", "this", "->", "headers", "->", "hasCacheControlDirective", "(", "'max-age'", ")", ")", "{", "return", "(", "int", ")", "$", "this", "->", "headers", "->", "getCacheControlDirective", "(", "'max-age'", ")", ";", "}", "if", "(", "NULL", "!==", "$", "this", "->", "getExpires", "(", ")", ")", "{", "return", "$", "this", "->", "getExpires", "(", ")", "->", "format", "(", "'U'", ")", "-", "$", "this", "->", "getDate", "(", ")", "->", "format", "(", "'U'", ")", ";", "}", "return", "NULL", ";", "}" ]
Returns the number of seconds after the time specified in the response's Date header when the response should no longer be considered fresh. First, it checks for a s-maxage directive, then a max-age directive, and then it falls back on an expires header. It returns null when no maximum age can be established. @return integer|null Number of seconds
[ "Returns", "the", "number", "of", "seconds", "after", "the", "time", "specified", "in", "the", "response", "s", "Date", "header", "when", "the", "response", "should", "no", "longer", "be", "considered", "fresh", ".", "First", "it", "checks", "for", "a", "s", "-", "maxage", "directive", "then", "a", "max", "-", "age", "directive", "and", "then", "it", "falls", "back", "on", "an", "expires", "header", ".", "It", "returns", "null", "when", "no", "maximum", "age", "can", "be", "established", "." ]
train
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Http/Response.php#L758-L774
Vectrex/vxPHP
src/Http/Response.php
Response.setEtag
public function setEtag($etag = NULL, $weak = FALSE) { if (NULL === $etag) { $this->headers->remove('Etag'); } else { if (0 !== strpos($etag, '"')) { $etag = '"' . $etag . '"'; } $this->headers->set('ETag', (TRUE === $weak ? 'W/' : '') . $etag); } return $this; }
php
public function setEtag($etag = NULL, $weak = FALSE) { if (NULL === $etag) { $this->headers->remove('Etag'); } else { if (0 !== strpos($etag, '"')) { $etag = '"' . $etag . '"'; } $this->headers->set('ETag', (TRUE === $weak ? 'W/' : '') . $etag); } return $this; }
[ "public", "function", "setEtag", "(", "$", "etag", "=", "NULL", ",", "$", "weak", "=", "FALSE", ")", "{", "if", "(", "NULL", "===", "$", "etag", ")", "{", "$", "this", "->", "headers", "->", "remove", "(", "'Etag'", ")", ";", "}", "else", "{", "if", "(", "0", "!==", "strpos", "(", "$", "etag", ",", "'\"'", ")", ")", "{", "$", "etag", "=", "'\"'", ".", "$", "etag", ".", "'\"'", ";", "}", "$", "this", "->", "headers", "->", "set", "(", "'ETag'", ",", "(", "TRUE", "===", "$", "weak", "?", "'W/'", ":", "''", ")", ".", "$", "etag", ")", ";", "}", "return", "$", "this", ";", "}" ]
Sets the ETag value. @param string|null $etag The ETag unique identifier or null to remove the header @param Boolean $weak Whether you want a weak ETag or not @return Response
[ "Sets", "the", "ETag", "value", "." ]
train
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Http/Response.php#L901-L917
Vectrex/vxPHP
src/Http/Response.php
Response.setCache
public function setCache(array $options) { if ($diff = array_diff(array_keys($options), ['etag', 'last_modified', 'max_age', 's_maxage', 'private', 'public'])) { throw new \InvalidArgumentException(sprintf('Response does not support the following options: "%s".', implode('", "', array_values($diff)))); } if (isset($options['etag'])) { $this->setEtag($options['etag']); } if (isset($options['last_modified'])) { $this->setLastModified($options['last_modified']); } if (isset($options['max_age'])) { $this->setMaxAge($options['max_age']); } if (isset($options['s_maxage'])) { $this->setSharedMaxAge($options['s_maxage']); } if (isset($options['public'])) { if ($options['public']) { $this->setPublic(); } else { $this->setPrivate(); } } if (isset($options['private'])) { if ($options['private']) { $this->setPrivate(); } else { $this->setPublic(); } } return $this; }
php
public function setCache(array $options) { if ($diff = array_diff(array_keys($options), ['etag', 'last_modified', 'max_age', 's_maxage', 'private', 'public'])) { throw new \InvalidArgumentException(sprintf('Response does not support the following options: "%s".', implode('", "', array_values($diff)))); } if (isset($options['etag'])) { $this->setEtag($options['etag']); } if (isset($options['last_modified'])) { $this->setLastModified($options['last_modified']); } if (isset($options['max_age'])) { $this->setMaxAge($options['max_age']); } if (isset($options['s_maxage'])) { $this->setSharedMaxAge($options['s_maxage']); } if (isset($options['public'])) { if ($options['public']) { $this->setPublic(); } else { $this->setPrivate(); } } if (isset($options['private'])) { if ($options['private']) { $this->setPrivate(); } else { $this->setPublic(); } } return $this; }
[ "public", "function", "setCache", "(", "array", "$", "options", ")", "{", "if", "(", "$", "diff", "=", "array_diff", "(", "array_keys", "(", "$", "options", ")", ",", "[", "'etag'", ",", "'last_modified'", ",", "'max_age'", ",", "'s_maxage'", ",", "'private'", ",", "'public'", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Response does not support the following options: \"%s\".'", ",", "implode", "(", "'\", \"'", ",", "array_values", "(", "$", "diff", ")", ")", ")", ")", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'etag'", "]", ")", ")", "{", "$", "this", "->", "setEtag", "(", "$", "options", "[", "'etag'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'last_modified'", "]", ")", ")", "{", "$", "this", "->", "setLastModified", "(", "$", "options", "[", "'last_modified'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'max_age'", "]", ")", ")", "{", "$", "this", "->", "setMaxAge", "(", "$", "options", "[", "'max_age'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'s_maxage'", "]", ")", ")", "{", "$", "this", "->", "setSharedMaxAge", "(", "$", "options", "[", "'s_maxage'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'public'", "]", ")", ")", "{", "if", "(", "$", "options", "[", "'public'", "]", ")", "{", "$", "this", "->", "setPublic", "(", ")", ";", "}", "else", "{", "$", "this", "->", "setPrivate", "(", ")", ";", "}", "}", "if", "(", "isset", "(", "$", "options", "[", "'private'", "]", ")", ")", "{", "if", "(", "$", "options", "[", "'private'", "]", ")", "{", "$", "this", "->", "setPrivate", "(", ")", ";", "}", "else", "{", "$", "this", "->", "setPublic", "(", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Sets the response's cache headers (validation and/or expiration). Available options are: etag, last_modified, max_age, s_maxage, private, and public. @param array $options An array of cache options @return Response @throws \InvalidArgumentException
[ "Sets", "the", "response", "s", "cache", "headers", "(", "validation", "and", "/", "or", "expiration", ")", ".", "Available", "options", "are", ":", "etag", "last_modified", "max_age", "s_maxage", "private", "and", "public", "." ]
train
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Http/Response.php#L928-L966
Vectrex/vxPHP
src/Http/Response.php
Response.setNotModified
public function setNotModified() { $this->setStatusCode(self::HTTP_NOT_MODIFIED); $this->setContent(NULL); // remove headers that MUST NOT be included with 304 Not Modified responses foreach (['Allow', 'Content-Encoding', 'Content-Language', 'Content-Length', 'Content-MD5', 'Content-Type', 'Last-Modified'] as $header) { $this->headers->remove($header); } return $this; }
php
public function setNotModified() { $this->setStatusCode(self::HTTP_NOT_MODIFIED); $this->setContent(NULL); // remove headers that MUST NOT be included with 304 Not Modified responses foreach (['Allow', 'Content-Encoding', 'Content-Language', 'Content-Length', 'Content-MD5', 'Content-Type', 'Last-Modified'] as $header) { $this->headers->remove($header); } return $this; }
[ "public", "function", "setNotModified", "(", ")", "{", "$", "this", "->", "setStatusCode", "(", "self", "::", "HTTP_NOT_MODIFIED", ")", ";", "$", "this", "->", "setContent", "(", "NULL", ")", ";", "// remove headers that MUST NOT be included with 304 Not Modified responses", "foreach", "(", "[", "'Allow'", ",", "'Content-Encoding'", ",", "'Content-Language'", ",", "'Content-Length'", ",", "'Content-MD5'", ",", "'Content-Type'", ",", "'Last-Modified'", "]", "as", "$", "header", ")", "{", "$", "this", "->", "headers", "->", "remove", "(", "$", "header", ")", ";", "}", "return", "$", "this", ";", "}" ]
Modifies the response so that it conforms to the rules defined for a 304 status code. This sets the status, removes the body, and discards any headers that MUST NOT be included in 304 responses. @return Response @see http://tools.ietf.org/html/rfc2616#section-10.3.5
[ "Modifies", "the", "response", "so", "that", "it", "conforms", "to", "the", "rules", "defined", "for", "a", "304", "status", "code", ".", "This", "sets", "the", "status", "removes", "the", "body", "and", "discards", "any", "headers", "that", "MUST", "NOT", "be", "included", "in", "304", "responses", "." ]
train
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Http/Response.php#L977-L990
Vectrex/vxPHP
src/Http/Response.php
Response.getVary
public function getVary() { if (!$vary = $this->headers->get('Vary', NULL, FALSE)) { return []; } $ret = []; foreach ($vary as $item) { $ret = array_merge($ret, preg_split('/[\s,]+/', $item)); } return $ret; }
php
public function getVary() { if (!$vary = $this->headers->get('Vary', NULL, FALSE)) { return []; } $ret = []; foreach ($vary as $item) { $ret = array_merge($ret, preg_split('/[\s,]+/', $item)); } return $ret; }
[ "public", "function", "getVary", "(", ")", "{", "if", "(", "!", "$", "vary", "=", "$", "this", "->", "headers", "->", "get", "(", "'Vary'", ",", "NULL", ",", "FALSE", ")", ")", "{", "return", "[", "]", ";", "}", "$", "ret", "=", "[", "]", ";", "foreach", "(", "$", "vary", "as", "$", "item", ")", "{", "$", "ret", "=", "array_merge", "(", "$", "ret", ",", "preg_split", "(", "'/[\\s,]+/'", ",", "$", "item", ")", ")", ";", "}", "return", "$", "ret", ";", "}" ]
Returns an array of header names given in the Vary header. @return array An array of Vary names
[ "Returns", "an", "array", "of", "header", "names", "given", "in", "the", "Vary", "header", "." ]
train
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Http/Response.php#L1008-L1021
Vectrex/vxPHP
src/Http/Response.php
Response.setVary
public function setVary($headers, $replace = TRUE) { $this->headers->set('Vary', $headers, $replace); return $this; }
php
public function setVary($headers, $replace = TRUE) { $this->headers->set('Vary', $headers, $replace); return $this; }
[ "public", "function", "setVary", "(", "$", "headers", ",", "$", "replace", "=", "TRUE", ")", "{", "$", "this", "->", "headers", "->", "set", "(", "'Vary'", ",", "$", "headers", ",", "$", "replace", ")", ";", "return", "$", "this", ";", "}" ]
Sets the Vary header. @param string|array $headers @param Boolean $replace Whether to replace the actual value of not (true by default) @return Response
[ "Sets", "the", "Vary", "header", "." ]
train
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Http/Response.php#L1030-L1035
Vectrex/vxPHP
src/Http/Response.php
Response.isNotModified
public function isNotModified(Request $request) { if (!$request->isMethodSafe()) { return FALSE; } $lastModified = $request->headers->get('If-Modified-Since'); $modifiedSince = $request->headers->get('If-Modified-Since'); $notModified = FALSE; if ($etags = $request->getETags()) { $notModified = in_array($this->getEtag(), $etags) || in_array('*', $etags); } if ($modifiedSince && $lastModified) { $notModified = strtotime($modifiedSince) >= strtotime($lastModified) && (!$etags || $notModified); } if ($notModified) { $this->setNotModified(); } return $notModified; }
php
public function isNotModified(Request $request) { if (!$request->isMethodSafe()) { return FALSE; } $lastModified = $request->headers->get('If-Modified-Since'); $modifiedSince = $request->headers->get('If-Modified-Since'); $notModified = FALSE; if ($etags = $request->getETags()) { $notModified = in_array($this->getEtag(), $etags) || in_array('*', $etags); } if ($modifiedSince && $lastModified) { $notModified = strtotime($modifiedSince) >= strtotime($lastModified) && (!$etags || $notModified); } if ($notModified) { $this->setNotModified(); } return $notModified; }
[ "public", "function", "isNotModified", "(", "Request", "$", "request", ")", "{", "if", "(", "!", "$", "request", "->", "isMethodSafe", "(", ")", ")", "{", "return", "FALSE", ";", "}", "$", "lastModified", "=", "$", "request", "->", "headers", "->", "get", "(", "'If-Modified-Since'", ")", ";", "$", "modifiedSince", "=", "$", "request", "->", "headers", "->", "get", "(", "'If-Modified-Since'", ")", ";", "$", "notModified", "=", "FALSE", ";", "if", "(", "$", "etags", "=", "$", "request", "->", "getETags", "(", ")", ")", "{", "$", "notModified", "=", "in_array", "(", "$", "this", "->", "getEtag", "(", ")", ",", "$", "etags", ")", "||", "in_array", "(", "'*'", ",", "$", "etags", ")", ";", "}", "if", "(", "$", "modifiedSince", "&&", "$", "lastModified", ")", "{", "$", "notModified", "=", "strtotime", "(", "$", "modifiedSince", ")", ">=", "strtotime", "(", "$", "lastModified", ")", "&&", "(", "!", "$", "etags", "||", "$", "notModified", ")", ";", "}", "if", "(", "$", "notModified", ")", "{", "$", "this", "->", "setNotModified", "(", ")", ";", "}", "return", "$", "notModified", ";", "}" ]
Determines if the Response validators (ETag, Last-Modified) match a conditional value specified in the Request. If the Response is not modified, it sets the status code to 304 and removes the actual content by calling the setNotModified() method. @param Request $request A Request instance @return Boolean true if the Response validators match the Request, false otherwise
[ "Determines", "if", "the", "Response", "validators", "(", "ETag", "Last", "-", "Modified", ")", "match", "a", "conditional", "value", "specified", "in", "the", "Request", ".", "If", "the", "Response", "is", "not", "modified", "it", "sets", "the", "status", "code", "to", "304", "and", "removes", "the", "actual", "content", "by", "calling", "the", "setNotModified", "()", "method", "." ]
train
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Http/Response.php#L1046-L1068
Vectrex/vxPHP
src/Http/Response.php
Response.isRedirect
public function isRedirect($location = NULL) { return in_array( $this->statusCode, [ self::HTTP_CREATED, self::HTTP_MOVED_PERMANENTLY, self::HTTP_FOUND, self::HTTP_SEE_OTHER, self::HTTP_TEMPORARY_REDIRECT, self::HTTP_PERMANENTLY_REDIRECT ] ) && (NULL === $location ?: $location == $this->headers->get('Location')); }
php
public function isRedirect($location = NULL) { return in_array( $this->statusCode, [ self::HTTP_CREATED, self::HTTP_MOVED_PERMANENTLY, self::HTTP_FOUND, self::HTTP_SEE_OTHER, self::HTTP_TEMPORARY_REDIRECT, self::HTTP_PERMANENTLY_REDIRECT ] ) && (NULL === $location ?: $location == $this->headers->get('Location')); }
[ "public", "function", "isRedirect", "(", "$", "location", "=", "NULL", ")", "{", "return", "in_array", "(", "$", "this", "->", "statusCode", ",", "[", "self", "::", "HTTP_CREATED", ",", "self", "::", "HTTP_MOVED_PERMANENTLY", ",", "self", "::", "HTTP_FOUND", ",", "self", "::", "HTTP_SEE_OTHER", ",", "self", "::", "HTTP_TEMPORARY_REDIRECT", ",", "self", "::", "HTTP_PERMANENTLY_REDIRECT", "]", ")", "&&", "(", "NULL", "===", "$", "location", "?", ":", "$", "location", "==", "$", "this", "->", "headers", "->", "get", "(", "'Location'", ")", ")", ";", "}" ]
Is the response a redirect of some form? @param string $location @return Boolean
[ "Is", "the", "response", "a", "redirect", "of", "some", "form?" ]
train
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Http/Response.php#L1176-L1190
Vectrex/vxPHP
src/Http/Response.php
Response.ensureIEOverSSLCompatibility
protected function ensureIEOverSSLCompatibility(Request $request) { if ( FALSE !== stripos($this->headers->get('Content-Disposition'), 'attachment') && preg_match('/MSIE (.*?);/i', $request->server->get('HTTP_USER_AGENT'), $match) == 1 && TRUE === $request->isSecure() ) { if (intval(preg_replace('/(MSIE )(.*?);/', '$2', $match[0])) < 9) { $this->headers->remove('Cache-Control'); } } }
php
protected function ensureIEOverSSLCompatibility(Request $request) { if ( FALSE !== stripos($this->headers->get('Content-Disposition'), 'attachment') && preg_match('/MSIE (.*?);/i', $request->server->get('HTTP_USER_AGENT'), $match) == 1 && TRUE === $request->isSecure() ) { if (intval(preg_replace('/(MSIE )(.*?);/', '$2', $match[0])) < 9) { $this->headers->remove('Cache-Control'); } } }
[ "protected", "function", "ensureIEOverSSLCompatibility", "(", "Request", "$", "request", ")", "{", "if", "(", "FALSE", "!==", "stripos", "(", "$", "this", "->", "headers", "->", "get", "(", "'Content-Disposition'", ")", ",", "'attachment'", ")", "&&", "preg_match", "(", "'/MSIE (.*?);/i'", ",", "$", "request", "->", "server", "->", "get", "(", "'HTTP_USER_AGENT'", ")", ",", "$", "match", ")", "==", "1", "&&", "TRUE", "===", "$", "request", "->", "isSecure", "(", ")", ")", "{", "if", "(", "intval", "(", "preg_replace", "(", "'/(MSIE )(.*?);/'", ",", "'$2'", ",", "$", "match", "[", "0", "]", ")", ")", "<", "9", ")", "{", "$", "this", "->", "headers", "->", "remove", "(", "'Cache-Control'", ")", ";", "}", "}", "}" ]
Check if we need to remove Cache-Control for ssl encrypted downloads when using IE < 9 @link http://support.microsoft.com/kb/323308
[ "Check", "if", "we", "need", "to", "remove", "Cache", "-", "Control", "for", "ssl", "encrypted", "downloads", "when", "using", "IE", "<", "9" ]
train
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Http/Response.php#L1235-L1247
netbull/CoreBundle
Utils/PDFLabelFormat.php
PDFLabelFormat.setOptions
public function setOptions( array $options ) { foreach ( $this->defaults as $option => $defaults ) { $this->values[$option] = ( array_key_exists($defaults['name'], $options) ) ? $options[$option] : $defaults['default']; } }
php
public function setOptions( array $options ) { foreach ( $this->defaults as $option => $defaults ) { $this->values[$option] = ( array_key_exists($defaults['name'], $options) ) ? $options[$option] : $defaults['default']; } }
[ "public", "function", "setOptions", "(", "array", "$", "options", ")", "{", "foreach", "(", "$", "this", "->", "defaults", "as", "$", "option", "=>", "$", "defaults", ")", "{", "$", "this", "->", "values", "[", "$", "option", "]", "=", "(", "array_key_exists", "(", "$", "defaults", "[", "'name'", "]", ",", "$", "options", ")", ")", "?", "$", "options", "[", "$", "option", "]", ":", "$", "defaults", "[", "'default'", "]", ";", "}", "}" ]
Set options @param array $options
[ "Set", "options" ]
train
https://github.com/netbull/CoreBundle/blob/0bacc1d9e4733b6da613027400c48421e5a14645/Utils/PDFLabelFormat.php#L145-L150
netbull/CoreBundle
Utils/PDFLabelFormat.php
PDFLabelFormat.getValue
public function getValue( $field, $default = null ) { if ( array_key_exists($field, $this->defaults) ){ switch ($this->defaults[$field]['type']) { case self::TYPE_INT: return (int) $this->values[$field]; case self::TYPE_FLOAT: // Round float values to three decimal places and trim trailing zeros. // Add a leading zero to values less than 1. $f = sprintf('%05.3f', $this->values[$field]); $f = rtrim($f, '0'); $f = rtrim($f, '.'); return (float) (empty($f) ? '0' : $f); } return $this->values[$field]; } return $default; }
php
public function getValue( $field, $default = null ) { if ( array_key_exists($field, $this->defaults) ){ switch ($this->defaults[$field]['type']) { case self::TYPE_INT: return (int) $this->values[$field]; case self::TYPE_FLOAT: // Round float values to three decimal places and trim trailing zeros. // Add a leading zero to values less than 1. $f = sprintf('%05.3f', $this->values[$field]); $f = rtrim($f, '0'); $f = rtrim($f, '.'); return (float) (empty($f) ? '0' : $f); } return $this->values[$field]; } return $default; }
[ "public", "function", "getValue", "(", "$", "field", ",", "$", "default", "=", "null", ")", "{", "if", "(", "array_key_exists", "(", "$", "field", ",", "$", "this", "->", "defaults", ")", ")", "{", "switch", "(", "$", "this", "->", "defaults", "[", "$", "field", "]", "[", "'type'", "]", ")", "{", "case", "self", "::", "TYPE_INT", ":", "return", "(", "int", ")", "$", "this", "->", "values", "[", "$", "field", "]", ";", "case", "self", "::", "TYPE_FLOAT", ":", "// Round float values to three decimal places and trim trailing zeros.", "// Add a leading zero to values less than 1.", "$", "f", "=", "sprintf", "(", "'%05.3f'", ",", "$", "this", "->", "values", "[", "$", "field", "]", ")", ";", "$", "f", "=", "rtrim", "(", "$", "f", ",", "'0'", ")", ";", "$", "f", "=", "rtrim", "(", "$", "f", ",", "'.'", ")", ";", "return", "(", "float", ")", "(", "empty", "(", "$", "f", ")", "?", "'0'", ":", "$", "f", ")", ";", "}", "return", "$", "this", "->", "values", "[", "$", "field", "]", ";", "}", "return", "$", "default", ";", "}" ]
Get Label Format field from associative array. @param string $field Name of a label format field. @param null|string $default @return float|int|mixed|null
[ "Get", "Label", "Format", "field", "from", "associative", "array", "." ]
train
https://github.com/netbull/CoreBundle/blob/0bacc1d9e4733b6da613027400c48421e5a14645/Utils/PDFLabelFormat.php#L159-L176
netbull/CoreBundle
Utils/PDFLabelFormat.php
PDFLabelFormat.isMetric
public function isMetric( $field ) { if ( array_key_exists($field, $this->defaults) ){ return ( isset($this->defaults[$field]['metric']) ) ? $this->defaults[$field]['metric'] : false; } return false; }
php
public function isMetric( $field ) { if ( array_key_exists($field, $this->defaults) ){ return ( isset($this->defaults[$field]['metric']) ) ? $this->defaults[$field]['metric'] : false; } return false; }
[ "public", "function", "isMetric", "(", "$", "field", ")", "{", "if", "(", "array_key_exists", "(", "$", "field", ",", "$", "this", "->", "defaults", ")", ")", "{", "return", "(", "isset", "(", "$", "this", "->", "defaults", "[", "$", "field", "]", "[", "'metric'", "]", ")", ")", "?", "$", "this", "->", "defaults", "[", "$", "field", "]", "[", "'metric'", "]", ":", "false", ";", "}", "return", "false", ";", "}" ]
Check if field is metric @param $field @return bool
[ "Check", "if", "field", "is", "metric" ]
train
https://github.com/netbull/CoreBundle/blob/0bacc1d9e4733b6da613027400c48421e5a14645/Utils/PDFLabelFormat.php#L183-L189
geega/php-simple-orm
src/Config.php
Config.init
public function init() { $host =getenv('PDO_HOST'); if($host) { $this->setHost(trim($host)); } $database = getenv('PDO_DATABASE'); if($database) { $this->setDatabase(trim($database)); } $user = getenv('PDO_USER'); if($user) { $this->setUser($user); } $password = getenv('PDO_PASSWORD'); if($password) { $this->setPassword($password); } }
php
public function init() { $host =getenv('PDO_HOST'); if($host) { $this->setHost(trim($host)); } $database = getenv('PDO_DATABASE'); if($database) { $this->setDatabase(trim($database)); } $user = getenv('PDO_USER'); if($user) { $this->setUser($user); } $password = getenv('PDO_PASSWORD'); if($password) { $this->setPassword($password); } }
[ "public", "function", "init", "(", ")", "{", "$", "host", "=", "getenv", "(", "'PDO_HOST'", ")", ";", "if", "(", "$", "host", ")", "{", "$", "this", "->", "setHost", "(", "trim", "(", "$", "host", ")", ")", ";", "}", "$", "database", "=", "getenv", "(", "'PDO_DATABASE'", ")", ";", "if", "(", "$", "database", ")", "{", "$", "this", "->", "setDatabase", "(", "trim", "(", "$", "database", ")", ")", ";", "}", "$", "user", "=", "getenv", "(", "'PDO_USER'", ")", ";", "if", "(", "$", "user", ")", "{", "$", "this", "->", "setUser", "(", "$", "user", ")", ";", "}", "$", "password", "=", "getenv", "(", "'PDO_PASSWORD'", ")", ";", "if", "(", "$", "password", ")", "{", "$", "this", "->", "setPassword", "(", "$", "password", ")", ";", "}", "}" ]
Main init method
[ "Main", "init", "method" ]
train
https://github.com/geega/php-simple-orm/blob/8ef636fd181c16ee3936d630d99e232c53883447/src/Config.php#L47-L67
PaladinDigital/blog
database/migrations/2018_02_20_165840_create_media_table.php
CreateMediaTable.up
public function up() { Schema::create('media', function (Blueprint $table) { $table->increments('id'); $table->morphs('model'); $table->string('collection_name'); $table->string('name'); $table->string('file_name'); $table->string('mime_type')->nullable(); $table->string('disk'); $table->unsignedInteger('size'); $table->json('manipulations'); $table->json('custom_properties'); $table->unsignedInteger('order_column')->nullable(); $table->nullableTimestamps(); }); }
php
public function up() { Schema::create('media', function (Blueprint $table) { $table->increments('id'); $table->morphs('model'); $table->string('collection_name'); $table->string('name'); $table->string('file_name'); $table->string('mime_type')->nullable(); $table->string('disk'); $table->unsignedInteger('size'); $table->json('manipulations'); $table->json('custom_properties'); $table->unsignedInteger('order_column')->nullable(); $table->nullableTimestamps(); }); }
[ "public", "function", "up", "(", ")", "{", "Schema", "::", "create", "(", "'media'", ",", "function", "(", "Blueprint", "$", "table", ")", "{", "$", "table", "->", "increments", "(", "'id'", ")", ";", "$", "table", "->", "morphs", "(", "'model'", ")", ";", "$", "table", "->", "string", "(", "'collection_name'", ")", ";", "$", "table", "->", "string", "(", "'name'", ")", ";", "$", "table", "->", "string", "(", "'file_name'", ")", ";", "$", "table", "->", "string", "(", "'mime_type'", ")", "->", "nullable", "(", ")", ";", "$", "table", "->", "string", "(", "'disk'", ")", ";", "$", "table", "->", "unsignedInteger", "(", "'size'", ")", ";", "$", "table", "->", "json", "(", "'manipulations'", ")", ";", "$", "table", "->", "json", "(", "'custom_properties'", ")", ";", "$", "table", "->", "unsignedInteger", "(", "'order_column'", ")", "->", "nullable", "(", ")", ";", "$", "table", "->", "nullableTimestamps", "(", ")", ";", "}", ")", ";", "}" ]
Run the migrations.
[ "Run", "the", "migrations", "." ]
train
https://github.com/PaladinDigital/blog/blob/87f713f14e955b615d3f735e84773caff40750dc/database/migrations/2018_02_20_165840_create_media_table.php#L12-L28
fond-of/spryker-conditional-availability
src/FondOfSpryker/Client/ConditionalAvailability/Plugin/Elasticsearch/Query/ConditionalAvailabilityPingSearchQueryPlugin.php
ConditionalAvailabilityPingSearchQueryPlugin.setSearchDateTimeRange
public function setSearchDateTimeRange(DateTimeInterface $dateTimeFrom, DateTimeInterface $dateTimeUntil): void { $this->dateTimeFrom = $dateTimeFrom; $this->dateTimeUntil = $dateTimeUntil; $this->query = $this->createSearchQuery(); }
php
public function setSearchDateTimeRange(DateTimeInterface $dateTimeFrom, DateTimeInterface $dateTimeUntil): void { $this->dateTimeFrom = $dateTimeFrom; $this->dateTimeUntil = $dateTimeUntil; $this->query = $this->createSearchQuery(); }
[ "public", "function", "setSearchDateTimeRange", "(", "DateTimeInterface", "$", "dateTimeFrom", ",", "DateTimeInterface", "$", "dateTimeUntil", ")", ":", "void", "{", "$", "this", "->", "dateTimeFrom", "=", "$", "dateTimeFrom", ";", "$", "this", "->", "dateTimeUntil", "=", "$", "dateTimeUntil", ";", "$", "this", "->", "query", "=", "$", "this", "->", "createSearchQuery", "(", ")", ";", "}" ]
@param \DateTimeInterface $dateTimeFrom @param \DateTimeInterface $dateTimeUntil @return void
[ "@param", "\\", "DateTimeInterface", "$dateTimeFrom", "@param", "\\", "DateTimeInterface", "$dateTimeUntil" ]
train
https://github.com/fond-of/spryker-conditional-availability/blob/79820697e1f310a3488cfe26b5e1af21be7c3b27/src/FondOfSpryker/Client/ConditionalAvailability/Plugin/Elasticsearch/Query/ConditionalAvailabilityPingSearchQueryPlugin.php#L72-L77
lasallecms/lasallecms-l5-usermanagement-pkg
src/UsermanagementServiceProvider.php
UsermanagementServiceProvider.boot
public function boot() { $this->setupConfiguration(); $this->setupMigrations(); $this->setupSeeds(); $this->setupRoutes($this->app->router); $this->setupTranslations(); $this->setupViews(); $this->setupAssets(); }
php
public function boot() { $this->setupConfiguration(); $this->setupMigrations(); $this->setupSeeds(); $this->setupRoutes($this->app->router); $this->setupTranslations(); $this->setupViews(); $this->setupAssets(); }
[ "public", "function", "boot", "(", ")", "{", "$", "this", "->", "setupConfiguration", "(", ")", ";", "$", "this", "->", "setupMigrations", "(", ")", ";", "$", "this", "->", "setupSeeds", "(", ")", ";", "$", "this", "->", "setupRoutes", "(", "$", "this", "->", "app", "->", "router", ")", ";", "$", "this", "->", "setupTranslations", "(", ")", ";", "$", "this", "->", "setupViews", "(", ")", ";", "$", "this", "->", "setupAssets", "(", ")", ";", "}" ]
Boot the service provider. @return void
[ "Boot", "the", "service", "provider", "." ]
train
https://github.com/lasallecms/lasallecms-l5-usermanagement-pkg/blob/b5203d596e18e2566e7fdcd3f13868bb44a94c1d/src/UsermanagementServiceProvider.php#L58-L72
lasallecms/lasallecms-l5-usermanagement-pkg
src/UsermanagementServiceProvider.php
UsermanagementServiceProvider.registerUsermanagement
private function registerUsermanagement() { $this->app->bind('usermanagement', function($app) { return new Usermanagement($app); }); $this->app->bind( 'Illuminate\Contracts\Auth\Registrar', 'Lasallecms\Usermanagement\Services\Registrar' ); }
php
private function registerUsermanagement() { $this->app->bind('usermanagement', function($app) { return new Usermanagement($app); }); $this->app->bind( 'Illuminate\Contracts\Auth\Registrar', 'Lasallecms\Usermanagement\Services\Registrar' ); }
[ "private", "function", "registerUsermanagement", "(", ")", "{", "$", "this", "->", "app", "->", "bind", "(", "'usermanagement'", ",", "function", "(", "$", "app", ")", "{", "return", "new", "Usermanagement", "(", "$", "app", ")", ";", "}", ")", ";", "$", "this", "->", "app", "->", "bind", "(", "'Illuminate\\Contracts\\Auth\\Registrar'", ",", "'Lasallecms\\Usermanagement\\Services\\Registrar'", ")", ";", "}" ]
Register the application bindings. @return void
[ "Register", "the", "application", "bindings", "." ]
train
https://github.com/lasallecms/lasallecms-l5-usermanagement-pkg/blob/b5203d596e18e2566e7fdcd3f13868bb44a94c1d/src/UsermanagementServiceProvider.php#L131-L141
ezra-obiwale/dSCore
src/Core/Engine.php
Engine.getConfig
public static function getConfig() { $args = func_get_args(); if (count($args) === 0) { return static::$config; } $except = true; if (gettype($args[count($args) - 1]) === 'boolean') { $except = $args[count($args) - 1]; unset($args[count($args) - 1]); } $value = null; $path = ''; $error = false; foreach ($args as $key => $arg) { if ($key === 0) { $path = '$config[' . $arg . ']'; if (!isset(static::$config[$arg])) { $error = true; break; } $value = & static::$config[$arg]; } else { $path .= '[' . $arg . ']'; if (!isset($value[$arg])) { $error = true; break; } $value = & $value[$arg]; } } if ($error && $except) { throw new Exception('Invalid config path "' . $path . '"', true); } elseif ($error) { return null; } return $value; }
php
public static function getConfig() { $args = func_get_args(); if (count($args) === 0) { return static::$config; } $except = true; if (gettype($args[count($args) - 1]) === 'boolean') { $except = $args[count($args) - 1]; unset($args[count($args) - 1]); } $value = null; $path = ''; $error = false; foreach ($args as $key => $arg) { if ($key === 0) { $path = '$config[' . $arg . ']'; if (!isset(static::$config[$arg])) { $error = true; break; } $value = & static::$config[$arg]; } else { $path .= '[' . $arg . ']'; if (!isset($value[$arg])) { $error = true; break; } $value = & $value[$arg]; } } if ($error && $except) { throw new Exception('Invalid config path "' . $path . '"', true); } elseif ($error) { return null; } return $value; }
[ "public", "static", "function", "getConfig", "(", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "if", "(", "count", "(", "$", "args", ")", "===", "0", ")", "{", "return", "static", "::", "$", "config", ";", "}", "$", "except", "=", "true", ";", "if", "(", "gettype", "(", "$", "args", "[", "count", "(", "$", "args", ")", "-", "1", "]", ")", "===", "'boolean'", ")", "{", "$", "except", "=", "$", "args", "[", "count", "(", "$", "args", ")", "-", "1", "]", ";", "unset", "(", "$", "args", "[", "count", "(", "$", "args", ")", "-", "1", "]", ")", ";", "}", "$", "value", "=", "null", ";", "$", "path", "=", "''", ";", "$", "error", "=", "false", ";", "foreach", "(", "$", "args", "as", "$", "key", "=>", "$", "arg", ")", "{", "if", "(", "$", "key", "===", "0", ")", "{", "$", "path", "=", "'$config['", ".", "$", "arg", ".", "']'", ";", "if", "(", "!", "isset", "(", "static", "::", "$", "config", "[", "$", "arg", "]", ")", ")", "{", "$", "error", "=", "true", ";", "break", ";", "}", "$", "value", "=", "&", "static", "::", "$", "config", "[", "$", "arg", "]", ";", "}", "else", "{", "$", "path", ".=", "'['", ".", "$", "arg", ".", "']'", ";", "if", "(", "!", "isset", "(", "$", "value", "[", "$", "arg", "]", ")", ")", "{", "$", "error", "=", "true", ";", "break", ";", "}", "$", "value", "=", "&", "$", "value", "[", "$", "arg", "]", ";", "}", "}", "if", "(", "$", "error", "&&", "$", "except", ")", "{", "throw", "new", "Exception", "(", "'Invalid config path \"'", ".", "$", "path", ".", "'\"'", ",", "true", ")", ";", "}", "elseif", "(", "$", "error", ")", "{", "return", "null", ";", "}", "return", "$", "value", ";", "}" ]
Gets (settings from) the config file @param $_ Pass in as many params to indicate the array path to required config. If last parameter is boolean, that will indicate whether to throw exception if required config is not found. Defaults to TRUE. @return mixed @throws Exception
[ "Gets", "(", "settings", "from", ")", "the", "config", "file" ]
train
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Core/Engine.php#L31-L77
ezra-obiwale/dSCore
src/Core/Engine.php
Engine.getInject
public static function getInject($type = null) { if ($type === null) return static::$inject; elseif (isset(static::$inject[$type])) return static::$inject[$type]; return array(); }
php
public static function getInject($type = null) { if ($type === null) return static::$inject; elseif (isset(static::$inject[$type])) return static::$inject[$type]; return array(); }
[ "public", "static", "function", "getInject", "(", "$", "type", "=", "null", ")", "{", "if", "(", "$", "type", "===", "null", ")", "return", "static", "::", "$", "inject", ";", "elseif", "(", "isset", "(", "static", "::", "$", "inject", "[", "$", "type", "]", ")", ")", "return", "static", "::", "$", "inject", "[", "$", "type", "]", ";", "return", "array", "(", ")", ";", "}" ]
Fetches classes to inject from the config @param string $type all|controllers|services|views @return array
[ "Fetches", "classes", "to", "inject", "from", "the", "config" ]
train
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Core/Engine.php#L84-L91
ezra-obiwale/dSCore
src/Core/Engine.php
Engine.initDB
protected static function initDB() { $dbConfig = static::getConfig('db', static::getServer()); static::$db = new Connection($dbConfig['dsn'], $dbConfig['user'], $dbConfig['password'], $dbConfig['options']); static::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); if (!empty($dbConfig['tablePrefix'])) static::$db->setTablePrefix($dbConfig['tablePrefix']); }
php
protected static function initDB() { $dbConfig = static::getConfig('db', static::getServer()); static::$db = new Connection($dbConfig['dsn'], $dbConfig['user'], $dbConfig['password'], $dbConfig['options']); static::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); if (!empty($dbConfig['tablePrefix'])) static::$db->setTablePrefix($dbConfig['tablePrefix']); }
[ "protected", "static", "function", "initDB", "(", ")", "{", "$", "dbConfig", "=", "static", "::", "getConfig", "(", "'db'", ",", "static", "::", "getServer", "(", ")", ")", ";", "static", "::", "$", "db", "=", "new", "Connection", "(", "$", "dbConfig", "[", "'dsn'", "]", ",", "$", "dbConfig", "[", "'user'", "]", ",", "$", "dbConfig", "[", "'password'", "]", ",", "$", "dbConfig", "[", "'options'", "]", ")", ";", "static", "::", "$", "db", "->", "setAttribute", "(", "PDO", "::", "ATTR_ERRMODE", ",", "PDO", "::", "ERRMODE_EXCEPTION", ")", ";", "if", "(", "!", "empty", "(", "$", "dbConfig", "[", "'tablePrefix'", "]", ")", ")", "static", "::", "$", "db", "->", "setTablePrefix", "(", "$", "dbConfig", "[", "'tablePrefix'", "]", ")", ";", "}" ]
Creates a database connection using \DBScribe\Connection
[ "Creates", "a", "database", "connection", "using", "\\", "DBScribe", "\\", "Connection" ]
train
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Core/Engine.php#L108-L115
ezra-obiwale/dSCore
src/Core/Engine.php
Engine.getUrls
public static function getUrls() { if (static::$urls !== null) return static::$urls; $uri = $_SERVER['REQUEST_URI']; static::$isVirtual = true; if (substr($uri, 0, strlen($_SERVER['SCRIPT_NAME'])) === $_SERVER['SCRIPT_NAME']) { $uri = str_replace('/index.php', '', $uri); } else if (stristr($_SERVER['SCRIPT_NAME'], '/index.php', true)) { static::$serverPath = stristr($_SERVER['SCRIPT_NAME'], '/index.php', true); $uri = str_replace(array(static::$serverPath, '/index.php'), '', $uri); static::$isVirtual = false; } parse_str($_SERVER['QUERY_STRING'], $_GET); static::$urls = static::updateArrayKeys(explode('/', str_replace('?' . $_SERVER['QUERY_STRING'], '', $uri)), true); return static::$urls; }
php
public static function getUrls() { if (static::$urls !== null) return static::$urls; $uri = $_SERVER['REQUEST_URI']; static::$isVirtual = true; if (substr($uri, 0, strlen($_SERVER['SCRIPT_NAME'])) === $_SERVER['SCRIPT_NAME']) { $uri = str_replace('/index.php', '', $uri); } else if (stristr($_SERVER['SCRIPT_NAME'], '/index.php', true)) { static::$serverPath = stristr($_SERVER['SCRIPT_NAME'], '/index.php', true); $uri = str_replace(array(static::$serverPath, '/index.php'), '', $uri); static::$isVirtual = false; } parse_str($_SERVER['QUERY_STRING'], $_GET); static::$urls = static::updateArrayKeys(explode('/', str_replace('?' . $_SERVER['QUERY_STRING'], '', $uri)), true); return static::$urls; }
[ "public", "static", "function", "getUrls", "(", ")", "{", "if", "(", "static", "::", "$", "urls", "!==", "null", ")", "return", "static", "::", "$", "urls", ";", "$", "uri", "=", "$", "_SERVER", "[", "'REQUEST_URI'", "]", ";", "static", "::", "$", "isVirtual", "=", "true", ";", "if", "(", "substr", "(", "$", "uri", ",", "0", ",", "strlen", "(", "$", "_SERVER", "[", "'SCRIPT_NAME'", "]", ")", ")", "===", "$", "_SERVER", "[", "'SCRIPT_NAME'", "]", ")", "{", "$", "uri", "=", "str_replace", "(", "'/index.php'", ",", "''", ",", "$", "uri", ")", ";", "}", "else", "if", "(", "stristr", "(", "$", "_SERVER", "[", "'SCRIPT_NAME'", "]", ",", "'/index.php'", ",", "true", ")", ")", "{", "static", "::", "$", "serverPath", "=", "stristr", "(", "$", "_SERVER", "[", "'SCRIPT_NAME'", "]", ",", "'/index.php'", ",", "true", ")", ";", "$", "uri", "=", "str_replace", "(", "array", "(", "static", "::", "$", "serverPath", ",", "'/index.php'", ")", ",", "''", ",", "$", "uri", ")", ";", "static", "::", "$", "isVirtual", "=", "false", ";", "}", "parse_str", "(", "$", "_SERVER", "[", "'QUERY_STRING'", "]", ",", "$", "_GET", ")", ";", "static", "::", "$", "urls", "=", "static", "::", "updateArrayKeys", "(", "explode", "(", "'/'", ",", "str_replace", "(", "'?'", ".", "$", "_SERVER", "[", "'QUERY_STRING'", "]", ",", "''", ",", "$", "uri", ")", ")", ",", "true", ")", ";", "return", "static", "::", "$", "urls", ";", "}" ]
Fetches the urls from the server request uri @return array
[ "Fetches", "the", "urls", "from", "the", "server", "request", "uri" ]
train
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Core/Engine.php#L132-L152
ezra-obiwale/dSCore
src/Core/Engine.php
Engine.checkAlias
protected static function checkAlias($module) { // $module alias not called if (array_key_exists($module, static::getConfig('modules'))) return $module; // check module alias foreach (static::getConfig('modules') as $cModule => $moduleOptions) { if (!array_key_exists('alias', $moduleOptions)) continue; if ($moduleOptions['alias'] === Util::camelToHyphen($module)) return $cModule; } // module nor alias found return $module; }
php
protected static function checkAlias($module) { // $module alias not called if (array_key_exists($module, static::getConfig('modules'))) return $module; // check module alias foreach (static::getConfig('modules') as $cModule => $moduleOptions) { if (!array_key_exists('alias', $moduleOptions)) continue; if ($moduleOptions['alias'] === Util::camelToHyphen($module)) return $cModule; } // module nor alias found return $module; }
[ "protected", "static", "function", "checkAlias", "(", "$", "module", ")", "{", "// $module alias not called", "if", "(", "array_key_exists", "(", "$", "module", ",", "static", "::", "getConfig", "(", "'modules'", ")", ")", ")", "return", "$", "module", ";", "// check module alias", "foreach", "(", "static", "::", "getConfig", "(", "'modules'", ")", "as", "$", "cModule", "=>", "$", "moduleOptions", ")", "{", "if", "(", "!", "array_key_exists", "(", "'alias'", ",", "$", "moduleOptions", ")", ")", "continue", ";", "if", "(", "$", "moduleOptions", "[", "'alias'", "]", "===", "Util", "::", "camelToHyphen", "(", "$", "module", ")", ")", "return", "$", "cModule", ";", "}", "// module nor alias found", "return", "$", "module", ";", "}" ]
Checks if the module is an alias and returns the ModuleName @param string $module @return string
[ "Checks", "if", "the", "module", "is", "an", "alias", "and", "returns", "the", "ModuleName" ]
train
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Core/Engine.php#L177-L193
ezra-obiwale/dSCore
src/Core/Engine.php
Engine.getModuleAlias
public static function getModuleAlias($module) { if (NULL !== $alias = static::getConfig('modules', $module, 'alias', false)) { return $alias; } return Util::camelToHyphen($module); }
php
public static function getModuleAlias($module) { if (NULL !== $alias = static::getConfig('modules', $module, 'alias', false)) { return $alias; } return Util::camelToHyphen($module); }
[ "public", "static", "function", "getModuleAlias", "(", "$", "module", ")", "{", "if", "(", "NULL", "!==", "$", "alias", "=", "static", "::", "getConfig", "(", "'modules'", ",", "$", "module", ",", "'alias'", ",", "false", ")", ")", "{", "return", "$", "alias", ";", "}", "return", "Util", "::", "camelToHyphen", "(", "$", "module", ")", ";", "}" ]
Fetches the alias for the given module @param string $module @return string
[ "Fetches", "the", "alias", "for", "the", "given", "module" ]
train
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Core/Engine.php#L200-L206
ezra-obiwale/dSCore
src/Core/Engine.php
Engine.getDefaultModule
public static function getDefaultModule($getAlias = false) { if (!$module = static::getConfig('defaults', 'module', false)) { $modules = static::getConfig('modules'); $moduleNames = array_keys($modules); $module = $moduleNames[0]; } return $getAlias ? static::getModuleAlias($module) : $module; }
php
public static function getDefaultModule($getAlias = false) { if (!$module = static::getConfig('defaults', 'module', false)) { $modules = static::getConfig('modules'); $moduleNames = array_keys($modules); $module = $moduleNames[0]; } return $getAlias ? static::getModuleAlias($module) : $module; }
[ "public", "static", "function", "getDefaultModule", "(", "$", "getAlias", "=", "false", ")", "{", "if", "(", "!", "$", "module", "=", "static", "::", "getConfig", "(", "'defaults'", ",", "'module'", ",", "false", ")", ")", "{", "$", "modules", "=", "static", "::", "getConfig", "(", "'modules'", ")", ";", "$", "moduleNames", "=", "array_keys", "(", "$", "modules", ")", ";", "$", "module", "=", "$", "moduleNames", "[", "0", "]", ";", "}", "return", "$", "getAlias", "?", "static", "::", "getModuleAlias", "(", "$", "module", ")", ":", "$", "module", ";", "}" ]
Fetches the default module from the config @param boolean $getAlias Indicates whether to return the alias if available or not @return string
[ "Fetches", "the", "default", "module", "from", "the", "config" ]
train
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Core/Engine.php#L229-L237
ezra-obiwale/dSCore
src/Core/Engine.php
Engine.getDefaultController
public static function getDefaultController($module = null, $exception = false) { $module = ($module === null) ? static::getDefaultModule() : $module; return static::getConfig('modules', $module, 'defaults', 'controller', $exception); }
php
public static function getDefaultController($module = null, $exception = false) { $module = ($module === null) ? static::getDefaultModule() : $module; return static::getConfig('modules', $module, 'defaults', 'controller', $exception); }
[ "public", "static", "function", "getDefaultController", "(", "$", "module", "=", "null", ",", "$", "exception", "=", "false", ")", "{", "$", "module", "=", "(", "$", "module", "===", "null", ")", "?", "static", "::", "getDefaultModule", "(", ")", ":", "$", "module", ";", "return", "static", "::", "getConfig", "(", "'modules'", ",", "$", "module", ",", "'defaults'", ",", "'controller'", ",", "$", "exception", ")", ";", "}" ]
Fetches the default controller from the config @param string $module @param boolean $exception Indicates whether to throw an exception if not found @return string
[ "Fetches", "the", "default", "controller", "from", "the", "config" ]
train
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Core/Engine.php#L268-L272
ezra-obiwale/dSCore
src/Core/Engine.php
Engine.getAction
public static function getAction($exception = true) { $urls = static::getUrls(); if (!empty($urls) && count($urls) >= 3) { $return = strtolower($urls[2]); } else { if (!$return = static::getDefaultAction(static::getModule(), false)) { if ($exception) throw new \Exception('Required action not found'); return '-'; } } return lcfirst(Util::hyphenToCamel($return)); }
php
public static function getAction($exception = true) { $urls = static::getUrls(); if (!empty($urls) && count($urls) >= 3) { $return = strtolower($urls[2]); } else { if (!$return = static::getDefaultAction(static::getModule(), false)) { if ($exception) throw new \Exception('Required action not found'); return '-'; } } return lcfirst(Util::hyphenToCamel($return)); }
[ "public", "static", "function", "getAction", "(", "$", "exception", "=", "true", ")", "{", "$", "urls", "=", "static", "::", "getUrls", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "urls", ")", "&&", "count", "(", "$", "urls", ")", ">=", "3", ")", "{", "$", "return", "=", "strtolower", "(", "$", "urls", "[", "2", "]", ")", ";", "}", "else", "{", "if", "(", "!", "$", "return", "=", "static", "::", "getDefaultAction", "(", "static", "::", "getModule", "(", ")", ",", "false", ")", ")", "{", "if", "(", "$", "exception", ")", "throw", "new", "\\", "Exception", "(", "'Required action not found'", ")", ";", "return", "'-'", ";", "}", "}", "return", "lcfirst", "(", "Util", "::", "hyphenToCamel", "(", "$", "return", ")", ")", ";", "}" ]
Fetches the current action @param boolean $exception Indicates whether to thrown an exception or not if not found @return string
[ "Fetches", "the", "current", "action" ]
train
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Core/Engine.php#L279-L293