repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1
value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
zepi/turbo-base | Zepi/DataSource/Doctrine/src/DataSource/AbstractDoctrineDataSource.php | AbstractDoctrineDataSource.get | public function get($id)
{
try {
$em = $this->entityManager->getDoctrineEntityManager();
$accessEntity = $em->getRepository($this->getEntityClass())->findOneBy(array(
'id' => $id,
));
if ($accessEntity !== null) {
return $accessEntity;
}
return false;
} catch (\Exception $e) {
throw new Exception('Cannot load the entity from the database for the given id "' . $id . '".', 0, $e);
}
} | php | public function get($id)
{
try {
$em = $this->entityManager->getDoctrineEntityManager();
$accessEntity = $em->getRepository($this->getEntityClass())->findOneBy(array(
'id' => $id,
));
if ($accessEntity !== null) {
return $accessEntity;
}
return false;
} catch (\Exception $e) {
throw new Exception('Cannot load the entity from the database for the given id "' . $id . '".', 0, $e);
}
} | [
"public",
"function",
"get",
"(",
"$",
"id",
")",
"{",
"try",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"entityManager",
"->",
"getDoctrineEntityManager",
"(",
")",
";",
"$",
"accessEntity",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"$",
"this",
"->",
... | Returns the entity object for the given id
@param integer $id
@return false|mixed
@throws \Zepi\DataSource\Doctrine\Exception Cannot load the entity from the database for the given id "{id}". | [
"Returns",
"the",
"entity",
"object",
"for",
"the",
"given",
"id"
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/DataSource/Doctrine/src/DataSource/AbstractDoctrineDataSource.php#L163-L179 | train |
zepi/turbo-base | Zepi/DataSource/Doctrine/src/DataSource/AbstractDoctrineDataSource.php | AbstractDoctrineDataSource.add | public function add(EntityInterface $entity)
{
if (!is_a($entity, $this->getEntityClass())) {
throw new Exception('The given entity (' . get_class($entity) . ') is not compatible with this data source (' . self::class . '.');
}
try {
$em = $this->entityManager->getDoctrineEntityManager();
$em->persist($entity);
$em->flush();
return $entity->getId();
} catch (\Exception $e) {
throw new Exception('Cannot add the entity "' . $entity . '".', 0, $e);
}
} | php | public function add(EntityInterface $entity)
{
if (!is_a($entity, $this->getEntityClass())) {
throw new Exception('The given entity (' . get_class($entity) . ') is not compatible with this data source (' . self::class . '.');
}
try {
$em = $this->entityManager->getDoctrineEntityManager();
$em->persist($entity);
$em->flush();
return $entity->getId();
} catch (\Exception $e) {
throw new Exception('Cannot add the entity "' . $entity . '".', 0, $e);
}
} | [
"public",
"function",
"add",
"(",
"EntityInterface",
"$",
"entity",
")",
"{",
"if",
"(",
"!",
"is_a",
"(",
"$",
"entity",
",",
"$",
"this",
"->",
"getEntityClass",
"(",
")",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'The given entity ('",
".",
... | Adds an entity. Returns the id of the entity
or false, if the entity can not inserted.
@param \Zepi\DataSource\Core\Entity\EntityInterface $entity
@return \Zepi\DataSource\Core\Entity\EntityInterface|false
@throws \Zepi\DataSource\Doctrine\Exception The given entity is not compatible with this data source.
@throws \Zepi\DataSource\Doctrine\Exception Cannot add the entity "{entity}". | [
"Adds",
"an",
"entity",
".",
"Returns",
"the",
"id",
"of",
"the",
"entity",
"or",
"false",
"if",
"the",
"entity",
"can",
"not",
"inserted",
"."
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/DataSource/Doctrine/src/DataSource/AbstractDoctrineDataSource.php#L191-L206 | train |
zepi/turbo-base | Zepi/DataSource/Doctrine/src/DataSource/AbstractDoctrineDataSource.php | AbstractDoctrineDataSource.update | public function update(EntityInterface $entity)
{
if (!is_a($entity, $this->getEntityClass())) {
throw new Exception('The given entity (' . get_class($entity) . ') is not compatible with this data source (' . self::class . '.');
}
try {
$em = $this->entityManager->getDoctrineEntityManager();
$em->flush();
return true;
} catch (\Exception $e) {
throw new Exception('Cannot update the entity"' . $entity . '".', 0, $e);
}
} | php | public function update(EntityInterface $entity)
{
if (!is_a($entity, $this->getEntityClass())) {
throw new Exception('The given entity (' . get_class($entity) . ') is not compatible with this data source (' . self::class . '.');
}
try {
$em = $this->entityManager->getDoctrineEntityManager();
$em->flush();
return true;
} catch (\Exception $e) {
throw new Exception('Cannot update the entity"' . $entity . '".', 0, $e);
}
} | [
"public",
"function",
"update",
"(",
"EntityInterface",
"$",
"entity",
")",
"{",
"if",
"(",
"!",
"is_a",
"(",
"$",
"entity",
",",
"$",
"this",
"->",
"getEntityClass",
"(",
")",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'The given entity ('",
".",... | Updates the entity. Returns true if everything worked as excepted or
false if the update didn't worked.
@param \Zepi\DataSource\Core\Entity\EntityInterface $entity
@return boolean
@throws \Zepi\DataSource\Doctrine\Exception The given entity is not compatible with this data source.
@throws \Zepi\DataSource\Doctrine\Exception Cannot update the entity "{entity}". | [
"Updates",
"the",
"entity",
".",
"Returns",
"true",
"if",
"everything",
"worked",
"as",
"excepted",
"or",
"false",
"if",
"the",
"update",
"didn",
"t",
"worked",
"."
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/DataSource/Doctrine/src/DataSource/AbstractDoctrineDataSource.php#L218-L232 | train |
Opifer/ContentBundle | Block/Service/NavigationBlockService.php | NavigationBlockService.buildTree | protected function buildTree(array $simpleTree, $tree = [])
{
foreach ($simpleTree as $item) {
if (!isset($this->collection[$item['id']])) {
continue;
}
$content = $this->collection[$item['id']];
unset($this->collection[$item['id']]); // TODO Fix multi-usage of single item
if (isset($item['__children']) && count($item['__children'])) {
$content['__children'] = $this->buildTree($item['__children']);
} else {
$content['__children'] = [];
}
$tree[] = $content;
}
return $tree;
} | php | protected function buildTree(array $simpleTree, $tree = [])
{
foreach ($simpleTree as $item) {
if (!isset($this->collection[$item['id']])) {
continue;
}
$content = $this->collection[$item['id']];
unset($this->collection[$item['id']]); // TODO Fix multi-usage of single item
if (isset($item['__children']) && count($item['__children'])) {
$content['__children'] = $this->buildTree($item['__children']);
} else {
$content['__children'] = [];
}
$tree[] = $content;
}
return $tree;
} | [
"protected",
"function",
"buildTree",
"(",
"array",
"$",
"simpleTree",
",",
"$",
"tree",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"simpleTree",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"collection",
"[",
"$... | Build the tree from the simpletree and the collection
@param array $simpleTree
@param array $tree
@return array | [
"Build",
"the",
"tree",
"from",
"the",
"simpletree",
"and",
"the",
"collection"
] | df44ef36b81a839ce87ea9a92f7728618111541f | https://github.com/Opifer/ContentBundle/blob/df44ef36b81a839ce87ea9a92f7728618111541f/Block/Service/NavigationBlockService.php#L127-L148 | train |
vincenttouzet/BaseBundle | Command/GenerateCommand.php | GenerateCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
if (!$this->metadata) {
try {
$this->metadata = $this->retrieveMetadatas($input->getArgument('name'));
} catch (\Exception $e) {
$io->error($e->getMessage());
return;
}
}
$metadatas = $this->metadata->getMetadata();
$namespace = str_replace('\\Entity', '', $this->metadata->getNamespace());
$path = $this->metadata->getPath();
$basePath = sprintf(
'%s/%s',
$path,
str_replace('\\', '/', $namespace)
);
$appDir = $this->getContainer()->getParameter('kernel.root_dir');
$adminGenerator = new AdminGenerator($appDir);
$managerGenerator = new ManagerGenerator($appDir);
$adminCtlGenerator = new AdminControllerGenerator($appDir);
$servicesGenerator = new ServicesGenerator($appDir);
$transGenerator = new TranslationsGenerator($appDir);
foreach ($metadatas as $metadata) {
$entityName = $this->getEntityNameFromMetadata($metadata);
$output->writeln('');
$output->writeln(sprintf('Generate files for entity %s', $entityName));
// generate Admin class
$output->writeln($adminGenerator->generate($namespace, $basePath, $metadata));
// generate Manager class
$output->writeln($managerGenerator->generate($namespace, $basePath, $metadata));
// generate AdminController class
$output->writeln($adminCtlGenerator->generate($namespace, $basePath, $metadata));
// update translations
$transGenerator->setBundleName($this->getBundleNameFromEntity($metadata->rootEntityName));
$output->writeln($transGenerator->generate($namespace, $basePath, $metadata));
// update services.yml
$servicesGenerator->setBundleName($this->getBundleNameFromEntity($metadata->rootEntityName));
$output->writeln($servicesGenerator->generate($namespace, $basePath, $metadata));
}
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
if (!$this->metadata) {
try {
$this->metadata = $this->retrieveMetadatas($input->getArgument('name'));
} catch (\Exception $e) {
$io->error($e->getMessage());
return;
}
}
$metadatas = $this->metadata->getMetadata();
$namespace = str_replace('\\Entity', '', $this->metadata->getNamespace());
$path = $this->metadata->getPath();
$basePath = sprintf(
'%s/%s',
$path,
str_replace('\\', '/', $namespace)
);
$appDir = $this->getContainer()->getParameter('kernel.root_dir');
$adminGenerator = new AdminGenerator($appDir);
$managerGenerator = new ManagerGenerator($appDir);
$adminCtlGenerator = new AdminControllerGenerator($appDir);
$servicesGenerator = new ServicesGenerator($appDir);
$transGenerator = new TranslationsGenerator($appDir);
foreach ($metadatas as $metadata) {
$entityName = $this->getEntityNameFromMetadata($metadata);
$output->writeln('');
$output->writeln(sprintf('Generate files for entity %s', $entityName));
// generate Admin class
$output->writeln($adminGenerator->generate($namespace, $basePath, $metadata));
// generate Manager class
$output->writeln($managerGenerator->generate($namespace, $basePath, $metadata));
// generate AdminController class
$output->writeln($adminCtlGenerator->generate($namespace, $basePath, $metadata));
// update translations
$transGenerator->setBundleName($this->getBundleNameFromEntity($metadata->rootEntityName));
$output->writeln($transGenerator->generate($namespace, $basePath, $metadata));
// update services.yml
$servicesGenerator->setBundleName($this->getBundleNameFromEntity($metadata->rootEntityName));
$output->writeln($servicesGenerator->generate($namespace, $basePath, $metadata));
}
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"io",
"=",
"new",
"SymfonyStyle",
"(",
"$",
"input",
",",
"$",
"output",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"metada... | execute command.
@param InputInterface $input InputInterface instance
@param OutputInterface $output OutputInterface instance
@return int|null|void | [
"execute",
"command",
"."
] | 04faac91884ac5ae270a32ba3d63dca8892aa1dd | https://github.com/vincenttouzet/BaseBundle/blob/04faac91884ac5ae270a32ba3d63dca8892aa1dd/Command/GenerateCommand.php#L93-L140 | train |
mtoolkit/mtoolkit-network | src/rpc/json/server/MRPCJsonWebService.php | MRPCJsonWebService.execute | public function execute( $className )
{
$this->className = $className;
// Parse the request
$rawRequest = file_get_contents( 'php://input' );
/* @var $request array */
$request = json_decode( $rawRequest, true );
// Is valid request?
if( $request == false )
{
throw new MRPCJsonServerException( sprintf( 'Invalid body (%s).', $rawRequest ) );
}
// Does the request respect the 2.0 specification?
if( $request['jsonrpc'] != '2.0' )
{
throw new MRPCJsonServerException( sprintf( 'The request does not respect the 2.0 specification.' ) );
}
// Set the request properties
$this->request = new MRPCJsonRequest();
$this->request
->setMethod( $request['method'] )
->setParams( $request['params'] )
->setId( $request['id'] );
// Call the procedure/member
$callResponse = call_user_func(
array( $this, $this->request->getMethod() )
, $this->request->getParams() );
// Does the call fail?
if( $callResponse === false )
{
throw new MRPCJsonServerException( 'Invalid method name.' );
}
} | php | public function execute( $className )
{
$this->className = $className;
// Parse the request
$rawRequest = file_get_contents( 'php://input' );
/* @var $request array */
$request = json_decode( $rawRequest, true );
// Is valid request?
if( $request == false )
{
throw new MRPCJsonServerException( sprintf( 'Invalid body (%s).', $rawRequest ) );
}
// Does the request respect the 2.0 specification?
if( $request['jsonrpc'] != '2.0' )
{
throw new MRPCJsonServerException( sprintf( 'The request does not respect the 2.0 specification.' ) );
}
// Set the request properties
$this->request = new MRPCJsonRequest();
$this->request
->setMethod( $request['method'] )
->setParams( $request['params'] )
->setId( $request['id'] );
// Call the procedure/member
$callResponse = call_user_func(
array( $this, $this->request->getMethod() )
, $this->request->getParams() );
// Does the call fail?
if( $callResponse === false )
{
throw new MRPCJsonServerException( 'Invalid method name.' );
}
} | [
"public",
"function",
"execute",
"(",
"$",
"className",
")",
"{",
"$",
"this",
"->",
"className",
"=",
"$",
"className",
";",
"// Parse the request",
"$",
"rawRequest",
"=",
"file_get_contents",
"(",
"'php://input'",
")",
";",
"/* @var $request array */",
"$",
"... | Reads the request and run the web method.
@param $className
@throws MRPCJsonServerException | [
"Reads",
"the",
"request",
"and",
"run",
"the",
"web",
"method",
"."
] | eecf251df546a60ecb693fd3983e78cb946cb9d4 | https://github.com/mtoolkit/mtoolkit-network/blob/eecf251df546a60ecb693fd3983e78cb946cb9d4/src/rpc/json/server/MRPCJsonWebService.php#L120-L158 | train |
mtoolkit/mtoolkit-network | src/rpc/json/server/MRPCJsonWebService.php | MRPCJsonWebService.autorun | public static function autorun()
{
/* @var $classes string[] */
$classes = array_reverse( get_declared_classes() );
foreach( $classes as $class )
{
$type = new \ReflectionClass( $class );
$abstract = $type->isAbstract();
if( is_subclass_of( $class, MRPCJsonWebService::class ) === false || $abstract === true )
{
continue;
}
/* @var $webService MRPCJsonWebService */
$webService = new $class();
// If the definitions are requested
if( $_SERVER['QUERY_STRING'] == 'definition' )
{
$definition = new MRPCJsonWebServiceDefinition( $class );
$webService->getHttpResponse()->setContentType( ContentType::TEXT_HTML );
$webService->getHttpResponse()->setOutput( (string)$definition );
}
// Normal web service execution
else
{
$webService->getHttpResponse()->setContentType( ContentType::APPLICATION_JSON );
try
{
$webService->execute( $class );
$webService->getResponse()->setId( $webService->getRequest()->getId() );
} catch( MRPCJsonServerException $ex )
{
$error = new MRPCJsonError();
$error->setCode( -1 );
$error->setMessage( $ex->getMessage() );
$webService->response = new MRPCJsonResponse();
$webService->response->setError( $error );
}
$webService->getHttpResponse()->setOutput( $webService->getResponse()->toJSON() );
}
return $webService;
}
return null;
} | php | public static function autorun()
{
/* @var $classes string[] */
$classes = array_reverse( get_declared_classes() );
foreach( $classes as $class )
{
$type = new \ReflectionClass( $class );
$abstract = $type->isAbstract();
if( is_subclass_of( $class, MRPCJsonWebService::class ) === false || $abstract === true )
{
continue;
}
/* @var $webService MRPCJsonWebService */
$webService = new $class();
// If the definitions are requested
if( $_SERVER['QUERY_STRING'] == 'definition' )
{
$definition = new MRPCJsonWebServiceDefinition( $class );
$webService->getHttpResponse()->setContentType( ContentType::TEXT_HTML );
$webService->getHttpResponse()->setOutput( (string)$definition );
}
// Normal web service execution
else
{
$webService->getHttpResponse()->setContentType( ContentType::APPLICATION_JSON );
try
{
$webService->execute( $class );
$webService->getResponse()->setId( $webService->getRequest()->getId() );
} catch( MRPCJsonServerException $ex )
{
$error = new MRPCJsonError();
$error->setCode( -1 );
$error->setMessage( $ex->getMessage() );
$webService->response = new MRPCJsonResponse();
$webService->response->setError( $error );
}
$webService->getHttpResponse()->setOutput( $webService->getResponse()->toJSON() );
}
return $webService;
}
return null;
} | [
"public",
"static",
"function",
"autorun",
"(",
")",
"{",
"/* @var $classes string[] */",
"$",
"classes",
"=",
"array_reverse",
"(",
"get_declared_classes",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"classes",
"as",
"$",
"class",
")",
"{",
"$",
"type",
"=",
... | Run the instance of the web service. | [
"Run",
"the",
"instance",
"of",
"the",
"web",
"service",
"."
] | eecf251df546a60ecb693fd3983e78cb946cb9d4 | https://github.com/mtoolkit/mtoolkit-network/blob/eecf251df546a60ecb693fd3983e78cb946cb9d4/src/rpc/json/server/MRPCJsonWebService.php#L163-L215 | train |
rozaverta/cmf | core/Event/Driver/EventDriverInterface.php | EventDriverInterface.update | public function update( string $name, string $title = "", bool $completable = false ): Prop
{
$row = self::getEventItem($name);
if( !$row )
{
throw new NotFoundException("Event '{$name}' not found");
}
$this->permissible($row->module_id, $name);
$title = trim($title);
if( strlen($title) < 1 )
{
$title = $name . " event";
}
$prop = new Prop([
"action" => "update",
"updated" => false
]);
if( $title === $row->title && $completable === $row->completable )
{
return $prop;
}
// dispatch event
$event = new EventUpdateDriverEvent($this, $name, $title, $completable);
$dispatcher = EventManager::dispatcher($event->getName());
$dispatcher->dispatch($event);
$prop->set(
"updated",
\DB::
table("events")
->whereId($row->id)
->update(compact('title', 'completable')) > 0
);
$prop->get("updated") && $this->addLogDebug(Text::createInstance("The %s event is successfully updated", $name));
$dispatcher->complete($prop);
return $prop;
} | php | public function update( string $name, string $title = "", bool $completable = false ): Prop
{
$row = self::getEventItem($name);
if( !$row )
{
throw new NotFoundException("Event '{$name}' not found");
}
$this->permissible($row->module_id, $name);
$title = trim($title);
if( strlen($title) < 1 )
{
$title = $name . " event";
}
$prop = new Prop([
"action" => "update",
"updated" => false
]);
if( $title === $row->title && $completable === $row->completable )
{
return $prop;
}
// dispatch event
$event = new EventUpdateDriverEvent($this, $name, $title, $completable);
$dispatcher = EventManager::dispatcher($event->getName());
$dispatcher->dispatch($event);
$prop->set(
"updated",
\DB::
table("events")
->whereId($row->id)
->update(compact('title', 'completable')) > 0
);
$prop->get("updated") && $this->addLogDebug(Text::createInstance("The %s event is successfully updated", $name));
$dispatcher->complete($prop);
return $prop;
} | [
"public",
"function",
"update",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"title",
"=",
"\"\"",
",",
"bool",
"$",
"completable",
"=",
"false",
")",
":",
"Prop",
"{",
"$",
"row",
"=",
"self",
"::",
"getEventItem",
"(",
"$",
"name",
")",
";",
"... | Update event data
@param string $name
@param string $title
@param bool $completable
@return Prop
@throws NotFoundException | [
"Update",
"event",
"data"
] | 95ed38362e397d1c700ee255f7200234ef98d356 | https://github.com/rozaverta/cmf/blob/95ed38362e397d1c700ee255f7200234ef98d356/core/Event/Driver/EventDriverInterface.php#L93-L135 | train |
rozaverta/cmf | core/Event/Driver/EventDriverInterface.php | EventDriverInterface.hasName | public static function hasName( $name, $module_id = null ): bool
{
if( !self::isValidName($name) )
{
return false;
}
$builder = \DB::table("events")->where("name", $name);
if( is_numeric($module_id) )
{
$builder->where("module_id", (int) $module_id );
}
return $builder->count(["id"]) > 0;
} | php | public static function hasName( $name, $module_id = null ): bool
{
if( !self::isValidName($name) )
{
return false;
}
$builder = \DB::table("events")->where("name", $name);
if( is_numeric($module_id) )
{
$builder->where("module_id", (int) $module_id );
}
return $builder->count(["id"]) > 0;
} | [
"public",
"static",
"function",
"hasName",
"(",
"$",
"name",
",",
"$",
"module_id",
"=",
"null",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"self",
"::",
"isValidName",
"(",
"$",
"name",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"builder",
"=",
... | Config name is exists
@param string $name
@param null | int $module_id
@return bool | [
"Config",
"name",
"is",
"exists"
] | 95ed38362e397d1c700ee255f7200234ef98d356 | https://github.com/rozaverta/cmf/blob/95ed38362e397d1c700ee255f7200234ef98d356/core/Event/Driver/EventDriverInterface.php#L317-L331 | train |
rozaverta/cmf | core/Event/Driver/EventDriverInterface.php | EventDriverInterface.isValidName | public static function isValidName( $name ): bool
{
$len = strlen($name);
if( $len < 5 || ! preg_match('/^on[A-Z][a-zA-Z]*$/', $name) )
{
return false;
}
return $len < 256;
} | php | public static function isValidName( $name ): bool
{
$len = strlen($name);
if( $len < 5 || ! preg_match('/^on[A-Z][a-zA-Z]*$/', $name) )
{
return false;
}
return $len < 256;
} | [
"public",
"static",
"function",
"isValidName",
"(",
"$",
"name",
")",
":",
"bool",
"{",
"$",
"len",
"=",
"strlen",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"len",
"<",
"5",
"||",
"!",
"preg_match",
"(",
"'/^on[A-Z][a-zA-Z]*$/'",
",",
"$",
"name",
... | Validate config name
@param string $name
@return bool | [
"Validate",
"config",
"name"
] | 95ed38362e397d1c700ee255f7200234ef98d356 | https://github.com/rozaverta/cmf/blob/95ed38362e397d1c700ee255f7200234ef98d356/core/Event/Driver/EventDriverInterface.php#L339-L348 | train |
sndatabase/core | src/PreparedStatement.php | PreparedStatement.bindParam | public function bindParam($tag, &$param, $type = DB::PARAM_AUTO) {
if (!is_int($tag) and ctype_digit($tag))
$tag = intval($tag);
elseif (is_string($tag)) {
if (':' != substr($tag, 0, 1))
$tag = ":$tag";
} else
return false;
$this->parameters[$tag] = array('param' => &$param, 'type' => $type);
return true;
} | php | public function bindParam($tag, &$param, $type = DB::PARAM_AUTO) {
if (!is_int($tag) and ctype_digit($tag))
$tag = intval($tag);
elseif (is_string($tag)) {
if (':' != substr($tag, 0, 1))
$tag = ":$tag";
} else
return false;
$this->parameters[$tag] = array('param' => &$param, 'type' => $type);
return true;
} | [
"public",
"function",
"bindParam",
"(",
"$",
"tag",
",",
"&",
"$",
"param",
",",
"$",
"type",
"=",
"DB",
"::",
"PARAM_AUTO",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"tag",
")",
"and",
"ctype_digit",
"(",
"$",
"tag",
")",
")",
"$",
"tag",
... | Binds parameter to statement
@param string|int $tag Parameter marker in the statement. If marker is '?', use integer value here.
@param &mixed $param Parameter to bind, as reference
@param int $type Parameter type, defaults to string.
@return boolean | [
"Binds",
"parameter",
"to",
"statement"
] | 8645b71f1cb437a845fcf12ae742655dd874b229 | https://github.com/sndatabase/core/blob/8645b71f1cb437a845fcf12ae742655dd874b229/src/PreparedStatement.php#L51-L61 | train |
ddehart/dilmun | src/Nabu/StaticLogger.php | StaticLogger.processContext | private static function processContext($message, array $context = array())
{
$replace = array();
foreach ($context as $key => $value) {
$templated = "{" . $key . "}";
$replace[$templated] = $value;
}
if (self::checkContextException($context)) {
/**
* @var \Exception $exception
*/
$exception = $context["exception"];
$replace["{line}"] = $exception->getLine();
$replace["{file}"] = $exception->getFile();
$replace["{message}"] = $exception->getMessage();
}
return strtr($message, $replace);
} | php | private static function processContext($message, array $context = array())
{
$replace = array();
foreach ($context as $key => $value) {
$templated = "{" . $key . "}";
$replace[$templated] = $value;
}
if (self::checkContextException($context)) {
/**
* @var \Exception $exception
*/
$exception = $context["exception"];
$replace["{line}"] = $exception->getLine();
$replace["{file}"] = $exception->getFile();
$replace["{message}"] = $exception->getMessage();
}
return strtr($message, $replace);
} | [
"private",
"static",
"function",
"processContext",
"(",
"$",
"message",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"$",
"replace",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"context",
"as",
"$",
"key",
"=>",
"$",
"value",... | Processes context as supplied by the log method, replacing templated strings with data from the context array
or processing exception data via checkContextException.
Context array elements with the "exception" key are processed by pulling Exception line, file, and message into
the log message provided appropriate templates within the message: {line}, {file}, and {message}, respectively.
Note that any line, file, or message templates provided outside of an exception will be overwritten by context
processing, and so the order in which the context array data are stacked is relevant.
@param string $message The original log message to be processed with context.
@param array $context An array of key => value pairs with additional data to be inserted into the log
message provided {templated text} (i.e. surrounded by curly braces.
@return string The processed log message | [
"Processes",
"context",
"as",
"supplied",
"by",
"the",
"log",
"method",
"replacing",
"templated",
"strings",
"with",
"data",
"from",
"the",
"context",
"array",
"or",
"processing",
"exception",
"data",
"via",
"checkContextException",
"."
] | e2a294dbcd4c6754063c247be64930c5ee91378f | https://github.com/ddehart/dilmun/blob/e2a294dbcd4c6754063c247be64930c5ee91378f/src/Nabu/StaticLogger.php#L208-L229 | train |
ddehart/dilmun | src/Nabu/StaticLogger.php | StaticLogger.checkContextException | private static function checkContextException(array $context = array())
{
if (isset($context["exception"])) {
$includes_exception = $context["exception"] instanceof \Exception;
} else {
$includes_exception = false;
}
return $includes_exception;
} | php | private static function checkContextException(array $context = array())
{
if (isset($context["exception"])) {
$includes_exception = $context["exception"] instanceof \Exception;
} else {
$includes_exception = false;
}
return $includes_exception;
} | [
"private",
"static",
"function",
"checkContextException",
"(",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"context",
"[",
"\"exception\"",
"]",
")",
")",
"{",
"$",
"includes_exception",
"=",
"$",
"context",
"... | Determines whether a context array contains an Exception.
@param array $context PSR-3 context array.
@return bool Returns true if the context array contains an element identified by an "exception" key
AND the value that corresponds with the "exception" key is an Exception.
Returns false otherwise. | [
"Determines",
"whether",
"a",
"context",
"array",
"contains",
"an",
"Exception",
"."
] | e2a294dbcd4c6754063c247be64930c5ee91378f | https://github.com/ddehart/dilmun/blob/e2a294dbcd4c6754063c247be64930c5ee91378f/src/Nabu/StaticLogger.php#L239-L248 | train |
digipolisgent/robo-digipolis-code-validation | src/PhpMd.php | PhpMd.rulesets | public function rulesets($ruleSetFileNames)
{
if (!is_array($ruleSetFileNames)) {
$ruleSetFileNames = [$ruleSetFileNames];
}
$this->rulesets = array_unique(array_merge($this->rulesets, $ruleSetFileNames));
return $this;
} | php | public function rulesets($ruleSetFileNames)
{
if (!is_array($ruleSetFileNames)) {
$ruleSetFileNames = [$ruleSetFileNames];
}
$this->rulesets = array_unique(array_merge($this->rulesets, $ruleSetFileNames));
return $this;
} | [
"public",
"function",
"rulesets",
"(",
"$",
"ruleSetFileNames",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"ruleSetFileNames",
")",
")",
"{",
"$",
"ruleSetFileNames",
"=",
"[",
"$",
"ruleSetFileNames",
"]",
";",
"}",
"$",
"this",
"->",
"rulesets",
"... | Sets the rule-sets.
@param array|string $ruleSetFileNames
Array of rule-set filenames or identifiers.
@return $this | [
"Sets",
"the",
"rule",
"-",
"sets",
"."
] | 56f69f88a368a5049af7021901042820bee914df | https://github.com/digipolisgent/robo-digipolis-code-validation/blob/56f69f88a368a5049af7021901042820bee914df/src/PhpMd.php#L131-L139 | train |
digipolisgent/robo-digipolis-code-validation | src/PhpMd.php | PhpMd.allowedFileExtensions | public function allowedFileExtensions($fileExtensions)
{
if (!is_array($fileExtensions)) {
$fileExtensions = [$fileExtensions];
}
$this->extensions = array_unique(array_merge($this->extensions, $fileExtensions));
return $this;
} | php | public function allowedFileExtensions($fileExtensions)
{
if (!is_array($fileExtensions)) {
$fileExtensions = [$fileExtensions];
}
$this->extensions = array_unique(array_merge($this->extensions, $fileExtensions));
return $this;
} | [
"public",
"function",
"allowedFileExtensions",
"(",
"$",
"fileExtensions",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"fileExtensions",
")",
")",
"{",
"$",
"fileExtensions",
"=",
"[",
"$",
"fileExtensions",
"]",
";",
"}",
"$",
"this",
"->",
"extension... | Sets a list of filename extensions for valid php source code files.
@param array|string $fileExtensions
List of valid file extensions without leading dot.
@return $this | [
"Sets",
"a",
"list",
"of",
"filename",
"extensions",
"for",
"valid",
"php",
"source",
"code",
"files",
"."
] | 56f69f88a368a5049af7021901042820bee914df | https://github.com/digipolisgent/robo-digipolis-code-validation/blob/56f69f88a368a5049af7021901042820bee914df/src/PhpMd.php#L149-L157 | train |
digipolisgent/robo-digipolis-code-validation | src/PhpMd.php | PhpMd.ignorePatterns | public function ignorePatterns($ignorePatterns)
{
if (!is_array($ignorePatterns)) {
$ignorePatterns = [$ignorePatterns];
}
$this->ignorePatterns = array_unique(array_merge($this->ignorePatterns, $ignorePatterns));
return $this;
} | php | public function ignorePatterns($ignorePatterns)
{
if (!is_array($ignorePatterns)) {
$ignorePatterns = [$ignorePatterns];
}
$this->ignorePatterns = array_unique(array_merge($this->ignorePatterns, $ignorePatterns));
return $this;
} | [
"public",
"function",
"ignorePatterns",
"(",
"$",
"ignorePatterns",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"ignorePatterns",
")",
")",
"{",
"$",
"ignorePatterns",
"=",
"[",
"$",
"ignorePatterns",
"]",
";",
"}",
"$",
"this",
"->",
"ignorePatterns",... | Sets a list of ignore patterns that is used to exclude directories from
the source analysis.
@param array|string $ignorePatterns
List of ignore patterns.
@return $this | [
"Sets",
"a",
"list",
"of",
"ignore",
"patterns",
"that",
"is",
"used",
"to",
"exclude",
"directories",
"from",
"the",
"source",
"analysis",
"."
] | 56f69f88a368a5049af7021901042820bee914df | https://github.com/digipolisgent/robo-digipolis-code-validation/blob/56f69f88a368a5049af7021901042820bee914df/src/PhpMd.php#L168-L176 | train |
elumina-elearning/oauth2-server | src/ResourceServer.php | ResourceServer.isValidRequest | public function isValidRequest($headerOnly = true, $accessToken = null)
{
$accessTokenString = ($accessToken !== null)
? $accessToken
: $this->determineAccessToken($headerOnly);
// Set the access token
$this->accessToken = $this->getAccessTokenStorage()->get($accessTokenString);
// Ensure the access token exists
if (!$this->accessToken instanceof AccessTokenEntity) {
throw new AccessDeniedException();
}
// Check the access token hasn't expired
// Ensure the auth code hasn't expired
if ($this->accessToken->isExpired() === true) {
throw new AccessDeniedException();
}
\Illuminate\Support\Facades\DB::table('oauth_access_tokens')->where('id', $accessTokenString)->update(['expire_time' => time() + 30]);
return true;
} | php | public function isValidRequest($headerOnly = true, $accessToken = null)
{
$accessTokenString = ($accessToken !== null)
? $accessToken
: $this->determineAccessToken($headerOnly);
// Set the access token
$this->accessToken = $this->getAccessTokenStorage()->get($accessTokenString);
// Ensure the access token exists
if (!$this->accessToken instanceof AccessTokenEntity) {
throw new AccessDeniedException();
}
// Check the access token hasn't expired
// Ensure the auth code hasn't expired
if ($this->accessToken->isExpired() === true) {
throw new AccessDeniedException();
}
\Illuminate\Support\Facades\DB::table('oauth_access_tokens')->where('id', $accessTokenString)->update(['expire_time' => time() + 30]);
return true;
} | [
"public",
"function",
"isValidRequest",
"(",
"$",
"headerOnly",
"=",
"true",
",",
"$",
"accessToken",
"=",
"null",
")",
"{",
"$",
"accessTokenString",
"=",
"(",
"$",
"accessToken",
"!==",
"null",
")",
"?",
"$",
"accessToken",
":",
"$",
"this",
"->",
"det... | Checks if the access token is valid or not
@param bool $headerOnly Limit Access Token to Authorization header
@param \EluminaElearning\OAuth2\Server\Entity\AccessTokenEntity|null $accessToken Access Token
@throws \EluminaElearning\OAuth2\Server\Exception\AccessDeniedException
@throws \EluminaElearning\OAuth2\Server\Exception\InvalidRequestException
@return bool | [
"Checks",
"if",
"the",
"access",
"token",
"is",
"valid",
"or",
"not"
] | 9adff5ef58b36fc879637faa518a8025e4b8cd56 | https://github.com/elumina-elearning/oauth2-server/blob/9adff5ef58b36fc879637faa518a8025e4b8cd56/src/ResourceServer.php#L107-L130 | train |
elumina-elearning/oauth2-server | src/ResourceServer.php | ResourceServer.determineAccessToken | public function determineAccessToken($headerOnly = false)
{
if (!empty($this->getRequest()->headers->get('Authorization'))) {
$accessToken = $this->getTokenType()->determineAccessTokenInHeader($this->getRequest());
} elseif ($headerOnly === false && (! $this->getTokenType() instanceof MAC)) {
$accessToken = ($this->getRequest()->server->get('REQUEST_METHOD') === 'GET')
? $this->getRequest()->query->get($this->tokenKey)
: $this->getRequest()->request->get($this->tokenKey);
}
if (empty($accessToken)) {
throw new InvalidRequestException('access token');
}
return $accessToken;
} | php | public function determineAccessToken($headerOnly = false)
{
if (!empty($this->getRequest()->headers->get('Authorization'))) {
$accessToken = $this->getTokenType()->determineAccessTokenInHeader($this->getRequest());
} elseif ($headerOnly === false && (! $this->getTokenType() instanceof MAC)) {
$accessToken = ($this->getRequest()->server->get('REQUEST_METHOD') === 'GET')
? $this->getRequest()->query->get($this->tokenKey)
: $this->getRequest()->request->get($this->tokenKey);
}
if (empty($accessToken)) {
throw new InvalidRequestException('access token');
}
return $accessToken;
} | [
"public",
"function",
"determineAccessToken",
"(",
"$",
"headerOnly",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"headers",
"->",
"get",
"(",
"'Authorization'",
")",
")",
")",
"{",
"$",
"acces... | Reads in the access token from the headers
@param bool $headerOnly Limit Access Token to Authorization header
@throws \EluminaElearning\OAuth2\Server\Exception\InvalidRequestException Thrown if there is no access token presented
@return string | [
"Reads",
"in",
"the",
"access",
"token",
"from",
"the",
"headers"
] | 9adff5ef58b36fc879637faa518a8025e4b8cd56 | https://github.com/elumina-elearning/oauth2-server/blob/9adff5ef58b36fc879637faa518a8025e4b8cd56/src/ResourceServer.php#L141-L156 | train |
gap-db/orm | GapOrm/Commands/SynchronizeController.php | SynchronizeController.indexAction | public function indexAction()
{
$models = $this->getAllModels();
foreach($models as $model) {
$this->checkTable(new $model['namespace']);
}
} | php | public function indexAction()
{
$models = $this->getAllModels();
foreach($models as $model) {
$this->checkTable(new $model['namespace']);
}
} | [
"public",
"function",
"indexAction",
"(",
")",
"{",
"$",
"models",
"=",
"$",
"this",
"->",
"getAllModels",
"(",
")",
";",
"foreach",
"(",
"$",
"models",
"as",
"$",
"model",
")",
"{",
"$",
"this",
"->",
"checkTable",
"(",
"new",
"$",
"model",
"[",
"... | Synchronize all table fields
@Route ('GapOrm:synchronize') | [
"Synchronize",
"all",
"table",
"fields"
] | bcd8e3d27b19b14814d3207489071c4a250a6ac5 | https://github.com/gap-db/orm/blob/bcd8e3d27b19b14814d3207489071c4a250a6ac5/GapOrm/Commands/SynchronizeController.php#L25-L32 | train |
gap-db/orm | GapOrm/Commands/SynchronizeController.php | SynchronizeController.checkTable | private function checkTable($modelObj)
{
if (!method_exists($modelObj, 'table')) {
return false;
}
// get table name
$tableName = $modelObj->table();
// check table, add if not exist
$existTable = PdoDriver::getInstance()->tableExists($tableName);
if (!$existTable) {
$this->createTable($tableName, $modelObj->getFields());
CliManager::getMessage('Created table ' . $tableName);
}
// get database table data and check
PdoDriver::getInstance()->query('SHOW COLUMNS FROM ' . $tableName);
$dbFields = PdoDriver::getInstance()->selectAll();
$modelFieldNames = [];
foreach ($modelObj->getFields() as $modelField) {
$modelFieldNames[] = $modelField->identifier();
}
// check db fields on model fields
$dbFieldNames = [];
foreach ($dbFields as $dbField) {
if (!in_array($dbField->Field, $modelFieldNames)) {
echo " --- Old field " . CliManager::setTextColor($dbField->Field, 'yellow') . " in table " . CliManager::setTextColor($modelObj->table(), 'green') . " --- \n\r";
}
$dbFieldNames[] = $dbField->Field;
}
// check model fields on db fields
foreach ($modelObj->getFields() as $key => $modelField) {
if (!in_array($modelField->identifier(), $dbFieldNames)) {
// Add new fields to db table
$previousField = false;
if (isset($modelObj->getFields()[$key-1])) {
$previousField = $modelObj->getFields()[$key-1];
}
$this->createField($tableName, $modelField, $previousField);
echo CliManager::setTextColor(" --- Add New field " . $modelField->identifier() . " in table " . $modelObj->table(), 'green') . " --- \n\r";
}
}
} | php | private function checkTable($modelObj)
{
if (!method_exists($modelObj, 'table')) {
return false;
}
// get table name
$tableName = $modelObj->table();
// check table, add if not exist
$existTable = PdoDriver::getInstance()->tableExists($tableName);
if (!$existTable) {
$this->createTable($tableName, $modelObj->getFields());
CliManager::getMessage('Created table ' . $tableName);
}
// get database table data and check
PdoDriver::getInstance()->query('SHOW COLUMNS FROM ' . $tableName);
$dbFields = PdoDriver::getInstance()->selectAll();
$modelFieldNames = [];
foreach ($modelObj->getFields() as $modelField) {
$modelFieldNames[] = $modelField->identifier();
}
// check db fields on model fields
$dbFieldNames = [];
foreach ($dbFields as $dbField) {
if (!in_array($dbField->Field, $modelFieldNames)) {
echo " --- Old field " . CliManager::setTextColor($dbField->Field, 'yellow') . " in table " . CliManager::setTextColor($modelObj->table(), 'green') . " --- \n\r";
}
$dbFieldNames[] = $dbField->Field;
}
// check model fields on db fields
foreach ($modelObj->getFields() as $key => $modelField) {
if (!in_array($modelField->identifier(), $dbFieldNames)) {
// Add new fields to db table
$previousField = false;
if (isset($modelObj->getFields()[$key-1])) {
$previousField = $modelObj->getFields()[$key-1];
}
$this->createField($tableName, $modelField, $previousField);
echo CliManager::setTextColor(" --- Add New field " . $modelField->identifier() . " in table " . $modelObj->table(), 'green') . " --- \n\r";
}
}
} | [
"private",
"function",
"checkTable",
"(",
"$",
"modelObj",
")",
"{",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"modelObj",
",",
"'table'",
")",
")",
"{",
"return",
"false",
";",
"}",
"// get table name",
"$",
"tableName",
"=",
"$",
"modelObj",
"->",
"ta... | Check Table fields
@param $modelObj
@return bool | [
"Check",
"Table",
"fields"
] | bcd8e3d27b19b14814d3207489071c4a250a6ac5 | https://github.com/gap-db/orm/blob/bcd8e3d27b19b14814d3207489071c4a250a6ac5/GapOrm/Commands/SynchronizeController.php#L40-L92 | train |
gap-db/orm | GapOrm/Commands/SynchronizeController.php | SynchronizeController.getAllModels | private function getAllModels()
{
$modules = Safan::handler()->getModules();
$modelClasses = [];
foreach ($modules as $moduleName => $modulePath) {
$modelsPath = APP_BASE_PATH . DS . $modulePath . DS . 'Models';
$modelFiles = [];
if (is_dir($modelsPath)) {
$modelFiles = scandir($modelsPath);
}
foreach ($modelFiles as $modelFile) {
if ($modelFile != '.' && $modelFile != '..' && is_dir($modelsPath . DS . $modelFile)) {
$subModelFiles = scandir($modelsPath . DS . $modelFile);
foreach ($subModelFiles as $subModelFile) {
if ($subModelFile != '.' && $subModelFile != '..' && is_file($modelsPath . DS . $modelFile . DS . $subModelFile)) {
$subModelName = substr($subModelFile, 0, -4);
$modelClasses[] = [
'name' => $subModelName,
'namespace' => '\\' . $moduleName . '\\Models\\' . $modelFile . '\\' . $subModelName,
'file' => $modelsPath . DS . $modelFile . DS . $subModelFile
];
}
}
} elseif ($modelFile != '.' && $modelFile != '..' && is_file($modelsPath . DS . $modelFile)) {
$modelName = substr($modelFile, 0, -4);
$modelClasses[] = [
'name' => $modelName,
'namespace' => '\\' . $moduleName . '\\Models\\' . $modelName,
'file' => $modelsPath . DS . $modelFile
];
}
}
}
return $modelClasses;
} | php | private function getAllModels()
{
$modules = Safan::handler()->getModules();
$modelClasses = [];
foreach ($modules as $moduleName => $modulePath) {
$modelsPath = APP_BASE_PATH . DS . $modulePath . DS . 'Models';
$modelFiles = [];
if (is_dir($modelsPath)) {
$modelFiles = scandir($modelsPath);
}
foreach ($modelFiles as $modelFile) {
if ($modelFile != '.' && $modelFile != '..' && is_dir($modelsPath . DS . $modelFile)) {
$subModelFiles = scandir($modelsPath . DS . $modelFile);
foreach ($subModelFiles as $subModelFile) {
if ($subModelFile != '.' && $subModelFile != '..' && is_file($modelsPath . DS . $modelFile . DS . $subModelFile)) {
$subModelName = substr($subModelFile, 0, -4);
$modelClasses[] = [
'name' => $subModelName,
'namespace' => '\\' . $moduleName . '\\Models\\' . $modelFile . '\\' . $subModelName,
'file' => $modelsPath . DS . $modelFile . DS . $subModelFile
];
}
}
} elseif ($modelFile != '.' && $modelFile != '..' && is_file($modelsPath . DS . $modelFile)) {
$modelName = substr($modelFile, 0, -4);
$modelClasses[] = [
'name' => $modelName,
'namespace' => '\\' . $moduleName . '\\Models\\' . $modelName,
'file' => $modelsPath . DS . $modelFile
];
}
}
}
return $modelClasses;
} | [
"private",
"function",
"getAllModels",
"(",
")",
"{",
"$",
"modules",
"=",
"Safan",
"::",
"handler",
"(",
")",
"->",
"getModules",
"(",
")",
";",
"$",
"modelClasses",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"modules",
"as",
"$",
"moduleName",
"=>",
... | Return all Model Class names
@return array | [
"Return",
"all",
"Model",
"Class",
"names"
] | bcd8e3d27b19b14814d3207489071c4a250a6ac5 | https://github.com/gap-db/orm/blob/bcd8e3d27b19b14814d3207489071c4a250a6ac5/GapOrm/Commands/SynchronizeController.php#L99-L140 | train |
phossa2/libs | src/Phossa2/Query/Traits/Clause/ClauseTrait.php | ClauseTrait.quoteAlias | protected function quoteAlias($alias, array $settings)/*# : string */
{
if (is_int($alias)) {
return '';
} else {
$prefix = $settings['quotePrefix'];
$suffix = $settings['quoteSuffix'];
return ' AS ' . $this->quoteSpace($alias, $prefix, $suffix);
}
} | php | protected function quoteAlias($alias, array $settings)/*# : string */
{
if (is_int($alias)) {
return '';
} else {
$prefix = $settings['quotePrefix'];
$suffix = $settings['quoteSuffix'];
return ' AS ' . $this->quoteSpace($alias, $prefix, $suffix);
}
} | [
"protected",
"function",
"quoteAlias",
"(",
"$",
"alias",
",",
"array",
"$",
"settings",
")",
"/*# : string */",
"{",
"if",
"(",
"is_int",
"(",
"$",
"alias",
")",
")",
"{",
"return",
"''",
";",
"}",
"else",
"{",
"$",
"prefix",
"=",
"$",
"settings",
"... | Quote an alias if not an int
@param int|string $alias
@param array $settings
@return string
@access protected | [
"Quote",
"an",
"alias",
"if",
"not",
"an",
"int"
] | 921e485c8cc29067f279da2cdd06f47a9bddd115 | https://github.com/phossa2/libs/blob/921e485c8cc29067f279da2cdd06f47a9bddd115/src/Phossa2/Query/Traits/Clause/ClauseTrait.php#L71-L80 | train |
phossa2/libs | src/Phossa2/Query/Traits/Clause/ClauseTrait.php | ClauseTrait.& | protected function &getClause(/*# string */ $clauseName)/*# : array */
{
if (empty($clauseName)) {
return $this->clause;
} else {
if (!isset($this->clause[$clauseName])) {
$this->clause[$clauseName] = [];
}
return $this->clause[$clauseName];
}
} | php | protected function &getClause(/*# string */ $clauseName)/*# : array */
{
if (empty($clauseName)) {
return $this->clause;
} else {
if (!isset($this->clause[$clauseName])) {
$this->clause[$clauseName] = [];
}
return $this->clause[$clauseName];
}
} | [
"protected",
"function",
"&",
"getClause",
"(",
"/*# string */",
"$",
"clauseName",
")",
"/*# : array */",
"{",
"if",
"(",
"empty",
"(",
"$",
"clauseName",
")",
")",
"{",
"return",
"$",
"this",
"->",
"clause",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"is... | Return specific clause part
@param string $clauseName
@param array
@access protected | [
"Return",
"specific",
"clause",
"part"
] | 921e485c8cc29067f279da2cdd06f47a9bddd115 | https://github.com/phossa2/libs/blob/921e485c8cc29067f279da2cdd06f47a9bddd115/src/Phossa2/Query/Traits/Clause/ClauseTrait.php#L130-L140 | train |
phossa2/libs | src/Phossa2/Query/Traits/Clause/ClauseTrait.php | ClauseTrait.processValue | protected function processValue(
$value,
array $settings,
/*# bool */ $between = false
)/*# : string */ {
if (is_object($value)) {
return $this->quoteObject($value, $settings);
} elseif (is_array($value)) {
return $this->processArrayValue($value, $settings, $between);
} else {
return $this->processScalarValue($value);
}
} | php | protected function processValue(
$value,
array $settings,
/*# bool */ $between = false
)/*# : string */ {
if (is_object($value)) {
return $this->quoteObject($value, $settings);
} elseif (is_array($value)) {
return $this->processArrayValue($value, $settings, $between);
} else {
return $this->processScalarValue($value);
}
} | [
"protected",
"function",
"processValue",
"(",
"$",
"value",
",",
"array",
"$",
"settings",
",",
"/*# bool */",
"$",
"between",
"=",
"false",
")",
"/*# : string */",
"{",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"this",
"->... | Process value part in the clause
@param mixed $value
@param array $settings
@return string
@access protected | [
"Process",
"value",
"part",
"in",
"the",
"clause"
] | 921e485c8cc29067f279da2cdd06f47a9bddd115 | https://github.com/phossa2/libs/blob/921e485c8cc29067f279da2cdd06f47a9bddd115/src/Phossa2/Query/Traits/Clause/ClauseTrait.php#L167-L179 | train |
phossa2/libs | src/Phossa2/Query/Traits/Clause/ClauseTrait.php | ClauseTrait.processArrayValue | protected function processArrayValue(
array $value,
array $settings,
/*# bool */ $between = false
)/*# : string */ {
if ($between) {
$v1 = $this->processValue($value[0], $settings);
$v2 = $this->processValue($value[1], $settings);
return $v1 . ' AND ' . $v2;
} else {
$result = [];
foreach ($value as $val) {
$result[] = $this->processValue($val, $settings);
}
return '(' . join(', ', $result) . ')';
}
} | php | protected function processArrayValue(
array $value,
array $settings,
/*# bool */ $between = false
)/*# : string */ {
if ($between) {
$v1 = $this->processValue($value[0], $settings);
$v2 = $this->processValue($value[1], $settings);
return $v1 . ' AND ' . $v2;
} else {
$result = [];
foreach ($value as $val) {
$result[] = $this->processValue($val, $settings);
}
return '(' . join(', ', $result) . ')';
}
} | [
"protected",
"function",
"processArrayValue",
"(",
"array",
"$",
"value",
",",
"array",
"$",
"settings",
",",
"/*# bool */",
"$",
"between",
"=",
"false",
")",
"/*# : string */",
"{",
"if",
"(",
"$",
"between",
")",
"{",
"$",
"v1",
"=",
"$",
"this",
"->"... | Process value array
@param array $value
@param array $settings
@return string
@access protected | [
"Process",
"value",
"array"
] | 921e485c8cc29067f279da2cdd06f47a9bddd115 | https://github.com/phossa2/libs/blob/921e485c8cc29067f279da2cdd06f47a9bddd115/src/Phossa2/Query/Traits/Clause/ClauseTrait.php#L189-L205 | train |
phossa2/libs | src/Phossa2/Query/Traits/Clause/ClauseTrait.php | ClauseTrait.processScalarValue | protected function processScalarValue($value)/*# : string */
{
if (ClauseInterface::NO_VALUE == $value) {
return '?';
} elseif (is_null($value) || is_bool($value)) {
return strtoupper(var_export($value, true));
} else {
return $this->getBuilder()->getParameter()->getPlaceholder($value);
}
} | php | protected function processScalarValue($value)/*# : string */
{
if (ClauseInterface::NO_VALUE == $value) {
return '?';
} elseif (is_null($value) || is_bool($value)) {
return strtoupper(var_export($value, true));
} else {
return $this->getBuilder()->getParameter()->getPlaceholder($value);
}
} | [
"protected",
"function",
"processScalarValue",
"(",
"$",
"value",
")",
"/*# : string */",
"{",
"if",
"(",
"ClauseInterface",
"::",
"NO_VALUE",
"==",
"$",
"value",
")",
"{",
"return",
"'?'",
";",
"}",
"elseif",
"(",
"is_null",
"(",
"$",
"value",
")",
"||",
... | Process scalar value
@param mixed $value
@return string
@access protected | [
"Process",
"scalar",
"value"
] | 921e485c8cc29067f279da2cdd06f47a9bddd115 | https://github.com/phossa2/libs/blob/921e485c8cc29067f279da2cdd06f47a9bddd115/src/Phossa2/Query/Traits/Clause/ClauseTrait.php#L214-L223 | train |
phossa2/libs | src/Phossa2/Query/Traits/Clause/ClauseTrait.php | ClauseTrait.joinClause | protected function joinClause(
/*# : string */ $prefix,
/*# : string */ $seperator,
array $clause,
array $settings
)/*# : string */ {
if (empty($clause)) {
return '';
} else {
$sepr = $settings['seperator'];
$join = $settings['join'];
$pref = empty($prefix) ? $join : ($sepr . $prefix . $join);
return $pref . join($seperator . $join, $clause);
}
} | php | protected function joinClause(
/*# : string */ $prefix,
/*# : string */ $seperator,
array $clause,
array $settings
)/*# : string */ {
if (empty($clause)) {
return '';
} else {
$sepr = $settings['seperator'];
$join = $settings['join'];
$pref = empty($prefix) ? $join : ($sepr . $prefix . $join);
return $pref . join($seperator . $join, $clause);
}
} | [
"protected",
"function",
"joinClause",
"(",
"/*# : string */",
"$",
"prefix",
",",
"/*# : string */",
"$",
"seperator",
",",
"array",
"$",
"clause",
",",
"array",
"$",
"settings",
")",
"/*# : string */",
"{",
"if",
"(",
"empty",
"(",
"$",
"clause",
")",
")",... | Join a clause with prefix and its parts
@param string $prefix
@param string $seperator
@param array $clause
@param array $settings
@return string
@access protected | [
"Join",
"a",
"clause",
"with",
"prefix",
"and",
"its",
"parts"
] | 921e485c8cc29067f279da2cdd06f47a9bddd115 | https://github.com/phossa2/libs/blob/921e485c8cc29067f279da2cdd06f47a9bddd115/src/Phossa2/Query/Traits/Clause/ClauseTrait.php#L235-L249 | train |
phossa2/libs | src/Phossa2/Query/Traits/Clause/ClauseTrait.php | ClauseTrait.buildClause | protected function buildClause(
/*# string */ $clauseName,
/*# string */ $clausePrefix,
array $settings,
array $clauseParts = []
)/*# string */ {
$clause = &$this->getClause($clauseName);
foreach ($clause as $alias => $field) {
$part =
$this->quoteItem($field[0], $settings, $field[1]) .
$this->quoteAlias($alias, $settings) .
(isset($field[2]) ? (' ' . $field[2]) : '');
$clauseParts[] = $part;
}
return $this->joinClause($clausePrefix, ',', $clauseParts, $settings);
} | php | protected function buildClause(
/*# string */ $clauseName,
/*# string */ $clausePrefix,
array $settings,
array $clauseParts = []
)/*# string */ {
$clause = &$this->getClause($clauseName);
foreach ($clause as $alias => $field) {
$part =
$this->quoteItem($field[0], $settings, $field[1]) .
$this->quoteAlias($alias, $settings) .
(isset($field[2]) ? (' ' . $field[2]) : '');
$clauseParts[] = $part;
}
return $this->joinClause($clausePrefix, ',', $clauseParts, $settings);
} | [
"protected",
"function",
"buildClause",
"(",
"/*# string */",
"$",
"clauseName",
",",
"/*# string */",
"$",
"clausePrefix",
",",
"array",
"$",
"settings",
",",
"array",
"$",
"clauseParts",
"=",
"[",
"]",
")",
"/*# string */",
"{",
"$",
"clause",
"=",
"&",
"$... | Build a generic clause
@param string $clauseName
@param string $clausePrefix
@param array $settings
@param array $clauseParts
@return string
@access protected | [
"Build",
"a",
"generic",
"clause"
] | 921e485c8cc29067f279da2cdd06f47a9bddd115 | https://github.com/phossa2/libs/blob/921e485c8cc29067f279da2cdd06f47a9bddd115/src/Phossa2/Query/Traits/Clause/ClauseTrait.php#L261-L276 | train |
jmpantoja/planb-utils | src/DS/Deque/Deque.php | Deque.typed | public static function typed(string $type, iterable $input = []): Deque
{
$resolver = Resolver::typed($type);
return new static($input, $resolver);
} | php | public static function typed(string $type, iterable $input = []): Deque
{
$resolver = Resolver::typed($type);
return new static($input, $resolver);
} | [
"public",
"static",
"function",
"typed",
"(",
"string",
"$",
"type",
",",
"iterable",
"$",
"input",
"=",
"[",
"]",
")",
":",
"Deque",
"{",
"$",
"resolver",
"=",
"Resolver",
"::",
"typed",
"(",
"$",
"type",
")",
";",
"return",
"new",
"static",
"(",
... | Deque named constructor.
@param string $type
@param mixed[] $input
@return \PlanB\DS\Deque\Deque | [
"Deque",
"named",
"constructor",
"."
] | d17fbced4a285275928f8428ee56e269eb851690 | https://github.com/jmpantoja/planb-utils/blob/d17fbced4a285275928f8428ee56e269eb851690/src/DS/Deque/Deque.php#L49-L55 | train |
rseyferth/chickenwire | src/ChickenWire/Util/Html.php | Html.link | public function link($target, $caption = null, $attributes = array())
{
// Check if target needs to be resolved
if (is_object($target)) {
// Try to get a link
$target = Url::instance()->show($target);
}
// Create element
$link = new \HtmlObject\Link($target, $caption, $attributes);
return $link;
} | php | public function link($target, $caption = null, $attributes = array())
{
// Check if target needs to be resolved
if (is_object($target)) {
// Try to get a link
$target = Url::instance()->show($target);
}
// Create element
$link = new \HtmlObject\Link($target, $caption, $attributes);
return $link;
} | [
"public",
"function",
"link",
"(",
"$",
"target",
",",
"$",
"caption",
"=",
"null",
",",
"$",
"attributes",
"=",
"array",
"(",
")",
")",
"{",
"// Check if target needs to be resolved",
"if",
"(",
"is_object",
"(",
"$",
"target",
")",
")",
"{",
"// Try to g... | Create a new Link element
<code>
echo $this->html->link('http://www.google.com/', 'Google', array("target" => "_blank"));
</code>
<code>
<a href="http://www.google.com/" target="_blank">Google</a>
</code>
<br>
<code>
$person = People::find(1);
echo $this->html->link($person, $person->name);
</code>
<code>
<a href="/people/1">John Doe</a>
</code>
<br>
<code>
$person = People::find(1);
echo $this->html->link($this->url->edit($person), "Edit " . $person->name);
</code>
<code>
<a href="/people/1/edit">John Doe</a>
</code>
@param string|\ChickenWire\Model A url or a Model instance to link to. When you pass a Model instance, the Url helper will be used to resolve it to a 'show' action url.
@param string The text/elements to put inside the link.
@param array An array of attributes to add to the element.
@return \HtmlObject\Link The Link element. | [
"Create",
"a",
"new",
"Link",
"element"
] | 74921f0a0d489366602e25df43eda894719e43d3 | https://github.com/rseyferth/chickenwire/blob/74921f0a0d489366602e25df43eda894719e43d3/src/ChickenWire/Util/Html.php#L102-L117 | train |
rseyferth/chickenwire | src/ChickenWire/Util/Html.php | Html.deleteLink | public function deleteLink($target, $caption = null, $confirmMessage = 'Are you sure?', $attributes = array())
{
// Check if target needs to be resolved
if (is_array($target) || is_object($target)) {
// Try to get a link
$target = Url::instance()->delete($target);
}
// Set method to delete
$attributes = array_merge(array(
"data-method" => "delete",
"rel" => "nofollow"
), $attributes);
// Confirm?
if (is_null($confirmMessage)) {
$attributes['data-confirm'] = 'Are you sure?';
} elseif ($confirmMessage !== false) {
$attributes['data-confirm'] = $confirmMessage;
}
// Create element
$link = new \HtmlObject\Link($target, $caption, $attributes);
return $link;
} | php | public function deleteLink($target, $caption = null, $confirmMessage = 'Are you sure?', $attributes = array())
{
// Check if target needs to be resolved
if (is_array($target) || is_object($target)) {
// Try to get a link
$target = Url::instance()->delete($target);
}
// Set method to delete
$attributes = array_merge(array(
"data-method" => "delete",
"rel" => "nofollow"
), $attributes);
// Confirm?
if (is_null($confirmMessage)) {
$attributes['data-confirm'] = 'Are you sure?';
} elseif ($confirmMessage !== false) {
$attributes['data-confirm'] = $confirmMessage;
}
// Create element
$link = new \HtmlObject\Link($target, $caption, $attributes);
return $link;
} | [
"public",
"function",
"deleteLink",
"(",
"$",
"target",
",",
"$",
"caption",
"=",
"null",
",",
"$",
"confirmMessage",
"=",
"'Are you sure?'",
",",
"$",
"attributes",
"=",
"array",
"(",
")",
")",
"{",
"// Check if target needs to be resolved",
"if",
"(",
"is_ar... | Create new delete Link element
**Note** This requires the ChickenWire front-end Javascript library to be included in your page.
@param \ChickenWire\Model|string The Model instance to create the delete link for, or a string containing a url.
@param string The text/elements to put inside the link.
@param string|false The message to confirm the deletion. When false, no message will be shown.
@param array An array of attributes to add to the element.
@return \HtmlObject\Link The Link element. | [
"Create",
"new",
"delete",
"Link",
"element"
] | 74921f0a0d489366602e25df43eda894719e43d3 | https://github.com/rseyferth/chickenwire/blob/74921f0a0d489366602e25df43eda894719e43d3/src/ChickenWire/Util/Html.php#L130-L158 | train |
rseyferth/chickenwire | src/ChickenWire/Util/Html.php | Html.listingFor | public function listingFor($items, \Closure $callback, $attributes = array(), $element = 'ul', $childElement = 'li')
{
// Create the element
$list = \HtmlObject\Element::$element('', $attributes);
// Get closure info
$closureMethod = Reflection::getClosureMethod($callback);
$closureArgs = Reflection::getClosureParams($closureMethod);
// Loop through items
$index = 0;
foreach ($items as $item) {
// Invoke the closure
$li = Reflection::invokeClosure($callback,
array($index, $item),
array($item));
// Is it an element?
if (is_string($li)) {
// Create li containing that...
$realLi = \HtmlObject\Element::$childElement($li);
$list->addChild($realLi);
} elseif (is_subclass_of($li, "\\HtmlObject\\Traits\\Tag")) {
// An li tag?
if ($li->getTag() !== $childElement) {
// Wrap it!
$realLi = \HtmlObject\Element::$childElement($li);
$list->addChild($realLi);
} else {
// Add it as it is
$list->addChild($li);
}
} else {
// Not good.
throw new \Exception("The ulFor callback needs to return a HTMLObject\\Element, or a string containing HTML.", 1);
}
$index++;
}
return $list;
} | php | public function listingFor($items, \Closure $callback, $attributes = array(), $element = 'ul', $childElement = 'li')
{
// Create the element
$list = \HtmlObject\Element::$element('', $attributes);
// Get closure info
$closureMethod = Reflection::getClosureMethod($callback);
$closureArgs = Reflection::getClosureParams($closureMethod);
// Loop through items
$index = 0;
foreach ($items as $item) {
// Invoke the closure
$li = Reflection::invokeClosure($callback,
array($index, $item),
array($item));
// Is it an element?
if (is_string($li)) {
// Create li containing that...
$realLi = \HtmlObject\Element::$childElement($li);
$list->addChild($realLi);
} elseif (is_subclass_of($li, "\\HtmlObject\\Traits\\Tag")) {
// An li tag?
if ($li->getTag() !== $childElement) {
// Wrap it!
$realLi = \HtmlObject\Element::$childElement($li);
$list->addChild($realLi);
} else {
// Add it as it is
$list->addChild($li);
}
} else {
// Not good.
throw new \Exception("The ulFor callback needs to return a HTMLObject\\Element, or a string containing HTML.", 1);
}
$index++;
}
return $list;
} | [
"public",
"function",
"listingFor",
"(",
"$",
"items",
",",
"\\",
"Closure",
"$",
"callback",
",",
"$",
"attributes",
"=",
"array",
"(",
")",
",",
"$",
"element",
"=",
"'ul'",
",",
"$",
"childElement",
"=",
"'li'",
")",
"{",
"// Create the element",
"$",... | Create a listing for the given array of items, using a callback for each item
For example, in a view you might do:
<code>
$this->html->listingFor($this->people, function($person) {
return $person->name;
});
</code>
<code>
<ul>
<li>John Doe</li>
<li>Phil Spector</li>
</ul>
</code>
<br>
Or a little more complex:
<code>
$this->html->listingFor($this->people, function($index, $person) {
return $this->html->link($person, $index . ": " . $person->name);
});
</code>
<code>
<ul>
<li><a href="/people/1">0: John Doe</a></li>
<li><a href="/people/2">1: Phil Spector</a></li>
</ul>
</code>
<br>
And, if you want to modify the list item itself:
<code>
$this->html->listingFor($this->people, function($person) {
return $this->html->li($person->name, array("class" => "person " . $person->gender));
});
</code>
<code>
<ul>
<li class="person male">John Doe</li>
<li class="person female">Jane Doe</li>
</ul>
</code>
@param array Array of items to iterate
@param \Closure The callback function to call for each item
@param array Array of HTML attributes to apply to the listing
@param string The HTML element for the list
@param string The HTML element for the items
@return \HtmlObject\Element | [
"Create",
"a",
"listing",
"for",
"the",
"given",
"array",
"of",
"items",
"using",
"a",
"callback",
"for",
"each",
"item"
] | 74921f0a0d489366602e25df43eda894719e43d3 | https://github.com/rseyferth/chickenwire/blob/74921f0a0d489366602e25df43eda894719e43d3/src/ChickenWire/Util/Html.php#L215-L270 | train |
rseyferth/chickenwire | src/ChickenWire/Util/Html.php | Html.listing | public function listing($contents = array(), $attributes = array(), $element = 'ul', $childElement = 'li')
{
// Create list
$list = \HtmlObject\Element::$element('', $attributes);
// Array?
if (!is_null($contents) && !is_array($contents)) {
$contents = array($contents);
}
// Loop contents
foreach ($contents as $li) {
// Is it an element?
if (is_string($li)) {
// Create li containing that...
$realLi = \HtmlObject\Element::$childElement($li);
$list->addChild($realLi);
} elseif (is_subclass_of($li, "\\HtmlObject\\Traits\\Tag")) {
// An li tag?
if ($li->getTag() !== $childElement) {
// Wrap it!
$realLi = \HtmlObject\Element::$childElement($li);
$list->addChild($realLi);
} else {
// Add it as it is
$list->addChild($li);
}
} else {
// Not good.
throw new \Exception("Invalid contents for listing. ", 1);
}
}
return $list;
} | php | public function listing($contents = array(), $attributes = array(), $element = 'ul', $childElement = 'li')
{
// Create list
$list = \HtmlObject\Element::$element('', $attributes);
// Array?
if (!is_null($contents) && !is_array($contents)) {
$contents = array($contents);
}
// Loop contents
foreach ($contents as $li) {
// Is it an element?
if (is_string($li)) {
// Create li containing that...
$realLi = \HtmlObject\Element::$childElement($li);
$list->addChild($realLi);
} elseif (is_subclass_of($li, "\\HtmlObject\\Traits\\Tag")) {
// An li tag?
if ($li->getTag() !== $childElement) {
// Wrap it!
$realLi = \HtmlObject\Element::$childElement($li);
$list->addChild($realLi);
} else {
// Add it as it is
$list->addChild($li);
}
} else {
// Not good.
throw new \Exception("Invalid contents for listing. ", 1);
}
}
return $list;
} | [
"public",
"function",
"listing",
"(",
"$",
"contents",
"=",
"array",
"(",
")",
",",
"$",
"attributes",
"=",
"array",
"(",
")",
",",
"$",
"element",
"=",
"'ul'",
",",
"$",
"childElement",
"=",
"'li'",
")",
"{",
"// Create list",
"$",
"list",
"=",
"\\"... | Create a new listing
**Simple list**
<code>
$this->html->listing(array('item 1', 'item 2', 'item 3'));
</code>
<code>
$this->html->ul(array('item 1', 'item 2', 'item 3'));
</code>
<code>
<ul>
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
</ul>
</code>
<br>
**Ordered list**
<code>
$this->html->listing(array('item 1', 'item 2', 'item 3'), array(), 'ol');
</code>
<code>
$this->html->ol(array('item 1', 'item 2', 'item 3'));
</code>
<code>
<ol>
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
</ol>
</code>
<br>
**Custom list**
<code>
$this->html->listing(array('item 1', 'item 2', 'item 3'), array('class' => 'listing'), 'div', 'span');
</code>
<code>
<div class="listing">
<span>item 1</span>
<span>item 2</span>
<span>item 3</span>
</div>
</code>
@param array Array of strings or elements to add as list items.
@param array Attributes to add the to the listing element
@param string The HTML element to use for the listing.
@param string The HTML element to use for the list items.
@return \HtmlObject\Element The created element. | [
"Create",
"a",
"new",
"listing"
] | 74921f0a0d489366602e25df43eda894719e43d3 | https://github.com/rseyferth/chickenwire/blob/74921f0a0d489366602e25df43eda894719e43d3/src/ChickenWire/Util/Html.php#L337-L387 | train |
rseyferth/chickenwire | src/ChickenWire/Util/Html.php | Html.li | public function li($contents = '', $attributes = array())
{
$li = \HtmlObject\Element::li($contents, $attributes);
return $li;
} | php | public function li($contents = '', $attributes = array())
{
$li = \HtmlObject\Element::li($contents, $attributes);
return $li;
} | [
"public",
"function",
"li",
"(",
"$",
"contents",
"=",
"''",
",",
"$",
"attributes",
"=",
"array",
"(",
")",
")",
"{",
"$",
"li",
"=",
"\\",
"HtmlObject",
"\\",
"Element",
"::",
"li",
"(",
"$",
"contents",
",",
"$",
"attributes",
")",
";",
"return"... | Create a new list item
@param string|Element The contents of the list item
@param array Attributes to add to the element
@return \HtmlObject\Element The created element | [
"Create",
"a",
"new",
"list",
"item"
] | 74921f0a0d489366602e25df43eda894719e43d3 | https://github.com/rseyferth/chickenwire/blob/74921f0a0d489366602e25df43eda894719e43d3/src/ChickenWire/Util/Html.php#L418-L424 | train |
railsphp/framework | src/Rails/ActionDispatch/Http/Session.php | Session.start | public function start($name = null, $id = null)
{
if (!session_id()) {
if ($name) {
session_name($name);
}
if ($id) {
session_id($this->id);
}
session_start();
return true;
}
return false;
} | php | public function start($name = null, $id = null)
{
if (!session_id()) {
if ($name) {
session_name($name);
}
if ($id) {
session_id($this->id);
}
session_start();
return true;
}
return false;
} | [
"public",
"function",
"start",
"(",
"$",
"name",
"=",
"null",
",",
"$",
"id",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"session_id",
"(",
")",
")",
"{",
"if",
"(",
"$",
"name",
")",
"{",
"session_name",
"(",
"$",
"name",
")",
";",
"}",
"if",
"(... | Starts the PHP session, if not yet started. | [
"Starts",
"the",
"PHP",
"session",
"if",
"not",
"yet",
"started",
"."
] | 2ac9d3e493035dcc68f3c3812423327127327cd5 | https://github.com/railsphp/framework/blob/2ac9d3e493035dcc68f3c3812423327127327cd5/src/Rails/ActionDispatch/Http/Session.php#L82-L95 | train |
railsphp/framework | src/Rails/ActionDispatch/Http/Session.php | Session.destroy | public function destroy()
{
$_SESSION = [];
if ($this->cookieJar) {
$this->cookieJar->remove($this->name());
} else {
$params = session_get_cookie_params();
setcookie($this->name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}
session_destroy();
} | php | public function destroy()
{
$_SESSION = [];
if ($this->cookieJar) {
$this->cookieJar->remove($this->name());
} else {
$params = session_get_cookie_params();
setcookie($this->name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}
session_destroy();
} | [
"public",
"function",
"destroy",
"(",
")",
"{",
"$",
"_SESSION",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"cookieJar",
")",
"{",
"$",
"this",
"->",
"cookieJar",
"->",
"remove",
"(",
"$",
"this",
"->",
"name",
"(",
")",
")",
";",
"}",
"... | Destroys the PHP session. | [
"Destroys",
"the",
"PHP",
"session",
"."
] | 2ac9d3e493035dcc68f3c3812423327127327cd5 | https://github.com/railsphp/framework/blob/2ac9d3e493035dcc68f3c3812423327127327cd5/src/Rails/ActionDispatch/Http/Session.php#L100-L115 | train |
zepi/turbo-base | Zepi/Web/UserInterface/src/Form/Group.php | Group.getHtmlId | public function getHtmlId()
{
$form = $this->getParentOfType('\\Zepi\\Web\\UserInterface\\Form\\Form');
// If the group isn't assigned to a data form we can not generate
// the id of the group.
if (!$form) {
return $this->key;
}
return $form->getHtmlId() . '-' . $this->key;
} | php | public function getHtmlId()
{
$form = $this->getParentOfType('\\Zepi\\Web\\UserInterface\\Form\\Form');
// If the group isn't assigned to a data form we can not generate
// the id of the group.
if (!$form) {
return $this->key;
}
return $form->getHtmlId() . '-' . $this->key;
} | [
"public",
"function",
"getHtmlId",
"(",
")",
"{",
"$",
"form",
"=",
"$",
"this",
"->",
"getParentOfType",
"(",
"'\\\\Zepi\\\\Web\\\\UserInterface\\\\Form\\\\Form'",
")",
";",
"// If the group isn't assigned to a data form we can not generate",
"// the id of the group.",
"if",
... | Returns the html id of this group
@access public
@return string | [
"Returns",
"the",
"html",
"id",
"of",
"this",
"group"
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Web/UserInterface/src/Form/Group.php#L94-L105 | train |
coolms/common | src/Form/Annotation/AnnotationBuilderTrait.php | AnnotationBuilderTrait.getFormFactory | public function getFormFactory()
{
if ($this->formFactory) {
return $this->formFactory;
}
$this->formFactory = new Factory();
return $this->formFactory;
} | php | public function getFormFactory()
{
if ($this->formFactory) {
return $this->formFactory;
}
$this->formFactory = new Factory();
return $this->formFactory;
} | [
"public",
"function",
"getFormFactory",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"formFactory",
")",
"{",
"return",
"$",
"this",
"->",
"formFactory",
";",
"}",
"$",
"this",
"->",
"formFactory",
"=",
"new",
"Factory",
"(",
")",
";",
"return",
"$",
... | Retrieve form factory
Lazy-loads the default form factory if none is currently set.
@return Factory | [
"Retrieve",
"form",
"factory"
] | 3572993cdcdb2898cdde396a2f1de9864b193660 | https://github.com/coolms/common/blob/3572993cdcdb2898cdde396a2f1de9864b193660/src/Form/Annotation/AnnotationBuilderTrait.php#L32-L40 | train |
coolms/common | src/Form/Annotation/AnnotationBuilderTrait.php | AnnotationBuilderTrait.createForm | public function createForm($entity)
{
$formSpec = ArrayUtils::iteratorToArray($this->getFormSpecification($entity));
if (!isset($formSpec['options']['merge_input_filter'])) {
$formSpec['options']['merge_input_filter'] = true;
}
return $this->getFormFactory()->createForm($formSpec);
} | php | public function createForm($entity)
{
$formSpec = ArrayUtils::iteratorToArray($this->getFormSpecification($entity));
if (!isset($formSpec['options']['merge_input_filter'])) {
$formSpec['options']['merge_input_filter'] = true;
}
return $this->getFormFactory()->createForm($formSpec);
} | [
"public",
"function",
"createForm",
"(",
"$",
"entity",
")",
"{",
"$",
"formSpec",
"=",
"ArrayUtils",
"::",
"iteratorToArray",
"(",
"$",
"this",
"->",
"getFormSpecification",
"(",
"$",
"entity",
")",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"formSpec... | Create a form from an object.
@param string|object $entity
@return \CmsCommon\Form\FormInterface | [
"Create",
"a",
"form",
"from",
"an",
"object",
"."
] | 3572993cdcdb2898cdde396a2f1de9864b193660 | https://github.com/coolms/common/blob/3572993cdcdb2898cdde396a2f1de9864b193660/src/Form/Annotation/AnnotationBuilderTrait.php#L48-L56 | train |
coolms/common | src/Form/Annotation/AnnotationBuilderTrait.php | AnnotationBuilderTrait.configureElement | protected function configureElement($annotations, $reflection, $formSpec, $filterSpec)
{
// If the element is marked as exclude, return early
if ($this->checkForExclude($annotations)) {
return;
}
$events = $this->getEventManager();
$name = $this->discoverName($annotations, $reflection);
$elementSpec = new ArrayObject([
'flags' => [],
'spec' => [
'name' => $name
],
]);
$inputSpec = new ArrayObject([
'name' => $name,
]);
$event = new Event();
$event->setParams([
'name' => $name,
'elementSpec' => $elementSpec,
'inputSpec' => $inputSpec,
'formSpec' => $formSpec,
'filterSpec' => $filterSpec,
]);
foreach ($annotations as $annotation) {
$event->setParam('annotation', $annotation);
$events->trigger(__FUNCTION__, $this, $event);
}
// Since "filters", "type", "validators" is a reserved names in the filter specification,
// we need to add the specification without the name as the key.
// In all other cases, though, the name is fine.
if ($event->getParam('inputSpec')->count() > 1 || $annotations->hasAnnotation(Input::class)) {
if ($name === 'type' || $name === 'filters' || $name === 'validators') {
$filterSpec[] = $event->getParam('inputSpec');
} else {
$filterSpec[$name] = $event->getParam('inputSpec');
}
}
$elementSpec = $event->getParam('elementSpec');
$type = isset($elementSpec['spec']['type'])
? $elementSpec['spec']['type']
: Element::class;
// Compose as a fieldset or an element, based on specification type.
// If preserve defined order is true, all elements are composed as elements to keep their ordering
if (!$this->preserveDefinedOrder() && is_subclass_of($type, FieldsetInterface::class)) {
if (!isset($formSpec['fieldsets'])) {
$formSpec['fieldsets'] = [];
}
if (isset($formSpec['fieldsets'][$name])) {
$formSpec['fieldsets'][] = $elementSpec;
} else {
$formSpec['fieldsets'][$name] = $elementSpec;
}
} else {
if (!isset($formSpec['elements'])) {
$formSpec['elements'] = [];
}
if (isset($formSpec['elements'][$name])) {
$formSpec['elements'][] = $elementSpec;
} else {
$formSpec['elements'][$name] = $elementSpec;
}
}
} | php | protected function configureElement($annotations, $reflection, $formSpec, $filterSpec)
{
// If the element is marked as exclude, return early
if ($this->checkForExclude($annotations)) {
return;
}
$events = $this->getEventManager();
$name = $this->discoverName($annotations, $reflection);
$elementSpec = new ArrayObject([
'flags' => [],
'spec' => [
'name' => $name
],
]);
$inputSpec = new ArrayObject([
'name' => $name,
]);
$event = new Event();
$event->setParams([
'name' => $name,
'elementSpec' => $elementSpec,
'inputSpec' => $inputSpec,
'formSpec' => $formSpec,
'filterSpec' => $filterSpec,
]);
foreach ($annotations as $annotation) {
$event->setParam('annotation', $annotation);
$events->trigger(__FUNCTION__, $this, $event);
}
// Since "filters", "type", "validators" is a reserved names in the filter specification,
// we need to add the specification without the name as the key.
// In all other cases, though, the name is fine.
if ($event->getParam('inputSpec')->count() > 1 || $annotations->hasAnnotation(Input::class)) {
if ($name === 'type' || $name === 'filters' || $name === 'validators') {
$filterSpec[] = $event->getParam('inputSpec');
} else {
$filterSpec[$name] = $event->getParam('inputSpec');
}
}
$elementSpec = $event->getParam('elementSpec');
$type = isset($elementSpec['spec']['type'])
? $elementSpec['spec']['type']
: Element::class;
// Compose as a fieldset or an element, based on specification type.
// If preserve defined order is true, all elements are composed as elements to keep their ordering
if (!$this->preserveDefinedOrder() && is_subclass_of($type, FieldsetInterface::class)) {
if (!isset($formSpec['fieldsets'])) {
$formSpec['fieldsets'] = [];
}
if (isset($formSpec['fieldsets'][$name])) {
$formSpec['fieldsets'][] = $elementSpec;
} else {
$formSpec['fieldsets'][$name] = $elementSpec;
}
} else {
if (!isset($formSpec['elements'])) {
$formSpec['elements'] = [];
}
if (isset($formSpec['elements'][$name])) {
$formSpec['elements'][] = $elementSpec;
} else {
$formSpec['elements'][$name] = $elementSpec;
}
}
} | [
"protected",
"function",
"configureElement",
"(",
"$",
"annotations",
",",
"$",
"reflection",
",",
"$",
"formSpec",
",",
"$",
"filterSpec",
")",
"{",
"// If the element is marked as exclude, return early",
"if",
"(",
"$",
"this",
"->",
"checkForExclude",
"(",
"$",
... | Configure an element from annotations
@param AnnotationCollection $annotations
@param PropertyReflection $reflection
@param ArrayObject $formSpec
@param ArrayObject $filterSpec
@return void
@triggers checkForExclude
@triggers discoverName
@triggers configureElement | [
"Configure",
"an",
"element",
"from",
"annotations"
] | 3572993cdcdb2898cdde396a2f1de9864b193660 | https://github.com/coolms/common/blob/3572993cdcdb2898cdde396a2f1de9864b193660/src/Form/Annotation/AnnotationBuilderTrait.php#L71-L146 | train |
Fenzland/Htsl.php | libs/Htsl.php | Htsl.compile | public function compile( string$fromFile, string$toFile='' )
{
$fromFile= $this->getFilePath($fromFile);
$result= $this->execute(new FileBuffer($this,$fromFile));
if( $toFile ){
return file_put_contents($toFile,$result);
}else{
return $result;
}
} | php | public function compile( string$fromFile, string$toFile='' )
{
$fromFile= $this->getFilePath($fromFile);
$result= $this->execute(new FileBuffer($this,$fromFile));
if( $toFile ){
return file_put_contents($toFile,$result);
}else{
return $result;
}
} | [
"public",
"function",
"compile",
"(",
"string",
"$",
"fromFile",
",",
"string",
"$",
"toFile",
"=",
"''",
")",
"{",
"$",
"fromFile",
"=",
"$",
"this",
"->",
"getFilePath",
"(",
"$",
"fromFile",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"execut... | Compiling a HTSL file into a HTML or PHP file.
@api
@access public
@param string $fromFile
@param string $toFile
@return int|string | [
"Compiling",
"a",
"HTSL",
"file",
"into",
"a",
"HTML",
"or",
"PHP",
"file",
"."
] | 28ecc4afd1a5bdb29dea3589c8132adba87f3947 | https://github.com/Fenzland/Htsl.php/blob/28ecc4afd1a5bdb29dea3589c8132adba87f3947/libs/Htsl.php#L92-L103 | train |
Fenzland/Htsl.php | libs/Htsl.php | Htsl.setBasePath | public function setBasePath( string$basePath ):self
{
$this->basePath= '/'===substr($basePath,-1) ? substr($basePath,0,-1) : $basePath;
return $this;
} | php | public function setBasePath( string$basePath ):self
{
$this->basePath= '/'===substr($basePath,-1) ? substr($basePath,0,-1) : $basePath;
return $this;
} | [
"public",
"function",
"setBasePath",
"(",
"string",
"$",
"basePath",
")",
":",
"self",
"{",
"$",
"this",
"->",
"basePath",
"=",
"'/'",
"===",
"substr",
"(",
"$",
"basePath",
",",
"-",
"1",
")",
"?",
"substr",
"(",
"$",
"basePath",
",",
"0",
",",
"-... | Setting the base path of the HTSL project to parse.
@api
@access public
@param string $basePath
@return self | [
"Setting",
"the",
"base",
"path",
"of",
"the",
"HTSL",
"project",
"to",
"parse",
"."
] | 28ecc4afd1a5bdb29dea3589c8132adba87f3947 | https://github.com/Fenzland/Htsl.php/blob/28ecc4afd1a5bdb29dea3589c8132adba87f3947/libs/Htsl.php#L132-L137 | train |
Fenzland/Htsl.php | libs/Htsl.php | Htsl.getConfig | public function getConfig( string...$keys )
{
$result= $this->config;
foreach( $keys as $key ){
if( !isset($result[$key]) )
{ return null; }
$result= $result[$key];
}
return $result;
} | php | public function getConfig( string...$keys )
{
$result= $this->config;
foreach( $keys as $key ){
if( !isset($result[$key]) )
{ return null; }
$result= $result[$key];
}
return $result;
} | [
"public",
"function",
"getConfig",
"(",
"string",
"...",
"$",
"keys",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"config",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"result",
"[",
"$",
... | Getting the config of Htsl.
@internal
@access public
@param string $keys
@return mixed | [
"Getting",
"the",
"config",
"of",
"Htsl",
"."
] | 28ecc4afd1a5bdb29dea3589c8132adba87f3947 | https://github.com/Fenzland/Htsl.php/blob/28ecc4afd1a5bdb29dea3589c8132adba87f3947/libs/Htsl.php#L180-L192 | train |
Fenzland/Htsl.php | libs/Htsl.php | Htsl.getFilePath | public function getFilePath( string$filePath, string$path=null ):string
{
if( !isset($this->basePath) )
{ throw new \Exception('BasePath musbe set.'); }
if( !strlen($filePath) )
{ throw new \Exception('FilePath cannot be empty.'); }
if( '/'===$filePath{0} ){
if( is_null($path) )
{ return $filePath; }
else
{ return $this->basePath.$filePath; }
}else{
if( !strlen($path) )
{ return $this->basePath.'/'.$filePath; }
elseif( '/'===substr($path,-1) )
{ return $path.$filePath; }
else
{ return $path.'/'.$filePath; }
}
} | php | public function getFilePath( string$filePath, string$path=null ):string
{
if( !isset($this->basePath) )
{ throw new \Exception('BasePath musbe set.'); }
if( !strlen($filePath) )
{ throw new \Exception('FilePath cannot be empty.'); }
if( '/'===$filePath{0} ){
if( is_null($path) )
{ return $filePath; }
else
{ return $this->basePath.$filePath; }
}else{
if( !strlen($path) )
{ return $this->basePath.'/'.$filePath; }
elseif( '/'===substr($path,-1) )
{ return $path.$filePath; }
else
{ return $path.'/'.$filePath; }
}
} | [
"public",
"function",
"getFilePath",
"(",
"string",
"$",
"filePath",
",",
"string",
"$",
"path",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"basePath",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",... | Getting the real file path of the HTSL file by relative path.
@internal
@access public
@param string $filePath
@param string|null $path
@return string | [
"Getting",
"the",
"real",
"file",
"path",
"of",
"the",
"HTSL",
"file",
"by",
"relative",
"path",
"."
] | 28ecc4afd1a5bdb29dea3589c8132adba87f3947 | https://github.com/Fenzland/Htsl.php/blob/28ecc4afd1a5bdb29dea3589c8132adba87f3947/libs/Htsl.php#L206-L228 | train |
Fenzland/Htsl.php | libs/Htsl.php | Htsl.getFileContent | public function getFileContent( string$filePath ):string
{
return isset($this->fileGetter) ? $this->fileGetter($filePath) : file_get_contents($filePath);
} | php | public function getFileContent( string$filePath ):string
{
return isset($this->fileGetter) ? $this->fileGetter($filePath) : file_get_contents($filePath);
} | [
"public",
"function",
"getFileContent",
"(",
"string",
"$",
"filePath",
")",
":",
"string",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"fileGetter",
")",
"?",
"$",
"this",
"->",
"fileGetter",
"(",
"$",
"filePath",
")",
":",
"file_get_contents",
"(",
... | Getting the content of file.
@internal
@access public
@param string $filePath
@return string | [
"Getting",
"the",
"content",
"of",
"file",
"."
] | 28ecc4afd1a5bdb29dea3589c8132adba87f3947 | https://github.com/Fenzland/Htsl.php/blob/28ecc4afd1a5bdb29dea3589c8132adba87f3947/libs/Htsl.php#L241-L244 | train |
mpaleo/scaffolder-support | src/Scaffolder/Support/InputTypeResolverTrait.php | InputTypeResolverTrait.getInputFor | public static function getInputFor(\stdClass $fieldData)
{
$formData = explode(':', $fieldData->type->ui);
$type = $formData[0];
$options = isset($formData[1]) ? $formData[1] : '[]';
if ($type == 'text' ||
$type == 'number' ||
$type == 'textarea' ||
$type == 'date'
)
{
return '{!! Form::' . $type . '(\'' . $fieldData->name . '\', (isset($model)) ? $model->' . $fieldData->name . ' : null, ' . $options . ') !!}';
}
elseif ($type == 'select')
{
$list = isset($formData[1]) ? $formData[1] : '[]';
$options = isset($formData[2]) ? $formData[2] : '[]';
return '{!! Form::select(\'' . $fieldData->name . '\', ' . $list . ', (isset($model)) ? $model->' . $fieldData->name . ' : null, ' . $options . ') !!}';
}
elseif ($type == 'selectRange')
{
$begin = isset($formData[1]) ? $formData[1] : '0';
$end = isset($formData[2]) ? $formData[2] : '0';
$options = isset($formData[3]) ? $formData[3] : '[]';
return '{!! Form::selectRange(\'' . $fieldData->name . '\', ' . $begin . ', ' . $end . ', (isset($model)) ? $model->' . $fieldData->name . ' : null, ' . $options . ') !!}';
}
elseif ($type == 'checkbox')
{
$options = isset($formData[1]) ? $formData[1] : 'false';
return '{!! Form::checkbox(\'' . $fieldData->name . '\', 1, (isset($model) && $model->' . $fieldData->name . ' == 1) ? true : false, ' . $options . ') !!}';
}
elseif ($type == 'radio')
{
array_shift($formData);
$radioGroup = '';
$radioId = 0;
foreach ($formData as $value)
{
$radioGroup .= '{!! Form::radio(\'' . $fieldData->name . '\', \'' . $value . '\', (isset($model) && $model->' . $fieldData->name . ' == \'' . $value . '\') ? true : false, [\'id\' => ' . $radioId . ']) !!}';
$radioId++;
if (end($formData) != $value) $radioGroup .= PHP_EOL . "\t";
}
return $radioGroup;
}
else
{
throw new \Exception('Input type not implemented');
}
} | php | public static function getInputFor(\stdClass $fieldData)
{
$formData = explode(':', $fieldData->type->ui);
$type = $formData[0];
$options = isset($formData[1]) ? $formData[1] : '[]';
if ($type == 'text' ||
$type == 'number' ||
$type == 'textarea' ||
$type == 'date'
)
{
return '{!! Form::' . $type . '(\'' . $fieldData->name . '\', (isset($model)) ? $model->' . $fieldData->name . ' : null, ' . $options . ') !!}';
}
elseif ($type == 'select')
{
$list = isset($formData[1]) ? $formData[1] : '[]';
$options = isset($formData[2]) ? $formData[2] : '[]';
return '{!! Form::select(\'' . $fieldData->name . '\', ' . $list . ', (isset($model)) ? $model->' . $fieldData->name . ' : null, ' . $options . ') !!}';
}
elseif ($type == 'selectRange')
{
$begin = isset($formData[1]) ? $formData[1] : '0';
$end = isset($formData[2]) ? $formData[2] : '0';
$options = isset($formData[3]) ? $formData[3] : '[]';
return '{!! Form::selectRange(\'' . $fieldData->name . '\', ' . $begin . ', ' . $end . ', (isset($model)) ? $model->' . $fieldData->name . ' : null, ' . $options . ') !!}';
}
elseif ($type == 'checkbox')
{
$options = isset($formData[1]) ? $formData[1] : 'false';
return '{!! Form::checkbox(\'' . $fieldData->name . '\', 1, (isset($model) && $model->' . $fieldData->name . ' == 1) ? true : false, ' . $options . ') !!}';
}
elseif ($type == 'radio')
{
array_shift($formData);
$radioGroup = '';
$radioId = 0;
foreach ($formData as $value)
{
$radioGroup .= '{!! Form::radio(\'' . $fieldData->name . '\', \'' . $value . '\', (isset($model) && $model->' . $fieldData->name . ' == \'' . $value . '\') ? true : false, [\'id\' => ' . $radioId . ']) !!}';
$radioId++;
if (end($formData) != $value) $radioGroup .= PHP_EOL . "\t";
}
return $radioGroup;
}
else
{
throw new \Exception('Input type not implemented');
}
} | [
"public",
"static",
"function",
"getInputFor",
"(",
"\\",
"stdClass",
"$",
"fieldData",
")",
"{",
"$",
"formData",
"=",
"explode",
"(",
"':'",
",",
"$",
"fieldData",
"->",
"type",
"->",
"ui",
")",
";",
"$",
"type",
"=",
"$",
"formData",
"[",
"0",
"]"... | Get the input for the field.
@param \stdClass $fieldData
@return string
@throws \Exception | [
"Get",
"the",
"input",
"for",
"the",
"field",
"."
] | d599c88596c65302a984078cd0519221a2d2ceac | https://github.com/mpaleo/scaffolder-support/blob/d599c88596c65302a984078cd0519221a2d2ceac/src/Scaffolder/Support/InputTypeResolverTrait.php#L15-L70 | train |
harpya/ufw-base | src/ufw/Router.php | Router.processMap | protected function processMap($arr, $prefix='') {
foreach ($arr as $uri => $options) {
$uri = $prefix . $this->preProcessURI($uri);
foreach ($options as $method => $target) {
if (!is_array($target)) continue;
if (array_key_exists('name', $target)) {
$this->map($method, $uri, $target, $target['name']);
} else {
$this->map($method, $uri, $target);
}
}
}
} | php | protected function processMap($arr, $prefix='') {
foreach ($arr as $uri => $options) {
$uri = $prefix . $this->preProcessURI($uri);
foreach ($options as $method => $target) {
if (!is_array($target)) continue;
if (array_key_exists('name', $target)) {
$this->map($method, $uri, $target, $target['name']);
} else {
$this->map($method, $uri, $target);
}
}
}
} | [
"protected",
"function",
"processMap",
"(",
"$",
"arr",
",",
"$",
"prefix",
"=",
"''",
")",
"{",
"foreach",
"(",
"$",
"arr",
"as",
"$",
"uri",
"=>",
"$",
"options",
")",
"{",
"$",
"uri",
"=",
"$",
"prefix",
".",
"$",
"this",
"->",
"preProcessURI",
... | For each array item, pre process and add to global mapping
@param array $arr
@param string $prefix | [
"For",
"each",
"array",
"item",
"pre",
"process",
"and",
"add",
"to",
"global",
"mapping"
] | 9e2db1d9625f4b875783f98830e0410cf4fd125b | https://github.com/harpya/ufw-base/blob/9e2db1d9625f4b875783f98830e0410cf4fd125b/src/ufw/Router.php#L74-L92 | train |
harpya/ufw-base | src/ufw/Router.php | Router.preProcessURI | public function preProcessURI($uri) {
$s = preg_replace("/\{([\w]+)\}/", "[*:$1]", $uri);
if (!empty($s)) {
$uri = $s;
}
return $uri;
} | php | public function preProcessURI($uri) {
$s = preg_replace("/\{([\w]+)\}/", "[*:$1]", $uri);
if (!empty($s)) {
$uri = $s;
}
return $uri;
} | [
"public",
"function",
"preProcessURI",
"(",
"$",
"uri",
")",
"{",
"$",
"s",
"=",
"preg_replace",
"(",
"\"/\\{([\\w]+)\\}/\"",
",",
"\"[*:$1]\"",
",",
"$",
"uri",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"s",
")",
")",
"{",
"$",
"uri",
"=",
"$",... | Replace the macros by regular expressions to extract arguments from URL
@param string $uri
@return string | [
"Replace",
"the",
"macros",
"by",
"regular",
"expressions",
"to",
"extract",
"arguments",
"from",
"URL"
] | 9e2db1d9625f4b875783f98830e0410cf4fd125b | https://github.com/harpya/ufw-base/blob/9e2db1d9625f4b875783f98830e0410cf4fd125b/src/ufw/Router.php#L99-L107 | train |
harpya/ufw-base | src/ufw/Router.php | Router.evaluate | public function evaluate($target) {
switch (Utils::get('type', $target)) {
case 'class' :
$return = $this->processClass(Utils::get('target',$target), Utils::get('match', $target));
break;
case 'controller' :
$return = $this->processController(Utils::get('target', $target), Utils::get('match', $target));
break;
case 'view':
$return = $this->processView(Utils::get('target', $target), Utils::get('match', $target));
break;
case 'eval':
$return = eval($target['target']['eval']);
break;
default:
throw new \Exception("Undefined target",404);
}
return $return;
} | php | public function evaluate($target) {
switch (Utils::get('type', $target)) {
case 'class' :
$return = $this->processClass(Utils::get('target',$target), Utils::get('match', $target));
break;
case 'controller' :
$return = $this->processController(Utils::get('target', $target), Utils::get('match', $target));
break;
case 'view':
$return = $this->processView(Utils::get('target', $target), Utils::get('match', $target));
break;
case 'eval':
$return = eval($target['target']['eval']);
break;
default:
throw new \Exception("Undefined target",404);
}
return $return;
} | [
"public",
"function",
"evaluate",
"(",
"$",
"target",
")",
"{",
"switch",
"(",
"Utils",
"::",
"get",
"(",
"'type'",
",",
"$",
"target",
")",
")",
"{",
"case",
"'class'",
":",
"$",
"return",
"=",
"$",
"this",
"->",
"processClass",
"(",
"Utils",
"::",
... | Determine which type of target is, and execute it.
@param array $target
@return mixed
@throws \Exception | [
"Determine",
"which",
"type",
"of",
"target",
"is",
"and",
"execute",
"it",
"."
] | 9e2db1d9625f4b875783f98830e0410cf4fd125b | https://github.com/harpya/ufw-base/blob/9e2db1d9625f4b875783f98830e0410cf4fd125b/src/ufw/Router.php#L120-L140 | train |
harpya/ufw-base | src/ufw/Router.php | Router.resolve | public function resolve() {
$return = false;
$match = $this->match();
if (!$match) {
$target = $this->getDefaultRoute();
if ($target) {
$match = ['target' => $target];
}
}
if (substr(Utils::get('name', $match, ''),0,7) =='plugin:') {
Application::getInstance()->preparePlugin($match['name']);
}
if (is_array($match) && array_key_exists('target', $match)) {
$target = $match['target'];
$return = ['target'=>$target, 'match'=>$match, 'application' => $this->getApplicationName()];
if (array_key_exists('class', $target)) {
$return['type'] = 'class';
} elseif (array_key_exists('controller', $target)) {
$return['type'] = 'controller';
} elseif (array_key_exists('view', $target)) {
$return['type'] = 'view';
} elseif (array_key_exists('eval', $target)) {
$return['type'] = 'eval';
} else {
$return = ['success'=>false, 'msg' => "Target undefined",'code'=>404, 'info'=> $match];
}
} else {
$return = ['success'=>false, 'msg' => "Target not found",'code'=>404, 'info'=> $match];
}
return $return;
} | php | public function resolve() {
$return = false;
$match = $this->match();
if (!$match) {
$target = $this->getDefaultRoute();
if ($target) {
$match = ['target' => $target];
}
}
if (substr(Utils::get('name', $match, ''),0,7) =='plugin:') {
Application::getInstance()->preparePlugin($match['name']);
}
if (is_array($match) && array_key_exists('target', $match)) {
$target = $match['target'];
$return = ['target'=>$target, 'match'=>$match, 'application' => $this->getApplicationName()];
if (array_key_exists('class', $target)) {
$return['type'] = 'class';
} elseif (array_key_exists('controller', $target)) {
$return['type'] = 'controller';
} elseif (array_key_exists('view', $target)) {
$return['type'] = 'view';
} elseif (array_key_exists('eval', $target)) {
$return['type'] = 'eval';
} else {
$return = ['success'=>false, 'msg' => "Target undefined",'code'=>404, 'info'=> $match];
}
} else {
$return = ['success'=>false, 'msg' => "Target not found",'code'=>404, 'info'=> $match];
}
return $return;
} | [
"public",
"function",
"resolve",
"(",
")",
"{",
"$",
"return",
"=",
"false",
";",
"$",
"match",
"=",
"$",
"this",
"->",
"match",
"(",
")",
";",
"if",
"(",
"!",
"$",
"match",
")",
"{",
"$",
"target",
"=",
"$",
"this",
"->",
"getDefaultRoute",
"(",... | Perform the match among the URI and the routes available
@return mixed | [
"Perform",
"the",
"match",
"among",
"the",
"URI",
"and",
"the",
"routes",
"available"
] | 9e2db1d9625f4b875783f98830e0410cf4fd125b | https://github.com/harpya/ufw-base/blob/9e2db1d9625f4b875783f98830e0410cf4fd125b/src/ufw/Router.php#L164-L203 | train |
frogsystem/legacy-bridge | src/Controllers/AdminController.php | AdminController.assets | public function assets(Response $response, $asset)
{
$filesystem = new Filesystem(new Adapter(FS2ADMIN));
$expires = 8640000;
try {
// generate cache data
$timestamp_string = gmdate('D, d M Y H:i:s ', $filesystem->getTimestamp($asset)) . 'GMT';
$etag = md5($filesystem->read($asset));
$mime_type = $filesystem->getMimetype($asset);
if (0 !== strpos($mime_type, 'image')) {
$mime_type = 'text/css';
}
$if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : false;
$if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? $_SERVER['HTTP_IF_NONE_MATCH'] : false;
if ((($if_none_match && $if_none_match == "\"{$etag}\"") || (!$if_none_match)) &&
($if_modified_since && $if_modified_since == $timestamp_string)
) {
return $response->withStatus('304');
} else {
$response = $response
->withHeader('Last-Modified', $timestamp_string)
->withHeader('ETag', "\"{$etag}\"");
}
// send out content type, expire time and the file
$response->getBody()->write($filesystem->read($asset));
return $response
->withHeader('Expires', gmdate('D, d M Y H:i:s ', time() + $expires) . 'GMT')
->withHeader('Content-Type', $mime_type)
->withHeader('Pragma', 'cache')
->withHeader('Cache-Control', 'cache');
} catch (FileNotFoundException $e) {
throw $e;
}
} | php | public function assets(Response $response, $asset)
{
$filesystem = new Filesystem(new Adapter(FS2ADMIN));
$expires = 8640000;
try {
// generate cache data
$timestamp_string = gmdate('D, d M Y H:i:s ', $filesystem->getTimestamp($asset)) . 'GMT';
$etag = md5($filesystem->read($asset));
$mime_type = $filesystem->getMimetype($asset);
if (0 !== strpos($mime_type, 'image')) {
$mime_type = 'text/css';
}
$if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : false;
$if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? $_SERVER['HTTP_IF_NONE_MATCH'] : false;
if ((($if_none_match && $if_none_match == "\"{$etag}\"") || (!$if_none_match)) &&
($if_modified_since && $if_modified_since == $timestamp_string)
) {
return $response->withStatus('304');
} else {
$response = $response
->withHeader('Last-Modified', $timestamp_string)
->withHeader('ETag', "\"{$etag}\"");
}
// send out content type, expire time and the file
$response->getBody()->write($filesystem->read($asset));
return $response
->withHeader('Expires', gmdate('D, d M Y H:i:s ', time() + $expires) . 'GMT')
->withHeader('Content-Type', $mime_type)
->withHeader('Pragma', 'cache')
->withHeader('Cache-Control', 'cache');
} catch (FileNotFoundException $e) {
throw $e;
}
} | [
"public",
"function",
"assets",
"(",
"Response",
"$",
"response",
",",
"$",
"asset",
")",
"{",
"$",
"filesystem",
"=",
"new",
"Filesystem",
"(",
"new",
"Adapter",
"(",
"FS2ADMIN",
")",
")",
";",
"$",
"expires",
"=",
"8640000",
";",
"try",
"{",
"// gene... | Return admin assets
@param Response $response
@param $asset
@return Response|static
@throws FileNotFoundException | [
"Return",
"admin",
"assets"
] | a4ea3bea701e2b737c119a5d89b7778e8745658c | https://github.com/frogsystem/legacy-bridge/blob/a4ea3bea701e2b737c119a5d89b7778e8745658c/src/Controllers/AdminController.php#L56-L95 | train |
laravie/quemon | src/Http/Controllers/QueueController.php | QueueController.index | public function index()
{
try {
$jobs = FailedJob::orderBy('id', 'DESC')->paginate();
} catch (QueryException $e) {
return $this->setup();
}
return view('laravie/quemon::index', compact('jobs'));
} | php | public function index()
{
try {
$jobs = FailedJob::orderBy('id', 'DESC')->paginate();
} catch (QueryException $e) {
return $this->setup();
}
return view('laravie/quemon::index', compact('jobs'));
} | [
"public",
"function",
"index",
"(",
")",
"{",
"try",
"{",
"$",
"jobs",
"=",
"FailedJob",
"::",
"orderBy",
"(",
"'id'",
",",
"'DESC'",
")",
"->",
"paginate",
"(",
")",
";",
"}",
"catch",
"(",
"QueryException",
"$",
"e",
")",
"{",
"return",
"$",
"thi... | List of failed jobs.
@return mixed | [
"List",
"of",
"failed",
"jobs",
"."
] | e548782301934d99c7e7262386e14e263a9d5422 | https://github.com/laravie/quemon/blob/e548782301934d99c7e7262386e14e263a9d5422/src/Http/Controllers/QueueController.php#L29-L38 | train |
dazarobbo/Cola | src/ArrayList.php | ArrayList.add | public function add($value) {
if($this->_ReadOnly){
throw new ReadOnlyException(\get_called_class() . ' is read only');
}
$this->_Arr = \array_merge($this->_Arr, \func_get_args());
return $this;
} | php | public function add($value) {
if($this->_ReadOnly){
throw new ReadOnlyException(\get_called_class() . ' is read only');
}
$this->_Arr = \array_merge($this->_Arr, \func_get_args());
return $this;
} | [
"public",
"function",
"add",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_ReadOnly",
")",
"{",
"throw",
"new",
"ReadOnlyException",
"(",
"\\",
"get_called_class",
"(",
")",
".",
"' is read only'",
")",
";",
"}",
"$",
"this",
"->",
"_Arr... | Adds a value to the list, multiple can be given
@param mixed $value
@return \Cola\ArrayList
@throws ReadOnlyException | [
"Adds",
"a",
"value",
"to",
"the",
"list",
"multiple",
"can",
"be",
"given"
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/ArrayList.php#L73-L83 | train |
dazarobbo/Cola | src/ArrayList.php | ArrayList.average | public function average(){
Number::setScale(static::NUMERIC_FUNCTIONS_SCALE);
return Number::divide($this->sum(), \strval($this->count()));
} | php | public function average(){
Number::setScale(static::NUMERIC_FUNCTIONS_SCALE);
return Number::divide($this->sum(), \strval($this->count()));
} | [
"public",
"function",
"average",
"(",
")",
"{",
"Number",
"::",
"setScale",
"(",
"static",
"::",
"NUMERIC_FUNCTIONS_SCALE",
")",
";",
"return",
"Number",
"::",
"divide",
"(",
"$",
"this",
"->",
"sum",
"(",
")",
",",
"\\",
"strval",
"(",
"$",
"this",
"-... | Computes the average value for a list of numbers
@return string | [
"Computes",
"the",
"average",
"value",
"for",
"a",
"list",
"of",
"numbers"
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/ArrayList.php#L89-L92 | train |
dazarobbo/Cola | src/ArrayList.php | ArrayList.chunk | public function chunk($size){
$outer = new static();
$chunks = \array_chunk($this->_Arr, $size);
foreach($chunks as $chunk){
$outer->pushBack(new static($chunk));
}
return $outer;
} | php | public function chunk($size){
$outer = new static();
$chunks = \array_chunk($this->_Arr, $size);
foreach($chunks as $chunk){
$outer->pushBack(new static($chunk));
}
return $outer;
} | [
"public",
"function",
"chunk",
"(",
"$",
"size",
")",
"{",
"$",
"outer",
"=",
"new",
"static",
"(",
")",
";",
"$",
"chunks",
"=",
"\\",
"array_chunk",
"(",
"$",
"this",
"->",
"_Arr",
",",
"$",
"size",
")",
";",
"foreach",
"(",
"$",
"chunks",
"as"... | Divides this list into a list of smaller-chunked lists
@param int $size Size of each chunked list
@return \static | [
"Divides",
"this",
"list",
"into",
"a",
"list",
"of",
"smaller",
"-",
"chunked",
"lists"
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/ArrayList.php#L113-L124 | train |
dazarobbo/Cola | src/ArrayList.php | ArrayList.concat | public function concat(ICollection $coll){
$arr = array();
$coll->copyTo($arr);
return new static(\array_merge($this->_Arr, \array_values($arr)));
} | php | public function concat(ICollection $coll){
$arr = array();
$coll->copyTo($arr);
return new static(\array_merge($this->_Arr, \array_values($arr)));
} | [
"public",
"function",
"concat",
"(",
"ICollection",
"$",
"coll",
")",
"{",
"$",
"arr",
"=",
"array",
"(",
")",
";",
"$",
"coll",
"->",
"copyTo",
"(",
"$",
"arr",
")",
";",
"return",
"new",
"static",
"(",
"\\",
"array_merge",
"(",
"$",
"this",
"->",... | Concatenates this list with an ICollection and returns a
new list
@param \Cola\ICollection $coll
@return \static | [
"Concatenates",
"this",
"list",
"with",
"an",
"ICollection",
"and",
"returns",
"a",
"new",
"list"
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/ArrayList.php#L149-L156 | train |
dazarobbo/Cola | src/ArrayList.php | ArrayList.copy | public function copy($deep = true){
$arr = array();
foreach($this->_Arr as $key => $item){
$arr[$key] = $deep
? Functions\Object::copy($item)
: $item;
}
return new static($arr);
} | php | public function copy($deep = true){
$arr = array();
foreach($this->_Arr as $key => $item){
$arr[$key] = $deep
? Functions\Object::copy($item)
: $item;
}
return new static($arr);
} | [
"public",
"function",
"copy",
"(",
"$",
"deep",
"=",
"true",
")",
"{",
"$",
"arr",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"_Arr",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"$",
"arr",
"[",
"$",
"key",
"]",
"=",
... | Creates a copy of this list. By default, a deep-copy
is performed.
@param bool $deep True for deep copy, false for shallow
@return \static | [
"Creates",
"a",
"copy",
"of",
"this",
"list",
".",
"By",
"default",
"a",
"deep",
"-",
"copy",
"is",
"performed",
"."
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/ArrayList.php#L173-L185 | train |
dazarobbo/Cola | src/ArrayList.php | ArrayList.copyTo | public function copyTo(array &$arr, $index = 0) {
if(!$this->offsetExists($index)){
throw new \OutOfRangeException('$index is invalid');
}
$arr = \array_slice($this->_Arr, $index);
return $this;
} | php | public function copyTo(array &$arr, $index = 0) {
if(!$this->offsetExists($index)){
throw new \OutOfRangeException('$index is invalid');
}
$arr = \array_slice($this->_Arr, $index);
return $this;
} | [
"public",
"function",
"copyTo",
"(",
"array",
"&",
"$",
"arr",
",",
"$",
"index",
"=",
"0",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"offsetExists",
"(",
"$",
"index",
")",
")",
"{",
"throw",
"new",
"\\",
"OutOfRangeException",
"(",
"'$index is i... | Copies this list to a given array by reference
@param array $arr destination
@param int $index Where to start copying, the start by default
@return \Cola\ArrayList | [
"Copies",
"this",
"list",
"to",
"a",
"given",
"array",
"by",
"reference"
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/ArrayList.php#L193-L203 | train |
dazarobbo/Cola | src/ArrayList.php | ArrayList.intersect | public function intersect(ICollection $coll){
//array_intersect does not work on \Closure objects
$arr = array();
$coll->copyTo($arr);
$ret = array();
foreach($this->_Arr as $outerItem){
foreach($arr as $innerItem){
if($innerItem === $outerItem){
$ret[] = $outerItem;
break;
}
}
}
return new static($ret);
} | php | public function intersect(ICollection $coll){
//array_intersect does not work on \Closure objects
$arr = array();
$coll->copyTo($arr);
$ret = array();
foreach($this->_Arr as $outerItem){
foreach($arr as $innerItem){
if($innerItem === $outerItem){
$ret[] = $outerItem;
break;
}
}
}
return new static($ret);
} | [
"public",
"function",
"intersect",
"(",
"ICollection",
"$",
"coll",
")",
"{",
"//array_intersect does not work on \\Closure objects",
"$",
"arr",
"=",
"array",
"(",
")",
";",
"$",
"coll",
"->",
"copyTo",
"(",
"$",
"arr",
")",
";",
"$",
"ret",
"=",
"array",
... | Returns a new list with each element existing in
this list and a given ICollection
@param \Cola\ICollection $coll
@return \static | [
"Returns",
"a",
"new",
"list",
"with",
"each",
"element",
"existing",
"in",
"this",
"list",
"and",
"a",
"given",
"ICollection"
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/ArrayList.php#L283-L305 | train |
dazarobbo/Cola | src/ArrayList.php | ArrayList.insert | public function insert($index, $value) {
if($this->_ReadOnly){
throw new ReadOnlyException(\get_called_class() . ' is read only');
}
//Permit 0-index insertion
if(!$this->offsetExists($index)){
throw new \OutOfRangeException('$index is invalid');
}
\array_splice($this->_Arr, $index, 0, array($value));
return $this;
} | php | public function insert($index, $value) {
if($this->_ReadOnly){
throw new ReadOnlyException(\get_called_class() . ' is read only');
}
//Permit 0-index insertion
if(!$this->offsetExists($index)){
throw new \OutOfRangeException('$index is invalid');
}
\array_splice($this->_Arr, $index, 0, array($value));
return $this;
} | [
"public",
"function",
"insert",
"(",
"$",
"index",
",",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_ReadOnly",
")",
"{",
"throw",
"new",
"ReadOnlyException",
"(",
"\\",
"get_called_class",
"(",
")",
".",
"' is read only'",
")",
";",
"}",
"/... | Inserts a value into the list at a given index
@param int $index
@param mixed $value
@return \Cola\ArrayList
@throws ReadOnlyException|\OutOfRangeException | [
"Inserts",
"a",
"value",
"into",
"the",
"list",
"at",
"a",
"given",
"index"
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/ArrayList.php#L332-L347 | train |
dazarobbo/Cola | src/ArrayList.php | ArrayList.insertRange | public function insertRange($index, ICollection $coll){
if($this->_ReadOnly){
throw new \RuntimeException(\get_called_class() . ' is read only');
}
if(!$this->offsetExists($index)){
throw new \OutOfRangeException('$index is invalid');
}
$arr = array();
$coll->copyTo($arr);
\array_splice($this->_Arr, $index, 0, $arr);
return $this;
} | php | public function insertRange($index, ICollection $coll){
if($this->_ReadOnly){
throw new \RuntimeException(\get_called_class() . ' is read only');
}
if(!$this->offsetExists($index)){
throw new \OutOfRangeException('$index is invalid');
}
$arr = array();
$coll->copyTo($arr);
\array_splice($this->_Arr, $index, 0, $arr);
return $this;
} | [
"public",
"function",
"insertRange",
"(",
"$",
"index",
",",
"ICollection",
"$",
"coll",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_ReadOnly",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\\",
"get_called_class",
"(",
")",
".",
"' is read only'... | Inserts a collection of items into the list at a given index
@param int $index
@param \Cola\ICollection $coll
@return \Cola\ArrayList
@throws ReadOnlyException|\OutOfRangeException | [
"Inserts",
"a",
"collection",
"of",
"items",
"into",
"the",
"list",
"at",
"a",
"given",
"index"
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/ArrayList.php#L356-L373 | train |
dazarobbo/Cola | src/ArrayList.php | ArrayList.lastIndexOf | public function lastIndexOf($value){
$i = $this->count() - 1;
while($i >= 0 && $this->_Arr[$i] !== $value){
--$i;
}
return $i;
} | php | public function lastIndexOf($value){
$i = $this->count() - 1;
while($i >= 0 && $this->_Arr[$i] !== $value){
--$i;
}
return $i;
} | [
"public",
"function",
"lastIndexOf",
"(",
"$",
"value",
")",
"{",
"$",
"i",
"=",
"$",
"this",
"->",
"count",
"(",
")",
"-",
"1",
";",
"while",
"(",
"$",
"i",
">=",
"0",
"&&",
"$",
"this",
"->",
"_Arr",
"[",
"$",
"i",
"]",
"!==",
"$",
"value",... | Returns the index of the last matching value
@param mixed $value
@return int -1 if not found | [
"Returns",
"the",
"index",
"of",
"the",
"last",
"matching",
"value"
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/ArrayList.php#L406-L416 | train |
dazarobbo/Cola | src/ArrayList.php | ArrayList.max | public function max(){
if($this->isEmpty()){
throw new \UnderflowException(\get_called_class() . ' is empty');
}
$max = $this->front();
for($i = 1, $l = $this->count(); $i < $l; ++$i){
if(Number::greaterThan($this->_Arr[$i], $max)){
$max = $this->_Arr[$i];
}
}
return $max;
} | php | public function max(){
if($this->isEmpty()){
throw new \UnderflowException(\get_called_class() . ' is empty');
}
$max = $this->front();
for($i = 1, $l = $this->count(); $i < $l; ++$i){
if(Number::greaterThan($this->_Arr[$i], $max)){
$max = $this->_Arr[$i];
}
}
return $max;
} | [
"public",
"function",
"max",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isEmpty",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"UnderflowException",
"(",
"\\",
"get_called_class",
"(",
")",
".",
"' is empty'",
")",
";",
"}",
"$",
"max",
"=",
"$",
"... | Returns the maximum value of this list. Result is undefined
for non numeric lists.
@return string
@throws \UnderflowException | [
"Returns",
"the",
"maximum",
"value",
"of",
"this",
"list",
".",
"Result",
"is",
"undefined",
"for",
"non",
"numeric",
"lists",
"."
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/ArrayList.php#L434-L450 | train |
dazarobbo/Cola | src/ArrayList.php | ArrayList.min | public function min(){
if($this->isEmpty()){
throw new \UnderflowException(\get_called_class() . ' is empty');
}
$min = $this->front();
for($i = 1, $l = $this->count(); $i < $l; ++$i){
if(Number::lessThan($this->_Arr[$i], $min)){
$min = $this->_Arr[$i];
}
}
return $min;
} | php | public function min(){
if($this->isEmpty()){
throw new \UnderflowException(\get_called_class() . ' is empty');
}
$min = $this->front();
for($i = 1, $l = $this->count(); $i < $l; ++$i){
if(Number::lessThan($this->_Arr[$i], $min)){
$min = $this->_Arr[$i];
}
}
return $min;
} | [
"public",
"function",
"min",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isEmpty",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"UnderflowException",
"(",
"\\",
"get_called_class",
"(",
")",
".",
"' is empty'",
")",
";",
"}",
"$",
"min",
"=",
"$",
"... | Returns the minimum value of this list. Result is undefined
for non numeric lists.
@return string
@throws \UnderflowException | [
"Returns",
"the",
"minimum",
"value",
"of",
"this",
"list",
".",
"Result",
"is",
"undefined",
"for",
"non",
"numeric",
"lists",
"."
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/ArrayList.php#L458-L474 | train |
dazarobbo/Cola | src/ArrayList.php | ArrayList.popBack | public function popBack(){
if($this->_ReadOnly){
throw new ReadOnlyException(\get_called_class() . ' is read only');
}
if($this->isEmpty()){
throw new \UnderflowException(\get_called_class() . ' is empty');
}
return \array_pop($this->_Arr);
} | php | public function popBack(){
if($this->_ReadOnly){
throw new ReadOnlyException(\get_called_class() . ' is read only');
}
if($this->isEmpty()){
throw new \UnderflowException(\get_called_class() . ' is empty');
}
return \array_pop($this->_Arr);
} | [
"public",
"function",
"popBack",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_ReadOnly",
")",
"{",
"throw",
"new",
"ReadOnlyException",
"(",
"\\",
"get_called_class",
"(",
")",
".",
"' is read only'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isE... | Removes and returns the last element of the list
@return mixed
@throws ReadOnlyException | [
"Removes",
"and",
"returns",
"the",
"last",
"element",
"of",
"the",
"list"
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/ArrayList.php#L529-L541 | train |
dazarobbo/Cola | src/ArrayList.php | ArrayList.popFront | public function popFront(){
if($this->_ReadOnly){
throw new ReadOnlyException(\get_called_class() . ' is read only');
}
if($this->isEmpty()){
throw new \UnderflowException(\get_called_class() . ' is empty');
}
return \array_shift($this->_Arr);
} | php | public function popFront(){
if($this->_ReadOnly){
throw new ReadOnlyException(\get_called_class() . ' is read only');
}
if($this->isEmpty()){
throw new \UnderflowException(\get_called_class() . ' is empty');
}
return \array_shift($this->_Arr);
} | [
"public",
"function",
"popFront",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_ReadOnly",
")",
"{",
"throw",
"new",
"ReadOnlyException",
"(",
"\\",
"get_called_class",
"(",
")",
".",
"' is read only'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"is... | Removes and returns the first element of the list
@return mixed
@throws ReadOnlyException | [
"Removes",
"and",
"returns",
"the",
"first",
"element",
"of",
"the",
"list"
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/ArrayList.php#L548-L560 | train |
dazarobbo/Cola | src/ArrayList.php | ArrayList.product | public function product(){
Number::setScale(static::NUMERIC_FUNCTIONS_SCALE);
$total = \strval($this->front());
for($i = 1, $l = $this->count(); $i < $l; ++$i){
$total = Number::multiply($total, \strval($this->_Arr[$i]));
}
return $total;
} | php | public function product(){
Number::setScale(static::NUMERIC_FUNCTIONS_SCALE);
$total = \strval($this->front());
for($i = 1, $l = $this->count(); $i < $l; ++$i){
$total = Number::multiply($total, \strval($this->_Arr[$i]));
}
return $total;
} | [
"public",
"function",
"product",
"(",
")",
"{",
"Number",
"::",
"setScale",
"(",
"static",
"::",
"NUMERIC_FUNCTIONS_SCALE",
")",
";",
"$",
"total",
"=",
"\\",
"strval",
"(",
"$",
"this",
"->",
"front",
"(",
")",
")",
";",
"for",
"(",
"$",
"i",
"=",
... | Computes the product of a list of numbers
@return string | [
"Computes",
"the",
"product",
"of",
"a",
"list",
"of",
"numbers"
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/ArrayList.php#L566-L578 | train |
dazarobbo/Cola | src/ArrayList.php | ArrayList.pushBack | public function pushBack(){
if($this->_ReadOnly){
throw new ReadOnlyException(\get_called_class() . ' is read only');
}
$this->_Arr = \array_merge($this->_Arr, \func_get_args());
return $this;
} | php | public function pushBack(){
if($this->_ReadOnly){
throw new ReadOnlyException(\get_called_class() . ' is read only');
}
$this->_Arr = \array_merge($this->_Arr, \func_get_args());
return $this;
} | [
"public",
"function",
"pushBack",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_ReadOnly",
")",
"{",
"throw",
"new",
"ReadOnlyException",
"(",
"\\",
"get_called_class",
"(",
")",
".",
"' is read only'",
")",
";",
"}",
"$",
"this",
"->",
"_Arr",
"=",
"... | Adds items to the end of this list. Multiple arguments can be given.
@return \Cola\ArrayList
@throws ReadOnlyException | [
"Adds",
"items",
"to",
"the",
"end",
"of",
"this",
"list",
".",
"Multiple",
"arguments",
"can",
"be",
"given",
"."
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/ArrayList.php#L585-L595 | train |
dazarobbo/Cola | src/ArrayList.php | ArrayList.pushFront | public function pushFront(){
if($this->_ReadOnly){
throw new ReadOnlyException(\get_called_class() . ' is read only');
}
$this->_Arr = \array_merge(\func_get_args(), $this->_Arr);
return $this;
} | php | public function pushFront(){
if($this->_ReadOnly){
throw new ReadOnlyException(\get_called_class() . ' is read only');
}
$this->_Arr = \array_merge(\func_get_args(), $this->_Arr);
return $this;
} | [
"public",
"function",
"pushFront",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_ReadOnly",
")",
"{",
"throw",
"new",
"ReadOnlyException",
"(",
"\\",
"get_called_class",
"(",
")",
".",
"' is read only'",
")",
";",
"}",
"$",
"this",
"->",
"_Arr",
"=",
... | Adds items to the beginning of this list. Multiple arguments can be given.
@return \Cola\ArrayList
@throws ReadOnlyException | [
"Adds",
"items",
"to",
"the",
"beginning",
"of",
"this",
"list",
".",
"Multiple",
"arguments",
"can",
"be",
"given",
"."
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/ArrayList.php#L602-L612 | train |
dazarobbo/Cola | src/ArrayList.php | ArrayList.& | public function &random(){
if($this->isEmpty()){
throw new \UnderflowException(\get_called_class() . ' is empty');
}
return $this->_Arr[\array_rand($this->_Arr, 1)];
} | php | public function &random(){
if($this->isEmpty()){
throw new \UnderflowException(\get_called_class() . ' is empty');
}
return $this->_Arr[\array_rand($this->_Arr, 1)];
} | [
"public",
"function",
"&",
"random",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isEmpty",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"UnderflowException",
"(",
"\\",
"get_called_class",
"(",
")",
".",
"' is empty'",
")",
";",
"}",
"return",
"$",
"t... | Returns a reference to a random item from the list
@return mixed | [
"Returns",
"a",
"reference",
"to",
"a",
"random",
"item",
"from",
"the",
"list"
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/ArrayList.php#L618-L626 | train |
dazarobbo/Cola | src/ArrayList.php | ArrayList.readOnly | public function readOnly($bool = true){
$list = $this->copy(false);
$list->setReadOnly();
return $list;
} | php | public function readOnly($bool = true){
$list = $this->copy(false);
$list->setReadOnly();
return $list;
} | [
"public",
"function",
"readOnly",
"(",
"$",
"bool",
"=",
"true",
")",
"{",
"$",
"list",
"=",
"$",
"this",
"->",
"copy",
"(",
"false",
")",
";",
"$",
"list",
"->",
"setReadOnly",
"(",
")",
";",
"return",
"$",
"list",
";",
"}"
] | Creates a shallow copy of this list and sets it to read only
@param bool $bool
@return \static | [
"Creates",
"a",
"shallow",
"copy",
"of",
"this",
"list",
"and",
"sets",
"it",
"to",
"read",
"only"
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/ArrayList.php#L633-L637 | train |
dazarobbo/Cola | src/ArrayList.php | ArrayList.remove | public function remove($value) {
if($this->_ReadOnly){
throw new ReadOnlyException(\get_called_class() . ' is read only');
}
if(($key = \array_search($value, $this->_Arr)) !== false){
\array_splice($this->_Arr, $key, 1);
}
return $this;
} | php | public function remove($value) {
if($this->_ReadOnly){
throw new ReadOnlyException(\get_called_class() . ' is read only');
}
if(($key = \array_search($value, $this->_Arr)) !== false){
\array_splice($this->_Arr, $key, 1);
}
return $this;
} | [
"public",
"function",
"remove",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_ReadOnly",
")",
"{",
"throw",
"new",
"ReadOnlyException",
"(",
"\\",
"get_called_class",
"(",
")",
".",
"' is read only'",
")",
";",
"}",
"if",
"(",
"(",
"$",
... | Removes the first matching value from the list
@param mixed $value
@return \Cola\ArrayList
@throws ReadOnlyException | [
"Removes",
"the",
"first",
"matching",
"value",
"from",
"the",
"list"
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/ArrayList.php#L645-L657 | train |
dazarobbo/Cola | src/ArrayList.php | ArrayList.removeAt | public function removeAt($index) {
if($this->_ReadOnly){
throw new \RuntimeException(\get_called_class() . ' is read only');
}
if(!$this->offsetExists($index)){
throw new \OutOfRangeException('$index is invalid');
}
\array_splice($this->_Arr, $index, 1);
return $this;
} | php | public function removeAt($index) {
if($this->_ReadOnly){
throw new \RuntimeException(\get_called_class() . ' is read only');
}
if(!$this->offsetExists($index)){
throw new \OutOfRangeException('$index is invalid');
}
\array_splice($this->_Arr, $index, 1);
return $this;
} | [
"public",
"function",
"removeAt",
"(",
"$",
"index",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_ReadOnly",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\\",
"get_called_class",
"(",
")",
".",
"' is read only'",
")",
";",
"}",
"if",
"(",
"!"... | Removes a value at the given index
@param int $index
@return \Cola\ArrayList
@throws ReadOnlyException|\OutOfRangeException | [
"Removes",
"a",
"value",
"at",
"the",
"given",
"index"
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/ArrayList.php#L665-L679 | train |
dazarobbo/Cola | src/ArrayList.php | ArrayList.resize | public function resize($size, $value = null){
if($this->_ReadOnly){
throw new ReadOnlyException(\get_called_class() . ' is read only');
}
if(!\is_int($size)){
throw new \InvalidArgumentException('$size is not an int');
}
if($size < 0){
throw new \OutOfBoundsException('$size cannot be less than 0');
}
$len = $this->count();
if($size > $len){
$this->_Arr = \array_pad($this->_Arr, $size, $value);
}
else if($size < $len){
$this->_Arr = \array_slice($this->_Arr, 0, $size, false);
}
return $this;
} | php | public function resize($size, $value = null){
if($this->_ReadOnly){
throw new ReadOnlyException(\get_called_class() . ' is read only');
}
if(!\is_int($size)){
throw new \InvalidArgumentException('$size is not an int');
}
if($size < 0){
throw new \OutOfBoundsException('$size cannot be less than 0');
}
$len = $this->count();
if($size > $len){
$this->_Arr = \array_pad($this->_Arr, $size, $value);
}
else if($size < $len){
$this->_Arr = \array_slice($this->_Arr, 0, $size, false);
}
return $this;
} | [
"public",
"function",
"resize",
"(",
"$",
"size",
",",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_ReadOnly",
")",
"{",
"throw",
"new",
"ReadOnlyException",
"(",
"\\",
"get_called_class",
"(",
")",
".",
"' is read only'",
")",
... | Resizes this list to a given size. Expanding the list will
pad it with a value. Contracting the list cuts off extraneous
values.
@param int $size
@param mixed $value
@return \Cola\ArrayList
@throws ReadOnlyException
@throws \InvalidArgumentException
@throws \OutOfBoundsException | [
"Resizes",
"this",
"list",
"to",
"a",
"given",
"size",
".",
"Expanding",
"the",
"list",
"will",
"pad",
"it",
"with",
"a",
"value",
".",
"Contracting",
"the",
"list",
"cuts",
"off",
"extraneous",
"values",
"."
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/ArrayList.php#L734-L759 | train |
dazarobbo/Cola | src/ArrayList.php | ArrayList.reverse | public function reverse(){
if($this->_ReadOnly){
throw new ReadOnlyException(\get_called_class() . ' is read only');
}
$this->_Arr = \array_reverse($this->_Arr);
return $this;
} | php | public function reverse(){
if($this->_ReadOnly){
throw new ReadOnlyException(\get_called_class() . ' is read only');
}
$this->_Arr = \array_reverse($this->_Arr);
return $this;
} | [
"public",
"function",
"reverse",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_ReadOnly",
")",
"{",
"throw",
"new",
"ReadOnlyException",
"(",
"\\",
"get_called_class",
"(",
")",
".",
"' is read only'",
")",
";",
"}",
"$",
"this",
"->",
"_Arr",
"=",
"\... | Reverses this list
@return \Cola\ArrayList
@throws ReadOnlyException | [
"Reverses",
"this",
"list"
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/ArrayList.php#L766-L776 | train |
dazarobbo/Cola | src/ArrayList.php | ArrayList.sentinelSearch | public function sentinelSearch($value){
$l = $this->count();
$arr = $this->_Arr;
$arr[$l] = $value;
$i = 0;
while($arr[$i] !== $value){
++$i;
}
return $i !== $l ? $i : static::NO_INDEX;
} | php | public function sentinelSearch($value){
$l = $this->count();
$arr = $this->_Arr;
$arr[$l] = $value;
$i = 0;
while($arr[$i] !== $value){
++$i;
}
return $i !== $l ? $i : static::NO_INDEX;
} | [
"public",
"function",
"sentinelSearch",
"(",
"$",
"value",
")",
"{",
"$",
"l",
"=",
"$",
"this",
"->",
"count",
"(",
")",
";",
"$",
"arr",
"=",
"$",
"this",
"->",
"_Arr",
";",
"$",
"arr",
"[",
"$",
"l",
"]",
"=",
"$",
"value",
";",
"$",
"i",
... | Performs a sentinel search for a value
@param mixed $value
@return int -1 for no match | [
"Performs",
"a",
"sentinel",
"search",
"for",
"a",
"value"
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/ArrayList.php#L783-L796 | train |
dazarobbo/Cola | src/ArrayList.php | ArrayList.slice | public function slice($index, $count = null){
if(!$this->offsetExists($index)){
throw new \OutOfRangeException('$index is invalid');
}
$arr = \array_slice($this->_Arr, $index, $count);
return new static($arr);
} | php | public function slice($index, $count = null){
if(!$this->offsetExists($index)){
throw new \OutOfRangeException('$index is invalid');
}
$arr = \array_slice($this->_Arr, $index, $count);
return new static($arr);
} | [
"public",
"function",
"slice",
"(",
"$",
"index",
",",
"$",
"count",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"offsetExists",
"(",
"$",
"index",
")",
")",
"{",
"throw",
"new",
"\\",
"OutOfRangeException",
"(",
"'$index is invalid'",
")... | Creates a new list from a subset of this list
@param int $index index to start the subset at
@param int $count number of items to include
@throws \OutOfRangeException
@return \static | [
"Creates",
"a",
"new",
"list",
"from",
"a",
"subset",
"of",
"this",
"list"
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/ArrayList.php#L813-L822 | train |
dazarobbo/Cola | src/ArrayList.php | ArrayList.sort | public function sort(\Closure $compare = null){
if($this->_ReadOnly){
throw new ReadOnlyException(\get_called_class() . ' is read only');
}
if(\is_callable($compare)){
\usort($this->_Arr, $compare);
}
else{
\sort($this->_Arr);
}
return $this;
} | php | public function sort(\Closure $compare = null){
if($this->_ReadOnly){
throw new ReadOnlyException(\get_called_class() . ' is read only');
}
if(\is_callable($compare)){
\usort($this->_Arr, $compare);
}
else{
\sort($this->_Arr);
}
return $this;
} | [
"public",
"function",
"sort",
"(",
"\\",
"Closure",
"$",
"compare",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_ReadOnly",
")",
"{",
"throw",
"new",
"ReadOnlyException",
"(",
"\\",
"get_called_class",
"(",
")",
".",
"' is read only'",
")",
";"... | Sorts this list, optionally by a user defined compare function
@param \Closure $compare
@return \Cola\ArrayList
@throws ReadOnlyException | [
"Sorts",
"this",
"list",
"optionally",
"by",
"a",
"user",
"defined",
"compare",
"function"
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/ArrayList.php#L839-L854 | train |
dazarobbo/Cola | src/ArrayList.php | ArrayList.sum | public function sum(){
Number::setScale(static::NUMERIC_FUNCTIONS_SCALE);
$total = '0';
foreach($this->_Arr as $item){
$total = Number::add($total, \strval($item));
}
return $total;
} | php | public function sum(){
Number::setScale(static::NUMERIC_FUNCTIONS_SCALE);
$total = '0';
foreach($this->_Arr as $item){
$total = Number::add($total, \strval($item));
}
return $total;
} | [
"public",
"function",
"sum",
"(",
")",
"{",
"Number",
"::",
"setScale",
"(",
"static",
"::",
"NUMERIC_FUNCTIONS_SCALE",
")",
";",
"$",
"total",
"=",
"'0'",
";",
"foreach",
"(",
"$",
"this",
"->",
"_Arr",
"as",
"$",
"item",
")",
"{",
"$",
"total",
"="... | Computes the sum of all numbers in this list
@return string | [
"Computes",
"the",
"sum",
"of",
"all",
"numbers",
"in",
"this",
"list"
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/ArrayList.php#L860-L872 | train |
dazarobbo/Cola | src/ArrayList.php | ArrayList.stdDev | public function stdDev(){
Number::setScale(static::NUMERIC_FUNCTIONS_SCALE);
$mean = $this->average();
$squares = new static();
foreach($this->_Arr as $num){
$squares->add(Number::pow(Number::sub(\strval($num), $mean), '2'));
}
return Number::sqrt($squares->average());
} | php | public function stdDev(){
Number::setScale(static::NUMERIC_FUNCTIONS_SCALE);
$mean = $this->average();
$squares = new static();
foreach($this->_Arr as $num){
$squares->add(Number::pow(Number::sub(\strval($num), $mean), '2'));
}
return Number::sqrt($squares->average());
} | [
"public",
"function",
"stdDev",
"(",
")",
"{",
"Number",
"::",
"setScale",
"(",
"static",
"::",
"NUMERIC_FUNCTIONS_SCALE",
")",
";",
"$",
"mean",
"=",
"$",
"this",
"->",
"average",
"(",
")",
";",
"$",
"squares",
"=",
"new",
"static",
"(",
")",
";",
"... | Computes the population standard deviation for the numbers
in this list
@return string | [
"Computes",
"the",
"population",
"standard",
"deviation",
"for",
"the",
"numbers",
"in",
"this",
"list"
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/ArrayList.php#L879-L892 | train |
dazarobbo/Cola | src/ArrayList.php | ArrayList.unique | public function unique(\Closure $compare = null){
if(\is_callable($compare)){
$arr = new static();
$this->each(function($outerItem) use (&$arr, $compare){
if(!$arr->some(function($cmpItem) use ($outerItem, $compare){
return $compare($outerItem, $cmpItem);
})){
$arr->_Arr[] = $outerItem;
}
});
return $arr;
}
else{
return new static(\array_values(\array_unique(
$this->_Arr, \SORT_REGULAR)));
}
} | php | public function unique(\Closure $compare = null){
if(\is_callable($compare)){
$arr = new static();
$this->each(function($outerItem) use (&$arr, $compare){
if(!$arr->some(function($cmpItem) use ($outerItem, $compare){
return $compare($outerItem, $cmpItem);
})){
$arr->_Arr[] = $outerItem;
}
});
return $arr;
}
else{
return new static(\array_values(\array_unique(
$this->_Arr, \SORT_REGULAR)));
}
} | [
"public",
"function",
"unique",
"(",
"\\",
"Closure",
"$",
"compare",
"=",
"null",
")",
"{",
"if",
"(",
"\\",
"is_callable",
"(",
"$",
"compare",
")",
")",
"{",
"$",
"arr",
"=",
"new",
"static",
"(",
")",
";",
"$",
"this",
"->",
"each",
"(",
"fun... | Eliminates duplicate values from this list, optionally according
to a user defined compare function
@param \Closure $compare
@return \static | [
"Eliminates",
"duplicate",
"values",
"from",
"this",
"list",
"optionally",
"according",
"to",
"a",
"user",
"defined",
"compare",
"function"
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/ArrayList.php#L908-L932 | train |
BlackBoxRepo/PandoContentBundle | Service/MethodService.php | MethodService.call | public function call(MethodArgumentDocument $methodArgument)
{
$serviceName = $methodArgument->getMethod()->getService()->getServiceName();
$service = $this->container->get($serviceName);
if (null === $service) {
throw new UndefinedServiceException(sprintf('"%s" is not a service', $serviceName));
}
$methodName = $methodArgument->getMethod()->getName();
try {
$r = new \ReflectionMethod($service, $methodName);
} catch (\ReflectionException $e) {
throw new BadMethodCallException(sprintf('"%s" is not a method in %s', $methodName, $serviceName));
}
$methodArguments = $methodArgument->getArguments();
$numberOfArgs = $methodArguments->count();
$minArgs = $r->getNumberOfRequiredParameters();
$maxArgs = $r->getNumberOfParameters();
if ($numberOfArgs < $minArgs || $numberOfArgs > $maxArgs) {
$range = $minArgs === $maxArgs ? $minArgs : "$minArgs-$maxArgs";
throw new WrongNumberOfArgumentsException(
sprintf('Method "%s" in %s expects %s arguments, got %d', $methodName, $serviceName, $range, $numberOfArgs)
);
}
return $service->$methodName(...$this->buildArgumentArray($r->getParameters(), $methodArguments));
} | php | public function call(MethodArgumentDocument $methodArgument)
{
$serviceName = $methodArgument->getMethod()->getService()->getServiceName();
$service = $this->container->get($serviceName);
if (null === $service) {
throw new UndefinedServiceException(sprintf('"%s" is not a service', $serviceName));
}
$methodName = $methodArgument->getMethod()->getName();
try {
$r = new \ReflectionMethod($service, $methodName);
} catch (\ReflectionException $e) {
throw new BadMethodCallException(sprintf('"%s" is not a method in %s', $methodName, $serviceName));
}
$methodArguments = $methodArgument->getArguments();
$numberOfArgs = $methodArguments->count();
$minArgs = $r->getNumberOfRequiredParameters();
$maxArgs = $r->getNumberOfParameters();
if ($numberOfArgs < $minArgs || $numberOfArgs > $maxArgs) {
$range = $minArgs === $maxArgs ? $minArgs : "$minArgs-$maxArgs";
throw new WrongNumberOfArgumentsException(
sprintf('Method "%s" in %s expects %s arguments, got %d', $methodName, $serviceName, $range, $numberOfArgs)
);
}
return $service->$methodName(...$this->buildArgumentArray($r->getParameters(), $methodArguments));
} | [
"public",
"function",
"call",
"(",
"MethodArgumentDocument",
"$",
"methodArgument",
")",
"{",
"$",
"serviceName",
"=",
"$",
"methodArgument",
"->",
"getMethod",
"(",
")",
"->",
"getService",
"(",
")",
"->",
"getServiceName",
"(",
")",
";",
"$",
"service",
"=... | Executes the passed in method via the associated service that's retrieved from the container.
This gets called recursively to supply all the arguments for each given method.
@param MethodArgumentDocument $methodArgument
@throws WrongNumberOfArgumentsException if we have more or less arguments than the method requires
@throws BadArgumentTypeException if the type of a given argument does not match the method arguments expected type
@throws MissingMethodArgumentException if argument has neither callback nor value
@throws UndefinedServiceException if service doesn't exist
@throws BadMethodCallException if the service doesn't have the given method
@return mixed | [
"Executes",
"the",
"passed",
"in",
"method",
"via",
"the",
"associated",
"service",
"that",
"s",
"retrieved",
"from",
"the",
"container",
".",
"This",
"gets",
"called",
"recursively",
"to",
"supply",
"all",
"the",
"arguments",
"for",
"each",
"given",
"method",... | fa54d0c7542c1d359a5dbb4f32dab3e195e41007 | https://github.com/BlackBoxRepo/PandoContentBundle/blob/fa54d0c7542c1d359a5dbb4f32dab3e195e41007/Service/MethodService.php#L44-L72 | train |
Palmabit-IT/authenticator | src/Palmabit/Authentication/Helpers/SentryAuthenticationHelper.php | SentryAuthenticationHelper.checkProfileEditPermission | public function checkProfileEditPermission($user_id) {
$current_user_id = App::make('sentry')->getUser()->id;
// edit his profile
if ($user_id == $current_user_id) {
return true;
}
// has special permission to edit other user profiles
$edit_perm = Config::get('authentication::permissions.edit_profile');
if ($this->hasPermission($edit_perm)) {
return true;
}
return false;
} | php | public function checkProfileEditPermission($user_id) {
$current_user_id = App::make('sentry')->getUser()->id;
// edit his profile
if ($user_id == $current_user_id) {
return true;
}
// has special permission to edit other user profiles
$edit_perm = Config::get('authentication::permissions.edit_profile');
if ($this->hasPermission($edit_perm)) {
return true;
}
return false;
} | [
"public",
"function",
"checkProfileEditPermission",
"(",
"$",
"user_id",
")",
"{",
"$",
"current_user_id",
"=",
"App",
"::",
"make",
"(",
"'sentry'",
")",
"->",
"getUser",
"(",
")",
"->",
"id",
";",
"// edit his profile",
"if",
"(",
"$",
"user_id",
"==",
"... | Check if the current user has permission to edit the profile
@return boolean | [
"Check",
"if",
"the",
"current",
"user",
"has",
"permission",
"to",
"edit",
"the",
"profile"
] | 986cfc7e666e0e1b0312e518d586ec61b08cdb42 | https://github.com/Palmabit-IT/authenticator/blob/986cfc7e666e0e1b0312e518d586ec61b08cdb42/src/Palmabit/Authentication/Helpers/SentryAuthenticationHelper.php#L38-L52 | train |
Palmabit-IT/authenticator | src/Palmabit/Authentication/Helpers/SentryAuthenticationHelper.php | SentryAuthenticationHelper.getNotificationRegistrationUsersEmail | public function getNotificationRegistrationUsersEmail() {
$group_name = Config::get('authentication::permissions.profile_notification_group');
$user_r = App::make('user_repository');
$users = $user_r->findFromGroupName($group_name)->lists('email');
return $users;
} | php | public function getNotificationRegistrationUsersEmail() {
$group_name = Config::get('authentication::permissions.profile_notification_group');
$user_r = App::make('user_repository');
$users = $user_r->findFromGroupName($group_name)->lists('email');
return $users;
} | [
"public",
"function",
"getNotificationRegistrationUsersEmail",
"(",
")",
"{",
"$",
"group_name",
"=",
"Config",
"::",
"get",
"(",
"'authentication::permissions.profile_notification_group'",
")",
";",
"$",
"user_r",
"=",
"App",
"::",
"make",
"(",
"'user_repository'",
"... | Obtain the user that needs to be notificated on registration
@return array | [
"Obtain",
"the",
"user",
"that",
"needs",
"to",
"be",
"notificated",
"on",
"registration"
] | 986cfc7e666e0e1b0312e518d586ec61b08cdb42 | https://github.com/Palmabit-IT/authenticator/blob/986cfc7e666e0e1b0312e518d586ec61b08cdb42/src/Palmabit/Authentication/Helpers/SentryAuthenticationHelper.php#L59-L65 | train |
opsbears/piccolo-templating | src/TemplatingModule.php | TemplatingModule.addTemplatingEngineClass | public function addTemplatingEngineClass(array &$globalConfig, string $templateEngineClass) {
$globalConfig[$this->getModuleKey()][self::CONFIG_ENGINES][] = $templateEngineClass;
} | php | public function addTemplatingEngineClass(array &$globalConfig, string $templateEngineClass) {
$globalConfig[$this->getModuleKey()][self::CONFIG_ENGINES][] = $templateEngineClass;
} | [
"public",
"function",
"addTemplatingEngineClass",
"(",
"array",
"&",
"$",
"globalConfig",
",",
"string",
"$",
"templateEngineClass",
")",
"{",
"$",
"globalConfig",
"[",
"$",
"this",
"->",
"getModuleKey",
"(",
")",
"]",
"[",
"self",
"::",
"CONFIG_ENGINES",
"]",... | Adds a class as a possible template engine. This must be done before the configureDependencyInjection function
is called.
@param array $globalConfig
@param string $templateEngineClass
@throws ConfigurationException if the DIC configuration phase has already finished. | [
"Adds",
"a",
"class",
"as",
"a",
"possible",
"template",
"engine",
".",
"This",
"must",
"be",
"done",
"before",
"the",
"configureDependencyInjection",
"function",
"is",
"called",
"."
] | b5faeb2fc4c8f2b003aa5edb245f9559cd0101c3 | https://github.com/opsbears/piccolo-templating/blob/b5faeb2fc4c8f2b003aa5edb245f9559cd0101c3/src/TemplatingModule.php#L47-L49 | train |
opsbears/piccolo-templating | src/TemplatingModule.php | TemplatingModule.configureDependencyInjection | public function configureDependencyInjection(DependencyInjectionContainer $dic,
array $moduleConfig,
array $globalConfig) {
/**
* @var TemplateEngine[] $engines
*/
$engines = [];
if (empty($moduleConfig[self::CONFIG_ENGINES])) {
throw new ConfigurationException('The templating module itself was loaded, but there is no module ' .
' for the actual template engine present. Did you forget to load your templating module?');
}
//Create the instances of the template engine to be used with the TemplateRenderingChain
foreach ($moduleConfig[self::CONFIG_ENGINES] as $engineClass) {
$engines[] = $dic->make($engineClass);
}
if (isset($moduleConfig[self::CONFIG_FILTERS])) {
foreach ($moduleConfig[self::CONFIG_FILTERS] as $filterClass) {
$filterInstance = $dic->make($filterClass);
if ($filterInstance instanceof TemplateFilter) {
foreach ($engines as $engine) {
$engine->registerFilter($filterInstance);
}
} else {
throw new ConfigurationException($filterClass . ' does not implement ' . TemplateFilter::class);
}
}
}
if (isset($moduleConfig[self::CONFIG_FUNCTIONS])) {
foreach ($moduleConfig[self::CONFIG_FUNCTIONS] as $functionClass) {
$functionInstance = $dic->make($functionClass);
if ($functionInstance instanceof TemplateFunction) {
foreach ($engines as $engine) {
$engine->registerFunction($functionInstance);
}
} else {
throw new ConfigurationException($functionClass . ' does not implement ' . TemplateFunction::class);
}
}
}
$dic->setClassParameters(TemplateRenderingChain::class, ['templateEngines' => $engines]);
} | php | public function configureDependencyInjection(DependencyInjectionContainer $dic,
array $moduleConfig,
array $globalConfig) {
/**
* @var TemplateEngine[] $engines
*/
$engines = [];
if (empty($moduleConfig[self::CONFIG_ENGINES])) {
throw new ConfigurationException('The templating module itself was loaded, but there is no module ' .
' for the actual template engine present. Did you forget to load your templating module?');
}
//Create the instances of the template engine to be used with the TemplateRenderingChain
foreach ($moduleConfig[self::CONFIG_ENGINES] as $engineClass) {
$engines[] = $dic->make($engineClass);
}
if (isset($moduleConfig[self::CONFIG_FILTERS])) {
foreach ($moduleConfig[self::CONFIG_FILTERS] as $filterClass) {
$filterInstance = $dic->make($filterClass);
if ($filterInstance instanceof TemplateFilter) {
foreach ($engines as $engine) {
$engine->registerFilter($filterInstance);
}
} else {
throw new ConfigurationException($filterClass . ' does not implement ' . TemplateFilter::class);
}
}
}
if (isset($moduleConfig[self::CONFIG_FUNCTIONS])) {
foreach ($moduleConfig[self::CONFIG_FUNCTIONS] as $functionClass) {
$functionInstance = $dic->make($functionClass);
if ($functionInstance instanceof TemplateFunction) {
foreach ($engines as $engine) {
$engine->registerFunction($functionInstance);
}
} else {
throw new ConfigurationException($functionClass . ' does not implement ' . TemplateFunction::class);
}
}
}
$dic->setClassParameters(TemplateRenderingChain::class, ['templateEngines' => $engines]);
} | [
"public",
"function",
"configureDependencyInjection",
"(",
"DependencyInjectionContainer",
"$",
"dic",
",",
"array",
"$",
"moduleConfig",
",",
"array",
"$",
"globalConfig",
")",
"{",
"/**\n\t\t * @var TemplateEngine[] $engines\n\t\t */",
"$",
"engines",
"=",
"[",
"]",
"... | Configures the TemplateRenderingChain with the previously registered templating engines.
@param DependencyInjectionContainer $dic
@param array $moduleConfig
@param array $globalConfig
@throws ConfigurationException if no templating module was loaded. | [
"Configures",
"the",
"TemplateRenderingChain",
"with",
"the",
"previously",
"registered",
"templating",
"engines",
"."
] | b5faeb2fc4c8f2b003aa5edb245f9559cd0101c3 | https://github.com/opsbears/piccolo-templating/blob/b5faeb2fc4c8f2b003aa5edb245f9559cd0101c3/src/TemplatingModule.php#L72-L112 | train |
cawaphp/serializer | src/Serializer.php | Serializer.serializeObject | private function serializeObject($object, string $className = null)
{
if (is_null($className)) {
$index = array_search($object, $this->references, true);
if ($index !== false) {
$this->referencesUsed[] = $index;
return ['@ref' => $index];
}
$this->references[] = $object;
}
$data = ['@type' => get_class($object)];
$reflectionClass = new \ReflectionClass($className ? $className : $object);
// parent class
$parent = $reflectionClass->getParentClass();
if ($parent) {
$parentData = $this->serializeObject($object, $parent->getName());
if (count($parentData) > 0) {
$data = array_merge($data, $parentData);
}
}
// current $object
foreach ($reflectionClass->getProperties() as $property) {
$property->setAccessible(true);
$value = $property->getValue($object);
$name = $property->getName();
// for parent class, don't reserialize public & protected properties
if (isset($data[$name])) {
continue;
}
// optimization: only save value if not the default value
$defaults = $reflectionClass->getDefaultProperties();
if (array_key_exists($name, $defaults) && $defaults[$name] === $value) {
continue;
}
$this->serializeValue($name, $value, $data);
}
// ugly hack for public undeclared properties and
// for internal object like datetime that can't be accessed by reflection
// @see http://news.php.net/php.internals/93826%20view%20original
if (!$className) {
foreach (get_object_vars($object) as $key => $value) {
if (!isset($data[$key])) {
$this->serializeValue($key, $value, $data);
}
}
}
return $data;
} | php | private function serializeObject($object, string $className = null)
{
if (is_null($className)) {
$index = array_search($object, $this->references, true);
if ($index !== false) {
$this->referencesUsed[] = $index;
return ['@ref' => $index];
}
$this->references[] = $object;
}
$data = ['@type' => get_class($object)];
$reflectionClass = new \ReflectionClass($className ? $className : $object);
// parent class
$parent = $reflectionClass->getParentClass();
if ($parent) {
$parentData = $this->serializeObject($object, $parent->getName());
if (count($parentData) > 0) {
$data = array_merge($data, $parentData);
}
}
// current $object
foreach ($reflectionClass->getProperties() as $property) {
$property->setAccessible(true);
$value = $property->getValue($object);
$name = $property->getName();
// for parent class, don't reserialize public & protected properties
if (isset($data[$name])) {
continue;
}
// optimization: only save value if not the default value
$defaults = $reflectionClass->getDefaultProperties();
if (array_key_exists($name, $defaults) && $defaults[$name] === $value) {
continue;
}
$this->serializeValue($name, $value, $data);
}
// ugly hack for public undeclared properties and
// for internal object like datetime that can't be accessed by reflection
// @see http://news.php.net/php.internals/93826%20view%20original
if (!$className) {
foreach (get_object_vars($object) as $key => $value) {
if (!isset($data[$key])) {
$this->serializeValue($key, $value, $data);
}
}
}
return $data;
} | [
"private",
"function",
"serializeObject",
"(",
"$",
"object",
",",
"string",
"$",
"className",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"className",
")",
")",
"{",
"$",
"index",
"=",
"array_search",
"(",
"$",
"object",
",",
"$",
"this",
... | Recursive serialize.
@param object $object
@param string $className
@return array | [
"Recursive",
"serialize",
"."
] | dedf2206d6a617086321060429c2c9bb227ffc71 | https://github.com/cawaphp/serializer/blob/dedf2206d6a617086321060429c2c9bb227ffc71/src/Serializer.php#L77-L136 | train |
cawaphp/serializer | src/Serializer.php | Serializer.unserializeObject | private function unserializeObject($object, &$data, string $className = null) : array
{
$reflectionClass = new \ReflectionClass($className ? $className : $object);
unset($data['@type']);
// parent class
$parent = $reflectionClass->getParentClass();
if ($parent) {
$this->unserializeObject($object, $data, $parent->getName());
}
foreach ($reflectionClass->getProperties() as $property) {
$name = $property->getName();
if (array_key_exists($name, $data)) {
$currentValue = $data[$name];
if (isset($data[$name]['@ref'])) {
$currentValue = $this->references[$data[$name]['@ref']];
} elseif (isset($data[$name]['@type'])) {
$reflection = new \ReflectionClass($data[$name]['@type']);
$parent = $reflection;
$internal = false;
while ($parent !== false) {
$internal = $parent->isInternal() ? true : $internal;
$parent = $parent->getParentClass();
}
if ($internal) {
$currentData = $data[$name];
$currentType = $data[$name]['@type'];
unset($currentData['@type']);
$serialize = preg_replace(
'`^a:`',
'O:' . strlen($currentType) . ':"' . $currentType . '":',
serialize($currentData)
);
$currentValue = unserialize($serialize);
} else {
$currentValue = $reflection->newInstanceWithoutConstructor();
$this->unserializeObject($currentValue, $data[$name]);
}
} elseif (is_array($currentValue)) {
$currentValue = [];
foreach ($data[$name] as $key => $value) {
if (isset($value['@type'])) {
$reflection = new \ReflectionClass($value['@type']);
$currentValue[$key] = $reflection->newInstanceWithoutConstructor();
$this->unserializeObject($currentValue[$key], $value);
} else {
$currentValue[$key] = $value;
}
}
}
$property->setAccessible(true);
$property->setValue($object, $currentValue);
unset($data[$name]);
}
}
return $data;
} | php | private function unserializeObject($object, &$data, string $className = null) : array
{
$reflectionClass = new \ReflectionClass($className ? $className : $object);
unset($data['@type']);
// parent class
$parent = $reflectionClass->getParentClass();
if ($parent) {
$this->unserializeObject($object, $data, $parent->getName());
}
foreach ($reflectionClass->getProperties() as $property) {
$name = $property->getName();
if (array_key_exists($name, $data)) {
$currentValue = $data[$name];
if (isset($data[$name]['@ref'])) {
$currentValue = $this->references[$data[$name]['@ref']];
} elseif (isset($data[$name]['@type'])) {
$reflection = new \ReflectionClass($data[$name]['@type']);
$parent = $reflection;
$internal = false;
while ($parent !== false) {
$internal = $parent->isInternal() ? true : $internal;
$parent = $parent->getParentClass();
}
if ($internal) {
$currentData = $data[$name];
$currentType = $data[$name]['@type'];
unset($currentData['@type']);
$serialize = preg_replace(
'`^a:`',
'O:' . strlen($currentType) . ':"' . $currentType . '":',
serialize($currentData)
);
$currentValue = unserialize($serialize);
} else {
$currentValue = $reflection->newInstanceWithoutConstructor();
$this->unserializeObject($currentValue, $data[$name]);
}
} elseif (is_array($currentValue)) {
$currentValue = [];
foreach ($data[$name] as $key => $value) {
if (isset($value['@type'])) {
$reflection = new \ReflectionClass($value['@type']);
$currentValue[$key] = $reflection->newInstanceWithoutConstructor();
$this->unserializeObject($currentValue[$key], $value);
} else {
$currentValue[$key] = $value;
}
}
}
$property->setAccessible(true);
$property->setValue($object, $currentValue);
unset($data[$name]);
}
}
return $data;
} | [
"private",
"function",
"unserializeObject",
"(",
"$",
"object",
",",
"&",
"$",
"data",
",",
"string",
"$",
"className",
"=",
"null",
")",
":",
"array",
"{",
"$",
"reflectionClass",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"className",
"?",
"$",
"cl... | Recursive unserialize to get parent class property.
@param object $object
@param array $data
@param string $className
@return array | [
"Recursive",
"unserialize",
"to",
"get",
"parent",
"class",
"property",
"."
] | dedf2206d6a617086321060429c2c9bb227ffc71 | https://github.com/cawaphp/serializer/blob/dedf2206d6a617086321060429c2c9bb227ffc71/src/Serializer.php#L171-L237 | train |
EarthlingInteractive/PHPCMIPREST | lib/EarthIT/CMIPREST/ResultAssembler/JAOResultAssembler.php | EarthIT_CMIPREST_ResultAssembler_JAOResultAssembler._q45 | protected function _q45( EarthIT_Schema_ResourceClass $rc, array $items ) {
$restObjects = array();
foreach( $items as $item ) {
$restObjects[] = $this->internalObjectToJao($rc, $item);
}
return $restObjects;
} | php | protected function _q45( EarthIT_Schema_ResourceClass $rc, array $items ) {
$restObjects = array();
foreach( $items as $item ) {
$restObjects[] = $this->internalObjectToJao($rc, $item);
}
return $restObjects;
} | [
"protected",
"function",
"_q45",
"(",
"EarthIT_Schema_ResourceClass",
"$",
"rc",
",",
"array",
"$",
"items",
")",
"{",
"$",
"restObjects",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"$",
"restObjects",
"[",
... | Convert the given rows from internal to REST format according to the
specified resource class. | [
"Convert",
"the",
"given",
"rows",
"from",
"internal",
"to",
"REST",
"format",
"according",
"to",
"the",
"specified",
"resource",
"class",
"."
] | db0398ea4fc07fa62f2de9ba43f2f3137170d9f0 | https://github.com/EarthlingInteractive/PHPCMIPREST/blob/db0398ea4fc07fa62f2de9ba43f2f3137170d9f0/lib/EarthIT/CMIPREST/ResultAssembler/JAOResultAssembler.php#L101-L107 | train |
jfortunato/fortune | src/ResourceFactory.php | ResourceFactory.newSimpleOutput | public function newSimpleOutput()
{
$config = $this->config->getCurrentResourceConfiguration();
return new SimpleOutput(
$this->newSerializer($config),
$this->newResource($config)
);
} | php | public function newSimpleOutput()
{
$config = $this->config->getCurrentResourceConfiguration();
return new SimpleOutput(
$this->newSerializer($config),
$this->newResource($config)
);
} | [
"public",
"function",
"newSimpleOutput",
"(",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"config",
"->",
"getCurrentResourceConfiguration",
"(",
")",
";",
"return",
"new",
"SimpleOutput",
"(",
"$",
"this",
"->",
"newSerializer",
"(",
"$",
"config",
")"... | Creates a SimpleOutput instance to be used with native PHP.
@return SimpleOutput | [
"Creates",
"a",
"SimpleOutput",
"instance",
"to",
"be",
"used",
"with",
"native",
"PHP",
"."
] | 3bbf66a85304070562e54a66c99145f58f32877e | https://github.com/jfortunato/fortune/blob/3bbf66a85304070562e54a66c99145f58f32877e/src/ResourceFactory.php#L68-L76 | train |
jfortunato/fortune | src/ResourceFactory.php | ResourceFactory.newSlimOutput | public function newSlimOutput(Request $request, Response $response)
{
$config = $this->config->getCurrentResourceConfiguration();
return new SlimOutput(
$request,
$response,
$this->newSerializer($config),
$this->newResource($config)
);
} | php | public function newSlimOutput(Request $request, Response $response)
{
$config = $this->config->getCurrentResourceConfiguration();
return new SlimOutput(
$request,
$response,
$this->newSerializer($config),
$this->newResource($config)
);
} | [
"public",
"function",
"newSlimOutput",
"(",
"Request",
"$",
"request",
",",
"Response",
"$",
"response",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"config",
"->",
"getCurrentResourceConfiguration",
"(",
")",
";",
"return",
"new",
"SlimOutput",
"(",
"$... | Creates a SlimOutput instance to be used with the slim PHP framework.
@param Request $request
@param Response $response
@return SlimOutput | [
"Creates",
"a",
"SlimOutput",
"instance",
"to",
"be",
"used",
"with",
"the",
"slim",
"PHP",
"framework",
"."
] | 3bbf66a85304070562e54a66c99145f58f32877e | https://github.com/jfortunato/fortune/blob/3bbf66a85304070562e54a66c99145f58f32877e/src/ResourceFactory.php#L85-L95 | train |
jfortunato/fortune | src/ResourceFactory.php | ResourceFactory.generateSlimRoutes | public function generateSlimRoutes(Slim $slim)
{
// if we are not on a resources's route, then dont generate any routes
if (!$this->config->getCurrentResourceConfiguration()) {
return;
}
$output = $this->newSlimOutput($slim->request, $slim->response);
$generator = new SlimRouteGenerator($slim, $output, $this->config);
$generator->generateRoutes();
} | php | public function generateSlimRoutes(Slim $slim)
{
// if we are not on a resources's route, then dont generate any routes
if (!$this->config->getCurrentResourceConfiguration()) {
return;
}
$output = $this->newSlimOutput($slim->request, $slim->response);
$generator = new SlimRouteGenerator($slim, $output, $this->config);
$generator->generateRoutes();
} | [
"public",
"function",
"generateSlimRoutes",
"(",
"Slim",
"$",
"slim",
")",
"{",
"// if we are not on a resources's route, then dont generate any routes",
"if",
"(",
"!",
"$",
"this",
"->",
"config",
"->",
"getCurrentResourceConfiguration",
"(",
")",
")",
"{",
"return",
... | Helper for generating all the routes for the configured resources in slim.
@param Slim $slim
@return void | [
"Helper",
"for",
"generating",
"all",
"the",
"routes",
"for",
"the",
"configured",
"resources",
"in",
"slim",
"."
] | 3bbf66a85304070562e54a66c99145f58f32877e | https://github.com/jfortunato/fortune/blob/3bbf66a85304070562e54a66c99145f58f32877e/src/ResourceFactory.php#L103-L115 | train |
jfortunato/fortune | src/ResourceFactory.php | ResourceFactory.resourceFor | public function resourceFor($resourceName)
{
$resourceConfig = $this->config->resourceConfigurationFor($resourceName);
return $this->newResource($resourceConfig);
} | php | public function resourceFor($resourceName)
{
$resourceConfig = $this->config->resourceConfigurationFor($resourceName);
return $this->newResource($resourceConfig);
} | [
"public",
"function",
"resourceFor",
"(",
"$",
"resourceName",
")",
"{",
"$",
"resourceConfig",
"=",
"$",
"this",
"->",
"config",
"->",
"resourceConfigurationFor",
"(",
"$",
"resourceName",
")",
";",
"return",
"$",
"this",
"->",
"newResource",
"(",
"$",
"res... | Finds a ResourceConfiguration for given resource name.
@param string $resourceName
@return ResourceConfiguration | [
"Finds",
"a",
"ResourceConfiguration",
"for",
"given",
"resource",
"name",
"."
] | 3bbf66a85304070562e54a66c99145f58f32877e | https://github.com/jfortunato/fortune/blob/3bbf66a85304070562e54a66c99145f58f32877e/src/ResourceFactory.php#L133-L138 | train |
jfortunato/fortune | src/ResourceFactory.php | ResourceFactory.newRepository | protected function newRepository(ResourceConfiguration $config)
{
if ($this->database instanceof EntityManager) {
return $this->newDoctrineRepository($this->database, $config->getEntityClass(), $config->getParent());
} elseif ($this->database instanceof PDO) {
return $this->newPdoRepository($this->database, $config->getResource(), $config->getParent());
}
throw new \Exception("Couldn't determine database connection type.");
} | php | protected function newRepository(ResourceConfiguration $config)
{
if ($this->database instanceof EntityManager) {
return $this->newDoctrineRepository($this->database, $config->getEntityClass(), $config->getParent());
} elseif ($this->database instanceof PDO) {
return $this->newPdoRepository($this->database, $config->getResource(), $config->getParent());
}
throw new \Exception("Couldn't determine database connection type.");
} | [
"protected",
"function",
"newRepository",
"(",
"ResourceConfiguration",
"$",
"config",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"database",
"instanceof",
"EntityManager",
")",
"{",
"return",
"$",
"this",
"->",
"newDoctrineRepository",
"(",
"$",
"this",
"->",
"d... | Determines which repository to use based on the database connection
that was passed in.
@param string $entityClass
@return ResourceRepositoryInterface | [
"Determines",
"which",
"repository",
"to",
"use",
"based",
"on",
"the",
"database",
"connection",
"that",
"was",
"passed",
"in",
"."
] | 3bbf66a85304070562e54a66c99145f58f32877e | https://github.com/jfortunato/fortune/blob/3bbf66a85304070562e54a66c99145f58f32877e/src/ResourceFactory.php#L171-L180 | train |
jfortunato/fortune | src/ResourceFactory.php | ResourceFactory.newSerializer | protected function newSerializer(ResourceConfiguration $config)
{
return new JMSSerializer(
SerializerBuilder::create()->build(),
new SerializationContext,
new JMSPropertyExcluder($config->getExcludedProperties())
);
} | php | protected function newSerializer(ResourceConfiguration $config)
{
return new JMSSerializer(
SerializerBuilder::create()->build(),
new SerializationContext,
new JMSPropertyExcluder($config->getExcludedProperties())
);
} | [
"protected",
"function",
"newSerializer",
"(",
"ResourceConfiguration",
"$",
"config",
")",
"{",
"return",
"new",
"JMSSerializer",
"(",
"SerializerBuilder",
"::",
"create",
"(",
")",
"->",
"build",
"(",
")",
",",
"new",
"SerializationContext",
",",
"new",
"JMSPr... | Creates JMSSerializer instance.
@return JMSSerializer | [
"Creates",
"JMSSerializer",
"instance",
"."
] | 3bbf66a85304070562e54a66c99145f58f32877e | https://github.com/jfortunato/fortune/blob/3bbf66a85304070562e54a66c99145f58f32877e/src/ResourceFactory.php#L187-L194 | train |
jfortunato/fortune | src/ResourceFactory.php | ResourceFactory.newResource | protected function newResource(ResourceConfiguration $config)
{
return new Resource(
$this->newRepository($config),
$this->newValidator($config),
$this->newSecurity(),
$this,
$config
);
} | php | protected function newResource(ResourceConfiguration $config)
{
return new Resource(
$this->newRepository($config),
$this->newValidator($config),
$this->newSecurity(),
$this,
$config
);
} | [
"protected",
"function",
"newResource",
"(",
"ResourceConfiguration",
"$",
"config",
")",
"{",
"return",
"new",
"Resource",
"(",
"$",
"this",
"->",
"newRepository",
"(",
"$",
"config",
")",
",",
"$",
"this",
"->",
"newValidator",
"(",
"$",
"config",
")",
"... | Creates a new Resource based off its ResourceConfiguration
@param ResourceConfiguration $config
@return Resource | [
"Creates",
"a",
"new",
"Resource",
"based",
"off",
"its",
"ResourceConfiguration"
] | 3bbf66a85304070562e54a66c99145f58f32877e | https://github.com/jfortunato/fortune/blob/3bbf66a85304070562e54a66c99145f58f32877e/src/ResourceFactory.php#L202-L211 | train |
jfortunato/fortune | src/ResourceFactory.php | ResourceFactory.newValidator | protected function newValidator(ResourceConfiguration $config)
{
$class = $config->getValidatorClass();
return $config->isUsingYamlValidation() ?
new YamlResourceValidator($config->getYamlValidation()) : new $class();
} | php | protected function newValidator(ResourceConfiguration $config)
{
$class = $config->getValidatorClass();
return $config->isUsingYamlValidation() ?
new YamlResourceValidator($config->getYamlValidation()) : new $class();
} | [
"protected",
"function",
"newValidator",
"(",
"ResourceConfiguration",
"$",
"config",
")",
"{",
"$",
"class",
"=",
"$",
"config",
"->",
"getValidatorClass",
"(",
")",
";",
"return",
"$",
"config",
"->",
"isUsingYamlValidation",
"(",
")",
"?",
"new",
"YamlResou... | Checks the configuration to decide what validation class to use.
@param ResourceConfiguration $config
@return YamlResourceValidator|object | [
"Checks",
"the",
"configuration",
"to",
"decide",
"what",
"validation",
"class",
"to",
"use",
"."
] | 3bbf66a85304070562e54a66c99145f58f32877e | https://github.com/jfortunato/fortune/blob/3bbf66a85304070562e54a66c99145f58f32877e/src/ResourceFactory.php#L219-L225 | train |
jfortunato/fortune | src/ResourceFactory.php | ResourceFactory.newSecurity | protected function newSecurity()
{
$config = $this->config->getCurrentResourceConfiguration();
return new Security(
new SimpleAuthenticationBouncer($config),
new SimpleRoleBouncer($config),
new ParentBouncer($config)
);
} | php | protected function newSecurity()
{
$config = $this->config->getCurrentResourceConfiguration();
return new Security(
new SimpleAuthenticationBouncer($config),
new SimpleRoleBouncer($config),
new ParentBouncer($config)
);
} | [
"protected",
"function",
"newSecurity",
"(",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"config",
"->",
"getCurrentResourceConfiguration",
"(",
")",
";",
"return",
"new",
"Security",
"(",
"new",
"SimpleAuthenticationBouncer",
"(",
"$",
"config",
")",
","... | Creates a Security gateway with all Bouncers
@return Security | [
"Creates",
"a",
"Security",
"gateway",
"with",
"all",
"Bouncers"
] | 3bbf66a85304070562e54a66c99145f58f32877e | https://github.com/jfortunato/fortune/blob/3bbf66a85304070562e54a66c99145f58f32877e/src/ResourceFactory.php#L232-L241 | train |
yoozoo/protoapiphp | src/httpClient.php | HttpClient.callApi | public function callApi(Message $req, $method, $uri, $handler)
{
// check handler, php before 5.4 doesn't support Type Hinting of callable
if (!is_callable($handler)) {
throw new GeneralException("Can not find response handler.");
}
$data = [
'json' => (object) $req->to_array(),
'http_errors' => false,
];
$response = $this->request($method, $uri, $data);
$rawContent = $response->getBody()->getContents();
$content = json_decode($rawContent, true);
if (!$content) {
throw new GeneralException("Response is not json data: " . $rawContent);
}
$statusCode = $response->getStatusCode();
switch ($statusCode) {
case 200:
// happy path
if (isset($content)) {
return $handler($content, "", "");
} else {
throw new GeneralException("Cannot find response body: " . $rawContent);
}
break;
case 400:
// biz error
if (isset($content)) {
return $handler("", $content, "");
}
throw new GeneralException("Cannot find Biz Error body: " . $rawContent);
break;
case 420:
// common error
if (isset($content)) {
return $handler("", "", $content);
}
throw new GeneralException("Cannot find Common Error body: " . $rawContent);
break;
case 500:
// internal error
throw new InternalServerErrorException("Internal server error: " . $rawContent);
break;
}
} | php | public function callApi(Message $req, $method, $uri, $handler)
{
// check handler, php before 5.4 doesn't support Type Hinting of callable
if (!is_callable($handler)) {
throw new GeneralException("Can not find response handler.");
}
$data = [
'json' => (object) $req->to_array(),
'http_errors' => false,
];
$response = $this->request($method, $uri, $data);
$rawContent = $response->getBody()->getContents();
$content = json_decode($rawContent, true);
if (!$content) {
throw new GeneralException("Response is not json data: " . $rawContent);
}
$statusCode = $response->getStatusCode();
switch ($statusCode) {
case 200:
// happy path
if (isset($content)) {
return $handler($content, "", "");
} else {
throw new GeneralException("Cannot find response body: " . $rawContent);
}
break;
case 400:
// biz error
if (isset($content)) {
return $handler("", $content, "");
}
throw new GeneralException("Cannot find Biz Error body: " . $rawContent);
break;
case 420:
// common error
if (isset($content)) {
return $handler("", "", $content);
}
throw new GeneralException("Cannot find Common Error body: " . $rawContent);
break;
case 500:
// internal error
throw new InternalServerErrorException("Internal server error: " . $rawContent);
break;
}
} | [
"public",
"function",
"callApi",
"(",
"Message",
"$",
"req",
",",
"$",
"method",
",",
"$",
"uri",
",",
"$",
"handler",
")",
"{",
"// check handler, php before 5.4 doesn't support Type Hinting of callable",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"handler",
")",
... | call api, handle error, return response
@param Message $req
@param String $method
@param String $uri
@param function $handler function($response, $bizerror, $common) create response oject or throw biz error exception
@return Message $result | [
"call",
"api",
"handle",
"error",
"return",
"response"
] | 524f7688e55a616f9edca8711b101c058a1ce6e5 | https://github.com/yoozoo/protoapiphp/blob/524f7688e55a616f9edca8711b101c058a1ce6e5/src/httpClient.php#L23-L71 | train |
bytepark/lib-migration | src/Repository/AbstractRepository.php | AbstractRepository.diff | public function diff(Repository $otherRepository)
{
$diffRepository = new Memory();
foreach ($this->unitOfWorkStore as $unitOfWork) {
if (!$otherRepository->contains($unitOfWork)) {
$diffRepository->add($unitOfWork);
}
}
$diffRepository->sort();
return $diffRepository;
} | php | public function diff(Repository $otherRepository)
{
$diffRepository = new Memory();
foreach ($this->unitOfWorkStore as $unitOfWork) {
if (!$otherRepository->contains($unitOfWork)) {
$diffRepository->add($unitOfWork);
}
}
$diffRepository->sort();
return $diffRepository;
} | [
"public",
"function",
"diff",
"(",
"Repository",
"$",
"otherRepository",
")",
"{",
"$",
"diffRepository",
"=",
"new",
"Memory",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"unitOfWorkStore",
"as",
"$",
"unitOfWork",
")",
"{",
"if",
"(",
"!",
"$",
... | Calculates the diff to the given repository
The method returns a Repository including all Migrations present in this
instance but not the given other repository.
@param Repository $otherRepository The repository to diff to
@throws \Bytepark\Component\Migration\Exception\UnitIsAlreadyPresentException
@return Repository The diff | [
"Calculates",
"the",
"diff",
"to",
"the",
"given",
"repository"
] | 14d75f6978e257f456493c673175ca5d07b28c84 | https://github.com/bytepark/lib-migration/blob/14d75f6978e257f456493c673175ca5d07b28c84/src/Repository/AbstractRepository.php#L59-L72 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.