repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
mcaskill/Slim-Polyglot | src/Polyglot.php | Polyglot.isLanguageIncludedInRoutes | public function isLanguageIncludedInRoutes($state = null)
{
if (isset($state)) {
$this->languageIncludedInRoutes = (bool) $state;
}
return $this->languageIncludedInRoutes;
} | php | public function isLanguageIncludedInRoutes($state = null)
{
if (isset($state)) {
$this->languageIncludedInRoutes = (bool) $state;
}
return $this->languageIncludedInRoutes;
} | [
"public",
"function",
"isLanguageIncludedInRoutes",
"(",
"$",
"state",
"=",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"state",
")",
")",
"{",
"$",
"this",
"->",
"languageIncludedInRoutes",
"=",
"(",
"bool",
")",
"$",
"state",
";",
"}",
"return",
... | Determine if languages are included in a route.
@param bool|null $state
@return bool | [
"Determine",
"if",
"languages",
"are",
"included",
"in",
"a",
"route",
"."
] | 4c2355f3835dcbf17b57cfc7d7cb8b61b5e26f45 | https://github.com/mcaskill/Slim-Polyglot/blob/4c2355f3835dcbf17b57cfc7d7cb8b61b5e26f45/src/Polyglot.php#L798-L805 | train |
QoboLtd/cakephp-utils | src/ModuleConfig/Parser/Schema.php | Schema.applyCallback | protected function applyCallback(stdClass $schema): stdClass
{
if (is_callable($this->callback)) {
$result = call_user_func_array($this->callback, [Convert::objectToArray($schema)]);
if (is_null($result)) {
throw new InvalidArgumentException('Callback returned `null`. Did you forget to `return $schema;`?');
}
if ($result !== false) {
return Convert::arrayToObject($result);
}
}
return $schema;
} | php | protected function applyCallback(stdClass $schema): stdClass
{
if (is_callable($this->callback)) {
$result = call_user_func_array($this->callback, [Convert::objectToArray($schema)]);
if (is_null($result)) {
throw new InvalidArgumentException('Callback returned `null`. Did you forget to `return $schema;`?');
}
if ($result !== false) {
return Convert::arrayToObject($result);
}
}
return $schema;
} | [
"protected",
"function",
"applyCallback",
"(",
"stdClass",
"$",
"schema",
")",
":",
"stdClass",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"this",
"->",
"callback",
")",
")",
"{",
"$",
"result",
"=",
"call_user_func_array",
"(",
"$",
"this",
"->",
"callback"... | Apply the optional callback.
@param \stdClass $schema JSON schema object.
@return \stdClass JSON schema object after callback processing. | [
"Apply",
"the",
"optional",
"callback",
"."
] | 4b07a3e6f2e611e7c6909c913e6166d280f3c751 | https://github.com/QoboLtd/cakephp-utils/blob/4b07a3e6f2e611e7c6909c913e6166d280f3c751/src/ModuleConfig/Parser/Schema.php#L125-L140 | train |
romm/formz | Classes/Validation/Validator/Form/FormValidatorExecutor.php | FormValidatorExecutor.checkFieldsActivation | public function checkFieldsActivation()
{
foreach ($this->getFormObject()->getConfiguration()->getFields() as $field) {
if (false === $this->result->fieldIsDeactivated($field)) {
$this->checkFieldActivation($field);
}
}
return $this;
} | php | public function checkFieldsActivation()
{
foreach ($this->getFormObject()->getConfiguration()->getFields() as $field) {
if (false === $this->result->fieldIsDeactivated($field)) {
$this->checkFieldActivation($field);
}
}
return $this;
} | [
"public",
"function",
"checkFieldsActivation",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getFormObject",
"(",
")",
"->",
"getConfiguration",
"(",
")",
"->",
"getFields",
"(",
")",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"... | This function will take care of deactivating the validation for fields
that do not match their activation condition.
@return FormValidatorExecutor | [
"This",
"function",
"will",
"take",
"care",
"of",
"deactivating",
"the",
"validation",
"for",
"fields",
"that",
"do",
"not",
"match",
"their",
"activation",
"condition",
"."
] | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/Validation/Validator/Form/FormValidatorExecutor.php#L121-L130 | train |
TheBigBrainsCompany/TbbcCacheBundle | Cache/CacheManager.php | CacheManager.addCache | public function addCache(CacheInterface $cache)
{
$this->cacheMap[$cache->getName()] = $cache;
$this->cacheNames[] = $cache->getName();
} | php | public function addCache(CacheInterface $cache)
{
$this->cacheMap[$cache->getName()] = $cache;
$this->cacheNames[] = $cache->getName();
} | [
"public",
"function",
"addCache",
"(",
"CacheInterface",
"$",
"cache",
")",
"{",
"$",
"this",
"->",
"cacheMap",
"[",
"$",
"cache",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"cache",
";",
"$",
"this",
"->",
"cacheNames",
"[",
"]",
"=",
"$",
"cache",
... | Adds a Cache
@param CacheInterface $cache | [
"Adds",
"a",
"Cache"
] | 14053e304e50c28aa40a94f08f295c3138639473 | https://github.com/TheBigBrainsCompany/TbbcCacheBundle/blob/14053e304e50c28aa40a94f08f295c3138639473/Cache/CacheManager.php#L35-L39 | train |
evseevnn-zz/php-cassandra-binary | src/Database.php | Database.query | public function query($cql, array $values = [], $consistency = ConsistencyEnum::CONSISTENCY_QUORUM) {
if ($this->batchQuery && in_array(substr($cql, 0, 6), ['INSERT', 'UPDATE', 'DELETE'])) {
$this->appendQueryToStack($cql, $values);
return true;
}
if (empty($values)) {
$response = $this->connection->sendRequest(RequestFactory::query($cql, $consistency));
} else {
$response = $this->connection->sendRequest(RequestFactory::prepare($cql));
$responseType = $response->getType();
if ($responseType !== OpcodeEnum::RESULT) {
throw new QueryException($response->getData());
} else {
$preparedData = $response->getData();
}
$response = $this->connection->sendRequest(
RequestFactory::execute($preparedData, $values, $consistency)
);
}
if ($response->getType() === OpcodeEnum::ERROR) {
throw new CassandraException($response->getData());
} else {
$data = $response->getData();
if ($data instanceof Rows) {
return $data->asArray();
}
}
return !empty($data) ? $data : $response->getType() === OpcodeEnum::RESULT;
} | php | public function query($cql, array $values = [], $consistency = ConsistencyEnum::CONSISTENCY_QUORUM) {
if ($this->batchQuery && in_array(substr($cql, 0, 6), ['INSERT', 'UPDATE', 'DELETE'])) {
$this->appendQueryToStack($cql, $values);
return true;
}
if (empty($values)) {
$response = $this->connection->sendRequest(RequestFactory::query($cql, $consistency));
} else {
$response = $this->connection->sendRequest(RequestFactory::prepare($cql));
$responseType = $response->getType();
if ($responseType !== OpcodeEnum::RESULT) {
throw new QueryException($response->getData());
} else {
$preparedData = $response->getData();
}
$response = $this->connection->sendRequest(
RequestFactory::execute($preparedData, $values, $consistency)
);
}
if ($response->getType() === OpcodeEnum::ERROR) {
throw new CassandraException($response->getData());
} else {
$data = $response->getData();
if ($data instanceof Rows) {
return $data->asArray();
}
}
return !empty($data) ? $data : $response->getType() === OpcodeEnum::RESULT;
} | [
"public",
"function",
"query",
"(",
"$",
"cql",
",",
"array",
"$",
"values",
"=",
"[",
"]",
",",
"$",
"consistency",
"=",
"ConsistencyEnum",
"::",
"CONSISTENCY_QUORUM",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"batchQuery",
"&&",
"in_array",
"(",
"substr"... | Send query into database
@param string $cql
@param array $values
@param int $consistency
@throws Exception\QueryException
@throws Exception\CassandraException
@return array|null | [
"Send",
"query",
"into",
"database"
] | c8437390b9cb27878e4358806083f6424c5682c3 | https://github.com/evseevnn-zz/php-cassandra-binary/blob/c8437390b9cb27878e4358806083f6424c5682c3/src/Database.php#L178-L208 | train |
romm/formz | Classes/AssetHandler/JavaScript/FormzConfigurationJavaScriptAssetHandler.php | FormzConfigurationJavaScriptAssetHandler.getFormzConfiguration | protected function getFormzConfiguration()
{
$rootConfigurationArray = $this->getFormObject()
->getConfiguration()
->getRootConfiguration()
->toArray();
$cleanFormzConfigurationArray = [
'view' => $rootConfigurationArray['view']
];
return ArrayService::get()->arrayToJavaScriptJson($cleanFormzConfigurationArray);
} | php | protected function getFormzConfiguration()
{
$rootConfigurationArray = $this->getFormObject()
->getConfiguration()
->getRootConfiguration()
->toArray();
$cleanFormzConfigurationArray = [
'view' => $rootConfigurationArray['view']
];
return ArrayService::get()->arrayToJavaScriptJson($cleanFormzConfigurationArray);
} | [
"protected",
"function",
"getFormzConfiguration",
"(",
")",
"{",
"$",
"rootConfigurationArray",
"=",
"$",
"this",
"->",
"getFormObject",
"(",
")",
"->",
"getConfiguration",
"(",
")",
"->",
"getRootConfiguration",
"(",
")",
"->",
"toArray",
"(",
")",
";",
"$",
... | Returns a JSON array containing the FormZ configuration.
@return string | [
"Returns",
"a",
"JSON",
"array",
"containing",
"the",
"FormZ",
"configuration",
"."
] | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/AssetHandler/JavaScript/FormzConfigurationJavaScriptAssetHandler.php#L70-L82 | train |
lcobucci/di-builder | src/ContainerBuilder.php | ContainerBuilder.setDefaultConfiguration | private function setDefaultConfiguration(): void
{
$this->parameterBag->set('app.devmode', false);
$this->parameterBag->set('container.dumper.inline_class_loader', true);
$this->config->addPass($this->parameterBag);
} | php | private function setDefaultConfiguration(): void
{
$this->parameterBag->set('app.devmode', false);
$this->parameterBag->set('container.dumper.inline_class_loader', true);
$this->config->addPass($this->parameterBag);
} | [
"private",
"function",
"setDefaultConfiguration",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"parameterBag",
"->",
"set",
"(",
"'app.devmode'",
",",
"false",
")",
";",
"$",
"this",
"->",
"parameterBag",
"->",
"set",
"(",
"'container.dumper.inline_class_loade... | Configures the default parameters and appends the handler | [
"Configures",
"the",
"default",
"parameters",
"and",
"appends",
"the",
"handler"
] | bfe59405150db1ef199190915066ed6b59a85b0a | https://github.com/lcobucci/di-builder/blob/bfe59405150db1ef199190915066ed6b59a85b0a/src/ContainerBuilder.php#L47-L53 | train |
alexandresalome/PHP-Selenium | src/Selenium/Specification/Dumper/BrowserDumper.php | BrowserDumper.dump | public function dump()
{
$methods = $this->specification->getMethods();
$result = '<?php
/*
* This file is part of PHP Selenium Library.
* (c) Alexandre Salomé <alexandre.salome@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Selenium;
/**
* Browser class containing all methods of Selenium Server, with documentation.
*
* This class was generated, do not modify it.
*
* @author Alexandre Salomé <alexandre.salome@gmail.com>
*/
class GeneratedBrowser extends BaseBrowser
{
';
foreach ($methods as $method) {
$result .= $this->dumpMethod($method)."\n\n";
}
$result .= "}
";
return $result;
} | php | public function dump()
{
$methods = $this->specification->getMethods();
$result = '<?php
/*
* This file is part of PHP Selenium Library.
* (c) Alexandre Salomé <alexandre.salome@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Selenium;
/**
* Browser class containing all methods of Selenium Server, with documentation.
*
* This class was generated, do not modify it.
*
* @author Alexandre Salomé <alexandre.salome@gmail.com>
*/
class GeneratedBrowser extends BaseBrowser
{
';
foreach ($methods as $method) {
$result .= $this->dumpMethod($method)."\n\n";
}
$result .= "}
";
return $result;
} | [
"public",
"function",
"dump",
"(",
")",
"{",
"$",
"methods",
"=",
"$",
"this",
"->",
"specification",
"->",
"getMethods",
"(",
")",
";",
"$",
"result",
"=",
"'<?php\n/*\n * This file is part of PHP Selenium Library.\n * (c) Alexandre Salomé <alexandre.salome@gmail.com>\n *\... | Dumps to source code
@return string The sourcecode | [
"Dumps",
"to",
"source",
"code"
] | f737b6e396d9d6e2ee5092794bdc42a2ff5ef2c6 | https://github.com/alexandresalome/PHP-Selenium/blob/f737b6e396d9d6e2ee5092794bdc42a2ff5ef2c6/src/Selenium/Specification/Dumper/BrowserDumper.php#L44-L78 | train |
alexandresalome/PHP-Selenium | src/Selenium/Specification/Dumper/BrowserDumper.php | BrowserDumper.dumpMethod | protected function dumpMethod(Method $method)
{
$builder = new MethodBuilder();
$documentation = $method->getDescription()."\n\n";
$signature = array();
foreach ($method->getParameters() as $parameter) {
$builder->addParameter($parameter->getName());
$documentation .= "@param string $".$parameter->getName()." ".$parameter->getDescription()."\n\n";
$signature[] = '$'.$parameter->getName();
}
$signature = implode(', ', $signature);
if ($method->isAction()) {
$documentation .= '@return \Selenium\Browser Fluid interface';
$body = '$this->driver->action("'.$method->getName().'"'. ($signature ? ', '.$signature : '') . ');'."\n";
$body .= "\n";
$body .= "return \$this;";
} else {
$returnType = $method->getReturnType();
if ($returnType === 'boolean') {
$getMethod = 'getBoolean';
} elseif ($returnType === 'string') {
$getMethod = 'getString';
} elseif ($returnType === 'string[]') {
$getMethod = 'getStringArray';
} elseif ($returnType === 'number') {
$getMethod = 'getNumber';
$returnType = 'integer';
if (0 === strpos($method->getReturnDescription(), 'of ')) {
$returnType .= ' number';
}
}
$documentation .= '@return '.$returnType.' '.$method->getReturnDescription();
$body = 'return $this->driver->'.$getMethod.'("'.$method->getName().'"'.($signature ? ', '.$signature : '').');';
}
$builder->setName($method->getName());
$builder->setBody($body);
$builder->setDocumentation($documentation);
return $builder->buildCode();
} | php | protected function dumpMethod(Method $method)
{
$builder = new MethodBuilder();
$documentation = $method->getDescription()."\n\n";
$signature = array();
foreach ($method->getParameters() as $parameter) {
$builder->addParameter($parameter->getName());
$documentation .= "@param string $".$parameter->getName()." ".$parameter->getDescription()."\n\n";
$signature[] = '$'.$parameter->getName();
}
$signature = implode(', ', $signature);
if ($method->isAction()) {
$documentation .= '@return \Selenium\Browser Fluid interface';
$body = '$this->driver->action("'.$method->getName().'"'. ($signature ? ', '.$signature : '') . ');'."\n";
$body .= "\n";
$body .= "return \$this;";
} else {
$returnType = $method->getReturnType();
if ($returnType === 'boolean') {
$getMethod = 'getBoolean';
} elseif ($returnType === 'string') {
$getMethod = 'getString';
} elseif ($returnType === 'string[]') {
$getMethod = 'getStringArray';
} elseif ($returnType === 'number') {
$getMethod = 'getNumber';
$returnType = 'integer';
if (0 === strpos($method->getReturnDescription(), 'of ')) {
$returnType .= ' number';
}
}
$documentation .= '@return '.$returnType.' '.$method->getReturnDescription();
$body = 'return $this->driver->'.$getMethod.'("'.$method->getName().'"'.($signature ? ', '.$signature : '').');';
}
$builder->setName($method->getName());
$builder->setBody($body);
$builder->setDocumentation($documentation);
return $builder->buildCode();
} | [
"protected",
"function",
"dumpMethod",
"(",
"Method",
"$",
"method",
")",
"{",
"$",
"builder",
"=",
"new",
"MethodBuilder",
"(",
")",
";",
"$",
"documentation",
"=",
"$",
"method",
"->",
"getDescription",
"(",
")",
".",
"\"\\n\\n\"",
";",
"$",
"signature",... | Dumps a method.
@param Method $method Specification of a method
@return string | [
"Dumps",
"a",
"method",
"."
] | f737b6e396d9d6e2ee5092794bdc42a2ff5ef2c6 | https://github.com/alexandresalome/PHP-Selenium/blob/f737b6e396d9d6e2ee5092794bdc42a2ff5ef2c6/src/Selenium/Specification/Dumper/BrowserDumper.php#L87-L137 | train |
TheBigBrainsCompany/TbbcCacheBundle | DependencyInjection/TbbcCacheExtension.php | TbbcCacheExtension.createCache | private function createCache(array $config, ContainerBuilder $container)
{
$type = $config['type'];
if (array_key_exists($type, $this->cacheFactories)) {
$id = sprintf('tbbc_cache.%s_cache', $config['name']);
$this->cacheFactories[$type]->create($container, $id, $config);
return $id;
}
// TODO: throw exception ?
} | php | private function createCache(array $config, ContainerBuilder $container)
{
$type = $config['type'];
if (array_key_exists($type, $this->cacheFactories)) {
$id = sprintf('tbbc_cache.%s_cache', $config['name']);
$this->cacheFactories[$type]->create($container, $id, $config);
return $id;
}
// TODO: throw exception ?
} | [
"private",
"function",
"createCache",
"(",
"array",
"$",
"config",
",",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"type",
"=",
"$",
"config",
"[",
"'type'",
"]",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"type",
",",
"$",
"this",
"->",
"... | Creates a single cache service
@param array $config
@param ContainerBuilder $container
@return string | [
"Creates",
"a",
"single",
"cache",
"service"
] | 14053e304e50c28aa40a94f08f295c3138639473 | https://github.com/TheBigBrainsCompany/TbbcCacheBundle/blob/14053e304e50c28aa40a94f08f295c3138639473/DependencyInjection/TbbcCacheExtension.php#L123-L134 | train |
TheBigBrainsCompany/TbbcCacheBundle | DependencyInjection/TbbcCacheExtension.php | TbbcCacheExtension.createCacheFactories | private function createCacheFactories()
{
if (null !== $this->cacheFactories) {
return $this->cacheFactories;
}
// load bundled cache factories
$tempContainer = new ContainerBuilder();
$loader = new Loader\XmlFileLoader($tempContainer, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('cache_factories.xml');
$cacheFactories = array();
foreach ($tempContainer->findTaggedServiceIds('tbbc_cache.cache_factory') as $id => $factories) {
foreach ($factories as $factory) {
if (!isset($factory['cache_type'])) {
throw new \InvalidArgumentException(sprintf(
'Service "%s" must define a "cache_type" attribute for "tbbc_cache.cache_factory" tag',
$id
));
}
$factoryService = $tempContainer->get($id);
$cacheFactories[str_replace('-', '_', strtolower($factory['cache_type']))] = $factoryService;
}
}
return $this->cacheFactories = $cacheFactories;
} | php | private function createCacheFactories()
{
if (null !== $this->cacheFactories) {
return $this->cacheFactories;
}
// load bundled cache factories
$tempContainer = new ContainerBuilder();
$loader = new Loader\XmlFileLoader($tempContainer, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('cache_factories.xml');
$cacheFactories = array();
foreach ($tempContainer->findTaggedServiceIds('tbbc_cache.cache_factory') as $id => $factories) {
foreach ($factories as $factory) {
if (!isset($factory['cache_type'])) {
throw new \InvalidArgumentException(sprintf(
'Service "%s" must define a "cache_type" attribute for "tbbc_cache.cache_factory" tag',
$id
));
}
$factoryService = $tempContainer->get($id);
$cacheFactories[str_replace('-', '_', strtolower($factory['cache_type']))] = $factoryService;
}
}
return $this->cacheFactories = $cacheFactories;
} | [
"private",
"function",
"createCacheFactories",
"(",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"cacheFactories",
")",
"{",
"return",
"$",
"this",
"->",
"cacheFactories",
";",
"}",
"// load bundled cache factories",
"$",
"tempContainer",
"=",
"new",
... | Creates the cache factories
@return array|CacheFactoryInterface[] | [
"Creates",
"the",
"cache",
"factories"
] | 14053e304e50c28aa40a94f08f295c3138639473 | https://github.com/TheBigBrainsCompany/TbbcCacheBundle/blob/14053e304e50c28aa40a94f08f295c3138639473/DependencyInjection/TbbcCacheExtension.php#L141-L169 | train |
romm/formz | Classes/Service/MessageService.php | MessageService.sanitizeValidatorResult | public function sanitizeValidatorResult(Result $result, $validationName)
{
$newResult = new Result;
$this->sanitizeValidatorResultMessages('error', $result->getFlattenedErrors(), $newResult, $validationName);
$this->sanitizeValidatorResultMessages('warning', $result->getFlattenedWarnings(), $newResult, $validationName);
$this->sanitizeValidatorResultMessages('notice', $result->getFlattenedNotices(), $newResult, $validationName);
return $newResult;
} | php | public function sanitizeValidatorResult(Result $result, $validationName)
{
$newResult = new Result;
$this->sanitizeValidatorResultMessages('error', $result->getFlattenedErrors(), $newResult, $validationName);
$this->sanitizeValidatorResultMessages('warning', $result->getFlattenedWarnings(), $newResult, $validationName);
$this->sanitizeValidatorResultMessages('notice', $result->getFlattenedNotices(), $newResult, $validationName);
return $newResult;
} | [
"public",
"function",
"sanitizeValidatorResult",
"(",
"Result",
"$",
"result",
",",
"$",
"validationName",
")",
"{",
"$",
"newResult",
"=",
"new",
"Result",
";",
"$",
"this",
"->",
"sanitizeValidatorResultMessages",
"(",
"'error'",
",",
"$",
"result",
"->",
"g... | This function will go through all errors, warnings and notices and check
if they are instances of `FormzMessageInterface`. If not, they are
converted in order to have more informations that are needed later.
@param Result $result
@param string $validationName
@return Result | [
"This",
"function",
"will",
"go",
"through",
"all",
"errors",
"warnings",
"and",
"notices",
"and",
"check",
"if",
"they",
"are",
"instances",
"of",
"FormzMessageInterface",
".",
"If",
"not",
"they",
"are",
"converted",
"in",
"order",
"to",
"have",
"more",
"i... | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/Service/MessageService.php#L65-L74 | train |
romm/formz | Classes/Service/MessageService.php | MessageService.filterMessages | public function filterMessages(array $messages, array $supportedMessages, $canCreateNewMessages = false)
{
// Adding the keys `value` and `extension` to the messages, only if it is missing.
$addValueToArray = function (array &$a) {
foreach ($a as $k => $v) {
if (false === isset($v['value'])) {
$a[$k]['value'] = '';
}
if (false === isset($v['extension'])) {
$a[$k]['extension'] = '';
}
}
return $a;
};
$messagesArray = [];
foreach ($messages as $key => $message) {
if ($message instanceof FormzMessage) {
$message = $message->toArray();
}
$messagesArray[$key] = $message;
}
$addValueToArray($messagesArray);
$addValueToArray($supportedMessages);
$messagesResult = $supportedMessages;
ArrayUtility::mergeRecursiveWithOverrule(
$messagesResult,
$messagesArray,
(bool)$canCreateNewMessages
);
return $messagesResult;
} | php | public function filterMessages(array $messages, array $supportedMessages, $canCreateNewMessages = false)
{
// Adding the keys `value` and `extension` to the messages, only if it is missing.
$addValueToArray = function (array &$a) {
foreach ($a as $k => $v) {
if (false === isset($v['value'])) {
$a[$k]['value'] = '';
}
if (false === isset($v['extension'])) {
$a[$k]['extension'] = '';
}
}
return $a;
};
$messagesArray = [];
foreach ($messages as $key => $message) {
if ($message instanceof FormzMessage) {
$message = $message->toArray();
}
$messagesArray[$key] = $message;
}
$addValueToArray($messagesArray);
$addValueToArray($supportedMessages);
$messagesResult = $supportedMessages;
ArrayUtility::mergeRecursiveWithOverrule(
$messagesResult,
$messagesArray,
(bool)$canCreateNewMessages
);
return $messagesResult;
} | [
"public",
"function",
"filterMessages",
"(",
"array",
"$",
"messages",
",",
"array",
"$",
"supportedMessages",
",",
"$",
"canCreateNewMessages",
"=",
"false",
")",
"{",
"// Adding the keys `value` and `extension` to the messages, only if it is missing.",
"$",
"addValueToArray... | Will return an array by considering the supported messages, and filling
the supported ones with the given values.
@param FormzMessage[] $messages
@param array $supportedMessages
@param bool $canCreateNewMessages
@return array | [
"Will",
"return",
"an",
"array",
"by",
"considering",
"the",
"supported",
"messages",
"and",
"filling",
"the",
"supported",
"ones",
"with",
"the",
"given",
"values",
"."
] | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/Service/MessageService.php#L140-L177 | train |
vegas-cmf/forms | src/Decorator.php | Decorator.render | public function render(ElementInterface $formElement, $value = '', $attributes = array())
{
$this->checkDependencies();
$config = $this->di->get('config');
if (empty($this->templateName) && !empty($config->forms->templates->default_name)) {
$this->templateName = $config->forms->templates->default_name;
}
$this->variables['element'] = $formElement;
$this->variables['value'] = $value;
$this->variables['attributes'] = $attributes;
$partial = $this->generatePartial();
return $partial;
} | php | public function render(ElementInterface $formElement, $value = '', $attributes = array())
{
$this->checkDependencies();
$config = $this->di->get('config');
if (empty($this->templateName) && !empty($config->forms->templates->default_name)) {
$this->templateName = $config->forms->templates->default_name;
}
$this->variables['element'] = $formElement;
$this->variables['value'] = $value;
$this->variables['attributes'] = $attributes;
$partial = $this->generatePartial();
return $partial;
} | [
"public",
"function",
"render",
"(",
"ElementInterface",
"$",
"formElement",
",",
"$",
"value",
"=",
"''",
",",
"$",
"attributes",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"checkDependencies",
"(",
")",
";",
"$",
"config",
"=",
"$",
"this",... | Render form element with current templatePath and templateName.
If templatePath or templateName are not set, render default.
@param ElementInterface $formElement
@param string $value
@param array $attributes
@return string
@throws Decorator\Exception\DiNotSetException
@throws Decorator\Exception\InvalidAssetsManagerException
@throws Decorator\Exception\ViewNotSetException | [
"Render",
"form",
"element",
"with",
"current",
"templatePath",
"and",
"templateName",
".",
"If",
"templatePath",
"or",
"templateName",
"are",
"not",
"set",
"render",
"default",
"."
] | f2513b1367c3124f399955ed50ff0e3c13eb671b | https://github.com/vegas-cmf/forms/blob/f2513b1367c3124f399955ed50ff0e3c13eb671b/src/Decorator.php#L56-L73 | train |
vegas-cmf/forms | src/Decorator.php | Decorator.checkDependencies | private function checkDependencies()
{
if (!($this->di instanceof DiInterface)) {
throw new DiNotSetException();
}
if (!$this->di->has('view')) {
throw new ViewNotSetException();
}
if (!$this->di->has('assets')) {
throw new InvalidAssetsManagerException();
}
} | php | private function checkDependencies()
{
if (!($this->di instanceof DiInterface)) {
throw new DiNotSetException();
}
if (!$this->di->has('view')) {
throw new ViewNotSetException();
}
if (!$this->di->has('assets')) {
throw new InvalidAssetsManagerException();
}
} | [
"private",
"function",
"checkDependencies",
"(",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"this",
"->",
"di",
"instanceof",
"DiInterface",
")",
")",
"{",
"throw",
"new",
"DiNotSetException",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"di",
"->... | Check for required DI services.
@throws Decorator\Exception\DiNotSetException
@throws Decorator\Exception\InvalidAssetsManagerException
@throws Decorator\Exception\ViewNotSetException | [
"Check",
"for",
"required",
"DI",
"services",
"."
] | f2513b1367c3124f399955ed50ff0e3c13eb671b | https://github.com/vegas-cmf/forms/blob/f2513b1367c3124f399955ed50ff0e3c13eb671b/src/Decorator.php#L82-L95 | train |
QoboLtd/cakephp-utils | src/ModuleConfig/PathFinder/BasePathFinder.php | BasePathFinder.getFilePath | protected function getFilePath(string $path): string
{
if (empty($path)) {
$path = $this->fileName;
}
return $path;
} | php | protected function getFilePath(string $path): string
{
if (empty($path)) {
$path = $this->fileName;
}
return $path;
} | [
"protected",
"function",
"getFilePath",
"(",
"string",
"$",
"path",
")",
":",
"string",
"{",
"if",
"(",
"empty",
"(",
"$",
"path",
")",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"fileName",
";",
"}",
"return",
"$",
"path",
";",
"}"
] | Get file path string
If file path is given, return as is. Otherwise
fallback on the default file name.
@param string $path File path
@return string | [
"Get",
"file",
"path",
"string"
] | 4b07a3e6f2e611e7c6909c913e6166d280f3c751 | https://github.com/QoboLtd/cakephp-utils/blob/4b07a3e6f2e611e7c6909c913e6166d280f3c751/src/ModuleConfig/PathFinder/BasePathFinder.php#L122-L129 | train |
QoboLtd/cakephp-utils | src/ModuleConfig/PathFinder/BasePathFinder.php | BasePathFinder.getDistributionFilePath | protected function getDistributionFilePath(string $path): string
{
$postfix = self::DIST_FILENAME_POSTFIX;
if (empty($path)) {
$path = $this->fileName;
}
// Check if this is the distribution file path
$pathinfo = pathinfo($path);
$postfixIndex = strlen($pathinfo['filename']) - strlen($postfix);
$isDistributionFile = substr($pathinfo['filename'], $postfixIndex) === $postfix;
if (!$isDistributionFile) {
$extension = !empty($pathinfo['extension']) ? '.' . $pathinfo['extension'] : '';
$path = $pathinfo['filename'] . $postfix . $extension;
}
return $path;
} | php | protected function getDistributionFilePath(string $path): string
{
$postfix = self::DIST_FILENAME_POSTFIX;
if (empty($path)) {
$path = $this->fileName;
}
// Check if this is the distribution file path
$pathinfo = pathinfo($path);
$postfixIndex = strlen($pathinfo['filename']) - strlen($postfix);
$isDistributionFile = substr($pathinfo['filename'], $postfixIndex) === $postfix;
if (!$isDistributionFile) {
$extension = !empty($pathinfo['extension']) ? '.' . $pathinfo['extension'] : '';
$path = $pathinfo['filename'] . $postfix . $extension;
}
return $path;
} | [
"protected",
"function",
"getDistributionFilePath",
"(",
"string",
"$",
"path",
")",
":",
"string",
"{",
"$",
"postfix",
"=",
"self",
"::",
"DIST_FILENAME_POSTFIX",
";",
"if",
"(",
"empty",
"(",
"$",
"path",
")",
")",
"{",
"$",
"path",
"=",
"$",
"this",
... | Get file path string for the corresponding distribution file
If distribution file path is given, return as is. Otherwise
adjust the provided one.
@param string $path File path
@return string | [
"Get",
"file",
"path",
"string",
"for",
"the",
"corresponding",
"distribution",
"file"
] | 4b07a3e6f2e611e7c6909c913e6166d280f3c751 | https://github.com/QoboLtd/cakephp-utils/blob/4b07a3e6f2e611e7c6909c913e6166d280f3c751/src/ModuleConfig/PathFinder/BasePathFinder.php#L140-L158 | train |
QoboLtd/cakephp-utils | src/ModuleConfig/PathFinder/BasePathFinder.php | BasePathFinder.validatePath | protected function validatePath(string $path): void
{
if (empty($path)) {
$this->fail(new InvalidArgumentException("Path is not specified"));
}
if (!is_string($path)) {
$this->fail(new InvalidArgumentException("Path is not a string"));
}
} | php | protected function validatePath(string $path): void
{
if (empty($path)) {
$this->fail(new InvalidArgumentException("Path is not specified"));
}
if (!is_string($path)) {
$this->fail(new InvalidArgumentException("Path is not a string"));
}
} | [
"protected",
"function",
"validatePath",
"(",
"string",
"$",
"path",
")",
":",
"void",
"{",
"if",
"(",
"empty",
"(",
"$",
"path",
")",
")",
"{",
"$",
"this",
"->",
"fail",
"(",
"new",
"InvalidArgumentException",
"(",
"\"Path is not specified\"",
")",
")",
... | Validate path string
Check that the given path is a non-empty
string.
NOTE: This method is very different from
the Utility::validatePath(), which
checks the filesystem path for
existence.
@param string $path Path string to check
@return void | [
"Validate",
"path",
"string"
] | 4b07a3e6f2e611e7c6909c913e6166d280f3c751 | https://github.com/QoboLtd/cakephp-utils/blob/4b07a3e6f2e611e7c6909c913e6166d280f3c751/src/ModuleConfig/PathFinder/BasePathFinder.php#L185-L194 | train |
QoboLtd/cakephp-utils | src/ModuleConfig/PathFinder/BasePathFinder.php | BasePathFinder.addFileExtension | protected function addFileExtension(string $path): string
{
$extension = pathinfo($path, PATHINFO_EXTENSION);
if (empty($extension)) {
$path .= $this->extension;
}
return $path;
} | php | protected function addFileExtension(string $path): string
{
$extension = pathinfo($path, PATHINFO_EXTENSION);
if (empty($extension)) {
$path .= $this->extension;
}
return $path;
} | [
"protected",
"function",
"addFileExtension",
"(",
"string",
"$",
"path",
")",
":",
"string",
"{",
"$",
"extension",
"=",
"pathinfo",
"(",
"$",
"path",
",",
"PATHINFO_EXTENSION",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"extension",
")",
")",
"{",
"$",
"... | Add default extension if path doesn't have one
Check if the given path has a file exntesion.
If not, add the default one and return the
modified path.
@param string $path Path
@return string | [
"Add",
"default",
"extension",
"if",
"path",
"doesn",
"t",
"have",
"one"
] | 4b07a3e6f2e611e7c6909c913e6166d280f3c751 | https://github.com/QoboLtd/cakephp-utils/blob/4b07a3e6f2e611e7c6909c913e6166d280f3c751/src/ModuleConfig/PathFinder/BasePathFinder.php#L206-L214 | train |
romm/formz | Classes/AssetHandler/JavaScript/FormRequestDataJavaScriptAssetHandler.php | FormRequestDataJavaScriptAssetHandler.getSubmittedFormValues | protected function getSubmittedFormValues()
{
$result = [];
$formName = $this->getFormObject()->getName();
$originalRequest = $this->getControllerContext()
->getRequest()
->getOriginalRequest();
if (null !== $originalRequest
&& $originalRequest->hasArgument($formName)
) {
$result = $originalRequest->getArgument($formName);
}
return $result;
} | php | protected function getSubmittedFormValues()
{
$result = [];
$formName = $this->getFormObject()->getName();
$originalRequest = $this->getControllerContext()
->getRequest()
->getOriginalRequest();
if (null !== $originalRequest
&& $originalRequest->hasArgument($formName)
) {
$result = $originalRequest->getArgument($formName);
}
return $result;
} | [
"protected",
"function",
"getSubmittedFormValues",
"(",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"$",
"formName",
"=",
"$",
"this",
"->",
"getFormObject",
"(",
")",
"->",
"getName",
"(",
")",
";",
"$",
"originalRequest",
"=",
"$",
"this",
"->",
"ge... | Will fetch the values of the fields of the submitted form, if a form has
been submitted.
@return array | [
"Will",
"fetch",
"the",
"values",
"of",
"the",
"fields",
"of",
"the",
"submitted",
"form",
"if",
"a",
"form",
"has",
"been",
"submitted",
"."
] | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/AssetHandler/JavaScript/FormRequestDataJavaScriptAssetHandler.php#L72-L87 | train |
QuickenLoans/mcp-panthor | src/Middleware/EncryptedCookiesMiddleware.php | EncryptedCookiesMiddleware.encryptAndRenderCookies | private function encryptAndRenderCookies($resCookies)
{
$renderable = [];
foreach ($resCookies as $cookie) {
if (is_string($cookie)) {
$cookie = SetCookie::fromSetCookieString($cookie);
}
if ($cookie instanceof SetCookie) {
$val = $cookie->getValue();
if ($val instanceof OpaqueProperty) {
$val = $val->getValue();
}
if (!in_array($cookie->getName(), $this->unencryptedCookies)) {
$val = $this->encryption->encrypt($val);
}
$renderable[$cookie->getName()] = (string) $cookie->withValue($val);
}
}
return $renderable;
} | php | private function encryptAndRenderCookies($resCookies)
{
$renderable = [];
foreach ($resCookies as $cookie) {
if (is_string($cookie)) {
$cookie = SetCookie::fromSetCookieString($cookie);
}
if ($cookie instanceof SetCookie) {
$val = $cookie->getValue();
if ($val instanceof OpaqueProperty) {
$val = $val->getValue();
}
if (!in_array($cookie->getName(), $this->unencryptedCookies)) {
$val = $this->encryption->encrypt($val);
}
$renderable[$cookie->getName()] = (string) $cookie->withValue($val);
}
}
return $renderable;
} | [
"private",
"function",
"encryptAndRenderCookies",
"(",
"$",
"resCookies",
")",
"{",
"$",
"renderable",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"resCookies",
"as",
"$",
"cookie",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"cookie",
")",
")",
"{",
"$",... | Parse all cookies set on the response
- If string - leave alone (this is expected to be a fully rendered cookie string with expiry, etc)
- If instance of "SetCookie" - stringify
- If instance of "SetCookie" and OpaqueProperty - stringify
Cookies that are "SetCookie" will be encrypted if possible, or not if configured to not encrypt.
Cookies will be automatically deduped.
@param SetCookie[]|string[] $resCookies
@return string[] | [
"Parse",
"all",
"cookies",
"set",
"on",
"the",
"response"
] | b73e22d83d21b8ed4296bee6aebc66c8b07f292c | https://github.com/QuickenLoans/mcp-panthor/blob/b73e22d83d21b8ed4296bee6aebc66c8b07f292c/src/Middleware/EncryptedCookiesMiddleware.php#L163-L187 | train |
QuickenLoans/mcp-panthor | src/Twig/TwigExtension.php | TwigExtension.formatTimepoint | public function formatTimepoint($time, $format)
{
if ($time instanceof TimePoint) {
return $time->format($format, $this->displayTimezone);
}
if ($time instanceof DateTime) {
$formatted = clone $time;
$formatted->setTimezone(new DateTimeZone($this->displayTimezone));
return $formatted->format($format);
}
return '';
} | php | public function formatTimepoint($time, $format)
{
if ($time instanceof TimePoint) {
return $time->format($format, $this->displayTimezone);
}
if ($time instanceof DateTime) {
$formatted = clone $time;
$formatted->setTimezone(new DateTimeZone($this->displayTimezone));
return $formatted->format($format);
}
return '';
} | [
"public",
"function",
"formatTimepoint",
"(",
"$",
"time",
",",
"$",
"format",
")",
"{",
"if",
"(",
"$",
"time",
"instanceof",
"TimePoint",
")",
"{",
"return",
"$",
"time",
"->",
"format",
"(",
"$",
"format",
",",
"$",
"this",
"->",
"displayTimezone",
... | Format a DateTime or TimePoint. Invalid values will output an empty string.
@param TimePoint|DateTime|null $time
@param string $format
@return string | [
"Format",
"a",
"DateTime",
"or",
"TimePoint",
".",
"Invalid",
"values",
"will",
"output",
"an",
"empty",
"string",
"."
] | b73e22d83d21b8ed4296bee6aebc66c8b07f292c | https://github.com/QuickenLoans/mcp-panthor/blob/b73e22d83d21b8ed4296bee6aebc66c8b07f292c/src/Twig/TwigExtension.php#L119-L132 | train |
romm/formz | Classes/Controller/AjaxValidationController.php | AjaxValidationController.processRequest | public function processRequest(RequestInterface $request, ResponseInterface $response)
{
$this->result = new AjaxResult;
try {
$this->processRequestParent($request, $response);
} catch (Exception $exception) {
if (false === $this->protectedRequestMode) {
throw $exception;
}
$this->result->clear();
$errorMessage = ExtensionService::get()->isInDebugMode()
? $this->getDebugMessageForException($exception)
: ContextService::get()->translate(self::DEFAULT_ERROR_MESSAGE_KEY);
$error = new Error($errorMessage, 1490176818);
$this->result->addError($error);
$this->result->setData('errorCode', $exception->getCode());
}
// Cleaning every external message.
ob_clean();
$this->injectResultInResponse();
} | php | public function processRequest(RequestInterface $request, ResponseInterface $response)
{
$this->result = new AjaxResult;
try {
$this->processRequestParent($request, $response);
} catch (Exception $exception) {
if (false === $this->protectedRequestMode) {
throw $exception;
}
$this->result->clear();
$errorMessage = ExtensionService::get()->isInDebugMode()
? $this->getDebugMessageForException($exception)
: ContextService::get()->translate(self::DEFAULT_ERROR_MESSAGE_KEY);
$error = new Error($errorMessage, 1490176818);
$this->result->addError($error);
$this->result->setData('errorCode', $exception->getCode());
}
// Cleaning every external message.
ob_clean();
$this->injectResultInResponse();
} | [
"public",
"function",
"processRequest",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"this",
"->",
"result",
"=",
"new",
"AjaxResult",
";",
"try",
"{",
"$",
"this",
"->",
"processRequestParent",
"(",
"$",
... | Will process the request, but also prevent any external message to be
displayed, and catch any exception that could occur during the
validation.
@param RequestInterface $request
@param ResponseInterface $response
@throws Exception | [
"Will",
"process",
"the",
"request",
"but",
"also",
"prevent",
"any",
"external",
"message",
"to",
"be",
"displayed",
"and",
"catch",
"any",
"exception",
"that",
"could",
"occur",
"during",
"the",
"validation",
"."
] | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/Controller/AjaxValidationController.php#L120-L146 | train |
romm/formz | Classes/Controller/AjaxValidationController.php | AjaxValidationController.initializeActionMethodValidators | protected function initializeActionMethodValidators()
{
$this->initializeActionMethodValidatorsParent();
$request = $this->getRequest();
if (false === $request->hasArgument('name')) {
throw MissingArgumentException::ajaxControllerNameArgumentNotSet();
}
if (false === $request->hasArgument('className')) {
throw MissingArgumentException::ajaxControllerClassNameArgumentNotSet();
}
$className = $request->getArgument('className');
if (false === class_exists($className)) {
throw ClassNotFoundException::ajaxControllerFormClassNameNotFound($className);
}
if (false === in_array(FormInterface::class, class_implements($className))) {
throw InvalidArgumentTypeException::ajaxControllerWrongFormType($className);
}
$this->arguments->addNewArgument($request->getArgument('name'), $className, true);
} | php | protected function initializeActionMethodValidators()
{
$this->initializeActionMethodValidatorsParent();
$request = $this->getRequest();
if (false === $request->hasArgument('name')) {
throw MissingArgumentException::ajaxControllerNameArgumentNotSet();
}
if (false === $request->hasArgument('className')) {
throw MissingArgumentException::ajaxControllerClassNameArgumentNotSet();
}
$className = $request->getArgument('className');
if (false === class_exists($className)) {
throw ClassNotFoundException::ajaxControllerFormClassNameNotFound($className);
}
if (false === in_array(FormInterface::class, class_implements($className))) {
throw InvalidArgumentTypeException::ajaxControllerWrongFormType($className);
}
$this->arguments->addNewArgument($request->getArgument('name'), $className, true);
} | [
"protected",
"function",
"initializeActionMethodValidators",
"(",
")",
"{",
"$",
"this",
"->",
"initializeActionMethodValidatorsParent",
"(",
")",
";",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"if",
"(",
"false",
"===",
"$",
"reques... | Will take care of adding a new argument to the request, based on the form
name and the form class name found in the request arguments. | [
"Will",
"take",
"care",
"of",
"adding",
"a",
"new",
"argument",
"to",
"the",
"request",
"based",
"on",
"the",
"form",
"name",
"and",
"the",
"form",
"class",
"name",
"found",
"in",
"the",
"request",
"arguments",
"."
] | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/Controller/AjaxValidationController.php#L152-L177 | train |
romm/formz | Classes/Controller/AjaxValidationController.php | AjaxValidationController.runAction | public function runAction($name, $className, $fieldName, $validatorName)
{
$this->formName = $name;
$this->formClassName = $className;
$this->fieldName = $fieldName;
$this->validatorName = $validatorName;
$this->form = $this->getForm();
$this->formObject = $this->getFormObject();
$this->formObject->setForm($this->form);
$this->validation = $this->getFieldValidation();
$validatorDataObject = new ValidatorDataObject($this->formObject, $this->validation);
/** @var ValidatorInterface $validator */
$validator = Core::instantiate(
$this->validation->getClassName(),
$this->validation->getOptions(),
$validatorDataObject
);
$fieldValue = ObjectAccess::getProperty($this->form, $this->fieldName);
$result = $validator->validate($fieldValue);
$this->result->merge($result);
} | php | public function runAction($name, $className, $fieldName, $validatorName)
{
$this->formName = $name;
$this->formClassName = $className;
$this->fieldName = $fieldName;
$this->validatorName = $validatorName;
$this->form = $this->getForm();
$this->formObject = $this->getFormObject();
$this->formObject->setForm($this->form);
$this->validation = $this->getFieldValidation();
$validatorDataObject = new ValidatorDataObject($this->formObject, $this->validation);
/** @var ValidatorInterface $validator */
$validator = Core::instantiate(
$this->validation->getClassName(),
$this->validation->getOptions(),
$validatorDataObject
);
$fieldValue = ObjectAccess::getProperty($this->form, $this->fieldName);
$result = $validator->validate($fieldValue);
$this->result->merge($result);
} | [
"public",
"function",
"runAction",
"(",
"$",
"name",
",",
"$",
"className",
",",
"$",
"fieldName",
",",
"$",
"validatorName",
")",
"{",
"$",
"this",
"->",
"formName",
"=",
"$",
"name",
";",
"$",
"this",
"->",
"formClassName",
"=",
"$",
"className",
";"... | Main action that will process the field validation.
@param string $name
@param string $className
@param string $fieldName
@param string $validatorName | [
"Main",
"action",
"that",
"will",
"process",
"the",
"field",
"validation",
"."
] | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/Controller/AjaxValidationController.php#L187-L213 | train |
QoboLtd/cakephp-utils | src/ModuleConfig/Parser/ListParser.php | ListParser.normalize | protected function normalize(array $data, string $prefix = null): array
{
if ($prefix) {
$prefix .= '.';
}
$result = [];
foreach ($data as $item) {
$value = [
'label' => (string)$item['label'],
'inactive' => (bool)$item['inactive']
];
if (! empty($item['children'])) {
$value['children'] = $this->normalize($item['children'], $prefix . $item['value']);
}
$result[$prefix . $item['value']] = $value;
}
return $result;
} | php | protected function normalize(array $data, string $prefix = null): array
{
if ($prefix) {
$prefix .= '.';
}
$result = [];
foreach ($data as $item) {
$value = [
'label' => (string)$item['label'],
'inactive' => (bool)$item['inactive']
];
if (! empty($item['children'])) {
$value['children'] = $this->normalize($item['children'], $prefix . $item['value']);
}
$result[$prefix . $item['value']] = $value;
}
return $result;
} | [
"protected",
"function",
"normalize",
"(",
"array",
"$",
"data",
",",
"string",
"$",
"prefix",
"=",
"null",
")",
":",
"array",
"{",
"if",
"(",
"$",
"prefix",
")",
"{",
"$",
"prefix",
".=",
"'.'",
";",
"}",
"$",
"result",
"=",
"[",
"]",
";",
"fore... | Method that restructures list options csv data for better handling.
@param mixed[] $data csv data
@param string|null $prefix nested option prefix
@return mixed[] | [
"Method",
"that",
"restructures",
"list",
"options",
"csv",
"data",
"for",
"better",
"handling",
"."
] | 4b07a3e6f2e611e7c6909c913e6166d280f3c751 | https://github.com/QoboLtd/cakephp-utils/blob/4b07a3e6f2e611e7c6909c913e6166d280f3c751/src/ModuleConfig/Parser/ListParser.php#L72-L92 | train |
QoboLtd/cakephp-utils | src/ModuleConfig/Parser/ListParser.php | ListParser.filter | protected function filter(array $data): array
{
$result = [];
foreach ($data as $key => $value) {
if ($value['inactive']) {
continue;
}
$result[$key] = $value;
if (isset($value['children'])) {
$result[$key]['children'] = $this->filter($value['children']);
}
}
return $result;
} | php | protected function filter(array $data): array
{
$result = [];
foreach ($data as $key => $value) {
if ($value['inactive']) {
continue;
}
$result[$key] = $value;
if (isset($value['children'])) {
$result[$key]['children'] = $this->filter($value['children']);
}
}
return $result;
} | [
"protected",
"function",
"filter",
"(",
"array",
"$",
"data",
")",
":",
"array",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"[",
"'inactive'",
"]",... | Method that filters list options, excluding non-active ones
@param mixed[] $data list options
@return mixed[] | [
"Method",
"that",
"filters",
"list",
"options",
"excluding",
"non",
"-",
"active",
"ones"
] | 4b07a3e6f2e611e7c6909c913e6166d280f3c751 | https://github.com/QoboLtd/cakephp-utils/blob/4b07a3e6f2e611e7c6909c913e6166d280f3c751/src/ModuleConfig/Parser/ListParser.php#L100-L115 | train |
QoboLtd/cakephp-utils | src/ModuleConfig/Parser/ListParser.php | ListParser.flatten | protected function flatten(array $data): array
{
$result = [];
foreach ($data as $key => $value) {
$item = [
'label' => $value['label'],
'inactive' => $value['inactive']
];
$result[$key] = $item;
if (isset($value['children'])) {
$result = array_merge($result, $this->flatten($value['children']));
}
}
return $result;
} | php | protected function flatten(array $data): array
{
$result = [];
foreach ($data as $key => $value) {
$item = [
'label' => $value['label'],
'inactive' => $value['inactive']
];
$result[$key] = $item;
if (isset($value['children'])) {
$result = array_merge($result, $this->flatten($value['children']));
}
}
return $result;
} | [
"protected",
"function",
"flatten",
"(",
"array",
"$",
"data",
")",
":",
"array",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"item",
"=",
"[",
"'label'",
"=>",
"$",
... | Flatten list options.
@param mixed[] $data List options
@return mixed[] | [
"Flatten",
"list",
"options",
"."
] | 4b07a3e6f2e611e7c6909c913e6166d280f3c751 | https://github.com/QoboLtd/cakephp-utils/blob/4b07a3e6f2e611e7c6909c913e6166d280f3c751/src/ModuleConfig/Parser/ListParser.php#L123-L140 | train |
QoboLtd/cakephp-utils | src/ModuleConfig/Cache/Cache.php | Cache.setOptions | protected function setOptions(array $options = []): void
{
$this->options = $options;
$this->configName = empty($options['cacheConfig']) ? static::DEFAULT_CONFIG : (string)$options['cacheConfig'];
$this->skipCache = empty($this->options['cacheSkip']) ? false : (bool)$this->options['cacheSkip'];
} | php | protected function setOptions(array $options = []): void
{
$this->options = $options;
$this->configName = empty($options['cacheConfig']) ? static::DEFAULT_CONFIG : (string)$options['cacheConfig'];
$this->skipCache = empty($this->options['cacheSkip']) ? false : (bool)$this->options['cacheSkip'];
} | [
"protected",
"function",
"setOptions",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"void",
"{",
"$",
"this",
"->",
"options",
"=",
"$",
"options",
";",
"$",
"this",
"->",
"configName",
"=",
"empty",
"(",
"$",
"options",
"[",
"'cacheConfig'",... | Set cache options
@param mixed[] $options Cache options
@return void | [
"Set",
"cache",
"options"
] | 4b07a3e6f2e611e7c6909c913e6166d280f3c751 | https://github.com/QoboLtd/cakephp-utils/blob/4b07a3e6f2e611e7c6909c913e6166d280f3c751/src/ModuleConfig/Cache/Cache.php#L115-L120 | train |
QoboLtd/cakephp-utils | src/ModuleConfig/Cache/Cache.php | Cache.getKey | public function getKey(array $params): string
{
// Push current options to the list of
// params to ensure unique cache key for
// each set of options.
$params[] = $this->options;
$params = json_encode($params);
$params = $params ?: microtime();
$params = md5($params);
$result = $this->name . '_' . $params;
return $result;
} | php | public function getKey(array $params): string
{
// Push current options to the list of
// params to ensure unique cache key for
// each set of options.
$params[] = $this->options;
$params = json_encode($params);
$params = $params ?: microtime();
$params = md5($params);
$result = $this->name . '_' . $params;
return $result;
} | [
"public",
"function",
"getKey",
"(",
"array",
"$",
"params",
")",
":",
"string",
"{",
"// Push current options to the list of",
"// params to ensure unique cache key for",
"// each set of options.",
"$",
"params",
"[",
"]",
"=",
"$",
"this",
"->",
"options",
";",
"$",... | Generate cache key
In order to avoid hardcoding any particular values
in the cache key, we instead rely on a given array
of parameters. The array will be converted to
a string via json_encode() and shortened using an
md5 checksum.
For those cases where json_encode() fails, the current
microtime() will be used, as it's better to have at
least some cache key than nothing at all.
Name of the current cache instance is used as a prefix.
And just for convenience, the array of current instance
options is appended to key parameters.
@param mixed[] $params Parameters for key generation
@return string | [
"Generate",
"cache",
"key"
] | 4b07a3e6f2e611e7c6909c913e6166d280f3c751 | https://github.com/QoboLtd/cakephp-utils/blob/4b07a3e6f2e611e7c6909c913e6166d280f3c751/src/ModuleConfig/Cache/Cache.php#L162-L176 | train |
QoboLtd/cakephp-utils | src/ModuleConfig/Cache/Cache.php | Cache.readFrom | public function readFrom(string $key)
{
$result = false;
if ($this->skipCache()) {
$this->warnings[] = 'Skipping read from cache';
return $result;
}
$cachedData = CakeCache::read($key, $this->getConfig());
if (!$this->isValidCache($cachedData)) {
CakeCache::delete($key, $this->getConfig());
return $result;
}
$result = $cachedData['data'];
return $result;
} | php | public function readFrom(string $key)
{
$result = false;
if ($this->skipCache()) {
$this->warnings[] = 'Skipping read from cache';
return $result;
}
$cachedData = CakeCache::read($key, $this->getConfig());
if (!$this->isValidCache($cachedData)) {
CakeCache::delete($key, $this->getConfig());
return $result;
}
$result = $cachedData['data'];
return $result;
} | [
"public",
"function",
"readFrom",
"(",
"string",
"$",
"key",
")",
"{",
"$",
"result",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"skipCache",
"(",
")",
")",
"{",
"$",
"this",
"->",
"warnings",
"[",
"]",
"=",
"'Skipping read from cache'",
";",
"... | Read cached value from a given key
@param string $key Cache key
@return mixed False on failure, cached value otherwise | [
"Read",
"cached",
"value",
"from",
"a",
"given",
"key"
] | 4b07a3e6f2e611e7c6909c913e6166d280f3c751 | https://github.com/QoboLtd/cakephp-utils/blob/4b07a3e6f2e611e7c6909c913e6166d280f3c751/src/ModuleConfig/Cache/Cache.php#L184-L203 | train |
romm/formz | Classes/Condition/Parser/Node/BooleanNode.php | BooleanNode.getLogicalResult | protected function getLogicalResult(callable $logicalAndFunction, callable $logicalOrFunction)
{
switch ($this->operator) {
case ConditionParser::LOGICAL_AND:
$result = call_user_func($logicalAndFunction);
break;
case ConditionParser::LOGICAL_OR:
$result = call_user_func($logicalOrFunction);
break;
default:
throw InvalidConfigurationException::wrongBooleanNodeOperator($this->operator);
}
return $result;
} | php | protected function getLogicalResult(callable $logicalAndFunction, callable $logicalOrFunction)
{
switch ($this->operator) {
case ConditionParser::LOGICAL_AND:
$result = call_user_func($logicalAndFunction);
break;
case ConditionParser::LOGICAL_OR:
$result = call_user_func($logicalOrFunction);
break;
default:
throw InvalidConfigurationException::wrongBooleanNodeOperator($this->operator);
}
return $result;
} | [
"protected",
"function",
"getLogicalResult",
"(",
"callable",
"$",
"logicalAndFunction",
",",
"callable",
"$",
"logicalOrFunction",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"operator",
")",
"{",
"case",
"ConditionParser",
"::",
"LOGICAL_AND",
":",
"$",
"resul... | Global function to get the result of a logical operation, the processor
does not matter.
@param callable $logicalAndFunction
@param callable $logicalOrFunction
@return null
@throws InvalidConfigurationException | [
"Global",
"function",
"to",
"get",
"the",
"result",
"of",
"a",
"logical",
"operation",
"the",
"processor",
"does",
"not",
"matter",
"."
] | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/Condition/Parser/Node/BooleanNode.php#L121-L135 | train |
romm/formz | Classes/Condition/Parser/Node/BooleanNode.php | BooleanNode.processLogicalOrPhp | protected function processLogicalOrPhp(PhpConditionDataObject $dataObject)
{
return $this->leftNode->getPhpResult($dataObject) || $this->rightNode->getPhpResult($dataObject);
} | php | protected function processLogicalOrPhp(PhpConditionDataObject $dataObject)
{
return $this->leftNode->getPhpResult($dataObject) || $this->rightNode->getPhpResult($dataObject);
} | [
"protected",
"function",
"processLogicalOrPhp",
"(",
"PhpConditionDataObject",
"$",
"dataObject",
")",
"{",
"return",
"$",
"this",
"->",
"leftNode",
"->",
"getPhpResult",
"(",
"$",
"dataObject",
")",
"||",
"$",
"this",
"->",
"rightNode",
"->",
"getPhpResult",
"(... | Will process a logical "or" operation on the two given nodes.
@param PhpConditionDataObject $dataObject
@return bool | [
"Will",
"process",
"a",
"logical",
"or",
"operation",
"on",
"the",
"two",
"given",
"nodes",
"."
] | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/Condition/Parser/Node/BooleanNode.php#L242-L245 | train |
dljoseph/silverstripe-maintenance-mode | src/UtilityPage.php | UtilityPage.requireDefaultRecords | public function requireDefaultRecords()
{
parent::requireDefaultRecords();
// Skip creation of default records
if (!self::config()->create_default_pages) {
return;
}
// Ensure that an assets path exists before we do any error page creation
if (!file_exists(ASSETS_PATH)) {
mkdir(ASSETS_PATH);
}
$code = self::$defaults['ErrorCode'];
$page = UtilityPage::get()->filter('ErrorCode', $code)->first();
$pageExists = !empty($page);
if (!$pageExists) {
$page = UtilityPage::get()->first();
$pageExists = ($page && $page->exists());
//Only create a UtilityPage on dev/build if one does not already exist.
$page = UtilityPage::create(array(
'Title' => _t('MaintenanceMode.TITLE', 'Undergoing Scheduled Maintenance'),
'URLSegment' => _t('MaintenanceMode.URLSEGMENT', 'offline'),
'MenuTitle' => _t('MaintenanceMode.MENUTITLE', 'Utility Page'),
'Content' => _t('MaintenanceMode.CONTENT', '<h1>We’ll be back soon!</h1>'
.'<p>Sorry for the inconvenience but '
.'our site is currently down for scheduled maintenance. '
.'If you need to you can always <a href="mailto:#">contact us</a>, '
.'otherwise we’ll be back online shortly!</p>'
.'<p>— The Team</p>'),
'ParentID' => 0
));
$page->write();
$page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
}
// Ensure a static error page is created from latest Utility Page content
// Check if static files are enabled
if (!self::config()->enable_static_file) {
return;
}
// Ensure this page has cached error content
$success = true;
if (!$page->hasStaticPage()) {
// Update static content
$success = $page->writeStaticPage();
} elseif ($pageExists) {
// If page exists and already has content, no alteration_message is displayed
return;
}
if ($success) {
DB::alteration_message(
sprintf('%s error Utility Page created', $code),
'created'
);
} else {
DB::alteration_message(
sprintf('%s error Utility page could not be created. Please check permissions', $code),
'error'
);
}
} | php | public function requireDefaultRecords()
{
parent::requireDefaultRecords();
// Skip creation of default records
if (!self::config()->create_default_pages) {
return;
}
// Ensure that an assets path exists before we do any error page creation
if (!file_exists(ASSETS_PATH)) {
mkdir(ASSETS_PATH);
}
$code = self::$defaults['ErrorCode'];
$page = UtilityPage::get()->filter('ErrorCode', $code)->first();
$pageExists = !empty($page);
if (!$pageExists) {
$page = UtilityPage::get()->first();
$pageExists = ($page && $page->exists());
//Only create a UtilityPage on dev/build if one does not already exist.
$page = UtilityPage::create(array(
'Title' => _t('MaintenanceMode.TITLE', 'Undergoing Scheduled Maintenance'),
'URLSegment' => _t('MaintenanceMode.URLSEGMENT', 'offline'),
'MenuTitle' => _t('MaintenanceMode.MENUTITLE', 'Utility Page'),
'Content' => _t('MaintenanceMode.CONTENT', '<h1>We’ll be back soon!</h1>'
.'<p>Sorry for the inconvenience but '
.'our site is currently down for scheduled maintenance. '
.'If you need to you can always <a href="mailto:#">contact us</a>, '
.'otherwise we’ll be back online shortly!</p>'
.'<p>— The Team</p>'),
'ParentID' => 0
));
$page->write();
$page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
}
// Ensure a static error page is created from latest Utility Page content
// Check if static files are enabled
if (!self::config()->enable_static_file) {
return;
}
// Ensure this page has cached error content
$success = true;
if (!$page->hasStaticPage()) {
// Update static content
$success = $page->writeStaticPage();
} elseif ($pageExists) {
// If page exists and already has content, no alteration_message is displayed
return;
}
if ($success) {
DB::alteration_message(
sprintf('%s error Utility Page created', $code),
'created'
);
} else {
DB::alteration_message(
sprintf('%s error Utility page could not be created. Please check permissions', $code),
'error'
);
}
} | [
"public",
"function",
"requireDefaultRecords",
"(",
")",
"{",
"parent",
"::",
"requireDefaultRecords",
"(",
")",
";",
"// Skip creation of default records",
"if",
"(",
"!",
"self",
"::",
"config",
"(",
")",
"->",
"create_default_pages",
")",
"{",
"return",
";",
... | Create default Utility Page setup
Ensures that there is always a 503 Utility page by checking if there's an
instance of ErrorPage with a 503 error code. If there is not,
one is created when the DB is built. | [
"Create",
"default",
"Utility",
"Page",
"setup",
"Ensures",
"that",
"there",
"is",
"always",
"a",
"503",
"Utility",
"page",
"by",
"checking",
"if",
"there",
"s",
"an",
"instance",
"of",
"ErrorPage",
"with",
"a",
"503",
"error",
"code",
".",
"If",
"there",
... | 6f392454338dee962c158ceb40bdc208f1b8f734 | https://github.com/dljoseph/silverstripe-maintenance-mode/blob/6f392454338dee962c158ceb40bdc208f1b8f734/src/UtilityPage.php#L58-L129 | train |
dljoseph/silverstripe-maintenance-mode | src/UtilityPage.php | UtilityPage.get_top_level_templates | public static function get_top_level_templates()
{
$ss_templates_array = array();
$current_theme_path = THEMES_PATH.'/'.Config::inst()->get('SSViewer', 'theme');
//theme directories to search
$search_dir_array = array(
MAINTENANCE_MODE_PATH.'/templates',
$current_theme_path.'/templates'
);
foreach ($search_dir_array as $directory) {
//Get all the SS templates in the directory
foreach (glob("{$directory}/*.ss") as $template_path) {
//get the template name from the path excluding the ".ss" extension
$template = basename($template_path, '.ss');
//Add the key=>value pair to the ss_template_array
$ss_templates_array[$template] = $template;
}
}
return $ss_templates_array;
} | php | public static function get_top_level_templates()
{
$ss_templates_array = array();
$current_theme_path = THEMES_PATH.'/'.Config::inst()->get('SSViewer', 'theme');
//theme directories to search
$search_dir_array = array(
MAINTENANCE_MODE_PATH.'/templates',
$current_theme_path.'/templates'
);
foreach ($search_dir_array as $directory) {
//Get all the SS templates in the directory
foreach (glob("{$directory}/*.ss") as $template_path) {
//get the template name from the path excluding the ".ss" extension
$template = basename($template_path, '.ss');
//Add the key=>value pair to the ss_template_array
$ss_templates_array[$template] = $template;
}
}
return $ss_templates_array;
} | [
"public",
"static",
"function",
"get_top_level_templates",
"(",
")",
"{",
"$",
"ss_templates_array",
"=",
"array",
"(",
")",
";",
"$",
"current_theme_path",
"=",
"THEMES_PATH",
".",
"'/'",
".",
"Config",
"::",
"inst",
"(",
")",
"->",
"get",
"(",
"'SSViewer'"... | This function returns an array of top-level theme templates
@return array | [
"This",
"function",
"returns",
"an",
"array",
"of",
"top",
"-",
"level",
"theme",
"templates"
] | 6f392454338dee962c158ceb40bdc208f1b8f734 | https://github.com/dljoseph/silverstripe-maintenance-mode/blob/6f392454338dee962c158ceb40bdc208f1b8f734/src/UtilityPage.php#L158-L186 | train |
romm/formz | Classes/Form/FormObjectFactory.php | FormObjectFactory.getInstanceFromClassName | public function getInstanceFromClassName($className, $name)
{
if (false === class_exists($className)) {
throw ClassNotFoundException::wrongFormClassName($className);
}
if (false === in_array(FormInterface::class, class_implements($className))) {
throw InvalidArgumentTypeException::wrongFormType($className);
}
$cacheIdentifier = $this->getCacheIdentifier($className, $name);
if (false === isset($this->instances[$cacheIdentifier])) {
$cacheInstance = CacheService::get()->getCacheInstance();
if ($cacheInstance->has($cacheIdentifier)) {
$instance = $cacheInstance->get($cacheIdentifier);
} else {
$instance = $this->createInstance($className, $name);
$cacheInstance->set($cacheIdentifier, $instance);
}
/** @var Configuration $formzConfigurationObject */
$formzConfigurationObject = $this->configurationFactory
->getFormzConfiguration()
->getObject(true);
if (false === $formzConfigurationObject->hasForm($instance->getClassName(), $instance->getName())) {
$formzConfigurationObject->addForm($instance);
}
$this->instances[$cacheIdentifier] = $instance;
}
return $this->instances[$cacheIdentifier];
} | php | public function getInstanceFromClassName($className, $name)
{
if (false === class_exists($className)) {
throw ClassNotFoundException::wrongFormClassName($className);
}
if (false === in_array(FormInterface::class, class_implements($className))) {
throw InvalidArgumentTypeException::wrongFormType($className);
}
$cacheIdentifier = $this->getCacheIdentifier($className, $name);
if (false === isset($this->instances[$cacheIdentifier])) {
$cacheInstance = CacheService::get()->getCacheInstance();
if ($cacheInstance->has($cacheIdentifier)) {
$instance = $cacheInstance->get($cacheIdentifier);
} else {
$instance = $this->createInstance($className, $name);
$cacheInstance->set($cacheIdentifier, $instance);
}
/** @var Configuration $formzConfigurationObject */
$formzConfigurationObject = $this->configurationFactory
->getFormzConfiguration()
->getObject(true);
if (false === $formzConfigurationObject->hasForm($instance->getClassName(), $instance->getName())) {
$formzConfigurationObject->addForm($instance);
}
$this->instances[$cacheIdentifier] = $instance;
}
return $this->instances[$cacheIdentifier];
} | [
"public",
"function",
"getInstanceFromClassName",
"(",
"$",
"className",
",",
"$",
"name",
")",
"{",
"if",
"(",
"false",
"===",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"throw",
"ClassNotFoundException",
"::",
"wrongFormClassName",
"(",
"$",
"clas... | Will create an instance of `FormObject` based on a class which implements
the interface `FormInterface`.
@param string $className
@param string $name
@return FormObject
@throws ClassNotFoundException
@throws InvalidArgumentTypeException | [
"Will",
"create",
"an",
"instance",
"of",
"FormObject",
"based",
"on",
"a",
"class",
"which",
"implements",
"the",
"interface",
"FormInterface",
"."
] | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/Form/FormObjectFactory.php#L65-L100 | train |
romm/formz | Classes/Form/FormObjectFactory.php | FormObjectFactory.createInstance | protected function createInstance($className, $name)
{
$formConfiguration = $this->typoScriptService->getFormConfiguration($className);
/** @var FormObject $instance */
$instance = Core::instantiate(FormObject::class, $className, $name, $formConfiguration);
$this->insertObjectProperties($instance);
$instance->getHash();
return $instance;
} | php | protected function createInstance($className, $name)
{
$formConfiguration = $this->typoScriptService->getFormConfiguration($className);
/** @var FormObject $instance */
$instance = Core::instantiate(FormObject::class, $className, $name, $formConfiguration);
$this->insertObjectProperties($instance);
$instance->getHash();
return $instance;
} | [
"protected",
"function",
"createInstance",
"(",
"$",
"className",
",",
"$",
"name",
")",
"{",
"$",
"formConfiguration",
"=",
"$",
"this",
"->",
"typoScriptService",
"->",
"getFormConfiguration",
"(",
"$",
"className",
")",
";",
"/** @var FormObject $instance */",
... | Creates and initializes a new `FormObject` instance.
@param string $className
@param string $name
@return FormObject | [
"Creates",
"and",
"initializes",
"a",
"new",
"FormObject",
"instance",
"."
] | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/Form/FormObjectFactory.php#L121-L133 | train |
romm/formz | Classes/Form/FormObjectFactory.php | FormObjectFactory.insertObjectProperties | protected function insertObjectProperties(FormObject $instance)
{
$className = $instance->getClassName();
/** @var ReflectionService $reflectionService */
$reflectionService = GeneralUtility::makeInstance(ReflectionService::class);
$reflectionProperties = $reflectionService->getClassPropertyNames($className);
$classReflection = new \ReflectionClass($className);
$publicProperties = $classReflection->getProperties(\ReflectionProperty::IS_PUBLIC);
foreach ($reflectionProperties as $property) {
if (false === in_array($property, self::$ignoredProperties)
&& false === $reflectionService->isPropertyTaggedWith($className, $property, self::IGNORE_PROPERTY)
&& ((true === in_array($property, $publicProperties))
|| $reflectionService->hasMethod($className, 'get' . ucfirst($property))
)
) {
$instance->addProperty($property);
}
}
unset($publicProperties);
} | php | protected function insertObjectProperties(FormObject $instance)
{
$className = $instance->getClassName();
/** @var ReflectionService $reflectionService */
$reflectionService = GeneralUtility::makeInstance(ReflectionService::class);
$reflectionProperties = $reflectionService->getClassPropertyNames($className);
$classReflection = new \ReflectionClass($className);
$publicProperties = $classReflection->getProperties(\ReflectionProperty::IS_PUBLIC);
foreach ($reflectionProperties as $property) {
if (false === in_array($property, self::$ignoredProperties)
&& false === $reflectionService->isPropertyTaggedWith($className, $property, self::IGNORE_PROPERTY)
&& ((true === in_array($property, $publicProperties))
|| $reflectionService->hasMethod($className, 'get' . ucfirst($property))
)
) {
$instance->addProperty($property);
}
}
unset($publicProperties);
} | [
"protected",
"function",
"insertObjectProperties",
"(",
"FormObject",
"$",
"instance",
")",
"{",
"$",
"className",
"=",
"$",
"instance",
"->",
"getClassName",
"(",
")",
";",
"/** @var ReflectionService $reflectionService */",
"$",
"reflectionService",
"=",
"GeneralUtili... | Will insert all the accessible properties of the given instance.
@param FormObject $instance | [
"Will",
"insert",
"all",
"the",
"accessible",
"properties",
"of",
"the",
"given",
"instance",
"."
] | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/Form/FormObjectFactory.php#L140-L163 | train |
DevFactoryCH/taxonomy | src/TaxonomyTrait.php | TaxonomyTrait.addTerm | public function addTerm($term_id) {
$term = ($term_id instanceof Term) ? $term_id : Term::findOrFail($term_id);
$term_relation = [
'term_id' => $term->id,
'vocabulary_id' => $term->vocabulary_id,
];
return $this->related()->save(new TermRelation($term_relation));
} | php | public function addTerm($term_id) {
$term = ($term_id instanceof Term) ? $term_id : Term::findOrFail($term_id);
$term_relation = [
'term_id' => $term->id,
'vocabulary_id' => $term->vocabulary_id,
];
return $this->related()->save(new TermRelation($term_relation));
} | [
"public",
"function",
"addTerm",
"(",
"$",
"term_id",
")",
"{",
"$",
"term",
"=",
"(",
"$",
"term_id",
"instanceof",
"Term",
")",
"?",
"$",
"term_id",
":",
"Term",
"::",
"findOrFail",
"(",
"$",
"term_id",
")",
";",
"$",
"term_relation",
"=",
"[",
"'t... | Add an existing term to the inheriting model
@param $term_id int
The ID of the term or an instance of the Term object
@return object
The TermRelation object | [
"Add",
"an",
"existing",
"term",
"to",
"the",
"inheriting",
"model"
] | ff49a2e450d749b82243e5514e8e847ae21371e8 | https://github.com/DevFactoryCH/taxonomy/blob/ff49a2e450d749b82243e5514e8e847ae21371e8/src/TaxonomyTrait.php#L26-L35 | train |
DevFactoryCH/taxonomy | src/TaxonomyTrait.php | TaxonomyTrait.hasTerm | public function hasTerm($term_id) {
$term = ($term_id instanceof Term) ? $term_id : Term::findOrFail($term_id);
$term_relation = [
'term_id' => $term->id,
'vocabulary_id' => $term->vocabulary_id,
];
return ($this->related()->where('term_id', $term_id)->count()) ? TRUE : FALSE;
} | php | public function hasTerm($term_id) {
$term = ($term_id instanceof Term) ? $term_id : Term::findOrFail($term_id);
$term_relation = [
'term_id' => $term->id,
'vocabulary_id' => $term->vocabulary_id,
];
return ($this->related()->where('term_id', $term_id)->count()) ? TRUE : FALSE;
} | [
"public",
"function",
"hasTerm",
"(",
"$",
"term_id",
")",
"{",
"$",
"term",
"=",
"(",
"$",
"term_id",
"instanceof",
"Term",
")",
"?",
"$",
"term_id",
":",
"Term",
"::",
"findOrFail",
"(",
"$",
"term_id",
")",
";",
"$",
"term_relation",
"=",
"[",
"'t... | Check if the Model instance has the passed term as an existing relation
@param mixed $term_id
The ID of the term or an instance of the Term object
@return object
The TermRelation object | [
"Check",
"if",
"the",
"Model",
"instance",
"has",
"the",
"passed",
"term",
"as",
"an",
"existing",
"relation"
] | ff49a2e450d749b82243e5514e8e847ae21371e8 | https://github.com/DevFactoryCH/taxonomy/blob/ff49a2e450d749b82243e5514e8e847ae21371e8/src/TaxonomyTrait.php#L46-L55 | train |
DevFactoryCH/taxonomy | src/TaxonomyTrait.php | TaxonomyTrait.getTermsByVocabularyName | public function getTermsByVocabularyName($name) {
$vocabulary = \Taxonomy::getVocabularyByName($name);
return $this->related()->where('vocabulary_id', $vocabulary->id)->get();
} | php | public function getTermsByVocabularyName($name) {
$vocabulary = \Taxonomy::getVocabularyByName($name);
return $this->related()->where('vocabulary_id', $vocabulary->id)->get();
} | [
"public",
"function",
"getTermsByVocabularyName",
"(",
"$",
"name",
")",
"{",
"$",
"vocabulary",
"=",
"\\",
"Taxonomy",
"::",
"getVocabularyByName",
"(",
"$",
"name",
")",
";",
"return",
"$",
"this",
"->",
"related",
"(",
")",
"->",
"where",
"(",
"'vocabul... | Get all the terms for a given vocabulary that are linked to the current
Model.
@param $name string
The name of the vocabulary
@return object
A collection of TermRelation objects | [
"Get",
"all",
"the",
"terms",
"for",
"a",
"given",
"vocabulary",
"that",
"are",
"linked",
"to",
"the",
"current",
"Model",
"."
] | ff49a2e450d749b82243e5514e8e847ae21371e8 | https://github.com/DevFactoryCH/taxonomy/blob/ff49a2e450d749b82243e5514e8e847ae21371e8/src/TaxonomyTrait.php#L67-L71 | train |
DevFactoryCH/taxonomy | src/TaxonomyTrait.php | TaxonomyTrait.getTermsByVocabularyNameAsArray | public function getTermsByVocabularyNameAsArray($name) {
$vocabulary = \Taxonomy::getVocabularyByName($name);
$term_relations = $this->related()->where('vocabulary_id', $vocabulary->id)->get();
$data = [];
foreach ($term_relations as $term_relation) {
$data[$term_relation->term->id] = $term_relation->term->name;
}
return $data;
} | php | public function getTermsByVocabularyNameAsArray($name) {
$vocabulary = \Taxonomy::getVocabularyByName($name);
$term_relations = $this->related()->where('vocabulary_id', $vocabulary->id)->get();
$data = [];
foreach ($term_relations as $term_relation) {
$data[$term_relation->term->id] = $term_relation->term->name;
}
return $data;
} | [
"public",
"function",
"getTermsByVocabularyNameAsArray",
"(",
"$",
"name",
")",
"{",
"$",
"vocabulary",
"=",
"\\",
"Taxonomy",
"::",
"getVocabularyByName",
"(",
"$",
"name",
")",
";",
"$",
"term_relations",
"=",
"$",
"this",
"->",
"related",
"(",
")",
"->",
... | Get all the terms for a given vocabulary that are linked to the current
Model as a key value pair array.
@param $name string
The name of the vocabulary
@return array
A key value pair array of the type 'id' => 'name' | [
"Get",
"all",
"the",
"terms",
"for",
"a",
"given",
"vocabulary",
"that",
"are",
"linked",
"to",
"the",
"current",
"Model",
"as",
"a",
"key",
"value",
"pair",
"array",
"."
] | ff49a2e450d749b82243e5514e8e847ae21371e8 | https://github.com/DevFactoryCH/taxonomy/blob/ff49a2e450d749b82243e5514e8e847ae21371e8/src/TaxonomyTrait.php#L83-L94 | train |
DevFactoryCH/taxonomy | src/TaxonomyTrait.php | TaxonomyTrait.removeTerm | public function removeTerm($term_id) {
$term_id = ($term_id instanceof Term) ? $term_id->id : $term_id;
return $this->related()->where('term_id', $term_id)->delete();
} | php | public function removeTerm($term_id) {
$term_id = ($term_id instanceof Term) ? $term_id->id : $term_id;
return $this->related()->where('term_id', $term_id)->delete();
} | [
"public",
"function",
"removeTerm",
"(",
"$",
"term_id",
")",
"{",
"$",
"term_id",
"=",
"(",
"$",
"term_id",
"instanceof",
"Term",
")",
"?",
"$",
"term_id",
"->",
"id",
":",
"$",
"term_id",
";",
"return",
"$",
"this",
"->",
"related",
"(",
")",
"->",... | Unlink the given term with the current model object
@param $term_id int
The ID of the term or an instance of the Term object
@return bool
TRUE if the term relation has been deleted, otherwise FALSE | [
"Unlink",
"the",
"given",
"term",
"with",
"the",
"current",
"model",
"object"
] | ff49a2e450d749b82243e5514e8e847ae21371e8 | https://github.com/DevFactoryCH/taxonomy/blob/ff49a2e450d749b82243e5514e8e847ae21371e8/src/TaxonomyTrait.php#L105-L108 | train |
romm/formz | Classes/Service/ViewHelper/Form/FormViewHelperService.php | FormViewHelperService.applyBehavioursOnSubmittedForm | public function applyBehavioursOnSubmittedForm(ControllerContext $controllerContext)
{
if ($this->formObject->formWasSubmitted()) {
$request = $controllerContext->getRequest()->getOriginalRequest();
$formName = $this->formObject->getName();
if ($request
&& $request->hasArgument($formName)
) {
/** @var BehavioursManager $behavioursManager */
$behavioursManager = GeneralUtility::makeInstance(BehavioursManager::class);
/** @var array $originalForm */
$originalForm = $request->getArgument($formName);
$formProperties = $behavioursManager->applyBehaviourOnPropertiesArray(
$originalForm,
$this->formObject->getConfiguration()
);
$request->setArgument($formName, $formProperties);
}
}
} | php | public function applyBehavioursOnSubmittedForm(ControllerContext $controllerContext)
{
if ($this->formObject->formWasSubmitted()) {
$request = $controllerContext->getRequest()->getOriginalRequest();
$formName = $this->formObject->getName();
if ($request
&& $request->hasArgument($formName)
) {
/** @var BehavioursManager $behavioursManager */
$behavioursManager = GeneralUtility::makeInstance(BehavioursManager::class);
/** @var array $originalForm */
$originalForm = $request->getArgument($formName);
$formProperties = $behavioursManager->applyBehaviourOnPropertiesArray(
$originalForm,
$this->formObject->getConfiguration()
);
$request->setArgument($formName, $formProperties);
}
}
} | [
"public",
"function",
"applyBehavioursOnSubmittedForm",
"(",
"ControllerContext",
"$",
"controllerContext",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"formObject",
"->",
"formWasSubmitted",
"(",
")",
")",
"{",
"$",
"request",
"=",
"$",
"controllerContext",
"->",
"... | Will loop on the submitted form fields and apply behaviours if their
configuration contains.
@param ControllerContext $controllerContext | [
"Will",
"loop",
"on",
"the",
"submitted",
"form",
"fields",
"and",
"apply",
"behaviours",
"if",
"their",
"configuration",
"contains",
"."
] | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/Service/ViewHelper/Form/FormViewHelperService.php#L75-L98 | train |
romm/formz | Classes/Condition/Processor/ConditionProcessor.php | ConditionProcessor.getActivationConditionTreeForField | public function getActivationConditionTreeForField(Field $field)
{
$key = $field->getName();
if (false === array_key_exists($key, $this->fieldsTrees)) {
$this->fieldsTrees[$key] = $this->getConditionTree($field->getActivation());
}
$this->fieldsTrees[$key]->injectDependencies($this, $field->getActivation());
return $this->fieldsTrees[$key];
} | php | public function getActivationConditionTreeForField(Field $field)
{
$key = $field->getName();
if (false === array_key_exists($key, $this->fieldsTrees)) {
$this->fieldsTrees[$key] = $this->getConditionTree($field->getActivation());
}
$this->fieldsTrees[$key]->injectDependencies($this, $field->getActivation());
return $this->fieldsTrees[$key];
} | [
"public",
"function",
"getActivationConditionTreeForField",
"(",
"Field",
"$",
"field",
")",
"{",
"$",
"key",
"=",
"$",
"field",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"false",
"===",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"fiel... | Returns the condition tree for a given field instance, giving access to
CSS, JavaScript and PHP transpiled results.
@param Field $field
@return ConditionTree | [
"Returns",
"the",
"condition",
"tree",
"for",
"a",
"given",
"field",
"instance",
"giving",
"access",
"to",
"CSS",
"JavaScript",
"and",
"PHP",
"transpiled",
"results",
"."
] | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/Condition/Processor/ConditionProcessor.php#L62-L73 | train |
romm/formz | Classes/Condition/Processor/ConditionProcessor.php | ConditionProcessor.getActivationConditionTreeForValidation | public function getActivationConditionTreeForValidation(Validation $validation)
{
$key = $validation->getParentField()->getName() . '->' . $validation->getName();
if (false === array_key_exists($key, $this->validationsTrees)) {
$this->validationsTrees[$key] = $this->getConditionTree($validation->getActivation());
}
$this->validationsTrees[$key]->injectDependencies($this, $validation->getActivation());
return $this->validationsTrees[$key];
} | php | public function getActivationConditionTreeForValidation(Validation $validation)
{
$key = $validation->getParentField()->getName() . '->' . $validation->getName();
if (false === array_key_exists($key, $this->validationsTrees)) {
$this->validationsTrees[$key] = $this->getConditionTree($validation->getActivation());
}
$this->validationsTrees[$key]->injectDependencies($this, $validation->getActivation());
return $this->validationsTrees[$key];
} | [
"public",
"function",
"getActivationConditionTreeForValidation",
"(",
"Validation",
"$",
"validation",
")",
"{",
"$",
"key",
"=",
"$",
"validation",
"->",
"getParentField",
"(",
")",
"->",
"getName",
"(",
")",
".",
"'->'",
".",
"$",
"validation",
"->",
"getNam... | Returns the condition tree for a given validation instance, giving access
to CSS, JavaScript and PHP transpiled results.
@param Validation $validation
@return ConditionTree | [
"Returns",
"the",
"condition",
"tree",
"for",
"a",
"given",
"validation",
"instance",
"giving",
"access",
"to",
"CSS",
"JavaScript",
"and",
"PHP",
"transpiled",
"results",
"."
] | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/Condition/Processor/ConditionProcessor.php#L82-L93 | train |
romm/formz | Classes/Condition/Processor/ConditionProcessor.php | ConditionProcessor.calculateAllTrees | public function calculateAllTrees()
{
$fields = $this->formObject->getConfiguration()->getFields();
foreach ($fields as $field) {
$this->getActivationConditionTreeForField($field);
foreach ($field->getValidation() as $validation) {
$this->getActivationConditionTreeForValidation($validation);
}
}
} | php | public function calculateAllTrees()
{
$fields = $this->formObject->getConfiguration()->getFields();
foreach ($fields as $field) {
$this->getActivationConditionTreeForField($field);
foreach ($field->getValidation() as $validation) {
$this->getActivationConditionTreeForValidation($validation);
}
}
} | [
"public",
"function",
"calculateAllTrees",
"(",
")",
"{",
"$",
"fields",
"=",
"$",
"this",
"->",
"formObject",
"->",
"getConfiguration",
"(",
")",
"->",
"getFields",
"(",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"$",
"this... | Function that will calculate all trees from fields and their validation
rules.
This is useful to be able to store this instance in cache. | [
"Function",
"that",
"will",
"calculate",
"all",
"trees",
"from",
"fields",
"and",
"their",
"validation",
"rules",
"."
] | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/Condition/Processor/ConditionProcessor.php#L101-L112 | train |
lotfio/ouch | src/Ouch/Handlers.php | Handlers.exceptionHandler | public function exceptionHandler($e) : void
{
$this->setError(
(int) $e->getCode(),
(string) $e->getMessage(),
(string) $e->getFile(),
(int) $e->getLine(),
(string) get_class($e),
$e->getTrace()
);
View::render('500.php', (object) $this->errors);
} | php | public function exceptionHandler($e) : void
{
$this->setError(
(int) $e->getCode(),
(string) $e->getMessage(),
(string) $e->getFile(),
(int) $e->getLine(),
(string) get_class($e),
$e->getTrace()
);
View::render('500.php', (object) $this->errors);
} | [
"public",
"function",
"exceptionHandler",
"(",
"$",
"e",
")",
":",
"void",
"{",
"$",
"this",
"->",
"setError",
"(",
"(",
"int",
")",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"(",
"string",
")",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"(",
... | exception handler.
@param object $e exception object
@return void throw exception based on the error type | [
"exception",
"handler",
"."
] | 2d82d936a58f39cba005696107401d5a809c542d | https://github.com/lotfio/ouch/blob/2d82d936a58f39cba005696107401d5a809c542d/src/Ouch/Handlers.php#L46-L58 | train |
lotfio/ouch | src/Ouch/Handlers.php | Handlers.fatalHandler | public function fatalHandler() : void
{
$errors = error_get_last();
if (is_array($errors)) {
$this->setError(
(int) $errors['type'],
(string) $errors['message'],
(string) $errors['file'],
(int) $errors['line'],
'FatalErrorException'
);
View::render('500.php', (object) $this->errors);
return;
}
} | php | public function fatalHandler() : void
{
$errors = error_get_last();
if (is_array($errors)) {
$this->setError(
(int) $errors['type'],
(string) $errors['message'],
(string) $errors['file'],
(int) $errors['line'],
'FatalErrorException'
);
View::render('500.php', (object) $this->errors);
return;
}
} | [
"public",
"function",
"fatalHandler",
"(",
")",
":",
"void",
"{",
"$",
"errors",
"=",
"error_get_last",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"errors",
")",
")",
"{",
"$",
"this",
"->",
"setError",
"(",
"(",
"int",
")",
"$",
"errors",
"["... | error handler method.
@return void | [
"error",
"handler",
"method",
"."
] | 2d82d936a58f39cba005696107401d5a809c542d | https://github.com/lotfio/ouch/blob/2d82d936a58f39cba005696107401d5a809c542d/src/Ouch/Handlers.php#L65-L81 | train |
atk4/schema | src/MigratorConsole.php | MigratorConsole.migrateModels | public function migrateModels($models)
{
// run inside callback
$this->set(function ($c) use ($models) {
$c->notice('Preparing to migrate models');
$p = $c->app->db;
foreach ($models as $model) {
if (!is_object($model)) {
$model = $this->factory($model);
$p->add($model);
}
$m = new \atk4\schema\Migration\MySQL($model);
$result = $m->migrate();
$c->debug(' '.get_class($model).'.. '.$result);
}
$c->notice('Done with migration');
});
} | php | public function migrateModels($models)
{
// run inside callback
$this->set(function ($c) use ($models) {
$c->notice('Preparing to migrate models');
$p = $c->app->db;
foreach ($models as $model) {
if (!is_object($model)) {
$model = $this->factory($model);
$p->add($model);
}
$m = new \atk4\schema\Migration\MySQL($model);
$result = $m->migrate();
$c->debug(' '.get_class($model).'.. '.$result);
}
$c->notice('Done with migration');
});
} | [
"public",
"function",
"migrateModels",
"(",
"$",
"models",
")",
"{",
"// run inside callback",
"$",
"this",
"->",
"set",
"(",
"function",
"(",
"$",
"c",
")",
"use",
"(",
"$",
"models",
")",
"{",
"$",
"c",
"->",
"notice",
"(",
"'Preparing to migrate models'... | Provided with array of models, perform migration for each of them. | [
"Provided",
"with",
"array",
"of",
"models",
"perform",
"migration",
"for",
"each",
"of",
"them",
"."
] | d86750ecfa4d78a5624561ff269d4d76ecf92b40 | https://github.com/atk4/schema/blob/d86750ecfa4d78a5624561ff269d4d76ecf92b40/src/MigratorConsole.php#L14-L35 | train |
romm/formz | Classes/Service/ExtensionService.php | ExtensionService.getExtensionConfiguration | public function getExtensionConfiguration($configurationName)
{
$result = null;
$extensionConfiguration = $this->getFullExtensionConfiguration();
if (null === $configurationName) {
$result = $extensionConfiguration;
} elseif (ArrayUtility::isValidPath($extensionConfiguration, $configurationName, '.')) {
$result = ArrayUtility::getValueByPath($extensionConfiguration, $configurationName, '.');
}
return $result;
} | php | public function getExtensionConfiguration($configurationName)
{
$result = null;
$extensionConfiguration = $this->getFullExtensionConfiguration();
if (null === $configurationName) {
$result = $extensionConfiguration;
} elseif (ArrayUtility::isValidPath($extensionConfiguration, $configurationName, '.')) {
$result = ArrayUtility::getValueByPath($extensionConfiguration, $configurationName, '.');
}
return $result;
} | [
"public",
"function",
"getExtensionConfiguration",
"(",
"$",
"configurationName",
")",
"{",
"$",
"result",
"=",
"null",
";",
"$",
"extensionConfiguration",
"=",
"$",
"this",
"->",
"getFullExtensionConfiguration",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"... | Return the wanted extension configuration.
@param string $configurationName
@return mixed | [
"Return",
"the",
"wanted",
"extension",
"configuration",
"."
] | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/Service/ExtensionService.php#L38-L50 | train |
QuickenLoans/mcp-panthor | src/HTTP/CookieHandler.php | CookieHandler.expireCookie | public function expireCookie(ResponseInterface $response, $name)
{
$cookie = SetCookie::createExpired($name)
->withMaxAge($this->configuration['maxAge'])
->withPath($this->configuration['path'])
->withDomain($this->configuration['domain'])
->withSecure($this->configuration['secure'])
->withHttpOnly($this->configuration['httpOnly']);
return $response->withAddedHeader(static::RESPONSE_COOKIE_NAME, $cookie);
} | php | public function expireCookie(ResponseInterface $response, $name)
{
$cookie = SetCookie::createExpired($name)
->withMaxAge($this->configuration['maxAge'])
->withPath($this->configuration['path'])
->withDomain($this->configuration['domain'])
->withSecure($this->configuration['secure'])
->withHttpOnly($this->configuration['httpOnly']);
return $response->withAddedHeader(static::RESPONSE_COOKIE_NAME, $cookie);
} | [
"public",
"function",
"expireCookie",
"(",
"ResponseInterface",
"$",
"response",
",",
"$",
"name",
")",
"{",
"$",
"cookie",
"=",
"SetCookie",
"::",
"createExpired",
"(",
"$",
"name",
")",
"->",
"withMaxAge",
"(",
"$",
"this",
"->",
"configuration",
"[",
"'... | Expire a cookie in the response.
Do not worry about duplicated cookies, they will be deduped when the
response is rendered by "EncryptedCookieMiddleware".
@param ResponseInterface $response
@param string $name
@return ResponseInterface | [
"Expire",
"a",
"cookie",
"in",
"the",
"response",
"."
] | b73e22d83d21b8ed4296bee6aebc66c8b07f292c | https://github.com/QuickenLoans/mcp-panthor/blob/b73e22d83d21b8ed4296bee6aebc66c8b07f292c/src/HTTP/CookieHandler.php#L156-L166 | train |
romm/formz | Classes/Validation/Validator/AbstractValidator.php | AbstractValidator.addError | protected function addError($key, $code, array $arguments = [], $title = '')
{
$message = $this->addMessage(Error::class, $key, $code, $arguments, $title);
$this->result->addError($message);
} | php | protected function addError($key, $code, array $arguments = [], $title = '')
{
$message = $this->addMessage(Error::class, $key, $code, $arguments, $title);
$this->result->addError($message);
} | [
"protected",
"function",
"addError",
"(",
"$",
"key",
",",
"$",
"code",
",",
"array",
"$",
"arguments",
"=",
"[",
"]",
",",
"$",
"title",
"=",
"''",
")",
"{",
"$",
"message",
"=",
"$",
"this",
"->",
"addMessage",
"(",
"Error",
"::",
"class",
",",
... | Creates a new validation error and adds it to the result.
@param string $key
@param int $code
@param array $arguments
@param string $title | [
"Creates",
"a",
"new",
"validation",
"error",
"and",
"adds",
"it",
"to",
"the",
"result",
"."
] | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/Validation/Validator/AbstractValidator.php#L135-L139 | train |
romm/formz | Classes/Validation/Validator/AbstractValidator.php | AbstractValidator.addWarning | protected function addWarning($key, $code, array $arguments = [], $title = '')
{
$message = $this->addMessage(Warning::class, $key, $code, $arguments, $title);
$this->result->addWarning($message);
} | php | protected function addWarning($key, $code, array $arguments = [], $title = '')
{
$message = $this->addMessage(Warning::class, $key, $code, $arguments, $title);
$this->result->addWarning($message);
} | [
"protected",
"function",
"addWarning",
"(",
"$",
"key",
",",
"$",
"code",
",",
"array",
"$",
"arguments",
"=",
"[",
"]",
",",
"$",
"title",
"=",
"''",
")",
"{",
"$",
"message",
"=",
"$",
"this",
"->",
"addMessage",
"(",
"Warning",
"::",
"class",
",... | Creates a new validation warning and adds it to the result.
@param string $key
@param int $code
@param array $arguments
@param string $title | [
"Creates",
"a",
"new",
"validation",
"warning",
"and",
"adds",
"it",
"to",
"the",
"result",
"."
] | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/Validation/Validator/AbstractValidator.php#L149-L153 | train |
romm/formz | Classes/Validation/Validator/AbstractValidator.php | AbstractValidator.addNotice | protected function addNotice($key, $code, array $arguments = [], $title = '')
{
$message = $this->addMessage(Notice::class, $key, $code, $arguments, $title);
$this->result->addNotice($message);
} | php | protected function addNotice($key, $code, array $arguments = [], $title = '')
{
$message = $this->addMessage(Notice::class, $key, $code, $arguments, $title);
$this->result->addNotice($message);
} | [
"protected",
"function",
"addNotice",
"(",
"$",
"key",
",",
"$",
"code",
",",
"array",
"$",
"arguments",
"=",
"[",
"]",
",",
"$",
"title",
"=",
"''",
")",
"{",
"$",
"message",
"=",
"$",
"this",
"->",
"addMessage",
"(",
"Notice",
"::",
"class",
",",... | Creates a new validation notice and adds it to the result.
@param string $key
@param int $code
@param array $arguments
@param string $title | [
"Creates",
"a",
"new",
"validation",
"notice",
"and",
"adds",
"it",
"to",
"the",
"result",
"."
] | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/Validation/Validator/AbstractValidator.php#L163-L167 | train |
romm/formz | Classes/Form/FormObject.php | FormObject.addProperty | public function addProperty($name)
{
if (false === $this->hasProperty($name)) {
$this->properties[] = $name;
$this->hashService->resetHash();
}
return $this;
} | php | public function addProperty($name)
{
if (false === $this->hasProperty($name)) {
$this->properties[] = $name;
$this->hashService->resetHash();
}
return $this;
} | [
"public",
"function",
"addProperty",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"hasProperty",
"(",
"$",
"name",
")",
")",
"{",
"$",
"this",
"->",
"properties",
"[",
"]",
"=",
"$",
"name",
";",
"$",
"this",
"->",
"h... | Registers a new property for this form.
@param string $name
@return $this | [
"Registers",
"a",
"new",
"property",
"for",
"this",
"form",
"."
] | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/Form/FormObject.php#L126-L134 | train |
evseevnn-zz/php-cassandra-binary | src/Protocol/Response/DataStream.php | DataStream.read | protected function read($length) {
if ($this->length < $length) {
throw new \Exception('Reading while at end of stream');
}
$output = substr($this->data, 0, $length);
$this->data = substr($this->data, $length);
$this->length -= $length;
return $output;
} | php | protected function read($length) {
if ($this->length < $length) {
throw new \Exception('Reading while at end of stream');
}
$output = substr($this->data, 0, $length);
$this->data = substr($this->data, $length);
$this->length -= $length;
return $output;
} | [
"protected",
"function",
"read",
"(",
"$",
"length",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"length",
"<",
"$",
"length",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Reading while at end of stream'",
")",
";",
"}",
"$",
"output",
"=",
"substr",
... | Read data from stream.
@param int $length
@throws \Exception
@return string | [
"Read",
"data",
"from",
"stream",
"."
] | c8437390b9cb27878e4358806083f6424c5682c3 | https://github.com/evseevnn-zz/php-cassandra-binary/blob/c8437390b9cb27878e4358806083f6424c5682c3/src/Protocol/Response/DataStream.php#L38-L46 | train |
evseevnn-zz/php-cassandra-binary | src/Protocol/Response/DataStream.php | DataStream.readInt | public function readInt($isCollectionElement = false) {
if ($isCollectionElement) {
$length = $this->readShort();
return unpack('l', strrev($this->read($length)))[1];
}
return unpack('l', strrev($this->read(4)))[1];
} | php | public function readInt($isCollectionElement = false) {
if ($isCollectionElement) {
$length = $this->readShort();
return unpack('l', strrev($this->read($length)))[1];
}
return unpack('l', strrev($this->read(4)))[1];
} | [
"public",
"function",
"readInt",
"(",
"$",
"isCollectionElement",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"isCollectionElement",
")",
"{",
"$",
"length",
"=",
"$",
"this",
"->",
"readShort",
"(",
")",
";",
"return",
"unpack",
"(",
"'l'",
",",
"strrev",
... | Read unsigned int.
@param bool $isCollectionElement
@return int | [
"Read",
"unsigned",
"int",
"."
] | c8437390b9cb27878e4358806083f6424c5682c3 | https://github.com/evseevnn-zz/php-cassandra-binary/blob/c8437390b9cb27878e4358806083f6424c5682c3/src/Protocol/Response/DataStream.php#L72-L78 | train |
evseevnn-zz/php-cassandra-binary | src/Protocol/Response/DataStream.php | DataStream.readBigInt | function readBigInt($isCollectionElement = false) {
if ($isCollectionElement) {
$length = $this->readShort();
} else {
$length = 8;
}
$data = $this->read($length);
$arr = unpack('N2', $data);
if (PHP_INT_SIZE == 4) {
$hi = $arr[1];
$lo = $arr[2];
$isNeg = $hi < 0;
// Check for a negative
if ($isNeg) {
$hi = ~$hi & (int)0xffffffff;
$lo = ~$lo & (int)0xffffffff;
if ($lo == (int)0xffffffff) {
$hi++;
$lo = 0;
} else {
$lo++;
}
}
// Force 32bit words in excess of 2G to pe positive - we deal wigh sign
// explicitly below
if ($hi & (int)0x80000000) {
$hi &= (int)0x7fffffff;
$hi += 0x80000000;
}
if ($lo & (int)0x80000000) {
$lo &= (int)0x7fffffff;
$lo += 0x80000000;
}
$value = $hi * 4294967296 + $lo;
if ($isNeg) {
$value = 0 - $value;
}
} else {
if ($arr[2] & 0x80000000) {
$arr[2] = $arr[2] & 0xffffffff;
}
if ($arr[1] & 0x80000000) {
$arr[1] = $arr[1] & 0xffffffff;
$arr[1] = $arr[1] ^ 0xffffffff;
$arr[2] = $arr[2] ^ 0xffffffff;
$value = 0 - $arr[1]*4294967296 - $arr[2] - 1;
} else {
$value = $arr[1]*4294967296 + $arr[2];
}
}
return $value;
} | php | function readBigInt($isCollectionElement = false) {
if ($isCollectionElement) {
$length = $this->readShort();
} else {
$length = 8;
}
$data = $this->read($length);
$arr = unpack('N2', $data);
if (PHP_INT_SIZE == 4) {
$hi = $arr[1];
$lo = $arr[2];
$isNeg = $hi < 0;
// Check for a negative
if ($isNeg) {
$hi = ~$hi & (int)0xffffffff;
$lo = ~$lo & (int)0xffffffff;
if ($lo == (int)0xffffffff) {
$hi++;
$lo = 0;
} else {
$lo++;
}
}
// Force 32bit words in excess of 2G to pe positive - we deal wigh sign
// explicitly below
if ($hi & (int)0x80000000) {
$hi &= (int)0x7fffffff;
$hi += 0x80000000;
}
if ($lo & (int)0x80000000) {
$lo &= (int)0x7fffffff;
$lo += 0x80000000;
}
$value = $hi * 4294967296 + $lo;
if ($isNeg) {
$value = 0 - $value;
}
} else {
if ($arr[2] & 0x80000000) {
$arr[2] = $arr[2] & 0xffffffff;
}
if ($arr[1] & 0x80000000) {
$arr[1] = $arr[1] & 0xffffffff;
$arr[1] = $arr[1] ^ 0xffffffff;
$arr[2] = $arr[2] ^ 0xffffffff;
$value = 0 - $arr[1]*4294967296 - $arr[2] - 1;
} else {
$value = $arr[1]*4294967296 + $arr[2];
}
}
return $value;
} | [
"function",
"readBigInt",
"(",
"$",
"isCollectionElement",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"isCollectionElement",
")",
"{",
"$",
"length",
"=",
"$",
"this",
"->",
"readShort",
"(",
")",
";",
"}",
"else",
"{",
"$",
"length",
"=",
"8",
";",
"}"... | Read unsigned big int;
@return int; | [
"Read",
"unsigned",
"big",
"int",
";"
] | c8437390b9cb27878e4358806083f6424c5682c3 | https://github.com/evseevnn-zz/php-cassandra-binary/blob/c8437390b9cb27878e4358806083f6424c5682c3/src/Protocol/Response/DataStream.php#L85-L145 | train |
evseevnn-zz/php-cassandra-binary | src/Protocol/Response/DataStream.php | DataStream.readBytes | public function readBytes($isCollectionElement = false) {
if ($isCollectionElement)
$this->readShort();
$length = $this->readInt();
if ($length == -1)
return null;
return $this->read($length);
} | php | public function readBytes($isCollectionElement = false) {
if ($isCollectionElement)
$this->readShort();
$length = $this->readInt();
if ($length == -1)
return null;
return $this->read($length);
} | [
"public",
"function",
"readBytes",
"(",
"$",
"isCollectionElement",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"isCollectionElement",
")",
"$",
"this",
"->",
"readShort",
"(",
")",
";",
"$",
"length",
"=",
"$",
"this",
"->",
"readInt",
"(",
")",
";",
"if"... | Read bytes.
@param bool $isCollectionElement
@return string | [
"Read",
"bytes",
"."
] | c8437390b9cb27878e4358806083f6424c5682c3 | https://github.com/evseevnn-zz/php-cassandra-binary/blob/c8437390b9cb27878e4358806083f6424c5682c3/src/Protocol/Response/DataStream.php#L173-L182 | train |
evseevnn-zz/php-cassandra-binary | src/Protocol/Response/DataStream.php | DataStream.readUuid | public function readUuid($isCollectionElement = false) {
if ($isCollectionElement)
$this->readShort();
$uuid = '';
$data = $this->read(16);
for ($i = 0; $i < 16; ++$i) {
if ($i == 4 || $i == 6 || $i == 8 || $i == 10) {
$uuid .= '-';
}
$uuid .= str_pad(dechex(ord($data{$i})), 2, '0', STR_PAD_LEFT);
}
return $uuid;
} | php | public function readUuid($isCollectionElement = false) {
if ($isCollectionElement)
$this->readShort();
$uuid = '';
$data = $this->read(16);
for ($i = 0; $i < 16; ++$i) {
if ($i == 4 || $i == 6 || $i == 8 || $i == 10) {
$uuid .= '-';
}
$uuid .= str_pad(dechex(ord($data{$i})), 2, '0', STR_PAD_LEFT);
}
return $uuid;
} | [
"public",
"function",
"readUuid",
"(",
"$",
"isCollectionElement",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"isCollectionElement",
")",
"$",
"this",
"->",
"readShort",
"(",
")",
";",
"$",
"uuid",
"=",
"''",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"r... | Read uuid.
@param bool $isCollectionElement
@return string | [
"Read",
"uuid",
"."
] | c8437390b9cb27878e4358806083f6424c5682c3 | https://github.com/evseevnn-zz/php-cassandra-binary/blob/c8437390b9cb27878e4358806083f6424c5682c3/src/Protocol/Response/DataStream.php#L190-L204 | train |
evseevnn-zz/php-cassandra-binary | src/Protocol/Response/DataStream.php | DataStream.readList | public function readList($valueType) {
$list = array();
$count = $this->readShort();
for ($i = 0; $i < $count; ++$i) {
$list[] = $this->readByType($valueType, true);
}
return $list;
} | php | public function readList($valueType) {
$list = array();
$count = $this->readShort();
for ($i = 0; $i < $count; ++$i) {
$list[] = $this->readByType($valueType, true);
}
return $list;
} | [
"public",
"function",
"readList",
"(",
"$",
"valueType",
")",
"{",
"$",
"list",
"=",
"array",
"(",
")",
";",
"$",
"count",
"=",
"$",
"this",
"->",
"readShort",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"count",
"... | Read list.
@param $valueType
@return array | [
"Read",
"list",
"."
] | c8437390b9cb27878e4358806083f6424c5682c3 | https://github.com/evseevnn-zz/php-cassandra-binary/blob/c8437390b9cb27878e4358806083f6424c5682c3/src/Protocol/Response/DataStream.php#L226-L233 | train |
evseevnn-zz/php-cassandra-binary | src/Protocol/Response/DataStream.php | DataStream.readMap | public function readMap($keyType, $valueType) {
$map = array();
$count = $this->readShort();
for ($i = 0; $i < $count; ++$i) {
$map[$this->readByType($keyType, true)] = $this->readByType($valueType, true);
}
return $map;
} | php | public function readMap($keyType, $valueType) {
$map = array();
$count = $this->readShort();
for ($i = 0; $i < $count; ++$i) {
$map[$this->readByType($keyType, true)] = $this->readByType($valueType, true);
}
return $map;
} | [
"public",
"function",
"readMap",
"(",
"$",
"keyType",
",",
"$",
"valueType",
")",
"{",
"$",
"map",
"=",
"array",
"(",
")",
";",
"$",
"count",
"=",
"$",
"this",
"->",
"readShort",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"... | Read map.
@param $keyType
@param $valueType
@return array | [
"Read",
"map",
"."
] | c8437390b9cb27878e4358806083f6424c5682c3 | https://github.com/evseevnn-zz/php-cassandra-binary/blob/c8437390b9cb27878e4358806083f6424c5682c3/src/Protocol/Response/DataStream.php#L242-L249 | train |
evseevnn-zz/php-cassandra-binary | src/Protocol/Response/DataStream.php | DataStream.readFloat | public function readFloat($isCollectionElement = false) {
if ($isCollectionElement) {
$this->readShort();
}
return unpack('f', strrev($this->read(4)))[1];
} | php | public function readFloat($isCollectionElement = false) {
if ($isCollectionElement) {
$this->readShort();
}
return unpack('f', strrev($this->read(4)))[1];
} | [
"public",
"function",
"readFloat",
"(",
"$",
"isCollectionElement",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"isCollectionElement",
")",
"{",
"$",
"this",
"->",
"readShort",
"(",
")",
";",
"}",
"return",
"unpack",
"(",
"'f'",
",",
"strrev",
"(",
"$",
"t... | Read float.
@param bool $isCollectionElement
@return float | [
"Read",
"float",
"."
] | c8437390b9cb27878e4358806083f6424c5682c3 | https://github.com/evseevnn-zz/php-cassandra-binary/blob/c8437390b9cb27878e4358806083f6424c5682c3/src/Protocol/Response/DataStream.php#L257-L262 | train |
evseevnn-zz/php-cassandra-binary | src/Protocol/Response/DataStream.php | DataStream.readDouble | public function readDouble($isCollectionElement = false) {
if ($isCollectionElement) {
$this->readShort();
}
return unpack('d', strrev($this->read(8)))[1];
} | php | public function readDouble($isCollectionElement = false) {
if ($isCollectionElement) {
$this->readShort();
}
return unpack('d', strrev($this->read(8)))[1];
} | [
"public",
"function",
"readDouble",
"(",
"$",
"isCollectionElement",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"isCollectionElement",
")",
"{",
"$",
"this",
"->",
"readShort",
"(",
")",
";",
"}",
"return",
"unpack",
"(",
"'d'",
",",
"strrev",
"(",
"$",
"... | Read double.
@param bool $isCollectionElement
@return double | [
"Read",
"double",
"."
] | c8437390b9cb27878e4358806083f6424c5682c3 | https://github.com/evseevnn-zz/php-cassandra-binary/blob/c8437390b9cb27878e4358806083f6424c5682c3/src/Protocol/Response/DataStream.php#L270-L275 | train |
evseevnn-zz/php-cassandra-binary | src/Protocol/Response/DataStream.php | DataStream.readInet | public function readInet($isCollectionElement = false) {
if ($isCollectionElement) {
$data = $this->read($this->readShort());
} else {
$data = $this->data;
}
return inet_ntop($data);
} | php | public function readInet($isCollectionElement = false) {
if ($isCollectionElement) {
$data = $this->read($this->readShort());
} else {
$data = $this->data;
}
return inet_ntop($data);
} | [
"public",
"function",
"readInet",
"(",
"$",
"isCollectionElement",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"isCollectionElement",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"read",
"(",
"$",
"this",
"->",
"readShort",
"(",
")",
")",
";",
"}",
"el... | Read inet.
@param bool $isCollectionElement
@return string | [
"Read",
"inet",
"."
] | c8437390b9cb27878e4358806083f6424c5682c3 | https://github.com/evseevnn-zz/php-cassandra-binary/blob/c8437390b9cb27878e4358806083f6424c5682c3/src/Protocol/Response/DataStream.php#L292-L299 | train |
evseevnn-zz/php-cassandra-binary | src/Protocol/Response/DataStream.php | DataStream.readVarint | public function readVarint($isCollectionElement = false) {
if($isCollectionElement) {
$length = $this->readShort();
} else {
$length = strlen($this->data);
}
$hex = unpack('H*', $this->read($length));
return $this->bchexdec($hex[1]);
} | php | public function readVarint($isCollectionElement = false) {
if($isCollectionElement) {
$length = $this->readShort();
} else {
$length = strlen($this->data);
}
$hex = unpack('H*', $this->read($length));
return $this->bchexdec($hex[1]);
} | [
"public",
"function",
"readVarint",
"(",
"$",
"isCollectionElement",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"isCollectionElement",
")",
"{",
"$",
"length",
"=",
"$",
"this",
"->",
"readShort",
"(",
")",
";",
"}",
"else",
"{",
"$",
"length",
"=",
"strl... | Read variable length integer.
@param bool $isCollectionElement
@return string | [
"Read",
"variable",
"length",
"integer",
"."
] | c8437390b9cb27878e4358806083f6424c5682c3 | https://github.com/evseevnn-zz/php-cassandra-binary/blob/c8437390b9cb27878e4358806083f6424c5682c3/src/Protocol/Response/DataStream.php#L307-L316 | train |
evseevnn-zz/php-cassandra-binary | src/Protocol/Response/DataStream.php | DataStream.readDecimal | public function readDecimal($isCollectionElement = false) {
if ($isCollectionElement) {
$this->readShort();
}
$scale = $this->readInt();
$value = $this->readVarint($isCollectionElement);
$len = strlen($value);
return substr($value, 0, $len - $scale) . '.' . substr($value, $len - $scale);
} | php | public function readDecimal($isCollectionElement = false) {
if ($isCollectionElement) {
$this->readShort();
}
$scale = $this->readInt();
$value = $this->readVarint($isCollectionElement);
$len = strlen($value);
return substr($value, 0, $len - $scale) . '.' . substr($value, $len - $scale);
} | [
"public",
"function",
"readDecimal",
"(",
"$",
"isCollectionElement",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"isCollectionElement",
")",
"{",
"$",
"this",
"->",
"readShort",
"(",
")",
";",
"}",
"$",
"scale",
"=",
"$",
"this",
"->",
"readInt",
"(",
")"... | Read variable length decimal.
@param bool $isCollectionElement
@return string | [
"Read",
"variable",
"length",
"decimal",
"."
] | c8437390b9cb27878e4358806083f6424c5682c3 | https://github.com/evseevnn-zz/php-cassandra-binary/blob/c8437390b9cb27878e4358806083f6424c5682c3/src/Protocol/Response/DataStream.php#L324-L332 | train |
atk4/schema | src/Migration.php | Migration.setModel | public function setModel(\atk4\data\Model $m)
{
$this->table($m->table);
foreach ($m->elements as $field) {
// ignore not persisted model fields
if (!$field instanceof \atk4\data\Field) {
continue;
}
if ($field->never_persist) {
continue;
}
if ($field instanceof \atk4\data\Field_SQL_Expression) {
continue;
}
if ($field->short_name == $m->id_field) {
$this->id($field->actual ?: $field->short_name);
continue;
}
$this->field($field->actual ?: $field->short_name, ['type' => $field->type]); // todo add more options here
}
return $m;
} | php | public function setModel(\atk4\data\Model $m)
{
$this->table($m->table);
foreach ($m->elements as $field) {
// ignore not persisted model fields
if (!$field instanceof \atk4\data\Field) {
continue;
}
if ($field->never_persist) {
continue;
}
if ($field instanceof \atk4\data\Field_SQL_Expression) {
continue;
}
if ($field->short_name == $m->id_field) {
$this->id($field->actual ?: $field->short_name);
continue;
}
$this->field($field->actual ?: $field->short_name, ['type' => $field->type]); // todo add more options here
}
return $m;
} | [
"public",
"function",
"setModel",
"(",
"\\",
"atk4",
"\\",
"data",
"\\",
"Model",
"$",
"m",
")",
"{",
"$",
"this",
"->",
"table",
"(",
"$",
"m",
"->",
"table",
")",
";",
"foreach",
"(",
"$",
"m",
"->",
"elements",
"as",
"$",
"field",
")",
"{",
... | Sets model.
@param \atk4\data\Model $m
@return \atk4\data\Model | [
"Sets",
"model",
"."
] | d86750ecfa4d78a5624561ff269d4d76ecf92b40 | https://github.com/atk4/schema/blob/d86750ecfa4d78a5624561ff269d4d76ecf92b40/src/Migration.php#L76-L103 | train |
atk4/schema | src/Migration.php | Migration.mode | public function mode($mode)
{
if (!isset($this->templates[$mode])) {
throw new Exception(['Structure builder does not have this mode', 'mode' => $mode]);
}
$this->mode = $mode;
$this->template = $this->templates[$mode];
return $this;
} | php | public function mode($mode)
{
if (!isset($this->templates[$mode])) {
throw new Exception(['Structure builder does not have this mode', 'mode' => $mode]);
}
$this->mode = $mode;
$this->template = $this->templates[$mode];
return $this;
} | [
"public",
"function",
"mode",
"(",
"$",
"mode",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"templates",
"[",
"$",
"mode",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"[",
"'Structure builder does not have this mode'",
",",
"'mod... | Set SQL expression template.
@param string $mode Template name
@return $this | [
"Set",
"SQL",
"expression",
"template",
"."
] | d86750ecfa4d78a5624561ff269d4d76ecf92b40 | https://github.com/atk4/schema/blob/d86750ecfa4d78a5624561ff269d4d76ecf92b40/src/Migration.php#L112-L122 | train |
atk4/schema | src/Migration.php | Migration._render_statements | public function _render_statements()
{
$result = [];
if (isset($this->args['dropField'])) {
foreach ($this->args['dropField'] as $field => $junk) {
$result[] = 'drop column '.$this->_escape($field);
}
}
if (isset($this->args['newField'])) {
foreach ($this->args['newField'] as $field => $option) {
$result[] = 'add column '.$this->_render_one_field($field, $option);
}
}
if (isset($this->args['alterField'])) {
foreach ($this->args['alterField'] as $field => $option) {
$result[] = 'change column '.$this->_escape($field).' '.$this->_render_one_field($field, $option);
}
}
return implode(', ', $result);
} | php | public function _render_statements()
{
$result = [];
if (isset($this->args['dropField'])) {
foreach ($this->args['dropField'] as $field => $junk) {
$result[] = 'drop column '.$this->_escape($field);
}
}
if (isset($this->args['newField'])) {
foreach ($this->args['newField'] as $field => $option) {
$result[] = 'add column '.$this->_render_one_field($field, $option);
}
}
if (isset($this->args['alterField'])) {
foreach ($this->args['alterField'] as $field => $option) {
$result[] = 'change column '.$this->_escape($field).' '.$this->_render_one_field($field, $option);
}
}
return implode(', ', $result);
} | [
"public",
"function",
"_render_statements",
"(",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"args",
"[",
"'dropField'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"args",
"[",
"'dropField'",
... | Renders statement.
@return string | [
"Renders",
"statement",
"."
] | d86750ecfa4d78a5624561ff269d4d76ecf92b40 | https://github.com/atk4/schema/blob/d86750ecfa4d78a5624561ff269d4d76ecf92b40/src/Migration.php#L250-L273 | train |
atk4/schema | src/Migration.php | Migration.getModelFieldType | public function getModelFieldType($type)
{
$type = preg_replace('/\(.*/', '', strtolower($type)); // remove parenthesis
if (substr($type, 0, 7) == 'varchar' || substr($type, 0, 4) == 'char' || substr($type, 0, 4) == 'enum') {
$type = null;
}
if ($type == 'tinyint') {
$type = 'boolean';
}
if ($type == 'int') {
$type = 'integer';
}
if ($type == 'decimal') {
$type = 'float';
}
if ($type == 'longtext' || $type == 'longblob') {
$type = 'text';
}
return $type;
} | php | public function getModelFieldType($type)
{
$type = preg_replace('/\(.*/', '', strtolower($type)); // remove parenthesis
if (substr($type, 0, 7) == 'varchar' || substr($type, 0, 4) == 'char' || substr($type, 0, 4) == 'enum') {
$type = null;
}
if ($type == 'tinyint') {
$type = 'boolean';
}
if ($type == 'int') {
$type = 'integer';
}
if ($type == 'decimal') {
$type = 'float';
}
if ($type == 'longtext' || $type == 'longblob') {
$type = 'text';
}
return $type;
} | [
"public",
"function",
"getModelFieldType",
"(",
"$",
"type",
")",
"{",
"$",
"type",
"=",
"preg_replace",
"(",
"'/\\(.*/'",
",",
"''",
",",
"strtolower",
"(",
"$",
"type",
")",
")",
";",
"// remove parenthesis",
"if",
"(",
"substr",
"(",
"$",
"type",
",",... | Convert SQL field types to Agile Data field types.
@param string $type SQL field type
@return string | [
"Convert",
"SQL",
"field",
"types",
"to",
"Agile",
"Data",
"field",
"types",
"."
] | d86750ecfa4d78a5624561ff269d4d76ecf92b40 | https://github.com/atk4/schema/blob/d86750ecfa4d78a5624561ff269d4d76ecf92b40/src/Migration.php#L374-L399 | train |
atk4/schema | src/Migration.php | Migration.getSQLFieldType | public function getSQLFieldType($type, $options = [])
{
$type = strtolower($type);
$len = null;
switch ($type) {
case 'boolean':
$type = 'tinyint';
$len = 1;
break;
case 'integer':
$type = 'int';
break;
case 'money':
$type = 'decimal';
$len = '12,2';
break;
case 'float':
$type = 'decimal';
$len = '16,6';
break;
case 'date':
case 'datetime':
$type = 'date';
break;
case 'time':
$type = 'varchar';
$len = '8';
break;
case 'text':
$type = 'longtext';
break;
case 'array':
case 'object':
$type = 'longtext';
break;
default:
$type = 'varchar';
$len = '255';
break;
}
$len = $options['len'] ?? $len;
return $len !== null ? $type.'('.$len.')' : $type;
} | php | public function getSQLFieldType($type, $options = [])
{
$type = strtolower($type);
$len = null;
switch ($type) {
case 'boolean':
$type = 'tinyint';
$len = 1;
break;
case 'integer':
$type = 'int';
break;
case 'money':
$type = 'decimal';
$len = '12,2';
break;
case 'float':
$type = 'decimal';
$len = '16,6';
break;
case 'date':
case 'datetime':
$type = 'date';
break;
case 'time':
$type = 'varchar';
$len = '8';
break;
case 'text':
$type = 'longtext';
break;
case 'array':
case 'object':
$type = 'longtext';
break;
default:
$type = 'varchar';
$len = '255';
break;
}
$len = $options['len'] ?? $len;
return $len !== null ? $type.'('.$len.')' : $type;
} | [
"public",
"function",
"getSQLFieldType",
"(",
"$",
"type",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"type",
"=",
"strtolower",
"(",
"$",
"type",
")",
";",
"$",
"len",
"=",
"null",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'boo... | Convert Agile Data field types to SQL field types.
@param string $type Agile Data field type
@param array $options More options
@return string | [
"Convert",
"Agile",
"Data",
"field",
"types",
"to",
"SQL",
"field",
"types",
"."
] | d86750ecfa4d78a5624561ff269d4d76ecf92b40 | https://github.com/atk4/schema/blob/d86750ecfa4d78a5624561ff269d4d76ecf92b40/src/Migration.php#L409-L454 | train |
atk4/schema | src/Migration.php | Migration.importTable | public function importTable($table)
{
$this->table($table);
$has_fields = false;
foreach ($this->describeTable($table) as $row) {
$has_fields = true;
if ($row['pk']) {
$this->id($row['name']);
continue;
}
$type = $this->getModelFieldType($row['type']);
$this->field($row['name'], ['type'=>$type]);
}
return $has_fields;
} | php | public function importTable($table)
{
$this->table($table);
$has_fields = false;
foreach ($this->describeTable($table) as $row) {
$has_fields = true;
if ($row['pk']) {
$this->id($row['name']);
continue;
}
$type = $this->getModelFieldType($row['type']);
$this->field($row['name'], ['type'=>$type]);
}
return $has_fields;
} | [
"public",
"function",
"importTable",
"(",
"$",
"table",
")",
"{",
"$",
"this",
"->",
"table",
"(",
"$",
"table",
")",
";",
"$",
"has_fields",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"describeTable",
"(",
"$",
"table",
")",
"as",
"$",
... | Import fields from database into migration field config.
@param string $table
@return bool | [
"Import",
"fields",
"from",
"database",
"into",
"migration",
"field",
"config",
"."
] | d86750ecfa4d78a5624561ff269d4d76ecf92b40 | https://github.com/atk4/schema/blob/d86750ecfa4d78a5624561ff269d4d76ecf92b40/src/Migration.php#L463-L480 | train |
atk4/schema | src/Migration.php | Migration.id | public function id($name = null)
{
if (!$name) {
$name = 'id';
}
$val = $this->connection->expr($this->primary_key_expr);
$this->args['field'] =
[$name => $val] + (isset($this->args['field']) ? $this->args['field'] : []);
return $this;
} | php | public function id($name = null)
{
if (!$name) {
$name = 'id';
}
$val = $this->connection->expr($this->primary_key_expr);
$this->args['field'] =
[$name => $val] + (isset($this->args['field']) ? $this->args['field'] : []);
return $this;
} | [
"public",
"function",
"id",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"'id'",
";",
"}",
"$",
"val",
"=",
"$",
"this",
"->",
"connection",
"->",
"expr",
"(",
"$",
"this",
"->",
"primary_key... | Add ID field in template.
@param string $name
@return $this | [
"Add",
"ID",
"field",
"in",
"template",
"."
] | d86750ecfa4d78a5624561ff269d4d76ecf92b40 | https://github.com/atk4/schema/blob/d86750ecfa4d78a5624561ff269d4d76ecf92b40/src/Migration.php#L533-L545 | train |
atk4/schema | src/Migration.php | Migration._render_one_field | protected function _render_one_field($field, $options)
{
$name = $options['name'] ?? $field;
$type = $this->getSQLFieldType($options['type'] ?? null, $options);
return $this->_escape($name).' '.$type;
} | php | protected function _render_one_field($field, $options)
{
$name = $options['name'] ?? $field;
$type = $this->getSQLFieldType($options['type'] ?? null, $options);
return $this->_escape($name).' '.$type;
} | [
"protected",
"function",
"_render_one_field",
"(",
"$",
"field",
",",
"$",
"options",
")",
"{",
"$",
"name",
"=",
"$",
"options",
"[",
"'name'",
"]",
"??",
"$",
"field",
";",
"$",
"type",
"=",
"$",
"this",
"->",
"getSQLFieldType",
"(",
"$",
"options",
... | Renders one field.
@param string $field
@param array $options
@return string | [
"Renders",
"one",
"field",
"."
] | d86750ecfa4d78a5624561ff269d4d76ecf92b40 | https://github.com/atk4/schema/blob/d86750ecfa4d78a5624561ff269d4d76ecf92b40/src/Migration.php#L582-L588 | train |
atk4/schema | src/Migration.php | Migration._set_args | protected function _set_args($what, $alias, $value)
{
// save value in args
if ($alias === null) {
$this->args[$what][] = $value;
} else {
// don't allow multiple values with same alias
if (isset($this->args[$what][$alias])) {
throw new Exception([
ucfirst($what).' alias should be unique',
'alias' => $alias,
]);
}
$this->args[$what][$alias] = $value;
}
} | php | protected function _set_args($what, $alias, $value)
{
// save value in args
if ($alias === null) {
$this->args[$what][] = $value;
} else {
// don't allow multiple values with same alias
if (isset($this->args[$what][$alias])) {
throw new Exception([
ucfirst($what).' alias should be unique',
'alias' => $alias,
]);
}
$this->args[$what][$alias] = $value;
}
} | [
"protected",
"function",
"_set_args",
"(",
"$",
"what",
",",
"$",
"alias",
",",
"$",
"value",
")",
"{",
"// save value in args",
"if",
"(",
"$",
"alias",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"args",
"[",
"$",
"what",
"]",
"[",
"]",
"=",
"$",... | Sets value in args array. Doesn't allow duplicate aliases.
@param string $what Where to set it - table|field
@param string $alias Alias name
@param mixed $value Value to set in args array | [
"Sets",
"value",
"in",
"args",
"array",
".",
"Doesn",
"t",
"allow",
"duplicate",
"aliases",
"."
] | d86750ecfa4d78a5624561ff269d4d76ecf92b40 | https://github.com/atk4/schema/blob/d86750ecfa4d78a5624561ff269d4d76ecf92b40/src/Migration.php#L607-L624 | train |
QoboLtd/cakephp-utils | src/ModuleConfig/ModuleConfig.php | ModuleConfig.getFinder | protected function getFinder(): PathFinderInterface
{
$result = ClassFactory::createFinder($this->configType, $this->options);
return $result;
} | php | protected function getFinder(): PathFinderInterface
{
$result = ClassFactory::createFinder($this->configType, $this->options);
return $result;
} | [
"protected",
"function",
"getFinder",
"(",
")",
":",
"PathFinderInterface",
"{",
"$",
"result",
"=",
"ClassFactory",
"::",
"createFinder",
"(",
"$",
"this",
"->",
"configType",
",",
"$",
"this",
"->",
"options",
")",
";",
"return",
"$",
"result",
";",
"}"
... | Get path finder instance
@return \Qobo\Utils\ModuleConfig\PathFinder\PathFinderInterface | [
"Get",
"path",
"finder",
"instance"
] | 4b07a3e6f2e611e7c6909c913e6166d280f3c751 | https://github.com/QoboLtd/cakephp-utils/blob/4b07a3e6f2e611e7c6909c913e6166d280f3c751/src/ModuleConfig/ModuleConfig.php#L107-L112 | train |
QoboLtd/cakephp-utils | src/ModuleConfig/ModuleConfig.php | ModuleConfig.createSchema | public function createSchema(array $config = []): SchemaInterface
{
$path = rtrim(Configure::read('ModuleConfig.schemaPath'), '/');
$file = $this->configType . '.json';
$schemaPath = implode(DIRECTORY_SEPARATOR, [$path, $file]);
return new Schema($schemaPath, null, $config);
} | php | public function createSchema(array $config = []): SchemaInterface
{
$path = rtrim(Configure::read('ModuleConfig.schemaPath'), '/');
$file = $this->configType . '.json';
$schemaPath = implode(DIRECTORY_SEPARATOR, [$path, $file]);
return new Schema($schemaPath, null, $config);
} | [
"public",
"function",
"createSchema",
"(",
"array",
"$",
"config",
"=",
"[",
"]",
")",
":",
"SchemaInterface",
"{",
"$",
"path",
"=",
"rtrim",
"(",
"Configure",
"::",
"read",
"(",
"'ModuleConfig.schemaPath'",
")",
",",
"'/'",
")",
";",
"$",
"file",
"=",
... | Creates a new Schema instance for the current config type.
Reads the following configuration option: `ModuleConfig.schemaPath`.
@param mixed[] $config Schema config.
@return SchemaInterface Schema object. | [
"Creates",
"a",
"new",
"Schema",
"instance",
"for",
"the",
"current",
"config",
"type",
"."
] | 4b07a3e6f2e611e7c6909c913e6166d280f3c751 | https://github.com/QoboLtd/cakephp-utils/blob/4b07a3e6f2e611e7c6909c913e6166d280f3c751/src/ModuleConfig/ModuleConfig.php#L132-L139 | train |
QoboLtd/cakephp-utils | src/ModuleConfig/ModuleConfig.php | ModuleConfig.find | public function find(bool $validate = true)
{
$cache = $finder = $exception = $cacheKey = $result = null;
try {
// Cached response
$cache = new Cache(__FUNCTION__, $this->options);
$cacheKey = $cache->getKey([$this->module, $this->configType, $this->configFile, $validate]);
$result = $cache->readFrom($cacheKey);
if ($result !== false) {
return $result;
}
// Real response
$finder = $this->getFinder();
$result = $finder->find($this->module, $this->configFile, $validate);
} catch (InvalidArgumentException $exception) {
$this->mergeMessages($exception, __FUNCTION__);
}
// Get finder errors and warnings, if any
$this->mergeMessages($finder, __FUNCTION__);
$this->mergeMessages($cache, __FUNCTION__);
// Re-throw finder exception
if ($exception) {
throw $exception;
}
if ($cache && $cacheKey) {
$cache->writeTo($cacheKey, $result);
}
return $result;
} | php | public function find(bool $validate = true)
{
$cache = $finder = $exception = $cacheKey = $result = null;
try {
// Cached response
$cache = new Cache(__FUNCTION__, $this->options);
$cacheKey = $cache->getKey([$this->module, $this->configType, $this->configFile, $validate]);
$result = $cache->readFrom($cacheKey);
if ($result !== false) {
return $result;
}
// Real response
$finder = $this->getFinder();
$result = $finder->find($this->module, $this->configFile, $validate);
} catch (InvalidArgumentException $exception) {
$this->mergeMessages($exception, __FUNCTION__);
}
// Get finder errors and warnings, if any
$this->mergeMessages($finder, __FUNCTION__);
$this->mergeMessages($cache, __FUNCTION__);
// Re-throw finder exception
if ($exception) {
throw $exception;
}
if ($cache && $cacheKey) {
$cache->writeTo($cacheKey, $result);
}
return $result;
} | [
"public",
"function",
"find",
"(",
"bool",
"$",
"validate",
"=",
"true",
")",
"{",
"$",
"cache",
"=",
"$",
"finder",
"=",
"$",
"exception",
"=",
"$",
"cacheKey",
"=",
"$",
"result",
"=",
"null",
";",
"try",
"{",
"// Cached response",
"$",
"cache",
"=... | Find module configuration file
@param bool $validate Whether or not validate result
@return mixed Whatever the PathFinder returned | [
"Find",
"module",
"configuration",
"file"
] | 4b07a3e6f2e611e7c6909c913e6166d280f3c751 | https://github.com/QoboLtd/cakephp-utils/blob/4b07a3e6f2e611e7c6909c913e6166d280f3c751/src/ModuleConfig/ModuleConfig.php#L167-L199 | train |
QoboLtd/cakephp-utils | src/ModuleConfig/ModuleConfig.php | ModuleConfig.parse | public function parse()
{
$result = new stdClass();
$cache = $parser = $exception = $cacheKey = $path = null;
try {
$path = $this->find(false);
// Cached response
$cache = new PathCache(__FUNCTION__, $this->options);
$cacheKey = $cache->getKey([$path]);
$result = $cache->readFrom($cacheKey);
if ($result !== false) {
return $result;
}
// Real response
$parser = $this->getParser();
$result = $parser->parse($path);
} catch (InvalidArgumentException $exception) {
$this->mergeMessages($exception, __FUNCTION__);
}
$this->mergeMessages($parser, __FUNCTION__);
$this->mergeMessages($cache, __FUNCTION__);
// Re-throw parser exception
if ($exception) {
throw $exception;
}
if ($cache && $cacheKey) {
$cache->writeTo($cacheKey, $result, ['path' => $path]);
}
return $result;
} | php | public function parse()
{
$result = new stdClass();
$cache = $parser = $exception = $cacheKey = $path = null;
try {
$path = $this->find(false);
// Cached response
$cache = new PathCache(__FUNCTION__, $this->options);
$cacheKey = $cache->getKey([$path]);
$result = $cache->readFrom($cacheKey);
if ($result !== false) {
return $result;
}
// Real response
$parser = $this->getParser();
$result = $parser->parse($path);
} catch (InvalidArgumentException $exception) {
$this->mergeMessages($exception, __FUNCTION__);
}
$this->mergeMessages($parser, __FUNCTION__);
$this->mergeMessages($cache, __FUNCTION__);
// Re-throw parser exception
if ($exception) {
throw $exception;
}
if ($cache && $cacheKey) {
$cache->writeTo($cacheKey, $result, ['path' => $path]);
}
return $result;
} | [
"public",
"function",
"parse",
"(",
")",
"{",
"$",
"result",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"cache",
"=",
"$",
"parser",
"=",
"$",
"exception",
"=",
"$",
"cacheKey",
"=",
"$",
"path",
"=",
"null",
";",
"try",
"{",
"$",
"path",
"=",
... | Parse module configuration file
@return object Whatever Parser returned | [
"Parse",
"module",
"configuration",
"file"
] | 4b07a3e6f2e611e7c6909c913e6166d280f3c751 | https://github.com/QoboLtd/cakephp-utils/blob/4b07a3e6f2e611e7c6909c913e6166d280f3c751/src/ModuleConfig/ModuleConfig.php#L206-L238 | train |
QoboLtd/cakephp-utils | src/ModuleConfig/ModuleConfig.php | ModuleConfig.mergeMessages | protected function mergeMessages($source = null, string $caller = 'ModuleConfig'): void
{
$source = is_object($source) ? $source : new stdClass();
if ($source instanceof InvalidArgumentException) {
$this->errors = array_merge($this->errors, $this->formatMessages($source->getMessage(), $caller));
return;
}
if ($source instanceof ErrorAwareInterface) {
$this->errors = array_merge($this->errors, $this->formatMessages($source->getErrors(), $caller));
$this->warnings = array_merge($this->warnings, $this->formatMessages($source->getWarnings(), $caller));
return;
}
$this->errors[] = "Cannot merge messages from [" . get_class($source) . "]";
} | php | protected function mergeMessages($source = null, string $caller = 'ModuleConfig'): void
{
$source = is_object($source) ? $source : new stdClass();
if ($source instanceof InvalidArgumentException) {
$this->errors = array_merge($this->errors, $this->formatMessages($source->getMessage(), $caller));
return;
}
if ($source instanceof ErrorAwareInterface) {
$this->errors = array_merge($this->errors, $this->formatMessages($source->getErrors(), $caller));
$this->warnings = array_merge($this->warnings, $this->formatMessages($source->getWarnings(), $caller));
return;
}
$this->errors[] = "Cannot merge messages from [" . get_class($source) . "]";
} | [
"protected",
"function",
"mergeMessages",
"(",
"$",
"source",
"=",
"null",
",",
"string",
"$",
"caller",
"=",
"'ModuleConfig'",
")",
":",
"void",
"{",
"$",
"source",
"=",
"is_object",
"(",
"$",
"source",
")",
"?",
"$",
"source",
":",
"new",
"stdClass",
... | Merge warning and error messages
Merge warning and error messages from a given source
object into our warnings and messages.
@param object $source Source object (ideally one using ErrorTrait)
@param string $caller Caller that generated a message
@return void | [
"Merge",
"warning",
"and",
"error",
"messages"
] | 4b07a3e6f2e611e7c6909c913e6166d280f3c751 | https://github.com/QoboLtd/cakephp-utils/blob/4b07a3e6f2e611e7c6909c913e6166d280f3c751/src/ModuleConfig/ModuleConfig.php#L289-L307 | train |
QoboLtd/cakephp-utils | src/ModuleConfig/ModuleConfig.php | ModuleConfig.exists | public static function exists(string $moduleName, array $options = []) : bool
{
$config = (new ModuleConfig(ConfigType::MIGRATION(), $moduleName, null, $options))->parseToArray();
if (empty($config)) {
return false;
}
$config = (new ModuleConfig(ConfigType::MODULE(), $moduleName, null, $options))->parseToArray();
if (empty($config['table']) || empty($config['table']['type'])) {
return false;
}
return true;
} | php | public static function exists(string $moduleName, array $options = []) : bool
{
$config = (new ModuleConfig(ConfigType::MIGRATION(), $moduleName, null, $options))->parseToArray();
if (empty($config)) {
return false;
}
$config = (new ModuleConfig(ConfigType::MODULE(), $moduleName, null, $options))->parseToArray();
if (empty($config['table']) || empty($config['table']['type'])) {
return false;
}
return true;
} | [
"public",
"static",
"function",
"exists",
"(",
"string",
"$",
"moduleName",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"bool",
"{",
"$",
"config",
"=",
"(",
"new",
"ModuleConfig",
"(",
"ConfigType",
"::",
"MIGRATION",
"(",
")",
",",
"$",
... | Checks if the provided module name exists
@param string $moduleName Module name
@param mixed[] $options Options for ModuleConfig constructor
@return bool | [
"Checks",
"if",
"the",
"provided",
"module",
"name",
"exists"
] | 4b07a3e6f2e611e7c6909c913e6166d280f3c751 | https://github.com/QoboLtd/cakephp-utils/blob/4b07a3e6f2e611e7c6909c913e6166d280f3c751/src/ModuleConfig/ModuleConfig.php#L316-L329 | train |
QoboLtd/cakephp-utils | src/ModuleConfig/ModuleConfig.php | ModuleConfig.hasMigrationFields | public static function hasMigrationFields(string $moduleName, array $fields, array $options = []): bool
{
$config = (new ModuleConfig(ConfigType::MIGRATION(), $moduleName, null, $options))->parseToArray();
$fieldKeys = array_flip($fields);
$diff = array_diff_key($fieldKeys, $config);
return empty($diff);
} | php | public static function hasMigrationFields(string $moduleName, array $fields, array $options = []): bool
{
$config = (new ModuleConfig(ConfigType::MIGRATION(), $moduleName, null, $options))->parseToArray();
$fieldKeys = array_flip($fields);
$diff = array_diff_key($fieldKeys, $config);
return empty($diff);
} | [
"public",
"static",
"function",
"hasMigrationFields",
"(",
"string",
"$",
"moduleName",
",",
"array",
"$",
"fields",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"bool",
"{",
"$",
"config",
"=",
"(",
"new",
"ModuleConfig",
"(",
"ConfigType",
":... | Checks whether the provided fields exists in migration configuration
@param string $moduleName Module name
@param mixed[] $fields List of fields to be checked
@param mixed[] $options Options for ModuleConfig constructor
@return bool | [
"Checks",
"whether",
"the",
"provided",
"fields",
"exists",
"in",
"migration",
"configuration"
] | 4b07a3e6f2e611e7c6909c913e6166d280f3c751 | https://github.com/QoboLtd/cakephp-utils/blob/4b07a3e6f2e611e7c6909c913e6166d280f3c751/src/ModuleConfig/ModuleConfig.php#L339-L347 | train |
subscribepro/subscribepro-php | src/SubscribePro/Service/Webhook/WebhookService.php | WebhookService.readEvent | public function readEvent()
{
$rawRequestBody = $this->httpClient->getRawRequest();
$webhookEvent = !empty($rawRequestBody['webhook_event'])
? json_decode($rawRequestBody['webhook_event'], true)
: false;
return $webhookEvent ? $this->dataFactory->create($webhookEvent) : false;
} | php | public function readEvent()
{
$rawRequestBody = $this->httpClient->getRawRequest();
$webhookEvent = !empty($rawRequestBody['webhook_event'])
? json_decode($rawRequestBody['webhook_event'], true)
: false;
return $webhookEvent ? $this->dataFactory->create($webhookEvent) : false;
} | [
"public",
"function",
"readEvent",
"(",
")",
"{",
"$",
"rawRequestBody",
"=",
"$",
"this",
"->",
"httpClient",
"->",
"getRawRequest",
"(",
")",
";",
"$",
"webhookEvent",
"=",
"!",
"empty",
"(",
"$",
"rawRequestBody",
"[",
"'webhook_event'",
"]",
")",
"?",
... | Read webhook event from request
@return \SubscribePro\Service\Webhook\EventInterface|bool | [
"Read",
"webhook",
"event",
"from",
"request"
] | e1909a4ac0cf7855466411a3fd1f017524218cc6 | https://github.com/subscribepro/subscribepro-php/blob/e1909a4ac0cf7855466411a3fd1f017524218cc6/src/SubscribePro/Service/Webhook/WebhookService.php#L57-L64 | train |
romm/formz | Classes/AssetHandler/Connector/CssAssetHandlerConnector.php | CssAssetHandlerConnector.includeGeneratedCss | public function includeGeneratedCss()
{
$filePath = $this->assetHandlerConnectorManager->getFormzGeneratedFilePath() . '.css';
$this->assetHandlerConnectorManager->createFileInTemporaryDirectory(
$filePath,
function () {
/** @var MessageContainerDisplayCssAssetHandler $errorContainerDisplayCssAssetHandler */
$errorContainerDisplayCssAssetHandler = $this->assetHandlerConnectorManager
->getAssetHandlerFactory()
->getAssetHandler(MessageContainerDisplayCssAssetHandler::class);
/** @var FieldsActivationCssAssetHandler $fieldsActivationCssAssetHandler */
$fieldsActivationCssAssetHandler = $this->assetHandlerConnectorManager
->getAssetHandlerFactory()
->getAssetHandler(FieldsActivationCssAssetHandler::class);
$css = $errorContainerDisplayCssAssetHandler->getErrorContainerDisplayCss() . LF;
$css .= $fieldsActivationCssAssetHandler->getFieldsActivationCss();
return $css;
}
);
$this->assetHandlerConnectorManager
->getPageRenderer()
->addCssFile(StringService::get()->getResourceRelativePath($filePath));
return $this;
} | php | public function includeGeneratedCss()
{
$filePath = $this->assetHandlerConnectorManager->getFormzGeneratedFilePath() . '.css';
$this->assetHandlerConnectorManager->createFileInTemporaryDirectory(
$filePath,
function () {
/** @var MessageContainerDisplayCssAssetHandler $errorContainerDisplayCssAssetHandler */
$errorContainerDisplayCssAssetHandler = $this->assetHandlerConnectorManager
->getAssetHandlerFactory()
->getAssetHandler(MessageContainerDisplayCssAssetHandler::class);
/** @var FieldsActivationCssAssetHandler $fieldsActivationCssAssetHandler */
$fieldsActivationCssAssetHandler = $this->assetHandlerConnectorManager
->getAssetHandlerFactory()
->getAssetHandler(FieldsActivationCssAssetHandler::class);
$css = $errorContainerDisplayCssAssetHandler->getErrorContainerDisplayCss() . LF;
$css .= $fieldsActivationCssAssetHandler->getFieldsActivationCss();
return $css;
}
);
$this->assetHandlerConnectorManager
->getPageRenderer()
->addCssFile(StringService::get()->getResourceRelativePath($filePath));
return $this;
} | [
"public",
"function",
"includeGeneratedCss",
"(",
")",
"{",
"$",
"filePath",
"=",
"$",
"this",
"->",
"assetHandlerConnectorManager",
"->",
"getFormzGeneratedFilePath",
"(",
")",
".",
"'.css'",
";",
"$",
"this",
"->",
"assetHandlerConnectorManager",
"->",
"createFile... | Will take care of generating the CSS with the `AssetHandlerFactory`. The
code will be put in a `.css` file in the `typo3temp` directory.
If the file already exists, it is included directly before the code
generation.
@return $this | [
"Will",
"take",
"care",
"of",
"generating",
"the",
"CSS",
"with",
"the",
"AssetHandlerFactory",
".",
"The",
"code",
"will",
"be",
"put",
"in",
"a",
".",
"css",
"file",
"in",
"the",
"typo3temp",
"directory",
"."
] | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/AssetHandler/Connector/CssAssetHandlerConnector.php#L73-L102 | train |
romm/formz | Classes/AssetHandler/Connector/AssetHandlerConnectorManager.php | AssetHandlerConnectorManager.includeDefaultAssets | public function includeDefaultAssets()
{
if (false === $this->assetHandlerConnectorStates->defaultAssetsWereIncluded()) {
$this->assetHandlerConnectorStates->markDefaultAssetsAsIncluded();
$this->getJavaScriptAssetHandlerConnector()->includeDefaultJavaScriptFiles();
$this->getCssAssetHandlerConnector()->includeDefaultCssFiles();
}
return $this;
} | php | public function includeDefaultAssets()
{
if (false === $this->assetHandlerConnectorStates->defaultAssetsWereIncluded()) {
$this->assetHandlerConnectorStates->markDefaultAssetsAsIncluded();
$this->getJavaScriptAssetHandlerConnector()->includeDefaultJavaScriptFiles();
$this->getCssAssetHandlerConnector()->includeDefaultCssFiles();
}
return $this;
} | [
"public",
"function",
"includeDefaultAssets",
"(",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"assetHandlerConnectorStates",
"->",
"defaultAssetsWereIncluded",
"(",
")",
")",
"{",
"$",
"this",
"->",
"assetHandlerConnectorStates",
"->",
"markDefaultAsset... | Will take care of including internal FormZ JavaScript and CSS files. They
will be included only once, even if the view helper is used several times
in the same page.
@return $this | [
"Will",
"take",
"care",
"of",
"including",
"internal",
"FormZ",
"JavaScript",
"and",
"CSS",
"files",
".",
"They",
"will",
"be",
"included",
"only",
"once",
"even",
"if",
"the",
"view",
"helper",
"is",
"used",
"several",
"times",
"in",
"the",
"same",
"page"... | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/AssetHandler/Connector/AssetHandlerConnectorManager.php#L94-L104 | train |
romm/formz | Classes/AssetHandler/Connector/AssetHandlerConnectorManager.php | AssetHandlerConnectorManager.getFormzGeneratedFilePath | public function getFormzGeneratedFilePath($prefix = '')
{
$formObject = $this->assetHandlerFactory->getFormObject();
$formIdentifier = CacheService::get()->getFormCacheIdentifier($formObject->getClassName(), $formObject->getName());
$prefix = (false === empty($prefix))
? $prefix . '-'
: '';
$identifier = substr(
'fz-' . $prefix . $formIdentifier,
0,
22
);
$identifier .= '-' . md5($formObject->getHash() . $formObject->getName());
return CacheService::GENERATED_FILES_PATH . $identifier;
} | php | public function getFormzGeneratedFilePath($prefix = '')
{
$formObject = $this->assetHandlerFactory->getFormObject();
$formIdentifier = CacheService::get()->getFormCacheIdentifier($formObject->getClassName(), $formObject->getName());
$prefix = (false === empty($prefix))
? $prefix . '-'
: '';
$identifier = substr(
'fz-' . $prefix . $formIdentifier,
0,
22
);
$identifier .= '-' . md5($formObject->getHash() . $formObject->getName());
return CacheService::GENERATED_FILES_PATH . $identifier;
} | [
"public",
"function",
"getFormzGeneratedFilePath",
"(",
"$",
"prefix",
"=",
"''",
")",
"{",
"$",
"formObject",
"=",
"$",
"this",
"->",
"assetHandlerFactory",
"->",
"getFormObject",
"(",
")",
";",
"$",
"formIdentifier",
"=",
"CacheService",
"::",
"get",
"(",
... | Returns a file name based on the form object class name.
@param string $prefix
@return string | [
"Returns",
"a",
"file",
"name",
"based",
"on",
"the",
"form",
"object",
"class",
"name",
"."
] | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/AssetHandler/Connector/AssetHandlerConnectorManager.php#L112-L128 | train |
romm/formz | Classes/AssetHandler/Connector/AssetHandlerConnectorManager.php | AssetHandlerConnectorManager.createFileInTemporaryDirectory | public function createFileInTemporaryDirectory($relativePath, callable $callback)
{
$result = false;
$absolutePath = GeneralUtility::getFileAbsFileName($relativePath);
if (false === $this->fileExists($absolutePath)) {
$content = call_user_func($callback);
$result = $this->writeTemporaryFile($absolutePath, $content);
if (null !== $result) {
throw FileCreationFailedException::fileCreationFailed($absolutePath, $result);
}
}
return $result;
} | php | public function createFileInTemporaryDirectory($relativePath, callable $callback)
{
$result = false;
$absolutePath = GeneralUtility::getFileAbsFileName($relativePath);
if (false === $this->fileExists($absolutePath)) {
$content = call_user_func($callback);
$result = $this->writeTemporaryFile($absolutePath, $content);
if (null !== $result) {
throw FileCreationFailedException::fileCreationFailed($absolutePath, $result);
}
}
return $result;
} | [
"public",
"function",
"createFileInTemporaryDirectory",
"(",
"$",
"relativePath",
",",
"callable",
"$",
"callback",
")",
"{",
"$",
"result",
"=",
"false",
";",
"$",
"absolutePath",
"=",
"GeneralUtility",
"::",
"getFileAbsFileName",
"(",
"$",
"relativePath",
")",
... | This function will check if the file at the given path exists. If it does
not, the callback is called to get the content of the file, which is put
in the created file.
A boolean is returned: if the file did not exist, and it was created
without error, `true` is returned. Otherwise, `false` is returned.
@param string $relativePath
@param callable $callback
@return bool
@throws FileCreationFailedException | [
"This",
"function",
"will",
"check",
"if",
"the",
"file",
"at",
"the",
"given",
"path",
"exists",
".",
"If",
"it",
"does",
"not",
"the",
"callback",
"is",
"called",
"to",
"get",
"the",
"content",
"of",
"the",
"file",
"which",
"is",
"put",
"in",
"the",
... | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/AssetHandler/Connector/AssetHandlerConnectorManager.php#L143-L159 | train |
romm/formz | Classes/Service/ContextService.php | ContextService.getContextHash | public function getContextHash()
{
return ($this->environmentService->isEnvironmentInFrontendMode())
? 'fe-' . Core::get()->getPageController()->id
: 'be-' . StringService::get()->sanitizeString(GeneralUtility::_GET('M'));
} | php | public function getContextHash()
{
return ($this->environmentService->isEnvironmentInFrontendMode())
? 'fe-' . Core::get()->getPageController()->id
: 'be-' . StringService::get()->sanitizeString(GeneralUtility::_GET('M'));
} | [
"public",
"function",
"getContextHash",
"(",
")",
"{",
"return",
"(",
"$",
"this",
"->",
"environmentService",
"->",
"isEnvironmentInFrontendMode",
"(",
")",
")",
"?",
"'fe-'",
".",
"Core",
"::",
"get",
"(",
")",
"->",
"getPageController",
"(",
")",
"->",
... | Returns a unique hash for the context of the current request, depending
on whether the request comes from frontend or backend.
@return string | [
"Returns",
"a",
"unique",
"hash",
"for",
"the",
"context",
"of",
"the",
"current",
"request",
"depending",
"on",
"whether",
"the",
"request",
"comes",
"from",
"frontend",
"or",
"backend",
"."
] | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/Service/ContextService.php#L43-L48 | train |
romm/formz | Classes/Service/ContextService.php | ContextService.getLanguageKey | public function getLanguageKey()
{
$languageKey = 'unknown';
if ($this->environmentService->isEnvironmentInFrontendMode()) {
$pageController = Core::get()->getPageController();
if (isset($pageController->config['config']['language'])) {
$languageKey = $pageController->config['config']['language'];
}
} else {
$backendUser = Core::get()->getBackendUser();
if (strlen($backendUser->uc['lang']) > 0) {
$languageKey = $backendUser->uc['lang'];
}
}
return $languageKey;
} | php | public function getLanguageKey()
{
$languageKey = 'unknown';
if ($this->environmentService->isEnvironmentInFrontendMode()) {
$pageController = Core::get()->getPageController();
if (isset($pageController->config['config']['language'])) {
$languageKey = $pageController->config['config']['language'];
}
} else {
$backendUser = Core::get()->getBackendUser();
if (strlen($backendUser->uc['lang']) > 0) {
$languageKey = $backendUser->uc['lang'];
}
}
return $languageKey;
} | [
"public",
"function",
"getLanguageKey",
"(",
")",
"{",
"$",
"languageKey",
"=",
"'unknown'",
";",
"if",
"(",
"$",
"this",
"->",
"environmentService",
"->",
"isEnvironmentInFrontendMode",
"(",
")",
")",
"{",
"$",
"pageController",
"=",
"Core",
"::",
"get",
"(... | Returns the current language key.
@return string | [
"Returns",
"the",
"current",
"language",
"key",
"."
] | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/Service/ContextService.php#L55-L74 | train |
vegas-cmf/forms | src/Element/Select.php | Select.addOptions | public function addOptions(array $options)
{
$existingOptions = $this->getOptions();
$newOptions = empty($existingOptions) ? $options : array_merge((array)$existingOptions, $options);
$this->setOptions($newOptions);
return $this;
} | php | public function addOptions(array $options)
{
$existingOptions = $this->getOptions();
$newOptions = empty($existingOptions) ? $options : array_merge((array)$existingOptions, $options);
$this->setOptions($newOptions);
return $this;
} | [
"public",
"function",
"addOptions",
"(",
"array",
"$",
"options",
")",
"{",
"$",
"existingOptions",
"=",
"$",
"this",
"->",
"getOptions",
"(",
")",
";",
"$",
"newOptions",
"=",
"empty",
"(",
"$",
"existingOptions",
")",
"?",
"$",
"options",
":",
"array_m... | Allows to add multiple options at once when providing just one array.
@param array $options array of key => value for each option
@return $this | [
"Allows",
"to",
"add",
"multiple",
"options",
"at",
"once",
"when",
"providing",
"just",
"one",
"array",
"."
] | f2513b1367c3124f399955ed50ff0e3c13eb671b | https://github.com/vegas-cmf/forms/blob/f2513b1367c3124f399955ed50ff0e3c13eb671b/src/Element/Select.php#L25-L31 | train |
QoboLtd/cakephp-utils | src/ModuleConfig/Parser/Parser.php | Parser.getDataFromPath | protected function getDataFromPath(string $path): string
{
$isPathRequired = $this->getConfig('pathRequired');
try {
Utility::validatePath($path);
} catch (InvalidArgumentException $e) {
if ($isPathRequired) {
throw $e;
}
$this->warnings[] = $e->getMessage();
return (string)json_encode($this->getEmptyResult());
}
return (string)file_get_contents($path);
} | php | protected function getDataFromPath(string $path): string
{
$isPathRequired = $this->getConfig('pathRequired');
try {
Utility::validatePath($path);
} catch (InvalidArgumentException $e) {
if ($isPathRequired) {
throw $e;
}
$this->warnings[] = $e->getMessage();
return (string)json_encode($this->getEmptyResult());
}
return (string)file_get_contents($path);
} | [
"protected",
"function",
"getDataFromPath",
"(",
"string",
"$",
"path",
")",
":",
"string",
"{",
"$",
"isPathRequired",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'pathRequired'",
")",
";",
"try",
"{",
"Utility",
"::",
"validatePath",
"(",
"$",
"path",
")"... | Read raw data from path.
If the configuration option `pathRequired` is set to `true`, then an
exception will be raised if the path cannot be validated.
Otherwise a warning will be raised and a string representation of an
empty json object will be sent back to the caller.
@see \Qobo\Utils\Utility::validatePath()
@param string $path Full path to file.
@return string File contents. | [
"Read",
"raw",
"data",
"from",
"path",
"."
] | 4b07a3e6f2e611e7c6909c913e6166d280f3c751 | https://github.com/QoboLtd/cakephp-utils/blob/4b07a3e6f2e611e7c6909c913e6166d280f3c751/src/ModuleConfig/Parser/Parser.php#L144-L160 | train |
QoboLtd/cakephp-utils | src/ModuleConfig/Parser/Parser.php | Parser.validate | protected function validate(stdClass $data): void
{
$config = $this->getConfig();
$schema = $this->readSchema();
// No need to validate empty data (empty() does not work on objects)
$dataArray = Convert::objectToArray($data);
if (empty($dataArray)) {
if ($config['allowEmptyData'] === false) {
throw new JsonValidationException('Empty data is not allowed.');
}
$this->warnings[] = "Skipping validation of empty data";
return;
}
// No need to validate with empty schema (empty() does not work on objects)
$schemaArray = Convert::objectToArray($schema);
if (empty($schemaArray)) {
if ($config['allowEmptySchema'] === false) {
throw new JsonValidationException('Empty schema is not allowed.');
}
$this->warnings[] = "Skipping validation with empty schema";
return;
}
$this->runValidator($data, $schema);
} | php | protected function validate(stdClass $data): void
{
$config = $this->getConfig();
$schema = $this->readSchema();
// No need to validate empty data (empty() does not work on objects)
$dataArray = Convert::objectToArray($data);
if (empty($dataArray)) {
if ($config['allowEmptyData'] === false) {
throw new JsonValidationException('Empty data is not allowed.');
}
$this->warnings[] = "Skipping validation of empty data";
return;
}
// No need to validate with empty schema (empty() does not work on objects)
$schemaArray = Convert::objectToArray($schema);
if (empty($schemaArray)) {
if ($config['allowEmptySchema'] === false) {
throw new JsonValidationException('Empty schema is not allowed.');
}
$this->warnings[] = "Skipping validation with empty schema";
return;
}
$this->runValidator($data, $schema);
} | [
"protected",
"function",
"validate",
"(",
"stdClass",
"$",
"data",
")",
":",
"void",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
";",
"$",
"schema",
"=",
"$",
"this",
"->",
"readSchema",
"(",
")",
";",
"// No need to validate empty... | Validate the JSON object against the schema.
@param \stdClass $data JSON object.
@throws \Qobo\Utils\ModuleConfig\Parser\JsonValidationException When json validation fails.
@return void | [
"Validate",
"the",
"JSON",
"object",
"against",
"the",
"schema",
"."
] | 4b07a3e6f2e611e7c6909c913e6166d280f3c751 | https://github.com/QoboLtd/cakephp-utils/blob/4b07a3e6f2e611e7c6909c913e6166d280f3c751/src/ModuleConfig/Parser/Parser.php#L169-L197 | train |
QoboLtd/cakephp-utils | src/ModuleConfig/Parser/Parser.php | Parser.readSchema | protected function readSchema(): \stdClass
{
$schema = $this->getEmptyResult();
try {
$schema = $this->getSchema()->read();
} catch (InvalidArgumentException $e) {
$this->errors[] = $e->getMessage();
throw new JsonValidationException("Schema file `{$this->schema->getSchemaPath()}` cannot be read", 0, $e);
}
return $schema;
} | php | protected function readSchema(): \stdClass
{
$schema = $this->getEmptyResult();
try {
$schema = $this->getSchema()->read();
} catch (InvalidArgumentException $e) {
$this->errors[] = $e->getMessage();
throw new JsonValidationException("Schema file `{$this->schema->getSchemaPath()}` cannot be read", 0, $e);
}
return $schema;
} | [
"protected",
"function",
"readSchema",
"(",
")",
":",
"\\",
"stdClass",
"{",
"$",
"schema",
"=",
"$",
"this",
"->",
"getEmptyResult",
"(",
")",
";",
"try",
"{",
"$",
"schema",
"=",
"$",
"this",
"->",
"getSchema",
"(",
")",
"->",
"read",
"(",
")",
"... | Reads the schema.
@throws \Qobo\Utils\ModuleConfig\Parser\JsonValidationException When the schema cannot be read.
@return \stdClass Schema | [
"Reads",
"the",
"schema",
"."
] | 4b07a3e6f2e611e7c6909c913e6166d280f3c751 | https://github.com/QoboLtd/cakephp-utils/blob/4b07a3e6f2e611e7c6909c913e6166d280f3c751/src/ModuleConfig/Parser/Parser.php#L205-L218 | train |
QoboLtd/cakephp-utils | src/ModuleConfig/Parser/Parser.php | Parser.runValidator | protected function runValidator(stdClass $data, stdClass $schema): void
{
$config = $this->getConfig();
$validator = new Validator;
$validator->validate($data, $schema, $config['validationMode']);
if (!$validator->isValid()) {
foreach ($validator->getErrors() as $error) {
$this->errors[] = sprintf('[%s]: %s', $error['pointer'], $error['message']);
}
throw new JsonValidationException('Failed to validate json data against the schema.');
}
} | php | protected function runValidator(stdClass $data, stdClass $schema): void
{
$config = $this->getConfig();
$validator = new Validator;
$validator->validate($data, $schema, $config['validationMode']);
if (!$validator->isValid()) {
foreach ($validator->getErrors() as $error) {
$this->errors[] = sprintf('[%s]: %s', $error['pointer'], $error['message']);
}
throw new JsonValidationException('Failed to validate json data against the schema.');
}
} | [
"protected",
"function",
"runValidator",
"(",
"stdClass",
"$",
"data",
",",
"stdClass",
"$",
"schema",
")",
":",
"void",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
";",
"$",
"validator",
"=",
"new",
"Validator",
";",
"$",
"valid... | Runs the json validation.
@param stdClass $data Data to validate against a schema.
@param stdClass $schema The schema which is used to validate the data.
@throws \Qobo\Utils\ModuleConfig\Parser\JsonValidationException When the validation fails.
@return void | [
"Runs",
"the",
"json",
"validation",
"."
] | 4b07a3e6f2e611e7c6909c913e6166d280f3c751 | https://github.com/QoboLtd/cakephp-utils/blob/4b07a3e6f2e611e7c6909c913e6166d280f3c751/src/ModuleConfig/Parser/Parser.php#L228-L242 | train |
romm/formz | Classes/ViewHelpers/FormViewHelper.php | FormViewHelper.renderForm | final protected function renderForm(array $arguments)
{
/*
* We begin by setting up the form service: request results and form
* instance are inserted in the service, and are used afterwards.
*
* There are only two ways to be sure the values injected are correct:
* when the form was actually submitted by the user, or when the
* argument `object` of the view helper is filled with a form instance.
*/
$this->formService->activateFormContext();
/*
* If the form was submitted, applying custom behaviours on its fields.
*/
$this->formService->applyBehavioursOnSubmittedForm($this->controllerContext);
/*
* Adding the default class configured in TypoScript configuration to
* the form HTML tag.
*/
$this->addDefaultClass();
/*
* Handling data attributes that are added to the form HTML tag,
* depending on several parameters.
*/
$this->handleDataAttributes();
/*
* Including JavaScript and CSS assets in the page renderer.
*/
$this->handleAssets();
$this->timeTracker->logTime('pre-render');
/*
* Getting the result of the original Fluid `FormViewHelper` rendering.
*/
$result = $this->getParentRenderResult($arguments);
/*
* Language files need to be included at the end, because they depend on
* what was used by previous assets.
*/
$this->getAssetHandlerConnectorManager()
->getJavaScriptAssetHandlerConnector()
->includeLanguageJavaScriptFiles();
return $result;
} | php | final protected function renderForm(array $arguments)
{
/*
* We begin by setting up the form service: request results and form
* instance are inserted in the service, and are used afterwards.
*
* There are only two ways to be sure the values injected are correct:
* when the form was actually submitted by the user, or when the
* argument `object` of the view helper is filled with a form instance.
*/
$this->formService->activateFormContext();
/*
* If the form was submitted, applying custom behaviours on its fields.
*/
$this->formService->applyBehavioursOnSubmittedForm($this->controllerContext);
/*
* Adding the default class configured in TypoScript configuration to
* the form HTML tag.
*/
$this->addDefaultClass();
/*
* Handling data attributes that are added to the form HTML tag,
* depending on several parameters.
*/
$this->handleDataAttributes();
/*
* Including JavaScript and CSS assets in the page renderer.
*/
$this->handleAssets();
$this->timeTracker->logTime('pre-render');
/*
* Getting the result of the original Fluid `FormViewHelper` rendering.
*/
$result = $this->getParentRenderResult($arguments);
/*
* Language files need to be included at the end, because they depend on
* what was used by previous assets.
*/
$this->getAssetHandlerConnectorManager()
->getJavaScriptAssetHandlerConnector()
->includeLanguageJavaScriptFiles();
return $result;
} | [
"final",
"protected",
"function",
"renderForm",
"(",
"array",
"$",
"arguments",
")",
"{",
"/*\n * We begin by setting up the form service: request results and form\n * instance are inserted in the service, and are used afterwards.\n *\n * There are only two ways t... | Will render the whole form and return the HTML result.
@param array $arguments
@return string | [
"Will",
"render",
"the",
"whole",
"form",
"and",
"return",
"the",
"HTML",
"result",
"."
] | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/ViewHelpers/FormViewHelper.php#L210-L260 | train |
romm/formz | Classes/ViewHelpers/FormViewHelper.php | FormViewHelper.addDefaultClass | protected function addDefaultClass()
{
$formDefaultClass = $this->formObject
->getConfiguration()
->getSettings()
->getDefaultClass();
$class = $this->tag->getAttribute('class');
if (false === empty($formDefaultClass)) {
$class = (!empty($class) ? $class . ' ' : '') . $formDefaultClass;
$this->tag->addAttribute('class', $class);
}
} | php | protected function addDefaultClass()
{
$formDefaultClass = $this->formObject
->getConfiguration()
->getSettings()
->getDefaultClass();
$class = $this->tag->getAttribute('class');
if (false === empty($formDefaultClass)) {
$class = (!empty($class) ? $class . ' ' : '') . $formDefaultClass;
$this->tag->addAttribute('class', $class);
}
} | [
"protected",
"function",
"addDefaultClass",
"(",
")",
"{",
"$",
"formDefaultClass",
"=",
"$",
"this",
"->",
"formObject",
"->",
"getConfiguration",
"(",
")",
"->",
"getSettings",
"(",
")",
"->",
"getDefaultClass",
"(",
")",
";",
"$",
"class",
"=",
"$",
"th... | Will add a default class to the form element.
To customize the class, take a look at `settings.defaultClass` in the
form TypoScript configuration. | [
"Will",
"add",
"a",
"default",
"class",
"to",
"the",
"form",
"element",
"."
] | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/ViewHelpers/FormViewHelper.php#L268-L281 | train |
romm/formz | Classes/ViewHelpers/FormViewHelper.php | FormViewHelper.handleDataAttributes | protected function handleDataAttributes()
{
$dataAttributes = [];
$dataAttributesAssetHandler = $this->getDataAttributesAssetHandler();
if ($this->formObject->hasForm()) {
if (false === $this->formObject->hasFormResult()) {
$form = $this->formObject->getForm();
$formValidator = $this->getFormValidator($this->getFormObjectName());
$formResult = $formValidator->validateGhost($form);
} else {
$formResult = $this->formObject->getFormResult();
}
$dataAttributes += $dataAttributesAssetHandler->getFieldsValuesDataAttributes($formResult);
}
if (true === $this->formObject->formWasSubmitted()) {
$dataAttributes += [DataAttributesAssetHandler::getFieldSubmissionDone() => '1'];
$dataAttributes += $dataAttributesAssetHandler->getFieldsValidDataAttributes();
$dataAttributes += $dataAttributesAssetHandler->getFieldsMessagesDataAttributes();
}
$this->tag->addAttributes($dataAttributes);
} | php | protected function handleDataAttributes()
{
$dataAttributes = [];
$dataAttributesAssetHandler = $this->getDataAttributesAssetHandler();
if ($this->formObject->hasForm()) {
if (false === $this->formObject->hasFormResult()) {
$form = $this->formObject->getForm();
$formValidator = $this->getFormValidator($this->getFormObjectName());
$formResult = $formValidator->validateGhost($form);
} else {
$formResult = $this->formObject->getFormResult();
}
$dataAttributes += $dataAttributesAssetHandler->getFieldsValuesDataAttributes($formResult);
}
if (true === $this->formObject->formWasSubmitted()) {
$dataAttributes += [DataAttributesAssetHandler::getFieldSubmissionDone() => '1'];
$dataAttributes += $dataAttributesAssetHandler->getFieldsValidDataAttributes();
$dataAttributes += $dataAttributesAssetHandler->getFieldsMessagesDataAttributes();
}
$this->tag->addAttributes($dataAttributes);
} | [
"protected",
"function",
"handleDataAttributes",
"(",
")",
"{",
"$",
"dataAttributes",
"=",
"[",
"]",
";",
"$",
"dataAttributesAssetHandler",
"=",
"$",
"this",
"->",
"getDataAttributesAssetHandler",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"formObject",
"-... | Adds custom data attributes to the form element, based on the
submitted form values and results. | [
"Adds",
"custom",
"data",
"attributes",
"to",
"the",
"form",
"element",
"based",
"on",
"the",
"submitted",
"form",
"values",
"and",
"results",
"."
] | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/ViewHelpers/FormViewHelper.php#L287-L312 | train |
romm/formz | Classes/ViewHelpers/FormViewHelper.php | FormViewHelper.handleAssets | protected function handleAssets()
{
$assetHandlerConnectorManager = $this->getAssetHandlerConnectorManager();
// Default FormZ assets.
$assetHandlerConnectorManager->includeDefaultAssets();
// JavaScript assets.
$assetHandlerConnectorManager->getJavaScriptAssetHandlerConnector()
->generateAndIncludeFormzConfigurationJavaScript()
->generateAndIncludeJavaScript()
->generateAndIncludeInlineJavaScript()
->includeJavaScriptValidationAndConditionFiles();
// CSS assets.
$assetHandlerConnectorManager->getCssAssetHandlerConnector()
->includeGeneratedCss();
} | php | protected function handleAssets()
{
$assetHandlerConnectorManager = $this->getAssetHandlerConnectorManager();
// Default FormZ assets.
$assetHandlerConnectorManager->includeDefaultAssets();
// JavaScript assets.
$assetHandlerConnectorManager->getJavaScriptAssetHandlerConnector()
->generateAndIncludeFormzConfigurationJavaScript()
->generateAndIncludeJavaScript()
->generateAndIncludeInlineJavaScript()
->includeJavaScriptValidationAndConditionFiles();
// CSS assets.
$assetHandlerConnectorManager->getCssAssetHandlerConnector()
->includeGeneratedCss();
} | [
"protected",
"function",
"handleAssets",
"(",
")",
"{",
"$",
"assetHandlerConnectorManager",
"=",
"$",
"this",
"->",
"getAssetHandlerConnectorManager",
"(",
")",
";",
"// Default FormZ assets.",
"$",
"assetHandlerConnectorManager",
"->",
"includeDefaultAssets",
"(",
")",
... | Will include all JavaScript and CSS assets needed for this form. | [
"Will",
"include",
"all",
"JavaScript",
"and",
"CSS",
"assets",
"needed",
"for",
"this",
"form",
"."
] | b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f | https://github.com/romm/formz/blob/b0bc266a1c86377ab43ef8d1c07a4b5f54d5fc3f/Classes/ViewHelpers/FormViewHelper.php#L317-L334 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.