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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
aviat4ion/Query | src/QueryBuilder.php | QueryBuilder._compileType | protected function _compileType(string $type='', string $table=''): string
{
$setArrayKeys = $this->state->getSetArrayKeys();
switch($type)
{
case 'insert':
$paramCount = count($setArrayKeys);
$params = array_fill(0, $paramCount, '?');
$sql = "INSERT INTO {$table} ("
. implode(',', $setArrayKeys)
. ")\nVALUES (".implode(',', $params).')';
break;
case 'update':
$setString = $this->state->getSetString();
$sql = "UPDATE {$table}\nSET {$setString}";
break;
case 'replace':
// @TODO implement
$sql = '';
break;
case 'delete':
$sql = "DELETE FROM {$table}";
break;
// Get queries
default:
$fromString = $this->state->getFromString();
$selectString = $this->state->getSelectString();
$sql = "SELECT * \nFROM {$fromString}";
// Set the select string
if ( ! empty($selectString))
{
// Replace the star with the selected fields
$sql = str_replace('*', $selectString, $sql);
}
break;
}
return $sql;
} | php | protected function _compileType(string $type='', string $table=''): string
{
$setArrayKeys = $this->state->getSetArrayKeys();
switch($type)
{
case 'insert':
$paramCount = count($setArrayKeys);
$params = array_fill(0, $paramCount, '?');
$sql = "INSERT INTO {$table} ("
. implode(',', $setArrayKeys)
. ")\nVALUES (".implode(',', $params).')';
break;
case 'update':
$setString = $this->state->getSetString();
$sql = "UPDATE {$table}\nSET {$setString}";
break;
case 'replace':
// @TODO implement
$sql = '';
break;
case 'delete':
$sql = "DELETE FROM {$table}";
break;
// Get queries
default:
$fromString = $this->state->getFromString();
$selectString = $this->state->getSelectString();
$sql = "SELECT * \nFROM {$fromString}";
// Set the select string
if ( ! empty($selectString))
{
// Replace the star with the selected fields
$sql = str_replace('*', $selectString, $sql);
}
break;
}
return $sql;
} | [
"protected",
"function",
"_compileType",
"(",
"string",
"$",
"type",
"=",
"''",
",",
"string",
"$",
"table",
"=",
"''",
")",
":",
"string",
"{",
"$",
"setArrayKeys",
"=",
"$",
"this",
"->",
"state",
"->",
"getSetArrayKeys",
"(",
")",
";",
"switch",
"("... | Sub-method for generating sql strings
@param string $type
@param string $table
@return string | [
"Sub",
"-",
"method",
"for",
"generating",
"sql",
"strings"
] | 172eb3f6ebdfb7295b42e32cc74bf37c3ebd7650 | https://github.com/aviat4ion/Query/blob/172eb3f6ebdfb7295b42e32cc74bf37c3ebd7650/src/QueryBuilder.php#L1202-L1246 | train |
aviat4ion/Query | src/QueryBuilder.php | QueryBuilder._compile | protected function _compile(string $type='', string $table=''): string
{
// Get the base clause for the query
$sql = $this->_compileType($type, $this->driver->quoteTable($table));
$clauses = [
'queryMap',
'groupString',
'orderString',
'havingMap',
];
// Set each type of subclause
foreach($clauses as $clause)
{
$func = 'get' . ucFirst($clause);
$param = $this->state->$func();
if (\is_array($param))
{
foreach($param as $q)
{
$sql .= $q['conjunction'] . $q['string'];
}
}
else
{
$sql .= $param;
}
}
// Set the limit via the class variables
$limit = $this->state->getLimit();
if (is_numeric($limit))
{
$sql = $this->driver->getSql()->limit($sql, $limit, $this->state->getOffset());
}
// See if the query plan, rather than the
// query data should be returned
if ($this->explain === TRUE)
{
$sql = $this->driver->getSql()->explain($sql);
}
return $sql;
} | php | protected function _compile(string $type='', string $table=''): string
{
// Get the base clause for the query
$sql = $this->_compileType($type, $this->driver->quoteTable($table));
$clauses = [
'queryMap',
'groupString',
'orderString',
'havingMap',
];
// Set each type of subclause
foreach($clauses as $clause)
{
$func = 'get' . ucFirst($clause);
$param = $this->state->$func();
if (\is_array($param))
{
foreach($param as $q)
{
$sql .= $q['conjunction'] . $q['string'];
}
}
else
{
$sql .= $param;
}
}
// Set the limit via the class variables
$limit = $this->state->getLimit();
if (is_numeric($limit))
{
$sql = $this->driver->getSql()->limit($sql, $limit, $this->state->getOffset());
}
// See if the query plan, rather than the
// query data should be returned
if ($this->explain === TRUE)
{
$sql = $this->driver->getSql()->explain($sql);
}
return $sql;
} | [
"protected",
"function",
"_compile",
"(",
"string",
"$",
"type",
"=",
"''",
",",
"string",
"$",
"table",
"=",
"''",
")",
":",
"string",
"{",
"// Get the base clause for the query",
"$",
"sql",
"=",
"$",
"this",
"->",
"_compileType",
"(",
"$",
"type",
",",
... | String together the sql statements for sending to the db
@param string $type
@param string $table
@return string | [
"String",
"together",
"the",
"sql",
"statements",
"for",
"sending",
"to",
"the",
"db"
] | 172eb3f6ebdfb7295b42e32cc74bf37c3ebd7650 | https://github.com/aviat4ion/Query/blob/172eb3f6ebdfb7295b42e32cc74bf37c3ebd7650/src/QueryBuilder.php#L1255-L1300 | train |
joomlatools/joomlatools-framework-activities | template/helper/activity.php | ComActivitiesTemplateHelperActivity._renderObject | protected function _renderObject(ComActivitiesActivityObjectInterface $object, KObjectConfig $config)
{
$config->append(array('html' => true, 'escaped_urls' => true, 'fqr' => false, 'links' => true));
if ($output = $object->getDisplayName())
{
if ($config->html)
{
$output = $object->getDisplayName();
$attribs = $object->getAttributes() ? $this->buildAttributes($object->getAttributes()) : '';
if ($config->links && $url = $object->getUrl())
{
// Make sure we have a fully qualified route.
if ($config->fqr && !$url->getHost()) {
$url->setUrl($this->getTemplate()->url()->toString(KHttpUrl::AUTHORITY));
}
$url = $url->toString(KHttpUrl::FULL, $config->escaped_urls);
$output = "<a {$attribs} href=\"{$url}\">{$output}</a>";
}
else $output = "<span {$attribs}>{$output}</span>";
}
}
else $output = '';
return $output;
} | php | protected function _renderObject(ComActivitiesActivityObjectInterface $object, KObjectConfig $config)
{
$config->append(array('html' => true, 'escaped_urls' => true, 'fqr' => false, 'links' => true));
if ($output = $object->getDisplayName())
{
if ($config->html)
{
$output = $object->getDisplayName();
$attribs = $object->getAttributes() ? $this->buildAttributes($object->getAttributes()) : '';
if ($config->links && $url = $object->getUrl())
{
// Make sure we have a fully qualified route.
if ($config->fqr && !$url->getHost()) {
$url->setUrl($this->getTemplate()->url()->toString(KHttpUrl::AUTHORITY));
}
$url = $url->toString(KHttpUrl::FULL, $config->escaped_urls);
$output = "<a {$attribs} href=\"{$url}\">{$output}</a>";
}
else $output = "<span {$attribs}>{$output}</span>";
}
}
else $output = '';
return $output;
} | [
"protected",
"function",
"_renderObject",
"(",
"ComActivitiesActivityObjectInterface",
"$",
"object",
",",
"KObjectConfig",
"$",
"config",
")",
"{",
"$",
"config",
"->",
"append",
"(",
"array",
"(",
"'html'",
"=>",
"true",
",",
"'escaped_urls'",
"=>",
"true",
",... | Renders an activity object.
@param ComActivitiesActivityObjectInterface $object The activity object.
@param KObjectConfig $config The configuration object.
@return string The rendered object. | [
"Renders",
"an",
"activity",
"object",
"."
] | 701abf6186729f62643bc834055cdebc08c25c21 | https://github.com/joomlatools/joomlatools-framework-activities/blob/701abf6186729f62643bc834055cdebc08c25c21/template/helper/activity.php#L94-L121 | train |
joomlatools/joomlatools-framework-activities | activity/logger/logger.php | ComActivitiesActivityLogger.log | public function log($action, KModelEntityInterface $object, KObjectIdentifierInterface $subject)
{
$controller = $this->getObject($this->_controller);
if($controller instanceof KControllerModellable)
{
foreach($object as $entity)
{
// Only log if the entity status is valid.
$status = $this->getActivityStatus($entity, $action);
if (!empty($status) && $status !== KModelEntityInterface::STATUS_FAILED)
{
// Get the activity data
$data = $this->getActivityData($entity, $subject, $action);
// Set the status
if(!isset($data['status'] )) {
$data['status'] = $status;
}
// Set the action
if(!isset($data['action']))
{
$parts = explode('.', $action);
$data['action'] = $parts[1];
}
$controller->add($data);
}
}
}
} | php | public function log($action, KModelEntityInterface $object, KObjectIdentifierInterface $subject)
{
$controller = $this->getObject($this->_controller);
if($controller instanceof KControllerModellable)
{
foreach($object as $entity)
{
// Only log if the entity status is valid.
$status = $this->getActivityStatus($entity, $action);
if (!empty($status) && $status !== KModelEntityInterface::STATUS_FAILED)
{
// Get the activity data
$data = $this->getActivityData($entity, $subject, $action);
// Set the status
if(!isset($data['status'] )) {
$data['status'] = $status;
}
// Set the action
if(!isset($data['action']))
{
$parts = explode('.', $action);
$data['action'] = $parts[1];
}
$controller->add($data);
}
}
}
} | [
"public",
"function",
"log",
"(",
"$",
"action",
",",
"KModelEntityInterface",
"$",
"object",
",",
"KObjectIdentifierInterface",
"$",
"subject",
")",
"{",
"$",
"controller",
"=",
"$",
"this",
"->",
"getObject",
"(",
"$",
"this",
"->",
"_controller",
")",
";"... | Log an activity.
@param string $action The action to log.
@param KModelEntityInterface $object The activity object on which the action is performed.
@param KObjectIdentifierInterface $subject The activity subject who is performing the action. | [
"Log",
"an",
"activity",
"."
] | 701abf6186729f62643bc834055cdebc08c25c21 | https://github.com/joomlatools/joomlatools-framework-activities/blob/701abf6186729f62643bc834055cdebc08c25c21/activity/logger/logger.php#L79-L111 | train |
joomlatools/joomlatools-framework-activities | activity/logger/logger.php | ComActivitiesActivityLogger.getActivityObject | public function getActivityObject(KCommandInterface $command)
{
$parts = explode('.', $command->getName());
// Properly fetch data for the event.
if ($parts[0] == 'before') {
$object = $command->getSubject()->getModel()->fetch();
} else {
$object = $command->result;
}
return $object;
} | php | public function getActivityObject(KCommandInterface $command)
{
$parts = explode('.', $command->getName());
// Properly fetch data for the event.
if ($parts[0] == 'before') {
$object = $command->getSubject()->getModel()->fetch();
} else {
$object = $command->result;
}
return $object;
} | [
"public",
"function",
"getActivityObject",
"(",
"KCommandInterface",
"$",
"command",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"command",
"->",
"getName",
"(",
")",
")",
";",
"// Properly fetch data for the event.",
"if",
"(",
"$",
"parts",... | Get the activity object.
The activity object is the entity on which the action is executed.
@param KCommandInterface $command The command.
@return KModelEntityInterface The activity object. | [
"Get",
"the",
"activity",
"object",
"."
] | 701abf6186729f62643bc834055cdebc08c25c21 | https://github.com/joomlatools/joomlatools-framework-activities/blob/701abf6186729f62643bc834055cdebc08c25c21/activity/logger/logger.php#L145-L157 | train |
joomlatools/joomlatools-framework-activities | activity/logger/logger.php | ComActivitiesActivityLogger.getActivityStatus | public function getActivityStatus(KModelEntityInterface $object, $action = null)
{
$status = $object->getStatus();
// Commands may change the original status of an action.
if ($action == 'after.add' && $status == KModelEntityInterface::STATUS_UPDATED) {
$status = KModelEntityInterface::STATUS_CREATED;
}
// Ignore non-changing edits.
if ($action == 'after.edit' && $status == KModelEntityInterface::STATUS_FETCHED) {
$status = null;
}
return $status;
} | php | public function getActivityStatus(KModelEntityInterface $object, $action = null)
{
$status = $object->getStatus();
// Commands may change the original status of an action.
if ($action == 'after.add' && $status == KModelEntityInterface::STATUS_UPDATED) {
$status = KModelEntityInterface::STATUS_CREATED;
}
// Ignore non-changing edits.
if ($action == 'after.edit' && $status == KModelEntityInterface::STATUS_FETCHED) {
$status = null;
}
return $status;
} | [
"public",
"function",
"getActivityStatus",
"(",
"KModelEntityInterface",
"$",
"object",
",",
"$",
"action",
"=",
"null",
")",
"{",
"$",
"status",
"=",
"$",
"object",
"->",
"getStatus",
"(",
")",
";",
"// Commands may change the original status of an action.",
"if",
... | Get the activity status.
The activity status is the current status of the activity object.
@param KModelEntityInterface $object The activity object.
@param string $action The action being executed.
@return string The activity status. | [
"Get",
"the",
"activity",
"status",
"."
] | 701abf6186729f62643bc834055cdebc08c25c21 | https://github.com/joomlatools/joomlatools-framework-activities/blob/701abf6186729f62643bc834055cdebc08c25c21/activity/logger/logger.php#L168-L183 | train |
aviat4ion/Query | src/ConnectionManager.php | ConnectionManager.getInstance | public static function getInstance(): ConnectionManager
{
if (self::$instance === NULL)
{
self::$instance = new self();
}
return self::$instance;
} | php | public static function getInstance(): ConnectionManager
{
if (self::$instance === NULL)
{
self::$instance = new self();
}
return self::$instance;
} | [
"public",
"static",
"function",
"getInstance",
"(",
")",
":",
"ConnectionManager",
"{",
"if",
"(",
"self",
"::",
"$",
"instance",
"===",
"NULL",
")",
"{",
"self",
"::",
"$",
"instance",
"=",
"new",
"self",
"(",
")",
";",
"}",
"return",
"self",
"::",
... | Return a connection manager instance
@staticvar null $instance
@return ConnectionManager | [
"Return",
"a",
"connection",
"manager",
"instance"
] | 172eb3f6ebdfb7295b42e32cc74bf37c3ebd7650 | https://github.com/aviat4ion/Query/blob/172eb3f6ebdfb7295b42e32cc74bf37c3ebd7650/src/ConnectionManager.php#L85-L93 | train |
aviat4ion/Query | src/ConnectionManager.php | ConnectionManager.getConnection | public function getConnection($name = ''): QueryBuilderInterface
{
// If the parameter is a string, use it as an array index
if (is_scalar($name) && isset($this->connections[$name]))
{
return $this->connections[$name];
}
else if (empty($name) && ! empty($this->connections)) // Otherwise, return the last one
{
return end($this->connections);
}
// You should actually connect before trying to get a connection...
throw new InvalidArgumentException('The specified connection does not exist');
} | php | public function getConnection($name = ''): QueryBuilderInterface
{
// If the parameter is a string, use it as an array index
if (is_scalar($name) && isset($this->connections[$name]))
{
return $this->connections[$name];
}
else if (empty($name) && ! empty($this->connections)) // Otherwise, return the last one
{
return end($this->connections);
}
// You should actually connect before trying to get a connection...
throw new InvalidArgumentException('The specified connection does not exist');
} | [
"public",
"function",
"getConnection",
"(",
"$",
"name",
"=",
"''",
")",
":",
"QueryBuilderInterface",
"{",
"// If the parameter is a string, use it as an array index",
"if",
"(",
"is_scalar",
"(",
"$",
"name",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"connecti... | Returns the connection specified by the name given
@param string|array|object $name
@return QueryBuilderInterface
@throws InvalidArgumentException | [
"Returns",
"the",
"connection",
"specified",
"by",
"the",
"name",
"given"
] | 172eb3f6ebdfb7295b42e32cc74bf37c3ebd7650 | https://github.com/aviat4ion/Query/blob/172eb3f6ebdfb7295b42e32cc74bf37c3ebd7650/src/ConnectionManager.php#L102-L116 | train |
aviat4ion/Query | src/ConnectionManager.php | ConnectionManager.connect | public function connect(\stdClass $params): QueryBuilderInterface
{
list($dsn, $dbtype, $params, $options) = $this->parseParams($params);
$dbtype = ucfirst($dbtype);
$driver = "\\Query\\Drivers\\{$dbtype}\\Driver";
// Create the database connection
$db = ! empty($params->user)
? new $driver($dsn, $params->user, $params->pass, $options)
: new $driver($dsn, '', '', $options);
// Set the table prefix, if it exists
if (isset($params->prefix))
{
$db->setTablePrefix($params->prefix);
}
// Create Query Builder object
$conn = new QueryBuilder($db, new QueryParser($db));
// Save it for later
if (isset($params->alias))
{
$this->connections[$params->alias] = $conn;
}
else
{
$this->connections[] = $conn;
}
return $conn;
} | php | public function connect(\stdClass $params): QueryBuilderInterface
{
list($dsn, $dbtype, $params, $options) = $this->parseParams($params);
$dbtype = ucfirst($dbtype);
$driver = "\\Query\\Drivers\\{$dbtype}\\Driver";
// Create the database connection
$db = ! empty($params->user)
? new $driver($dsn, $params->user, $params->pass, $options)
: new $driver($dsn, '', '', $options);
// Set the table prefix, if it exists
if (isset($params->prefix))
{
$db->setTablePrefix($params->prefix);
}
// Create Query Builder object
$conn = new QueryBuilder($db, new QueryParser($db));
// Save it for later
if (isset($params->alias))
{
$this->connections[$params->alias] = $conn;
}
else
{
$this->connections[] = $conn;
}
return $conn;
} | [
"public",
"function",
"connect",
"(",
"\\",
"stdClass",
"$",
"params",
")",
":",
"QueryBuilderInterface",
"{",
"list",
"(",
"$",
"dsn",
",",
"$",
"dbtype",
",",
"$",
"params",
",",
"$",
"options",
")",
"=",
"$",
"this",
"->",
"parseParams",
"(",
"$",
... | Parse the passed parameters and return a connection
@param \stdClass $params
@return QueryBuilderInterface | [
"Parse",
"the",
"passed",
"parameters",
"and",
"return",
"a",
"connection"
] | 172eb3f6ebdfb7295b42e32cc74bf37c3ebd7650 | https://github.com/aviat4ion/Query/blob/172eb3f6ebdfb7295b42e32cc74bf37c3ebd7650/src/ConnectionManager.php#L124-L157 | train |
aviat4ion/Query | src/ConnectionManager.php | ConnectionManager.parseParams | public function parseParams(\stdClass $params): array
{
$params->type = strtolower($params->type);
$dbtype = ($params->type !== 'postgresql') ? $params->type : 'pgsql';
$dbtype = ucfirst($dbtype);
// Make sure the class exists
if ( ! class_exists("\\Query\\Drivers\\{$dbtype}\\Driver"))
{
throw new BadDBDriverException('Database driver does not exist, or is not supported');
}
// Set additional PDO options
$options = [];
if (isset($params->options))
{
$options = (array) $params->options;
}
// Create the dsn for the database to connect to
if(strtolower($dbtype) === 'sqlite')
{
$dsn = $params->file;
}
else
{
$dsn = $this->createDsn($dbtype, $params);
}
return [$dsn, $dbtype, $params, $options];
} | php | public function parseParams(\stdClass $params): array
{
$params->type = strtolower($params->type);
$dbtype = ($params->type !== 'postgresql') ? $params->type : 'pgsql';
$dbtype = ucfirst($dbtype);
// Make sure the class exists
if ( ! class_exists("\\Query\\Drivers\\{$dbtype}\\Driver"))
{
throw new BadDBDriverException('Database driver does not exist, or is not supported');
}
// Set additional PDO options
$options = [];
if (isset($params->options))
{
$options = (array) $params->options;
}
// Create the dsn for the database to connect to
if(strtolower($dbtype) === 'sqlite')
{
$dsn = $params->file;
}
else
{
$dsn = $this->createDsn($dbtype, $params);
}
return [$dsn, $dbtype, $params, $options];
} | [
"public",
"function",
"parseParams",
"(",
"\\",
"stdClass",
"$",
"params",
")",
":",
"array",
"{",
"$",
"params",
"->",
"type",
"=",
"strtolower",
"(",
"$",
"params",
"->",
"type",
")",
";",
"$",
"dbtype",
"=",
"(",
"$",
"params",
"->",
"type",
"!=="... | Parses params into a dsn and option array
@param \stdClass $params
@return array
@throws BadDBDriverException | [
"Parses",
"params",
"into",
"a",
"dsn",
"and",
"option",
"array"
] | 172eb3f6ebdfb7295b42e32cc74bf37c3ebd7650 | https://github.com/aviat4ion/Query/blob/172eb3f6ebdfb7295b42e32cc74bf37c3ebd7650/src/ConnectionManager.php#L166-L198 | train |
aviat4ion/Query | src/ConnectionManager.php | ConnectionManager.createDsn | private function createDsn(string $dbtype, \stdClass $params): string
{
$pairs = [];
if ( ! empty($params->database))
{
$pairs[] = implode('=', ['dbname', $params->database]);
}
$skip = [
'name' => 'name',
'pass' => 'pass',
'user' => 'user',
'type' => 'type',
'prefix' => 'prefix',
'options' => 'options',
'database' => 'database',
'alias' => 'alias'
];
foreach($params as $key => $val)
{
if (( ! array_key_exists($key, $skip)) && ! empty($val))
{
$pairs[] = implode('=', [$key, $val]);
}
}
return strtolower($dbtype) . ':' . implode(';', $pairs);
} | php | private function createDsn(string $dbtype, \stdClass $params): string
{
$pairs = [];
if ( ! empty($params->database))
{
$pairs[] = implode('=', ['dbname', $params->database]);
}
$skip = [
'name' => 'name',
'pass' => 'pass',
'user' => 'user',
'type' => 'type',
'prefix' => 'prefix',
'options' => 'options',
'database' => 'database',
'alias' => 'alias'
];
foreach($params as $key => $val)
{
if (( ! array_key_exists($key, $skip)) && ! empty($val))
{
$pairs[] = implode('=', [$key, $val]);
}
}
return strtolower($dbtype) . ':' . implode(';', $pairs);
} | [
"private",
"function",
"createDsn",
"(",
"string",
"$",
"dbtype",
",",
"\\",
"stdClass",
"$",
"params",
")",
":",
"string",
"{",
"$",
"pairs",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"params",
"->",
"database",
")",
")",
"{",
"$",
... | Create the dsn from the db type and params
@codeCoverageIgnore
@param string $dbtype
@param \stdClass $params
@return string | [
"Create",
"the",
"dsn",
"from",
"the",
"db",
"type",
"and",
"params"
] | 172eb3f6ebdfb7295b42e32cc74bf37c3ebd7650 | https://github.com/aviat4ion/Query/blob/172eb3f6ebdfb7295b42e32cc74bf37c3ebd7650/src/ConnectionManager.php#L208-L237 | train |
aviat4ion/Query | src/State.php | State.appendMap | public function appendMap(string $conjunction = '', string $string = '', string $type = ''): self
{
$this->queryMap[] = [
'type' => $type,
'conjunction' => $conjunction,
'string' => $string
];
return $this;
} | php | public function appendMap(string $conjunction = '', string $string = '', string $type = ''): self
{
$this->queryMap[] = [
'type' => $type,
'conjunction' => $conjunction,
'string' => $string
];
return $this;
} | [
"public",
"function",
"appendMap",
"(",
"string",
"$",
"conjunction",
"=",
"''",
",",
"string",
"$",
"string",
"=",
"''",
",",
"string",
"$",
"type",
"=",
"''",
")",
":",
"self",
"{",
"$",
"this",
"->",
"queryMap",
"[",
"]",
"=",
"[",
"'type'",
"=>... | Add an additional set of mapping pairs to a internal map
@param string $conjunction
@param string $string
@param string $type
@return State | [
"Add",
"an",
"additional",
"set",
"of",
"mapping",
"pairs",
"to",
"a",
"internal",
"map"
] | 172eb3f6ebdfb7295b42e32cc74bf37c3ebd7650 | https://github.com/aviat4ion/Query/blob/172eb3f6ebdfb7295b42e32cc74bf37c3ebd7650/src/State.php#L400-L408 | train |
netgen-layouts/content-browser-ezplatform | lib/Backend/EzPublishBackend.php | EzPublishBackend.buildItem | private function buildItem(SearchHit $searchHit): Item
{
/** @var \eZ\Publish\API\Repository\Values\Content\Location $location */
$location = $searchHit->valueObject;
/** @var \eZ\Publish\API\Repository\Values\Content\Content $content */
$content = $this->repository->sudo(
static function (Repository $repository) use ($location): Content {
return $repository->getContentService()->loadContentByContentInfo(
$location->contentInfo
);
}
);
return new Item(
$location,
$content,
$this->config->getItemType() === 'ezlocation' ?
$location->id :
$location->contentInfo->id,
$this->isSelectable($content)
);
} | php | private function buildItem(SearchHit $searchHit): Item
{
/** @var \eZ\Publish\API\Repository\Values\Content\Location $location */
$location = $searchHit->valueObject;
/** @var \eZ\Publish\API\Repository\Values\Content\Content $content */
$content = $this->repository->sudo(
static function (Repository $repository) use ($location): Content {
return $repository->getContentService()->loadContentByContentInfo(
$location->contentInfo
);
}
);
return new Item(
$location,
$content,
$this->config->getItemType() === 'ezlocation' ?
$location->id :
$location->contentInfo->id,
$this->isSelectable($content)
);
} | [
"private",
"function",
"buildItem",
"(",
"SearchHit",
"$",
"searchHit",
")",
":",
"Item",
"{",
"/** @var \\eZ\\Publish\\API\\Repository\\Values\\Content\\Location $location */",
"$",
"location",
"=",
"$",
"searchHit",
"->",
"valueObject",
";",
"/** @var \\eZ\\Publish\\API\\Re... | Builds the item from provided search hit. | [
"Builds",
"the",
"item",
"from",
"provided",
"search",
"hit",
"."
] | 1f189f154933b92757d8072aea1ba95ac07c1167 | https://github.com/netgen-layouts/content-browser-ezplatform/blob/1f189f154933b92757d8072aea1ba95ac07c1167/lib/Backend/EzPublishBackend.php#L318-L340 | train |
netgen-layouts/content-browser-ezplatform | lib/Backend/EzPublishBackend.php | EzPublishBackend.buildItems | private function buildItems(SearchResult $searchResult): array
{
return array_map(
function (SearchHit $searchHit): Item {
return $this->buildItem($searchHit);
},
$searchResult->searchHits
);
} | php | private function buildItems(SearchResult $searchResult): array
{
return array_map(
function (SearchHit $searchHit): Item {
return $this->buildItem($searchHit);
},
$searchResult->searchHits
);
} | [
"private",
"function",
"buildItems",
"(",
"SearchResult",
"$",
"searchResult",
")",
":",
"array",
"{",
"return",
"array_map",
"(",
"function",
"(",
"SearchHit",
"$",
"searchHit",
")",
":",
"Item",
"{",
"return",
"$",
"this",
"->",
"buildItem",
"(",
"$",
"s... | Builds the items from search result and its hits.
@return \Netgen\ContentBrowser\Ez\Item\EzPublish\Item[] | [
"Builds",
"the",
"items",
"from",
"search",
"result",
"and",
"its",
"hits",
"."
] | 1f189f154933b92757d8072aea1ba95ac07c1167 | https://github.com/netgen-layouts/content-browser-ezplatform/blob/1f189f154933b92757d8072aea1ba95ac07c1167/lib/Backend/EzPublishBackend.php#L347-L355 | train |
netgen-layouts/content-browser-ezplatform | lib/Backend/EzPublishBackend.php | EzPublishBackend.getContentTypeIds | private function getContentTypeIds(array $contentTypeIdentifiers): array
{
$idList = [];
foreach ($contentTypeIdentifiers as $identifier) {
try {
$contentType = $this->contentTypeHandler->loadByIdentifier($identifier);
$idList[] = $contentType->id;
} catch (APINotFoundException $e) {
continue;
}
}
return $idList;
} | php | private function getContentTypeIds(array $contentTypeIdentifiers): array
{
$idList = [];
foreach ($contentTypeIdentifiers as $identifier) {
try {
$contentType = $this->contentTypeHandler->loadByIdentifier($identifier);
$idList[] = $contentType->id;
} catch (APINotFoundException $e) {
continue;
}
}
return $idList;
} | [
"private",
"function",
"getContentTypeIds",
"(",
"array",
"$",
"contentTypeIdentifiers",
")",
":",
"array",
"{",
"$",
"idList",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"contentTypeIdentifiers",
"as",
"$",
"identifier",
")",
"{",
"try",
"{",
"$",
"contentTyp... | Returns content type IDs for all existing content types.
@return int[] | [
"Returns",
"content",
"type",
"IDs",
"for",
"all",
"existing",
"content",
"types",
"."
] | 1f189f154933b92757d8072aea1ba95ac07c1167 | https://github.com/netgen-layouts/content-browser-ezplatform/blob/1f189f154933b92757d8072aea1ba95ac07c1167/lib/Backend/EzPublishBackend.php#L362-L376 | train |
netgen-layouts/content-browser-ezplatform | lib/Backend/EzPublishBackend.php | EzPublishBackend.isSelectable | private function isSelectable(Content $content): bool
{
if (!$this->config->hasParameter('allowed_content_types')) {
return true;
}
if ($this->allowedContentTypeIds === null) {
$this->allowedContentTypeIds = [];
$allowedContentTypes = $this->config->getParameter('allowed_content_types');
if (is_string($allowedContentTypes) && $allowedContentTypes !== '') {
$allowedContentTypes = array_map('trim', explode(',', $allowedContentTypes));
$this->allowedContentTypeIds = $this->getContentTypeIds($allowedContentTypes);
}
}
if (count($this->allowedContentTypeIds) === 0) {
return true;
}
return in_array($content->contentInfo->contentTypeId, $this->allowedContentTypeIds, true);
} | php | private function isSelectable(Content $content): bool
{
if (!$this->config->hasParameter('allowed_content_types')) {
return true;
}
if ($this->allowedContentTypeIds === null) {
$this->allowedContentTypeIds = [];
$allowedContentTypes = $this->config->getParameter('allowed_content_types');
if (is_string($allowedContentTypes) && $allowedContentTypes !== '') {
$allowedContentTypes = array_map('trim', explode(',', $allowedContentTypes));
$this->allowedContentTypeIds = $this->getContentTypeIds($allowedContentTypes);
}
}
if (count($this->allowedContentTypeIds) === 0) {
return true;
}
return in_array($content->contentInfo->contentTypeId, $this->allowedContentTypeIds, true);
} | [
"private",
"function",
"isSelectable",
"(",
"Content",
"$",
"content",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"config",
"->",
"hasParameter",
"(",
"'allowed_content_types'",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"$",
... | Returns if the provided content is selectable. | [
"Returns",
"if",
"the",
"provided",
"content",
"is",
"selectable",
"."
] | 1f189f154933b92757d8072aea1ba95ac07c1167 | https://github.com/netgen-layouts/content-browser-ezplatform/blob/1f189f154933b92757d8072aea1ba95ac07c1167/lib/Backend/EzPublishBackend.php#L381-L402 | train |
aviat4ion/Query | src/Drivers/AbstractUtil.php | AbstractUtil.createTable | public function createTable($name, $fields, array $constraints=[], $ifNotExists=TRUE)
{
$existsStr = $ifNotExists ? ' IF NOT EXISTS ' : ' ';
// Reorganize into an array indexed with column information
// Eg $columnArray[$colname] = array(
// 'type' => ...,
// 'constraint' => ...,
// 'index' => ...,
// )
$columnArray = \arrayZipper([
'type' => $fields,
'constraint' => $constraints
]);
// Join column definitions together
$columns = [];
foreach($columnArray as $n => $props)
{
$str = $this->getDriver()->quoteIdent($n);
$str .= isset($props['type']) ? " {$props['type']}" : "";
$str .= isset($props['constraint']) ? " {$props['constraint']}" : "";
$columns[] = $str;
}
// Generate the sql for the creation of the table
$sql = 'CREATE TABLE'.$existsStr.$this->getDriver()->quoteTable($name).' (';
$sql .= implode(', ', $columns);
$sql .= ')';
return $sql;
} | php | public function createTable($name, $fields, array $constraints=[], $ifNotExists=TRUE)
{
$existsStr = $ifNotExists ? ' IF NOT EXISTS ' : ' ';
// Reorganize into an array indexed with column information
// Eg $columnArray[$colname] = array(
// 'type' => ...,
// 'constraint' => ...,
// 'index' => ...,
// )
$columnArray = \arrayZipper([
'type' => $fields,
'constraint' => $constraints
]);
// Join column definitions together
$columns = [];
foreach($columnArray as $n => $props)
{
$str = $this->getDriver()->quoteIdent($n);
$str .= isset($props['type']) ? " {$props['type']}" : "";
$str .= isset($props['constraint']) ? " {$props['constraint']}" : "";
$columns[] = $str;
}
// Generate the sql for the creation of the table
$sql = 'CREATE TABLE'.$existsStr.$this->getDriver()->quoteTable($name).' (';
$sql .= implode(', ', $columns);
$sql .= ')';
return $sql;
} | [
"public",
"function",
"createTable",
"(",
"$",
"name",
",",
"$",
"fields",
",",
"array",
"$",
"constraints",
"=",
"[",
"]",
",",
"$",
"ifNotExists",
"=",
"TRUE",
")",
"{",
"$",
"existsStr",
"=",
"$",
"ifNotExists",
"?",
"' IF NOT EXISTS '",
":",
"' '",
... | Convenience public function to generate sql for creating a db table
@param string $name
@param array $fields
@param array $constraints
@param bool $ifNotExists
@return string | [
"Convenience",
"public",
"function",
"to",
"generate",
"sql",
"for",
"creating",
"a",
"db",
"table"
] | 172eb3f6ebdfb7295b42e32cc74bf37c3ebd7650 | https://github.com/aviat4ion/Query/blob/172eb3f6ebdfb7295b42e32cc74bf37c3ebd7650/src/Drivers/AbstractUtil.php#L60-L92 | train |
usemarkup/addressing | Renderer/SerializableAddressAdapter.php | SerializableAddressAdapter.getStreetAddressLine | public function getStreetAddressLine($lineNumber)
{
$lines = $this->getStreetAddressLines();
if (!isset($lines[$lineNumber-1])) {
return null;
}
return $lines[$lineNumber-1];
} | php | public function getStreetAddressLine($lineNumber)
{
$lines = $this->getStreetAddressLines();
if (!isset($lines[$lineNumber-1])) {
return null;
}
return $lines[$lineNumber-1];
} | [
"public",
"function",
"getStreetAddressLine",
"(",
"$",
"lineNumber",
")",
"{",
"$",
"lines",
"=",
"$",
"this",
"->",
"getStreetAddressLines",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"lines",
"[",
"$",
"lineNumber",
"-",
"1",
"]",
")",
")",
... | Gets the numbered address line, counting from one. If there is no address line for provided number, return null.
@param int $lineNumber
@return string|null | [
"Gets",
"the",
"numbered",
"address",
"line",
"counting",
"from",
"one",
".",
"If",
"there",
"is",
"no",
"address",
"line",
"for",
"provided",
"number",
"return",
"null",
"."
] | facd8fe58ba187b92e06490d8a6416999fb8f711 | https://github.com/usemarkup/addressing/blob/facd8fe58ba187b92e06490d8a6416999fb8f711/Renderer/SerializableAddressAdapter.php#L59-L67 | train |
usemarkup/addressing | Iso/Iso3166Converter.php | Iso3166Converter.convertAlpha2ToAlpha3 | public function convertAlpha2ToAlpha3($alpha2)
{
if (!isset(self::$codes[$alpha2])) {
return null;
}
return self::$codes[$alpha2];
} | php | public function convertAlpha2ToAlpha3($alpha2)
{
if (!isset(self::$codes[$alpha2])) {
return null;
}
return self::$codes[$alpha2];
} | [
"public",
"function",
"convertAlpha2ToAlpha3",
"(",
"$",
"alpha2",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"codes",
"[",
"$",
"alpha2",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"self",
"::",
"$",
"codes",
"[",
"$... | Gets the ISO3166 alpha-3 code that corresponds to the provided alpha-2 code.
@param string $alpha2
@return string|null | [
"Gets",
"the",
"ISO3166",
"alpha",
"-",
"3",
"code",
"that",
"corresponds",
"to",
"the",
"provided",
"alpha",
"-",
"2",
"code",
"."
] | facd8fe58ba187b92e06490d8a6416999fb8f711 | https://github.com/usemarkup/addressing/blob/facd8fe58ba187b92e06490d8a6416999fb8f711/Iso/Iso3166Converter.php#L268-L275 | train |
usemarkup/addressing | Iso/Iso3166Converter.php | Iso3166Converter.convertAlpha3ToAlpha2 | public function convertAlpha3ToAlpha2($alpha3)
{
$alpha2 = array_search($alpha3, self::$codes);
if (false === $alpha2) {
return null;
}
return (string) $alpha2;
} | php | public function convertAlpha3ToAlpha2($alpha3)
{
$alpha2 = array_search($alpha3, self::$codes);
if (false === $alpha2) {
return null;
}
return (string) $alpha2;
} | [
"public",
"function",
"convertAlpha3ToAlpha2",
"(",
"$",
"alpha3",
")",
"{",
"$",
"alpha2",
"=",
"array_search",
"(",
"$",
"alpha3",
",",
"self",
"::",
"$",
"codes",
")",
";",
"if",
"(",
"false",
"===",
"$",
"alpha2",
")",
"{",
"return",
"null",
";",
... | Gets the ISO3166 alpha-2 code that corresponds to the provided alpha-3 code.
@param string $alpha3
@return string|null | [
"Gets",
"the",
"ISO3166",
"alpha",
"-",
"2",
"code",
"that",
"corresponds",
"to",
"the",
"provided",
"alpha",
"-",
"3",
"code",
"."
] | facd8fe58ba187b92e06490d8a6416999fb8f711 | https://github.com/usemarkup/addressing/blob/facd8fe58ba187b92e06490d8a6416999fb8f711/Iso/Iso3166Converter.php#L283-L291 | train |
usemarkup/addressing | Canonicalizer/PostalCodeCanonicalizer.php | PostalCodeCanonicalizer.canonicalizeForCountry | public function canonicalizeForCountry($postalCode, $country)
{
switch ($country) {
case 'GB':
case 'IM':
case 'JE':
case 'GG':
case 'GI':
$ukCanonicalizer = new UnitedKingdomPostcodeCanonicalizer();
return $ukCanonicalizer->canonicalize($postalCode);
case 'SE':
$seCanonicalizer = new SwedenPostalCodeCanonicalizer();
return $seCanonicalizer->canonicalize($postalCode);
case 'FI':
case 'IT':
case 'ES':
$fiveDigitCanonicalizer = new FixedConsecutiveDigitPostalCodeCanonicalizer(5);
return $fiveDigitCanonicalizer->canonicalize($postalCode);
case 'PT':
$variant = new CombinedPostalCodeVariant([new PostalCodeVariant([4]), new PostalCodeVariant([4, 3], '-')]);
return $variant->format($postalCode);
case 'NL':
$nlCanonicalizer = new NetherlandsPostalCodeCanonicalizer();
return $nlCanonicalizer->canonicalize($postalCode);
case 'NO':
case 'DK':
$fourDigitCanonicalizer = new FixedConsecutiveDigitPostalCodeCanonicalizer(4);
return $fourDigitCanonicalizer->canonicalize($postalCode);
break;
case 'CA':
$caCanonicalizer = new CanadaPostalCodeCanonicalizer();
return $caCanonicalizer->canonicalize($postalCode);
default:
return $postalCode;
}
} | php | public function canonicalizeForCountry($postalCode, $country)
{
switch ($country) {
case 'GB':
case 'IM':
case 'JE':
case 'GG':
case 'GI':
$ukCanonicalizer = new UnitedKingdomPostcodeCanonicalizer();
return $ukCanonicalizer->canonicalize($postalCode);
case 'SE':
$seCanonicalizer = new SwedenPostalCodeCanonicalizer();
return $seCanonicalizer->canonicalize($postalCode);
case 'FI':
case 'IT':
case 'ES':
$fiveDigitCanonicalizer = new FixedConsecutiveDigitPostalCodeCanonicalizer(5);
return $fiveDigitCanonicalizer->canonicalize($postalCode);
case 'PT':
$variant = new CombinedPostalCodeVariant([new PostalCodeVariant([4]), new PostalCodeVariant([4, 3], '-')]);
return $variant->format($postalCode);
case 'NL':
$nlCanonicalizer = new NetherlandsPostalCodeCanonicalizer();
return $nlCanonicalizer->canonicalize($postalCode);
case 'NO':
case 'DK':
$fourDigitCanonicalizer = new FixedConsecutiveDigitPostalCodeCanonicalizer(4);
return $fourDigitCanonicalizer->canonicalize($postalCode);
break;
case 'CA':
$caCanonicalizer = new CanadaPostalCodeCanonicalizer();
return $caCanonicalizer->canonicalize($postalCode);
default:
return $postalCode;
}
} | [
"public",
"function",
"canonicalizeForCountry",
"(",
"$",
"postalCode",
",",
"$",
"country",
")",
"{",
"switch",
"(",
"$",
"country",
")",
"{",
"case",
"'GB'",
":",
"case",
"'IM'",
":",
"case",
"'JE'",
":",
"case",
"'GG'",
":",
"case",
"'GI'",
":",
"$"... | Canonicalizes a provided postal code for a given country if it is possible to do so, otherwise returns the postal code unmodified.
@param string $postalCode A postal code string.
@param string $country The ISO3166 alpha-2 representation of a country.
@return string | [
"Canonicalizes",
"a",
"provided",
"postal",
"code",
"for",
"a",
"given",
"country",
"if",
"it",
"is",
"possible",
"to",
"do",
"so",
"otherwise",
"returns",
"the",
"postal",
"code",
"unmodified",
"."
] | facd8fe58ba187b92e06490d8a6416999fb8f711 | https://github.com/usemarkup/addressing/blob/facd8fe58ba187b92e06490d8a6416999fb8f711/Canonicalizer/PostalCodeCanonicalizer.php#L18-L66 | train |
usemarkup/addressing | Canonicalizer/CanonicalizeAddressDecorator.php | CanonicalizeAddressDecorator.getPostalCode | public function getPostalCode()
{
$canonicalizer = new PostalCodeCanonicalizer();
return $canonicalizer->canonicalizeForCountry($this->address->getPostalCode(), $this->address->getCountry());
} | php | public function getPostalCode()
{
$canonicalizer = new PostalCodeCanonicalizer();
return $canonicalizer->canonicalizeForCountry($this->address->getPostalCode(), $this->address->getCountry());
} | [
"public",
"function",
"getPostalCode",
"(",
")",
"{",
"$",
"canonicalizer",
"=",
"new",
"PostalCodeCanonicalizer",
"(",
")",
";",
"return",
"$",
"canonicalizer",
"->",
"canonicalizeForCountry",
"(",
"$",
"this",
"->",
"address",
"->",
"getPostalCode",
"(",
")",
... | Gets the postal code for this address.
If no postal code is indicated as part of the address information, returns an empty string.
@return string | [
"Gets",
"the",
"postal",
"code",
"for",
"this",
"address",
".",
"If",
"no",
"postal",
"code",
"is",
"indicated",
"as",
"part",
"of",
"the",
"address",
"information",
"returns",
"an",
"empty",
"string",
"."
] | facd8fe58ba187b92e06490d8a6416999fb8f711 | https://github.com/usemarkup/addressing/blob/facd8fe58ba187b92e06490d8a6416999fb8f711/Canonicalizer/CanonicalizeAddressDecorator.php#L93-L98 | train |
usemarkup/addressing | Provider/CountryNameProvider.php | CountryNameProvider.loadCountriesForLocale | private function loadCountriesForLocale($locale)
{
//load from Symfony Intl component
$regionBundle = Intl::getRegionBundle();
$this->displayCountries[$locale] = $regionBundle->getCountryNames($locale);
} | php | private function loadCountriesForLocale($locale)
{
//load from Symfony Intl component
$regionBundle = Intl::getRegionBundle();
$this->displayCountries[$locale] = $regionBundle->getCountryNames($locale);
} | [
"private",
"function",
"loadCountriesForLocale",
"(",
"$",
"locale",
")",
"{",
"//load from Symfony Intl component",
"$",
"regionBundle",
"=",
"Intl",
"::",
"getRegionBundle",
"(",
")",
";",
"$",
"this",
"->",
"displayCountries",
"[",
"$",
"locale",
"]",
"=",
"$... | Loads countries in.
@param string $locale | [
"Loads",
"countries",
"in",
"."
] | facd8fe58ba187b92e06490d8a6416999fb8f711 | https://github.com/usemarkup/addressing/blob/facd8fe58ba187b92e06490d8a6416999fb8f711/Provider/CountryNameProvider.php#L77-L82 | train |
usemarkup/addressing | Provider/IntlAddressHandlebarsTemplateProvider.php | IntlAddressHandlebarsTemplateProvider.getTemplateForCountry | public function getTemplateForCountry($country, $format, array $options = [])
{
return new HandlebarsTemplate($this->getRenderFunction(strtolower($country), $format));
} | php | public function getTemplateForCountry($country, $format, array $options = [])
{
return new HandlebarsTemplate($this->getRenderFunction(strtolower($country), $format));
} | [
"public",
"function",
"getTemplateForCountry",
"(",
"$",
"country",
",",
"$",
"format",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"return",
"new",
"HandlebarsTemplate",
"(",
"$",
"this",
"->",
"getRenderFunction",
"(",
"strtolower",
"(",
"$",
... | Gets a template that pertains to the provided country.
@param string $country The ISO3166 alpha-2 value for a country (case-insensitive).
@param string $format The address format being used.
@param array $options
@return TemplateInterface | [
"Gets",
"a",
"template",
"that",
"pertains",
"to",
"the",
"provided",
"country",
"."
] | facd8fe58ba187b92e06490d8a6416999fb8f711 | https://github.com/usemarkup/addressing/blob/facd8fe58ba187b92e06490d8a6416999fb8f711/Provider/IntlAddressHandlebarsTemplateProvider.php#L53-L56 | train |
usemarkup/addressing | Geography.php | Geography.checkInEu | public function checkInEu($addressOrCountry)
{
$country = (is_object($addressOrCountry) && method_exists($addressOrCountry, 'getCountry')) ? $addressOrCountry->getCountry() : $addressOrCountry;
if (!is_string($country)) {
return false;
}
return in_array($country, self::$euCountries);
} | php | public function checkInEu($addressOrCountry)
{
$country = (is_object($addressOrCountry) && method_exists($addressOrCountry, 'getCountry')) ? $addressOrCountry->getCountry() : $addressOrCountry;
if (!is_string($country)) {
return false;
}
return in_array($country, self::$euCountries);
} | [
"public",
"function",
"checkInEu",
"(",
"$",
"addressOrCountry",
")",
"{",
"$",
"country",
"=",
"(",
"is_object",
"(",
"$",
"addressOrCountry",
")",
"&&",
"method_exists",
"(",
"$",
"addressOrCountry",
",",
"'getCountry'",
")",
")",
"?",
"$",
"addressOrCountry... | Gets whether the country or address are in the EU.
@param mixed $addressOrCountry
@return bool | [
"Gets",
"whether",
"the",
"country",
"or",
"address",
"are",
"in",
"the",
"EU",
"."
] | facd8fe58ba187b92e06490d8a6416999fb8f711 | https://github.com/usemarkup/addressing/blob/facd8fe58ba187b92e06490d8a6416999fb8f711/Geography.php#L104-L112 | train |
usemarkup/addressing | Geography.php | Geography.getUsStateAbbreviationForName | public function getUsStateAbbreviationForName($name)
{
if (!in_array($name, self::$usStates)) {
return null;
}
return (string) array_search($name, self::$usStates);
} | php | public function getUsStateAbbreviationForName($name)
{
if (!in_array($name, self::$usStates)) {
return null;
}
return (string) array_search($name, self::$usStates);
} | [
"public",
"function",
"getUsStateAbbreviationForName",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"name",
",",
"self",
"::",
"$",
"usStates",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"(",
"string",
")",
"array_search",
... | Gets the abbreviation for the provided state name, if this can be found - otherwise returns null.
@param string $name
@return string|null | [
"Gets",
"the",
"abbreviation",
"for",
"the",
"provided",
"state",
"name",
"if",
"this",
"can",
"be",
"found",
"-",
"otherwise",
"returns",
"null",
"."
] | facd8fe58ba187b92e06490d8a6416999fb8f711 | https://github.com/usemarkup/addressing/blob/facd8fe58ba187b92e06490d8a6416999fb8f711/Geography.php#L120-L127 | train |
epfremmer/swagger-php | src/Parser/SwaggerParser.php | SwaggerParser.getVersion | public function getVersion()
{
if (!array_key_exists(self::VERSION_KEY, $this->data)) {
$this->data[self::VERSION_KEY] = self::MINIMUM_VERSION;
}
if (!version_compare($this->data[self::VERSION_KEY], SwaggerParser::MINIMUM_VERSION, '>=')) {
throw new InvalidVersionException($this->data[self::VERSION_KEY]);
}
return $this->data[self::VERSION_KEY];
} | php | public function getVersion()
{
if (!array_key_exists(self::VERSION_KEY, $this->data)) {
$this->data[self::VERSION_KEY] = self::MINIMUM_VERSION;
}
if (!version_compare($this->data[self::VERSION_KEY], SwaggerParser::MINIMUM_VERSION, '>=')) {
throw new InvalidVersionException($this->data[self::VERSION_KEY]);
}
return $this->data[self::VERSION_KEY];
} | [
"public",
"function",
"getVersion",
"(",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"self",
"::",
"VERSION_KEY",
",",
"$",
"this",
"->",
"data",
")",
")",
"{",
"$",
"this",
"->",
"data",
"[",
"self",
"::",
"VERSION_KEY",
"]",
"=",
"self",
"::... | Return swagger version
@return string | [
"Return",
"swagger",
"version"
] | 9915e610f8da8b1d50895941498a5c2904e96aa3 | https://github.com/epfremmer/swagger-php/blob/9915e610f8da8b1d50895941498a5c2904e96aa3/src/Parser/SwaggerParser.php#L35-L46 | train |
epfremmer/swagger-php | src/Parser/FileParser.php | FileParser.parse | protected function parse($file)
{
$data = json_decode(file_get_contents($file), true) ?: Yaml::parse(file_get_contents($file));
return $data;
} | php | protected function parse($file)
{
$data = json_decode(file_get_contents($file), true) ?: Yaml::parse(file_get_contents($file));
return $data;
} | [
"protected",
"function",
"parse",
"(",
"$",
"file",
")",
"{",
"$",
"data",
"=",
"json_decode",
"(",
"file_get_contents",
"(",
"$",
"file",
")",
",",
"true",
")",
"?",
":",
"Yaml",
"::",
"parse",
"(",
"file_get_contents",
"(",
"$",
"file",
")",
")",
"... | Parse the swagger file
@param string $file - fully qualified file path
@return array | [
"Parse",
"the",
"swagger",
"file"
] | 9915e610f8da8b1d50895941498a5c2904e96aa3 | https://github.com/epfremmer/swagger-php/blob/9915e610f8da8b1d50895941498a5c2904e96aa3/src/Parser/FileParser.php#L34-L39 | train |
epfremmer/swagger-php | src/Annotations/Discriminator.php | Discriminator.getClass | public function getClass(array $data)
{
if (!array_key_exists($this->field, $data)) {
return $this->map[$this->getDefault()];
}
$type = $data[$this->field];
// fallback to default if type not found in map
if (!isset($this->map[$type])) {
$type = $this->getDefault();
}
return $this->map[$type];
} | php | public function getClass(array $data)
{
if (!array_key_exists($this->field, $data)) {
return $this->map[$this->getDefault()];
}
$type = $data[$this->field];
// fallback to default if type not found in map
if (!isset($this->map[$type])) {
$type = $this->getDefault();
}
return $this->map[$type];
} | [
"public",
"function",
"getClass",
"(",
"array",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"this",
"->",
"field",
",",
"$",
"data",
")",
")",
"{",
"return",
"$",
"this",
"->",
"map",
"[",
"$",
"this",
"->",
"getDefault",
"... | Return the correct mapped class
@param array $data
@return mixed | [
"Return",
"the",
"correct",
"mapped",
"class"
] | 9915e610f8da8b1d50895941498a5c2904e96aa3 | https://github.com/epfremmer/swagger-php/blob/9915e610f8da8b1d50895941498a5c2904e96aa3/src/Annotations/Discriminator.php#L58-L72 | train |
epfremmer/swagger-php | src/Factory/SwaggerFactory.php | SwaggerFactory.serialize | public function serialize(Swagger $swagger)
{
$context = new SerializationContext();
$context->setVersion(
$swagger->getVersion()
);
return $this->serializer->serialize($swagger, 'json', $context);
} | php | public function serialize(Swagger $swagger)
{
$context = new SerializationContext();
$context->setVersion(
$swagger->getVersion()
);
return $this->serializer->serialize($swagger, 'json', $context);
} | [
"public",
"function",
"serialize",
"(",
"Swagger",
"$",
"swagger",
")",
"{",
"$",
"context",
"=",
"new",
"SerializationContext",
"(",
")",
";",
"$",
"context",
"->",
"setVersion",
"(",
"$",
"swagger",
"->",
"getVersion",
"(",
")",
")",
";",
"return",
"$"... | Return serialized Swagger document
@param Swagger $swagger
@return string | [
"Return",
"serialized",
"Swagger",
"document"
] | 9915e610f8da8b1d50895941498a5c2904e96aa3 | https://github.com/epfremmer/swagger-php/blob/9915e610f8da8b1d50895941498a5c2904e96aa3/src/Factory/SwaggerFactory.php#L89-L98 | train |
epfremmer/swagger-php | src/Factory/SwaggerFactory.php | SwaggerFactory.buildFromParser | private function buildFromParser(SwaggerParser $parser)
{
$context = new DeserializationContext();
$context->setVersion(
$parser->getVersion()
);
return $this->serializer->deserialize($parser, Swagger::class, 'json', $context);
} | php | private function buildFromParser(SwaggerParser $parser)
{
$context = new DeserializationContext();
$context->setVersion(
$parser->getVersion()
);
return $this->serializer->deserialize($parser, Swagger::class, 'json', $context);
} | [
"private",
"function",
"buildFromParser",
"(",
"SwaggerParser",
"$",
"parser",
")",
"{",
"$",
"context",
"=",
"new",
"DeserializationContext",
"(",
")",
";",
"$",
"context",
"->",
"setVersion",
"(",
"$",
"parser",
"->",
"getVersion",
"(",
")",
")",
";",
"r... | Return de-serialized Swagger result
@param SwaggerParser $parser
@return Swagger
@throws \LogicException | [
"Return",
"de",
"-",
"serialized",
"Swagger",
"result"
] | 9915e610f8da8b1d50895941498a5c2904e96aa3 | https://github.com/epfremmer/swagger-php/blob/9915e610f8da8b1d50895941498a5c2904e96aa3/src/Factory/SwaggerFactory.php#L107-L116 | train |
epfremmer/swagger-php | src/Listener/SerializationSubscriber.php | SerializationSubscriber.onPreDeserialize | public function onPreDeserialize(PreDeserializeEvent $event)
{
$class = $event->getType()['name'];
if (!class_exists($class)) {
return; // skip custom JMS types
}
$data = $event->getData();
$object = new \ReflectionClass($class);
$discriminator = $this->reader->getClassAnnotation($object, Discriminator::class);
if ($discriminator) {
$event->setType($discriminator->getClass($data));
}
} | php | public function onPreDeserialize(PreDeserializeEvent $event)
{
$class = $event->getType()['name'];
if (!class_exists($class)) {
return; // skip custom JMS types
}
$data = $event->getData();
$object = new \ReflectionClass($class);
$discriminator = $this->reader->getClassAnnotation($object, Discriminator::class);
if ($discriminator) {
$event->setType($discriminator->getClass($data));
}
} | [
"public",
"function",
"onPreDeserialize",
"(",
"PreDeserializeEvent",
"$",
"event",
")",
"{",
"$",
"class",
"=",
"$",
"event",
"->",
"getType",
"(",
")",
"[",
"'name'",
"]",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"return... | Checks for the existence of a discriminator annotation and sets the
corresponding mapped deserialization class
@param PreDeserializeEvent $event | [
"Checks",
"for",
"the",
"existence",
"of",
"a",
"discriminator",
"annotation",
"and",
"sets",
"the",
"corresponding",
"mapped",
"deserialization",
"class"
] | 9915e610f8da8b1d50895941498a5c2904e96aa3 | https://github.com/epfremmer/swagger-php/blob/9915e610f8da8b1d50895941498a5c2904e96aa3/src/Listener/SerializationSubscriber.php#L89-L105 | train |
epfremmer/swagger-php | src/Listener/SerializationSubscriber.php | SerializationSubscriber.onParameterPreDeserialize | public function onParameterPreDeserialize(PreDeserializeEvent $event)
{
$data = $event->getData();
if (array_key_exists('$ref', $data)) {
$event->setType(RefParameter::class);
return;
}
$data['class'] = $data['in'];
if (array_key_exists('type', $data)) {
$data['class'] = sprintf('%s.%s', $data['in'], $data['type']);
}
$event->setData($data);
} | php | public function onParameterPreDeserialize(PreDeserializeEvent $event)
{
$data = $event->getData();
if (array_key_exists('$ref', $data)) {
$event->setType(RefParameter::class);
return;
}
$data['class'] = $data['in'];
if (array_key_exists('type', $data)) {
$data['class'] = sprintf('%s.%s', $data['in'], $data['type']);
}
$event->setData($data);
} | [
"public",
"function",
"onParameterPreDeserialize",
"(",
"PreDeserializeEvent",
"$",
"event",
")",
"{",
"$",
"data",
"=",
"$",
"event",
"->",
"getData",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'$ref'",
",",
"$",
"data",
")",
")",
"{",
"$",
"ev... | Set custom composite discriminator key based on multiple parameter fields
before deserialization to ensure proper discrimination mapping
@param PreDeserializeEvent $event | [
"Set",
"custom",
"composite",
"discriminator",
"key",
"based",
"on",
"multiple",
"parameter",
"fields",
"before",
"deserialization",
"to",
"ensure",
"proper",
"discrimination",
"mapping"
] | 9915e610f8da8b1d50895941498a5c2904e96aa3 | https://github.com/epfremmer/swagger-php/blob/9915e610f8da8b1d50895941498a5c2904e96aa3/src/Listener/SerializationSubscriber.php#L135-L151 | train |
KnpLabs/mailjet-api-php | src/Mailjet/Api/Client.php | Client.post | public function post($apiQuery, $options = array())
{
if (!RequestApi::isPost($apiQuery)) {
throw new \InvalidArgumentException('Unsupported API query for POST method: ' . $apiQuery);
}
$request = $this->getApi()->post($apiQuery, null, $options);
$this->prepareRequest($request, $options);
$response = $request->send();
return $this->processResponse($response);
} | php | public function post($apiQuery, $options = array())
{
if (!RequestApi::isPost($apiQuery)) {
throw new \InvalidArgumentException('Unsupported API query for POST method: ' . $apiQuery);
}
$request = $this->getApi()->post($apiQuery, null, $options);
$this->prepareRequest($request, $options);
$response = $request->send();
return $this->processResponse($response);
} | [
"public",
"function",
"post",
"(",
"$",
"apiQuery",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"RequestApi",
"::",
"isPost",
"(",
"$",
"apiQuery",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Unsup... | Method for issuing low level API POST requests
@see Client::get() | [
"Method",
"for",
"issuing",
"low",
"level",
"API",
"POST",
"requests"
] | 042968e4c516845248323c8db367cdb033329ae4 | https://github.com/KnpLabs/mailjet-api-php/blob/042968e4c516845248323c8db367cdb033329ae4/src/Mailjet/Api/Client.php#L64-L77 | train |
M6Web/ElasticsearchBundle | src/M6Web/Bundle/ElasticsearchBundle/Elasticsearch/ConnectionPool/StaticAliveNoPingConnectionPool.php | StaticAliveNoPingConnectionPool.readyToRevive | protected function readyToRevive(Connection $connection)
{
$timeout = min(
$this->pingTimeout * pow(2, $connection->getPingFailures()),
$this->maxPingTimeout
);
if ($connection->getLastPing() + $timeout < time()) {
return true;
} else {
return false;
}
} | php | protected function readyToRevive(Connection $connection)
{
$timeout = min(
$this->pingTimeout * pow(2, $connection->getPingFailures()),
$this->maxPingTimeout
);
if ($connection->getLastPing() + $timeout < time()) {
return true;
} else {
return false;
}
} | [
"protected",
"function",
"readyToRevive",
"(",
"Connection",
"$",
"connection",
")",
"{",
"$",
"timeout",
"=",
"min",
"(",
"$",
"this",
"->",
"pingTimeout",
"*",
"pow",
"(",
"2",
",",
"$",
"connection",
"->",
"getPingFailures",
"(",
")",
")",
",",
"$",
... | > Same as parent private method.
@param Connection $connection
@return bool | [
">",
"Same",
"as",
"parent",
"private",
"method",
"."
] | 0f9bcba0bea85a359aa43bebbb777a5badf08b16 | https://github.com/M6Web/ElasticsearchBundle/blob/0f9bcba0bea85a359aa43bebbb777a5badf08b16/src/M6Web/Bundle/ElasticsearchBundle/Elasticsearch/ConnectionPool/StaticAliveNoPingConnectionPool.php#L90-L102 | train |
M6Web/ElasticsearchBundle | src/M6Web/Bundle/ElasticsearchBundle/Handler/EventHandler.php | EventHandler.extractTookFromResponse | protected function extractTookFromResponse(array $response)
{
if (is_null($response['body'])) {
return null;
}
$content = stream_get_contents($response['body']);
rewind($response['body']);
if (preg_match('/\"took\":(\d+)/', $content, $matches)) {
return (int) $matches[1];
}
return null;
} | php | protected function extractTookFromResponse(array $response)
{
if (is_null($response['body'])) {
return null;
}
$content = stream_get_contents($response['body']);
rewind($response['body']);
if (preg_match('/\"took\":(\d+)/', $content, $matches)) {
return (int) $matches[1];
}
return null;
} | [
"protected",
"function",
"extractTookFromResponse",
"(",
"array",
"$",
"response",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"response",
"[",
"'body'",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"content",
"=",
"stream_get_contents",
"(",
"$",
... | Extract took from response
@param array $response
@return int|null | [
"Extract",
"took",
"from",
"response"
] | 0f9bcba0bea85a359aa43bebbb777a5badf08b16 | https://github.com/M6Web/ElasticsearchBundle/blob/0f9bcba0bea85a359aa43bebbb777a5badf08b16/src/M6Web/Bundle/ElasticsearchBundle/Handler/EventHandler.php#L90-L103 | train |
M6Web/ElasticsearchBundle | src/M6Web/Bundle/ElasticsearchBundle/DependencyInjection/M6WebElasticsearchExtension.php | M6WebElasticsearchExtension.createElasticsearchClient | protected function createElasticsearchClient(ContainerBuilder $container, $name, $config)
{
$definitionId = 'm6web_elasticsearch.client.'.$name;
$handlerId = $this->createHandler($container, $config, $definitionId);
$clientConfig = [
'hosts' => $config['hosts'],
'handler' => new Reference($handlerId),
];
if (isset($config['retries'])) {
$clientConfig['retries'] = $config['retries'];
}
if (isset($config['logger'])) {
$clientConfig['logger'] = new Reference($config['logger']);
}
if (!empty($config['connectionPoolClass'])) {
$clientConfig['connectionPool'] = $config['connectionPoolClass'];
}
if (!empty($config['selectorClass'])) {
$clientConfig['selector'] = $config['selectorClass'];
}
if (!empty($config['connectionParams'])) {
$clientConfig['connectionParams'] = $config['connectionParams'];
}
$definition = (new Definition($config['client_class']))
->setArguments([$clientConfig]);
$this->setFactoryToDefinition($config['clientBuilderClass'], 'fromConfig', $definition);
$container->setDefinition($definitionId, $definition);
if ($container->getParameter('kernel.debug')) {
$this->createDataCollector($container);
}
} | php | protected function createElasticsearchClient(ContainerBuilder $container, $name, $config)
{
$definitionId = 'm6web_elasticsearch.client.'.$name;
$handlerId = $this->createHandler($container, $config, $definitionId);
$clientConfig = [
'hosts' => $config['hosts'],
'handler' => new Reference($handlerId),
];
if (isset($config['retries'])) {
$clientConfig['retries'] = $config['retries'];
}
if (isset($config['logger'])) {
$clientConfig['logger'] = new Reference($config['logger']);
}
if (!empty($config['connectionPoolClass'])) {
$clientConfig['connectionPool'] = $config['connectionPoolClass'];
}
if (!empty($config['selectorClass'])) {
$clientConfig['selector'] = $config['selectorClass'];
}
if (!empty($config['connectionParams'])) {
$clientConfig['connectionParams'] = $config['connectionParams'];
}
$definition = (new Definition($config['client_class']))
->setArguments([$clientConfig]);
$this->setFactoryToDefinition($config['clientBuilderClass'], 'fromConfig', $definition);
$container->setDefinition($definitionId, $definition);
if ($container->getParameter('kernel.debug')) {
$this->createDataCollector($container);
}
} | [
"protected",
"function",
"createElasticsearchClient",
"(",
"ContainerBuilder",
"$",
"container",
",",
"$",
"name",
",",
"$",
"config",
")",
"{",
"$",
"definitionId",
"=",
"'m6web_elasticsearch.client.'",
".",
"$",
"name",
";",
"$",
"handlerId",
"=",
"$",
"this",... | Add a new Elasticsearch client definition in the container
@param ContainerBuilder $container
@param string $name
@param array $config | [
"Add",
"a",
"new",
"Elasticsearch",
"client",
"definition",
"in",
"the",
"container"
] | 0f9bcba0bea85a359aa43bebbb777a5badf08b16 | https://github.com/M6Web/ElasticsearchBundle/blob/0f9bcba0bea85a359aa43bebbb777a5badf08b16/src/M6Web/Bundle/ElasticsearchBundle/DependencyInjection/M6WebElasticsearchExtension.php#L59-L99 | train |
M6Web/ElasticsearchBundle | src/M6Web/Bundle/ElasticsearchBundle/DependencyInjection/M6WebElasticsearchExtension.php | M6WebElasticsearchExtension.createHandler | protected function createHandler(ContainerBuilder $container, array $config, $definitionId)
{
// cURL handler
$singleHandler = (new Definition('GuzzleHttp\Ring\Client\CurlHandler'))
->setPublic(false);
$this->setFactoryToDefinition('Elasticsearch\ClientBuilder', 'defaultHandler', $singleHandler);
$singleHandlerId = $definitionId.'.single_handler';
$container->setDefinition($singleHandlerId, $singleHandler);
// Headers handler
$headersHandler = (new Definition('M6Web\Bundle\ElasticsearchBundle\Handler\HeadersHandler'))
->setPublic(false)
->setArguments([new Reference($singleHandlerId)]);
if (isset($config['headers'])) {
foreach ($config['headers'] as $key => $value) {
$headersHandler->addMethodCall('setHeader', [$key, $value]);
}
}
$headersHandlerId = $definitionId.'.headers_handler';
$container->setDefinition($headersHandlerId, $headersHandler);
// Event handler
$eventHandler = (new Definition('M6Web\Bundle\ElasticsearchBundle\Handler\EventHandler'))
->setPublic(false)
->setArguments([new Reference('event_dispatcher'), new Reference($headersHandlerId)]);
$eventHandlerId = $definitionId.'.event_handler';
$container->setDefinition($eventHandlerId, $eventHandler);
return $eventHandlerId;
} | php | protected function createHandler(ContainerBuilder $container, array $config, $definitionId)
{
// cURL handler
$singleHandler = (new Definition('GuzzleHttp\Ring\Client\CurlHandler'))
->setPublic(false);
$this->setFactoryToDefinition('Elasticsearch\ClientBuilder', 'defaultHandler', $singleHandler);
$singleHandlerId = $definitionId.'.single_handler';
$container->setDefinition($singleHandlerId, $singleHandler);
// Headers handler
$headersHandler = (new Definition('M6Web\Bundle\ElasticsearchBundle\Handler\HeadersHandler'))
->setPublic(false)
->setArguments([new Reference($singleHandlerId)]);
if (isset($config['headers'])) {
foreach ($config['headers'] as $key => $value) {
$headersHandler->addMethodCall('setHeader', [$key, $value]);
}
}
$headersHandlerId = $definitionId.'.headers_handler';
$container->setDefinition($headersHandlerId, $headersHandler);
// Event handler
$eventHandler = (new Definition('M6Web\Bundle\ElasticsearchBundle\Handler\EventHandler'))
->setPublic(false)
->setArguments([new Reference('event_dispatcher'), new Reference($headersHandlerId)]);
$eventHandlerId = $definitionId.'.event_handler';
$container->setDefinition($eventHandlerId, $eventHandler);
return $eventHandlerId;
} | [
"protected",
"function",
"createHandler",
"(",
"ContainerBuilder",
"$",
"container",
",",
"array",
"$",
"config",
",",
"$",
"definitionId",
")",
"{",
"// cURL handler",
"$",
"singleHandler",
"=",
"(",
"new",
"Definition",
"(",
"'GuzzleHttp\\Ring\\Client\\CurlHandler'"... | Create request handler
@param ContainerBuilder $container
@param array $config
@param string $definitionId
@return string | [
"Create",
"request",
"handler"
] | 0f9bcba0bea85a359aa43bebbb777a5badf08b16 | https://github.com/M6Web/ElasticsearchBundle/blob/0f9bcba0bea85a359aa43bebbb777a5badf08b16/src/M6Web/Bundle/ElasticsearchBundle/DependencyInjection/M6WebElasticsearchExtension.php#L110-L141 | train |
mpociot/reflection-docblock | src/Mpociot/Reflection/DocBlock/Type/Collection.php | Collection.add | public function add($type)
{
if (!is_string($type)) {
throw new \InvalidArgumentException(
'A type should be represented by a string, received: '
.var_export($type, true)
);
}
// separate the type by the OR operator
$type_parts = explode(self::OPERATOR_OR, $type);
foreach ($type_parts as $part) {
$expanded_type = $this->expand($part);
if ($expanded_type) {
$this[] = $expanded_type;
}
}
} | php | public function add($type)
{
if (!is_string($type)) {
throw new \InvalidArgumentException(
'A type should be represented by a string, received: '
.var_export($type, true)
);
}
// separate the type by the OR operator
$type_parts = explode(self::OPERATOR_OR, $type);
foreach ($type_parts as $part) {
$expanded_type = $this->expand($part);
if ($expanded_type) {
$this[] = $expanded_type;
}
}
} | [
"public",
"function",
"add",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"type",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'A type should be represented by a string, received: '",
".",
"var_export",
"(",
"$",
... | Adds a new type to the collection and expands it if it contains a
relative namespace.
If a class in the type contains a relative namespace than this collection
will try to expand that into a FQCN.
@param string $type A 'Type' as defined in the phpDocumentor
documentation.
@throws \InvalidArgumentException if a non-string argument is passed.
@see http://phpdoc.org/docs/latest/for-users/types.html for the
definition of a type.
@return void | [
"Adds",
"a",
"new",
"type",
"to",
"the",
"collection",
"and",
"expands",
"it",
"if",
"it",
"contains",
"a",
"relative",
"namespace",
"."
] | c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587 | https://github.com/mpociot/reflection-docblock/blob/c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587/src/Mpociot/Reflection/DocBlock/Type/Collection.php#L99-L116 | train |
mpociot/reflection-docblock | src/Mpociot/Reflection/DocBlock/Serializer.php | Serializer.setLineLength | public function setLineLength($lineLength)
{
$this->lineLength = null === $lineLength ? null : (int)$lineLength;
return $this;
} | php | public function setLineLength($lineLength)
{
$this->lineLength = null === $lineLength ? null : (int)$lineLength;
return $this;
} | [
"public",
"function",
"setLineLength",
"(",
"$",
"lineLength",
")",
"{",
"$",
"this",
"->",
"lineLength",
"=",
"null",
"===",
"$",
"lineLength",
"?",
"null",
":",
"(",
"int",
")",
"$",
"lineLength",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the line length.
Sets the length of each line in the serialization. Content will be
wrapped within this limit.
@param int|null $lineLength The length of each line. NULL to disable line
wrapping altogether.
@return $this This serializer object. | [
"Sets",
"the",
"line",
"length",
"."
] | c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587 | https://github.com/mpociot/reflection-docblock/blob/c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587/src/Mpociot/Reflection/DocBlock/Serializer.php#L144-L148 | train |
mpociot/reflection-docblock | src/Mpociot/Reflection/DocBlock/Context.php | Context.setNamespaceAliases | public function setNamespaceAliases(array $namespace_aliases)
{
$this->namespace_aliases = array();
foreach ($namespace_aliases as $alias => $fqnn) {
$this->setNamespaceAlias($alias, $fqnn);
}
return $this;
} | php | public function setNamespaceAliases(array $namespace_aliases)
{
$this->namespace_aliases = array();
foreach ($namespace_aliases as $alias => $fqnn) {
$this->setNamespaceAlias($alias, $fqnn);
}
return $this;
} | [
"public",
"function",
"setNamespaceAliases",
"(",
"array",
"$",
"namespace_aliases",
")",
"{",
"$",
"this",
"->",
"namespace_aliases",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"namespace_aliases",
"as",
"$",
"alias",
"=>",
"$",
"fqnn",
")",
"{",
"... | Sets the namespace aliases, replacing all previous ones.
@param array $namespace_aliases List of namespace aliases => Fully
Qualified Namespace.
@return $this | [
"Sets",
"the",
"namespace",
"aliases",
"replacing",
"all",
"previous",
"ones",
"."
] | c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587 | https://github.com/mpociot/reflection-docblock/blob/c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587/src/Mpociot/Reflection/DocBlock/Context.php#L112-L119 | train |
mpociot/reflection-docblock | src/Mpociot/Reflection/DocBlock/Context.php | Context.setNamespaceAlias | public function setNamespaceAlias($alias, $fqnn)
{
$this->namespace_aliases[$alias] = '\\' . trim((string)$fqnn, '\\');
return $this;
} | php | public function setNamespaceAlias($alias, $fqnn)
{
$this->namespace_aliases[$alias] = '\\' . trim((string)$fqnn, '\\');
return $this;
} | [
"public",
"function",
"setNamespaceAlias",
"(",
"$",
"alias",
",",
"$",
"fqnn",
")",
"{",
"$",
"this",
"->",
"namespace_aliases",
"[",
"$",
"alias",
"]",
"=",
"'\\\\'",
".",
"trim",
"(",
"(",
"string",
")",
"$",
"fqnn",
",",
"'\\\\'",
")",
";",
"retu... | Adds a namespace alias to the context.
@param string $alias The alias name (the part after "as", or the last
part of the Fully Qualified Namespace Name) to add.
@param string $fqnn The Fully Qualified Namespace Name for this alias.
Any form of leading/trailing slashes are accepted, but what will be
stored is a name, prefixed with a slash, and no trailing slash.
@return $this | [
"Adds",
"a",
"namespace",
"alias",
"to",
"the",
"context",
"."
] | c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587 | https://github.com/mpociot/reflection-docblock/blob/c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587/src/Mpociot/Reflection/DocBlock/Context.php#L132-L136 | train |
mpociot/reflection-docblock | src/Mpociot/Reflection/DocBlock.php | DocBlock.getText | public function getText()
{
$short = $this->getShortDescription();
$long = $this->getLongDescription()->getContents();
if ($long) {
return "{$short}\n\n{$long}";
} else {
return $short;
}
} | php | public function getText()
{
$short = $this->getShortDescription();
$long = $this->getLongDescription()->getContents();
if ($long) {
return "{$short}\n\n{$long}";
} else {
return $short;
}
} | [
"public",
"function",
"getText",
"(",
")",
"{",
"$",
"short",
"=",
"$",
"this",
"->",
"getShortDescription",
"(",
")",
";",
"$",
"long",
"=",
"$",
"this",
"->",
"getLongDescription",
"(",
")",
"->",
"getContents",
"(",
")",
";",
"if",
"(",
"$",
"long... | Gets the text portion of the doc block.
Gets the text portion (short and long description combined) of the doc
block.
@return string The text portion of the doc block. | [
"Gets",
"the",
"text",
"portion",
"of",
"the",
"doc",
"block",
"."
] | c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587 | https://github.com/mpociot/reflection-docblock/blob/c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587/src/Mpociot/Reflection/DocBlock.php#L256-L266 | train |
mpociot/reflection-docblock | src/Mpociot/Reflection/DocBlock.php | DocBlock.setText | public function setText($comment)
{
list(,$short, $long) = $this->splitDocBlock($comment);
$this->short_description = $short;
$this->long_description = new DocBlock\Description($long, $this);
return $this;
} | php | public function setText($comment)
{
list(,$short, $long) = $this->splitDocBlock($comment);
$this->short_description = $short;
$this->long_description = new DocBlock\Description($long, $this);
return $this;
} | [
"public",
"function",
"setText",
"(",
"$",
"comment",
")",
"{",
"list",
"(",
",",
"$",
"short",
",",
"$",
"long",
")",
"=",
"$",
"this",
"->",
"splitDocBlock",
"(",
"$",
"comment",
")",
";",
"$",
"this",
"->",
"short_description",
"=",
"$",
"short",
... | Set the text portion of the doc block.
Sets the text portion (short and long description combined) of the doc
block.
@param string $docblock The new text portion of the doc block.
@return $this This doc block. | [
"Set",
"the",
"text",
"portion",
"of",
"the",
"doc",
"block",
"."
] | c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587 | https://github.com/mpociot/reflection-docblock/blob/c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587/src/Mpociot/Reflection/DocBlock.php#L278-L284 | train |
mpociot/reflection-docblock | src/Mpociot/Reflection/DocBlock.php | DocBlock.appendTag | public function appendTag(Tag $tag)
{
if (null === $tag->getDocBlock()) {
$tag->setDocBlock($this);
}
if ($tag->getDocBlock() === $this) {
$this->tags[] = $tag;
} else {
throw new \LogicException(
'This tag belongs to a different DocBlock object.'
);
}
return $tag;
} | php | public function appendTag(Tag $tag)
{
if (null === $tag->getDocBlock()) {
$tag->setDocBlock($this);
}
if ($tag->getDocBlock() === $this) {
$this->tags[] = $tag;
} else {
throw new \LogicException(
'This tag belongs to a different DocBlock object.'
);
}
return $tag;
} | [
"public",
"function",
"appendTag",
"(",
"Tag",
"$",
"tag",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"tag",
"->",
"getDocBlock",
"(",
")",
")",
"{",
"$",
"tag",
"->",
"setDocBlock",
"(",
"$",
"this",
")",
";",
"}",
"if",
"(",
"$",
"tag",
"->",
"... | Appends a tag at the end of the list of tags.
@param Tag $tag The tag to add.
@return Tag The newly added tag.
@throws \LogicException When the tag belongs to a different DocBlock. | [
"Appends",
"a",
"tag",
"at",
"the",
"end",
"of",
"the",
"list",
"of",
"tags",
"."
] | c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587 | https://github.com/mpociot/reflection-docblock/blob/c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587/src/Mpociot/Reflection/DocBlock.php#L425-L440 | train |
mpociot/reflection-docblock | src/Mpociot/Reflection/DocBlock/Description.php | Description.setContent | public function setContent($content)
{
$this->contents = trim($content);
$this->parsedContents = null;
return $this;
} | php | public function setContent($content)
{
$this->contents = trim($content);
$this->parsedContents = null;
return $this;
} | [
"public",
"function",
"setContent",
"(",
"$",
"content",
")",
"{",
"$",
"this",
"->",
"contents",
"=",
"trim",
"(",
"$",
"content",
")",
";",
"$",
"this",
"->",
"parsedContents",
"=",
"null",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the text of this description.
@param string $content The new text of this description.
@return $this | [
"Sets",
"the",
"text",
"of",
"this",
"description",
"."
] | c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587 | https://github.com/mpociot/reflection-docblock/blob/c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587/src/Mpociot/Reflection/DocBlock/Description.php#L63-L69 | train |
mpociot/reflection-docblock | src/Mpociot/Reflection/DocBlock/Description.php | Description.getFormattedContents | public function getFormattedContents()
{
$result = $this->contents;
// if the long description contains a plain HTML <code> element, surround
// it with a pre element. Please note that we explicitly used str_replace
// and not preg_replace to gain performance
if (strpos($result, '<code>') !== false) {
$result = str_replace(
array('<code>', "<code>\r\n", "<code>\n", "<code>\r", '</code>'),
array('<pre><code>', '<code>', '<code>', '<code>', '</code></pre>'),
$result
);
}
if (class_exists('Parsedown')) {
$markdown = \Parsedown::instance();
$result = $markdown->parse($result);
} elseif (class_exists('dflydev\markdown\MarkdownExtraParser')) {
$markdown = new \dflydev\markdown\MarkdownExtraParser();
$result = $markdown->transformMarkdown($result);
}
return trim($result);
} | php | public function getFormattedContents()
{
$result = $this->contents;
// if the long description contains a plain HTML <code> element, surround
// it with a pre element. Please note that we explicitly used str_replace
// and not preg_replace to gain performance
if (strpos($result, '<code>') !== false) {
$result = str_replace(
array('<code>', "<code>\r\n", "<code>\n", "<code>\r", '</code>'),
array('<pre><code>', '<code>', '<code>', '<code>', '</code></pre>'),
$result
);
}
if (class_exists('Parsedown')) {
$markdown = \Parsedown::instance();
$result = $markdown->parse($result);
} elseif (class_exists('dflydev\markdown\MarkdownExtraParser')) {
$markdown = new \dflydev\markdown\MarkdownExtraParser();
$result = $markdown->transformMarkdown($result);
}
return trim($result);
} | [
"public",
"function",
"getFormattedContents",
"(",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"contents",
";",
"// if the long description contains a plain HTML <code> element, surround",
"// it with a pre element. Please note that we explicitly used str_replace",
"// and not p... | Return a formatted variant of the Long Description using MarkDown.
@todo this should become a more intelligent piece of code where the
configuration contains a setting what format long descriptions are.
@codeCoverageIgnore Will be removed soon, in favor of adapters at
PhpDocumentor itself that will process text in various formats.
@return string | [
"Return",
"a",
"formatted",
"variant",
"of",
"the",
"Long",
"Description",
"using",
"MarkDown",
"."
] | c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587 | https://github.com/mpociot/reflection-docblock/blob/c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587/src/Mpociot/Reflection/DocBlock/Description.php#L149-L173 | train |
mpociot/reflection-docblock | src/Mpociot/Reflection/DocBlock/Tag.php | Tag.createInstance | final public static function createInstance(
$tag_line,
DocBlock $docblock = null,
Location $location = null
) {
if (!preg_match(
'/^@(' . self::REGEX_TAGNAME . ')(?:\s*([^\s].*)|$)?/us',
$tag_line,
$matches
)) {
throw new \InvalidArgumentException(
'Invalid tag_line detected: ' . $tag_line
);
}
$handler = __CLASS__;
if (isset(self::$tagHandlerMappings[$matches[1]])) {
$handler = self::$tagHandlerMappings[$matches[1]];
} elseif (isset($docblock)) {
$tagName = (string)new Type\Collection(
array($matches[1]),
$docblock->getContext()
);
if (isset(self::$tagHandlerMappings[$tagName])) {
$handler = self::$tagHandlerMappings[$tagName];
}
}
return new $handler(
$matches[1],
isset($matches[2]) ? $matches[2] : '',
$docblock,
$location
);
} | php | final public static function createInstance(
$tag_line,
DocBlock $docblock = null,
Location $location = null
) {
if (!preg_match(
'/^@(' . self::REGEX_TAGNAME . ')(?:\s*([^\s].*)|$)?/us',
$tag_line,
$matches
)) {
throw new \InvalidArgumentException(
'Invalid tag_line detected: ' . $tag_line
);
}
$handler = __CLASS__;
if (isset(self::$tagHandlerMappings[$matches[1]])) {
$handler = self::$tagHandlerMappings[$matches[1]];
} elseif (isset($docblock)) {
$tagName = (string)new Type\Collection(
array($matches[1]),
$docblock->getContext()
);
if (isset(self::$tagHandlerMappings[$tagName])) {
$handler = self::$tagHandlerMappings[$tagName];
}
}
return new $handler(
$matches[1],
isset($matches[2]) ? $matches[2] : '',
$docblock,
$location
);
} | [
"final",
"public",
"static",
"function",
"createInstance",
"(",
"$",
"tag_line",
",",
"DocBlock",
"$",
"docblock",
"=",
"null",
",",
"Location",
"$",
"location",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"'/^@('",
".",
"self",
"::",
"REGE... | Factory method responsible for instantiating the correct sub type.
@param string $tag_line The text for this tag, including description.
@param DocBlock $docblock The DocBlock which this tag belongs to.
@param Location $location Location of the tag.
@throws \InvalidArgumentException if an invalid tag line was presented.
@return static A new tag object. | [
"Factory",
"method",
"responsible",
"for",
"instantiating",
"the",
"correct",
"sub",
"type",
"."
] | c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587 | https://github.com/mpociot/reflection-docblock/blob/c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587/src/Mpociot/Reflection/DocBlock/Tag.php#L112-L147 | train |
mpociot/reflection-docblock | src/Mpociot/Reflection/DocBlock/Tag.php | Tag.registerTagHandler | final public static function registerTagHandler($tag, $handler)
{
$tag = trim((string)$tag);
if (null === $handler) {
unset(self::$tagHandlerMappings[$tag]);
return true;
}
if ('' !== $tag
&& class_exists($handler, true)
&& is_subclass_of($handler, __CLASS__)
&& !strpos($tag, '\\') //Accept no slash, and 1st slash at offset 0.
) {
self::$tagHandlerMappings[$tag] = $handler;
return true;
}
return false;
} | php | final public static function registerTagHandler($tag, $handler)
{
$tag = trim((string)$tag);
if (null === $handler) {
unset(self::$tagHandlerMappings[$tag]);
return true;
}
if ('' !== $tag
&& class_exists($handler, true)
&& is_subclass_of($handler, __CLASS__)
&& !strpos($tag, '\\') //Accept no slash, and 1st slash at offset 0.
) {
self::$tagHandlerMappings[$tag] = $handler;
return true;
}
return false;
} | [
"final",
"public",
"static",
"function",
"registerTagHandler",
"(",
"$",
"tag",
",",
"$",
"handler",
")",
"{",
"$",
"tag",
"=",
"trim",
"(",
"(",
"string",
")",
"$",
"tag",
")",
";",
"if",
"(",
"null",
"===",
"$",
"handler",
")",
"{",
"unset",
"(",... | Registers a handler for tags.
Registers a handler for tags. The class specified is autoloaded if it's
not available. It must inherit from this class.
@param string $tag Name of tag to regiser a handler for. When
registering a namespaced tag, the full name, along with a prefixing
slash MUST be provided.
@param string|null $handler FQCN of handler. Specifing NULL removes the
handler for the specified tag, if any.
@return bool TRUE on success, FALSE on failure. | [
"Registers",
"a",
"handler",
"for",
"tags",
"."
] | c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587 | https://github.com/mpociot/reflection-docblock/blob/c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587/src/Mpociot/Reflection/DocBlock/Tag.php#L163-L182 | train |
mpociot/reflection-docblock | src/Mpociot/Reflection/DocBlock/Tag.php | Tag.setName | public function setName($name)
{
if (!preg_match('/^' . self::REGEX_TAGNAME . '$/u', $name)) {
throw new \InvalidArgumentException(
'Invalid tag name supplied: ' . $name
);
}
$this->tag = $name;
return $this;
} | php | public function setName($name)
{
if (!preg_match('/^' . self::REGEX_TAGNAME . '$/u', $name)) {
throw new \InvalidArgumentException(
'Invalid tag name supplied: ' . $name
);
}
$this->tag = $name;
return $this;
} | [
"public",
"function",
"setName",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"'/^'",
".",
"self",
"::",
"REGEX_TAGNAME",
".",
"'$/u'",
",",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Invalid ta... | Sets the name of this tag.
@param string $name The new name of this tag.
@return $this
@throws \InvalidArgumentException When an invalid tag name is provided. | [
"Sets",
"the",
"name",
"of",
"this",
"tag",
"."
] | c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587 | https://github.com/mpociot/reflection-docblock/blob/c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587/src/Mpociot/Reflection/DocBlock/Tag.php#L223-L234 | train |
mpociot/reflection-docblock | src/Mpociot/Reflection/DocBlock/Tag.php | Tag.getContent | public function getContent()
{
if (null === $this->content) {
$this->content = $this->description;
}
return $this->content;
} | php | public function getContent()
{
if (null === $this->content) {
$this->content = $this->description;
}
return $this->content;
} | [
"public",
"function",
"getContent",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"content",
")",
"{",
"$",
"this",
"->",
"content",
"=",
"$",
"this",
"->",
"description",
";",
"}",
"return",
"$",
"this",
"->",
"content",
";",
"}"
] | Gets the content of this tag.
@return string | [
"Gets",
"the",
"content",
"of",
"this",
"tag",
"."
] | c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587 | https://github.com/mpociot/reflection-docblock/blob/c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587/src/Mpociot/Reflection/DocBlock/Tag.php#L241-L248 | train |
mpociot/reflection-docblock | src/Mpociot/Reflection/DocBlock/Tag.php | Tag.setDescription | public function setDescription($description)
{
$this->content = null;
$this->parsedDescription = null;
$this->description = trim($description);
return $this;
} | php | public function setDescription($description)
{
$this->content = null;
$this->parsedDescription = null;
$this->description = trim($description);
return $this;
} | [
"public",
"function",
"setDescription",
"(",
"$",
"description",
")",
"{",
"$",
"this",
"->",
"content",
"=",
"null",
";",
"$",
"this",
"->",
"parsedDescription",
"=",
"null",
";",
"$",
"this",
"->",
"description",
"=",
"trim",
"(",
"$",
"description",
"... | Sets the description component of this tag.
@param string $description The new description component of this tag.
@return $this | [
"Sets",
"the",
"description",
"component",
"of",
"this",
"tag",
"."
] | c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587 | https://github.com/mpociot/reflection-docblock/blob/c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587/src/Mpociot/Reflection/DocBlock/Tag.php#L282-L289 | train |
mpociot/reflection-docblock | src/Mpociot/Reflection/DocBlock/Tag.php | Tag.getParsedDescription | public function getParsedDescription()
{
if (null === $this->parsedDescription) {
$description = new Description($this->description, $this->docblock);
$this->parsedDescription = $description->getParsedContents();
}
return $this->parsedDescription;
} | php | public function getParsedDescription()
{
if (null === $this->parsedDescription) {
$description = new Description($this->description, $this->docblock);
$this->parsedDescription = $description->getParsedContents();
}
return $this->parsedDescription;
} | [
"public",
"function",
"getParsedDescription",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"parsedDescription",
")",
"{",
"$",
"description",
"=",
"new",
"Description",
"(",
"$",
"this",
"->",
"description",
",",
"$",
"this",
"->",
"docblock... | Gets the parsed text of this description.
@return array An array of strings and tag objects, in the order they
occur within the description. | [
"Gets",
"the",
"parsed",
"text",
"of",
"this",
"description",
"."
] | c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587 | https://github.com/mpociot/reflection-docblock/blob/c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587/src/Mpociot/Reflection/DocBlock/Tag.php#L297-L304 | train |
mpociot/reflection-docblock | src/Mpociot/Reflection/DocBlock/Tag/ReturnTag.php | ReturnTag.getTypesCollection | protected function getTypesCollection()
{
if (null === $this->types) {
$this->types = new Collection(
array($this->type),
$this->docblock ? $this->docblock->getContext() : null
);
}
return $this->types;
} | php | protected function getTypesCollection()
{
if (null === $this->types) {
$this->types = new Collection(
array($this->type),
$this->docblock ? $this->docblock->getContext() : null
);
}
return $this->types;
} | [
"protected",
"function",
"getTypesCollection",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"types",
")",
"{",
"$",
"this",
"->",
"types",
"=",
"new",
"Collection",
"(",
"array",
"(",
"$",
"this",
"->",
"type",
")",
",",
"$",
"this",
... | Returns the type collection.
@return void | [
"Returns",
"the",
"type",
"collection",
"."
] | c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587 | https://github.com/mpociot/reflection-docblock/blob/c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587/src/Mpociot/Reflection/DocBlock/Tag/ReturnTag.php#L89-L98 | train |
mpociot/reflection-docblock | src/Mpociot/Reflection/DocBlock/Tag/AuthorTag.php | AuthorTag.setAuthorName | public function setAuthorName($authorName)
{
$this->content = null;
$this->authorName
= preg_match('/^' . self::REGEX_AUTHOR_NAME . '$/u', $authorName)
? $authorName : '';
return $this;
} | php | public function setAuthorName($authorName)
{
$this->content = null;
$this->authorName
= preg_match('/^' . self::REGEX_AUTHOR_NAME . '$/u', $authorName)
? $authorName : '';
return $this;
} | [
"public",
"function",
"setAuthorName",
"(",
"$",
"authorName",
")",
"{",
"$",
"this",
"->",
"content",
"=",
"null",
";",
"$",
"this",
"->",
"authorName",
"=",
"preg_match",
"(",
"'/^'",
".",
"self",
"::",
"REGEX_AUTHOR_NAME",
".",
"'$/u'",
",",
"$",
"aut... | Sets the author's name.
@param string $authorName The new author name.
An invalid value will set an empty string.
@return $this | [
"Sets",
"the",
"author",
"s",
"name",
"."
] | c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587 | https://github.com/mpociot/reflection-docblock/blob/c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587/src/Mpociot/Reflection/DocBlock/Tag/AuthorTag.php#L94-L102 | train |
mpociot/reflection-docblock | src/Mpociot/Reflection/DocBlock/Tag/AuthorTag.php | AuthorTag.setAuthorEmail | public function setAuthorEmail($authorEmail)
{
$this->authorEmail
= preg_match('/^' . self::REGEX_AUTHOR_EMAIL . '$/u', $authorEmail)
? $authorEmail : '';
$this->content = null;
return $this;
} | php | public function setAuthorEmail($authorEmail)
{
$this->authorEmail
= preg_match('/^' . self::REGEX_AUTHOR_EMAIL . '$/u', $authorEmail)
? $authorEmail : '';
$this->content = null;
return $this;
} | [
"public",
"function",
"setAuthorEmail",
"(",
"$",
"authorEmail",
")",
"{",
"$",
"this",
"->",
"authorEmail",
"=",
"preg_match",
"(",
"'/^'",
".",
"self",
"::",
"REGEX_AUTHOR_EMAIL",
".",
"'$/u'",
",",
"$",
"authorEmail",
")",
"?",
"$",
"authorEmail",
":",
... | Sets the author's email.
@param string $authorEmail The new author email.
An invalid value will set an empty string.
@return $this | [
"Sets",
"the",
"author",
"s",
"email",
"."
] | c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587 | https://github.com/mpociot/reflection-docblock/blob/c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587/src/Mpociot/Reflection/DocBlock/Tag/AuthorTag.php#L122-L130 | train |
mpociot/reflection-docblock | src/Mpociot/Reflection/DocBlock/Tag/VersionTag.php | VersionTag.setVersion | public function setVersion($version)
{
$this->version
= preg_match('/^' . self::REGEX_VECTOR . '$/ux', $version)
? $version
: '';
$this->content = null;
return $this;
} | php | public function setVersion($version)
{
$this->version
= preg_match('/^' . self::REGEX_VECTOR . '$/ux', $version)
? $version
: '';
$this->content = null;
return $this;
} | [
"public",
"function",
"setVersion",
"(",
"$",
"version",
")",
"{",
"$",
"this",
"->",
"version",
"=",
"preg_match",
"(",
"'/^'",
".",
"self",
"::",
"REGEX_VECTOR",
".",
"'$/ux'",
",",
"$",
"version",
")",
"?",
"$",
"version",
":",
"''",
";",
"$",
"th... | Sets the version section of the tag.
@param string $version The new version section of the tag.
An invalid value will set an empty string.
@return $this | [
"Sets",
"the",
"version",
"section",
"of",
"the",
"tag",
"."
] | c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587 | https://github.com/mpociot/reflection-docblock/blob/c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587/src/Mpociot/Reflection/DocBlock/Tag/VersionTag.php#L98-L107 | train |
mpociot/reflection-docblock | src/Mpociot/Reflection/DocBlock/Tag/MethodTag.php | MethodTag.getArguments | public function getArguments()
{
if (empty($this->arguments)) {
return array();
}
$arguments = explode(',', $this->arguments);
foreach ($arguments as $key => $value) {
$arguments[$key] = explode(' ', trim($value));
}
return $arguments;
} | php | public function getArguments()
{
if (empty($this->arguments)) {
return array();
}
$arguments = explode(',', $this->arguments);
foreach ($arguments as $key => $value) {
$arguments[$key] = explode(' ', trim($value));
}
return $arguments;
} | [
"public",
"function",
"getArguments",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"arguments",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"arguments",
"=",
"explode",
"(",
"','",
",",
"$",
"this",
"->",
"arguments",
"... | Returns an array containing each argument as array of type and name.
Please note that the argument sub-array may only contain 1 element if no
type was specified.
@return string[] | [
"Returns",
"an",
"array",
"containing",
"each",
"argument",
"as",
"array",
"of",
"type",
"and",
"name",
"."
] | c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587 | https://github.com/mpociot/reflection-docblock/blob/c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587/src/Mpociot/Reflection/DocBlock/Tag/MethodTag.php#L170-L182 | train |
mpociot/reflection-docblock | src/Mpociot/Reflection/DocBlock/Tag/ExampleTag.php | ExampleTag.setFilePath | public function setFilePath($filePath)
{
$this->isURI = false;
$this->filePath = trim($filePath);
$this->content = null;
return $this;
} | php | public function setFilePath($filePath)
{
$this->isURI = false;
$this->filePath = trim($filePath);
$this->content = null;
return $this;
} | [
"public",
"function",
"setFilePath",
"(",
"$",
"filePath",
")",
"{",
"$",
"this",
"->",
"isURI",
"=",
"false",
";",
"$",
"this",
"->",
"filePath",
"=",
"trim",
"(",
"$",
"filePath",
")",
";",
"$",
"this",
"->",
"content",
"=",
"null",
";",
"return",
... | Sets the file path.
@param string $filePath The new file path to use for the example.
@return $this | [
"Sets",
"the",
"file",
"path",
"."
] | c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587 | https://github.com/mpociot/reflection-docblock/blob/c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587/src/Mpociot/Reflection/DocBlock/Tag/ExampleTag.php#L121-L128 | train |
mpociot/reflection-docblock | src/Mpociot/Reflection/DocBlock/Tag/ExampleTag.php | ExampleTag.setFileURI | public function setFileURI($uri)
{
$this->isURI = true;
if (false === strpos($uri, ':')) {
//Relative URL
$this->filePath = rawurldecode(
str_replace(array('/', '\\'), '%2F', $uri)
);
} else {
//Absolute URL or URI.
$this->filePath = $uri;
}
$this->content = null;
return $this;
} | php | public function setFileURI($uri)
{
$this->isURI = true;
if (false === strpos($uri, ':')) {
//Relative URL
$this->filePath = rawurldecode(
str_replace(array('/', '\\'), '%2F', $uri)
);
} else {
//Absolute URL or URI.
$this->filePath = $uri;
}
$this->content = null;
return $this;
} | [
"public",
"function",
"setFileURI",
"(",
"$",
"uri",
")",
"{",
"$",
"this",
"->",
"isURI",
"=",
"true",
";",
"if",
"(",
"false",
"===",
"strpos",
"(",
"$",
"uri",
",",
"':'",
")",
")",
"{",
"//Relative URL",
"$",
"this",
"->",
"filePath",
"=",
"raw... | Sets the file path as an URI.
This function is equivalent to {@link setFilePath()}, except that it
convers an URI to a file path before that.
There is no getFileURI(), as {@link getFilePath()} is compatible.
@param type $uri The new file URI to use as an example. | [
"Sets",
"the",
"file",
"path",
"as",
"an",
"URI",
"."
] | c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587 | https://github.com/mpociot/reflection-docblock/blob/c8b2e2b1f5cebbb06e2b5ccbf2958f2198867587/src/Mpociot/Reflection/DocBlock/Tag/ExampleTag.php#L140-L155 | train |
appstract/lush-http | src/Request/RequestGetters.php | RequestGetters.getParameter | public function getParameter($parameter)
{
return isset($this->getParameters()[$parameter]) ? $this->getParameters()[$parameter] : null;
} | php | public function getParameter($parameter)
{
return isset($this->getParameters()[$parameter]) ? $this->getParameters()[$parameter] : null;
} | [
"public",
"function",
"getParameter",
"(",
"$",
"parameter",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"getParameters",
"(",
")",
"[",
"$",
"parameter",
"]",
")",
"?",
"$",
"this",
"->",
"getParameters",
"(",
")",
"[",
"$",
"parameter",
"]",... | Get a specific parameter.
@param $parameter
@return mixed | [
"Get",
"a",
"specific",
"parameter",
"."
] | 771c501e1ea6a16b6c33917f595a04e5e37ad9b7 | https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Request/RequestGetters.php#L44-L47 | train |
appstract/lush-http | src/Request/Adapter/CurlMock.php | CurlMock.setOptions | public function setOptions(array $curlOptions, array $lushOptions = null)
{
$this->curlOptions = $curlOptions;
$this->lushOptions = $lushOptions;
} | php | public function setOptions(array $curlOptions, array $lushOptions = null)
{
$this->curlOptions = $curlOptions;
$this->lushOptions = $lushOptions;
} | [
"public",
"function",
"setOptions",
"(",
"array",
"$",
"curlOptions",
",",
"array",
"$",
"lushOptions",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"curlOptions",
"=",
"$",
"curlOptions",
";",
"$",
"this",
"->",
"lushOptions",
"=",
"$",
"lushOptions",
";",
... | Set options array.
@param array $curlOptions
@param array $lushOptions | [
"Set",
"options",
"array",
"."
] | 771c501e1ea6a16b6c33917f595a04e5e37ad9b7 | https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Request/Adapter/CurlMock.php#L73-L77 | train |
appstract/lush-http | src/Request/Adapter/CurlMock.php | CurlMock.createResponse | protected function createResponse($statusCode, $contentType)
{
switch ($statusCode) {
case 200:
case 201:
return $this->createContent($contentType);
default:
// fail on error
if ($this->curlOptions[45]) {
throw new LushRequestException($this, ['message' => sprintf('%d - Mocked server error', $statusCode), 'code' => $statusCode, 'response' => 'false']);
}
return json_encode(['url' => $this->ch, 'status' => sprintf('Error: %d', $statusCode)]);
}
} | php | protected function createResponse($statusCode, $contentType)
{
switch ($statusCode) {
case 200:
case 201:
return $this->createContent($contentType);
default:
// fail on error
if ($this->curlOptions[45]) {
throw new LushRequestException($this, ['message' => sprintf('%d - Mocked server error', $statusCode), 'code' => $statusCode, 'response' => 'false']);
}
return json_encode(['url' => $this->ch, 'status' => sprintf('Error: %d', $statusCode)]);
}
} | [
"protected",
"function",
"createResponse",
"(",
"$",
"statusCode",
",",
"$",
"contentType",
")",
"{",
"switch",
"(",
"$",
"statusCode",
")",
"{",
"case",
"200",
":",
"case",
"201",
":",
"return",
"$",
"this",
"->",
"createContent",
"(",
"$",
"contentType",... | Create a example response based on statuscode.
@param $statusCode
@param $contentType
@return string | [
"Create",
"a",
"example",
"response",
"based",
"on",
"statuscode",
"."
] | 771c501e1ea6a16b6c33917f595a04e5e37ad9b7 | https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Request/Adapter/CurlMock.php#L163-L177 | train |
appstract/lush-http | src/Request/Adapter/CurlMock.php | CurlMock.createContent | protected function createContent($type)
{
if ($type == 'json') {
$this->headers['content_type'] = 'application/json; charset=UTF-8';
return json_encode(['url' => $this->ch, 'status' => 'ok']);
} elseif ($type == 'xml') {
$this->headers['content_type'] = 'text/xml; charset=UTF-8';
return '<?xml version="1.0" encoding="UTF-8"?><result><url>'.$this->ch.'</url><status>ok</status></result>';
}
return 'ok';
} | php | protected function createContent($type)
{
if ($type == 'json') {
$this->headers['content_type'] = 'application/json; charset=UTF-8';
return json_encode(['url' => $this->ch, 'status' => 'ok']);
} elseif ($type == 'xml') {
$this->headers['content_type'] = 'text/xml; charset=UTF-8';
return '<?xml version="1.0" encoding="UTF-8"?><result><url>'.$this->ch.'</url><status>ok</status></result>';
}
return 'ok';
} | [
"protected",
"function",
"createContent",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"$",
"type",
"==",
"'json'",
")",
"{",
"$",
"this",
"->",
"headers",
"[",
"'content_type'",
"]",
"=",
"'application/json; charset=UTF-8'",
";",
"return",
"json_encode",
"(",
"["... | Create sample content for response.
@param $type
@return string | [
"Create",
"sample",
"content",
"for",
"response",
"."
] | 771c501e1ea6a16b6c33917f595a04e5e37ad9b7 | https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Request/Adapter/CurlMock.php#L186-L199 | train |
appstract/lush-http | src/Response/ResponseGetters.php | ResponseGetters.getResult | public function getResult()
{
if ($this->autoFormat && ! empty($this->object)) {
return $this->object;
}
return $this->content;
} | php | public function getResult()
{
if ($this->autoFormat && ! empty($this->object)) {
return $this->object;
}
return $this->content;
} | [
"public",
"function",
"getResult",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"autoFormat",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"object",
")",
")",
"{",
"return",
"$",
"this",
"->",
"object",
";",
"}",
"return",
"$",
"this",
"->",
"conten... | Get the content of the result.
@return mixed | [
"Get",
"the",
"content",
"of",
"the",
"result",
"."
] | 771c501e1ea6a16b6c33917f595a04e5e37ad9b7 | https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Response/ResponseGetters.php#L14-L21 | train |
appstract/lush-http | src/Response/LushResponse.php | LushResponse.isJson | public function isJson()
{
if (isset($this->isJson)) {
return $this->isJson;
}
// check based on content header
if (strpos($this->getHeader('content_type'), 'application/json') !== false) {
$this->isJson = true;
} else {
// check based on content
json_decode($this->content);
$this->isJson = (json_last_error() == JSON_ERROR_NONE);
}
return $this->isJson;
} | php | public function isJson()
{
if (isset($this->isJson)) {
return $this->isJson;
}
// check based on content header
if (strpos($this->getHeader('content_type'), 'application/json') !== false) {
$this->isJson = true;
} else {
// check based on content
json_decode($this->content);
$this->isJson = (json_last_error() == JSON_ERROR_NONE);
}
return $this->isJson;
} | [
"public",
"function",
"isJson",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"isJson",
")",
")",
"{",
"return",
"$",
"this",
"->",
"isJson",
";",
"}",
"// check based on content header",
"if",
"(",
"strpos",
"(",
"$",
"this",
"->",
"getHe... | Check if content is json.
@return null | [
"Check",
"if",
"content",
"is",
"json",
"."
] | 771c501e1ea6a16b6c33917f595a04e5e37ad9b7 | https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Response/LushResponse.php#L57-L73 | train |
appstract/lush-http | src/Response/LushResponse.php | LushResponse.formatContent | protected function formatContent($content)
{
if ($this->request->method == 'HEAD') {
return (object) $this->headers;
}
if ($this->isXml()) {
return json_decode($this->parseXml($content));
}
if ($this->isJson()) {
return json_decode($content);
}
} | php | protected function formatContent($content)
{
if ($this->request->method == 'HEAD') {
return (object) $this->headers;
}
if ($this->isXml()) {
return json_decode($this->parseXml($content));
}
if ($this->isJson()) {
return json_decode($content);
}
} | [
"protected",
"function",
"formatContent",
"(",
"$",
"content",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"request",
"->",
"method",
"==",
"'HEAD'",
")",
"{",
"return",
"(",
"object",
")",
"$",
"this",
"->",
"headers",
";",
"}",
"if",
"(",
"$",
"this",
... | format content.
@param $content
@return mixed | [
"format",
"content",
"."
] | 771c501e1ea6a16b6c33917f595a04e5e37ad9b7 | https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Response/LushResponse.php#L100-L113 | train |
appstract/lush-http | src/Response/LushResponse.php | LushResponse.& | public function &__get($property)
{
$return = null;
// check if the property is present in the content object
if (isset($this->object->{ $property })) {
$return = $this->object->{ $property };
}
return $return;
} | php | public function &__get($property)
{
$return = null;
// check if the property is present in the content object
if (isset($this->object->{ $property })) {
$return = $this->object->{ $property };
}
return $return;
} | [
"public",
"function",
"&",
"__get",
"(",
"$",
"property",
")",
"{",
"$",
"return",
"=",
"null",
";",
"// check if the property is present in the content object",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"object",
"->",
"{",
"$",
"property",
"}",
")",
")",... | Magic getter for content properties.
@param $property
@return mixed | [
"Magic",
"getter",
"for",
"content",
"properties",
"."
] | 771c501e1ea6a16b6c33917f595a04e5e37ad9b7 | https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Response/LushResponse.php#L136-L146 | train |
appstract/lush-http | src/Lush.php | Lush.url | public function url($url, $parameters = [])
{
$this->url = $url;
$this->parameters = $parameters;
return $this;
} | php | public function url($url, $parameters = [])
{
$this->url = $url;
$this->parameters = $parameters;
return $this;
} | [
"public",
"function",
"url",
"(",
"$",
"url",
",",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"url",
"=",
"$",
"url",
";",
"$",
"this",
"->",
"parameters",
"=",
"$",
"parameters",
";",
"return",
"$",
"this",
";",
"}"
] | Set the url with parameters.
@param $url
@param array|object $parameters
@return $this | [
"Set",
"the",
"url",
"with",
"parameters",
"."
] | 771c501e1ea6a16b6c33917f595a04e5e37ad9b7 | https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Lush.php#L49-L55 | train |
appstract/lush-http | src/Lush.php | Lush.reset | public function reset()
{
$this->url = '';
$this->parameters = [];
$this->headers = [];
$this->options = [];
return $this;
} | php | public function reset()
{
$this->url = '';
$this->parameters = [];
$this->headers = [];
$this->options = [];
return $this;
} | [
"public",
"function",
"reset",
"(",
")",
"{",
"$",
"this",
"->",
"url",
"=",
"''",
";",
"$",
"this",
"->",
"parameters",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"headers",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"options",
"=",
"[",
"]",
";",
"... | Reset all request options.
@return $this | [
"Reset",
"all",
"request",
"options",
"."
] | 771c501e1ea6a16b6c33917f595a04e5e37ad9b7 | https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Lush.php#L90-L98 | train |
appstract/lush-http | src/Lush.php | Lush.addOption | protected function addOption($name, $value)
{
$this->baseload['options'] = array_merge($this->baseload['options'], [$name => $value]);
} | php | protected function addOption($name, $value)
{
$this->baseload['options'] = array_merge($this->baseload['options'], [$name => $value]);
} | [
"protected",
"function",
"addOption",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"baseload",
"[",
"'options'",
"]",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"baseload",
"[",
"'options'",
"]",
",",
"[",
"$",
"name",
"=>",
"$"... | Add option.
@param $name
@param $value | [
"Add",
"option",
"."
] | 771c501e1ea6a16b6c33917f595a04e5e37ad9b7 | https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Lush.php#L182-L185 | train |
appstract/lush-http | src/Request/LushRequest.php | LushRequest.formatUrl | protected function formatUrl()
{
// append trailing slash to the
// baseUrl if it is missing
if (! empty($this->payload['base_url']) && substr($this->payload['base_url'], -1) !== '/') {
$this->payload['base_url'] = $this->payload['base_url'].'/';
}
// append the base url
$this->payload['url'] = trim($this->payload['base_url'].$this->payload['url']);
} | php | protected function formatUrl()
{
// append trailing slash to the
// baseUrl if it is missing
if (! empty($this->payload['base_url']) && substr($this->payload['base_url'], -1) !== '/') {
$this->payload['base_url'] = $this->payload['base_url'].'/';
}
// append the base url
$this->payload['url'] = trim($this->payload['base_url'].$this->payload['url']);
} | [
"protected",
"function",
"formatUrl",
"(",
")",
"{",
"// append trailing slash to the",
"// baseUrl if it is missing",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"payload",
"[",
"'base_url'",
"]",
")",
"&&",
"substr",
"(",
"$",
"this",
"->",
"payload",
"... | Format url. | [
"Format",
"url",
"."
] | 771c501e1ea6a16b6c33917f595a04e5e37ad9b7 | https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Request/LushRequest.php#L51-L61 | train |
appstract/lush-http | src/Request/LushRequest.php | LushRequest.validateInput | protected function validateInput()
{
if (! filter_var($this->payload['url'], FILTER_VALIDATE_URL)) {
throw new LushException('URL is invalid', 100);
}
if (! in_array($this->method, $this->allowedMethods)) {
throw new LushException(sprintf("Method '%s' is not supported", $this->method), 101);
}
} | php | protected function validateInput()
{
if (! filter_var($this->payload['url'], FILTER_VALIDATE_URL)) {
throw new LushException('URL is invalid', 100);
}
if (! in_array($this->method, $this->allowedMethods)) {
throw new LushException(sprintf("Method '%s' is not supported", $this->method), 101);
}
} | [
"protected",
"function",
"validateInput",
"(",
")",
"{",
"if",
"(",
"!",
"filter_var",
"(",
"$",
"this",
"->",
"payload",
"[",
"'url'",
"]",
",",
"FILTER_VALIDATE_URL",
")",
")",
"{",
"throw",
"new",
"LushException",
"(",
"'URL is invalid'",
",",
"100",
")... | Validate given options. | [
"Validate",
"given",
"options",
"."
] | 771c501e1ea6a16b6c33917f595a04e5e37ad9b7 | https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Request/LushRequest.php#L66-L75 | train |
appstract/lush-http | src/Request/LushRequest.php | LushRequest.addHeaders | protected function addHeaders()
{
$userHeaders = array_map(function ($key, $value) {
// format header like this 'x-header: value'
return sprintf('%s: %s', $key, $value);
}, array_keys($this->payload['headers']), $this->payload['headers']);
$headers = array_merge($this->defaultHeaders, $userHeaders);
$this->addCurlOption(CURLOPT_HTTPHEADER, $headers);
} | php | protected function addHeaders()
{
$userHeaders = array_map(function ($key, $value) {
// format header like this 'x-header: value'
return sprintf('%s: %s', $key, $value);
}, array_keys($this->payload['headers']), $this->payload['headers']);
$headers = array_merge($this->defaultHeaders, $userHeaders);
$this->addCurlOption(CURLOPT_HTTPHEADER, $headers);
} | [
"protected",
"function",
"addHeaders",
"(",
")",
"{",
"$",
"userHeaders",
"=",
"array_map",
"(",
"function",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"// format header like this 'x-header: value'",
"return",
"sprintf",
"(",
"'%s: %s'",
",",
"$",
"key",
",... | Add request headers. | [
"Add",
"request",
"headers",
"."
] | 771c501e1ea6a16b6c33917f595a04e5e37ad9b7 | https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Request/LushRequest.php#L80-L90 | train |
appstract/lush-http | src/Request/LushRequest.php | LushRequest.addRequestBody | protected function addRequestBody()
{
if (! empty($this->payload['parameters'])) {
if (in_array($this->method, ['DELETE', 'PATCH', 'POST', 'PUT'])) {
$this->addCurlOption(CURLOPT_POSTFIELDS, $this->formattedRequestBody());
} elseif (is_array($this->payload['parameters'])) {
// append parameters in the url
$this->payload['url'] = sprintf('%s?%s', $this->payload['url'], $this->formattedRequestBody());
}
}
} | php | protected function addRequestBody()
{
if (! empty($this->payload['parameters'])) {
if (in_array($this->method, ['DELETE', 'PATCH', 'POST', 'PUT'])) {
$this->addCurlOption(CURLOPT_POSTFIELDS, $this->formattedRequestBody());
} elseif (is_array($this->payload['parameters'])) {
// append parameters in the url
$this->payload['url'] = sprintf('%s?%s', $this->payload['url'], $this->formattedRequestBody());
}
}
} | [
"protected",
"function",
"addRequestBody",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"payload",
"[",
"'parameters'",
"]",
")",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"this",
"->",
"method",
",",
"[",
"'DELETE'",
",",
"'PATCH... | Add request body. | [
"Add",
"request",
"body",
"."
] | 771c501e1ea6a16b6c33917f595a04e5e37ad9b7 | https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Request/LushRequest.php#L95-L105 | train |
appstract/lush-http | src/Request/LushRequest.php | LushRequest.formattedRequestBody | protected function formattedRequestBody()
{
if (isset($this->payload['options']['body_format']) && $this->payload['options']['body_format'] == 'json') {
return json_encode($this->payload['parameters']);
}
return http_build_query($this->payload['parameters']);
} | php | protected function formattedRequestBody()
{
if (isset($this->payload['options']['body_format']) && $this->payload['options']['body_format'] == 'json') {
return json_encode($this->payload['parameters']);
}
return http_build_query($this->payload['parameters']);
} | [
"protected",
"function",
"formattedRequestBody",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"payload",
"[",
"'options'",
"]",
"[",
"'body_format'",
"]",
")",
"&&",
"$",
"this",
"->",
"payload",
"[",
"'options'",
"]",
"[",
"'body_format'",
... | Get formatted request body based on body_format.
@return null|string | [
"Get",
"formatted",
"request",
"body",
"based",
"on",
"body_format",
"."
] | 771c501e1ea6a16b6c33917f595a04e5e37ad9b7 | https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Request/LushRequest.php#L112-L119 | train |
appstract/lush-http | src/Request/LushRequest.php | LushRequest.initOptions | protected function initOptions()
{
// Set method
if ($this->method == 'POST') {
$this->addCurlOption(CURLOPT_POST, true);
} elseif (in_array($this->method, ['DELETE', 'HEAD', 'PATCH', 'PUT'])) {
if ($this->method == 'HEAD') {
$this->addCurlOption(CURLOPT_NOBODY, true);
}
$this->addCurlOption(CURLOPT_CUSTOMREQUEST, $this->method);
}
// Set allowed protocols
if (defined('CURLOPT_PROTOCOLS')) {
$this->addCurlOption(CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
}
// Handle options from payload
if (! empty($this->payload['options']) && is_array($this->payload['options'])) {
// Add authentication
$this->handleAuthentication();
// Add user options
$this->handleUserOptions();
}
$this->mergeCurlOptions();
} | php | protected function initOptions()
{
// Set method
if ($this->method == 'POST') {
$this->addCurlOption(CURLOPT_POST, true);
} elseif (in_array($this->method, ['DELETE', 'HEAD', 'PATCH', 'PUT'])) {
if ($this->method == 'HEAD') {
$this->addCurlOption(CURLOPT_NOBODY, true);
}
$this->addCurlOption(CURLOPT_CUSTOMREQUEST, $this->method);
}
// Set allowed protocols
if (defined('CURLOPT_PROTOCOLS')) {
$this->addCurlOption(CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
}
// Handle options from payload
if (! empty($this->payload['options']) && is_array($this->payload['options'])) {
// Add authentication
$this->handleAuthentication();
// Add user options
$this->handleUserOptions();
}
$this->mergeCurlOptions();
} | [
"protected",
"function",
"initOptions",
"(",
")",
"{",
"// Set method",
"if",
"(",
"$",
"this",
"->",
"method",
"==",
"'POST'",
")",
"{",
"$",
"this",
"->",
"addCurlOption",
"(",
"CURLOPT_POST",
",",
"true",
")",
";",
"}",
"elseif",
"(",
"in_array",
"(",... | Set request options. | [
"Set",
"request",
"options",
"."
] | 771c501e1ea6a16b6c33917f595a04e5e37ad9b7 | https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Request/LushRequest.php#L146-L174 | train |
appstract/lush-http | src/Request/LushRequest.php | LushRequest.handleAuthentication | protected function handleAuthentication()
{
if (isset($this->payload['options']['username'], $this->payload['options']['password'])) {
$this->addCurlOption(CURLOPT_USERPWD, sprintf('%s:%s', $this->payload['options']['username'], $this->payload['options']['password']));
}
} | php | protected function handleAuthentication()
{
if (isset($this->payload['options']['username'], $this->payload['options']['password'])) {
$this->addCurlOption(CURLOPT_USERPWD, sprintf('%s:%s', $this->payload['options']['username'], $this->payload['options']['password']));
}
} | [
"protected",
"function",
"handleAuthentication",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"payload",
"[",
"'options'",
"]",
"[",
"'username'",
"]",
",",
"$",
"this",
"->",
"payload",
"[",
"'options'",
"]",
"[",
"'password'",
"]",
")",
... | Handle authentication. | [
"Handle",
"authentication",
"."
] | 771c501e1ea6a16b6c33917f595a04e5e37ad9b7 | https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Request/LushRequest.php#L179-L184 | train |
appstract/lush-http | src/Request/LushRequest.php | LushRequest.handleUserOptions | protected function handleUserOptions()
{
foreach ($this->payload['options'] as $option => $value) {
$resolvedOption = RequestOptions::resolve($option);
if ($resolvedOption['type'] == 'curl_option') {
$this->addCurlOption($resolvedOption['option'], $value);
} else {
$this->addOption($option, $value);
}
}
} | php | protected function handleUserOptions()
{
foreach ($this->payload['options'] as $option => $value) {
$resolvedOption = RequestOptions::resolve($option);
if ($resolvedOption['type'] == 'curl_option') {
$this->addCurlOption($resolvedOption['option'], $value);
} else {
$this->addOption($option, $value);
}
}
} | [
"protected",
"function",
"handleUserOptions",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"payload",
"[",
"'options'",
"]",
"as",
"$",
"option",
"=>",
"$",
"value",
")",
"{",
"$",
"resolvedOption",
"=",
"RequestOptions",
"::",
"resolve",
"(",
"$",
... | Handle user options. | [
"Handle",
"user",
"options",
"."
] | 771c501e1ea6a16b6c33917f595a04e5e37ad9b7 | https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Request/LushRequest.php#L189-L200 | train |
appstract/lush-http | src/Request/CurlRequest.php | CurlRequest.makeRequest | protected function makeRequest()
{
// init Curl
$this->client->init($this->payload['url']);
$this->client->setOptions($this->curlOptions, $this->options);
// get results
$content = $this->client->execute();
$headers = $this->client->getInfo();
$response = new LushResponse(compact('content', 'headers'), $this);
// handle errors
if ($content === false || substr($headers['http_code'], 0, 1) != 2) {
$error = [
'code' => $this->client->getErrorCode(),
'message' => $this->client->getErrorMessage(),
'response' => $response,
];
$this->client->close();
throw new LushRequestException($this, $error);
}
$this->client->close();
return $response;
} | php | protected function makeRequest()
{
// init Curl
$this->client->init($this->payload['url']);
$this->client->setOptions($this->curlOptions, $this->options);
// get results
$content = $this->client->execute();
$headers = $this->client->getInfo();
$response = new LushResponse(compact('content', 'headers'), $this);
// handle errors
if ($content === false || substr($headers['http_code'], 0, 1) != 2) {
$error = [
'code' => $this->client->getErrorCode(),
'message' => $this->client->getErrorMessage(),
'response' => $response,
];
$this->client->close();
throw new LushRequestException($this, $error);
}
$this->client->close();
return $response;
} | [
"protected",
"function",
"makeRequest",
"(",
")",
"{",
"// init Curl",
"$",
"this",
"->",
"client",
"->",
"init",
"(",
"$",
"this",
"->",
"payload",
"[",
"'url'",
"]",
")",
";",
"$",
"this",
"->",
"client",
"->",
"setOptions",
"(",
"$",
"this",
"->",
... | Sends the Curl requests and returns result array.
@return \Appstract\LushHttp\Response\LushResponse | [
"Sends",
"the",
"Curl",
"requests",
"and",
"returns",
"result",
"array",
"."
] | 771c501e1ea6a16b6c33917f595a04e5e37ad9b7 | https://github.com/appstract/lush-http/blob/771c501e1ea6a16b6c33917f595a04e5e37ad9b7/src/Request/CurlRequest.php#L63-L91 | train |
nails/module-cdn | cdn/controllers/Serve.php | Serve.serveBadSrc | protected function serveBadSrc(array $params)
{
$error = $params['error'];
$oInput = Factory::service('Input');
header('Cache-Control: no-cache, must-revalidate', true);
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT', true);
header('Content-Type: application/json', true);
header($oInput->server('SERVER_PROTOCOL') . ' 400 Bad Request', true, 400);
// --------------------------------------------------------------------------
$out = [
'status' => 400,
'message' => 'Invalid Request',
];
if (!empty($error)) {
$out['error'] = $error;
}
echo json_encode($out);
// --------------------------------------------------------------------------
/**
* Kill script, th, th, that's all folks. Stop the output class from hijacking
* our headers and setting an incorrect Content-Type
*/
exit(0);
} | php | protected function serveBadSrc(array $params)
{
$error = $params['error'];
$oInput = Factory::service('Input');
header('Cache-Control: no-cache, must-revalidate', true);
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT', true);
header('Content-Type: application/json', true);
header($oInput->server('SERVER_PROTOCOL') . ' 400 Bad Request', true, 400);
// --------------------------------------------------------------------------
$out = [
'status' => 400,
'message' => 'Invalid Request',
];
if (!empty($error)) {
$out['error'] = $error;
}
echo json_encode($out);
// --------------------------------------------------------------------------
/**
* Kill script, th, th, that's all folks. Stop the output class from hijacking
* our headers and setting an incorrect Content-Type
*/
exit(0);
} | [
"protected",
"function",
"serveBadSrc",
"(",
"array",
"$",
"params",
")",
"{",
"$",
"error",
"=",
"$",
"params",
"[",
"'error'",
"]",
";",
"$",
"oInput",
"=",
"Factory",
"::",
"service",
"(",
"'Input'",
")",
";",
"header",
"(",
"'Cache-Control: no-cache, m... | Serves a response for bad requests
@param array $params
@internal param string $error The error which occurred | [
"Serves",
"a",
"response",
"for",
"bad",
"requests"
] | 1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef | https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/cdn/controllers/Serve.php#L260-L291 | train |
jon48/webtrees-lib | src/Webtrees/Family.php | Family.getIntance | public static function getIntance($xref, Tree $tree, $gedcom = null){
$dfam = null;
$fam = fw\Family::getInstance($xref, $tree, $gedcom);
if($fam){
$dfam = new Family($fam);
}
return $dfam;
} | php | public static function getIntance($xref, Tree $tree, $gedcom = null){
$dfam = null;
$fam = fw\Family::getInstance($xref, $tree, $gedcom);
if($fam){
$dfam = new Family($fam);
}
return $dfam;
} | [
"public",
"static",
"function",
"getIntance",
"(",
"$",
"xref",
",",
"Tree",
"$",
"tree",
",",
"$",
"gedcom",
"=",
"null",
")",
"{",
"$",
"dfam",
"=",
"null",
";",
"$",
"fam",
"=",
"fw",
"\\",
"Family",
"::",
"getInstance",
"(",
"$",
"xref",
",",
... | Extend \Fisharebest\Webtrees\Family getInstance, in order to retrieve directly a \MyArtJaub\Webtrees\Family object
@param string $xref
@param Tree $tree
@param string $gedcom
@return NULL|\MyArtJaub\Webtrees\Family | [
"Extend",
"\\",
"Fisharebest",
"\\",
"Webtrees",
"\\",
"Family",
"getInstance",
"in",
"order",
"to",
"retrieve",
"directly",
"a",
"\\",
"MyArtJaub",
"\\",
"Webtrees",
"\\",
"Family",
"object"
] | e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7 | https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Family.php#L33-L40 | train |
jon48/webtrees-lib | src/Webtrees/Family.php | Family.isMarriageSourced | function isMarriageSourced(){
if($this->is_marriage_sourced !== null) return $this->is_marriage_sourced;
$this->is_marriage_sourced = $this->isFactSourced(WT_EVENTS_MARR.'|MARC');
return $this->is_marriage_sourced;
} | php | function isMarriageSourced(){
if($this->is_marriage_sourced !== null) return $this->is_marriage_sourced;
$this->is_marriage_sourced = $this->isFactSourced(WT_EVENTS_MARR.'|MARC');
return $this->is_marriage_sourced;
} | [
"function",
"isMarriageSourced",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"is_marriage_sourced",
"!==",
"null",
")",
"return",
"$",
"this",
"->",
"is_marriage_sourced",
";",
"$",
"this",
"->",
"is_marriage_sourced",
"=",
"$",
"this",
"->",
"isFactSourced",... | Check if this family's marriages are sourced
@return int Level of sources | [
"Check",
"if",
"this",
"family",
"s",
"marriages",
"are",
"sourced"
] | e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7 | https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Family.php#L47-L51 | train |
jon48/webtrees-lib | src/Webtrees/Family.php | Family.getSpouseById | public function getSpouseById(\Fisharebest\Webtrees\Individual $person) {
if ($this->gedcomrecord->getWife() &&
$person->getXref() === $this->gedcomrecord->getWife()->getXref()) {
return $this->gedcomrecord->getHusband();
} else {
return $this->gedcomrecord->getWife();
}
} | php | public function getSpouseById(\Fisharebest\Webtrees\Individual $person) {
if ($this->gedcomrecord->getWife() &&
$person->getXref() === $this->gedcomrecord->getWife()->getXref()) {
return $this->gedcomrecord->getHusband();
} else {
return $this->gedcomrecord->getWife();
}
} | [
"public",
"function",
"getSpouseById",
"(",
"\\",
"Fisharebest",
"\\",
"Webtrees",
"\\",
"Individual",
"$",
"person",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"gedcomrecord",
"->",
"getWife",
"(",
")",
"&&",
"$",
"person",
"->",
"getXref",
"(",
")",
"==="... | Find the spouse of a person, using the Xref comparison.
@param Individual $person
@return Individual|null | [
"Find",
"the",
"spouse",
"of",
"a",
"person",
"using",
"the",
"Xref",
"comparison",
"."
] | e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7 | https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Family.php#L60-L67 | train |
kadet1090/KeyLighter | Language/GreedyLanguage.php | GreedyLanguage.parse | public function parse($tokens = null, $additional = [], $embedded = false)
{
if (is_string($tokens)) {
$tokens = $this->tokenize($tokens, $additional, $embedded);
} elseif (!$tokens instanceof TokenIterator) {
// Todo: Own Exceptions
throw new \InvalidArgumentException('$tokens must be string or TokenIterator');
}
return $this->_process($tokens);
} | php | public function parse($tokens = null, $additional = [], $embedded = false)
{
if (is_string($tokens)) {
$tokens = $this->tokenize($tokens, $additional, $embedded);
} elseif (!$tokens instanceof TokenIterator) {
// Todo: Own Exceptions
throw new \InvalidArgumentException('$tokens must be string or TokenIterator');
}
return $this->_process($tokens);
} | [
"public",
"function",
"parse",
"(",
"$",
"tokens",
"=",
"null",
",",
"$",
"additional",
"=",
"[",
"]",
",",
"$",
"embedded",
"=",
"false",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"tokens",
")",
")",
"{",
"$",
"tokens",
"=",
"$",
"this",
"->",... | Parses source and removes wrong tokens.
@param TokenIterator|string $tokens
@param array $additional
@param bool $embedded
@return Tokens
@throws \InvalidArgumentException | [
"Parses",
"source",
"and",
"removes",
"wrong",
"tokens",
"."
] | 6aac402b7fe0170edf3c5afbae652009951068af | https://github.com/kadet1090/KeyLighter/blob/6aac402b7fe0170edf3c5afbae652009951068af/Language/GreedyLanguage.php#L84-L94 | train |
GrupaZero/cms | src/Gzero/Cms/Policies/ContentPolicy.php | ContentPolicy.viewOnFrontend | public function viewOnFrontend(User $user, Content $content)
{
if ($content->canBeShown()) {
return true;
}
return ($content->author->id === $user->id);
} | php | public function viewOnFrontend(User $user, Content $content)
{
if ($content->canBeShown()) {
return true;
}
return ($content->author->id === $user->id);
} | [
"public",
"function",
"viewOnFrontend",
"(",
"User",
"$",
"user",
",",
"Content",
"$",
"content",
")",
"{",
"if",
"(",
"$",
"content",
"->",
"canBeShown",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"(",
"$",
"content",
"->",
"author",
... | Policy for viewing single unpublished element
@param User $user User trying to do it
@param Content $content Content that we're trying to update
@return boolean | [
"Policy",
"for",
"viewing",
"single",
"unpublished",
"element"
] | a7956966d2edec54fc99ebb61eeb2f01704aa2c2 | https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Policies/ContentPolicy.php#L84-L90 | train |
Rareloop/primer-core | src/Primer/Renderable/Pattern.php | Pattern.render | public function render($showChrome = true)
{
$html = $this->template->render($this->data);
// Tidy the HTML
$parser = new Parser();
$html = $parser->indent($html);
if ($showChrome) {
return View::render('pattern', [
'title' => $this->title,
'id' => $this->id,
'html' => $html,
'template' => $this->templateRaw,
'copy' => $this->copy,
'data' => json_encode($this->data, JSON_PRETTY_PRINT),
]);
} else {
return $html;
}
} | php | public function render($showChrome = true)
{
$html = $this->template->render($this->data);
// Tidy the HTML
$parser = new Parser();
$html = $parser->indent($html);
if ($showChrome) {
return View::render('pattern', [
'title' => $this->title,
'id' => $this->id,
'html' => $html,
'template' => $this->templateRaw,
'copy' => $this->copy,
'data' => json_encode($this->data, JSON_PRETTY_PRINT),
]);
} else {
return $html;
}
} | [
"public",
"function",
"render",
"(",
"$",
"showChrome",
"=",
"true",
")",
"{",
"$",
"html",
"=",
"$",
"this",
"->",
"template",
"->",
"render",
"(",
"$",
"this",
"->",
"data",
")",
";",
"// Tidy the HTML",
"$",
"parser",
"=",
"new",
"Parser",
"(",
")... | Renders the pattern
@param boolean $showChrome Whether or not the item should render descriptive chrome
@return String HTML text | [
"Renders",
"the",
"pattern"
] | fe098d6794a4add368f97672397dc93d223a1786 | https://github.com/Rareloop/primer-core/blob/fe098d6794a4add368f97672397dc93d223a1786/src/Primer/Renderable/Pattern.php#L132-L152 | train |
Rareloop/primer-core | src/Primer/Renderable/Pattern.php | Pattern.loadPatternsInPath | public static function loadPatternsInPath($path)
{
$patterns = array();
if ($handle = opendir($path)) {
while (false !== ($entry = readdir($handle))) {
$fullPath = $path . '/' . $entry;
if ($entry != '..' && $entry != '.' && is_dir($fullPath)) {
$id = trim(str_replace(Primer::$PATTERN_PATH, '', $fullPath), '/');
// Load the pattern
$patterns[] = new Pattern($id);
}
}
closedir($handle);
}
return $patterns;
} | php | public static function loadPatternsInPath($path)
{
$patterns = array();
if ($handle = opendir($path)) {
while (false !== ($entry = readdir($handle))) {
$fullPath = $path . '/' . $entry;
if ($entry != '..' && $entry != '.' && is_dir($fullPath)) {
$id = trim(str_replace(Primer::$PATTERN_PATH, '', $fullPath), '/');
// Load the pattern
$patterns[] = new Pattern($id);
}
}
closedir($handle);
}
return $patterns;
} | [
"public",
"static",
"function",
"loadPatternsInPath",
"(",
"$",
"path",
")",
"{",
"$",
"patterns",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"handle",
"=",
"opendir",
"(",
"$",
"path",
")",
")",
"{",
"while",
"(",
"false",
"!==",
"(",
"$",
"entr... | Helper function to load all patterns in a folder
@param String $path The path of the directory to load from
@return Array Array of all patterns loaded | [
"Helper",
"function",
"to",
"load",
"all",
"patterns",
"in",
"a",
"folder"
] | fe098d6794a4add368f97672397dc93d223a1786 | https://github.com/Rareloop/primer-core/blob/fe098d6794a4add368f97672397dc93d223a1786/src/Primer/Renderable/Pattern.php#L162-L182 | train |
locomotivemtl/charcoal-user | src/Charcoal/User/Authenticator.php | Authenticator.authenticate | public function authenticate()
{
$u = $this->authenticateBySession();
if ($u) {
return $u;
}
$u = $this->authenticateByToken();
if ($u) {
return $u;
}
return null;
} | php | public function authenticate()
{
$u = $this->authenticateBySession();
if ($u) {
return $u;
}
$u = $this->authenticateByToken();
if ($u) {
return $u;
}
return null;
} | [
"public",
"function",
"authenticate",
"(",
")",
"{",
"$",
"u",
"=",
"$",
"this",
"->",
"authenticateBySession",
"(",
")",
";",
"if",
"(",
"$",
"u",
")",
"{",
"return",
"$",
"u",
";",
"}",
"$",
"u",
"=",
"$",
"this",
"->",
"authenticateByToken",
"("... | Determine if the current user is authenticated.
The user is authenticated via _session ID_ or _auth token_.
@return \Charcoal\User\UserInterface|null Returns the authenticated user object
or NULL if not authenticated. | [
"Determine",
"if",
"the",
"current",
"user",
"is",
"authenticated",
"."
] | 86405a592379ebc2b77a7a9a7f68a85f2afe85f0 | https://github.com/locomotivemtl/charcoal-user/blob/86405a592379ebc2b77a7a9a7f68a85f2afe85f0/src/Charcoal/User/Authenticator.php#L81-L94 | train |
locomotivemtl/charcoal-user | src/Charcoal/User/Authenticator.php | Authenticator.authenticateBySession | private function authenticateBySession()
{
$u = $this->userFactory()->create($this->userType());
// Call static method on user
$u = call_user_func([get_class($u), 'getAuthenticated'], $this->userFactory());
if ($u && $u->id()) {
$u->saveToSession();
return $u;
} else {
return null;
}
} | php | private function authenticateBySession()
{
$u = $this->userFactory()->create($this->userType());
// Call static method on user
$u = call_user_func([get_class($u), 'getAuthenticated'], $this->userFactory());
if ($u && $u->id()) {
$u->saveToSession();
return $u;
} else {
return null;
}
} | [
"private",
"function",
"authenticateBySession",
"(",
")",
"{",
"$",
"u",
"=",
"$",
"this",
"->",
"userFactory",
"(",
")",
"->",
"create",
"(",
"$",
"this",
"->",
"userType",
"(",
")",
")",
";",
"// Call static method on user",
"$",
"u",
"=",
"call_user_fun... | Attempt to authenticate a user using their session ID.
@return \Charcoal\User\UserInterface|null Returns the authenticated user object
or NULL if not authenticated. | [
"Attempt",
"to",
"authenticate",
"a",
"user",
"using",
"their",
"session",
"ID",
"."
] | 86405a592379ebc2b77a7a9a7f68a85f2afe85f0 | https://github.com/locomotivemtl/charcoal-user/blob/86405a592379ebc2b77a7a9a7f68a85f2afe85f0/src/Charcoal/User/Authenticator.php#L269-L282 | train |
locomotivemtl/charcoal-user | src/Charcoal/User/Authenticator.php | Authenticator.authenticateByToken | private function authenticateByToken()
{
$tokenType = $this->tokenType();
$authToken = $this->tokenFactory()->create($tokenType);
if ($authToken->metadata()->enabled() !== true) {
return null;
}
$tokenData = $authToken->getTokenDataFromCookie();
if (!$tokenData) {
return null;
}
$userId = $authToken->getUserIdFromToken($tokenData['ident'], $tokenData['token']);
if (!$userId) {
return null;
}
$u = $this->userFactory()->create($this->userType());
$u->load($userId);
if ($u->id()) {
$u->saveToSession();
return $u;
} else {
return null;
}
} | php | private function authenticateByToken()
{
$tokenType = $this->tokenType();
$authToken = $this->tokenFactory()->create($tokenType);
if ($authToken->metadata()->enabled() !== true) {
return null;
}
$tokenData = $authToken->getTokenDataFromCookie();
if (!$tokenData) {
return null;
}
$userId = $authToken->getUserIdFromToken($tokenData['ident'], $tokenData['token']);
if (!$userId) {
return null;
}
$u = $this->userFactory()->create($this->userType());
$u->load($userId);
if ($u->id()) {
$u->saveToSession();
return $u;
} else {
return null;
}
} | [
"private",
"function",
"authenticateByToken",
"(",
")",
"{",
"$",
"tokenType",
"=",
"$",
"this",
"->",
"tokenType",
"(",
")",
";",
"$",
"authToken",
"=",
"$",
"this",
"->",
"tokenFactory",
"(",
")",
"->",
"create",
"(",
"$",
"tokenType",
")",
";",
"if"... | Attempt to authenticate a user using their auth token.
@return \Charcoal\User\UserInterface|null Returns the authenticated user object
or NULL if not authenticated. | [
"Attempt",
"to",
"authenticate",
"a",
"user",
"using",
"their",
"auth",
"token",
"."
] | 86405a592379ebc2b77a7a9a7f68a85f2afe85f0 | https://github.com/locomotivemtl/charcoal-user/blob/86405a592379ebc2b77a7a9a7f68a85f2afe85f0/src/Charcoal/User/Authenticator.php#L290-L317 | train |
GrupaZero/cms | src/Gzero/Cms/Models/Block.php | Block.files | public function files($active = true)
{
$query = $this->morphToMany(File::class, 'uploadable')
->with('translations')
->withPivot('weight')
->orderBy('weight', 'ASC')
->withTimestamps();
if ($active) {
$query->where('is_active', '=', 1);
}
return $query;
} | php | public function files($active = true)
{
$query = $this->morphToMany(File::class, 'uploadable')
->with('translations')
->withPivot('weight')
->orderBy('weight', 'ASC')
->withTimestamps();
if ($active) {
$query->where('is_active', '=', 1);
}
return $query;
} | [
"public",
"function",
"files",
"(",
"$",
"active",
"=",
"true",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"morphToMany",
"(",
"File",
"::",
"class",
",",
"'uploadable'",
")",
"->",
"with",
"(",
"'translations'",
")",
"->",
"withPivot",
"(",
"'wei... | Get all of the files for the content.
@param bool $active Only active file
@return \Illuminate\Database\Eloquent\Relations\BelongsToMany|\Illuminate\Database\Eloquent\Relations\morphToMany | [
"Get",
"all",
"of",
"the",
"files",
"for",
"the",
"content",
"."
] | a7956966d2edec54fc99ebb61eeb2f01704aa2c2 | https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Models/Block.php#L85-L98 | train |
GrupaZero/cms | src/Gzero/Cms/Models/Block.php | Block.getActiveTranslation | public function getActiveTranslation($languageCode)
{
return $this->translations->first(function ($translation) use ($languageCode) {
return $translation->is_active === true && $translation->language_code === $languageCode;
});
} | php | public function getActiveTranslation($languageCode)
{
return $this->translations->first(function ($translation) use ($languageCode) {
return $translation->is_active === true && $translation->language_code === $languageCode;
});
} | [
"public",
"function",
"getActiveTranslation",
"(",
"$",
"languageCode",
")",
"{",
"return",
"$",
"this",
"->",
"translations",
"->",
"first",
"(",
"function",
"(",
"$",
"translation",
")",
"use",
"(",
"$",
"languageCode",
")",
"{",
"return",
"$",
"translatio... | Returns active translation in specific language
@param string $languageCode Language code
@return mixed | [
"Returns",
"active",
"translation",
"in",
"specific",
"language"
] | a7956966d2edec54fc99ebb61eeb2f01704aa2c2 | https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Models/Block.php#L150-L155 | train |
GrupaZero/cms | src/Gzero/Cms/Models/Block.php | Block.setFilterAttribute | public function setFilterAttribute($value)
{
return ($value) ? $this->attributes['filter'] = json_encode($value) : $this->attributes['filter'] = null;
} | php | public function setFilterAttribute($value)
{
return ($value) ? $this->attributes['filter'] = json_encode($value) : $this->attributes['filter'] = null;
} | [
"public",
"function",
"setFilterAttribute",
"(",
"$",
"value",
")",
"{",
"return",
"(",
"$",
"value",
")",
"?",
"$",
"this",
"->",
"attributes",
"[",
"'filter'",
"]",
"=",
"json_encode",
"(",
"$",
"value",
")",
":",
"$",
"this",
"->",
"attributes",
"["... | Set the filter value
@param string $value filter value
@return string | [
"Set",
"the",
"filter",
"value"
] | a7956966d2edec54fc99ebb61eeb2f01704aa2c2 | https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Models/Block.php#L174-L177 | train |
GrupaZero/cms | src/Gzero/Cms/Models/Block.php | Block.setOptionsAttribute | public function setOptionsAttribute($value)
{
return ($value) ? $this->attributes['options'] = json_encode($value) : $this->attributes['options'] = null;
} | php | public function setOptionsAttribute($value)
{
return ($value) ? $this->attributes['options'] = json_encode($value) : $this->attributes['options'] = null;
} | [
"public",
"function",
"setOptionsAttribute",
"(",
"$",
"value",
")",
"{",
"return",
"(",
"$",
"value",
")",
"?",
"$",
"this",
"->",
"attributes",
"[",
"'options'",
"]",
"=",
"json_encode",
"(",
"$",
"value",
")",
":",
"$",
"this",
"->",
"attributes",
"... | Set the options value
@param string $value filter value
@return string | [
"Set",
"the",
"options",
"value"
] | a7956966d2edec54fc99ebb61eeb2f01704aa2c2 | https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Models/Block.php#L198-L201 | train |
jon48/webtrees-lib | src/Webtrees/Mvc/View/ViewBag.php | ViewBag.set | public function set($key, $value, $override = true) {
if(is_null($key)) return;
if(!$override && array_key_exists($key, $this->data)) return;
$this->data[$key] = $value;
} | php | public function set($key, $value, $override = true) {
if(is_null($key)) return;
if(!$override && array_key_exists($key, $this->data)) return;
$this->data[$key] = $value;
} | [
"public",
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"override",
"=",
"true",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"key",
")",
")",
"return",
";",
"if",
"(",
"!",
"$",
"override",
"&&",
"array_key_exists",
"(",
"$",
"ke... | Set the value for the specified key.
Can define whether to override an existing value;
@param string $key
@param mixed $value
@param bool $override | [
"Set",
"the",
"value",
"for",
"the",
"specified",
"key",
".",
"Can",
"define",
"whether",
"to",
"override",
"an",
"existing",
"value",
";"
] | e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7 | https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Mvc/View/ViewBag.php#L75-L79 | train |
GrupaZero/cms | src/Gzero/Cms/BlockFinder.php | BlockFinder.getBlocksIds | public function getBlocksIds($routable, $onlyActive = false)
{
return $this->findBlocksForPath($routable, $this->getFilterArray($onlyActive));
} | php | public function getBlocksIds($routable, $onlyActive = false)
{
return $this->findBlocksForPath($routable, $this->getFilterArray($onlyActive));
} | [
"public",
"function",
"getBlocksIds",
"(",
"$",
"routable",
",",
"$",
"onlyActive",
"=",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"findBlocksForPath",
"(",
"$",
"routable",
",",
"$",
"this",
"->",
"getFilterArray",
"(",
"$",
"onlyActive",
")",
")",
... | It returns blocks ids that should be displayed on specified content
@param string|Routable $routable Routable
@param bool $onlyActive Trigger to display only active blocks
@return array | [
"It",
"returns",
"blocks",
"ids",
"that",
"should",
"be",
"displayed",
"on",
"specified",
"content"
] | a7956966d2edec54fc99ebb61eeb2f01704aa2c2 | https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/BlockFinder.php#L41-L44 | train |
GrupaZero/cms | src/Gzero/Cms/BlockFinder.php | BlockFinder.findBlocksForPath | protected function findBlocksForPath($routable, $filter)
{
if (is_string($routable)) { // static page like "home", "contact" etc.
return $this->handleStaticPageCase($routable, $filter);
}
$ids = $routable->getTreePath();
$idsCount = count($ids);
$blockIds = [];
if ($idsCount === 1) { // Root case
$allIds = [];
$rootPath = $ids[0] . '/';
if (isset($filter['paths'][$rootPath])) {
$allIds = $filter['paths'][$rootPath];
}
// We're returning only blocks ids that uses filter property
$blockIds = array_keys($allIds + $filter['excluded'], true, true);
} else {
$allIds = [];
$parentPath = '';
foreach ($ids as $index => $id) {
$parentPath .= $id . '/';
$pathMatch = ($index + 1 < $idsCount) ? $parentPath . '*' : $parentPath;
if (isset($filter['paths'][$pathMatch])) {
// Order of operation is important! We want to override $allIds be lower level filter (left overrides right)
$allIds = $filter['paths'][$pathMatch] + $allIds;
}
}
// We're returning only blocks ids that uses filter property
$blockIds = array_keys($allIds + $filter['excluded'], true, true);
}
return $blockIds;
} | php | protected function findBlocksForPath($routable, $filter)
{
if (is_string($routable)) { // static page like "home", "contact" etc.
return $this->handleStaticPageCase($routable, $filter);
}
$ids = $routable->getTreePath();
$idsCount = count($ids);
$blockIds = [];
if ($idsCount === 1) { // Root case
$allIds = [];
$rootPath = $ids[0] . '/';
if (isset($filter['paths'][$rootPath])) {
$allIds = $filter['paths'][$rootPath];
}
// We're returning only blocks ids that uses filter property
$blockIds = array_keys($allIds + $filter['excluded'], true, true);
} else {
$allIds = [];
$parentPath = '';
foreach ($ids as $index => $id) {
$parentPath .= $id . '/';
$pathMatch = ($index + 1 < $idsCount) ? $parentPath . '*' : $parentPath;
if (isset($filter['paths'][$pathMatch])) {
// Order of operation is important! We want to override $allIds be lower level filter (left overrides right)
$allIds = $filter['paths'][$pathMatch] + $allIds;
}
}
// We're returning only blocks ids that uses filter property
$blockIds = array_keys($allIds + $filter['excluded'], true, true);
}
return $blockIds;
} | [
"protected",
"function",
"findBlocksForPath",
"(",
"$",
"routable",
",",
"$",
"filter",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"routable",
")",
")",
"{",
"// static page like \"home\", \"contact\" etc.",
"return",
"$",
"this",
"->",
"handleStaticPageCase",
"(... | Find all blocks ids that should be displayed on specific path
@param string|Routable $routable Routable path or static page named route
@param array $filter Array with all filters
@return array | [
"Find",
"all",
"blocks",
"ids",
"that",
"should",
"be",
"displayed",
"on",
"specific",
"path"
] | a7956966d2edec54fc99ebb61eeb2f01704aa2c2 | https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/BlockFinder.php#L54-L85 | train |
GrupaZero/cms | src/Gzero/Cms/BlockFinder.php | BlockFinder.getFilterArray | protected function getFilterArray($onlyActive)
{
$cacheKey = ($onlyActive) ? 'public' : 'admin';
if ($this->cache->tags(['blocks'])->has('blocks:filter:' . $cacheKey)) {
return $this->cache->tags(['blocks'])->get('blocks:filter:' . $cacheKey);
} else {
$blocks = $this->blockRepository->getBlocksWithFilter($onlyActive);
$filter = $this->buildFilterArray($blocks);
$this->cache->tags(['blocks'])->forever('blocks:filter:' . $cacheKey, $filter);
return $filter;
}
} | php | protected function getFilterArray($onlyActive)
{
$cacheKey = ($onlyActive) ? 'public' : 'admin';
if ($this->cache->tags(['blocks'])->has('blocks:filter:' . $cacheKey)) {
return $this->cache->tags(['blocks'])->get('blocks:filter:' . $cacheKey);
} else {
$blocks = $this->blockRepository->getBlocksWithFilter($onlyActive);
$filter = $this->buildFilterArray($blocks);
$this->cache->tags(['blocks'])->forever('blocks:filter:' . $cacheKey, $filter);
return $filter;
}
} | [
"protected",
"function",
"getFilterArray",
"(",
"$",
"onlyActive",
")",
"{",
"$",
"cacheKey",
"=",
"(",
"$",
"onlyActive",
")",
"?",
"'public'",
":",
"'admin'",
";",
"if",
"(",
"$",
"this",
"->",
"cache",
"->",
"tags",
"(",
"[",
"'blocks'",
"]",
")",
... | It builds filter array with all blocks
@param bool $onlyActive Filter only public blocks
@return array | [
"It",
"builds",
"filter",
"array",
"with",
"all",
"blocks"
] | a7956966d2edec54fc99ebb61eeb2f01704aa2c2 | https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/BlockFinder.php#L94-L105 | train |
GrupaZero/cms | src/Gzero/Cms/BlockFinder.php | BlockFinder.buildFilterArray | protected function buildFilterArray($blocks)
{
$filter = [];
$excluded = [];
foreach ($blocks as $block) {
$this->extractFilter($block, $filter, $excluded);
}
return ['paths' => $filter, 'excluded' => $excluded];
} | php | protected function buildFilterArray($blocks)
{
$filter = [];
$excluded = [];
foreach ($blocks as $block) {
$this->extractFilter($block, $filter, $excluded);
}
return ['paths' => $filter, 'excluded' => $excluded];
} | [
"protected",
"function",
"buildFilterArray",
"(",
"$",
"blocks",
")",
"{",
"$",
"filter",
"=",
"[",
"]",
";",
"$",
"excluded",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"blocks",
"as",
"$",
"block",
")",
"{",
"$",
"this",
"->",
"extractFilter",
"(",
... | It extracts all filters from blocks & build filter array
@param array|Collection $blocks Blocks
@return array | [
"It",
"extracts",
"all",
"filters",
"from",
"blocks",
"&",
"build",
"filter",
"array"
] | a7956966d2edec54fc99ebb61eeb2f01704aa2c2 | https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/BlockFinder.php#L114-L122 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.