repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
esperecyan/dictionary-php
src/serializer/CatchfeelingSerializer.php
CatchfeelingSerializer.serializeWord
protected function serializeWord(array $word): string { if (!isset($word['type'][0]) || $word['type'][0] !== 'selection') { $answers = $this->getOrderedAnswers($word); if ($answers) { foreach ($answers as $answer) { if (strpos($answer, '//') === false) { $output = $answer; break; } } if (!isset($output)) { $output = str_replace('/', '/', $answers[0]); } $output = strtolower($output); $comment = ''; if (isset($word['answer'][0])) { $shiftJISableText = $this->convertToShiftJISable($word['text'][0]); if ($answers[0] !== $shiftJISableText && $this->isShiftJISable($shiftJISableText)) { $comment .= "【${shiftJISableText}】"; } } if (isset($word['description'][0])) { $shiftJISableDescription = $this->convertToShiftJISable($word['description'][0]['lml']); if ($this->isShiftJISable($shiftJISableDescription)) { $comment .= $shiftJISableDescription; } } if ($comment !== '') { $output .= "\t// " . str_replace("\n", ' ', $comment); } $output .= "\r\n"; } } if (!isset($output)) { $output = ''; $this->logUnserializableError('キャッチフィーリング', $word); } return $output; }
php
protected function serializeWord(array $word): string { if (!isset($word['type'][0]) || $word['type'][0] !== 'selection') { $answers = $this->getOrderedAnswers($word); if ($answers) { foreach ($answers as $answer) { if (strpos($answer, '//') === false) { $output = $answer; break; } } if (!isset($output)) { $output = str_replace('/', '/', $answers[0]); } $output = strtolower($output); $comment = ''; if (isset($word['answer'][0])) { $shiftJISableText = $this->convertToShiftJISable($word['text'][0]); if ($answers[0] !== $shiftJISableText && $this->isShiftJISable($shiftJISableText)) { $comment .= "【${shiftJISableText}】"; } } if (isset($word['description'][0])) { $shiftJISableDescription = $this->convertToShiftJISable($word['description'][0]['lml']); if ($this->isShiftJISable($shiftJISableDescription)) { $comment .= $shiftJISableDescription; } } if ($comment !== '') { $output .= "\t// " . str_replace("\n", ' ', $comment); } $output .= "\r\n"; } } if (!isset($output)) { $output = ''; $this->logUnserializableError('キャッチフィーリング', $word); } return $output; }
[ "protected", "function", "serializeWord", "(", "array", "$", "word", ")", ":", "string", "{", "if", "(", "!", "isset", "(", "$", "word", "[", "'type'", "]", "[", "0", "]", ")", "||", "$", "word", "[", "'type'", "]", "[", "0", "]", "!==", "'selection'", ")", "{", "$", "answers", "=", "$", "this", "->", "getOrderedAnswers", "(", "$", "word", ")", ";", "if", "(", "$", "answers", ")", "{", "foreach", "(", "$", "answers", "as", "$", "answer", ")", "{", "if", "(", "strpos", "(", "$", "answer", ",", "'//'", ")", "===", "false", ")", "{", "$", "output", "=", "$", "answer", ";", "break", ";", "}", "}", "if", "(", "!", "isset", "(", "$", "output", ")", ")", "{", "$", "output", "=", "str_replace", "(", "'/'", ",", "'/', ", "$", "n", "swers[0", "]", ")", ";", "", "", "}", "$", "output", "=", "strtolower", "(", "$", "output", ")", ";", "$", "comment", "=", "''", ";", "if", "(", "isset", "(", "$", "word", "[", "'answer'", "]", "[", "0", "]", ")", ")", "{", "$", "shiftJISableText", "=", "$", "this", "->", "convertToShiftJISable", "(", "$", "word", "[", "'text'", "]", "[", "0", "]", ")", ";", "if", "(", "$", "answers", "[", "0", "]", "!==", "$", "shiftJISableText", "&&", "$", "this", "->", "isShiftJISable", "(", "$", "shiftJISableText", ")", ")", "{", "$", "comment", ".=", "\"【${shiftJISableText}】\";", "", "}", "}", "if", "(", "isset", "(", "$", "word", "[", "'description'", "]", "[", "0", "]", ")", ")", "{", "$", "shiftJISableDescription", "=", "$", "this", "->", "convertToShiftJISable", "(", "$", "word", "[", "'description'", "]", "[", "0", "]", "[", "'lml'", "]", ")", ";", "if", "(", "$", "this", "->", "isShiftJISable", "(", "$", "shiftJISableDescription", ")", ")", "{", "$", "comment", ".=", "$", "shiftJISableDescription", ";", "}", "}", "if", "(", "$", "comment", "!==", "''", ")", "{", "$", "output", ".=", "\"\\t// \"", ".", "str_replace", "(", "\"\\n\"", ",", "' '", ",", "$", "comment", ")", ";", "}", "$", "output", ".=", "\"\\r\\n\"", ";", "}", "}", "if", "(", "!", "isset", "(", "$", "output", ")", ")", "{", "$", "output", "=", "''", ";", "$", "this", "->", "logUnserializableError", "(", "'キャッチフィーリング', $word);", "", "", "", "", "", "}", "return", "$", "output", ";", "}" ]
一つのお題を表す配列を直列化します。 @param (string|string[]|float)[][] $word @return string 末尾に改行 (CRLF) を含みます。直列化できないお題だった場合は空文字列を返します。
[ "一つのお題を表す配列を直列化します。" ]
train
https://github.com/esperecyan/dictionary-php/blob/14fad08fb43006995c763094e8e7ed0dc0e26676/src/serializer/CatchfeelingSerializer.php#L13-L54
gregorybesson/PlaygroundCore
src/Validator/MailDomain.php
MailDomain.setFile
public function setFile($file) { if (empty($file) || false === stream_resolve_include_path($file)) { throw new Exception\InvalidArgumentException('Invalid options to validator provided'); } $this->options['file'] = $file; return $this; }
php
public function setFile($file) { if (empty($file) || false === stream_resolve_include_path($file)) { throw new Exception\InvalidArgumentException('Invalid options to validator provided'); } $this->options['file'] = $file; return $this; }
[ "public", "function", "setFile", "(", "$", "file", ")", "{", "if", "(", "empty", "(", "$", "file", ")", "||", "false", "===", "stream_resolve_include_path", "(", "$", "file", ")", ")", "{", "throw", "new", "Exception", "\\", "InvalidArgumentException", "(", "'Invalid options to validator provided'", ")", ";", "}", "$", "this", "->", "options", "[", "'file'", "]", "=", "$", "file", ";", "return", "$", "this", ";", "}" ]
Sets the path to the file @param string $path to the file @return MailDomain Provides a fluent interface @throws Exception\InvalidArgumentException When file is not found
[ "Sets", "the", "path", "to", "the", "file" ]
train
https://github.com/gregorybesson/PlaygroundCore/blob/f8dfa4c7660b54354933b3c28c0cf35304a649df/src/Validator/MailDomain.php#L48-L56
Atlantic18/CoralCoreBundle
CoralCoreBundle.php
CoralCoreBundle.build
public function build(ContainerBuilder $container) { parent::build($container); $container->registerExtension(new CoralCoreExtension()); $container->addCompilerPass(new ConnectorCompilerPass); }
php
public function build(ContainerBuilder $container) { parent::build($container); $container->registerExtension(new CoralCoreExtension()); $container->addCompilerPass(new ConnectorCompilerPass); }
[ "public", "function", "build", "(", "ContainerBuilder", "$", "container", ")", "{", "parent", "::", "build", "(", "$", "container", ")", ";", "$", "container", "->", "registerExtension", "(", "new", "CoralCoreExtension", "(", ")", ")", ";", "$", "container", "->", "addCompilerPass", "(", "new", "ConnectorCompilerPass", ")", ";", "}" ]
Builds the bundle. It is only ever called once when the cache is empty. This method can be overridden to register compilation passes, other extensions, ... @param ContainerBuilder $container A ContainerBuilder instance
[ "Builds", "the", "bundle", "." ]
train
https://github.com/Atlantic18/CoralCoreBundle/blob/7d74ffaf51046ad13cbfc2b0b69d656a499f38ab/CoralCoreBundle.php#L27-L34
movoin/one-swoole
src/Logging/Provider.php
Provider.register
public function register() { $this->bind('logger', function ($server) { $name = $server->getProcessName(); $path = $this->config('runtime_path', '') . '/logs/' . $name . '.log'; return new Logger($name, $path); }); }
php
public function register() { $this->bind('logger', function ($server) { $name = $server->getProcessName(); $path = $this->config('runtime_path', '') . '/logs/' . $name . '.log'; return new Logger($name, $path); }); }
[ "public", "function", "register", "(", ")", "{", "$", "this", "->", "bind", "(", "'logger'", ",", "function", "(", "$", "server", ")", "{", "$", "name", "=", "$", "server", "->", "getProcessName", "(", ")", ";", "$", "path", "=", "$", "this", "->", "config", "(", "'runtime_path'", ",", "''", ")", ".", "'/logs/'", ".", "$", "name", ".", "'.log'", ";", "return", "new", "Logger", "(", "$", "name", ",", "$", "path", ")", ";", "}", ")", ";", "}" ]
注册服务 @return void
[ "注册服务" ]
train
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Logging/Provider.php#L24-L32
discophp/framework
core/twig/tag/PageNode.php
PageNode.compile
public function compile(\Twig_Compiler $compiler) { $compiler->addDebugInfo($this) ->write("list(\$context['page'], ") ->subcompile($this->getNode('elementsTarget')) ->raw(') = \Disco\twig\PageNode::page(') ->subcompile($this->getNode('criteria')) ->raw(");\n") ->subcompile($this->getNode('body'), false) ->write('unset($context[\'page\'], ') ->subcompile($this->getNode('elementsTarget')) ->raw(");\n"); }
php
public function compile(\Twig_Compiler $compiler) { $compiler->addDebugInfo($this) ->write("list(\$context['page'], ") ->subcompile($this->getNode('elementsTarget')) ->raw(') = \Disco\twig\PageNode::page(') ->subcompile($this->getNode('criteria')) ->raw(");\n") ->subcompile($this->getNode('body'), false) ->write('unset($context[\'page\'], ') ->subcompile($this->getNode('elementsTarget')) ->raw(");\n"); }
[ "public", "function", "compile", "(", "\\", "Twig_Compiler", "$", "compiler", ")", "{", "$", "compiler", "->", "addDebugInfo", "(", "$", "this", ")", "->", "write", "(", "\"list(\\$context['page'], \"", ")", "->", "subcompile", "(", "$", "this", "->", "getNode", "(", "'elementsTarget'", ")", ")", "->", "raw", "(", "') = \\Disco\\twig\\PageNode::page('", ")", "->", "subcompile", "(", "$", "this", "->", "getNode", "(", "'criteria'", ")", ")", "->", "raw", "(", "\");\\n\"", ")", "->", "subcompile", "(", "$", "this", "->", "getNode", "(", "'body'", ")", ",", "false", ")", "->", "write", "(", "'unset($context[\\'page\\'], '", ")", "->", "subcompile", "(", "$", "this", "->", "getNode", "(", "'elementsTarget'", ")", ")", "->", "raw", "(", "\");\\n\"", ")", ";", "}" ]
Provide the functionality for compiling a {{page}} {{endpage}} tag. @param \Twig_Compiler $compiler A \Twig_compliler instance. @return void
[ "Provide", "the", "functionality", "for", "compiling", "a", "{{", "page", "}}", "{{", "endpage", "}}", "tag", "." ]
train
https://github.com/discophp/framework/blob/40ff3ea5225810534195494dc6c21083da4d1356/core/twig/tag/PageNode.php#L20-L33
discophp/framework
core/twig/tag/PageNode.php
PageNode.page
public static function page($object){ $page = \Disco\classes\Router::$paginateCurrentPage; $parent = get_parent_class($object); if($parent === 'Disco\classes\LookUp'){ $object->page($page); $copy = clone $object; return Array( (new \Disco\classes\Paginate($page, $copy->total()->fetch(), $object->getLimit())), $object->fetch(), ); } else if($parent === 'Disco\classes\Model'){ $limit = $object->getLimit(); $object->limit($page - 1,$limit['limit']); $copy = clone $object; $copy->limit(0,1)->select('COUNT(*) AS total'); return Array( (new \Disco\classes\Paginate($page, $copy->first()['total'], $limit['limit'])), $object->asArray(), ); }//elif throw new \Disco\exceptions\Exception('The page tag can only be applied to classes that extend `\Disco\classes\LookUp` and `\Disco\classes\Model`'); }
php
public static function page($object){ $page = \Disco\classes\Router::$paginateCurrentPage; $parent = get_parent_class($object); if($parent === 'Disco\classes\LookUp'){ $object->page($page); $copy = clone $object; return Array( (new \Disco\classes\Paginate($page, $copy->total()->fetch(), $object->getLimit())), $object->fetch(), ); } else if($parent === 'Disco\classes\Model'){ $limit = $object->getLimit(); $object->limit($page - 1,$limit['limit']); $copy = clone $object; $copy->limit(0,1)->select('COUNT(*) AS total'); return Array( (new \Disco\classes\Paginate($page, $copy->first()['total'], $limit['limit'])), $object->asArray(), ); }//elif throw new \Disco\exceptions\Exception('The page tag can only be applied to classes that extend `\Disco\classes\LookUp` and `\Disco\classes\Model`'); }
[ "public", "static", "function", "page", "(", "$", "object", ")", "{", "$", "page", "=", "\\", "Disco", "\\", "classes", "\\", "Router", "::", "$", "paginateCurrentPage", ";", "$", "parent", "=", "get_parent_class", "(", "$", "object", ")", ";", "if", "(", "$", "parent", "===", "'Disco\\classes\\LookUp'", ")", "{", "$", "object", "->", "page", "(", "$", "page", ")", ";", "$", "copy", "=", "clone", "$", "object", ";", "return", "Array", "(", "(", "new", "\\", "Disco", "\\", "classes", "\\", "Paginate", "(", "$", "page", ",", "$", "copy", "->", "total", "(", ")", "->", "fetch", "(", ")", ",", "$", "object", "->", "getLimit", "(", ")", ")", ")", ",", "$", "object", "->", "fetch", "(", ")", ",", "", ")", ";", "}", "else", "if", "(", "$", "parent", "===", "'Disco\\classes\\Model'", ")", "{", "$", "limit", "=", "$", "object", "->", "getLimit", "(", ")", ";", "$", "object", "->", "limit", "(", "$", "page", "-", "1", ",", "$", "limit", "[", "'limit'", "]", ")", ";", "$", "copy", "=", "clone", "$", "object", ";", "$", "copy", "->", "limit", "(", "0", ",", "1", ")", "->", "select", "(", "'COUNT(*) AS total'", ")", ";", "return", "Array", "(", "(", "new", "\\", "Disco", "\\", "classes", "\\", "Paginate", "(", "$", "page", ",", "$", "copy", "->", "first", "(", ")", "[", "'total'", "]", ",", "$", "limit", "[", "'limit'", "]", ")", ")", ",", "$", "object", "->", "asArray", "(", ")", ",", "", ")", ";", "}", "//elif", "throw", "new", "\\", "Disco", "\\", "exceptions", "\\", "Exception", "(", "'The page tag can only be applied to classes that extend `\\Disco\\classes\\LookUp` and `\\Disco\\classes\\Model`'", ")", ";", "}" ]
The method the twig tag `page` uses to perform pagination on lookups and models. @param \Disco\classes\Lookup|\Disco\classes\Model $object A instance of a class that extends {@link \Disco\classes\LookUp} or {@link \Disco\classes\Model}. @return array The first element is the {@link \Disco\classes\Paginate}, the second is the results of the lookup or model query. @throws \Disco\exceptions\Exception When trying to use the lookup tag on a class that does not extend {@link \Disco\classes\LookUp} or {@link \Disco\classes\Model}.
[ "The", "method", "the", "twig", "tag", "page", "uses", "to", "perform", "pagination", "on", "lookups", "and", "models", "." ]
train
https://github.com/discophp/framework/blob/40ff3ea5225810534195494dc6c21083da4d1356/core/twig/tag/PageNode.php#L49-L85
avoo/SerializerTranslation
Configuration/Metadata/VirtualPropertyMetadata.php
VirtualPropertyMetadata.serialize
public function serialize() { return serialize(array( parent::serialize(), $this->parameters, $this->domain, $this->locale )); }
php
public function serialize() { return serialize(array( parent::serialize(), $this->parameters, $this->domain, $this->locale )); }
[ "public", "function", "serialize", "(", ")", "{", "return", "serialize", "(", "array", "(", "parent", "::", "serialize", "(", ")", ",", "$", "this", "->", "parameters", ",", "$", "this", "->", "domain", ",", "$", "this", "->", "locale", ")", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/avoo/SerializerTranslation/blob/e66de5482adb944197a36874465ef144b293a157/Configuration/Metadata/VirtualPropertyMetadata.php#L70-L78
avoo/SerializerTranslation
Configuration/Metadata/VirtualPropertyMetadata.php
VirtualPropertyMetadata.unserialize
public function unserialize($str) { list( $parentStr, $this->parameters, $this->domain, $this->locale ) = unserialize($str); parent::unserialize($parentStr); }
php
public function unserialize($str) { list( $parentStr, $this->parameters, $this->domain, $this->locale ) = unserialize($str); parent::unserialize($parentStr); }
[ "public", "function", "unserialize", "(", "$", "str", ")", "{", "list", "(", "$", "parentStr", ",", "$", "this", "->", "parameters", ",", "$", "this", "->", "domain", ",", "$", "this", "->", "locale", ")", "=", "unserialize", "(", "$", "str", ")", ";", "parent", "::", "unserialize", "(", "$", "parentStr", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/avoo/SerializerTranslation/blob/e66de5482adb944197a36874465ef144b293a157/Configuration/Metadata/VirtualPropertyMetadata.php#L83-L93
matthiasbayer/datadog-client
src/Bayer/DataDogClient/Factory.php
Factory.buildMetric
public static function buildMetric($name, array $points, array $options = array()) { $metric = new Metric($name, $points); foreach ($options as $property => $value) { self::setProperty($metric, $property, $value); } return $metric; }
php
public static function buildMetric($name, array $points, array $options = array()) { $metric = new Metric($name, $points); foreach ($options as $property => $value) { self::setProperty($metric, $property, $value); } return $metric; }
[ "public", "static", "function", "buildMetric", "(", "$", "name", ",", "array", "$", "points", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "metric", "=", "new", "Metric", "(", "$", "name", ",", "$", "points", ")", ";", "foreach", "(", "$", "options", "as", "$", "property", "=>", "$", "value", ")", "{", "self", "::", "setProperty", "(", "$", "metric", ",", "$", "property", ",", "$", "value", ")", ";", "}", "return", "$", "metric", ";", "}" ]
@param string $name @param array $points @param array $options @return Metric
[ "@param", "string", "$name", "@param", "array", "$points", "@param", "array", "$options" ]
train
https://github.com/matthiasbayer/datadog-client/blob/e625132c34bf36f783077c9ee4ed3214633cd272/src/Bayer/DataDogClient/Factory.php#L23-L31
matthiasbayer/datadog-client
src/Bayer/DataDogClient/Factory.php
Factory.buildEvent
public static function buildEvent($text, $title = '', array $options = array()) { $event = new Event($text, $title); foreach ($options as $property => $value) { self::setProperty($event, $property, $value); } return $event; }
php
public static function buildEvent($text, $title = '', array $options = array()) { $event = new Event($text, $title); foreach ($options as $property => $value) { self::setProperty($event, $property, $value); } return $event; }
[ "public", "static", "function", "buildEvent", "(", "$", "text", ",", "$", "title", "=", "''", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "event", "=", "new", "Event", "(", "$", "text", ",", "$", "title", ")", ";", "foreach", "(", "$", "options", "as", "$", "property", "=>", "$", "value", ")", "{", "self", "::", "setProperty", "(", "$", "event", ",", "$", "property", ",", "$", "value", ")", ";", "}", "return", "$", "event", ";", "}" ]
@param string $text @param string $title @param array $options @return Event
[ "@param", "string", "$text", "@param", "string", "$title", "@param", "array", "$options" ]
train
https://github.com/matthiasbayer/datadog-client/blob/e625132c34bf36f783077c9ee4ed3214633cd272/src/Bayer/DataDogClient/Factory.php#L40-L48
tonicospinelli/class-generation
src/ClassGeneration/Property.php
Property.setType
public function setType($type) { $this->type = (string)$type; $this->getDocBlock()->getTagCollection()->removeByName(Tag::TAG_VAR); $tag = Tag::createFromProperty($this); $this->getDocBlock()->addTag($tag); return $this; }
php
public function setType($type) { $this->type = (string)$type; $this->getDocBlock()->getTagCollection()->removeByName(Tag::TAG_VAR); $tag = Tag::createFromProperty($this); $this->getDocBlock()->addTag($tag); return $this; }
[ "public", "function", "setType", "(", "$", "type", ")", "{", "$", "this", "->", "type", "=", "(", "string", ")", "$", "type", ";", "$", "this", "->", "getDocBlock", "(", ")", "->", "getTagCollection", "(", ")", "->", "removeByName", "(", "Tag", "::", "TAG_VAR", ")", ";", "$", "tag", "=", "Tag", "::", "createFromProperty", "(", "$", "this", ")", ";", "$", "this", "->", "getDocBlock", "(", ")", "->", "addTag", "(", "$", "tag", ")", ";", "return", "$", "this", ";", "}" ]
Sets the property's type. @param string $type @return Property
[ "Sets", "the", "property", "s", "type", "." ]
train
https://github.com/tonicospinelli/class-generation/blob/eee63bdb68c066b25b885b57b23656e809381a76/src/ClassGeneration/Property.php#L146-L156
tonicospinelli/class-generation
src/ClassGeneration/Property.php
Property.toString
public function toString() { $static = ''; if ($this->isStatic()) { $static = 'static '; } $value = ''; if ($this->hasValue()) { $value = ' = ' . var_export($this->getValue(), true); } $property = $this->getDocBlock()->toString() . $this->getTabulationFormatted() . $this->getVisibility() . ' ' . $static . '$' . $this->getName() . $value . ';' . PHP_EOL; return $property; }
php
public function toString() { $static = ''; if ($this->isStatic()) { $static = 'static '; } $value = ''; if ($this->hasValue()) { $value = ' = ' . var_export($this->getValue(), true); } $property = $this->getDocBlock()->toString() . $this->getTabulationFormatted() . $this->getVisibility() . ' ' . $static . '$' . $this->getName() . $value . ';' . PHP_EOL; return $property; }
[ "public", "function", "toString", "(", ")", "{", "$", "static", "=", "''", ";", "if", "(", "$", "this", "->", "isStatic", "(", ")", ")", "{", "$", "static", "=", "'static '", ";", "}", "$", "value", "=", "''", ";", "if", "(", "$", "this", "->", "hasValue", "(", ")", ")", "{", "$", "value", "=", "' = '", ".", "var_export", "(", "$", "this", "->", "getValue", "(", ")", ",", "true", ")", ";", "}", "$", "property", "=", "$", "this", "->", "getDocBlock", "(", ")", "->", "toString", "(", ")", ".", "$", "this", "->", "getTabulationFormatted", "(", ")", ".", "$", "this", "->", "getVisibility", "(", ")", ".", "' '", ".", "$", "static", ".", "'$'", ".", "$", "this", "->", "getName", "(", ")", ".", "$", "value", ".", "';'", ".", "PHP_EOL", ";", "return", "$", "property", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/tonicospinelli/class-generation/blob/eee63bdb68c066b25b885b57b23656e809381a76/src/ClassGeneration/Property.php#L246-L266
gdbots/pbjx-bundle-php
src/Command/TailEventsCommand.php
TailEventsCommand.execute
protected function execute(InputInterface $input, OutputInterface $output) { $errOutput = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output; $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); $errOutput->setVerbosity(OutputInterface::VERBOSITY_NORMAL); $interval = NumberUtils::bound($input->getOption('interval'), 1, 60); $context = json_decode($input->getOption('context') ?: '{}', true); $context['tenant_id'] = (string)$input->getOption('tenant-id'); $streamId = StreamId::fromString($input->getArgument('stream-id')); $eventStore = $this->getPbjx()->getEventStore(); $since = Microtime::create(); while (true) { $event = null; $slice = $eventStore->getStreamSlice($streamId, $since, 25, true, false, $context); foreach ($slice as $event) { try { echo json_encode($event) . PHP_EOL; } catch (\Throwable $e) { $errOutput->writeln($e->getMessage()); } } if ($event instanceof Event) { $since = $event->get('occurred_at'); } sleep($interval); } }
php
protected function execute(InputInterface $input, OutputInterface $output) { $errOutput = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output; $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); $errOutput->setVerbosity(OutputInterface::VERBOSITY_NORMAL); $interval = NumberUtils::bound($input->getOption('interval'), 1, 60); $context = json_decode($input->getOption('context') ?: '{}', true); $context['tenant_id'] = (string)$input->getOption('tenant-id'); $streamId = StreamId::fromString($input->getArgument('stream-id')); $eventStore = $this->getPbjx()->getEventStore(); $since = Microtime::create(); while (true) { $event = null; $slice = $eventStore->getStreamSlice($streamId, $since, 25, true, false, $context); foreach ($slice as $event) { try { echo json_encode($event) . PHP_EOL; } catch (\Throwable $e) { $errOutput->writeln($e->getMessage()); } } if ($event instanceof Event) { $since = $event->get('occurred_at'); } sleep($interval); } }
[ "protected", "function", "execute", "(", "InputInterface", "$", "input", ",", "OutputInterface", "$", "output", ")", "{", "$", "errOutput", "=", "$", "output", "instanceof", "ConsoleOutputInterface", "?", "$", "output", "->", "getErrorOutput", "(", ")", ":", "$", "output", ";", "$", "output", "->", "setVerbosity", "(", "OutputInterface", "::", "VERBOSITY_QUIET", ")", ";", "$", "errOutput", "->", "setVerbosity", "(", "OutputInterface", "::", "VERBOSITY_NORMAL", ")", ";", "$", "interval", "=", "NumberUtils", "::", "bound", "(", "$", "input", "->", "getOption", "(", "'interval'", ")", ",", "1", ",", "60", ")", ";", "$", "context", "=", "json_decode", "(", "$", "input", "->", "getOption", "(", "'context'", ")", "?", ":", "'{}'", ",", "true", ")", ";", "$", "context", "[", "'tenant_id'", "]", "=", "(", "string", ")", "$", "input", "->", "getOption", "(", "'tenant-id'", ")", ";", "$", "streamId", "=", "StreamId", "::", "fromString", "(", "$", "input", "->", "getArgument", "(", "'stream-id'", ")", ")", ";", "$", "eventStore", "=", "$", "this", "->", "getPbjx", "(", ")", "->", "getEventStore", "(", ")", ";", "$", "since", "=", "Microtime", "::", "create", "(", ")", ";", "while", "(", "true", ")", "{", "$", "event", "=", "null", ";", "$", "slice", "=", "$", "eventStore", "->", "getStreamSlice", "(", "$", "streamId", ",", "$", "since", ",", "25", ",", "true", ",", "false", ",", "$", "context", ")", ";", "foreach", "(", "$", "slice", "as", "$", "event", ")", "{", "try", "{", "echo", "json_encode", "(", "$", "event", ")", ".", "PHP_EOL", ";", "}", "catch", "(", "\\", "Throwable", "$", "e", ")", "{", "$", "errOutput", "->", "writeln", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "}", "if", "(", "$", "event", "instanceof", "Event", ")", "{", "$", "since", "=", "$", "event", "->", "get", "(", "'occurred_at'", ")", ";", "}", "sleep", "(", "$", "interval", ")", ";", "}", "}" ]
@param InputInterface $input @param OutputInterface $output @return null
[ "@param", "InputInterface", "$input", "@param", "OutputInterface", "$output" ]
train
https://github.com/gdbots/pbjx-bundle-php/blob/f3c0088583879fc92f13247a0752634bd8696eac/src/Command/TailEventsCommand.php#L79-L111
pickles2/px2-sitemapexcel
php/apis/xlsx2csv.php
xlsx2csv.convert
public function convert( $path_xlsx, $path_csv ){ $this->path_xlsx = $path_xlsx; $this->path_csv = $path_csv; $this->path_tmp_csv = $path_csv.'.tmp'.time(); do{ $this->path_tmp_csv = $path_csv.'.tmp'.time(); } while( is_file($this->path_tmp_csv) ); // ページID自動発行のための情報をリセット $this->auto_id_num = 0; // 通し番号をリセット $this->extless_basename = $this->px->fs()->trim_extension(basename($this->path_xlsx));//ファイル名を記憶; 入力側のファイル名に準じる。 $path_toppage = '/'; if( strlen($this->px->conf()->path_top) ){ $path_toppage = $this->px->conf()->path_top; } $path_toppage = $this->regulize_path( $path_toppage ); // サイトマップCSVの定義を取得 $sitemap_definition = $this->get_sitemap_definition(); $phpExcelHelper = new pxplugin_sitemapExcel_helper_PHPExcelHelper(); if( !$phpExcelHelper ){ return false; } set_time_limit(0); $objPHPExcel = $phpExcelHelper->load($this->path_xlsx); $table_definition = $this->parse_definition($objPHPExcel, 0);//xlsxの構造定義を読み解く $col_title = array(); foreach($table_definition['col_define'] as $tmp_col_define){ if( isset( $col_title['start'] ) ){ $col_title['end'] = @$tmp_col_define['col']; break; } if( $tmp_col_define['key'] == 'title' ){ $col_title['start'] = @$tmp_col_define['col']; } } unset($tmp_col_define); $objPHPExcel->setActiveSheetIndex(0); $objSheet = $objPHPExcel->getActiveSheet(); // xlsxにあってサイトマップ定義にないカスタムカラムを定義に反映 $xls_custom_column_definition = $table_definition['col_define']; $tmp_last_elm_info = array(); foreach( $sitemap_definition as $tmp_row ){ unset($xls_custom_column_definition[$tmp_row['key']]); $tmp_last_elm_info = $tmp_row; } foreach( $xls_custom_column_definition as $tmp_key=>$tmp_row ){ @$tmp_last_elm_info['num'] ++; @$tmp_last_elm_info['col'] ++; $tmp_last_elm_info['key'] = $tmp_row['key']; $tmp_last_elm_info['name'] = $tmp_row['key']; $sitemap_definition[$tmp_last_elm_info['key']] = $tmp_last_elm_info; } $page_info = array(); foreach($sitemap_definition as $row){ $page_info[$row['key']] = '* '.$row['key']; } $this->output_csv_row( $page_info ); $last_breadcrumb = array(); $last_page_id = null; $logical_path_last_depth = 0; $xlsx_row = $table_definition['row_data_start']; $xlsx_row --; while(1){ set_time_limit(30); $xlsx_row ++; if( $xlsx_row > $table_definition['tbl_highest_row'] ){ // エクセルの最終行に達していたら、終了。 break; } if( $objSheet->getCell('A'.$xlsx_row)->getCalculatedValue() == 'EndOfData' ){ // A列が 'EndOfData' だったら、終了。 break; } $page_info = array(); $tmp_page_info = array(); foreach($sitemap_definition as $key=>$row){ $tmp_col_name = @$table_definition['col_define'][$row['key']]['col']; if(strlen($tmp_col_name)){ $tmp_page_info[$row['key']] = $objSheet->getCell($tmp_col_name.$xlsx_row)->getCalculatedValue(); // ユーザーが設定したセルフォーマットに従って文字列を復元する $cell_format = $objSheet->getStyle($tmp_col_name.$xlsx_row)->getNumberFormat()->getFormatCode(); if( $cell_format !== 'General' ){ $tmp_cell_value = \PHPExcel_Style_NumberFormat::toFormattedString( $tmp_page_info[$row['key']], $cell_format ); if( !is_null($tmp_cell_value) ){ $tmp_page_info[$row['key']] = $tmp_cell_value; } } unset($cell_format, $tmp_cell_value); }else{ $tmp_page_info[$row['key']] = ''; } } // -------------------- // 削除フラグ if( @$tmp_page_info['**delete_flg'] ){ continue; } // -------------------- // タイトルだけ特別 $col_title_col = @$col_title['start']; $tmp_page_info['title'] = ''; $logical_path_depth = 0; $alias_title_list = array(); while( @strcmp( strtoupper($col_title_col) , strtoupper($col_title['end']) ) < 0 ){ // ↑ $col_title['end'] には、titleの終端の右の列の名前が入っている。 よって `strcmp()` の結果は最大で `-1` となる。 $tmp_page_info['title'] .= trim( $objSheet->getCell($col_title_col.$xlsx_row)->getCalculatedValue() ); if(strlen($tmp_page_info['title'])){ $col_title_col ++; while( @strcmp( strtoupper($col_title_col) , strtoupper($col_title['end']) ) < 0 && strlen( $tmp_alias_title = trim( $objSheet->getCell(($col_title_col).$xlsx_row)->getCalculatedValue() ) ) ){ array_push( $alias_title_list, $tmp_alias_title ); $col_title_col ++; } break; } $col_title_col ++; $logical_path_depth ++; } unset($col_title_col); unset($tmp_alias_title); if(!@strlen( $tmp_page_info['path'] )){ if(!@strlen( $tmp_page_info['title'] )){ // pathもtitleも空白なら終わったものと思う。 // →スキップする に変更 continue; } $tmp_page_info['path'] = 'alias:/_tbd.html';//pathがなくてもtitleがあれば、仮の値を入れて通す。 } // -------------------- // list_flgの処理 if( !array_key_exists('list_flg', $table_definition['col_define']) ){ // エクセルの定義にlist_flg列がなかったら、 // 全ページにlist_flg=1をセット。 $tmp_page_info['list_flg'] = 1; } // -------------------- // 読み込んだパスを正規化 $tmp_page_info['path'] = $this->regulize_path( $tmp_page_info['path'] ); // -------------------- // 省略されたIDを自動的に付与 if(!strlen($tmp_page_info['id'])){ if( $path_toppage != $tmp_page_info['path'] ){ // トップページは空白でなければならない。 if( preg_match( '/^alias\\:/', $tmp_page_info['path'] ) ){ // エイリアスだったら自動付与 $tmp_page_info['id'] = $this->generate_auto_page_id(); }elseif( count($alias_title_list) ){ // 隠れエイリアスだったら自動付与 $tmp_page_info['id'] = $this->generate_auto_page_id(); } } } // トップページのIDは空白文字列でなければならない。 if( $path_toppage == $tmp_page_info['path'] ){ $tmp_page_info['id'] = ''; } // -------------------- // パンくずも特別 $tmp_breadcrumb = $last_breadcrumb; if( $logical_path_last_depth === $logical_path_depth ){ // 前回と深さが変わっていなかったら }elseif( $logical_path_last_depth < $logical_path_depth ){ // 前回の深さより深くなっていたら $tmp_breadcrumb = $last_breadcrumb; array_push($tmp_breadcrumb, $last_page_id ); }elseif( $logical_path_last_depth > $logical_path_depth ){ // 前回の深さより浅くなっていたら $tmp_breadcrumb = array(); for($i = 0; $i < $logical_path_depth; $i ++){ if(is_null($last_breadcrumb[$i])){break;} $tmp_breadcrumb[$i] = $last_breadcrumb[$i]; } } if( @strlen($tmp_page_info['logical_path']) ){ // エクセルの定義にlogical_path列があったら、 // この値を優先して採用する。 }else{ $tmp_page_info['logical_path'] = ''; if( count($tmp_breadcrumb) >= 2 ){ $tmp_page_info['logical_path'] = implode('>', $tmp_breadcrumb); $tmp_page_info['logical_path'] = preg_replace('/^(.*?)\\>/s', '', $tmp_page_info['logical_path']); } } // 今回のパンくずとパンくずの深さを記録 $logical_path_last_depth = $logical_path_depth; $last_breadcrumb = $tmp_breadcrumb; $last_page_id = $tmp_page_info['path']; if( preg_match( '/^alias\\:/', $tmp_page_info['path'] ) ){ $last_page_id = $tmp_page_info['id']; } // -------------------- // サイトマップにページを追加する $page_info = array(); foreach($sitemap_definition as $row){ $page_info[$row['key']] = $tmp_page_info[$row['key']]; } if( count($alias_title_list) ){ // エイリアスが省略されている場合 $page_info_base = $page_info; $page_info['path'] = 'alias:'.$page_info['path']; $this->output_csv_row( $page_info ); $tmp_last_page_id = $page_info['id']; foreach( $alias_title_list as $key=>$row ){ $page_info = $page_info_base; if( count($alias_title_list) > $key+1 ){ // 最後の1件以外なら $page_info['path'] = 'alias:'.$page_info['path']; } if( $page_info_base['category_top_flg'] ){ $page_info['category_top_flg'] = null; } array_push($tmp_breadcrumb, $tmp_last_page_id); $page_info['logical_path'] = ''; if( count($tmp_breadcrumb) >= 2 ){ $page_info['logical_path'] = implode('>', $tmp_breadcrumb); $page_info['logical_path'] = preg_replace('/^(.*?)\\>/s', '', $page_info['logical_path']); } $page_info['id'] = $this->generate_auto_page_id(); $page_info['title'] = $row; // var_dump($page_info['title']); $this->output_csv_row( $page_info ); $tmp_last_page_id = $page_info['id']; $logical_path_last_depth ++; $last_breadcrumb = $tmp_breadcrumb; $last_page_id = $tmp_last_page_id; } unset($page_info_base); unset($tmp_last_page_id); continue; }else{ // 通常のページの場合 $this->output_csv_row( $page_info ); continue; } continue; } $this->px->fs()->mkdir(dirname($this->path_csv)); $this->px->fs()->rename($this->path_tmp_csv, $this->path_csv); $this->px->fs()->chmod($this->path_csv, octdec( $this->px->conf()->file_default_permission )); set_time_limit(30); clearstatcache(); return $this; }
php
public function convert( $path_xlsx, $path_csv ){ $this->path_xlsx = $path_xlsx; $this->path_csv = $path_csv; $this->path_tmp_csv = $path_csv.'.tmp'.time(); do{ $this->path_tmp_csv = $path_csv.'.tmp'.time(); } while( is_file($this->path_tmp_csv) ); // ページID自動発行のための情報をリセット $this->auto_id_num = 0; // 通し番号をリセット $this->extless_basename = $this->px->fs()->trim_extension(basename($this->path_xlsx));//ファイル名を記憶; 入力側のファイル名に準じる。 $path_toppage = '/'; if( strlen($this->px->conf()->path_top) ){ $path_toppage = $this->px->conf()->path_top; } $path_toppage = $this->regulize_path( $path_toppage ); // サイトマップCSVの定義を取得 $sitemap_definition = $this->get_sitemap_definition(); $phpExcelHelper = new pxplugin_sitemapExcel_helper_PHPExcelHelper(); if( !$phpExcelHelper ){ return false; } set_time_limit(0); $objPHPExcel = $phpExcelHelper->load($this->path_xlsx); $table_definition = $this->parse_definition($objPHPExcel, 0);//xlsxの構造定義を読み解く $col_title = array(); foreach($table_definition['col_define'] as $tmp_col_define){ if( isset( $col_title['start'] ) ){ $col_title['end'] = @$tmp_col_define['col']; break; } if( $tmp_col_define['key'] == 'title' ){ $col_title['start'] = @$tmp_col_define['col']; } } unset($tmp_col_define); $objPHPExcel->setActiveSheetIndex(0); $objSheet = $objPHPExcel->getActiveSheet(); // xlsxにあってサイトマップ定義にないカスタムカラムを定義に反映 $xls_custom_column_definition = $table_definition['col_define']; $tmp_last_elm_info = array(); foreach( $sitemap_definition as $tmp_row ){ unset($xls_custom_column_definition[$tmp_row['key']]); $tmp_last_elm_info = $tmp_row; } foreach( $xls_custom_column_definition as $tmp_key=>$tmp_row ){ @$tmp_last_elm_info['num'] ++; @$tmp_last_elm_info['col'] ++; $tmp_last_elm_info['key'] = $tmp_row['key']; $tmp_last_elm_info['name'] = $tmp_row['key']; $sitemap_definition[$tmp_last_elm_info['key']] = $tmp_last_elm_info; } $page_info = array(); foreach($sitemap_definition as $row){ $page_info[$row['key']] = '* '.$row['key']; } $this->output_csv_row( $page_info ); $last_breadcrumb = array(); $last_page_id = null; $logical_path_last_depth = 0; $xlsx_row = $table_definition['row_data_start']; $xlsx_row --; while(1){ set_time_limit(30); $xlsx_row ++; if( $xlsx_row > $table_definition['tbl_highest_row'] ){ // エクセルの最終行に達していたら、終了。 break; } if( $objSheet->getCell('A'.$xlsx_row)->getCalculatedValue() == 'EndOfData' ){ // A列が 'EndOfData' だったら、終了。 break; } $page_info = array(); $tmp_page_info = array(); foreach($sitemap_definition as $key=>$row){ $tmp_col_name = @$table_definition['col_define'][$row['key']]['col']; if(strlen($tmp_col_name)){ $tmp_page_info[$row['key']] = $objSheet->getCell($tmp_col_name.$xlsx_row)->getCalculatedValue(); // ユーザーが設定したセルフォーマットに従って文字列を復元する $cell_format = $objSheet->getStyle($tmp_col_name.$xlsx_row)->getNumberFormat()->getFormatCode(); if( $cell_format !== 'General' ){ $tmp_cell_value = \PHPExcel_Style_NumberFormat::toFormattedString( $tmp_page_info[$row['key']], $cell_format ); if( !is_null($tmp_cell_value) ){ $tmp_page_info[$row['key']] = $tmp_cell_value; } } unset($cell_format, $tmp_cell_value); }else{ $tmp_page_info[$row['key']] = ''; } } // -------------------- // 削除フラグ if( @$tmp_page_info['**delete_flg'] ){ continue; } // -------------------- // タイトルだけ特別 $col_title_col = @$col_title['start']; $tmp_page_info['title'] = ''; $logical_path_depth = 0; $alias_title_list = array(); while( @strcmp( strtoupper($col_title_col) , strtoupper($col_title['end']) ) < 0 ){ // ↑ $col_title['end'] には、titleの終端の右の列の名前が入っている。 よって `strcmp()` の結果は最大で `-1` となる。 $tmp_page_info['title'] .= trim( $objSheet->getCell($col_title_col.$xlsx_row)->getCalculatedValue() ); if(strlen($tmp_page_info['title'])){ $col_title_col ++; while( @strcmp( strtoupper($col_title_col) , strtoupper($col_title['end']) ) < 0 && strlen( $tmp_alias_title = trim( $objSheet->getCell(($col_title_col).$xlsx_row)->getCalculatedValue() ) ) ){ array_push( $alias_title_list, $tmp_alias_title ); $col_title_col ++; } break; } $col_title_col ++; $logical_path_depth ++; } unset($col_title_col); unset($tmp_alias_title); if(!@strlen( $tmp_page_info['path'] )){ if(!@strlen( $tmp_page_info['title'] )){ // pathもtitleも空白なら終わったものと思う。 // →スキップする に変更 continue; } $tmp_page_info['path'] = 'alias:/_tbd.html';//pathがなくてもtitleがあれば、仮の値を入れて通す。 } // -------------------- // list_flgの処理 if( !array_key_exists('list_flg', $table_definition['col_define']) ){ // エクセルの定義にlist_flg列がなかったら、 // 全ページにlist_flg=1をセット。 $tmp_page_info['list_flg'] = 1; } // -------------------- // 読み込んだパスを正規化 $tmp_page_info['path'] = $this->regulize_path( $tmp_page_info['path'] ); // -------------------- // 省略されたIDを自動的に付与 if(!strlen($tmp_page_info['id'])){ if( $path_toppage != $tmp_page_info['path'] ){ // トップページは空白でなければならない。 if( preg_match( '/^alias\\:/', $tmp_page_info['path'] ) ){ // エイリアスだったら自動付与 $tmp_page_info['id'] = $this->generate_auto_page_id(); }elseif( count($alias_title_list) ){ // 隠れエイリアスだったら自動付与 $tmp_page_info['id'] = $this->generate_auto_page_id(); } } } // トップページのIDは空白文字列でなければならない。 if( $path_toppage == $tmp_page_info['path'] ){ $tmp_page_info['id'] = ''; } // -------------------- // パンくずも特別 $tmp_breadcrumb = $last_breadcrumb; if( $logical_path_last_depth === $logical_path_depth ){ // 前回と深さが変わっていなかったら }elseif( $logical_path_last_depth < $logical_path_depth ){ // 前回の深さより深くなっていたら $tmp_breadcrumb = $last_breadcrumb; array_push($tmp_breadcrumb, $last_page_id ); }elseif( $logical_path_last_depth > $logical_path_depth ){ // 前回の深さより浅くなっていたら $tmp_breadcrumb = array(); for($i = 0; $i < $logical_path_depth; $i ++){ if(is_null($last_breadcrumb[$i])){break;} $tmp_breadcrumb[$i] = $last_breadcrumb[$i]; } } if( @strlen($tmp_page_info['logical_path']) ){ // エクセルの定義にlogical_path列があったら、 // この値を優先して採用する。 }else{ $tmp_page_info['logical_path'] = ''; if( count($tmp_breadcrumb) >= 2 ){ $tmp_page_info['logical_path'] = implode('>', $tmp_breadcrumb); $tmp_page_info['logical_path'] = preg_replace('/^(.*?)\\>/s', '', $tmp_page_info['logical_path']); } } // 今回のパンくずとパンくずの深さを記録 $logical_path_last_depth = $logical_path_depth; $last_breadcrumb = $tmp_breadcrumb; $last_page_id = $tmp_page_info['path']; if( preg_match( '/^alias\\:/', $tmp_page_info['path'] ) ){ $last_page_id = $tmp_page_info['id']; } // -------------------- // サイトマップにページを追加する $page_info = array(); foreach($sitemap_definition as $row){ $page_info[$row['key']] = $tmp_page_info[$row['key']]; } if( count($alias_title_list) ){ // エイリアスが省略されている場合 $page_info_base = $page_info; $page_info['path'] = 'alias:'.$page_info['path']; $this->output_csv_row( $page_info ); $tmp_last_page_id = $page_info['id']; foreach( $alias_title_list as $key=>$row ){ $page_info = $page_info_base; if( count($alias_title_list) > $key+1 ){ // 最後の1件以外なら $page_info['path'] = 'alias:'.$page_info['path']; } if( $page_info_base['category_top_flg'] ){ $page_info['category_top_flg'] = null; } array_push($tmp_breadcrumb, $tmp_last_page_id); $page_info['logical_path'] = ''; if( count($tmp_breadcrumb) >= 2 ){ $page_info['logical_path'] = implode('>', $tmp_breadcrumb); $page_info['logical_path'] = preg_replace('/^(.*?)\\>/s', '', $page_info['logical_path']); } $page_info['id'] = $this->generate_auto_page_id(); $page_info['title'] = $row; // var_dump($page_info['title']); $this->output_csv_row( $page_info ); $tmp_last_page_id = $page_info['id']; $logical_path_last_depth ++; $last_breadcrumb = $tmp_breadcrumb; $last_page_id = $tmp_last_page_id; } unset($page_info_base); unset($tmp_last_page_id); continue; }else{ // 通常のページの場合 $this->output_csv_row( $page_info ); continue; } continue; } $this->px->fs()->mkdir(dirname($this->path_csv)); $this->px->fs()->rename($this->path_tmp_csv, $this->path_csv); $this->px->fs()->chmod($this->path_csv, octdec( $this->px->conf()->file_default_permission )); set_time_limit(30); clearstatcache(); return $this; }
[ "public", "function", "convert", "(", "$", "path_xlsx", ",", "$", "path_csv", ")", "{", "$", "this", "->", "path_xlsx", "=", "$", "path_xlsx", ";", "$", "this", "->", "path_csv", "=", "$", "path_csv", ";", "$", "this", "->", "path_tmp_csv", "=", "$", "path_csv", ".", "'.tmp'", ".", "time", "(", ")", ";", "do", "{", "$", "this", "->", "path_tmp_csv", "=", "$", "path_csv", ".", "'.tmp'", ".", "time", "(", ")", ";", "}", "while", "(", "is_file", "(", "$", "this", "->", "path_tmp_csv", ")", ")", ";", "// ページID自動発行のための情報をリセット", "$", "this", "->", "auto_id_num", "=", "0", ";", "// 通し番号をリセット", "$", "this", "->", "extless_basename", "=", "$", "this", "->", "px", "->", "fs", "(", ")", "->", "trim_extension", "(", "basename", "(", "$", "this", "->", "path_xlsx", ")", ")", ";", "//ファイル名を記憶; 入力側のファイル名に準じる。", "$", "path_toppage", "=", "'/'", ";", "if", "(", "strlen", "(", "$", "this", "->", "px", "->", "conf", "(", ")", "->", "path_top", ")", ")", "{", "$", "path_toppage", "=", "$", "this", "->", "px", "->", "conf", "(", ")", "->", "path_top", ";", "}", "$", "path_toppage", "=", "$", "this", "->", "regulize_path", "(", "$", "path_toppage", ")", ";", "// サイトマップCSVの定義を取得", "$", "sitemap_definition", "=", "$", "this", "->", "get_sitemap_definition", "(", ")", ";", "$", "phpExcelHelper", "=", "new", "pxplugin_sitemapExcel_helper_PHPExcelHelper", "(", ")", ";", "if", "(", "!", "$", "phpExcelHelper", ")", "{", "return", "false", ";", "}", "set_time_limit", "(", "0", ")", ";", "$", "objPHPExcel", "=", "$", "phpExcelHelper", "->", "load", "(", "$", "this", "->", "path_xlsx", ")", ";", "$", "table_definition", "=", "$", "this", "->", "parse_definition", "(", "$", "objPHPExcel", ",", "0", ")", ";", "//xlsxの構造定義を読み解く", "$", "col_title", "=", "array", "(", ")", ";", "foreach", "(", "$", "table_definition", "[", "'col_define'", "]", "as", "$", "tmp_col_define", ")", "{", "if", "(", "isset", "(", "$", "col_title", "[", "'start'", "]", ")", ")", "{", "$", "col_title", "[", "'end'", "]", "=", "@", "$", "tmp_col_define", "[", "'col'", "]", ";", "break", ";", "}", "if", "(", "$", "tmp_col_define", "[", "'key'", "]", "==", "'title'", ")", "{", "$", "col_title", "[", "'start'", "]", "=", "@", "$", "tmp_col_define", "[", "'col'", "]", ";", "}", "}", "unset", "(", "$", "tmp_col_define", ")", ";", "$", "objPHPExcel", "->", "setActiveSheetIndex", "(", "0", ")", ";", "$", "objSheet", "=", "$", "objPHPExcel", "->", "getActiveSheet", "(", ")", ";", "// xlsxにあってサイトマップ定義にないカスタムカラムを定義に反映", "$", "xls_custom_column_definition", "=", "$", "table_definition", "[", "'col_define'", "]", ";", "$", "tmp_last_elm_info", "=", "array", "(", ")", ";", "foreach", "(", "$", "sitemap_definition", "as", "$", "tmp_row", ")", "{", "unset", "(", "$", "xls_custom_column_definition", "[", "$", "tmp_row", "[", "'key'", "]", "]", ")", ";", "$", "tmp_last_elm_info", "=", "$", "tmp_row", ";", "}", "foreach", "(", "$", "xls_custom_column_definition", "as", "$", "tmp_key", "=>", "$", "tmp_row", ")", "{", "@", "$", "tmp_last_elm_info", "[", "'num'", "]", "++", ";", "@", "$", "tmp_last_elm_info", "[", "'col'", "]", "++", ";", "$", "tmp_last_elm_info", "[", "'key'", "]", "=", "$", "tmp_row", "[", "'key'", "]", ";", "$", "tmp_last_elm_info", "[", "'name'", "]", "=", "$", "tmp_row", "[", "'key'", "]", ";", "$", "sitemap_definition", "[", "$", "tmp_last_elm_info", "[", "'key'", "]", "]", "=", "$", "tmp_last_elm_info", ";", "}", "$", "page_info", "=", "array", "(", ")", ";", "foreach", "(", "$", "sitemap_definition", "as", "$", "row", ")", "{", "$", "page_info", "[", "$", "row", "[", "'key'", "]", "]", "=", "'* '", ".", "$", "row", "[", "'key'", "]", ";", "}", "$", "this", "->", "output_csv_row", "(", "$", "page_info", ")", ";", "$", "last_breadcrumb", "=", "array", "(", ")", ";", "$", "last_page_id", "=", "null", ";", "$", "logical_path_last_depth", "=", "0", ";", "$", "xlsx_row", "=", "$", "table_definition", "[", "'row_data_start'", "]", ";", "$", "xlsx_row", "--", ";", "while", "(", "1", ")", "{", "set_time_limit", "(", "30", ")", ";", "$", "xlsx_row", "++", ";", "if", "(", "$", "xlsx_row", ">", "$", "table_definition", "[", "'tbl_highest_row'", "]", ")", "{", "// エクセルの最終行に達していたら、終了。", "break", ";", "}", "if", "(", "$", "objSheet", "->", "getCell", "(", "'A'", ".", "$", "xlsx_row", ")", "->", "getCalculatedValue", "(", ")", "==", "'EndOfData'", ")", "{", "// A列が 'EndOfData' だったら、終了。", "break", ";", "}", "$", "page_info", "=", "array", "(", ")", ";", "$", "tmp_page_info", "=", "array", "(", ")", ";", "foreach", "(", "$", "sitemap_definition", "as", "$", "key", "=>", "$", "row", ")", "{", "$", "tmp_col_name", "=", "@", "$", "table_definition", "[", "'col_define'", "]", "[", "$", "row", "[", "'key'", "]", "]", "[", "'col'", "]", ";", "if", "(", "strlen", "(", "$", "tmp_col_name", ")", ")", "{", "$", "tmp_page_info", "[", "$", "row", "[", "'key'", "]", "]", "=", "$", "objSheet", "->", "getCell", "(", "$", "tmp_col_name", ".", "$", "xlsx_row", ")", "->", "getCalculatedValue", "(", ")", ";", "// ユーザーが設定したセルフォーマットに従って文字列を復元する", "$", "cell_format", "=", "$", "objSheet", "->", "getStyle", "(", "$", "tmp_col_name", ".", "$", "xlsx_row", ")", "->", "getNumberFormat", "(", ")", "->", "getFormatCode", "(", ")", ";", "if", "(", "$", "cell_format", "!==", "'General'", ")", "{", "$", "tmp_cell_value", "=", "\\", "PHPExcel_Style_NumberFormat", "::", "toFormattedString", "(", "$", "tmp_page_info", "[", "$", "row", "[", "'key'", "]", "]", ",", "$", "cell_format", ")", ";", "if", "(", "!", "is_null", "(", "$", "tmp_cell_value", ")", ")", "{", "$", "tmp_page_info", "[", "$", "row", "[", "'key'", "]", "]", "=", "$", "tmp_cell_value", ";", "}", "}", "unset", "(", "$", "cell_format", ",", "$", "tmp_cell_value", ")", ";", "}", "else", "{", "$", "tmp_page_info", "[", "$", "row", "[", "'key'", "]", "]", "=", "''", ";", "}", "}", "// --------------------", "// 削除フラグ", "if", "(", "@", "$", "tmp_page_info", "[", "'**delete_flg'", "]", ")", "{", "continue", ";", "}", "// --------------------", "// タイトルだけ特別", "$", "col_title_col", "=", "@", "$", "col_title", "[", "'start'", "]", ";", "$", "tmp_page_info", "[", "'title'", "]", "=", "''", ";", "$", "logical_path_depth", "=", "0", ";", "$", "alias_title_list", "=", "array", "(", ")", ";", "while", "(", "@", "strcmp", "(", "strtoupper", "(", "$", "col_title_col", ")", ",", "strtoupper", "(", "$", "col_title", "[", "'end'", "]", ")", ")", "<", "0", ")", "{", "// ↑ $col_title['end'] には、titleの終端の右の列の名前が入っている。 よって `strcmp()` の結果は最大で `-1` となる。", "$", "tmp_page_info", "[", "'title'", "]", ".=", "trim", "(", "$", "objSheet", "->", "getCell", "(", "$", "col_title_col", ".", "$", "xlsx_row", ")", "->", "getCalculatedValue", "(", ")", ")", ";", "if", "(", "strlen", "(", "$", "tmp_page_info", "[", "'title'", "]", ")", ")", "{", "$", "col_title_col", "++", ";", "while", "(", "@", "strcmp", "(", "strtoupper", "(", "$", "col_title_col", ")", ",", "strtoupper", "(", "$", "col_title", "[", "'end'", "]", ")", ")", "<", "0", "&&", "strlen", "(", "$", "tmp_alias_title", "=", "trim", "(", "$", "objSheet", "->", "getCell", "(", "(", "$", "col_title_col", ")", ".", "$", "xlsx_row", ")", "->", "getCalculatedValue", "(", ")", ")", ")", ")", "{", "array_push", "(", "$", "alias_title_list", ",", "$", "tmp_alias_title", ")", ";", "$", "col_title_col", "++", ";", "}", "break", ";", "}", "$", "col_title_col", "++", ";", "$", "logical_path_depth", "++", ";", "}", "unset", "(", "$", "col_title_col", ")", ";", "unset", "(", "$", "tmp_alias_title", ")", ";", "if", "(", "!", "@", "strlen", "(", "$", "tmp_page_info", "[", "'path'", "]", ")", ")", "{", "if", "(", "!", "@", "strlen", "(", "$", "tmp_page_info", "[", "'title'", "]", ")", ")", "{", "// pathもtitleも空白なら終わったものと思う。", "// \t→スキップする に変更", "continue", ";", "}", "$", "tmp_page_info", "[", "'path'", "]", "=", "'alias:/_tbd.html'", ";", "//pathがなくてもtitleがあれば、仮の値を入れて通す。", "}", "// --------------------", "// list_flgの処理", "if", "(", "!", "array_key_exists", "(", "'list_flg'", ",", "$", "table_definition", "[", "'col_define'", "]", ")", ")", "{", "// エクセルの定義にlist_flg列がなかったら、", "// 全ページにlist_flg=1をセット。", "$", "tmp_page_info", "[", "'list_flg'", "]", "=", "1", ";", "}", "// --------------------", "// 読み込んだパスを正規化", "$", "tmp_page_info", "[", "'path'", "]", "=", "$", "this", "->", "regulize_path", "(", "$", "tmp_page_info", "[", "'path'", "]", ")", ";", "// --------------------", "// 省略されたIDを自動的に付与", "if", "(", "!", "strlen", "(", "$", "tmp_page_info", "[", "'id'", "]", ")", ")", "{", "if", "(", "$", "path_toppage", "!=", "$", "tmp_page_info", "[", "'path'", "]", ")", "{", "// トップページは空白でなければならない。", "if", "(", "preg_match", "(", "'/^alias\\\\:/'", ",", "$", "tmp_page_info", "[", "'path'", "]", ")", ")", "{", "// エイリアスだったら自動付与", "$", "tmp_page_info", "[", "'id'", "]", "=", "$", "this", "->", "generate_auto_page_id", "(", ")", ";", "}", "elseif", "(", "count", "(", "$", "alias_title_list", ")", ")", "{", "// 隠れエイリアスだったら自動付与", "$", "tmp_page_info", "[", "'id'", "]", "=", "$", "this", "->", "generate_auto_page_id", "(", ")", ";", "}", "}", "}", "// トップページのIDは空白文字列でなければならない。", "if", "(", "$", "path_toppage", "==", "$", "tmp_page_info", "[", "'path'", "]", ")", "{", "$", "tmp_page_info", "[", "'id'", "]", "=", "''", ";", "}", "// --------------------", "// パンくずも特別", "$", "tmp_breadcrumb", "=", "$", "last_breadcrumb", ";", "if", "(", "$", "logical_path_last_depth", "===", "$", "logical_path_depth", ")", "{", "// 前回と深さが変わっていなかったら", "}", "elseif", "(", "$", "logical_path_last_depth", "<", "$", "logical_path_depth", ")", "{", "// 前回の深さより深くなっていたら", "$", "tmp_breadcrumb", "=", "$", "last_breadcrumb", ";", "array_push", "(", "$", "tmp_breadcrumb", ",", "$", "last_page_id", ")", ";", "}", "elseif", "(", "$", "logical_path_last_depth", ">", "$", "logical_path_depth", ")", "{", "// 前回の深さより浅くなっていたら", "$", "tmp_breadcrumb", "=", "array", "(", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "logical_path_depth", ";", "$", "i", "++", ")", "{", "if", "(", "is_null", "(", "$", "last_breadcrumb", "[", "$", "i", "]", ")", ")", "{", "break", ";", "}", "$", "tmp_breadcrumb", "[", "$", "i", "]", "=", "$", "last_breadcrumb", "[", "$", "i", "]", ";", "}", "}", "if", "(", "@", "strlen", "(", "$", "tmp_page_info", "[", "'logical_path'", "]", ")", ")", "{", "// エクセルの定義にlogical_path列があったら、", "// この値を優先して採用する。", "}", "else", "{", "$", "tmp_page_info", "[", "'logical_path'", "]", "=", "''", ";", "if", "(", "count", "(", "$", "tmp_breadcrumb", ")", ">=", "2", ")", "{", "$", "tmp_page_info", "[", "'logical_path'", "]", "=", "implode", "(", "'>'", ",", "$", "tmp_breadcrumb", ")", ";", "$", "tmp_page_info", "[", "'logical_path'", "]", "=", "preg_replace", "(", "'/^(.*?)\\\\>/s'", ",", "''", ",", "$", "tmp_page_info", "[", "'logical_path'", "]", ")", ";", "}", "}", "// 今回のパンくずとパンくずの深さを記録", "$", "logical_path_last_depth", "=", "$", "logical_path_depth", ";", "$", "last_breadcrumb", "=", "$", "tmp_breadcrumb", ";", "$", "last_page_id", "=", "$", "tmp_page_info", "[", "'path'", "]", ";", "if", "(", "preg_match", "(", "'/^alias\\\\:/'", ",", "$", "tmp_page_info", "[", "'path'", "]", ")", ")", "{", "$", "last_page_id", "=", "$", "tmp_page_info", "[", "'id'", "]", ";", "}", "// --------------------", "// サイトマップにページを追加する", "$", "page_info", "=", "array", "(", ")", ";", "foreach", "(", "$", "sitemap_definition", "as", "$", "row", ")", "{", "$", "page_info", "[", "$", "row", "[", "'key'", "]", "]", "=", "$", "tmp_page_info", "[", "$", "row", "[", "'key'", "]", "]", ";", "}", "if", "(", "count", "(", "$", "alias_title_list", ")", ")", "{", "// エイリアスが省略されている場合", "$", "page_info_base", "=", "$", "page_info", ";", "$", "page_info", "[", "'path'", "]", "=", "'alias:'", ".", "$", "page_info", "[", "'path'", "]", ";", "$", "this", "->", "output_csv_row", "(", "$", "page_info", ")", ";", "$", "tmp_last_page_id", "=", "$", "page_info", "[", "'id'", "]", ";", "foreach", "(", "$", "alias_title_list", "as", "$", "key", "=>", "$", "row", ")", "{", "$", "page_info", "=", "$", "page_info_base", ";", "if", "(", "count", "(", "$", "alias_title_list", ")", ">", "$", "key", "+", "1", ")", "{", "// 最後の1件以外なら", "$", "page_info", "[", "'path'", "]", "=", "'alias:'", ".", "$", "page_info", "[", "'path'", "]", ";", "}", "if", "(", "$", "page_info_base", "[", "'category_top_flg'", "]", ")", "{", "$", "page_info", "[", "'category_top_flg'", "]", "=", "null", ";", "}", "array_push", "(", "$", "tmp_breadcrumb", ",", "$", "tmp_last_page_id", ")", ";", "$", "page_info", "[", "'logical_path'", "]", "=", "''", ";", "if", "(", "count", "(", "$", "tmp_breadcrumb", ")", ">=", "2", ")", "{", "$", "page_info", "[", "'logical_path'", "]", "=", "implode", "(", "'>'", ",", "$", "tmp_breadcrumb", ")", ";", "$", "page_info", "[", "'logical_path'", "]", "=", "preg_replace", "(", "'/^(.*?)\\\\>/s'", ",", "''", ",", "$", "page_info", "[", "'logical_path'", "]", ")", ";", "}", "$", "page_info", "[", "'id'", "]", "=", "$", "this", "->", "generate_auto_page_id", "(", ")", ";", "$", "page_info", "[", "'title'", "]", "=", "$", "row", ";", "// var_dump($page_info['title']);", "$", "this", "->", "output_csv_row", "(", "$", "page_info", ")", ";", "$", "tmp_last_page_id", "=", "$", "page_info", "[", "'id'", "]", ";", "$", "logical_path_last_depth", "++", ";", "$", "last_breadcrumb", "=", "$", "tmp_breadcrumb", ";", "$", "last_page_id", "=", "$", "tmp_last_page_id", ";", "}", "unset", "(", "$", "page_info_base", ")", ";", "unset", "(", "$", "tmp_last_page_id", ")", ";", "continue", ";", "}", "else", "{", "// 通常のページの場合", "$", "this", "->", "output_csv_row", "(", "$", "page_info", ")", ";", "continue", ";", "}", "continue", ";", "}", "$", "this", "->", "px", "->", "fs", "(", ")", "->", "mkdir", "(", "dirname", "(", "$", "this", "->", "path_csv", ")", ")", ";", "$", "this", "->", "px", "->", "fs", "(", ")", "->", "rename", "(", "$", "this", "->", "path_tmp_csv", ",", "$", "this", "->", "path_csv", ")", ";", "$", "this", "->", "px", "->", "fs", "(", ")", "->", "chmod", "(", "$", "this", "->", "path_csv", ",", "octdec", "(", "$", "this", "->", "px", "->", "conf", "(", ")", "->", "file_default_permission", ")", ")", ";", "set_time_limit", "(", "30", ")", ";", "clearstatcache", "(", ")", ";", "return", "$", "this", ";", "}" ]
xlsxからサイトマップCSVを出力する。
[ "xlsxからサイトマップCSVを出力する。" ]
train
https://github.com/pickles2/px2-sitemapexcel/blob/fbfa207ee9b2e4bd977aadf69a935d3fade51fea/php/apis/xlsx2csv.php#L51-L323
pickles2/px2-sitemapexcel
php/apis/xlsx2csv.php
xlsx2csv.output_csv_row
private function output_csv_row( $row ){ $this->px->fs()->mkdir(dirname($this->path_tmp_csv)); file_put_contents( $this->path_tmp_csv, $this->px->fs()->mk_csv( array($row), array('charset'=>'UTF-8') ), FILE_APPEND|LOCK_EX ); return $res; }
php
private function output_csv_row( $row ){ $this->px->fs()->mkdir(dirname($this->path_tmp_csv)); file_put_contents( $this->path_tmp_csv, $this->px->fs()->mk_csv( array($row), array('charset'=>'UTF-8') ), FILE_APPEND|LOCK_EX ); return $res; }
[ "private", "function", "output_csv_row", "(", "$", "row", ")", "{", "$", "this", "->", "px", "->", "fs", "(", ")", "->", "mkdir", "(", "dirname", "(", "$", "this", "->", "path_tmp_csv", ")", ")", ";", "file_put_contents", "(", "$", "this", "->", "path_tmp_csv", ",", "$", "this", "->", "px", "->", "fs", "(", ")", "->", "mk_csv", "(", "array", "(", "$", "row", ")", ",", "array", "(", "'charset'", "=>", "'UTF-8'", ")", ")", ",", "FILE_APPEND", "|", "LOCK_EX", ")", ";", "return", "$", "res", ";", "}" ]
サイトマップの行を一時ファイルに出力する @return boolean result
[ "サイトマップの行を一時ファイルに出力する" ]
train
https://github.com/pickles2/px2-sitemapexcel/blob/fbfa207ee9b2e4bd977aadf69a935d3fade51fea/php/apis/xlsx2csv.php#L329-L340
pickles2/px2-sitemapexcel
php/apis/xlsx2csv.php
xlsx2csv.generate_auto_page_id
private function generate_auto_page_id(){ $this->auto_id_num ++; $rtn = 'sitemapExcel_auto_id_'.$this->extless_basename.'-'.intval($this->auto_id_num); return $rtn; }
php
private function generate_auto_page_id(){ $this->auto_id_num ++; $rtn = 'sitemapExcel_auto_id_'.$this->extless_basename.'-'.intval($this->auto_id_num); return $rtn; }
[ "private", "function", "generate_auto_page_id", "(", ")", "{", "$", "this", "->", "auto_id_num", "++", ";", "$", "rtn", "=", "'sitemapExcel_auto_id_'", ".", "$", "this", "->", "extless_basename", ".", "'-'", ".", "intval", "(", "$", "this", "->", "auto_id_num", ")", ";", "return", "$", "rtn", ";", "}" ]
ページIDを自動生成する
[ "ページIDを自動生成する" ]
train
https://github.com/pickles2/px2-sitemapexcel/blob/fbfa207ee9b2e4bd977aadf69a935d3fade51fea/php/apis/xlsx2csv.php#L353-L357
pickles2/px2-sitemapexcel
php/apis/xlsx2csv.php
xlsx2csv.regulize_path
private function regulize_path($path){ switch( $this->px->get_path_type($path) ){ case 'full_url': case 'data': case 'javascript': case 'anchor': break; default: $parsed_url = parse_url($path); $path_path = preg_replace( '/(?:\?|\#).*$/', '', $path); $path_path = preg_replace( '/\/$/s', '/'.$this->px->get_directory_index_primary(), $path_path); $path = $path_path.(strlen(@$parsed_url['query'])?'?'.@$parsed_url['query']:'').(strlen(@$parsed_url['fragment'])?'#'.@$parsed_url['fragment']:''); break; } return $path; }
php
private function regulize_path($path){ switch( $this->px->get_path_type($path) ){ case 'full_url': case 'data': case 'javascript': case 'anchor': break; default: $parsed_url = parse_url($path); $path_path = preg_replace( '/(?:\?|\#).*$/', '', $path); $path_path = preg_replace( '/\/$/s', '/'.$this->px->get_directory_index_primary(), $path_path); $path = $path_path.(strlen(@$parsed_url['query'])?'?'.@$parsed_url['query']:'').(strlen(@$parsed_url['fragment'])?'#'.@$parsed_url['fragment']:''); break; } return $path; }
[ "private", "function", "regulize_path", "(", "$", "path", ")", "{", "switch", "(", "$", "this", "->", "px", "->", "get_path_type", "(", "$", "path", ")", ")", "{", "case", "'full_url'", ":", "case", "'data'", ":", "case", "'javascript'", ":", "case", "'anchor'", ":", "break", ";", "default", ":", "$", "parsed_url", "=", "parse_url", "(", "$", "path", ")", ";", "$", "path_path", "=", "preg_replace", "(", "'/(?:\\?|\\#).*$/'", ",", "''", ",", "$", "path", ")", ";", "$", "path_path", "=", "preg_replace", "(", "'/\\/$/s'", ",", "'/'", ".", "$", "this", "->", "px", "->", "get_directory_index_primary", "(", ")", ",", "$", "path_path", ")", ";", "$", "path", "=", "$", "path_path", ".", "(", "strlen", "(", "@", "$", "parsed_url", "[", "'query'", "]", ")", "?", "'?'", ".", "@", "$", "parsed_url", "[", "'query'", "]", ":", "''", ")", ".", "(", "strlen", "(", "@", "$", "parsed_url", "[", "'fragment'", "]", ")", "?", "'#'", ".", "@", "$", "parsed_url", "[", "'fragment'", "]", ":", "''", ")", ";", "break", ";", "}", "return", "$", "path", ";", "}" ]
パス文字列の正規化
[ "パス文字列の正規化" ]
train
https://github.com/pickles2/px2-sitemapexcel/blob/fbfa207ee9b2e4bd977aadf69a935d3fade51fea/php/apis/xlsx2csv.php#L362-L377
pickles2/px2-sitemapexcel
php/apis/xlsx2csv.php
xlsx2csv.parse_definition
private function parse_definition( $objPHPExcel, $sheetIndex = 0 ){ $rtn = array(); $objPHPExcel->setActiveSheetIndex($sheetIndex); $objSheet = $objPHPExcel->getActiveSheet(); parse_str( $objSheet->getCell('A1')->getCalculatedValue(), $rtn ); $rtn['tbl_highest_row'] = $objSheet->getHighestRow(); // e.g. 10 $rtn['tbl_highest_col_name'] = $objSheet->getHighestColumn(); // e.g 'F' $rtn['tbl_highest_col'] = \PHPExcel_Cell::columnIndexFromString( $rtn['tbl_highest_col_name'] ); // e.g. 5 $rtn['row_definition'] = @intval($rtn['row_definition']); $rtn['row_data_start'] = @intval($rtn['row_data_start']); if( !@strlen($rtn['skip_empty_col']) ){ // 省略されていた場合にデフォルト値を与える $rtn['skip_empty_col'] = 20; } $rtn['skip_empty_col'] = intval($rtn['skip_empty_col']); $rtn['col_define'] = array(); $mergedCells = $objSheet->getMergeCells(); $mergeInfo = array(); foreach( $mergedCells as $mergeRow ){ if( preg_match( '/^([a-zA-Z]+)'.$rtn['row_definition'].'\:([a-zA-Z]+)'.$rtn['row_definition'].'$/', $mergeRow, $matched ) ){ $mergeInfo[$matched[1]] = $matched[2]; } } $col = 'A'; $skip_count = 0; while(1){ $def_key = $objSheet->getCell($col.$rtn['row_definition'])->getCalculatedValue(); if(!strlen($def_key)){ $skip_count ++; $col ++; if( $skip_count > $rtn['skip_empty_col'] ){ break; } continue; } $skip_count = 0; $rtn['col_define'][$def_key] = array( 'key'=>trim($def_key), 'col'=>$col, // 'name'=>$def_name, ); if( @strlen($mergeInfo[$col]) ){ $mergeStartCol = $mergeInfo[$col]; while( strcmp($mergeStartCol, $col) ){ $col ++; } }else{ $col ++; } } return $rtn; }
php
private function parse_definition( $objPHPExcel, $sheetIndex = 0 ){ $rtn = array(); $objPHPExcel->setActiveSheetIndex($sheetIndex); $objSheet = $objPHPExcel->getActiveSheet(); parse_str( $objSheet->getCell('A1')->getCalculatedValue(), $rtn ); $rtn['tbl_highest_row'] = $objSheet->getHighestRow(); // e.g. 10 $rtn['tbl_highest_col_name'] = $objSheet->getHighestColumn(); // e.g 'F' $rtn['tbl_highest_col'] = \PHPExcel_Cell::columnIndexFromString( $rtn['tbl_highest_col_name'] ); // e.g. 5 $rtn['row_definition'] = @intval($rtn['row_definition']); $rtn['row_data_start'] = @intval($rtn['row_data_start']); if( !@strlen($rtn['skip_empty_col']) ){ // 省略されていた場合にデフォルト値を与える $rtn['skip_empty_col'] = 20; } $rtn['skip_empty_col'] = intval($rtn['skip_empty_col']); $rtn['col_define'] = array(); $mergedCells = $objSheet->getMergeCells(); $mergeInfo = array(); foreach( $mergedCells as $mergeRow ){ if( preg_match( '/^([a-zA-Z]+)'.$rtn['row_definition'].'\:([a-zA-Z]+)'.$rtn['row_definition'].'$/', $mergeRow, $matched ) ){ $mergeInfo[$matched[1]] = $matched[2]; } } $col = 'A'; $skip_count = 0; while(1){ $def_key = $objSheet->getCell($col.$rtn['row_definition'])->getCalculatedValue(); if(!strlen($def_key)){ $skip_count ++; $col ++; if( $skip_count > $rtn['skip_empty_col'] ){ break; } continue; } $skip_count = 0; $rtn['col_define'][$def_key] = array( 'key'=>trim($def_key), 'col'=>$col, // 'name'=>$def_name, ); if( @strlen($mergeInfo[$col]) ){ $mergeStartCol = $mergeInfo[$col]; while( strcmp($mergeStartCol, $col) ){ $col ++; } }else{ $col ++; } } return $rtn; }
[ "private", "function", "parse_definition", "(", "$", "objPHPExcel", ",", "$", "sheetIndex", "=", "0", ")", "{", "$", "rtn", "=", "array", "(", ")", ";", "$", "objPHPExcel", "->", "setActiveSheetIndex", "(", "$", "sheetIndex", ")", ";", "$", "objSheet", "=", "$", "objPHPExcel", "->", "getActiveSheet", "(", ")", ";", "parse_str", "(", "$", "objSheet", "->", "getCell", "(", "'A1'", ")", "->", "getCalculatedValue", "(", ")", ",", "$", "rtn", ")", ";", "$", "rtn", "[", "'tbl_highest_row'", "]", "=", "$", "objSheet", "->", "getHighestRow", "(", ")", ";", "// e.g. 10", "$", "rtn", "[", "'tbl_highest_col_name'", "]", "=", "$", "objSheet", "->", "getHighestColumn", "(", ")", ";", "// e.g 'F'", "$", "rtn", "[", "'tbl_highest_col'", "]", "=", "\\", "PHPExcel_Cell", "::", "columnIndexFromString", "(", "$", "rtn", "[", "'tbl_highest_col_name'", "]", ")", ";", "// e.g. 5", "$", "rtn", "[", "'row_definition'", "]", "=", "@", "intval", "(", "$", "rtn", "[", "'row_definition'", "]", ")", ";", "$", "rtn", "[", "'row_data_start'", "]", "=", "@", "intval", "(", "$", "rtn", "[", "'row_data_start'", "]", ")", ";", "if", "(", "!", "@", "strlen", "(", "$", "rtn", "[", "'skip_empty_col'", "]", ")", ")", "{", "// 省略されていた場合にデフォルト値を与える", "$", "rtn", "[", "'skip_empty_col'", "]", "=", "20", ";", "}", "$", "rtn", "[", "'skip_empty_col'", "]", "=", "intval", "(", "$", "rtn", "[", "'skip_empty_col'", "]", ")", ";", "$", "rtn", "[", "'col_define'", "]", "=", "array", "(", ")", ";", "$", "mergedCells", "=", "$", "objSheet", "->", "getMergeCells", "(", ")", ";", "$", "mergeInfo", "=", "array", "(", ")", ";", "foreach", "(", "$", "mergedCells", "as", "$", "mergeRow", ")", "{", "if", "(", "preg_match", "(", "'/^([a-zA-Z]+)'", ".", "$", "rtn", "[", "'row_definition'", "]", ".", "'\\:([a-zA-Z]+)'", ".", "$", "rtn", "[", "'row_definition'", "]", ".", "'$/'", ",", "$", "mergeRow", ",", "$", "matched", ")", ")", "{", "$", "mergeInfo", "[", "$", "matched", "[", "1", "]", "]", "=", "$", "matched", "[", "2", "]", ";", "}", "}", "$", "col", "=", "'A'", ";", "$", "skip_count", "=", "0", ";", "while", "(", "1", ")", "{", "$", "def_key", "=", "$", "objSheet", "->", "getCell", "(", "$", "col", ".", "$", "rtn", "[", "'row_definition'", "]", ")", "->", "getCalculatedValue", "(", ")", ";", "if", "(", "!", "strlen", "(", "$", "def_key", ")", ")", "{", "$", "skip_count", "++", ";", "$", "col", "++", ";", "if", "(", "$", "skip_count", ">", "$", "rtn", "[", "'skip_empty_col'", "]", ")", "{", "break", ";", "}", "continue", ";", "}", "$", "skip_count", "=", "0", ";", "$", "rtn", "[", "'col_define'", "]", "[", "$", "def_key", "]", "=", "array", "(", "'key'", "=>", "trim", "(", "$", "def_key", ")", ",", "'col'", "=>", "$", "col", ",", "// 'name'=>$def_name,", ")", ";", "if", "(", "@", "strlen", "(", "$", "mergeInfo", "[", "$", "col", "]", ")", ")", "{", "$", "mergeStartCol", "=", "$", "mergeInfo", "[", "$", "col", "]", ";", "while", "(", "strcmp", "(", "$", "mergeStartCol", ",", "$", "col", ")", ")", "{", "$", "col", "++", ";", "}", "}", "else", "{", "$", "col", "++", ";", "}", "}", "return", "$", "rtn", ";", "}" ]
xlsxの構造定義設定を解析する
[ "xlsxの構造定義設定を解析する" ]
train
https://github.com/pickles2/px2-sitemapexcel/blob/fbfa207ee9b2e4bd977aadf69a935d3fade51fea/php/apis/xlsx2csv.php#L382-L442
pipelinersales/pipeliner-php-sdk
src/PipelinerSales/ApiClient/Query/Criteria.php
Criteria.toUrlQuery
public function toUrlQuery() { $queryData = array(); foreach (self::$properties as $p => $setter) { if ($this->$p !== null) { $queryData[$p] = $this->$p; } } return http_build_query($queryData); }
php
public function toUrlQuery() { $queryData = array(); foreach (self::$properties as $p => $setter) { if ($this->$p !== null) { $queryData[$p] = $this->$p; } } return http_build_query($queryData); }
[ "public", "function", "toUrlQuery", "(", ")", "{", "$", "queryData", "=", "array", "(", ")", ";", "foreach", "(", "self", "::", "$", "properties", "as", "$", "p", "=>", "$", "setter", ")", "{", "if", "(", "$", "this", "->", "$", "p", "!==", "null", ")", "{", "$", "queryData", "[", "$", "p", "]", "=", "$", "this", "->", "$", "p", ";", "}", "}", "return", "http_build_query", "(", "$", "queryData", ")", ";", "}" ]
Returns the resulting url-encoded query string. @return string
[ "Returns", "the", "resulting", "url", "-", "encoded", "query", "string", "." ]
train
https://github.com/pipelinersales/pipeliner-php-sdk/blob/a020149ffde815be17634542010814cf854c3d5f/src/PipelinerSales/ApiClient/Query/Criteria.php#L68-L77
pipelinersales/pipeliner-php-sdk
src/PipelinerSales/ApiClient/Query/Criteria.php
Criteria.set
public function set($criteria) { if ($criteria instanceof Criteria) { //this is much faster than using the same method that's used for arrays (see below) $this->limit = $criteria->limit; $this->offset = $criteria->offset; $this->sort = $criteria->sort; $this->filter = $criteria->filter; $this->after = $criteria->after; $this->loadonly = $criteria->loadonly; } elseif (is_string($criteria)) { //parse the string into an array and then parse the array $criteria = $this->parseHttpQuery($criteria); } if (is_array($criteria)) { foreach (self::$properties as $p => $setter) { if (isset($criteria[$p])) { $this->$setter($criteria[$p]); } } } }
php
public function set($criteria) { if ($criteria instanceof Criteria) { //this is much faster than using the same method that's used for arrays (see below) $this->limit = $criteria->limit; $this->offset = $criteria->offset; $this->sort = $criteria->sort; $this->filter = $criteria->filter; $this->after = $criteria->after; $this->loadonly = $criteria->loadonly; } elseif (is_string($criteria)) { //parse the string into an array and then parse the array $criteria = $this->parseHttpQuery($criteria); } if (is_array($criteria)) { foreach (self::$properties as $p => $setter) { if (isset($criteria[$p])) { $this->$setter($criteria[$p]); } } } }
[ "public", "function", "set", "(", "$", "criteria", ")", "{", "if", "(", "$", "criteria", "instanceof", "Criteria", ")", "{", "//this is much faster than using the same method that's used for arrays (see below)", "$", "this", "->", "limit", "=", "$", "criteria", "->", "limit", ";", "$", "this", "->", "offset", "=", "$", "criteria", "->", "offset", ";", "$", "this", "->", "sort", "=", "$", "criteria", "->", "sort", ";", "$", "this", "->", "filter", "=", "$", "criteria", "->", "filter", ";", "$", "this", "->", "after", "=", "$", "criteria", "->", "after", ";", "$", "this", "->", "loadonly", "=", "$", "criteria", "->", "loadonly", ";", "}", "elseif", "(", "is_string", "(", "$", "criteria", ")", ")", "{", "//parse the string into an array and then parse the array", "$", "criteria", "=", "$", "this", "->", "parseHttpQuery", "(", "$", "criteria", ")", ";", "}", "if", "(", "is_array", "(", "$", "criteria", ")", ")", "{", "foreach", "(", "self", "::", "$", "properties", "as", "$", "p", "=>", "$", "setter", ")", "{", "if", "(", "isset", "(", "$", "criteria", "[", "$", "p", "]", ")", ")", "{", "$", "this", "->", "$", "setter", "(", "$", "criteria", "[", "$", "p", "]", ")", ";", "}", "}", "}", "}" ]
Sets multiple parameters at once. @param mixed $criteria Can be one of the following: <ul> <li>Another Criteria object - copies that object's criteria into this one. Competely replaces the current object's values, unsetting those which have not been set in $criteria</li> <li>An array - sets the parameters present in the array. Parameters not present in the array will <b>not</b> be unset. If you wish to unset certain parameters, set them to null in the array.</li> <li>A string - the resulting query string (without a leading question mark), will be parsed back into the individual parameters and processed like an array.</li> </ul>
[ "Sets", "multiple", "parameters", "at", "once", "." ]
train
https://github.com/pipelinersales/pipeliner-php-sdk/blob/a020149ffde815be17634542010814cf854c3d5f/src/PipelinerSales/ApiClient/Query/Criteria.php#L247-L269
pipelinersales/pipeliner-php-sdk
src/PipelinerSales/ApiClient/Query/Criteria.php
Criteria.parseHttpQuery
private function parseHttpQuery($query) { /* can't use parse_str, because the minimum supported PHP version * is 5.3, which still has the magic_quotes_gpc option that affects its * result, so some users could hypothetically have that enabled */ if (empty($query)) { return array(); } $result = array(); $parts = explode('&', $query); foreach ($parts as $p) { $keyval = explode('=', $p); $result[urldecode($keyval[0])] = urldecode($keyval[1]); } return $result; }
php
private function parseHttpQuery($query) { /* can't use parse_str, because the minimum supported PHP version * is 5.3, which still has the magic_quotes_gpc option that affects its * result, so some users could hypothetically have that enabled */ if (empty($query)) { return array(); } $result = array(); $parts = explode('&', $query); foreach ($parts as $p) { $keyval = explode('=', $p); $result[urldecode($keyval[0])] = urldecode($keyval[1]); } return $result; }
[ "private", "function", "parseHttpQuery", "(", "$", "query", ")", "{", "/* can't use parse_str, because the minimum supported PHP version\n * is 5.3, which still has the magic_quotes_gpc option that affects its\n * result, so some users could hypothetically have that enabled */", "if", "(", "empty", "(", "$", "query", ")", ")", "{", "return", "array", "(", ")", ";", "}", "$", "result", "=", "array", "(", ")", ";", "$", "parts", "=", "explode", "(", "'&'", ",", "$", "query", ")", ";", "foreach", "(", "$", "parts", "as", "$", "p", ")", "{", "$", "keyval", "=", "explode", "(", "'='", ",", "$", "p", ")", ";", "$", "result", "[", "urldecode", "(", "$", "keyval", "[", "0", "]", ")", "]", "=", "urldecode", "(", "$", "keyval", "[", "1", "]", ")", ";", "}", "return", "$", "result", ";", "}" ]
Parses a http query into a key-value array, similar to PHP's parse_str function. @param string $query query string (without a leading question mark) @return array
[ "Parses", "a", "http", "query", "into", "a", "key", "-", "value", "array", "similar", "to", "PHP", "s", "parse_str", "function", "." ]
train
https://github.com/pipelinersales/pipeliner-php-sdk/blob/a020149ffde815be17634542010814cf854c3d5f/src/PipelinerSales/ApiClient/Query/Criteria.php#L276-L292
innobrig/flex-input
src/Input.php
Input.fromCookie
public static function fromCookie ($key, $default=null, $filter=null, $args=array()) { if (!$key) { return self::filterArray ($_COOKIE, $filter, $args); } return self::getPassedValue ($key, $default, 'C', $filter, $args); }
php
public static function fromCookie ($key, $default=null, $filter=null, $args=array()) { if (!$key) { return self::filterArray ($_COOKIE, $filter, $args); } return self::getPassedValue ($key, $default, 'C', $filter, $args); }
[ "public", "static", "function", "fromCookie", "(", "$", "key", ",", "$", "default", "=", "null", ",", "$", "filter", "=", "null", ",", "$", "args", "=", "array", "(", ")", ")", "{", "if", "(", "!", "$", "key", ")", "{", "return", "self", "::", "filterArray", "(", "$", "_COOKIE", ",", "$", "filter", ",", "$", "args", ")", ";", "}", "return", "self", "::", "getPassedValue", "(", "$", "key", ",", "$", "default", ",", "'C'", ",", "$", "filter", ",", "$", "args", ")", ";", "}" ]
Wrapper for COOKIE input @param string $key The input field to return. @param mixed $default The value to return if the requested field is not found (optional) (default=false). @param string $filter The filter directive to apply to the retrieved input (optional) (default=null) @param array $args The filter processing args to apply (optional) (default=array()) @return array|mixed @throws \Exception
[ "Wrapper", "for", "COOKIE", "input" ]
train
https://github.com/innobrig/flex-input/blob/81db6cd22820d310d35be9a71d545dafffb21c64/src/Input.php#L33-L40
innobrig/flex-input
src/Input.php
Input.fromDelete
public static function fromDelete ($key, $default=null, $filter=null, $args=array()) { if (!$key) { $values = array(); parse_str (file_get_contents("php://input"), $values); return self::filterArray ($values, $filter, $args); } return self::getPassedValue ($key, $default, 'D', $filter, $args); }
php
public static function fromDelete ($key, $default=null, $filter=null, $args=array()) { if (!$key) { $values = array(); parse_str (file_get_contents("php://input"), $values); return self::filterArray ($values, $filter, $args); } return self::getPassedValue ($key, $default, 'D', $filter, $args); }
[ "public", "static", "function", "fromDelete", "(", "$", "key", ",", "$", "default", "=", "null", ",", "$", "filter", "=", "null", ",", "$", "args", "=", "array", "(", ")", ")", "{", "if", "(", "!", "$", "key", ")", "{", "$", "values", "=", "array", "(", ")", ";", "parse_str", "(", "file_get_contents", "(", "\"php://input\"", ")", ",", "$", "values", ")", ";", "return", "self", "::", "filterArray", "(", "$", "values", ",", "$", "filter", ",", "$", "args", ")", ";", "}", "return", "self", "::", "getPassedValue", "(", "$", "key", ",", "$", "default", ",", "'D'", ",", "$", "filter", ",", "$", "args", ")", ";", "}" ]
Wrapper for DELETE input @param string $key The input field to return. @param mixed $default The value to return if the requested field is not found (optional) (default=false). @param string $filter The filter directive to apply to the retrieved input (optional) (default=null) @param array $args The filter processing args to apply (optional) (default=array()) @return array|mixed @throws \Exception
[ "Wrapper", "for", "DELETE", "input" ]
train
https://github.com/innobrig/flex-input/blob/81db6cd22820d310d35be9a71d545dafffb21c64/src/Input.php#L54-L63
innobrig/flex-input
src/Input.php
Input.fromFiles
public static function fromFiles ($key, $default=null, $filter=null, $args=array()) { if (!$key) { return self::filterArray ($_FILES, $filter, $args); } return self::getPassedValue ($key, $default, 'F', $filter, $args); }
php
public static function fromFiles ($key, $default=null, $filter=null, $args=array()) { if (!$key) { return self::filterArray ($_FILES, $filter, $args); } return self::getPassedValue ($key, $default, 'F', $filter, $args); }
[ "public", "static", "function", "fromFiles", "(", "$", "key", ",", "$", "default", "=", "null", ",", "$", "filter", "=", "null", ",", "$", "args", "=", "array", "(", ")", ")", "{", "if", "(", "!", "$", "key", ")", "{", "return", "self", "::", "filterArray", "(", "$", "_FILES", ",", "$", "filter", ",", "$", "args", ")", ";", "}", "return", "self", "::", "getPassedValue", "(", "$", "key", ",", "$", "default", ",", "'F'", ",", "$", "filter", ",", "$", "args", ")", ";", "}" ]
Wrapper for FILES input @param string $key The input field to return. @param mixed $default The value to return if the requested field is not found (optional) (default=false). @param string $filter The filter directive to apply to the retrieved input (optional) (default=null) @param array $args The filter processing args to apply (optional) (default=array()) @return array|mixed @throws \Exception
[ "Wrapper", "for", "FILES", "input" ]
train
https://github.com/innobrig/flex-input/blob/81db6cd22820d310d35be9a71d545dafffb21c64/src/Input.php#L77-L84
innobrig/flex-input
src/Input.php
Input.fromGet
public static function fromGet ($key, $default=null, $filter=null, $args=array()) { if (!$key) { return self::filterArray ($_GET, $filter, $args); } return self::getPassedValue ($key, $default, 'G', $filter, $args); }
php
public static function fromGet ($key, $default=null, $filter=null, $args=array()) { if (!$key) { return self::filterArray ($_GET, $filter, $args); } return self::getPassedValue ($key, $default, 'G', $filter, $args); }
[ "public", "static", "function", "fromGet", "(", "$", "key", ",", "$", "default", "=", "null", ",", "$", "filter", "=", "null", ",", "$", "args", "=", "array", "(", ")", ")", "{", "if", "(", "!", "$", "key", ")", "{", "return", "self", "::", "filterArray", "(", "$", "_GET", ",", "$", "filter", ",", "$", "args", ")", ";", "}", "return", "self", "::", "getPassedValue", "(", "$", "key", ",", "$", "default", ",", "'G'", ",", "$", "filter", ",", "$", "args", ")", ";", "}" ]
Wrapper for GET input @param string $key The input field to return. @param mixed $default The value to return if the requested field is not found (optional) (default=false). @param string $filter The filter directive to apply to the retrieved input (optional) (default=null) @param array $args The filter processing args to apply (optional) (default=array()) @return array|mixed @throws \Exception
[ "Wrapper", "for", "GET", "input" ]
train
https://github.com/innobrig/flex-input/blob/81db6cd22820d310d35be9a71d545dafffb21c64/src/Input.php#L98-L105
innobrig/flex-input
src/Input.php
Input.fromPost
public static function fromPost ($key, $default=null, $filter=null, $args=array()) { if (!$key) { return self::filterArray ($_POST, $filter, $args); } return self::getPassedValue ($key, $default, 'P', $filter, $args); }
php
public static function fromPost ($key, $default=null, $filter=null, $args=array()) { if (!$key) { return self::filterArray ($_POST, $filter, $args); } return self::getPassedValue ($key, $default, 'P', $filter, $args); }
[ "public", "static", "function", "fromPost", "(", "$", "key", ",", "$", "default", "=", "null", ",", "$", "filter", "=", "null", ",", "$", "args", "=", "array", "(", ")", ")", "{", "if", "(", "!", "$", "key", ")", "{", "return", "self", "::", "filterArray", "(", "$", "_POST", ",", "$", "filter", ",", "$", "args", ")", ";", "}", "return", "self", "::", "getPassedValue", "(", "$", "key", ",", "$", "default", ",", "'P'", ",", "$", "filter", ",", "$", "args", ")", ";", "}" ]
Wrapper for POST input @param string $key The input field to return. @param mixed $default The value to return if the requested field is not found (optional) (default=false). @param string $filter The filter directive to apply to the retrieved input (optional) (default=null) @param array $args The filter processing args to apply (optional) (default=array()) @return array|mixed @throws \Exception
[ "Wrapper", "for", "POST", "input" ]
train
https://github.com/innobrig/flex-input/blob/81db6cd22820d310d35be9a71d545dafffb21c64/src/Input.php#L119-L126
innobrig/flex-input
src/Input.php
Input.fromRequest
public static function fromRequest ($key, $default=null, $filter=null, $args=array()) { if (!$key) { return self::filterArray ($_REQUEST, $filter, $args); } return self::getPassedValue ($key, $default, 'R', $filter, $args); }
php
public static function fromRequest ($key, $default=null, $filter=null, $args=array()) { if (!$key) { return self::filterArray ($_REQUEST, $filter, $args); } return self::getPassedValue ($key, $default, 'R', $filter, $args); }
[ "public", "static", "function", "fromRequest", "(", "$", "key", ",", "$", "default", "=", "null", ",", "$", "filter", "=", "null", ",", "$", "args", "=", "array", "(", ")", ")", "{", "if", "(", "!", "$", "key", ")", "{", "return", "self", "::", "filterArray", "(", "$", "_REQUEST", ",", "$", "filter", ",", "$", "args", ")", ";", "}", "return", "self", "::", "getPassedValue", "(", "$", "key", ",", "$", "default", ",", "'R'", ",", "$", "filter", ",", "$", "args", ")", ";", "}" ]
Wrapper for REQUEST input @param string $key The input field to return. @param mixed $default The value to return if the requested field is not found (optional) (default=false). @param string $filter The filter directive to apply to the retrieved input (optional) (default=null) @param array $args The filter processing args to apply (optional) (default=array()) @return array|mixed @throws \Exception
[ "Wrapper", "for", "REQUEST", "input" ]
train
https://github.com/innobrig/flex-input/blob/81db6cd22820d310d35be9a71d545dafffb21c64/src/Input.php#L184-L191
innobrig/flex-input
src/Input.php
Input.getPassedValue
public static function getPassedValue ($key, $default=null, $source=null, $filter=null, $args=array(), $doTrim=true) { if (!$key) { throw new \Exception ('Empty key passed to Input::getPassedValue()'); } if (!$source) { $source = 'REQUEST'; } else { $source = strtoupper ($source); } if (!$filter) { $filter = self::$defaultFilter; } if (!$args) { $args = array ('flags' => self::$defaultFlags); } $_args = $args; $value = $default; switch (true) { case (isset($_REQUEST[$key]) && !isset($_FILES[$key]) && ($source == 'R' || $source == 'REQUEST')): if (is_array($_REQUEST[$key])) { $args['flags'] = FILTER_REQUIRE_ARRAY; $value = self::filterArray ($_REQUEST[$key], $filter, $_args, $doTrim); } else { $value = filter_var (self::trim($_REQUEST[$key], $doTrim), $filter, $args); } break; case isset($_GET[$key]) && ($source == 'G' || $source == 'GET'): if (is_array($_GET[$key])) { $args['flags'] = FILTER_REQUIRE_ARRAY; $value = self::filterArray ($_GET[$key], $filter, $_args, $doTrim); } else { $value = filter_var (self::trim($_GET[$key], $doTrim), $filter, $args); } break; case isset($_POST[$key]) && ($source == 'P' || $source == 'POST'): if (is_array($_POST[$key])) { $args['flags'] = FILTER_REQUIRE_ARRAY; $value = self::filterArray ($_POST[$key], $filter, $_args, $doTrim); } else { $value = filter_var (self::trim($_POST[$key], $doTrim), $filter, $args); } break; case isset($_COOKIE[$key]) && ($source == 'C' || $source == 'COOKIE'): if (is_array($_COOKIE[$key])) { $args['flags'] = FILTER_REQUIRE_ARRAY; $value = self::filterArray ($_COOKIE[$key], $filter, $_args, $doTrim); } else { $value = filter_var (self::trim($_COOKIE[$key], $doTrim), $filter, $args); } break; case isset($_FILES[$key]) && ($source == 'F' || $source == 'FILES'): if (is_array($_FILES[$key])) { $args['flags'] = FILTER_REQUIRE_ARRAY; $value = self::filterArray ($_FILES[$key], $filter, $_args, $doTrim); } else { $value = filter_var (self::trim($_FILES[$key], $doTrim), $filter, $args); } break; case (isset($_GET[$key]) || isset($_POST[$key])) && ($source == 'GP' || $source == 'GETPOST'): if (isset($_GET[$key])) { if (is_array($_GET[$key])) { $args['flags'] = FILTER_REQUIRE_ARRAY; $value = self::filterArray ($_GET[$key], $filter, $_args, $doTrim); } else { $value = filter_var (self::trim($_GET[$key], $doTrim), $filter, $args); } } if (isset($_POST[$key])) { if (is_array($_POST[$key])) { $args['flags'] = FILTER_REQUIRE_ARRAY; $value = self::filterArray ($_POST[$key], $filter, $_args, $doTrim); } else { $value = filter_var (self::trim($_POST[$key], $doTrim), $filter, $args); } } break; case ($source == 'D' || $source == 'DELETE'): case ($source == 'U' || $source == 'PUT'): // P is already taken by POST, so we use U for pUt. $values = array(); parse_str (file_get_contents("php://input"), $values); if (is_array($values[$key])) { $args['flags'] = FILTER_REQUIRE_ARRAY; $value = self::filterArray ($values, $filter, $_args, $doTrim); } else { $value = filter_var (self::trim($values[$key], $doTrim), $filter, $args); } break; default: if ($source) { static $valid = array('R', 'REQUEST', 'G', 'GET', 'P', 'POST', 'GP', 'GETPOST', 'C', 'COOKIE', 'U', 'PUT', 'D', 'DELETE', 'F', 'FILES'); if (!in_array($source, $valid)) { throw new \Exception ("Invalid input source [$source] received"); } } } return $value; }
php
public static function getPassedValue ($key, $default=null, $source=null, $filter=null, $args=array(), $doTrim=true) { if (!$key) { throw new \Exception ('Empty key passed to Input::getPassedValue()'); } if (!$source) { $source = 'REQUEST'; } else { $source = strtoupper ($source); } if (!$filter) { $filter = self::$defaultFilter; } if (!$args) { $args = array ('flags' => self::$defaultFlags); } $_args = $args; $value = $default; switch (true) { case (isset($_REQUEST[$key]) && !isset($_FILES[$key]) && ($source == 'R' || $source == 'REQUEST')): if (is_array($_REQUEST[$key])) { $args['flags'] = FILTER_REQUIRE_ARRAY; $value = self::filterArray ($_REQUEST[$key], $filter, $_args, $doTrim); } else { $value = filter_var (self::trim($_REQUEST[$key], $doTrim), $filter, $args); } break; case isset($_GET[$key]) && ($source == 'G' || $source == 'GET'): if (is_array($_GET[$key])) { $args['flags'] = FILTER_REQUIRE_ARRAY; $value = self::filterArray ($_GET[$key], $filter, $_args, $doTrim); } else { $value = filter_var (self::trim($_GET[$key], $doTrim), $filter, $args); } break; case isset($_POST[$key]) && ($source == 'P' || $source == 'POST'): if (is_array($_POST[$key])) { $args['flags'] = FILTER_REQUIRE_ARRAY; $value = self::filterArray ($_POST[$key], $filter, $_args, $doTrim); } else { $value = filter_var (self::trim($_POST[$key], $doTrim), $filter, $args); } break; case isset($_COOKIE[$key]) && ($source == 'C' || $source == 'COOKIE'): if (is_array($_COOKIE[$key])) { $args['flags'] = FILTER_REQUIRE_ARRAY; $value = self::filterArray ($_COOKIE[$key], $filter, $_args, $doTrim); } else { $value = filter_var (self::trim($_COOKIE[$key], $doTrim), $filter, $args); } break; case isset($_FILES[$key]) && ($source == 'F' || $source == 'FILES'): if (is_array($_FILES[$key])) { $args['flags'] = FILTER_REQUIRE_ARRAY; $value = self::filterArray ($_FILES[$key], $filter, $_args, $doTrim); } else { $value = filter_var (self::trim($_FILES[$key], $doTrim), $filter, $args); } break; case (isset($_GET[$key]) || isset($_POST[$key])) && ($source == 'GP' || $source == 'GETPOST'): if (isset($_GET[$key])) { if (is_array($_GET[$key])) { $args['flags'] = FILTER_REQUIRE_ARRAY; $value = self::filterArray ($_GET[$key], $filter, $_args, $doTrim); } else { $value = filter_var (self::trim($_GET[$key], $doTrim), $filter, $args); } } if (isset($_POST[$key])) { if (is_array($_POST[$key])) { $args['flags'] = FILTER_REQUIRE_ARRAY; $value = self::filterArray ($_POST[$key], $filter, $_args, $doTrim); } else { $value = filter_var (self::trim($_POST[$key], $doTrim), $filter, $args); } } break; case ($source == 'D' || $source == 'DELETE'): case ($source == 'U' || $source == 'PUT'): // P is already taken by POST, so we use U for pUt. $values = array(); parse_str (file_get_contents("php://input"), $values); if (is_array($values[$key])) { $args['flags'] = FILTER_REQUIRE_ARRAY; $value = self::filterArray ($values, $filter, $_args, $doTrim); } else { $value = filter_var (self::trim($values[$key], $doTrim), $filter, $args); } break; default: if ($source) { static $valid = array('R', 'REQUEST', 'G', 'GET', 'P', 'POST', 'GP', 'GETPOST', 'C', 'COOKIE', 'U', 'PUT', 'D', 'DELETE', 'F', 'FILES'); if (!in_array($source, $valid)) { throw new \Exception ("Invalid input source [$source] received"); } } } return $value; }
[ "public", "static", "function", "getPassedValue", "(", "$", "key", ",", "$", "default", "=", "null", ",", "$", "source", "=", "null", ",", "$", "filter", "=", "null", ",", "$", "args", "=", "array", "(", ")", ",", "$", "doTrim", "=", "true", ")", "{", "if", "(", "!", "$", "key", ")", "{", "throw", "new", "\\", "Exception", "(", "'Empty key passed to Input::getPassedValue()'", ")", ";", "}", "if", "(", "!", "$", "source", ")", "{", "$", "source", "=", "'REQUEST'", ";", "}", "else", "{", "$", "source", "=", "strtoupper", "(", "$", "source", ")", ";", "}", "if", "(", "!", "$", "filter", ")", "{", "$", "filter", "=", "self", "::", "$", "defaultFilter", ";", "}", "if", "(", "!", "$", "args", ")", "{", "$", "args", "=", "array", "(", "'flags'", "=>", "self", "::", "$", "defaultFlags", ")", ";", "}", "$", "_args", "=", "$", "args", ";", "$", "value", "=", "$", "default", ";", "switch", "(", "true", ")", "{", "case", "(", "isset", "(", "$", "_REQUEST", "[", "$", "key", "]", ")", "&&", "!", "isset", "(", "$", "_FILES", "[", "$", "key", "]", ")", "&&", "(", "$", "source", "==", "'R'", "||", "$", "source", "==", "'REQUEST'", ")", ")", ":", "if", "(", "is_array", "(", "$", "_REQUEST", "[", "$", "key", "]", ")", ")", "{", "$", "args", "[", "'flags'", "]", "=", "FILTER_REQUIRE_ARRAY", ";", "$", "value", "=", "self", "::", "filterArray", "(", "$", "_REQUEST", "[", "$", "key", "]", ",", "$", "filter", ",", "$", "_args", ",", "$", "doTrim", ")", ";", "}", "else", "{", "$", "value", "=", "filter_var", "(", "self", "::", "trim", "(", "$", "_REQUEST", "[", "$", "key", "]", ",", "$", "doTrim", ")", ",", "$", "filter", ",", "$", "args", ")", ";", "}", "break", ";", "case", "isset", "(", "$", "_GET", "[", "$", "key", "]", ")", "&&", "(", "$", "source", "==", "'G'", "||", "$", "source", "==", "'GET'", ")", ":", "if", "(", "is_array", "(", "$", "_GET", "[", "$", "key", "]", ")", ")", "{", "$", "args", "[", "'flags'", "]", "=", "FILTER_REQUIRE_ARRAY", ";", "$", "value", "=", "self", "::", "filterArray", "(", "$", "_GET", "[", "$", "key", "]", ",", "$", "filter", ",", "$", "_args", ",", "$", "doTrim", ")", ";", "}", "else", "{", "$", "value", "=", "filter_var", "(", "self", "::", "trim", "(", "$", "_GET", "[", "$", "key", "]", ",", "$", "doTrim", ")", ",", "$", "filter", ",", "$", "args", ")", ";", "}", "break", ";", "case", "isset", "(", "$", "_POST", "[", "$", "key", "]", ")", "&&", "(", "$", "source", "==", "'P'", "||", "$", "source", "==", "'POST'", ")", ":", "if", "(", "is_array", "(", "$", "_POST", "[", "$", "key", "]", ")", ")", "{", "$", "args", "[", "'flags'", "]", "=", "FILTER_REQUIRE_ARRAY", ";", "$", "value", "=", "self", "::", "filterArray", "(", "$", "_POST", "[", "$", "key", "]", ",", "$", "filter", ",", "$", "_args", ",", "$", "doTrim", ")", ";", "}", "else", "{", "$", "value", "=", "filter_var", "(", "self", "::", "trim", "(", "$", "_POST", "[", "$", "key", "]", ",", "$", "doTrim", ")", ",", "$", "filter", ",", "$", "args", ")", ";", "}", "break", ";", "case", "isset", "(", "$", "_COOKIE", "[", "$", "key", "]", ")", "&&", "(", "$", "source", "==", "'C'", "||", "$", "source", "==", "'COOKIE'", ")", ":", "if", "(", "is_array", "(", "$", "_COOKIE", "[", "$", "key", "]", ")", ")", "{", "$", "args", "[", "'flags'", "]", "=", "FILTER_REQUIRE_ARRAY", ";", "$", "value", "=", "self", "::", "filterArray", "(", "$", "_COOKIE", "[", "$", "key", "]", ",", "$", "filter", ",", "$", "_args", ",", "$", "doTrim", ")", ";", "}", "else", "{", "$", "value", "=", "filter_var", "(", "self", "::", "trim", "(", "$", "_COOKIE", "[", "$", "key", "]", ",", "$", "doTrim", ")", ",", "$", "filter", ",", "$", "args", ")", ";", "}", "break", ";", "case", "isset", "(", "$", "_FILES", "[", "$", "key", "]", ")", "&&", "(", "$", "source", "==", "'F'", "||", "$", "source", "==", "'FILES'", ")", ":", "if", "(", "is_array", "(", "$", "_FILES", "[", "$", "key", "]", ")", ")", "{", "$", "args", "[", "'flags'", "]", "=", "FILTER_REQUIRE_ARRAY", ";", "$", "value", "=", "self", "::", "filterArray", "(", "$", "_FILES", "[", "$", "key", "]", ",", "$", "filter", ",", "$", "_args", ",", "$", "doTrim", ")", ";", "}", "else", "{", "$", "value", "=", "filter_var", "(", "self", "::", "trim", "(", "$", "_FILES", "[", "$", "key", "]", ",", "$", "doTrim", ")", ",", "$", "filter", ",", "$", "args", ")", ";", "}", "break", ";", "case", "(", "isset", "(", "$", "_GET", "[", "$", "key", "]", ")", "||", "isset", "(", "$", "_POST", "[", "$", "key", "]", ")", ")", "&&", "(", "$", "source", "==", "'GP'", "||", "$", "source", "==", "'GETPOST'", ")", ":", "if", "(", "isset", "(", "$", "_GET", "[", "$", "key", "]", ")", ")", "{", "if", "(", "is_array", "(", "$", "_GET", "[", "$", "key", "]", ")", ")", "{", "$", "args", "[", "'flags'", "]", "=", "FILTER_REQUIRE_ARRAY", ";", "$", "value", "=", "self", "::", "filterArray", "(", "$", "_GET", "[", "$", "key", "]", ",", "$", "filter", ",", "$", "_args", ",", "$", "doTrim", ")", ";", "}", "else", "{", "$", "value", "=", "filter_var", "(", "self", "::", "trim", "(", "$", "_GET", "[", "$", "key", "]", ",", "$", "doTrim", ")", ",", "$", "filter", ",", "$", "args", ")", ";", "}", "}", "if", "(", "isset", "(", "$", "_POST", "[", "$", "key", "]", ")", ")", "{", "if", "(", "is_array", "(", "$", "_POST", "[", "$", "key", "]", ")", ")", "{", "$", "args", "[", "'flags'", "]", "=", "FILTER_REQUIRE_ARRAY", ";", "$", "value", "=", "self", "::", "filterArray", "(", "$", "_POST", "[", "$", "key", "]", ",", "$", "filter", ",", "$", "_args", ",", "$", "doTrim", ")", ";", "}", "else", "{", "$", "value", "=", "filter_var", "(", "self", "::", "trim", "(", "$", "_POST", "[", "$", "key", "]", ",", "$", "doTrim", ")", ",", "$", "filter", ",", "$", "args", ")", ";", "}", "}", "break", ";", "case", "(", "$", "source", "==", "'D'", "||", "$", "source", "==", "'DELETE'", ")", ":", "case", "(", "$", "source", "==", "'U'", "||", "$", "source", "==", "'PUT'", ")", ":", "// P is already taken by POST, so we use U for pUt.", "$", "values", "=", "array", "(", ")", ";", "parse_str", "(", "file_get_contents", "(", "\"php://input\"", ")", ",", "$", "values", ")", ";", "if", "(", "is_array", "(", "$", "values", "[", "$", "key", "]", ")", ")", "{", "$", "args", "[", "'flags'", "]", "=", "FILTER_REQUIRE_ARRAY", ";", "$", "value", "=", "self", "::", "filterArray", "(", "$", "values", ",", "$", "filter", ",", "$", "_args", ",", "$", "doTrim", ")", ";", "}", "else", "{", "$", "value", "=", "filter_var", "(", "self", "::", "trim", "(", "$", "values", "[", "$", "key", "]", ",", "$", "doTrim", ")", ",", "$", "filter", ",", "$", "args", ")", ";", "}", "break", ";", "default", ":", "if", "(", "$", "source", ")", "{", "static", "$", "valid", "=", "array", "(", "'R'", ",", "'REQUEST'", ",", "'G'", ",", "'GET'", ",", "'P'", ",", "'POST'", ",", "'GP'", ",", "'GETPOST'", ",", "'C'", ",", "'COOKIE'", ",", "'U'", ",", "'PUT'", ",", "'D'", ",", "'DELETE'", ",", "'F'", ",", "'FILES'", ")", ";", "if", "(", "!", "in_array", "(", "$", "source", ",", "$", "valid", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Invalid input source [$source] received\"", ")", ";", "}", "}", "}", "return", "$", "value", ";", "}" ]
Return the requested key using filter_var() from input in a safe way. This function is safe to use for recursive arrays and either returns a non-empty string (or array) or the (optional) default. @param string $key The input field to return. @param mixed $default The value to return if the requested field is not found (optional) (default=false). @param string $source The source field to get a parameter from (optional) (default=null=REQUEST) @param string $filter The filter directive to apply to the retrieved input (optional) (default=null=FILTER_SANITIZE_STRING) @param array $args The filter processing args to apply (optional) (default=array()=FILTER_FLAG_STRIP_LOW|FILTER_FLAG_STRIP_HIGH) @param bool $doTrim Whether or not to apply trim() to retrieved parameter (optional) (default=true) @return mixed The requested input key or the specified default. @throws \Exception
[ "Return", "the", "requested", "key", "using", "filter_var", "()", "from", "input", "in", "a", "safe", "way", "." ]
train
https://github.com/innobrig/flex-input/blob/81db6cd22820d310d35be9a71d545dafffb21c64/src/Input.php#L209-L319
innobrig/flex-input
src/Input.php
Input.filterArray
protected static function filterArray (array $values, $filter=null, $args=array(), $doTrim=true) { if (!$values) { return $values; } if (!$filter) { $filter = self::$defaultFilter; } if (!$args) { $args = array ('flags' => self::$defaultFlags); } foreach ($values as $k=>$v) { if (is_array($v)) { $values[$k] = self::filterArray ($v, $filter, $args, $doTrim); } else { $values[$k] = filter_var (self::trim($v, $doTrim), $filter, $args); } } return $values; }
php
protected static function filterArray (array $values, $filter=null, $args=array(), $doTrim=true) { if (!$values) { return $values; } if (!$filter) { $filter = self::$defaultFilter; } if (!$args) { $args = array ('flags' => self::$defaultFlags); } foreach ($values as $k=>$v) { if (is_array($v)) { $values[$k] = self::filterArray ($v, $filter, $args, $doTrim); } else { $values[$k] = filter_var (self::trim($v, $doTrim), $filter, $args); } } return $values; }
[ "protected", "static", "function", "filterArray", "(", "array", "$", "values", ",", "$", "filter", "=", "null", ",", "$", "args", "=", "array", "(", ")", ",", "$", "doTrim", "=", "true", ")", "{", "if", "(", "!", "$", "values", ")", "{", "return", "$", "values", ";", "}", "if", "(", "!", "$", "filter", ")", "{", "$", "filter", "=", "self", "::", "$", "defaultFilter", ";", "}", "if", "(", "!", "$", "args", ")", "{", "$", "args", "=", "array", "(", "'flags'", "=>", "self", "::", "$", "defaultFlags", ")", ";", "}", "foreach", "(", "$", "values", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "is_array", "(", "$", "v", ")", ")", "{", "$", "values", "[", "$", "k", "]", "=", "self", "::", "filterArray", "(", "$", "v", ",", "$", "filter", ",", "$", "args", ",", "$", "doTrim", ")", ";", "}", "else", "{", "$", "values", "[", "$", "k", "]", "=", "filter_var", "(", "self", "::", "trim", "(", "$", "v", ",", "$", "doTrim", ")", ",", "$", "filter", ",", "$", "args", ")", ";", "}", "}", "return", "$", "values", ";", "}" ]
Filter an array item by item. This function is recursive array safe. @param array $values The array to filter @param string $filter The filter directive to apply to the retrieved input (optional) (default=null) @param array $args The filter processing args to apply (optional) (default=array()) @param bool $doTrim Whether or not to apply trim() to retrieved parameter (optional) (default=true) @return array
[ "Filter", "an", "array", "item", "by", "item", ".", "This", "function", "is", "recursive", "array", "safe", "." ]
train
https://github.com/innobrig/flex-input/blob/81db6cd22820d310d35be9a71d545dafffb21c64/src/Input.php#L332-L355
innobrig/flex-input
src/Input.php
Input.decodeEntites
public static function decodeEntites ($data, $fields) { if (!$data) { return $data; } if (!is_array ($fields)) { $fields = [$fields]; } if (!is_array ($data)) { foreach ($fields as $field) { if (is_object($data) && isset($data->{$field})) { $data->{$field} = html_entity_decode ($data->{$field}); } else { $data[$field] = html_entity_decode ($data[$field]); } } } else { foreach ($data as $k => $v) { foreach ($fields as $field) { if (is_object($data) && isset($data->{$field})) { $data[$k]->{$field} = html_entity_decode ($v->{$field}); } else { $data[$k][$field] = html_entity_decode ($v[$field]); } } } } return $data; }
php
public static function decodeEntites ($data, $fields) { if (!$data) { return $data; } if (!is_array ($fields)) { $fields = [$fields]; } if (!is_array ($data)) { foreach ($fields as $field) { if (is_object($data) && isset($data->{$field})) { $data->{$field} = html_entity_decode ($data->{$field}); } else { $data[$field] = html_entity_decode ($data[$field]); } } } else { foreach ($data as $k => $v) { foreach ($fields as $field) { if (is_object($data) && isset($data->{$field})) { $data[$k]->{$field} = html_entity_decode ($v->{$field}); } else { $data[$k][$field] = html_entity_decode ($v[$field]); } } } } return $data; }
[ "public", "static", "function", "decodeEntites", "(", "$", "data", ",", "$", "fields", ")", "{", "if", "(", "!", "$", "data", ")", "{", "return", "$", "data", ";", "}", "if", "(", "!", "is_array", "(", "$", "fields", ")", ")", "{", "$", "fields", "=", "[", "$", "fields", "]", ";", "}", "if", "(", "!", "is_array", "(", "$", "data", ")", ")", "{", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "if", "(", "is_object", "(", "$", "data", ")", "&&", "isset", "(", "$", "data", "->", "{", "$", "field", "}", ")", ")", "{", "$", "data", "->", "{", "$", "field", "}", "=", "html_entity_decode", "(", "$", "data", "->", "{", "$", "field", "}", ")", ";", "}", "else", "{", "$", "data", "[", "$", "field", "]", "=", "html_entity_decode", "(", "$", "data", "[", "$", "field", "]", ")", ";", "}", "}", "}", "else", "{", "foreach", "(", "$", "data", "as", "$", "k", "=>", "$", "v", ")", "{", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "if", "(", "is_object", "(", "$", "data", ")", "&&", "isset", "(", "$", "data", "->", "{", "$", "field", "}", ")", ")", "{", "$", "data", "[", "$", "k", "]", "->", "{", "$", "field", "}", "=", "html_entity_decode", "(", "$", "v", "->", "{", "$", "field", "}", ")", ";", "}", "else", "{", "$", "data", "[", "$", "k", "]", "[", "$", "field", "]", "=", "html_entity_decode", "(", "$", "v", "[", "$", "field", "]", ")", ";", "}", "}", "}", "}", "return", "$", "data", ";", "}" ]
Decode previously encoded HTML entiries WARNING: Only do this if you know you can trust the received input, this is not safe for user-submitted content! @param mixed $data The field|array|object to decode @param bool $fields The array|object fields to decode @return mixed The data with html decoded entities
[ "Decode", "previously", "encoded", "HTML", "entiries", "WARNING", ":", "Only", "do", "this", "if", "you", "know", "you", "can", "trust", "the", "received", "input", "this", "is", "not", "safe", "for", "user", "-", "submitted", "content!" ]
train
https://github.com/innobrig/flex-input/blob/81db6cd22820d310d35be9a71d545dafffb21c64/src/Input.php#L385-L416
Wonail/wocenter
traits/LoadModelTrait.php
LoadModelTrait.loadModel
protected function loadModel($modelClass, $id, $throwException = true, $config = []) { if (!class_exists($modelClass)) { throw new InvalidConfigException("Model Class `{$modelClass}` does not exists"); } $model = $modelClass::findOne($id); if (!is_object($model)) { if ($throwException) { throw new NotFoundHttpException(Yii::t('wocenter/app', 'Not found.')); } else { return null; } } if (!empty($config)) { Yii::configure($model, $config); } return $model; }
php
protected function loadModel($modelClass, $id, $throwException = true, $config = []) { if (!class_exists($modelClass)) { throw new InvalidConfigException("Model Class `{$modelClass}` does not exists"); } $model = $modelClass::findOne($id); if (!is_object($model)) { if ($throwException) { throw new NotFoundHttpException(Yii::t('wocenter/app', 'Not found.')); } else { return null; } } if (!empty($config)) { Yii::configure($model, $config); } return $model; }
[ "protected", "function", "loadModel", "(", "$", "modelClass", ",", "$", "id", ",", "$", "throwException", "=", "true", ",", "$", "config", "=", "[", "]", ")", "{", "if", "(", "!", "class_exists", "(", "$", "modelClass", ")", ")", "{", "throw", "new", "InvalidConfigException", "(", "\"Model Class `{$modelClass}` does not exists\"", ")", ";", "}", "$", "model", "=", "$", "modelClass", "::", "findOne", "(", "$", "id", ")", ";", "if", "(", "!", "is_object", "(", "$", "model", ")", ")", "{", "if", "(", "$", "throwException", ")", "{", "throw", "new", "NotFoundHttpException", "(", "Yii", "::", "t", "(", "'wocenter/app'", ",", "'Not found.'", ")", ")", ";", "}", "else", "{", "return", "null", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "config", ")", ")", "{", "Yii", "::", "configure", "(", "$", "model", ",", "$", "config", ")", ";", "}", "return", "$", "model", ";", "}" ]
根据模型主键获取相关数据,如果数据不存在,则抛出400异常 @param \yii\db\ActiveRecord|string $modelClass 模型对象 @param integer $id 主键ID @param boolean $throwException 是否允许抛出异常 @param array $config 配置模型属性 e.g. ['scenario' => 'update'] @return null|\yii\db\ActiveRecord @throws InvalidConfigException @throws NotFoundHttpException if the model cannot be found
[ "根据模型主键获取相关数据,如果数据不存在,则抛出400异常" ]
train
https://github.com/Wonail/wocenter/blob/186c15aad008d32fbf5ad75256cf01581dccf9e6/traits/LoadModelTrait.php#L29-L47
puli/twig-extension
src/CacheWarmer/TwigTemplateCacheWarmer.php
TwigTemplateCacheWarmer.warmUp
public function warmUp($cacheDir) { $iterator = new ResourceFilterIterator( new RecursiveResourceIteratorIterator( new ResourceCollectionIterator( $this->repo->get('/')->listChildren(), ResourceCollectionIterator::CURRENT_AS_PATH ), RecursiveResourceIteratorIterator::SELF_FIRST ), $this->suffix, ResourceFilterIterator::FILTER_BY_NAME | ResourceFilterIterator::MATCH_SUFFIX ); foreach ($iterator as $path) { try { $this->twig->loadTemplate($path); } catch (Twig_Error $e) { // Problem during compilation, stop } } }
php
public function warmUp($cacheDir) { $iterator = new ResourceFilterIterator( new RecursiveResourceIteratorIterator( new ResourceCollectionIterator( $this->repo->get('/')->listChildren(), ResourceCollectionIterator::CURRENT_AS_PATH ), RecursiveResourceIteratorIterator::SELF_FIRST ), $this->suffix, ResourceFilterIterator::FILTER_BY_NAME | ResourceFilterIterator::MATCH_SUFFIX ); foreach ($iterator as $path) { try { $this->twig->loadTemplate($path); } catch (Twig_Error $e) { // Problem during compilation, stop } } }
[ "public", "function", "warmUp", "(", "$", "cacheDir", ")", "{", "$", "iterator", "=", "new", "ResourceFilterIterator", "(", "new", "RecursiveResourceIteratorIterator", "(", "new", "ResourceCollectionIterator", "(", "$", "this", "->", "repo", "->", "get", "(", "'/'", ")", "->", "listChildren", "(", ")", ",", "ResourceCollectionIterator", "::", "CURRENT_AS_PATH", ")", ",", "RecursiveResourceIteratorIterator", "::", "SELF_FIRST", ")", ",", "$", "this", "->", "suffix", ",", "ResourceFilterIterator", "::", "FILTER_BY_NAME", "|", "ResourceFilterIterator", "::", "MATCH_SUFFIX", ")", ";", "foreach", "(", "$", "iterator", "as", "$", "path", ")", "{", "try", "{", "$", "this", "->", "twig", "->", "loadTemplate", "(", "$", "path", ")", ";", "}", "catch", "(", "Twig_Error", "$", "e", ")", "{", "// Problem during compilation, stop", "}", "}", "}" ]
Warms up the cache. @param string $cacheDir The cache directory @throws RuntimeException If setEnvironment() wasn't called
[ "Warms", "up", "the", "cache", "." ]
train
https://github.com/puli/twig-extension/blob/b19fce610aa9fda5d86c73045ed5b9d378c47b93/src/CacheWarmer/TwigTemplateCacheWarmer.php#L59-L80
christeredvartsen/sysinfo
src/SysInfo/Linux/Disk.php
Disk.sumField
private function sumField($devices = null, $partitions = null, $field) { $result = 0; if ($devices) { $devices = (array) $devices; } if (is_array($devices)) { $devices = array_flip($devices); } if ($partitions) { $partitions = (array) $partitions; } if (is_array($partitions)) { $partitions = array_flip($partitions); } foreach ($this->devices as $device => $partition) { if ($devices && !isset($devices[$device])) { continue; } foreach ($partition as $p => $info) { if ($partitions && !isset($partitions[$p])) { continue; } $result += $info[$field]; } } return $result; }
php
private function sumField($devices = null, $partitions = null, $field) { $result = 0; if ($devices) { $devices = (array) $devices; } if (is_array($devices)) { $devices = array_flip($devices); } if ($partitions) { $partitions = (array) $partitions; } if (is_array($partitions)) { $partitions = array_flip($partitions); } foreach ($this->devices as $device => $partition) { if ($devices && !isset($devices[$device])) { continue; } foreach ($partition as $p => $info) { if ($partitions && !isset($partitions[$p])) { continue; } $result += $info[$field]; } } return $result; }
[ "private", "function", "sumField", "(", "$", "devices", "=", "null", ",", "$", "partitions", "=", "null", ",", "$", "field", ")", "{", "$", "result", "=", "0", ";", "if", "(", "$", "devices", ")", "{", "$", "devices", "=", "(", "array", ")", "$", "devices", ";", "}", "if", "(", "is_array", "(", "$", "devices", ")", ")", "{", "$", "devices", "=", "array_flip", "(", "$", "devices", ")", ";", "}", "if", "(", "$", "partitions", ")", "{", "$", "partitions", "=", "(", "array", ")", "$", "partitions", ";", "}", "if", "(", "is_array", "(", "$", "partitions", ")", ")", "{", "$", "partitions", "=", "array_flip", "(", "$", "partitions", ")", ";", "}", "foreach", "(", "$", "this", "->", "devices", "as", "$", "device", "=>", "$", "partition", ")", "{", "if", "(", "$", "devices", "&&", "!", "isset", "(", "$", "devices", "[", "$", "device", "]", ")", ")", "{", "continue", ";", "}", "foreach", "(", "$", "partition", "as", "$", "p", "=>", "$", "info", ")", "{", "if", "(", "$", "partitions", "&&", "!", "isset", "(", "$", "partitions", "[", "$", "p", "]", ")", ")", "{", "continue", ";", "}", "$", "result", "+=", "$", "info", "[", "$", "field", "]", ";", "}", "}", "return", "$", "result", ";", "}" ]
Calcuate a sum @param string|string[] $devices The name of the device to fetch, for instance "sda", or an array of device names: array('hda', 'hdb'). @param int|int[] $partitions Which partition(s) to fetch info about. @return int
[ "Calcuate", "a", "sum" ]
train
https://github.com/christeredvartsen/sysinfo/blob/f1a8acb2997a41b52e9da970e5db041acd5b2ea3/src/SysInfo/Linux/Disk.php#L86-L120
huasituo/hstcms
src/Providers/GeneratorServiceProvider.php
GeneratorServiceProvider.register
public function register() { $generators = [ 'command.make.hstcms' => \Huasituo\Hstcms\Console\Generators\MakeInstallCommand::class, 'command.make.hstcms.manage.founder' => \Huasituo\Hstcms\Console\Generators\MakeManageFounderCommand::class, 'command.make.hstcms.api' => \Huasituo\Hstcms\Console\Generators\MakeApiCommand::class, ]; foreach ($generators as $slug => $class) { $this->app->singleton($slug, function ($app) use ($slug, $class) { return $app[$class]; }); $this->commands($slug); } }
php
public function register() { $generators = [ 'command.make.hstcms' => \Huasituo\Hstcms\Console\Generators\MakeInstallCommand::class, 'command.make.hstcms.manage.founder' => \Huasituo\Hstcms\Console\Generators\MakeManageFounderCommand::class, 'command.make.hstcms.api' => \Huasituo\Hstcms\Console\Generators\MakeApiCommand::class, ]; foreach ($generators as $slug => $class) { $this->app->singleton($slug, function ($app) use ($slug, $class) { return $app[$class]; }); $this->commands($slug); } }
[ "public", "function", "register", "(", ")", "{", "$", "generators", "=", "[", "'command.make.hstcms'", "=>", "\\", "Huasituo", "\\", "Hstcms", "\\", "Console", "\\", "Generators", "\\", "MakeInstallCommand", "::", "class", ",", "'command.make.hstcms.manage.founder'", "=>", "\\", "Huasituo", "\\", "Hstcms", "\\", "Console", "\\", "Generators", "\\", "MakeManageFounderCommand", "::", "class", ",", "'command.make.hstcms.api'", "=>", "\\", "Huasituo", "\\", "Hstcms", "\\", "Console", "\\", "Generators", "\\", "MakeApiCommand", "::", "class", ",", "]", ";", "foreach", "(", "$", "generators", "as", "$", "slug", "=>", "$", "class", ")", "{", "$", "this", "->", "app", "->", "singleton", "(", "$", "slug", ",", "function", "(", "$", "app", ")", "use", "(", "$", "slug", ",", "$", "class", ")", "{", "return", "$", "app", "[", "$", "class", "]", ";", "}", ")", ";", "$", "this", "->", "commands", "(", "$", "slug", ")", ";", "}", "}" ]
Register the application services.
[ "Register", "the", "application", "services", "." ]
train
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Providers/GeneratorServiceProvider.php#L24-L38
movoin/one-swoole
src/Context/Payload.php
Payload.withCode
public function withCode(int $code): PayloadInterface { if ($this->code === $code) { return $this; } $clone = clone $this; $clone->code = $code; return $clone; }
php
public function withCode(int $code): PayloadInterface { if ($this->code === $code) { return $this; } $clone = clone $this; $clone->code = $code; return $clone; }
[ "public", "function", "withCode", "(", "int", "$", "code", ")", ":", "PayloadInterface", "{", "if", "(", "$", "this", "->", "code", "===", "$", "code", ")", "{", "return", "$", "this", ";", "}", "$", "clone", "=", "clone", "$", "this", ";", "$", "clone", "->", "code", "=", "$", "code", ";", "return", "$", "clone", ";", "}" ]
根据指定状态码克隆一个新的基本数据 @param int $code @return \One\Context\Contracts\Payload
[ "根据指定状态码克隆一个新的基本数据" ]
train
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Context/Payload.php#L88-L98
movoin/one-swoole
src/Context/Payload.php
Payload.withMessage
public function withMessage(string $message): PayloadInterface { if ($this->message === $message) { return $this; } $clone = clone $this; $clone->message = $message; return $clone; }
php
public function withMessage(string $message): PayloadInterface { if ($this->message === $message) { return $this; } $clone = clone $this; $clone->message = $message; return $clone; }
[ "public", "function", "withMessage", "(", "string", "$", "message", ")", ":", "PayloadInterface", "{", "if", "(", "$", "this", "->", "message", "===", "$", "message", ")", "{", "return", "$", "this", ";", "}", "$", "clone", "=", "clone", "$", "this", ";", "$", "clone", "->", "message", "=", "$", "message", ";", "return", "$", "clone", ";", "}" ]
根据指定的消息数组克隆一个新的基本数据 @param string $message @return \One\Context\Contracts\Payload
[ "根据指定的消息数组克隆一个新的基本数据" ]
train
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Context/Payload.php#L117-L127
movoin/one-swoole
src/Context/Payload.php
Payload.withData
public function withData($data): PayloadInterface { if ($this->data === $data) { return $this; } $clone = clone $this; $clone->data = $data; return $clone; }
php
public function withData($data): PayloadInterface { if ($this->data === $data) { return $this; } $clone = clone $this; $clone->data = $data; return $clone; }
[ "public", "function", "withData", "(", "$", "data", ")", ":", "PayloadInterface", "{", "if", "(", "$", "this", "->", "data", "===", "$", "data", ")", "{", "return", "$", "this", ";", "}", "$", "clone", "=", "clone", "$", "this", ";", "$", "clone", "->", "data", "=", "$", "data", ";", "return", "$", "clone", ";", "}" ]
根据指定的输出数组克隆一个新的基本数据 @param mixed $data @return \One\Context\Contracts\Payload
[ "根据指定的输出数组克隆一个新的基本数据" ]
train
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Context/Payload.php#L146-L156
movoin/one-swoole
src/Context/Payload.php
Payload.withError
public function withError(string $error): PayloadInterface { if ($this->error === $error) { return $this; } $clone = clone $this; $clone->error = $error; return $clone; }
php
public function withError(string $error): PayloadInterface { if ($this->error === $error) { return $this; } $clone = clone $this; $clone->error = $error; return $clone; }
[ "public", "function", "withError", "(", "string", "$", "error", ")", ":", "PayloadInterface", "{", "if", "(", "$", "this", "->", "error", "===", "$", "error", ")", "{", "return", "$", "this", ";", "}", "$", "clone", "=", "clone", "$", "this", ";", "$", "clone", "->", "error", "=", "$", "error", ";", "return", "$", "clone", ";", "}" ]
根据指定的错误数组克隆一个新的基本数据 @param string $error @return \One\Context\Contracts\Payload
[ "根据指定的错误数组克隆一个新的基本数据" ]
train
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Context/Payload.php#L175-L185
movoin/one-swoole
src/Context/Payload.php
Payload.withOptions
public function withOptions(array $options): PayloadInterface { if ($this->options === $options) { return $this; } $clone = clone $this; $clone->options = $options; return $clone; }
php
public function withOptions(array $options): PayloadInterface { if ($this->options === $options) { return $this; } $clone = clone $this; $clone->options = $options; return $clone; }
[ "public", "function", "withOptions", "(", "array", "$", "options", ")", ":", "PayloadInterface", "{", "if", "(", "$", "this", "->", "options", "===", "$", "options", ")", "{", "return", "$", "this", ";", "}", "$", "clone", "=", "clone", "$", "this", ";", "$", "clone", "->", "options", "=", "$", "options", ";", "return", "$", "clone", ";", "}" ]
根据指定的选项数组克隆一个新的基本数据 @param array $options @return \One\Context\Contracts\Payload
[ "根据指定的选项数组克隆一个新的基本数据" ]
train
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Context/Payload.php#L204-L214
movoin/one-swoole
src/Context/Payload.php
Payload.toArray
public function toArray(): array { $payload = [ 'code' => $this->getCode() ]; if (! empty($this->getMessage())) { $payload['message'] = $this->getMessage(); } if (! empty($this->getError())) { $payload['error'] = $this->getError(); } if (! empty($this->getData())) { $payload['data'] = $this->getData(); } if (! empty($this->getOptions())) { $payload += $this->getOptions(); } return $payload; }
php
public function toArray(): array { $payload = [ 'code' => $this->getCode() ]; if (! empty($this->getMessage())) { $payload['message'] = $this->getMessage(); } if (! empty($this->getError())) { $payload['error'] = $this->getError(); } if (! empty($this->getData())) { $payload['data'] = $this->getData(); } if (! empty($this->getOptions())) { $payload += $this->getOptions(); } return $payload; }
[ "public", "function", "toArray", "(", ")", ":", "array", "{", "$", "payload", "=", "[", "'code'", "=>", "$", "this", "->", "getCode", "(", ")", "]", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "getMessage", "(", ")", ")", ")", "{", "$", "payload", "[", "'message'", "]", "=", "$", "this", "->", "getMessage", "(", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "getError", "(", ")", ")", ")", "{", "$", "payload", "[", "'error'", "]", "=", "$", "this", "->", "getError", "(", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "getData", "(", ")", ")", ")", "{", "$", "payload", "[", "'data'", "]", "=", "$", "this", "->", "getData", "(", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "getOptions", "(", ")", ")", ")", "{", "$", "payload", "+=", "$", "this", "->", "getOptions", "(", ")", ";", "}", "return", "$", "payload", ";", "}" ]
获得数组内容 @return array
[ "获得数组内容" ]
train
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/src/Context/Payload.php#L231-L254
shawnsandy/ui-pages
src/Controllers/GithubLoginController.php
GithubLoginController.handleAuth
public function handleAuth(Request $request) { try { $user = Socialite::with('github')->stateless()->user(); } catch (Exception $e) { return redirect('/dash-login'); } $request->session()->put( config('pagekit.session_key', 'pagekit_session'), [ 'github_id' => $user->id, 'github_name' => $user->name, 'github_email' => $user->email ] ); $request->session()->save(); return $user->user['login']; }
php
public function handleAuth(Request $request) { try { $user = Socialite::with('github')->stateless()->user(); } catch (Exception $e) { return redirect('/dash-login'); } $request->session()->put( config('pagekit.session_key', 'pagekit_session'), [ 'github_id' => $user->id, 'github_name' => $user->name, 'github_email' => $user->email ] ); $request->session()->save(); return $user->user['login']; }
[ "public", "function", "handleAuth", "(", "Request", "$", "request", ")", "{", "try", "{", "$", "user", "=", "Socialite", "::", "with", "(", "'github'", ")", "->", "stateless", "(", ")", "->", "user", "(", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "return", "redirect", "(", "'/dash-login'", ")", ";", "}", "$", "request", "->", "session", "(", ")", "->", "put", "(", "config", "(", "'pagekit.session_key'", ",", "'pagekit_session'", ")", ",", "[", "'github_id'", "=>", "$", "user", "->", "id", ",", "'github_name'", "=>", "$", "user", "->", "name", ",", "'github_email'", "=>", "$", "user", "->", "email", "]", ")", ";", "$", "request", "->", "session", "(", ")", "->", "save", "(", ")", ";", "return", "$", "user", "->", "user", "[", "'login'", "]", ";", "}" ]
Handles the request from the provider @param Request $request @return Redirect
[ "Handles", "the", "request", "from", "the", "provider" ]
train
https://github.com/shawnsandy/ui-pages/blob/11584c12fa3e2b9a5c513f4ec9e2eaf78c206ca8/src/Controllers/GithubLoginController.php#L50-L68
shawnsandy/ui-pages
src/Controllers/GithubLoginController.php
GithubLoginController.loginUser
protected function loginUser($user) { $this->session->put( config('pagekit.session_key', 'pagekit_session'), [ 'github_id' => $user->id, 'github_name' => $user->name, 'github_email' => $user->email ] ); $this->session->save(); }
php
protected function loginUser($user) { $this->session->put( config('pagekit.session_key', 'pagekit_session'), [ 'github_id' => $user->id, 'github_name' => $user->name, 'github_email' => $user->email ] ); $this->session->save(); }
[ "protected", "function", "loginUser", "(", "$", "user", ")", "{", "$", "this", "->", "session", "->", "put", "(", "config", "(", "'pagekit.session_key'", ",", "'pagekit_session'", ")", ",", "[", "'github_id'", "=>", "$", "user", "->", "id", ",", "'github_name'", "=>", "$", "user", "->", "name", ",", "'github_email'", "=>", "$", "user", "->", "email", "]", ")", ";", "$", "this", "->", "session", "->", "save", "(", ")", ";", "}" ]
Checks if the user credentials matches the credentials stored in the config @param $user
[ "Checks", "if", "the", "user", "credentials", "matches", "the", "credentials", "stored", "in", "the", "config" ]
train
https://github.com/shawnsandy/ui-pages/blob/11584c12fa3e2b9a5c513f4ec9e2eaf78c206ca8/src/Controllers/GithubLoginController.php#L76-L87
gregorybesson/PlaygroundCore
src/TwitterCard/Config.php
Config.getTags
public function getTags($useDefault = null) { if (is_null($useDefault)) { $useDefault = $this->useDefault; } $tags = array(); foreach ($this->tags as $tag) { if (!array_key_exists($tag->getProperty(), $tags)) { $tags[$tag->getProperty()] = $tag->getValue(); } } if ($useDefault) { foreach ($this->defaultTags as $tag) { if (!array_key_exists($tag->getProperty(), $tags)) { $tags[$tag->getProperty()] = $tag->getValue(); } } } return $tags; }
php
public function getTags($useDefault = null) { if (is_null($useDefault)) { $useDefault = $this->useDefault; } $tags = array(); foreach ($this->tags as $tag) { if (!array_key_exists($tag->getProperty(), $tags)) { $tags[$tag->getProperty()] = $tag->getValue(); } } if ($useDefault) { foreach ($this->defaultTags as $tag) { if (!array_key_exists($tag->getProperty(), $tags)) { $tags[$tag->getProperty()] = $tag->getValue(); } } } return $tags; }
[ "public", "function", "getTags", "(", "$", "useDefault", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "useDefault", ")", ")", "{", "$", "useDefault", "=", "$", "this", "->", "useDefault", ";", "}", "$", "tags", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "tags", "as", "$", "tag", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "tag", "->", "getProperty", "(", ")", ",", "$", "tags", ")", ")", "{", "$", "tags", "[", "$", "tag", "->", "getProperty", "(", ")", "]", "=", "$", "tag", "->", "getValue", "(", ")", ";", "}", "}", "if", "(", "$", "useDefault", ")", "{", "foreach", "(", "$", "this", "->", "defaultTags", "as", "$", "tag", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "tag", "->", "getProperty", "(", ")", ",", "$", "tags", ")", ")", "{", "$", "tags", "[", "$", "tag", "->", "getProperty", "(", ")", "]", "=", "$", "tag", "->", "getValue", "(", ")", ";", "}", "}", "}", "return", "$", "tags", ";", "}" ]
return the tags merged with the defaults @return array
[ "return", "the", "tags", "merged", "with", "the", "defaults" ]
train
https://github.com/gregorybesson/PlaygroundCore/blob/f8dfa4c7660b54354933b3c28c0cf35304a649df/src/TwitterCard/Config.php#L89-L108
WellCommerce/CoreBundle
Helper/Request/RequestHelper.php
RequestHelper.getCurrentRequest
public function getCurrentRequest() { if (null === $this->request) { $this->request = $this->requestStack->getMasterRequest(); } return $this->request; }
php
public function getCurrentRequest() { if (null === $this->request) { $this->request = $this->requestStack->getMasterRequest(); } return $this->request; }
[ "public", "function", "getCurrentRequest", "(", ")", "{", "if", "(", "null", "===", "$", "this", "->", "request", ")", "{", "$", "this", "->", "request", "=", "$", "this", "->", "requestStack", "->", "getMasterRequest", "(", ")", ";", "}", "return", "$", "this", "->", "request", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/WellCommerce/CoreBundle/blob/984fbd544d4b10cf11e54e0f3c304d100deb6842/Helper/Request/RequestHelper.php#L55-L62
WellCommerce/CoreBundle
Helper/Request/RequestHelper.php
RequestHelper.getSessionAttribute
public function getSessionAttribute(string $name, $default = null) { if (null !== $this->getCurrentRequest() && $this->request->hasSession()) { return $this->request->getSession()->get($name, $default); } return $default; }
php
public function getSessionAttribute(string $name, $default = null) { if (null !== $this->getCurrentRequest() && $this->request->hasSession()) { return $this->request->getSession()->get($name, $default); } return $default; }
[ "public", "function", "getSessionAttribute", "(", "string", "$", "name", ",", "$", "default", "=", "null", ")", "{", "if", "(", "null", "!==", "$", "this", "->", "getCurrentRequest", "(", ")", "&&", "$", "this", "->", "request", "->", "hasSession", "(", ")", ")", "{", "return", "$", "this", "->", "request", "->", "getSession", "(", ")", "->", "get", "(", "$", "name", ",", "$", "default", ")", ";", "}", "return", "$", "default", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/WellCommerce/CoreBundle/blob/984fbd544d4b10cf11e54e0f3c304d100deb6842/Helper/Request/RequestHelper.php#L79-L86
WellCommerce/CoreBundle
Helper/Request/RequestHelper.php
RequestHelper.setSessionAttribute
public function setSessionAttribute(string $name, $value) { if (null === $this->getCurrentRequest() || false === $this->request->hasSession()) { throw new \LogicException('Cannot set session attributes without valid session.'); } return $this->request->getSession()->set($name, $value); }
php
public function setSessionAttribute(string $name, $value) { if (null === $this->getCurrentRequest() || false === $this->request->hasSession()) { throw new \LogicException('Cannot set session attributes without valid session.'); } return $this->request->getSession()->set($name, $value); }
[ "public", "function", "setSessionAttribute", "(", "string", "$", "name", ",", "$", "value", ")", "{", "if", "(", "null", "===", "$", "this", "->", "getCurrentRequest", "(", ")", "||", "false", "===", "$", "this", "->", "request", "->", "hasSession", "(", ")", ")", "{", "throw", "new", "\\", "LogicException", "(", "'Cannot set session attributes without valid session.'", ")", ";", "}", "return", "$", "this", "->", "request", "->", "getSession", "(", ")", "->", "set", "(", "$", "name", ",", "$", "value", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/WellCommerce/CoreBundle/blob/984fbd544d4b10cf11e54e0f3c304d100deb6842/Helper/Request/RequestHelper.php#L91-L98
WellCommerce/CoreBundle
Helper/Request/RequestHelper.php
RequestHelper.hasSessionAttribute
public function hasSessionAttribute(string $name): bool { if (null !== $this->getCurrentRequest() && $this->request->hasSession()) { return $this->request->getSession()->has($name); } return false; }
php
public function hasSessionAttribute(string $name): bool { if (null !== $this->getCurrentRequest() && $this->request->hasSession()) { return $this->request->getSession()->has($name); } return false; }
[ "public", "function", "hasSessionAttribute", "(", "string", "$", "name", ")", ":", "bool", "{", "if", "(", "null", "!==", "$", "this", "->", "getCurrentRequest", "(", ")", "&&", "$", "this", "->", "request", "->", "hasSession", "(", ")", ")", "{", "return", "$", "this", "->", "request", "->", "getSession", "(", ")", "->", "has", "(", "$", "name", ")", ";", "}", "return", "false", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/WellCommerce/CoreBundle/blob/984fbd544d4b10cf11e54e0f3c304d100deb6842/Helper/Request/RequestHelper.php#L103-L110
WellCommerce/CoreBundle
Helper/Request/RequestHelper.php
RequestHelper.getSessionId
public function getSessionId(): string { if (null !== $this->getCurrentRequest() && $this->request->hasSession()) { return $this->request->getSession()->getId(); } return ''; }
php
public function getSessionId(): string { if (null !== $this->getCurrentRequest() && $this->request->hasSession()) { return $this->request->getSession()->getId(); } return ''; }
[ "public", "function", "getSessionId", "(", ")", ":", "string", "{", "if", "(", "null", "!==", "$", "this", "->", "getCurrentRequest", "(", ")", "&&", "$", "this", "->", "request", "->", "hasSession", "(", ")", ")", "{", "return", "$", "this", "->", "request", "->", "getSession", "(", ")", "->", "getId", "(", ")", ";", "}", "return", "''", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/WellCommerce/CoreBundle/blob/984fbd544d4b10cf11e54e0f3c304d100deb6842/Helper/Request/RequestHelper.php#L115-L122
WellCommerce/CoreBundle
Helper/Request/RequestHelper.php
RequestHelper.getSessionName
public function getSessionName(): string { if (null !== $this->getCurrentRequest() && $this->request->hasSession()) { return $this->request->getSession()->getName(); } return ''; }
php
public function getSessionName(): string { if (null !== $this->getCurrentRequest() && $this->request->hasSession()) { return $this->request->getSession()->getName(); } return ''; }
[ "public", "function", "getSessionName", "(", ")", ":", "string", "{", "if", "(", "null", "!==", "$", "this", "->", "getCurrentRequest", "(", ")", "&&", "$", "this", "->", "request", "->", "hasSession", "(", ")", ")", "{", "return", "$", "this", "->", "request", "->", "getSession", "(", ")", "->", "getName", "(", ")", ";", "}", "return", "''", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/WellCommerce/CoreBundle/blob/984fbd544d4b10cf11e54e0f3c304d100deb6842/Helper/Request/RequestHelper.php#L127-L134
WellCommerce/CoreBundle
Helper/Request/RequestHelper.php
RequestHelper.hasRequestBagParam
public function hasRequestBagParam(string $name): bool { if ($this->getCurrentRequest() instanceof Request) { return $this->request->request->has($name); } return false; }
php
public function hasRequestBagParam(string $name): bool { if ($this->getCurrentRequest() instanceof Request) { return $this->request->request->has($name); } return false; }
[ "public", "function", "hasRequestBagParam", "(", "string", "$", "name", ")", ":", "bool", "{", "if", "(", "$", "this", "->", "getCurrentRequest", "(", ")", "instanceof", "Request", ")", "{", "return", "$", "this", "->", "request", "->", "request", "->", "has", "(", "$", "name", ")", ";", "}", "return", "false", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/WellCommerce/CoreBundle/blob/984fbd544d4b10cf11e54e0f3c304d100deb6842/Helper/Request/RequestHelper.php#L139-L146
WellCommerce/CoreBundle
Helper/Request/RequestHelper.php
RequestHelper.hasRequestBagParams
public function hasRequestBagParams(array $params = []): bool { foreach ($params as $param) { if (!$this->hasRequestBagParam($param)) { return false; } } return true; }
php
public function hasRequestBagParams(array $params = []): bool { foreach ($params as $param) { if (!$this->hasRequestBagParam($param)) { return false; } } return true; }
[ "public", "function", "hasRequestBagParams", "(", "array", "$", "params", "=", "[", "]", ")", ":", "bool", "{", "foreach", "(", "$", "params", "as", "$", "param", ")", "{", "if", "(", "!", "$", "this", "->", "hasRequestBagParam", "(", "$", "param", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/WellCommerce/CoreBundle/blob/984fbd544d4b10cf11e54e0f3c304d100deb6842/Helper/Request/RequestHelper.php#L151-L160
WellCommerce/CoreBundle
Helper/Request/RequestHelper.php
RequestHelper.getRequestBagParam
public function getRequestBagParam(string $name, $default = null, int $filter = FILTER_SANITIZE_SPECIAL_CHARS) { if (false === $this->hasRequestBagParam($name)) { return $default; } return $this->request->request->filter($name, $default, $filter); }
php
public function getRequestBagParam(string $name, $default = null, int $filter = FILTER_SANITIZE_SPECIAL_CHARS) { if (false === $this->hasRequestBagParam($name)) { return $default; } return $this->request->request->filter($name, $default, $filter); }
[ "public", "function", "getRequestBagParam", "(", "string", "$", "name", ",", "$", "default", "=", "null", ",", "int", "$", "filter", "=", "FILTER_SANITIZE_SPECIAL_CHARS", ")", "{", "if", "(", "false", "===", "$", "this", "->", "hasRequestBagParam", "(", "$", "name", ")", ")", "{", "return", "$", "default", ";", "}", "return", "$", "this", "->", "request", "->", "request", "->", "filter", "(", "$", "name", ",", "$", "default", ",", "$", "filter", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/WellCommerce/CoreBundle/blob/984fbd544d4b10cf11e54e0f3c304d100deb6842/Helper/Request/RequestHelper.php#L165-L172
WellCommerce/CoreBundle
Helper/Request/RequestHelper.php
RequestHelper.getQueryBagParam
public function getQueryBagParam(string $name, $default = null, int $filter = FILTER_SANITIZE_SPECIAL_CHARS) { if (null === $this->getCurrentRequest() || false === $this->request->query->has($name)) { return $default; } return $this->request->query->filter($name, $default, $filter); }
php
public function getQueryBagParam(string $name, $default = null, int $filter = FILTER_SANITIZE_SPECIAL_CHARS) { if (null === $this->getCurrentRequest() || false === $this->request->query->has($name)) { return $default; } return $this->request->query->filter($name, $default, $filter); }
[ "public", "function", "getQueryBagParam", "(", "string", "$", "name", ",", "$", "default", "=", "null", ",", "int", "$", "filter", "=", "FILTER_SANITIZE_SPECIAL_CHARS", ")", "{", "if", "(", "null", "===", "$", "this", "->", "getCurrentRequest", "(", ")", "||", "false", "===", "$", "this", "->", "request", "->", "query", "->", "has", "(", "$", "name", ")", ")", "{", "return", "$", "default", ";", "}", "return", "$", "this", "->", "request", "->", "query", "->", "filter", "(", "$", "name", ",", "$", "default", ",", "$", "filter", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/WellCommerce/CoreBundle/blob/984fbd544d4b10cf11e54e0f3c304d100deb6842/Helper/Request/RequestHelper.php#L177-L184
WellCommerce/CoreBundle
Helper/Request/RequestHelper.php
RequestHelper.hasAttributesBagParam
public function hasAttributesBagParam(string $name): bool { if ($this->getCurrentRequest() instanceof Request) { return $this->request->attributes->has($name); } return false; }
php
public function hasAttributesBagParam(string $name): bool { if ($this->getCurrentRequest() instanceof Request) { return $this->request->attributes->has($name); } return false; }
[ "public", "function", "hasAttributesBagParam", "(", "string", "$", "name", ")", ":", "bool", "{", "if", "(", "$", "this", "->", "getCurrentRequest", "(", ")", "instanceof", "Request", ")", "{", "return", "$", "this", "->", "request", "->", "attributes", "->", "has", "(", "$", "name", ")", ";", "}", "return", "false", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/WellCommerce/CoreBundle/blob/984fbd544d4b10cf11e54e0f3c304d100deb6842/Helper/Request/RequestHelper.php#L189-L196
WellCommerce/CoreBundle
Helper/Request/RequestHelper.php
RequestHelper.hasAttributesBagParams
public function hasAttributesBagParams(array $params = []): bool { foreach ($params as $param) { if (!$this->hasAttributesBagParam($param)) { return false; } } return true; }
php
public function hasAttributesBagParams(array $params = []): bool { foreach ($params as $param) { if (!$this->hasAttributesBagParam($param)) { return false; } } return true; }
[ "public", "function", "hasAttributesBagParams", "(", "array", "$", "params", "=", "[", "]", ")", ":", "bool", "{", "foreach", "(", "$", "params", "as", "$", "param", ")", "{", "if", "(", "!", "$", "this", "->", "hasAttributesBagParam", "(", "$", "param", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/WellCommerce/CoreBundle/blob/984fbd544d4b10cf11e54e0f3c304d100deb6842/Helper/Request/RequestHelper.php#L201-L210
WellCommerce/CoreBundle
Helper/Request/RequestHelper.php
RequestHelper.getAttributesBagParam
public function getAttributesBagParam(string $name, $default = null, int $filter = FILTER_SANITIZE_SPECIAL_CHARS) { if (false === $this->hasAttributesBagParam($name)) { return $default; } return $this->request->attributes->filter($name, $default, $filter); }
php
public function getAttributesBagParam(string $name, $default = null, int $filter = FILTER_SANITIZE_SPECIAL_CHARS) { if (false === $this->hasAttributesBagParam($name)) { return $default; } return $this->request->attributes->filter($name, $default, $filter); }
[ "public", "function", "getAttributesBagParam", "(", "string", "$", "name", ",", "$", "default", "=", "null", ",", "int", "$", "filter", "=", "FILTER_SANITIZE_SPECIAL_CHARS", ")", "{", "if", "(", "false", "===", "$", "this", "->", "hasAttributesBagParam", "(", "$", "name", ")", ")", "{", "return", "$", "default", ";", "}", "return", "$", "this", "->", "request", "->", "attributes", "->", "filter", "(", "$", "name", ",", "$", "default", ",", "$", "filter", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/WellCommerce/CoreBundle/blob/984fbd544d4b10cf11e54e0f3c304d100deb6842/Helper/Request/RequestHelper.php#L215-L222
WellCommerce/CoreBundle
Helper/Request/RequestHelper.php
RequestHelper.getCurrentLocale
public function getCurrentLocale(): string { if (null !== $this->getCurrentRequest()) { return $this->getCurrentRequest()->getLocale(); } return $this->fallbackLocale; }
php
public function getCurrentLocale(): string { if (null !== $this->getCurrentRequest()) { return $this->getCurrentRequest()->getLocale(); } return $this->fallbackLocale; }
[ "public", "function", "getCurrentLocale", "(", ")", ":", "string", "{", "if", "(", "null", "!==", "$", "this", "->", "getCurrentRequest", "(", ")", ")", "{", "return", "$", "this", "->", "getCurrentRequest", "(", ")", "->", "getLocale", "(", ")", ";", "}", "return", "$", "this", "->", "fallbackLocale", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/WellCommerce/CoreBundle/blob/984fbd544d4b10cf11e54e0f3c304d100deb6842/Helper/Request/RequestHelper.php#L227-L234
sokil/php-rest
src/Sokil/Rest/Client/Factory.php
Factory.getConnection
public function getConnection() { if(!$this->_connection) { $this->_connection = new \Guzzle\Http\Client($this->getHost()); } return $this->_connection; }
php
public function getConnection() { if(!$this->_connection) { $this->_connection = new \Guzzle\Http\Client($this->getHost()); } return $this->_connection; }
[ "public", "function", "getConnection", "(", ")", "{", "if", "(", "!", "$", "this", "->", "_connection", ")", "{", "$", "this", "->", "_connection", "=", "new", "\\", "Guzzle", "\\", "Http", "\\", "Client", "(", "$", "this", "->", "getHost", "(", ")", ")", ";", "}", "return", "$", "this", "->", "_connection", ";", "}" ]
Get Guzzle RESTful client @return \Guzzle\Http\Client
[ "Get", "Guzzle", "RESTful", "client" ]
train
https://github.com/sokil/php-rest/blob/5399d4ca38d3595de68598605d3d0d70f7ecfc7b/src/Sokil/Rest/Client/Factory.php#L63-L70
huasituo/hstcms
src/Libraries/Fields/Textarea.php
Textarea.option
public function option($option) { $option['width'] = isset($option['width']) ? $option['width'] : 300; $option['height'] = isset($option['height']) ? $option['height'] : 100; $option['value'] = isset($option['value']) ? $option['value'] : ''; $option['fvalue'] = isset($option['fvalue']) ? $option['fvalue'] : ''; $option['fieldtype'] = isset($option['fieldtype']) ? $option['fieldtype'] : 'TEXT'; $option['fieldlength'] = isset($option['fieldlength']) ? $option['fieldlength'] : ''; return ' <div class="hstui-form-group hstui-form-group-sm"> <label class="hstui-u-sm-2 hstui-form-label">'.hst_lang('hstcms::public.width').'</label> <div class="hstui-u-sm-10 hstui-form-input"> <input type="text" name="setting[option][width]" value="'.$option['width'].'" class="hstui-input hstui-length-5"> <div class="hstui-form-input-tips" id="J_form_tips_name" data-tips="'.hst_lang('hstcms::manage.fields.type.width.tips').'">'.hst_lang('hstcms::manage.fields.type.width.tips').'</div> </div> </div> <div class="hstui-form-group hstui-form-group-sm"> <label class="hstui-u-sm-2 hstui-form-label">'.hst_lang('hstcms::public.height').'</label> <div class="hstui-u-sm-10 hstui-form-input"> <input type="text" name="setting[option][height]" value="'.$option['height'].'" class="hstui-input hstui-length-5"> <div class="hstui-form-input-tips" id="J_form_tips_name" data-tips="'.hst_lang('hstcms::fields.type.height.tips').'">'.hst_lang('hstcms::fields.type.height.tips').'</div> </div> </div> '.$this->get_default_value($option['value']).$this->field_type($option['fieldtype'], $option['fieldlength'], $option['fvalue']); }
php
public function option($option) { $option['width'] = isset($option['width']) ? $option['width'] : 300; $option['height'] = isset($option['height']) ? $option['height'] : 100; $option['value'] = isset($option['value']) ? $option['value'] : ''; $option['fvalue'] = isset($option['fvalue']) ? $option['fvalue'] : ''; $option['fieldtype'] = isset($option['fieldtype']) ? $option['fieldtype'] : 'TEXT'; $option['fieldlength'] = isset($option['fieldlength']) ? $option['fieldlength'] : ''; return ' <div class="hstui-form-group hstui-form-group-sm"> <label class="hstui-u-sm-2 hstui-form-label">'.hst_lang('hstcms::public.width').'</label> <div class="hstui-u-sm-10 hstui-form-input"> <input type="text" name="setting[option][width]" value="'.$option['width'].'" class="hstui-input hstui-length-5"> <div class="hstui-form-input-tips" id="J_form_tips_name" data-tips="'.hst_lang('hstcms::manage.fields.type.width.tips').'">'.hst_lang('hstcms::manage.fields.type.width.tips').'</div> </div> </div> <div class="hstui-form-group hstui-form-group-sm"> <label class="hstui-u-sm-2 hstui-form-label">'.hst_lang('hstcms::public.height').'</label> <div class="hstui-u-sm-10 hstui-form-input"> <input type="text" name="setting[option][height]" value="'.$option['height'].'" class="hstui-input hstui-length-5"> <div class="hstui-form-input-tips" id="J_form_tips_name" data-tips="'.hst_lang('hstcms::fields.type.height.tips').'">'.hst_lang('hstcms::fields.type.height.tips').'</div> </div> </div> '.$this->get_default_value($option['value']).$this->field_type($option['fieldtype'], $option['fieldlength'], $option['fvalue']); }
[ "public", "function", "option", "(", "$", "option", ")", "{", "$", "option", "[", "'width'", "]", "=", "isset", "(", "$", "option", "[", "'width'", "]", ")", "?", "$", "option", "[", "'width'", "]", ":", "300", ";", "$", "option", "[", "'height'", "]", "=", "isset", "(", "$", "option", "[", "'height'", "]", ")", "?", "$", "option", "[", "'height'", "]", ":", "100", ";", "$", "option", "[", "'value'", "]", "=", "isset", "(", "$", "option", "[", "'value'", "]", ")", "?", "$", "option", "[", "'value'", "]", ":", "''", ";", "$", "option", "[", "'fvalue'", "]", "=", "isset", "(", "$", "option", "[", "'fvalue'", "]", ")", "?", "$", "option", "[", "'fvalue'", "]", ":", "''", ";", "$", "option", "[", "'fieldtype'", "]", "=", "isset", "(", "$", "option", "[", "'fieldtype'", "]", ")", "?", "$", "option", "[", "'fieldtype'", "]", ":", "'TEXT'", ";", "$", "option", "[", "'fieldlength'", "]", "=", "isset", "(", "$", "option", "[", "'fieldlength'", "]", ")", "?", "$", "option", "[", "'fieldlength'", "]", ":", "''", ";", "return", "'\n\t\t\t<div class=\"hstui-form-group hstui-form-group-sm\">\n\t <label class=\"hstui-u-sm-2 hstui-form-label\">'", ".", "hst_lang", "(", "'hstcms::public.width'", ")", ".", "'</label>\n\t <div class=\"hstui-u-sm-10 hstui-form-input\">\n\t <input type=\"text\" name=\"setting[option][width]\" value=\"'", ".", "$", "option", "[", "'width'", "]", ".", "'\" class=\"hstui-input hstui-length-5\">\n\t <div class=\"hstui-form-input-tips\" id=\"J_form_tips_name\" data-tips=\"'", ".", "hst_lang", "(", "'hstcms::manage.fields.type.width.tips'", ")", ".", "'\">'", ".", "hst_lang", "(", "'hstcms::manage.fields.type.width.tips'", ")", ".", "'</div>\n\t </div>\n\t </div>\n\t\t\t<div class=\"hstui-form-group hstui-form-group-sm\">\n\t <label class=\"hstui-u-sm-2 hstui-form-label\">'", ".", "hst_lang", "(", "'hstcms::public.height'", ")", ".", "'</label>\n\t <div class=\"hstui-u-sm-10 hstui-form-input\">\n\t <input type=\"text\" name=\"setting[option][height]\" value=\"'", ".", "$", "option", "[", "'height'", "]", ".", "'\" class=\"hstui-input hstui-length-5\">\n\t <div class=\"hstui-form-input-tips\" id=\"J_form_tips_name\" data-tips=\"'", ".", "hst_lang", "(", "'hstcms::fields.type.height.tips'", ")", ".", "'\">'", ".", "hst_lang", "(", "'hstcms::fields.type.height.tips'", ")", ".", "'</div>\n\t </div>\n\t </div>\n '", ".", "$", "this", "->", "get_default_value", "(", "$", "option", "[", "'value'", "]", ")", ".", "$", "this", "->", "field_type", "(", "$", "option", "[", "'fieldtype'", "]", ",", "$", "option", "[", "'fieldlength'", "]", ",", "$", "option", "[", "'fvalue'", "]", ")", ";", "}" ]
字段相关属性参数 @param array $value 值 @return string
[ "字段相关属性参数" ]
train
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/Fields/Textarea.php#L32-L56
prooph/link-app-core
src/Service/SystemConfigProvider.php
SystemConfigProvider.initialize
public function initialize($instance, ServiceLocatorInterface $serviceLocator) { if ($instance instanceof NeedsSystemConfig) { if ($serviceLocator instanceof ControllerManager) { $serviceLocator = $serviceLocator->getServiceLocator(); } $instance->setSystemConfig($serviceLocator->get('prooph.link.system_config')); } }
php
public function initialize($instance, ServiceLocatorInterface $serviceLocator) { if ($instance instanceof NeedsSystemConfig) { if ($serviceLocator instanceof ControllerManager) { $serviceLocator = $serviceLocator->getServiceLocator(); } $instance->setSystemConfig($serviceLocator->get('prooph.link.system_config')); } }
[ "public", "function", "initialize", "(", "$", "instance", ",", "ServiceLocatorInterface", "$", "serviceLocator", ")", "{", "if", "(", "$", "instance", "instanceof", "NeedsSystemConfig", ")", "{", "if", "(", "$", "serviceLocator", "instanceof", "ControllerManager", ")", "{", "$", "serviceLocator", "=", "$", "serviceLocator", "->", "getServiceLocator", "(", ")", ";", "}", "$", "instance", "->", "setSystemConfig", "(", "$", "serviceLocator", "->", "get", "(", "'prooph.link.system_config'", ")", ")", ";", "}", "}" ]
Initialize @param $instance @param ServiceLocatorInterface $serviceLocator @return mixed
[ "Initialize" ]
train
https://github.com/prooph/link-app-core/blob/835a5945dfa7be7b2cebfa6e84e757ecfd783357/src/Service/SystemConfigProvider.php#L35-L43
geo6/php-text-tools
src/Text.php
Text.diff
public static function diff($old, $new): array { if (!is_array($old)) { $old = preg_split("/[\s]+/", $old); } if (!is_array($new)) { $new = preg_split("/[\s]+/", $new); } $oldNormalized = array_map(function (string $str) { return strtoupper(self::removeAccents($str)); }, $old); $newNormalized = array_map(function (string $str) { return strtoupper(self::removeAccents($str)); }, $new); $matrix = []; $maxlen = 0; foreach ($oldNormalized as $oindex => $ovalue) { $nkeys = array_keys($newNormalized, $ovalue); foreach ($nkeys as $nindex) { $matrix[$oindex][$nindex] = (isset($matrix[$oindex - 1][$nindex - 1]) ? $matrix[$oindex - 1][$nindex - 1] + 1 : 1); if ($matrix[$oindex][$nindex] > $maxlen) { $maxlen = $matrix[$oindex][$nindex]; $omax = $oindex + 1 - $maxlen; $nmax = $nindex + 1 - $maxlen; } } } if ($maxlen == 0) { return [ [ 'deleted' => $old, 'inserted' => $new, ], ]; } return array_merge( self::diff(array_slice($old, 0, $omax), array_slice($new, 0, $nmax)), array_slice($new, $nmax, $maxlen), self::diff(array_slice($old, $omax + $maxlen), array_slice($new, $nmax + $maxlen)) ); }
php
public static function diff($old, $new): array { if (!is_array($old)) { $old = preg_split("/[\s]+/", $old); } if (!is_array($new)) { $new = preg_split("/[\s]+/", $new); } $oldNormalized = array_map(function (string $str) { return strtoupper(self::removeAccents($str)); }, $old); $newNormalized = array_map(function (string $str) { return strtoupper(self::removeAccents($str)); }, $new); $matrix = []; $maxlen = 0; foreach ($oldNormalized as $oindex => $ovalue) { $nkeys = array_keys($newNormalized, $ovalue); foreach ($nkeys as $nindex) { $matrix[$oindex][$nindex] = (isset($matrix[$oindex - 1][$nindex - 1]) ? $matrix[$oindex - 1][$nindex - 1] + 1 : 1); if ($matrix[$oindex][$nindex] > $maxlen) { $maxlen = $matrix[$oindex][$nindex]; $omax = $oindex + 1 - $maxlen; $nmax = $nindex + 1 - $maxlen; } } } if ($maxlen == 0) { return [ [ 'deleted' => $old, 'inserted' => $new, ], ]; } return array_merge( self::diff(array_slice($old, 0, $omax), array_slice($new, 0, $nmax)), array_slice($new, $nmax, $maxlen), self::diff(array_slice($old, $omax + $maxlen), array_slice($new, $nmax + $maxlen)) ); }
[ "public", "static", "function", "diff", "(", "$", "old", ",", "$", "new", ")", ":", "array", "{", "if", "(", "!", "is_array", "(", "$", "old", ")", ")", "{", "$", "old", "=", "preg_split", "(", "\"/[\\s]+/\"", ",", "$", "old", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "new", ")", ")", "{", "$", "new", "=", "preg_split", "(", "\"/[\\s]+/\"", ",", "$", "new", ")", ";", "}", "$", "oldNormalized", "=", "array_map", "(", "function", "(", "string", "$", "str", ")", "{", "return", "strtoupper", "(", "self", "::", "removeAccents", "(", "$", "str", ")", ")", ";", "}", ",", "$", "old", ")", ";", "$", "newNormalized", "=", "array_map", "(", "function", "(", "string", "$", "str", ")", "{", "return", "strtoupper", "(", "self", "::", "removeAccents", "(", "$", "str", ")", ")", ";", "}", ",", "$", "new", ")", ";", "$", "matrix", "=", "[", "]", ";", "$", "maxlen", "=", "0", ";", "foreach", "(", "$", "oldNormalized", "as", "$", "oindex", "=>", "$", "ovalue", ")", "{", "$", "nkeys", "=", "array_keys", "(", "$", "newNormalized", ",", "$", "ovalue", ")", ";", "foreach", "(", "$", "nkeys", "as", "$", "nindex", ")", "{", "$", "matrix", "[", "$", "oindex", "]", "[", "$", "nindex", "]", "=", "(", "isset", "(", "$", "matrix", "[", "$", "oindex", "-", "1", "]", "[", "$", "nindex", "-", "1", "]", ")", "?", "$", "matrix", "[", "$", "oindex", "-", "1", "]", "[", "$", "nindex", "-", "1", "]", "+", "1", ":", "1", ")", ";", "if", "(", "$", "matrix", "[", "$", "oindex", "]", "[", "$", "nindex", "]", ">", "$", "maxlen", ")", "{", "$", "maxlen", "=", "$", "matrix", "[", "$", "oindex", "]", "[", "$", "nindex", "]", ";", "$", "omax", "=", "$", "oindex", "+", "1", "-", "$", "maxlen", ";", "$", "nmax", "=", "$", "nindex", "+", "1", "-", "$", "maxlen", ";", "}", "}", "}", "if", "(", "$", "maxlen", "==", "0", ")", "{", "return", "[", "[", "'deleted'", "=>", "$", "old", ",", "'inserted'", "=>", "$", "new", ",", "]", ",", "]", ";", "}", "return", "array_merge", "(", "self", "::", "diff", "(", "array_slice", "(", "$", "old", ",", "0", ",", "$", "omax", ")", ",", "array_slice", "(", "$", "new", ",", "0", ",", "$", "nmax", ")", ")", ",", "array_slice", "(", "$", "new", ",", "$", "nmax", ",", "$", "maxlen", ")", ",", "self", "::", "diff", "(", "array_slice", "(", "$", "old", ",", "$", "omax", "+", "$", "maxlen", ")", ",", "array_slice", "(", "$", "new", ",", "$", "nmax", "+", "$", "maxlen", ")", ")", ")", ";", "}" ]
@author Paul Butler <[email protected]> @author Mike Robinson @author Jonathan Beliën <[email protected]> @see https://github.com/paulgb/simplediff/blob/master/php/simplediff.php @param string|array $old @param string|array $new
[ "@author", "Paul", "Butler", "<github@paulbutler", ".", "org", ">", "@author", "Mike", "Robinson", "@author", "Jonathan", "Beliën", "<jbe@geo6", ".", "be", ">" ]
train
https://github.com/geo6/php-text-tools/blob/f50fd42cfb323ae32dce58d5c1d44398d0102f08/src/Text.php#L27-L73
geo6/php-text-tools
src/Text.php
Text.renderDiff
public static function renderDiff(array $diff): array { $returnOld = ''; $returnNew = ''; foreach ($diff as $k) { if (is_array($k)) { $returnOld .= (!empty($k['deleted']) ? '<del>'.implode(' ', $k['deleted']).'</del> ' : ''); $returnNew .= (!empty($k['inserted']) ? '<ins>'.implode(' ', $k['inserted']).'</ins> ' : ''); } else { $returnOld .= $k.' '; $returnNew .= $k.' '; } } return [ 'old' => $returnOld, 'new' => $returnNew, ]; }
php
public static function renderDiff(array $diff): array { $returnOld = ''; $returnNew = ''; foreach ($diff as $k) { if (is_array($k)) { $returnOld .= (!empty($k['deleted']) ? '<del>'.implode(' ', $k['deleted']).'</del> ' : ''); $returnNew .= (!empty($k['inserted']) ? '<ins>'.implode(' ', $k['inserted']).'</ins> ' : ''); } else { $returnOld .= $k.' '; $returnNew .= $k.' '; } } return [ 'old' => $returnOld, 'new' => $returnNew, ]; }
[ "public", "static", "function", "renderDiff", "(", "array", "$", "diff", ")", ":", "array", "{", "$", "returnOld", "=", "''", ";", "$", "returnNew", "=", "''", ";", "foreach", "(", "$", "diff", "as", "$", "k", ")", "{", "if", "(", "is_array", "(", "$", "k", ")", ")", "{", "$", "returnOld", ".=", "(", "!", "empty", "(", "$", "k", "[", "'deleted'", "]", ")", "?", "'<del>'", ".", "implode", "(", "' '", ",", "$", "k", "[", "'deleted'", "]", ")", ".", "'</del> '", ":", "''", ")", ";", "$", "returnNew", ".=", "(", "!", "empty", "(", "$", "k", "[", "'inserted'", "]", ")", "?", "'<ins>'", ".", "implode", "(", "' '", ",", "$", "k", "[", "'inserted'", "]", ")", ".", "'</ins> '", ":", "''", ")", ";", "}", "else", "{", "$", "returnOld", ".=", "$", "k", ".", "' '", ";", "$", "returnNew", ".=", "$", "k", ".", "' '", ";", "}", "}", "return", "[", "'old'", "=>", "$", "returnOld", ",", "'new'", "=>", "$", "returnNew", ",", "]", ";", "}" ]
@author Paul Butler <[email protected]> @author Mike Robinson @author Jonathan Beliën <[email protected]> @see https://github.com/paulgb/simplediff/blob/master/php/simplediff.php
[ "@author", "Paul", "Butler", "<github@paulbutler", ".", "org", ">", "@author", "Mike", "Robinson", "@author", "Jonathan", "Beliën", "<jbe@geo6", ".", "be", ">" ]
train
https://github.com/geo6/php-text-tools/blob/f50fd42cfb323ae32dce58d5c1d44398d0102f08/src/Text.php#L82-L101
puli/discovery
src/InMemoryDiscovery.php
InMemoryDiscovery.addBindingType
public function addBindingType(BindingType $type) { if (isset($this->types[$type->getName()])) { throw DuplicateTypeException::forTypeName($type->getName()); } $this->types[$type->getName()] = $type; }
php
public function addBindingType(BindingType $type) { if (isset($this->types[$type->getName()])) { throw DuplicateTypeException::forTypeName($type->getName()); } $this->types[$type->getName()] = $type; }
[ "public", "function", "addBindingType", "(", "BindingType", "$", "type", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "types", "[", "$", "type", "->", "getName", "(", ")", "]", ")", ")", "{", "throw", "DuplicateTypeException", "::", "forTypeName", "(", "$", "type", "->", "getName", "(", ")", ")", ";", "}", "$", "this", "->", "types", "[", "$", "type", "->", "getName", "(", ")", "]", "=", "$", "type", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/puli/discovery/blob/975f5e099563f1096bfabc17fbe4d1816408ad98/src/InMemoryDiscovery.php#L44-L51
puli/discovery
src/InMemoryDiscovery.php
InMemoryDiscovery.removeBindingType
public function removeBindingType($typeName) { Assert::stringNotEmpty($typeName, 'The type class must be a non-empty string. Got: %s'); unset($this->types[$typeName]); $this->removeBindingsWithTypeName($typeName); }
php
public function removeBindingType($typeName) { Assert::stringNotEmpty($typeName, 'The type class must be a non-empty string. Got: %s'); unset($this->types[$typeName]); $this->removeBindingsWithTypeName($typeName); }
[ "public", "function", "removeBindingType", "(", "$", "typeName", ")", "{", "Assert", "::", "stringNotEmpty", "(", "$", "typeName", ",", "'The type class must be a non-empty string. Got: %s'", ")", ";", "unset", "(", "$", "this", "->", "types", "[", "$", "typeName", "]", ")", ";", "$", "this", "->", "removeBindingsWithTypeName", "(", "$", "typeName", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/puli/discovery/blob/975f5e099563f1096bfabc17fbe4d1816408ad98/src/InMemoryDiscovery.php#L56-L63
puli/discovery
src/InMemoryDiscovery.php
InMemoryDiscovery.getBindingType
public function getBindingType($typeName) { Assert::stringNotEmpty($typeName, 'The type class must be a non-empty string. Got: %s'); if (!isset($this->types[$typeName])) { throw NoSuchTypeException::forTypeName($typeName); } return $this->types[$typeName]; }
php
public function getBindingType($typeName) { Assert::stringNotEmpty($typeName, 'The type class must be a non-empty string. Got: %s'); if (!isset($this->types[$typeName])) { throw NoSuchTypeException::forTypeName($typeName); } return $this->types[$typeName]; }
[ "public", "function", "getBindingType", "(", "$", "typeName", ")", "{", "Assert", "::", "stringNotEmpty", "(", "$", "typeName", ",", "'The type class must be a non-empty string. Got: %s'", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "types", "[", "$", "typeName", "]", ")", ")", "{", "throw", "NoSuchTypeException", "::", "forTypeName", "(", "$", "typeName", ")", ";", "}", "return", "$", "this", "->", "types", "[", "$", "typeName", "]", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/puli/discovery/blob/975f5e099563f1096bfabc17fbe4d1816408ad98/src/InMemoryDiscovery.php#L87-L96
puli/discovery
src/InMemoryDiscovery.php
InMemoryDiscovery.addBinding
public function addBinding(Binding $binding) { $typeName = $binding->getTypeName(); $this->initializeBinding($binding); $this->bindingsByTypeName[$typeName][] = $binding; }
php
public function addBinding(Binding $binding) { $typeName = $binding->getTypeName(); $this->initializeBinding($binding); $this->bindingsByTypeName[$typeName][] = $binding; }
[ "public", "function", "addBinding", "(", "Binding", "$", "binding", ")", "{", "$", "typeName", "=", "$", "binding", "->", "getTypeName", "(", ")", ";", "$", "this", "->", "initializeBinding", "(", "$", "binding", ")", ";", "$", "this", "->", "bindingsByTypeName", "[", "$", "typeName", "]", "[", "]", "=", "$", "binding", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/puli/discovery/blob/975f5e099563f1096bfabc17fbe4d1816408ad98/src/InMemoryDiscovery.php#L117-L124
puli/discovery
src/InMemoryDiscovery.php
InMemoryDiscovery.findBindings
public function findBindings($typeName, Expression $expr = null) { Assert::stringNotEmpty($typeName, 'The type class must be a non-empty string. Got: %s'); if (!isset($this->bindingsByTypeName[$typeName])) { return array(); } $bindings = $this->bindingsByTypeName[$typeName]; if (null !== $expr) { $bindings = Expr::filter($bindings, $expr); } return array_values($bindings); }
php
public function findBindings($typeName, Expression $expr = null) { Assert::stringNotEmpty($typeName, 'The type class must be a non-empty string. Got: %s'); if (!isset($this->bindingsByTypeName[$typeName])) { return array(); } $bindings = $this->bindingsByTypeName[$typeName]; if (null !== $expr) { $bindings = Expr::filter($bindings, $expr); } return array_values($bindings); }
[ "public", "function", "findBindings", "(", "$", "typeName", ",", "Expression", "$", "expr", "=", "null", ")", "{", "Assert", "::", "stringNotEmpty", "(", "$", "typeName", ",", "'The type class must be a non-empty string. Got: %s'", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "bindingsByTypeName", "[", "$", "typeName", "]", ")", ")", "{", "return", "array", "(", ")", ";", "}", "$", "bindings", "=", "$", "this", "->", "bindingsByTypeName", "[", "$", "typeName", "]", ";", "if", "(", "null", "!==", "$", "expr", ")", "{", "$", "bindings", "=", "Expr", "::", "filter", "(", "$", "bindings", ",", "$", "expr", ")", ";", "}", "return", "array_values", "(", "$", "bindings", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/puli/discovery/blob/975f5e099563f1096bfabc17fbe4d1816408ad98/src/InMemoryDiscovery.php#L129-L144
puli/discovery
src/InMemoryDiscovery.php
InMemoryDiscovery.getBindings
public function getBindings() { $bindings = array(); foreach ($this->bindingsByTypeName as $bindingsOfType) { foreach ($bindingsOfType as $binding) { $bindings[] = $binding; } } return $bindings; }
php
public function getBindings() { $bindings = array(); foreach ($this->bindingsByTypeName as $bindingsOfType) { foreach ($bindingsOfType as $binding) { $bindings[] = $binding; } } return $bindings; }
[ "public", "function", "getBindings", "(", ")", "{", "$", "bindings", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "bindingsByTypeName", "as", "$", "bindingsOfType", ")", "{", "foreach", "(", "$", "bindingsOfType", "as", "$", "binding", ")", "{", "$", "bindings", "[", "]", "=", "$", "binding", ";", "}", "}", "return", "$", "bindings", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/puli/discovery/blob/975f5e099563f1096bfabc17fbe4d1816408ad98/src/InMemoryDiscovery.php#L149-L160
puli/discovery
src/InMemoryDiscovery.php
InMemoryDiscovery.removeBindingsThatMatch
protected function removeBindingsThatMatch(Expression $expr) { foreach ($this->bindingsByTypeName as $typeName => $bindings) { foreach ($bindings as $key => $binding) { if ($expr->evaluate($binding)) { unset($this->bindingsByTypeName[$typeName][$key]); } } if (0 === count($this->bindingsByTypeName[$typeName])) { unset($this->bindingsByTypeName[$typeName]); } } }
php
protected function removeBindingsThatMatch(Expression $expr) { foreach ($this->bindingsByTypeName as $typeName => $bindings) { foreach ($bindings as $key => $binding) { if ($expr->evaluate($binding)) { unset($this->bindingsByTypeName[$typeName][$key]); } } if (0 === count($this->bindingsByTypeName[$typeName])) { unset($this->bindingsByTypeName[$typeName]); } } }
[ "protected", "function", "removeBindingsThatMatch", "(", "Expression", "$", "expr", ")", "{", "foreach", "(", "$", "this", "->", "bindingsByTypeName", "as", "$", "typeName", "=>", "$", "bindings", ")", "{", "foreach", "(", "$", "bindings", "as", "$", "key", "=>", "$", "binding", ")", "{", "if", "(", "$", "expr", "->", "evaluate", "(", "$", "binding", ")", ")", "{", "unset", "(", "$", "this", "->", "bindingsByTypeName", "[", "$", "typeName", "]", "[", "$", "key", "]", ")", ";", "}", "}", "if", "(", "0", "===", "count", "(", "$", "this", "->", "bindingsByTypeName", "[", "$", "typeName", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "bindingsByTypeName", "[", "$", "typeName", "]", ")", ";", "}", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/puli/discovery/blob/975f5e099563f1096bfabc17fbe4d1816408ad98/src/InMemoryDiscovery.php#L173-L186
puli/discovery
src/InMemoryDiscovery.php
InMemoryDiscovery.removeBindingsWithTypeNameThatMatch
protected function removeBindingsWithTypeNameThatMatch($typeName, Expression $expr) { if (!isset($this->bindingsByTypeName[$typeName])) { return; } foreach ($this->bindingsByTypeName[$typeName] as $key => $binding) { if ($expr->evaluate($binding)) { unset($this->bindingsByTypeName[$typeName][$key]); } } if (0 === count($this->bindingsByTypeName[$typeName])) { unset($this->bindingsByTypeName[$typeName]); } }
php
protected function removeBindingsWithTypeNameThatMatch($typeName, Expression $expr) { if (!isset($this->bindingsByTypeName[$typeName])) { return; } foreach ($this->bindingsByTypeName[$typeName] as $key => $binding) { if ($expr->evaluate($binding)) { unset($this->bindingsByTypeName[$typeName][$key]); } } if (0 === count($this->bindingsByTypeName[$typeName])) { unset($this->bindingsByTypeName[$typeName]); } }
[ "protected", "function", "removeBindingsWithTypeNameThatMatch", "(", "$", "typeName", ",", "Expression", "$", "expr", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "bindingsByTypeName", "[", "$", "typeName", "]", ")", ")", "{", "return", ";", "}", "foreach", "(", "$", "this", "->", "bindingsByTypeName", "[", "$", "typeName", "]", "as", "$", "key", "=>", "$", "binding", ")", "{", "if", "(", "$", "expr", "->", "evaluate", "(", "$", "binding", ")", ")", "{", "unset", "(", "$", "this", "->", "bindingsByTypeName", "[", "$", "typeName", "]", "[", "$", "key", "]", ")", ";", "}", "}", "if", "(", "0", "===", "count", "(", "$", "this", "->", "bindingsByTypeName", "[", "$", "typeName", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "bindingsByTypeName", "[", "$", "typeName", "]", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/puli/discovery/blob/975f5e099563f1096bfabc17fbe4d1816408ad98/src/InMemoryDiscovery.php#L203-L218
puli/discovery
src/InMemoryDiscovery.php
InMemoryDiscovery.hasBindingsThatMatch
protected function hasBindingsThatMatch(Expression $expr) { foreach ($this->bindingsByTypeName as $typeName => $bindings) { foreach ($bindings as $key => $binding) { if ($expr->evaluate($binding)) { return true; } } } return false; }
php
protected function hasBindingsThatMatch(Expression $expr) { foreach ($this->bindingsByTypeName as $typeName => $bindings) { foreach ($bindings as $key => $binding) { if ($expr->evaluate($binding)) { return true; } } } return false; }
[ "protected", "function", "hasBindingsThatMatch", "(", "Expression", "$", "expr", ")", "{", "foreach", "(", "$", "this", "->", "bindingsByTypeName", "as", "$", "typeName", "=>", "$", "bindings", ")", "{", "foreach", "(", "$", "bindings", "as", "$", "key", "=>", "$", "binding", ")", "{", "if", "(", "$", "expr", "->", "evaluate", "(", "$", "binding", ")", ")", "{", "return", "true", ";", "}", "}", "}", "return", "false", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/puli/discovery/blob/975f5e099563f1096bfabc17fbe4d1816408ad98/src/InMemoryDiscovery.php#L231-L242
puli/discovery
src/InMemoryDiscovery.php
InMemoryDiscovery.hasBindingsWithTypeNameThatMatch
protected function hasBindingsWithTypeNameThatMatch($typeName, Expression $expr) { if (!isset($this->bindingsByTypeName[$typeName])) { return false; } foreach ($this->bindingsByTypeName[$typeName] as $binding) { if ($expr->evaluate($binding)) { return true; } } return false; }
php
protected function hasBindingsWithTypeNameThatMatch($typeName, Expression $expr) { if (!isset($this->bindingsByTypeName[$typeName])) { return false; } foreach ($this->bindingsByTypeName[$typeName] as $binding) { if ($expr->evaluate($binding)) { return true; } } return false; }
[ "protected", "function", "hasBindingsWithTypeNameThatMatch", "(", "$", "typeName", ",", "Expression", "$", "expr", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "bindingsByTypeName", "[", "$", "typeName", "]", ")", ")", "{", "return", "false", ";", "}", "foreach", "(", "$", "this", "->", "bindingsByTypeName", "[", "$", "typeName", "]", "as", "$", "binding", ")", "{", "if", "(", "$", "expr", "->", "evaluate", "(", "$", "binding", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/puli/discovery/blob/975f5e099563f1096bfabc17fbe4d1816408ad98/src/InMemoryDiscovery.php#L255-L268
goblindegook/Syllables
src/Template/Loader/Taxonomy.php
Taxonomy._prepare_filter
protected function _prepare_filter() { $term = \get_queried_object(); if ( ! empty( $term->slug ) && ! empty( $term->taxonomy ) ) { $this->term = $term->slug; $this->taxonomy = $term->taxonomy; } }
php
protected function _prepare_filter() { $term = \get_queried_object(); if ( ! empty( $term->slug ) && ! empty( $term->taxonomy ) ) { $this->term = $term->slug; $this->taxonomy = $term->taxonomy; } }
[ "protected", "function", "_prepare_filter", "(", ")", "{", "$", "term", "=", "\\", "get_queried_object", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "term", "->", "slug", ")", "&&", "!", "empty", "(", "$", "term", "->", "taxonomy", ")", ")", "{", "$", "this", "->", "term", "=", "$", "term", "->", "slug", ";", "$", "this", "->", "taxonomy", "=", "$", "term", "->", "taxonomy", ";", "}", "}" ]
Prepares the object when the filter is applied. @uses \get_queried_object() @codeCoverageIgnore
[ "Prepares", "the", "object", "when", "the", "filter", "is", "applied", "." ]
train
https://github.com/goblindegook/Syllables/blob/1a98cd15e37595a85b242242f88fee38c4e36acc/src/Template/Loader/Taxonomy.php#L53-L60
goblindegook/Syllables
src/Template/Loader/Taxonomy.php
Taxonomy._should_load_template
protected function _should_load_template() { return ( \is_tax() || \is_category() || \is_tag() ) && ! empty( $this->term ) && in_array( $this->taxonomy, $this->taxonomies ); }
php
protected function _should_load_template() { return ( \is_tax() || \is_category() || \is_tag() ) && ! empty( $this->term ) && in_array( $this->taxonomy, $this->taxonomies ); }
[ "protected", "function", "_should_load_template", "(", ")", "{", "return", "(", "\\", "is_tax", "(", ")", "||", "\\", "is_category", "(", ")", "||", "\\", "is_tag", "(", ")", ")", "&&", "!", "empty", "(", "$", "this", "->", "term", ")", "&&", "in_array", "(", "$", "this", "->", "taxonomy", ",", "$", "this", "->", "taxonomies", ")", ";", "}" ]
Determines whether a custom template for a taxonomy term should be loaded. @return boolean Whether a custom template should be loaded. @uses \is_category() @uses \is_tag() @uses \is_tax() @codeCoverageIgnore
[ "Determines", "whether", "a", "custom", "template", "for", "a", "taxonomy", "term", "should", "be", "loaded", "." ]
train
https://github.com/goblindegook/Syllables/blob/1a98cd15e37595a85b242242f88fee38c4e36acc/src/Template/Loader/Taxonomy.php#L73-L77
movoin/one-swoole
example/app/Actions/MiddlewareAcmeAction.php
MiddlewareAcmeAction.run
protected function run(Request $request) { $payload = new Payload; if ($request->get('acme') === 1) { $payload = $payload->withMessage('Acme Interceptor is work'); } return $payload; }
php
protected function run(Request $request) { $payload = new Payload; if ($request->get('acme') === 1) { $payload = $payload->withMessage('Acme Interceptor is work'); } return $payload; }
[ "protected", "function", "run", "(", "Request", "$", "request", ")", "{", "$", "payload", "=", "new", "Payload", ";", "if", "(", "$", "request", "->", "get", "(", "'acme'", ")", "===", "1", ")", "{", "$", "payload", "=", "$", "payload", "->", "withMessage", "(", "'Acme Interceptor is work'", ")", ";", "}", "return", "$", "payload", ";", "}" ]
响应请求 @param \One\Protocol\Contracts\Request $request @return \One\Context\Contracts\Payload
[ "响应请求" ]
train
https://github.com/movoin/one-swoole/blob/b9b175963ead91416cc50902a04e05ff3ef571de/example/app/Actions/MiddlewareAcmeAction.php#L34-L43
activecollab/databasestructure
src/Builder/BaseTypeClassBuilder.php
BaseTypeClassBuilder.buildFields
private function buildFields(array $fields, $indent, array &$result) { $stringified_field_names = []; $fields_with_default_value = []; foreach ($fields as $field) { if ($field instanceof ScalarField && $field->getShouldBeAddedToModel()) { $stringified_field_names[] = var_export($field->getName(), true); if ($field->getName() != 'id' && $field->getDefaultValue() !== null) { $fields_with_default_value[$field->getName()] = $field->getDefaultValue(); } } } $result[] = ''; $result[] = $indent . '/**'; $result[] = $indent . ' * Table fields that are managed by this entity.'; $result[] = $indent . ' *'; $result[] = $indent . ' * @var array'; $result[] = $indent . ' */'; $result[] = $indent . 'protected $fields = [' . implode(', ', $stringified_field_names) . '];'; if (count($fields_with_default_value)) { $result[] = ''; $result[] = $indent . '/**'; $result[] = $indent . ' * List of default field values.'; $result[] = $indent . ' *'; $result[] = $indent . ' * @var array'; $result[] = $indent . ' */'; $result[] = $indent . 'protected $default_field_values = ['; foreach ($fields_with_default_value as $field_name => $default_value) { $result[] = $indent . ' ' . var_export($field_name, true) . ' => ' . var_export($default_value, true) . ','; } $result[] = $indent . '];'; } }
php
private function buildFields(array $fields, $indent, array &$result) { $stringified_field_names = []; $fields_with_default_value = []; foreach ($fields as $field) { if ($field instanceof ScalarField && $field->getShouldBeAddedToModel()) { $stringified_field_names[] = var_export($field->getName(), true); if ($field->getName() != 'id' && $field->getDefaultValue() !== null) { $fields_with_default_value[$field->getName()] = $field->getDefaultValue(); } } } $result[] = ''; $result[] = $indent . '/**'; $result[] = $indent . ' * Table fields that are managed by this entity.'; $result[] = $indent . ' *'; $result[] = $indent . ' * @var array'; $result[] = $indent . ' */'; $result[] = $indent . 'protected $fields = [' . implode(', ', $stringified_field_names) . '];'; if (count($fields_with_default_value)) { $result[] = ''; $result[] = $indent . '/**'; $result[] = $indent . ' * List of default field values.'; $result[] = $indent . ' *'; $result[] = $indent . ' * @var array'; $result[] = $indent . ' */'; $result[] = $indent . 'protected $default_field_values = ['; foreach ($fields_with_default_value as $field_name => $default_value) { $result[] = $indent . ' ' . var_export($field_name, true) . ' => ' . var_export($default_value, true) . ','; } $result[] = $indent . '];'; } }
[ "private", "function", "buildFields", "(", "array", "$", "fields", ",", "$", "indent", ",", "array", "&", "$", "result", ")", "{", "$", "stringified_field_names", "=", "[", "]", ";", "$", "fields_with_default_value", "=", "[", "]", ";", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "if", "(", "$", "field", "instanceof", "ScalarField", "&&", "$", "field", "->", "getShouldBeAddedToModel", "(", ")", ")", "{", "$", "stringified_field_names", "[", "]", "=", "var_export", "(", "$", "field", "->", "getName", "(", ")", ",", "true", ")", ";", "if", "(", "$", "field", "->", "getName", "(", ")", "!=", "'id'", "&&", "$", "field", "->", "getDefaultValue", "(", ")", "!==", "null", ")", "{", "$", "fields_with_default_value", "[", "$", "field", "->", "getName", "(", ")", "]", "=", "$", "field", "->", "getDefaultValue", "(", ")", ";", "}", "}", "}", "$", "result", "[", "]", "=", "''", ";", "$", "result", "[", "]", "=", "$", "indent", ".", "'/**'", ";", "$", "result", "[", "]", "=", "$", "indent", ".", "' * Table fields that are managed by this entity.'", ";", "$", "result", "[", "]", "=", "$", "indent", ".", "' *'", ";", "$", "result", "[", "]", "=", "$", "indent", ".", "' * @var array'", ";", "$", "result", "[", "]", "=", "$", "indent", ".", "' */'", ";", "$", "result", "[", "]", "=", "$", "indent", ".", "'protected $fields = ['", ".", "implode", "(", "', '", ",", "$", "stringified_field_names", ")", ".", "'];'", ";", "if", "(", "count", "(", "$", "fields_with_default_value", ")", ")", "{", "$", "result", "[", "]", "=", "''", ";", "$", "result", "[", "]", "=", "$", "indent", ".", "'/**'", ";", "$", "result", "[", "]", "=", "$", "indent", ".", "' * List of default field values.'", ";", "$", "result", "[", "]", "=", "$", "indent", ".", "' *'", ";", "$", "result", "[", "]", "=", "$", "indent", ".", "' * @var array'", ";", "$", "result", "[", "]", "=", "$", "indent", ".", "' */'", ";", "$", "result", "[", "]", "=", "$", "indent", ".", "'protected $default_field_values = ['", ";", "foreach", "(", "$", "fields_with_default_value", "as", "$", "field_name", "=>", "$", "default_value", ")", "{", "$", "result", "[", "]", "=", "$", "indent", ".", "' '", ".", "var_export", "(", "$", "field_name", ",", "true", ")", ".", "' => '", ".", "var_export", "(", "$", "default_value", ",", "true", ")", ".", "','", ";", "}", "$", "result", "[", "]", "=", "$", "indent", ".", "'];'", ";", "}", "}" ]
Build field definitions. @param FieldInterface[] $fields @param string $indent @param array $result
[ "Build", "field", "definitions", "." ]
train
https://github.com/activecollab/databasestructure/blob/4b2353c4422186bcfce63b3212da3e70e63eb5df/src/Builder/BaseTypeClassBuilder.php#L273-L311
activecollab/databasestructure
src/Builder/BaseTypeClassBuilder.php
BaseTypeClassBuilder.buildGeneratedFields
public function buildGeneratedFields(array $generated_field_names, $indent, array &$result) { $result[] = ''; $result[] = $indent . '/**'; $result[] = $indent . ' * Generated fields that are loaded, but not managed by the entity..'; $result[] = $indent . ' *'; $result[] = $indent . ' * @var array'; $result[] = $indent . ' */'; $result[] = $indent . 'protected $generated_fields = [' . implode(', ', array_map(function ($field_name) { return var_export($field_name, true); }, $generated_field_names)) . '];'; }
php
public function buildGeneratedFields(array $generated_field_names, $indent, array &$result) { $result[] = ''; $result[] = $indent . '/**'; $result[] = $indent . ' * Generated fields that are loaded, but not managed by the entity..'; $result[] = $indent . ' *'; $result[] = $indent . ' * @var array'; $result[] = $indent . ' */'; $result[] = $indent . 'protected $generated_fields = [' . implode(', ', array_map(function ($field_name) { return var_export($field_name, true); }, $generated_field_names)) . '];'; }
[ "public", "function", "buildGeneratedFields", "(", "array", "$", "generated_field_names", ",", "$", "indent", ",", "array", "&", "$", "result", ")", "{", "$", "result", "[", "]", "=", "''", ";", "$", "result", "[", "]", "=", "$", "indent", ".", "'/**'", ";", "$", "result", "[", "]", "=", "$", "indent", ".", "' * Generated fields that are loaded, but not managed by the entity..'", ";", "$", "result", "[", "]", "=", "$", "indent", ".", "' *'", ";", "$", "result", "[", "]", "=", "$", "indent", ".", "' * @var array'", ";", "$", "result", "[", "]", "=", "$", "indent", ".", "' */'", ";", "$", "result", "[", "]", "=", "$", "indent", ".", "'protected $generated_fields = ['", ".", "implode", "(", "', '", ",", "array_map", "(", "function", "(", "$", "field_name", ")", "{", "return", "var_export", "(", "$", "field_name", ",", "true", ")", ";", "}", ",", "$", "generated_field_names", ")", ")", ".", "'];'", ";", "}" ]
Build a list of generated fields. @param string[] $generated_field_names @param string $indent @param array $result
[ "Build", "a", "list", "of", "generated", "fields", "." ]
train
https://github.com/activecollab/databasestructure/blob/4b2353c4422186bcfce63b3212da3e70e63eb5df/src/Builder/BaseTypeClassBuilder.php#L320-L331
activecollab/databasestructure
src/Builder/BaseTypeClassBuilder.php
BaseTypeClassBuilder.buildGeneratedFieldGetter
private function buildGeneratedFieldGetter($field_name, $caster, $indent, array &$result) { $short_getter = null; switch ($caster) { case ValueCasterInterface::CAST_INT: $return_type = 'int'; break; case ValueCasterInterface::CAST_FLOAT: $return_type = 'float'; break; case ValueCasterInterface::CAST_BOOL: $return_type = 'bool'; break; case ValueCasterInterface::CAST_DATE: $return_type = '\\' . DateValueInterface::class; break; case ValueCasterInterface::CAST_DATETIME: $return_type = '\\' . DateTimeValueInterface::class; break; case ValueCasterInterface::CAST_JSON: $return_type = 'mixed'; break; default: $return_type = 'string'; } if ($this->useShortGetterName($field_name)) { $short_getter = $this->getShortGetterName($field_name); $lines[] = ''; $lines[] = '/**'; $lines[] = ' * Return value of ' . $field_name . ' field.'; $lines[] = ' *'; $lines[] = ' * @return ' . $return_type; $lines[] = ' */'; $lines[] = 'public function ' . $short_getter . '()'; $lines[] = '{'; $lines[] = ' return $this->getFieldValue(' . var_export($field_name, true) . ');'; $lines[] = '}'; } $lines[] = ''; $lines[] = '/**'; $lines[] = ' * Return value of ' . $field_name . ' field.'; $lines[] = ' *'; $lines[] = ' * @return ' . $return_type; if ($short_getter && $this->getStructure()->getConfig('deprecate_long_bool_field_getter')) { $lines[] = " * @deprecated use $short_getter()"; } $lines[] = ' */'; $lines[] = 'public function ' . $this->getGetterName($field_name) . '()'; $lines[] = '{'; $lines[] = ' return $this->getFieldValue(' . var_export($field_name, true) . ');'; $lines[] = '}'; $lines[] = ''; foreach ($lines as $line) { $result[] = $line ? $indent . $line : ''; } }
php
private function buildGeneratedFieldGetter($field_name, $caster, $indent, array &$result) { $short_getter = null; switch ($caster) { case ValueCasterInterface::CAST_INT: $return_type = 'int'; break; case ValueCasterInterface::CAST_FLOAT: $return_type = 'float'; break; case ValueCasterInterface::CAST_BOOL: $return_type = 'bool'; break; case ValueCasterInterface::CAST_DATE: $return_type = '\\' . DateValueInterface::class; break; case ValueCasterInterface::CAST_DATETIME: $return_type = '\\' . DateTimeValueInterface::class; break; case ValueCasterInterface::CAST_JSON: $return_type = 'mixed'; break; default: $return_type = 'string'; } if ($this->useShortGetterName($field_name)) { $short_getter = $this->getShortGetterName($field_name); $lines[] = ''; $lines[] = '/**'; $lines[] = ' * Return value of ' . $field_name . ' field.'; $lines[] = ' *'; $lines[] = ' * @return ' . $return_type; $lines[] = ' */'; $lines[] = 'public function ' . $short_getter . '()'; $lines[] = '{'; $lines[] = ' return $this->getFieldValue(' . var_export($field_name, true) . ');'; $lines[] = '}'; } $lines[] = ''; $lines[] = '/**'; $lines[] = ' * Return value of ' . $field_name . ' field.'; $lines[] = ' *'; $lines[] = ' * @return ' . $return_type; if ($short_getter && $this->getStructure()->getConfig('deprecate_long_bool_field_getter')) { $lines[] = " * @deprecated use $short_getter()"; } $lines[] = ' */'; $lines[] = 'public function ' . $this->getGetterName($field_name) . '()'; $lines[] = '{'; $lines[] = ' return $this->getFieldValue(' . var_export($field_name, true) . ');'; $lines[] = '}'; $lines[] = ''; foreach ($lines as $line) { $result[] = $line ? $indent . $line : ''; } }
[ "private", "function", "buildGeneratedFieldGetter", "(", "$", "field_name", ",", "$", "caster", ",", "$", "indent", ",", "array", "&", "$", "result", ")", "{", "$", "short_getter", "=", "null", ";", "switch", "(", "$", "caster", ")", "{", "case", "ValueCasterInterface", "::", "CAST_INT", ":", "$", "return_type", "=", "'int'", ";", "break", ";", "case", "ValueCasterInterface", "::", "CAST_FLOAT", ":", "$", "return_type", "=", "'float'", ";", "break", ";", "case", "ValueCasterInterface", "::", "CAST_BOOL", ":", "$", "return_type", "=", "'bool'", ";", "break", ";", "case", "ValueCasterInterface", "::", "CAST_DATE", ":", "$", "return_type", "=", "'\\\\'", ".", "DateValueInterface", "::", "class", ";", "break", ";", "case", "ValueCasterInterface", "::", "CAST_DATETIME", ":", "$", "return_type", "=", "'\\\\'", ".", "DateTimeValueInterface", "::", "class", ";", "break", ";", "case", "ValueCasterInterface", "::", "CAST_JSON", ":", "$", "return_type", "=", "'mixed'", ";", "break", ";", "default", ":", "$", "return_type", "=", "'string'", ";", "}", "if", "(", "$", "this", "->", "useShortGetterName", "(", "$", "field_name", ")", ")", "{", "$", "short_getter", "=", "$", "this", "->", "getShortGetterName", "(", "$", "field_name", ")", ";", "$", "lines", "[", "]", "=", "''", ";", "$", "lines", "[", "]", "=", "'/**'", ";", "$", "lines", "[", "]", "=", "' * Return value of '", ".", "$", "field_name", ".", "' field.'", ";", "$", "lines", "[", "]", "=", "' *'", ";", "$", "lines", "[", "]", "=", "' * @return '", ".", "$", "return_type", ";", "$", "lines", "[", "]", "=", "' */'", ";", "$", "lines", "[", "]", "=", "'public function '", ".", "$", "short_getter", ".", "'()'", ";", "$", "lines", "[", "]", "=", "'{'", ";", "$", "lines", "[", "]", "=", "' return $this->getFieldValue('", ".", "var_export", "(", "$", "field_name", ",", "true", ")", ".", "');'", ";", "$", "lines", "[", "]", "=", "'}'", ";", "}", "$", "lines", "[", "]", "=", "''", ";", "$", "lines", "[", "]", "=", "'/**'", ";", "$", "lines", "[", "]", "=", "' * Return value of '", ".", "$", "field_name", ".", "' field.'", ";", "$", "lines", "[", "]", "=", "' *'", ";", "$", "lines", "[", "]", "=", "' * @return '", ".", "$", "return_type", ";", "if", "(", "$", "short_getter", "&&", "$", "this", "->", "getStructure", "(", ")", "->", "getConfig", "(", "'deprecate_long_bool_field_getter'", ")", ")", "{", "$", "lines", "[", "]", "=", "\" * @deprecated use $short_getter()\"", ";", "}", "$", "lines", "[", "]", "=", "' */'", ";", "$", "lines", "[", "]", "=", "'public function '", ".", "$", "this", "->", "getGetterName", "(", "$", "field_name", ")", ".", "'()'", ";", "$", "lines", "[", "]", "=", "'{'", ";", "$", "lines", "[", "]", "=", "' return $this->getFieldValue('", ".", "var_export", "(", "$", "field_name", ",", "true", ")", ".", "');'", ";", "$", "lines", "[", "]", "=", "'}'", ";", "$", "lines", "[", "]", "=", "''", ";", "foreach", "(", "$", "lines", "as", "$", "line", ")", "{", "$", "result", "[", "]", "=", "$", "line", "?", "$", "indent", ".", "$", "line", ":", "''", ";", "}", "}" ]
Build getter for generated field. @param string $field_name @param string $caster @param string $indent @param array $result
[ "Build", "getter", "for", "generated", "field", "." ]
train
https://github.com/activecollab/databasestructure/blob/4b2353c4422186bcfce63b3212da3e70e63eb5df/src/Builder/BaseTypeClassBuilder.php#L466-L528
activecollab/databasestructure
src/Builder/BaseTypeClassBuilder.php
BaseTypeClassBuilder.useShortGetterName
private function useShortGetterName($field_name) { return substr($field_name, 0, 3) === 'is_' || in_array(substr($field_name, 0, 4), ['has_', 'had_', 'was_']) || in_array(substr($field_name, 0, 5), ['were_', 'have_']); }
php
private function useShortGetterName($field_name) { return substr($field_name, 0, 3) === 'is_' || in_array(substr($field_name, 0, 4), ['has_', 'had_', 'was_']) || in_array(substr($field_name, 0, 5), ['were_', 'have_']); }
[ "private", "function", "useShortGetterName", "(", "$", "field_name", ")", "{", "return", "substr", "(", "$", "field_name", ",", "0", ",", "3", ")", "===", "'is_'", "||", "in_array", "(", "substr", "(", "$", "field_name", ",", "0", ",", "4", ")", ",", "[", "'has_'", ",", "'had_'", ",", "'was_'", "]", ")", "||", "in_array", "(", "substr", "(", "$", "field_name", ",", "0", ",", "5", ")", ",", "[", "'were_'", ",", "'have_'", "]", ")", ";", "}" ]
Return true if we should use a short getter name. @param string $field_name @return bool
[ "Return", "true", "if", "we", "should", "use", "a", "short", "getter", "name", "." ]
train
https://github.com/activecollab/databasestructure/blob/4b2353c4422186bcfce63b3212da3e70e63eb5df/src/Builder/BaseTypeClassBuilder.php#L536-L539
activecollab/databasestructure
src/Builder/BaseTypeClassBuilder.php
BaseTypeClassBuilder.buildJsonSerialize
private function buildJsonSerialize(array $serialize, $indent, array &$result) { if (count($serialize)) { $result[] = ''; $result[] = $indent . '/**'; $result[] = $indent . ' * Prepare object properties so they can be serialized to JSON.'; $result[] = $indent . ' *'; $result[] = $indent . ' * @return array'; $result[] = $indent . ' */'; $result[] = $indent . 'public function jsonSerialize()'; $result[] = $indent . '{'; $result[] = $indent . ' return array_merge(parent::jsonSerialize(), ['; foreach ($serialize as $field) { $result[] = $indent . ' ' . var_export($field, true) . ' => $this->' . $this->getGetterName($field) . '(),'; } $result[] = $indent . ' ]);'; $result[] = $indent . '}'; } }
php
private function buildJsonSerialize(array $serialize, $indent, array &$result) { if (count($serialize)) { $result[] = ''; $result[] = $indent . '/**'; $result[] = $indent . ' * Prepare object properties so they can be serialized to JSON.'; $result[] = $indent . ' *'; $result[] = $indent . ' * @return array'; $result[] = $indent . ' */'; $result[] = $indent . 'public function jsonSerialize()'; $result[] = $indent . '{'; $result[] = $indent . ' return array_merge(parent::jsonSerialize(), ['; foreach ($serialize as $field) { $result[] = $indent . ' ' . var_export($field, true) . ' => $this->' . $this->getGetterName($field) . '(),'; } $result[] = $indent . ' ]);'; $result[] = $indent . '}'; } }
[ "private", "function", "buildJsonSerialize", "(", "array", "$", "serialize", ",", "$", "indent", ",", "array", "&", "$", "result", ")", "{", "if", "(", "count", "(", "$", "serialize", ")", ")", "{", "$", "result", "[", "]", "=", "''", ";", "$", "result", "[", "]", "=", "$", "indent", ".", "'/**'", ";", "$", "result", "[", "]", "=", "$", "indent", ".", "' * Prepare object properties so they can be serialized to JSON.'", ";", "$", "result", "[", "]", "=", "$", "indent", ".", "' *'", ";", "$", "result", "[", "]", "=", "$", "indent", ".", "' * @return array'", ";", "$", "result", "[", "]", "=", "$", "indent", ".", "' */'", ";", "$", "result", "[", "]", "=", "$", "indent", ".", "'public function jsonSerialize()'", ";", "$", "result", "[", "]", "=", "$", "indent", ".", "'{'", ";", "$", "result", "[", "]", "=", "$", "indent", ".", "' return array_merge(parent::jsonSerialize(), ['", ";", "foreach", "(", "$", "serialize", "as", "$", "field", ")", "{", "$", "result", "[", "]", "=", "$", "indent", ".", "' '", ".", "var_export", "(", "$", "field", ",", "true", ")", ".", "' => $this->'", ".", "$", "this", "->", "getGetterName", "(", "$", "field", ")", ".", "'(),'", ";", "}", "$", "result", "[", "]", "=", "$", "indent", ".", "' ]);'", ";", "$", "result", "[", "]", "=", "$", "indent", ".", "'}'", ";", "}", "}" ]
Build JSON serialize method, if we need to serialize extra fields. @param array $serialize @param string $indent @param array $result
[ "Build", "JSON", "serialize", "method", "if", "we", "need", "to", "serialize", "extra", "fields", "." ]
train
https://github.com/activecollab/databasestructure/blob/4b2353c4422186bcfce63b3212da3e70e63eb5df/src/Builder/BaseTypeClassBuilder.php#L548-L568
activecollab/databasestructure
src/Builder/BaseTypeClassBuilder.php
BaseTypeClassBuilder.buildValidatePresenceLinesForScalarField
private function buildValidatePresenceLinesForScalarField(ScalarField $field, $line_indent, array &$validator_lines) { if ($field instanceof RequiredInterface && $field instanceof UniqueInterface) { if ($field->isRequired() && $field->isUnique()) { $validator_lines[] = $line_indent . $this->buildValidatePresenceAndUniquenessLine($field->getName(), $field->getUniquenessContext()); } elseif ($field->isRequired()) { $validator_lines[] = $line_indent . $this->buildValidatePresenceLine($field->getName()); } elseif ($field->isUnique()) { $validator_lines[] = $line_indent . $this->buildValidateUniquenessLine($field->getName(), $field->getUniquenessContext()); } } elseif ($field instanceof RequiredInterface && $field->isRequired()) { $validator_lines[] = $line_indent . $this->buildValidatePresenceLine($field->getName()); } elseif ($field instanceof UniqueInterface && $field->isUnique()) { $validator_lines[] = $line_indent . $this->buildValidateUniquenessLine($field->getName(), $field->getUniquenessContext()); } }
php
private function buildValidatePresenceLinesForScalarField(ScalarField $field, $line_indent, array &$validator_lines) { if ($field instanceof RequiredInterface && $field instanceof UniqueInterface) { if ($field->isRequired() && $field->isUnique()) { $validator_lines[] = $line_indent . $this->buildValidatePresenceAndUniquenessLine($field->getName(), $field->getUniquenessContext()); } elseif ($field->isRequired()) { $validator_lines[] = $line_indent . $this->buildValidatePresenceLine($field->getName()); } elseif ($field->isUnique()) { $validator_lines[] = $line_indent . $this->buildValidateUniquenessLine($field->getName(), $field->getUniquenessContext()); } } elseif ($field instanceof RequiredInterface && $field->isRequired()) { $validator_lines[] = $line_indent . $this->buildValidatePresenceLine($field->getName()); } elseif ($field instanceof UniqueInterface && $field->isUnique()) { $validator_lines[] = $line_indent . $this->buildValidateUniquenessLine($field->getName(), $field->getUniquenessContext()); } }
[ "private", "function", "buildValidatePresenceLinesForScalarField", "(", "ScalarField", "$", "field", ",", "$", "line_indent", ",", "array", "&", "$", "validator_lines", ")", "{", "if", "(", "$", "field", "instanceof", "RequiredInterface", "&&", "$", "field", "instanceof", "UniqueInterface", ")", "{", "if", "(", "$", "field", "->", "isRequired", "(", ")", "&&", "$", "field", "->", "isUnique", "(", ")", ")", "{", "$", "validator_lines", "[", "]", "=", "$", "line_indent", ".", "$", "this", "->", "buildValidatePresenceAndUniquenessLine", "(", "$", "field", "->", "getName", "(", ")", ",", "$", "field", "->", "getUniquenessContext", "(", ")", ")", ";", "}", "elseif", "(", "$", "field", "->", "isRequired", "(", ")", ")", "{", "$", "validator_lines", "[", "]", "=", "$", "line_indent", ".", "$", "this", "->", "buildValidatePresenceLine", "(", "$", "field", "->", "getName", "(", ")", ")", ";", "}", "elseif", "(", "$", "field", "->", "isUnique", "(", ")", ")", "{", "$", "validator_lines", "[", "]", "=", "$", "line_indent", ".", "$", "this", "->", "buildValidateUniquenessLine", "(", "$", "field", "->", "getName", "(", ")", ",", "$", "field", "->", "getUniquenessContext", "(", ")", ")", ";", "}", "}", "elseif", "(", "$", "field", "instanceof", "RequiredInterface", "&&", "$", "field", "->", "isRequired", "(", ")", ")", "{", "$", "validator_lines", "[", "]", "=", "$", "line_indent", ".", "$", "this", "->", "buildValidatePresenceLine", "(", "$", "field", "->", "getName", "(", ")", ")", ";", "}", "elseif", "(", "$", "field", "instanceof", "UniqueInterface", "&&", "$", "field", "->", "isUnique", "(", ")", ")", "{", "$", "validator_lines", "[", "]", "=", "$", "line_indent", ".", "$", "this", "->", "buildValidateUniquenessLine", "(", "$", "field", "->", "getName", "(", ")", ",", "$", "field", "->", "getUniquenessContext", "(", ")", ")", ";", "}", "}" ]
Build validate lines for scalar fields. @param ScalarField $field @param string $line_indent @param array $validator_lines
[ "Build", "validate", "lines", "for", "scalar", "fields", "." ]
train
https://github.com/activecollab/databasestructure/blob/4b2353c4422186bcfce63b3212da3e70e63eb5df/src/Builder/BaseTypeClassBuilder.php#L628-L643
activecollab/databasestructure
src/Builder/BaseTypeClassBuilder.php
BaseTypeClassBuilder.buildValidateUniquenessLine
private function buildValidateUniquenessLine($field_name, array $context) { $field_names = [var_export($field_name, true)]; foreach ($context as $v) { $field_names[] = var_export($v, true); } return '$validator->unique(' . implode(', ', $field_names) . ');'; }
php
private function buildValidateUniquenessLine($field_name, array $context) { $field_names = [var_export($field_name, true)]; foreach ($context as $v) { $field_names[] = var_export($v, true); } return '$validator->unique(' . implode(', ', $field_names) . ');'; }
[ "private", "function", "buildValidateUniquenessLine", "(", "$", "field_name", ",", "array", "$", "context", ")", "{", "$", "field_names", "=", "[", "var_export", "(", "$", "field_name", ",", "true", ")", "]", ";", "foreach", "(", "$", "context", "as", "$", "v", ")", "{", "$", "field_names", "[", "]", "=", "var_export", "(", "$", "v", ",", "true", ")", ";", "}", "return", "'$validator->unique('", ".", "implode", "(", "', '", ",", "$", "field_names", ")", ".", "');'", ";", "}" ]
Build validator uniqueness line. @param string $field_name @param array $context @return string
[ "Build", "validator", "uniqueness", "line", "." ]
train
https://github.com/activecollab/databasestructure/blob/4b2353c4422186bcfce63b3212da3e70e63eb5df/src/Builder/BaseTypeClassBuilder.php#L663-L672
huasituo/hstcms
src/Libraries/HstcmsEmail.php
HstcmsEmail.sendMail
static function sendMail($data, $view) { $res = Mail::send( $view, ['data' => $data], function ($message) use ($data) { $message->to($data['email'])->subject($data['title']); }); return $res ? true : false; }
php
static function sendMail($data, $view) { $res = Mail::send( $view, ['data' => $data], function ($message) use ($data) { $message->to($data['email'])->subject($data['title']); }); return $res ? true : false; }
[ "static", "function", "sendMail", "(", "$", "data", ",", "$", "view", ")", "{", "$", "res", "=", "Mail", "::", "send", "(", "$", "view", ",", "[", "'data'", "=>", "$", "data", "]", ",", "function", "(", "$", "message", ")", "use", "(", "$", "data", ")", "{", "$", "message", "->", "to", "(", "$", "data", "[", "'email'", "]", ")", "->", "subject", "(", "$", "data", "[", "'title'", "]", ")", ";", "}", ")", ";", "return", "$", "res", "?", "true", ":", "false", ";", "}" ]
发送邮件 @param array $data @param str $view @return bool
[ "发送邮件" ]
train
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/HstcmsEmail.php#L26-L33
e0ipso/drupal-unit-autoload
src/AutoloaderBootstrap.php
AutoloaderBootstrap.register
public function register() { if ($this->checkLoadedAutoloader()) { return; } // Parse the composer.json. $composer_config = $this->getConfig(); $this->registerDrupalPaths($composer_config); $this->registerPsr($composer_config); }
php
public function register() { if ($this->checkLoadedAutoloader()) { return; } // Parse the composer.json. $composer_config = $this->getConfig(); $this->registerDrupalPaths($composer_config); $this->registerPsr($composer_config); }
[ "public", "function", "register", "(", ")", "{", "if", "(", "$", "this", "->", "checkLoadedAutoloader", "(", ")", ")", "{", "return", ";", "}", "// Parse the composer.json.", "$", "composer_config", "=", "$", "this", "->", "getConfig", "(", ")", ";", "$", "this", "->", "registerDrupalPaths", "(", "$", "composer_config", ")", ";", "$", "this", "->", "registerPsr", "(", "$", "composer_config", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/e0ipso/drupal-unit-autoload/blob/7ce147b269c7333eca31e2cd04b736d6274b9cbf/src/AutoloaderBootstrap.php#L72-L80
e0ipso/drupal-unit-autoload
src/AutoloaderBootstrap.php
AutoloaderBootstrap.registerDrupalPaths
protected function registerDrupalPaths($composer_config) { if (empty($composer_config['class-location'])) { return; } $this->loader->setClassMap((array) $composer_config['class-location']); $this->load(); }
php
protected function registerDrupalPaths($composer_config) { if (empty($composer_config['class-location'])) { return; } $this->loader->setClassMap((array) $composer_config['class-location']); $this->load(); }
[ "protected", "function", "registerDrupalPaths", "(", "$", "composer_config", ")", "{", "if", "(", "empty", "(", "$", "composer_config", "[", "'class-location'", "]", ")", ")", "{", "return", ";", "}", "$", "this", "->", "loader", "->", "setClassMap", "(", "(", "array", ")", "$", "composer_config", "[", "'class-location'", "]", ")", ";", "$", "this", "->", "load", "(", ")", ";", "}" ]
Register the path based autoloader. @param object $composer_config The Composer configuration.
[ "Register", "the", "path", "based", "autoloader", "." ]
train
https://github.com/e0ipso/drupal-unit-autoload/blob/7ce147b269c7333eca31e2cd04b736d6274b9cbf/src/AutoloaderBootstrap.php#L102-L108
e0ipso/drupal-unit-autoload
src/AutoloaderBootstrap.php
AutoloaderBootstrap.registerPsr
protected function registerPsr(array $composer_config) { $psr0 = $psr4 = array(); if (!empty($composer_config['psr-0'])) { $psr0 = (array) $composer_config['psr-0']; } if (!empty($composer_config['psr-4'])) { $psr4 = (array) $composer_config['psr-4']; } if (empty($psr4) && empty($psr0)) { return; } $this->loader->setPsrClassMap(array( 'psr-0' => $psr0, 'psr-4' => $psr4, )); $this->loader->registerPsr($this->classLoader); }
php
protected function registerPsr(array $composer_config) { $psr0 = $psr4 = array(); if (!empty($composer_config['psr-0'])) { $psr0 = (array) $composer_config['psr-0']; } if (!empty($composer_config['psr-4'])) { $psr4 = (array) $composer_config['psr-4']; } if (empty($psr4) && empty($psr0)) { return; } $this->loader->setPsrClassMap(array( 'psr-0' => $psr0, 'psr-4' => $psr4, )); $this->loader->registerPsr($this->classLoader); }
[ "protected", "function", "registerPsr", "(", "array", "$", "composer_config", ")", "{", "$", "psr0", "=", "$", "psr4", "=", "array", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "composer_config", "[", "'psr-0'", "]", ")", ")", "{", "$", "psr0", "=", "(", "array", ")", "$", "composer_config", "[", "'psr-0'", "]", ";", "}", "if", "(", "!", "empty", "(", "$", "composer_config", "[", "'psr-4'", "]", ")", ")", "{", "$", "psr4", "=", "(", "array", ")", "$", "composer_config", "[", "'psr-4'", "]", ";", "}", "if", "(", "empty", "(", "$", "psr4", ")", "&&", "empty", "(", "$", "psr0", ")", ")", "{", "return", ";", "}", "$", "this", "->", "loader", "->", "setPsrClassMap", "(", "array", "(", "'psr-0'", "=>", "$", "psr0", ",", "'psr-4'", "=>", "$", "psr4", ",", ")", ")", ";", "$", "this", "->", "loader", "->", "registerPsr", "(", "$", "this", "->", "classLoader", ")", ";", "}" ]
Use Composer's autoloader to register the PRS-0 and PSR-4 paths. @param array $composer_config The Composer configuration.
[ "Use", "Composer", "s", "autoloader", "to", "register", "the", "PRS", "-", "0", "and", "PSR", "-", "4", "paths", "." ]
train
https://github.com/e0ipso/drupal-unit-autoload/blob/7ce147b269c7333eca31e2cd04b736d6274b9cbf/src/AutoloaderBootstrap.php#L116-L132
e0ipso/drupal-unit-autoload
src/AutoloaderBootstrap.php
AutoloaderBootstrap.getConfig
public function getConfig() { // Initialize empty configuration. $config = [ 'psr-0' => [], 'psr-4' => [], 'class-location' => [], ]; // Find the tokenized paths. $psrs = array( 'psr-0' => $this->classLoader->getPrefixes(), 'psr-4' => $this->classLoader->getPrefixesPsr4(), ); // Get all the PSR-0 and PSR-0 and detect the ones that have Drupal tokens. foreach ($psrs as $psr_type => $namespaces) { $namespaces = $namespaces ?: []; foreach ($namespaces as $prefix => $paths) { $token_paths = array(); if (!is_array($paths)) { $paths = array($paths); } foreach ($paths as $path) { $token_resolver = $this->tokenFactory->factory($path); if (!$token_resolver->hasToken()) { continue; } $path = $token_resolver->trimPath(); $token_paths[] = $path; } // If there were paths, add them to the config. if (!empty($token_paths)) { $config[$psr_type][$prefix] = $token_paths; } } } // Get the drupal path configuration. $composer_config = json_decode(file_get_contents(static::COMPOSER_CONFIGURATION_NAME)); $config['class-location'] = array(); if (isset($composer_config->autoload->{'class-location'})) { $config['class-location'] = array_merge($config['class-location'], (array) $composer_config->autoload->{'class-location'}); } if (isset($composer_config->{'autoload-dev'}->{'class-location'})) { $config['class-location'] = array_merge($config['class-location'], (array) $composer_config->{'autoload-dev'}->{'class-location'}); } return $config; }
php
public function getConfig() { // Initialize empty configuration. $config = [ 'psr-0' => [], 'psr-4' => [], 'class-location' => [], ]; // Find the tokenized paths. $psrs = array( 'psr-0' => $this->classLoader->getPrefixes(), 'psr-4' => $this->classLoader->getPrefixesPsr4(), ); // Get all the PSR-0 and PSR-0 and detect the ones that have Drupal tokens. foreach ($psrs as $psr_type => $namespaces) { $namespaces = $namespaces ?: []; foreach ($namespaces as $prefix => $paths) { $token_paths = array(); if (!is_array($paths)) { $paths = array($paths); } foreach ($paths as $path) { $token_resolver = $this->tokenFactory->factory($path); if (!$token_resolver->hasToken()) { continue; } $path = $token_resolver->trimPath(); $token_paths[] = $path; } // If there were paths, add them to the config. if (!empty($token_paths)) { $config[$psr_type][$prefix] = $token_paths; } } } // Get the drupal path configuration. $composer_config = json_decode(file_get_contents(static::COMPOSER_CONFIGURATION_NAME)); $config['class-location'] = array(); if (isset($composer_config->autoload->{'class-location'})) { $config['class-location'] = array_merge($config['class-location'], (array) $composer_config->autoload->{'class-location'}); } if (isset($composer_config->{'autoload-dev'}->{'class-location'})) { $config['class-location'] = array_merge($config['class-location'], (array) $composer_config->{'autoload-dev'}->{'class-location'}); } return $config; }
[ "public", "function", "getConfig", "(", ")", "{", "// Initialize empty configuration.", "$", "config", "=", "[", "'psr-0'", "=>", "[", "]", ",", "'psr-4'", "=>", "[", "]", ",", "'class-location'", "=>", "[", "]", ",", "]", ";", "// Find the tokenized paths.", "$", "psrs", "=", "array", "(", "'psr-0'", "=>", "$", "this", "->", "classLoader", "->", "getPrefixes", "(", ")", ",", "'psr-4'", "=>", "$", "this", "->", "classLoader", "->", "getPrefixesPsr4", "(", ")", ",", ")", ";", "// Get all the PSR-0 and PSR-0 and detect the ones that have Drupal tokens.", "foreach", "(", "$", "psrs", "as", "$", "psr_type", "=>", "$", "namespaces", ")", "{", "$", "namespaces", "=", "$", "namespaces", "?", ":", "[", "]", ";", "foreach", "(", "$", "namespaces", "as", "$", "prefix", "=>", "$", "paths", ")", "{", "$", "token_paths", "=", "array", "(", ")", ";", "if", "(", "!", "is_array", "(", "$", "paths", ")", ")", "{", "$", "paths", "=", "array", "(", "$", "paths", ")", ";", "}", "foreach", "(", "$", "paths", "as", "$", "path", ")", "{", "$", "token_resolver", "=", "$", "this", "->", "tokenFactory", "->", "factory", "(", "$", "path", ")", ";", "if", "(", "!", "$", "token_resolver", "->", "hasToken", "(", ")", ")", "{", "continue", ";", "}", "$", "path", "=", "$", "token_resolver", "->", "trimPath", "(", ")", ";", "$", "token_paths", "[", "]", "=", "$", "path", ";", "}", "// If there were paths, add them to the config.", "if", "(", "!", "empty", "(", "$", "token_paths", ")", ")", "{", "$", "config", "[", "$", "psr_type", "]", "[", "$", "prefix", "]", "=", "$", "token_paths", ";", "}", "}", "}", "// Get the drupal path configuration.", "$", "composer_config", "=", "json_decode", "(", "file_get_contents", "(", "static", "::", "COMPOSER_CONFIGURATION_NAME", ")", ")", ";", "$", "config", "[", "'class-location'", "]", "=", "array", "(", ")", ";", "if", "(", "isset", "(", "$", "composer_config", "->", "autoload", "->", "{", "'class-location'", "}", ")", ")", "{", "$", "config", "[", "'class-location'", "]", "=", "array_merge", "(", "$", "config", "[", "'class-location'", "]", ",", "(", "array", ")", "$", "composer_config", "->", "autoload", "->", "{", "'class-location'", "}", ")", ";", "}", "if", "(", "isset", "(", "$", "composer_config", "->", "{", "'autoload-dev'", "}", "->", "{", "'class-location'", "}", ")", ")", "{", "$", "config", "[", "'class-location'", "]", "=", "array_merge", "(", "$", "config", "[", "'class-location'", "]", ",", "(", "array", ")", "$", "composer_config", "->", "{", "'autoload-dev'", "}", "->", "{", "'class-location'", "}", ")", ";", "}", "return", "$", "config", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/e0ipso/drupal-unit-autoload/blob/7ce147b269c7333eca31e2cd04b736d6274b9cbf/src/AutoloaderBootstrap.php#L145-L192
gintonicweb/GintonicCMS
src/Controller/Admin/UsersController.php
UsersController.beforeFilter
public function beforeFilter(Event $event) { $this->Users->hasOne('Roles', [ 'className' => 'Permissions.Roles', ]); $action = $this->Crud->action(); $action->config('scaffold.fields_blacklist', ['password', 'token']); $action->config('scaffold.fields', [ 'id', 'email', 'username', 'verified', 'deleted', 'role.role' => [ 'formatter' => function ($name, $value, $entity) { if (isset($entity->role)) { return $entity->role->names($entity->role->role); } return 'User'; }, 'options' => Role::names(), ], ]); $this->Crud->listener('relatedModels')->relatedModels(['Roles'], 'index'); }
php
public function beforeFilter(Event $event) { $this->Users->hasOne('Roles', [ 'className' => 'Permissions.Roles', ]); $action = $this->Crud->action(); $action->config('scaffold.fields_blacklist', ['password', 'token']); $action->config('scaffold.fields', [ 'id', 'email', 'username', 'verified', 'deleted', 'role.role' => [ 'formatter' => function ($name, $value, $entity) { if (isset($entity->role)) { return $entity->role->names($entity->role->role); } return 'User'; }, 'options' => Role::names(), ], ]); $this->Crud->listener('relatedModels')->relatedModels(['Roles'], 'index'); }
[ "public", "function", "beforeFilter", "(", "Event", "$", "event", ")", "{", "$", "this", "->", "Users", "->", "hasOne", "(", "'Roles'", ",", "[", "'className'", "=>", "'Permissions.Roles'", ",", "]", ")", ";", "$", "action", "=", "$", "this", "->", "Crud", "->", "action", "(", ")", ";", "$", "action", "->", "config", "(", "'scaffold.fields_blacklist'", ",", "[", "'password'", ",", "'token'", "]", ")", ";", "$", "action", "->", "config", "(", "'scaffold.fields'", ",", "[", "'id'", ",", "'email'", ",", "'username'", ",", "'verified'", ",", "'deleted'", ",", "'role.role'", "=>", "[", "'formatter'", "=>", "function", "(", "$", "name", ",", "$", "value", ",", "$", "entity", ")", "{", "if", "(", "isset", "(", "$", "entity", "->", "role", ")", ")", "{", "return", "$", "entity", "->", "role", "->", "names", "(", "$", "entity", "->", "role", "->", "role", ")", ";", "}", "return", "'User'", ";", "}", ",", "'options'", "=>", "Role", "::", "names", "(", ")", ",", "]", ",", "]", ")", ";", "$", "this", "->", "Crud", "->", "listener", "(", "'relatedModels'", ")", "->", "relatedModels", "(", "[", "'Roles'", "]", ",", "'index'", ")", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/gintonicweb/GintonicCMS/blob/b34445fecea56a7d432d0f3e2f988cde8ead746b/src/Controller/Admin/UsersController.php#L24-L49
gintonicweb/GintonicCMS
src/Controller/Admin/UsersController.php
UsersController.index
public function index() { $action = $this->Crud->action(); $action->config('scaffold.fields_blacklist', ['created', 'modified']); $this->Crud->execute(); }
php
public function index() { $action = $this->Crud->action(); $action->config('scaffold.fields_blacklist', ['created', 'modified']); $this->Crud->execute(); }
[ "public", "function", "index", "(", ")", "{", "$", "action", "=", "$", "this", "->", "Crud", "->", "action", "(", ")", ";", "$", "action", "->", "config", "(", "'scaffold.fields_blacklist'", ",", "[", "'created'", ",", "'modified'", "]", ")", ";", "$", "this", "->", "Crud", "->", "execute", "(", ")", ";", "}" ]
Index method Don't show created and modified fields @return void
[ "Index", "method", "Don", "t", "show", "created", "and", "modified", "fields" ]
train
https://github.com/gintonicweb/GintonicCMS/blob/b34445fecea56a7d432d0f3e2f988cde8ead746b/src/Controller/Admin/UsersController.php#L57-L62
gintonicweb/GintonicCMS
src/Controller/Admin/UsersController.php
UsersController.view
public function view() { $action = $this->Crud->action(); $action->config('scaffold.relations', false); $this->Crud->execute(); }
php
public function view() { $action = $this->Crud->action(); $action->config('scaffold.relations', false); $this->Crud->execute(); }
[ "public", "function", "view", "(", ")", "{", "$", "action", "=", "$", "this", "->", "Crud", "->", "action", "(", ")", ";", "$", "action", "->", "config", "(", "'scaffold.relations'", ",", "false", ")", ";", "$", "this", "->", "Crud", "->", "execute", "(", ")", ";", "}" ]
View method Related models are blacklisted because the role is already present in the main user panel @return void
[ "View", "method", "Related", "models", "are", "blacklisted", "because", "the", "role", "is", "already", "present", "in", "the", "main", "user", "panel" ]
train
https://github.com/gintonicweb/GintonicCMS/blob/b34445fecea56a7d432d0f3e2f988cde8ead746b/src/Controller/Admin/UsersController.php#L71-L76
fuelphp/display
src/Parser/HandlebarsLoader.php
HandlebarsLoader.findView
public function findView($name) { if (substr($name, -11) !== '.handlebars' && substr($name, -4) !== '.hbs') { $name = $this->prefix . $name . '.handlebars'; } if ( ! $file = parent::findView($name)) { throw new ViewNotFoundException('Could not locate: '.$name); } return $file; }
php
public function findView($name) { if (substr($name, -11) !== '.handlebars' && substr($name, -4) !== '.hbs') { $name = $this->prefix . $name . '.handlebars'; } if ( ! $file = parent::findView($name)) { throw new ViewNotFoundException('Could not locate: '.$name); } return $file; }
[ "public", "function", "findView", "(", "$", "name", ")", "{", "if", "(", "substr", "(", "$", "name", ",", "-", "11", ")", "!==", "'.handlebars'", "&&", "substr", "(", "$", "name", ",", "-", "4", ")", "!==", "'.hbs'", ")", "{", "$", "name", "=", "$", "this", "->", "prefix", ".", "$", "name", ".", "'.handlebars'", ";", "}", "if", "(", "!", "$", "file", "=", "parent", "::", "findView", "(", "$", "name", ")", ")", "{", "throw", "new", "ViewNotFoundException", "(", "'Could not locate: '", ".", "$", "name", ")", ";", "}", "return", "$", "file", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/fuelphp/display/blob/d9a3eddbf80f0fd81beb40d9f4507600ac6611a4/src/Parser/HandlebarsLoader.php#L52-L65
tequila/mongodb-php-lib
src/Query.php
Query.getOptions
public function getOptions(Server $server) { if (isset($this->options['collation']) && !$server->supportsCollation()) { throw new UnsupportedException( 'Option "collation" is not supported by the server.' ); } if (isset($this->options['readConcern'])) { if (!$server->supportsReadConcern()) { throw new UnsupportedException( 'Option "readConcern" is not supported by the server.' ); } } elseif ($this->readConcern && $server->supportsReadConcern()) { $this->options['readConcern'] = $this->readConcern; } return $this->options; }
php
public function getOptions(Server $server) { if (isset($this->options['collation']) && !$server->supportsCollation()) { throw new UnsupportedException( 'Option "collation" is not supported by the server.' ); } if (isset($this->options['readConcern'])) { if (!$server->supportsReadConcern()) { throw new UnsupportedException( 'Option "readConcern" is not supported by the server.' ); } } elseif ($this->readConcern && $server->supportsReadConcern()) { $this->options['readConcern'] = $this->readConcern; } return $this->options; }
[ "public", "function", "getOptions", "(", "Server", "$", "server", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "'collation'", "]", ")", "&&", "!", "$", "server", "->", "supportsCollation", "(", ")", ")", "{", "throw", "new", "UnsupportedException", "(", "'Option \"collation\" is not supported by the server.'", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "'readConcern'", "]", ")", ")", "{", "if", "(", "!", "$", "server", "->", "supportsReadConcern", "(", ")", ")", "{", "throw", "new", "UnsupportedException", "(", "'Option \"readConcern\" is not supported by the server.'", ")", ";", "}", "}", "elseif", "(", "$", "this", "->", "readConcern", "&&", "$", "server", "->", "supportsReadConcern", "(", ")", ")", "{", "$", "this", "->", "options", "[", "'readConcern'", "]", "=", "$", "this", "->", "readConcern", ";", "}", "return", "$", "this", "->", "options", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/tequila/mongodb-php-lib/blob/49a25f45268df358f5ceb40a655d9a7ddc6db4f7/src/Query.php#L46-L65
drupol/valuewrapper
src/Object/ClosureObject.php
ClosureObject.hash
public function hash(): string { return $this->doHash($this->type() . $this->serializer->serialize($this->value())); }
php
public function hash(): string { return $this->doHash($this->type() . $this->serializer->serialize($this->value())); }
[ "public", "function", "hash", "(", ")", ":", "string", "{", "return", "$", "this", "->", "doHash", "(", "$", "this", "->", "type", "(", ")", ".", "$", "this", "->", "serializer", "->", "serialize", "(", "$", "this", "->", "value", "(", ")", ")", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/drupol/valuewrapper/blob/49cc07e4d0284718c24ba6e9cf524c1f4226694e/src/Object/ClosureObject.php#L42-L45
drupol/valuewrapper
src/Object/ClosureObject.php
ClosureObject.unserialize
public function unserialize($serialized) { $unserialized = \unserialize($serialized); $this->set( $this->serializer->unserialize(\base64_decode($unserialized['value'], true)) ); }
php
public function unserialize($serialized) { $unserialized = \unserialize($serialized); $this->set( $this->serializer->unserialize(\base64_decode($unserialized['value'], true)) ); }
[ "public", "function", "unserialize", "(", "$", "serialized", ")", "{", "$", "unserialized", "=", "\\", "unserialize", "(", "$", "serialized", ")", ";", "$", "this", "->", "set", "(", "$", "this", "->", "serializer", "->", "unserialize", "(", "\\", "base64_decode", "(", "$", "unserialized", "[", "'value'", "]", ",", "true", ")", ")", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/drupol/valuewrapper/blob/49cc07e4d0284718c24ba6e9cf524c1f4226694e/src/Object/ClosureObject.php#L60-L67
sohenk/wangeditor3forlaravel
src/WangEditorController.php
WangEditorController.serve
public function serve(Request $request) { $res = [ 'errno' => 9999, 'data' => [], 'info' => '上传图片失败,原因为:非法传参' ]; if ($request->hasFile('ChooseFile')) { $files = $request->file('ChooseFile'); $maxCount = config('wangeditor.uploadImgMaxLength', 5); if (count($files) > $maxCount) { $res = array_replace([ 'info' => '上传图片失败,原因为:一次性最多可上传 ' . $maxCount . ' 张图片' ], $res); } else { $data = $request->all(); $rules = [ 'ChooseFile.*' => 'mimes:jpeg,png,gif|max:5120', ]; $messages = [ 'ChooseFile.*.required' => '必须传入文件', 'ChooseFile.*.mimes' => '文件类型不允许,请上传常规的图片(jpg、png、gif)文件', 'ChooseFile.*.max' => '文件过大,文件大小不得超出5MB', ]; $validator = Validator::make($data, $rules, $messages); $validator = Validator::make($data, $rules, $messages); if ($validator->passes()) { $_data = []; foreach ($files as $file) { if ($file->isValid()) { $storage = Storage::disk(config('wangeditor.upload.disk', 'public')); $result = $storage->url($storage->put(config('wangeditor.upload.path', 'uploads/images'), $file)); $_data[] = $result; } } $res = [ 'errno' => 0, 'data' => $_data, ]; } else { $res = array_replace(['info' => $validator->messages()->first()], $res); } } } return $res; }
php
public function serve(Request $request) { $res = [ 'errno' => 9999, 'data' => [], 'info' => '上传图片失败,原因为:非法传参' ]; if ($request->hasFile('ChooseFile')) { $files = $request->file('ChooseFile'); $maxCount = config('wangeditor.uploadImgMaxLength', 5); if (count($files) > $maxCount) { $res = array_replace([ 'info' => '上传图片失败,原因为:一次性最多可上传 ' . $maxCount . ' 张图片' ], $res); } else { $data = $request->all(); $rules = [ 'ChooseFile.*' => 'mimes:jpeg,png,gif|max:5120', ]; $messages = [ 'ChooseFile.*.required' => '必须传入文件', 'ChooseFile.*.mimes' => '文件类型不允许,请上传常规的图片(jpg、png、gif)文件', 'ChooseFile.*.max' => '文件过大,文件大小不得超出5MB', ]; $validator = Validator::make($data, $rules, $messages); $validator = Validator::make($data, $rules, $messages); if ($validator->passes()) { $_data = []; foreach ($files as $file) { if ($file->isValid()) { $storage = Storage::disk(config('wangeditor.upload.disk', 'public')); $result = $storage->url($storage->put(config('wangeditor.upload.path', 'uploads/images'), $file)); $_data[] = $result; } } $res = [ 'errno' => 0, 'data' => $_data, ]; } else { $res = array_replace(['info' => $validator->messages()->first()], $res); } } } return $res; }
[ "public", "function", "serve", "(", "Request", "$", "request", ")", "{", "$", "res", "=", "[", "'errno'", "=>", "9999", ",", "'data'", "=>", "[", "]", ",", "'info'", "=>", "'上传图片失败,原因为:非法传参'", "]", ";", "if", "(", "$", "request", "->", "hasFile", "(", "'ChooseFile'", ")", ")", "{", "$", "files", "=", "$", "request", "->", "file", "(", "'ChooseFile'", ")", ";", "$", "maxCount", "=", "config", "(", "'wangeditor.uploadImgMaxLength'", ",", "5", ")", ";", "if", "(", "count", "(", "$", "files", ")", ">", "$", "maxCount", ")", "{", "$", "res", "=", "array_replace", "(", "[", "'info'", "=>", "'上传图片失败,原因为:一次性最多可上传 ' . $maxCount . ' 张图片'", "", "", "", "", "", "]", ",", "$", "res", ")", ";", "}", "else", "{", "$", "data", "=", "$", "request", "->", "all", "(", ")", ";", "$", "rules", "=", "[", "'ChooseFile.*'", "=>", "'mimes:jpeg,png,gif|max:5120'", ",", "]", ";", "$", "messages", "=", "[", "'ChooseFile.*.required'", "=>", "'必须传入文件',", "", "'ChooseFile.*.mimes'", "=>", "'文件类型不允许,请上传常规的图片(jpg、png、gif)文件',", "", "'ChooseFile.*.max'", "=>", "'文件过大,文件大小不得超出5MB',", "", "]", ";", "$", "validator", "=", "Validator", "::", "make", "(", "$", "data", ",", "$", "rules", ",", "$", "messages", ")", ";", "$", "validator", "=", "Validator", "::", "make", "(", "$", "data", ",", "$", "rules", ",", "$", "messages", ")", ";", "if", "(", "$", "validator", "->", "passes", "(", ")", ")", "{", "$", "_data", "=", "[", "]", ";", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "if", "(", "$", "file", "->", "isValid", "(", ")", ")", "{", "$", "storage", "=", "Storage", "::", "disk", "(", "config", "(", "'wangeditor.upload.disk'", ",", "'public'", ")", ")", ";", "$", "result", "=", "$", "storage", "->", "url", "(", "$", "storage", "->", "put", "(", "config", "(", "'wangeditor.upload.path'", ",", "'uploads/images'", ")", ",", "$", "file", ")", ")", ";", "$", "_data", "[", "]", "=", "$", "result", ";", "}", "}", "$", "res", "=", "[", "'errno'", "=>", "0", ",", "'data'", "=>", "$", "_data", ",", "]", ";", "}", "else", "{", "$", "res", "=", "array_replace", "(", "[", "'info'", "=>", "$", "validator", "->", "messages", "(", ")", "->", "first", "(", ")", "]", ",", "$", "res", ")", ";", "}", "}", "}", "return", "$", "res", ";", "}" ]
Processing upload files @param Request $request @return string
[ "Processing", "upload", "files" ]
train
https://github.com/sohenk/wangeditor3forlaravel/blob/a67c6b69926774c9c157920c5380de4aae06fea3/src/WangEditorController.php#L27-L84
phpalchemy/cerberus
src/Alchemy/Component/Cerberus/Model/Base/LoginLog.php
LoginLog.getDateTime
public function getDateTime($format = NULL) { if ($format === null) { return $this->date_time; } else { return $this->date_time instanceof \DateTime ? $this->date_time->format($format) : null; } }
php
public function getDateTime($format = NULL) { if ($format === null) { return $this->date_time; } else { return $this->date_time instanceof \DateTime ? $this->date_time->format($format) : null; } }
[ "public", "function", "getDateTime", "(", "$", "format", "=", "NULL", ")", "{", "if", "(", "$", "format", "===", "null", ")", "{", "return", "$", "this", "->", "date_time", ";", "}", "else", "{", "return", "$", "this", "->", "date_time", "instanceof", "\\", "DateTime", "?", "$", "this", "->", "date_time", "->", "format", "(", "$", "format", ")", ":", "null", ";", "}", "}" ]
Get the [optionally formatted] temporal [date_time] column value. @param string $format The date/time format string (either date()-style or strftime()-style). If format is NULL, then the raw \DateTime object will be returned. @return string|\DateTime Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 @throws PropelException - if unable to parse/validate the date/time value.
[ "Get", "the", "[", "optionally", "formatted", "]", "temporal", "[", "date_time", "]", "column", "value", "." ]
train
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/LoginLog.php#L373-L380
phpalchemy/cerberus
src/Alchemy/Component/Cerberus/Model/Base/LoginLog.php
LoginLog.setDateTime
public function setDateTime($v) { $dt = PropelDateTime::newInstance($v, null, '\DateTime'); if ($this->date_time !== null || $dt !== null) { if ($dt !== $this->date_time) { $this->date_time = $dt; $this->modifiedColumns[LoginLogTableMap::COL_DATE_TIME] = true; } } // if either are not null return $this; }
php
public function setDateTime($v) { $dt = PropelDateTime::newInstance($v, null, '\DateTime'); if ($this->date_time !== null || $dt !== null) { if ($dt !== $this->date_time) { $this->date_time = $dt; $this->modifiedColumns[LoginLogTableMap::COL_DATE_TIME] = true; } } // if either are not null return $this; }
[ "public", "function", "setDateTime", "(", "$", "v", ")", "{", "$", "dt", "=", "PropelDateTime", "::", "newInstance", "(", "$", "v", ",", "null", ",", "'\\DateTime'", ")", ";", "if", "(", "$", "this", "->", "date_time", "!==", "null", "||", "$", "dt", "!==", "null", ")", "{", "if", "(", "$", "dt", "!==", "$", "this", "->", "date_time", ")", "{", "$", "this", "->", "date_time", "=", "$", "dt", ";", "$", "this", "->", "modifiedColumns", "[", "LoginLogTableMap", "::", "COL_DATE_TIME", "]", "=", "true", ";", "}", "}", "// if either are not null", "return", "$", "this", ";", "}" ]
Sets the value of [date_time] column to a normalized version of the date/time value specified. @param mixed $v string, integer (timestamp), or \DateTime value. Empty strings are treated as NULL. @return $this|\Alchemy\Component\Cerberus\Model\LoginLog The current object (for fluent API support)
[ "Sets", "the", "value", "of", "[", "date_time", "]", "column", "to", "a", "normalized", "version", "of", "the", "date", "/", "time", "value", "specified", "." ]
train
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/LoginLog.php#L599-L610
phpalchemy/cerberus
src/Alchemy/Component/Cerberus/Model/Base/LoginLog.php
LoginLog.setUserId
public function setUserId($v) { if ($v !== null) { $v = (string) $v; } if ($this->user_id !== $v) { $this->user_id = $v; $this->modifiedColumns[LoginLogTableMap::COL_USER_ID] = true; } return $this; }
php
public function setUserId($v) { if ($v !== null) { $v = (string) $v; } if ($this->user_id !== $v) { $this->user_id = $v; $this->modifiedColumns[LoginLogTableMap::COL_USER_ID] = true; } return $this; }
[ "public", "function", "setUserId", "(", "$", "v", ")", "{", "if", "(", "$", "v", "!==", "null", ")", "{", "$", "v", "=", "(", "string", ")", "$", "v", ";", "}", "if", "(", "$", "this", "->", "user_id", "!==", "$", "v", ")", "{", "$", "this", "->", "user_id", "=", "$", "v", ";", "$", "this", "->", "modifiedColumns", "[", "LoginLogTableMap", "::", "COL_USER_ID", "]", "=", "true", ";", "}", "return", "$", "this", ";", "}" ]
Set the value of [user_id] column. @param string $v new value @return $this|\Alchemy\Component\Cerberus\Model\LoginLog The current object (for fluent API support)
[ "Set", "the", "value", "of", "[", "user_id", "]", "column", "." ]
train
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/LoginLog.php#L618-L630
phpalchemy/cerberus
src/Alchemy/Component/Cerberus/Model/Base/LoginLog.php
LoginLog.setSessionId
public function setSessionId($v) { if ($v !== null) { $v = (string) $v; } if ($this->session_id !== $v) { $this->session_id = $v; $this->modifiedColumns[LoginLogTableMap::COL_SESSION_ID] = true; } return $this; }
php
public function setSessionId($v) { if ($v !== null) { $v = (string) $v; } if ($this->session_id !== $v) { $this->session_id = $v; $this->modifiedColumns[LoginLogTableMap::COL_SESSION_ID] = true; } return $this; }
[ "public", "function", "setSessionId", "(", "$", "v", ")", "{", "if", "(", "$", "v", "!==", "null", ")", "{", "$", "v", "=", "(", "string", ")", "$", "v", ";", "}", "if", "(", "$", "this", "->", "session_id", "!==", "$", "v", ")", "{", "$", "this", "->", "session_id", "=", "$", "v", ";", "$", "this", "->", "modifiedColumns", "[", "LoginLogTableMap", "::", "COL_SESSION_ID", "]", "=", "true", ";", "}", "return", "$", "this", ";", "}" ]
Set the value of [session_id] column. @param string $v new value @return $this|\Alchemy\Component\Cerberus\Model\LoginLog The current object (for fluent API support)
[ "Set", "the", "value", "of", "[", "session_id", "]", "column", "." ]
train
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/LoginLog.php#L658-L670
phpalchemy/cerberus
src/Alchemy/Component/Cerberus/Model/Base/LoginLog.php
LoginLog.setClientIp
public function setClientIp($v) { if ($v !== null) { $v = (string) $v; } if ($this->client_ip !== $v) { $this->client_ip = $v; $this->modifiedColumns[LoginLogTableMap::COL_CLIENT_IP] = true; } return $this; }
php
public function setClientIp($v) { if ($v !== null) { $v = (string) $v; } if ($this->client_ip !== $v) { $this->client_ip = $v; $this->modifiedColumns[LoginLogTableMap::COL_CLIENT_IP] = true; } return $this; }
[ "public", "function", "setClientIp", "(", "$", "v", ")", "{", "if", "(", "$", "v", "!==", "null", ")", "{", "$", "v", "=", "(", "string", ")", "$", "v", ";", "}", "if", "(", "$", "this", "->", "client_ip", "!==", "$", "v", ")", "{", "$", "this", "->", "client_ip", "=", "$", "v", ";", "$", "this", "->", "modifiedColumns", "[", "LoginLogTableMap", "::", "COL_CLIENT_IP", "]", "=", "true", ";", "}", "return", "$", "this", ";", "}" ]
Set the value of [client_ip] column. @param string $v new value @return $this|\Alchemy\Component\Cerberus\Model\LoginLog The current object (for fluent API support)
[ "Set", "the", "value", "of", "[", "client_ip", "]", "column", "." ]
train
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/LoginLog.php#L698-L710