repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
sequencelengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
sequencelengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
Double-Opt-in/php-client-api
src/Client/Commands/Responses/DecryptedCommandResponse.php
DecryptedCommandResponse.resolveActionFromStdClass
protected function resolveActionFromStdClass(stdClass $stdClass) { if (isset($stdClass->data)) $stdClass->data = $this->cryptographyEngine->decrypt($stdClass->data, $this->email); return Action::createFromStdClass($stdClass); }
php
protected function resolveActionFromStdClass(stdClass $stdClass) { if (isset($stdClass->data)) $stdClass->data = $this->cryptographyEngine->decrypt($stdClass->data, $this->email); return Action::createFromStdClass($stdClass); }
[ "protected", "function", "resolveActionFromStdClass", "(", "stdClass", "$", "stdClass", ")", "{", "if", "(", "isset", "(", "$", "stdClass", "->", "data", ")", ")", "$", "stdClass", "->", "data", "=", "$", "this", "->", "cryptographyEngine", "->", "decrypt", "(", "$", "stdClass", "->", "data", ",", "$", "this", "->", "email", ")", ";", "return", "Action", "::", "createFromStdClass", "(", "$", "stdClass", ")", ";", "}" ]
resolves an action from a stdClass @param \stdClass $stdClass @return Action
[ "resolves", "an", "action", "from", "a", "stdClass" ]
train
https://github.com/Double-Opt-in/php-client-api/blob/2f17da58ec20a408bbd55b2cdd053bc689f995f4/src/Client/Commands/Responses/DecryptedCommandResponse.php#L51-L57
yoanm/symfony-jsonrpc-http-server-doc
src/Provider/RawDocProvider.php
RawDocProvider.getDoc
public function getDoc($host = null) : array { return $this->serverDocNormalizer->normalize( $this->httpServerDocCreator->create($host) ); }
php
public function getDoc($host = null) : array { return $this->serverDocNormalizer->normalize( $this->httpServerDocCreator->create($host) ); }
[ "public", "function", "getDoc", "(", "$", "host", "=", "null", ")", ":", "array", "{", "return", "$", "this", "->", "serverDocNormalizer", "->", "normalize", "(", "$", "this", "->", "httpServerDocCreator", "->", "create", "(", "$", "host", ")", ")", ";", "}" ]
@param string|null $host @return array
[ "@param", "string|null", "$host" ]
train
https://github.com/yoanm/symfony-jsonrpc-http-server-doc/blob/7a59862f74fef29d0e2ad017188977419503ad94/src/Provider/RawDocProvider.php#L36-L41
andrelohmann/silverstripe-extended-image
code/extensions/ExtendedGDBackend.php
ExtendedGDBackend.merge
public function merge(GDBackend $image){ imagealphablending($this->owner->getImageResource(), false); imagesavealpha($this->owner->getImageResource(), true); imagealphablending($image->getImageResource(), false); imagesavealpha($image->getImageResource(), true); $srcX = 0; $srcY = 0; $srcW = $image->getWidth(); $srcH = $image->getHeight(); $dstX = round(($this->owner->getWidth() - $srcW)/2); $dstY = round(($this->owner->getHeight() - $srcH)/2); $dstW = $image->getWidth(); $dstH = $image->getHeight(); imagecopyresampled($this->owner->getImageResource(), $image->getImageResource(), $dstX, $dstY, $srcX, $srcY, $dstW, $dstH, $srcW, $srcH); $output = clone $this->owner; $output->setImageResource($this->owner->getImageResource()); return $output; }
php
public function merge(GDBackend $image){ imagealphablending($this->owner->getImageResource(), false); imagesavealpha($this->owner->getImageResource(), true); imagealphablending($image->getImageResource(), false); imagesavealpha($image->getImageResource(), true); $srcX = 0; $srcY = 0; $srcW = $image->getWidth(); $srcH = $image->getHeight(); $dstX = round(($this->owner->getWidth() - $srcW)/2); $dstY = round(($this->owner->getHeight() - $srcH)/2); $dstW = $image->getWidth(); $dstH = $image->getHeight(); imagecopyresampled($this->owner->getImageResource(), $image->getImageResource(), $dstX, $dstY, $srcX, $srcY, $dstW, $dstH, $srcW, $srcH); $output = clone $this->owner; $output->setImageResource($this->owner->getImageResource()); return $output; }
[ "public", "function", "merge", "(", "GDBackend", "$", "image", ")", "{", "imagealphablending", "(", "$", "this", "->", "owner", "->", "getImageResource", "(", ")", ",", "false", ")", ";", "imagesavealpha", "(", "$", "this", "->", "owner", "->", "getImageResource", "(", ")", ",", "true", ")", ";", "imagealphablending", "(", "$", "image", "->", "getImageResource", "(", ")", ",", "false", ")", ";", "imagesavealpha", "(", "$", "image", "->", "getImageResource", "(", ")", ",", "true", ")", ";", "$", "srcX", "=", "0", ";", "$", "srcY", "=", "0", ";", "$", "srcW", "=", "$", "image", "->", "getWidth", "(", ")", ";", "$", "srcH", "=", "$", "image", "->", "getHeight", "(", ")", ";", "$", "dstX", "=", "round", "(", "(", "$", "this", "->", "owner", "->", "getWidth", "(", ")", "-", "$", "srcW", ")", "/", "2", ")", ";", "$", "dstY", "=", "round", "(", "(", "$", "this", "->", "owner", "->", "getHeight", "(", ")", "-", "$", "srcH", ")", "/", "2", ")", ";", "$", "dstW", "=", "$", "image", "->", "getWidth", "(", ")", ";", "$", "dstH", "=", "$", "image", "->", "getHeight", "(", ")", ";", "imagecopyresampled", "(", "$", "this", "->", "owner", "->", "getImageResource", "(", ")", ",", "$", "image", "->", "getImageResource", "(", ")", ",", "$", "dstX", ",", "$", "dstY", ",", "$", "srcX", ",", "$", "srcY", ",", "$", "dstW", ",", "$", "dstH", ",", "$", "srcW", ",", "$", "srcH", ")", ";", "$", "output", "=", "clone", "$", "this", "->", "owner", ";", "$", "output", "->", "setImageResource", "(", "$", "this", "->", "owner", "->", "getImageResource", "(", ")", ")", ";", "return", "$", "output", ";", "}" ]
Merge two Images together
[ "Merge", "two", "Images", "together" ]
train
https://github.com/andrelohmann/silverstripe-extended-image/blob/178e9142ae8ff63f9bf36464093379f6e836b90b/code/extensions/ExtendedGDBackend.php#L15-L37
andrelohmann/silverstripe-extended-image
code/extensions/ExtendedGDBackend.php
ExtendedGDBackend.blur
public function blur($intensity) { $image = $this->owner->getImageResource(); switch($intensity){ case 'light': for ($x=1; $x<=10; $x++) imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR); break; case 'strong': for ($x=1; $x<=40; $x++) imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR); break; case 'normal': default: for ($x=1; $x<=25; $x++) imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR); break; } $output = clone $this->owner; $output->setImageResource($image); return $output; }
php
public function blur($intensity) { $image = $this->owner->getImageResource(); switch($intensity){ case 'light': for ($x=1; $x<=10; $x++) imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR); break; case 'strong': for ($x=1; $x<=40; $x++) imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR); break; case 'normal': default: for ($x=1; $x<=25; $x++) imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR); break; } $output = clone $this->owner; $output->setImageResource($image); return $output; }
[ "public", "function", "blur", "(", "$", "intensity", ")", "{", "$", "image", "=", "$", "this", "->", "owner", "->", "getImageResource", "(", ")", ";", "switch", "(", "$", "intensity", ")", "{", "case", "'light'", ":", "for", "(", "$", "x", "=", "1", ";", "$", "x", "<=", "10", ";", "$", "x", "++", ")", "imagefilter", "(", "$", "image", ",", "IMG_FILTER_GAUSSIAN_BLUR", ")", ";", "break", ";", "case", "'strong'", ":", "for", "(", "$", "x", "=", "1", ";", "$", "x", "<=", "40", ";", "$", "x", "++", ")", "imagefilter", "(", "$", "image", ",", "IMG_FILTER_GAUSSIAN_BLUR", ")", ";", "break", ";", "case", "'normal'", ":", "default", ":", "for", "(", "$", "x", "=", "1", ";", "$", "x", "<=", "25", ";", "$", "x", "++", ")", "imagefilter", "(", "$", "image", ",", "IMG_FILTER_GAUSSIAN_BLUR", ")", ";", "break", ";", "}", "$", "output", "=", "clone", "$", "this", "->", "owner", ";", "$", "output", "->", "setImageResource", "(", "$", "image", ")", ";", "return", "$", "output", ";", "}" ]
blur the image
[ "blur", "the", "image" ]
train
https://github.com/andrelohmann/silverstripe-extended-image/blob/178e9142ae8ff63f9bf36464093379f6e836b90b/code/extensions/ExtendedGDBackend.php#L42-L66
andrelohmann/silverstripe-extended-image
code/extensions/ExtendedGDBackend.php
ExtendedGDBackend.toJpeg
public function toJpeg($backgroundColor, $type) { $image = $this->owner->getImageResource(); switch($type){ case IMAGETYPE_GIF: case IMAGETYPE_PNG: $newGD = imagecreatetruecolor($this->owner->getWidth(), $this->owner->getHeight()); $bg = GDBackend::color_web2gd($newGD, $backgroundColor); imagefill($newGD, 0, 0, $bg); imagealphablending($newGD, TRUE); imagecopy($newGD, $image, 0, 0, 0, 0, $this->owner->getWidth(), $this->owner->getHeight()); break; case IMAGETYPE_JPEG: $newGD = $image; break; } $output = clone $this->owner; $output->setImageResource($newGD); return $output; }
php
public function toJpeg($backgroundColor, $type) { $image = $this->owner->getImageResource(); switch($type){ case IMAGETYPE_GIF: case IMAGETYPE_PNG: $newGD = imagecreatetruecolor($this->owner->getWidth(), $this->owner->getHeight()); $bg = GDBackend::color_web2gd($newGD, $backgroundColor); imagefill($newGD, 0, 0, $bg); imagealphablending($newGD, TRUE); imagecopy($newGD, $image, 0, 0, 0, 0, $this->owner->getWidth(), $this->owner->getHeight()); break; case IMAGETYPE_JPEG: $newGD = $image; break; } $output = clone $this->owner; $output->setImageResource($newGD); return $output; }
[ "public", "function", "toJpeg", "(", "$", "backgroundColor", ",", "$", "type", ")", "{", "$", "image", "=", "$", "this", "->", "owner", "->", "getImageResource", "(", ")", ";", "switch", "(", "$", "type", ")", "{", "case", "IMAGETYPE_GIF", ":", "case", "IMAGETYPE_PNG", ":", "$", "newGD", "=", "imagecreatetruecolor", "(", "$", "this", "->", "owner", "->", "getWidth", "(", ")", ",", "$", "this", "->", "owner", "->", "getHeight", "(", ")", ")", ";", "$", "bg", "=", "GDBackend", "::", "color_web2gd", "(", "$", "newGD", ",", "$", "backgroundColor", ")", ";", "imagefill", "(", "$", "newGD", ",", "0", ",", "0", ",", "$", "bg", ")", ";", "imagealphablending", "(", "$", "newGD", ",", "TRUE", ")", ";", "imagecopy", "(", "$", "newGD", ",", "$", "image", ",", "0", ",", "0", ",", "0", ",", "0", ",", "$", "this", "->", "owner", "->", "getWidth", "(", ")", ",", "$", "this", "->", "owner", "->", "getHeight", "(", ")", ")", ";", "break", ";", "case", "IMAGETYPE_JPEG", ":", "$", "newGD", "=", "$", "image", ";", "break", ";", "}", "$", "output", "=", "clone", "$", "this", "->", "owner", ";", "$", "output", "->", "setImageResource", "(", "$", "newGD", ")", ";", "return", "$", "output", ";", "}" ]
convert to jpeg
[ "convert", "to", "jpeg" ]
train
https://github.com/andrelohmann/silverstripe-extended-image/blob/178e9142ae8ff63f9bf36464093379f6e836b90b/code/extensions/ExtendedGDBackend.php#L144-L165
mihai-stancu/serializer
Serializer/Normalizer/MixedDenormalizer.php
MixedDenormalizer.denormalize
public function denormalize($values, $class, $format = null, array $context = array()) { if (!is_array($values)) { return $values; } $filtered = array_filter( $values, function ($value) use ($class, $format) { return $this->serializer->supportsDenormalization($value, $class, $format); } ); if (count($filtered) !== count($values)) { throw new \InvalidArgumentException('Not all values within the array can be denormalized.'); } return array_map( function ($value) use ($class, $format, $context) { return $this->serializer->denormalize($value, $class, $format, $context); }, $filtered ); }
php
public function denormalize($values, $class, $format = null, array $context = array()) { if (!is_array($values)) { return $values; } $filtered = array_filter( $values, function ($value) use ($class, $format) { return $this->serializer->supportsDenormalization($value, $class, $format); } ); if (count($filtered) !== count($values)) { throw new \InvalidArgumentException('Not all values within the array can be denormalized.'); } return array_map( function ($value) use ($class, $format, $context) { return $this->serializer->denormalize($value, $class, $format, $context); }, $filtered ); }
[ "public", "function", "denormalize", "(", "$", "values", ",", "$", "class", ",", "$", "format", "=", "null", ",", "array", "$", "context", "=", "array", "(", ")", ")", "{", "if", "(", "!", "is_array", "(", "$", "values", ")", ")", "{", "return", "$", "values", ";", "}", "$", "filtered", "=", "array_filter", "(", "$", "values", ",", "function", "(", "$", "value", ")", "use", "(", "$", "class", ",", "$", "format", ")", "{", "return", "$", "this", "->", "serializer", "->", "supportsDenormalization", "(", "$", "value", ",", "$", "class", ",", "$", "format", ")", ";", "}", ")", ";", "if", "(", "count", "(", "$", "filtered", ")", "!==", "count", "(", "$", "values", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Not all values within the array can be denormalized.'", ")", ";", "}", "return", "array_map", "(", "function", "(", "$", "value", ")", "use", "(", "$", "class", ",", "$", "format", ",", "$", "context", ")", "{", "return", "$", "this", "->", "serializer", "->", "denormalize", "(", "$", "value", ",", "$", "class", ",", "$", "format", ",", "$", "context", ")", ";", "}", ",", "$", "filtered", ")", ";", "}" ]
@param array $values @param string $class @param string $format @param array $context @return array|object
[ "@param", "array", "$values", "@param", "string", "$class", "@param", "string", "$format", "@param", "array", "$context" ]
train
https://github.com/mihai-stancu/serializer/blob/4d96f942a3c44d5b5652868be726af656bf1baad/Serializer/Normalizer/MixedDenormalizer.php#L32-L55
mihai-stancu/serializer
Serializer/Normalizer/MixedDenormalizer.php
MixedDenormalizer.supportsDenormalization
public function supportsDenormalization($data, $type, $format = null) { if ($type !== static::TYPE) { return false; } if (!is_null($data) and !is_scalar($data) and !is_resource($data) and !is_array($data)) { return false; } return true; }
php
public function supportsDenormalization($data, $type, $format = null) { if ($type !== static::TYPE) { return false; } if (!is_null($data) and !is_scalar($data) and !is_resource($data) and !is_array($data)) { return false; } return true; }
[ "public", "function", "supportsDenormalization", "(", "$", "data", ",", "$", "type", ",", "$", "format", "=", "null", ")", "{", "if", "(", "$", "type", "!==", "static", "::", "TYPE", ")", "{", "return", "false", ";", "}", "if", "(", "!", "is_null", "(", "$", "data", ")", "and", "!", "is_scalar", "(", "$", "data", ")", "and", "!", "is_resource", "(", "$", "data", ")", "and", "!", "is_array", "(", "$", "data", ")", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
@param array $data @param string $type @param string $format @return bool
[ "@param", "array", "$data", "@param", "string", "$type", "@param", "string", "$format" ]
train
https://github.com/mihai-stancu/serializer/blob/4d96f942a3c44d5b5652868be726af656bf1baad/Serializer/Normalizer/MixedDenormalizer.php#L64-L75
meccado/acl-admin-control-panel
src/Middleware/AdminMiddleware.php
AdminMiddleware.handle
public function handle($request, Closure $next) { if (\Auth::check() && \Auth::user()->isAdmin()){ return $next($request); }else if (\Auth::check() && !\Auth::user()->isAdmin()){ return redirect('/')->withErrors('You are not administrator'); } }
php
public function handle($request, Closure $next) { if (\Auth::check() && \Auth::user()->isAdmin()){ return $next($request); }else if (\Auth::check() && !\Auth::user()->isAdmin()){ return redirect('/')->withErrors('You are not administrator'); } }
[ "public", "function", "handle", "(", "$", "request", ",", "Closure", "$", "next", ")", "{", "if", "(", "\\", "Auth", "::", "check", "(", ")", "&&", "\\", "Auth", "::", "user", "(", ")", "->", "isAdmin", "(", ")", ")", "{", "return", "$", "next", "(", "$", "request", ")", ";", "}", "else", "if", "(", "\\", "Auth", "::", "check", "(", ")", "&&", "!", "\\", "Auth", "::", "user", "(", ")", "->", "isAdmin", "(", ")", ")", "{", "return", "redirect", "(", "'/'", ")", "->", "withErrors", "(", "'You are not administrator'", ")", ";", "}", "}" ]
Handle an incoming request. @param \Illuminate\Http\Request $request @param \Closure $next @return mixed
[ "Handle", "an", "incoming", "request", "." ]
train
https://github.com/meccado/acl-admin-control-panel/blob/50ac4c0dbf8bd49944ecad6a70708a70411b7378/src/Middleware/AdminMiddleware.php#L16-L23
egeloen/IvorySerializerBundle
DependencyInjection/Compiler/RegisterClassMetadataLoaderPass.php
RegisterClassMetadataLoaderPass.process
public function process(ContainerBuilder $container) { $loaders = []; foreach ($container->findTaggedServiceIds($tag = 'ivory.serializer.loader') as $id => $attributes) { foreach ($attributes as $attribute) { $priority = isset($attribute['priority']) ? $attribute['priority'] : 0; $loaders[$priority][] = new Reference($id); } } if (empty($loaders)) { throw new \RuntimeException(sprintf( 'You must define at least one class metadata loader by enabling the reflection loader in your '. 'configuration or by registering a loader in the container with the tag "%s".', $tag )); } $loader = 'ivory.serializer.mapping.loader'; ksort($loaders); $loaders = call_user_func_array('array_merge', $loaders); if (count($loaders) > 1) { $container->setDefinition($loader, new Definition(ChainClassMetadataLoader::class, [ $loaders, new Reference('ivory.serializer.type.parser'), ])); } else { $container->setAlias($loader, (string) array_shift($loaders)); } }
php
public function process(ContainerBuilder $container) { $loaders = []; foreach ($container->findTaggedServiceIds($tag = 'ivory.serializer.loader') as $id => $attributes) { foreach ($attributes as $attribute) { $priority = isset($attribute['priority']) ? $attribute['priority'] : 0; $loaders[$priority][] = new Reference($id); } } if (empty($loaders)) { throw new \RuntimeException(sprintf( 'You must define at least one class metadata loader by enabling the reflection loader in your '. 'configuration or by registering a loader in the container with the tag "%s".', $tag )); } $loader = 'ivory.serializer.mapping.loader'; ksort($loaders); $loaders = call_user_func_array('array_merge', $loaders); if (count($loaders) > 1) { $container->setDefinition($loader, new Definition(ChainClassMetadataLoader::class, [ $loaders, new Reference('ivory.serializer.type.parser'), ])); } else { $container->setAlias($loader, (string) array_shift($loaders)); } }
[ "public", "function", "process", "(", "ContainerBuilder", "$", "container", ")", "{", "$", "loaders", "=", "[", "]", ";", "foreach", "(", "$", "container", "->", "findTaggedServiceIds", "(", "$", "tag", "=", "'ivory.serializer.loader'", ")", "as", "$", "id", "=>", "$", "attributes", ")", "{", "foreach", "(", "$", "attributes", "as", "$", "attribute", ")", "{", "$", "priority", "=", "isset", "(", "$", "attribute", "[", "'priority'", "]", ")", "?", "$", "attribute", "[", "'priority'", "]", ":", "0", ";", "$", "loaders", "[", "$", "priority", "]", "[", "]", "=", "new", "Reference", "(", "$", "id", ")", ";", "}", "}", "if", "(", "empty", "(", "$", "loaders", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'You must define at least one class metadata loader by enabling the reflection loader in your '", ".", "'configuration or by registering a loader in the container with the tag \"%s\".'", ",", "$", "tag", ")", ")", ";", "}", "$", "loader", "=", "'ivory.serializer.mapping.loader'", ";", "ksort", "(", "$", "loaders", ")", ";", "$", "loaders", "=", "call_user_func_array", "(", "'array_merge'", ",", "$", "loaders", ")", ";", "if", "(", "count", "(", "$", "loaders", ")", ">", "1", ")", "{", "$", "container", "->", "setDefinition", "(", "$", "loader", ",", "new", "Definition", "(", "ChainClassMetadataLoader", "::", "class", ",", "[", "$", "loaders", ",", "new", "Reference", "(", "'ivory.serializer.type.parser'", ")", ",", "]", ")", ")", ";", "}", "else", "{", "$", "container", "->", "setAlias", "(", "$", "loader", ",", "(", "string", ")", "array_shift", "(", "$", "loaders", ")", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/egeloen/IvorySerializerBundle/blob/a2bdd912bf715c61b823cf7257ee232d5c823dd3/DependencyInjection/Compiler/RegisterClassMetadataLoaderPass.php#L28-L60
javiacei/IdeupSimplePaginatorBundle
Paginator/Adapter/AdapterFactory.php
AdapterFactory.createAdapter
public function createAdapter($collection) { if (\is_array($collection)) { $className = 'Array'; } else { try { $r = new \ReflectionClass($collection); $className = $r->getName(); } catch (\ReflectionException $exc) { throw new AdapterNotSupportedException($collection); } } $adapterName = __NAMESPACE__ . "\\" . $className . 'Adapter' ; return new $adapterName($collection); }
php
public function createAdapter($collection) { if (\is_array($collection)) { $className = 'Array'; } else { try { $r = new \ReflectionClass($collection); $className = $r->getName(); } catch (\ReflectionException $exc) { throw new AdapterNotSupportedException($collection); } } $adapterName = __NAMESPACE__ . "\\" . $className . 'Adapter' ; return new $adapterName($collection); }
[ "public", "function", "createAdapter", "(", "$", "collection", ")", "{", "if", "(", "\\", "is_array", "(", "$", "collection", ")", ")", "{", "$", "className", "=", "'Array'", ";", "}", "else", "{", "try", "{", "$", "r", "=", "new", "\\", "ReflectionClass", "(", "$", "collection", ")", ";", "$", "className", "=", "$", "r", "->", "getName", "(", ")", ";", "}", "catch", "(", "\\", "ReflectionException", "$", "exc", ")", "{", "throw", "new", "AdapterNotSupportedException", "(", "$", "collection", ")", ";", "}", "}", "$", "adapterName", "=", "__NAMESPACE__", ".", "\"\\\\\"", ".", "$", "className", ".", "'Adapter'", ";", "return", "new", "$", "adapterName", "(", "$", "collection", ")", ";", "}" ]
This method recieve a data collection and returns the corresponding adapter. @param mixed $collection @return AdapterInterface @throws Ideup\SimplePaginatorBundle\Paginator\Exception\AdapterNotSupportedException
[ "This", "method", "recieve", "a", "data", "collection", "and", "returns", "the", "corresponding", "adapter", "." ]
train
https://github.com/javiacei/IdeupSimplePaginatorBundle/blob/12639a9c75bc403649fc2b2881e190a017d8c5b2/Paginator/Adapter/AdapterFactory.php#L24-L42
jenwachter/html-form
src/Elements/Select.php
Select.compile
public function compile($value = "") { $html = $this->compiledLabel; if (!empty($this->help)) { $html .= "<div class='help'>{$this->help}</div>"; } $hasOptionValue = $this->hasOptionValue($this->options); $html .= "<select name=\"{$this->name}\" {$this->compiledAttr}>"; // handle options in an associative array differently than ones in a numeric array if ($hasOptionValue || $this->useNumericValue) { foreach ($this->options as $k => $v) { $html .= "<option value=\"{$k}\""; if ($value === $k || (is_numeric($value) && (int) $value === $k)) { $html .= " selected=\"selected\""; } $html .= ">{$v}</option>"; } } else { foreach ($this->options as $k => $v) { $html .= "<option value=\"{$v}\""; if ( $value === $v) { $html .= " selected=\"selected\""; } $html .= ">{$v}</option>"; } } $html .= "</select>"; return $html; }
php
public function compile($value = "") { $html = $this->compiledLabel; if (!empty($this->help)) { $html .= "<div class='help'>{$this->help}</div>"; } $hasOptionValue = $this->hasOptionValue($this->options); $html .= "<select name=\"{$this->name}\" {$this->compiledAttr}>"; // handle options in an associative array differently than ones in a numeric array if ($hasOptionValue || $this->useNumericValue) { foreach ($this->options as $k => $v) { $html .= "<option value=\"{$k}\""; if ($value === $k || (is_numeric($value) && (int) $value === $k)) { $html .= " selected=\"selected\""; } $html .= ">{$v}</option>"; } } else { foreach ($this->options as $k => $v) { $html .= "<option value=\"{$v}\""; if ( $value === $v) { $html .= " selected=\"selected\""; } $html .= ">{$v}</option>"; } } $html .= "</select>"; return $html; }
[ "public", "function", "compile", "(", "$", "value", "=", "\"\"", ")", "{", "$", "html", "=", "$", "this", "->", "compiledLabel", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "help", ")", ")", "{", "$", "html", ".=", "\"<div class='help'>{$this->help}</div>\"", ";", "}", "$", "hasOptionValue", "=", "$", "this", "->", "hasOptionValue", "(", "$", "this", "->", "options", ")", ";", "$", "html", ".=", "\"<select name=\\\"{$this->name}\\\" {$this->compiledAttr}>\"", ";", "// handle options in an associative array differently than ones in a numeric array", "if", "(", "$", "hasOptionValue", "||", "$", "this", "->", "useNumericValue", ")", "{", "foreach", "(", "$", "this", "->", "options", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "html", ".=", "\"<option value=\\\"{$k}\\\"\"", ";", "if", "(", "$", "value", "===", "$", "k", "||", "(", "is_numeric", "(", "$", "value", ")", "&&", "(", "int", ")", "$", "value", "===", "$", "k", ")", ")", "{", "$", "html", ".=", "\" selected=\\\"selected\\\"\"", ";", "}", "$", "html", ".=", "\">{$v}</option>\"", ";", "}", "}", "else", "{", "foreach", "(", "$", "this", "->", "options", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "html", ".=", "\"<option value=\\\"{$v}\\\"\"", ";", "if", "(", "$", "value", "===", "$", "v", ")", "{", "$", "html", ".=", "\" selected=\\\"selected\\\"\"", ";", "}", "$", "html", ".=", "\">{$v}</option>\"", ";", "}", "}", "$", "html", ".=", "\"</select>\"", ";", "return", "$", "html", ";", "}" ]
Builds the HTML of the form field. @param string $value Value of the form field @return null
[ "Builds", "the", "HTML", "of", "the", "form", "field", "." ]
train
https://github.com/jenwachter/html-form/blob/eaece87d474f7da5c25679548fb8f1608a94303c/src/Elements/Select.php#L13-L50
zicht/z-plugin-git
git/Plugin.php
Plugin.appendConfiguration
public function appendConfiguration(ArrayNodeDefinition $rootNode) { $rootNode ->children() ->arrayNode('vcs') ->children() ->scalarNode('url')->end() ->arrayNode('export') ->children() ->scalarNode('revfile')->isRequired()->end() ->end() ->end() ->end() ->end() ->end() ; }
php
public function appendConfiguration(ArrayNodeDefinition $rootNode) { $rootNode ->children() ->arrayNode('vcs') ->children() ->scalarNode('url')->end() ->arrayNode('export') ->children() ->scalarNode('revfile')->isRequired()->end() ->end() ->end() ->end() ->end() ->end() ; }
[ "public", "function", "appendConfiguration", "(", "ArrayNodeDefinition", "$", "rootNode", ")", "{", "$", "rootNode", "->", "children", "(", ")", "->", "arrayNode", "(", "'vcs'", ")", "->", "children", "(", ")", "->", "scalarNode", "(", "'url'", ")", "->", "end", "(", ")", "->", "arrayNode", "(", "'export'", ")", "->", "children", "(", ")", "->", "scalarNode", "(", "'revfile'", ")", "->", "isRequired", "(", ")", "->", "end", "(", ")", "->", "end", "(", ")", "->", "end", "(", ")", "->", "end", "(", ")", "->", "end", "(", ")", "->", "end", "(", ")", ";", "}" ]
Appends Git configuration options @param \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $rootNode @return mixed|void
[ "Appends", "Git", "configuration", "options" ]
train
https://github.com/zicht/z-plugin-git/blob/0ed336b19a20225f96111e30db1ae59fabdea0e7/git/Plugin.php#L27-L43
phpmob/changmin
src/PhpMob/CmsBundle/Doctrine/ORM/PageRepository.php
PageRepository.findBySlug
public function findBySlug(string $slug, ?string $locale): ?SlugAwareInterface { $queryBuilder = $this->createQueryBuilder('o'); return $queryBuilder ->join('o.translations', 'translation', 'WITH', 'translation.locale = :locale') ->leftJoin('o.template', 'tpl') ->addSelect('translation') ->addSelect('tpl') ->where($queryBuilder->expr()->eq('translation.slug', ':slug')) ->andWhere($queryBuilder->expr()->eq('o.enabled', ':enabled')) ->setParameter(':slug', $slug) ->setParameter(':locale', $locale) ->setParameter(':enabled', true) ->getQuery()->getOneOrNullResult(); }
php
public function findBySlug(string $slug, ?string $locale): ?SlugAwareInterface { $queryBuilder = $this->createQueryBuilder('o'); return $queryBuilder ->join('o.translations', 'translation', 'WITH', 'translation.locale = :locale') ->leftJoin('o.template', 'tpl') ->addSelect('translation') ->addSelect('tpl') ->where($queryBuilder->expr()->eq('translation.slug', ':slug')) ->andWhere($queryBuilder->expr()->eq('o.enabled', ':enabled')) ->setParameter(':slug', $slug) ->setParameter(':locale', $locale) ->setParameter(':enabled', true) ->getQuery()->getOneOrNullResult(); }
[ "public", "function", "findBySlug", "(", "string", "$", "slug", ",", "?", "string", "$", "locale", ")", ":", "?", "SlugAwareInterface", "{", "$", "queryBuilder", "=", "$", "this", "->", "createQueryBuilder", "(", "'o'", ")", ";", "return", "$", "queryBuilder", "->", "join", "(", "'o.translations'", ",", "'translation'", ",", "'WITH'", ",", "'translation.locale = :locale'", ")", "->", "leftJoin", "(", "'o.template'", ",", "'tpl'", ")", "->", "addSelect", "(", "'translation'", ")", "->", "addSelect", "(", "'tpl'", ")", "->", "where", "(", "$", "queryBuilder", "->", "expr", "(", ")", "->", "eq", "(", "'translation.slug'", ",", "':slug'", ")", ")", "->", "andWhere", "(", "$", "queryBuilder", "->", "expr", "(", ")", "->", "eq", "(", "'o.enabled'", ",", "':enabled'", ")", ")", "->", "setParameter", "(", "':slug'", ",", "$", "slug", ")", "->", "setParameter", "(", "':locale'", ",", "$", "locale", ")", "->", "setParameter", "(", "':enabled'", ",", "true", ")", "->", "getQuery", "(", ")", "->", "getOneOrNullResult", "(", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/CmsBundle/Doctrine/ORM/PageRepository.php#L26-L41
afrittella/back-project
src/database/migrations/2017_03_10_213644_create_attachments_table.php
CreateAttachmentsTable.up
public function up() { Schema::create($this->table_attachments, function(Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('original_name'); $table->text('description')->nullable(); $table->boolean('is_main')->default(false)->index(); $table->integer('user_id')->nullable()->unsigned()->index(); $table->timestamps(); $table->foreign('user_id')->references('id')->on('users')->onDelete('SET NULL')->onUpdate('CASCADE'); }); Schema::create('attachables', function(Blueprint $table) { $table->integer('attachment_id')->unsigned(); $table->morphs('attachable'); }); }
php
public function up() { Schema::create($this->table_attachments, function(Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('original_name'); $table->text('description')->nullable(); $table->boolean('is_main')->default(false)->index(); $table->integer('user_id')->nullable()->unsigned()->index(); $table->timestamps(); $table->foreign('user_id')->references('id')->on('users')->onDelete('SET NULL')->onUpdate('CASCADE'); }); Schema::create('attachables', function(Blueprint $table) { $table->integer('attachment_id')->unsigned(); $table->morphs('attachable'); }); }
[ "public", "function", "up", "(", ")", "{", "Schema", "::", "create", "(", "$", "this", "->", "table_attachments", ",", "function", "(", "Blueprint", "$", "table", ")", "{", "$", "table", "->", "increments", "(", "'id'", ")", ";", "$", "table", "->", "string", "(", "'name'", ")", ";", "$", "table", "->", "string", "(", "'original_name'", ")", ";", "$", "table", "->", "text", "(", "'description'", ")", "->", "nullable", "(", ")", ";", "$", "table", "->", "boolean", "(", "'is_main'", ")", "->", "default", "(", "false", ")", "->", "index", "(", ")", ";", "$", "table", "->", "integer", "(", "'user_id'", ")", "->", "nullable", "(", ")", "->", "unsigned", "(", ")", "->", "index", "(", ")", ";", "$", "table", "->", "timestamps", "(", ")", ";", "$", "table", "->", "foreign", "(", "'user_id'", ")", "->", "references", "(", "'id'", ")", "->", "on", "(", "'users'", ")", "->", "onDelete", "(", "'SET NULL'", ")", "->", "onUpdate", "(", "'CASCADE'", ")", ";", "}", ")", ";", "Schema", "::", "create", "(", "'attachables'", ",", "function", "(", "Blueprint", "$", "table", ")", "{", "$", "table", "->", "integer", "(", "'attachment_id'", ")", "->", "unsigned", "(", ")", ";", "$", "table", "->", "morphs", "(", "'attachable'", ")", ";", "}", ")", ";", "}" ]
Run the migrations. @return void
[ "Run", "the", "migrations", "." ]
train
https://github.com/afrittella/back-project/blob/e1aa2e3ee03d453033f75a4b16f073c60b5f32d1/src/database/migrations/2017_03_10_213644_create_attachments_table.php#L21-L39
phossa2/config
src/Config/Traits/DelegatorWritableTrait.php
DelegatorWritableTrait.isWritable
public function isWritable()/*# : bool */ { foreach ($this->lookup_pool as $reg) { if ($reg instanceof WritableInterface && $reg->isWritable()) { $this->clearLookupCache(); $this->setWritable($reg); return true; } } return false; }
php
public function isWritable()/*# : bool */ { foreach ($this->lookup_pool as $reg) { if ($reg instanceof WritableInterface && $reg->isWritable()) { $this->clearLookupCache(); $this->setWritable($reg); return true; } } return false; }
[ "public", "function", "isWritable", "(", ")", "/*# : bool */", "{", "foreach", "(", "$", "this", "->", "lookup_pool", "as", "$", "reg", ")", "{", "if", "(", "$", "reg", "instanceof", "WritableInterface", "&&", "$", "reg", "->", "isWritable", "(", ")", ")", "{", "$", "this", "->", "clearLookupCache", "(", ")", ";", "$", "this", "->", "setWritable", "(", "$", "reg", ")", ";", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Override `isWritable()` in the WritableTrait. Delegator's writability is base on its registries {@inheritDoc}
[ "Override", "isWritable", "()", "in", "the", "WritableTrait", "." ]
train
https://github.com/phossa2/config/blob/7c046fd2c97633b69545b4745d8bffe28e19b1df/src/Config/Traits/DelegatorWritableTrait.php#L43-L53
phossa2/config
src/Config/Traits/DelegatorWritableTrait.php
DelegatorWritableTrait.setWritable
public function setWritable($writable)/*# : bool */ { if (!is_bool($writable)) { $this->writable = $writable; } elseif (false === $writable) { return $this->setRegistryWritableFalse(); } elseif (!$this->isWritable()) { return $this->setRegistryWritableTrue(); } return true; }
php
public function setWritable($writable)/*# : bool */ { if (!is_bool($writable)) { $this->writable = $writable; } elseif (false === $writable) { return $this->setRegistryWritableFalse(); } elseif (!$this->isWritable()) { return $this->setRegistryWritableTrue(); } return true; }
[ "public", "function", "setWritable", "(", "$", "writable", ")", "/*# : bool */", "{", "if", "(", "!", "is_bool", "(", "$", "writable", ")", ")", "{", "$", "this", "->", "writable", "=", "$", "writable", ";", "}", "elseif", "(", "false", "===", "$", "writable", ")", "{", "return", "$", "this", "->", "setRegistryWritableFalse", "(", ")", ";", "}", "elseif", "(", "!", "$", "this", "->", "isWritable", "(", ")", ")", "{", "return", "$", "this", "->", "setRegistryWritableTrue", "(", ")", ";", "}", "return", "true", ";", "}" ]
Override `setWritable()` in the WritableTrait {@inheritDoc}
[ "Override", "setWritable", "()", "in", "the", "WritableTrait" ]
train
https://github.com/phossa2/config/blob/7c046fd2c97633b69545b4745d8bffe28e19b1df/src/Config/Traits/DelegatorWritableTrait.php#L60-L71
phossa2/config
src/Config/Traits/DelegatorWritableTrait.php
DelegatorWritableTrait.setRegistryWritableFalse
protected function setRegistryWritableFalse()/*# : bool */ { foreach ($this->lookup_pool as $reg) { if ($reg instanceof WritableInterface && !$reg->setWritable(false)) { return false; } } return true; }
php
protected function setRegistryWritableFalse()/*# : bool */ { foreach ($this->lookup_pool as $reg) { if ($reg instanceof WritableInterface && !$reg->setWritable(false)) { return false; } } return true; }
[ "protected", "function", "setRegistryWritableFalse", "(", ")", "/*# : bool */", "{", "foreach", "(", "$", "this", "->", "lookup_pool", "as", "$", "reg", ")", "{", "if", "(", "$", "reg", "instanceof", "WritableInterface", "&&", "!", "$", "reg", "->", "setWritable", "(", "false", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Set writable to FALSE in all registries @return bool @access protected
[ "Set", "writable", "to", "FALSE", "in", "all", "registries" ]
train
https://github.com/phossa2/config/blob/7c046fd2c97633b69545b4745d8bffe28e19b1df/src/Config/Traits/DelegatorWritableTrait.php#L79-L88
PeekAndPoke/psi
src/Operation/Terminal/MedianOperation.php
MedianOperation.apply
public function apply(\Iterator $set) { /** @var mixed[] $data */ $data = array_values(iterator_to_array($set)); $count = count($data); if ($count === 0) { return 0; } sort($data); $middle = (($count + 1) / 2) - 1; $left = (int) floor($middle); $right = (int) ceil($middle); $leftVal = $data[$left]; $rightVal = $data[$right]; return is_scalar($leftVal) && is_scalar($rightVal) ? ($data[$left] + $data[$right]) / 2 : 0; }
php
public function apply(\Iterator $set) { /** @var mixed[] $data */ $data = array_values(iterator_to_array($set)); $count = count($data); if ($count === 0) { return 0; } sort($data); $middle = (($count + 1) / 2) - 1; $left = (int) floor($middle); $right = (int) ceil($middle); $leftVal = $data[$left]; $rightVal = $data[$right]; return is_scalar($leftVal) && is_scalar($rightVal) ? ($data[$left] + $data[$right]) / 2 : 0; }
[ "public", "function", "apply", "(", "\\", "Iterator", "$", "set", ")", "{", "/** @var mixed[] $data */", "$", "data", "=", "array_values", "(", "iterator_to_array", "(", "$", "set", ")", ")", ";", "$", "count", "=", "count", "(", "$", "data", ")", ";", "if", "(", "$", "count", "===", "0", ")", "{", "return", "0", ";", "}", "sort", "(", "$", "data", ")", ";", "$", "middle", "=", "(", "(", "$", "count", "+", "1", ")", "/", "2", ")", "-", "1", ";", "$", "left", "=", "(", "int", ")", "floor", "(", "$", "middle", ")", ";", "$", "right", "=", "(", "int", ")", "ceil", "(", "$", "middle", ")", ";", "$", "leftVal", "=", "$", "data", "[", "$", "left", "]", ";", "$", "rightVal", "=", "$", "data", "[", "$", "right", "]", ";", "return", "is_scalar", "(", "$", "leftVal", ")", "&&", "is_scalar", "(", "$", "rightVal", ")", "?", "(", "$", "data", "[", "$", "left", "]", "+", "$", "data", "[", "$", "right", "]", ")", "/", "2", ":", "0", ";", "}" ]
{@inheritdoc} @return float
[ "{", "@inheritdoc", "}" ]
train
https://github.com/PeekAndPoke/psi/blob/cfd45d995d3a2c2ea6ba5b1ce7b5fcc71179456f/src/Operation/Terminal/MedianOperation.php#L24-L44
steeffeen/FancyManiaLinks
FML/Script/Features/CheckBoxFeature.php
CheckBoxFeature.setQuad
public function setQuad(Quad $quad) { $quad->checkId(); $quad->setScriptEvents(true); $this->quad = $quad; return $this; }
php
public function setQuad(Quad $quad) { $quad->checkId(); $quad->setScriptEvents(true); $this->quad = $quad; return $this; }
[ "public", "function", "setQuad", "(", "Quad", "$", "quad", ")", "{", "$", "quad", "->", "checkId", "(", ")", ";", "$", "quad", "->", "setScriptEvents", "(", "true", ")", ";", "$", "this", "->", "quad", "=", "$", "quad", ";", "return", "$", "this", ";", "}" ]
Set the CheckBox Quad @api @param Quad $quad CheckBox Quad @return static
[ "Set", "the", "CheckBox", "Quad" ]
train
https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Script/Features/CheckBoxFeature.php#L97-L103
steeffeen/FancyManiaLinks
FML/Script/Features/CheckBoxFeature.php
CheckBoxFeature.buildInitScriptText
protected function buildInitScriptText() { $quadId = Builder::getId($this->getQuad()); $entryId = Builder::EMPTY_STRING; if ($this->entry) { $entryId = Builder::getId($this->getEntry()); } $default = Builder::getBoolean($this->default); $enabledDesignString = $this->enabledDesign->getDesignString(); $disabledDesignString = $this->disabledDesign->getDesignString(); return " declare Quad_CheckBox <=> (Page.GetFirstChild(\"{$quadId}\") as CMlQuad); declare Text[Boolean] " . self::VAR_CHECKBOX_DESIGNS . " as Designs for Quad_CheckBox; Designs[True] = \"{$enabledDesignString}\"; Designs[False] = \"{$disabledDesignString}\"; declare Boolean " . self::VAR_CHECKBOX_ENABLED . " as Enabled for Quad_CheckBox; Enabled = !{$default}; declare Text " . self::VAR_CHECKBOX_ENTRY_ID . " as EntryId for Quad_CheckBox; EntryId = \"{$entryId}\"; " . self::FUNCTION_UPDATE_QUAD_DESIGN . "(Quad_CheckBox); "; }
php
protected function buildInitScriptText() { $quadId = Builder::getId($this->getQuad()); $entryId = Builder::EMPTY_STRING; if ($this->entry) { $entryId = Builder::getId($this->getEntry()); } $default = Builder::getBoolean($this->default); $enabledDesignString = $this->enabledDesign->getDesignString(); $disabledDesignString = $this->disabledDesign->getDesignString(); return " declare Quad_CheckBox <=> (Page.GetFirstChild(\"{$quadId}\") as CMlQuad); declare Text[Boolean] " . self::VAR_CHECKBOX_DESIGNS . " as Designs for Quad_CheckBox; Designs[True] = \"{$enabledDesignString}\"; Designs[False] = \"{$disabledDesignString}\"; declare Boolean " . self::VAR_CHECKBOX_ENABLED . " as Enabled for Quad_CheckBox; Enabled = !{$default}; declare Text " . self::VAR_CHECKBOX_ENTRY_ID . " as EntryId for Quad_CheckBox; EntryId = \"{$entryId}\"; " . self::FUNCTION_UPDATE_QUAD_DESIGN . "(Quad_CheckBox); "; }
[ "protected", "function", "buildInitScriptText", "(", ")", "{", "$", "quadId", "=", "Builder", "::", "getId", "(", "$", "this", "->", "getQuad", "(", ")", ")", ";", "$", "entryId", "=", "Builder", "::", "EMPTY_STRING", ";", "if", "(", "$", "this", "->", "entry", ")", "{", "$", "entryId", "=", "Builder", "::", "getId", "(", "$", "this", "->", "getEntry", "(", ")", ")", ";", "}", "$", "default", "=", "Builder", "::", "getBoolean", "(", "$", "this", "->", "default", ")", ";", "$", "enabledDesignString", "=", "$", "this", "->", "enabledDesign", "->", "getDesignString", "(", ")", ";", "$", "disabledDesignString", "=", "$", "this", "->", "disabledDesign", "->", "getDesignString", "(", ")", ";", "return", "\"\ndeclare Quad_CheckBox <=> (Page.GetFirstChild(\\\"{$quadId}\\\") as CMlQuad);\ndeclare Text[Boolean] \"", ".", "self", "::", "VAR_CHECKBOX_DESIGNS", ".", "\" as Designs for Quad_CheckBox;\nDesigns[True] = \\\"{$enabledDesignString}\\\";\nDesigns[False] = \\\"{$disabledDesignString}\\\";\ndeclare Boolean \"", ".", "self", "::", "VAR_CHECKBOX_ENABLED", ".", "\" as Enabled for Quad_CheckBox;\nEnabled = !{$default};\ndeclare Text \"", ".", "self", "::", "VAR_CHECKBOX_ENTRY_ID", ".", "\" as EntryId for Quad_CheckBox;\nEntryId = \\\"{$entryId}\\\";\n\"", ".", "self", "::", "FUNCTION_UPDATE_QUAD_DESIGN", ".", "\"(Quad_CheckBox);\n\"", ";", "}" ]
Build the init script text @return string
[ "Build", "the", "init", "script", "text" ]
train
https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Script/Features/CheckBoxFeature.php#L256-L279
ClanCats/Core
src/classes/CCFile.php
CCFile.mkdir
public static function mkdir( $path ) { if ( !is_dir( dirname( $path ) ) ) { if ( !mkdir( dirname( $path ), 0755, true ) ) { throw new CCException( "CCFile - could not create directory: ".dirname( $path ) ); } } }
php
public static function mkdir( $path ) { if ( !is_dir( dirname( $path ) ) ) { if ( !mkdir( dirname( $path ), 0755, true ) ) { throw new CCException( "CCFile - could not create directory: ".dirname( $path ) ); } } }
[ "public", "static", "function", "mkdir", "(", "$", "path", ")", "{", "if", "(", "!", "is_dir", "(", "dirname", "(", "$", "path", ")", ")", ")", "{", "if", "(", "!", "mkdir", "(", "dirname", "(", "$", "path", ")", ",", "0755", ",", "true", ")", ")", "{", "throw", "new", "CCException", "(", "\"CCFile - could not create directory: \"", ".", "dirname", "(", "$", "path", ")", ")", ";", "}", "}", "}" ]
Create a directory @param string $path @return void
[ "Create", "a", "directory" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCFile.php#L72-L81
ClanCats/Core
src/classes/CCFile.php
CCFile.write
public static function write( $path, $content ) { static::mkdir( $path ); // if writing the file fails if ( file_put_contents( $path, $content, LOCK_EX ) === false ) { if ( static::_can_print() ) { CCCli::line( CCCli::color( 'failure', 'red' ).' creating '.$path ); } return false; } // everything went good if ( static::_can_print() ) { CCCli::line( CCCli::color( 'created', 'green' ).' '.$path ); } return true; }
php
public static function write( $path, $content ) { static::mkdir( $path ); // if writing the file fails if ( file_put_contents( $path, $content, LOCK_EX ) === false ) { if ( static::_can_print() ) { CCCli::line( CCCli::color( 'failure', 'red' ).' creating '.$path ); } return false; } // everything went good if ( static::_can_print() ) { CCCli::line( CCCli::color( 'created', 'green' ).' '.$path ); } return true; }
[ "public", "static", "function", "write", "(", "$", "path", ",", "$", "content", ")", "{", "static", "::", "mkdir", "(", "$", "path", ")", ";", "// if writing the file fails", "if", "(", "file_put_contents", "(", "$", "path", ",", "$", "content", ",", "LOCK_EX", ")", "===", "false", ")", "{", "if", "(", "static", "::", "_can_print", "(", ")", ")", "{", "CCCli", "::", "line", "(", "CCCli", "::", "color", "(", "'failure'", ",", "'red'", ")", ".", "' creating '", ".", "$", "path", ")", ";", "}", "return", "false", ";", "}", "// everything went good", "if", "(", "static", "::", "_can_print", "(", ")", ")", "{", "CCCli", "::", "line", "(", "CCCli", "::", "color", "(", "'created'", ",", "'green'", ")", ".", "' '", ".", "$", "path", ")", ";", "}", "return", "true", ";", "}" ]
save a file @param string $path @param string $content @return bool
[ "save", "a", "file" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCFile.php#L90-L113
ClanCats/Core
src/classes/CCFile.php
CCFile.append
public static function append( $path, $content ) { if ( !is_dir( dirname( $path ) ) ) { if ( !mkdir( dirname( $path ), 0755, true ) ) { throw new CCException( "CCFile - could not create directory: ".dirname( $path ) ); } } return file_put_contents( $path, $content, LOCK_EX | FILE_APPEND ); }
php
public static function append( $path, $content ) { if ( !is_dir( dirname( $path ) ) ) { if ( !mkdir( dirname( $path ), 0755, true ) ) { throw new CCException( "CCFile - could not create directory: ".dirname( $path ) ); } } return file_put_contents( $path, $content, LOCK_EX | FILE_APPEND ); }
[ "public", "static", "function", "append", "(", "$", "path", ",", "$", "content", ")", "{", "if", "(", "!", "is_dir", "(", "dirname", "(", "$", "path", ")", ")", ")", "{", "if", "(", "!", "mkdir", "(", "dirname", "(", "$", "path", ")", ",", "0755", ",", "true", ")", ")", "{", "throw", "new", "CCException", "(", "\"CCFile - could not create directory: \"", ".", "dirname", "(", "$", "path", ")", ")", ";", "}", "}", "return", "file_put_contents", "(", "$", "path", ",", "$", "content", ",", "LOCK_EX", "|", "FILE_APPEND", ")", ";", "}" ]
append to a file @param string $path @param string $content @return bool
[ "append", "to", "a", "file" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCFile.php#L122-L132
ClanCats/Core
src/classes/CCFile.php
CCFile.delete
public static function delete( $path ) { $success = false; if ( file_exists( $path ) ) { $success = unlink( $path ); } if ( static::_can_print() ) { if ( $success ) { CCCli::line( CCCli::color( 'removed', 'green' ).' '.$path ); } else { CCCli::line( CCCli::color( 'removing failure', 'red' ).' '.$path ); } } return $success; }
php
public static function delete( $path ) { $success = false; if ( file_exists( $path ) ) { $success = unlink( $path ); } if ( static::_can_print() ) { if ( $success ) { CCCli::line( CCCli::color( 'removed', 'green' ).' '.$path ); } else { CCCli::line( CCCli::color( 'removing failure', 'red' ).' '.$path ); } } return $success; }
[ "public", "static", "function", "delete", "(", "$", "path", ")", "{", "$", "success", "=", "false", ";", "if", "(", "file_exists", "(", "$", "path", ")", ")", "{", "$", "success", "=", "unlink", "(", "$", "path", ")", ";", "}", "if", "(", "static", "::", "_can_print", "(", ")", ")", "{", "if", "(", "$", "success", ")", "{", "CCCli", "::", "line", "(", "CCCli", "::", "color", "(", "'removed'", ",", "'green'", ")", ".", "' '", ".", "$", "path", ")", ";", "}", "else", "{", "CCCli", "::", "line", "(", "CCCli", "::", "color", "(", "'removing failure'", ",", "'red'", ")", ".", "' '", ".", "$", "path", ")", ";", "}", "}", "return", "$", "success", ";", "}" ]
Delete a file This function is going to remove a file from your filesystem @param string $path @return bool
[ "Delete", "a", "file", "This", "function", "is", "going", "to", "remove", "a", "file", "from", "your", "filesystem" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCFile.php#L141-L163
ClanCats/Core
src/classes/CCFile.php
CCFile.upload
public static function upload( $key, $path ) { if ( $file = static::upload_path( $key ) ) { return move_uploaded_file( $file, $path ); } return false; }
php
public static function upload( $key, $path ) { if ( $file = static::upload_path( $key ) ) { return move_uploaded_file( $file, $path ); } return false; }
[ "public", "static", "function", "upload", "(", "$", "key", ",", "$", "path", ")", "{", "if", "(", "$", "file", "=", "static", "::", "upload_path", "(", "$", "key", ")", ")", "{", "return", "move_uploaded_file", "(", "$", "file", ",", "$", "path", ")", ";", "}", "return", "false", ";", "}" ]
Move user uploads to another dir @param string $key @param string $path @return bool
[ "Move", "user", "uploads", "to", "another", "dir" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCFile.php#L194-L202
2amigos/yiifoundation
widgets/Magellan.php
Magellan.init
public function init() { $this->assets = array( 'js' => YII_DEBUG ? 'foundation/foundation.magellan.js' : 'foundation.min.js' ); $this->htmlOptions['data-magellan-expedition'] = Enum::NAV_FIXED; parent::init(); }
php
public function init() { $this->assets = array( 'js' => YII_DEBUG ? 'foundation/foundation.magellan.js' : 'foundation.min.js' ); $this->htmlOptions['data-magellan-expedition'] = Enum::NAV_FIXED; parent::init(); }
[ "public", "function", "init", "(", ")", "{", "$", "this", "->", "assets", "=", "array", "(", "'js'", "=>", "YII_DEBUG", "?", "'foundation/foundation.magellan.js'", ":", "'foundation.min.js'", ")", ";", "$", "this", "->", "htmlOptions", "[", "'data-magellan-expedition'", "]", "=", "Enum", "::", "NAV_FIXED", ";", "parent", "::", "init", "(", ")", ";", "}" ]
Widget's initialization widget
[ "Widget", "s", "initialization", "widget" ]
train
https://github.com/2amigos/yiifoundation/blob/49bed0d3ca1a9bac9299000e48a2661bdc8f9a29/widgets/Magellan.php#L40-L47
2amigos/yiifoundation
widgets/Magellan.php
Magellan.renderMagellan
public function renderMagellan() { $list = array(); foreach ($this->items as $item) { $listItem['url'] = '#' . $item['id']; $listItem['label'] = $item['label']; $listItem['itemOptions'] = array('data-magellan-arrival' => $item['id']); $list[] = $listItem; } return \CHtml::tag('div', $this->htmlOptions, Nav::sub($list)); }
php
public function renderMagellan() { $list = array(); foreach ($this->items as $item) { $listItem['url'] = '#' . $item['id']; $listItem['label'] = $item['label']; $listItem['itemOptions'] = array('data-magellan-arrival' => $item['id']); $list[] = $listItem; } return \CHtml::tag('div', $this->htmlOptions, Nav::sub($list)); }
[ "public", "function", "renderMagellan", "(", ")", "{", "$", "list", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "items", "as", "$", "item", ")", "{", "$", "listItem", "[", "'url'", "]", "=", "'#'", ".", "$", "item", "[", "'id'", "]", ";", "$", "listItem", "[", "'label'", "]", "=", "$", "item", "[", "'label'", "]", ";", "$", "listItem", "[", "'itemOptions'", "]", "=", "array", "(", "'data-magellan-arrival'", "=>", "$", "item", "[", "'id'", "]", ")", ";", "$", "list", "[", "]", "=", "$", "listItem", ";", "}", "return", "\\", "CHtml", "::", "tag", "(", "'div'", ",", "$", "this", "->", "htmlOptions", ",", "Nav", "::", "sub", "(", "$", "list", ")", ")", ";", "}" ]
Renders magellan @return string the resulting tag
[ "Renders", "magellan" ]
train
https://github.com/2amigos/yiifoundation/blob/49bed0d3ca1a9bac9299000e48a2661bdc8f9a29/widgets/Magellan.php#L61-L72
webforge-labs/psc-cms
lib/Psc/Code/Generate/AnnotationWriter.php
AnnotationWriter.writeAnnotation
public function writeAnnotation($annotation) { $walkedValues = array(); foreach ($this->extractValues($annotation) as $field=>$value) { $walkedValues[] = $this->walkField($field, $value, $this->inferType($value)); } return '@'.$this->getAnnotationName($annotation).( count($walkedValues) > 0 ? '('.implode(', ',$walkedValues).')' : NULL); }
php
public function writeAnnotation($annotation) { $walkedValues = array(); foreach ($this->extractValues($annotation) as $field=>$value) { $walkedValues[] = $this->walkField($field, $value, $this->inferType($value)); } return '@'.$this->getAnnotationName($annotation).( count($walkedValues) > 0 ? '('.implode(', ',$walkedValues).')' : NULL); }
[ "public", "function", "writeAnnotation", "(", "$", "annotation", ")", "{", "$", "walkedValues", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "extractValues", "(", "$", "annotation", ")", "as", "$", "field", "=>", "$", "value", ")", "{", "$", "walkedValues", "[", "]", "=", "$", "this", "->", "walkField", "(", "$", "field", ",", "$", "value", ",", "$", "this", "->", "inferType", "(", "$", "value", ")", ")", ";", "}", "return", "'@'", ".", "$", "this", "->", "getAnnotationName", "(", "$", "annotation", ")", ".", "(", "count", "(", "$", "walkedValues", ")", ">", "0", "?", "'('", ".", "implode", "(", "', '", ",", "$", "walkedValues", ")", ".", "')'", ":", "NULL", ")", ";", "}" ]
Annotation ::= "@" AnnotationName ["(" [Values] ")"] AnnotationName ::= QualifiedName | SimpleName QualifiedName ::= NameSpacePart "\" {NameSpacePart "\"}* SimpleName NameSpacePart ::= identifier | null | false | true SimpleName ::= identifier | null | false | true @param PscAnnotation|DoctrineAnnotation $annotation
[ "Annotation", "::", "=", "@", "AnnotationName", "[", "(", "[", "Values", "]", ")", "]" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Code/Generate/AnnotationWriter.php#L39-L46
ufocoder/yii2-SyncSocial
src/behaviors/SynchronizerBehavior.php
SynchronizerBehavior.syncActiveRecord
public function syncActiveRecord( $event ) { $synchronizer = $this->getSynchonizer(); $function = $this->canSyncActiveRecord; $flag = true; $model = $event->sender; if ( is_callable( $function ) && ( $function instanceof Closure ) ) { $flag = $function( $model ); } if ($flag) { foreach ( $this->syncServices as $serviceName ) { $synchronizer->syncActiveRecord( $serviceName, $model ); } } }
php
public function syncActiveRecord( $event ) { $synchronizer = $this->getSynchonizer(); $function = $this->canSyncActiveRecord; $flag = true; $model = $event->sender; if ( is_callable( $function ) && ( $function instanceof Closure ) ) { $flag = $function( $model ); } if ($flag) { foreach ( $this->syncServices as $serviceName ) { $synchronizer->syncActiveRecord( $serviceName, $model ); } } }
[ "public", "function", "syncActiveRecord", "(", "$", "event", ")", "{", "$", "synchronizer", "=", "$", "this", "->", "getSynchonizer", "(", ")", ";", "$", "function", "=", "$", "this", "->", "canSyncActiveRecord", ";", "$", "flag", "=", "true", ";", "$", "model", "=", "$", "event", "->", "sender", ";", "if", "(", "is_callable", "(", "$", "function", ")", "&&", "(", "$", "function", "instanceof", "Closure", ")", ")", "{", "$", "flag", "=", "$", "function", "(", "$", "model", ")", ";", "}", "if", "(", "$", "flag", ")", "{", "foreach", "(", "$", "this", "->", "syncServices", "as", "$", "serviceName", ")", "{", "$", "synchronizer", "->", "syncActiveRecord", "(", "$", "serviceName", ",", "$", "model", ")", ";", "}", "}", "}" ]
@param \yii\base\Event $event @throws Exception
[ "@param", "\\", "yii", "\\", "base", "\\", "Event", "$event" ]
train
https://github.com/ufocoder/yii2-SyncSocial/blob/2dbaaec2dad782c52fdd5b648a31ba7fe2a75e1b/src/behaviors/SynchronizerBehavior.php#L63-L80
ufocoder/yii2-SyncSocial
src/behaviors/SynchronizerBehavior.php
SynchronizerBehavior.afterDelete
public function afterDelete( $event ) { $synchronizer = $this->getSynchonizer(); foreach ( $this->syncServices as $serviceName ) { $synchronizer->deleteSyncModel( $serviceName, $event->sender, $this->syncDelete ); } }
php
public function afterDelete( $event ) { $synchronizer = $this->getSynchonizer(); foreach ( $this->syncServices as $serviceName ) { $synchronizer->deleteSyncModel( $serviceName, $event->sender, $this->syncDelete ); } }
[ "public", "function", "afterDelete", "(", "$", "event", ")", "{", "$", "synchronizer", "=", "$", "this", "->", "getSynchonizer", "(", ")", ";", "foreach", "(", "$", "this", "->", "syncServices", "as", "$", "serviceName", ")", "{", "$", "synchronizer", "->", "deleteSyncModel", "(", "$", "serviceName", ",", "$", "event", "->", "sender", ",", "$", "this", "->", "syncDelete", ")", ";", "}", "}" ]
@param \yii\base\Event $event @throws Exception
[ "@param", "\\", "yii", "\\", "base", "\\", "Event", "$event" ]
train
https://github.com/ufocoder/yii2-SyncSocial/blob/2dbaaec2dad782c52fdd5b648a31ba7fe2a75e1b/src/behaviors/SynchronizerBehavior.php#L87-L92
webforge-labs/psc-cms
lib/Psc/Doctrine/BaseEntity.php
BaseEntity.callSetter
public function callSetter($field, $value) { $f = 'set'.ucfirst($field); if (!method_exists($this, $f)) throw new \InvalidArgumentException($f.'() existiert nicht in '.\Psc\Code\Code::getClass($this)); return $this->$f($value); }
php
public function callSetter($field, $value) { $f = 'set'.ucfirst($field); if (!method_exists($this, $f)) throw new \InvalidArgumentException($f.'() existiert nicht in '.\Psc\Code\Code::getClass($this)); return $this->$f($value); }
[ "public", "function", "callSetter", "(", "$", "field", ",", "$", "value", ")", "{", "$", "f", "=", "'set'", ".", "ucfirst", "(", "$", "field", ")", ";", "if", "(", "!", "method_exists", "(", "$", "this", ",", "$", "f", ")", ")", "throw", "new", "\\", "InvalidArgumentException", "(", "$", "f", ".", "'() existiert nicht in '", ".", "\\", "Psc", "\\", "Code", "\\", "Code", "::", "getClass", "(", "$", "this", ")", ")", ";", "return", "$", "this", "->", "$", "f", "(", "$", "value", ")", ";", "}" ]
Ruft den Setter für das Feld $field auf dem Entity auf @param string $field der Name des Feldes in CamelCase @return die Rückgabe des Setters
[ "Ruft", "den", "Setter", "für", "das", "Feld", "$field", "auf", "dem", "Entity", "auf" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/BaseEntity.php#L19-L23
webforge-labs/psc-cms
lib/Psc/Doctrine/BaseEntity.php
BaseEntity.callGetter
public function callGetter($field) { $f = 'get'.ucfirst($field); if (!method_exists($this, $f)) throw new \InvalidArgumentException($f.'() existiert nicht in '.\Psc\Code\Code::getClass($this)); return $this->$f(); }
php
public function callGetter($field) { $f = 'get'.ucfirst($field); if (!method_exists($this, $f)) throw new \InvalidArgumentException($f.'() existiert nicht in '.\Psc\Code\Code::getClass($this)); return $this->$f(); }
[ "public", "function", "callGetter", "(", "$", "field", ")", "{", "$", "f", "=", "'get'", ".", "ucfirst", "(", "$", "field", ")", ";", "if", "(", "!", "method_exists", "(", "$", "this", ",", "$", "f", ")", ")", "throw", "new", "\\", "InvalidArgumentException", "(", "$", "f", ".", "'() existiert nicht in '", ".", "\\", "Psc", "\\", "Code", "\\", "Code", "::", "getClass", "(", "$", "this", ")", ")", ";", "return", "$", "this", "->", "$", "f", "(", ")", ";", "}" ]
Ruft den Getter für das Feld $field auf dem Entity auf @param string $field der Name des Feldes in CamelCase @return mixed
[ "Ruft", "den", "Getter", "für", "das", "Feld", "$field", "auf", "dem", "Entity", "auf" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/BaseEntity.php#L31-L35
zircote/AMQP
library/AMQP/Util/FrameBuilder.php
FrameBuilder.channelClose
public function channelClose($options) { $args = new Writer(); $args->writeShort($options['reply_code']) ->writeShortStr($options['reply_text']) ->writeShort($options['method_signature'][0]) ->writeShort($options['method_signature'][1]); return $args; }
php
public function channelClose($options) { $args = new Writer(); $args->writeShort($options['reply_code']) ->writeShortStr($options['reply_text']) ->writeShort($options['method_signature'][0]) ->writeShort($options['method_signature'][1]); return $args; }
[ "public", "function", "channelClose", "(", "$", "options", ")", "{", "$", "args", "=", "new", "Writer", "(", ")", ";", "$", "args", "->", "writeShort", "(", "$", "options", "[", "'reply_code'", "]", ")", "->", "writeShortStr", "(", "$", "options", "[", "'reply_text'", "]", ")", "->", "writeShort", "(", "$", "options", "[", "'method_signature'", "]", "[", "0", "]", ")", "->", "writeShort", "(", "$", "options", "[", "'method_signature'", "]", "[", "1", "]", ")", ";", "return", "$", "args", ";", "}" ]
@param int $replyCode @param string $replyText @param string $classId @param string $methodId @return \AMQP\Wire\Writer
[ "@param", "int", "$replyCode", "@param", "string", "$replyText", "@param", "string", "$classId", "@param", "string", "$methodId" ]
train
https://github.com/zircote/AMQP/blob/b96777b372f556797db4fd0ba02edb18d4bf4a1e/library/AMQP/Util/FrameBuilder.php#L23-L31
zircote/AMQP
library/AMQP/Util/FrameBuilder.php
FrameBuilder.accessRequest
public function accessRequest($realm, $options) { $args = new Writer(); $args->writeShortStr($realm) ->writeBit($options['exclusive']) ->writeBit($options['passive']) ->writeBit($options['active']) ->writeBit($options['write']) ->writeBit($options['read']); return $args; }
php
public function accessRequest($realm, $options) { $args = new Writer(); $args->writeShortStr($realm) ->writeBit($options['exclusive']) ->writeBit($options['passive']) ->writeBit($options['active']) ->writeBit($options['write']) ->writeBit($options['read']); return $args; }
[ "public", "function", "accessRequest", "(", "$", "realm", ",", "$", "options", ")", "{", "$", "args", "=", "new", "Writer", "(", ")", ";", "$", "args", "->", "writeShortStr", "(", "$", "realm", ")", "->", "writeBit", "(", "$", "options", "[", "'exclusive'", "]", ")", "->", "writeBit", "(", "$", "options", "[", "'passive'", "]", ")", "->", "writeBit", "(", "$", "options", "[", "'active'", "]", ")", "->", "writeBit", "(", "$", "options", "[", "'write'", "]", ")", "->", "writeBit", "(", "$", "options", "[", "'read'", "]", ")", ";", "return", "$", "args", ";", "}" ]
@param string $realm @param string $exclusive @param string $passive @param bool $active @param bool $write @param bool $read @return \AMQP\Wire\Writer
[ "@param", "string", "$realm", "@param", "string", "$exclusive", "@param", "string", "$passive", "@param", "bool", "$active", "@param", "bool", "$write", "@param", "bool", "$read" ]
train
https://github.com/zircote/AMQP/blob/b96777b372f556797db4fd0ba02edb18d4bf4a1e/library/AMQP/Util/FrameBuilder.php#L79-L89
zircote/AMQP
library/AMQP/Util/FrameBuilder.php
FrameBuilder.exchangeDeclare
public function exchangeDeclare($exchange, $type, $options = array()) { $args = new Writer(); $args->writeShort($options['ticket']) ->writeShortStr($exchange) ->writeShortStr($type) ->writeBit($options['passive']) ->writeBit($options['durable']) ->writeBit($options['auto_delete']) ->writeBit($options['internal']) ->writeBit($options['no_wait']) ->writeTable($options['arguments']); return $args; }
php
public function exchangeDeclare($exchange, $type, $options = array()) { $args = new Writer(); $args->writeShort($options['ticket']) ->writeShortStr($exchange) ->writeShortStr($type) ->writeBit($options['passive']) ->writeBit($options['durable']) ->writeBit($options['auto_delete']) ->writeBit($options['internal']) ->writeBit($options['no_wait']) ->writeTable($options['arguments']); return $args; }
[ "public", "function", "exchangeDeclare", "(", "$", "exchange", ",", "$", "type", ",", "$", "options", "=", "array", "(", ")", ")", "{", "$", "args", "=", "new", "Writer", "(", ")", ";", "$", "args", "->", "writeShort", "(", "$", "options", "[", "'ticket'", "]", ")", "->", "writeShortStr", "(", "$", "exchange", ")", "->", "writeShortStr", "(", "$", "type", ")", "->", "writeBit", "(", "$", "options", "[", "'passive'", "]", ")", "->", "writeBit", "(", "$", "options", "[", "'durable'", "]", ")", "->", "writeBit", "(", "$", "options", "[", "'auto_delete'", "]", ")", "->", "writeBit", "(", "$", "options", "[", "'internal'", "]", ")", "->", "writeBit", "(", "$", "options", "[", "'no_wait'", "]", ")", "->", "writeTable", "(", "$", "options", "[", "'arguments'", "]", ")", ";", "return", "$", "args", ";", "}" ]
@param string $exchange @param int $type @param bool $passive @param bool $durable @param bool $autoDelete @param bool $internal @param bool $nowait @param array $arguments @param string $ticket @return \AMQP\Wire\Writer
[ "@param", "string", "$exchange", "@param", "int", "$type", "@param", "bool", "$passive", "@param", "bool", "$durable", "@param", "bool", "$autoDelete", "@param", "bool", "$internal", "@param", "bool", "$nowait", "@param", "array", "$arguments", "@param", "string", "$ticket" ]
train
https://github.com/zircote/AMQP/blob/b96777b372f556797db4fd0ba02edb18d4bf4a1e/library/AMQP/Util/FrameBuilder.php#L104-L117
zircote/AMQP
library/AMQP/Util/FrameBuilder.php
FrameBuilder.exchangeDelete
public function exchangeDelete($exchange, $options) { $args = new Writer(); $args->writeShort($options['ticket']) ->writeShortStr($exchange) ->writeBit($options['if_unused']) ->writeBit($options['no_wait']); return $args; }
php
public function exchangeDelete($exchange, $options) { $args = new Writer(); $args->writeShort($options['ticket']) ->writeShortStr($exchange) ->writeBit($options['if_unused']) ->writeBit($options['no_wait']); return $args; }
[ "public", "function", "exchangeDelete", "(", "$", "exchange", ",", "$", "options", ")", "{", "$", "args", "=", "new", "Writer", "(", ")", ";", "$", "args", "->", "writeShort", "(", "$", "options", "[", "'ticket'", "]", ")", "->", "writeShortStr", "(", "$", "exchange", ")", "->", "writeBit", "(", "$", "options", "[", "'if_unused'", "]", ")", "->", "writeBit", "(", "$", "options", "[", "'no_wait'", "]", ")", ";", "return", "$", "args", ";", "}" ]
@param string $exchange @param bool $ifUnused @param bool $nowait @param string $ticket @return \AMQP\Wire\Writer
[ "@param", "string", "$exchange", "@param", "bool", "$ifUnused", "@param", "bool", "$nowait", "@param", "string", "$ticket" ]
train
https://github.com/zircote/AMQP/blob/b96777b372f556797db4fd0ba02edb18d4bf4a1e/library/AMQP/Util/FrameBuilder.php#L127-L135
zircote/AMQP
library/AMQP/Util/FrameBuilder.php
FrameBuilder.queueBind
public function queueBind($queue, $exchange, $options) { $args = new Writer(); $args->writeShort($options['ticket']) ->writeShortStr($queue) ->writeShortStr($exchange) ->writeShortStr($options['routing_key']) ->writeBit($options['no_wait']) ->writeTable($options['arguments']); return $args; }
php
public function queueBind($queue, $exchange, $options) { $args = new Writer(); $args->writeShort($options['ticket']) ->writeShortStr($queue) ->writeShortStr($exchange) ->writeShortStr($options['routing_key']) ->writeBit($options['no_wait']) ->writeTable($options['arguments']); return $args; }
[ "public", "function", "queueBind", "(", "$", "queue", ",", "$", "exchange", ",", "$", "options", ")", "{", "$", "args", "=", "new", "Writer", "(", ")", ";", "$", "args", "->", "writeShort", "(", "$", "options", "[", "'ticket'", "]", ")", "->", "writeShortStr", "(", "$", "queue", ")", "->", "writeShortStr", "(", "$", "exchange", ")", "->", "writeShortStr", "(", "$", "options", "[", "'routing_key'", "]", ")", "->", "writeBit", "(", "$", "options", "[", "'no_wait'", "]", ")", "->", "writeTable", "(", "$", "options", "[", "'arguments'", "]", ")", ";", "return", "$", "args", ";", "}" ]
@param string $queue @param string $exchange @param string $routing_key @param bool $nowait @param array $arguments @param string $ticket @return \AMQP\Wire\Writer
[ "@param", "string", "$queue", "@param", "string", "$exchange", "@param", "string", "$routing_key", "@param", "bool", "$nowait", "@param", "array", "$arguments", "@param", "string", "$ticket" ]
train
https://github.com/zircote/AMQP/blob/b96777b372f556797db4fd0ba02edb18d4bf4a1e/library/AMQP/Util/FrameBuilder.php#L147-L157
zircote/AMQP
library/AMQP/Util/FrameBuilder.php
FrameBuilder.queueDeclare
public function queueDeclare($options) { $args = new Writer(); $args->writeShort($options['ticket']) ->writeShortStr($options['queue']) ->writeBit($options['passive']) ->writeBit($options['durable']) ->writeBit($options['exclusive']) ->writeBit($options['auto_delete']) ->writeBit($options['no_wait']) ->writeTable($options['arguments']); return $args; }
php
public function queueDeclare($options) { $args = new Writer(); $args->writeShort($options['ticket']) ->writeShortStr($options['queue']) ->writeBit($options['passive']) ->writeBit($options['durable']) ->writeBit($options['exclusive']) ->writeBit($options['auto_delete']) ->writeBit($options['no_wait']) ->writeTable($options['arguments']); return $args; }
[ "public", "function", "queueDeclare", "(", "$", "options", ")", "{", "$", "args", "=", "new", "Writer", "(", ")", ";", "$", "args", "->", "writeShort", "(", "$", "options", "[", "'ticket'", "]", ")", "->", "writeShortStr", "(", "$", "options", "[", "'queue'", "]", ")", "->", "writeBit", "(", "$", "options", "[", "'passive'", "]", ")", "->", "writeBit", "(", "$", "options", "[", "'durable'", "]", ")", "->", "writeBit", "(", "$", "options", "[", "'exclusive'", "]", ")", "->", "writeBit", "(", "$", "options", "[", "'auto_delete'", "]", ")", "->", "writeBit", "(", "$", "options", "[", "'no_wait'", "]", ")", "->", "writeTable", "(", "$", "options", "[", "'arguments'", "]", ")", ";", "return", "$", "args", ";", "}" ]
@param string $queue @param bool $passive @param bool $durable @param bool $exclusive @param bool $autoDelete @param bool $nowait @param array $arguments @param string $ticket @return \AMQP\Wire\Writer
[ "@param", "string", "$queue", "@param", "bool", "$passive", "@param", "bool", "$durable", "@param", "bool", "$exclusive", "@param", "bool", "$autoDelete", "@param", "bool", "$nowait", "@param", "array", "$arguments", "@param", "string", "$ticket" ]
train
https://github.com/zircote/AMQP/blob/b96777b372f556797db4fd0ba02edb18d4bf4a1e/library/AMQP/Util/FrameBuilder.php#L182-L194
zircote/AMQP
library/AMQP/Util/FrameBuilder.php
FrameBuilder.queueDelete
public function queueDelete($options) { $args = new Writer(); $args->writeShort($options['ticket']) ->writeShortStr($options['queue']) ->writeBit($options['if_unused']) ->writeBit($options['if_empty']) ->writeBit($options['no_wait']); return $args; }
php
public function queueDelete($options) { $args = new Writer(); $args->writeShort($options['ticket']) ->writeShortStr($options['queue']) ->writeBit($options['if_unused']) ->writeBit($options['if_empty']) ->writeBit($options['no_wait']); return $args; }
[ "public", "function", "queueDelete", "(", "$", "options", ")", "{", "$", "args", "=", "new", "Writer", "(", ")", ";", "$", "args", "->", "writeShort", "(", "$", "options", "[", "'ticket'", "]", ")", "->", "writeShortStr", "(", "$", "options", "[", "'queue'", "]", ")", "->", "writeBit", "(", "$", "options", "[", "'if_unused'", "]", ")", "->", "writeBit", "(", "$", "options", "[", "'if_empty'", "]", ")", "->", "writeBit", "(", "$", "options", "[", "'no_wait'", "]", ")", ";", "return", "$", "args", ";", "}" ]
@param string $queue @param bool $ifUnused @param bool $ifEmpty @param bool $nowait @param string $ticket @return \AMQP\Wire\Writer
[ "@param", "string", "$queue", "@param", "bool", "$ifUnused", "@param", "bool", "$ifEmpty", "@param", "bool", "$nowait", "@param", "string", "$ticket" ]
train
https://github.com/zircote/AMQP/blob/b96777b372f556797db4fd0ba02edb18d4bf4a1e/library/AMQP/Util/FrameBuilder.php#L205-L214
zircote/AMQP
library/AMQP/Util/FrameBuilder.php
FrameBuilder.queuePurge
public function queuePurge($options) { $args = new Writer(); $args->writeShort($options['ticket']) ->writeShortStr($options['queue']) ->writeBit($options['no_wait']); return $args; }
php
public function queuePurge($options) { $args = new Writer(); $args->writeShort($options['ticket']) ->writeShortStr($options['queue']) ->writeBit($options['no_wait']); return $args; }
[ "public", "function", "queuePurge", "(", "$", "options", ")", "{", "$", "args", "=", "new", "Writer", "(", ")", ";", "$", "args", "->", "writeShort", "(", "$", "options", "[", "'ticket'", "]", ")", "->", "writeShortStr", "(", "$", "options", "[", "'queue'", "]", ")", "->", "writeBit", "(", "$", "options", "[", "'no_wait'", "]", ")", ";", "return", "$", "args", ";", "}" ]
@param string $queue @param bool $nowait @param string $ticket @return \AMQP\Wire\Writer
[ "@param", "string", "$queue", "@param", "bool", "$nowait", "@param", "string", "$ticket" ]
train
https://github.com/zircote/AMQP/blob/b96777b372f556797db4fd0ba02edb18d4bf4a1e/library/AMQP/Util/FrameBuilder.php#L223-L230
zircote/AMQP
library/AMQP/Util/FrameBuilder.php
FrameBuilder.basicAck
public function basicAck($deliveryTag, $multiple) { $args = new Writer(); $args->writeLongLong($deliveryTag) ->writeBit($multiple); return $args; }
php
public function basicAck($deliveryTag, $multiple) { $args = new Writer(); $args->writeLongLong($deliveryTag) ->writeBit($multiple); return $args; }
[ "public", "function", "basicAck", "(", "$", "deliveryTag", ",", "$", "multiple", ")", "{", "$", "args", "=", "new", "Writer", "(", ")", ";", "$", "args", "->", "writeLongLong", "(", "$", "deliveryTag", ")", "->", "writeBit", "(", "$", "multiple", ")", ";", "return", "$", "args", ";", "}" ]
@param string $deliveryTag @param bool $multiple @return \AMQP\Wire\Writer
[ "@param", "string", "$deliveryTag", "@param", "bool", "$multiple" ]
train
https://github.com/zircote/AMQP/blob/b96777b372f556797db4fd0ba02edb18d4bf4a1e/library/AMQP/Util/FrameBuilder.php#L238-L244
zircote/AMQP
library/AMQP/Util/FrameBuilder.php
FrameBuilder.basicCancel
public function basicCancel($consumerTag, $nowait) { $args = new Writer(); $args->writeShortStr($consumerTag) ->writeBit($nowait); return $args; }
php
public function basicCancel($consumerTag, $nowait) { $args = new Writer(); $args->writeShortStr($consumerTag) ->writeBit($nowait); return $args; }
[ "public", "function", "basicCancel", "(", "$", "consumerTag", ",", "$", "nowait", ")", "{", "$", "args", "=", "new", "Writer", "(", ")", ";", "$", "args", "->", "writeShortStr", "(", "$", "consumerTag", ")", "->", "writeBit", "(", "$", "nowait", ")", ";", "return", "$", "args", ";", "}" ]
@param $consumerTag @param $nowait @return \AMQP\Wire\Writer
[ "@param", "$consumerTag", "@param", "$nowait" ]
train
https://github.com/zircote/AMQP/blob/b96777b372f556797db4fd0ba02edb18d4bf4a1e/library/AMQP/Util/FrameBuilder.php#L252-L258
zircote/AMQP
library/AMQP/Util/FrameBuilder.php
FrameBuilder.basicConsume
public function basicConsume($options) { $args = new Writer(); $args->writeShort($options['ticket']) ->writeShortStr($options['queue']) ->writeShortStr($options['consumer_tag']) ->writeBit($options['no_local']) ->writeBit($options['no_ack']) ->writeBit($options['exclusive']) ->writeBit($options['no_wait']); return $args; }
php
public function basicConsume($options) { $args = new Writer(); $args->writeShort($options['ticket']) ->writeShortStr($options['queue']) ->writeShortStr($options['consumer_tag']) ->writeBit($options['no_local']) ->writeBit($options['no_ack']) ->writeBit($options['exclusive']) ->writeBit($options['no_wait']); return $args; }
[ "public", "function", "basicConsume", "(", "$", "options", ")", "{", "$", "args", "=", "new", "Writer", "(", ")", ";", "$", "args", "->", "writeShort", "(", "$", "options", "[", "'ticket'", "]", ")", "->", "writeShortStr", "(", "$", "options", "[", "'queue'", "]", ")", "->", "writeShortStr", "(", "$", "options", "[", "'consumer_tag'", "]", ")", "->", "writeBit", "(", "$", "options", "[", "'no_local'", "]", ")", "->", "writeBit", "(", "$", "options", "[", "'no_ack'", "]", ")", "->", "writeBit", "(", "$", "options", "[", "'exclusive'", "]", ")", "->", "writeBit", "(", "$", "options", "[", "'no_wait'", "]", ")", ";", "return", "$", "args", ";", "}" ]
@param string $queue @param string $consumerTag @param bool $noLocal @param bool $noAck @param bool $exclusive @param bool $nowait @param string $ticket @return \AMQP\Wire\Writer
[ "@param", "string", "$queue", "@param", "string", "$consumerTag", "@param", "bool", "$noLocal", "@param", "bool", "$noAck", "@param", "bool", "$exclusive", "@param", "bool", "$nowait", "@param", "string", "$ticket" ]
train
https://github.com/zircote/AMQP/blob/b96777b372f556797db4fd0ba02edb18d4bf4a1e/library/AMQP/Util/FrameBuilder.php#L271-L282
zircote/AMQP
library/AMQP/Util/FrameBuilder.php
FrameBuilder.basicGet
public function basicGet($options) { $args = new Writer(); $args->writeShort($options['ticket']) ->writeShortStr($options['queue']) ->writeBit($options['no_ack']); return $args; }
php
public function basicGet($options) { $args = new Writer(); $args->writeShort($options['ticket']) ->writeShortStr($options['queue']) ->writeBit($options['no_ack']); return $args; }
[ "public", "function", "basicGet", "(", "$", "options", ")", "{", "$", "args", "=", "new", "Writer", "(", ")", ";", "$", "args", "->", "writeShort", "(", "$", "options", "[", "'ticket'", "]", ")", "->", "writeShortStr", "(", "$", "options", "[", "'queue'", "]", ")", "->", "writeBit", "(", "$", "options", "[", "'no_ack'", "]", ")", ";", "return", "$", "args", ";", "}" ]
@param string $queue @param bool $noAck @param string $ticket @return \AMQP\Wire\Writer
[ "@param", "string", "$queue", "@param", "bool", "$noAck", "@param", "string", "$ticket" ]
train
https://github.com/zircote/AMQP/blob/b96777b372f556797db4fd0ba02edb18d4bf4a1e/library/AMQP/Util/FrameBuilder.php#L291-L298
zircote/AMQP
library/AMQP/Util/FrameBuilder.php
FrameBuilder.basicPublish
public function basicPublish($options) { $args = new Writer(); $args->writeShort($options['ticket']) ->writeShortStr($options['exchange']) ->writeShortStr($options['routing_key']) ->writeBit($options['mandatory']) ->writeBit($options['immediate']); return $args; }
php
public function basicPublish($options) { $args = new Writer(); $args->writeShort($options['ticket']) ->writeShortStr($options['exchange']) ->writeShortStr($options['routing_key']) ->writeBit($options['mandatory']) ->writeBit($options['immediate']); return $args; }
[ "public", "function", "basicPublish", "(", "$", "options", ")", "{", "$", "args", "=", "new", "Writer", "(", ")", ";", "$", "args", "->", "writeShort", "(", "$", "options", "[", "'ticket'", "]", ")", "->", "writeShortStr", "(", "$", "options", "[", "'exchange'", "]", ")", "->", "writeShortStr", "(", "$", "options", "[", "'routing_key'", "]", ")", "->", "writeBit", "(", "$", "options", "[", "'mandatory'", "]", ")", "->", "writeBit", "(", "$", "options", "[", "'immediate'", "]", ")", ";", "return", "$", "args", ";", "}" ]
@param string $exchange @param string $routingKey @param bool $mandatory @param bool $immediate @param string $ticket @return \AMQP\Wire\Writer
[ "@param", "string", "$exchange", "@param", "string", "$routingKey", "@param", "bool", "$mandatory", "@param", "bool", "$immediate", "@param", "string", "$ticket" ]
train
https://github.com/zircote/AMQP/blob/b96777b372f556797db4fd0ba02edb18d4bf4a1e/library/AMQP/Util/FrameBuilder.php#L309-L318
zircote/AMQP
library/AMQP/Util/FrameBuilder.php
FrameBuilder.basicQos
public function basicQos($prefetchSize, $prefetchCount, $aGlobal) { $args = new Writer(); $args->writeLong($prefetchSize) ->writeShort($prefetchCount) ->writeBit($aGlobal); return $args; }
php
public function basicQos($prefetchSize, $prefetchCount, $aGlobal) { $args = new Writer(); $args->writeLong($prefetchSize) ->writeShort($prefetchCount) ->writeBit($aGlobal); return $args; }
[ "public", "function", "basicQos", "(", "$", "prefetchSize", ",", "$", "prefetchCount", ",", "$", "aGlobal", ")", "{", "$", "args", "=", "new", "Writer", "(", ")", ";", "$", "args", "->", "writeLong", "(", "$", "prefetchSize", ")", "->", "writeShort", "(", "$", "prefetchCount", ")", "->", "writeBit", "(", "$", "aGlobal", ")", ";", "return", "$", "args", ";", "}" ]
@param int $prefetchSize @param int $prefetchCount @param bool $aGlobal @return \AMQP\Wire\Writer
[ "@param", "int", "$prefetchSize", "@param", "int", "$prefetchCount", "@param", "bool", "$aGlobal" ]
train
https://github.com/zircote/AMQP/blob/b96777b372f556797db4fd0ba02edb18d4bf4a1e/library/AMQP/Util/FrameBuilder.php#L327-L334
zircote/AMQP
library/AMQP/Util/FrameBuilder.php
FrameBuilder.basicReject
public function basicReject($deliveryTag, $reQueue) { $args = new Writer(); $args->writeLongLong($deliveryTag) ->writeBit($reQueue); return $args; }
php
public function basicReject($deliveryTag, $reQueue) { $args = new Writer(); $args->writeLongLong($deliveryTag) ->writeBit($reQueue); return $args; }
[ "public", "function", "basicReject", "(", "$", "deliveryTag", ",", "$", "reQueue", ")", "{", "$", "args", "=", "new", "Writer", "(", ")", ";", "$", "args", "->", "writeLongLong", "(", "$", "deliveryTag", ")", "->", "writeBit", "(", "$", "reQueue", ")", ";", "return", "$", "args", ";", "}" ]
@param string $deliveryTag @param bool $reQueue @return \AMQP\Wire\Writer
[ "@param", "string", "$deliveryTag", "@param", "bool", "$reQueue" ]
train
https://github.com/zircote/AMQP/blob/b96777b372f556797db4fd0ba02edb18d4bf4a1e/library/AMQP/Util/FrameBuilder.php#L354-L360
scrutinizer-ci/rabbitmq
src/Scrutinizer/RabbitMQ/Rpc/GroupsVersionExclusionStrategy.php
GroupsVersionExclusionStrategy.shouldSkipProperty
public function shouldSkipProperty(PropertyMetadata $property, NavigatorContext $navigatorContext) { return $this->versionStrategy->shouldSkipProperty($property, $navigatorContext) || $this->groupStrategy->shouldSkipProperty($property, $navigatorContext); }
php
public function shouldSkipProperty(PropertyMetadata $property, NavigatorContext $navigatorContext) { return $this->versionStrategy->shouldSkipProperty($property, $navigatorContext) || $this->groupStrategy->shouldSkipProperty($property, $navigatorContext); }
[ "public", "function", "shouldSkipProperty", "(", "PropertyMetadata", "$", "property", ",", "NavigatorContext", "$", "navigatorContext", ")", "{", "return", "$", "this", "->", "versionStrategy", "->", "shouldSkipProperty", "(", "$", "property", ",", "$", "navigatorContext", ")", "||", "$", "this", "->", "groupStrategy", "->", "shouldSkipProperty", "(", "$", "property", ",", "$", "navigatorContext", ")", ";", "}" ]
Whether the property should be skipped. @param PropertyMetadata $property @param NavigatorContext $navigatorContext @return boolean
[ "Whether", "the", "property", "should", "be", "skipped", "." ]
train
https://github.com/scrutinizer-ci/rabbitmq/blob/5603f7901de2ad352086287f8d2c65bbae5170d5/src/Scrutinizer/RabbitMQ/Rpc/GroupsVersionExclusionStrategy.php#L40-L44
claroline/ForumBundle
Listener/ForumWidgetListener.php
ForumWidgetListener.onDisplay
public function onDisplay(DisplayWidgetEvent $event) { if (!$this->request) { throw new NoHttpRequestException(); } $workspace = $event->getInstance()->getWorkspace(); $templatePath = 'ClarolineForumBundle:Forum:forumsWorkspaceWidget.html.twig'; $widgetType = 'workspace'; if ($workspace == null) { $templatePath = 'ClarolineForumBundle:Forum:forumsDesktopWidget.html.twig'; $widgetType = 'desktop'; } $event->setContent($this->templatingEngine->render( $templatePath, array( 'widgetType' => $widgetType, 'messages' => $this->forumWidgetManager->getLastMessages($event->getInstance(), $workspace) ) )); $event->stopPropagation(); }
php
public function onDisplay(DisplayWidgetEvent $event) { if (!$this->request) { throw new NoHttpRequestException(); } $workspace = $event->getInstance()->getWorkspace(); $templatePath = 'ClarolineForumBundle:Forum:forumsWorkspaceWidget.html.twig'; $widgetType = 'workspace'; if ($workspace == null) { $templatePath = 'ClarolineForumBundle:Forum:forumsDesktopWidget.html.twig'; $widgetType = 'desktop'; } $event->setContent($this->templatingEngine->render( $templatePath, array( 'widgetType' => $widgetType, 'messages' => $this->forumWidgetManager->getLastMessages($event->getInstance(), $workspace) ) )); $event->stopPropagation(); }
[ "public", "function", "onDisplay", "(", "DisplayWidgetEvent", "$", "event", ")", "{", "if", "(", "!", "$", "this", "->", "request", ")", "{", "throw", "new", "NoHttpRequestException", "(", ")", ";", "}", "$", "workspace", "=", "$", "event", "->", "getInstance", "(", ")", "->", "getWorkspace", "(", ")", ";", "$", "templatePath", "=", "'ClarolineForumBundle:Forum:forumsWorkspaceWidget.html.twig'", ";", "$", "widgetType", "=", "'workspace'", ";", "if", "(", "$", "workspace", "==", "null", ")", "{", "$", "templatePath", "=", "'ClarolineForumBundle:Forum:forumsDesktopWidget.html.twig'", ";", "$", "widgetType", "=", "'desktop'", ";", "}", "$", "event", "->", "setContent", "(", "$", "this", "->", "templatingEngine", "->", "render", "(", "$", "templatePath", ",", "array", "(", "'widgetType'", "=>", "$", "widgetType", ",", "'messages'", "=>", "$", "this", "->", "forumWidgetManager", "->", "getLastMessages", "(", "$", "event", "->", "getInstance", "(", ")", ",", "$", "workspace", ")", ")", ")", ")", ";", "$", "event", "->", "stopPropagation", "(", ")", ";", "}" ]
@DI\Observe("widget_claroline_forum_widget") @param DisplayWidgetEvent $event @throws \Claroline\CoreBundle\Listener\NoHttpRequestException
[ "@DI", "\\", "Observe", "(", "widget_claroline_forum_widget", ")" ]
train
https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Listener/ForumWidgetListener.php#L81-L104
qcubed/orm
src/Database/Service.php
Service.initializeDatabaseConnections
public static function initializeDatabaseConnections() { // for backward compatibility, don't use MAX_DB_CONNECTION_INDEX directly, // but check if MAX_DB_CONNECTION_INDEX is defined $intMaxIndex = defined('MAX_DB_CONNECTION_INDEX') ? constant('MAX_DB_CONNECTION_INDEX') : 9; if (defined('DB_CONNECTION_0')) { // This causes a conflict with how DbBackedSessionHandler works. throw new \Exception('Do not define DB_CONNECTION_0. Start at DB_CONNECTION_1'); } for ($intIndex = 1; $intIndex <= $intMaxIndex; $intIndex++) { $strConstantName = sprintf('DB_CONNECTION_%s', $intIndex); if (defined($strConstantName)) { // Expected Keys to be Set $strExpectedKeys = array( 'adapter', 'server', 'port', 'database', 'username', 'password', 'profiling', 'dateformat' ); // Lookup the Serialized Array from the DB_CONFIG constants and unserialize it $strSerialArray = constant($strConstantName); $objConfigArray = unserialize($strSerialArray); // Set All Expected Keys foreach ($strExpectedKeys as $strExpectedKey) { if (!array_key_exists($strExpectedKey, $objConfigArray)) { $objConfigArray[$strExpectedKey] = null; } } if (!$objConfigArray['adapter']) { throw new \Exception('No Adapter Defined for ' . $strConstantName . ': ' . var_export($objConfigArray, true)); } if (!$objConfigArray['server']) { throw new \Exception('No Server Defined for ' . $strConstantName . ': ' . constant($strConstantName)); } $strDatabaseType = 'QCubed\\Database\\' . $objConfigArray['adapter'] . '\\Database'; //if (!class_exists($strDatabaseType)) { // throw new \Exception('Database adapter was not found: ' . $objConfigArray['adapter']); //} self::$Database[$intIndex] = new $strDatabaseType($intIndex, $objConfigArray); } } }
php
public static function initializeDatabaseConnections() { // for backward compatibility, don't use MAX_DB_CONNECTION_INDEX directly, // but check if MAX_DB_CONNECTION_INDEX is defined $intMaxIndex = defined('MAX_DB_CONNECTION_INDEX') ? constant('MAX_DB_CONNECTION_INDEX') : 9; if (defined('DB_CONNECTION_0')) { // This causes a conflict with how DbBackedSessionHandler works. throw new \Exception('Do not define DB_CONNECTION_0. Start at DB_CONNECTION_1'); } for ($intIndex = 1; $intIndex <= $intMaxIndex; $intIndex++) { $strConstantName = sprintf('DB_CONNECTION_%s', $intIndex); if (defined($strConstantName)) { // Expected Keys to be Set $strExpectedKeys = array( 'adapter', 'server', 'port', 'database', 'username', 'password', 'profiling', 'dateformat' ); // Lookup the Serialized Array from the DB_CONFIG constants and unserialize it $strSerialArray = constant($strConstantName); $objConfigArray = unserialize($strSerialArray); // Set All Expected Keys foreach ($strExpectedKeys as $strExpectedKey) { if (!array_key_exists($strExpectedKey, $objConfigArray)) { $objConfigArray[$strExpectedKey] = null; } } if (!$objConfigArray['adapter']) { throw new \Exception('No Adapter Defined for ' . $strConstantName . ': ' . var_export($objConfigArray, true)); } if (!$objConfigArray['server']) { throw new \Exception('No Server Defined for ' . $strConstantName . ': ' . constant($strConstantName)); } $strDatabaseType = 'QCubed\\Database\\' . $objConfigArray['adapter'] . '\\Database'; //if (!class_exists($strDatabaseType)) { // throw new \Exception('Database adapter was not found: ' . $objConfigArray['adapter']); //} self::$Database[$intIndex] = new $strDatabaseType($intIndex, $objConfigArray); } } }
[ "public", "static", "function", "initializeDatabaseConnections", "(", ")", "{", "// for backward compatibility, don't use MAX_DB_CONNECTION_INDEX directly,", "// but check if MAX_DB_CONNECTION_INDEX is defined", "$", "intMaxIndex", "=", "defined", "(", "'MAX_DB_CONNECTION_INDEX'", ")", "?", "constant", "(", "'MAX_DB_CONNECTION_INDEX'", ")", ":", "9", ";", "if", "(", "defined", "(", "'DB_CONNECTION_0'", ")", ")", "{", "// This causes a conflict with how DbBackedSessionHandler works.", "throw", "new", "\\", "Exception", "(", "'Do not define DB_CONNECTION_0. Start at DB_CONNECTION_1'", ")", ";", "}", "for", "(", "$", "intIndex", "=", "1", ";", "$", "intIndex", "<=", "$", "intMaxIndex", ";", "$", "intIndex", "++", ")", "{", "$", "strConstantName", "=", "sprintf", "(", "'DB_CONNECTION_%s'", ",", "$", "intIndex", ")", ";", "if", "(", "defined", "(", "$", "strConstantName", ")", ")", "{", "// Expected Keys to be Set", "$", "strExpectedKeys", "=", "array", "(", "'adapter'", ",", "'server'", ",", "'port'", ",", "'database'", ",", "'username'", ",", "'password'", ",", "'profiling'", ",", "'dateformat'", ")", ";", "// Lookup the Serialized Array from the DB_CONFIG constants and unserialize it", "$", "strSerialArray", "=", "constant", "(", "$", "strConstantName", ")", ";", "$", "objConfigArray", "=", "unserialize", "(", "$", "strSerialArray", ")", ";", "// Set All Expected Keys", "foreach", "(", "$", "strExpectedKeys", "as", "$", "strExpectedKey", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "strExpectedKey", ",", "$", "objConfigArray", ")", ")", "{", "$", "objConfigArray", "[", "$", "strExpectedKey", "]", "=", "null", ";", "}", "}", "if", "(", "!", "$", "objConfigArray", "[", "'adapter'", "]", ")", "{", "throw", "new", "\\", "Exception", "(", "'No Adapter Defined for '", ".", "$", "strConstantName", ".", "': '", ".", "var_export", "(", "$", "objConfigArray", ",", "true", ")", ")", ";", "}", "if", "(", "!", "$", "objConfigArray", "[", "'server'", "]", ")", "{", "throw", "new", "\\", "Exception", "(", "'No Server Defined for '", ".", "$", "strConstantName", ".", "': '", ".", "constant", "(", "$", "strConstantName", ")", ")", ";", "}", "$", "strDatabaseType", "=", "'QCubed\\\\Database\\\\'", ".", "$", "objConfigArray", "[", "'adapter'", "]", ".", "'\\\\Database'", ";", "//if (!class_exists($strDatabaseType)) {", "//\tthrow new \\Exception('Database adapter was not found: ' . $objConfigArray['adapter']);", "//}", "self", "::", "$", "Database", "[", "$", "intIndex", "]", "=", "new", "$", "strDatabaseType", "(", "$", "intIndex", ",", "$", "objConfigArray", ")", ";", "}", "}", "}" ]
This call will initialize the database connection(s) as defined by the constants DB_CONNECTION_X, where "X" is the index number of a particular database connection. @throws \Exception @return void
[ "This", "call", "will", "initialize", "the", "database", "connection", "(", "s", ")", "as", "defined", "by", "the", "constants", "DB_CONNECTION_X", "where", "X", "is", "the", "index", "number", "of", "a", "particular", "database", "connection", "." ]
train
https://github.com/qcubed/orm/blob/f320eba671f20874b1f3809c5293f8c02d5b1204/src/Database/Service.php#L43-L99
ClanCats/Core
src/classes/CCError.php
CCError._init
public static function _init() { // we capture non fatal errors only in dev environments if ( ClanCats::in_development() ) { // add a hook to the main resposne CCEvent::mind( 'response.output', function( $output ) { if ( strpos( $output, '</body>' ) === false ) { return $output; } $table = \UI\Table::create( array( 'style' => array( 'width' => '100%', ), 'cellpadding' => '5', 'class' => 'table debug-table debug-table-errors', )); $table->header( array( '#', 'message', 'file' ) ); foreach( \CCError::$non_fatals as $key => $item ) { $table->row( array( $key+1, $item->getMessage(), CCStr::strip( $item->getFile(), CCROOT ).':'.$item->getLine(), )); } return str_replace( '</body>', $table."\n</body>", $output ); }); } }
php
public static function _init() { // we capture non fatal errors only in dev environments if ( ClanCats::in_development() ) { // add a hook to the main resposne CCEvent::mind( 'response.output', function( $output ) { if ( strpos( $output, '</body>' ) === false ) { return $output; } $table = \UI\Table::create( array( 'style' => array( 'width' => '100%', ), 'cellpadding' => '5', 'class' => 'table debug-table debug-table-errors', )); $table->header( array( '#', 'message', 'file' ) ); foreach( \CCError::$non_fatals as $key => $item ) { $table->row( array( $key+1, $item->getMessage(), CCStr::strip( $item->getFile(), CCROOT ).':'.$item->getLine(), )); } return str_replace( '</body>', $table."\n</body>", $output ); }); } }
[ "public", "static", "function", "_init", "(", ")", "{", "// we capture non fatal errors only in dev environments", "if", "(", "ClanCats", "::", "in_development", "(", ")", ")", "{", "// add a hook to the main resposne", "CCEvent", "::", "mind", "(", "'response.output'", ",", "function", "(", "$", "output", ")", "{", "if", "(", "strpos", "(", "$", "output", ",", "'</body>'", ")", "===", "false", ")", "{", "return", "$", "output", ";", "}", "$", "table", "=", "\\", "UI", "\\", "Table", "::", "create", "(", "array", "(", "'style'", "=>", "array", "(", "'width'", "=>", "'100%'", ",", ")", ",", "'cellpadding'", "=>", "'5'", ",", "'class'", "=>", "'table debug-table debug-table-errors'", ",", ")", ")", ";", "$", "table", "->", "header", "(", "array", "(", "'#'", ",", "'message'", ",", "'file'", ")", ")", ";", "foreach", "(", "\\", "CCError", "::", "$", "non_fatals", "as", "$", "key", "=>", "$", "item", ")", "{", "$", "table", "->", "row", "(", "array", "(", "$", "key", "+", "1", ",", "$", "item", "->", "getMessage", "(", ")", ",", "CCStr", "::", "strip", "(", "$", "item", "->", "getFile", "(", ")", ",", "CCROOT", ")", ".", "':'", ".", "$", "item", "->", "getLine", "(", ")", ",", ")", ")", ";", "}", "return", "str_replace", "(", "'</body>'", ",", "$", "table", ".", "\"\\n</body>\"", ",", "$", "output", ")", ";", "}", ")", ";", "}", "}" ]
error class init @return void
[ "error", "class", "init" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCError.php#L62-L97
ClanCats/Core
src/classes/CCError.php
CCError.is_fatal_level
private static function is_fatal_level( $level ) { $fatals = array( E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, E_DEPRECATED, ); if ( is_object( ClanCats::$config ) && ClanCats::$config instanceof CCConfig ) { if ( in_array( $level, ClanCats::$config->get( 'error.fatal_levels', $fatals ) )) { return true; } } return false; }
php
private static function is_fatal_level( $level ) { $fatals = array( E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, E_DEPRECATED, ); if ( is_object( ClanCats::$config ) && ClanCats::$config instanceof CCConfig ) { if ( in_array( $level, ClanCats::$config->get( 'error.fatal_levels', $fatals ) )) { return true; } } return false; }
[ "private", "static", "function", "is_fatal_level", "(", "$", "level", ")", "{", "$", "fatals", "=", "array", "(", "E_ERROR", ",", "E_PARSE", ",", "E_CORE_ERROR", ",", "E_CORE_WARNING", ",", "E_COMPILE_ERROR", ",", "E_COMPILE_WARNING", ",", "E_DEPRECATED", ",", ")", ";", "if", "(", "is_object", "(", "ClanCats", "::", "$", "config", ")", "&&", "ClanCats", "::", "$", "config", "instanceof", "CCConfig", ")", "{", "if", "(", "in_array", "(", "$", "level", ",", "ClanCats", "::", "$", "config", "->", "get", "(", "'error.fatal_levels'", ",", "$", "fatals", ")", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
check if a level is fatal @param int $level @return bool
[ "check", "if", "a", "level", "is", "fatal" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCError.php#L105-L126
ClanCats/Core
src/classes/CCError.php
CCError.exception
public static function exception( $exception ) { // clean the main output buffer while ( ob_get_level() > 0 ) { ob_end_clean(); } $error_handler = "\\".CCCORE_NAMESPACE."\\CCError_Handler".( ClanCats::is_cli() ? '_Cli' : '' ); $error_inspector = "\\".CCCORE_NAMESPACE."\\CCError_Inspector"; if ( is_object( ClanCats::$config ) && ClanCats::$config instanceof CCConfig ) { $error_handler = ClanCats::$config->get( 'error.'.( ClanCats::is_cli() ? 'cli_' : '' ).'handler', $error_handler ); $error_inspector = ClanCats::$config->get( 'error.inspector', $error_inspector ); } $inspector = new $error_inspector( $exception ); $handler = new $error_handler( $inspector ); $handler->handle(); }
php
public static function exception( $exception ) { // clean the main output buffer while ( ob_get_level() > 0 ) { ob_end_clean(); } $error_handler = "\\".CCCORE_NAMESPACE."\\CCError_Handler".( ClanCats::is_cli() ? '_Cli' : '' ); $error_inspector = "\\".CCCORE_NAMESPACE."\\CCError_Inspector"; if ( is_object( ClanCats::$config ) && ClanCats::$config instanceof CCConfig ) { $error_handler = ClanCats::$config->get( 'error.'.( ClanCats::is_cli() ? 'cli_' : '' ).'handler', $error_handler ); $error_inspector = ClanCats::$config->get( 'error.inspector', $error_inspector ); } $inspector = new $error_inspector( $exception ); $handler = new $error_handler( $inspector ); $handler->handle(); }
[ "public", "static", "function", "exception", "(", "$", "exception", ")", "{", "// clean the main output buffer", "while", "(", "ob_get_level", "(", ")", ">", "0", ")", "{", "ob_end_clean", "(", ")", ";", "}", "$", "error_handler", "=", "\"\\\\\"", ".", "CCCORE_NAMESPACE", ".", "\"\\\\CCError_Handler\"", ".", "(", "ClanCats", "::", "is_cli", "(", ")", "?", "'_Cli'", ":", "''", ")", ";", "$", "error_inspector", "=", "\"\\\\\"", ".", "CCCORE_NAMESPACE", ".", "\"\\\\CCError_Inspector\"", ";", "if", "(", "is_object", "(", "ClanCats", "::", "$", "config", ")", "&&", "ClanCats", "::", "$", "config", "instanceof", "CCConfig", ")", "{", "$", "error_handler", "=", "ClanCats", "::", "$", "config", "->", "get", "(", "'error.'", ".", "(", "ClanCats", "::", "is_cli", "(", ")", "?", "'cli_'", ":", "''", ")", ".", "'handler'", ",", "$", "error_handler", ")", ";", "$", "error_inspector", "=", "ClanCats", "::", "$", "config", "->", "get", "(", "'error.inspector'", ",", "$", "error_inspector", ")", ";", "}", "$", "inspector", "=", "new", "$", "error_inspector", "(", "$", "exception", ")", ";", "$", "handler", "=", "new", "$", "error_handler", "(", "$", "inspector", ")", ";", "$", "handler", "->", "handle", "(", ")", ";", "}" ]
exception handler @param Exception $exception @return void
[ "exception", "handler" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCError.php#L134-L156
ClanCats/Core
src/classes/CCError.php
CCError.error
public static function error( $num, $message, $file, $line ) { $exception = new CCException( static::$error_types[$num]." - ".$message, 0, $num, $file, $line ); if ( static::is_fatal_level( $num ) ) { if ( static::$in_shutdown_process ) { static::exception( $exception ); } else { throw $exception; } } else { static::$non_fatals[] = $exception; } }
php
public static function error( $num, $message, $file, $line ) { $exception = new CCException( static::$error_types[$num]." - ".$message, 0, $num, $file, $line ); if ( static::is_fatal_level( $num ) ) { if ( static::$in_shutdown_process ) { static::exception( $exception ); } else { throw $exception; } } else { static::$non_fatals[] = $exception; } }
[ "public", "static", "function", "error", "(", "$", "num", ",", "$", "message", ",", "$", "file", ",", "$", "line", ")", "{", "$", "exception", "=", "new", "CCException", "(", "static", "::", "$", "error_types", "[", "$", "num", "]", ".", "\" - \"", ".", "$", "message", ",", "0", ",", "$", "num", ",", "$", "file", ",", "$", "line", ")", ";", "if", "(", "static", "::", "is_fatal_level", "(", "$", "num", ")", ")", "{", "if", "(", "static", "::", "$", "in_shutdown_process", ")", "{", "static", "::", "exception", "(", "$", "exception", ")", ";", "}", "else", "{", "throw", "$", "exception", ";", "}", "}", "else", "{", "static", "::", "$", "non_fatals", "[", "]", "=", "$", "exception", ";", "}", "}" ]
The error handler converts PHP errors to CCExceptions. These get handled by the CCError exception handler. Also the error handler decides the fatality of an error. @param CCException $exception @return void
[ "The", "error", "handler", "converts", "PHP", "errors", "to", "CCExceptions", ".", "These", "get", "handled", "by", "the", "CCError", "exception", "handler", "." ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCError.php#L167-L184
ClanCats/Core
src/classes/CCError.php
CCError.shutdown
public static function shutdown() { // enter shutdown context static::$in_shutdown_process = true; $error = error_get_last(); // if the error is not null and the level is // fatal. Forward the error to our error handler. if ( !is_null( $error ) && static::is_fatal_level( $error['type'] ) ) { static::error( $error['type'], $error['message'], $error['file'], $error['line'] ); } }
php
public static function shutdown() { // enter shutdown context static::$in_shutdown_process = true; $error = error_get_last(); // if the error is not null and the level is // fatal. Forward the error to our error handler. if ( !is_null( $error ) && static::is_fatal_level( $error['type'] ) ) { static::error( $error['type'], $error['message'], $error['file'], $error['line'] ); } }
[ "public", "static", "function", "shutdown", "(", ")", "{", "// enter shutdown context", "static", "::", "$", "in_shutdown_process", "=", "true", ";", "$", "error", "=", "error_get_last", "(", ")", ";", "// if the error is not null and the level is ", "// fatal. Forward the error to our error handler.", "if", "(", "!", "is_null", "(", "$", "error", ")", "&&", "static", "::", "is_fatal_level", "(", "$", "error", "[", "'type'", "]", ")", ")", "{", "static", "::", "error", "(", "$", "error", "[", "'type'", "]", ",", "$", "error", "[", "'message'", "]", ",", "$", "error", "[", "'file'", "]", ",", "$", "error", "[", "'line'", "]", ")", ";", "}", "}" ]
shutdown handler @return void
[ "shutdown", "handler" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCError.php#L191-L204
yuncms/framework
src/admin/widgets/Nav.php
Nav.run
public function run() { $tag = ArrayHelper::remove($options, 'tag', 'ul'); return Html::tag($tag, $this->top . $this->renderItems($this->items), $this->options); }
php
public function run() { $tag = ArrayHelper::remove($options, 'tag', 'ul'); return Html::tag($tag, $this->top . $this->renderItems($this->items), $this->options); }
[ "public", "function", "run", "(", ")", "{", "$", "tag", "=", "ArrayHelper", "::", "remove", "(", "$", "options", ",", "'tag'", ",", "'ul'", ")", ";", "return", "Html", "::", "tag", "(", "$", "tag", ",", "$", "this", "->", "top", ".", "$", "this", "->", "renderItems", "(", "$", "this", "->", "items", ")", ",", "$", "this", "->", "options", ")", ";", "}" ]
执行 @throws InvalidConfigException
[ "执行" ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/admin/widgets/Nav.php#L135-L139
yuncms/framework
src/admin/widgets/Nav.php
Nav.renderItems
public function renderItems($items) { if (is_string($items)) { return $items; } $lines = []; foreach ($items as $item) { if (is_string($item)) { return $item; } if (!isset ($item['label'])) { throw new InvalidConfigException ("The 'label' option is required."); } $encodeLabel = isset ($item['encode']) ? $item['encode'] : $this->encodeLabels; if ($item['parent'] == null) {//如果是顶级菜单 $item['label'] = $encodeLabel ? Html::tag('span', Html::encode($item['label']), ['class' => 'nav-label']) : $item['label']; } else { $item['label'] = $encodeLabel ? Html::encode($item['label']) : $item['label']; } $item['icon'] = isset ($item['icon']) ? Html::tag('i', '', ['class' => 'fa fa-lg fa-fw ' . $item['icon']]) : ''; $options = ArrayHelper::getValue($item, 'options', []); $subItems = ArrayHelper::getValue($item, 'items'); if (isset ($item['active'])) { $active = ArrayHelper::remove($item, 'active', false); } else { $active = $this->isItemActive($item); } //判断是否有子菜单 if ($subItems !== null && is_array($subItems)) { if ($this->activateItems) { $subItems = $this->isChildActive($subItems, $active); if ($active) { //如果被激活则父菜单是打开状态 Html::addCssClass($options, 'active'); } } $subItems = $this->renderItems($subItems); if($subItems){ $submenuTemplate = ArrayHelper::getValue($item, 'submenuTemplate', $this->submenuTemplate); $subItems = strtr($submenuTemplate, [ '{items}' => $this->renderItems($subItems), ]); } } if ($this->activateItems && $active) {//无子菜单则激活当前菜单 Html::addCssClass($options, 'active'); } if (isset ($item['visible']) && !$item['visible']) { continue; } if ($subItems == null) { Html::removeCssClass($options, 'open'); } $menu = $this->renderItem($item); $lines[] = Html::tag('li', $menu . $subItems, $options); } if (empty($lines)) { return null; } return implode("\n", $lines); }
php
public function renderItems($items) { if (is_string($items)) { return $items; } $lines = []; foreach ($items as $item) { if (is_string($item)) { return $item; } if (!isset ($item['label'])) { throw new InvalidConfigException ("The 'label' option is required."); } $encodeLabel = isset ($item['encode']) ? $item['encode'] : $this->encodeLabels; if ($item['parent'] == null) {//如果是顶级菜单 $item['label'] = $encodeLabel ? Html::tag('span', Html::encode($item['label']), ['class' => 'nav-label']) : $item['label']; } else { $item['label'] = $encodeLabel ? Html::encode($item['label']) : $item['label']; } $item['icon'] = isset ($item['icon']) ? Html::tag('i', '', ['class' => 'fa fa-lg fa-fw ' . $item['icon']]) : ''; $options = ArrayHelper::getValue($item, 'options', []); $subItems = ArrayHelper::getValue($item, 'items'); if (isset ($item['active'])) { $active = ArrayHelper::remove($item, 'active', false); } else { $active = $this->isItemActive($item); } //判断是否有子菜单 if ($subItems !== null && is_array($subItems)) { if ($this->activateItems) { $subItems = $this->isChildActive($subItems, $active); if ($active) { //如果被激活则父菜单是打开状态 Html::addCssClass($options, 'active'); } } $subItems = $this->renderItems($subItems); if($subItems){ $submenuTemplate = ArrayHelper::getValue($item, 'submenuTemplate', $this->submenuTemplate); $subItems = strtr($submenuTemplate, [ '{items}' => $this->renderItems($subItems), ]); } } if ($this->activateItems && $active) {//无子菜单则激活当前菜单 Html::addCssClass($options, 'active'); } if (isset ($item['visible']) && !$item['visible']) { continue; } if ($subItems == null) { Html::removeCssClass($options, 'open'); } $menu = $this->renderItem($item); $lines[] = Html::tag('li', $menu . $subItems, $options); } if (empty($lines)) { return null; } return implode("\n", $lines); }
[ "public", "function", "renderItems", "(", "$", "items", ")", "{", "if", "(", "is_string", "(", "$", "items", ")", ")", "{", "return", "$", "items", ";", "}", "$", "lines", "=", "[", "]", ";", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "if", "(", "is_string", "(", "$", "item", ")", ")", "{", "return", "$", "item", ";", "}", "if", "(", "!", "isset", "(", "$", "item", "[", "'label'", "]", ")", ")", "{", "throw", "new", "InvalidConfigException", "(", "\"The 'label' option is required.\"", ")", ";", "}", "$", "encodeLabel", "=", "isset", "(", "$", "item", "[", "'encode'", "]", ")", "?", "$", "item", "[", "'encode'", "]", ":", "$", "this", "->", "encodeLabels", ";", "if", "(", "$", "item", "[", "'parent'", "]", "==", "null", ")", "{", "//如果是顶级菜单", "$", "item", "[", "'label'", "]", "=", "$", "encodeLabel", "?", "Html", "::", "tag", "(", "'span'", ",", "Html", "::", "encode", "(", "$", "item", "[", "'label'", "]", ")", ",", "[", "'class'", "=>", "'nav-label'", "]", ")", ":", "$", "item", "[", "'label'", "]", ";", "}", "else", "{", "$", "item", "[", "'label'", "]", "=", "$", "encodeLabel", "?", "Html", "::", "encode", "(", "$", "item", "[", "'label'", "]", ")", ":", "$", "item", "[", "'label'", "]", ";", "}", "$", "item", "[", "'icon'", "]", "=", "isset", "(", "$", "item", "[", "'icon'", "]", ")", "?", "Html", "::", "tag", "(", "'i'", ",", "''", ",", "[", "'class'", "=>", "'fa fa-lg fa-fw '", ".", "$", "item", "[", "'icon'", "]", "]", ")", ":", "''", ";", "$", "options", "=", "ArrayHelper", "::", "getValue", "(", "$", "item", ",", "'options'", ",", "[", "]", ")", ";", "$", "subItems", "=", "ArrayHelper", "::", "getValue", "(", "$", "item", ",", "'items'", ")", ";", "if", "(", "isset", "(", "$", "item", "[", "'active'", "]", ")", ")", "{", "$", "active", "=", "ArrayHelper", "::", "remove", "(", "$", "item", ",", "'active'", ",", "false", ")", ";", "}", "else", "{", "$", "active", "=", "$", "this", "->", "isItemActive", "(", "$", "item", ")", ";", "}", "//判断是否有子菜单", "if", "(", "$", "subItems", "!==", "null", "&&", "is_array", "(", "$", "subItems", ")", ")", "{", "if", "(", "$", "this", "->", "activateItems", ")", "{", "$", "subItems", "=", "$", "this", "->", "isChildActive", "(", "$", "subItems", ",", "$", "active", ")", ";", "if", "(", "$", "active", ")", "{", "//如果被激活则父菜单是打开状态", "Html", "::", "addCssClass", "(", "$", "options", ",", "'active'", ")", ";", "}", "}", "$", "subItems", "=", "$", "this", "->", "renderItems", "(", "$", "subItems", ")", ";", "if", "(", "$", "subItems", ")", "{", "$", "submenuTemplate", "=", "ArrayHelper", "::", "getValue", "(", "$", "item", ",", "'submenuTemplate'", ",", "$", "this", "->", "submenuTemplate", ")", ";", "$", "subItems", "=", "strtr", "(", "$", "submenuTemplate", ",", "[", "'{items}'", "=>", "$", "this", "->", "renderItems", "(", "$", "subItems", ")", ",", "]", ")", ";", "}", "}", "if", "(", "$", "this", "->", "activateItems", "&&", "$", "active", ")", "{", "//无子菜单则激活当前菜单", "Html", "::", "addCssClass", "(", "$", "options", ",", "'active'", ")", ";", "}", "if", "(", "isset", "(", "$", "item", "[", "'visible'", "]", ")", "&&", "!", "$", "item", "[", "'visible'", "]", ")", "{", "continue", ";", "}", "if", "(", "$", "subItems", "==", "null", ")", "{", "Html", "::", "removeCssClass", "(", "$", "options", ",", "'open'", ")", ";", "}", "$", "menu", "=", "$", "this", "->", "renderItem", "(", "$", "item", ")", ";", "$", "lines", "[", "]", "=", "Html", "::", "tag", "(", "'li'", ",", "$", "menu", ".", "$", "subItems", ",", "$", "options", ")", ";", "}", "if", "(", "empty", "(", "$", "lines", ")", ")", "{", "return", "null", ";", "}", "return", "implode", "(", "\"\\n\"", ",", "$", "lines", ")", ";", "}" ]
渲染所以项目 @param $items @return null|string @throws InvalidConfigException
[ "渲染所以项目" ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/admin/widgets/Nav.php#L147-L211
raoul2000/yii2-scrollup-widget
Scrollup.php
Scrollup.init
public function init() { parent::init(); if (! empty($this->theme) && ! in_array($this->theme, $this->_supportedThemes)) { throw new InvalidConfigException('Unsupported built-in theme : ' . $this->theme); } if (isset($this->pluginOptions['animation']) && ! in_array($this->pluginOptions['animation'], $this->_supportedAnimation)) { throw new InvalidConfigException('Unsupported animation mode : ' . $this->pluginOptions['animation']); } }
php
public function init() { parent::init(); if (! empty($this->theme) && ! in_array($this->theme, $this->_supportedThemes)) { throw new InvalidConfigException('Unsupported built-in theme : ' . $this->theme); } if (isset($this->pluginOptions['animation']) && ! in_array($this->pluginOptions['animation'], $this->_supportedAnimation)) { throw new InvalidConfigException('Unsupported animation mode : ' . $this->pluginOptions['animation']); } }
[ "public", "function", "init", "(", ")", "{", "parent", "::", "init", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "theme", ")", "&&", "!", "in_array", "(", "$", "this", "->", "theme", ",", "$", "this", "->", "_supportedThemes", ")", ")", "{", "throw", "new", "InvalidConfigException", "(", "'Unsupported built-in theme : '", ".", "$", "this", "->", "theme", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "pluginOptions", "[", "'animation'", "]", ")", "&&", "!", "in_array", "(", "$", "this", "->", "pluginOptions", "[", "'animation'", "]", ",", "$", "this", "->", "_supportedAnimation", ")", ")", "{", "throw", "new", "InvalidConfigException", "(", "'Unsupported animation mode : '", ".", "$", "this", "->", "pluginOptions", "[", "'animation'", "]", ")", ";", "}", "}" ]
Chekcs validity of theme and animation options
[ "Chekcs", "validity", "of", "theme", "and", "animation", "options" ]
train
https://github.com/raoul2000/yii2-scrollup-widget/blob/54d0d40755d81b039b90bfb36ed90325294b6864/Scrollup.php#L66-L75
raoul2000/yii2-scrollup-widget
Scrollup.php
Scrollup.registerClientScript
public function registerClientScript() { $view = $this->getView(); if (isset($this->theme)) { $path = $view->getAssetManager()->publish(__DIR__ . '/assets/css/themes'); $view->registerCSSFile($path[1] . '/' . $this->theme . '.css'); if ($this->theme == 'image' && isset($this->pluginOptions['scrollText'])) { $this->pluginOptions['scrollText'] = ''; } } ScrollupAsset::register($view); $options = empty($this->pluginOptions) ? '{}' : Json::encode($this->pluginOptions); $js = "$.scrollUp($options);"; $view->registerJs($js); }
php
public function registerClientScript() { $view = $this->getView(); if (isset($this->theme)) { $path = $view->getAssetManager()->publish(__DIR__ . '/assets/css/themes'); $view->registerCSSFile($path[1] . '/' . $this->theme . '.css'); if ($this->theme == 'image' && isset($this->pluginOptions['scrollText'])) { $this->pluginOptions['scrollText'] = ''; } } ScrollupAsset::register($view); $options = empty($this->pluginOptions) ? '{}' : Json::encode($this->pluginOptions); $js = "$.scrollUp($options);"; $view->registerJs($js); }
[ "public", "function", "registerClientScript", "(", ")", "{", "$", "view", "=", "$", "this", "->", "getView", "(", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "theme", ")", ")", "{", "$", "path", "=", "$", "view", "->", "getAssetManager", "(", ")", "->", "publish", "(", "__DIR__", ".", "'/assets/css/themes'", ")", ";", "$", "view", "->", "registerCSSFile", "(", "$", "path", "[", "1", "]", ".", "'/'", ".", "$", "this", "->", "theme", ".", "'.css'", ")", ";", "if", "(", "$", "this", "->", "theme", "==", "'image'", "&&", "isset", "(", "$", "this", "->", "pluginOptions", "[", "'scrollText'", "]", ")", ")", "{", "$", "this", "->", "pluginOptions", "[", "'scrollText'", "]", "=", "''", ";", "}", "}", "ScrollupAsset", "::", "register", "(", "$", "view", ")", ";", "$", "options", "=", "empty", "(", "$", "this", "->", "pluginOptions", ")", "?", "'{}'", ":", "Json", "::", "encode", "(", "$", "this", "->", "pluginOptions", ")", ";", "$", "js", "=", "\"$.scrollUp($options);\"", ";", "$", "view", "->", "registerJs", "(", "$", "js", ")", ";", "}" ]
Registers the needed JavaScript and inject the JS initialization code. Note that if a supported theme is set, all css in the assets/css/theme folder are published but only the css for the theme is registred.Moreover, if the select theme is 'image', the 'scrollText plugin option is cleared.
[ "Registers", "the", "needed", "JavaScript", "and", "inject", "the", "JS", "initialization", "code", "." ]
train
https://github.com/raoul2000/yii2-scrollup-widget/blob/54d0d40755d81b039b90bfb36ed90325294b6864/Scrollup.php#L92-L110
fubhy/graphql-php
src/Language/Source.php
Source.getLocation
public function getLocation($position) { $pattern = '/\r\n|[\n\r\u2028\u2029]/g'; $subject = mb_substr($this->body, 0, $position, 'UTF-8'); preg_match_all($pattern, $subject, $matches, PREG_OFFSET_CAPTURE); $location = array_reduce($matches[0], function ($carry, $match) use ($position) { return [ $carry[0] + 1, $position + 1 - ($match[1] + mb_strlen($match[0], 'UTF-8')) ]; }, [1, $position + 1]); return new SourceLocation($location[0], $location[1]); }
php
public function getLocation($position) { $pattern = '/\r\n|[\n\r\u2028\u2029]/g'; $subject = mb_substr($this->body, 0, $position, 'UTF-8'); preg_match_all($pattern, $subject, $matches, PREG_OFFSET_CAPTURE); $location = array_reduce($matches[0], function ($carry, $match) use ($position) { return [ $carry[0] + 1, $position + 1 - ($match[1] + mb_strlen($match[0], 'UTF-8')) ]; }, [1, $position + 1]); return new SourceLocation($location[0], $location[1]); }
[ "public", "function", "getLocation", "(", "$", "position", ")", "{", "$", "pattern", "=", "'/\\r\\n|[\\n\\r\\u2028\\u2029]/g'", ";", "$", "subject", "=", "mb_substr", "(", "$", "this", "->", "body", ",", "0", ",", "$", "position", ",", "'UTF-8'", ")", ";", "preg_match_all", "(", "$", "pattern", ",", "$", "subject", ",", "$", "matches", ",", "PREG_OFFSET_CAPTURE", ")", ";", "$", "location", "=", "array_reduce", "(", "$", "matches", "[", "0", "]", ",", "function", "(", "$", "carry", ",", "$", "match", ")", "use", "(", "$", "position", ")", "{", "return", "[", "$", "carry", "[", "0", "]", "+", "1", ",", "$", "position", "+", "1", "-", "(", "$", "match", "[", "1", "]", "+", "mb_strlen", "(", "$", "match", "[", "0", "]", ",", "'UTF-8'", ")", ")", "]", ";", "}", ",", "[", "1", ",", "$", "position", "+", "1", "]", ")", ";", "return", "new", "SourceLocation", "(", "$", "location", "[", "0", "]", ",", "$", "location", "[", "1", "]", ")", ";", "}" ]
Takes a Source and a UTF-8 character offset, and returns the corresponding line and column as a SourceLocation. @param $position @return \Fubhy\GraphQL\Language\SourceLocation
[ "Takes", "a", "Source", "and", "a", "UTF", "-", "8", "character", "offset", "and", "returns", "the", "corresponding", "line", "and", "column", "as", "a", "SourceLocation", "." ]
train
https://github.com/fubhy/graphql-php/blob/c1de2233c731ca29e5c5db4c43f3b9db36478c83/src/Language/Source.php#L74-L88
spiral-modules/auth
source/Auth/Middlewares/Firewalls/RedirectFirewall.php
RedirectFirewall.withRedirect
public function withRedirect(UriInterface $uri): self { $middleware = clone $this; $middleware->redirect = $uri; return $middleware; }
php
public function withRedirect(UriInterface $uri): self { $middleware = clone $this; $middleware->redirect = $uri; return $middleware; }
[ "public", "function", "withRedirect", "(", "UriInterface", "$", "uri", ")", ":", "self", "{", "$", "middleware", "=", "clone", "$", "this", ";", "$", "middleware", "->", "redirect", "=", "$", "uri", ";", "return", "$", "middleware", ";", "}" ]
@param UriInterface $uri @return RedirectFirewall
[ "@param", "UriInterface", "$uri" ]
train
https://github.com/spiral-modules/auth/blob/24e2070028f7257e8192914556963a4794428a99/source/Auth/Middlewares/Firewalls/RedirectFirewall.php#L49-L55
spiral-modules/auth
source/Auth/Middlewares/Firewalls/RedirectFirewall.php
RedirectFirewall.denyAccess
public function denyAccess(Request $request, Response $response, callable $next) { return $response->withStatus($this->status)->withHeader( 'Location', (string)$this->redirect ); }
php
public function denyAccess(Request $request, Response $response, callable $next) { return $response->withStatus($this->status)->withHeader( 'Location', (string)$this->redirect ); }
[ "public", "function", "denyAccess", "(", "Request", "$", "request", ",", "Response", "$", "response", ",", "callable", "$", "next", ")", "{", "return", "$", "response", "->", "withStatus", "(", "$", "this", "->", "status", ")", "->", "withHeader", "(", "'Location'", ",", "(", "string", ")", "$", "this", "->", "redirect", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/spiral-modules/auth/blob/24e2070028f7257e8192914556963a4794428a99/source/Auth/Middlewares/Firewalls/RedirectFirewall.php#L60-L66
joomlatools/joomlatools-platform-legacy
code/base/node.php
JNode.addChild
public function addChild(&$child) { JLog::add('JNode::addChild() is deprecated.', JLog::WARNING, 'deprecated'); if ($child instanceof Jnode) { $child->setParent($this); } }
php
public function addChild(&$child) { JLog::add('JNode::addChild() is deprecated.', JLog::WARNING, 'deprecated'); if ($child instanceof Jnode) { $child->setParent($this); } }
[ "public", "function", "addChild", "(", "&", "$", "child", ")", "{", "JLog", "::", "add", "(", "'JNode::addChild() is deprecated.'", ",", "JLog", "::", "WARNING", ",", "'deprecated'", ")", ";", "if", "(", "$", "child", "instanceof", "Jnode", ")", "{", "$", "child", "->", "setParent", "(", "$", "this", ")", ";", "}", "}" ]
Add child to this node If the child already has a parent, the link is unset @param JNode &$child The child to be added @return void @since 11.1
[ "Add", "child", "to", "this", "node" ]
train
https://github.com/joomlatools/joomlatools-platform-legacy/blob/3a76944e2f2c415faa6504754c75321a3b478c06/code/base/node.php#L60-L68
joomlatools/joomlatools-platform-legacy
code/base/node.php
JNode.setParent
public function setParent(&$parent) { JLog::add('JNode::setParent() is deprecated.', JLog::WARNING, 'deprecated'); if ($parent instanceof JNode || is_null($parent)) { $hash = spl_object_hash($this); if (!is_null($this->_parent)) { unset($this->_parent->children[$hash]); } if (!is_null($parent)) { $parent->_children[$hash] = & $this; } $this->_parent = & $parent; } }
php
public function setParent(&$parent) { JLog::add('JNode::setParent() is deprecated.', JLog::WARNING, 'deprecated'); if ($parent instanceof JNode || is_null($parent)) { $hash = spl_object_hash($this); if (!is_null($this->_parent)) { unset($this->_parent->children[$hash]); } if (!is_null($parent)) { $parent->_children[$hash] = & $this; } $this->_parent = & $parent; } }
[ "public", "function", "setParent", "(", "&", "$", "parent", ")", "{", "JLog", "::", "add", "(", "'JNode::setParent() is deprecated.'", ",", "JLog", "::", "WARNING", ",", "'deprecated'", ")", ";", "if", "(", "$", "parent", "instanceof", "JNode", "||", "is_null", "(", "$", "parent", ")", ")", "{", "$", "hash", "=", "spl_object_hash", "(", "$", "this", ")", ";", "if", "(", "!", "is_null", "(", "$", "this", "->", "_parent", ")", ")", "{", "unset", "(", "$", "this", "->", "_parent", "->", "children", "[", "$", "hash", "]", ")", ";", "}", "if", "(", "!", "is_null", "(", "$", "parent", ")", ")", "{", "$", "parent", "->", "_children", "[", "$", "hash", "]", "=", "&", "$", "this", ";", "}", "$", "this", "->", "_parent", "=", "&", "$", "parent", ";", "}", "}" ]
Set the parent of a this node If the node already has a parent, the link is unset @param mixed &$parent The JNode for parent to be set or null @return void @since 11.1
[ "Set", "the", "parent", "of", "a", "this", "node" ]
train
https://github.com/joomlatools/joomlatools-platform-legacy/blob/3a76944e2f2c415faa6504754c75321a3b478c06/code/base/node.php#L81-L101
Nobiles2/smsapi-bundle
DependencyInjection/KCHSmsApiExtension.php
KCHSmsApiExtension.load
public function load(array $configs, ContainerBuilder $container) { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.yml'); // Services registration if(count($config['clients'])) { foreach($config['clients'] as $clientName => $clientData) { $service = $container->setDefinition( sprintf('kch_sms_api.client.%s', $clientName), new Definition( '%kch_sms_api.client.class%', array($clientData['client_login']) ) )->addMethodCall('setPasswordHash', array($clientData['client_password_hash'])); $this->registerFactories($container, $service, $clientName); } } }
php
public function load(array $configs, ContainerBuilder $container) { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.yml'); // Services registration if(count($config['clients'])) { foreach($config['clients'] as $clientName => $clientData) { $service = $container->setDefinition( sprintf('kch_sms_api.client.%s', $clientName), new Definition( '%kch_sms_api.client.class%', array($clientData['client_login']) ) )->addMethodCall('setPasswordHash', array($clientData['client_password_hash'])); $this->registerFactories($container, $service, $clientName); } } }
[ "public", "function", "load", "(", "array", "$", "configs", ",", "ContainerBuilder", "$", "container", ")", "{", "$", "configuration", "=", "new", "Configuration", "(", ")", ";", "$", "config", "=", "$", "this", "->", "processConfiguration", "(", "$", "configuration", ",", "$", "configs", ")", ";", "$", "loader", "=", "new", "Loader", "\\", "YamlFileLoader", "(", "$", "container", ",", "new", "FileLocator", "(", "__DIR__", ".", "'/../Resources/config'", ")", ")", ";", "$", "loader", "->", "load", "(", "'services.yml'", ")", ";", "// Services registration", "if", "(", "count", "(", "$", "config", "[", "'clients'", "]", ")", ")", "{", "foreach", "(", "$", "config", "[", "'clients'", "]", "as", "$", "clientName", "=>", "$", "clientData", ")", "{", "$", "service", "=", "$", "container", "->", "setDefinition", "(", "sprintf", "(", "'kch_sms_api.client.%s'", ",", "$", "clientName", ")", ",", "new", "Definition", "(", "'%kch_sms_api.client.class%'", ",", "array", "(", "$", "clientData", "[", "'client_login'", "]", ")", ")", ")", "->", "addMethodCall", "(", "'setPasswordHash'", ",", "array", "(", "$", "clientData", "[", "'client_password_hash'", "]", ")", ")", ";", "$", "this", "->", "registerFactories", "(", "$", "container", ",", "$", "service", ",", "$", "clientName", ")", ";", "}", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Nobiles2/smsapi-bundle/blob/f3f5e76e021b6a5da8c8d8accb81c4e283b9faa7/DependencyInjection/KCHSmsApiExtension.php#L21-L43
Nobiles2/smsapi-bundle
DependencyInjection/KCHSmsApiExtension.php
KCHSmsApiExtension.registerFactories
private function registerFactories(ContainerBuilder $container, Definition $clientService, $clientName) { // SmsFactory $container->setDefinition( sprintf('kch_sms_api.sms_factory.%s', $clientName), new Definition('%kch_sms_api.sms_factory.class%') ) ->addMethodCall('setClient', array($clientService)) ->addTag('kch_sms_api.factory', array('alias' => 'kch_sms_api_factory')); // MmsFactory $container->setDefinition( sprintf('kch_sms_api.mms_factory.%s', $clientName), new Definition('%kch_sms_api.mms_factory.class%') ) ->addMethodCall('setClient', array($clientService)) ->addTag('kch_sms_api.factory', array('alias' => 'kch_sms_api_factory')); // VmsFactory $container->setDefinition( sprintf('kch_sms_api.vms_factory.%s', $clientName), new Definition('%kch_sms_api.vms_factory.class%') ) ->addMethodCall('setClient', array($clientService)) ->addTag('kch_sms_api.factory', array('alias' => 'kch_sms_api_factory')); // SenderFactory $container->setDefinition( sprintf('kch_sms_api.sender_factory.%s', $clientName), new Definition('%kch_sms_api.sender_factory.class%') ) ->addMethodCall('setClient', array($clientService)) ->addTag('kch_sms_api.factory', array('alias' => 'kch_sms_api_factory')); // ContactsFactory $container->setDefinition( sprintf('kch_sms_api.contacts_factory.%s', $clientName), new Definition('%kch_sms_api.contacts_factory.class%') ) ->addMethodCall('setClient', array($clientService)) ->addTag('kch_sms_api.factory', array('alias' => 'kch_sms_api_factory')); }
php
private function registerFactories(ContainerBuilder $container, Definition $clientService, $clientName) { // SmsFactory $container->setDefinition( sprintf('kch_sms_api.sms_factory.%s', $clientName), new Definition('%kch_sms_api.sms_factory.class%') ) ->addMethodCall('setClient', array($clientService)) ->addTag('kch_sms_api.factory', array('alias' => 'kch_sms_api_factory')); // MmsFactory $container->setDefinition( sprintf('kch_sms_api.mms_factory.%s', $clientName), new Definition('%kch_sms_api.mms_factory.class%') ) ->addMethodCall('setClient', array($clientService)) ->addTag('kch_sms_api.factory', array('alias' => 'kch_sms_api_factory')); // VmsFactory $container->setDefinition( sprintf('kch_sms_api.vms_factory.%s', $clientName), new Definition('%kch_sms_api.vms_factory.class%') ) ->addMethodCall('setClient', array($clientService)) ->addTag('kch_sms_api.factory', array('alias' => 'kch_sms_api_factory')); // SenderFactory $container->setDefinition( sprintf('kch_sms_api.sender_factory.%s', $clientName), new Definition('%kch_sms_api.sender_factory.class%') ) ->addMethodCall('setClient', array($clientService)) ->addTag('kch_sms_api.factory', array('alias' => 'kch_sms_api_factory')); // ContactsFactory $container->setDefinition( sprintf('kch_sms_api.contacts_factory.%s', $clientName), new Definition('%kch_sms_api.contacts_factory.class%') ) ->addMethodCall('setClient', array($clientService)) ->addTag('kch_sms_api.factory', array('alias' => 'kch_sms_api_factory')); }
[ "private", "function", "registerFactories", "(", "ContainerBuilder", "$", "container", ",", "Definition", "$", "clientService", ",", "$", "clientName", ")", "{", "// SmsFactory", "$", "container", "->", "setDefinition", "(", "sprintf", "(", "'kch_sms_api.sms_factory.%s'", ",", "$", "clientName", ")", ",", "new", "Definition", "(", "'%kch_sms_api.sms_factory.class%'", ")", ")", "->", "addMethodCall", "(", "'setClient'", ",", "array", "(", "$", "clientService", ")", ")", "->", "addTag", "(", "'kch_sms_api.factory'", ",", "array", "(", "'alias'", "=>", "'kch_sms_api_factory'", ")", ")", ";", "// MmsFactory", "$", "container", "->", "setDefinition", "(", "sprintf", "(", "'kch_sms_api.mms_factory.%s'", ",", "$", "clientName", ")", ",", "new", "Definition", "(", "'%kch_sms_api.mms_factory.class%'", ")", ")", "->", "addMethodCall", "(", "'setClient'", ",", "array", "(", "$", "clientService", ")", ")", "->", "addTag", "(", "'kch_sms_api.factory'", ",", "array", "(", "'alias'", "=>", "'kch_sms_api_factory'", ")", ")", ";", "// VmsFactory", "$", "container", "->", "setDefinition", "(", "sprintf", "(", "'kch_sms_api.vms_factory.%s'", ",", "$", "clientName", ")", ",", "new", "Definition", "(", "'%kch_sms_api.vms_factory.class%'", ")", ")", "->", "addMethodCall", "(", "'setClient'", ",", "array", "(", "$", "clientService", ")", ")", "->", "addTag", "(", "'kch_sms_api.factory'", ",", "array", "(", "'alias'", "=>", "'kch_sms_api_factory'", ")", ")", ";", "// SenderFactory", "$", "container", "->", "setDefinition", "(", "sprintf", "(", "'kch_sms_api.sender_factory.%s'", ",", "$", "clientName", ")", ",", "new", "Definition", "(", "'%kch_sms_api.sender_factory.class%'", ")", ")", "->", "addMethodCall", "(", "'setClient'", ",", "array", "(", "$", "clientService", ")", ")", "->", "addTag", "(", "'kch_sms_api.factory'", ",", "array", "(", "'alias'", "=>", "'kch_sms_api_factory'", ")", ")", ";", "// ContactsFactory", "$", "container", "->", "setDefinition", "(", "sprintf", "(", "'kch_sms_api.contacts_factory.%s'", ",", "$", "clientName", ")", ",", "new", "Definition", "(", "'%kch_sms_api.contacts_factory.class%'", ")", ")", "->", "addMethodCall", "(", "'setClient'", ",", "array", "(", "$", "clientService", ")", ")", "->", "addTag", "(", "'kch_sms_api.factory'", ",", "array", "(", "'alias'", "=>", "'kch_sms_api_factory'", ")", ")", ";", "}" ]
Method register all library factories for Client. @param ContainerBuilder $container @param Definition $clientService @param $clientName
[ "Method", "register", "all", "library", "factories", "for", "Client", "." ]
train
https://github.com/Nobiles2/smsapi-bundle/blob/f3f5e76e021b6a5da8c8d8accb81c4e283b9faa7/DependencyInjection/KCHSmsApiExtension.php#L52-L93
webforge-labs/psc-cms
lib/Psc/Doctrine/EntityBuilder.php
EntityBuilder.generateI18nAPI
public function generateI18nAPI(ClassBuilderProperty $property, $originalName, $originalFlags = 0x000000, $originalUpperCaseName = NULL) { $originalType = $property->getType()->getType(); $properties = array(); foreach ($this->getLanguages() as $lang) { $properties[$lang] = $this->createProperty( $originalName.ucfirst($lang), $originalType, // des inner types // vererbe vom type, aber nur nullable+unique, alle anderen flags maskieren, die virtuelleln properties haben keine setter/getter und keinen docblock ($originalFlags & (self::NULLABLE | self::UNIQUE)) | self::WITHOUT_GETTER | self::WITHOUT_SETTER, ($originalUpperCaseName) ? $originalUpperCaseName.ucfirst($lang) : NULL ); $this->setForcedMetaProperty($properties[$lang], FALSE); // nicht in die meta exportieren, weil wir sie da nicht wollen, das i18n-property schon! } // wir müssen den initialisierungs code für den i18n array in den getter injecten $initCode = array(); $initCode[] = sprintf('if (count($this->%s) == 0) {', $property->getName()); foreach ($this->getLanguages() as $lang) { $initCode[] = sprintf(' $this->%s[\'%s\'] = $this->%s;', $property->getName(), $lang, $properties[$lang]->getName()); } $initCode[] = '}'; $this->getMethod($property->getGetterName())->beforeBody($initCode); // wir müssen den setter für den i18n Array injecten (der soll die virtuellen properties setzen) $updateCode = array(); foreach ($this->getLanguages() as $lang) { $updateCode[] = sprintf('$this->%s = $this->%s[\'%s\'];', $properties[$lang]->getName(), $property->getName(), $lang); } $this->getMethod($property->getSetterName())->insertBody($updateCode, -1); // vor: return $this; // dann müssen wir getField $getCode = array(); $getCode[] = sprintf('$title = $this->%s();', $property->getGetterName()); $getCode[] = 'return $title[$lang];'; $this->addMethod(new GMethod( 'get'.($originalUpperCaseName ?: ucfirst($originalName)), array(new GParameter('lang', NULL)), $getCode )); // und setField bauen $setCode = array(); // wir könnten uns noch überlegen bei else: eine exception zu schmeissen? foreach ($this->getLanguages() as $key=>$lang) { if ($key === 0) { $setCode[] = sprintf('if ($lang === \'%s\') {', $lang); } else { $setCode[] = sprintf('} elseif ($lang === \'%s\') {', $lang); } // setze klassenVariable und i18nVariable auf den neuen Wert $setCode[] = sprintf(' $this->%s = $this->%s[\'%s\'] = $value;', $properties[$lang]->getName(), $property->getName(), $lang); } $setCode[] = '}'; $setCode[] = 'return $this;'; $this->addMethod(new GMethod( 'set'.($originalUpperCaseName ?: ucfirst($originalName)), array(new GParameter('value', $originalType->getPHPHint()), new GParameter('lang', NULL)), $setCode )); }
php
public function generateI18nAPI(ClassBuilderProperty $property, $originalName, $originalFlags = 0x000000, $originalUpperCaseName = NULL) { $originalType = $property->getType()->getType(); $properties = array(); foreach ($this->getLanguages() as $lang) { $properties[$lang] = $this->createProperty( $originalName.ucfirst($lang), $originalType, // des inner types // vererbe vom type, aber nur nullable+unique, alle anderen flags maskieren, die virtuelleln properties haben keine setter/getter und keinen docblock ($originalFlags & (self::NULLABLE | self::UNIQUE)) | self::WITHOUT_GETTER | self::WITHOUT_SETTER, ($originalUpperCaseName) ? $originalUpperCaseName.ucfirst($lang) : NULL ); $this->setForcedMetaProperty($properties[$lang], FALSE); // nicht in die meta exportieren, weil wir sie da nicht wollen, das i18n-property schon! } // wir müssen den initialisierungs code für den i18n array in den getter injecten $initCode = array(); $initCode[] = sprintf('if (count($this->%s) == 0) {', $property->getName()); foreach ($this->getLanguages() as $lang) { $initCode[] = sprintf(' $this->%s[\'%s\'] = $this->%s;', $property->getName(), $lang, $properties[$lang]->getName()); } $initCode[] = '}'; $this->getMethod($property->getGetterName())->beforeBody($initCode); // wir müssen den setter für den i18n Array injecten (der soll die virtuellen properties setzen) $updateCode = array(); foreach ($this->getLanguages() as $lang) { $updateCode[] = sprintf('$this->%s = $this->%s[\'%s\'];', $properties[$lang]->getName(), $property->getName(), $lang); } $this->getMethod($property->getSetterName())->insertBody($updateCode, -1); // vor: return $this; // dann müssen wir getField $getCode = array(); $getCode[] = sprintf('$title = $this->%s();', $property->getGetterName()); $getCode[] = 'return $title[$lang];'; $this->addMethod(new GMethod( 'get'.($originalUpperCaseName ?: ucfirst($originalName)), array(new GParameter('lang', NULL)), $getCode )); // und setField bauen $setCode = array(); // wir könnten uns noch überlegen bei else: eine exception zu schmeissen? foreach ($this->getLanguages() as $key=>$lang) { if ($key === 0) { $setCode[] = sprintf('if ($lang === \'%s\') {', $lang); } else { $setCode[] = sprintf('} elseif ($lang === \'%s\') {', $lang); } // setze klassenVariable und i18nVariable auf den neuen Wert $setCode[] = sprintf(' $this->%s = $this->%s[\'%s\'] = $value;', $properties[$lang]->getName(), $property->getName(), $lang); } $setCode[] = '}'; $setCode[] = 'return $this;'; $this->addMethod(new GMethod( 'set'.($originalUpperCaseName ?: ucfirst($originalName)), array(new GParameter('value', $originalType->getPHPHint()), new GParameter('lang', NULL)), $setCode )); }
[ "public", "function", "generateI18nAPI", "(", "ClassBuilderProperty", "$", "property", ",", "$", "originalName", ",", "$", "originalFlags", "=", "0x000000", ",", "$", "originalUpperCaseName", "=", "NULL", ")", "{", "$", "originalType", "=", "$", "property", "->", "getType", "(", ")", "->", "getType", "(", ")", ";", "$", "properties", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "getLanguages", "(", ")", "as", "$", "lang", ")", "{", "$", "properties", "[", "$", "lang", "]", "=", "$", "this", "->", "createProperty", "(", "$", "originalName", ".", "ucfirst", "(", "$", "lang", ")", ",", "$", "originalType", ",", "// des inner types", "// vererbe vom type, aber nur nullable+unique, alle anderen flags maskieren, die virtuelleln properties haben keine setter/getter und keinen docblock", "(", "$", "originalFlags", "&", "(", "self", "::", "NULLABLE", "|", "self", "::", "UNIQUE", ")", ")", "|", "self", "::", "WITHOUT_GETTER", "|", "self", "::", "WITHOUT_SETTER", ",", "(", "$", "originalUpperCaseName", ")", "?", "$", "originalUpperCaseName", ".", "ucfirst", "(", "$", "lang", ")", ":", "NULL", ")", ";", "$", "this", "->", "setForcedMetaProperty", "(", "$", "properties", "[", "$", "lang", "]", ",", "FALSE", ")", ";", "// nicht in die meta exportieren, weil wir sie da nicht wollen, das i18n-property schon!", "}", "// wir müssen den initialisierungs code für den i18n array in den getter injecten", "$", "initCode", "=", "array", "(", ")", ";", "$", "initCode", "[", "]", "=", "sprintf", "(", "'if (count($this->%s) == 0) {'", ",", "$", "property", "->", "getName", "(", ")", ")", ";", "foreach", "(", "$", "this", "->", "getLanguages", "(", ")", "as", "$", "lang", ")", "{", "$", "initCode", "[", "]", "=", "sprintf", "(", "' $this->%s[\\'%s\\'] = $this->%s;'", ",", "$", "property", "->", "getName", "(", ")", ",", "$", "lang", ",", "$", "properties", "[", "$", "lang", "]", "->", "getName", "(", ")", ")", ";", "}", "$", "initCode", "[", "]", "=", "'}'", ";", "$", "this", "->", "getMethod", "(", "$", "property", "->", "getGetterName", "(", ")", ")", "->", "beforeBody", "(", "$", "initCode", ")", ";", "// wir müssen den setter für den i18n Array injecten (der soll die virtuellen properties setzen)", "$", "updateCode", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "getLanguages", "(", ")", "as", "$", "lang", ")", "{", "$", "updateCode", "[", "]", "=", "sprintf", "(", "'$this->%s = $this->%s[\\'%s\\'];'", ",", "$", "properties", "[", "$", "lang", "]", "->", "getName", "(", ")", ",", "$", "property", "->", "getName", "(", ")", ",", "$", "lang", ")", ";", "}", "$", "this", "->", "getMethod", "(", "$", "property", "->", "getSetterName", "(", ")", ")", "->", "insertBody", "(", "$", "updateCode", ",", "-", "1", ")", ";", "// vor: return $this;", "// dann müssen wir getField", "$", "getCode", "=", "array", "(", ")", ";", "$", "getCode", "[", "]", "=", "sprintf", "(", "'$title = $this->%s();'", ",", "$", "property", "->", "getGetterName", "(", ")", ")", ";", "$", "getCode", "[", "]", "=", "'return $title[$lang];'", ";", "$", "this", "->", "addMethod", "(", "new", "GMethod", "(", "'get'", ".", "(", "$", "originalUpperCaseName", "?", ":", "ucfirst", "(", "$", "originalName", ")", ")", ",", "array", "(", "new", "GParameter", "(", "'lang'", ",", "NULL", ")", ")", ",", "$", "getCode", ")", ")", ";", "// und setField bauen", "$", "setCode", "=", "array", "(", ")", ";", "// wir könnten uns noch überlegen bei else: eine exception zu schmeissen?", "foreach", "(", "$", "this", "->", "getLanguages", "(", ")", "as", "$", "key", "=>", "$", "lang", ")", "{", "if", "(", "$", "key", "===", "0", ")", "{", "$", "setCode", "[", "]", "=", "sprintf", "(", "'if ($lang === \\'%s\\') {'", ",", "$", "lang", ")", ";", "}", "else", "{", "$", "setCode", "[", "]", "=", "sprintf", "(", "'} elseif ($lang === \\'%s\\') {'", ",", "$", "lang", ")", ";", "}", "// setze klassenVariable und i18nVariable auf den neuen Wert", "$", "setCode", "[", "]", "=", "sprintf", "(", "' $this->%s = $this->%s[\\'%s\\'] = $value;'", ",", "$", "properties", "[", "$", "lang", "]", "->", "getName", "(", ")", ",", "$", "property", "->", "getName", "(", ")", ",", "$", "lang", ")", ";", "}", "$", "setCode", "[", "]", "=", "'}'", ";", "$", "setCode", "[", "]", "=", "'return $this;'", ";", "$", "this", "->", "addMethod", "(", "new", "GMethod", "(", "'set'", ".", "(", "$", "originalUpperCaseName", "?", ":", "ucfirst", "(", "$", "originalName", ")", ")", ",", "array", "(", "new", "GParameter", "(", "'value'", ",", "$", "originalType", "->", "getPHPHint", "(", ")", ")", ",", "new", "GParameter", "(", "'lang'", ",", "NULL", ")", ")", ",", "$", "setCode", ")", ")", ";", "}" ]
Erstellt die i18nAPI für ein i18nProperty i18nPropertyName ist title: erstellt einen virtuellen Getter für den OriginalNamen des Properties (getTitle($lang)) erstellt einen virtuellen Setter für den OriginalNamen des Properties (setTitle($value, $lang)) setI18nTitle(Array $titles); getI18nTitle() -> array gibt es schon zusätzlich müssen wir die Properties (welche nicht im MetaSet sind) erstellen: titleDe, titleEn, usw je nach $this->languages alle ohne getter
[ "Erstellt", "die", "i18nAPI", "für", "ein", "i18nProperty" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/EntityBuilder.php#L216-L281
webforge-labs/psc-cms
lib/Psc/Doctrine/EntityBuilder.php
EntityBuilder.createRelation
public function createRelation($relationType, EntityRelationMeta $source, EntityRelationMeta $target, $side = NULL, $updateOtherSide = true) { Code::value($relationType, self::RELATION_MANY_TO_MANY, self::RELATION_MANY_TO_ONE, self::RELATION_ONE_TO_MANY, self::RELATION_ONE_TO_ONE); Code::value($side, self::SIDE_OWNING, self::SIDE_INVERSE, NULL); // Parameter übersetzen in constructor parameter von relation if ($side !== NULL) { $direction = EntityRelation::BIDIRECTIONAL; $whoIsOwningSide = $side === self::SIDE_OWNING ? EntityRelation::SOURCE : EntityRelation::TARGET; } else { $direction = EntityRelation::UNIDIRECTIONAL; $whoIsOwningSide = NULL; } $relation = new EntityRelation($source, $target, $relationType, $direction, $whoIsOwningSide); $this->buildRelation($relation); return $relation; }
php
public function createRelation($relationType, EntityRelationMeta $source, EntityRelationMeta $target, $side = NULL, $updateOtherSide = true) { Code::value($relationType, self::RELATION_MANY_TO_MANY, self::RELATION_MANY_TO_ONE, self::RELATION_ONE_TO_MANY, self::RELATION_ONE_TO_ONE); Code::value($side, self::SIDE_OWNING, self::SIDE_INVERSE, NULL); // Parameter übersetzen in constructor parameter von relation if ($side !== NULL) { $direction = EntityRelation::BIDIRECTIONAL; $whoIsOwningSide = $side === self::SIDE_OWNING ? EntityRelation::SOURCE : EntityRelation::TARGET; } else { $direction = EntityRelation::UNIDIRECTIONAL; $whoIsOwningSide = NULL; } $relation = new EntityRelation($source, $target, $relationType, $direction, $whoIsOwningSide); $this->buildRelation($relation); return $relation; }
[ "public", "function", "createRelation", "(", "$", "relationType", ",", "EntityRelationMeta", "$", "source", ",", "EntityRelationMeta", "$", "target", ",", "$", "side", "=", "NULL", ",", "$", "updateOtherSide", "=", "true", ")", "{", "Code", "::", "value", "(", "$", "relationType", ",", "self", "::", "RELATION_MANY_TO_MANY", ",", "self", "::", "RELATION_MANY_TO_ONE", ",", "self", "::", "RELATION_ONE_TO_MANY", ",", "self", "::", "RELATION_ONE_TO_ONE", ")", ";", "Code", "::", "value", "(", "$", "side", ",", "self", "::", "SIDE_OWNING", ",", "self", "::", "SIDE_INVERSE", ",", "NULL", ")", ";", "// Parameter übersetzen in constructor parameter von relation", "if", "(", "$", "side", "!==", "NULL", ")", "{", "$", "direction", "=", "EntityRelation", "::", "BIDIRECTIONAL", ";", "$", "whoIsOwningSide", "=", "$", "side", "===", "self", "::", "SIDE_OWNING", "?", "EntityRelation", "::", "SOURCE", ":", "EntityRelation", "::", "TARGET", ";", "}", "else", "{", "$", "direction", "=", "EntityRelation", "::", "UNIDIRECTIONAL", ";", "$", "whoIsOwningSide", "=", "NULL", ";", "}", "$", "relation", "=", "new", "EntityRelation", "(", "$", "source", ",", "$", "target", ",", "$", "relationType", ",", "$", "direction", ",", "$", "whoIsOwningSide", ")", ";", "$", "this", "->", "buildRelation", "(", "$", "relation", ")", ";", "return", "$", "relation", ";", "}" ]
Legacy Interface für den ModelCompiler (für den ersten Wurf) erstellt eine Relation und ruft direkt buildRelation auf @return EntityRelation
[ "Legacy", "Interface", "für", "den", "ModelCompiler", "(", "für", "den", "ersten", "Wurf", ")" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/EntityBuilder.php#L299-L316
webforge-labs/psc-cms
lib/Psc/Doctrine/EntityBuilder.php
EntityBuilder.buildSetMetaGetter
public function buildSetMetaGetter(CodeExporter $codeExporter = NULL) { if (!isset($codeExporter)) $codeExporter = new CodeExporter(new CodeWriter); $code = array(); $code[] = 'return new \Psc\Data\SetMeta(array('; foreach ($this->getProperties() as $property) { if ($property->getWasElevated()) continue; if (!$this->isMetaProperty($property)) continue; if ($property->getType() === NULL) throw new EntityBuilderException('Property '.$property->getName().' hat keinen Typ!'); $code[] = sprintf(" '%s' => %s,", $property->getName(), $codeExporter->exportType($property->getType())); } $code[] = '));'; $this->createMethod( 'getSetMeta', array(), $code, GMethod::MODIFIER_STATIC | GMethod::MODIFIER_PUBLIC ); return $this; }
php
public function buildSetMetaGetter(CodeExporter $codeExporter = NULL) { if (!isset($codeExporter)) $codeExporter = new CodeExporter(new CodeWriter); $code = array(); $code[] = 'return new \Psc\Data\SetMeta(array('; foreach ($this->getProperties() as $property) { if ($property->getWasElevated()) continue; if (!$this->isMetaProperty($property)) continue; if ($property->getType() === NULL) throw new EntityBuilderException('Property '.$property->getName().' hat keinen Typ!'); $code[] = sprintf(" '%s' => %s,", $property->getName(), $codeExporter->exportType($property->getType())); } $code[] = '));'; $this->createMethod( 'getSetMeta', array(), $code, GMethod::MODIFIER_STATIC | GMethod::MODIFIER_PUBLIC ); return $this; }
[ "public", "function", "buildSetMetaGetter", "(", "CodeExporter", "$", "codeExporter", "=", "NULL", ")", "{", "if", "(", "!", "isset", "(", "$", "codeExporter", ")", ")", "$", "codeExporter", "=", "new", "CodeExporter", "(", "new", "CodeWriter", ")", ";", "$", "code", "=", "array", "(", ")", ";", "$", "code", "[", "]", "=", "'return new \\Psc\\Data\\SetMeta(array('", ";", "foreach", "(", "$", "this", "->", "getProperties", "(", ")", "as", "$", "property", ")", "{", "if", "(", "$", "property", "->", "getWasElevated", "(", ")", ")", "continue", ";", "if", "(", "!", "$", "this", "->", "isMetaProperty", "(", "$", "property", ")", ")", "continue", ";", "if", "(", "$", "property", "->", "getType", "(", ")", "===", "NULL", ")", "throw", "new", "EntityBuilderException", "(", "'Property '", ".", "$", "property", "->", "getName", "(", ")", ".", "' hat keinen Typ!'", ")", ";", "$", "code", "[", "]", "=", "sprintf", "(", "\" '%s' => %s,\"", ",", "$", "property", "->", "getName", "(", ")", ",", "$", "codeExporter", "->", "exportType", "(", "$", "property", "->", "getType", "(", ")", ")", ")", ";", "}", "$", "code", "[", "]", "=", "'));'", ";", "$", "this", "->", "createMethod", "(", "'getSetMeta'", ",", "array", "(", ")", ",", "$", "code", ",", "GMethod", "::", "MODIFIER_STATIC", "|", "GMethod", "::", "MODIFIER_PUBLIC", ")", ";", "return", "$", "this", ";", "}" ]
Erstellt eine Funktion die für das Entity eine SetMeta mit allen Properties zurückgibt @chainable
[ "Erstellt", "eine", "Funktion", "die", "für", "das", "Entity", "eine", "SetMeta", "mit", "allen", "Properties", "zurückgibt" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/EntityBuilder.php#L414-L438
webforge-labs/psc-cms
lib/Psc/Doctrine/EntityBuilder.php
EntityBuilder.isMetaProperty
public function isMetaProperty($property) { if (array_key_exists($property->getName(), $this->forcedMetaProperties)) return $this->forcedMetaProperties[$property->getName()]; return TRUE; }
php
public function isMetaProperty($property) { if (array_key_exists($property->getName(), $this->forcedMetaProperties)) return $this->forcedMetaProperties[$property->getName()]; return TRUE; }
[ "public", "function", "isMetaProperty", "(", "$", "property", ")", "{", "if", "(", "array_key_exists", "(", "$", "property", "->", "getName", "(", ")", ",", "$", "this", "->", "forcedMetaProperties", ")", ")", "return", "$", "this", "->", "forcedMetaProperties", "[", "$", "property", "->", "getName", "(", ")", "]", ";", "return", "TRUE", ";", "}" ]
Soll dsa Property z.b. im SetMetaGetter genannt werden?
[ "Soll", "dsa", "Property", "z", ".", "b", ".", "im", "SetMetaGetter", "genannt", "werden?" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/EntityBuilder.php#L443-L447
webforge-labs/psc-cms
lib/Psc/Doctrine/EntityBuilder.php
EntityBuilder.getTableName
public function getTableName() { if (!isset($this->tableName)) { return \Doctrine\Common\Util\Inflector::tableize($this->getEntityName()).'s'; } return $this->tableName; }
php
public function getTableName() { if (!isset($this->tableName)) { return \Doctrine\Common\Util\Inflector::tableize($this->getEntityName()).'s'; } return $this->tableName; }
[ "public", "function", "getTableName", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "tableName", ")", ")", "{", "return", "\\", "Doctrine", "\\", "Common", "\\", "Util", "\\", "Inflector", "::", "tableize", "(", "$", "this", "->", "getEntityName", "(", ")", ")", ".", "'s'", ";", "}", "return", "$", "this", "->", "tableName", ";", "}" ]
return string@
[ "return", "string" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/EntityBuilder.php#L641-L646
ClanCats/Core
src/classes/CCIn/Instance.php
CCIn_Instance.get
public function get( $key, $default = null ) { if ( !isset( $this->GET[$key] ) ) { return $default; } return $this->GET[$key]; }
php
public function get( $key, $default = null ) { if ( !isset( $this->GET[$key] ) ) { return $default; } return $this->GET[$key]; }
[ "public", "function", "get", "(", "$", "key", ",", "$", "default", "=", "null", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "GET", "[", "$", "key", "]", ")", ")", "{", "return", "$", "default", ";", "}", "return", "$", "this", "->", "GET", "[", "$", "key", "]", ";", "}" ]
get a GET param @param string $key @param mixed $default @return mixed
[ "get", "a", "GET", "param" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCIn/Instance.php#L77-L84
ClanCats/Core
src/classes/CCIn/Instance.php
CCIn_Instance.post
public function post( $key, $default = null ) { if ( !isset( $this->POST[$key] ) ) { return $default; } return $this->POST[$key]; }
php
public function post( $key, $default = null ) { if ( !isset( $this->POST[$key] ) ) { return $default; } return $this->POST[$key]; }
[ "public", "function", "post", "(", "$", "key", ",", "$", "default", "=", "null", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "POST", "[", "$", "key", "]", ")", ")", "{", "return", "$", "default", ";", "}", "return", "$", "this", "->", "POST", "[", "$", "key", "]", ";", "}" ]
get a POST param @param string $key @param mixed $default @return mixed
[ "get", "a", "POST", "param" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCIn/Instance.php#L104-L111
ClanCats/Core
src/classes/CCIn/Instance.php
CCIn_Instance.server
public function server( $key, $default = null ) { if ( !isset( $this->SERVER[strtoupper( $key )] ) ) { return $default; } return $this->SERVER[strtoupper( $key )]; }
php
public function server( $key, $default = null ) { if ( !isset( $this->SERVER[strtoupper( $key )] ) ) { return $default; } return $this->SERVER[strtoupper( $key )]; }
[ "public", "function", "server", "(", "$", "key", ",", "$", "default", "=", "null", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "SERVER", "[", "strtoupper", "(", "$", "key", ")", "]", ")", ")", "{", "return", "$", "default", ";", "}", "return", "$", "this", "->", "SERVER", "[", "strtoupper", "(", "$", "key", ")", "]", ";", "}" ]
get a SERVER param @param string $key @return mixed
[ "get", "a", "SERVER", "param" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCIn/Instance.php#L130-L136
ClanCats/Core
src/classes/CCIn/Instance.php
CCIn_Instance.file
public function file( $key, $default = null ) { if ( !isset( $this->FILES[$key] ) ) { return $default; } return $this->FILES[$key]; }
php
public function file( $key, $default = null ) { if ( !isset( $this->FILES[$key] ) ) { return $default; } return $this->FILES[$key]; }
[ "public", "function", "file", "(", "$", "key", ",", "$", "default", "=", "null", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "FILES", "[", "$", "key", "]", ")", ")", "{", "return", "$", "default", ";", "}", "return", "$", "this", "->", "FILES", "[", "$", "key", "]", ";", "}" ]
get a FILE param @param string $key @param mixed $default @return mixed
[ "get", "a", "FILE", "param" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCIn/Instance.php#L156-L163
ClanCats/Core
src/classes/CCIn/Instance.php
CCIn_Instance.client
public function client( $key = null ) { // check if we already set the client object if ( is_null( $this->client ) ) { // make client $this->client = new \stdClass; /* * get clients ip address */ // Cloudlfare fix if ( $this->has_server( 'HTTP_CF_CONNECTING_IP' ) ) { $this->client->ip = $this->server( 'HTTP_CF_CONNECTING_IP' ); } // proxy? elseif ( $this->has_server( 'HTTP_X_FORWARDED_FOR' ) ) { $this->client->ip = $this->server( 'HTTP_X_FORWARDED_FOR' ); } // another proxy? elseif ( $this->has_server( 'HTTP_CLIENT_IP' ) ) { $this->client->ip = $this->server( 'HTTP_CLIENT_IP' ); } // or default else { $this->client->ip = $this->server( 'REMOTE_ADDR', '127.0.0.1' ); } /* * set clients user agent */ $this->client->agent = $this->server( 'HTTP_USER_AGENT', '' ); /* * set clients port */ $this->client->port = $this->server( 'REMOTE_PORT', '' ); /* * set clients fingerprint based on host and agent */ $this->client->fingerprint = CCStr::hash( $this->client('agent').$this->client('ip') ); /* * set clients language */ $this->client->language = CCLang::set_current( $this->server( 'HTTP_ACCEPT_LANGUAGE' ) ); } // return the object if ( is_null( $key ) ) { return $this->client; } // return a special key return $this->client->{$key}; }
php
public function client( $key = null ) { // check if we already set the client object if ( is_null( $this->client ) ) { // make client $this->client = new \stdClass; /* * get clients ip address */ // Cloudlfare fix if ( $this->has_server( 'HTTP_CF_CONNECTING_IP' ) ) { $this->client->ip = $this->server( 'HTTP_CF_CONNECTING_IP' ); } // proxy? elseif ( $this->has_server( 'HTTP_X_FORWARDED_FOR' ) ) { $this->client->ip = $this->server( 'HTTP_X_FORWARDED_FOR' ); } // another proxy? elseif ( $this->has_server( 'HTTP_CLIENT_IP' ) ) { $this->client->ip = $this->server( 'HTTP_CLIENT_IP' ); } // or default else { $this->client->ip = $this->server( 'REMOTE_ADDR', '127.0.0.1' ); } /* * set clients user agent */ $this->client->agent = $this->server( 'HTTP_USER_AGENT', '' ); /* * set clients port */ $this->client->port = $this->server( 'REMOTE_PORT', '' ); /* * set clients fingerprint based on host and agent */ $this->client->fingerprint = CCStr::hash( $this->client('agent').$this->client('ip') ); /* * set clients language */ $this->client->language = CCLang::set_current( $this->server( 'HTTP_ACCEPT_LANGUAGE' ) ); } // return the object if ( is_null( $key ) ) { return $this->client; } // return a special key return $this->client->{$key}; }
[ "public", "function", "client", "(", "$", "key", "=", "null", ")", "{", "// check if we already set the client object", "if", "(", "is_null", "(", "$", "this", "->", "client", ")", ")", "{", "// make client ", "$", "this", "->", "client", "=", "new", "\\", "stdClass", ";", "/*\n\t\t\t * get clients ip address\n\t\t\t */", "// Cloudlfare fix ", "if", "(", "$", "this", "->", "has_server", "(", "'HTTP_CF_CONNECTING_IP'", ")", ")", "{", "$", "this", "->", "client", "->", "ip", "=", "$", "this", "->", "server", "(", "'HTTP_CF_CONNECTING_IP'", ")", ";", "}", "// proxy?", "elseif", "(", "$", "this", "->", "has_server", "(", "'HTTP_X_FORWARDED_FOR'", ")", ")", "{", "$", "this", "->", "client", "->", "ip", "=", "$", "this", "->", "server", "(", "'HTTP_X_FORWARDED_FOR'", ")", ";", "}", "// another proxy?", "elseif", "(", "$", "this", "->", "has_server", "(", "'HTTP_CLIENT_IP'", ")", ")", "{", "$", "this", "->", "client", "->", "ip", "=", "$", "this", "->", "server", "(", "'HTTP_CLIENT_IP'", ")", ";", "}", "// or default", "else", "{", "$", "this", "->", "client", "->", "ip", "=", "$", "this", "->", "server", "(", "'REMOTE_ADDR'", ",", "'127.0.0.1'", ")", ";", "}", "/*\n\t\t\t * set clients user agent\n\t\t\t */", "$", "this", "->", "client", "->", "agent", "=", "$", "this", "->", "server", "(", "'HTTP_USER_AGENT'", ",", "''", ")", ";", "/*\n\t\t\t * set clients port\n\t\t\t */", "$", "this", "->", "client", "->", "port", "=", "$", "this", "->", "server", "(", "'REMOTE_PORT'", ",", "''", ")", ";", "/*\n\t\t\t * set clients fingerprint based on host and agent\n\t\t\t */", "$", "this", "->", "client", "->", "fingerprint", "=", "CCStr", "::", "hash", "(", "$", "this", "->", "client", "(", "'agent'", ")", ".", "$", "this", "->", "client", "(", "'ip'", ")", ")", ";", "/*\n\t\t\t * set clients language\n\t\t\t */", "$", "this", "->", "client", "->", "language", "=", "CCLang", "::", "set_current", "(", "$", "this", "->", "server", "(", "'HTTP_ACCEPT_LANGUAGE'", ")", ")", ";", "}", "// return the object", "if", "(", "is_null", "(", "$", "key", ")", ")", "{", "return", "$", "this", "->", "client", ";", "}", "// return a special key", "return", "$", "this", "->", "client", "->", "{", "$", "key", "}", ";", "}" ]
get the client data @param string $key @return mixed
[ "get", "the", "client", "data" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCIn/Instance.php#L182-L243
ClanCats/Core
src/classes/CCIn/Instance.php
CCIn_Instance.method
public function method( $is = null ) { if ( !is_null( $is ) ) { return strtoupper( $is ) === $this->method(); } return strtoupper( $this->server( 'HTTP_X_HTTP_METHOD_OVERRIDE', $this->server( 'REQUEST_METHOD', 'GET' ) ) ); }
php
public function method( $is = null ) { if ( !is_null( $is ) ) { return strtoupper( $is ) === $this->method(); } return strtoupper( $this->server( 'HTTP_X_HTTP_METHOD_OVERRIDE', $this->server( 'REQUEST_METHOD', 'GET' ) ) ); }
[ "public", "function", "method", "(", "$", "is", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "is", ")", ")", "{", "return", "strtoupper", "(", "$", "is", ")", "===", "$", "this", "->", "method", "(", ")", ";", "}", "return", "strtoupper", "(", "$", "this", "->", "server", "(", "'HTTP_X_HTTP_METHOD_OVERRIDE'", ",", "$", "this", "->", "server", "(", "'REQUEST_METHOD'", ",", "'GET'", ")", ")", ")", ";", "}" ]
get the current requesting method GET, POST, PUT, DELETE @param string $is @return string
[ "get", "the", "current", "requesting", "method", "GET", "POST", "PUT", "DELETE" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCIn/Instance.php#L252-L260
ClanCats/Core
src/classes/CCIn/Instance.php
CCIn_Instance.uri
public function uri( $full = false ) { // check if we already set the current uri if ( is_null( $this->uri ) ) { $this->uri = $this->server('REQUEST_URI', '/' ); // fix doubled slashes $this->uri = preg_replace( '/(\/+)/','/', $this->uri ); // remove get params if ( !$full ) { $this->uri = CCStr::cut( $this->uri, '?' ); } // cut the offset from the config $this->uri = substr( $this->uri, strlen( ClanCats::$config->get( 'url.path' ) ) ); // if null or false set to default if ( !$this->uri ) { $this->uri = ''; } } return $this->uri; }
php
public function uri( $full = false ) { // check if we already set the current uri if ( is_null( $this->uri ) ) { $this->uri = $this->server('REQUEST_URI', '/' ); // fix doubled slashes $this->uri = preg_replace( '/(\/+)/','/', $this->uri ); // remove get params if ( !$full ) { $this->uri = CCStr::cut( $this->uri, '?' ); } // cut the offset from the config $this->uri = substr( $this->uri, strlen( ClanCats::$config->get( 'url.path' ) ) ); // if null or false set to default if ( !$this->uri ) { $this->uri = ''; } } return $this->uri; }
[ "public", "function", "uri", "(", "$", "full", "=", "false", ")", "{", "// check if we already set the current uri", "if", "(", "is_null", "(", "$", "this", "->", "uri", ")", ")", "{", "$", "this", "->", "uri", "=", "$", "this", "->", "server", "(", "'REQUEST_URI'", ",", "'/'", ")", ";", "// fix doubled slashes", "$", "this", "->", "uri", "=", "preg_replace", "(", "'/(\\/+)/'", ",", "'/'", ",", "$", "this", "->", "uri", ")", ";", "// remove get params", "if", "(", "!", "$", "full", ")", "{", "$", "this", "->", "uri", "=", "CCStr", "::", "cut", "(", "$", "this", "->", "uri", ",", "'?'", ")", ";", "}", "// cut the offset from the config", "$", "this", "->", "uri", "=", "substr", "(", "$", "this", "->", "uri", ",", "strlen", "(", "ClanCats", "::", "$", "config", "->", "get", "(", "'url.path'", ")", ")", ")", ";", "// if null or false set to default", "if", "(", "!", "$", "this", "->", "uri", ")", "{", "$", "this", "->", "uri", "=", "''", ";", "}", "}", "return", "$", "this", "->", "uri", ";", "}" ]
get the requestet uri @param bool $full Don't cut the get params @return string
[ "get", "the", "requestet", "uri" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCIn/Instance.php#L308-L334
ClanCats/Core
src/bundles/Database/Handler/Driver.php
Handler_Driver.connect
public function connect( $conf ) { $connection_params = array(); foreach( $conf as $key => $value ) { if ( is_string( $value ) ) { $connection_params[ '{'.$key.'}' ] = $value; } } $connection_string = \CCStr::replace( $this->connection_string, $connection_params ); $this->connection = new \PDO( $connection_string, $conf['user'], $conf['pass'], $this->connection_attributes( $conf ) ); // At the moment this will never happen because pdo is going to // trhow an exception when the connection fails /*if ( !$this->connection ) { return false; }*/ // let pdo throw exceptions $this->connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); return true; }
php
public function connect( $conf ) { $connection_params = array(); foreach( $conf as $key => $value ) { if ( is_string( $value ) ) { $connection_params[ '{'.$key.'}' ] = $value; } } $connection_string = \CCStr::replace( $this->connection_string, $connection_params ); $this->connection = new \PDO( $connection_string, $conf['user'], $conf['pass'], $this->connection_attributes( $conf ) ); // At the moment this will never happen because pdo is going to // trhow an exception when the connection fails /*if ( !$this->connection ) { return false; }*/ // let pdo throw exceptions $this->connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); return true; }
[ "public", "function", "connect", "(", "$", "conf", ")", "{", "$", "connection_params", "=", "array", "(", ")", ";", "foreach", "(", "$", "conf", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_string", "(", "$", "value", ")", ")", "{", "$", "connection_params", "[", "'{'", ".", "$", "key", ".", "'}'", "]", "=", "$", "value", ";", "}", "}", "$", "connection_string", "=", "\\", "CCStr", "::", "replace", "(", "$", "this", "->", "connection_string", ",", "$", "connection_params", ")", ";", "$", "this", "->", "connection", "=", "new", "\\", "PDO", "(", "$", "connection_string", ",", "$", "conf", "[", "'user'", "]", ",", "$", "conf", "[", "'pass'", "]", ",", "$", "this", "->", "connection_attributes", "(", "$", "conf", ")", ")", ";", "// At the moment this will never happen because pdo is going to ", "// trhow an exception when the connection fails", "/*if ( !$this->connection )\n\t\t{\n\t\t\treturn false;\n\t\t}*/", "// let pdo throw exceptions", "$", "this", "->", "connection", "->", "setAttribute", "(", "\\", "PDO", "::", "ATTR_ERRMODE", ",", "\\", "PDO", "::", "ERRMODE_EXCEPTION", ")", ";", "return", "true", ";", "}" ]
connect to database @param array $conf @return bool
[ "connect", "to", "database" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Handler/Driver.php#L34-L61
mihai-stancu/serializer
Serializer/Encoder/UbjsonEncoder.php
UbjsonEncoder.decode
public function decode($data, $format, array $context = array()) { $value = Encoder::decode($data, Encoder::TYPE_ARRAY); return $value; }
php
public function decode($data, $format, array $context = array()) { $value = Encoder::decode($data, Encoder::TYPE_ARRAY); return $value; }
[ "public", "function", "decode", "(", "$", "data", ",", "$", "format", ",", "array", "$", "context", "=", "array", "(", ")", ")", "{", "$", "value", "=", "Encoder", "::", "decode", "(", "$", "data", ",", "Encoder", "::", "TYPE_ARRAY", ")", ";", "return", "$", "value", ";", "}" ]
@param string $data @param string $format @param array $context @return mixed
[ "@param", "string", "$data", "@param", "string", "$format", "@param", "array", "$context" ]
train
https://github.com/mihai-stancu/serializer/blob/4d96f942a3c44d5b5652868be726af656bf1baad/Serializer/Encoder/UbjsonEncoder.php#L45-L50
drnkwati/guzzle-promises
src/Promise.php
Promise.__callHandler
public static function __callHandler($index, $value, array $handler) { /** @var PromiseInterface $promise */ $promise = $handler[0]; // The promise may have been cancelled or resolved before placing // this thunk in the queue. if ($promise->getState() !== self::PENDING) { return; } try { if (isset($handler[$index])) { $promise->resolve(call_user_func($handler[$index], $value)); } elseif ($index === 1) { // Forward resolution values as-is. $promise->resolve($value); } else { // Forward rejections down the chain. $promise->reject($value); } } catch (\Throwable $reason) { $promise->reject($reason); } catch (\Exception $reason) { $promise->reject($reason); } }
php
public static function __callHandler($index, $value, array $handler) { /** @var PromiseInterface $promise */ $promise = $handler[0]; // The promise may have been cancelled or resolved before placing // this thunk in the queue. if ($promise->getState() !== self::PENDING) { return; } try { if (isset($handler[$index])) { $promise->resolve(call_user_func($handler[$index], $value)); } elseif ($index === 1) { // Forward resolution values as-is. $promise->resolve($value); } else { // Forward rejections down the chain. $promise->reject($value); } } catch (\Throwable $reason) { $promise->reject($reason); } catch (\Exception $reason) { $promise->reject($reason); } }
[ "public", "static", "function", "__callHandler", "(", "$", "index", ",", "$", "value", ",", "array", "$", "handler", ")", "{", "/** @var PromiseInterface $promise */", "$", "promise", "=", "$", "handler", "[", "0", "]", ";", "// The promise may have been cancelled or resolved before placing", "// this thunk in the queue.", "if", "(", "$", "promise", "->", "getState", "(", ")", "!==", "self", "::", "PENDING", ")", "{", "return", ";", "}", "try", "{", "if", "(", "isset", "(", "$", "handler", "[", "$", "index", "]", ")", ")", "{", "$", "promise", "->", "resolve", "(", "call_user_func", "(", "$", "handler", "[", "$", "index", "]", ",", "$", "value", ")", ")", ";", "}", "elseif", "(", "$", "index", "===", "1", ")", "{", "// Forward resolution values as-is.", "$", "promise", "->", "resolve", "(", "$", "value", ")", ";", "}", "else", "{", "// Forward rejections down the chain.", "$", "promise", "->", "reject", "(", "$", "value", ")", ";", "}", "}", "catch", "(", "\\", "Throwable", "$", "reason", ")", "{", "$", "promise", "->", "reject", "(", "$", "reason", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "reason", ")", "{", "$", "promise", "->", "reject", "(", "$", "reason", ")", ";", "}", "}" ]
Call a stack of handlers using a specific callback index and value. @internal @param int $index 1 (resolve) or 2 (reject). @param mixed $value Value to pass to the callback. @param array $handler Array of handler data (promise and callbacks). @return array Returns the next group to resolve.
[ "Call", "a", "stack", "of", "handlers", "using", "a", "specific", "callback", "index", "and", "value", "." ]
train
https://github.com/drnkwati/guzzle-promises/blob/e5c302747c348d618474add41c7d442bb1bfc2cf/src/Promise.php#L193-L219
inc2734/wp-share-buttons
src/App/Contract/Model/Requester.php
Requester._add_localize_script
public function _add_localize_script() { $handle = get_template(); if ( ! wp_script_is( get_template() ) && wp_script_is( get_stylesheet() ) ) { $handle = get_stylesheet(); } $handle = apply_filters( 'inc2734_wp_share_buttons_localize_script_handle', $handle ); wp_localize_script( $handle, 'inc2734_wp_share_buttons_' . $this->service_name, [ 'endpoint' => admin_url( 'admin-ajax.php' ), 'action' => 'inc2734_wp_share_buttons_' . $this->service_name, '_ajax_nonce' => wp_create_nonce( $this->_get_nonce_key() ), ] ); }
php
public function _add_localize_script() { $handle = get_template(); if ( ! wp_script_is( get_template() ) && wp_script_is( get_stylesheet() ) ) { $handle = get_stylesheet(); } $handle = apply_filters( 'inc2734_wp_share_buttons_localize_script_handle', $handle ); wp_localize_script( $handle, 'inc2734_wp_share_buttons_' . $this->service_name, [ 'endpoint' => admin_url( 'admin-ajax.php' ), 'action' => 'inc2734_wp_share_buttons_' . $this->service_name, '_ajax_nonce' => wp_create_nonce( $this->_get_nonce_key() ), ] ); }
[ "public", "function", "_add_localize_script", "(", ")", "{", "$", "handle", "=", "get_template", "(", ")", ";", "if", "(", "!", "wp_script_is", "(", "get_template", "(", ")", ")", "&&", "wp_script_is", "(", "get_stylesheet", "(", ")", ")", ")", "{", "$", "handle", "=", "get_stylesheet", "(", ")", ";", "}", "$", "handle", "=", "apply_filters", "(", "'inc2734_wp_share_buttons_localize_script_handle'", ",", "$", "handle", ")", ";", "wp_localize_script", "(", "$", "handle", ",", "'inc2734_wp_share_buttons_'", ".", "$", "this", "->", "service_name", ",", "[", "'endpoint'", "=>", "admin_url", "(", "'admin-ajax.php'", ")", ",", "'action'", "=>", "'inc2734_wp_share_buttons_'", ".", "$", "this", "->", "service_name", ",", "'_ajax_nonce'", "=>", "wp_create_nonce", "(", "$", "this", "->", "_get_nonce_key", "(", ")", ")", ",", "]", ")", ";", "}" ]
Setup localize script @return void
[ "Setup", "localize", "script" ]
train
https://github.com/inc2734/wp-share-buttons/blob/cd032893ca083a343f5871e855cce68f4ede3a17/src/App/Contract/Model/Requester.php#L44-L60
inc2734/wp-share-buttons
src/App/Contract/Model/Requester.php
Requester._ajax
public function _ajax() { check_ajax_referer( $this->_get_nonce_key() ); if ( ! isset( $_GET['post_id'] ) ) { $this->_send_json( '-' ); return; } $post_id = sanitize_text_field( wp_unslash( $_GET['post_id'] ) ); $count_cache = new Count_Cache( $post_id, $this->service_name ); $cache = $count_cache->get(); if ( $cache ) { $this->_send_json( $cache ); return; } $count = $this->_request(); $count_cache->update( $count ); $this->_send_json( $count ); }
php
public function _ajax() { check_ajax_referer( $this->_get_nonce_key() ); if ( ! isset( $_GET['post_id'] ) ) { $this->_send_json( '-' ); return; } $post_id = sanitize_text_field( wp_unslash( $_GET['post_id'] ) ); $count_cache = new Count_Cache( $post_id, $this->service_name ); $cache = $count_cache->get(); if ( $cache ) { $this->_send_json( $cache ); return; } $count = $this->_request(); $count_cache->update( $count ); $this->_send_json( $count ); }
[ "public", "function", "_ajax", "(", ")", "{", "check_ajax_referer", "(", "$", "this", "->", "_get_nonce_key", "(", ")", ")", ";", "if", "(", "!", "isset", "(", "$", "_GET", "[", "'post_id'", "]", ")", ")", "{", "$", "this", "->", "_send_json", "(", "'-'", ")", ";", "return", ";", "}", "$", "post_id", "=", "sanitize_text_field", "(", "wp_unslash", "(", "$", "_GET", "[", "'post_id'", "]", ")", ")", ";", "$", "count_cache", "=", "new", "Count_Cache", "(", "$", "post_id", ",", "$", "this", "->", "service_name", ")", ";", "$", "cache", "=", "$", "count_cache", "->", "get", "(", ")", ";", "if", "(", "$", "cache", ")", "{", "$", "this", "->", "_send_json", "(", "$", "cache", ")", ";", "return", ";", "}", "$", "count", "=", "$", "this", "->", "_request", "(", ")", ";", "$", "count_cache", "->", "update", "(", "$", "count", ")", ";", "$", "this", "->", "_send_json", "(", "$", "count", ")", ";", "}" ]
Ajax @return void
[ "Ajax" ]
train
https://github.com/inc2734/wp-share-buttons/blob/cd032893ca083a343f5871e855cce68f4ede3a17/src/App/Contract/Model/Requester.php#L67-L87
inc2734/wp-share-buttons
src/App/Contract/Model/Requester.php
Requester._request
protected function _request() { if ( empty( $_GET['post_id'] ) ) { return '-'; } $permalink = get_permalink( sanitize_text_field( wp_unslash( $_GET['post_id'] ) ) ); if ( ! $permalink ) { return '-'; } if ( 0 === strpos( $permalink, 'http://' ) ) { $count = $this->_get_count( rawurlencode( $permalink ) ); } elseif ( 0 === strpos( $permalink, 'https://' ) ) { $count = $this->_get_count( rawurlencode( $permalink ) ); if ( apply_filters( 'inc2734_wp_share_buttons_apply_https_total_count', true ) ) { $https_count = $count; $http_count = $this->_get_count( rawurlencode( str_replace( 'https://', 'http://', $permalink ) ) ); $count = $this->_add( $https_count, $http_count ); } } if ( ! is_numeric( $count ) ) { return '-'; } return $count; }
php
protected function _request() { if ( empty( $_GET['post_id'] ) ) { return '-'; } $permalink = get_permalink( sanitize_text_field( wp_unslash( $_GET['post_id'] ) ) ); if ( ! $permalink ) { return '-'; } if ( 0 === strpos( $permalink, 'http://' ) ) { $count = $this->_get_count( rawurlencode( $permalink ) ); } elseif ( 0 === strpos( $permalink, 'https://' ) ) { $count = $this->_get_count( rawurlencode( $permalink ) ); if ( apply_filters( 'inc2734_wp_share_buttons_apply_https_total_count', true ) ) { $https_count = $count; $http_count = $this->_get_count( rawurlencode( str_replace( 'https://', 'http://', $permalink ) ) ); $count = $this->_add( $https_count, $http_count ); } } if ( ! is_numeric( $count ) ) { return '-'; } return $count; }
[ "protected", "function", "_request", "(", ")", "{", "if", "(", "empty", "(", "$", "_GET", "[", "'post_id'", "]", ")", ")", "{", "return", "'-'", ";", "}", "$", "permalink", "=", "get_permalink", "(", "sanitize_text_field", "(", "wp_unslash", "(", "$", "_GET", "[", "'post_id'", "]", ")", ")", ")", ";", "if", "(", "!", "$", "permalink", ")", "{", "return", "'-'", ";", "}", "if", "(", "0", "===", "strpos", "(", "$", "permalink", ",", "'http://'", ")", ")", "{", "$", "count", "=", "$", "this", "->", "_get_count", "(", "rawurlencode", "(", "$", "permalink", ")", ")", ";", "}", "elseif", "(", "0", "===", "strpos", "(", "$", "permalink", ",", "'https://'", ")", ")", "{", "$", "count", "=", "$", "this", "->", "_get_count", "(", "rawurlencode", "(", "$", "permalink", ")", ")", ";", "if", "(", "apply_filters", "(", "'inc2734_wp_share_buttons_apply_https_total_count'", ",", "true", ")", ")", "{", "$", "https_count", "=", "$", "count", ";", "$", "http_count", "=", "$", "this", "->", "_get_count", "(", "rawurlencode", "(", "str_replace", "(", "'https://'", ",", "'http://'", ",", "$", "permalink", ")", ")", ")", ";", "$", "count", "=", "$", "this", "->", "_add", "(", "$", "https_count", ",", "$", "http_count", ")", ";", "}", "}", "if", "(", "!", "is_numeric", "(", "$", "count", ")", ")", "{", "return", "'-'", ";", "}", "return", "$", "count", ";", "}" ]
Request to API @return int Count
[ "Request", "to", "API" ]
train
https://github.com/inc2734/wp-share-buttons/blob/cd032893ca083a343f5871e855cce68f4ede3a17/src/App/Contract/Model/Requester.php#L112-L138
inc2734/wp-share-buttons
src/App/Contract/Model/Requester.php
Requester._add
protected function _add( $arg1, $arg2 ) { if ( is_numeric( $arg1 ) && is_numeric( $arg2 ) ) { return $arg1 + $arg2; } elseif ( is_numeric( $arg2 ) ) { return $arg1; } elseif ( is_numeric( $arg2 ) ) { return $arg2; } return '-'; }
php
protected function _add( $arg1, $arg2 ) { if ( is_numeric( $arg1 ) && is_numeric( $arg2 ) ) { return $arg1 + $arg2; } elseif ( is_numeric( $arg2 ) ) { return $arg1; } elseif ( is_numeric( $arg2 ) ) { return $arg2; } return '-'; }
[ "protected", "function", "_add", "(", "$", "arg1", ",", "$", "arg2", ")", "{", "if", "(", "is_numeric", "(", "$", "arg1", ")", "&&", "is_numeric", "(", "$", "arg2", ")", ")", "{", "return", "$", "arg1", "+", "$", "arg2", ";", "}", "elseif", "(", "is_numeric", "(", "$", "arg2", ")", ")", "{", "return", "$", "arg1", ";", "}", "elseif", "(", "is_numeric", "(", "$", "arg2", ")", ")", "{", "return", "$", "arg2", ";", "}", "return", "'-'", ";", "}" ]
Add count @param int|- $a @param int|- $b
[ "Add", "count" ]
train
https://github.com/inc2734/wp-share-buttons/blob/cd032893ca083a343f5871e855cce68f4ede3a17/src/App/Contract/Model/Requester.php#L146-L156
AydinHassan/cli-md-renderer
src/Renderer/ParagraphRenderer.php
ParagraphRenderer.render
public function render(AbstractBlock $block, CliRenderer $renderer) { if (!($block instanceof Paragraph)) { throw new \InvalidArgumentException(sprintf('Incompatible block type: "%s"', get_class($block))); } return $renderer->renderInlines($block->children()) . "\n"; }
php
public function render(AbstractBlock $block, CliRenderer $renderer) { if (!($block instanceof Paragraph)) { throw new \InvalidArgumentException(sprintf('Incompatible block type: "%s"', get_class($block))); } return $renderer->renderInlines($block->children()) . "\n"; }
[ "public", "function", "render", "(", "AbstractBlock", "$", "block", ",", "CliRenderer", "$", "renderer", ")", "{", "if", "(", "!", "(", "$", "block", "instanceof", "Paragraph", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Incompatible block type: \"%s\"'", ",", "get_class", "(", "$", "block", ")", ")", ")", ";", "}", "return", "$", "renderer", "->", "renderInlines", "(", "$", "block", "->", "children", "(", ")", ")", ".", "\"\\n\"", ";", "}" ]
@param AbstractBlock $block @param CliRenderer $renderer @return string
[ "@param", "AbstractBlock", "$block", "@param", "CliRenderer", "$renderer" ]
train
https://github.com/AydinHassan/cli-md-renderer/blob/521f9ace2aeadd58bf8a3910704be8360f5bd7b2/src/Renderer/ParagraphRenderer.php#L23-L30
rayrutjes/domain-foundation
src/Repository/AggregateRootRepository.php
AggregateRootRepository.load
public function load(AggregateRootIdentifier $aggregateRootIdentifier, $expectedVersion = null) { $eventStream = $this->eventStore->read($this->aggregateRootType, $aggregateRootIdentifier); if ($eventStream->isEmpty()) { throw new AggregateNotFoundException($aggregateRootIdentifier); } $className = $this->aggregateRootType->className(); $aggregateRoot = $className::loadFromHistory($eventStream); $actualVersion = $aggregateRoot->lastCommittedEventSequenceNumber(); if (null !== $expectedVersion && $actualVersion !== $expectedVersion) { throw new ConflictingAggregateVersionException($aggregateRootIdentifier, $actualVersion, $expectedVersion); } return $this->unitOfWork->registerAggregate( $aggregateRoot, $this->eventBus, $this->createSaveAggregateCallback() ); }
php
public function load(AggregateRootIdentifier $aggregateRootIdentifier, $expectedVersion = null) { $eventStream = $this->eventStore->read($this->aggregateRootType, $aggregateRootIdentifier); if ($eventStream->isEmpty()) { throw new AggregateNotFoundException($aggregateRootIdentifier); } $className = $this->aggregateRootType->className(); $aggregateRoot = $className::loadFromHistory($eventStream); $actualVersion = $aggregateRoot->lastCommittedEventSequenceNumber(); if (null !== $expectedVersion && $actualVersion !== $expectedVersion) { throw new ConflictingAggregateVersionException($aggregateRootIdentifier, $actualVersion, $expectedVersion); } return $this->unitOfWork->registerAggregate( $aggregateRoot, $this->eventBus, $this->createSaveAggregateCallback() ); }
[ "public", "function", "load", "(", "AggregateRootIdentifier", "$", "aggregateRootIdentifier", ",", "$", "expectedVersion", "=", "null", ")", "{", "$", "eventStream", "=", "$", "this", "->", "eventStore", "->", "read", "(", "$", "this", "->", "aggregateRootType", ",", "$", "aggregateRootIdentifier", ")", ";", "if", "(", "$", "eventStream", "->", "isEmpty", "(", ")", ")", "{", "throw", "new", "AggregateNotFoundException", "(", "$", "aggregateRootIdentifier", ")", ";", "}", "$", "className", "=", "$", "this", "->", "aggregateRootType", "->", "className", "(", ")", ";", "$", "aggregateRoot", "=", "$", "className", "::", "loadFromHistory", "(", "$", "eventStream", ")", ";", "$", "actualVersion", "=", "$", "aggregateRoot", "->", "lastCommittedEventSequenceNumber", "(", ")", ";", "if", "(", "null", "!==", "$", "expectedVersion", "&&", "$", "actualVersion", "!==", "$", "expectedVersion", ")", "{", "throw", "new", "ConflictingAggregateVersionException", "(", "$", "aggregateRootIdentifier", ",", "$", "actualVersion", ",", "$", "expectedVersion", ")", ";", "}", "return", "$", "this", "->", "unitOfWork", "->", "registerAggregate", "(", "$", "aggregateRoot", ",", "$", "this", "->", "eventBus", ",", "$", "this", "->", "createSaveAggregateCallback", "(", ")", ")", ";", "}" ]
@param AggregateRootIdentifier $aggregateRootIdentifier @param int $expectedVersion @return AggregateRoot @throws AggregateNotFoundException
[ "@param", "AggregateRootIdentifier", "$aggregateRootIdentifier", "@param", "int", "$expectedVersion" ]
train
https://github.com/rayrutjes/domain-foundation/blob/2bce7cd6a6612f718e70e3176589c1abf39d1a3e/src/Repository/AggregateRootRepository.php#L78-L98
rayrutjes/domain-foundation
src/Repository/AggregateRootRepository.php
AggregateRootRepository.doSave
public function doSave(AggregateRoot $aggregateRoot) { $eventStream = $aggregateRoot->uncommittedChanges(); if (!$eventStream->isEmpty()) { $this->eventStore->append($this->aggregateRootType, $eventStream); } }
php
public function doSave(AggregateRoot $aggregateRoot) { $eventStream = $aggregateRoot->uncommittedChanges(); if (!$eventStream->isEmpty()) { $this->eventStore->append($this->aggregateRootType, $eventStream); } }
[ "public", "function", "doSave", "(", "AggregateRoot", "$", "aggregateRoot", ")", "{", "$", "eventStream", "=", "$", "aggregateRoot", "->", "uncommittedChanges", "(", ")", ";", "if", "(", "!", "$", "eventStream", "->", "isEmpty", "(", ")", ")", "{", "$", "this", "->", "eventStore", "->", "append", "(", "$", "this", "->", "aggregateRootType", ",", "$", "eventStream", ")", ";", "}", "}" ]
@internal @param AggregateRoot $aggregateRoot
[ "@internal" ]
train
https://github.com/rayrutjes/domain-foundation/blob/2bce7cd6a6612f718e70e3176589c1abf39d1a3e/src/Repository/AggregateRootRepository.php#L105-L112
phpmob/changmin
src/PhpMob/CmsBundle/Form/Type/PageType.php
PageType.buildForm
public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('translations', ResourceTranslationsType::class, [ 'label' => 'phpmob.form.page.translations', //'label' => false, 'entry_type' => PageTranslationType::class, ]) ->add('enabled', CheckboxType::class, [ 'label' => 'phpmob.form.page.enabled', 'required' => false, ]) ->add('template', TemplateChoiceType::class, [ 'label' => 'phpmob.form.page.template', 'placeholder' => 'phpmob.form.page.template_select', 'required' => false, ]) ->add('script', TextareaType::class, [ 'label' => 'phpmob.form.page.script', 'required' => false, ]) ->add('style', TextareaType::class, [ 'label' => 'phpmob.form.page.style', 'required' => false, ]) ->add('options', YamlType::class, [ 'label' => 'phpmob.form.page.options', 'required' => false, ]) ->add('definedTranslations', YamlType::class, [ 'label' => 'phpmob.form.page.defined_translations', 'required' => false, ]) ; }
php
public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('translations', ResourceTranslationsType::class, [ 'label' => 'phpmob.form.page.translations', //'label' => false, 'entry_type' => PageTranslationType::class, ]) ->add('enabled', CheckboxType::class, [ 'label' => 'phpmob.form.page.enabled', 'required' => false, ]) ->add('template', TemplateChoiceType::class, [ 'label' => 'phpmob.form.page.template', 'placeholder' => 'phpmob.form.page.template_select', 'required' => false, ]) ->add('script', TextareaType::class, [ 'label' => 'phpmob.form.page.script', 'required' => false, ]) ->add('style', TextareaType::class, [ 'label' => 'phpmob.form.page.style', 'required' => false, ]) ->add('options', YamlType::class, [ 'label' => 'phpmob.form.page.options', 'required' => false, ]) ->add('definedTranslations', YamlType::class, [ 'label' => 'phpmob.form.page.defined_translations', 'required' => false, ]) ; }
[ "public", "function", "buildForm", "(", "FormBuilderInterface", "$", "builder", ",", "array", "$", "options", ")", "{", "$", "builder", "->", "add", "(", "'translations'", ",", "ResourceTranslationsType", "::", "class", ",", "[", "'label'", "=>", "'phpmob.form.page.translations'", ",", "//'label' => false,", "'entry_type'", "=>", "PageTranslationType", "::", "class", ",", "]", ")", "->", "add", "(", "'enabled'", ",", "CheckboxType", "::", "class", ",", "[", "'label'", "=>", "'phpmob.form.page.enabled'", ",", "'required'", "=>", "false", ",", "]", ")", "->", "add", "(", "'template'", ",", "TemplateChoiceType", "::", "class", ",", "[", "'label'", "=>", "'phpmob.form.page.template'", ",", "'placeholder'", "=>", "'phpmob.form.page.template_select'", ",", "'required'", "=>", "false", ",", "]", ")", "->", "add", "(", "'script'", ",", "TextareaType", "::", "class", ",", "[", "'label'", "=>", "'phpmob.form.page.script'", ",", "'required'", "=>", "false", ",", "]", ")", "->", "add", "(", "'style'", ",", "TextareaType", "::", "class", ",", "[", "'label'", "=>", "'phpmob.form.page.style'", ",", "'required'", "=>", "false", ",", "]", ")", "->", "add", "(", "'options'", ",", "YamlType", "::", "class", ",", "[", "'label'", "=>", "'phpmob.form.page.options'", ",", "'required'", "=>", "false", ",", "]", ")", "->", "add", "(", "'definedTranslations'", ",", "YamlType", "::", "class", ",", "[", "'label'", "=>", "'phpmob.form.page.defined_translations'", ",", "'required'", "=>", "false", ",", "]", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/CmsBundle/Form/Type/PageType.php#L29-L63
CakeCMS/Core
src/Utility/Macros.php
Macros.get
public function get($key = null) { if (Arr::key($key, $this->_data)) { return $this->_data[$key]; } return $this->_data; }
php
public function get($key = null) { if (Arr::key($key, $this->_data)) { return $this->_data[$key]; } return $this->_data; }
[ "public", "function", "get", "(", "$", "key", "=", "null", ")", "{", "if", "(", "Arr", "::", "key", "(", "$", "key", ",", "$", "this", "->", "_data", ")", ")", "{", "return", "$", "this", "->", "_data", "[", "$", "key", "]", ";", "}", "return", "$", "this", "->", "_data", ";", "}" ]
Get replacement val or all list. @param null|string|int $key @return array
[ "Get", "replacement", "val", "or", "all", "list", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/Utility/Macros.php#L60-L67
CakeCMS/Core
src/Utility/Macros.php
Macros.set
public function set($key, $val) { $this->_data = Hash::merge([$key => $val], $this->_data); return $this; }
php
public function set($key, $val) { $this->_data = Hash::merge([$key => $val], $this->_data); return $this; }
[ "public", "function", "set", "(", "$", "key", ",", "$", "val", ")", "{", "$", "this", "->", "_data", "=", "Hash", "::", "merge", "(", "[", "$", "key", "=>", "$", "val", "]", ",", "$", "this", "->", "_data", ")", ";", "return", "$", "this", ";", "}" ]
Add new value in list. @param string|int $key @param string|int $val @return $this
[ "Add", "new", "value", "in", "list", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/Utility/Macros.php#L76-L80
CakeCMS/Core
src/Utility/Macros.php
Macros.text
public function text($text) { foreach ($this->_data as $macros => $value) { $macros = '{' . $macros . '}'; $text = preg_replace('#' . $macros . '#ius', $value, $text); } return $text; }
php
public function text($text) { foreach ($this->_data as $macros => $value) { $macros = '{' . $macros . '}'; $text = preg_replace('#' . $macros . '#ius', $value, $text); } return $text; }
[ "public", "function", "text", "(", "$", "text", ")", "{", "foreach", "(", "$", "this", "->", "_data", "as", "$", "macros", "=>", "$", "value", ")", "{", "$", "macros", "=", "'{'", ".", "$", "macros", ".", "'}'", ";", "$", "text", "=", "preg_replace", "(", "'#'", ".", "$", "macros", ".", "'#ius'", ",", "$", "value", ",", "$", "text", ")", ";", "}", "return", "$", "text", ";", "}" ]
Get replacement text. @param string $text @return string mixed
[ "Get", "replacement", "text", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/Utility/Macros.php#L88-L96
lode/fem
src/page.php
page.exception
public function exception($exception, $user_message=null) { if ($exception instanceof \Exception == false) { return $this->error('unknown exception format', response::STATUS_INTERNAL_SERVER_ERROR); } $exception_class = bootstrap::get_library('exception'); $this->data['exception']['current'] = $exception; $this->data['exception']['current_trace_string'] = $exception_class::clean_paths(nl2br($exception->getTraceAsString())); $previous = $exception->getPrevious(); if ($previous) { $this->data['exception']['previous'] = $previous; $this->data['exception']['previous_trace_string'] = $exception_class::clean_paths(nl2br($previous->getTraceAsString())); } $reason = $exception->getMessage(); $code = $exception->getCode(); $this->error($reason, $code, $user_message); }
php
public function exception($exception, $user_message=null) { if ($exception instanceof \Exception == false) { return $this->error('unknown exception format', response::STATUS_INTERNAL_SERVER_ERROR); } $exception_class = bootstrap::get_library('exception'); $this->data['exception']['current'] = $exception; $this->data['exception']['current_trace_string'] = $exception_class::clean_paths(nl2br($exception->getTraceAsString())); $previous = $exception->getPrevious(); if ($previous) { $this->data['exception']['previous'] = $previous; $this->data['exception']['previous_trace_string'] = $exception_class::clean_paths(nl2br($previous->getTraceAsString())); } $reason = $exception->getMessage(); $code = $exception->getCode(); $this->error($reason, $code, $user_message); }
[ "public", "function", "exception", "(", "$", "exception", ",", "$", "user_message", "=", "null", ")", "{", "if", "(", "$", "exception", "instanceof", "\\", "Exception", "==", "false", ")", "{", "return", "$", "this", "->", "error", "(", "'unknown exception format'", ",", "response", "::", "STATUS_INTERNAL_SERVER_ERROR", ")", ";", "}", "$", "exception_class", "=", "bootstrap", "::", "get_library", "(", "'exception'", ")", ";", "$", "this", "->", "data", "[", "'exception'", "]", "[", "'current'", "]", "=", "$", "exception", ";", "$", "this", "->", "data", "[", "'exception'", "]", "[", "'current_trace_string'", "]", "=", "$", "exception_class", "::", "clean_paths", "(", "nl2br", "(", "$", "exception", "->", "getTraceAsString", "(", ")", ")", ")", ";", "$", "previous", "=", "$", "exception", "->", "getPrevious", "(", ")", ";", "if", "(", "$", "previous", ")", "{", "$", "this", "->", "data", "[", "'exception'", "]", "[", "'previous'", "]", "=", "$", "previous", ";", "$", "this", "->", "data", "[", "'exception'", "]", "[", "'previous_trace_string'", "]", "=", "$", "exception_class", "::", "clean_paths", "(", "nl2br", "(", "$", "previous", "->", "getTraceAsString", "(", ")", ")", ")", ";", "}", "$", "reason", "=", "$", "exception", "->", "getMessage", "(", ")", ";", "$", "code", "=", "$", "exception", "->", "getCode", "(", ")", ";", "$", "this", "->", "error", "(", "$", "reason", ",", "$", "code", ",", "$", "user_message", ")", ";", "}" ]
show an error page using an exception @param object $exception one that extends \Exception @param string $user_message optional, human-friendly message to show to the user @return void script execution terminates
[ "show", "an", "error", "page", "using", "an", "exception" ]
train
https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/page.php#L35-L54
lode/fem
src/page.php
page.error
public function error($reason=null, $code=response::STATUS_INTERNAL_SERVER_ERROR, $user_message=null) { $response = bootstrap::get_library('response'); $error_data = [ 'status_code' => $code, 'status_message' => $response::get_status_message($code), ]; $error_data['status_code_is_'.$code] = true; if ($user_message) { $error_data['user_message'] = $user_message; } if (ENVIRONMENT == 'development') { $error_data['development'] = true; if ($reason) { $error_data['reason'] = $reason; } } if (!empty($this->data['exception']['current'])) { if ($this->data['exception']['current'] instanceof \alsvanzelf\fem\exception) { if (empty($error_data['user_message'])) { $error_data['user_message'] = $this->data['exception']['current']->getUserMessage(); } $error_data['user_action'] = $this->data['exception']['current']->getUserAction(); } if (ENVIRONMENT != 'development') { unset($this->data['exception']); } } $response::send_status($code); if (empty(static::$default_error_template)) { $page_data = [ 'error' => $error_data, ]; if (!empty($this->data['exception'])) { $page_data['exception'] = $this->data['exception']; } static::show_default_error($page_data); } else { $this->data['title'] = $error_data['status_message']; $this->data['error'] = $error_data; $this->show(static::$default_error_template); } die; }
php
public function error($reason=null, $code=response::STATUS_INTERNAL_SERVER_ERROR, $user_message=null) { $response = bootstrap::get_library('response'); $error_data = [ 'status_code' => $code, 'status_message' => $response::get_status_message($code), ]; $error_data['status_code_is_'.$code] = true; if ($user_message) { $error_data['user_message'] = $user_message; } if (ENVIRONMENT == 'development') { $error_data['development'] = true; if ($reason) { $error_data['reason'] = $reason; } } if (!empty($this->data['exception']['current'])) { if ($this->data['exception']['current'] instanceof \alsvanzelf\fem\exception) { if (empty($error_data['user_message'])) { $error_data['user_message'] = $this->data['exception']['current']->getUserMessage(); } $error_data['user_action'] = $this->data['exception']['current']->getUserAction(); } if (ENVIRONMENT != 'development') { unset($this->data['exception']); } } $response::send_status($code); if (empty(static::$default_error_template)) { $page_data = [ 'error' => $error_data, ]; if (!empty($this->data['exception'])) { $page_data['exception'] = $this->data['exception']; } static::show_default_error($page_data); } else { $this->data['title'] = $error_data['status_message']; $this->data['error'] = $error_data; $this->show(static::$default_error_template); } die; }
[ "public", "function", "error", "(", "$", "reason", "=", "null", ",", "$", "code", "=", "response", "::", "STATUS_INTERNAL_SERVER_ERROR", ",", "$", "user_message", "=", "null", ")", "{", "$", "response", "=", "bootstrap", "::", "get_library", "(", "'response'", ")", ";", "$", "error_data", "=", "[", "'status_code'", "=>", "$", "code", ",", "'status_message'", "=>", "$", "response", "::", "get_status_message", "(", "$", "code", ")", ",", "]", ";", "$", "error_data", "[", "'status_code_is_'", ".", "$", "code", "]", "=", "true", ";", "if", "(", "$", "user_message", ")", "{", "$", "error_data", "[", "'user_message'", "]", "=", "$", "user_message", ";", "}", "if", "(", "ENVIRONMENT", "==", "'development'", ")", "{", "$", "error_data", "[", "'development'", "]", "=", "true", ";", "if", "(", "$", "reason", ")", "{", "$", "error_data", "[", "'reason'", "]", "=", "$", "reason", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "data", "[", "'exception'", "]", "[", "'current'", "]", ")", ")", "{", "if", "(", "$", "this", "->", "data", "[", "'exception'", "]", "[", "'current'", "]", "instanceof", "\\", "alsvanzelf", "\\", "fem", "\\", "exception", ")", "{", "if", "(", "empty", "(", "$", "error_data", "[", "'user_message'", "]", ")", ")", "{", "$", "error_data", "[", "'user_message'", "]", "=", "$", "this", "->", "data", "[", "'exception'", "]", "[", "'current'", "]", "->", "getUserMessage", "(", ")", ";", "}", "$", "error_data", "[", "'user_action'", "]", "=", "$", "this", "->", "data", "[", "'exception'", "]", "[", "'current'", "]", "->", "getUserAction", "(", ")", ";", "}", "if", "(", "ENVIRONMENT", "!=", "'development'", ")", "{", "unset", "(", "$", "this", "->", "data", "[", "'exception'", "]", ")", ";", "}", "}", "$", "response", "::", "send_status", "(", "$", "code", ")", ";", "if", "(", "empty", "(", "static", "::", "$", "default_error_template", ")", ")", "{", "$", "page_data", "=", "[", "'error'", "=>", "$", "error_data", ",", "]", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "data", "[", "'exception'", "]", ")", ")", "{", "$", "page_data", "[", "'exception'", "]", "=", "$", "this", "->", "data", "[", "'exception'", "]", ";", "}", "static", "::", "show_default_error", "(", "$", "page_data", ")", ";", "}", "else", "{", "$", "this", "->", "data", "[", "'title'", "]", "=", "$", "error_data", "[", "'status_message'", "]", ";", "$", "this", "->", "data", "[", "'error'", "]", "=", "$", "error_data", ";", "$", "this", "->", "show", "(", "static", "::", "$", "default_error_template", ")", ";", "}", "die", ";", "}" ]
show an error page @param string $reason technical description, only shown on development environments @param int $code http status code, @see response::STATUS_* @param string $user_message optional, human-friendly message to show to the user @return void script execution terminates
[ "show", "an", "error", "page" ]
train
https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/page.php#L64-L118
lode/fem
src/page.php
page.show_default_error
private static function show_default_error($error_data) { $template_path = \alsvanzelf\fem\ROOT_DIR.'vendor/alsvanzelf/fem/src/templates/default_error.html'; $template_content = file_get_contents($template_path); $renderer = new \Mustache_Engine(); echo $renderer->render($template_content, $error_data); }
php
private static function show_default_error($error_data) { $template_path = \alsvanzelf\fem\ROOT_DIR.'vendor/alsvanzelf/fem/src/templates/default_error.html'; $template_content = file_get_contents($template_path); $renderer = new \Mustache_Engine(); echo $renderer->render($template_content, $error_data); }
[ "private", "static", "function", "show_default_error", "(", "$", "error_data", ")", "{", "$", "template_path", "=", "\\", "alsvanzelf", "\\", "fem", "\\", "ROOT_DIR", ".", "'vendor/alsvanzelf/fem/src/templates/default_error.html'", ";", "$", "template_content", "=", "file_get_contents", "(", "$", "template_path", ")", ";", "$", "renderer", "=", "new", "\\", "Mustache_Engine", "(", ")", ";", "echo", "$", "renderer", "->", "render", "(", "$", "template_content", ",", "$", "error_data", ")", ";", "}" ]
shows a default error template in case no specific one is set @param array $error_data as build up in ::error() @return void however, mustache has echo'd the html
[ "shows", "a", "default", "error", "template", "in", "case", "no", "specific", "one", "is", "set" ]
train
https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/page.php#L126-L132
joseph-walker/vector
src/Lib/Logic.php
Logic.__orCombinator
protected static function __orCombinator(array $fs, $a) { return self::any(Arrays::map(function ($c) use ($a) { return $c($a); }, $fs)); }
php
protected static function __orCombinator(array $fs, $a) { return self::any(Arrays::map(function ($c) use ($a) { return $c($a); }, $fs)); }
[ "protected", "static", "function", "__orCombinator", "(", "array", "$", "fs", ",", "$", "a", ")", "{", "return", "self", "::", "any", "(", "Arrays", "::", "map", "(", "function", "(", "$", "c", ")", "use", "(", "$", "a", ")", "{", "return", "$", "c", "(", "$", "a", ")", ";", "}", ",", "$", "fs", ")", ")", ";", "}" ]
Logical Or Combinator Given n functions {f1, f2, ..., fn}, combine them in such a way to produce a new function g that returns true given at least one of {f1(x), f2(x), ... fn(x)} return true. @example $funcF = function($x) { return $x >= 5; }; $funcG = function($x) { return $x == 0; }; $combinator = Logic::orCombinator([$funcF, $funcG]); $combinator(9); // True $combinator(0); // True $combinator(2); // False @type [(a -> Bool)] -> a -> Bool @param array $fs array of functions to combine @param mixed $a value to test @return \Closure test for or using provided functions
[ "Logical", "Or", "Combinator" ]
train
https://github.com/joseph-walker/vector/blob/e349aa2e9e0535b1993f9fffc0476e7fd8e113fc/src/Lib/Logic.php#L48-L53
joseph-walker/vector
src/Lib/Logic.php
Logic.__andCombinator
protected static function __andCombinator(array $fs, $a) { return self::all(Arrays::map(function ($c) use ($a) { return $c($a); }, $fs)); }
php
protected static function __andCombinator(array $fs, $a) { return self::all(Arrays::map(function ($c) use ($a) { return $c($a); }, $fs)); }
[ "protected", "static", "function", "__andCombinator", "(", "array", "$", "fs", ",", "$", "a", ")", "{", "return", "self", "::", "all", "(", "Arrays", "::", "map", "(", "function", "(", "$", "c", ")", "use", "(", "$", "a", ")", "{", "return", "$", "c", "(", "$", "a", ")", ";", "}", ",", "$", "fs", ")", ")", ";", "}" ]
Logical And Combinator Given n functions {f1, f2, ..., fn}, combine them in such a way to produce a new function g that returns true given {f1(x), f2(x), ... fn(x)} all return true. @example $funcF = function($x) { return $x < 5; }; $funcG = function($x) { return $x > 0; }; $combinator = Logic::andCombinator([$funcF, $funcG]); $combinator(4); // True $combinator(2); // True $combinator(7); // False @type [(a -> Bool)] -> a -> Bool @param array $fs array of functions to combine @param mixed $a value to test @return \Closure test for or using provided functions
[ "Logical", "And", "Combinator" ]
train
https://github.com/joseph-walker/vector/blob/e349aa2e9e0535b1993f9fffc0476e7fd8e113fc/src/Lib/Logic.php#L75-L80
yuncms/framework
src/models/BaseUser.php
BaseUser.generateAuthKey
public function generateAuthKey() { try { $this->auth_key = Yii::$app->security->generateRandomString(32); } catch (Exception $e) { throw $e; } }
php
public function generateAuthKey() { try { $this->auth_key = Yii::$app->security->generateRandomString(32); } catch (Exception $e) { throw $e; } }
[ "public", "function", "generateAuthKey", "(", ")", "{", "try", "{", "$", "this", "->", "auth_key", "=", "Yii", "::", "$", "app", "->", "security", "->", "generateRandomString", "(", "32", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "throw", "$", "e", ";", "}", "}" ]
创建 "记住我" 身份验证Key @return void @throws Exception
[ "创建", "记住我", "身份验证Key" ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/models/BaseUser.php#L288-L295
yuncms/framework
src/models/BaseUser.php
BaseUser.generateAccessToken
public function generateAccessToken() { try { $this->access_token = Yii::$app->security->generateRandomString(32); } catch (Exception $e) { throw $e; } }
php
public function generateAccessToken() { try { $this->access_token = Yii::$app->security->generateRandomString(32); } catch (Exception $e) { throw $e; } }
[ "public", "function", "generateAccessToken", "(", ")", "{", "try", "{", "$", "this", "->", "access_token", "=", "Yii", "::", "$", "app", "->", "security", "->", "generateRandomString", "(", "32", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "throw", "$", "e", ";", "}", "}" ]
创建 "记住我" 身份验证Key @return void @throws Exception
[ "创建", "记住我", "身份验证Key" ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/models/BaseUser.php#L302-L309
yuncms/framework
src/models/BaseUser.php
BaseUser.generateUsername
public function generateUsername() { if ($this->email) { $this->username = explode('@', $this->email)[0]; if ($this->validate(['username'])) { return $this->username; } } else if ($this->nickname) { $this->username = Inflector::slug($this->nickname, ''); if ($this->validate(['username'])) { return $this->username; } } // generate name like "user1", "user2", etc... while (!$this->validate(['username'])) { $row = (new Query())->from('{{%user}}')->select('MAX(id) as id')->one(); $this->username = 'user' . ++$row['id']; } return $this->username; }
php
public function generateUsername() { if ($this->email) { $this->username = explode('@', $this->email)[0]; if ($this->validate(['username'])) { return $this->username; } } else if ($this->nickname) { $this->username = Inflector::slug($this->nickname, ''); if ($this->validate(['username'])) { return $this->username; } } // generate name like "user1", "user2", etc... while (!$this->validate(['username'])) { $row = (new Query())->from('{{%user}}')->select('MAX(id) as id')->one(); $this->username = 'user' . ++$row['id']; } return $this->username; }
[ "public", "function", "generateUsername", "(", ")", "{", "if", "(", "$", "this", "->", "email", ")", "{", "$", "this", "->", "username", "=", "explode", "(", "'@'", ",", "$", "this", "->", "email", ")", "[", "0", "]", ";", "if", "(", "$", "this", "->", "validate", "(", "[", "'username'", "]", ")", ")", "{", "return", "$", "this", "->", "username", ";", "}", "}", "else", "if", "(", "$", "this", "->", "nickname", ")", "{", "$", "this", "->", "username", "=", "Inflector", "::", "slug", "(", "$", "this", "->", "nickname", ",", "''", ")", ";", "if", "(", "$", "this", "->", "validate", "(", "[", "'username'", "]", ")", ")", "{", "return", "$", "this", "->", "username", ";", "}", "}", "// generate name like \"user1\", \"user2\", etc...", "while", "(", "!", "$", "this", "->", "validate", "(", "[", "'username'", "]", ")", ")", "{", "$", "row", "=", "(", "new", "Query", "(", ")", ")", "->", "from", "(", "'{{%user}}'", ")", "->", "select", "(", "'MAX(id) as id'", ")", "->", "one", "(", ")", ";", "$", "this", "->", "username", "=", "'user'", ".", "++", "$", "row", "[", "'id'", "]", ";", "}", "return", "$", "this", "->", "username", ";", "}" ]
随机生成一个用户名
[ "随机生成一个用户名" ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/models/BaseUser.php#L314-L333