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
yoanm/php-jsonrpc-http-server-openapi-doc-sdk
src/App/Normalizer/Component/ExternalSchemaListDocNormalizer.php
ExternalSchemaListDocNormalizer.getMethodExternalSchemaList
protected function getMethodExternalSchemaList(MethodDoc $method) : array { $list = []; // Create request params schema if provided if (null !== $method->getParamsDoc()) { $key = $this->definitionRefResolver->getMethodDefinitionId( $method, DefinitionRefResolver::METHOD_PARAMS_DEFINITION_TYPE ); $list[$key] = $this->typeDocNormalizer->normalize($method->getParamsDoc()); } // Create custom result schema if provided if (null !== $method->getResultDoc()) { $key = $this->definitionRefResolver->getMethodDefinitionId( $method, DefinitionRefResolver::METHOD_RESULT_DEFINITION_TYPE ); $list[$key] = $this->typeDocNormalizer->normalize($method->getResultDoc()); } return $list; }
php
protected function getMethodExternalSchemaList(MethodDoc $method) : array { $list = []; // Create request params schema if provided if (null !== $method->getParamsDoc()) { $key = $this->definitionRefResolver->getMethodDefinitionId( $method, DefinitionRefResolver::METHOD_PARAMS_DEFINITION_TYPE ); $list[$key] = $this->typeDocNormalizer->normalize($method->getParamsDoc()); } // Create custom result schema if provided if (null !== $method->getResultDoc()) { $key = $this->definitionRefResolver->getMethodDefinitionId( $method, DefinitionRefResolver::METHOD_RESULT_DEFINITION_TYPE ); $list[$key] = $this->typeDocNormalizer->normalize($method->getResultDoc()); } return $list; }
[ "protected", "function", "getMethodExternalSchemaList", "(", "MethodDoc", "$", "method", ")", ":", "array", "{", "$", "list", "=", "[", "]", ";", "// Create request params schema if provided", "if", "(", "null", "!==", "$", "method", "->", "getParamsDoc", "(", ")", ")", "{", "$", "key", "=", "$", "this", "->", "definitionRefResolver", "->", "getMethodDefinitionId", "(", "$", "method", ",", "DefinitionRefResolver", "::", "METHOD_PARAMS_DEFINITION_TYPE", ")", ";", "$", "list", "[", "$", "key", "]", "=", "$", "this", "->", "typeDocNormalizer", "->", "normalize", "(", "$", "method", "->", "getParamsDoc", "(", ")", ")", ";", "}", "// Create custom result schema if provided", "if", "(", "null", "!==", "$", "method", "->", "getResultDoc", "(", ")", ")", "{", "$", "key", "=", "$", "this", "->", "definitionRefResolver", "->", "getMethodDefinitionId", "(", "$", "method", ",", "DefinitionRefResolver", "::", "METHOD_RESULT_DEFINITION_TYPE", ")", ";", "$", "list", "[", "$", "key", "]", "=", "$", "this", "->", "typeDocNormalizer", "->", "normalize", "(", "$", "method", "->", "getResultDoc", "(", ")", ")", ";", "}", "return", "$", "list", ";", "}" ]
@param MethodDoc $method @return array[] @throws \ReflectionException
[ "@param", "MethodDoc", "$method" ]
train
https://github.com/yoanm/php-jsonrpc-http-server-openapi-doc-sdk/blob/52d6bb5d0671e0363bbf482c3c75fef97d7d1d5e/src/App/Normalizer/Component/ExternalSchemaListDocNormalizer.php#L129-L151
stubbles/stubbles-webapp-core
src/main/php/routing/RoutingAnnotations.php
RoutingAnnotations.mimeTypeClasses
public function mimeTypeClasses(): array { $mimeTypeClasses = []; foreach ($this->annotations->named('SupportsMimeType') as $supportedMimeType) { if ($supportedMimeType->hasValueByName('class')) { $mimeTypeClasses[$supportedMimeType->mimeType()] = $this->nameForMimeTypeClass($supportedMimeType->class()); } } return $mimeTypeClasses; }
php
public function mimeTypeClasses(): array { $mimeTypeClasses = []; foreach ($this->annotations->named('SupportsMimeType') as $supportedMimeType) { if ($supportedMimeType->hasValueByName('class')) { $mimeTypeClasses[$supportedMimeType->mimeType()] = $this->nameForMimeTypeClass($supportedMimeType->class()); } } return $mimeTypeClasses; }
[ "public", "function", "mimeTypeClasses", "(", ")", ":", "array", "{", "$", "mimeTypeClasses", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "annotations", "->", "named", "(", "'SupportsMimeType'", ")", "as", "$", "supportedMimeType", ")", "{", "if", "(", "$", "supportedMimeType", "->", "hasValueByName", "(", "'class'", ")", ")", "{", "$", "mimeTypeClasses", "[", "$", "supportedMimeType", "->", "mimeType", "(", ")", "]", "=", "$", "this", "->", "nameForMimeTypeClass", "(", "$", "supportedMimeType", "->", "class", "(", ")", ")", ";", "}", "}", "return", "$", "mimeTypeClasses", ";", "}" ]
returns a list of all mime type classes a route supports via @SupportsMimeType @return string[] @since 5.1.0
[ "returns", "a", "list", "of", "all", "mime", "type", "classes", "a", "route", "supports", "via", "@SupportsMimeType" ]
train
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/routing/RoutingAnnotations.php#L124-L134
stubbles/stubbles-webapp-core
src/main/php/routing/RoutingAnnotations.php
RoutingAnnotations.statusCodes
public function statusCodes(): array { return array_map( function($status) { return new Status($status->getCode(), $status->getDescription()); }, $this->annotations->named('Status') ); }
php
public function statusCodes(): array { return array_map( function($status) { return new Status($status->getCode(), $status->getDescription()); }, $this->annotations->named('Status') ); }
[ "public", "function", "statusCodes", "(", ")", ":", "array", "{", "return", "array_map", "(", "function", "(", "$", "status", ")", "{", "return", "new", "Status", "(", "$", "status", "->", "getCode", "(", ")", ",", "$", "status", "->", "getDescription", "(", ")", ")", ";", "}", ",", "$", "this", "->", "annotations", "->", "named", "(", "'Status'", ")", ")", ";", "}" ]
returns list of possible status codes on this route @return stubbles\webapp\routing\api\Status[] @since 6.1.0
[ "returns", "list", "of", "possible", "status", "codes", "on", "this", "route" ]
train
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/routing/RoutingAnnotations.php#L220-L229
stubbles/stubbles-webapp-core
src/main/php/routing/RoutingAnnotations.php
RoutingAnnotations.headers
public function headers(): array { return array_map( function($header) { return new Header($header->getName(), $header->getDescription()); }, $this->annotations->named('Header') ); }
php
public function headers(): array { return array_map( function($header) { return new Header($header->getName(), $header->getDescription()); }, $this->annotations->named('Header') ); }
[ "public", "function", "headers", "(", ")", ":", "array", "{", "return", "array_map", "(", "function", "(", "$", "header", ")", "{", "return", "new", "Header", "(", "$", "header", "->", "getName", "(", ")", ",", "$", "header", "->", "getDescription", "(", ")", ")", ";", "}", ",", "$", "this", "->", "annotations", "->", "named", "(", "'Header'", ")", ")", ";", "}" ]
returns list of headers on this route @return \stubbles\webapp\routing\api\Header[] @since 6.1.0
[ "returns", "list", "of", "headers", "on", "this", "route" ]
train
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/routing/RoutingAnnotations.php#L248-L257
stubbles/stubbles-webapp-core
src/main/php/routing/RoutingAnnotations.php
RoutingAnnotations.parameters
public function parameters(): array { return array_map( function($parameter) { $param = new Parameter( $parameter->getName(), $parameter->getDescription(), $parameter->getIn() ); if ($parameter->hasValueByName('required') && $parameter->isRequired()) { $param->markRequired(); } return $param; }, $this->annotations->named('Parameter') ); }
php
public function parameters(): array { return array_map( function($parameter) { $param = new Parameter( $parameter->getName(), $parameter->getDescription(), $parameter->getIn() ); if ($parameter->hasValueByName('required') && $parameter->isRequired()) { $param->markRequired(); } return $param; }, $this->annotations->named('Parameter') ); }
[ "public", "function", "parameters", "(", ")", ":", "array", "{", "return", "array_map", "(", "function", "(", "$", "parameter", ")", "{", "$", "param", "=", "new", "Parameter", "(", "$", "parameter", "->", "getName", "(", ")", ",", "$", "parameter", "->", "getDescription", "(", ")", ",", "$", "parameter", "->", "getIn", "(", ")", ")", ";", "if", "(", "$", "parameter", "->", "hasValueByName", "(", "'required'", ")", "&&", "$", "parameter", "->", "isRequired", "(", ")", ")", "{", "$", "param", "->", "markRequired", "(", ")", ";", "}", "return", "$", "param", ";", "}", ",", "$", "this", "->", "annotations", "->", "named", "(", "'Parameter'", ")", ")", ";", "}" ]
returns list of parameters @return \stubbles\webapp\routing\api\Parameter[] @since 6.1.0
[ "returns", "list", "of", "parameters" ]
train
https://github.com/stubbles/stubbles-webapp-core/blob/7705f129011a81d5cc3c76b4b150fab3dadac6a3/src/main/php/routing/RoutingAnnotations.php#L276-L295
wizbii/pipeline
DependencyInjection/Configuration.php
Configuration.getConfigTreeBuilder
public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder->root('wizbii_pipeline'); $rootNode ->children() ->scalarNode('name')->end() ->arrayNode('connection') ->children() ->scalarNode('host')->end() ->scalarNode('port')->end() ->scalarNode('user')->end() ->scalarNode('password')->end() ->scalarNode('vhost')->end() ->end() ->end() ->arrayNode("actions") ->useAttributeAsKey('name') ->prototype("array") ->children() ->enumNode('type')->values(['direct', 'funnel'])->defaultValue('funnel')->end() ->arrayNode('triggered_by_events') ->prototype('scalar')->end() ->end() ->end() ->end() ->end() ->arrayNode("stores") ->useAttributeAsKey('name') ->prototype("array") ->children() ->scalarNode('service')->end() ->arrayNode('triggered_by_actions') ->prototype('scalar')->end() ->end() ->arrayNode('triggered_by_stores') ->prototype('scalar')->end() ->end() ->scalarNode('triggered_event')->end() ->end() ->end() ->end() ->end() ->end(); // Here you should define the parameters that are allowed to // configure your bundle. See the documentation linked above for // more information on that topic. return $treeBuilder; }
php
public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder->root('wizbii_pipeline'); $rootNode ->children() ->scalarNode('name')->end() ->arrayNode('connection') ->children() ->scalarNode('host')->end() ->scalarNode('port')->end() ->scalarNode('user')->end() ->scalarNode('password')->end() ->scalarNode('vhost')->end() ->end() ->end() ->arrayNode("actions") ->useAttributeAsKey('name') ->prototype("array") ->children() ->enumNode('type')->values(['direct', 'funnel'])->defaultValue('funnel')->end() ->arrayNode('triggered_by_events') ->prototype('scalar')->end() ->end() ->end() ->end() ->end() ->arrayNode("stores") ->useAttributeAsKey('name') ->prototype("array") ->children() ->scalarNode('service')->end() ->arrayNode('triggered_by_actions') ->prototype('scalar')->end() ->end() ->arrayNode('triggered_by_stores') ->prototype('scalar')->end() ->end() ->scalarNode('triggered_event')->end() ->end() ->end() ->end() ->end() ->end(); // Here you should define the parameters that are allowed to // configure your bundle. See the documentation linked above for // more information on that topic. return $treeBuilder; }
[ "public", "function", "getConfigTreeBuilder", "(", ")", "{", "$", "treeBuilder", "=", "new", "TreeBuilder", "(", ")", ";", "$", "rootNode", "=", "$", "treeBuilder", "->", "root", "(", "'wizbii_pipeline'", ")", ";", "$", "rootNode", "->", "children", "(", ")", "->", "scalarNode", "(", "'name'", ")", "->", "end", "(", ")", "->", "arrayNode", "(", "'connection'", ")", "->", "children", "(", ")", "->", "scalarNode", "(", "'host'", ")", "->", "end", "(", ")", "->", "scalarNode", "(", "'port'", ")", "->", "end", "(", ")", "->", "scalarNode", "(", "'user'", ")", "->", "end", "(", ")", "->", "scalarNode", "(", "'password'", ")", "->", "end", "(", ")", "->", "scalarNode", "(", "'vhost'", ")", "->", "end", "(", ")", "->", "end", "(", ")", "->", "end", "(", ")", "->", "arrayNode", "(", "\"actions\"", ")", "->", "useAttributeAsKey", "(", "'name'", ")", "->", "prototype", "(", "\"array\"", ")", "->", "children", "(", ")", "->", "enumNode", "(", "'type'", ")", "->", "values", "(", "[", "'direct'", ",", "'funnel'", "]", ")", "->", "defaultValue", "(", "'funnel'", ")", "->", "end", "(", ")", "->", "arrayNode", "(", "'triggered_by_events'", ")", "->", "prototype", "(", "'scalar'", ")", "->", "end", "(", ")", "->", "end", "(", ")", "->", "end", "(", ")", "->", "end", "(", ")", "->", "end", "(", ")", "->", "arrayNode", "(", "\"stores\"", ")", "->", "useAttributeAsKey", "(", "'name'", ")", "->", "prototype", "(", "\"array\"", ")", "->", "children", "(", ")", "->", "scalarNode", "(", "'service'", ")", "->", "end", "(", ")", "->", "arrayNode", "(", "'triggered_by_actions'", ")", "->", "prototype", "(", "'scalar'", ")", "->", "end", "(", ")", "->", "end", "(", ")", "->", "arrayNode", "(", "'triggered_by_stores'", ")", "->", "prototype", "(", "'scalar'", ")", "->", "end", "(", ")", "->", "end", "(", ")", "->", "scalarNode", "(", "'triggered_event'", ")", "->", "end", "(", ")", "->", "end", "(", ")", "->", "end", "(", ")", "->", "end", "(", ")", "->", "end", "(", ")", "->", "end", "(", ")", ";", "// Here you should define the parameters that are allowed to", "// configure your bundle. See the documentation linked above for", "// more information on that topic.", "return", "$", "treeBuilder", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/wizbii/pipeline/blob/8d22b976a53bb52abf0333b62b308ec7127cf414/DependencyInjection/Configuration.php#L18-L69
sanpii/assetic
src/Assetic/Filter/CleanCssFilter.php
CleanCssFilter.filterDump
public function filterDump(AssetInterface $asset) { $commandline = $this->getBinary(); $formats = array(); $optimizations = array(); if ($this->keepLineBreaks) { if ($this->isV4()) { $format[] = 'keep-breaks'; } else { array_push($commandline, '--keep-line-breaks'); } } if ($this->compatibility) { array_push($commandline, '--compatibility ' . $this->compatibility); } if ($this->debug) { array_push($commandline, '--debug'); } if ($this->rootPath) { if ($this->isV4()) { $this->deprecatedOption('rootPath'); } else { array_push($commandline, '--root ' . $this->rootPath); } } if ($this->skipImport) { if ($this->isV4()) { array_push($commandline, '--inline=none'); } else { array_push($commandline, '--skip-import'); } } if ($this->timeout) { if ($this->isV4()) { array_push($commandline, '--inline-timeout' . $this->timeout); } else { array_push($commandline, '--timeout ' . $this->timeout); } } if ($this->roundingPrecision) { if ($this->isV4()) { $this->deprecatedOption('roundingPrecision'); } else { array_push($commandline, '--rounding-precision ' . $this->roundingPrecision); } } if ($this->removeSpecialComments) { if ($this->isV4()) { $optimizations[] = 'specialComments:0'; } else { array_push($commandline, '--s0'); } } if ($this->onlyKeepFirstSpecialComment) { if ($this->isV4()) { $optimizations[] = 'specialComments:1'; } else { array_push($commandline, '--s1'); } } if ($this->semanticMerging) { if ($this->isV4()) { $this->deprecatedOption('semanticMerging'); } else { array_push($commandline, '--semantic-merging'); } } if ($this->skipAdvanced) { $this->deprecatedOption('skipAdvanced'); array_push($commandline, '--skip-advanced'); } if ($this->skipAggresiveMerging) { if ($this->isV4()) { $this->deprecatedOption('skipAggresiveMerging'); } else { array_push($commandline, '--skip-aggressive-merging'); } } if ($this->skipImportFrom) { $this->deprecatedOption('skipImportFrom'); array_push($commandline, '--skip-import-from ' . $this->skipImportFrom); } if ($this->mediaMerging) { if ($this->isV4()) { $this->deprecatedOption('mediaMerging'); } else { array_push($commandline, '--skip-media-merging'); } } if ($this->skipRebase) { $this->deprecatedOption('skipRebase'); array_push($commandline, '--skip-rebase'); } if ($this->skipRestructuring) { if ($this->isV4()) { $this->deprecatedOption('skipRestructuring'); } else { array_push($commandline, '--skip-restructuring'); } } if ($this->skipShorthandCompacting) { $this->deprecatedOption('skipShorthandCompacting'); array_push($commandline, '--skip-shorthand-compacting'); } if ($this->sourceMap) { array_push($commandline, '--source-map'); } if ($this->sourceMapInlineSources) { array_push($commandline, '--source-map-inline-sources'); } if (!empty($formats)) { array_push($commandline, '--format', implode(';', $formats)); } if (!empty($optimizations)) { array_push($commandline, '-O1', implode(';', $optimizations)); } // input and output files $input = tempnam(sys_get_temp_dir(), 'input'); file_put_contents($input, $asset->getContent()); array_push($commandline, $input); $proc = new Process(implode(' ', $commandline)); $code = $proc->run(); unlink($input); if (127 === $code) { throw new \RuntimeException('Path to node executable could not be resolved.'); } if (0 !== $code) { throw FilterException::fromProcess($proc)->setInput($asset->getContent()); } $asset->setContent($proc->getOutput()); }
php
public function filterDump(AssetInterface $asset) { $commandline = $this->getBinary(); $formats = array(); $optimizations = array(); if ($this->keepLineBreaks) { if ($this->isV4()) { $format[] = 'keep-breaks'; } else { array_push($commandline, '--keep-line-breaks'); } } if ($this->compatibility) { array_push($commandline, '--compatibility ' . $this->compatibility); } if ($this->debug) { array_push($commandline, '--debug'); } if ($this->rootPath) { if ($this->isV4()) { $this->deprecatedOption('rootPath'); } else { array_push($commandline, '--root ' . $this->rootPath); } } if ($this->skipImport) { if ($this->isV4()) { array_push($commandline, '--inline=none'); } else { array_push($commandline, '--skip-import'); } } if ($this->timeout) { if ($this->isV4()) { array_push($commandline, '--inline-timeout' . $this->timeout); } else { array_push($commandline, '--timeout ' . $this->timeout); } } if ($this->roundingPrecision) { if ($this->isV4()) { $this->deprecatedOption('roundingPrecision'); } else { array_push($commandline, '--rounding-precision ' . $this->roundingPrecision); } } if ($this->removeSpecialComments) { if ($this->isV4()) { $optimizations[] = 'specialComments:0'; } else { array_push($commandline, '--s0'); } } if ($this->onlyKeepFirstSpecialComment) { if ($this->isV4()) { $optimizations[] = 'specialComments:1'; } else { array_push($commandline, '--s1'); } } if ($this->semanticMerging) { if ($this->isV4()) { $this->deprecatedOption('semanticMerging'); } else { array_push($commandline, '--semantic-merging'); } } if ($this->skipAdvanced) { $this->deprecatedOption('skipAdvanced'); array_push($commandline, '--skip-advanced'); } if ($this->skipAggresiveMerging) { if ($this->isV4()) { $this->deprecatedOption('skipAggresiveMerging'); } else { array_push($commandline, '--skip-aggressive-merging'); } } if ($this->skipImportFrom) { $this->deprecatedOption('skipImportFrom'); array_push($commandline, '--skip-import-from ' . $this->skipImportFrom); } if ($this->mediaMerging) { if ($this->isV4()) { $this->deprecatedOption('mediaMerging'); } else { array_push($commandline, '--skip-media-merging'); } } if ($this->skipRebase) { $this->deprecatedOption('skipRebase'); array_push($commandline, '--skip-rebase'); } if ($this->skipRestructuring) { if ($this->isV4()) { $this->deprecatedOption('skipRestructuring'); } else { array_push($commandline, '--skip-restructuring'); } } if ($this->skipShorthandCompacting) { $this->deprecatedOption('skipShorthandCompacting'); array_push($commandline, '--skip-shorthand-compacting'); } if ($this->sourceMap) { array_push($commandline, '--source-map'); } if ($this->sourceMapInlineSources) { array_push($commandline, '--source-map-inline-sources'); } if (!empty($formats)) { array_push($commandline, '--format', implode(';', $formats)); } if (!empty($optimizations)) { array_push($commandline, '-O1', implode(';', $optimizations)); } // input and output files $input = tempnam(sys_get_temp_dir(), 'input'); file_put_contents($input, $asset->getContent()); array_push($commandline, $input); $proc = new Process(implode(' ', $commandline)); $code = $proc->run(); unlink($input); if (127 === $code) { throw new \RuntimeException('Path to node executable could not be resolved.'); } if (0 !== $code) { throw FilterException::fromProcess($proc)->setInput($asset->getContent()); } $asset->setContent($proc->getOutput()); }
[ "public", "function", "filterDump", "(", "AssetInterface", "$", "asset", ")", "{", "$", "commandline", "=", "$", "this", "->", "getBinary", "(", ")", ";", "$", "formats", "=", "array", "(", ")", ";", "$", "optimizations", "=", "array", "(", ")", ";", "if", "(", "$", "this", "->", "keepLineBreaks", ")", "{", "if", "(", "$", "this", "->", "isV4", "(", ")", ")", "{", "$", "format", "[", "]", "=", "'keep-breaks'", ";", "}", "else", "{", "array_push", "(", "$", "commandline", ",", "'--keep-line-breaks'", ")", ";", "}", "}", "if", "(", "$", "this", "->", "compatibility", ")", "{", "array_push", "(", "$", "commandline", ",", "'--compatibility '", ".", "$", "this", "->", "compatibility", ")", ";", "}", "if", "(", "$", "this", "->", "debug", ")", "{", "array_push", "(", "$", "commandline", ",", "'--debug'", ")", ";", "}", "if", "(", "$", "this", "->", "rootPath", ")", "{", "if", "(", "$", "this", "->", "isV4", "(", ")", ")", "{", "$", "this", "->", "deprecatedOption", "(", "'rootPath'", ")", ";", "}", "else", "{", "array_push", "(", "$", "commandline", ",", "'--root '", ".", "$", "this", "->", "rootPath", ")", ";", "}", "}", "if", "(", "$", "this", "->", "skipImport", ")", "{", "if", "(", "$", "this", "->", "isV4", "(", ")", ")", "{", "array_push", "(", "$", "commandline", ",", "'--inline=none'", ")", ";", "}", "else", "{", "array_push", "(", "$", "commandline", ",", "'--skip-import'", ")", ";", "}", "}", "if", "(", "$", "this", "->", "timeout", ")", "{", "if", "(", "$", "this", "->", "isV4", "(", ")", ")", "{", "array_push", "(", "$", "commandline", ",", "'--inline-timeout'", ".", "$", "this", "->", "timeout", ")", ";", "}", "else", "{", "array_push", "(", "$", "commandline", ",", "'--timeout '", ".", "$", "this", "->", "timeout", ")", ";", "}", "}", "if", "(", "$", "this", "->", "roundingPrecision", ")", "{", "if", "(", "$", "this", "->", "isV4", "(", ")", ")", "{", "$", "this", "->", "deprecatedOption", "(", "'roundingPrecision'", ")", ";", "}", "else", "{", "array_push", "(", "$", "commandline", ",", "'--rounding-precision '", ".", "$", "this", "->", "roundingPrecision", ")", ";", "}", "}", "if", "(", "$", "this", "->", "removeSpecialComments", ")", "{", "if", "(", "$", "this", "->", "isV4", "(", ")", ")", "{", "$", "optimizations", "[", "]", "=", "'specialComments:0'", ";", "}", "else", "{", "array_push", "(", "$", "commandline", ",", "'--s0'", ")", ";", "}", "}", "if", "(", "$", "this", "->", "onlyKeepFirstSpecialComment", ")", "{", "if", "(", "$", "this", "->", "isV4", "(", ")", ")", "{", "$", "optimizations", "[", "]", "=", "'specialComments:1'", ";", "}", "else", "{", "array_push", "(", "$", "commandline", ",", "'--s1'", ")", ";", "}", "}", "if", "(", "$", "this", "->", "semanticMerging", ")", "{", "if", "(", "$", "this", "->", "isV4", "(", ")", ")", "{", "$", "this", "->", "deprecatedOption", "(", "'semanticMerging'", ")", ";", "}", "else", "{", "array_push", "(", "$", "commandline", ",", "'--semantic-merging'", ")", ";", "}", "}", "if", "(", "$", "this", "->", "skipAdvanced", ")", "{", "$", "this", "->", "deprecatedOption", "(", "'skipAdvanced'", ")", ";", "array_push", "(", "$", "commandline", ",", "'--skip-advanced'", ")", ";", "}", "if", "(", "$", "this", "->", "skipAggresiveMerging", ")", "{", "if", "(", "$", "this", "->", "isV4", "(", ")", ")", "{", "$", "this", "->", "deprecatedOption", "(", "'skipAggresiveMerging'", ")", ";", "}", "else", "{", "array_push", "(", "$", "commandline", ",", "'--skip-aggressive-merging'", ")", ";", "}", "}", "if", "(", "$", "this", "->", "skipImportFrom", ")", "{", "$", "this", "->", "deprecatedOption", "(", "'skipImportFrom'", ")", ";", "array_push", "(", "$", "commandline", ",", "'--skip-import-from '", ".", "$", "this", "->", "skipImportFrom", ")", ";", "}", "if", "(", "$", "this", "->", "mediaMerging", ")", "{", "if", "(", "$", "this", "->", "isV4", "(", ")", ")", "{", "$", "this", "->", "deprecatedOption", "(", "'mediaMerging'", ")", ";", "}", "else", "{", "array_push", "(", "$", "commandline", ",", "'--skip-media-merging'", ")", ";", "}", "}", "if", "(", "$", "this", "->", "skipRebase", ")", "{", "$", "this", "->", "deprecatedOption", "(", "'skipRebase'", ")", ";", "array_push", "(", "$", "commandline", ",", "'--skip-rebase'", ")", ";", "}", "if", "(", "$", "this", "->", "skipRestructuring", ")", "{", "if", "(", "$", "this", "->", "isV4", "(", ")", ")", "{", "$", "this", "->", "deprecatedOption", "(", "'skipRestructuring'", ")", ";", "}", "else", "{", "array_push", "(", "$", "commandline", ",", "'--skip-restructuring'", ")", ";", "}", "}", "if", "(", "$", "this", "->", "skipShorthandCompacting", ")", "{", "$", "this", "->", "deprecatedOption", "(", "'skipShorthandCompacting'", ")", ";", "array_push", "(", "$", "commandline", ",", "'--skip-shorthand-compacting'", ")", ";", "}", "if", "(", "$", "this", "->", "sourceMap", ")", "{", "array_push", "(", "$", "commandline", ",", "'--source-map'", ")", ";", "}", "if", "(", "$", "this", "->", "sourceMapInlineSources", ")", "{", "array_push", "(", "$", "commandline", ",", "'--source-map-inline-sources'", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "formats", ")", ")", "{", "array_push", "(", "$", "commandline", ",", "'--format'", ",", "implode", "(", "';'", ",", "$", "formats", ")", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "optimizations", ")", ")", "{", "array_push", "(", "$", "commandline", ",", "'-O1'", ",", "implode", "(", "';'", ",", "$", "optimizations", ")", ")", ";", "}", "// input and output files", "$", "input", "=", "tempnam", "(", "sys_get_temp_dir", "(", ")", ",", "'input'", ")", ";", "file_put_contents", "(", "$", "input", ",", "$", "asset", "->", "getContent", "(", ")", ")", ";", "array_push", "(", "$", "commandline", ",", "$", "input", ")", ";", "$", "proc", "=", "new", "Process", "(", "implode", "(", "' '", ",", "$", "commandline", ")", ")", ";", "$", "code", "=", "$", "proc", "->", "run", "(", ")", ";", "unlink", "(", "$", "input", ")", ";", "if", "(", "127", "===", "$", "code", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Path to node executable could not be resolved.'", ")", ";", "}", "if", "(", "0", "!==", "$", "code", ")", "{", "throw", "FilterException", "::", "fromProcess", "(", "$", "proc", ")", "->", "setInput", "(", "$", "asset", "->", "getContent", "(", ")", ")", ";", "}", "$", "asset", "->", "setContent", "(", "$", "proc", "->", "getOutput", "(", ")", ")", ";", "}" ]
Run the asset through CleanCss @see FilterInterface::filterDump()
[ "Run", "the", "asset", "through", "CleanCss" ]
train
https://github.com/sanpii/assetic/blob/5c446eee54cc396cbbd6e252108f430e6e617c95/src/Assetic/Filter/CleanCssFilter.php#L264-L421
Laralum/Roles
src/Traits/HasRoles.php
HasRoles.hasRole
public function hasRole(Role $role) { $role = !is_string($role) ?: Role::where(['name' => $role])->firstOrFail(); if ($role) { foreach ($this->roles as $r) { if ($r->id == $role->id) { return true; } } } return false; }
php
public function hasRole(Role $role) { $role = !is_string($role) ?: Role::where(['name' => $role])->firstOrFail(); if ($role) { foreach ($this->roles as $r) { if ($r->id == $role->id) { return true; } } } return false; }
[ "public", "function", "hasRole", "(", "Role", "$", "role", ")", "{", "$", "role", "=", "!", "is_string", "(", "$", "role", ")", "?", ":", "Role", "::", "where", "(", "[", "'name'", "=>", "$", "role", "]", ")", "->", "firstOrFail", "(", ")", ";", "if", "(", "$", "role", ")", "{", "foreach", "(", "$", "this", "->", "roles", "as", "$", "r", ")", "{", "if", "(", "$", "r", "->", "id", "==", "$", "role", "->", "id", ")", "{", "return", "true", ";", "}", "}", "}", "return", "false", ";", "}" ]
Returns true if the user has the role. @param mixed $role @return bool
[ "Returns", "true", "if", "the", "user", "has", "the", "role", "." ]
train
https://github.com/Laralum/Roles/blob/f934967a5dcebebf81915dd50fccdbcb7e23c113/src/Traits/HasRoles.php#L24-L37
gregorybesson/PlaygroundCore
src/Entity/Website.php
Website.populate
public function populate($data = array()) { if (isset($data['name']) && $data['name'] !== null) { $this->name = $data['name']; } if (isset($data['code']) && $data['code'] !== null) { $this->code = $data['code']; } if (isset($data['phase']) && $data['phase'] !== null) { $this->phase = $data['phase']; } if (isset($data['active']) && $data['active'] !== null) { $this->active = $data['active']; } }
php
public function populate($data = array()) { if (isset($data['name']) && $data['name'] !== null) { $this->name = $data['name']; } if (isset($data['code']) && $data['code'] !== null) { $this->code = $data['code']; } if (isset($data['phase']) && $data['phase'] !== null) { $this->phase = $data['phase']; } if (isset($data['active']) && $data['active'] !== null) { $this->active = $data['active']; } }
[ "public", "function", "populate", "(", "$", "data", "=", "array", "(", ")", ")", "{", "if", "(", "isset", "(", "$", "data", "[", "'name'", "]", ")", "&&", "$", "data", "[", "'name'", "]", "!==", "null", ")", "{", "$", "this", "->", "name", "=", "$", "data", "[", "'name'", "]", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'code'", "]", ")", "&&", "$", "data", "[", "'code'", "]", "!==", "null", ")", "{", "$", "this", "->", "code", "=", "$", "data", "[", "'code'", "]", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'phase'", "]", ")", "&&", "$", "data", "[", "'phase'", "]", "!==", "null", ")", "{", "$", "this", "->", "phase", "=", "$", "data", "[", "'phase'", "]", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'active'", "]", ")", "&&", "$", "data", "[", "'active'", "]", "!==", "null", ")", "{", "$", "this", "->", "active", "=", "$", "data", "[", "'active'", "]", ";", "}", "}" ]
Populate from an array. @param array $data
[ "Populate", "from", "an", "array", "." ]
train
https://github.com/gregorybesson/PlaygroundCore/blob/f8dfa4c7660b54354933b3c28c0cf35304a649df/src/Entity/Website.php#L265-L279
gregorybesson/PlaygroundCore
src/Controller/Plugin/ShortenUrl.php
ShortenUrl.getService
public function getService() { if (!$this->service) { $this->setService($this->serviceLocator->get('playgroundcore_shortenurl_service')); } return $this->service; }
php
public function getService() { if (!$this->service) { $this->setService($this->serviceLocator->get('playgroundcore_shortenurl_service')); } return $this->service; }
[ "public", "function", "getService", "(", ")", "{", "if", "(", "!", "$", "this", "->", "service", ")", "{", "$", "this", "->", "setService", "(", "$", "this", "->", "serviceLocator", "->", "get", "(", "'playgroundcore_shortenurl_service'", ")", ")", ";", "}", "return", "$", "this", "->", "service", ";", "}" ]
get mapper @return Service
[ "get", "mapper" ]
train
https://github.com/gregorybesson/PlaygroundCore/blob/f8dfa4c7660b54354933b3c28c0cf35304a649df/src/Controller/Plugin/ShortenUrl.php#L53-L60
axelitus/php-base
src/Comparer.php
Comparer.compare
final public function compare($item1, $item2) { if (!$this->isReady()) { throw new \RuntimeException("The comparer is not ready, no valid callback has been set."); } return call_user_func_array($this->callback, [$item1, $item2, $this->options]); }
php
final public function compare($item1, $item2) { if (!$this->isReady()) { throw new \RuntimeException("The comparer is not ready, no valid callback has been set."); } return call_user_func_array($this->callback, [$item1, $item2, $this->options]); }
[ "final", "public", "function", "compare", "(", "$", "item1", ",", "$", "item2", ")", "{", "if", "(", "!", "$", "this", "->", "isReady", "(", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "\"The comparer is not ready, no valid callback has been set.\"", ")", ";", "}", "return", "call_user_func_array", "(", "$", "this", "->", "callback", ",", "[", "$", "item1", ",", "$", "item2", ",", "$", "this", "->", "options", "]", ")", ";", "}" ]
Compares two items. @param mixed $item1 The left operand. @param mixed $item2 The right operand. @throws \RuntimeException @return int Return <0 if $item1<$item2; 0if $item1=$item2; >1 if $item1>$item2
[ "Compares", "two", "items", "." ]
train
https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Comparer.php#L144-L151
activecollab/databasestructure
src/Field/Composite/UpdatedAtField.php
UpdatedAtField.onAddedToType
public function onAddedToType(TypeInterface &$type) { parent::onAddedToType($type); if ($this->getAddIndex()) { $type->addIndex(new Index($this->name)); } $type->addTrait(UpdatedAtInterface::class, UpdatedAtInterfaceImplementation::class)->serialize($this->name); }
php
public function onAddedToType(TypeInterface &$type) { parent::onAddedToType($type); if ($this->getAddIndex()) { $type->addIndex(new Index($this->name)); } $type->addTrait(UpdatedAtInterface::class, UpdatedAtInterfaceImplementation::class)->serialize($this->name); }
[ "public", "function", "onAddedToType", "(", "TypeInterface", "&", "$", "type", ")", "{", "parent", "::", "onAddedToType", "(", "$", "type", ")", ";", "if", "(", "$", "this", "->", "getAddIndex", "(", ")", ")", "{", "$", "type", "->", "addIndex", "(", "new", "Index", "(", "$", "this", "->", "name", ")", ")", ";", "}", "$", "type", "->", "addTrait", "(", "UpdatedAtInterface", "::", "class", ",", "UpdatedAtInterfaceImplementation", "::", "class", ")", "->", "serialize", "(", "$", "this", "->", "name", ")", ";", "}" ]
Method that is called when field is added to a type. @param TypeInterface $type
[ "Method", "that", "is", "called", "when", "field", "is", "added", "to", "a", "type", "." ]
train
https://github.com/activecollab/databasestructure/blob/4b2353c4422186bcfce63b3212da3e70e63eb5df/src/Field/Composite/UpdatedAtField.php#L64-L73
jan-dolata/crude-crud
src/Engine/Traits/FromModelTraitPart/OrderTrait.php
OrderTrait.reorder
public function reorder(array $newOrder) { $param = $this->crudeSetup->getOrderParameters(); $idAttr = $param['idAttr']; $orderAttr = $param['orderAttr']; $table = $this->model->getTable(); $data = collect($newOrder)->map(function($item) { return "({$item['id']},{$item['order']})"; })->toArray(); $data = implode(',', $data); \DB::statement("INSERT INTO {$table} (`{$idAttr}`,`{$orderAttr}`) VALUES {$data} ON DUPLICATE KEY UPDATE `{$orderAttr}`=VALUES(`{$orderAttr}`);"); }
php
public function reorder(array $newOrder) { $param = $this->crudeSetup->getOrderParameters(); $idAttr = $param['idAttr']; $orderAttr = $param['orderAttr']; $table = $this->model->getTable(); $data = collect($newOrder)->map(function($item) { return "({$item['id']},{$item['order']})"; })->toArray(); $data = implode(',', $data); \DB::statement("INSERT INTO {$table} (`{$idAttr}`,`{$orderAttr}`) VALUES {$data} ON DUPLICATE KEY UPDATE `{$orderAttr}`=VALUES(`{$orderAttr}`);"); }
[ "public", "function", "reorder", "(", "array", "$", "newOrder", ")", "{", "$", "param", "=", "$", "this", "->", "crudeSetup", "->", "getOrderParameters", "(", ")", ";", "$", "idAttr", "=", "$", "param", "[", "'idAttr'", "]", ";", "$", "orderAttr", "=", "$", "param", "[", "'orderAttr'", "]", ";", "$", "table", "=", "$", "this", "->", "model", "->", "getTable", "(", ")", ";", "$", "data", "=", "collect", "(", "$", "newOrder", ")", "->", "map", "(", "function", "(", "$", "item", ")", "{", "return", "\"({$item['id']},{$item['order']})\"", ";", "}", ")", "->", "toArray", "(", ")", ";", "$", "data", "=", "implode", "(", "','", ",", "$", "data", ")", ";", "\\", "DB", "::", "statement", "(", "\"INSERT INTO {$table} (`{$idAttr}`,`{$orderAttr}`) VALUES {$data} ON DUPLICATE KEY UPDATE `{$orderAttr}`=VALUES(`{$orderAttr}`);\"", ")", ";", "}" ]
Set new order for selected items @param array $newOrder - list of ids and new order positions
[ "Set", "new", "order", "for", "selected", "items" ]
train
https://github.com/jan-dolata/crude-crud/blob/9129ea08278835cf5cecfd46a90369226ae6bdd7/src/Engine/Traits/FromModelTraitPart/OrderTrait.php#L53-L67
acasademont/wurfl
WURFL/Handlers/AndroidHandler.php
WURFL_Handlers_AndroidHandler.getAndroidVersion
public static function getAndroidVersion($ua, $use_default=true) { // Replace Android version names with their numbers // ex: Froyo => 2.2 $ua = str_replace(array_keys(self::$androidReleaseMap), array_values(self::$androidReleaseMap), $ua); // Initializing $version $version = null; // Look for "Android <Version>" first and then for "Android/<Version>" if (preg_match('#Android (\d\.\d)#', $ua, $matches)) { $version = $matches[1]; } elseif (preg_match('#Android/(\d\.\d)#', $ua, $matches)) { $version = $matches[1]; } // Now check extracted Android version for validity if (in_array($version, self::$validAndroidVersions)) { return $version; } return $use_default? self::ANDROID_DEFAULT_VERSION: null; }
php
public static function getAndroidVersion($ua, $use_default=true) { // Replace Android version names with their numbers // ex: Froyo => 2.2 $ua = str_replace(array_keys(self::$androidReleaseMap), array_values(self::$androidReleaseMap), $ua); // Initializing $version $version = null; // Look for "Android <Version>" first and then for "Android/<Version>" if (preg_match('#Android (\d\.\d)#', $ua, $matches)) { $version = $matches[1]; } elseif (preg_match('#Android/(\d\.\d)#', $ua, $matches)) { $version = $matches[1]; } // Now check extracted Android version for validity if (in_array($version, self::$validAndroidVersions)) { return $version; } return $use_default? self::ANDROID_DEFAULT_VERSION: null; }
[ "public", "static", "function", "getAndroidVersion", "(", "$", "ua", ",", "$", "use_default", "=", "true", ")", "{", "// Replace Android version names with their numbers", "// ex: Froyo => 2.2", "$", "ua", "=", "str_replace", "(", "array_keys", "(", "self", "::", "$", "androidReleaseMap", ")", ",", "array_values", "(", "self", "::", "$", "androidReleaseMap", ")", ",", "$", "ua", ")", ";", "// Initializing $version", "$", "version", "=", "null", ";", "// Look for \"Android <Version>\" first and then for \"Android/<Version>\"", "if", "(", "preg_match", "(", "'#Android (\\d\\.\\d)#'", ",", "$", "ua", ",", "$", "matches", ")", ")", "{", "$", "version", "=", "$", "matches", "[", "1", "]", ";", "}", "elseif", "(", "preg_match", "(", "'#Android/(\\d\\.\\d)#'", ",", "$", "ua", ",", "$", "matches", ")", ")", "{", "$", "version", "=", "$", "matches", "[", "1", "]", ";", "}", "// Now check extracted Android version for validity", "if", "(", "in_array", "(", "$", "version", ",", "self", "::", "$", "validAndroidVersions", ")", ")", "{", "return", "$", "version", ";", "}", "return", "$", "use_default", "?", "self", "::", "ANDROID_DEFAULT_VERSION", ":", "null", ";", "}" ]
Get the Android version from the User Agent, or the default Android version is it cannot be determined @param string $ua User Agent @param boolean $use_default Return the default version on fail, else return null @return string Android version @see self::ANDROID_DEFAULT_VERSION
[ "Get", "the", "Android", "version", "from", "the", "User", "Agent", "or", "the", "default", "Android", "version", "is", "it", "cannot", "be", "determined" ]
train
https://github.com/acasademont/wurfl/blob/0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2/WURFL/Handlers/AndroidHandler.php#L154-L175
bluelyte/transmission-remote
src/Remote.php
Remote.setPort
public function setPort($port) { if (!ctype_digit($port)) { trigger_error('Port must be a positive integer: ' . var_export($port, true), E_USER_ERROR); } $this->port = $port; }
php
public function setPort($port) { if (!ctype_digit($port)) { trigger_error('Port must be a positive integer: ' . var_export($port, true), E_USER_ERROR); } $this->port = $port; }
[ "public", "function", "setPort", "(", "$", "port", ")", "{", "if", "(", "!", "ctype_digit", "(", "$", "port", ")", ")", "{", "trigger_error", "(", "'Port must be a positive integer: '", ".", "var_export", "(", "$", "port", ",", "true", ")", ",", "E_USER_ERROR", ")", ";", "}", "$", "this", "->", "port", "=", "$", "port", ";", "}" ]
Sets the port on which to operate the daemon. @param string $port
[ "Sets", "the", "port", "on", "which", "to", "operate", "the", "daemon", "." ]
train
https://github.com/bluelyte/transmission-remote/blob/82683b8b9101f623dbd6c1923348cff00380250c/src/Remote.php#L83-L89
bluelyte/transmission-remote
src/Remote.php
Remote.setDownloadPath
public function setDownloadPath($downloadPath) { if (!is_dir($downloadPath) || !is_writable($downloadPath)) { trigger_error('Cannot write to directory: ' . $downloadPath, E_USER_ERROR); } $this->downloadPath = $downloadPath; }
php
public function setDownloadPath($downloadPath) { if (!is_dir($downloadPath) || !is_writable($downloadPath)) { trigger_error('Cannot write to directory: ' . $downloadPath, E_USER_ERROR); } $this->downloadPath = $downloadPath; }
[ "public", "function", "setDownloadPath", "(", "$", "downloadPath", ")", "{", "if", "(", "!", "is_dir", "(", "$", "downloadPath", ")", "||", "!", "is_writable", "(", "$", "downloadPath", ")", ")", "{", "trigger_error", "(", "'Cannot write to directory: '", ".", "$", "downloadPath", ",", "E_USER_ERROR", ")", ";", "}", "$", "this", "->", "downloadPath", "=", "$", "downloadPath", ";", "}" ]
Sets the path at which to store downloaded files. @param string $downloadPath
[ "Sets", "the", "path", "at", "which", "to", "store", "downloaded", "files", "." ]
train
https://github.com/bluelyte/transmission-remote/blob/82683b8b9101f623dbd6c1923348cff00380250c/src/Remote.php#L106-L112
bluelyte/transmission-remote
src/Remote.php
Remote.execute
protected function execute($command) { $process = proc_open($command, array(1 => array('pipe', 'w'), 2 => array('pipe', 'w')), $pipes); fclose($pipes[2]); $this->output = stream_get_contents($pipes[1]); fclose($pipes[1]); $status = proc_get_status($process); $this->status = $status['exitcode']; proc_close($process); }
php
protected function execute($command) { $process = proc_open($command, array(1 => array('pipe', 'w'), 2 => array('pipe', 'w')), $pipes); fclose($pipes[2]); $this->output = stream_get_contents($pipes[1]); fclose($pipes[1]); $status = proc_get_status($process); $this->status = $status['exitcode']; proc_close($process); }
[ "protected", "function", "execute", "(", "$", "command", ")", "{", "$", "process", "=", "proc_open", "(", "$", "command", ",", "array", "(", "1", "=>", "array", "(", "'pipe'", ",", "'w'", ")", ",", "2", "=>", "array", "(", "'pipe'", ",", "'w'", ")", ")", ",", "$", "pipes", ")", ";", "fclose", "(", "$", "pipes", "[", "2", "]", ")", ";", "$", "this", "->", "output", "=", "stream_get_contents", "(", "$", "pipes", "[", "1", "]", ")", ";", "fclose", "(", "$", "pipes", "[", "1", "]", ")", ";", "$", "status", "=", "proc_get_status", "(", "$", "process", ")", ";", "$", "this", "->", "status", "=", "$", "status", "[", "'exitcode'", "]", ";", "proc_close", "(", "$", "process", ")", ";", "}" ]
Execute a shell command. @param string $command
[ "Execute", "a", "shell", "command", "." ]
train
https://github.com/bluelyte/transmission-remote/blob/82683b8b9101f623dbd6c1923348cff00380250c/src/Remote.php#L131-L140
bluelyte/transmission-remote
src/Remote.php
Remote.start
public function start() { if ($this->started) { return; } $auth = $this->getAuthFlag(); $command = 'transmission-remote -C ' . $auth . ' -' . ($this->encryption ? 'er' : 'ep') . ' -p ' . $this->port . ' -' . ($this->upnp ? 'm' : 'M') . ($this->downloadPath ? ' -w ' . $this->downloadPath : ''); $this->execute($command); $this->execute('transmission-remote ' . $auth . ' -l'); if ($this->getStatus() == 1) { $this->execute('transmission-daemon'); } $this->started = true; }
php
public function start() { if ($this->started) { return; } $auth = $this->getAuthFlag(); $command = 'transmission-remote -C ' . $auth . ' -' . ($this->encryption ? 'er' : 'ep') . ' -p ' . $this->port . ' -' . ($this->upnp ? 'm' : 'M') . ($this->downloadPath ? ' -w ' . $this->downloadPath : ''); $this->execute($command); $this->execute('transmission-remote ' . $auth . ' -l'); if ($this->getStatus() == 1) { $this->execute('transmission-daemon'); } $this->started = true; }
[ "public", "function", "start", "(", ")", "{", "if", "(", "$", "this", "->", "started", ")", "{", "return", ";", "}", "$", "auth", "=", "$", "this", "->", "getAuthFlag", "(", ")", ";", "$", "command", "=", "'transmission-remote -C '", ".", "$", "auth", ".", "' -'", ".", "(", "$", "this", "->", "encryption", "?", "'er'", ":", "'ep'", ")", ".", "' -p '", ".", "$", "this", "->", "port", ".", "' -'", ".", "(", "$", "this", "->", "upnp", "?", "'m'", ":", "'M'", ")", ".", "(", "$", "this", "->", "downloadPath", "?", "' -w '", ".", "$", "this", "->", "downloadPath", ":", "''", ")", ";", "$", "this", "->", "execute", "(", "$", "command", ")", ";", "$", "this", "->", "execute", "(", "'transmission-remote '", ".", "$", "auth", ".", "' -l'", ")", ";", "if", "(", "$", "this", "->", "getStatus", "(", ")", "==", "1", ")", "{", "$", "this", "->", "execute", "(", "'transmission-daemon'", ")", ";", "}", "$", "this", "->", "started", "=", "true", ";", "}" ]
Starts the daemon.
[ "Starts", "the", "daemon", "." ]
train
https://github.com/bluelyte/transmission-remote/blob/82683b8b9101f623dbd6c1923348cff00380250c/src/Remote.php#L175-L196
bluelyte/transmission-remote
src/Remote.php
Remote.addTorrents
public function addTorrents($paths) { if (is_array($paths)) { $paths = implode(' ', $paths); } $this->execute('transmission-remote ' . $this->getAuthFlag() . ' -a ' . $paths); }
php
public function addTorrents($paths) { if (is_array($paths)) { $paths = implode(' ', $paths); } $this->execute('transmission-remote ' . $this->getAuthFlag() . ' -a ' . $paths); }
[ "public", "function", "addTorrents", "(", "$", "paths", ")", "{", "if", "(", "is_array", "(", "$", "paths", ")", ")", "{", "$", "paths", "=", "implode", "(", "' '", ",", "$", "paths", ")", ";", "}", "$", "this", "->", "execute", "(", "'transmission-remote '", ".", "$", "this", "->", "getAuthFlag", "(", ")", ".", "' -a '", ".", "$", "paths", ")", ";", "}" ]
Adds a torrent to download. @param string|array $path Space-delimited list or array of paths to one or more .torrent files
[ "Adds", "a", "torrent", "to", "download", "." ]
train
https://github.com/bluelyte/transmission-remote/blob/82683b8b9101f623dbd6c1923348cff00380250c/src/Remote.php#L204-L210
dreamcommerce/common-bundle
src/DreamCommerce/Component/Common/Http/GuzzleClient.php
GuzzleClient.send
public function send(RequestInterface $request, array $options = array()): ResponseInterface { return $this->guzzleClient->send($request, $options); }
php
public function send(RequestInterface $request, array $options = array()): ResponseInterface { return $this->guzzleClient->send($request, $options); }
[ "public", "function", "send", "(", "RequestInterface", "$", "request", ",", "array", "$", "options", "=", "array", "(", ")", ")", ":", "ResponseInterface", "{", "return", "$", "this", "->", "guzzleClient", "->", "send", "(", "$", "request", ",", "$", "options", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/dreamcommerce/common-bundle/blob/adb0850e90e63c3997f10d1ce110bf13a84b63ab/src/DreamCommerce/Component/Common/Http/GuzzleClient.php#L42-L45
dreamcommerce/common-bundle
src/DreamCommerce/Component/Common/Http/GuzzleClient.php
GuzzleClient.request
public function request(string $method, $uri, array $options = array()): ResponseInterface { return $this->guzzleClient->request($method, $uri, $options); }
php
public function request(string $method, $uri, array $options = array()): ResponseInterface { return $this->guzzleClient->request($method, $uri, $options); }
[ "public", "function", "request", "(", "string", "$", "method", ",", "$", "uri", ",", "array", "$", "options", "=", "array", "(", ")", ")", ":", "ResponseInterface", "{", "return", "$", "this", "->", "guzzleClient", "->", "request", "(", "$", "method", ",", "$", "uri", ",", "$", "options", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/dreamcommerce/common-bundle/blob/adb0850e90e63c3997f10d1ce110bf13a84b63ab/src/DreamCommerce/Component/Common/Http/GuzzleClient.php#L50-L53
braincrafted/arrayquery
src/Braincrafted/ArrayQuery/Filter/ReplaceFilter.php
ReplaceFilter.evaluate
public function evaluate($value, array $args = array()) { if (false === isset($args[0]) || false === isset($args[1])) { throw new \InvalidArgumentException('replace requires two arguments'); } return str_replace($args[0], $args[1], $value); }
php
public function evaluate($value, array $args = array()) { if (false === isset($args[0]) || false === isset($args[1])) { throw new \InvalidArgumentException('replace requires two arguments'); } return str_replace($args[0], $args[1], $value); }
[ "public", "function", "evaluate", "(", "$", "value", ",", "array", "$", "args", "=", "array", "(", ")", ")", "{", "if", "(", "false", "===", "isset", "(", "$", "args", "[", "0", "]", ")", "||", "false", "===", "isset", "(", "$", "args", "[", "1", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'replace requires two arguments'", ")", ";", "}", "return", "str_replace", "(", "$", "args", "[", "0", "]", ",", "$", "args", "[", "1", "]", ",", "$", "value", ")", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/braincrafted/arrayquery/blob/8b0c44ee76cea796589422f52e2f7130676b9bd1/src/Braincrafted/ArrayQuery/Filter/ReplaceFilter.php#L36-L43
jasny/router
src/Router/UrlParsing.php
UrlParsing.splitUrl
protected function splitUrl($url) { $path = parse_url(trim($url, '/'), PHP_URL_PATH); return $path ? explode('/', $path) : array(); }
php
protected function splitUrl($url) { $path = parse_url(trim($url, '/'), PHP_URL_PATH); return $path ? explode('/', $path) : array(); }
[ "protected", "function", "splitUrl", "(", "$", "url", ")", "{", "$", "path", "=", "parse_url", "(", "trim", "(", "$", "url", ",", "'/'", ")", ",", "PHP_URL_PATH", ")", ";", "return", "$", "path", "?", "explode", "(", "'/'", ",", "$", "path", ")", ":", "array", "(", ")", ";", "}" ]
Get parts of a URL path @param string $url @return array
[ "Get", "parts", "of", "a", "URL", "path" ]
train
https://github.com/jasny/router/blob/4c776665ba343150b442c21893946e3d54190896/src/Router/UrlParsing.php#L16-L20
vincentchalamon/VinceCmsSonataAdminBundle
Form/Type/TemplateType.php
TemplateType.buildForm
public function buildForm(FormBuilderInterface $builder, array $options) { $builder->addViewTransformer(new ContentsTransformer($this->repository, $this->class)); $list = $this->repository->createQueryBuilder('t') ->innerJoin('t.areas', 'a')->addSelect('a') ->getQuery()->execute(); foreach ($list as $template) { /** @var Template $template */ $builder->add($template->getSlug(), 'area', array( 'label' => false, 'areas' => $template->getAreas(), 'attr' => array('template_id' => $template->getId()), ) ); } }
php
public function buildForm(FormBuilderInterface $builder, array $options) { $builder->addViewTransformer(new ContentsTransformer($this->repository, $this->class)); $list = $this->repository->createQueryBuilder('t') ->innerJoin('t.areas', 'a')->addSelect('a') ->getQuery()->execute(); foreach ($list as $template) { /** @var Template $template */ $builder->add($template->getSlug(), 'area', array( 'label' => false, 'areas' => $template->getAreas(), 'attr' => array('template_id' => $template->getId()), ) ); } }
[ "public", "function", "buildForm", "(", "FormBuilderInterface", "$", "builder", ",", "array", "$", "options", ")", "{", "$", "builder", "->", "addViewTransformer", "(", "new", "ContentsTransformer", "(", "$", "this", "->", "repository", ",", "$", "this", "->", "class", ")", ")", ";", "$", "list", "=", "$", "this", "->", "repository", "->", "createQueryBuilder", "(", "'t'", ")", "->", "innerJoin", "(", "'t.areas'", ",", "'a'", ")", "->", "addSelect", "(", "'a'", ")", "->", "getQuery", "(", ")", "->", "execute", "(", ")", ";", "foreach", "(", "$", "list", "as", "$", "template", ")", "{", "/** @var Template $template */", "$", "builder", "->", "add", "(", "$", "template", "->", "getSlug", "(", ")", ",", "'area'", ",", "array", "(", "'label'", "=>", "false", ",", "'areas'", "=>", "$", "template", "->", "getAreas", "(", ")", ",", "'attr'", "=>", "array", "(", "'template_id'", "=>", "$", "template", "->", "getId", "(", ")", ")", ",", ")", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/vincentchalamon/VinceCmsSonataAdminBundle/blob/edc768061734a92ba116488dd7b61ad40af21ceb/Form/Type/TemplateType.php#L75-L90
dengyongbin/loopeer-lib
src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/AssertHelper.php
AssertHelper.type
private function type($value, $type) { switch (func_num_args()) { case 0 : case 1 : return false; case 2 : // 二个参数时, 才执行正常处理逻辑 if (is_array($type)) { foreach ( $type as $t ) { if ($this -> type($value, $t)) { return true; } } return false; } $t = strtolower(gettype($value)); $type = strtolower($type); if ($type == $t) { return true; } else if ($type == 'mixed') { return true; } else { switch ($t) { case "integer" : if ($type == 'int') { return true; } case "double" : return $type == 'number'; case "boolean" : return $type == 'bool'; case "user function" : return $type == 'function'; case "string" : case "array" : case "object" : case "resource" : case "null" : case "unknown type" : default : return false; } } return false; default : // 多于两个参数,认为第二个及其后的统统为可能的值. $varList = func_get_args(); $value = array_shift($varList); return $this -> type($value, $varList); } }
php
private function type($value, $type) { switch (func_num_args()) { case 0 : case 1 : return false; case 2 : // 二个参数时, 才执行正常处理逻辑 if (is_array($type)) { foreach ( $type as $t ) { if ($this -> type($value, $t)) { return true; } } return false; } $t = strtolower(gettype($value)); $type = strtolower($type); if ($type == $t) { return true; } else if ($type == 'mixed') { return true; } else { switch ($t) { case "integer" : if ($type == 'int') { return true; } case "double" : return $type == 'number'; case "boolean" : return $type == 'bool'; case "user function" : return $type == 'function'; case "string" : case "array" : case "object" : case "resource" : case "null" : case "unknown type" : default : return false; } } return false; default : // 多于两个参数,认为第二个及其后的统统为可能的值. $varList = func_get_args(); $value = array_shift($varList); return $this -> type($value, $varList); } }
[ "private", "function", "type", "(", "$", "value", ",", "$", "type", ")", "{", "switch", "(", "func_num_args", "(", ")", ")", "{", "case", "0", ":", "case", "1", ":", "return", "false", ";", "case", "2", ":", "// 二个参数时, 才执行正常处理逻辑", "if", "(", "is_array", "(", "$", "type", ")", ")", "{", "foreach", "(", "$", "type", "as", "$", "t", ")", "{", "if", "(", "$", "this", "->", "type", "(", "$", "value", ",", "$", "t", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}", "$", "t", "=", "strtolower", "(", "gettype", "(", "$", "value", ")", ")", ";", "$", "type", "=", "strtolower", "(", "$", "type", ")", ";", "if", "(", "$", "type", "==", "$", "t", ")", "{", "return", "true", ";", "}", "else", "if", "(", "$", "type", "==", "'mixed'", ")", "{", "return", "true", ";", "}", "else", "{", "switch", "(", "$", "t", ")", "{", "case", "\"integer\"", ":", "if", "(", "$", "type", "==", "'int'", ")", "{", "return", "true", ";", "}", "case", "\"double\"", ":", "return", "$", "type", "==", "'number'", ";", "case", "\"boolean\"", ":", "return", "$", "type", "==", "'bool'", ";", "case", "\"user function\"", ":", "return", "$", "type", "==", "'function'", ";", "case", "\"string\"", ":", "case", "\"array\"", ":", "case", "\"object\"", ":", "case", "\"resource\"", ":", "case", "\"null\"", ":", "case", "\"unknown type\"", ":", "default", ":", "return", "false", ";", "}", "}", "return", "false", ";", "default", ":", "// 多于两个参数,认为第二个及其后的统统为可能的值.", "$", "varList", "=", "func_get_args", "(", ")", ";", "$", "value", "=", "array_shift", "(", "$", "varList", ")", ";", "return", "$", "this", "->", "type", "(", "$", "value", ",", "$", "varList", ")", ";", "}", "}" ]
检查变量类型是否为指定类型; @param mixed $value @param string | array $type @return boolean
[ "检查变量类型是否为指定类型", ";" ]
train
https://github.com/dengyongbin/loopeer-lib/blob/4609338f6a48666ca96ee380509a5b5cb066808f/src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/AssertHelper.php#L61-L117
dengyongbin/loopeer-lib
src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/AssertHelper.php
AssertHelper.between
private function between($value, $min = null, $max = null) { $value = intval($value); if ($min !== null && $max !== null) { return $value >= intval($min) && $value <= intval($max); } if ($min !== null) { return intval($min) <= $value; } if ($max !== null) { return $value <= intval($max); } return false; }
php
private function between($value, $min = null, $max = null) { $value = intval($value); if ($min !== null && $max !== null) { return $value >= intval($min) && $value <= intval($max); } if ($min !== null) { return intval($min) <= $value; } if ($max !== null) { return $value <= intval($max); } return false; }
[ "private", "function", "between", "(", "$", "value", ",", "$", "min", "=", "null", ",", "$", "max", "=", "null", ")", "{", "$", "value", "=", "intval", "(", "$", "value", ")", ";", "if", "(", "$", "min", "!==", "null", "&&", "$", "max", "!==", "null", ")", "{", "return", "$", "value", ">=", "intval", "(", "$", "min", ")", "&&", "$", "value", "<=", "intval", "(", "$", "max", ")", ";", "}", "if", "(", "$", "min", "!==", "null", ")", "{", "return", "intval", "(", "$", "min", ")", "<=", "$", "value", ";", "}", "if", "(", "$", "max", "!==", "null", ")", "{", "return", "$", "value", "<=", "intval", "(", "$", "max", ")", ";", "}", "return", "false", ";", "}" ]
断言一个数值在另外两个数值之间 @param int $value @param int $min @param int $max @return boolean
[ "断言一个数值在另外两个数值之间" ]
train
https://github.com/dengyongbin/loopeer-lib/blob/4609338f6a48666ca96ee380509a5b5cb066808f/src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/AssertHelper.php#L149-L165
dengyongbin/loopeer-lib
src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/AssertHelper.php
AssertHelper.match
private function match($value, $regStr) { return $this -> type($value, 'string', 'number') && ($this -> equal($value, $regStr) || (preg_match(strval($regStr), strval($value)) > 0)); }
php
private function match($value, $regStr) { return $this -> type($value, 'string', 'number') && ($this -> equal($value, $regStr) || (preg_match(strval($regStr), strval($value)) > 0)); }
[ "private", "function", "match", "(", "$", "value", ",", "$", "regStr", ")", "{", "return", "$", "this", "->", "type", "(", "$", "value", ",", "'string'", ",", "'number'", ")", "&&", "(", "$", "this", "->", "equal", "(", "$", "value", ",", "$", "regStr", ")", "||", "(", "preg_match", "(", "strval", "(", "$", "regStr", ")", ",", "strval", "(", "$", "value", ")", ")", ">", "0", ")", ")", ";", "}" ]
断言一个字符串匹配指定的正则表达式格式 @param string $value @param regexpString $regStr @return boolean
[ "断言一个字符串匹配指定的正则表达式格式" ]
train
https://github.com/dengyongbin/loopeer-lib/blob/4609338f6a48666ca96ee380509a5b5cb066808f/src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/AssertHelper.php#L173-L175
dengyongbin/loopeer-lib
src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/AssertHelper.php
AssertHelper.not
private function not($value) { switch (func_num_args()) { case 0 : return true; case 1 : return ! $value; case 2 : $varList = func_get_arg(1); if (is_array($varList)) { return $this -> not($this -> maybe($value, $varList)); } return $value == $varList; default : $varList = func_get_args(); $value = array_shift($varList); return $this -> not($this -> maybe($value, $varList)); } }
php
private function not($value) { switch (func_num_args()) { case 0 : return true; case 1 : return ! $value; case 2 : $varList = func_get_arg(1); if (is_array($varList)) { return $this -> not($this -> maybe($value, $varList)); } return $value == $varList; default : $varList = func_get_args(); $value = array_shift($varList); return $this -> not($this -> maybe($value, $varList)); } }
[ "private", "function", "not", "(", "$", "value", ")", "{", "switch", "(", "func_num_args", "(", ")", ")", "{", "case", "0", ":", "return", "true", ";", "case", "1", ":", "return", "!", "$", "value", ";", "case", "2", ":", "$", "varList", "=", "func_get_arg", "(", "1", ")", ";", "if", "(", "is_array", "(", "$", "varList", ")", ")", "{", "return", "$", "this", "->", "not", "(", "$", "this", "->", "maybe", "(", "$", "value", ",", "$", "varList", ")", ")", ";", "}", "return", "$", "value", "==", "$", "varList", ";", "default", ":", "$", "varList", "=", "func_get_args", "(", ")", ";", "$", "value", "=", "array_shift", "(", "$", "varList", ")", ";", "return", "$", "this", "->", "not", "(", "$", "this", "->", "maybe", "(", "$", "value", ",", "$", "varList", ")", ")", ";", "}", "}" ]
断言不等于或非 @param mixed $value @param mixed $checkValue @return boolean
[ "断言不等于或非" ]
train
https://github.com/dengyongbin/loopeer-lib/blob/4609338f6a48666ca96ee380509a5b5cb066808f/src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/AssertHelper.php#L201-L221
dengyongbin/loopeer-lib
src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/AssertHelper.php
AssertHelper.maybe
private function maybe($value, $varList) { switch(func_num_args()){ case 0: return false; case 1: return !!$value; case 2: if (is_array($varList)) { return array_search($value, $varList, true) !== false; } return $value == $varList; default: $varList = func_get_args(); $value = array_shift($varList); return $this->maybe($value, $varList); } }
php
private function maybe($value, $varList) { switch(func_num_args()){ case 0: return false; case 1: return !!$value; case 2: if (is_array($varList)) { return array_search($value, $varList, true) !== false; } return $value == $varList; default: $varList = func_get_args(); $value = array_shift($varList); return $this->maybe($value, $varList); } }
[ "private", "function", "maybe", "(", "$", "value", ",", "$", "varList", ")", "{", "switch", "(", "func_num_args", "(", ")", ")", "{", "case", "0", ":", "return", "false", ";", "case", "1", ":", "return", "!", "!", "$", "value", ";", "case", "2", ":", "if", "(", "is_array", "(", "$", "varList", ")", ")", "{", "return", "array_search", "(", "$", "value", ",", "$", "varList", ",", "true", ")", "!==", "false", ";", "}", "return", "$", "value", "==", "$", "varList", ";", "default", ":", "$", "varList", "=", "func_get_args", "(", ")", ";", "$", "value", "=", "array_shift", "(", "$", "varList", ")", ";", "return", "$", "this", "->", "maybe", "(", "$", "value", ",", "$", "varList", ")", ";", "}", "}" ]
断言一个值在给定的一组值之中. 如果只给定一个非数组的值, 那么则进行equal判断; @param mixed $value @param mixed $varList @return boolean
[ "断言一个值在给定的一组值之中", ".", "如果只给定一个非数组的值", "那么则进行equal判断", ";" ]
train
https://github.com/dengyongbin/loopeer-lib/blob/4609338f6a48666ca96ee380509a5b5cb066808f/src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/AssertHelper.php#L229-L245
dengyongbin/loopeer-lib
src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/AssertHelper.php
AssertHelper.possible
private function possible($value,$conditions = true){ switch(func_num_args()){ case 0: return false; case 1: return !!$value; case 2: if (is_array($conditions)) { $notInAssert = true; foreach ( $conditions as $type => $checkValue ) { if ($this -> maybe($type, $this -> checkName)) { // mark the process type $notInAssert = $notInAssert || true; if (is_array($checkValue)) { array_unshift($checkValue, $value); } else { $checkValue = array ( $value, $checkValue, ); } // call other assert, if true return else continue; if (call_user_func_array(array ( $this, $type, ), $checkValue)) { return true; } } } // 如果未进行过assert判断,则进行value search return $notInAssert ? $this -> maybe($value, $conditions) : false; } return $value == $conditions; default: $conditions = func_get_args(); $value = array_shift($conditions); foreach ($conditions as $c){ if($this->possible($value, $c)){ return true; } } // 如果未进行过assert判断,则进行value search return $this->maybe($value, $conditions); } }
php
private function possible($value,$conditions = true){ switch(func_num_args()){ case 0: return false; case 1: return !!$value; case 2: if (is_array($conditions)) { $notInAssert = true; foreach ( $conditions as $type => $checkValue ) { if ($this -> maybe($type, $this -> checkName)) { // mark the process type $notInAssert = $notInAssert || true; if (is_array($checkValue)) { array_unshift($checkValue, $value); } else { $checkValue = array ( $value, $checkValue, ); } // call other assert, if true return else continue; if (call_user_func_array(array ( $this, $type, ), $checkValue)) { return true; } } } // 如果未进行过assert判断,则进行value search return $notInAssert ? $this -> maybe($value, $conditions) : false; } return $value == $conditions; default: $conditions = func_get_args(); $value = array_shift($conditions); foreach ($conditions as $c){ if($this->possible($value, $c)){ return true; } } // 如果未进行过assert判断,则进行value search return $this->maybe($value, $conditions); } }
[ "private", "function", "possible", "(", "$", "value", ",", "$", "conditions", "=", "true", ")", "{", "switch", "(", "func_num_args", "(", ")", ")", "{", "case", "0", ":", "return", "false", ";", "case", "1", ":", "return", "!", "!", "$", "value", ";", "case", "2", ":", "if", "(", "is_array", "(", "$", "conditions", ")", ")", "{", "$", "notInAssert", "=", "true", ";", "foreach", "(", "$", "conditions", "as", "$", "type", "=>", "$", "checkValue", ")", "{", "if", "(", "$", "this", "->", "maybe", "(", "$", "type", ",", "$", "this", "->", "checkName", ")", ")", "{", "// mark the process type", "$", "notInAssert", "=", "$", "notInAssert", "||", "true", ";", "if", "(", "is_array", "(", "$", "checkValue", ")", ")", "{", "array_unshift", "(", "$", "checkValue", ",", "$", "value", ")", ";", "}", "else", "{", "$", "checkValue", "=", "array", "(", "$", "value", ",", "$", "checkValue", ",", ")", ";", "}", "// call other assert, if true return else continue;", "if", "(", "call_user_func_array", "(", "array", "(", "$", "this", ",", "$", "type", ",", ")", ",", "$", "checkValue", ")", ")", "{", "return", "true", ";", "}", "}", "}", "// 如果未进行过assert判断,则进行value search", "return", "$", "notInAssert", "?", "$", "this", "->", "maybe", "(", "$", "value", ",", "$", "conditions", ")", ":", "false", ";", "}", "return", "$", "value", "==", "$", "conditions", ";", "default", ":", "$", "conditions", "=", "func_get_args", "(", ")", ";", "$", "value", "=", "array_shift", "(", "$", "conditions", ")", ";", "foreach", "(", "$", "conditions", "as", "$", "c", ")", "{", "if", "(", "$", "this", "->", "possible", "(", "$", "value", ",", "$", "c", ")", ")", "{", "return", "true", ";", "}", "}", "// 如果未进行过assert判断,则进行value search", "return", "$", "this", "->", "maybe", "(", "$", "value", ",", "$", "conditions", ")", ";", "}", "}" ]
断言一个值会符合一组条件中的任意一项. @param unknown $value @param unknown $condition @return boolean
[ "断言一个值会符合一组条件中的任意一项", "." ]
train
https://github.com/dengyongbin/loopeer-lib/blob/4609338f6a48666ca96ee380509a5b5cb066808f/src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/AssertHelper.php#L252-L305
dengyongbin/loopeer-lib
src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/AssertHelper.php
AssertHelper.makesure
private function makesure($value, $conditions = false) { switch (func_num_args()) { case 0 : return false; case 1 : return ! ! $value; case 2 : if (is_array($conditions)) { // 必须全部返回true, 结果才能为true; 任意false结果为false foreach ( $conditions as $type => $checkValue ) { // 可以调用断言 if ($this -> maybe($type, $this -> checkName)) { // print_r($type); // print_r($conditions); if (is_array($checkValue)) { array_unshift($checkValue, $value); } else { $checkValue = array ( $value, $checkValue, ); } // call other assert, if true return else continue; if (! call_user_func_array(array ( $this, $type, ), $checkValue)) { return false; } } else { // 如果任意值不能调用assert判断, 直接判断值相等.. 如果不等, 直接返回false if ($value !== $type) { return false; } } } return true; } return $value == $conditions; } }
php
private function makesure($value, $conditions = false) { switch (func_num_args()) { case 0 : return false; case 1 : return ! ! $value; case 2 : if (is_array($conditions)) { // 必须全部返回true, 结果才能为true; 任意false结果为false foreach ( $conditions as $type => $checkValue ) { // 可以调用断言 if ($this -> maybe($type, $this -> checkName)) { // print_r($type); // print_r($conditions); if (is_array($checkValue)) { array_unshift($checkValue, $value); } else { $checkValue = array ( $value, $checkValue, ); } // call other assert, if true return else continue; if (! call_user_func_array(array ( $this, $type, ), $checkValue)) { return false; } } else { // 如果任意值不能调用assert判断, 直接判断值相等.. 如果不等, 直接返回false if ($value !== $type) { return false; } } } return true; } return $value == $conditions; } }
[ "private", "function", "makesure", "(", "$", "value", ",", "$", "conditions", "=", "false", ")", "{", "switch", "(", "func_num_args", "(", ")", ")", "{", "case", "0", ":", "return", "false", ";", "case", "1", ":", "return", "!", "!", "$", "value", ";", "case", "2", ":", "if", "(", "is_array", "(", "$", "conditions", ")", ")", "{", "// 必须全部返回true, 结果才能为true; 任意false结果为false", "foreach", "(", "$", "conditions", "as", "$", "type", "=>", "$", "checkValue", ")", "{", "// 可以调用断言", "if", "(", "$", "this", "->", "maybe", "(", "$", "type", ",", "$", "this", "->", "checkName", ")", ")", "{", "// print_r($type);", "// print_r($conditions);", "if", "(", "is_array", "(", "$", "checkValue", ")", ")", "{", "array_unshift", "(", "$", "checkValue", ",", "$", "value", ")", ";", "}", "else", "{", "$", "checkValue", "=", "array", "(", "$", "value", ",", "$", "checkValue", ",", ")", ";", "}", "// call other assert, if true return else continue;", "if", "(", "!", "call_user_func_array", "(", "array", "(", "$", "this", ",", "$", "type", ",", ")", ",", "$", "checkValue", ")", ")", "{", "return", "false", ";", "}", "}", "else", "{", "// 如果任意值不能调用assert判断, 直接判断值相等.. 如果不等, 直接返回false", "if", "(", "$", "value", "!==", "$", "type", ")", "{", "return", "false", ";", "}", "}", "}", "return", "true", ";", "}", "return", "$", "value", "==", "$", "conditions", ";", "}", "}" ]
判断一个值是否完全符合一组条件 @param mixed $value @param array $conditions @return boolean
[ "判断一个值是否完全符合一组条件" ]
train
https://github.com/dengyongbin/loopeer-lib/blob/4609338f6a48666ca96ee380509a5b5cb066808f/src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/AssertHelper.php#L312-L358
esperecyan/dictionary-php
src/Parser.php
Parser.getBinary
public function getBinary(\SplFileInfo $file): string { if (!($file instanceof \SplFileObject)) { $file = $file->openFile(); } else { $file->rewind(); } if ($file instanceof \SplTempFileObject) { $binary = ''; while ($file->valid()) { $binary .= $file->fread(self::READ_LENGTH); } } else { if (!($file instanceof \SplFileObject)) { $file = $file->openFile(); } $binary = $file->fread($file->getSize()); } return $binary; }
php
public function getBinary(\SplFileInfo $file): string { if (!($file instanceof \SplFileObject)) { $file = $file->openFile(); } else { $file->rewind(); } if ($file instanceof \SplTempFileObject) { $binary = ''; while ($file->valid()) { $binary .= $file->fread(self::READ_LENGTH); } } else { if (!($file instanceof \SplFileObject)) { $file = $file->openFile(); } $binary = $file->fread($file->getSize()); } return $binary; }
[ "public", "function", "getBinary", "(", "\\", "SplFileInfo", "$", "file", ")", ":", "string", "{", "if", "(", "!", "(", "$", "file", "instanceof", "\\", "SplFileObject", ")", ")", "{", "$", "file", "=", "$", "file", "->", "openFile", "(", ")", ";", "}", "else", "{", "$", "file", "->", "rewind", "(", ")", ";", "}", "if", "(", "$", "file", "instanceof", "\\", "SplTempFileObject", ")", "{", "$", "binary", "=", "''", ";", "while", "(", "$", "file", "->", "valid", "(", ")", ")", "{", "$", "binary", ".=", "$", "file", "->", "fread", "(", "self", "::", "READ_LENGTH", ")", ";", "}", "}", "else", "{", "if", "(", "!", "(", "$", "file", "instanceof", "\\", "SplFileObject", ")", ")", "{", "$", "file", "=", "$", "file", "->", "openFile", "(", ")", ";", "}", "$", "binary", "=", "$", "file", "->", "fread", "(", "$", "file", "->", "getSize", "(", ")", ")", ";", "}", "return", "$", "binary", ";", "}" ]
SplFileInfo の中身を取得します。 @param \SplFileInfo $file @return string
[ "SplFileInfo", "の中身を取得します。" ]
train
https://github.com/esperecyan/dictionary-php/blob/14fad08fb43006995c763094e8e7ed0dc0e26676/src/Parser.php#L57-L76
phpalchemy/cerberus
src/Alchemy/Component/Cerberus/Model/Base/Permission.php
Permission.hydrate
public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) { try { $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : PermissionTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; $this->id = (null !== $col) ? (int) $col : null; $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : PermissionTableMap::translateFieldName('Name', TableMap::TYPE_PHPNAME, $indexType)]; $this->name = (null !== $col) ? (string) $col : null; $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : PermissionTableMap::translateFieldName('CreateDate', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } $this->create_date = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : PermissionTableMap::translateFieldName('Description', TableMap::TYPE_PHPNAME, $indexType)]; $this->description = (null !== $col) ? (string) $col : null; $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : PermissionTableMap::translateFieldName('UpdateDate', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } $this->update_date = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : PermissionTableMap::translateFieldName('Status', TableMap::TYPE_PHPNAME, $indexType)]; $this->status = (null !== $col) ? (string) $col : null; $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : PermissionTableMap::translateFieldName('ParentId', TableMap::TYPE_PHPNAME, $indexType)]; $this->parent_id = (null !== $col) ? (int) $col : null; $this->resetModified(); $this->setNew(false); if ($rehydrate) { $this->ensureConsistency(); } return $startcol + 7; // 7 = PermissionTableMap::NUM_HYDRATE_COLUMNS. } catch (Exception $e) { throw new PropelException(sprintf('Error populating %s object', '\\Alchemy\\Component\\Cerberus\\Model\\Permission'), 0, $e); } }
php
public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) { try { $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : PermissionTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; $this->id = (null !== $col) ? (int) $col : null; $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : PermissionTableMap::translateFieldName('Name', TableMap::TYPE_PHPNAME, $indexType)]; $this->name = (null !== $col) ? (string) $col : null; $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : PermissionTableMap::translateFieldName('CreateDate', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } $this->create_date = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : PermissionTableMap::translateFieldName('Description', TableMap::TYPE_PHPNAME, $indexType)]; $this->description = (null !== $col) ? (string) $col : null; $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : PermissionTableMap::translateFieldName('UpdateDate', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } $this->update_date = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : PermissionTableMap::translateFieldName('Status', TableMap::TYPE_PHPNAME, $indexType)]; $this->status = (null !== $col) ? (string) $col : null; $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : PermissionTableMap::translateFieldName('ParentId', TableMap::TYPE_PHPNAME, $indexType)]; $this->parent_id = (null !== $col) ? (int) $col : null; $this->resetModified(); $this->setNew(false); if ($rehydrate) { $this->ensureConsistency(); } return $startcol + 7; // 7 = PermissionTableMap::NUM_HYDRATE_COLUMNS. } catch (Exception $e) { throw new PropelException(sprintf('Error populating %s object', '\\Alchemy\\Component\\Cerberus\\Model\\Permission'), 0, $e); } }
[ "public", "function", "hydrate", "(", "$", "row", ",", "$", "startcol", "=", "0", ",", "$", "rehydrate", "=", "false", ",", "$", "indexType", "=", "TableMap", "::", "TYPE_NUM", ")", "{", "try", "{", "$", "col", "=", "$", "row", "[", "TableMap", "::", "TYPE_NUM", "==", "$", "indexType", "?", "0", "+", "$", "startcol", ":", "PermissionTableMap", "::", "translateFieldName", "(", "'Id'", ",", "TableMap", "::", "TYPE_PHPNAME", ",", "$", "indexType", ")", "]", ";", "$", "this", "->", "id", "=", "(", "null", "!==", "$", "col", ")", "?", "(", "int", ")", "$", "col", ":", "null", ";", "$", "col", "=", "$", "row", "[", "TableMap", "::", "TYPE_NUM", "==", "$", "indexType", "?", "1", "+", "$", "startcol", ":", "PermissionTableMap", "::", "translateFieldName", "(", "'Name'", ",", "TableMap", "::", "TYPE_PHPNAME", ",", "$", "indexType", ")", "]", ";", "$", "this", "->", "name", "=", "(", "null", "!==", "$", "col", ")", "?", "(", "string", ")", "$", "col", ":", "null", ";", "$", "col", "=", "$", "row", "[", "TableMap", "::", "TYPE_NUM", "==", "$", "indexType", "?", "2", "+", "$", "startcol", ":", "PermissionTableMap", "::", "translateFieldName", "(", "'CreateDate'", ",", "TableMap", "::", "TYPE_PHPNAME", ",", "$", "indexType", ")", "]", ";", "if", "(", "$", "col", "===", "'0000-00-00 00:00:00'", ")", "{", "$", "col", "=", "null", ";", "}", "$", "this", "->", "create_date", "=", "(", "null", "!==", "$", "col", ")", "?", "PropelDateTime", "::", "newInstance", "(", "$", "col", ",", "null", ",", "'\\DateTime'", ")", ":", "null", ";", "$", "col", "=", "$", "row", "[", "TableMap", "::", "TYPE_NUM", "==", "$", "indexType", "?", "3", "+", "$", "startcol", ":", "PermissionTableMap", "::", "translateFieldName", "(", "'Description'", ",", "TableMap", "::", "TYPE_PHPNAME", ",", "$", "indexType", ")", "]", ";", "$", "this", "->", "description", "=", "(", "null", "!==", "$", "col", ")", "?", "(", "string", ")", "$", "col", ":", "null", ";", "$", "col", "=", "$", "row", "[", "TableMap", "::", "TYPE_NUM", "==", "$", "indexType", "?", "4", "+", "$", "startcol", ":", "PermissionTableMap", "::", "translateFieldName", "(", "'UpdateDate'", ",", "TableMap", "::", "TYPE_PHPNAME", ",", "$", "indexType", ")", "]", ";", "if", "(", "$", "col", "===", "'0000-00-00 00:00:00'", ")", "{", "$", "col", "=", "null", ";", "}", "$", "this", "->", "update_date", "=", "(", "null", "!==", "$", "col", ")", "?", "PropelDateTime", "::", "newInstance", "(", "$", "col", ",", "null", ",", "'\\DateTime'", ")", ":", "null", ";", "$", "col", "=", "$", "row", "[", "TableMap", "::", "TYPE_NUM", "==", "$", "indexType", "?", "5", "+", "$", "startcol", ":", "PermissionTableMap", "::", "translateFieldName", "(", "'Status'", ",", "TableMap", "::", "TYPE_PHPNAME", ",", "$", "indexType", ")", "]", ";", "$", "this", "->", "status", "=", "(", "null", "!==", "$", "col", ")", "?", "(", "string", ")", "$", "col", ":", "null", ";", "$", "col", "=", "$", "row", "[", "TableMap", "::", "TYPE_NUM", "==", "$", "indexType", "?", "6", "+", "$", "startcol", ":", "PermissionTableMap", "::", "translateFieldName", "(", "'ParentId'", ",", "TableMap", "::", "TYPE_PHPNAME", ",", "$", "indexType", ")", "]", ";", "$", "this", "->", "parent_id", "=", "(", "null", "!==", "$", "col", ")", "?", "(", "int", ")", "$", "col", ":", "null", ";", "$", "this", "->", "resetModified", "(", ")", ";", "$", "this", "->", "setNew", "(", "false", ")", ";", "if", "(", "$", "rehydrate", ")", "{", "$", "this", "->", "ensureConsistency", "(", ")", ";", "}", "return", "$", "startcol", "+", "7", ";", "// 7 = PermissionTableMap::NUM_HYDRATE_COLUMNS.", "}", "catch", "(", "Exception", "$", "e", ")", "{", "throw", "new", "PropelException", "(", "sprintf", "(", "'Error populating %s object'", ",", "'\\\\Alchemy\\\\Component\\\\Cerberus\\\\Model\\\\Permission'", ")", ",", "0", ",", "$", "e", ")", ";", "}", "}" ]
Hydrates (populates) the object variables with values from the database resultset. An offset (0-based "start column") is specified so that objects can be hydrated with a subset of the columns in the resultset rows. This is needed, for example, for results of JOIN queries where the resultset row includes columns from two or more tables. @param array $row The row returned by DataFetcher->fetch(). @param int $startcol 0-based offset column which indicates which restultset column to start with. @param boolean $rehydrate Whether this object is being re-hydrated from the database. @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. @return int next starting column @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
[ "Hydrates", "(", "populates", ")", "the", "object", "variables", "with", "values", "from", "the", "database", "resultset", "." ]
train
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/Permission.php#L515-L558
phpalchemy/cerberus
src/Alchemy/Component/Cerberus/Model/Base/Permission.php
Permission.ensureConsistency
public function ensureConsistency() { if ($this->aPermissionRelatedByParentId !== null && $this->parent_id !== $this->aPermissionRelatedByParentId->getId()) { $this->aPermissionRelatedByParentId = null; } }
php
public function ensureConsistency() { if ($this->aPermissionRelatedByParentId !== null && $this->parent_id !== $this->aPermissionRelatedByParentId->getId()) { $this->aPermissionRelatedByParentId = null; } }
[ "public", "function", "ensureConsistency", "(", ")", "{", "if", "(", "$", "this", "->", "aPermissionRelatedByParentId", "!==", "null", "&&", "$", "this", "->", "parent_id", "!==", "$", "this", "->", "aPermissionRelatedByParentId", "->", "getId", "(", ")", ")", "{", "$", "this", "->", "aPermissionRelatedByParentId", "=", "null", ";", "}", "}" ]
Checks and repairs the internal consistency of the object. This method is executed after an already-instantiated object is re-hydrated from the database. It exists to check any foreign keys to make sure that the objects related to the current object are correct based on foreign key. You can override this method in the stub class, but you should always invoke the base method from the overridden method (i.e. parent::ensureConsistency()), in case your model changes. @throws PropelException
[ "Checks", "and", "repairs", "the", "internal", "consistency", "of", "the", "object", "." ]
train
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/Permission.php#L573-L578
phpalchemy/cerberus
src/Alchemy/Component/Cerberus/Model/Base/Permission.php
Permission.setParentId
public function setParentId($v) { if ($v !== null) { $v = (int) $v; } if ($this->parent_id !== $v) { $this->parent_id = $v; $this->modifiedColumns[PermissionTableMap::COL_PARENT_ID] = true; } if ($this->aPermissionRelatedByParentId !== null && $this->aPermissionRelatedByParentId->getId() !== $v) { $this->aPermissionRelatedByParentId = null; } return $this; }
php
public function setParentId($v) { if ($v !== null) { $v = (int) $v; } if ($this->parent_id !== $v) { $this->parent_id = $v; $this->modifiedColumns[PermissionTableMap::COL_PARENT_ID] = true; } if ($this->aPermissionRelatedByParentId !== null && $this->aPermissionRelatedByParentId->getId() !== $v) { $this->aPermissionRelatedByParentId = null; } return $this; }
[ "public", "function", "setParentId", "(", "$", "v", ")", "{", "if", "(", "$", "v", "!==", "null", ")", "{", "$", "v", "=", "(", "int", ")", "$", "v", ";", "}", "if", "(", "$", "this", "->", "parent_id", "!==", "$", "v", ")", "{", "$", "this", "->", "parent_id", "=", "$", "v", ";", "$", "this", "->", "modifiedColumns", "[", "PermissionTableMap", "::", "COL_PARENT_ID", "]", "=", "true", ";", "}", "if", "(", "$", "this", "->", "aPermissionRelatedByParentId", "!==", "null", "&&", "$", "this", "->", "aPermissionRelatedByParentId", "->", "getId", "(", ")", "!==", "$", "v", ")", "{", "$", "this", "->", "aPermissionRelatedByParentId", "=", "null", ";", "}", "return", "$", "this", ";", "}" ]
Set the value of [parent_id] column. @param int $v new value @return $this|\Alchemy\Component\Cerberus\Model\Permission The current object (for fluent API support)
[ "Set", "the", "value", "of", "[", "parent_id", "]", "column", "." ]
train
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/Permission.php#L706-L722
phpalchemy/cerberus
src/Alchemy/Component/Cerberus/Model/Base/Permission.php
Permission.reload
public function reload($deep = false, ConnectionInterface $con = null) { if ($this->isDeleted()) { throw new PropelException("Cannot reload a deleted object."); } if ($this->isNew()) { throw new PropelException("Cannot reload an unsaved object."); } if ($con === null) { $con = Propel::getServiceContainer()->getReadConnection(PermissionTableMap::DATABASE_NAME); } // We don't need to alter the object instance pool; we're just modifying this instance // already in the pool. $dataFetcher = ChildPermissionQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); $row = $dataFetcher->fetch(); $dataFetcher->close(); if (!$row) { throw new PropelException('Cannot find matching row in the database to reload object values.'); } $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate if ($deep) { // also de-associate any related objects? $this->aPermissionRelatedByParentId = null; $this->collPermissionsRelatedById = null; $this->collRolePermissions = null; $this->collRoles = null; } // if (deep) }
php
public function reload($deep = false, ConnectionInterface $con = null) { if ($this->isDeleted()) { throw new PropelException("Cannot reload a deleted object."); } if ($this->isNew()) { throw new PropelException("Cannot reload an unsaved object."); } if ($con === null) { $con = Propel::getServiceContainer()->getReadConnection(PermissionTableMap::DATABASE_NAME); } // We don't need to alter the object instance pool; we're just modifying this instance // already in the pool. $dataFetcher = ChildPermissionQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); $row = $dataFetcher->fetch(); $dataFetcher->close(); if (!$row) { throw new PropelException('Cannot find matching row in the database to reload object values.'); } $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate if ($deep) { // also de-associate any related objects? $this->aPermissionRelatedByParentId = null; $this->collPermissionsRelatedById = null; $this->collRolePermissions = null; $this->collRoles = null; } // if (deep) }
[ "public", "function", "reload", "(", "$", "deep", "=", "false", ",", "ConnectionInterface", "$", "con", "=", "null", ")", "{", "if", "(", "$", "this", "->", "isDeleted", "(", ")", ")", "{", "throw", "new", "PropelException", "(", "\"Cannot reload a deleted object.\"", ")", ";", "}", "if", "(", "$", "this", "->", "isNew", "(", ")", ")", "{", "throw", "new", "PropelException", "(", "\"Cannot reload an unsaved object.\"", ")", ";", "}", "if", "(", "$", "con", "===", "null", ")", "{", "$", "con", "=", "Propel", "::", "getServiceContainer", "(", ")", "->", "getReadConnection", "(", "PermissionTableMap", "::", "DATABASE_NAME", ")", ";", "}", "// We don't need to alter the object instance pool; we're just modifying this instance", "// already in the pool.", "$", "dataFetcher", "=", "ChildPermissionQuery", "::", "create", "(", "null", ",", "$", "this", "->", "buildPkeyCriteria", "(", ")", ")", "->", "setFormatter", "(", "ModelCriteria", "::", "FORMAT_STATEMENT", ")", "->", "find", "(", "$", "con", ")", ";", "$", "row", "=", "$", "dataFetcher", "->", "fetch", "(", ")", ";", "$", "dataFetcher", "->", "close", "(", ")", ";", "if", "(", "!", "$", "row", ")", "{", "throw", "new", "PropelException", "(", "'Cannot find matching row in the database to reload object values.'", ")", ";", "}", "$", "this", "->", "hydrate", "(", "$", "row", ",", "0", ",", "true", ",", "$", "dataFetcher", "->", "getIndexType", "(", ")", ")", ";", "// rehydrate", "if", "(", "$", "deep", ")", "{", "// also de-associate any related objects?", "$", "this", "->", "aPermissionRelatedByParentId", "=", "null", ";", "$", "this", "->", "collPermissionsRelatedById", "=", "null", ";", "$", "this", "->", "collRolePermissions", "=", "null", ";", "$", "this", "->", "collRoles", "=", "null", ";", "}", "// if (deep)", "}" ]
Reloads this object from datastore based on primary key and (optionally) resets all associated objects. This will only work if the object has been saved and has a valid primary key set. @param boolean $deep (optional) Whether to also de-associated any related objects. @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. @return void @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
[ "Reloads", "this", "object", "from", "datastore", "based", "on", "primary", "key", "and", "(", "optionally", ")", "resets", "all", "associated", "objects", "." ]
train
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/Permission.php#L734-L768
phpalchemy/cerberus
src/Alchemy/Component/Cerberus/Model/Base/Permission.php
Permission.doSave
protected function doSave(ConnectionInterface $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their corresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aPermissionRelatedByParentId !== null) { if ($this->aPermissionRelatedByParentId->isModified() || $this->aPermissionRelatedByParentId->isNew()) { $affectedRows += $this->aPermissionRelatedByParentId->save($con); } $this->setPermissionRelatedByParentId($this->aPermissionRelatedByParentId); } if ($this->isNew() || $this->isModified()) { // persist changes if ($this->isNew()) { $this->doInsert($con); } else { $this->doUpdate($con); } $affectedRows += 1; $this->resetModified(); } if ($this->rolesScheduledForDeletion !== null) { if (!$this->rolesScheduledForDeletion->isEmpty()) { $pks = array(); foreach ($this->rolesScheduledForDeletion as $entry) { $entryPk = []; $entryPk[1] = $this->getId(); $entryPk[0] = $entry->getId(); $pks[] = $entryPk; } \Alchemy\Component\Cerberus\Model\RolePermissionQuery::create() ->filterByPrimaryKeys($pks) ->delete($con); $this->rolesScheduledForDeletion = null; } } if ($this->collRoles) { foreach ($this->collRoles as $role) { if (!$role->isDeleted() && ($role->isNew() || $role->isModified())) { $role->save($con); } } } if ($this->permissionsRelatedByIdScheduledForDeletion !== null) { if (!$this->permissionsRelatedByIdScheduledForDeletion->isEmpty()) { \Alchemy\Component\Cerberus\Model\PermissionQuery::create() ->filterByPrimaryKeys($this->permissionsRelatedByIdScheduledForDeletion->getPrimaryKeys(false)) ->delete($con); $this->permissionsRelatedByIdScheduledForDeletion = null; } } if ($this->collPermissionsRelatedById !== null) { foreach ($this->collPermissionsRelatedById as $referrerFK) { if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { $affectedRows += $referrerFK->save($con); } } } if ($this->rolePermissionsScheduledForDeletion !== null) { if (!$this->rolePermissionsScheduledForDeletion->isEmpty()) { \Alchemy\Component\Cerberus\Model\RolePermissionQuery::create() ->filterByPrimaryKeys($this->rolePermissionsScheduledForDeletion->getPrimaryKeys(false)) ->delete($con); $this->rolePermissionsScheduledForDeletion = null; } } if ($this->collRolePermissions !== null) { foreach ($this->collRolePermissions as $referrerFK) { if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; }
php
protected function doSave(ConnectionInterface $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their corresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aPermissionRelatedByParentId !== null) { if ($this->aPermissionRelatedByParentId->isModified() || $this->aPermissionRelatedByParentId->isNew()) { $affectedRows += $this->aPermissionRelatedByParentId->save($con); } $this->setPermissionRelatedByParentId($this->aPermissionRelatedByParentId); } if ($this->isNew() || $this->isModified()) { // persist changes if ($this->isNew()) { $this->doInsert($con); } else { $this->doUpdate($con); } $affectedRows += 1; $this->resetModified(); } if ($this->rolesScheduledForDeletion !== null) { if (!$this->rolesScheduledForDeletion->isEmpty()) { $pks = array(); foreach ($this->rolesScheduledForDeletion as $entry) { $entryPk = []; $entryPk[1] = $this->getId(); $entryPk[0] = $entry->getId(); $pks[] = $entryPk; } \Alchemy\Component\Cerberus\Model\RolePermissionQuery::create() ->filterByPrimaryKeys($pks) ->delete($con); $this->rolesScheduledForDeletion = null; } } if ($this->collRoles) { foreach ($this->collRoles as $role) { if (!$role->isDeleted() && ($role->isNew() || $role->isModified())) { $role->save($con); } } } if ($this->permissionsRelatedByIdScheduledForDeletion !== null) { if (!$this->permissionsRelatedByIdScheduledForDeletion->isEmpty()) { \Alchemy\Component\Cerberus\Model\PermissionQuery::create() ->filterByPrimaryKeys($this->permissionsRelatedByIdScheduledForDeletion->getPrimaryKeys(false)) ->delete($con); $this->permissionsRelatedByIdScheduledForDeletion = null; } } if ($this->collPermissionsRelatedById !== null) { foreach ($this->collPermissionsRelatedById as $referrerFK) { if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { $affectedRows += $referrerFK->save($con); } } } if ($this->rolePermissionsScheduledForDeletion !== null) { if (!$this->rolePermissionsScheduledForDeletion->isEmpty()) { \Alchemy\Component\Cerberus\Model\RolePermissionQuery::create() ->filterByPrimaryKeys($this->rolePermissionsScheduledForDeletion->getPrimaryKeys(false)) ->delete($con); $this->rolePermissionsScheduledForDeletion = null; } } if ($this->collRolePermissions !== null) { foreach ($this->collRolePermissions as $referrerFK) { if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; }
[ "protected", "function", "doSave", "(", "ConnectionInterface", "$", "con", ")", "{", "$", "affectedRows", "=", "0", ";", "// initialize var to track total num of affected rows", "if", "(", "!", "$", "this", "->", "alreadyInSave", ")", "{", "$", "this", "->", "alreadyInSave", "=", "true", ";", "// We call the save method on the following object(s) if they", "// were passed to this object by their corresponding set", "// method. This object relates to these object(s) by a", "// foreign key reference.", "if", "(", "$", "this", "->", "aPermissionRelatedByParentId", "!==", "null", ")", "{", "if", "(", "$", "this", "->", "aPermissionRelatedByParentId", "->", "isModified", "(", ")", "||", "$", "this", "->", "aPermissionRelatedByParentId", "->", "isNew", "(", ")", ")", "{", "$", "affectedRows", "+=", "$", "this", "->", "aPermissionRelatedByParentId", "->", "save", "(", "$", "con", ")", ";", "}", "$", "this", "->", "setPermissionRelatedByParentId", "(", "$", "this", "->", "aPermissionRelatedByParentId", ")", ";", "}", "if", "(", "$", "this", "->", "isNew", "(", ")", "||", "$", "this", "->", "isModified", "(", ")", ")", "{", "// persist changes", "if", "(", "$", "this", "->", "isNew", "(", ")", ")", "{", "$", "this", "->", "doInsert", "(", "$", "con", ")", ";", "}", "else", "{", "$", "this", "->", "doUpdate", "(", "$", "con", ")", ";", "}", "$", "affectedRows", "+=", "1", ";", "$", "this", "->", "resetModified", "(", ")", ";", "}", "if", "(", "$", "this", "->", "rolesScheduledForDeletion", "!==", "null", ")", "{", "if", "(", "!", "$", "this", "->", "rolesScheduledForDeletion", "->", "isEmpty", "(", ")", ")", "{", "$", "pks", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "rolesScheduledForDeletion", "as", "$", "entry", ")", "{", "$", "entryPk", "=", "[", "]", ";", "$", "entryPk", "[", "1", "]", "=", "$", "this", "->", "getId", "(", ")", ";", "$", "entryPk", "[", "0", "]", "=", "$", "entry", "->", "getId", "(", ")", ";", "$", "pks", "[", "]", "=", "$", "entryPk", ";", "}", "\\", "Alchemy", "\\", "Component", "\\", "Cerberus", "\\", "Model", "\\", "RolePermissionQuery", "::", "create", "(", ")", "->", "filterByPrimaryKeys", "(", "$", "pks", ")", "->", "delete", "(", "$", "con", ")", ";", "$", "this", "->", "rolesScheduledForDeletion", "=", "null", ";", "}", "}", "if", "(", "$", "this", "->", "collRoles", ")", "{", "foreach", "(", "$", "this", "->", "collRoles", "as", "$", "role", ")", "{", "if", "(", "!", "$", "role", "->", "isDeleted", "(", ")", "&&", "(", "$", "role", "->", "isNew", "(", ")", "||", "$", "role", "->", "isModified", "(", ")", ")", ")", "{", "$", "role", "->", "save", "(", "$", "con", ")", ";", "}", "}", "}", "if", "(", "$", "this", "->", "permissionsRelatedByIdScheduledForDeletion", "!==", "null", ")", "{", "if", "(", "!", "$", "this", "->", "permissionsRelatedByIdScheduledForDeletion", "->", "isEmpty", "(", ")", ")", "{", "\\", "Alchemy", "\\", "Component", "\\", "Cerberus", "\\", "Model", "\\", "PermissionQuery", "::", "create", "(", ")", "->", "filterByPrimaryKeys", "(", "$", "this", "->", "permissionsRelatedByIdScheduledForDeletion", "->", "getPrimaryKeys", "(", "false", ")", ")", "->", "delete", "(", "$", "con", ")", ";", "$", "this", "->", "permissionsRelatedByIdScheduledForDeletion", "=", "null", ";", "}", "}", "if", "(", "$", "this", "->", "collPermissionsRelatedById", "!==", "null", ")", "{", "foreach", "(", "$", "this", "->", "collPermissionsRelatedById", "as", "$", "referrerFK", ")", "{", "if", "(", "!", "$", "referrerFK", "->", "isDeleted", "(", ")", "&&", "(", "$", "referrerFK", "->", "isNew", "(", ")", "||", "$", "referrerFK", "->", "isModified", "(", ")", ")", ")", "{", "$", "affectedRows", "+=", "$", "referrerFK", "->", "save", "(", "$", "con", ")", ";", "}", "}", "}", "if", "(", "$", "this", "->", "rolePermissionsScheduledForDeletion", "!==", "null", ")", "{", "if", "(", "!", "$", "this", "->", "rolePermissionsScheduledForDeletion", "->", "isEmpty", "(", ")", ")", "{", "\\", "Alchemy", "\\", "Component", "\\", "Cerberus", "\\", "Model", "\\", "RolePermissionQuery", "::", "create", "(", ")", "->", "filterByPrimaryKeys", "(", "$", "this", "->", "rolePermissionsScheduledForDeletion", "->", "getPrimaryKeys", "(", "false", ")", ")", "->", "delete", "(", "$", "con", ")", ";", "$", "this", "->", "rolePermissionsScheduledForDeletion", "=", "null", ";", "}", "}", "if", "(", "$", "this", "->", "collRolePermissions", "!==", "null", ")", "{", "foreach", "(", "$", "this", "->", "collRolePermissions", "as", "$", "referrerFK", ")", "{", "if", "(", "!", "$", "referrerFK", "->", "isDeleted", "(", ")", "&&", "(", "$", "referrerFK", "->", "isNew", "(", ")", "||", "$", "referrerFK", "->", "isModified", "(", ")", ")", ")", "{", "$", "affectedRows", "+=", "$", "referrerFK", "->", "save", "(", "$", "con", ")", ";", "}", "}", "}", "$", "this", "->", "alreadyInSave", "=", "false", ";", "}", "return", "$", "affectedRows", ";", "}" ]
Performs the work of inserting or updating the row in the database. If the object is new, it inserts it; otherwise an update is performed. All related objects are also updated in this method. @param ConnectionInterface $con @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. @throws PropelException @see save()
[ "Performs", "the", "work", "of", "inserting", "or", "updating", "the", "row", "in", "the", "database", "." ]
train
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/Permission.php#L860-L957
phpalchemy/cerberus
src/Alchemy/Component/Cerberus/Model/Base/Permission.php
Permission.toArray
public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) { if (isset($alreadyDumpedObjects['Permission'][$this->getPrimaryKey()])) { return '*RECURSION*'; } $alreadyDumpedObjects['Permission'][$this->getPrimaryKey()] = true; $keys = PermissionTableMap::getFieldNames($keyType); $result = array( $keys[0] => $this->getId(), $keys[1] => $this->getName(), $keys[2] => $this->getCreateDate(), $keys[3] => $this->getDescription(), $keys[4] => $this->getUpdateDate(), $keys[5] => $this->getStatus(), $keys[6] => $this->getParentId(), ); $virtualColumns = $this->virtualColumns; foreach ($virtualColumns as $key => $virtualColumn) { $result[$key] = $virtualColumn; } if ($includeForeignObjects) { if (null !== $this->aPermissionRelatedByParentId) { $result['PermissionRelatedByParentId'] = $this->aPermissionRelatedByParentId->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); } if (null !== $this->collPermissionsRelatedById) { $result['PermissionsRelatedById'] = $this->collPermissionsRelatedById->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); } if (null !== $this->collRolePermissions) { $result['RolePermissions'] = $this->collRolePermissions->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); } } return $result; }
php
public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) { if (isset($alreadyDumpedObjects['Permission'][$this->getPrimaryKey()])) { return '*RECURSION*'; } $alreadyDumpedObjects['Permission'][$this->getPrimaryKey()] = true; $keys = PermissionTableMap::getFieldNames($keyType); $result = array( $keys[0] => $this->getId(), $keys[1] => $this->getName(), $keys[2] => $this->getCreateDate(), $keys[3] => $this->getDescription(), $keys[4] => $this->getUpdateDate(), $keys[5] => $this->getStatus(), $keys[6] => $this->getParentId(), ); $virtualColumns = $this->virtualColumns; foreach ($virtualColumns as $key => $virtualColumn) { $result[$key] = $virtualColumn; } if ($includeForeignObjects) { if (null !== $this->aPermissionRelatedByParentId) { $result['PermissionRelatedByParentId'] = $this->aPermissionRelatedByParentId->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); } if (null !== $this->collPermissionsRelatedById) { $result['PermissionsRelatedById'] = $this->collPermissionsRelatedById->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); } if (null !== $this->collRolePermissions) { $result['RolePermissions'] = $this->collRolePermissions->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); } } return $result; }
[ "public", "function", "toArray", "(", "$", "keyType", "=", "TableMap", "::", "TYPE_PHPNAME", ",", "$", "includeLazyLoadColumns", "=", "true", ",", "$", "alreadyDumpedObjects", "=", "array", "(", ")", ",", "$", "includeForeignObjects", "=", "false", ")", "{", "if", "(", "isset", "(", "$", "alreadyDumpedObjects", "[", "'Permission'", "]", "[", "$", "this", "->", "getPrimaryKey", "(", ")", "]", ")", ")", "{", "return", "'*RECURSION*'", ";", "}", "$", "alreadyDumpedObjects", "[", "'Permission'", "]", "[", "$", "this", "->", "getPrimaryKey", "(", ")", "]", "=", "true", ";", "$", "keys", "=", "PermissionTableMap", "::", "getFieldNames", "(", "$", "keyType", ")", ";", "$", "result", "=", "array", "(", "$", "keys", "[", "0", "]", "=>", "$", "this", "->", "getId", "(", ")", ",", "$", "keys", "[", "1", "]", "=>", "$", "this", "->", "getName", "(", ")", ",", "$", "keys", "[", "2", "]", "=>", "$", "this", "->", "getCreateDate", "(", ")", ",", "$", "keys", "[", "3", "]", "=>", "$", "this", "->", "getDescription", "(", ")", ",", "$", "keys", "[", "4", "]", "=>", "$", "this", "->", "getUpdateDate", "(", ")", ",", "$", "keys", "[", "5", "]", "=>", "$", "this", "->", "getStatus", "(", ")", ",", "$", "keys", "[", "6", "]", "=>", "$", "this", "->", "getParentId", "(", ")", ",", ")", ";", "$", "virtualColumns", "=", "$", "this", "->", "virtualColumns", ";", "foreach", "(", "$", "virtualColumns", "as", "$", "key", "=>", "$", "virtualColumn", ")", "{", "$", "result", "[", "$", "key", "]", "=", "$", "virtualColumn", ";", "}", "if", "(", "$", "includeForeignObjects", ")", "{", "if", "(", "null", "!==", "$", "this", "->", "aPermissionRelatedByParentId", ")", "{", "$", "result", "[", "'PermissionRelatedByParentId'", "]", "=", "$", "this", "->", "aPermissionRelatedByParentId", "->", "toArray", "(", "$", "keyType", ",", "$", "includeLazyLoadColumns", ",", "$", "alreadyDumpedObjects", ",", "true", ")", ";", "}", "if", "(", "null", "!==", "$", "this", "->", "collPermissionsRelatedById", ")", "{", "$", "result", "[", "'PermissionsRelatedById'", "]", "=", "$", "this", "->", "collPermissionsRelatedById", "->", "toArray", "(", "null", ",", "true", ",", "$", "keyType", ",", "$", "includeLazyLoadColumns", ",", "$", "alreadyDumpedObjects", ")", ";", "}", "if", "(", "null", "!==", "$", "this", "->", "collRolePermissions", ")", "{", "$", "result", "[", "'RolePermissions'", "]", "=", "$", "this", "->", "collRolePermissions", "->", "toArray", "(", "null", ",", "true", ",", "$", "keyType", ",", "$", "includeLazyLoadColumns", ",", "$", "alreadyDumpedObjects", ")", ";", "}", "}", "return", "$", "result", ";", "}" ]
Exports the object as an array. You can specify the key type of the array by passing one of the class type constants. @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. Defaults to TableMap::TYPE_PHPNAME. @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. @param array $alreadyDumpedObjects List of objects to skip to avoid recursion @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. @return array an associative array containing the field names (as keys) and field values
[ "Exports", "the", "object", "as", "an", "array", "." ]
train
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/Permission.php#L1135-L1169
phpalchemy/cerberus
src/Alchemy/Component/Cerberus/Model/Base/Permission.php
Permission.setByPosition
public function setByPosition($pos, $value) { switch ($pos) { case 0: $this->setId($value); break; case 1: $this->setName($value); break; case 2: $this->setCreateDate($value); break; case 3: $this->setDescription($value); break; case 4: $this->setUpdateDate($value); break; case 5: $this->setStatus($value); break; case 6: $this->setParentId($value); break; } // switch() return $this; }
php
public function setByPosition($pos, $value) { switch ($pos) { case 0: $this->setId($value); break; case 1: $this->setName($value); break; case 2: $this->setCreateDate($value); break; case 3: $this->setDescription($value); break; case 4: $this->setUpdateDate($value); break; case 5: $this->setStatus($value); break; case 6: $this->setParentId($value); break; } // switch() return $this; }
[ "public", "function", "setByPosition", "(", "$", "pos", ",", "$", "value", ")", "{", "switch", "(", "$", "pos", ")", "{", "case", "0", ":", "$", "this", "->", "setId", "(", "$", "value", ")", ";", "break", ";", "case", "1", ":", "$", "this", "->", "setName", "(", "$", "value", ")", ";", "break", ";", "case", "2", ":", "$", "this", "->", "setCreateDate", "(", "$", "value", ")", ";", "break", ";", "case", "3", ":", "$", "this", "->", "setDescription", "(", "$", "value", ")", ";", "break", ";", "case", "4", ":", "$", "this", "->", "setUpdateDate", "(", "$", "value", ")", ";", "break", ";", "case", "5", ":", "$", "this", "->", "setStatus", "(", "$", "value", ")", ";", "break", ";", "case", "6", ":", "$", "this", "->", "setParentId", "(", "$", "value", ")", ";", "break", ";", "}", "// switch()", "return", "$", "this", ";", "}" ]
Sets a field from the object by Position as specified in the xml schema. Zero-based. @param int $pos position in xml schema @param mixed $value field value @return $this|\Alchemy\Component\Cerberus\Model\Permission
[ "Sets", "a", "field", "from", "the", "object", "by", "Position", "as", "specified", "in", "the", "xml", "schema", ".", "Zero", "-", "based", "." ]
train
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/Permission.php#L1197-L1224
phpalchemy/cerberus
src/Alchemy/Component/Cerberus/Model/Base/Permission.php
Permission.fromArray
public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) { $keys = PermissionTableMap::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setName($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setCreateDate($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setDescription($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setUpdateDate($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setStatus($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setParentId($arr[$keys[6]]); } }
php
public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) { $keys = PermissionTableMap::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setName($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setCreateDate($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setDescription($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setUpdateDate($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setStatus($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setParentId($arr[$keys[6]]); } }
[ "public", "function", "fromArray", "(", "$", "arr", ",", "$", "keyType", "=", "TableMap", "::", "TYPE_PHPNAME", ")", "{", "$", "keys", "=", "PermissionTableMap", "::", "getFieldNames", "(", "$", "keyType", ")", ";", "if", "(", "array_key_exists", "(", "$", "keys", "[", "0", "]", ",", "$", "arr", ")", ")", "{", "$", "this", "->", "setId", "(", "$", "arr", "[", "$", "keys", "[", "0", "]", "]", ")", ";", "}", "if", "(", "array_key_exists", "(", "$", "keys", "[", "1", "]", ",", "$", "arr", ")", ")", "{", "$", "this", "->", "setName", "(", "$", "arr", "[", "$", "keys", "[", "1", "]", "]", ")", ";", "}", "if", "(", "array_key_exists", "(", "$", "keys", "[", "2", "]", ",", "$", "arr", ")", ")", "{", "$", "this", "->", "setCreateDate", "(", "$", "arr", "[", "$", "keys", "[", "2", "]", "]", ")", ";", "}", "if", "(", "array_key_exists", "(", "$", "keys", "[", "3", "]", ",", "$", "arr", ")", ")", "{", "$", "this", "->", "setDescription", "(", "$", "arr", "[", "$", "keys", "[", "3", "]", "]", ")", ";", "}", "if", "(", "array_key_exists", "(", "$", "keys", "[", "4", "]", ",", "$", "arr", ")", ")", "{", "$", "this", "->", "setUpdateDate", "(", "$", "arr", "[", "$", "keys", "[", "4", "]", "]", ")", ";", "}", "if", "(", "array_key_exists", "(", "$", "keys", "[", "5", "]", ",", "$", "arr", ")", ")", "{", "$", "this", "->", "setStatus", "(", "$", "arr", "[", "$", "keys", "[", "5", "]", "]", ")", ";", "}", "if", "(", "array_key_exists", "(", "$", "keys", "[", "6", "]", ",", "$", "arr", ")", ")", "{", "$", "this", "->", "setParentId", "(", "$", "arr", "[", "$", "keys", "[", "6", "]", "]", ")", ";", "}", "}" ]
Populates the object using an array. This is particularly useful when populating an object from one of the request arrays (e.g. $_POST). This method goes through the column names, checking to see whether a matching key exists in populated array. If so the setByName() method is called for that column. You can specify the key type of the array by additionally passing one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. The default key type is the column's TableMap::TYPE_PHPNAME. @param array $arr An array to populate the object from. @param string $keyType The type of keys the array uses. @return void
[ "Populates", "the", "object", "using", "an", "array", "." ]
train
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/Permission.php#L1243-L1268
phpalchemy/cerberus
src/Alchemy/Component/Cerberus/Model/Base/Permission.php
Permission.buildCriteria
public function buildCriteria() { $criteria = new Criteria(PermissionTableMap::DATABASE_NAME); if ($this->isColumnModified(PermissionTableMap::COL_ID)) { $criteria->add(PermissionTableMap::COL_ID, $this->id); } if ($this->isColumnModified(PermissionTableMap::COL_NAME)) { $criteria->add(PermissionTableMap::COL_NAME, $this->name); } if ($this->isColumnModified(PermissionTableMap::COL_CREATE_DATE)) { $criteria->add(PermissionTableMap::COL_CREATE_DATE, $this->create_date); } if ($this->isColumnModified(PermissionTableMap::COL_DESCRIPTION)) { $criteria->add(PermissionTableMap::COL_DESCRIPTION, $this->description); } if ($this->isColumnModified(PermissionTableMap::COL_UPDATE_DATE)) { $criteria->add(PermissionTableMap::COL_UPDATE_DATE, $this->update_date); } if ($this->isColumnModified(PermissionTableMap::COL_STATUS)) { $criteria->add(PermissionTableMap::COL_STATUS, $this->status); } if ($this->isColumnModified(PermissionTableMap::COL_PARENT_ID)) { $criteria->add(PermissionTableMap::COL_PARENT_ID, $this->parent_id); } return $criteria; }
php
public function buildCriteria() { $criteria = new Criteria(PermissionTableMap::DATABASE_NAME); if ($this->isColumnModified(PermissionTableMap::COL_ID)) { $criteria->add(PermissionTableMap::COL_ID, $this->id); } if ($this->isColumnModified(PermissionTableMap::COL_NAME)) { $criteria->add(PermissionTableMap::COL_NAME, $this->name); } if ($this->isColumnModified(PermissionTableMap::COL_CREATE_DATE)) { $criteria->add(PermissionTableMap::COL_CREATE_DATE, $this->create_date); } if ($this->isColumnModified(PermissionTableMap::COL_DESCRIPTION)) { $criteria->add(PermissionTableMap::COL_DESCRIPTION, $this->description); } if ($this->isColumnModified(PermissionTableMap::COL_UPDATE_DATE)) { $criteria->add(PermissionTableMap::COL_UPDATE_DATE, $this->update_date); } if ($this->isColumnModified(PermissionTableMap::COL_STATUS)) { $criteria->add(PermissionTableMap::COL_STATUS, $this->status); } if ($this->isColumnModified(PermissionTableMap::COL_PARENT_ID)) { $criteria->add(PermissionTableMap::COL_PARENT_ID, $this->parent_id); } return $criteria; }
[ "public", "function", "buildCriteria", "(", ")", "{", "$", "criteria", "=", "new", "Criteria", "(", "PermissionTableMap", "::", "DATABASE_NAME", ")", ";", "if", "(", "$", "this", "->", "isColumnModified", "(", "PermissionTableMap", "::", "COL_ID", ")", ")", "{", "$", "criteria", "->", "add", "(", "PermissionTableMap", "::", "COL_ID", ",", "$", "this", "->", "id", ")", ";", "}", "if", "(", "$", "this", "->", "isColumnModified", "(", "PermissionTableMap", "::", "COL_NAME", ")", ")", "{", "$", "criteria", "->", "add", "(", "PermissionTableMap", "::", "COL_NAME", ",", "$", "this", "->", "name", ")", ";", "}", "if", "(", "$", "this", "->", "isColumnModified", "(", "PermissionTableMap", "::", "COL_CREATE_DATE", ")", ")", "{", "$", "criteria", "->", "add", "(", "PermissionTableMap", "::", "COL_CREATE_DATE", ",", "$", "this", "->", "create_date", ")", ";", "}", "if", "(", "$", "this", "->", "isColumnModified", "(", "PermissionTableMap", "::", "COL_DESCRIPTION", ")", ")", "{", "$", "criteria", "->", "add", "(", "PermissionTableMap", "::", "COL_DESCRIPTION", ",", "$", "this", "->", "description", ")", ";", "}", "if", "(", "$", "this", "->", "isColumnModified", "(", "PermissionTableMap", "::", "COL_UPDATE_DATE", ")", ")", "{", "$", "criteria", "->", "add", "(", "PermissionTableMap", "::", "COL_UPDATE_DATE", ",", "$", "this", "->", "update_date", ")", ";", "}", "if", "(", "$", "this", "->", "isColumnModified", "(", "PermissionTableMap", "::", "COL_STATUS", ")", ")", "{", "$", "criteria", "->", "add", "(", "PermissionTableMap", "::", "COL_STATUS", ",", "$", "this", "->", "status", ")", ";", "}", "if", "(", "$", "this", "->", "isColumnModified", "(", "PermissionTableMap", "::", "COL_PARENT_ID", ")", ")", "{", "$", "criteria", "->", "add", "(", "PermissionTableMap", "::", "COL_PARENT_ID", ",", "$", "this", "->", "parent_id", ")", ";", "}", "return", "$", "criteria", ";", "}" ]
Build a Criteria object containing the values of all modified columns in this object. @return Criteria The Criteria object containing all modified values.
[ "Build", "a", "Criteria", "object", "containing", "the", "values", "of", "all", "modified", "columns", "in", "this", "object", "." ]
train
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/Permission.php#L1299-L1326
phpalchemy/cerberus
src/Alchemy/Component/Cerberus/Model/Base/Permission.php
Permission.setPermissionRelatedByParentId
public function setPermissionRelatedByParentId(ChildPermission $v = null) { if ($v === null) { $this->setParentId(NULL); } else { $this->setParentId($v->getId()); } $this->aPermissionRelatedByParentId = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the ChildPermission object, it will not be re-added. if ($v !== null) { $v->addPermissionRelatedById($this); } return $this; }
php
public function setPermissionRelatedByParentId(ChildPermission $v = null) { if ($v === null) { $this->setParentId(NULL); } else { $this->setParentId($v->getId()); } $this->aPermissionRelatedByParentId = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the ChildPermission object, it will not be re-added. if ($v !== null) { $v->addPermissionRelatedById($this); } return $this; }
[ "public", "function", "setPermissionRelatedByParentId", "(", "ChildPermission", "$", "v", "=", "null", ")", "{", "if", "(", "$", "v", "===", "null", ")", "{", "$", "this", "->", "setParentId", "(", "NULL", ")", ";", "}", "else", "{", "$", "this", "->", "setParentId", "(", "$", "v", "->", "getId", "(", ")", ")", ";", "}", "$", "this", "->", "aPermissionRelatedByParentId", "=", "$", "v", ";", "// Add binding for other direction of this n:n relationship.", "// If this object has already been added to the ChildPermission object, it will not be re-added.", "if", "(", "$", "v", "!==", "null", ")", "{", "$", "v", "->", "addPermissionRelatedById", "(", "$", "this", ")", ";", "}", "return", "$", "this", ";", "}" ]
Declares an association between this object and a ChildPermission object. @param ChildPermission $v @return $this|\Alchemy\Component\Cerberus\Model\Permission The current object (for fluent API support) @throws PropelException
[ "Declares", "an", "association", "between", "this", "object", "and", "a", "ChildPermission", "object", "." ]
train
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/Permission.php#L1471-L1489
phpalchemy/cerberus
src/Alchemy/Component/Cerberus/Model/Base/Permission.php
Permission.getPermissionRelatedByParentId
public function getPermissionRelatedByParentId(ConnectionInterface $con = null) { if ($this->aPermissionRelatedByParentId === null && ($this->parent_id !== null)) { $this->aPermissionRelatedByParentId = ChildPermissionQuery::create()->findPk($this->parent_id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aPermissionRelatedByParentId->addPermissionsRelatedById($this); */ } return $this->aPermissionRelatedByParentId; }
php
public function getPermissionRelatedByParentId(ConnectionInterface $con = null) { if ($this->aPermissionRelatedByParentId === null && ($this->parent_id !== null)) { $this->aPermissionRelatedByParentId = ChildPermissionQuery::create()->findPk($this->parent_id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aPermissionRelatedByParentId->addPermissionsRelatedById($this); */ } return $this->aPermissionRelatedByParentId; }
[ "public", "function", "getPermissionRelatedByParentId", "(", "ConnectionInterface", "$", "con", "=", "null", ")", "{", "if", "(", "$", "this", "->", "aPermissionRelatedByParentId", "===", "null", "&&", "(", "$", "this", "->", "parent_id", "!==", "null", ")", ")", "{", "$", "this", "->", "aPermissionRelatedByParentId", "=", "ChildPermissionQuery", "::", "create", "(", ")", "->", "findPk", "(", "$", "this", "->", "parent_id", ",", "$", "con", ")", ";", "/* The following can be used additionally to\n guarantee the related object contains a reference\n to this object. This level of coupling may, however, be\n undesirable since it could result in an only partially populated collection\n in the referenced object.\n $this->aPermissionRelatedByParentId->addPermissionsRelatedById($this);\n */", "}", "return", "$", "this", "->", "aPermissionRelatedByParentId", ";", "}" ]
Get the associated ChildPermission object @param ConnectionInterface $con Optional Connection object. @return ChildPermission The associated ChildPermission object. @throws PropelException
[ "Get", "the", "associated", "ChildPermission", "object" ]
train
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/Permission.php#L1499-L1513
phpalchemy/cerberus
src/Alchemy/Component/Cerberus/Model/Base/Permission.php
Permission.initPermissionsRelatedById
public function initPermissionsRelatedById($overrideExisting = true) { if (null !== $this->collPermissionsRelatedById && !$overrideExisting) { return; } $this->collPermissionsRelatedById = new ObjectCollection(); $this->collPermissionsRelatedById->setModel('\Alchemy\Component\Cerberus\Model\Permission'); }
php
public function initPermissionsRelatedById($overrideExisting = true) { if (null !== $this->collPermissionsRelatedById && !$overrideExisting) { return; } $this->collPermissionsRelatedById = new ObjectCollection(); $this->collPermissionsRelatedById->setModel('\Alchemy\Component\Cerberus\Model\Permission'); }
[ "public", "function", "initPermissionsRelatedById", "(", "$", "overrideExisting", "=", "true", ")", "{", "if", "(", "null", "!==", "$", "this", "->", "collPermissionsRelatedById", "&&", "!", "$", "overrideExisting", ")", "{", "return", ";", "}", "$", "this", "->", "collPermissionsRelatedById", "=", "new", "ObjectCollection", "(", ")", ";", "$", "this", "->", "collPermissionsRelatedById", "->", "setModel", "(", "'\\Alchemy\\Component\\Cerberus\\Model\\Permission'", ")", ";", "}" ]
Initializes the collPermissionsRelatedById collection. By default this just sets the collPermissionsRelatedById collection to an empty array (like clearcollPermissionsRelatedById()); however, you may wish to override this method in your stub class to provide setting appropriate to your application -- for example, setting the initial array to the values stored in database. @param boolean $overrideExisting If set to true, the method call initializes the collection even if it is not empty @return void
[ "Initializes", "the", "collPermissionsRelatedById", "collection", "." ]
train
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/Permission.php#L1568-L1575
phpalchemy/cerberus
src/Alchemy/Component/Cerberus/Model/Base/Permission.php
Permission.getPermissionsRelatedById
public function getPermissionsRelatedById(Criteria $criteria = null, ConnectionInterface $con = null) { $partial = $this->collPermissionsRelatedByIdPartial && !$this->isNew(); if (null === $this->collPermissionsRelatedById || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collPermissionsRelatedById) { // return empty collection $this->initPermissionsRelatedById(); } else { $collPermissionsRelatedById = ChildPermissionQuery::create(null, $criteria) ->filterByPermissionRelatedByParentId($this) ->find($con); if (null !== $criteria) { if (false !== $this->collPermissionsRelatedByIdPartial && count($collPermissionsRelatedById)) { $this->initPermissionsRelatedById(false); foreach ($collPermissionsRelatedById as $obj) { if (false == $this->collPermissionsRelatedById->contains($obj)) { $this->collPermissionsRelatedById->append($obj); } } $this->collPermissionsRelatedByIdPartial = true; } return $collPermissionsRelatedById; } if ($partial && $this->collPermissionsRelatedById) { foreach ($this->collPermissionsRelatedById as $obj) { if ($obj->isNew()) { $collPermissionsRelatedById[] = $obj; } } } $this->collPermissionsRelatedById = $collPermissionsRelatedById; $this->collPermissionsRelatedByIdPartial = false; } } return $this->collPermissionsRelatedById; }
php
public function getPermissionsRelatedById(Criteria $criteria = null, ConnectionInterface $con = null) { $partial = $this->collPermissionsRelatedByIdPartial && !$this->isNew(); if (null === $this->collPermissionsRelatedById || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collPermissionsRelatedById) { // return empty collection $this->initPermissionsRelatedById(); } else { $collPermissionsRelatedById = ChildPermissionQuery::create(null, $criteria) ->filterByPermissionRelatedByParentId($this) ->find($con); if (null !== $criteria) { if (false !== $this->collPermissionsRelatedByIdPartial && count($collPermissionsRelatedById)) { $this->initPermissionsRelatedById(false); foreach ($collPermissionsRelatedById as $obj) { if (false == $this->collPermissionsRelatedById->contains($obj)) { $this->collPermissionsRelatedById->append($obj); } } $this->collPermissionsRelatedByIdPartial = true; } return $collPermissionsRelatedById; } if ($partial && $this->collPermissionsRelatedById) { foreach ($this->collPermissionsRelatedById as $obj) { if ($obj->isNew()) { $collPermissionsRelatedById[] = $obj; } } } $this->collPermissionsRelatedById = $collPermissionsRelatedById; $this->collPermissionsRelatedByIdPartial = false; } } return $this->collPermissionsRelatedById; }
[ "public", "function", "getPermissionsRelatedById", "(", "Criteria", "$", "criteria", "=", "null", ",", "ConnectionInterface", "$", "con", "=", "null", ")", "{", "$", "partial", "=", "$", "this", "->", "collPermissionsRelatedByIdPartial", "&&", "!", "$", "this", "->", "isNew", "(", ")", ";", "if", "(", "null", "===", "$", "this", "->", "collPermissionsRelatedById", "||", "null", "!==", "$", "criteria", "||", "$", "partial", ")", "{", "if", "(", "$", "this", "->", "isNew", "(", ")", "&&", "null", "===", "$", "this", "->", "collPermissionsRelatedById", ")", "{", "// return empty collection", "$", "this", "->", "initPermissionsRelatedById", "(", ")", ";", "}", "else", "{", "$", "collPermissionsRelatedById", "=", "ChildPermissionQuery", "::", "create", "(", "null", ",", "$", "criteria", ")", "->", "filterByPermissionRelatedByParentId", "(", "$", "this", ")", "->", "find", "(", "$", "con", ")", ";", "if", "(", "null", "!==", "$", "criteria", ")", "{", "if", "(", "false", "!==", "$", "this", "->", "collPermissionsRelatedByIdPartial", "&&", "count", "(", "$", "collPermissionsRelatedById", ")", ")", "{", "$", "this", "->", "initPermissionsRelatedById", "(", "false", ")", ";", "foreach", "(", "$", "collPermissionsRelatedById", "as", "$", "obj", ")", "{", "if", "(", "false", "==", "$", "this", "->", "collPermissionsRelatedById", "->", "contains", "(", "$", "obj", ")", ")", "{", "$", "this", "->", "collPermissionsRelatedById", "->", "append", "(", "$", "obj", ")", ";", "}", "}", "$", "this", "->", "collPermissionsRelatedByIdPartial", "=", "true", ";", "}", "return", "$", "collPermissionsRelatedById", ";", "}", "if", "(", "$", "partial", "&&", "$", "this", "->", "collPermissionsRelatedById", ")", "{", "foreach", "(", "$", "this", "->", "collPermissionsRelatedById", "as", "$", "obj", ")", "{", "if", "(", "$", "obj", "->", "isNew", "(", ")", ")", "{", "$", "collPermissionsRelatedById", "[", "]", "=", "$", "obj", ";", "}", "}", "}", "$", "this", "->", "collPermissionsRelatedById", "=", "$", "collPermissionsRelatedById", ";", "$", "this", "->", "collPermissionsRelatedByIdPartial", "=", "false", ";", "}", "}", "return", "$", "this", "->", "collPermissionsRelatedById", ";", "}" ]
Gets an array of ChildPermission objects which contain a foreign key that references this object. If the $criteria is not null, it is used to always fetch the results from the database. Otherwise the results are fetched from the database the first time, then cached. Next time the same method is called without $criteria, the cached collection is returned. If this ChildPermission is new, it will return an empty collection or the current collection; the criteria is ignored on a new object. @param Criteria $criteria optional Criteria object to narrow the query @param ConnectionInterface $con optional connection object @return ObjectCollection|ChildPermission[] List of ChildPermission objects @throws PropelException
[ "Gets", "an", "array", "of", "ChildPermission", "objects", "which", "contain", "a", "foreign", "key", "that", "references", "this", "object", "." ]
train
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/Permission.php#L1591-L1633
phpalchemy/cerberus
src/Alchemy/Component/Cerberus/Model/Base/Permission.php
Permission.setPermissionsRelatedById
public function setPermissionsRelatedById(Collection $permissionsRelatedById, ConnectionInterface $con = null) { /** @var ChildPermission[] $permissionsRelatedByIdToDelete */ $permissionsRelatedByIdToDelete = $this->getPermissionsRelatedById(new Criteria(), $con)->diff($permissionsRelatedById); $this->permissionsRelatedByIdScheduledForDeletion = $permissionsRelatedByIdToDelete; foreach ($permissionsRelatedByIdToDelete as $permissionRelatedByIdRemoved) { $permissionRelatedByIdRemoved->setPermissionRelatedByParentId(null); } $this->collPermissionsRelatedById = null; foreach ($permissionsRelatedById as $permissionRelatedById) { $this->addPermissionRelatedById($permissionRelatedById); } $this->collPermissionsRelatedById = $permissionsRelatedById; $this->collPermissionsRelatedByIdPartial = false; return $this; }
php
public function setPermissionsRelatedById(Collection $permissionsRelatedById, ConnectionInterface $con = null) { /** @var ChildPermission[] $permissionsRelatedByIdToDelete */ $permissionsRelatedByIdToDelete = $this->getPermissionsRelatedById(new Criteria(), $con)->diff($permissionsRelatedById); $this->permissionsRelatedByIdScheduledForDeletion = $permissionsRelatedByIdToDelete; foreach ($permissionsRelatedByIdToDelete as $permissionRelatedByIdRemoved) { $permissionRelatedByIdRemoved->setPermissionRelatedByParentId(null); } $this->collPermissionsRelatedById = null; foreach ($permissionsRelatedById as $permissionRelatedById) { $this->addPermissionRelatedById($permissionRelatedById); } $this->collPermissionsRelatedById = $permissionsRelatedById; $this->collPermissionsRelatedByIdPartial = false; return $this; }
[ "public", "function", "setPermissionsRelatedById", "(", "Collection", "$", "permissionsRelatedById", ",", "ConnectionInterface", "$", "con", "=", "null", ")", "{", "/** @var ChildPermission[] $permissionsRelatedByIdToDelete */", "$", "permissionsRelatedByIdToDelete", "=", "$", "this", "->", "getPermissionsRelatedById", "(", "new", "Criteria", "(", ")", ",", "$", "con", ")", "->", "diff", "(", "$", "permissionsRelatedById", ")", ";", "$", "this", "->", "permissionsRelatedByIdScheduledForDeletion", "=", "$", "permissionsRelatedByIdToDelete", ";", "foreach", "(", "$", "permissionsRelatedByIdToDelete", "as", "$", "permissionRelatedByIdRemoved", ")", "{", "$", "permissionRelatedByIdRemoved", "->", "setPermissionRelatedByParentId", "(", "null", ")", ";", "}", "$", "this", "->", "collPermissionsRelatedById", "=", "null", ";", "foreach", "(", "$", "permissionsRelatedById", "as", "$", "permissionRelatedById", ")", "{", "$", "this", "->", "addPermissionRelatedById", "(", "$", "permissionRelatedById", ")", ";", "}", "$", "this", "->", "collPermissionsRelatedById", "=", "$", "permissionsRelatedById", ";", "$", "this", "->", "collPermissionsRelatedByIdPartial", "=", "false", ";", "return", "$", "this", ";", "}" ]
Sets a collection of ChildPermission objects related by a one-to-many relationship to the current object. It will also schedule objects for deletion based on a diff between old objects (aka persisted) and new objects from the given Propel collection. @param Collection $permissionsRelatedById A Propel collection. @param ConnectionInterface $con Optional connection object @return $this|ChildPermission The current object (for fluent API support)
[ "Sets", "a", "collection", "of", "ChildPermission", "objects", "related", "by", "a", "one", "-", "to", "-", "many", "relationship", "to", "the", "current", "object", ".", "It", "will", "also", "schedule", "objects", "for", "deletion", "based", "on", "a", "diff", "between", "old", "objects", "(", "aka", "persisted", ")", "and", "new", "objects", "from", "the", "given", "Propel", "collection", "." ]
train
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/Permission.php#L1645-L1666
phpalchemy/cerberus
src/Alchemy/Component/Cerberus/Model/Base/Permission.php
Permission.countPermissionsRelatedById
public function countPermissionsRelatedById(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) { $partial = $this->collPermissionsRelatedByIdPartial && !$this->isNew(); if (null === $this->collPermissionsRelatedById || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collPermissionsRelatedById) { return 0; } if ($partial && !$criteria) { return count($this->getPermissionsRelatedById()); } $query = ChildPermissionQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query ->filterByPermissionRelatedByParentId($this) ->count($con); } return count($this->collPermissionsRelatedById); }
php
public function countPermissionsRelatedById(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) { $partial = $this->collPermissionsRelatedByIdPartial && !$this->isNew(); if (null === $this->collPermissionsRelatedById || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collPermissionsRelatedById) { return 0; } if ($partial && !$criteria) { return count($this->getPermissionsRelatedById()); } $query = ChildPermissionQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query ->filterByPermissionRelatedByParentId($this) ->count($con); } return count($this->collPermissionsRelatedById); }
[ "public", "function", "countPermissionsRelatedById", "(", "Criteria", "$", "criteria", "=", "null", ",", "$", "distinct", "=", "false", ",", "ConnectionInterface", "$", "con", "=", "null", ")", "{", "$", "partial", "=", "$", "this", "->", "collPermissionsRelatedByIdPartial", "&&", "!", "$", "this", "->", "isNew", "(", ")", ";", "if", "(", "null", "===", "$", "this", "->", "collPermissionsRelatedById", "||", "null", "!==", "$", "criteria", "||", "$", "partial", ")", "{", "if", "(", "$", "this", "->", "isNew", "(", ")", "&&", "null", "===", "$", "this", "->", "collPermissionsRelatedById", ")", "{", "return", "0", ";", "}", "if", "(", "$", "partial", "&&", "!", "$", "criteria", ")", "{", "return", "count", "(", "$", "this", "->", "getPermissionsRelatedById", "(", ")", ")", ";", "}", "$", "query", "=", "ChildPermissionQuery", "::", "create", "(", "null", ",", "$", "criteria", ")", ";", "if", "(", "$", "distinct", ")", "{", "$", "query", "->", "distinct", "(", ")", ";", "}", "return", "$", "query", "->", "filterByPermissionRelatedByParentId", "(", "$", "this", ")", "->", "count", "(", "$", "con", ")", ";", "}", "return", "count", "(", "$", "this", "->", "collPermissionsRelatedById", ")", ";", "}" ]
Returns the number of related Permission objects. @param Criteria $criteria @param boolean $distinct @param ConnectionInterface $con @return int Count of related Permission objects. @throws PropelException
[ "Returns", "the", "number", "of", "related", "Permission", "objects", "." ]
train
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/Permission.php#L1677-L1700
phpalchemy/cerberus
src/Alchemy/Component/Cerberus/Model/Base/Permission.php
Permission.addPermissionRelatedById
public function addPermissionRelatedById(ChildPermission $l) { if ($this->collPermissionsRelatedById === null) { $this->initPermissionsRelatedById(); $this->collPermissionsRelatedByIdPartial = true; } if (!$this->collPermissionsRelatedById->contains($l)) { $this->doAddPermissionRelatedById($l); } return $this; }
php
public function addPermissionRelatedById(ChildPermission $l) { if ($this->collPermissionsRelatedById === null) { $this->initPermissionsRelatedById(); $this->collPermissionsRelatedByIdPartial = true; } if (!$this->collPermissionsRelatedById->contains($l)) { $this->doAddPermissionRelatedById($l); } return $this; }
[ "public", "function", "addPermissionRelatedById", "(", "ChildPermission", "$", "l", ")", "{", "if", "(", "$", "this", "->", "collPermissionsRelatedById", "===", "null", ")", "{", "$", "this", "->", "initPermissionsRelatedById", "(", ")", ";", "$", "this", "->", "collPermissionsRelatedByIdPartial", "=", "true", ";", "}", "if", "(", "!", "$", "this", "->", "collPermissionsRelatedById", "->", "contains", "(", "$", "l", ")", ")", "{", "$", "this", "->", "doAddPermissionRelatedById", "(", "$", "l", ")", ";", "}", "return", "$", "this", ";", "}" ]
Method called to associate a ChildPermission object to this object through the ChildPermission foreign key attribute. @param ChildPermission $l ChildPermission @return $this|\Alchemy\Component\Cerberus\Model\Permission The current object (for fluent API support)
[ "Method", "called", "to", "associate", "a", "ChildPermission", "object", "to", "this", "object", "through", "the", "ChildPermission", "foreign", "key", "attribute", "." ]
train
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/Permission.php#L1709-L1721
phpalchemy/cerberus
src/Alchemy/Component/Cerberus/Model/Base/Permission.php
Permission.getRolePermissions
public function getRolePermissions(Criteria $criteria = null, ConnectionInterface $con = null) { $partial = $this->collRolePermissionsPartial && !$this->isNew(); if (null === $this->collRolePermissions || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collRolePermissions) { // return empty collection $this->initRolePermissions(); } else { $collRolePermissions = ChildRolePermissionQuery::create(null, $criteria) ->filterByPermission($this) ->find($con); if (null !== $criteria) { if (false !== $this->collRolePermissionsPartial && count($collRolePermissions)) { $this->initRolePermissions(false); foreach ($collRolePermissions as $obj) { if (false == $this->collRolePermissions->contains($obj)) { $this->collRolePermissions->append($obj); } } $this->collRolePermissionsPartial = true; } return $collRolePermissions; } if ($partial && $this->collRolePermissions) { foreach ($this->collRolePermissions as $obj) { if ($obj->isNew()) { $collRolePermissions[] = $obj; } } } $this->collRolePermissions = $collRolePermissions; $this->collRolePermissionsPartial = false; } } return $this->collRolePermissions; }
php
public function getRolePermissions(Criteria $criteria = null, ConnectionInterface $con = null) { $partial = $this->collRolePermissionsPartial && !$this->isNew(); if (null === $this->collRolePermissions || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collRolePermissions) { // return empty collection $this->initRolePermissions(); } else { $collRolePermissions = ChildRolePermissionQuery::create(null, $criteria) ->filterByPermission($this) ->find($con); if (null !== $criteria) { if (false !== $this->collRolePermissionsPartial && count($collRolePermissions)) { $this->initRolePermissions(false); foreach ($collRolePermissions as $obj) { if (false == $this->collRolePermissions->contains($obj)) { $this->collRolePermissions->append($obj); } } $this->collRolePermissionsPartial = true; } return $collRolePermissions; } if ($partial && $this->collRolePermissions) { foreach ($this->collRolePermissions as $obj) { if ($obj->isNew()) { $collRolePermissions[] = $obj; } } } $this->collRolePermissions = $collRolePermissions; $this->collRolePermissionsPartial = false; } } return $this->collRolePermissions; }
[ "public", "function", "getRolePermissions", "(", "Criteria", "$", "criteria", "=", "null", ",", "ConnectionInterface", "$", "con", "=", "null", ")", "{", "$", "partial", "=", "$", "this", "->", "collRolePermissionsPartial", "&&", "!", "$", "this", "->", "isNew", "(", ")", ";", "if", "(", "null", "===", "$", "this", "->", "collRolePermissions", "||", "null", "!==", "$", "criteria", "||", "$", "partial", ")", "{", "if", "(", "$", "this", "->", "isNew", "(", ")", "&&", "null", "===", "$", "this", "->", "collRolePermissions", ")", "{", "// return empty collection", "$", "this", "->", "initRolePermissions", "(", ")", ";", "}", "else", "{", "$", "collRolePermissions", "=", "ChildRolePermissionQuery", "::", "create", "(", "null", ",", "$", "criteria", ")", "->", "filterByPermission", "(", "$", "this", ")", "->", "find", "(", "$", "con", ")", ";", "if", "(", "null", "!==", "$", "criteria", ")", "{", "if", "(", "false", "!==", "$", "this", "->", "collRolePermissionsPartial", "&&", "count", "(", "$", "collRolePermissions", ")", ")", "{", "$", "this", "->", "initRolePermissions", "(", "false", ")", ";", "foreach", "(", "$", "collRolePermissions", "as", "$", "obj", ")", "{", "if", "(", "false", "==", "$", "this", "->", "collRolePermissions", "->", "contains", "(", "$", "obj", ")", ")", "{", "$", "this", "->", "collRolePermissions", "->", "append", "(", "$", "obj", ")", ";", "}", "}", "$", "this", "->", "collRolePermissionsPartial", "=", "true", ";", "}", "return", "$", "collRolePermissions", ";", "}", "if", "(", "$", "partial", "&&", "$", "this", "->", "collRolePermissions", ")", "{", "foreach", "(", "$", "this", "->", "collRolePermissions", "as", "$", "obj", ")", "{", "if", "(", "$", "obj", "->", "isNew", "(", ")", ")", "{", "$", "collRolePermissions", "[", "]", "=", "$", "obj", ";", "}", "}", "}", "$", "this", "->", "collRolePermissions", "=", "$", "collRolePermissions", ";", "$", "this", "->", "collRolePermissionsPartial", "=", "false", ";", "}", "}", "return", "$", "this", "->", "collRolePermissions", ";", "}" ]
Gets an array of ChildRolePermission objects which contain a foreign key that references this object. If the $criteria is not null, it is used to always fetch the results from the database. Otherwise the results are fetched from the database the first time, then cached. Next time the same method is called without $criteria, the cached collection is returned. If this ChildPermission is new, it will return an empty collection or the current collection; the criteria is ignored on a new object. @param Criteria $criteria optional Criteria object to narrow the query @param ConnectionInterface $con optional connection object @return ObjectCollection|ChildRolePermission[] List of ChildRolePermission objects @throws PropelException
[ "Gets", "an", "array", "of", "ChildRolePermission", "objects", "which", "contain", "a", "foreign", "key", "that", "references", "this", "object", "." ]
train
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/Permission.php#L1809-L1851
phpalchemy/cerberus
src/Alchemy/Component/Cerberus/Model/Base/Permission.php
Permission.setRolePermissions
public function setRolePermissions(Collection $rolePermissions, ConnectionInterface $con = null) { /** @var ChildRolePermission[] $rolePermissionsToDelete */ $rolePermissionsToDelete = $this->getRolePermissions(new Criteria(), $con)->diff($rolePermissions); //since at least one column in the foreign key is at the same time a PK //we can not just set a PK to NULL in the lines below. We have to store //a backup of all values, so we are able to manipulate these items based on the onDelete value later. $this->rolePermissionsScheduledForDeletion = clone $rolePermissionsToDelete; foreach ($rolePermissionsToDelete as $rolePermissionRemoved) { $rolePermissionRemoved->setPermission(null); } $this->collRolePermissions = null; foreach ($rolePermissions as $rolePermission) { $this->addRolePermission($rolePermission); } $this->collRolePermissions = $rolePermissions; $this->collRolePermissionsPartial = false; return $this; }
php
public function setRolePermissions(Collection $rolePermissions, ConnectionInterface $con = null) { /** @var ChildRolePermission[] $rolePermissionsToDelete */ $rolePermissionsToDelete = $this->getRolePermissions(new Criteria(), $con)->diff($rolePermissions); //since at least one column in the foreign key is at the same time a PK //we can not just set a PK to NULL in the lines below. We have to store //a backup of all values, so we are able to manipulate these items based on the onDelete value later. $this->rolePermissionsScheduledForDeletion = clone $rolePermissionsToDelete; foreach ($rolePermissionsToDelete as $rolePermissionRemoved) { $rolePermissionRemoved->setPermission(null); } $this->collRolePermissions = null; foreach ($rolePermissions as $rolePermission) { $this->addRolePermission($rolePermission); } $this->collRolePermissions = $rolePermissions; $this->collRolePermissionsPartial = false; return $this; }
[ "public", "function", "setRolePermissions", "(", "Collection", "$", "rolePermissions", ",", "ConnectionInterface", "$", "con", "=", "null", ")", "{", "/** @var ChildRolePermission[] $rolePermissionsToDelete */", "$", "rolePermissionsToDelete", "=", "$", "this", "->", "getRolePermissions", "(", "new", "Criteria", "(", ")", ",", "$", "con", ")", "->", "diff", "(", "$", "rolePermissions", ")", ";", "//since at least one column in the foreign key is at the same time a PK", "//we can not just set a PK to NULL in the lines below. We have to store", "//a backup of all values, so we are able to manipulate these items based on the onDelete value later.", "$", "this", "->", "rolePermissionsScheduledForDeletion", "=", "clone", "$", "rolePermissionsToDelete", ";", "foreach", "(", "$", "rolePermissionsToDelete", "as", "$", "rolePermissionRemoved", ")", "{", "$", "rolePermissionRemoved", "->", "setPermission", "(", "null", ")", ";", "}", "$", "this", "->", "collRolePermissions", "=", "null", ";", "foreach", "(", "$", "rolePermissions", "as", "$", "rolePermission", ")", "{", "$", "this", "->", "addRolePermission", "(", "$", "rolePermission", ")", ";", "}", "$", "this", "->", "collRolePermissions", "=", "$", "rolePermissions", ";", "$", "this", "->", "collRolePermissionsPartial", "=", "false", ";", "return", "$", "this", ";", "}" ]
Sets a collection of ChildRolePermission objects related by a one-to-many relationship to the current object. It will also schedule objects for deletion based on a diff between old objects (aka persisted) and new objects from the given Propel collection. @param Collection $rolePermissions A Propel collection. @param ConnectionInterface $con Optional connection object @return $this|ChildPermission The current object (for fluent API support)
[ "Sets", "a", "collection", "of", "ChildRolePermission", "objects", "related", "by", "a", "one", "-", "to", "-", "many", "relationship", "to", "the", "current", "object", ".", "It", "will", "also", "schedule", "objects", "for", "deletion", "based", "on", "a", "diff", "between", "old", "objects", "(", "aka", "persisted", ")", "and", "new", "objects", "from", "the", "given", "Propel", "collection", "." ]
train
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/Permission.php#L1863-L1887
phpalchemy/cerberus
src/Alchemy/Component/Cerberus/Model/Base/Permission.php
Permission.countRolePermissions
public function countRolePermissions(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) { $partial = $this->collRolePermissionsPartial && !$this->isNew(); if (null === $this->collRolePermissions || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collRolePermissions) { return 0; } if ($partial && !$criteria) { return count($this->getRolePermissions()); } $query = ChildRolePermissionQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query ->filterByPermission($this) ->count($con); } return count($this->collRolePermissions); }
php
public function countRolePermissions(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) { $partial = $this->collRolePermissionsPartial && !$this->isNew(); if (null === $this->collRolePermissions || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collRolePermissions) { return 0; } if ($partial && !$criteria) { return count($this->getRolePermissions()); } $query = ChildRolePermissionQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query ->filterByPermission($this) ->count($con); } return count($this->collRolePermissions); }
[ "public", "function", "countRolePermissions", "(", "Criteria", "$", "criteria", "=", "null", ",", "$", "distinct", "=", "false", ",", "ConnectionInterface", "$", "con", "=", "null", ")", "{", "$", "partial", "=", "$", "this", "->", "collRolePermissionsPartial", "&&", "!", "$", "this", "->", "isNew", "(", ")", ";", "if", "(", "null", "===", "$", "this", "->", "collRolePermissions", "||", "null", "!==", "$", "criteria", "||", "$", "partial", ")", "{", "if", "(", "$", "this", "->", "isNew", "(", ")", "&&", "null", "===", "$", "this", "->", "collRolePermissions", ")", "{", "return", "0", ";", "}", "if", "(", "$", "partial", "&&", "!", "$", "criteria", ")", "{", "return", "count", "(", "$", "this", "->", "getRolePermissions", "(", ")", ")", ";", "}", "$", "query", "=", "ChildRolePermissionQuery", "::", "create", "(", "null", ",", "$", "criteria", ")", ";", "if", "(", "$", "distinct", ")", "{", "$", "query", "->", "distinct", "(", ")", ";", "}", "return", "$", "query", "->", "filterByPermission", "(", "$", "this", ")", "->", "count", "(", "$", "con", ")", ";", "}", "return", "count", "(", "$", "this", "->", "collRolePermissions", ")", ";", "}" ]
Returns the number of related RolePermission objects. @param Criteria $criteria @param boolean $distinct @param ConnectionInterface $con @return int Count of related RolePermission objects. @throws PropelException
[ "Returns", "the", "number", "of", "related", "RolePermission", "objects", "." ]
train
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/Permission.php#L1898-L1921
phpalchemy/cerberus
src/Alchemy/Component/Cerberus/Model/Base/Permission.php
Permission.getRolePermissionsJoinRole
public function getRolePermissionsJoinRole(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN) { $query = ChildRolePermissionQuery::create(null, $criteria); $query->joinWith('Role', $joinBehavior); return $this->getRolePermissions($query, $con); }
php
public function getRolePermissionsJoinRole(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN) { $query = ChildRolePermissionQuery::create(null, $criteria); $query->joinWith('Role', $joinBehavior); return $this->getRolePermissions($query, $con); }
[ "public", "function", "getRolePermissionsJoinRole", "(", "Criteria", "$", "criteria", "=", "null", ",", "ConnectionInterface", "$", "con", "=", "null", ",", "$", "joinBehavior", "=", "Criteria", "::", "LEFT_JOIN", ")", "{", "$", "query", "=", "ChildRolePermissionQuery", "::", "create", "(", "null", ",", "$", "criteria", ")", ";", "$", "query", "->", "joinWith", "(", "'Role'", ",", "$", "joinBehavior", ")", ";", "return", "$", "this", "->", "getRolePermissions", "(", "$", "query", ",", "$", "con", ")", ";", "}" ]
If this collection has already been initialized with an identical criteria, it returns the collection. Otherwise if this Permission is new, it will return an empty collection; or if this Permission has previously been saved, it will retrieve related RolePermissions from storage. This method is protected by default in order to keep the public api reasonable. You can provide public methods for those you actually need in Permission. @param Criteria $criteria optional Criteria object to narrow the query @param ConnectionInterface $con optional connection object @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) @return ObjectCollection|ChildRolePermission[] List of ChildRolePermission objects
[ "If", "this", "collection", "has", "already", "been", "initialized", "with", "an", "identical", "criteria", "it", "returns", "the", "collection", ".", "Otherwise", "if", "this", "Permission", "is", "new", "it", "will", "return", "an", "empty", "collection", ";", "or", "if", "this", "Permission", "has", "previously", "been", "saved", "it", "will", "retrieve", "related", "RolePermissions", "from", "storage", "." ]
train
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/Permission.php#L1990-L1996
phpalchemy/cerberus
src/Alchemy/Component/Cerberus/Model/Base/Permission.php
Permission.getRoles
public function getRoles(Criteria $criteria = null, ConnectionInterface $con = null) { $partial = $this->collRolesPartial && !$this->isNew(); if (null === $this->collRoles || null !== $criteria || $partial) { if ($this->isNew()) { // return empty collection if (null === $this->collRoles) { $this->initRoles(); } } else { $query = ChildRoleQuery::create(null, $criteria) ->filterByPermission($this); $collRoles = $query->find($con); if (null !== $criteria) { return $collRoles; } if ($partial && $this->collRoles) { //make sure that already added objects gets added to the list of the database. foreach ($this->collRoles as $obj) { if (!$collRoles->contains($obj)) { $collRoles[] = $obj; } } } $this->collRoles = $collRoles; $this->collRolesPartial = false; } } return $this->collRoles; }
php
public function getRoles(Criteria $criteria = null, ConnectionInterface $con = null) { $partial = $this->collRolesPartial && !$this->isNew(); if (null === $this->collRoles || null !== $criteria || $partial) { if ($this->isNew()) { // return empty collection if (null === $this->collRoles) { $this->initRoles(); } } else { $query = ChildRoleQuery::create(null, $criteria) ->filterByPermission($this); $collRoles = $query->find($con); if (null !== $criteria) { return $collRoles; } if ($partial && $this->collRoles) { //make sure that already added objects gets added to the list of the database. foreach ($this->collRoles as $obj) { if (!$collRoles->contains($obj)) { $collRoles[] = $obj; } } } $this->collRoles = $collRoles; $this->collRolesPartial = false; } } return $this->collRoles; }
[ "public", "function", "getRoles", "(", "Criteria", "$", "criteria", "=", "null", ",", "ConnectionInterface", "$", "con", "=", "null", ")", "{", "$", "partial", "=", "$", "this", "->", "collRolesPartial", "&&", "!", "$", "this", "->", "isNew", "(", ")", ";", "if", "(", "null", "===", "$", "this", "->", "collRoles", "||", "null", "!==", "$", "criteria", "||", "$", "partial", ")", "{", "if", "(", "$", "this", "->", "isNew", "(", ")", ")", "{", "// return empty collection", "if", "(", "null", "===", "$", "this", "->", "collRoles", ")", "{", "$", "this", "->", "initRoles", "(", ")", ";", "}", "}", "else", "{", "$", "query", "=", "ChildRoleQuery", "::", "create", "(", "null", ",", "$", "criteria", ")", "->", "filterByPermission", "(", "$", "this", ")", ";", "$", "collRoles", "=", "$", "query", "->", "find", "(", "$", "con", ")", ";", "if", "(", "null", "!==", "$", "criteria", ")", "{", "return", "$", "collRoles", ";", "}", "if", "(", "$", "partial", "&&", "$", "this", "->", "collRoles", ")", "{", "//make sure that already added objects gets added to the list of the database.", "foreach", "(", "$", "this", "->", "collRoles", "as", "$", "obj", ")", "{", "if", "(", "!", "$", "collRoles", "->", "contains", "(", "$", "obj", ")", ")", "{", "$", "collRoles", "[", "]", "=", "$", "obj", ";", "}", "}", "}", "$", "this", "->", "collRoles", "=", "$", "collRoles", ";", "$", "this", "->", "collRolesPartial", "=", "false", ";", "}", "}", "return", "$", "this", "->", "collRoles", ";", "}" ]
Gets a collection of ChildRole objects related by a many-to-many relationship to the current object by way of the role_permission cross-reference table. If the $criteria is not null, it is used to always fetch the results from the database. Otherwise the results are fetched from the database the first time, then cached. Next time the same method is called without $criteria, the cached collection is returned. If this ChildPermission is new, it will return an empty collection or the current collection; the criteria is ignored on a new object. @param Criteria $criteria Optional query object to filter the query @param ConnectionInterface $con Optional connection object @return ObjectCollection|ChildRole[] List of ChildRole objects
[ "Gets", "a", "collection", "of", "ChildRole", "objects", "related", "by", "a", "many", "-", "to", "-", "many", "relationship", "to", "the", "current", "object", "by", "way", "of", "the", "role_permission", "cross", "-", "reference", "table", "." ]
train
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/Permission.php#L2054-L2087
phpalchemy/cerberus
src/Alchemy/Component/Cerberus/Model/Base/Permission.php
Permission.countRoles
public function countRoles(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) { $partial = $this->collRolesPartial && !$this->isNew(); if (null === $this->collRoles || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collRoles) { return 0; } else { if ($partial && !$criteria) { return count($this->getRoles()); } $query = ChildRoleQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query ->filterByPermission($this) ->count($con); } } else { return count($this->collRoles); } }
php
public function countRoles(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) { $partial = $this->collRolesPartial && !$this->isNew(); if (null === $this->collRoles || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collRoles) { return 0; } else { if ($partial && !$criteria) { return count($this->getRoles()); } $query = ChildRoleQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query ->filterByPermission($this) ->count($con); } } else { return count($this->collRoles); } }
[ "public", "function", "countRoles", "(", "Criteria", "$", "criteria", "=", "null", ",", "$", "distinct", "=", "false", ",", "ConnectionInterface", "$", "con", "=", "null", ")", "{", "$", "partial", "=", "$", "this", "->", "collRolesPartial", "&&", "!", "$", "this", "->", "isNew", "(", ")", ";", "if", "(", "null", "===", "$", "this", "->", "collRoles", "||", "null", "!==", "$", "criteria", "||", "$", "partial", ")", "{", "if", "(", "$", "this", "->", "isNew", "(", ")", "&&", "null", "===", "$", "this", "->", "collRoles", ")", "{", "return", "0", ";", "}", "else", "{", "if", "(", "$", "partial", "&&", "!", "$", "criteria", ")", "{", "return", "count", "(", "$", "this", "->", "getRoles", "(", ")", ")", ";", "}", "$", "query", "=", "ChildRoleQuery", "::", "create", "(", "null", ",", "$", "criteria", ")", ";", "if", "(", "$", "distinct", ")", "{", "$", "query", "->", "distinct", "(", ")", ";", "}", "return", "$", "query", "->", "filterByPermission", "(", "$", "this", ")", "->", "count", "(", "$", "con", ")", ";", "}", "}", "else", "{", "return", "count", "(", "$", "this", "->", "collRoles", ")", ";", "}", "}" ]
Gets the number of Role objects related by a many-to-many relationship to the current object by way of the role_permission cross-reference table. @param Criteria $criteria Optional query object to filter the query @param boolean $distinct Set to true to force count distinct @param ConnectionInterface $con Optional connection object @return int the number of related Role objects
[ "Gets", "the", "number", "of", "Role", "objects", "related", "by", "a", "many", "-", "to", "-", "many", "relationship", "to", "the", "current", "object", "by", "way", "of", "the", "role_permission", "cross", "-", "reference", "table", "." ]
train
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/Permission.php#L2132-L2156
phpalchemy/cerberus
src/Alchemy/Component/Cerberus/Model/Base/Permission.php
Permission.removeRole
public function removeRole(ChildRole $role) { if ($this->getRoles()->contains($role)) { $rolePermission = new ChildRolePermission(); $rolePermission->setRole($role); if ($role->isPermissionsLoaded()) { //remove the back reference if available $role->getPermissions()->removeObject($this); } $rolePermission->setPermission($this); $this->removeRolePermission(clone $rolePermission); $rolePermission->clear(); $this->collRoles->remove($this->collRoles->search($role)); if (null === $this->rolesScheduledForDeletion) { $this->rolesScheduledForDeletion = clone $this->collRoles; $this->rolesScheduledForDeletion->clear(); } $this->rolesScheduledForDeletion->push($role); } return $this; }
php
public function removeRole(ChildRole $role) { if ($this->getRoles()->contains($role)) { $rolePermission = new ChildRolePermission(); $rolePermission->setRole($role); if ($role->isPermissionsLoaded()) { //remove the back reference if available $role->getPermissions()->removeObject($this); } $rolePermission->setPermission($this); $this->removeRolePermission(clone $rolePermission); $rolePermission->clear(); $this->collRoles->remove($this->collRoles->search($role)); if (null === $this->rolesScheduledForDeletion) { $this->rolesScheduledForDeletion = clone $this->collRoles; $this->rolesScheduledForDeletion->clear(); } $this->rolesScheduledForDeletion->push($role); } return $this; }
[ "public", "function", "removeRole", "(", "ChildRole", "$", "role", ")", "{", "if", "(", "$", "this", "->", "getRoles", "(", ")", "->", "contains", "(", "$", "role", ")", ")", "{", "$", "rolePermission", "=", "new", "ChildRolePermission", "(", ")", ";", "$", "rolePermission", "->", "setRole", "(", "$", "role", ")", ";", "if", "(", "$", "role", "->", "isPermissionsLoaded", "(", ")", ")", "{", "//remove the back reference if available", "$", "role", "->", "getPermissions", "(", ")", "->", "removeObject", "(", "$", "this", ")", ";", "}", "$", "rolePermission", "->", "setPermission", "(", "$", "this", ")", ";", "$", "this", "->", "removeRolePermission", "(", "clone", "$", "rolePermission", ")", ";", "$", "rolePermission", "->", "clear", "(", ")", ";", "$", "this", "->", "collRoles", "->", "remove", "(", "$", "this", "->", "collRoles", "->", "search", "(", "$", "role", ")", ")", ";", "if", "(", "null", "===", "$", "this", "->", "rolesScheduledForDeletion", ")", "{", "$", "this", "->", "rolesScheduledForDeletion", "=", "clone", "$", "this", "->", "collRoles", ";", "$", "this", "->", "rolesScheduledForDeletion", "->", "clear", "(", ")", ";", "}", "$", "this", "->", "rolesScheduledForDeletion", "->", "push", "(", "$", "role", ")", ";", "}", "return", "$", "this", ";", "}" ]
Remove role of this object through the role_permission cross reference table. @param ChildRole $role @return ChildPermission The current object (for fluent API support)
[ "Remove", "role", "of", "this", "object", "through", "the", "role_permission", "cross", "reference", "table", "." ]
train
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/Permission.php#L2212-L2238
phpalchemy/cerberus
src/Alchemy/Component/Cerberus/Model/Base/Permission.php
Permission.clear
public function clear() { if (null !== $this->aPermissionRelatedByParentId) { $this->aPermissionRelatedByParentId->removePermissionRelatedById($this); } $this->id = null; $this->name = null; $this->create_date = null; $this->description = null; $this->update_date = null; $this->status = null; $this->parent_id = null; $this->alreadyInSave = false; $this->clearAllReferences(); $this->applyDefaultValues(); $this->resetModified(); $this->setNew(true); $this->setDeleted(false); }
php
public function clear() { if (null !== $this->aPermissionRelatedByParentId) { $this->aPermissionRelatedByParentId->removePermissionRelatedById($this); } $this->id = null; $this->name = null; $this->create_date = null; $this->description = null; $this->update_date = null; $this->status = null; $this->parent_id = null; $this->alreadyInSave = false; $this->clearAllReferences(); $this->applyDefaultValues(); $this->resetModified(); $this->setNew(true); $this->setDeleted(false); }
[ "public", "function", "clear", "(", ")", "{", "if", "(", "null", "!==", "$", "this", "->", "aPermissionRelatedByParentId", ")", "{", "$", "this", "->", "aPermissionRelatedByParentId", "->", "removePermissionRelatedById", "(", "$", "this", ")", ";", "}", "$", "this", "->", "id", "=", "null", ";", "$", "this", "->", "name", "=", "null", ";", "$", "this", "->", "create_date", "=", "null", ";", "$", "this", "->", "description", "=", "null", ";", "$", "this", "->", "update_date", "=", "null", ";", "$", "this", "->", "status", "=", "null", ";", "$", "this", "->", "parent_id", "=", "null", ";", "$", "this", "->", "alreadyInSave", "=", "false", ";", "$", "this", "->", "clearAllReferences", "(", ")", ";", "$", "this", "->", "applyDefaultValues", "(", ")", ";", "$", "this", "->", "resetModified", "(", ")", ";", "$", "this", "->", "setNew", "(", "true", ")", ";", "$", "this", "->", "setDeleted", "(", "false", ")", ";", "}" ]
Clears the current object, sets all attributes to their default values and removes outgoing references as well as back-references (from other objects to this one. Results probably in a database change of those foreign objects when you call `save` there).
[ "Clears", "the", "current", "object", "sets", "all", "attributes", "to", "their", "default", "values", "and", "removes", "outgoing", "references", "as", "well", "as", "back", "-", "references", "(", "from", "other", "objects", "to", "this", "one", ".", "Results", "probably", "in", "a", "database", "change", "of", "those", "foreign", "objects", "when", "you", "call", "save", "there", ")", "." ]
train
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/Permission.php#L2245-L2263
phpalchemy/cerberus
src/Alchemy/Component/Cerberus/Model/Base/Permission.php
Permission.clearAllReferences
public function clearAllReferences($deep = false) { if ($deep) { if ($this->collPermissionsRelatedById) { foreach ($this->collPermissionsRelatedById as $o) { $o->clearAllReferences($deep); } } if ($this->collRolePermissions) { foreach ($this->collRolePermissions as $o) { $o->clearAllReferences($deep); } } if ($this->collRoles) { foreach ($this->collRoles as $o) { $o->clearAllReferences($deep); } } } // if ($deep) $this->collPermissionsRelatedById = null; $this->collRolePermissions = null; $this->collRoles = null; $this->aPermissionRelatedByParentId = null; }
php
public function clearAllReferences($deep = false) { if ($deep) { if ($this->collPermissionsRelatedById) { foreach ($this->collPermissionsRelatedById as $o) { $o->clearAllReferences($deep); } } if ($this->collRolePermissions) { foreach ($this->collRolePermissions as $o) { $o->clearAllReferences($deep); } } if ($this->collRoles) { foreach ($this->collRoles as $o) { $o->clearAllReferences($deep); } } } // if ($deep) $this->collPermissionsRelatedById = null; $this->collRolePermissions = null; $this->collRoles = null; $this->aPermissionRelatedByParentId = null; }
[ "public", "function", "clearAllReferences", "(", "$", "deep", "=", "false", ")", "{", "if", "(", "$", "deep", ")", "{", "if", "(", "$", "this", "->", "collPermissionsRelatedById", ")", "{", "foreach", "(", "$", "this", "->", "collPermissionsRelatedById", "as", "$", "o", ")", "{", "$", "o", "->", "clearAllReferences", "(", "$", "deep", ")", ";", "}", "}", "if", "(", "$", "this", "->", "collRolePermissions", ")", "{", "foreach", "(", "$", "this", "->", "collRolePermissions", "as", "$", "o", ")", "{", "$", "o", "->", "clearAllReferences", "(", "$", "deep", ")", ";", "}", "}", "if", "(", "$", "this", "->", "collRoles", ")", "{", "foreach", "(", "$", "this", "->", "collRoles", "as", "$", "o", ")", "{", "$", "o", "->", "clearAllReferences", "(", "$", "deep", ")", ";", "}", "}", "}", "// if ($deep)", "$", "this", "->", "collPermissionsRelatedById", "=", "null", ";", "$", "this", "->", "collRolePermissions", "=", "null", ";", "$", "this", "->", "collRoles", "=", "null", ";", "$", "this", "->", "aPermissionRelatedByParentId", "=", "null", ";", "}" ]
Resets all references and back-references to other model objects or collections of model objects. This method is used to reset all php object references (not the actual reference in the database). Necessary for object serialisation. @param boolean $deep Whether to also clear the references on all referrer objects.
[ "Resets", "all", "references", "and", "back", "-", "references", "to", "other", "model", "objects", "or", "collections", "of", "model", "objects", "." ]
train
https://github.com/phpalchemy/cerberus/blob/3424a360c9bded71eb5b570bc114a7759cb23ec6/src/Alchemy/Component/Cerberus/Model/Base/Permission.php#L2273-L2297
huasituo/hstcms
src/Libraries/Alipay/AopClient.php
AopClient.sdkExecute
public function sdkExecute($request) { $this->setupCharsets($request); $params['app_id'] = $this->appId; $params['method'] = $request->getApiMethodName(); $params['format'] = $this->format; $params['sign_type'] = $this->signType; $params['timestamp'] = date("Y-m-d H:i:s"); $params['alipay_sdk'] = $this->alipaySdkVersion; $params['charset'] = $this->postCharset; $version = $request->getApiVersion(); $params['version'] = $this->checkEmpty($version) ? $this->apiVersion : $version; if ($notify_url = $request->getNotifyUrl()) { $params['notify_url'] = $notify_url; } $dict = $request->getApiParas(); $params['biz_content'] = $dict['biz_content']; ksort($params); $params['sign'] = $this->generateSign($params, $this->signType); foreach ($params as &$value) { $value = $this->characet($value, $params['charset']); } return http_build_query($params); }
php
public function sdkExecute($request) { $this->setupCharsets($request); $params['app_id'] = $this->appId; $params['method'] = $request->getApiMethodName(); $params['format'] = $this->format; $params['sign_type'] = $this->signType; $params['timestamp'] = date("Y-m-d H:i:s"); $params['alipay_sdk'] = $this->alipaySdkVersion; $params['charset'] = $this->postCharset; $version = $request->getApiVersion(); $params['version'] = $this->checkEmpty($version) ? $this->apiVersion : $version; if ($notify_url = $request->getNotifyUrl()) { $params['notify_url'] = $notify_url; } $dict = $request->getApiParas(); $params['biz_content'] = $dict['biz_content']; ksort($params); $params['sign'] = $this->generateSign($params, $this->signType); foreach ($params as &$value) { $value = $this->characet($value, $params['charset']); } return http_build_query($params); }
[ "public", "function", "sdkExecute", "(", "$", "request", ")", "{", "$", "this", "->", "setupCharsets", "(", "$", "request", ")", ";", "$", "params", "[", "'app_id'", "]", "=", "$", "this", "->", "appId", ";", "$", "params", "[", "'method'", "]", "=", "$", "request", "->", "getApiMethodName", "(", ")", ";", "$", "params", "[", "'format'", "]", "=", "$", "this", "->", "format", ";", "$", "params", "[", "'sign_type'", "]", "=", "$", "this", "->", "signType", ";", "$", "params", "[", "'timestamp'", "]", "=", "date", "(", "\"Y-m-d H:i:s\"", ")", ";", "$", "params", "[", "'alipay_sdk'", "]", "=", "$", "this", "->", "alipaySdkVersion", ";", "$", "params", "[", "'charset'", "]", "=", "$", "this", "->", "postCharset", ";", "$", "version", "=", "$", "request", "->", "getApiVersion", "(", ")", ";", "$", "params", "[", "'version'", "]", "=", "$", "this", "->", "checkEmpty", "(", "$", "version", ")", "?", "$", "this", "->", "apiVersion", ":", "$", "version", ";", "if", "(", "$", "notify_url", "=", "$", "request", "->", "getNotifyUrl", "(", ")", ")", "{", "$", "params", "[", "'notify_url'", "]", "=", "$", "notify_url", ";", "}", "$", "dict", "=", "$", "request", "->", "getApiParas", "(", ")", ";", "$", "params", "[", "'biz_content'", "]", "=", "$", "dict", "[", "'biz_content'", "]", ";", "ksort", "(", "$", "params", ")", ";", "$", "params", "[", "'sign'", "]", "=", "$", "this", "->", "generateSign", "(", "$", "params", ",", "$", "this", "->", "signType", ")", ";", "foreach", "(", "$", "params", "as", "&", "$", "value", ")", "{", "$", "value", "=", "$", "this", "->", "characet", "(", "$", "value", ",", "$", "params", "[", "'charset'", "]", ")", ";", "}", "return", "http_build_query", "(", "$", "params", ")", ";", "}" ]
生成用于调用收银台SDK的字符串 @param $request SDK接口的请求参数对象 @return string @author guofa.tgf
[ "生成用于调用收银台SDK的字符串" ]
train
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/Alipay/AopClient.php#L283-L314
huasituo/hstcms
src/Libraries/Alipay/AopClient.php
AopClient.pageExecute
public function pageExecute($request,$httpmethod = "POST") { $this->setupCharsets($request); if (strcasecmp($this->fileCharset, $this->postCharset)) { // writeLog("本地文件字符集编码与表单提交编码不一致,请务必设置成一样,属性名分别为postCharset!"); throw new Exception("文件编码:[" . $this->fileCharset . "] 与表单提交编码:[" . $this->postCharset . "]两者不一致!"); } $iv=null; if(!$this->checkEmpty($request->getApiVersion())){ $iv=$request->getApiVersion(); }else{ $iv=$this->apiVersion; } //组装系统参数 $sysParams["app_id"] = $this->appId; $sysParams["version"] = $iv; $sysParams["format"] = $this->format; $sysParams["sign_type"] = $this->signType; $sysParams["method"] = $request->getApiMethodName(); $sysParams["timestamp"] = date("Y-m-d H:i:s"); $sysParams["alipay_sdk"] = $this->alipaySdkVersion; $sysParams["terminal_type"] = $request->getTerminalType(); $sysParams["terminal_info"] = $request->getTerminalInfo(); $sysParams["prod_code"] = $request->getProdCode(); $sysParams["notify_url"] = $request->getNotifyUrl(); $sysParams["return_url"] = $request->getReturnUrl(); $sysParams["charset"] = $this->postCharset; //获取业务参数 $apiParams = $request->getApiParas(); if (method_exists($request,"getNeedEncrypt") &&$request->getNeedEncrypt()){ $sysParams["encrypt_type"] = $this->encryptType; if ($this->checkEmpty($apiParams['biz_content'])) { throw new Exception(" api request Fail! The reason : encrypt request is not supperted!"); } if ($this->checkEmpty($this->encryptKey) || $this->checkEmpty($this->encryptType)) { throw new Exception(" encryptType and encryptKey must not null! "); } if ("AES" != $this->encryptType) { throw new Exception("加密类型只支持AES"); } // 执行加密 $enCryptContent = encrypts($apiParams['biz_content'], $this->encryptKey); $apiParams['biz_content'] = $enCryptContent; } //print_r($apiParams); $totalParams = array_merge($apiParams, $sysParams); //待签名字符串 $preSignStr = $this->getSignContent($totalParams); //签名 $totalParams["sign"] = $this->generateSign($totalParams, $this->signType); if ("GET" == strtoupper($httpmethod)) { //value做urlencode $preString=$this->getSignContentUrlencode($totalParams); //拼接GET请求串 $requestUrl = $this->gatewayUrl."?".$preString; return $requestUrl; } else { //拼接表单字符串 return $this->buildRequestForm($totalParams); } }
php
public function pageExecute($request,$httpmethod = "POST") { $this->setupCharsets($request); if (strcasecmp($this->fileCharset, $this->postCharset)) { // writeLog("本地文件字符集编码与表单提交编码不一致,请务必设置成一样,属性名分别为postCharset!"); throw new Exception("文件编码:[" . $this->fileCharset . "] 与表单提交编码:[" . $this->postCharset . "]两者不一致!"); } $iv=null; if(!$this->checkEmpty($request->getApiVersion())){ $iv=$request->getApiVersion(); }else{ $iv=$this->apiVersion; } //组装系统参数 $sysParams["app_id"] = $this->appId; $sysParams["version"] = $iv; $sysParams["format"] = $this->format; $sysParams["sign_type"] = $this->signType; $sysParams["method"] = $request->getApiMethodName(); $sysParams["timestamp"] = date("Y-m-d H:i:s"); $sysParams["alipay_sdk"] = $this->alipaySdkVersion; $sysParams["terminal_type"] = $request->getTerminalType(); $sysParams["terminal_info"] = $request->getTerminalInfo(); $sysParams["prod_code"] = $request->getProdCode(); $sysParams["notify_url"] = $request->getNotifyUrl(); $sysParams["return_url"] = $request->getReturnUrl(); $sysParams["charset"] = $this->postCharset; //获取业务参数 $apiParams = $request->getApiParas(); if (method_exists($request,"getNeedEncrypt") &&$request->getNeedEncrypt()){ $sysParams["encrypt_type"] = $this->encryptType; if ($this->checkEmpty($apiParams['biz_content'])) { throw new Exception(" api request Fail! The reason : encrypt request is not supperted!"); } if ($this->checkEmpty($this->encryptKey) || $this->checkEmpty($this->encryptType)) { throw new Exception(" encryptType and encryptKey must not null! "); } if ("AES" != $this->encryptType) { throw new Exception("加密类型只支持AES"); } // 执行加密 $enCryptContent = encrypts($apiParams['biz_content'], $this->encryptKey); $apiParams['biz_content'] = $enCryptContent; } //print_r($apiParams); $totalParams = array_merge($apiParams, $sysParams); //待签名字符串 $preSignStr = $this->getSignContent($totalParams); //签名 $totalParams["sign"] = $this->generateSign($totalParams, $this->signType); if ("GET" == strtoupper($httpmethod)) { //value做urlencode $preString=$this->getSignContentUrlencode($totalParams); //拼接GET请求串 $requestUrl = $this->gatewayUrl."?".$preString; return $requestUrl; } else { //拼接表单字符串 return $this->buildRequestForm($totalParams); } }
[ "public", "function", "pageExecute", "(", "$", "request", ",", "$", "httpmethod", "=", "\"POST\"", ")", "{", "$", "this", "->", "setupCharsets", "(", "$", "request", ")", ";", "if", "(", "strcasecmp", "(", "$", "this", "->", "fileCharset", ",", "$", "this", "->", "postCharset", ")", ")", "{", "// writeLog(\"本地文件字符集编码与表单提交编码不一致,请务必设置成一样,属性名分别为postCharset!\");", "throw", "new", "Exception", "(", "\"文件编码:[\" . $this->", "i", "e", "Char", "se", "t . \"] 与表单提", "编", ":[\" . $this->postCharset . \"]", "者", "一", "致!\")", ";", "", "", "", "", "", "}", "$", "iv", "=", "null", ";", "if", "(", "!", "$", "this", "->", "checkEmpty", "(", "$", "request", "->", "getApiVersion", "(", ")", ")", ")", "{", "$", "iv", "=", "$", "request", "->", "getApiVersion", "(", ")", ";", "}", "else", "{", "$", "iv", "=", "$", "this", "->", "apiVersion", ";", "}", "//组装系统参数", "$", "sysParams", "[", "\"app_id\"", "]", "=", "$", "this", "->", "appId", ";", "$", "sysParams", "[", "\"version\"", "]", "=", "$", "iv", ";", "$", "sysParams", "[", "\"format\"", "]", "=", "$", "this", "->", "format", ";", "$", "sysParams", "[", "\"sign_type\"", "]", "=", "$", "this", "->", "signType", ";", "$", "sysParams", "[", "\"method\"", "]", "=", "$", "request", "->", "getApiMethodName", "(", ")", ";", "$", "sysParams", "[", "\"timestamp\"", "]", "=", "date", "(", "\"Y-m-d H:i:s\"", ")", ";", "$", "sysParams", "[", "\"alipay_sdk\"", "]", "=", "$", "this", "->", "alipaySdkVersion", ";", "$", "sysParams", "[", "\"terminal_type\"", "]", "=", "$", "request", "->", "getTerminalType", "(", ")", ";", "$", "sysParams", "[", "\"terminal_info\"", "]", "=", "$", "request", "->", "getTerminalInfo", "(", ")", ";", "$", "sysParams", "[", "\"prod_code\"", "]", "=", "$", "request", "->", "getProdCode", "(", ")", ";", "$", "sysParams", "[", "\"notify_url\"", "]", "=", "$", "request", "->", "getNotifyUrl", "(", ")", ";", "$", "sysParams", "[", "\"return_url\"", "]", "=", "$", "request", "->", "getReturnUrl", "(", ")", ";", "$", "sysParams", "[", "\"charset\"", "]", "=", "$", "this", "->", "postCharset", ";", "//获取业务参数", "$", "apiParams", "=", "$", "request", "->", "getApiParas", "(", ")", ";", "if", "(", "method_exists", "(", "$", "request", ",", "\"getNeedEncrypt\"", ")", "&&", "$", "request", "->", "getNeedEncrypt", "(", ")", ")", "{", "$", "sysParams", "[", "\"encrypt_type\"", "]", "=", "$", "this", "->", "encryptType", ";", "if", "(", "$", "this", "->", "checkEmpty", "(", "$", "apiParams", "[", "'biz_content'", "]", ")", ")", "{", "throw", "new", "Exception", "(", "\" api request Fail! The reason : encrypt request is not supperted!\"", ")", ";", "}", "if", "(", "$", "this", "->", "checkEmpty", "(", "$", "this", "->", "encryptKey", ")", "||", "$", "this", "->", "checkEmpty", "(", "$", "this", "->", "encryptType", ")", ")", "{", "throw", "new", "Exception", "(", "\" encryptType and encryptKey must not null! \"", ")", ";", "}", "if", "(", "\"AES\"", "!=", "$", "this", "->", "encryptType", ")", "{", "throw", "new", "Exception", "(", "\"加密类型只支持AES\");", "", "", "}", "// 执行加密", "$", "enCryptContent", "=", "encrypts", "(", "$", "apiParams", "[", "'biz_content'", "]", ",", "$", "this", "->", "encryptKey", ")", ";", "$", "apiParams", "[", "'biz_content'", "]", "=", "$", "enCryptContent", ";", "}", "//print_r($apiParams);", "$", "totalParams", "=", "array_merge", "(", "$", "apiParams", ",", "$", "sysParams", ")", ";", "//待签名字符串", "$", "preSignStr", "=", "$", "this", "->", "getSignContent", "(", "$", "totalParams", ")", ";", "//签名", "$", "totalParams", "[", "\"sign\"", "]", "=", "$", "this", "->", "generateSign", "(", "$", "totalParams", ",", "$", "this", "->", "signType", ")", ";", "if", "(", "\"GET\"", "==", "strtoupper", "(", "$", "httpmethod", ")", ")", "{", "//value做urlencode", "$", "preString", "=", "$", "this", "->", "getSignContentUrlencode", "(", "$", "totalParams", ")", ";", "//拼接GET请求串", "$", "requestUrl", "=", "$", "this", "->", "gatewayUrl", ".", "\"?\"", ".", "$", "preString", ";", "return", "$", "requestUrl", ";", "}", "else", "{", "//拼接表单字符串", "return", "$", "this", "->", "buildRequestForm", "(", "$", "totalParams", ")", ";", "}", "}" ]
/* 页面提交执行方法 @param:跳转类接口的request; $httpmethod 提交方式。两个值可选:post、get @return:构建好的、签名后的最终跳转URL(GET)或String形式的form(POST) auther:笙默
[ "/", "*", "页面提交执行方法" ]
train
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/Alipay/AopClient.php#L322-L406
huasituo/hstcms
src/Libraries/Alipay/AopClient.php
AopClient.buildRequestForm
protected function buildRequestForm($para_temp) { $sHtml = "<form id='alipaysubmit' name='alipaysubmit' action='".$this->gatewayUrl."?charset=".trim($this->postCharset)."' method='POST'>"; while (list ($key, $val) = each ($para_temp)) { if (false === $this->checkEmpty($val)) { //$val = $this->characet($val, $this->postCharset); $val = str_replace("'","&apos;",$val); //$val = str_replace("\"","&quot;",$val); $sHtml.= "<input type='hidden' name='".$key."' value='".$val."'/>"; } } //submit按钮控件请不要含有name属性 $sHtml = $sHtml."<input type='submit' value='ok' style='display:none;''></form>"; $sHtml = $sHtml."<script>document.forms['alipaysubmit'].submit();</script>"; return $sHtml; }
php
protected function buildRequestForm($para_temp) { $sHtml = "<form id='alipaysubmit' name='alipaysubmit' action='".$this->gatewayUrl."?charset=".trim($this->postCharset)."' method='POST'>"; while (list ($key, $val) = each ($para_temp)) { if (false === $this->checkEmpty($val)) { //$val = $this->characet($val, $this->postCharset); $val = str_replace("'","&apos;",$val); //$val = str_replace("\"","&quot;",$val); $sHtml.= "<input type='hidden' name='".$key."' value='".$val."'/>"; } } //submit按钮控件请不要含有name属性 $sHtml = $sHtml."<input type='submit' value='ok' style='display:none;''></form>"; $sHtml = $sHtml."<script>document.forms['alipaysubmit'].submit();</script>"; return $sHtml; }
[ "protected", "function", "buildRequestForm", "(", "$", "para_temp", ")", "{", "$", "sHtml", "=", "\"<form id='alipaysubmit' name='alipaysubmit' action='\"", ".", "$", "this", "->", "gatewayUrl", ".", "\"?charset=\"", ".", "trim", "(", "$", "this", "->", "postCharset", ")", ".", "\"' method='POST'>\"", ";", "while", "(", "list", "(", "$", "key", ",", "$", "val", ")", "=", "each", "(", "$", "para_temp", ")", ")", "{", "if", "(", "false", "===", "$", "this", "->", "checkEmpty", "(", "$", "val", ")", ")", "{", "//$val = $this->characet($val, $this->postCharset);", "$", "val", "=", "str_replace", "(", "\"'\"", ",", "\"&apos;\"", ",", "$", "val", ")", ";", "//$val = str_replace(\"\\\"\",\"&quot;\",$val);", "$", "sHtml", ".=", "\"<input type='hidden' name='\"", ".", "$", "key", ".", "\"' value='\"", ".", "$", "val", ".", "\"'/>\"", ";", "}", "}", "//submit按钮控件请不要含有name属性", "$", "sHtml", "=", "$", "sHtml", ".", "\"<input type='submit' value='ok' style='display:none;''></form>\"", ";", "$", "sHtml", "=", "$", "sHtml", ".", "\"<script>document.forms['alipaysubmit'].submit();</script>\"", ";", "return", "$", "sHtml", ";", "}" ]
建立请求,以表单HTML形式构造(默认) @param $para_temp 请求参数数组 @return 提交表单HTML文本
[ "建立请求,以表单HTML形式构造(默认)" ]
train
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/Alipay/AopClient.php#L415-L433
huasituo/hstcms
src/Libraries/Alipay/AopClient.php
AopClient.characet
function characet($data, $targetCharset) { if (!empty($data)) { $fileType = $this->fileCharset; if (strcasecmp($fileType, $targetCharset) != 0) { $data = mb_convert_encoding($data, $targetCharset, $fileType); // $data = iconv($fileType, $targetCharset.'//IGNORE', $data); } } return $data; }
php
function characet($data, $targetCharset) { if (!empty($data)) { $fileType = $this->fileCharset; if (strcasecmp($fileType, $targetCharset) != 0) { $data = mb_convert_encoding($data, $targetCharset, $fileType); // $data = iconv($fileType, $targetCharset.'//IGNORE', $data); } } return $data; }
[ "function", "characet", "(", "$", "data", ",", "$", "targetCharset", ")", "{", "if", "(", "!", "empty", "(", "$", "data", ")", ")", "{", "$", "fileType", "=", "$", "this", "->", "fileCharset", ";", "if", "(", "strcasecmp", "(", "$", "fileType", ",", "$", "targetCharset", ")", "!=", "0", ")", "{", "$", "data", "=", "mb_convert_encoding", "(", "$", "data", ",", "$", "targetCharset", ",", "$", "fileType", ")", ";", "//\t\t\t\t$data = iconv($fileType, $targetCharset.'//IGNORE', $data);", "}", "}", "return", "$", "data", ";", "}" ]
转换字符集编码 @param $data @param $targetCharset @return string
[ "转换字符集编码" ]
train
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/Alipay/AopClient.php#L591-L603
huasituo/hstcms
src/Libraries/Alipay/AopClient.php
AopClient.rsaCheckV1
public function rsaCheckV1($params, $rsaPublicKeyFilePath,$signType='RSA') { $sign = $params['sign']; $params['sign_type'] = null; $params['sign'] = null; return $this->verify($this->getSignContent($params), $sign, $rsaPublicKeyFilePath,$signType); }
php
public function rsaCheckV1($params, $rsaPublicKeyFilePath,$signType='RSA') { $sign = $params['sign']; $params['sign_type'] = null; $params['sign'] = null; return $this->verify($this->getSignContent($params), $sign, $rsaPublicKeyFilePath,$signType); }
[ "public", "function", "rsaCheckV1", "(", "$", "params", ",", "$", "rsaPublicKeyFilePath", ",", "$", "signType", "=", "'RSA'", ")", "{", "$", "sign", "=", "$", "params", "[", "'sign'", "]", ";", "$", "params", "[", "'sign_type'", "]", "=", "null", ";", "$", "params", "[", "'sign'", "]", "=", "null", ";", "return", "$", "this", "->", "verify", "(", "$", "this", "->", "getSignContent", "(", "$", "params", ")", ",", "$", "sign", ",", "$", "rsaPublicKeyFilePath", ",", "$", "signType", ")", ";", "}" ]
rsaCheckV1 & rsaCheckV2 验证签名 在使用本方法前,必须初始化AopClient且传入公钥参数。 公钥是否是读取字符串还是读取文件,是根据初始化传入的值判断的。
[ "rsaCheckV1", "&", "rsaCheckV2", "验证签名", "在使用本方法前,必须初始化AopClient且传入公钥参数。", "公钥是否是读取字符串还是读取文件,是根据初始化传入的值判断的。" ]
train
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/Alipay/AopClient.php#L652-L657
huasituo/hstcms
src/Libraries/Alipay/AopClient.php
AopClient.checkSignAndDecrypt
public function checkSignAndDecrypt($params, $rsaPublicKeyPem, $rsaPrivateKeyPem, $isCheckSign, $isDecrypt, $signType='RSA') { $charset = $params['charset']; $bizContent = $params['biz_content']; if ($isCheckSign) { if (!$this->rsaCheckV2($params, $rsaPublicKeyPem, $signType)) { echo "<br/>checkSign failure<br/>"; exit; } } if ($isDecrypt) { return $this->rsaDecrypt($bizContent, $rsaPrivateKeyPem, $charset); } return $bizContent; }
php
public function checkSignAndDecrypt($params, $rsaPublicKeyPem, $rsaPrivateKeyPem, $isCheckSign, $isDecrypt, $signType='RSA') { $charset = $params['charset']; $bizContent = $params['biz_content']; if ($isCheckSign) { if (!$this->rsaCheckV2($params, $rsaPublicKeyPem, $signType)) { echo "<br/>checkSign failure<br/>"; exit; } } if ($isDecrypt) { return $this->rsaDecrypt($bizContent, $rsaPrivateKeyPem, $charset); } return $bizContent; }
[ "public", "function", "checkSignAndDecrypt", "(", "$", "params", ",", "$", "rsaPublicKeyPem", ",", "$", "rsaPrivateKeyPem", ",", "$", "isCheckSign", ",", "$", "isDecrypt", ",", "$", "signType", "=", "'RSA'", ")", "{", "$", "charset", "=", "$", "params", "[", "'charset'", "]", ";", "$", "bizContent", "=", "$", "params", "[", "'biz_content'", "]", ";", "if", "(", "$", "isCheckSign", ")", "{", "if", "(", "!", "$", "this", "->", "rsaCheckV2", "(", "$", "params", ",", "$", "rsaPublicKeyPem", ",", "$", "signType", ")", ")", "{", "echo", "\"<br/>checkSign failure<br/>\"", ";", "exit", ";", "}", "}", "if", "(", "$", "isDecrypt", ")", "{", "return", "$", "this", "->", "rsaDecrypt", "(", "$", "bizContent", ",", "$", "rsaPrivateKeyPem", ",", "$", "charset", ")", ";", "}", "return", "$", "bizContent", ";", "}" ]
在使用本方法前,必须初始化AopClient且传入公私钥参数。 公钥是否是读取字符串还是读取文件,是根据初始化传入的值判断的。
[ "在使用本方法前,必须初始化AopClient且传入公私钥参数。", "公钥是否是读取字符串还是读取文件,是根据初始化传入的值判断的。" ]
train
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/Alipay/AopClient.php#L701-L715
huasituo/hstcms
src/Libraries/Alipay/AopClient.php
AopClient.encryptAndSign
public function encryptAndSign($bizContent, $rsaPublicKeyPem, $rsaPrivateKeyPem, $charset, $isEncrypt, $isSign, $signType='RSA') { // 加密,并签名 if ($isEncrypt && $isSign) { $encrypted = $this->rsaEncrypt($bizContent, $rsaPublicKeyPem, $charset); $sign = $this->sign($encrypted, $signType); $response = "<?xml version=\"1.0\" encoding=\"$charset\"?><alipay><response>$encrypted</response><encryption_type>RSA</encryption_type><sign>$sign</sign><sign_type>$signType</sign_type></alipay>"; return $response; } // 加密,不签名 if ($isEncrypt && (!$isSign)) { $encrypted = $this->rsaEncrypt($bizContent, $rsaPublicKeyPem, $charset); $response = "<?xml version=\"1.0\" encoding=\"$charset\"?><alipay><response>$encrypted</response><encryption_type>$signType</encryption_type></alipay>"; return $response; } // 不加密,但签名 if ((!$isEncrypt) && $isSign) { $sign = $this->sign($bizContent, $signType); $response = "<?xml version=\"1.0\" encoding=\"$charset\"?><alipay><response>$bizContent</response><sign>$sign</sign><sign_type>$signType</sign_type></alipay>"; return $response; } // 不加密,不签名 $response = "<?xml version=\"1.0\" encoding=\"$charset\"?>$bizContent"; return $response; }
php
public function encryptAndSign($bizContent, $rsaPublicKeyPem, $rsaPrivateKeyPem, $charset, $isEncrypt, $isSign, $signType='RSA') { // 加密,并签名 if ($isEncrypt && $isSign) { $encrypted = $this->rsaEncrypt($bizContent, $rsaPublicKeyPem, $charset); $sign = $this->sign($encrypted, $signType); $response = "<?xml version=\"1.0\" encoding=\"$charset\"?><alipay><response>$encrypted</response><encryption_type>RSA</encryption_type><sign>$sign</sign><sign_type>$signType</sign_type></alipay>"; return $response; } // 加密,不签名 if ($isEncrypt && (!$isSign)) { $encrypted = $this->rsaEncrypt($bizContent, $rsaPublicKeyPem, $charset); $response = "<?xml version=\"1.0\" encoding=\"$charset\"?><alipay><response>$encrypted</response><encryption_type>$signType</encryption_type></alipay>"; return $response; } // 不加密,但签名 if ((!$isEncrypt) && $isSign) { $sign = $this->sign($bizContent, $signType); $response = "<?xml version=\"1.0\" encoding=\"$charset\"?><alipay><response>$bizContent</response><sign>$sign</sign><sign_type>$signType</sign_type></alipay>"; return $response; } // 不加密,不签名 $response = "<?xml version=\"1.0\" encoding=\"$charset\"?>$bizContent"; return $response; }
[ "public", "function", "encryptAndSign", "(", "$", "bizContent", ",", "$", "rsaPublicKeyPem", ",", "$", "rsaPrivateKeyPem", ",", "$", "charset", ",", "$", "isEncrypt", ",", "$", "isSign", ",", "$", "signType", "=", "'RSA'", ")", "{", "// 加密,并签名", "if", "(", "$", "isEncrypt", "&&", "$", "isSign", ")", "{", "$", "encrypted", "=", "$", "this", "->", "rsaEncrypt", "(", "$", "bizContent", ",", "$", "rsaPublicKeyPem", ",", "$", "charset", ")", ";", "$", "sign", "=", "$", "this", "->", "sign", "(", "$", "encrypted", ",", "$", "signType", ")", ";", "$", "response", "=", "\"<?xml version=\\\"1.0\\\" encoding=\\\"$charset\\\"?><alipay><response>$encrypted</response><encryption_type>RSA</encryption_type><sign>$sign</sign><sign_type>$signType</sign_type></alipay>\"", ";", "return", "$", "response", ";", "}", "// 加密,不签名", "if", "(", "$", "isEncrypt", "&&", "(", "!", "$", "isSign", ")", ")", "{", "$", "encrypted", "=", "$", "this", "->", "rsaEncrypt", "(", "$", "bizContent", ",", "$", "rsaPublicKeyPem", ",", "$", "charset", ")", ";", "$", "response", "=", "\"<?xml version=\\\"1.0\\\" encoding=\\\"$charset\\\"?><alipay><response>$encrypted</response><encryption_type>$signType</encryption_type></alipay>\"", ";", "return", "$", "response", ";", "}", "// 不加密,但签名", "if", "(", "(", "!", "$", "isEncrypt", ")", "&&", "$", "isSign", ")", "{", "$", "sign", "=", "$", "this", "->", "sign", "(", "$", "bizContent", ",", "$", "signType", ")", ";", "$", "response", "=", "\"<?xml version=\\\"1.0\\\" encoding=\\\"$charset\\\"?><alipay><response>$bizContent</response><sign>$sign</sign><sign_type>$signType</sign_type></alipay>\"", ";", "return", "$", "response", ";", "}", "// 不加密,不签名", "$", "response", "=", "\"<?xml version=\\\"1.0\\\" encoding=\\\"$charset\\\"?>$bizContent\"", ";", "return", "$", "response", ";", "}" ]
在使用本方法前,必须初始化AopClient且传入公私钥参数。 公钥是否是读取字符串还是读取文件,是根据初始化传入的值判断的。
[ "在使用本方法前,必须初始化AopClient且传入公私钥参数。", "公钥是否是读取字符串还是读取文件,是根据初始化传入的值判断的。" ]
train
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/Alipay/AopClient.php#L721-L744
huasituo/hstcms
src/Libraries/Alipay/AopClient.php
AopClient.rsaEncrypt
public function rsaEncrypt($data, $rsaPublicKeyPem, $charset) { if($this->checkEmpty($this->alipayPublicKey)){ //读取字符串 $pubKey= $this->alipayrsaPublicKey; $res = "-----BEGIN PUBLIC KEY-----\n" . wordwrap($pubKey, 64, "\n", true) . "\n-----END PUBLIC KEY-----"; }else { //读取公钥文件 $pubKey = file_get_contents($rsaPublicKeyFilePath); //转换为openssl格式密钥 $res = openssl_get_publickey($pubKey); } ($res) or die('支付宝RSA公钥错误。请检查公钥文件格式是否正确'); $blocks = $this->splitCN($data, 0, 30, $charset); $chrtext  = null; $encodes  = array(); foreach ($blocks as $n => $block) { if (!openssl_public_encrypt($block, $chrtext , $res)) { echo "<br/>" . openssl_error_string() . "<br/>"; } $encodes[] = $chrtext ; } $chrtext = implode(",", $encodes); return base64_encode($chrtext); }
php
public function rsaEncrypt($data, $rsaPublicKeyPem, $charset) { if($this->checkEmpty($this->alipayPublicKey)){ //读取字符串 $pubKey= $this->alipayrsaPublicKey; $res = "-----BEGIN PUBLIC KEY-----\n" . wordwrap($pubKey, 64, "\n", true) . "\n-----END PUBLIC KEY-----"; }else { //读取公钥文件 $pubKey = file_get_contents($rsaPublicKeyFilePath); //转换为openssl格式密钥 $res = openssl_get_publickey($pubKey); } ($res) or die('支付宝RSA公钥错误。请检查公钥文件格式是否正确'); $blocks = $this->splitCN($data, 0, 30, $charset); $chrtext  = null; $encodes  = array(); foreach ($blocks as $n => $block) { if (!openssl_public_encrypt($block, $chrtext , $res)) { echo "<br/>" . openssl_error_string() . "<br/>"; } $encodes[] = $chrtext ; } $chrtext = implode(",", $encodes); return base64_encode($chrtext); }
[ "public", "function", "rsaEncrypt", "(", "$", "data", ",", "$", "rsaPublicKeyPem", ",", "$", "charset", ")", "{", "if", "(", "$", "this", "->", "checkEmpty", "(", "$", "this", "->", "alipayPublicKey", ")", ")", "{", "//读取字符串", "$", "pubKey", "=", "$", "this", "->", "alipayrsaPublicKey", ";", "$", "res", "=", "\"-----BEGIN PUBLIC KEY-----\\n\"", ".", "wordwrap", "(", "$", "pubKey", ",", "64", ",", "\"\\n\"", ",", "true", ")", ".", "\"\\n-----END PUBLIC KEY-----\"", ";", "}", "else", "{", "//读取公钥文件", "$", "pubKey", "=", "file_get_contents", "(", "$", "rsaPublicKeyFilePath", ")", ";", "//转换为openssl格式密钥", "$", "res", "=", "openssl_get_publickey", "(", "$", "pubKey", ")", ";", "}", "(", "$", "res", ")", "or", "die", "(", "'支付宝RSA公钥错误。请检查公钥文件格式是否正确'); ", "", "", "$", "blocks", "=", "$", "this", "->", "splitCN", "(", "$", "data", ",", "0", ",", "30", ",", "$", "charset", ")", ";", "$", "chrtext  ", " ", "ull;", "", "$", "encodes  ", " ", "rray(", ")", ";", "", "foreach", "(", "$", "blocks", "as", "$", "n", "=>", "$", "block", ")", "{", "if", "(", "!", "openssl_public_encrypt", "(", "$", "block", ",", "$", "chrtext ,", " ", "r", "es)", ")", " ", "", "echo", "\"<br/>\"", ".", "openssl_error_string", "(", ")", ".", "\"<br/>\"", ";", "}", "$", "encodes", "[", "]", "=", "$", "chrtext ;", "", "}", "$", "chrtext", "=", "implode", "(", "\",\"", ",", "$", "encodes", ")", ";", "return", "base64_encode", "(", "$", "chrtext", ")", ";", "}" ]
在使用本方法前,必须初始化AopClient且传入公私钥参数。 公钥是否是读取字符串还是读取文件,是根据初始化传入的值判断的。
[ "在使用本方法前,必须初始化AopClient且传入公私钥参数。", "公钥是否是读取字符串还是读取文件,是根据初始化传入的值判断的。" ]
train
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/Alipay/AopClient.php#L750-L777
huasituo/hstcms
src/Libraries/Alipay/AopClient.php
AopClient.rsaDecrypt
public function rsaDecrypt($data, $rsaPrivateKeyPem, $charset) { if($this->checkEmpty($this->rsaPrivateKeyFilePath)){ //读字符串 $priKey=$this->rsaPrivateKey; $res = "-----BEGIN RSA PRIVATE KEY-----\n" . wordwrap($priKey, 64, "\n", true) . "\n-----END RSA PRIVATE KEY-----"; }else { $priKey = file_get_contents($this->rsaPrivateKeyFilePath); $res = openssl_get_privatekey($priKey); } ($res) or die('您使用的私钥格式错误,请检查RSA私钥配置'); //转换为openssl格式密钥 $decodes = explode(',', $data); $strnull = ""; $dcyCont = ""; foreach ($decodes as $n => $decode) { if (!openssl_private_decrypt($decode, $dcyCont, $res)) { echo "<br/>" . openssl_error_string() . "<br/>"; } $strnull .= $dcyCont; } return $strnull; }
php
public function rsaDecrypt($data, $rsaPrivateKeyPem, $charset) { if($this->checkEmpty($this->rsaPrivateKeyFilePath)){ //读字符串 $priKey=$this->rsaPrivateKey; $res = "-----BEGIN RSA PRIVATE KEY-----\n" . wordwrap($priKey, 64, "\n", true) . "\n-----END RSA PRIVATE KEY-----"; }else { $priKey = file_get_contents($this->rsaPrivateKeyFilePath); $res = openssl_get_privatekey($priKey); } ($res) or die('您使用的私钥格式错误,请检查RSA私钥配置'); //转换为openssl格式密钥 $decodes = explode(',', $data); $strnull = ""; $dcyCont = ""; foreach ($decodes as $n => $decode) { if (!openssl_private_decrypt($decode, $dcyCont, $res)) { echo "<br/>" . openssl_error_string() . "<br/>"; } $strnull .= $dcyCont; } return $strnull; }
[ "public", "function", "rsaDecrypt", "(", "$", "data", ",", "$", "rsaPrivateKeyPem", ",", "$", "charset", ")", "{", "if", "(", "$", "this", "->", "checkEmpty", "(", "$", "this", "->", "rsaPrivateKeyFilePath", ")", ")", "{", "//读字符串", "$", "priKey", "=", "$", "this", "->", "rsaPrivateKey", ";", "$", "res", "=", "\"-----BEGIN RSA PRIVATE KEY-----\\n\"", ".", "wordwrap", "(", "$", "priKey", ",", "64", ",", "\"\\n\"", ",", "true", ")", ".", "\"\\n-----END RSA PRIVATE KEY-----\"", ";", "}", "else", "{", "$", "priKey", "=", "file_get_contents", "(", "$", "this", "->", "rsaPrivateKeyFilePath", ")", ";", "$", "res", "=", "openssl_get_privatekey", "(", "$", "priKey", ")", ";", "}", "(", "$", "res", ")", "or", "die", "(", "'您使用的私钥格式错误,请检查RSA私钥配置'); ", "", "", "//转换为openssl格式密钥", "$", "decodes", "=", "explode", "(", "','", ",", "$", "data", ")", ";", "$", "strnull", "=", "\"\"", ";", "$", "dcyCont", "=", "\"\"", ";", "foreach", "(", "$", "decodes", "as", "$", "n", "=>", "$", "decode", ")", "{", "if", "(", "!", "openssl_private_decrypt", "(", "$", "decode", ",", "$", "dcyCont", ",", "$", "res", ")", ")", "{", "echo", "\"<br/>\"", ".", "openssl_error_string", "(", ")", ".", "\"<br/>\"", ";", "}", "$", "strnull", ".=", "$", "dcyCont", ";", "}", "return", "$", "strnull", ";", "}" ]
在使用本方法前,必须初始化AopClient且传入公私钥参数。 公钥是否是读取字符串还是读取文件,是根据初始化传入的值判断的。
[ "在使用本方法前,必须初始化AopClient且传入公私钥参数。", "公钥是否是读取字符串还是读取文件,是根据初始化传入的值判断的。" ]
train
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/Alipay/AopClient.php#L783-L807
huasituo/hstcms
src/Libraries/Alipay/AopClient.php
AopClient.checkResponseSign
public function checkResponseSign($request, $signData, $resp, $respObject) { if (!$this->checkEmpty($this->alipayPublicKey) || !$this->checkEmpty($this->alipayrsaPublicKey)) { if ($signData == null || $this->checkEmpty($signData->sign) || $this->checkEmpty($signData->signSourceData)) { throw new Exception(" check sign Fail! The reason : signData is Empty"); } // 获取结果sub_code $responseSubCode = $this->parserResponseSubCode($request, $resp, $respObject, $this->format); if (!$this->checkEmpty($responseSubCode) || ($this->checkEmpty($responseSubCode) && !$this->checkEmpty($signData->sign))) { $checkResult = $this->verify($signData->signSourceData, $signData->sign, $this->alipayPublicKey, $this->signType); if (!$checkResult) { if (strpos($signData->signSourceData, "\\/") > 0) { $signData->signSourceData = str_replace("\\/", "/", $signData->signSourceData); $checkResult = $this->verify($signData->signSourceData, $signData->sign, $this->alipayPublicKey, $this->signType); if (!$checkResult) { throw new Exception("check sign Fail! [sign=" . $signData->sign . ", signSourceData=" . $signData->signSourceData . "]"); } } else { throw new Exception("check sign Fail! [sign=" . $signData->sign . ", signSourceData=" . $signData->signSourceData . "]"); } } } } }
php
public function checkResponseSign($request, $signData, $resp, $respObject) { if (!$this->checkEmpty($this->alipayPublicKey) || !$this->checkEmpty($this->alipayrsaPublicKey)) { if ($signData == null || $this->checkEmpty($signData->sign) || $this->checkEmpty($signData->signSourceData)) { throw new Exception(" check sign Fail! The reason : signData is Empty"); } // 获取结果sub_code $responseSubCode = $this->parserResponseSubCode($request, $resp, $respObject, $this->format); if (!$this->checkEmpty($responseSubCode) || ($this->checkEmpty($responseSubCode) && !$this->checkEmpty($signData->sign))) { $checkResult = $this->verify($signData->signSourceData, $signData->sign, $this->alipayPublicKey, $this->signType); if (!$checkResult) { if (strpos($signData->signSourceData, "\\/") > 0) { $signData->signSourceData = str_replace("\\/", "/", $signData->signSourceData); $checkResult = $this->verify($signData->signSourceData, $signData->sign, $this->alipayPublicKey, $this->signType); if (!$checkResult) { throw new Exception("check sign Fail! [sign=" . $signData->sign . ", signSourceData=" . $signData->signSourceData . "]"); } } else { throw new Exception("check sign Fail! [sign=" . $signData->sign . ", signSourceData=" . $signData->signSourceData . "]"); } } } } }
[ "public", "function", "checkResponseSign", "(", "$", "request", ",", "$", "signData", ",", "$", "resp", ",", "$", "respObject", ")", "{", "if", "(", "!", "$", "this", "->", "checkEmpty", "(", "$", "this", "->", "alipayPublicKey", ")", "||", "!", "$", "this", "->", "checkEmpty", "(", "$", "this", "->", "alipayrsaPublicKey", ")", ")", "{", "if", "(", "$", "signData", "==", "null", "||", "$", "this", "->", "checkEmpty", "(", "$", "signData", "->", "sign", ")", "||", "$", "this", "->", "checkEmpty", "(", "$", "signData", "->", "signSourceData", ")", ")", "{", "throw", "new", "Exception", "(", "\" check sign Fail! The reason : signData is Empty\"", ")", ";", "}", "// 获取结果sub_code", "$", "responseSubCode", "=", "$", "this", "->", "parserResponseSubCode", "(", "$", "request", ",", "$", "resp", ",", "$", "respObject", ",", "$", "this", "->", "format", ")", ";", "if", "(", "!", "$", "this", "->", "checkEmpty", "(", "$", "responseSubCode", ")", "||", "(", "$", "this", "->", "checkEmpty", "(", "$", "responseSubCode", ")", "&&", "!", "$", "this", "->", "checkEmpty", "(", "$", "signData", "->", "sign", ")", ")", ")", "{", "$", "checkResult", "=", "$", "this", "->", "verify", "(", "$", "signData", "->", "signSourceData", ",", "$", "signData", "->", "sign", ",", "$", "this", "->", "alipayPublicKey", ",", "$", "this", "->", "signType", ")", ";", "if", "(", "!", "$", "checkResult", ")", "{", "if", "(", "strpos", "(", "$", "signData", "->", "signSourceData", ",", "\"\\\\/\"", ")", ">", "0", ")", "{", "$", "signData", "->", "signSourceData", "=", "str_replace", "(", "\"\\\\/\"", ",", "\"/\"", ",", "$", "signData", "->", "signSourceData", ")", ";", "$", "checkResult", "=", "$", "this", "->", "verify", "(", "$", "signData", "->", "signSourceData", ",", "$", "signData", "->", "sign", ",", "$", "this", "->", "alipayPublicKey", ",", "$", "this", "->", "signType", ")", ";", "if", "(", "!", "$", "checkResult", ")", "{", "throw", "new", "Exception", "(", "\"check sign Fail! [sign=\"", ".", "$", "signData", "->", "sign", ".", "\", signSourceData=\"", ".", "$", "signData", "->", "signSourceData", ".", "\"]\"", ")", ";", "}", "}", "else", "{", "throw", "new", "Exception", "(", "\"check sign Fail! [sign=\"", ".", "$", "signData", "->", "sign", ".", "\", signSourceData=\"", ".", "$", "signData", "->", "signSourceData", ".", "\"]\"", ")", ";", "}", "}", "}", "}", "}" ]
验签 @param $request @param $signData @param $resp @param $respObject @throws Exception
[ "验签" ]
train
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/Alipay/AopClient.php#L1022-L1064
huasituo/hstcms
src/Libraries/Alipay/AopClient.php
AopClient.encryptJSONSignSource
private function encryptJSONSignSource($request, $responseContent) { $parsetItem = $this->parserEncryptJSONSignSource($request, $responseContent); $bodyIndexContent = substr($responseContent, 0, $parsetItem->startIndex); $bodyEndContent = substr($responseContent, $parsetItem->endIndex, strlen($responseContent) + 1 - $parsetItem->endIndex); $bizContent = decrypts($parsetItem->encryptContent, $this->encryptKey); return $bodyIndexContent . $bizContent . $bodyEndContent; }
php
private function encryptJSONSignSource($request, $responseContent) { $parsetItem = $this->parserEncryptJSONSignSource($request, $responseContent); $bodyIndexContent = substr($responseContent, 0, $parsetItem->startIndex); $bodyEndContent = substr($responseContent, $parsetItem->endIndex, strlen($responseContent) + 1 - $parsetItem->endIndex); $bizContent = decrypts($parsetItem->encryptContent, $this->encryptKey); return $bodyIndexContent . $bizContent . $bodyEndContent; }
[ "private", "function", "encryptJSONSignSource", "(", "$", "request", ",", "$", "responseContent", ")", "{", "$", "parsetItem", "=", "$", "this", "->", "parserEncryptJSONSignSource", "(", "$", "request", ",", "$", "responseContent", ")", ";", "$", "bodyIndexContent", "=", "substr", "(", "$", "responseContent", ",", "0", ",", "$", "parsetItem", "->", "startIndex", ")", ";", "$", "bodyEndContent", "=", "substr", "(", "$", "responseContent", ",", "$", "parsetItem", "->", "endIndex", ",", "strlen", "(", "$", "responseContent", ")", "+", "1", "-", "$", "parsetItem", "->", "endIndex", ")", ";", "$", "bizContent", "=", "decrypts", "(", "$", "parsetItem", "->", "encryptContent", ",", "$", "this", "->", "encryptKey", ")", ";", "return", "$", "bodyIndexContent", ".", "$", "bizContent", ".", "$", "bodyEndContent", ";", "}" ]
获取加密内容
[ "获取加密内容" ]
train
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/Alipay/AopClient.php#L1076-L1086
huasituo/hstcms
src/Libraries/Alipay/AopClient.php
AopClient.encryptXMLSignSource
private function encryptXMLSignSource($request, $responseContent) { $parsetItem = $this->parserEncryptXMLSignSource($request, $responseContent); $bodyIndexContent = substr($responseContent, 0, $parsetItem->startIndex); $bodyEndContent = substr($responseContent, $parsetItem->endIndex, strlen($responseContent) + 1 - $parsetItem->endIndex); $bizContent = decrypts($parsetItem->encryptContent, $this->encryptKey); return $bodyIndexContent . $bizContent . $bodyEndContent; }
php
private function encryptXMLSignSource($request, $responseContent) { $parsetItem = $this->parserEncryptXMLSignSource($request, $responseContent); $bodyIndexContent = substr($responseContent, 0, $parsetItem->startIndex); $bodyEndContent = substr($responseContent, $parsetItem->endIndex, strlen($responseContent) + 1 - $parsetItem->endIndex); $bizContent = decrypts($parsetItem->encryptContent, $this->encryptKey); return $bodyIndexContent . $bizContent . $bodyEndContent; }
[ "private", "function", "encryptXMLSignSource", "(", "$", "request", ",", "$", "responseContent", ")", "{", "$", "parsetItem", "=", "$", "this", "->", "parserEncryptXMLSignSource", "(", "$", "request", ",", "$", "responseContent", ")", ";", "$", "bodyIndexContent", "=", "substr", "(", "$", "responseContent", ",", "0", ",", "$", "parsetItem", "->", "startIndex", ")", ";", "$", "bodyEndContent", "=", "substr", "(", "$", "responseContent", ",", "$", "parsetItem", "->", "endIndex", ",", "strlen", "(", "$", "responseContent", ")", "+", "1", "-", "$", "parsetItem", "->", "endIndex", ")", ";", "$", "bizContent", "=", "decrypts", "(", "$", "parsetItem", "->", "encryptContent", ",", "$", "this", "->", "encryptKey", ")", ";", "return", "$", "bodyIndexContent", ".", "$", "bizContent", ".", "$", "bodyEndContent", ";", "}" ]
获取加密内容
[ "获取加密内容" ]
train
https://github.com/huasituo/hstcms/blob/12819979289e58ce38e3e92540aeeb16e205e525/src/Libraries/Alipay/AopClient.php#L1141-L1151
FrenchFrogs/framework
src/Table/Column/Custom.php
Custom.setCustom
public function setCustom($custom) { if (!is_callable($custom)) { throw new \InvalidArgumentException('"' . $custom . '" is not callable'); } $this->custom = $custom; return $this; }
php
public function setCustom($custom) { if (!is_callable($custom)) { throw new \InvalidArgumentException('"' . $custom . '" is not callable'); } $this->custom = $custom; return $this; }
[ "public", "function", "setCustom", "(", "$", "custom", ")", "{", "if", "(", "!", "is_callable", "(", "$", "custom", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'\"'", ".", "$", "custom", ".", "'\" is not callable'", ")", ";", "}", "$", "this", "->", "custom", "=", "$", "custom", ";", "return", "$", "this", ";", "}" ]
SETTER for $custom @param $custom @return $this
[ "SETTER", "for", "$custom" ]
train
https://github.com/FrenchFrogs/framework/blob/a4838c698a5600437e87dac6d35ba8ebe32c4395/src/Table/Column/Custom.php#L37-L45
czim/laravel-pxlcms
src/Sluggable/SluggableTranslatedTrait.php
SluggableTranslatedTrait.findBySlug
public static function findBySlug($slug, $locale = null) { /** @var \Dimsav\Translatable\Translatable $model */ $model = (new static); /** @var SluggableTrait $translationModel */ $translationModel = $model->getTranslationModelName(); $parentKey = $model->getRelationKey(); $translationInstance = $translationModel::findBySlug($slug, $locale); if (empty($translationInstance)) return null; return static::find($translationInstance->{$parentKey}); }
php
public static function findBySlug($slug, $locale = null) { /** @var \Dimsav\Translatable\Translatable $model */ $model = (new static); /** @var SluggableTrait $translationModel */ $translationModel = $model->getTranslationModelName(); $parentKey = $model->getRelationKey(); $translationInstance = $translationModel::findBySlug($slug, $locale); if (empty($translationInstance)) return null; return static::find($translationInstance->{$parentKey}); }
[ "public", "static", "function", "findBySlug", "(", "$", "slug", ",", "$", "locale", "=", "null", ")", "{", "/** @var \\Dimsav\\Translatable\\Translatable $model */", "$", "model", "=", "(", "new", "static", ")", ";", "/** @var SluggableTrait $translationModel */", "$", "translationModel", "=", "$", "model", "->", "getTranslationModelName", "(", ")", ";", "$", "parentKey", "=", "$", "model", "->", "getRelationKey", "(", ")", ";", "$", "translationInstance", "=", "$", "translationModel", "::", "findBySlug", "(", "$", "slug", ",", "$", "locale", ")", ";", "if", "(", "empty", "(", "$", "translationInstance", ")", ")", "return", "null", ";", "return", "static", "::", "find", "(", "$", "translationInstance", "->", "{", "$", "parentKey", "}", ")", ";", "}" ]
Find by slug on translated attribute @param string $slug @param string $locale optional, if omitted returns for any locale @return $this|null
[ "Find", "by", "slug", "on", "translated", "attribute" ]
train
https://github.com/czim/laravel-pxlcms/blob/910297d2a3f2db86dde51b0e10fe5aad45f1aa1a/src/Sluggable/SluggableTranslatedTrait.php#L20-L34
czim/laravel-pxlcms
src/Sluggable/SluggableTranslatedTrait.php
SluggableTranslatedTrait.scopeWhereSlug
public function scopeWhereSlug($query, $slug, $locale = null) { return $query->whereHas('translations', function ($query) use ($slug, $locale) { return $query->whereSlug($slug, $locale, true); }); }
php
public function scopeWhereSlug($query, $slug, $locale = null) { return $query->whereHas('translations', function ($query) use ($slug, $locale) { return $query->whereSlug($slug, $locale, true); }); }
[ "public", "function", "scopeWhereSlug", "(", "$", "query", ",", "$", "slug", ",", "$", "locale", "=", "null", ")", "{", "return", "$", "query", "->", "whereHas", "(", "'translations'", ",", "function", "(", "$", "query", ")", "use", "(", "$", "slug", ",", "$", "locale", ")", "{", "return", "$", "query", "->", "whereSlug", "(", "$", "slug", ",", "$", "locale", ",", "true", ")", ";", "}", ")", ";", "}" ]
Scopes query for slug on translated attribute @param \Illuminate\Database\Eloquent\Builder $query @param string $slug @param string $locale @return $this|null
[ "Scopes", "query", "for", "slug", "on", "translated", "attribute" ]
train
https://github.com/czim/laravel-pxlcms/blob/910297d2a3f2db86dde51b0e10fe5aad45f1aa1a/src/Sluggable/SluggableTranslatedTrait.php#L44-L49
czim/laravel-pxlcms
src/Sluggable/SluggableTranslatedTrait.php
SluggableTranslatedTrait.sluggify
public function sluggify($force = false) { /** @var \Dimsav\Translatable\Translatable $this */ /** @var \Cviebrock\EloquentSluggable\SluggableInterface $translation */ $translation = $this->getTranslation(); if ( ! empty($translation)) { $translation->sluggify($force); } return $this; }
php
public function sluggify($force = false) { /** @var \Dimsav\Translatable\Translatable $this */ /** @var \Cviebrock\EloquentSluggable\SluggableInterface $translation */ $translation = $this->getTranslation(); if ( ! empty($translation)) { $translation->sluggify($force); } return $this; }
[ "public", "function", "sluggify", "(", "$", "force", "=", "false", ")", "{", "/** @var \\Dimsav\\Translatable\\Translatable $this */", "/** @var \\Cviebrock\\EloquentSluggable\\SluggableInterface $translation */", "$", "translation", "=", "$", "this", "->", "getTranslation", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "translation", ")", ")", "{", "$", "translation", "->", "sluggify", "(", "$", "force", ")", ";", "}", "return", "$", "this", ";", "}" ]
Sluggifies the translation model (for default/active locale) @param bool $force @return $this
[ "Sluggifies", "the", "translation", "model", "(", "for", "default", "/", "active", "locale", ")" ]
train
https://github.com/czim/laravel-pxlcms/blob/910297d2a3f2db86dde51b0e10fe5aad45f1aa1a/src/Sluggable/SluggableTranslatedTrait.php#L74-L86
dengyongbin/loopeer-lib
src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/HttpRequest.php
HttpRequest.encodePostBody
private function encodePostBody($body) { if ($body === null) { return ''; } if (! is_array($body)) { return urlencode(strval($body)); } $result = array (); foreach ( $body as $k => $v ) { $result [ ] = urlencode($k) . '=' . urlencode($v); } return join('&', $result); }
php
private function encodePostBody($body) { if ($body === null) { return ''; } if (! is_array($body)) { return urlencode(strval($body)); } $result = array (); foreach ( $body as $k => $v ) { $result [ ] = urlencode($k) . '=' . urlencode($v); } return join('&', $result); }
[ "private", "function", "encodePostBody", "(", "$", "body", ")", "{", "if", "(", "$", "body", "===", "null", ")", "{", "return", "''", ";", "}", "if", "(", "!", "is_array", "(", "$", "body", ")", ")", "{", "return", "urlencode", "(", "strval", "(", "$", "body", ")", ")", ";", "}", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "body", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "result", "[", "]", "=", "urlencode", "(", "$", "k", ")", ".", "'='", ".", "urlencode", "(", "$", "v", ")", ";", "}", "return", "join", "(", "'&'", ",", "$", "result", ")", ";", "}" ]
以标准uri风格编码一个array<K,V> @param array<K,V> $body @return string
[ "以标准uri风格编码一个array<K", "V", ">" ]
train
https://github.com/dengyongbin/loopeer-lib/blob/4609338f6a48666ca96ee380509a5b5cb066808f/src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/HttpRequest.php#L119-L134
dengyongbin/loopeer-lib
src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/HttpRequest.php
HttpRequest.parseResponse
private function parseResponse($content) { list ( $headerStr, $body ) = explode("\r\n\r\n", $content, 2); $header = array (); $headerPart = explode("\r\n", $headerStr); list ( $httpProtocol, $statusCode, $statStr ) = explode(' ', array_shift($headerPart), 3); foreach ( $headerPart as $item ) { list ( $key, $value ) = explode(':', $item); $header [$key] = $value; } $result = array ( 'protocol' => $httpProtocol, 'status' => intval($statusCode), 'statusMsg' => $statStr, 'header' => $header, 'content' => $body, ); return $result; }
php
private function parseResponse($content) { list ( $headerStr, $body ) = explode("\r\n\r\n", $content, 2); $header = array (); $headerPart = explode("\r\n", $headerStr); list ( $httpProtocol, $statusCode, $statStr ) = explode(' ', array_shift($headerPart), 3); foreach ( $headerPart as $item ) { list ( $key, $value ) = explode(':', $item); $header [$key] = $value; } $result = array ( 'protocol' => $httpProtocol, 'status' => intval($statusCode), 'statusMsg' => $statStr, 'header' => $header, 'content' => $body, ); return $result; }
[ "private", "function", "parseResponse", "(", "$", "content", ")", "{", "list", "(", "$", "headerStr", ",", "$", "body", ")", "=", "explode", "(", "\"\\r\\n\\r\\n\"", ",", "$", "content", ",", "2", ")", ";", "$", "header", "=", "array", "(", ")", ";", "$", "headerPart", "=", "explode", "(", "\"\\r\\n\"", ",", "$", "headerStr", ")", ";", "list", "(", "$", "httpProtocol", ",", "$", "statusCode", ",", "$", "statStr", ")", "=", "explode", "(", "' '", ",", "array_shift", "(", "$", "headerPart", ")", ",", "3", ")", ";", "foreach", "(", "$", "headerPart", "as", "$", "item", ")", "{", "list", "(", "$", "key", ",", "$", "value", ")", "=", "explode", "(", "':'", ",", "$", "item", ")", ";", "$", "header", "[", "$", "key", "]", "=", "$", "value", ";", "}", "$", "result", "=", "array", "(", "'protocol'", "=>", "$", "httpProtocol", ",", "'status'", "=>", "intval", "(", "$", "statusCode", ")", ",", "'statusMsg'", "=>", "$", "statStr", ",", "'header'", "=>", "$", "header", ",", "'content'", "=>", "$", "body", ",", ")", ";", "return", "$", "result", ";", "}" ]
解析curl的response,并折分其中的header与body部份. @param string $content @return array
[ "解析curl的response", "并折分其中的header与body部份", "." ]
train
https://github.com/dengyongbin/loopeer-lib/blob/4609338f6a48666ca96ee380509a5b5cb066808f/src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/HttpRequest.php#L140-L164
dengyongbin/loopeer-lib
src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/HttpRequest.php
HttpRequest.request
function request($path = '', $method = "GET", $payload = "", $reqHeaders = null, $curlOpts = null) { if ($path === null) { throw new HttpException('path must be string'); } // 决定访问位置 $url = $this->resolve($path); $curlOptsFinal = $this -> currentOpts; if (is_array($curlOpts)) { foreach ( $curlOpts as $k => $v ) { $curlOptsFinal [$k] = $v; } } if (is_array($reqHeaders)) { if(!is_array($curlOptsFinal [CURLOPT_HTTPHEADER])){ $curlOptsFinal [CURLOPT_HTTPHEADER] = array(); // 这玩意必须是个数组.不是就直接覆盖. } $curlOptsFinal [CURLOPT_HTTPHEADER] = array_merge($curlOptsFinal [CURLOPT_HTTPHEADER], $reqHeaders); //print_r($curlOptsFinal); } $port = parse_url($url, PHP_URL_PORT); $curlOptsFinal [CURLOPT_URL] = $url; $curlOptsFinal [CURLOPT_PORT] = empty($port) ? 80 : $port; $req = curl_init(); curl_setopt_array($req, $curlOptsFinal); switch ($method) { case self::HTTP_GET : curl_setopt($req, CURLOPT_CUSTOMREQUEST, 'GET'); break; case self::HTTP_POST : curl_setopt($req, CURLOPT_POST, true); curl_setopt($req, CURLOPT_POSTFIELDS, $payload); break; default : throw new HttpException("method not be support"); } $response = curl_exec($req); $errCode = curl_errno($req); if ($errCode === 0) { curl_close($req); // log http access $response = $this -> parseResponse($response); $status = $response['status']; $this -> log -> log("HttpRequest: $status $method $url"); return $response; } else { // get message and close curl resource; $errMsg = curl_error($req); curl_close($req); throw new HttpException( "curl_error($errMsg); with url($url)", $errCode); } }
php
function request($path = '', $method = "GET", $payload = "", $reqHeaders = null, $curlOpts = null) { if ($path === null) { throw new HttpException('path must be string'); } // 决定访问位置 $url = $this->resolve($path); $curlOptsFinal = $this -> currentOpts; if (is_array($curlOpts)) { foreach ( $curlOpts as $k => $v ) { $curlOptsFinal [$k] = $v; } } if (is_array($reqHeaders)) { if(!is_array($curlOptsFinal [CURLOPT_HTTPHEADER])){ $curlOptsFinal [CURLOPT_HTTPHEADER] = array(); // 这玩意必须是个数组.不是就直接覆盖. } $curlOptsFinal [CURLOPT_HTTPHEADER] = array_merge($curlOptsFinal [CURLOPT_HTTPHEADER], $reqHeaders); //print_r($curlOptsFinal); } $port = parse_url($url, PHP_URL_PORT); $curlOptsFinal [CURLOPT_URL] = $url; $curlOptsFinal [CURLOPT_PORT] = empty($port) ? 80 : $port; $req = curl_init(); curl_setopt_array($req, $curlOptsFinal); switch ($method) { case self::HTTP_GET : curl_setopt($req, CURLOPT_CUSTOMREQUEST, 'GET'); break; case self::HTTP_POST : curl_setopt($req, CURLOPT_POST, true); curl_setopt($req, CURLOPT_POSTFIELDS, $payload); break; default : throw new HttpException("method not be support"); } $response = curl_exec($req); $errCode = curl_errno($req); if ($errCode === 0) { curl_close($req); // log http access $response = $this -> parseResponse($response); $status = $response['status']; $this -> log -> log("HttpRequest: $status $method $url"); return $response; } else { // get message and close curl resource; $errMsg = curl_error($req); curl_close($req); throw new HttpException( "curl_error($errMsg); with url($url)", $errCode); } }
[ "function", "request", "(", "$", "path", "=", "''", ",", "$", "method", "=", "\"GET\"", ",", "$", "payload", "=", "\"\"", ",", "$", "reqHeaders", "=", "null", ",", "$", "curlOpts", "=", "null", ")", "{", "if", "(", "$", "path", "===", "null", ")", "{", "throw", "new", "HttpException", "(", "'path must be string'", ")", ";", "}", "// 决定访问位置 ", "$", "url", "=", "$", "this", "->", "resolve", "(", "$", "path", ")", ";", "$", "curlOptsFinal", "=", "$", "this", "->", "currentOpts", ";", "if", "(", "is_array", "(", "$", "curlOpts", ")", ")", "{", "foreach", "(", "$", "curlOpts", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "curlOptsFinal", "[", "$", "k", "]", "=", "$", "v", ";", "}", "}", "if", "(", "is_array", "(", "$", "reqHeaders", ")", ")", "{", "if", "(", "!", "is_array", "(", "$", "curlOptsFinal", "[", "CURLOPT_HTTPHEADER", "]", ")", ")", "{", "$", "curlOptsFinal", "[", "CURLOPT_HTTPHEADER", "]", "=", "array", "(", ")", ";", "// 这玩意必须是个数组.不是就直接覆盖.", "}", "$", "curlOptsFinal", "[", "CURLOPT_HTTPHEADER", "]", "=", "array_merge", "(", "$", "curlOptsFinal", "[", "CURLOPT_HTTPHEADER", "]", ",", "$", "reqHeaders", ")", ";", "//print_r($curlOptsFinal);", "}", "$", "port", "=", "parse_url", "(", "$", "url", ",", "PHP_URL_PORT", ")", ";", "$", "curlOptsFinal", "[", "CURLOPT_URL", "]", "=", "$", "url", ";", "$", "curlOptsFinal", "[", "CURLOPT_PORT", "]", "=", "empty", "(", "$", "port", ")", "?", "80", ":", "$", "port", ";", "$", "req", "=", "curl_init", "(", ")", ";", "curl_setopt_array", "(", "$", "req", ",", "$", "curlOptsFinal", ")", ";", "switch", "(", "$", "method", ")", "{", "case", "self", "::", "HTTP_GET", ":", "curl_setopt", "(", "$", "req", ",", "CURLOPT_CUSTOMREQUEST", ",", "'GET'", ")", ";", "break", ";", "case", "self", "::", "HTTP_POST", ":", "curl_setopt", "(", "$", "req", ",", "CURLOPT_POST", ",", "true", ")", ";", "curl_setopt", "(", "$", "req", ",", "CURLOPT_POSTFIELDS", ",", "$", "payload", ")", ";", "break", ";", "default", ":", "throw", "new", "HttpException", "(", "\"method not be support\"", ")", ";", "}", "$", "response", "=", "curl_exec", "(", "$", "req", ")", ";", "$", "errCode", "=", "curl_errno", "(", "$", "req", ")", ";", "if", "(", "$", "errCode", "===", "0", ")", "{", "curl_close", "(", "$", "req", ")", ";", "// log http access", "$", "response", "=", "$", "this", "->", "parseResponse", "(", "$", "response", ")", ";", "$", "status", "=", "$", "response", "[", "'status'", "]", ";", "$", "this", "->", "log", "->", "log", "(", "\"HttpRequest: $status $method $url\"", ")", ";", "return", "$", "response", ";", "}", "else", "{", "// get message and close curl resource;", "$", "errMsg", "=", "curl_error", "(", "$", "req", ")", ";", "curl_close", "(", "$", "req", ")", ";", "throw", "new", "HttpException", "(", "\"curl_error($errMsg); with url($url)\"", ",", "$", "errCode", ")", ";", "}", "}" ]
发起http请求, 并返回响应内容 @param [string] $path url的拼接部份,将拼接到urlBase部份 @param [string] $method 使用的http请求方法, 目前只支持GET和POST @param [mixed] $payload 请求时的附加的数据. @param [array] $reqHeaders 请求时附加的header信息 @param [array] $curlOpts 每次请求时, 对curl的配置信息. @throws HttpException 请求异常时, 抛出异常 @return array http response信息 , 具有如下结构 array( httpProtocol:'', status:'', statusMsg:'', header:array(), content:"" )
[ "发起http请求", "并返回响应内容" ]
train
https://github.com/dengyongbin/loopeer-lib/blob/4609338f6a48666ca96ee380509a5b5cb066808f/src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/HttpRequest.php#L187-L255
dengyongbin/loopeer-lib
src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/HttpRequest.php
HttpRequest.get
function get($path, $query = null, $headers = null, $curlOpts = null) { $payload = $this -> encodePostBody($query); if ($payload !== "") { if (strpos($path, '?')) { $url = $path . "&" . $payload; } else { $url = $path . "?" . $payload; } }else{ $url = $path; } return $this -> request($url, self::HTTP_GET, '', $headers, $curlOpts); }
php
function get($path, $query = null, $headers = null, $curlOpts = null) { $payload = $this -> encodePostBody($query); if ($payload !== "") { if (strpos($path, '?')) { $url = $path . "&" . $payload; } else { $url = $path . "?" . $payload; } }else{ $url = $path; } return $this -> request($url, self::HTTP_GET, '', $headers, $curlOpts); }
[ "function", "get", "(", "$", "path", ",", "$", "query", "=", "null", ",", "$", "headers", "=", "null", ",", "$", "curlOpts", "=", "null", ")", "{", "$", "payload", "=", "$", "this", "->", "encodePostBody", "(", "$", "query", ")", ";", "if", "(", "$", "payload", "!==", "\"\"", ")", "{", "if", "(", "strpos", "(", "$", "path", ",", "'?'", ")", ")", "{", "$", "url", "=", "$", "path", ".", "\"&\"", ".", "$", "payload", ";", "}", "else", "{", "$", "url", "=", "$", "path", ".", "\"?\"", ".", "$", "payload", ";", "}", "}", "else", "{", "$", "url", "=", "$", "path", ";", "}", "return", "$", "this", "->", "request", "(", "$", "url", ",", "self", "::", "HTTP_GET", ",", "''", ",", "$", "headers", ",", "$", "curlOpts", ")", ";", "}" ]
快速发起get请求 @param string $path 请求资源路径 @param array $query 请求参数 @param array $headers 附带header @param array $curlOpts 附加curlOpts @return array http response信息 , 具有如下结构 array( httpProtocol:'', status:'', statusMsg:'', header:array(), content:"" )
[ "快速发起get请求" ]
train
https://github.com/dengyongbin/loopeer-lib/blob/4609338f6a48666ca96ee380509a5b5cb066808f/src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/HttpRequest.php#L276-L290
dengyongbin/loopeer-lib
src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/HttpRequest.php
HttpRequest.post
function post($path = null, $postBody = null, $headers = null, $curlOpts = null) { $payload = $this -> encodePostBody($postBody); $this -> log -> debug("\n\n ====== Dump the payload before Http POST send! ====== \n\n$payload\n\n====== End Dump! ======\n"); return $this -> request($path, self::HTTP_POST, $payload, $headers, $curlOpts); }
php
function post($path = null, $postBody = null, $headers = null, $curlOpts = null) { $payload = $this -> encodePostBody($postBody); $this -> log -> debug("\n\n ====== Dump the payload before Http POST send! ====== \n\n$payload\n\n====== End Dump! ======\n"); return $this -> request($path, self::HTTP_POST, $payload, $headers, $curlOpts); }
[ "function", "post", "(", "$", "path", "=", "null", ",", "$", "postBody", "=", "null", ",", "$", "headers", "=", "null", ",", "$", "curlOpts", "=", "null", ")", "{", "$", "payload", "=", "$", "this", "->", "encodePostBody", "(", "$", "postBody", ")", ";", "$", "this", "->", "log", "->", "debug", "(", "\"\\n\\n ====== Dump the payload before Http POST send! ====== \\n\\n$payload\\n\\n====== End Dump! ======\\n\"", ")", ";", "return", "$", "this", "->", "request", "(", "$", "path", ",", "self", "::", "HTTP_POST", ",", "$", "payload", ",", "$", "headers", ",", "$", "curlOpts", ")", ";", "}" ]
快速发起post请求 @param string $path 请求资源路径 @param array $postBody 请求参数 @param array $headers 附带header @param array $curlOpts 附加curlOpts @return array http response信息 , 具有如下结构 array( httpProtocol:'', status:'', statusMsg:'', header:array(), content:"" )
[ "快速发起post请求" ]
train
https://github.com/dengyongbin/loopeer-lib/blob/4609338f6a48666ca96ee380509a5b5cb066808f/src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/HttpRequest.php#L311-L315
dengyongbin/loopeer-lib
src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/HttpRequest.php
HttpRequest.resolve
public function resolve($path){ // 如果不指定完整的url, 则认为是访问$urlBase内资源 if ($this -> isUrlFormat($path)) { $url = $path; } // 忽略重复的路径分隔符 else if (strpos($path, '/') === 0) { $url = $this -> urlBase . substr($path, 1); } else { $url = $this -> urlBase . $path; } return $url; }
php
public function resolve($path){ // 如果不指定完整的url, 则认为是访问$urlBase内资源 if ($this -> isUrlFormat($path)) { $url = $path; } // 忽略重复的路径分隔符 else if (strpos($path, '/') === 0) { $url = $this -> urlBase . substr($path, 1); } else { $url = $this -> urlBase . $path; } return $url; }
[ "public", "function", "resolve", "(", "$", "path", ")", "{", "// 如果不指定完整的url, 则认为是访问$urlBase内资源", "if", "(", "$", "this", "->", "isUrlFormat", "(", "$", "path", ")", ")", "{", "$", "url", "=", "$", "path", ";", "}", "// 忽略重复的路径分隔符", "else", "if", "(", "strpos", "(", "$", "path", ",", "'/'", ")", "===", "0", ")", "{", "$", "url", "=", "$", "this", "->", "urlBase", ".", "substr", "(", "$", "path", ",", "1", ")", ";", "}", "else", "{", "$", "url", "=", "$", "this", "->", "urlBase", ".", "$", "path", ";", "}", "return", "$", "url", ";", "}" ]
根据传入内容,决定具体请求地址; @param string $path @return Ambigous <string, unknown>
[ "根据传入内容", "决定具体请求地址", ";" ]
train
https://github.com/dengyongbin/loopeer-lib/blob/4609338f6a48666ca96ee380509a5b5cb066808f/src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/HttpRequest.php#L322-L335
dengyongbin/loopeer-lib
src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/HttpRequest.php
HttpRequest.getResourceAddress
public function getResourceAddress($url){ $url = $this->resolve($url); $p = strpos($url,'?'); $p = $p === false ? strpos($url,'#') : $p; return $p === false ? $url : substr($url, 0, $p); }
php
public function getResourceAddress($url){ $url = $this->resolve($url); $p = strpos($url,'?'); $p = $p === false ? strpos($url,'#') : $p; return $p === false ? $url : substr($url, 0, $p); }
[ "public", "function", "getResourceAddress", "(", "$", "url", ")", "{", "$", "url", "=", "$", "this", "->", "resolve", "(", "$", "url", ")", ";", "$", "p", "=", "strpos", "(", "$", "url", ",", "'?'", ")", ";", "$", "p", "=", "$", "p", "===", "false", "?", "strpos", "(", "$", "url", ",", "'#'", ")", ":", "$", "p", ";", "return", "$", "p", "===", "false", "?", "$", "url", ":", "substr", "(", "$", "url", ",", "0", ",", "$", "p", ")", ";", "}" ]
取得url中表示资源位置的部份,即去掉query_string及其后的部份 @param string $url @return string
[ "取得url中表示资源位置的部份", "即去掉query_string及其后的部份" ]
train
https://github.com/dengyongbin/loopeer-lib/blob/4609338f6a48666ca96ee380509a5b5cb066808f/src/Services/Baidu-Push-Server-SDK-Php-3.0.1/lib/HttpRequest.php#L343-L350
vincentchalamon/VinceCmsSonataAdminBundle
Admin/Entity/ArticleAdmin.php
ArticleAdmin.setUser
public function setUser(SecurityContext $context) { $this->user = $context->getToken() ? $context->getToken()->getUser() : null; }
php
public function setUser(SecurityContext $context) { $this->user = $context->getToken() ? $context->getToken()->getUser() : null; }
[ "public", "function", "setUser", "(", "SecurityContext", "$", "context", ")", "{", "$", "this", "->", "user", "=", "$", "context", "->", "getToken", "(", ")", "?", "$", "context", "->", "getToken", "(", ")", "->", "getUser", "(", ")", ":", "null", ";", "}" ]
Set user @author Vincent Chalamon <[email protected]> @param SecurityContext $context
[ "Set", "user" ]
train
https://github.com/vincentchalamon/VinceCmsSonataAdminBundle/blob/edc768061734a92ba116488dd7b61ad40af21ceb/Admin/Entity/ArticleAdmin.php#L112-L115
vincentchalamon/VinceCmsSonataAdminBundle
Admin/Entity/ArticleAdmin.php
ArticleAdmin.getBatchActions
public function getBatchActions() { return array_merge(parent::getBatchActions(), array( 'publish' => array( 'label' => $this->trans('action.publish', array(), 'SonataAdminBundle'), 'ask_confirmation' => true, ), 'unpublish' => array( 'label' => $this->trans('action.unpublish', array(), 'SonataAdminBundle'), 'ask_confirmation' => true, ), ) ); }
php
public function getBatchActions() { return array_merge(parent::getBatchActions(), array( 'publish' => array( 'label' => $this->trans('action.publish', array(), 'SonataAdminBundle'), 'ask_confirmation' => true, ), 'unpublish' => array( 'label' => $this->trans('action.unpublish', array(), 'SonataAdminBundle'), 'ask_confirmation' => true, ), ) ); }
[ "public", "function", "getBatchActions", "(", ")", "{", "return", "array_merge", "(", "parent", "::", "getBatchActions", "(", ")", ",", "array", "(", "'publish'", "=>", "array", "(", "'label'", "=>", "$", "this", "->", "trans", "(", "'action.publish'", ",", "array", "(", ")", ",", "'SonataAdminBundle'", ")", ",", "'ask_confirmation'", "=>", "true", ",", ")", ",", "'unpublish'", "=>", "array", "(", "'label'", "=>", "$", "this", "->", "trans", "(", "'action.unpublish'", ",", "array", "(", ")", ",", "'SonataAdminBundle'", ")", ",", "'ask_confirmation'", "=>", "true", ",", ")", ",", ")", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/vincentchalamon/VinceCmsSonataAdminBundle/blob/edc768061734a92ba116488dd7b61ad40af21ceb/Admin/Entity/ArticleAdmin.php#L172-L185
vincentchalamon/VinceCmsSonataAdminBundle
Admin/Entity/ArticleAdmin.php
ArticleAdmin.createQuery
public function createQuery($context = 'list') { $query = parent::createQuery($context); $query->leftJoin($query->getRootAlias().'.template', 'template')->addSelect('template') ->leftJoin('template.areas', 'area')->addSelect('area') ->leftJoin($query->getRootAlias().'.metas', 'articleMeta')->addSelect('articleMeta') ->leftJoin('articleMeta.meta', 'meta')->addSelect('meta'); return $query; }
php
public function createQuery($context = 'list') { $query = parent::createQuery($context); $query->leftJoin($query->getRootAlias().'.template', 'template')->addSelect('template') ->leftJoin('template.areas', 'area')->addSelect('area') ->leftJoin($query->getRootAlias().'.metas', 'articleMeta')->addSelect('articleMeta') ->leftJoin('articleMeta.meta', 'meta')->addSelect('meta'); return $query; }
[ "public", "function", "createQuery", "(", "$", "context", "=", "'list'", ")", "{", "$", "query", "=", "parent", "::", "createQuery", "(", "$", "context", ")", ";", "$", "query", "->", "leftJoin", "(", "$", "query", "->", "getRootAlias", "(", ")", ".", "'.template'", ",", "'template'", ")", "->", "addSelect", "(", "'template'", ")", "->", "leftJoin", "(", "'template.areas'", ",", "'area'", ")", "->", "addSelect", "(", "'area'", ")", "->", "leftJoin", "(", "$", "query", "->", "getRootAlias", "(", ")", ".", "'.metas'", ",", "'articleMeta'", ")", "->", "addSelect", "(", "'articleMeta'", ")", "->", "leftJoin", "(", "'articleMeta.meta'", ",", "'meta'", ")", "->", "addSelect", "(", "'meta'", ")", ";", "return", "$", "query", ";", "}" ]
Need to override createQuery method because or list order & joins {@inheritdoc}
[ "Need", "to", "override", "createQuery", "method", "because", "or", "list", "order", "&", "joins" ]
train
https://github.com/vincentchalamon/VinceCmsSonataAdminBundle/blob/edc768061734a92ba116488dd7b61ad40af21ceb/Admin/Entity/ArticleAdmin.php#L192-L201
vincentchalamon/VinceCmsSonataAdminBundle
Admin/Entity/ArticleAdmin.php
ArticleAdmin.getNewInstance
public function getNewInstance() { /** @var Article $article */ $article = parent::getNewInstance(); $builder = $this->repository->createQueryBuilder('m'); $metas = $builder->where( $builder->expr()->in('m.name', array('language', 'robots', 'og:type', 'twitter:card', 'twitter:creator', 'twitter:author', 'author', 'publisher')) )->getQuery()->execute(); foreach ($metas as $meta) { /** @var ArticleMeta $articleMeta */ $articleMeta = new $this->articleMetaClass(); /** @var Meta $meta */ $articleMeta->setMeta($meta); switch ($meta->getName()) { case 'robots': $articleMeta->setContents('index,follow'); break; case 'og:type': $articleMeta->setContents('article'); break; case 'twitter:card': $articleMeta->setContents('summary'); break; case 'twitter:creator': case 'twitter:author': if ($this->user && $this->user->getTwitterName()) { $articleMeta->setContents('@'.$this->user->getTwitterName()); } break; case 'author': if ($this->user) { $articleMeta->setContents(trim($this->user->getFirstname().' '.$this->user->getLastname()) ?: $this->user->getUsername()); } break; case 'publisher': if ($this->user && $this->user->getGplusName()) { $articleMeta->setContents($this->user->getGplusName()); } break; } if ($articleMeta->getContents()) { $article->addMeta($articleMeta); } } return $article; }
php
public function getNewInstance() { /** @var Article $article */ $article = parent::getNewInstance(); $builder = $this->repository->createQueryBuilder('m'); $metas = $builder->where( $builder->expr()->in('m.name', array('language', 'robots', 'og:type', 'twitter:card', 'twitter:creator', 'twitter:author', 'author', 'publisher')) )->getQuery()->execute(); foreach ($metas as $meta) { /** @var ArticleMeta $articleMeta */ $articleMeta = new $this->articleMetaClass(); /** @var Meta $meta */ $articleMeta->setMeta($meta); switch ($meta->getName()) { case 'robots': $articleMeta->setContents('index,follow'); break; case 'og:type': $articleMeta->setContents('article'); break; case 'twitter:card': $articleMeta->setContents('summary'); break; case 'twitter:creator': case 'twitter:author': if ($this->user && $this->user->getTwitterName()) { $articleMeta->setContents('@'.$this->user->getTwitterName()); } break; case 'author': if ($this->user) { $articleMeta->setContents(trim($this->user->getFirstname().' '.$this->user->getLastname()) ?: $this->user->getUsername()); } break; case 'publisher': if ($this->user && $this->user->getGplusName()) { $articleMeta->setContents($this->user->getGplusName()); } break; } if ($articleMeta->getContents()) { $article->addMeta($articleMeta); } } return $article; }
[ "public", "function", "getNewInstance", "(", ")", "{", "/** @var Article $article */", "$", "article", "=", "parent", "::", "getNewInstance", "(", ")", ";", "$", "builder", "=", "$", "this", "->", "repository", "->", "createQueryBuilder", "(", "'m'", ")", ";", "$", "metas", "=", "$", "builder", "->", "where", "(", "$", "builder", "->", "expr", "(", ")", "->", "in", "(", "'m.name'", ",", "array", "(", "'language'", ",", "'robots'", ",", "'og:type'", ",", "'twitter:card'", ",", "'twitter:creator'", ",", "'twitter:author'", ",", "'author'", ",", "'publisher'", ")", ")", ")", "->", "getQuery", "(", ")", "->", "execute", "(", ")", ";", "foreach", "(", "$", "metas", "as", "$", "meta", ")", "{", "/** @var ArticleMeta $articleMeta */", "$", "articleMeta", "=", "new", "$", "this", "->", "articleMetaClass", "(", ")", ";", "/** @var Meta $meta */", "$", "articleMeta", "->", "setMeta", "(", "$", "meta", ")", ";", "switch", "(", "$", "meta", "->", "getName", "(", ")", ")", "{", "case", "'robots'", ":", "$", "articleMeta", "->", "setContents", "(", "'index,follow'", ")", ";", "break", ";", "case", "'og:type'", ":", "$", "articleMeta", "->", "setContents", "(", "'article'", ")", ";", "break", ";", "case", "'twitter:card'", ":", "$", "articleMeta", "->", "setContents", "(", "'summary'", ")", ";", "break", ";", "case", "'twitter:creator'", ":", "case", "'twitter:author'", ":", "if", "(", "$", "this", "->", "user", "&&", "$", "this", "->", "user", "->", "getTwitterName", "(", ")", ")", "{", "$", "articleMeta", "->", "setContents", "(", "'@'", ".", "$", "this", "->", "user", "->", "getTwitterName", "(", ")", ")", ";", "}", "break", ";", "case", "'author'", ":", "if", "(", "$", "this", "->", "user", ")", "{", "$", "articleMeta", "->", "setContents", "(", "trim", "(", "$", "this", "->", "user", "->", "getFirstname", "(", ")", ".", "' '", ".", "$", "this", "->", "user", "->", "getLastname", "(", ")", ")", "?", ":", "$", "this", "->", "user", "->", "getUsername", "(", ")", ")", ";", "}", "break", ";", "case", "'publisher'", ":", "if", "(", "$", "this", "->", "user", "&&", "$", "this", "->", "user", "->", "getGplusName", "(", ")", ")", "{", "$", "articleMeta", "->", "setContents", "(", "$", "this", "->", "user", "->", "getGplusName", "(", ")", ")", ";", "}", "break", ";", "}", "if", "(", "$", "articleMeta", "->", "getContents", "(", ")", ")", "{", "$", "article", "->", "addMeta", "(", "$", "articleMeta", ")", ";", "}", "}", "return", "$", "article", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/vincentchalamon/VinceCmsSonataAdminBundle/blob/edc768061734a92ba116488dd7b61ad40af21ceb/Admin/Entity/ArticleAdmin.php#L214-L260
vincentchalamon/VinceCmsSonataAdminBundle
Admin/Entity/ArticleAdmin.php
ArticleAdmin.configureFormFields
protected function configureFormFields(FormMapper $mapper) { $mapper ->with('article.group.general', array('class' => 'col-md-6')) ->add('title', null, array( 'label' => 'article.field.title', ) ) ->add('summary', 'redactor', array( 'label' => 'article.field.summary', 'help' => 'article.help.summary', 'minHeight' => 100, ) ) ->add('tags', 'list', array( 'label' => 'article.field.tags', 'required' => false, 'help' => 'article.help.tags', ) ) ; if (!$this->getSubject()->isSystem()) { $mapper->add('url', null, array( 'label' => 'article.field.customUrl', 'required' => false, 'help' => 'article.help.customUrl', 'attr' => array( 'placeholder' => $this->getSubject()->getRoutePattern(), ), ) ); } $mapper->end(); if (!$this->getSubject()->isSystem()) { parent::configureFormFields($mapper); } $mapper ->with('article.group.template', array('class' => 'col-md-12')) ->add('template', null, array( 'label' => 'article.field.template', 'query_builder' => function (EntityRepository $repository) { return $repository->createQueryBuilder('template') ->orderBy('template.title', 'ASC'); }, ) ) ->add('contents', 'template', array( 'label' => false, ) ) ->end() ->with('article.group.metas', array('class' => 'col-md-12')) ->add('metas', 'metagroup', array( 'label' => false, ) ) ->end() ; }
php
protected function configureFormFields(FormMapper $mapper) { $mapper ->with('article.group.general', array('class' => 'col-md-6')) ->add('title', null, array( 'label' => 'article.field.title', ) ) ->add('summary', 'redactor', array( 'label' => 'article.field.summary', 'help' => 'article.help.summary', 'minHeight' => 100, ) ) ->add('tags', 'list', array( 'label' => 'article.field.tags', 'required' => false, 'help' => 'article.help.tags', ) ) ; if (!$this->getSubject()->isSystem()) { $mapper->add('url', null, array( 'label' => 'article.field.customUrl', 'required' => false, 'help' => 'article.help.customUrl', 'attr' => array( 'placeholder' => $this->getSubject()->getRoutePattern(), ), ) ); } $mapper->end(); if (!$this->getSubject()->isSystem()) { parent::configureFormFields($mapper); } $mapper ->with('article.group.template', array('class' => 'col-md-12')) ->add('template', null, array( 'label' => 'article.field.template', 'query_builder' => function (EntityRepository $repository) { return $repository->createQueryBuilder('template') ->orderBy('template.title', 'ASC'); }, ) ) ->add('contents', 'template', array( 'label' => false, ) ) ->end() ->with('article.group.metas', array('class' => 'col-md-12')) ->add('metas', 'metagroup', array( 'label' => false, ) ) ->end() ; }
[ "protected", "function", "configureFormFields", "(", "FormMapper", "$", "mapper", ")", "{", "$", "mapper", "->", "with", "(", "'article.group.general'", ",", "array", "(", "'class'", "=>", "'col-md-6'", ")", ")", "->", "add", "(", "'title'", ",", "null", ",", "array", "(", "'label'", "=>", "'article.field.title'", ",", ")", ")", "->", "add", "(", "'summary'", ",", "'redactor'", ",", "array", "(", "'label'", "=>", "'article.field.summary'", ",", "'help'", "=>", "'article.help.summary'", ",", "'minHeight'", "=>", "100", ",", ")", ")", "->", "add", "(", "'tags'", ",", "'list'", ",", "array", "(", "'label'", "=>", "'article.field.tags'", ",", "'required'", "=>", "false", ",", "'help'", "=>", "'article.help.tags'", ",", ")", ")", ";", "if", "(", "!", "$", "this", "->", "getSubject", "(", ")", "->", "isSystem", "(", ")", ")", "{", "$", "mapper", "->", "add", "(", "'url'", ",", "null", ",", "array", "(", "'label'", "=>", "'article.field.customUrl'", ",", "'required'", "=>", "false", ",", "'help'", "=>", "'article.help.customUrl'", ",", "'attr'", "=>", "array", "(", "'placeholder'", "=>", "$", "this", "->", "getSubject", "(", ")", "->", "getRoutePattern", "(", ")", ",", ")", ",", ")", ")", ";", "}", "$", "mapper", "->", "end", "(", ")", ";", "if", "(", "!", "$", "this", "->", "getSubject", "(", ")", "->", "isSystem", "(", ")", ")", "{", "parent", "::", "configureFormFields", "(", "$", "mapper", ")", ";", "}", "$", "mapper", "->", "with", "(", "'article.group.template'", ",", "array", "(", "'class'", "=>", "'col-md-12'", ")", ")", "->", "add", "(", "'template'", ",", "null", ",", "array", "(", "'label'", "=>", "'article.field.template'", ",", "'query_builder'", "=>", "function", "(", "EntityRepository", "$", "repository", ")", "{", "return", "$", "repository", "->", "createQueryBuilder", "(", "'template'", ")", "->", "orderBy", "(", "'template.title'", ",", "'ASC'", ")", ";", "}", ",", ")", ")", "->", "add", "(", "'contents'", ",", "'template'", ",", "array", "(", "'label'", "=>", "false", ",", ")", ")", "->", "end", "(", ")", "->", "with", "(", "'article.group.metas'", ",", "array", "(", "'class'", "=>", "'col-md-12'", ")", ")", "->", "add", "(", "'metas'", ",", "'metagroup'", ",", "array", "(", "'label'", "=>", "false", ",", ")", ")", "->", "end", "(", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/vincentchalamon/VinceCmsSonataAdminBundle/blob/edc768061734a92ba116488dd7b61ad40af21ceb/Admin/Entity/ArticleAdmin.php#L279-L337
vincentchalamon/VinceCmsSonataAdminBundle
Admin/Entity/ArticleAdmin.php
ArticleAdmin.prePersist
public function prePersist($object) { /** @var Article $object */ // Remove empty contents or from other templates foreach ($object->getContents() as $content) { /** @var Content $content */ if ($content->getArea()->getTemplate()->getId() != $object->getTemplate()->getId() || !trim(strip_tags($content->getContents(), '<img><input><button><iframe>')) || is_null($content->getContents())) { $object->removeContent($content); $this->em->remove($content); } } // Remove empty metas foreach ($object->getMetas() as $meta) { /** @var ArticleMeta $meta */ if (!trim(strip_tags($meta->getContents()))) { $object->removeMeta($meta); $this->em->remove($meta); } } }
php
public function prePersist($object) { /** @var Article $object */ // Remove empty contents or from other templates foreach ($object->getContents() as $content) { /** @var Content $content */ if ($content->getArea()->getTemplate()->getId() != $object->getTemplate()->getId() || !trim(strip_tags($content->getContents(), '<img><input><button><iframe>')) || is_null($content->getContents())) { $object->removeContent($content); $this->em->remove($content); } } // Remove empty metas foreach ($object->getMetas() as $meta) { /** @var ArticleMeta $meta */ if (!trim(strip_tags($meta->getContents()))) { $object->removeMeta($meta); $this->em->remove($meta); } } }
[ "public", "function", "prePersist", "(", "$", "object", ")", "{", "/** @var Article $object */", "// Remove empty contents or from other templates", "foreach", "(", "$", "object", "->", "getContents", "(", ")", "as", "$", "content", ")", "{", "/** @var Content $content */", "if", "(", "$", "content", "->", "getArea", "(", ")", "->", "getTemplate", "(", ")", "->", "getId", "(", ")", "!=", "$", "object", "->", "getTemplate", "(", ")", "->", "getId", "(", ")", "||", "!", "trim", "(", "strip_tags", "(", "$", "content", "->", "getContents", "(", ")", ",", "'<img><input><button><iframe>'", ")", ")", "||", "is_null", "(", "$", "content", "->", "getContents", "(", ")", ")", ")", "{", "$", "object", "->", "removeContent", "(", "$", "content", ")", ";", "$", "this", "->", "em", "->", "remove", "(", "$", "content", ")", ";", "}", "}", "// Remove empty metas", "foreach", "(", "$", "object", "->", "getMetas", "(", ")", "as", "$", "meta", ")", "{", "/** @var ArticleMeta $meta */", "if", "(", "!", "trim", "(", "strip_tags", "(", "$", "meta", "->", "getContents", "(", ")", ")", ")", ")", "{", "$", "object", "->", "removeMeta", "(", "$", "meta", ")", ";", "$", "this", "->", "em", "->", "remove", "(", "$", "meta", ")", ";", "}", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/vincentchalamon/VinceCmsSonataAdminBundle/blob/edc768061734a92ba116488dd7b61ad40af21ceb/Admin/Entity/ArticleAdmin.php#L342-L363
vincentchalamon/VinceCmsSonataAdminBundle
Admin/Entity/ArticleAdmin.php
ArticleAdmin.postPersist
public function postPersist($object) { // Need to clear router cache $files = Finder::create()->files()->name('/app[A-z]+Url(?:Generator|Matcher)\.php/')->in($this->cacheDir); foreach ($files as $file) { /** @var \SplFileInfo $file */ unlink($file->__toString()); } }
php
public function postPersist($object) { // Need to clear router cache $files = Finder::create()->files()->name('/app[A-z]+Url(?:Generator|Matcher)\.php/')->in($this->cacheDir); foreach ($files as $file) { /** @var \SplFileInfo $file */ unlink($file->__toString()); } }
[ "public", "function", "postPersist", "(", "$", "object", ")", "{", "// Need to clear router cache", "$", "files", "=", "Finder", "::", "create", "(", ")", "->", "files", "(", ")", "->", "name", "(", "'/app[A-z]+Url(?:Generator|Matcher)\\.php/'", ")", "->", "in", "(", "$", "this", "->", "cacheDir", ")", ";", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "/** @var \\SplFileInfo $file */", "unlink", "(", "$", "file", "->", "__toString", "(", ")", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/vincentchalamon/VinceCmsSonataAdminBundle/blob/edc768061734a92ba116488dd7b61ad40af21ceb/Admin/Entity/ArticleAdmin.php#L394-L402
chippyash/Math-Type-Calculator
src/Chippyash/Math/Type/Traits/CheckIntTypes.php
CheckIntTypes.checkIntTypes
protected function checkIntTypes(NumericTypeInterface $a, NumericTypeInterface $b) { $a1 = ($a instanceof IntType ? $a : $a->asIntType()); $b1 = ($a instanceof IntType ? $b : $b->asIntType()); return [$a1, $b1]; }
php
protected function checkIntTypes(NumericTypeInterface $a, NumericTypeInterface $b) { $a1 = ($a instanceof IntType ? $a : $a->asIntType()); $b1 = ($a instanceof IntType ? $b : $b->asIntType()); return [$a1, $b1]; }
[ "protected", "function", "checkIntTypes", "(", "NumericTypeInterface", "$", "a", ",", "NumericTypeInterface", "$", "b", ")", "{", "$", "a1", "=", "(", "$", "a", "instanceof", "IntType", "?", "$", "a", ":", "$", "a", "->", "asIntType", "(", ")", ")", ";", "$", "b1", "=", "(", "$", "a", "instanceof", "IntType", "?", "$", "b", ":", "$", "b", "->", "asIntType", "(", ")", ")", ";", "return", "[", "$", "a1", ",", "$", "b1", "]", ";", "}" ]
Check for integer type, converting if necessary @param NumericTypeInterface $a @param NumericTypeInterface $b @return array [IntType, IntType]
[ "Check", "for", "integer", "type", "converting", "if", "necessary" ]
train
https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Traits/CheckIntTypes.php#L28-L34
drunomics/service-utils
src/Core/Config/ConfigFactoryTrait.php
ConfigFactoryTrait.getConfigFactory
public function getConfigFactory() { if (empty($this->configFactory)) { $this->configFactory = \Drupal::service('config.factory'); } return $this->configFactory; }
php
public function getConfigFactory() { if (empty($this->configFactory)) { $this->configFactory = \Drupal::service('config.factory'); } return $this->configFactory; }
[ "public", "function", "getConfigFactory", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "configFactory", ")", ")", "{", "$", "this", "->", "configFactory", "=", "\\", "Drupal", "::", "service", "(", "'config.factory'", ")", ";", "}", "return", "$", "this", "->", "configFactory", ";", "}" ]
Gets the config factory. @return \Drupal\Core\Config\ConfigFactoryInterface The config factory.
[ "Gets", "the", "config", "factory", "." ]
train
https://github.com/drunomics/service-utils/blob/56761750043132365ef4ae5d9e0cf4263459328f/src/Core/Config/ConfigFactoryTrait.php#L38-L43
nkt/flame
src/QueryBuilder/Part/WherePart.php
WherePart.where
public function where($stmt) { if ($stmt instanceof Expression) { $this->where = $stmt; } elseif ($stmt instanceof \Closure) { $this->where = new Expression($this->getGrammar()); call_user_func($stmt, $this->where); } elseif (is_array($stmt)) { $this->where = new Expression($this->getGrammar(), $stmt); } else { throw new \InvalidArgumentException('Where statement could to be Expression, callable or array'); } return $this; }
php
public function where($stmt) { if ($stmt instanceof Expression) { $this->where = $stmt; } elseif ($stmt instanceof \Closure) { $this->where = new Expression($this->getGrammar()); call_user_func($stmt, $this->where); } elseif (is_array($stmt)) { $this->where = new Expression($this->getGrammar(), $stmt); } else { throw new \InvalidArgumentException('Where statement could to be Expression, callable or array'); } return $this; }
[ "public", "function", "where", "(", "$", "stmt", ")", "{", "if", "(", "$", "stmt", "instanceof", "Expression", ")", "{", "$", "this", "->", "where", "=", "$", "stmt", ";", "}", "elseif", "(", "$", "stmt", "instanceof", "\\", "Closure", ")", "{", "$", "this", "->", "where", "=", "new", "Expression", "(", "$", "this", "->", "getGrammar", "(", ")", ")", ";", "call_user_func", "(", "$", "stmt", ",", "$", "this", "->", "where", ")", ";", "}", "elseif", "(", "is_array", "(", "$", "stmt", ")", ")", "{", "$", "this", "->", "where", "=", "new", "Expression", "(", "$", "this", "->", "getGrammar", "(", ")", ",", "$", "stmt", ")", ";", "}", "else", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Where statement could to be Expression, callable or array'", ")", ";", "}", "return", "$", "this", ";", "}" ]
@param Expression|callable|array $stmt @return static @throws \InvalidArgumentException
[ "@param", "Expression|callable|array", "$stmt" ]
train
https://github.com/nkt/flame/blob/16f9f172db5a8a618b628429e0986eacb089d217/src/QueryBuilder/Part/WherePart.php#L24-L38
nkt/flame
src/Connection.php
Connection.prepare
public function prepare($sql, $driverOptions = []) { $this->placeholders = $this->types = []; $sql = preg_replace_callback(static::PLACEHOLDER_REGEX, function ($matches) { $name = $matches[2]; if (!isset($this->types[$name])) { $this->types[$name] = static::$typeMap[$matches[1]]; } $this->placeholders[] = $name; return '?'; }, $sql); return parent::prepare($sql, $driverOptions); }
php
public function prepare($sql, $driverOptions = []) { $this->placeholders = $this->types = []; $sql = preg_replace_callback(static::PLACEHOLDER_REGEX, function ($matches) { $name = $matches[2]; if (!isset($this->types[$name])) { $this->types[$name] = static::$typeMap[$matches[1]]; } $this->placeholders[] = $name; return '?'; }, $sql); return parent::prepare($sql, $driverOptions); }
[ "public", "function", "prepare", "(", "$", "sql", ",", "$", "driverOptions", "=", "[", "]", ")", "{", "$", "this", "->", "placeholders", "=", "$", "this", "->", "types", "=", "[", "]", ";", "$", "sql", "=", "preg_replace_callback", "(", "static", "::", "PLACEHOLDER_REGEX", ",", "function", "(", "$", "matches", ")", "{", "$", "name", "=", "$", "matches", "[", "2", "]", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "types", "[", "$", "name", "]", ")", ")", "{", "$", "this", "->", "types", "[", "$", "name", "]", "=", "static", "::", "$", "typeMap", "[", "$", "matches", "[", "1", "]", "]", ";", "}", "$", "this", "->", "placeholders", "[", "]", "=", "$", "name", ";", "return", "'?'", ";", "}", ",", "$", "sql", ")", ";", "return", "parent", "::", "prepare", "(", "$", "sql", ",", "$", "driverOptions", ")", ";", "}" ]
@param string $sql @param array $driverOptions @return Statement
[ "@param", "string", "$sql", "@param", "array", "$driverOptions" ]
train
https://github.com/nkt/flame/blob/16f9f172db5a8a618b628429e0986eacb089d217/src/Connection.php#L73-L87
shawnsandy/ui-pages
src/GitLoginMiddleware.php
GitLoginMiddleware.handle
public function handle($request, Closure $next) { /** * Grab the pagekit session array[github_name, github_email] * match to the pagekit.github_username and pagekit.github_email * redirect to login on fail */ $session = session(config('pagekit.session_key')); if ($session['github_name'] != config('pagekit.github_username') && $session['github_email'] != config('pagekit.github_email') ) { return redirect('/dash-login'); } return $next($request); }
php
public function handle($request, Closure $next) { /** * Grab the pagekit session array[github_name, github_email] * match to the pagekit.github_username and pagekit.github_email * redirect to login on fail */ $session = session(config('pagekit.session_key')); if ($session['github_name'] != config('pagekit.github_username') && $session['github_email'] != config('pagekit.github_email') ) { return redirect('/dash-login'); } return $next($request); }
[ "public", "function", "handle", "(", "$", "request", ",", "Closure", "$", "next", ")", "{", "/**\n * Grab the pagekit session array[github_name, github_email]\n * match to the pagekit.github_username and pagekit.github_email\n * redirect to login on fail\n */", "$", "session", "=", "session", "(", "config", "(", "'pagekit.session_key'", ")", ")", ";", "if", "(", "$", "session", "[", "'github_name'", "]", "!=", "config", "(", "'pagekit.github_username'", ")", "&&", "$", "session", "[", "'github_email'", "]", "!=", "config", "(", "'pagekit.github_email'", ")", ")", "{", "return", "redirect", "(", "'/dash-login'", ")", ";", "}", "return", "$", "next", "(", "$", "request", ")", ";", "}" ]
Handle function @param array $request request array @param Closure $next colsure @return mixed
[ "Handle", "function" ]
train
https://github.com/shawnsandy/ui-pages/blob/11584c12fa3e2b9a5c513f4ec9e2eaf78c206ca8/src/GitLoginMiddleware.php#L47-L65
comelyio/comely
src/Comely/IO/Cache/Cacheable/CacheItem.php
CacheItem.ttl
public function ttl(int $seconds = null): int { if (is_int($seconds) && $seconds >= 0) { $this->ttl = $seconds; } return $this->ttl; }
php
public function ttl(int $seconds = null): int { if (is_int($seconds) && $seconds >= 0) { $this->ttl = $seconds; } return $this->ttl; }
[ "public", "function", "ttl", "(", "int", "$", "seconds", "=", "null", ")", ":", "int", "{", "if", "(", "is_int", "(", "$", "seconds", ")", "&&", "$", "seconds", ">=", "0", ")", "{", "$", "this", "->", "ttl", "=", "$", "seconds", ";", "}", "return", "$", "this", "->", "ttl", ";", "}" ]
Set/get TTL for this value @param int|null $seconds @return int
[ "Set", "/", "get", "TTL", "for", "this", "value" ]
train
https://github.com/comelyio/comely/blob/561ea7aef36fea347a1a79d3ee5597d4057ddf82/src/Comely/IO/Cache/Cacheable/CacheItem.php#L70-L77
acasademont/wurfl
WURFL/CustomDeviceRepository.php
WURFL_CustomDeviceRepository.init
private function init() { $genericDevice = $this->getDevice(WURFL_Constants::GENERIC); if (!is_null($genericDevice)) { $this->_capabilitiesName = array_keys($genericDevice->getCapabilities()); $this->_groupIDCapabilitiesMap = $genericDevice->getGroupIdCapabilitiesNameMap(); } }
php
private function init() { $genericDevice = $this->getDevice(WURFL_Constants::GENERIC); if (!is_null($genericDevice)) { $this->_capabilitiesName = array_keys($genericDevice->getCapabilities()); $this->_groupIDCapabilitiesMap = $genericDevice->getGroupIdCapabilitiesNameMap(); } }
[ "private", "function", "init", "(", ")", "{", "$", "genericDevice", "=", "$", "this", "->", "getDevice", "(", "WURFL_Constants", "::", "GENERIC", ")", ";", "if", "(", "!", "is_null", "(", "$", "genericDevice", ")", ")", "{", "$", "this", "->", "_capabilitiesName", "=", "array_keys", "(", "$", "genericDevice", "->", "getCapabilities", "(", ")", ")", ";", "$", "this", "->", "_groupIDCapabilitiesMap", "=", "$", "genericDevice", "->", "getGroupIdCapabilitiesNameMap", "(", ")", ";", "}", "}" ]
Initializes this device repository by loading the base generic device capabilities names and group ID map
[ "Initializes", "this", "device", "repository", "by", "loading", "the", "base", "generic", "device", "capabilities", "names", "and", "group", "ID", "map" ]
train
https://github.com/acasademont/wurfl/blob/0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2/WURFL/CustomDeviceRepository.php#L70-L77
acasademont/wurfl
WURFL/CustomDeviceRepository.php
WURFL_CustomDeviceRepository.getDevice
public function getDevice($deviceId) { if (!isset($this->_deviceCache[$deviceId])) { $device = $this->persistenceStorage->load($deviceId); if (!$device) { throw new Exception("There is no device with ID [$deviceId] in the loaded WURFL Data"); } $this->_deviceCache[$deviceId] = $device; } return $this->_deviceCache[$deviceId]; }
php
public function getDevice($deviceId) { if (!isset($this->_deviceCache[$deviceId])) { $device = $this->persistenceStorage->load($deviceId); if (!$device) { throw new Exception("There is no device with ID [$deviceId] in the loaded WURFL Data"); } $this->_deviceCache[$deviceId] = $device; } return $this->_deviceCache[$deviceId]; }
[ "public", "function", "getDevice", "(", "$", "deviceId", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "_deviceCache", "[", "$", "deviceId", "]", ")", ")", "{", "$", "device", "=", "$", "this", "->", "persistenceStorage", "->", "load", "(", "$", "deviceId", ")", ";", "if", "(", "!", "$", "device", ")", "{", "throw", "new", "Exception", "(", "\"There is no device with ID [$deviceId] in the loaded WURFL Data\"", ")", ";", "}", "$", "this", "->", "_deviceCache", "[", "$", "deviceId", "]", "=", "$", "device", ";", "}", "return", "$", "this", "->", "_deviceCache", "[", "$", "deviceId", "]", ";", "}" ]
Returns a device for the given device ID @param string $deviceId @return WURFL_CustomDevice @throws WURFL_Exception if $deviceID is not defined in wurfl devices repository
[ "Returns", "a", "device", "for", "the", "given", "device", "ID" ]
train
https://github.com/acasademont/wurfl/blob/0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2/WURFL/CustomDeviceRepository.php#L105-L115
acasademont/wurfl
WURFL/CustomDeviceRepository.php
WURFL_CustomDeviceRepository.getAllDevicesID
public function getAllDevicesID() { $devicesId = array(); foreach ($this->deviceClassificationNames as $className) { $currentMap = $this->persistenceStorage->load($className); if (!is_array($currentMap)) { $currentMap = array(); } $devicesId = array_merge($devicesId, array_values($currentMap)); } return $devicesId; }
php
public function getAllDevicesID() { $devicesId = array(); foreach ($this->deviceClassificationNames as $className) { $currentMap = $this->persistenceStorage->load($className); if (!is_array($currentMap)) { $currentMap = array(); } $devicesId = array_merge($devicesId, array_values($currentMap)); } return $devicesId; }
[ "public", "function", "getAllDevicesID", "(", ")", "{", "$", "devicesId", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "deviceClassificationNames", "as", "$", "className", ")", "{", "$", "currentMap", "=", "$", "this", "->", "persistenceStorage", "->", "load", "(", "$", "className", ")", ";", "if", "(", "!", "is_array", "(", "$", "currentMap", ")", ")", "{", "$", "currentMap", "=", "array", "(", ")", ";", "}", "$", "devicesId", "=", "array_merge", "(", "$", "devicesId", ",", "array_values", "(", "$", "currentMap", ")", ")", ";", "}", "return", "$", "devicesId", ";", "}" ]
Returns an array of all the device ids @return array
[ "Returns", "an", "array", "of", "all", "the", "device", "ids" ]
train
https://github.com/acasademont/wurfl/blob/0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2/WURFL/CustomDeviceRepository.php#L136-L147
acasademont/wurfl
WURFL/CustomDeviceRepository.php
WURFL_CustomDeviceRepository.getAllCapabilitiesForDevice
public function getAllCapabilitiesForDevice($deviceID) { $devices = array_reverse($this->getDeviceHierarchy($deviceID)); $capabilities = array(); foreach ($devices as $device) { if (is_array($device->capabilities)) { $capabilities = array_merge($capabilities, $device->capabilities); } } return $capabilities; }
php
public function getAllCapabilitiesForDevice($deviceID) { $devices = array_reverse($this->getDeviceHierarchy($deviceID)); $capabilities = array(); foreach ($devices as $device) { if (is_array($device->capabilities)) { $capabilities = array_merge($capabilities, $device->capabilities); } } return $capabilities; }
[ "public", "function", "getAllCapabilitiesForDevice", "(", "$", "deviceID", ")", "{", "$", "devices", "=", "array_reverse", "(", "$", "this", "->", "getDeviceHierarchy", "(", "$", "deviceID", ")", ")", ";", "$", "capabilities", "=", "array", "(", ")", ";", "foreach", "(", "$", "devices", "as", "$", "device", ")", "{", "if", "(", "is_array", "(", "$", "device", "->", "capabilities", ")", ")", "{", "$", "capabilities", "=", "array_merge", "(", "$", "capabilities", ",", "$", "device", "->", "capabilities", ")", ";", "}", "}", "return", "$", "capabilities", ";", "}" ]
Returns an associative array of capabilityName => capabilityValue for the given $deviceID @param string $deviceID @return array associative array of capabilityName, capabilityValue
[ "Returns", "an", "associative", "array", "of", "capabilityName", "=", ">", "capabilityValue", "for", "the", "given", "$deviceID" ]
train
https://github.com/acasademont/wurfl/blob/0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2/WURFL/CustomDeviceRepository.php#L195-L206
acasademont/wurfl
WURFL/CustomDeviceRepository.php
WURFL_CustomDeviceRepository.getCapabilitiesNameForGroup
public function getCapabilitiesNameForGroup($groupID) { if (!array_key_exists($groupID, $this->_groupIDCapabilitiesMap)) { throw new WURFL_WURFLException("The Group ID " . $groupID . " supplied does not exist"); } return $this->_groupIDCapabilitiesMap [$groupID]; }
php
public function getCapabilitiesNameForGroup($groupID) { if (!array_key_exists($groupID, $this->_groupIDCapabilitiesMap)) { throw new WURFL_WURFLException("The Group ID " . $groupID . " supplied does not exist"); } return $this->_groupIDCapabilitiesMap [$groupID]; }
[ "public", "function", "getCapabilitiesNameForGroup", "(", "$", "groupID", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "groupID", ",", "$", "this", "->", "_groupIDCapabilitiesMap", ")", ")", "{", "throw", "new", "WURFL_WURFLException", "(", "\"The Group ID \"", ".", "$", "groupID", ".", "\" supplied does not exist\"", ")", ";", "}", "return", "$", "this", "->", "_groupIDCapabilitiesMap", "[", "$", "groupID", "]", ";", "}" ]
Returns an array of all capability names defined in the given group ID @param string $groupID @throws WURFL_WURFLException The given $groupID does not exist @return array of capability names
[ "Returns", "an", "array", "of", "all", "capability", "names", "defined", "in", "the", "given", "group", "ID" ]
train
https://github.com/acasademont/wurfl/blob/0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2/WURFL/CustomDeviceRepository.php#L244-L250
acasademont/wurfl
WURFL/CustomDeviceRepository.php
WURFL_CustomDeviceRepository.getGroupIDForCapability
public function getGroupIDForCapability($capability) { if (!isset($capability) || !array_key_exists($capability, $this->_groupIDCapabilitiesMap)) { throw new InvalidArgumentException("an invalid capability was specified."); } return $this->_groupIDCapabilitiesMap[$capability]; }
php
public function getGroupIDForCapability($capability) { if (!isset($capability) || !array_key_exists($capability, $this->_groupIDCapabilitiesMap)) { throw new InvalidArgumentException("an invalid capability was specified."); } return $this->_groupIDCapabilitiesMap[$capability]; }
[ "public", "function", "getGroupIDForCapability", "(", "$", "capability", ")", "{", "if", "(", "!", "isset", "(", "$", "capability", ")", "||", "!", "array_key_exists", "(", "$", "capability", ",", "$", "this", "->", "_groupIDCapabilitiesMap", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"an invalid capability was specified.\"", ")", ";", "}", "return", "$", "this", "->", "_groupIDCapabilitiesMap", "[", "$", "capability", "]", ";", "}" ]
Returns the group id that contains the given $capability @param string $capability @throws InvalidArgumentException an invalid $capability was specified @return string
[ "Returns", "the", "group", "id", "that", "contains", "the", "given", "$capability" ]
train
https://github.com/acasademont/wurfl/blob/0f4fb6e06b452ba95ad1d15e7d8226d0974b60c2/WURFL/CustomDeviceRepository.php#L259-L265
ubirak/symfony-json-rest-api
src/LinkRequestListener.php
LinkRequestListener.parseWeblink
private function parseWeblink($linkHeader) { $links = []; while (preg_match('/^((?:[^"]|"[^"]*")*?),/', $linkHeader, $matches)) { $linkHeader = trim(substr($linkHeader, strlen($matches[0]))); $links[] = Weblink::fromHeaderString($matches[1]); } if ($linkHeader) { $links[] = Weblink::fromHeaderString($linkHeader); } return $links; }
php
private function parseWeblink($linkHeader) { $links = []; while (preg_match('/^((?:[^"]|"[^"]*")*?),/', $linkHeader, $matches)) { $linkHeader = trim(substr($linkHeader, strlen($matches[0]))); $links[] = Weblink::fromHeaderString($matches[1]); } if ($linkHeader) { $links[] = Weblink::fromHeaderString($linkHeader); } return $links; }
[ "private", "function", "parseWeblink", "(", "$", "linkHeader", ")", "{", "$", "links", "=", "[", "]", ";", "while", "(", "preg_match", "(", "'/^((?:[^\"]|\"[^\"]*\")*?),/'", ",", "$", "linkHeader", ",", "$", "matches", ")", ")", "{", "$", "linkHeader", "=", "trim", "(", "substr", "(", "$", "linkHeader", ",", "strlen", "(", "$", "matches", "[", "0", "]", ")", ")", ")", ";", "$", "links", "[", "]", "=", "Weblink", "::", "fromHeaderString", "(", "$", "matches", "[", "1", "]", ")", ";", "}", "if", "(", "$", "linkHeader", ")", "{", "$", "links", "[", "]", "=", "Weblink", "::", "fromHeaderString", "(", "$", "linkHeader", ")", ";", "}", "return", "$", "links", ";", "}" ]
/* Due to limitations, multiple same-name headers are sent as comma separated values. This breaks those headers into Link headers following the format http://tools.ietf.org/html/rfc2068#section-19.6.2.4
[ "/", "*", "Due", "to", "limitations", "multiple", "same", "-", "name", "headers", "are", "sent", "as", "comma", "separated", "values", "." ]
train
https://github.com/ubirak/symfony-json-rest-api/blob/f34b58feebf7908897bc47403bd8859d4e26a069/src/LinkRequestListener.php#L38-L52