id
int32 0
241k
| 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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
229,400
|
milesj/utility
|
View/Helper/UtilityHelper.php
|
UtilityHelper.enum
|
public function enum($model, $field, $value = null, $domain = null) {
$enum = ClassRegistry::init($model)->enum($field);
list($plugin, $model) = pluginSplit($model);
// Set domain
if (!$domain) {
if ($plugin) {
$domain = Inflector::underscore($plugin);
} else {
$domain = 'default';
}
}
// Cache the translations
$key = Inflector::underscore($model) . '.' . Inflector::underscore($field);
$cache = $key . '.enum';
if (isset($this->_cached[$cache])) {
$enum = $this->_cached[$cache];
} else {
foreach ($enum as $k => &$v) {
$message = __d($domain, $key . '.' . $k);
// Only use message if a translation exists
if ($message !== $key . '.' . $k) {
$v = $message;
}
}
$this->_cached[$cache] = $enum;
}
// Filter down by value
if ($value !== null) {
return isset($enum[$value]) ? $enum[$value] : null;
}
return $enum;
}
|
php
|
public function enum($model, $field, $value = null, $domain = null) {
$enum = ClassRegistry::init($model)->enum($field);
list($plugin, $model) = pluginSplit($model);
// Set domain
if (!$domain) {
if ($plugin) {
$domain = Inflector::underscore($plugin);
} else {
$domain = 'default';
}
}
// Cache the translations
$key = Inflector::underscore($model) . '.' . Inflector::underscore($field);
$cache = $key . '.enum';
if (isset($this->_cached[$cache])) {
$enum = $this->_cached[$cache];
} else {
foreach ($enum as $k => &$v) {
$message = __d($domain, $key . '.' . $k);
// Only use message if a translation exists
if ($message !== $key . '.' . $k) {
$v = $message;
}
}
$this->_cached[$cache] = $enum;
}
// Filter down by value
if ($value !== null) {
return isset($enum[$value]) ? $enum[$value] : null;
}
return $enum;
}
|
[
"public",
"function",
"enum",
"(",
"$",
"model",
",",
"$",
"field",
",",
"$",
"value",
"=",
"null",
",",
"$",
"domain",
"=",
"null",
")",
"{",
"$",
"enum",
"=",
"ClassRegistry",
"::",
"init",
"(",
"$",
"model",
")",
"->",
"enum",
"(",
"$",
"field",
")",
";",
"list",
"(",
"$",
"plugin",
",",
"$",
"model",
")",
"=",
"pluginSplit",
"(",
"$",
"model",
")",
";",
"// Set domain\r",
"if",
"(",
"!",
"$",
"domain",
")",
"{",
"if",
"(",
"$",
"plugin",
")",
"{",
"$",
"domain",
"=",
"Inflector",
"::",
"underscore",
"(",
"$",
"plugin",
")",
";",
"}",
"else",
"{",
"$",
"domain",
"=",
"'default'",
";",
"}",
"}",
"// Cache the translations\r",
"$",
"key",
"=",
"Inflector",
"::",
"underscore",
"(",
"$",
"model",
")",
".",
"'.'",
".",
"Inflector",
"::",
"underscore",
"(",
"$",
"field",
")",
";",
"$",
"cache",
"=",
"$",
"key",
".",
"'.enum'",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_cached",
"[",
"$",
"cache",
"]",
")",
")",
"{",
"$",
"enum",
"=",
"$",
"this",
"->",
"_cached",
"[",
"$",
"cache",
"]",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"enum",
"as",
"$",
"k",
"=>",
"&",
"$",
"v",
")",
"{",
"$",
"message",
"=",
"__d",
"(",
"$",
"domain",
",",
"$",
"key",
".",
"'.'",
".",
"$",
"k",
")",
";",
"// Only use message if a translation exists\r",
"if",
"(",
"$",
"message",
"!==",
"$",
"key",
".",
"'.'",
".",
"$",
"k",
")",
"{",
"$",
"v",
"=",
"$",
"message",
";",
"}",
"}",
"$",
"this",
"->",
"_cached",
"[",
"$",
"cache",
"]",
"=",
"$",
"enum",
";",
"}",
"// Filter down by value\r",
"if",
"(",
"$",
"value",
"!==",
"null",
")",
"{",
"return",
"isset",
"(",
"$",
"enum",
"[",
"$",
"value",
"]",
")",
"?",
"$",
"enum",
"[",
"$",
"value",
"]",
":",
"null",
";",
"}",
"return",
"$",
"enum",
";",
"}"
] |
Retrieve an enum list for a Models field and translate the values.
@param string $model
@param string $field
@param mixed $value
@param string $domain
@return string|array
|
[
"Retrieve",
"an",
"enum",
"list",
"for",
"a",
"Models",
"field",
"and",
"translate",
"the",
"values",
"."
] |
146318ff0a882917defab7f4918b0d198eb5a3c0
|
https://github.com/milesj/utility/blob/146318ff0a882917defab7f4918b0d198eb5a3c0/View/Helper/UtilityHelper.php#L35-L75
|
229,401
|
milesj/utility
|
View/Helper/UtilityHelper.php
|
UtilityHelper.gravatar
|
public function gravatar($email, array $options = array(), array $attributes = array()) {
$options = $options + array(
'default' => 'mm',
'size' => 80,
'rating' => 'g',
'hash' => 'md5',
'secure' => env('HTTPS')
);
$email = Security::hash(strtolower(trim($email)), $options['hash']);
$query = array();
if ($options['secure']) {
$image = 'https://secure.gravatar.com/avatar/' . $email;
} else {
$image = 'http://www.gravatar.com/avatar/' . $email;
}
foreach (array('default' => 'd', 'size' => 's', 'rating' => 'r') as $key => $param) {
$query[] = $param . '=' . urlencode($options[$key]);
}
$image .= '?' . implode('&', $query);
return $this->Html->image($image, $attributes);
}
|
php
|
public function gravatar($email, array $options = array(), array $attributes = array()) {
$options = $options + array(
'default' => 'mm',
'size' => 80,
'rating' => 'g',
'hash' => 'md5',
'secure' => env('HTTPS')
);
$email = Security::hash(strtolower(trim($email)), $options['hash']);
$query = array();
if ($options['secure']) {
$image = 'https://secure.gravatar.com/avatar/' . $email;
} else {
$image = 'http://www.gravatar.com/avatar/' . $email;
}
foreach (array('default' => 'd', 'size' => 's', 'rating' => 'r') as $key => $param) {
$query[] = $param . '=' . urlencode($options[$key]);
}
$image .= '?' . implode('&', $query);
return $this->Html->image($image, $attributes);
}
|
[
"public",
"function",
"gravatar",
"(",
"$",
"email",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
",",
"array",
"$",
"attributes",
"=",
"array",
"(",
")",
")",
"{",
"$",
"options",
"=",
"$",
"options",
"+",
"array",
"(",
"'default'",
"=>",
"'mm'",
",",
"'size'",
"=>",
"80",
",",
"'rating'",
"=>",
"'g'",
",",
"'hash'",
"=>",
"'md5'",
",",
"'secure'",
"=>",
"env",
"(",
"'HTTPS'",
")",
")",
";",
"$",
"email",
"=",
"Security",
"::",
"hash",
"(",
"strtolower",
"(",
"trim",
"(",
"$",
"email",
")",
")",
",",
"$",
"options",
"[",
"'hash'",
"]",
")",
";",
"$",
"query",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'secure'",
"]",
")",
"{",
"$",
"image",
"=",
"'https://secure.gravatar.com/avatar/'",
".",
"$",
"email",
";",
"}",
"else",
"{",
"$",
"image",
"=",
"'http://www.gravatar.com/avatar/'",
".",
"$",
"email",
";",
"}",
"foreach",
"(",
"array",
"(",
"'default'",
"=>",
"'d'",
",",
"'size'",
"=>",
"'s'",
",",
"'rating'",
"=>",
"'r'",
")",
"as",
"$",
"key",
"=>",
"$",
"param",
")",
"{",
"$",
"query",
"[",
"]",
"=",
"$",
"param",
".",
"'='",
".",
"urlencode",
"(",
"$",
"options",
"[",
"$",
"key",
"]",
")",
";",
"}",
"$",
"image",
".=",
"'?'",
".",
"implode",
"(",
"'&'",
",",
"$",
"query",
")",
";",
"return",
"$",
"this",
"->",
"Html",
"->",
"image",
"(",
"$",
"image",
",",
"$",
"attributes",
")",
";",
"}"
] |
Render out a gravatar thumbnail based on an email.
@param string $email
@param array $options
@param array $attributes
@return string
|
[
"Render",
"out",
"a",
"gravatar",
"thumbnail",
"based",
"on",
"an",
"email",
"."
] |
146318ff0a882917defab7f4918b0d198eb5a3c0
|
https://github.com/milesj/utility/blob/146318ff0a882917defab7f4918b0d198eb5a3c0/View/Helper/UtilityHelper.php#L85-L110
|
229,402
|
mustafaaloko/elasticquent5
|
src/ElasticquentTrait.php
|
ElasticquentTrait.getElasticSearchClient
|
public function getElasticSearchClient()
{
$config = [];
if (\Config::has('elasticquent.config')) {
$config = \Config::get('elasticquent.config');
}
return new \Elasticsearch\Client($config);
}
|
php
|
public function getElasticSearchClient()
{
$config = [];
if (\Config::has('elasticquent.config')) {
$config = \Config::get('elasticquent.config');
}
return new \Elasticsearch\Client($config);
}
|
[
"public",
"function",
"getElasticSearchClient",
"(",
")",
"{",
"$",
"config",
"=",
"[",
"]",
";",
"if",
"(",
"\\",
"Config",
"::",
"has",
"(",
"'elasticquent.config'",
")",
")",
"{",
"$",
"config",
"=",
"\\",
"Config",
"::",
"get",
"(",
"'elasticquent.config'",
")",
";",
"}",
"return",
"new",
"\\",
"Elasticsearch",
"\\",
"Client",
"(",
"$",
"config",
")",
";",
"}"
] |
Get ElasticSearch Client.
@return \Elasticsearch\Client
|
[
"Get",
"ElasticSearch",
"Client",
"."
] |
63975ab98c786c58dc241f922e3126a192cbe294
|
https://github.com/mustafaaloko/elasticquent5/blob/63975ab98c786c58dc241f922e3126a192cbe294/src/ElasticquentTrait.php#L56-L65
|
229,403
|
mustafaaloko/elasticquent5
|
src/ElasticquentTrait.php
|
ElasticquentTrait.getBasicEsParams
|
public function getBasicEsParams($getIdIfPossible = true, $getSourceIfPossible = false, $getTimestampIfPossible = false, $limit = null, $offset = null)
{
$params = [
'index' => $this->getIndexName(),
'type' => $this->getTypeName(),
];
if ($getIdIfPossible and $this->getKey()) {
$params['id'] = $this->getKey();
}
$fieldsParam = [];
if ($getSourceIfPossible) {
array_push($fieldsParam, '_source');
}
if ($getTimestampIfPossible) {
array_push($fieldsParam, '_timestamp');
}
if ($fieldsParam) {
$params['fields'] = implode(',', $fieldsParam);
}
if (is_numeric($limit)) {
$params['size'] = $limit;
}
if (is_numeric($offset)) {
$params['from'] = $offset;
}
return $params;
}
|
php
|
public function getBasicEsParams($getIdIfPossible = true, $getSourceIfPossible = false, $getTimestampIfPossible = false, $limit = null, $offset = null)
{
$params = [
'index' => $this->getIndexName(),
'type' => $this->getTypeName(),
];
if ($getIdIfPossible and $this->getKey()) {
$params['id'] = $this->getKey();
}
$fieldsParam = [];
if ($getSourceIfPossible) {
array_push($fieldsParam, '_source');
}
if ($getTimestampIfPossible) {
array_push($fieldsParam, '_timestamp');
}
if ($fieldsParam) {
$params['fields'] = implode(',', $fieldsParam);
}
if (is_numeric($limit)) {
$params['size'] = $limit;
}
if (is_numeric($offset)) {
$params['from'] = $offset;
}
return $params;
}
|
[
"public",
"function",
"getBasicEsParams",
"(",
"$",
"getIdIfPossible",
"=",
"true",
",",
"$",
"getSourceIfPossible",
"=",
"false",
",",
"$",
"getTimestampIfPossible",
"=",
"false",
",",
"$",
"limit",
"=",
"null",
",",
"$",
"offset",
"=",
"null",
")",
"{",
"$",
"params",
"=",
"[",
"'index'",
"=>",
"$",
"this",
"->",
"getIndexName",
"(",
")",
",",
"'type'",
"=>",
"$",
"this",
"->",
"getTypeName",
"(",
")",
",",
"]",
";",
"if",
"(",
"$",
"getIdIfPossible",
"and",
"$",
"this",
"->",
"getKey",
"(",
")",
")",
"{",
"$",
"params",
"[",
"'id'",
"]",
"=",
"$",
"this",
"->",
"getKey",
"(",
")",
";",
"}",
"$",
"fieldsParam",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"getSourceIfPossible",
")",
"{",
"array_push",
"(",
"$",
"fieldsParam",
",",
"'_source'",
")",
";",
"}",
"if",
"(",
"$",
"getTimestampIfPossible",
")",
"{",
"array_push",
"(",
"$",
"fieldsParam",
",",
"'_timestamp'",
")",
";",
"}",
"if",
"(",
"$",
"fieldsParam",
")",
"{",
"$",
"params",
"[",
"'fields'",
"]",
"=",
"implode",
"(",
"','",
",",
"$",
"fieldsParam",
")",
";",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"limit",
")",
")",
"{",
"$",
"params",
"[",
"'size'",
"]",
"=",
"$",
"limit",
";",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"offset",
")",
")",
"{",
"$",
"params",
"[",
"'from'",
"]",
"=",
"$",
"offset",
";",
"}",
"return",
"$",
"params",
";",
"}"
] |
Get Basic Elasticsearch Params.
Most Elasticsearch API calls need the index and
type passed in a parameter array.
@param bool $getIdIfPossible
@param bool $getSourceIfPossible
@param bool $getTimestampIfPossible
@param int $limit
@param int $offset
@return array
|
[
"Get",
"Basic",
"Elasticsearch",
"Params",
"."
] |
63975ab98c786c58dc241f922e3126a192cbe294
|
https://github.com/mustafaaloko/elasticquent5/blob/63975ab98c786c58dc241f922e3126a192cbe294/src/ElasticquentTrait.php#L362-L396
|
229,404
|
mustafaaloko/elasticquent5
|
src/ElasticquentTrait.php
|
ElasticquentTrait.getMapping
|
public static function getMapping()
{
$instance = new static();
$params = $instance->getBasicEsParams();
return $instance->getElasticSearchClient()->indices()->getMapping($params);
}
|
php
|
public static function getMapping()
{
$instance = new static();
$params = $instance->getBasicEsParams();
return $instance->getElasticSearchClient()->indices()->getMapping($params);
}
|
[
"public",
"static",
"function",
"getMapping",
"(",
")",
"{",
"$",
"instance",
"=",
"new",
"static",
"(",
")",
";",
"$",
"params",
"=",
"$",
"instance",
"->",
"getBasicEsParams",
"(",
")",
";",
"return",
"$",
"instance",
"->",
"getElasticSearchClient",
"(",
")",
"->",
"indices",
"(",
")",
"->",
"getMapping",
"(",
"$",
"params",
")",
";",
"}"
] |
Get Mapping.
@return void
|
[
"Get",
"Mapping",
"."
] |
63975ab98c786c58dc241f922e3126a192cbe294
|
https://github.com/mustafaaloko/elasticquent5/blob/63975ab98c786c58dc241f922e3126a192cbe294/src/ElasticquentTrait.php#L417-L424
|
229,405
|
mustafaaloko/elasticquent5
|
src/ElasticquentTrait.php
|
ElasticquentTrait.putMapping
|
public static function putMapping($ignoreConflicts = false)
{
$instance = new static();
$mapping = $instance->getBasicEsParams();
$params = [
'_source' => ['enabled' => true],
'properties' => $instance->getMappingProperties(),
];
$mapping['body'][$instance->getTypeName()] = $params;
return $instance->getElasticSearchClient()->indices()->putMapping($mapping);
}
|
php
|
public static function putMapping($ignoreConflicts = false)
{
$instance = new static();
$mapping = $instance->getBasicEsParams();
$params = [
'_source' => ['enabled' => true],
'properties' => $instance->getMappingProperties(),
];
$mapping['body'][$instance->getTypeName()] = $params;
return $instance->getElasticSearchClient()->indices()->putMapping($mapping);
}
|
[
"public",
"static",
"function",
"putMapping",
"(",
"$",
"ignoreConflicts",
"=",
"false",
")",
"{",
"$",
"instance",
"=",
"new",
"static",
"(",
")",
";",
"$",
"mapping",
"=",
"$",
"instance",
"->",
"getBasicEsParams",
"(",
")",
";",
"$",
"params",
"=",
"[",
"'_source'",
"=>",
"[",
"'enabled'",
"=>",
"true",
"]",
",",
"'properties'",
"=>",
"$",
"instance",
"->",
"getMappingProperties",
"(",
")",
",",
"]",
";",
"$",
"mapping",
"[",
"'body'",
"]",
"[",
"$",
"instance",
"->",
"getTypeName",
"(",
")",
"]",
"=",
"$",
"params",
";",
"return",
"$",
"instance",
"->",
"getElasticSearchClient",
"(",
")",
"->",
"indices",
"(",
")",
"->",
"putMapping",
"(",
"$",
"mapping",
")",
";",
"}"
] |
Put Mapping.
@param bool $ignoreConflicts
@return array
|
[
"Put",
"Mapping",
"."
] |
63975ab98c786c58dc241f922e3126a192cbe294
|
https://github.com/mustafaaloko/elasticquent5/blob/63975ab98c786c58dc241f922e3126a192cbe294/src/ElasticquentTrait.php#L433-L447
|
229,406
|
mustafaaloko/elasticquent5
|
src/ElasticquentTrait.php
|
ElasticquentTrait.createIndex
|
public static function createIndex($shards = null, $replicas = null)
{
$instance = new static();
$client = $instance->getElasticSearchClient();
$index = [
'index' => $instance->getIndexName(),
];
if ($shards) {
$index['body']['settings']['number_of_shards'] = $shards;
}
if ($replicas) {
$index['body']['settings']['number_of_replicas'] = $replicas;
}
return $client->indices()->create($index);
}
|
php
|
public static function createIndex($shards = null, $replicas = null)
{
$instance = new static();
$client = $instance->getElasticSearchClient();
$index = [
'index' => $instance->getIndexName(),
];
if ($shards) {
$index['body']['settings']['number_of_shards'] = $shards;
}
if ($replicas) {
$index['body']['settings']['number_of_replicas'] = $replicas;
}
return $client->indices()->create($index);
}
|
[
"public",
"static",
"function",
"createIndex",
"(",
"$",
"shards",
"=",
"null",
",",
"$",
"replicas",
"=",
"null",
")",
"{",
"$",
"instance",
"=",
"new",
"static",
"(",
")",
";",
"$",
"client",
"=",
"$",
"instance",
"->",
"getElasticSearchClient",
"(",
")",
";",
"$",
"index",
"=",
"[",
"'index'",
"=>",
"$",
"instance",
"->",
"getIndexName",
"(",
")",
",",
"]",
";",
"if",
"(",
"$",
"shards",
")",
"{",
"$",
"index",
"[",
"'body'",
"]",
"[",
"'settings'",
"]",
"[",
"'number_of_shards'",
"]",
"=",
"$",
"shards",
";",
"}",
"if",
"(",
"$",
"replicas",
")",
"{",
"$",
"index",
"[",
"'body'",
"]",
"[",
"'settings'",
"]",
"[",
"'number_of_replicas'",
"]",
"=",
"$",
"replicas",
";",
"}",
"return",
"$",
"client",
"->",
"indices",
"(",
")",
"->",
"create",
"(",
"$",
"index",
")",
";",
"}"
] |
Create Index.
@param int $shards
@param int $replicas
@return array
|
[
"Create",
"Index",
"."
] |
63975ab98c786c58dc241f922e3126a192cbe294
|
https://github.com/mustafaaloko/elasticquent5/blob/63975ab98c786c58dc241f922e3126a192cbe294/src/ElasticquentTrait.php#L494-L513
|
229,407
|
fecshop/yii2-fec
|
component/redisqueue/Queue.php
|
Queue.buildPrefix
|
public function buildPrefix($name = null)
{
if (empty($name)) {
$name = 'default';
} elseif ($name && preg_match('/[^[:alnum:]]/', $name)) {
$name = md5($name);
}
return $this->queuePrefix . ':' . $name;
}
|
php
|
public function buildPrefix($name = null)
{
if (empty($name)) {
$name = 'default';
} elseif ($name && preg_match('/[^[:alnum:]]/', $name)) {
$name = md5($name);
}
return $this->queuePrefix . ':' . $name;
}
|
[
"public",
"function",
"buildPrefix",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"$",
"name",
"=",
"'default'",
";",
"}",
"elseif",
"(",
"$",
"name",
"&&",
"preg_match",
"(",
"'/[^[:alnum:]]/'",
",",
"$",
"name",
")",
")",
"{",
"$",
"name",
"=",
"md5",
"(",
"$",
"name",
")",
";",
"}",
"return",
"$",
"this",
"->",
"queuePrefix",
".",
"':'",
".",
"$",
"name",
";",
"}"
] |
Builds queue prefix
@param string|null $name Queue name
@return string
|
[
"Builds",
"queue",
"prefix"
] |
fda0e381f931bc503e493bec90185162109018e6
|
https://github.com/fecshop/yii2-fec/blob/fda0e381f931bc503e493bec90185162109018e6/component/redisqueue/Queue.php#L19-L27
|
229,408
|
fecshop/yii2-fec
|
component/redisqueue/Queue.php
|
Queue.push
|
public function push($job, $data = null, $queue = null, $options = [])
{
return $this->pushInternal($this->createPayload($job, $data), $queue, $options);
}
|
php
|
public function push($job, $data = null, $queue = null, $options = [])
{
return $this->pushInternal($this->createPayload($job, $data), $queue, $options);
}
|
[
"public",
"function",
"push",
"(",
"$",
"job",
",",
"$",
"data",
"=",
"null",
",",
"$",
"queue",
"=",
"null",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"pushInternal",
"(",
"$",
"this",
"->",
"createPayload",
"(",
"$",
"job",
",",
"$",
"data",
")",
",",
"$",
"queue",
",",
"$",
"options",
")",
";",
"}"
] |
Push job to the queue
@param string $job Fully qualified class name of the job
@param mixed $data Data for the job
@param string|null $queue Queue name
@return string ID of the job
|
[
"Push",
"job",
"to",
"the",
"queue"
] |
fda0e381f931bc503e493bec90185162109018e6
|
https://github.com/fecshop/yii2-fec/blob/fda0e381f931bc503e493bec90185162109018e6/component/redisqueue/Queue.php#L36-L39
|
229,409
|
fecshop/yii2-fec
|
component/redisqueue/Queue.php
|
Queue.createPayload
|
protected function createPayload($job, $data)
{
$payload = [
'job' => $job,
'data' => $data
];
$payload = $this->setMeta($payload, 'id', $this->getRandomId());
return $payload;
}
|
php
|
protected function createPayload($job, $data)
{
$payload = [
'job' => $job,
'data' => $data
];
$payload = $this->setMeta($payload, 'id', $this->getRandomId());
return $payload;
}
|
[
"protected",
"function",
"createPayload",
"(",
"$",
"job",
",",
"$",
"data",
")",
"{",
"$",
"payload",
"=",
"[",
"'job'",
"=>",
"$",
"job",
",",
"'data'",
"=>",
"$",
"data",
"]",
";",
"$",
"payload",
"=",
"$",
"this",
"->",
"setMeta",
"(",
"$",
"payload",
",",
"'id'",
",",
"$",
"this",
"->",
"getRandomId",
"(",
")",
")",
";",
"return",
"$",
"payload",
";",
"}"
] |
Create job array
@param string $job Fully qualified class name of the job
@param mixed $data Data for the job
@return array
|
[
"Create",
"job",
"array"
] |
fda0e381f931bc503e493bec90185162109018e6
|
https://github.com/fecshop/yii2-fec/blob/fda0e381f931bc503e493bec90185162109018e6/component/redisqueue/Queue.php#L57-L65
|
229,410
|
fuelphp/common
|
src/Table/Render.php
|
Render.renderTable
|
public function renderTable(Table $table)
{
//Generate each row
$rows = $this->buildRows($table);
$headerRows = $this->buildHeaders($table);
$footerRows = $this->buildFooters($table);
return $this->container($table, $rows, $headerRows, $footerRows);
}
|
php
|
public function renderTable(Table $table)
{
//Generate each row
$rows = $this->buildRows($table);
$headerRows = $this->buildHeaders($table);
$footerRows = $this->buildFooters($table);
return $this->container($table, $rows, $headerRows, $footerRows);
}
|
[
"public",
"function",
"renderTable",
"(",
"Table",
"$",
"table",
")",
"{",
"//Generate each row",
"$",
"rows",
"=",
"$",
"this",
"->",
"buildRows",
"(",
"$",
"table",
")",
";",
"$",
"headerRows",
"=",
"$",
"this",
"->",
"buildHeaders",
"(",
"$",
"table",
")",
";",
"$",
"footerRows",
"=",
"$",
"this",
"->",
"buildFooters",
"(",
"$",
"table",
")",
";",
"return",
"$",
"this",
"->",
"container",
"(",
"$",
"table",
",",
"$",
"rows",
",",
"$",
"headerRows",
",",
"$",
"footerRows",
")",
";",
"}"
] |
Renders the given table into a string. Output depends on the subclass
@param Table $table
@return string
|
[
"Renders",
"the",
"given",
"table",
"into",
"a",
"string",
".",
"Output",
"depends",
"on",
"the",
"subclass"
] |
ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40
|
https://github.com/fuelphp/common/blob/ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40/src/Table/Render.php#L31-L41
|
229,411
|
fuelphp/common
|
src/Table/Render.php
|
Render.buildRows
|
protected function buildRows(Table $table)
{
//Generate each row
$rows = array();
foreach ( $table->getRows() as $row )
{
//Build the cells for each row
$cells = array();
foreach ( $row as $cell )
{
$cells[] = $this->cell($cell);
}
$rows[] = $this->row($row, $cells);
}
return $rows;
}
|
php
|
protected function buildRows(Table $table)
{
//Generate each row
$rows = array();
foreach ( $table->getRows() as $row )
{
//Build the cells for each row
$cells = array();
foreach ( $row as $cell )
{
$cells[] = $this->cell($cell);
}
$rows[] = $this->row($row, $cells);
}
return $rows;
}
|
[
"protected",
"function",
"buildRows",
"(",
"Table",
"$",
"table",
")",
"{",
"//Generate each row",
"$",
"rows",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"table",
"->",
"getRows",
"(",
")",
"as",
"$",
"row",
")",
"{",
"//Build the cells for each row",
"$",
"cells",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"row",
"as",
"$",
"cell",
")",
"{",
"$",
"cells",
"[",
"]",
"=",
"$",
"this",
"->",
"cell",
"(",
"$",
"cell",
")",
";",
"}",
"$",
"rows",
"[",
"]",
"=",
"$",
"this",
"->",
"row",
"(",
"$",
"row",
",",
"$",
"cells",
")",
";",
"}",
"return",
"$",
"rows",
";",
"}"
] |
Renders the main body rows for the table
@param Table $table
@return array
|
[
"Renders",
"the",
"main",
"body",
"rows",
"for",
"the",
"table"
] |
ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40
|
https://github.com/fuelphp/common/blob/ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40/src/Table/Render.php#L50-L69
|
229,412
|
fuelphp/common
|
src/Table/Render.php
|
Render.buildHeaders
|
protected function buildHeaders(Table $table)
{
//Generate each row
$rows = array();
foreach ( $table->getHeaderRows() as $row )
{
//Build the cells for each row
$cells = array();
foreach ( $row as $cell )
{
$cells[] = $this->headerCell($cell);
}
$rows[] = $this->headerRow($row, $cells);
}
return $rows;
}
|
php
|
protected function buildHeaders(Table $table)
{
//Generate each row
$rows = array();
foreach ( $table->getHeaderRows() as $row )
{
//Build the cells for each row
$cells = array();
foreach ( $row as $cell )
{
$cells[] = $this->headerCell($cell);
}
$rows[] = $this->headerRow($row, $cells);
}
return $rows;
}
|
[
"protected",
"function",
"buildHeaders",
"(",
"Table",
"$",
"table",
")",
"{",
"//Generate each row",
"$",
"rows",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"table",
"->",
"getHeaderRows",
"(",
")",
"as",
"$",
"row",
")",
"{",
"//Build the cells for each row",
"$",
"cells",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"row",
"as",
"$",
"cell",
")",
"{",
"$",
"cells",
"[",
"]",
"=",
"$",
"this",
"->",
"headerCell",
"(",
"$",
"cell",
")",
";",
"}",
"$",
"rows",
"[",
"]",
"=",
"$",
"this",
"->",
"headerRow",
"(",
"$",
"row",
",",
"$",
"cells",
")",
";",
"}",
"return",
"$",
"rows",
";",
"}"
] |
Renders the header rows for the table
@param Table $table
@return array
|
[
"Renders",
"the",
"header",
"rows",
"for",
"the",
"table"
] |
ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40
|
https://github.com/fuelphp/common/blob/ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40/src/Table/Render.php#L78-L97
|
229,413
|
fuelphp/common
|
src/Table/Render.php
|
Render.buildFooters
|
protected function buildFooters(Table $table)
{
//Generate each row
$rows = array();
foreach ( $table->getFooterRows() as $row )
{
//Build the cells for each row
$cells = array();
foreach ( $row as $cell )
{
$cells[] = $this->footerCell($cell);
}
$rows[] = $this->footerRow($row, $cells);
}
return $rows;
}
|
php
|
protected function buildFooters(Table $table)
{
//Generate each row
$rows = array();
foreach ( $table->getFooterRows() as $row )
{
//Build the cells for each row
$cells = array();
foreach ( $row as $cell )
{
$cells[] = $this->footerCell($cell);
}
$rows[] = $this->footerRow($row, $cells);
}
return $rows;
}
|
[
"protected",
"function",
"buildFooters",
"(",
"Table",
"$",
"table",
")",
"{",
"//Generate each row",
"$",
"rows",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"table",
"->",
"getFooterRows",
"(",
")",
"as",
"$",
"row",
")",
"{",
"//Build the cells for each row",
"$",
"cells",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"row",
"as",
"$",
"cell",
")",
"{",
"$",
"cells",
"[",
"]",
"=",
"$",
"this",
"->",
"footerCell",
"(",
"$",
"cell",
")",
";",
"}",
"$",
"rows",
"[",
"]",
"=",
"$",
"this",
"->",
"footerRow",
"(",
"$",
"row",
",",
"$",
"cells",
")",
";",
"}",
"return",
"$",
"rows",
";",
"}"
] |
Renders the footer rows for the table
@param Table $table
@return array
|
[
"Renders",
"the",
"footer",
"rows",
"for",
"the",
"table"
] |
ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40
|
https://github.com/fuelphp/common/blob/ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40/src/Table/Render.php#L106-L125
|
229,414
|
odan/database
|
src/Database/FunctionBuilder.php
|
FunctionBuilder.sum
|
public function sum(string $field): FunctionExpression
{
$quoter = $this->db->getQuoter();
$expression = sprintf('SUM(%s)', $quoter->quoteName($field));
return new FunctionExpression($expression, $quoter);
}
|
php
|
public function sum(string $field): FunctionExpression
{
$quoter = $this->db->getQuoter();
$expression = sprintf('SUM(%s)', $quoter->quoteName($field));
return new FunctionExpression($expression, $quoter);
}
|
[
"public",
"function",
"sum",
"(",
"string",
"$",
"field",
")",
":",
"FunctionExpression",
"{",
"$",
"quoter",
"=",
"$",
"this",
"->",
"db",
"->",
"getQuoter",
"(",
")",
";",
"$",
"expression",
"=",
"sprintf",
"(",
"'SUM(%s)'",
",",
"$",
"quoter",
"->",
"quoteName",
"(",
"$",
"field",
")",
")",
";",
"return",
"new",
"FunctionExpression",
"(",
"$",
"expression",
",",
"$",
"quoter",
")",
";",
"}"
] |
Calculate a sum. The arguments will be treated as literal values.
@param string $field Field name
@return FunctionExpression Expression
|
[
"Calculate",
"a",
"sum",
".",
"The",
"arguments",
"will",
"be",
"treated",
"as",
"literal",
"values",
"."
] |
e514fb45ab72718a77b34ed2c44906f5159e8278
|
https://github.com/odan/database/blob/e514fb45ab72718a77b34ed2c44906f5159e8278/src/Database/FunctionBuilder.php#L36-L42
|
229,415
|
odan/database
|
src/Database/FunctionBuilder.php
|
FunctionBuilder.call
|
public function call(string $name, ...$parameters): FunctionExpression
{
$quoter = $this->db->getQuoter();
$list = implode(', ', $quoter->quoteArray($parameters));
$expression = sprintf('%s(%s)', strtoupper($name), $list);
return new FunctionExpression($expression, $quoter);
}
|
php
|
public function call(string $name, ...$parameters): FunctionExpression
{
$quoter = $this->db->getQuoter();
$list = implode(', ', $quoter->quoteArray($parameters));
$expression = sprintf('%s(%s)', strtoupper($name), $list);
return new FunctionExpression($expression, $quoter);
}
|
[
"public",
"function",
"call",
"(",
"string",
"$",
"name",
",",
"...",
"$",
"parameters",
")",
":",
"FunctionExpression",
"{",
"$",
"quoter",
"=",
"$",
"this",
"->",
"db",
"->",
"getQuoter",
"(",
")",
";",
"$",
"list",
"=",
"implode",
"(",
"', '",
",",
"$",
"quoter",
"->",
"quoteArray",
"(",
"$",
"parameters",
")",
")",
";",
"$",
"expression",
"=",
"sprintf",
"(",
"'%s(%s)'",
",",
"strtoupper",
"(",
"$",
"name",
")",
",",
"$",
"list",
")",
";",
"return",
"new",
"FunctionExpression",
"(",
"$",
"expression",
",",
"$",
"quoter",
")",
";",
"}"
] |
Create custom SQL function call.
@param string $name The name of the function
@param mixed ...$parameters The parameters for the function
@return FunctionExpression Expression
|
[
"Create",
"custom",
"SQL",
"function",
"call",
"."
] |
e514fb45ab72718a77b34ed2c44906f5159e8278
|
https://github.com/odan/database/blob/e514fb45ab72718a77b34ed2c44906f5159e8278/src/Database/FunctionBuilder.php#L122-L130
|
229,416
|
softark/creole
|
block/HeadlineTrait.php
|
HeadlineTrait.consumeHeadline
|
protected function consumeHeadline($lines, $current)
{
$line = trim($lines[$current]);
$level = 1;
while (isset($line[$level]) && $line[$level] === '=' && $level < 6) {
$level++;
}
$block = [
'headline',
// parse headline content. The leading and trailing '='s are removed.
'content' => $this->parseInline(trim($line, " \t=")),
'level' => $level,
];
return [$block, $current];
}
|
php
|
protected function consumeHeadline($lines, $current)
{
$line = trim($lines[$current]);
$level = 1;
while (isset($line[$level]) && $line[$level] === '=' && $level < 6) {
$level++;
}
$block = [
'headline',
// parse headline content. The leading and trailing '='s are removed.
'content' => $this->parseInline(trim($line, " \t=")),
'level' => $level,
];
return [$block, $current];
}
|
[
"protected",
"function",
"consumeHeadline",
"(",
"$",
"lines",
",",
"$",
"current",
")",
"{",
"$",
"line",
"=",
"trim",
"(",
"$",
"lines",
"[",
"$",
"current",
"]",
")",
";",
"$",
"level",
"=",
"1",
";",
"while",
"(",
"isset",
"(",
"$",
"line",
"[",
"$",
"level",
"]",
")",
"&&",
"$",
"line",
"[",
"$",
"level",
"]",
"===",
"'='",
"&&",
"$",
"level",
"<",
"6",
")",
"{",
"$",
"level",
"++",
";",
"}",
"$",
"block",
"=",
"[",
"'headline'",
",",
"// parse headline content. The leading and trailing '='s are removed.",
"'content'",
"=>",
"$",
"this",
"->",
"parseInline",
"(",
"trim",
"(",
"$",
"line",
",",
"\" \\t=\"",
")",
")",
",",
"'level'",
"=>",
"$",
"level",
",",
"]",
";",
"return",
"[",
"$",
"block",
",",
"$",
"current",
"]",
";",
"}"
] |
Consume lines for a headline
|
[
"Consume",
"lines",
"for",
"a",
"headline"
] |
f56f267e46fa45df1fab01f5d9f1c2bfb0394a9b
|
https://github.com/softark/creole/blob/f56f267e46fa45df1fab01f5d9f1c2bfb0394a9b/block/HeadlineTrait.php#L31-L45
|
229,417
|
odan/database
|
src/Database/Compression.php
|
Compression.compress
|
public function compress($value)
{
if ($value === null || $value === '') {
return $value;
}
return pack('L', strlen($value)) . gzcompress($value);
}
|
php
|
public function compress($value)
{
if ($value === null || $value === '') {
return $value;
}
return pack('L', strlen($value)) . gzcompress($value);
}
|
[
"public",
"function",
"compress",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
"||",
"$",
"value",
"===",
"''",
")",
"{",
"return",
"$",
"value",
";",
"}",
"return",
"pack",
"(",
"'L'",
",",
"strlen",
"(",
"$",
"value",
")",
")",
".",
"gzcompress",
"(",
"$",
"value",
")",
";",
"}"
] |
Compress compatible with MySQL COMPRESS.
@param string|mixed $value data to compress
@return string|null compressed data
|
[
"Compress",
"compatible",
"with",
"MySQL",
"COMPRESS",
"."
] |
e514fb45ab72718a77b34ed2c44906f5159e8278
|
https://github.com/odan/database/blob/e514fb45ab72718a77b34ed2c44906f5159e8278/src/Database/Compression.php#L32-L39
|
229,418
|
aedart/testing-laravel
|
src/Traits/ApplicationInitiatorTrait.php
|
ApplicationInitiatorTrait.startApplication
|
public function startApplication() : void
{
if ($this->hasApplicationBeenStarted()) {
throw new ApplicationRunningException(sprintf('Application has already been started. Please stop the application, before invoking start!'));
}
$this->refreshApplication();
if (!$this->factory) {
$this->factory = $this->app->make(Factory::class);
}
}
|
php
|
public function startApplication() : void
{
if ($this->hasApplicationBeenStarted()) {
throw new ApplicationRunningException(sprintf('Application has already been started. Please stop the application, before invoking start!'));
}
$this->refreshApplication();
if (!$this->factory) {
$this->factory = $this->app->make(Factory::class);
}
}
|
[
"public",
"function",
"startApplication",
"(",
")",
":",
"void",
"{",
"if",
"(",
"$",
"this",
"->",
"hasApplicationBeenStarted",
"(",
")",
")",
"{",
"throw",
"new",
"ApplicationRunningException",
"(",
"sprintf",
"(",
"'Application has already been started. Please stop the application, before invoking start!'",
")",
")",
";",
"}",
"$",
"this",
"->",
"refreshApplication",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"factory",
")",
"{",
"$",
"this",
"->",
"factory",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"Factory",
"::",
"class",
")",
";",
"}",
"}"
] |
Start the application
@return void
@throws ApplicationRunningException If an application has already been started / initialised and running
|
[
"Start",
"the",
"application"
] |
a17886c66358318a88226fc67cb85c6f7ccc0a99
|
https://github.com/aedart/testing-laravel/blob/a17886c66358318a88226fc67cb85c6f7ccc0a99/src/Traits/ApplicationInitiatorTrait.php#L64-L75
|
229,419
|
aedart/testing-laravel
|
src/Traits/ApplicationInitiatorTrait.php
|
ApplicationInitiatorTrait.stopApplication
|
public function stopApplication() : void
{
if ($this->hasApplicationBeenStarted()) {
foreach ($this->beforeApplicationDestroyedCallbacks as $callback) {
call_user_func($callback);
}
$this->app->flush();
$this->app = null;
Facade::clearResolvedInstances();
Facade::setFacadeApplication(null);
}
}
|
php
|
public function stopApplication() : void
{
if ($this->hasApplicationBeenStarted()) {
foreach ($this->beforeApplicationDestroyedCallbacks as $callback) {
call_user_func($callback);
}
$this->app->flush();
$this->app = null;
Facade::clearResolvedInstances();
Facade::setFacadeApplication(null);
}
}
|
[
"public",
"function",
"stopApplication",
"(",
")",
":",
"void",
"{",
"if",
"(",
"$",
"this",
"->",
"hasApplicationBeenStarted",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"beforeApplicationDestroyedCallbacks",
"as",
"$",
"callback",
")",
"{",
"call_user_func",
"(",
"$",
"callback",
")",
";",
"}",
"$",
"this",
"->",
"app",
"->",
"flush",
"(",
")",
";",
"$",
"this",
"->",
"app",
"=",
"null",
";",
"Facade",
"::",
"clearResolvedInstances",
"(",
")",
";",
"Facade",
"::",
"setFacadeApplication",
"(",
"null",
")",
";",
"}",
"}"
] |
Stop the application
@return void
|
[
"Stop",
"the",
"application"
] |
a17886c66358318a88226fc67cb85c6f7ccc0a99
|
https://github.com/aedart/testing-laravel/blob/a17886c66358318a88226fc67cb85c6f7ccc0a99/src/Traits/ApplicationInitiatorTrait.php#L82-L95
|
229,420
|
fecshop/yii2-fec
|
lib/PHPExcel/PHPExcel/Worksheet.php
|
PHPExcel_Worksheet.rangeToArray
|
public function rangeToArray($pRange = 'A1', $nullValue = null, $calculateFormulas = true, $formatData = true, $returnCellRef = false) {
// Returnvalue
$returnValue = array();
// Identify the range that we need to extract from the worksheet
list($rangeStart, $rangeEnd) = PHPExcel_Cell::rangeBoundaries($pRange);
$minCol = PHPExcel_Cell::stringFromColumnIndex($rangeStart[0] -1);
$minRow = $rangeStart[1];
$maxCol = PHPExcel_Cell::stringFromColumnIndex($rangeEnd[0] -1);
$maxRow = $rangeEnd[1];
$maxCol++;
// Loop through rows
$r = -1;
for ($row = $minRow; $row <= $maxRow; ++$row) {
$rRef = ($returnCellRef) ? $row : ++$r;
$c = -1;
// Loop through columns in the current row
for ($col = $minCol; $col != $maxCol; ++$col) {
$cRef = ($returnCellRef) ? $col : ++$c;
// Using getCell() will create a new cell if it doesn't already exist. We don't want that to happen
// so we test and retrieve directly against _cellCollection
if ($this->_cellCollection->isDataSet($col.$row)) {
// Cell exists
$cell = $this->_cellCollection->getCacheData($col.$row);
if ($cell->getValue() !== null) {
if ($cell->getValue() instanceof PHPExcel_RichText) {
$returnValue[$rRef][$cRef] = $cell->getValue()->getPlainText();
} else {
if ($calculateFormulas) {
$returnValue[$rRef][$cRef] = $cell->getCalculatedValue();
} else {
$returnValue[$rRef][$cRef] = $cell->getValue();
}
}
if ($formatData) {
$style = $this->_parent->getCellXfByIndex($cell->getXfIndex());
$returnValue[$rRef][$cRef] = PHPExcel_Style_NumberFormat::toFormattedString(
$returnValue[$rRef][$cRef],
($style && $style->getNumberFormat()) ?
$style->getNumberFormat()->getFormatCode() :
PHPExcel_Style_NumberFormat::FORMAT_GENERAL
);
}
} else {
// Cell holds a NULL
$returnValue[$rRef][$cRef] = $nullValue;
}
} else {
// Cell doesn't exist
$returnValue[$rRef][$cRef] = $nullValue;
}
}
}
// Return
return $returnValue;
}
|
php
|
public function rangeToArray($pRange = 'A1', $nullValue = null, $calculateFormulas = true, $formatData = true, $returnCellRef = false) {
// Returnvalue
$returnValue = array();
// Identify the range that we need to extract from the worksheet
list($rangeStart, $rangeEnd) = PHPExcel_Cell::rangeBoundaries($pRange);
$minCol = PHPExcel_Cell::stringFromColumnIndex($rangeStart[0] -1);
$minRow = $rangeStart[1];
$maxCol = PHPExcel_Cell::stringFromColumnIndex($rangeEnd[0] -1);
$maxRow = $rangeEnd[1];
$maxCol++;
// Loop through rows
$r = -1;
for ($row = $minRow; $row <= $maxRow; ++$row) {
$rRef = ($returnCellRef) ? $row : ++$r;
$c = -1;
// Loop through columns in the current row
for ($col = $minCol; $col != $maxCol; ++$col) {
$cRef = ($returnCellRef) ? $col : ++$c;
// Using getCell() will create a new cell if it doesn't already exist. We don't want that to happen
// so we test and retrieve directly against _cellCollection
if ($this->_cellCollection->isDataSet($col.$row)) {
// Cell exists
$cell = $this->_cellCollection->getCacheData($col.$row);
if ($cell->getValue() !== null) {
if ($cell->getValue() instanceof PHPExcel_RichText) {
$returnValue[$rRef][$cRef] = $cell->getValue()->getPlainText();
} else {
if ($calculateFormulas) {
$returnValue[$rRef][$cRef] = $cell->getCalculatedValue();
} else {
$returnValue[$rRef][$cRef] = $cell->getValue();
}
}
if ($formatData) {
$style = $this->_parent->getCellXfByIndex($cell->getXfIndex());
$returnValue[$rRef][$cRef] = PHPExcel_Style_NumberFormat::toFormattedString(
$returnValue[$rRef][$cRef],
($style && $style->getNumberFormat()) ?
$style->getNumberFormat()->getFormatCode() :
PHPExcel_Style_NumberFormat::FORMAT_GENERAL
);
}
} else {
// Cell holds a NULL
$returnValue[$rRef][$cRef] = $nullValue;
}
} else {
// Cell doesn't exist
$returnValue[$rRef][$cRef] = $nullValue;
}
}
}
// Return
return $returnValue;
}
|
[
"public",
"function",
"rangeToArray",
"(",
"$",
"pRange",
"=",
"'A1'",
",",
"$",
"nullValue",
"=",
"null",
",",
"$",
"calculateFormulas",
"=",
"true",
",",
"$",
"formatData",
"=",
"true",
",",
"$",
"returnCellRef",
"=",
"false",
")",
"{",
"// Returnvalue",
"$",
"returnValue",
"=",
"array",
"(",
")",
";",
"// Identify the range that we need to extract from the worksheet",
"list",
"(",
"$",
"rangeStart",
",",
"$",
"rangeEnd",
")",
"=",
"PHPExcel_Cell",
"::",
"rangeBoundaries",
"(",
"$",
"pRange",
")",
";",
"$",
"minCol",
"=",
"PHPExcel_Cell",
"::",
"stringFromColumnIndex",
"(",
"$",
"rangeStart",
"[",
"0",
"]",
"-",
"1",
")",
";",
"$",
"minRow",
"=",
"$",
"rangeStart",
"[",
"1",
"]",
";",
"$",
"maxCol",
"=",
"PHPExcel_Cell",
"::",
"stringFromColumnIndex",
"(",
"$",
"rangeEnd",
"[",
"0",
"]",
"-",
"1",
")",
";",
"$",
"maxRow",
"=",
"$",
"rangeEnd",
"[",
"1",
"]",
";",
"$",
"maxCol",
"++",
";",
"// Loop through rows",
"$",
"r",
"=",
"-",
"1",
";",
"for",
"(",
"$",
"row",
"=",
"$",
"minRow",
";",
"$",
"row",
"<=",
"$",
"maxRow",
";",
"++",
"$",
"row",
")",
"{",
"$",
"rRef",
"=",
"(",
"$",
"returnCellRef",
")",
"?",
"$",
"row",
":",
"++",
"$",
"r",
";",
"$",
"c",
"=",
"-",
"1",
";",
"// Loop through columns in the current row",
"for",
"(",
"$",
"col",
"=",
"$",
"minCol",
";",
"$",
"col",
"!=",
"$",
"maxCol",
";",
"++",
"$",
"col",
")",
"{",
"$",
"cRef",
"=",
"(",
"$",
"returnCellRef",
")",
"?",
"$",
"col",
":",
"++",
"$",
"c",
";",
"// Using getCell() will create a new cell if it doesn't already exist. We don't want that to happen",
"// so we test and retrieve directly against _cellCollection",
"if",
"(",
"$",
"this",
"->",
"_cellCollection",
"->",
"isDataSet",
"(",
"$",
"col",
".",
"$",
"row",
")",
")",
"{",
"// Cell exists",
"$",
"cell",
"=",
"$",
"this",
"->",
"_cellCollection",
"->",
"getCacheData",
"(",
"$",
"col",
".",
"$",
"row",
")",
";",
"if",
"(",
"$",
"cell",
"->",
"getValue",
"(",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"$",
"cell",
"->",
"getValue",
"(",
")",
"instanceof",
"PHPExcel_RichText",
")",
"{",
"$",
"returnValue",
"[",
"$",
"rRef",
"]",
"[",
"$",
"cRef",
"]",
"=",
"$",
"cell",
"->",
"getValue",
"(",
")",
"->",
"getPlainText",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"calculateFormulas",
")",
"{",
"$",
"returnValue",
"[",
"$",
"rRef",
"]",
"[",
"$",
"cRef",
"]",
"=",
"$",
"cell",
"->",
"getCalculatedValue",
"(",
")",
";",
"}",
"else",
"{",
"$",
"returnValue",
"[",
"$",
"rRef",
"]",
"[",
"$",
"cRef",
"]",
"=",
"$",
"cell",
"->",
"getValue",
"(",
")",
";",
"}",
"}",
"if",
"(",
"$",
"formatData",
")",
"{",
"$",
"style",
"=",
"$",
"this",
"->",
"_parent",
"->",
"getCellXfByIndex",
"(",
"$",
"cell",
"->",
"getXfIndex",
"(",
")",
")",
";",
"$",
"returnValue",
"[",
"$",
"rRef",
"]",
"[",
"$",
"cRef",
"]",
"=",
"PHPExcel_Style_NumberFormat",
"::",
"toFormattedString",
"(",
"$",
"returnValue",
"[",
"$",
"rRef",
"]",
"[",
"$",
"cRef",
"]",
",",
"(",
"$",
"style",
"&&",
"$",
"style",
"->",
"getNumberFormat",
"(",
")",
")",
"?",
"$",
"style",
"->",
"getNumberFormat",
"(",
")",
"->",
"getFormatCode",
"(",
")",
":",
"PHPExcel_Style_NumberFormat",
"::",
"FORMAT_GENERAL",
")",
";",
"}",
"}",
"else",
"{",
"// Cell holds a NULL",
"$",
"returnValue",
"[",
"$",
"rRef",
"]",
"[",
"$",
"cRef",
"]",
"=",
"$",
"nullValue",
";",
"}",
"}",
"else",
"{",
"// Cell doesn't exist",
"$",
"returnValue",
"[",
"$",
"rRef",
"]",
"[",
"$",
"cRef",
"]",
"=",
"$",
"nullValue",
";",
"}",
"}",
"}",
"// Return",
"return",
"$",
"returnValue",
";",
"}"
] |
Create array from a range of cells
@param string $pRange Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1")
@param mixed $nullValue Value returned in the array entry if a cell doesn't exist
@param boolean $calculateFormulas Should formulas be calculated?
@param boolean $formatData Should formatting be applied to cell values?
@param boolean $returnCellRef False - Return a simple array of rows and columns indexed by number counting from zero
True - Return rows and columns indexed by their actual row and column IDs
@return array
|
[
"Create",
"array",
"from",
"a",
"range",
"of",
"cells"
] |
fda0e381f931bc503e493bec90185162109018e6
|
https://github.com/fecshop/yii2-fec/blob/fda0e381f931bc503e493bec90185162109018e6/lib/PHPExcel/PHPExcel/Worksheet.php#L2429-L2486
|
229,421
|
netgen/NetgenOpenGraphBundle
|
bundle/Handler/FieldType/Image.php
|
Image.getFallbackValue
|
protected function getFallbackValue($tagName, array $params = array())
{
if (!empty($params[2]) && ($request = $this->requestStack->getCurrentRequest()) !== null) {
return $request->getUriForPath('/' . ltrim($params[2], '/'));
}
return '';
}
|
php
|
protected function getFallbackValue($tagName, array $params = array())
{
if (!empty($params[2]) && ($request = $this->requestStack->getCurrentRequest()) !== null) {
return $request->getUriForPath('/' . ltrim($params[2], '/'));
}
return '';
}
|
[
"protected",
"function",
"getFallbackValue",
"(",
"$",
"tagName",
",",
"array",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"params",
"[",
"2",
"]",
")",
"&&",
"(",
"$",
"request",
"=",
"$",
"this",
"->",
"requestStack",
"->",
"getCurrentRequest",
"(",
")",
")",
"!==",
"null",
")",
"{",
"return",
"$",
"request",
"->",
"getUriForPath",
"(",
"'/'",
".",
"ltrim",
"(",
"$",
"params",
"[",
"2",
"]",
",",
"'/'",
")",
")",
";",
"}",
"return",
"''",
";",
"}"
] |
Returns fallback value.
@param string $tagName
@param array $params
@return string
|
[
"Returns",
"fallback",
"value",
"."
] |
fcaad267742492cfa4049adbf075343c262c4767
|
https://github.com/netgen/NetgenOpenGraphBundle/blob/fcaad267742492cfa4049adbf075343c262c4767/bundle/Handler/FieldType/Image.php#L111-L118
|
229,422
|
softark/creole
|
Creole.php
|
Creole.isParagraphEnd
|
protected function isParagraphEnd($line)
{
if (empty($line) ||
ltrim($line) === '' ||
$this->identifyHeadline($line) ||
$this->identifyHr($line) ||
$this->identifyUl($line) ||
$this->identifyOl($line) ||
$this->identifyTable($line) ||
$this->identifyCode($line) ||
$this->identifyRawHtml($line))
{
return true;
}
return false;
}
|
php
|
protected function isParagraphEnd($line)
{
if (empty($line) ||
ltrim($line) === '' ||
$this->identifyHeadline($line) ||
$this->identifyHr($line) ||
$this->identifyUl($line) ||
$this->identifyOl($line) ||
$this->identifyTable($line) ||
$this->identifyCode($line) ||
$this->identifyRawHtml($line))
{
return true;
}
return false;
}
|
[
"protected",
"function",
"isParagraphEnd",
"(",
"$",
"line",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"line",
")",
"||",
"ltrim",
"(",
"$",
"line",
")",
"===",
"''",
"||",
"$",
"this",
"->",
"identifyHeadline",
"(",
"$",
"line",
")",
"||",
"$",
"this",
"->",
"identifyHr",
"(",
"$",
"line",
")",
"||",
"$",
"this",
"->",
"identifyUl",
"(",
"$",
"line",
")",
"||",
"$",
"this",
"->",
"identifyOl",
"(",
"$",
"line",
")",
"||",
"$",
"this",
"->",
"identifyTable",
"(",
"$",
"line",
")",
"||",
"$",
"this",
"->",
"identifyCode",
"(",
"$",
"line",
")",
"||",
"$",
"this",
"->",
"identifyRawHtml",
"(",
"$",
"line",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Checks if the paragraph ends
@param $line
@return bool true if end of paragraph
|
[
"Checks",
"if",
"the",
"paragraph",
"ends"
] |
f56f267e46fa45df1fab01f5d9f1c2bfb0394a9b
|
https://github.com/softark/creole/blob/f56f267e46fa45df1fab01f5d9f1c2bfb0394a9b/Creole.php#L64-L79
|
229,423
|
odan/database
|
src/Database/SelectQuery.php
|
SelectQuery.union
|
public function union(SelectQuery $query): self
{
$this->union[] = ['', $query->build(false)];
return $this;
}
|
php
|
public function union(SelectQuery $query): self
{
$this->union[] = ['', $query->build(false)];
return $this;
}
|
[
"public",
"function",
"union",
"(",
"SelectQuery",
"$",
"query",
")",
":",
"self",
"{",
"$",
"this",
"->",
"union",
"[",
"]",
"=",
"[",
"''",
",",
"$",
"query",
"->",
"build",
"(",
"false",
")",
"]",
";",
"return",
"$",
"this",
";",
"}"
] |
UNION is used to combine the result from multiple
SELECT statements into a single result set.
@param SelectQuery $query the query to combine
@return self
|
[
"UNION",
"is",
"used",
"to",
"combine",
"the",
"result",
"from",
"multiple",
"SELECT",
"statements",
"into",
"a",
"single",
"result",
"set",
"."
] |
e514fb45ab72718a77b34ed2c44906f5159e8278
|
https://github.com/odan/database/blob/e514fb45ab72718a77b34ed2c44906f5159e8278/src/Database/SelectQuery.php#L174-L179
|
229,424
|
odan/database
|
src/Database/SelectQuery.php
|
SelectQuery.leftJoinRaw
|
public function leftJoinRaw(string $table, string $conditions): self
{
$this->join[] = ['left', $table, new RawExp($conditions), null, null, null];
return $this;
}
|
php
|
public function leftJoinRaw(string $table, string $conditions): self
{
$this->join[] = ['left', $table, new RawExp($conditions), null, null, null];
return $this;
}
|
[
"public",
"function",
"leftJoinRaw",
"(",
"string",
"$",
"table",
",",
"string",
"$",
"conditions",
")",
":",
"self",
"{",
"$",
"this",
"->",
"join",
"[",
"]",
"=",
"[",
"'left'",
",",
"$",
"table",
",",
"new",
"RawExp",
"(",
"$",
"conditions",
")",
",",
"null",
",",
"null",
",",
"null",
"]",
";",
"return",
"$",
"this",
";",
"}"
] |
Left join with complex conditions.
@param string $table Table name
@param string $conditions The ON conditions e.g. 'user.id = article.user_id'
@return self
|
[
"Left",
"join",
"with",
"complex",
"conditions",
"."
] |
e514fb45ab72718a77b34ed2c44906f5159e8278
|
https://github.com/odan/database/blob/e514fb45ab72718a77b34ed2c44906f5159e8278/src/Database/SelectQuery.php#L283-L288
|
229,425
|
odan/database
|
src/Database/SelectQuery.php
|
SelectQuery.whereRaw
|
public function whereRaw(string $condition): self
{
$this->condition->where([new RawExp($condition)]);
return $this;
}
|
php
|
public function whereRaw(string $condition): self
{
$this->condition->where([new RawExp($condition)]);
return $this;
}
|
[
"public",
"function",
"whereRaw",
"(",
"string",
"$",
"condition",
")",
":",
"self",
"{",
"$",
"this",
"->",
"condition",
"->",
"where",
"(",
"[",
"new",
"RawExp",
"(",
"$",
"condition",
")",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Add a raw AND WHERE condition.
@param string $condition The raw where conditions e.g. 'user.id = article.user_id'
@return self
|
[
"Add",
"a",
"raw",
"AND",
"WHERE",
"condition",
"."
] |
e514fb45ab72718a77b34ed2c44906f5159e8278
|
https://github.com/odan/database/blob/e514fb45ab72718a77b34ed2c44906f5159e8278/src/Database/SelectQuery.php#L313-L318
|
229,426
|
odan/database
|
src/Database/SelectQuery.php
|
SelectQuery.orWhereRaw
|
public function orWhereRaw(string $condition): self
{
$this->condition->orWhere([new RawExp($condition)]);
return $this;
}
|
php
|
public function orWhereRaw(string $condition): self
{
$this->condition->orWhere([new RawExp($condition)]);
return $this;
}
|
[
"public",
"function",
"orWhereRaw",
"(",
"string",
"$",
"condition",
")",
":",
"self",
"{",
"$",
"this",
"->",
"condition",
"->",
"orWhere",
"(",
"[",
"new",
"RawExp",
"(",
"$",
"condition",
")",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Add a raw OR WHERE condition.
@param string $condition The raw where conditions e.g. 'user.id = article.user_id'
@return self
|
[
"Add",
"a",
"raw",
"OR",
"WHERE",
"condition",
"."
] |
e514fb45ab72718a77b34ed2c44906f5159e8278
|
https://github.com/odan/database/blob/e514fb45ab72718a77b34ed2c44906f5159e8278/src/Database/SelectQuery.php#L343-L348
|
229,427
|
odan/database
|
src/Database/SelectQuery.php
|
SelectQuery.orHavingRaw
|
public function orHavingRaw(string $condition): self
{
$this->condition->orHaving([new RawExp($condition)]);
return $this;
}
|
php
|
public function orHavingRaw(string $condition): self
{
$this->condition->orHaving([new RawExp($condition)]);
return $this;
}
|
[
"public",
"function",
"orHavingRaw",
"(",
"string",
"$",
"condition",
")",
":",
"self",
"{",
"$",
"this",
"->",
"condition",
"->",
"orHaving",
"(",
"[",
"new",
"RawExp",
"(",
"$",
"condition",
")",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Add OR having condition.
@param string $condition The raw HAVING conditions e.g. 'user.id = article.user_id'
@return self
|
[
"Add",
"OR",
"having",
"condition",
"."
] |
e514fb45ab72718a77b34ed2c44906f5159e8278
|
https://github.com/odan/database/blob/e514fb45ab72718a77b34ed2c44906f5159e8278/src/Database/SelectQuery.php#L465-L470
|
229,428
|
josegonzalez/cakephp-wysiwyg
|
View/Helper/WysiwygAppHelper.php
|
WysiwygAppHelper.input
|
public function input($fieldName, $options = array(), $helperOptions = array()) {
$helperOptions = Set::merge($this->_helperOptions, $helperOptions);
return $this->Form->input($fieldName, $options) . $this->_build($fieldName, $helperOptions);
}
|
php
|
public function input($fieldName, $options = array(), $helperOptions = array()) {
$helperOptions = Set::merge($this->_helperOptions, $helperOptions);
return $this->Form->input($fieldName, $options) . $this->_build($fieldName, $helperOptions);
}
|
[
"public",
"function",
"input",
"(",
"$",
"fieldName",
",",
"$",
"options",
"=",
"array",
"(",
")",
",",
"$",
"helperOptions",
"=",
"array",
"(",
")",
")",
"{",
"$",
"helperOptions",
"=",
"Set",
"::",
"merge",
"(",
"$",
"this",
"->",
"_helperOptions",
",",
"$",
"helperOptions",
")",
";",
"return",
"$",
"this",
"->",
"Form",
"->",
"input",
"(",
"$",
"fieldName",
",",
"$",
"options",
")",
".",
"$",
"this",
"->",
"_build",
"(",
"$",
"fieldName",
",",
"$",
"helperOptions",
")",
";",
"}"
] |
Creates an fckeditor input field
@param string $fieldName This should be "Modelname.fieldname"
@param array $options Each type of input takes different options.
@param array $helperOptions Each type of wysiwyg helper takes different options.
@return string An HTML input element with Wysiwyg Js
|
[
"Creates",
"an",
"fckeditor",
"input",
"field"
] |
c4909d29e8942797fa360946507768066a47adb0
|
https://github.com/josegonzalez/cakephp-wysiwyg/blob/c4909d29e8942797fa360946507768066a47adb0/View/Helper/WysiwygAppHelper.php#L81-L84
|
229,429
|
josegonzalez/cakephp-wysiwyg
|
View/Helper/WysiwygAppHelper.php
|
WysiwygAppHelper._initialize
|
protected function _initialize($options = array()) {
if ($this->_initialized) {
return;
}
$this->_initialized = true;
if (!empty($options['_css'])) {
foreach ((array)$options['_css'] as $css) {
$this->Html->css($css, null, array('inline' => false));
}
}
if (!empty($options['_cssText'])) {
$out = $this->Html->tag('style', $options['_cssText']);
$this->_View->append('css', $out);
}
if (!empty($options['_scriptBlock'])) {
$scriptOpts = array('block' => $options['_scriptBlock']);
} else {
$scriptOpts = false;
}
if (!empty($options['_scripts'])) {
foreach ((array)$options['_scripts'] as $script) {
$this->Html->script($script, $scriptOpts);
}
}
}
|
php
|
protected function _initialize($options = array()) {
if ($this->_initialized) {
return;
}
$this->_initialized = true;
if (!empty($options['_css'])) {
foreach ((array)$options['_css'] as $css) {
$this->Html->css($css, null, array('inline' => false));
}
}
if (!empty($options['_cssText'])) {
$out = $this->Html->tag('style', $options['_cssText']);
$this->_View->append('css', $out);
}
if (!empty($options['_scriptBlock'])) {
$scriptOpts = array('block' => $options['_scriptBlock']);
} else {
$scriptOpts = false;
}
if (!empty($options['_scripts'])) {
foreach ((array)$options['_scripts'] as $script) {
$this->Html->script($script, $scriptOpts);
}
}
}
|
[
"protected",
"function",
"_initialize",
"(",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_initialized",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"_initialized",
"=",
"true",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'_css'",
"]",
")",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"options",
"[",
"'_css'",
"]",
"as",
"$",
"css",
")",
"{",
"$",
"this",
"->",
"Html",
"->",
"css",
"(",
"$",
"css",
",",
"null",
",",
"array",
"(",
"'inline'",
"=>",
"false",
")",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'_cssText'",
"]",
")",
")",
"{",
"$",
"out",
"=",
"$",
"this",
"->",
"Html",
"->",
"tag",
"(",
"'style'",
",",
"$",
"options",
"[",
"'_cssText'",
"]",
")",
";",
"$",
"this",
"->",
"_View",
"->",
"append",
"(",
"'css'",
",",
"$",
"out",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'_scriptBlock'",
"]",
")",
")",
"{",
"$",
"scriptOpts",
"=",
"array",
"(",
"'block'",
"=>",
"$",
"options",
"[",
"'_scriptBlock'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"scriptOpts",
"=",
"false",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'_scripts'",
"]",
")",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"options",
"[",
"'_scripts'",
"]",
"as",
"$",
"script",
")",
"{",
"$",
"this",
"->",
"Html",
"->",
"script",
"(",
"$",
"script",
",",
"$",
"scriptOpts",
")",
";",
"}",
"}",
"}"
] |
Initialize the helper css and js for a given input field
@param array $options array of css files, javascript files, and css text to enqueue
@return void
|
[
"Initialize",
"the",
"helper",
"css",
"and",
"js",
"for",
"a",
"given",
"input",
"field"
] |
c4909d29e8942797fa360946507768066a47adb0
|
https://github.com/josegonzalez/cakephp-wysiwyg/blob/c4909d29e8942797fa360946507768066a47adb0/View/Helper/WysiwygAppHelper.php#L105-L133
|
229,430
|
josegonzalez/cakephp-wysiwyg
|
View/Helper/WysiwygAppHelper.php
|
WysiwygAppHelper._initializationOptions
|
protected function _initializationOptions($options = array()) {
$defaults = array(
'_buffer' => true,
'_css' => true,
'_cssText' => true,
'_scripts' => true,
'_scriptBlock' => false,
'_editor' => true,
'_inline' => true,
);
return json_encode(array_diff_key(array_merge(
$defaults,
(array)$options
), $defaults));
}
|
php
|
protected function _initializationOptions($options = array()) {
$defaults = array(
'_buffer' => true,
'_css' => true,
'_cssText' => true,
'_scripts' => true,
'_scriptBlock' => false,
'_editor' => true,
'_inline' => true,
);
return json_encode(array_diff_key(array_merge(
$defaults,
(array)$options
), $defaults));
}
|
[
"protected",
"function",
"_initializationOptions",
"(",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"defaults",
"=",
"array",
"(",
"'_buffer'",
"=>",
"true",
",",
"'_css'",
"=>",
"true",
",",
"'_cssText'",
"=>",
"true",
",",
"'_scripts'",
"=>",
"true",
",",
"'_scriptBlock'",
"=>",
"false",
",",
"'_editor'",
"=>",
"true",
",",
"'_inline'",
"=>",
"true",
",",
")",
";",
"return",
"json_encode",
"(",
"array_diff_key",
"(",
"array_merge",
"(",
"$",
"defaults",
",",
"(",
"array",
")",
"$",
"options",
")",
",",
"$",
"defaults",
")",
")",
";",
"}"
] |
Returns a json string containing helper settings
@param array $options array of Wysiwyg editor settings
@return string json_encoded array of options
|
[
"Returns",
"a",
"json",
"string",
"containing",
"helper",
"settings"
] |
c4909d29e8942797fa360946507768066a47adb0
|
https://github.com/josegonzalez/cakephp-wysiwyg/blob/c4909d29e8942797fa360946507768066a47adb0/View/Helper/WysiwygAppHelper.php#L141-L156
|
229,431
|
netgen/NetgenOpenGraphBundle
|
bundle/MetaTag/Renderer.php
|
Renderer.render
|
public function render(array $metaTags = array())
{
$html = '';
foreach ($metaTags as $metaTag) {
if (!$metaTag instanceof Item) {
throw new InvalidArgumentException('metaTags', 'Cannot render meta tag, not an instance of \Netgen\Bundle\OpenGraphBundle\MetaTag\Item');
}
$tagName = htmlspecialchars($metaTag->getTagName(), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
$tagValue = htmlspecialchars($metaTag->getTagValue(), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
if (!empty($tagName) && !empty($tagValue)) {
$html .= "<meta property=\"$tagName\" content=\"$tagValue\" />\n";
}
}
return $html;
}
|
php
|
public function render(array $metaTags = array())
{
$html = '';
foreach ($metaTags as $metaTag) {
if (!$metaTag instanceof Item) {
throw new InvalidArgumentException('metaTags', 'Cannot render meta tag, not an instance of \Netgen\Bundle\OpenGraphBundle\MetaTag\Item');
}
$tagName = htmlspecialchars($metaTag->getTagName(), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
$tagValue = htmlspecialchars($metaTag->getTagValue(), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
if (!empty($tagName) && !empty($tagValue)) {
$html .= "<meta property=\"$tagName\" content=\"$tagValue\" />\n";
}
}
return $html;
}
|
[
"public",
"function",
"render",
"(",
"array",
"$",
"metaTags",
"=",
"array",
"(",
")",
")",
"{",
"$",
"html",
"=",
"''",
";",
"foreach",
"(",
"$",
"metaTags",
"as",
"$",
"metaTag",
")",
"{",
"if",
"(",
"!",
"$",
"metaTag",
"instanceof",
"Item",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'metaTags'",
",",
"'Cannot render meta tag, not an instance of \\Netgen\\Bundle\\OpenGraphBundle\\MetaTag\\Item'",
")",
";",
"}",
"$",
"tagName",
"=",
"htmlspecialchars",
"(",
"$",
"metaTag",
"->",
"getTagName",
"(",
")",
",",
"ENT_QUOTES",
"|",
"ENT_SUBSTITUTE",
",",
"'UTF-8'",
")",
";",
"$",
"tagValue",
"=",
"htmlspecialchars",
"(",
"$",
"metaTag",
"->",
"getTagValue",
"(",
")",
",",
"ENT_QUOTES",
"|",
"ENT_SUBSTITUTE",
",",
"'UTF-8'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"tagName",
")",
"&&",
"!",
"empty",
"(",
"$",
"tagValue",
")",
")",
"{",
"$",
"html",
".=",
"\"<meta property=\\\"$tagName\\\" content=\\\"$tagValue\\\" />\\n\"",
";",
"}",
"}",
"return",
"$",
"html",
";",
"}"
] |
Renders provided meta tags.
@param \Netgen\Bundle\OpenGraphBundle\MetaTag\Item[]
@throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If meta tag is not an instance of
\Netgen\Bundle\OpenGraphBundle\MetaTag\Item
@return string
|
[
"Renders",
"provided",
"meta",
"tags",
"."
] |
fcaad267742492cfa4049adbf075343c262c4767
|
https://github.com/netgen/NetgenOpenGraphBundle/blob/fcaad267742492cfa4049adbf075343c262c4767/bundle/MetaTag/Renderer.php#L19-L37
|
229,432
|
fuelphp/common
|
src/Inflector.php
|
Inflector.humanize
|
public function humanize($str, $sep = '_', $lowercase = true)
{
// Allow dash, otherwise default to underscore
$sep = $sep != '-' ? '_' : $sep;
if ($lowercase === true)
{
$str = $this->str->ucfirst($str);
}
return str_replace($sep, " ", strval($str));
}
|
php
|
public function humanize($str, $sep = '_', $lowercase = true)
{
// Allow dash, otherwise default to underscore
$sep = $sep != '-' ? '_' : $sep;
if ($lowercase === true)
{
$str = $this->str->ucfirst($str);
}
return str_replace($sep, " ", strval($str));
}
|
[
"public",
"function",
"humanize",
"(",
"$",
"str",
",",
"$",
"sep",
"=",
"'_'",
",",
"$",
"lowercase",
"=",
"true",
")",
"{",
"// Allow dash, otherwise default to underscore",
"$",
"sep",
"=",
"$",
"sep",
"!=",
"'-'",
"?",
"'_'",
":",
"$",
"sep",
";",
"if",
"(",
"$",
"lowercase",
"===",
"true",
")",
"{",
"$",
"str",
"=",
"$",
"this",
"->",
"str",
"->",
"ucfirst",
"(",
"$",
"str",
")",
";",
"}",
"return",
"str_replace",
"(",
"$",
"sep",
",",
"\" \"",
",",
"strval",
"(",
"$",
"str",
")",
")",
";",
"}"
] |
Turns an underscore or dash separated word and turns it into a human looking string.
@param string the word
@param string the separator (either _ or -)
@param bool lowercare string and upper case first
@return string the human version of given string
|
[
"Turns",
"an",
"underscore",
"or",
"dash",
"separated",
"word",
"and",
"turns",
"it",
"into",
"a",
"human",
"looking",
"string",
"."
] |
ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40
|
https://github.com/fuelphp/common/blob/ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40/src/Inflector.php#L334-L345
|
229,433
|
fuelphp/common
|
src/Inflector.php
|
Inflector.classify
|
public function classify($name, $force_singular = true)
{
$class = ($force_singular) ? $this->singularize($name) : $name;
return $this->wordsToUpper($class);
}
|
php
|
public function classify($name, $force_singular = true)
{
$class = ($force_singular) ? $this->singularize($name) : $name;
return $this->wordsToUpper($class);
}
|
[
"public",
"function",
"classify",
"(",
"$",
"name",
",",
"$",
"force_singular",
"=",
"true",
")",
"{",
"$",
"class",
"=",
"(",
"$",
"force_singular",
")",
"?",
"$",
"this",
"->",
"singularize",
"(",
"$",
"name",
")",
":",
"$",
"name",
";",
"return",
"$",
"this",
"->",
"wordsToUpper",
"(",
"$",
"class",
")",
";",
"}"
] |
Takes a table name and creates the class name.
@param string the table name
@param bool whether to singularize the table name or not
@return string the class name
|
[
"Takes",
"a",
"table",
"name",
"and",
"creates",
"the",
"class",
"name",
"."
] |
ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40
|
https://github.com/fuelphp/common/blob/ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40/src/Inflector.php#L426-L430
|
229,434
|
fuelphp/common
|
src/Inflector.php
|
Inflector.isCountable
|
public function isCountable($word)
{
return ! (\in_array($this->str->lower(\strval($word)), $this->uncountableWords));
}
|
php
|
public function isCountable($word)
{
return ! (\in_array($this->str->lower(\strval($word)), $this->uncountableWords));
}
|
[
"public",
"function",
"isCountable",
"(",
"$",
"word",
")",
"{",
"return",
"!",
"(",
"\\",
"in_array",
"(",
"$",
"this",
"->",
"str",
"->",
"lower",
"(",
"\\",
"strval",
"(",
"$",
"word",
")",
")",
",",
"$",
"this",
"->",
"uncountableWords",
")",
")",
";",
"}"
] |
Checks if the given word has a plural version.
@param string the word to check
@return bool if the word is countable
|
[
"Checks",
"if",
"the",
"given",
"word",
"has",
"a",
"plural",
"version",
"."
] |
ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40
|
https://github.com/fuelphp/common/blob/ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40/src/Inflector.php#L455-L458
|
229,435
|
joomla-framework/datetime
|
src/Getter/DateTimeGetter.php
|
DateTimeGetter.get
|
public function get(DateTime $datetime, $name)
{
$value = null;
switch ($name)
{
case 'daysinmonth':
$value = $datetime->format('t');
break;
case 'dayofweek':
$value = $datetime->format('N');
break;
case 'dayofyear':
$value = $datetime->format('z');
break;
case 'isleapyear':
$value = (boolean) $datetime->format('L');
break;
case 'day':
$value = $datetime->format('d');
break;
case 'hour':
$value = $datetime->format('H');
break;
case 'minute':
$value = $datetime->format('i');
break;
case 'second':
$value = $datetime->format('s');
break;
case 'month':
$value = $datetime->format('m');
break;
case 'ordinal':
$value = $datetime->format('S');
break;
case 'week':
$value = $datetime->format('W');
break;
case 'year':
$value = $datetime->format('Y');
break;
default:
$trace = debug_backtrace();
trigger_error('Undefined property: ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_NOTICE);
}
return $value;
}
|
php
|
public function get(DateTime $datetime, $name)
{
$value = null;
switch ($name)
{
case 'daysinmonth':
$value = $datetime->format('t');
break;
case 'dayofweek':
$value = $datetime->format('N');
break;
case 'dayofyear':
$value = $datetime->format('z');
break;
case 'isleapyear':
$value = (boolean) $datetime->format('L');
break;
case 'day':
$value = $datetime->format('d');
break;
case 'hour':
$value = $datetime->format('H');
break;
case 'minute':
$value = $datetime->format('i');
break;
case 'second':
$value = $datetime->format('s');
break;
case 'month':
$value = $datetime->format('m');
break;
case 'ordinal':
$value = $datetime->format('S');
break;
case 'week':
$value = $datetime->format('W');
break;
case 'year':
$value = $datetime->format('Y');
break;
default:
$trace = debug_backtrace();
trigger_error('Undefined property: ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_NOTICE);
}
return $value;
}
|
[
"public",
"function",
"get",
"(",
"DateTime",
"$",
"datetime",
",",
"$",
"name",
")",
"{",
"$",
"value",
"=",
"null",
";",
"switch",
"(",
"$",
"name",
")",
"{",
"case",
"'daysinmonth'",
":",
"$",
"value",
"=",
"$",
"datetime",
"->",
"format",
"(",
"'t'",
")",
";",
"break",
";",
"case",
"'dayofweek'",
":",
"$",
"value",
"=",
"$",
"datetime",
"->",
"format",
"(",
"'N'",
")",
";",
"break",
";",
"case",
"'dayofyear'",
":",
"$",
"value",
"=",
"$",
"datetime",
"->",
"format",
"(",
"'z'",
")",
";",
"break",
";",
"case",
"'isleapyear'",
":",
"$",
"value",
"=",
"(",
"boolean",
")",
"$",
"datetime",
"->",
"format",
"(",
"'L'",
")",
";",
"break",
";",
"case",
"'day'",
":",
"$",
"value",
"=",
"$",
"datetime",
"->",
"format",
"(",
"'d'",
")",
";",
"break",
";",
"case",
"'hour'",
":",
"$",
"value",
"=",
"$",
"datetime",
"->",
"format",
"(",
"'H'",
")",
";",
"break",
";",
"case",
"'minute'",
":",
"$",
"value",
"=",
"$",
"datetime",
"->",
"format",
"(",
"'i'",
")",
";",
"break",
";",
"case",
"'second'",
":",
"$",
"value",
"=",
"$",
"datetime",
"->",
"format",
"(",
"'s'",
")",
";",
"break",
";",
"case",
"'month'",
":",
"$",
"value",
"=",
"$",
"datetime",
"->",
"format",
"(",
"'m'",
")",
";",
"break",
";",
"case",
"'ordinal'",
":",
"$",
"value",
"=",
"$",
"datetime",
"->",
"format",
"(",
"'S'",
")",
";",
"break",
";",
"case",
"'week'",
":",
"$",
"value",
"=",
"$",
"datetime",
"->",
"format",
"(",
"'W'",
")",
";",
"break",
";",
"case",
"'year'",
":",
"$",
"value",
"=",
"$",
"datetime",
"->",
"format",
"(",
"'Y'",
")",
";",
"break",
";",
"default",
":",
"$",
"trace",
"=",
"debug_backtrace",
"(",
")",
";",
"trigger_error",
"(",
"'Undefined property: '",
".",
"$",
"name",
".",
"' in '",
".",
"$",
"trace",
"[",
"0",
"]",
"[",
"'file'",
"]",
".",
"' on line '",
".",
"$",
"trace",
"[",
"0",
"]",
"[",
"'line'",
"]",
",",
"E_USER_NOTICE",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] |
Return a value of the property.
@param DateTime $datetime The DateTime object.
@param string $name The name of the property.
@return string
@since 2.0.0
|
[
"Return",
"a",
"value",
"of",
"the",
"property",
"."
] |
732fb60f054fa6aceaef93ff9a12d939d2a4797c
|
https://github.com/joomla-framework/datetime/blob/732fb60f054fa6aceaef93ff9a12d939d2a4797c/src/Getter/DateTimeGetter.php#L30-L90
|
229,436
|
fuelphp/common
|
src/Table/Render/SimpleTable.php
|
SimpleTable.container
|
protected function container(Table $table, array $rows, array $headers, array $footers)
{
$html = '<table';
$this->addAttributes($html, $table->getAttributes());
$html .= '><thead>';
$html .= implode("\n", $headers);
$html .= '</thead><tbody>';
$html .= implode("\n", $rows);
$html .= '</tbody><tfoot>';
$html .= implode("\n", $footers);
$html .= '</tfoot></table>';
return $html;
}
|
php
|
protected function container(Table $table, array $rows, array $headers, array $footers)
{
$html = '<table';
$this->addAttributes($html, $table->getAttributes());
$html .= '><thead>';
$html .= implode("\n", $headers);
$html .= '</thead><tbody>';
$html .= implode("\n", $rows);
$html .= '</tbody><tfoot>';
$html .= implode("\n", $footers);
$html .= '</tfoot></table>';
return $html;
}
|
[
"protected",
"function",
"container",
"(",
"Table",
"$",
"table",
",",
"array",
"$",
"rows",
",",
"array",
"$",
"headers",
",",
"array",
"$",
"footers",
")",
"{",
"$",
"html",
"=",
"'<table'",
";",
"$",
"this",
"->",
"addAttributes",
"(",
"$",
"html",
",",
"$",
"table",
"->",
"getAttributes",
"(",
")",
")",
";",
"$",
"html",
".=",
"'><thead>'",
";",
"$",
"html",
".=",
"implode",
"(",
"\"\\n\"",
",",
"$",
"headers",
")",
";",
"$",
"html",
".=",
"'</thead><tbody>'",
";",
"$",
"html",
".=",
"implode",
"(",
"\"\\n\"",
",",
"$",
"rows",
")",
";",
"$",
"html",
".=",
"'</tbody><tfoot>'",
";",
"$",
"html",
".=",
"implode",
"(",
"\"\\n\"",
",",
"$",
"footers",
")",
";",
"$",
"html",
".=",
"'</tfoot></table>'",
";",
"return",
"$",
"html",
";",
"}"
] |
Generates a "correct" table tag to contain the rendered rows
@param Table $table
@param array $rows
@param array $headers
@param array $footers
@return string
|
[
"Generates",
"a",
"correct",
"table",
"tag",
"to",
"contain",
"the",
"rendered",
"rows"
] |
ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40
|
https://github.com/fuelphp/common/blob/ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40/src/Table/Render/SimpleTable.php#L39-L52
|
229,437
|
fuelphp/common
|
src/Table/Render/SimpleTable.php
|
SimpleTable.row
|
protected function row(Row $row, array $cells)
{
$html = '<tr';
$this->addAttributes($html, $row->getAttributes());
$html .= '>' . implode('', $cells) . '</tr>';
return $html;
}
|
php
|
protected function row(Row $row, array $cells)
{
$html = '<tr';
$this->addAttributes($html, $row->getAttributes());
$html .= '>' . implode('', $cells) . '</tr>';
return $html;
}
|
[
"protected",
"function",
"row",
"(",
"Row",
"$",
"row",
",",
"array",
"$",
"cells",
")",
"{",
"$",
"html",
"=",
"'<tr'",
";",
"$",
"this",
"->",
"addAttributes",
"(",
"$",
"html",
",",
"$",
"row",
"->",
"getAttributes",
"(",
")",
")",
";",
"$",
"html",
".=",
"'>'",
".",
"implode",
"(",
"''",
",",
"$",
"cells",
")",
".",
"'</tr>'",
";",
"return",
"$",
"html",
";",
"}"
] |
Generates a tr with the given rendered cells
@param Row $row
@param array $cells
@return string
|
[
"Generates",
"a",
"tr",
"with",
"the",
"given",
"rendered",
"cells"
] |
ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40
|
https://github.com/fuelphp/common/blob/ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40/src/Table/Render/SimpleTable.php#L62-L69
|
229,438
|
fuelphp/common
|
src/Table/Render/SimpleTable.php
|
SimpleTable.cell
|
protected function cell(Cell $cell)
{
$html = '<td';
$this->addAttributes($html, $cell->getAttributes());
$html .= '>' . $cell->getContent() . '</td>';
return $html;
}
|
php
|
protected function cell(Cell $cell)
{
$html = '<td';
$this->addAttributes($html, $cell->getAttributes());
$html .= '>' . $cell->getContent() . '</td>';
return $html;
}
|
[
"protected",
"function",
"cell",
"(",
"Cell",
"$",
"cell",
")",
"{",
"$",
"html",
"=",
"'<td'",
";",
"$",
"this",
"->",
"addAttributes",
"(",
"$",
"html",
",",
"$",
"cell",
"->",
"getAttributes",
"(",
")",
")",
";",
"$",
"html",
".=",
"'>'",
".",
"$",
"cell",
"->",
"getContent",
"(",
")",
".",
"'</td>'",
";",
"return",
"$",
"html",
";",
"}"
] |
Creates a td tag using the given Cell
@param Cell $cell
@return string
|
[
"Creates",
"a",
"td",
"tag",
"using",
"the",
"given",
"Cell"
] |
ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40
|
https://github.com/fuelphp/common/blob/ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40/src/Table/Render/SimpleTable.php#L78-L85
|
229,439
|
fuelphp/common
|
src/Table/Render/SimpleTable.php
|
SimpleTable.addAttributes
|
protected function addAttributes(&$html, array $attributes)
{
if ( count($attributes) > 0 )
{
$attributes = Html::arrayToAttributes($attributes);
$html .= ' ' . $attributes;
}
}
|
php
|
protected function addAttributes(&$html, array $attributes)
{
if ( count($attributes) > 0 )
{
$attributes = Html::arrayToAttributes($attributes);
$html .= ' ' . $attributes;
}
}
|
[
"protected",
"function",
"addAttributes",
"(",
"&",
"$",
"html",
",",
"array",
"$",
"attributes",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"attributes",
")",
">",
"0",
")",
"{",
"$",
"attributes",
"=",
"Html",
"::",
"arrayToAttributes",
"(",
"$",
"attributes",
")",
";",
"$",
"html",
".=",
"' '",
".",
"$",
"attributes",
";",
"}",
"}"
] |
Helper function to convert an array into a list of attributes and append
them to a string
@param string $html
@param array $attributes
|
[
"Helper",
"function",
"to",
"convert",
"an",
"array",
"into",
"a",
"list",
"of",
"attributes",
"and",
"append",
"them",
"to",
"a",
"string"
] |
ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40
|
https://github.com/fuelphp/common/blob/ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40/src/Table/Render/SimpleTable.php#L94-L102
|
229,440
|
joomla-framework/datetime
|
src/DateInterval.php
|
DateInterval.add
|
public function add(DateInterval $interval)
{
$years = $this->y + $interval->y;
$months = $this->m + $interval->m;
$days = $this->d + $interval->d;
$hours = $this->h + $interval->h;
$minutes = $this->i + $interval->i;
$seconds = $this->s + $interval->s;
$spec = sprintf('P%sY%sM%sDT%sH%sM%sS', $years, $months, $days, $hours, $minutes, $seconds);
return new DateInterval($spec);
}
|
php
|
public function add(DateInterval $interval)
{
$years = $this->y + $interval->y;
$months = $this->m + $interval->m;
$days = $this->d + $interval->d;
$hours = $this->h + $interval->h;
$minutes = $this->i + $interval->i;
$seconds = $this->s + $interval->s;
$spec = sprintf('P%sY%sM%sDT%sH%sM%sS', $years, $months, $days, $hours, $minutes, $seconds);
return new DateInterval($spec);
}
|
[
"public",
"function",
"add",
"(",
"DateInterval",
"$",
"interval",
")",
"{",
"$",
"years",
"=",
"$",
"this",
"->",
"y",
"+",
"$",
"interval",
"->",
"y",
";",
"$",
"months",
"=",
"$",
"this",
"->",
"m",
"+",
"$",
"interval",
"->",
"m",
";",
"$",
"days",
"=",
"$",
"this",
"->",
"d",
"+",
"$",
"interval",
"->",
"d",
";",
"$",
"hours",
"=",
"$",
"this",
"->",
"h",
"+",
"$",
"interval",
"->",
"h",
";",
"$",
"minutes",
"=",
"$",
"this",
"->",
"i",
"+",
"$",
"interval",
"->",
"i",
";",
"$",
"seconds",
"=",
"$",
"this",
"->",
"s",
"+",
"$",
"interval",
"->",
"s",
";",
"$",
"spec",
"=",
"sprintf",
"(",
"'P%sY%sM%sDT%sH%sM%sS'",
",",
"$",
"years",
",",
"$",
"months",
",",
"$",
"days",
",",
"$",
"hours",
",",
"$",
"minutes",
",",
"$",
"seconds",
")",
";",
"return",
"new",
"DateInterval",
"(",
"$",
"spec",
")",
";",
"}"
] |
Creates a DateInterval object by adding another interval into it.
Uses absolute values for addition process.
@param DateInterval $interval The interval to be added.
@return DateInterval
@since 2.0.0
|
[
"Creates",
"a",
"DateInterval",
"object",
"by",
"adding",
"another",
"interval",
"into",
"it",
".",
"Uses",
"absolute",
"values",
"for",
"addition",
"process",
"."
] |
732fb60f054fa6aceaef93ff9a12d939d2a4797c
|
https://github.com/joomla-framework/datetime/blob/732fb60f054fa6aceaef93ff9a12d939d2a4797c/src/DateInterval.php#L70-L82
|
229,441
|
joomla-framework/datetime
|
src/DateInterval.php
|
DateInterval.equals
|
public function equals(DateInterval $interval)
{
$years = $this->y == $interval->y;
$months = $this->m == $interval->m;
$days = $this->d == $interval->d;
$hours = $this->h == $interval->h;
$minutes = $this->i == $interval->i;
$seconds = $this->s == $interval->s;
$invert = $this->invert == $interval->invert;
return $years && $months && $days && $hours && $minutes && $seconds && $invert;
}
|
php
|
public function equals(DateInterval $interval)
{
$years = $this->y == $interval->y;
$months = $this->m == $interval->m;
$days = $this->d == $interval->d;
$hours = $this->h == $interval->h;
$minutes = $this->i == $interval->i;
$seconds = $this->s == $interval->s;
$invert = $this->invert == $interval->invert;
return $years && $months && $days && $hours && $minutes && $seconds && $invert;
}
|
[
"public",
"function",
"equals",
"(",
"DateInterval",
"$",
"interval",
")",
"{",
"$",
"years",
"=",
"$",
"this",
"->",
"y",
"==",
"$",
"interval",
"->",
"y",
";",
"$",
"months",
"=",
"$",
"this",
"->",
"m",
"==",
"$",
"interval",
"->",
"m",
";",
"$",
"days",
"=",
"$",
"this",
"->",
"d",
"==",
"$",
"interval",
"->",
"d",
";",
"$",
"hours",
"=",
"$",
"this",
"->",
"h",
"==",
"$",
"interval",
"->",
"h",
";",
"$",
"minutes",
"=",
"$",
"this",
"->",
"i",
"==",
"$",
"interval",
"->",
"i",
";",
"$",
"seconds",
"=",
"$",
"this",
"->",
"s",
"==",
"$",
"interval",
"->",
"s",
";",
"$",
"invert",
"=",
"$",
"this",
"->",
"invert",
"==",
"$",
"interval",
"->",
"invert",
";",
"return",
"$",
"years",
"&&",
"$",
"months",
"&&",
"$",
"days",
"&&",
"$",
"hours",
"&&",
"$",
"minutes",
"&&",
"$",
"seconds",
"&&",
"$",
"invert",
";",
"}"
] |
Checks if the current interval is equals to the interval given as parameter.
@param DateInterval $interval The interval to compare.
@return boolean
@since 2.0.0
|
[
"Checks",
"if",
"the",
"current",
"interval",
"is",
"equals",
"to",
"the",
"interval",
"given",
"as",
"parameter",
"."
] |
732fb60f054fa6aceaef93ff9a12d939d2a4797c
|
https://github.com/joomla-framework/datetime/blob/732fb60f054fa6aceaef93ff9a12d939d2a4797c/src/DateInterval.php#L93-L104
|
229,442
|
joomla-framework/datetime
|
src/DateInterval.php
|
DateInterval.invert
|
public function invert()
{
$interval = $this->copy($this->interval);
$interval->invert = $interval->invert ? 0 : 1;
return new DateInterval($interval);
}
|
php
|
public function invert()
{
$interval = $this->copy($this->interval);
$interval->invert = $interval->invert ? 0 : 1;
return new DateInterval($interval);
}
|
[
"public",
"function",
"invert",
"(",
")",
"{",
"$",
"interval",
"=",
"$",
"this",
"->",
"copy",
"(",
"$",
"this",
"->",
"interval",
")",
";",
"$",
"interval",
"->",
"invert",
"=",
"$",
"interval",
"->",
"invert",
"?",
"0",
":",
"1",
";",
"return",
"new",
"DateInterval",
"(",
"$",
"interval",
")",
";",
"}"
] |
Creates a DateInterval object by inverting the value of the current one.
@return DateInterval
@since 2.0.0
|
[
"Creates",
"a",
"DateInterval",
"object",
"by",
"inverting",
"the",
"value",
"of",
"the",
"current",
"one",
"."
] |
732fb60f054fa6aceaef93ff9a12d939d2a4797c
|
https://github.com/joomla-framework/datetime/blob/732fb60f054fa6aceaef93ff9a12d939d2a4797c/src/DateInterval.php#L113-L119
|
229,443
|
joomla-framework/datetime
|
src/DateInterval.php
|
DateInterval.copy
|
private function copy(\DateInterval $interval)
{
$copy = new \DateInterval($interval->format('P%yY%mM%dDT%hH%iM%sS'));
$copy->invert = $interval->invert;
return $copy;
}
|
php
|
private function copy(\DateInterval $interval)
{
$copy = new \DateInterval($interval->format('P%yY%mM%dDT%hH%iM%sS'));
$copy->invert = $interval->invert;
return $copy;
}
|
[
"private",
"function",
"copy",
"(",
"\\",
"DateInterval",
"$",
"interval",
")",
"{",
"$",
"copy",
"=",
"new",
"\\",
"DateInterval",
"(",
"$",
"interval",
"->",
"format",
"(",
"'P%yY%mM%dDT%hH%iM%sS'",
")",
")",
";",
"$",
"copy",
"->",
"invert",
"=",
"$",
"interval",
"->",
"invert",
";",
"return",
"$",
"copy",
";",
"}"
] |
Creates a copy of PHP DateInterval object.
@param \DateInterval $interval The object to copy.
@return \DateInterval
@since 2.0.0
|
[
"Creates",
"a",
"copy",
"of",
"PHP",
"DateInterval",
"object",
"."
] |
732fb60f054fa6aceaef93ff9a12d939d2a4797c
|
https://github.com/joomla-framework/datetime/blob/732fb60f054fa6aceaef93ff9a12d939d2a4797c/src/DateInterval.php#L170-L176
|
229,444
|
thelia-modules/Paybox
|
EventListener/SendConfirmationEmail.php
|
SendConfirmationEmail.updateOrderStatus
|
public function updateOrderStatus(OrderEvent $event)
{
$paybox = new Paybox();
if ($event->getOrder()->isPaid() && $paybox->isPaymentModuleFor($event->getOrder())) {
$contact_email = ConfigQuery::read('store_email', false);
Tlog::getInstance()->debug(
"Order ".$event->getOrder()->getRef().": sending confirmation email from store contact e-mail $contact_email"
);
if ($contact_email) {
$order = $event->getOrder();
$this->getMailer()->sendEmailToCustomer(
Paybox::CONFIRMATION_MESSAGE_NAME,
$order->getCustomer(),
[
'order_id' => $order->getId(),
'order_ref' => $order->getRef()
]
);
Tlog::getInstance()->debug("Order ".$order->getRef().": confirmation email sent to customer.");
if (Paybox::getConfigValue('send_confirmation_email_on_successful_payment', false)) {
// Send now the order confirmation email to the customer
$event->getDispatcher()->dispatch(TheliaEvents::ORDER_SEND_CONFIRMATION_EMAIL, $event);
}
}
} else {
Tlog::getInstance()->debug(
"Order ".$event->getOrder()->getRef().": no confirmation email sent (order not paid, or not the proper payment module)."
);
}
}
|
php
|
public function updateOrderStatus(OrderEvent $event)
{
$paybox = new Paybox();
if ($event->getOrder()->isPaid() && $paybox->isPaymentModuleFor($event->getOrder())) {
$contact_email = ConfigQuery::read('store_email', false);
Tlog::getInstance()->debug(
"Order ".$event->getOrder()->getRef().": sending confirmation email from store contact e-mail $contact_email"
);
if ($contact_email) {
$order = $event->getOrder();
$this->getMailer()->sendEmailToCustomer(
Paybox::CONFIRMATION_MESSAGE_NAME,
$order->getCustomer(),
[
'order_id' => $order->getId(),
'order_ref' => $order->getRef()
]
);
Tlog::getInstance()->debug("Order ".$order->getRef().": confirmation email sent to customer.");
if (Paybox::getConfigValue('send_confirmation_email_on_successful_payment', false)) {
// Send now the order confirmation email to the customer
$event->getDispatcher()->dispatch(TheliaEvents::ORDER_SEND_CONFIRMATION_EMAIL, $event);
}
}
} else {
Tlog::getInstance()->debug(
"Order ".$event->getOrder()->getRef().": no confirmation email sent (order not paid, or not the proper payment module)."
);
}
}
|
[
"public",
"function",
"updateOrderStatus",
"(",
"OrderEvent",
"$",
"event",
")",
"{",
"$",
"paybox",
"=",
"new",
"Paybox",
"(",
")",
";",
"if",
"(",
"$",
"event",
"->",
"getOrder",
"(",
")",
"->",
"isPaid",
"(",
")",
"&&",
"$",
"paybox",
"->",
"isPaymentModuleFor",
"(",
"$",
"event",
"->",
"getOrder",
"(",
")",
")",
")",
"{",
"$",
"contact_email",
"=",
"ConfigQuery",
"::",
"read",
"(",
"'store_email'",
",",
"false",
")",
";",
"Tlog",
"::",
"getInstance",
"(",
")",
"->",
"debug",
"(",
"\"Order \"",
".",
"$",
"event",
"->",
"getOrder",
"(",
")",
"->",
"getRef",
"(",
")",
".",
"\": sending confirmation email from store contact e-mail $contact_email\"",
")",
";",
"if",
"(",
"$",
"contact_email",
")",
"{",
"$",
"order",
"=",
"$",
"event",
"->",
"getOrder",
"(",
")",
";",
"$",
"this",
"->",
"getMailer",
"(",
")",
"->",
"sendEmailToCustomer",
"(",
"Paybox",
"::",
"CONFIRMATION_MESSAGE_NAME",
",",
"$",
"order",
"->",
"getCustomer",
"(",
")",
",",
"[",
"'order_id'",
"=>",
"$",
"order",
"->",
"getId",
"(",
")",
",",
"'order_ref'",
"=>",
"$",
"order",
"->",
"getRef",
"(",
")",
"]",
")",
";",
"Tlog",
"::",
"getInstance",
"(",
")",
"->",
"debug",
"(",
"\"Order \"",
".",
"$",
"order",
"->",
"getRef",
"(",
")",
".",
"\": confirmation email sent to customer.\"",
")",
";",
"if",
"(",
"Paybox",
"::",
"getConfigValue",
"(",
"'send_confirmation_email_on_successful_payment'",
",",
"false",
")",
")",
"{",
"// Send now the order confirmation email to the customer",
"$",
"event",
"->",
"getDispatcher",
"(",
")",
"->",
"dispatch",
"(",
"TheliaEvents",
"::",
"ORDER_SEND_CONFIRMATION_EMAIL",
",",
"$",
"event",
")",
";",
"}",
"}",
"}",
"else",
"{",
"Tlog",
"::",
"getInstance",
"(",
")",
"->",
"debug",
"(",
"\"Order \"",
".",
"$",
"event",
"->",
"getOrder",
"(",
")",
"->",
"getRef",
"(",
")",
".",
"\": no confirmation email sent (order not paid, or not the proper payment module).\"",
")",
";",
"}",
"}"
] |
Checks if we are the payment module for the order, and if the order is paid,
then send a confirmation email to the customer.
@param OrderEvent $event
@throws \Exception
|
[
"Checks",
"if",
"we",
"are",
"the",
"payment",
"module",
"for",
"the",
"order",
"and",
"if",
"the",
"order",
"is",
"paid",
"then",
"send",
"a",
"confirmation",
"email",
"to",
"the",
"customer",
"."
] |
08b9f4478ecbdb234fc373d6540010af34d2d87c
|
https://github.com/thelia-modules/Paybox/blob/08b9f4478ecbdb234fc373d6540010af34d2d87c/EventListener/SendConfirmationEmail.php#L61-L96
|
229,445
|
thelia-modules/Paybox
|
EventListener/SendConfirmationEmail.php
|
SendConfirmationEmail.checkSendOrderConfirmationMessageToCustomer
|
public function checkSendOrderConfirmationMessageToCustomer(OrderEvent $event)
{
if (Paybox::getConfigValue('send_confirmation_email_on_successful_payment', false)) {
$paybox = new Paybox();
if ($paybox->isPaymentModuleFor($event->getOrder())) {
if (!$event->getOrder()->isPaid()) {
$event->stopPropagation();
}
}
}
}
|
php
|
public function checkSendOrderConfirmationMessageToCustomer(OrderEvent $event)
{
if (Paybox::getConfigValue('send_confirmation_email_on_successful_payment', false)) {
$paybox = new Paybox();
if ($paybox->isPaymentModuleFor($event->getOrder())) {
if (!$event->getOrder()->isPaid()) {
$event->stopPropagation();
}
}
}
}
|
[
"public",
"function",
"checkSendOrderConfirmationMessageToCustomer",
"(",
"OrderEvent",
"$",
"event",
")",
"{",
"if",
"(",
"Paybox",
"::",
"getConfigValue",
"(",
"'send_confirmation_email_on_successful_payment'",
",",
"false",
")",
")",
"{",
"$",
"paybox",
"=",
"new",
"Paybox",
"(",
")",
";",
"if",
"(",
"$",
"paybox",
"->",
"isPaymentModuleFor",
"(",
"$",
"event",
"->",
"getOrder",
"(",
")",
")",
")",
"{",
"if",
"(",
"!",
"$",
"event",
"->",
"getOrder",
"(",
")",
"->",
"isPaid",
"(",
")",
")",
"{",
"$",
"event",
"->",
"stopPropagation",
"(",
")",
";",
"}",
"}",
"}",
"}"
] |
Send the confirmation message only if the order is paid.
@param OrderEvent $event
|
[
"Send",
"the",
"confirmation",
"message",
"only",
"if",
"the",
"order",
"is",
"paid",
"."
] |
08b9f4478ecbdb234fc373d6540010af34d2d87c
|
https://github.com/thelia-modules/Paybox/blob/08b9f4478ecbdb234fc373d6540010af34d2d87c/EventListener/SendConfirmationEmail.php#L103-L114
|
229,446
|
michaeljs1990/jmem
|
src/Jmem/JsonLoader.php
|
JsonLoader.setFile
|
public function setFile($file) {
$f = $file;
if (preg_match('#^compress\.(.*)://(.*)#', $file, $r)) {
$f = $r[2];
}
if(is_readable($f)) {
$open = fopen($file, "rb");
$this->file = $open;
} else {
$this->handleError("{$file} is not readable.");
}
}
|
php
|
public function setFile($file) {
$f = $file;
if (preg_match('#^compress\.(.*)://(.*)#', $file, $r)) {
$f = $r[2];
}
if(is_readable($f)) {
$open = fopen($file, "rb");
$this->file = $open;
} else {
$this->handleError("{$file} is not readable.");
}
}
|
[
"public",
"function",
"setFile",
"(",
"$",
"file",
")",
"{",
"$",
"f",
"=",
"$",
"file",
";",
"if",
"(",
"preg_match",
"(",
"'#^compress\\.(.*)://(.*)#'",
",",
"$",
"file",
",",
"$",
"r",
")",
")",
"{",
"$",
"f",
"=",
"$",
"r",
"[",
"2",
"]",
";",
"}",
"if",
"(",
"is_readable",
"(",
"$",
"f",
")",
")",
"{",
"$",
"open",
"=",
"fopen",
"(",
"$",
"file",
",",
"\"rb\"",
")",
";",
"$",
"this",
"->",
"file",
"=",
"$",
"open",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"handleError",
"(",
"\"{$file} is not readable.\"",
")",
";",
"}",
"}"
] |
Set the file and open up a steam. If the file
cannot be opened for reading throw an error.
@param $file
@throws \Exception
|
[
"Set",
"the",
"file",
"and",
"open",
"up",
"a",
"steam",
".",
"If",
"the",
"file",
"cannot",
"be",
"opened",
"for",
"reading",
"throw",
"an",
"error",
"."
] |
3252fa2cccc90e564cf7295abf8625e07b52f908
|
https://github.com/michaeljs1990/jmem/blob/3252fa2cccc90e564cf7295abf8625e07b52f908/src/Jmem/JsonLoader.php#L40-L52
|
229,447
|
netgen/NetgenOpenGraphBundle
|
bundle/Handler/FieldType/Handler.php
|
Handler.validateField
|
protected function validateField($fieldIdentifier)
{
$field = $this->translationHelper->getTranslatedField($this->content, $fieldIdentifier);
if (!$field instanceof Field) {
throw new InvalidArgumentException('$params[0]', 'Field \'' . $fieldIdentifier . '\' does not exist in content.');
}
if (!$this->supports($field)) {
throw new InvalidArgumentException(
'$params[0]',
get_class($this) . ' field type handler does not support field with identifier \'' . $field->fieldDefIdentifier . '\'.'
);
}
return $field;
}
|
php
|
protected function validateField($fieldIdentifier)
{
$field = $this->translationHelper->getTranslatedField($this->content, $fieldIdentifier);
if (!$field instanceof Field) {
throw new InvalidArgumentException('$params[0]', 'Field \'' . $fieldIdentifier . '\' does not exist in content.');
}
if (!$this->supports($field)) {
throw new InvalidArgumentException(
'$params[0]',
get_class($this) . ' field type handler does not support field with identifier \'' . $field->fieldDefIdentifier . '\'.'
);
}
return $field;
}
|
[
"protected",
"function",
"validateField",
"(",
"$",
"fieldIdentifier",
")",
"{",
"$",
"field",
"=",
"$",
"this",
"->",
"translationHelper",
"->",
"getTranslatedField",
"(",
"$",
"this",
"->",
"content",
",",
"$",
"fieldIdentifier",
")",
";",
"if",
"(",
"!",
"$",
"field",
"instanceof",
"Field",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'$params[0]'",
",",
"'Field \\''",
".",
"$",
"fieldIdentifier",
".",
"'\\' does not exist in content.'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"supports",
"(",
"$",
"field",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'$params[0]'",
",",
"get_class",
"(",
"$",
"this",
")",
".",
"' field type handler does not support field with identifier \\''",
".",
"$",
"field",
"->",
"fieldDefIdentifier",
".",
"'\\'.'",
")",
";",
"}",
"return",
"$",
"field",
";",
"}"
] |
Validates field by field identifier.
@param string $fieldIdentifier
@throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If field does not exist, or the handler does not support it
@returns \eZ\Publish\API\Repository\Values\Content\Field
|
[
"Validates",
"field",
"by",
"field",
"identifier",
"."
] |
fcaad267742492cfa4049adbf075343c262c4767
|
https://github.com/netgen/NetgenOpenGraphBundle/blob/fcaad267742492cfa4049adbf075343c262c4767/bundle/Handler/FieldType/Handler.php#L124-L139
|
229,448
|
milesj/utility
|
View/Helper/DecodaHelper.php
|
DecodaHelper.parse
|
public function parse($string, array $whitelist = array(), $wrap = true) {
$parsed = $this->getDecoda()->reset($string)->whitelist($whitelist)->parse();
if ($wrap) {
return $this->Html->div('decoda', $parsed);
}
return $parsed;
}
|
php
|
public function parse($string, array $whitelist = array(), $wrap = true) {
$parsed = $this->getDecoda()->reset($string)->whitelist($whitelist)->parse();
if ($wrap) {
return $this->Html->div('decoda', $parsed);
}
return $parsed;
}
|
[
"public",
"function",
"parse",
"(",
"$",
"string",
",",
"array",
"$",
"whitelist",
"=",
"array",
"(",
")",
",",
"$",
"wrap",
"=",
"true",
")",
"{",
"$",
"parsed",
"=",
"$",
"this",
"->",
"getDecoda",
"(",
")",
"->",
"reset",
"(",
"$",
"string",
")",
"->",
"whitelist",
"(",
"$",
"whitelist",
")",
"->",
"parse",
"(",
")",
";",
"if",
"(",
"$",
"wrap",
")",
"{",
"return",
"$",
"this",
"->",
"Html",
"->",
"div",
"(",
"'decoda'",
",",
"$",
"parsed",
")",
";",
"}",
"return",
"$",
"parsed",
";",
"}"
] |
Reset the Decoda instance, apply any whitelisted tags and executes the parsing process.
@param string $string
@param array $whitelist
@param bool $wrap
@return string
|
[
"Reset",
"the",
"Decoda",
"instance",
"apply",
"any",
"whitelisted",
"tags",
"and",
"executes",
"the",
"parsing",
"process",
"."
] |
146318ff0a882917defab7f4918b0d198eb5a3c0
|
https://github.com/milesj/utility/blob/146318ff0a882917defab7f4918b0d198eb5a3c0/View/Helper/DecodaHelper.php#L125-L133
|
229,449
|
milesj/utility
|
View/Helper/DecodaHelper.php
|
DecodaHelper.strip
|
public function strip($string, $html = false) {
return $this->getDecoda()->reset($string)->strip($html);
}
|
php
|
public function strip($string, $html = false) {
return $this->getDecoda()->reset($string)->strip($html);
}
|
[
"public",
"function",
"strip",
"(",
"$",
"string",
",",
"$",
"html",
"=",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"getDecoda",
"(",
")",
"->",
"reset",
"(",
"$",
"string",
")",
"->",
"strip",
"(",
"$",
"html",
")",
";",
"}"
] |
Reset the Decoda instance and strip out any Decoda tags and HTML.
@param string $string
@param bool $html
@return string
|
[
"Reset",
"the",
"Decoda",
"instance",
"and",
"strip",
"out",
"any",
"Decoda",
"tags",
"and",
"HTML",
"."
] |
146318ff0a882917defab7f4918b0d198eb5a3c0
|
https://github.com/milesj/utility/blob/146318ff0a882917defab7f4918b0d198eb5a3c0/View/Helper/DecodaHelper.php#L142-L144
|
229,450
|
medz/oss-stream-wrapper
|
src/AliyunOssStream.php
|
AliyunOssStream._getOssClient
|
protected function _getOssClient($path)
{
if ($this->_oss === null) {
$url = explode(':', $path);
if (empty($url)) {
throw new Exception("Unable to parse URL $path");
}
$this->_oss = AliyunOSS::getWrapperClient($url[0]);
if (!$this->_oss) {
throw new Exception("Unknown client for wrapper {$url[0]}");
}
}
return $this->_oss;
}
|
php
|
protected function _getOssClient($path)
{
if ($this->_oss === null) {
$url = explode(':', $path);
if (empty($url)) {
throw new Exception("Unable to parse URL $path");
}
$this->_oss = AliyunOSS::getWrapperClient($url[0]);
if (!$this->_oss) {
throw new Exception("Unknown client for wrapper {$url[0]}");
}
}
return $this->_oss;
}
|
[
"protected",
"function",
"_getOssClient",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_oss",
"===",
"null",
")",
"{",
"$",
"url",
"=",
"explode",
"(",
"':'",
",",
"$",
"path",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"url",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Unable to parse URL $path\"",
")",
";",
"}",
"$",
"this",
"->",
"_oss",
"=",
"AliyunOSS",
"::",
"getWrapperClient",
"(",
"$",
"url",
"[",
"0",
"]",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"_oss",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Unknown client for wrapper {$url[0]}\"",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"_oss",
";",
"}"
] |
Retrieve client for this stream type.
@param string $path
@return oss
@author Seven Du <lovevipdsw@outlook.com>
@homepage http://medz.cn
|
[
"Retrieve",
"client",
"for",
"this",
"stream",
"type",
"."
] |
0630ed71351c6b804a815cff553fd0f57509ab54
|
https://github.com/medz/oss-stream-wrapper/blob/0630ed71351c6b804a815cff553fd0f57509ab54/src/AliyunOssStream.php#L55-L72
|
229,451
|
medz/oss-stream-wrapper
|
src/AliyunOssStream.php
|
AliyunOssStream._getNamePart
|
protected function _getNamePart($path)
{
$url = parse_url($path);
if ($url['host']) {
return !empty($url['path']) ? $url['host'].$url['path'] : $url['host'];
}
return '';
}
|
php
|
protected function _getNamePart($path)
{
$url = parse_url($path);
if ($url['host']) {
return !empty($url['path']) ? $url['host'].$url['path'] : $url['host'];
}
return '';
}
|
[
"protected",
"function",
"_getNamePart",
"(",
"$",
"path",
")",
"{",
"$",
"url",
"=",
"parse_url",
"(",
"$",
"path",
")",
";",
"if",
"(",
"$",
"url",
"[",
"'host'",
"]",
")",
"{",
"return",
"!",
"empty",
"(",
"$",
"url",
"[",
"'path'",
"]",
")",
"?",
"$",
"url",
"[",
"'host'",
"]",
".",
"$",
"url",
"[",
"'path'",
"]",
":",
"$",
"url",
"[",
"'host'",
"]",
";",
"}",
"return",
"''",
";",
"}"
] |
Extract object name from URL.
@param string $path
@return string
|
[
"Extract",
"object",
"name",
"from",
"URL",
"."
] |
0630ed71351c6b804a815cff553fd0f57509ab54
|
https://github.com/medz/oss-stream-wrapper/blob/0630ed71351c6b804a815cff553fd0f57509ab54/src/AliyunOssStream.php#L81-L89
|
229,452
|
medz/oss-stream-wrapper
|
src/AliyunOssStream.php
|
AliyunOssStream.stream_open
|
public function stream_open($path, $mode, $options, &$opened_path)
{
$name = $this->_getNamePart($path);
// If we open the file for writing, just return true. Create the object
// on fflush call
if (strpbrk($mode, 'wax')) {
$this->_objectName = $name;
$this->_objectBuffer = null;
$this->_objectSize = 0;
$this->_position = 0;
$this->_writeBuffer = true;
$this->_getOssClient($path);
return true;
} else {
// Otherwise, just see if the file exists or not
try {
$info = $this->_getOssClient($path)->getObjectMeta(AliyunOSS::getBucket(), $name);
if ($info) {
$this->_objectName = $name;
$this->_objectBuffer = null;
$this->_objectSize = (int) $info['content-length'];
$this->_position = 0;
$this->_writeBuffer = false;
return true;
}
} catch (\OSS\Core\OssException $e) {
return false;
}
}
return false;
}
|
php
|
public function stream_open($path, $mode, $options, &$opened_path)
{
$name = $this->_getNamePart($path);
// If we open the file for writing, just return true. Create the object
// on fflush call
if (strpbrk($mode, 'wax')) {
$this->_objectName = $name;
$this->_objectBuffer = null;
$this->_objectSize = 0;
$this->_position = 0;
$this->_writeBuffer = true;
$this->_getOssClient($path);
return true;
} else {
// Otherwise, just see if the file exists or not
try {
$info = $this->_getOssClient($path)->getObjectMeta(AliyunOSS::getBucket(), $name);
if ($info) {
$this->_objectName = $name;
$this->_objectBuffer = null;
$this->_objectSize = (int) $info['content-length'];
$this->_position = 0;
$this->_writeBuffer = false;
return true;
}
} catch (\OSS\Core\OssException $e) {
return false;
}
}
return false;
}
|
[
"public",
"function",
"stream_open",
"(",
"$",
"path",
",",
"$",
"mode",
",",
"$",
"options",
",",
"&",
"$",
"opened_path",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"_getNamePart",
"(",
"$",
"path",
")",
";",
"// If we open the file for writing, just return true. Create the object",
"// on fflush call",
"if",
"(",
"strpbrk",
"(",
"$",
"mode",
",",
"'wax'",
")",
")",
"{",
"$",
"this",
"->",
"_objectName",
"=",
"$",
"name",
";",
"$",
"this",
"->",
"_objectBuffer",
"=",
"null",
";",
"$",
"this",
"->",
"_objectSize",
"=",
"0",
";",
"$",
"this",
"->",
"_position",
"=",
"0",
";",
"$",
"this",
"->",
"_writeBuffer",
"=",
"true",
";",
"$",
"this",
"->",
"_getOssClient",
"(",
"$",
"path",
")",
";",
"return",
"true",
";",
"}",
"else",
"{",
"// Otherwise, just see if the file exists or not",
"try",
"{",
"$",
"info",
"=",
"$",
"this",
"->",
"_getOssClient",
"(",
"$",
"path",
")",
"->",
"getObjectMeta",
"(",
"AliyunOSS",
"::",
"getBucket",
"(",
")",
",",
"$",
"name",
")",
";",
"if",
"(",
"$",
"info",
")",
"{",
"$",
"this",
"->",
"_objectName",
"=",
"$",
"name",
";",
"$",
"this",
"->",
"_objectBuffer",
"=",
"null",
";",
"$",
"this",
"->",
"_objectSize",
"=",
"(",
"int",
")",
"$",
"info",
"[",
"'content-length'",
"]",
";",
"$",
"this",
"->",
"_position",
"=",
"0",
";",
"$",
"this",
"->",
"_writeBuffer",
"=",
"false",
";",
"return",
"true",
";",
"}",
"}",
"catch",
"(",
"\\",
"OSS",
"\\",
"Core",
"\\",
"OssException",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Open the stream.
@param string $path
@param string $mode
@param int $options
@param string $opened_path
@return bool
|
[
"Open",
"the",
"stream",
"."
] |
0630ed71351c6b804a815cff553fd0f57509ab54
|
https://github.com/medz/oss-stream-wrapper/blob/0630ed71351c6b804a815cff553fd0f57509ab54/src/AliyunOssStream.php#L101-L134
|
229,453
|
medz/oss-stream-wrapper
|
src/AliyunOssStream.php
|
AliyunOssStream.stream_close
|
public function stream_close()
{
$this->_objectName = null;
$this->_objectBuffer = null;
$this->_objectSize = 0;
$this->_position = 0;
$this->_writeBuffer = false;
unset($this->_oss);
}
|
php
|
public function stream_close()
{
$this->_objectName = null;
$this->_objectBuffer = null;
$this->_objectSize = 0;
$this->_position = 0;
$this->_writeBuffer = false;
unset($this->_oss);
}
|
[
"public",
"function",
"stream_close",
"(",
")",
"{",
"$",
"this",
"->",
"_objectName",
"=",
"null",
";",
"$",
"this",
"->",
"_objectBuffer",
"=",
"null",
";",
"$",
"this",
"->",
"_objectSize",
"=",
"0",
";",
"$",
"this",
"->",
"_position",
"=",
"0",
";",
"$",
"this",
"->",
"_writeBuffer",
"=",
"false",
";",
"unset",
"(",
"$",
"this",
"->",
"_oss",
")",
";",
"}"
] |
Close the stream.
@return void
|
[
"Close",
"the",
"stream",
"."
] |
0630ed71351c6b804a815cff553fd0f57509ab54
|
https://github.com/medz/oss-stream-wrapper/blob/0630ed71351c6b804a815cff553fd0f57509ab54/src/AliyunOssStream.php#L141-L149
|
229,454
|
medz/oss-stream-wrapper
|
src/AliyunOssStream.php
|
AliyunOssStream.stream_read
|
public function stream_read($count)
{
if (!$this->_objectName) {
return '';
}
// make sure that count doesn't exceed object size
if ($count + $this->_position > $this->_objectSize) {
$count = $this->_objectSize - $this->_position;
}
$range_start = $this->_position;
$range_end = $this->_position + $count -1;
// Only fetch more data from OSS if we haven't fetched any data yet (postion=0)
// OR, the range end position is greater than the size of the current object
// buffer AND if the range end position is less than or equal to the object's
// size returned by OSS
if (($this->_position == 0) || (($range_end > strlen($this->_objectBuffer)) && ($range_end <= $this->_objectSize))) {
$options = [
OssClient::OSS_RANGE => $range_start.'-'.$range_end,
];
$this->_objectBuffer .= $this->_oss->getObject(AliyunOSS::getBucket(), $this->_objectName, $options);
}
$data = substr($this->_objectBuffer, $this->_position, $count);
$this->_position += strlen($data);
return $data;
}
|
php
|
public function stream_read($count)
{
if (!$this->_objectName) {
return '';
}
// make sure that count doesn't exceed object size
if ($count + $this->_position > $this->_objectSize) {
$count = $this->_objectSize - $this->_position;
}
$range_start = $this->_position;
$range_end = $this->_position + $count -1;
// Only fetch more data from OSS if we haven't fetched any data yet (postion=0)
// OR, the range end position is greater than the size of the current object
// buffer AND if the range end position is less than or equal to the object's
// size returned by OSS
if (($this->_position == 0) || (($range_end > strlen($this->_objectBuffer)) && ($range_end <= $this->_objectSize))) {
$options = [
OssClient::OSS_RANGE => $range_start.'-'.$range_end,
];
$this->_objectBuffer .= $this->_oss->getObject(AliyunOSS::getBucket(), $this->_objectName, $options);
}
$data = substr($this->_objectBuffer, $this->_position, $count);
$this->_position += strlen($data);
return $data;
}
|
[
"public",
"function",
"stream_read",
"(",
"$",
"count",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_objectName",
")",
"{",
"return",
"''",
";",
"}",
"// make sure that count doesn't exceed object size",
"if",
"(",
"$",
"count",
"+",
"$",
"this",
"->",
"_position",
">",
"$",
"this",
"->",
"_objectSize",
")",
"{",
"$",
"count",
"=",
"$",
"this",
"->",
"_objectSize",
"-",
"$",
"this",
"->",
"_position",
";",
"}",
"$",
"range_start",
"=",
"$",
"this",
"->",
"_position",
";",
"$",
"range_end",
"=",
"$",
"this",
"->",
"_position",
"+",
"$",
"count",
"-",
"1",
";",
"// Only fetch more data from OSS if we haven't fetched any data yet (postion=0)",
"// OR, the range end position is greater than the size of the current object",
"// buffer AND if the range end position is less than or equal to the object's",
"// size returned by OSS",
"if",
"(",
"(",
"$",
"this",
"->",
"_position",
"==",
"0",
")",
"||",
"(",
"(",
"$",
"range_end",
">",
"strlen",
"(",
"$",
"this",
"->",
"_objectBuffer",
")",
")",
"&&",
"(",
"$",
"range_end",
"<=",
"$",
"this",
"->",
"_objectSize",
")",
")",
")",
"{",
"$",
"options",
"=",
"[",
"OssClient",
"::",
"OSS_RANGE",
"=>",
"$",
"range_start",
".",
"'-'",
".",
"$",
"range_end",
",",
"]",
";",
"$",
"this",
"->",
"_objectBuffer",
".=",
"$",
"this",
"->",
"_oss",
"->",
"getObject",
"(",
"AliyunOSS",
"::",
"getBucket",
"(",
")",
",",
"$",
"this",
"->",
"_objectName",
",",
"$",
"options",
")",
";",
"}",
"$",
"data",
"=",
"substr",
"(",
"$",
"this",
"->",
"_objectBuffer",
",",
"$",
"this",
"->",
"_position",
",",
"$",
"count",
")",
";",
"$",
"this",
"->",
"_position",
"+=",
"strlen",
"(",
"$",
"data",
")",
";",
"return",
"$",
"data",
";",
"}"
] |
Read from the stream.
http://bugs.php.net/21641 - stream_read() is always passed PHP's
internal read buffer size (8192) no matter what is passed as $count
parameter to fread().
@param int $count
@return string
|
[
"Read",
"from",
"the",
"stream",
"."
] |
0630ed71351c6b804a815cff553fd0f57509ab54
|
https://github.com/medz/oss-stream-wrapper/blob/0630ed71351c6b804a815cff553fd0f57509ab54/src/AliyunOssStream.php#L162-L191
|
229,455
|
medz/oss-stream-wrapper
|
src/AliyunOssStream.php
|
AliyunOssStream.stream_write
|
public function stream_write($data)
{
if (!$this->_objectName) {
return 0;
}
$len = strlen($data);
$this->_objectBuffer .= $data;
$this->_objectSize += $len;
// TODO: handle current position for writing!
return $len;
}
|
php
|
public function stream_write($data)
{
if (!$this->_objectName) {
return 0;
}
$len = strlen($data);
$this->_objectBuffer .= $data;
$this->_objectSize += $len;
// TODO: handle current position for writing!
return $len;
}
|
[
"public",
"function",
"stream_write",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_objectName",
")",
"{",
"return",
"0",
";",
"}",
"$",
"len",
"=",
"strlen",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"_objectBuffer",
".=",
"$",
"data",
";",
"$",
"this",
"->",
"_objectSize",
"+=",
"$",
"len",
";",
"// TODO: handle current position for writing!",
"return",
"$",
"len",
";",
"}"
] |
Write to the stream.
@param string $data
@return int
|
[
"Write",
"to",
"the",
"stream",
"."
] |
0630ed71351c6b804a815cff553fd0f57509ab54
|
https://github.com/medz/oss-stream-wrapper/blob/0630ed71351c6b804a815cff553fd0f57509ab54/src/AliyunOssStream.php#L200-L210
|
229,456
|
medz/oss-stream-wrapper
|
src/AliyunOssStream.php
|
AliyunOssStream.stream_flush
|
public function stream_flush()
{
// If the stream wasn't opened for writing, just return false
if (!$this->_writeBuffer) {
return false;
}
$ret = $this->_oss->putObject(AliyunOSS::getBucket(), $this->_objectName, $this->_objectBuffer);
$this->_objectBuffer = null;
return $ret;
}
|
php
|
public function stream_flush()
{
// If the stream wasn't opened for writing, just return false
if (!$this->_writeBuffer) {
return false;
}
$ret = $this->_oss->putObject(AliyunOSS::getBucket(), $this->_objectName, $this->_objectBuffer);
$this->_objectBuffer = null;
return $ret;
}
|
[
"public",
"function",
"stream_flush",
"(",
")",
"{",
"// If the stream wasn't opened for writing, just return false",
"if",
"(",
"!",
"$",
"this",
"->",
"_writeBuffer",
")",
"{",
"return",
"false",
";",
"}",
"$",
"ret",
"=",
"$",
"this",
"->",
"_oss",
"->",
"putObject",
"(",
"AliyunOSS",
"::",
"getBucket",
"(",
")",
",",
"$",
"this",
"->",
"_objectName",
",",
"$",
"this",
"->",
"_objectBuffer",
")",
";",
"$",
"this",
"->",
"_objectBuffer",
"=",
"null",
";",
"return",
"$",
"ret",
";",
"}"
] |
Flush current cached stream data to storage.
@return bool
|
[
"Flush",
"current",
"cached",
"stream",
"data",
"to",
"storage",
"."
] |
0630ed71351c6b804a815cff553fd0f57509ab54
|
https://github.com/medz/oss-stream-wrapper/blob/0630ed71351c6b804a815cff553fd0f57509ab54/src/AliyunOssStream.php#L302-L312
|
229,457
|
medz/oss-stream-wrapper
|
src/AliyunOssStream.php
|
AliyunOssStream.stream_stat
|
public function stream_stat()
{
if (!$this->_objectName) {
return [];
}
$stat = [];
$stat['dev'] = 0;
$stat['ino'] = 0;
$stat['mode'] = 0777;
$stat['nlink'] = 0;
$stat['uid'] = 0;
$stat['gid'] = 0;
$stat['rdev'] = 0;
$stat['size'] = 0;
$stat['atime'] = 0;
$stat['mtime'] = 0;
$stat['ctime'] = 0;
$stat['blksize'] = 0;
$stat['blocks'] = 0;
if (($slash = strstr($this->_objectName, '/')) === false || $slash == strlen($this->_objectName) - 1) {
/* bucket */
$stat['mode'] |= 040000;
} else {
$stat['mode'] |= 0100000;
}
$info = $this->_oss->getObjectMeta(AliyunOSS::getBucket(), $this->_objectName);
$info = $info['info'];
if (!empty($info['info'])) {
$stat['size'] = $info['download_content_length'];
$stat['atime'] = time();
$stat['mtime'] = $info['filetime'];
}
return $stat;
}
|
php
|
public function stream_stat()
{
if (!$this->_objectName) {
return [];
}
$stat = [];
$stat['dev'] = 0;
$stat['ino'] = 0;
$stat['mode'] = 0777;
$stat['nlink'] = 0;
$stat['uid'] = 0;
$stat['gid'] = 0;
$stat['rdev'] = 0;
$stat['size'] = 0;
$stat['atime'] = 0;
$stat['mtime'] = 0;
$stat['ctime'] = 0;
$stat['blksize'] = 0;
$stat['blocks'] = 0;
if (($slash = strstr($this->_objectName, '/')) === false || $slash == strlen($this->_objectName) - 1) {
/* bucket */
$stat['mode'] |= 040000;
} else {
$stat['mode'] |= 0100000;
}
$info = $this->_oss->getObjectMeta(AliyunOSS::getBucket(), $this->_objectName);
$info = $info['info'];
if (!empty($info['info'])) {
$stat['size'] = $info['download_content_length'];
$stat['atime'] = time();
$stat['mtime'] = $info['filetime'];
}
return $stat;
}
|
[
"public",
"function",
"stream_stat",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_objectName",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"stat",
"=",
"[",
"]",
";",
"$",
"stat",
"[",
"'dev'",
"]",
"=",
"0",
";",
"$",
"stat",
"[",
"'ino'",
"]",
"=",
"0",
";",
"$",
"stat",
"[",
"'mode'",
"]",
"=",
"0777",
";",
"$",
"stat",
"[",
"'nlink'",
"]",
"=",
"0",
";",
"$",
"stat",
"[",
"'uid'",
"]",
"=",
"0",
";",
"$",
"stat",
"[",
"'gid'",
"]",
"=",
"0",
";",
"$",
"stat",
"[",
"'rdev'",
"]",
"=",
"0",
";",
"$",
"stat",
"[",
"'size'",
"]",
"=",
"0",
";",
"$",
"stat",
"[",
"'atime'",
"]",
"=",
"0",
";",
"$",
"stat",
"[",
"'mtime'",
"]",
"=",
"0",
";",
"$",
"stat",
"[",
"'ctime'",
"]",
"=",
"0",
";",
"$",
"stat",
"[",
"'blksize'",
"]",
"=",
"0",
";",
"$",
"stat",
"[",
"'blocks'",
"]",
"=",
"0",
";",
"if",
"(",
"(",
"$",
"slash",
"=",
"strstr",
"(",
"$",
"this",
"->",
"_objectName",
",",
"'/'",
")",
")",
"===",
"false",
"||",
"$",
"slash",
"==",
"strlen",
"(",
"$",
"this",
"->",
"_objectName",
")",
"-",
"1",
")",
"{",
"/* bucket */",
"$",
"stat",
"[",
"'mode'",
"]",
"|=",
"040000",
";",
"}",
"else",
"{",
"$",
"stat",
"[",
"'mode'",
"]",
"|=",
"0100000",
";",
"}",
"$",
"info",
"=",
"$",
"this",
"->",
"_oss",
"->",
"getObjectMeta",
"(",
"AliyunOSS",
"::",
"getBucket",
"(",
")",
",",
"$",
"this",
"->",
"_objectName",
")",
";",
"$",
"info",
"=",
"$",
"info",
"[",
"'info'",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"info",
"[",
"'info'",
"]",
")",
")",
"{",
"$",
"stat",
"[",
"'size'",
"]",
"=",
"$",
"info",
"[",
"'download_content_length'",
"]",
";",
"$",
"stat",
"[",
"'atime'",
"]",
"=",
"time",
"(",
")",
";",
"$",
"stat",
"[",
"'mtime'",
"]",
"=",
"$",
"info",
"[",
"'filetime'",
"]",
";",
"}",
"return",
"$",
"stat",
";",
"}"
] |
Returns data array of stream variables.
@return array
|
[
"Returns",
"data",
"array",
"of",
"stream",
"variables",
"."
] |
0630ed71351c6b804a815cff553fd0f57509ab54
|
https://github.com/medz/oss-stream-wrapper/blob/0630ed71351c6b804a815cff553fd0f57509ab54/src/AliyunOssStream.php#L319-L355
|
229,458
|
medz/oss-stream-wrapper
|
src/AliyunOssStream.php
|
AliyunOssStream.unlink
|
public function unlink($path)
{
return $this->_getOssClient($path)->deleteObject(AliyunOSS::getBucket(), $this->_getNamePart($path));
}
|
php
|
public function unlink($path)
{
return $this->_getOssClient($path)->deleteObject(AliyunOSS::getBucket(), $this->_getNamePart($path));
}
|
[
"public",
"function",
"unlink",
"(",
"$",
"path",
")",
"{",
"return",
"$",
"this",
"->",
"_getOssClient",
"(",
"$",
"path",
")",
"->",
"deleteObject",
"(",
"AliyunOSS",
"::",
"getBucket",
"(",
")",
",",
"$",
"this",
"->",
"_getNamePart",
"(",
"$",
"path",
")",
")",
";",
"}"
] |
Attempt to delete the item.
@param string $path
@return bool
|
[
"Attempt",
"to",
"delete",
"the",
"item",
"."
] |
0630ed71351c6b804a815cff553fd0f57509ab54
|
https://github.com/medz/oss-stream-wrapper/blob/0630ed71351c6b804a815cff553fd0f57509ab54/src/AliyunOssStream.php#L364-L367
|
229,459
|
medz/oss-stream-wrapper
|
src/AliyunOssStream.php
|
AliyunOssStream.dir_readdir
|
public function dir_readdir()
{
$object = current($this->_bucketList);
if ($object !== false) {
next($this->_bucketList);
}
return $object;
}
|
php
|
public function dir_readdir()
{
$object = current($this->_bucketList);
if ($object !== false) {
next($this->_bucketList);
}
return $object;
}
|
[
"public",
"function",
"dir_readdir",
"(",
")",
"{",
"$",
"object",
"=",
"current",
"(",
"$",
"this",
"->",
"_bucketList",
")",
";",
"if",
"(",
"$",
"object",
"!==",
"false",
")",
"{",
"next",
"(",
"$",
"this",
"->",
"_bucketList",
")",
";",
"}",
"return",
"$",
"object",
";",
"}"
] |
Return the next filename in the directory.
@return string
|
[
"Return",
"the",
"next",
"filename",
"in",
"the",
"directory",
"."
] |
0630ed71351c6b804a815cff553fd0f57509ab54
|
https://github.com/medz/oss-stream-wrapper/blob/0630ed71351c6b804a815cff553fd0f57509ab54/src/AliyunOssStream.php#L417-L425
|
229,460
|
medz/oss-stream-wrapper
|
src/AliyunOssStream.php
|
AliyunOssStream.dir_opendir
|
public function dir_opendir($path, $options)
{
$dirName = $this->_getNamePart($path).'/';
if (preg_match('@^([a-z0-9+.]|-)+://$@', $path) || $dirName == '/') {
$list = $this->_getOssClient($path)->listObjects(AliyunOSS::getBucket());
} else {
$list = $this
->_getOssClient($path)
->listObjects(AliyunOSS::getBucket(), [
OssClient::OSS_PREFIX => $dirName,
]);
}
foreach ((array) $list->getPrefixList() as $l) {
array_push($this->_bucketList, basename($l->getPrefix()));
}
foreach ((array) $list->getObjectList() as $l) {
if ($l->getKey() == $dirName) {
continue;
}
array_push($this->_bucketList, basename($l->getKey()));
}
return $this->_bucketList !== false;
}
|
php
|
public function dir_opendir($path, $options)
{
$dirName = $this->_getNamePart($path).'/';
if (preg_match('@^([a-z0-9+.]|-)+://$@', $path) || $dirName == '/') {
$list = $this->_getOssClient($path)->listObjects(AliyunOSS::getBucket());
} else {
$list = $this
->_getOssClient($path)
->listObjects(AliyunOSS::getBucket(), [
OssClient::OSS_PREFIX => $dirName,
]);
}
foreach ((array) $list->getPrefixList() as $l) {
array_push($this->_bucketList, basename($l->getPrefix()));
}
foreach ((array) $list->getObjectList() as $l) {
if ($l->getKey() == $dirName) {
continue;
}
array_push($this->_bucketList, basename($l->getKey()));
}
return $this->_bucketList !== false;
}
|
[
"public",
"function",
"dir_opendir",
"(",
"$",
"path",
",",
"$",
"options",
")",
"{",
"$",
"dirName",
"=",
"$",
"this",
"->",
"_getNamePart",
"(",
"$",
"path",
")",
".",
"'/'",
";",
"if",
"(",
"preg_match",
"(",
"'@^([a-z0-9+.]|-)+://$@'",
",",
"$",
"path",
")",
"||",
"$",
"dirName",
"==",
"'/'",
")",
"{",
"$",
"list",
"=",
"$",
"this",
"->",
"_getOssClient",
"(",
"$",
"path",
")",
"->",
"listObjects",
"(",
"AliyunOSS",
"::",
"getBucket",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"list",
"=",
"$",
"this",
"->",
"_getOssClient",
"(",
"$",
"path",
")",
"->",
"listObjects",
"(",
"AliyunOSS",
"::",
"getBucket",
"(",
")",
",",
"[",
"OssClient",
"::",
"OSS_PREFIX",
"=>",
"$",
"dirName",
",",
"]",
")",
";",
"}",
"foreach",
"(",
"(",
"array",
")",
"$",
"list",
"->",
"getPrefixList",
"(",
")",
"as",
"$",
"l",
")",
"{",
"array_push",
"(",
"$",
"this",
"->",
"_bucketList",
",",
"basename",
"(",
"$",
"l",
"->",
"getPrefix",
"(",
")",
")",
")",
";",
"}",
"foreach",
"(",
"(",
"array",
")",
"$",
"list",
"->",
"getObjectList",
"(",
")",
"as",
"$",
"l",
")",
"{",
"if",
"(",
"$",
"l",
"->",
"getKey",
"(",
")",
"==",
"$",
"dirName",
")",
"{",
"continue",
";",
"}",
"array_push",
"(",
"$",
"this",
"->",
"_bucketList",
",",
"basename",
"(",
"$",
"l",
"->",
"getKey",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_bucketList",
"!==",
"false",
";",
"}"
] |
Attempt to open a directory.
@param string $path
@param int $options
@return bool
|
[
"Attempt",
"to",
"open",
"a",
"directory",
"."
] |
0630ed71351c6b804a815cff553fd0f57509ab54
|
https://github.com/medz/oss-stream-wrapper/blob/0630ed71351c6b804a815cff553fd0f57509ab54/src/AliyunOssStream.php#L435-L461
|
229,461
|
medz/oss-stream-wrapper
|
src/AliyunOssStream.php
|
AliyunOssStream.url_stat
|
public function url_stat($path, $flags)
{
$stat = [
'dev' => 0,
'ino' => 0,
'mode' => 0777,
'nlink' => 0,
'uid' => 0,
'gid' => 0,
'rdev' => 0,
'size' => 0,
'atime' => 0,
'mtime' => 0,
'ctime' => 0,
'blksize' => 0,
'blocks' => 0,
];
$name = $this->_getNamePart($path);
try {
$info = $this->_getOssClient($path)->getObjectMeta(AliyunOSS::getBucket(), $name);
if (isset($info['info']) && !empty($info['info'])) {
$info = $info['info'];
$stat['size'] = $info['download_content_length'];
$stat['atime'] = time();
$stat['mtime'] = $info['filetime'];
$stat['mode'] |= 0100000;
}
} catch (\OSS\Core\OssException $e) {
$stat['mode'] |= 040000;
}
return $stat;
}
|
php
|
public function url_stat($path, $flags)
{
$stat = [
'dev' => 0,
'ino' => 0,
'mode' => 0777,
'nlink' => 0,
'uid' => 0,
'gid' => 0,
'rdev' => 0,
'size' => 0,
'atime' => 0,
'mtime' => 0,
'ctime' => 0,
'blksize' => 0,
'blocks' => 0,
];
$name = $this->_getNamePart($path);
try {
$info = $this->_getOssClient($path)->getObjectMeta(AliyunOSS::getBucket(), $name);
if (isset($info['info']) && !empty($info['info'])) {
$info = $info['info'];
$stat['size'] = $info['download_content_length'];
$stat['atime'] = time();
$stat['mtime'] = $info['filetime'];
$stat['mode'] |= 0100000;
}
} catch (\OSS\Core\OssException $e) {
$stat['mode'] |= 040000;
}
return $stat;
}
|
[
"public",
"function",
"url_stat",
"(",
"$",
"path",
",",
"$",
"flags",
")",
"{",
"$",
"stat",
"=",
"[",
"'dev'",
"=>",
"0",
",",
"'ino'",
"=>",
"0",
",",
"'mode'",
"=>",
"0777",
",",
"'nlink'",
"=>",
"0",
",",
"'uid'",
"=>",
"0",
",",
"'gid'",
"=>",
"0",
",",
"'rdev'",
"=>",
"0",
",",
"'size'",
"=>",
"0",
",",
"'atime'",
"=>",
"0",
",",
"'mtime'",
"=>",
"0",
",",
"'ctime'",
"=>",
"0",
",",
"'blksize'",
"=>",
"0",
",",
"'blocks'",
"=>",
"0",
",",
"]",
";",
"$",
"name",
"=",
"$",
"this",
"->",
"_getNamePart",
"(",
"$",
"path",
")",
";",
"try",
"{",
"$",
"info",
"=",
"$",
"this",
"->",
"_getOssClient",
"(",
"$",
"path",
")",
"->",
"getObjectMeta",
"(",
"AliyunOSS",
"::",
"getBucket",
"(",
")",
",",
"$",
"name",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"info",
"[",
"'info'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"info",
"[",
"'info'",
"]",
")",
")",
"{",
"$",
"info",
"=",
"$",
"info",
"[",
"'info'",
"]",
";",
"$",
"stat",
"[",
"'size'",
"]",
"=",
"$",
"info",
"[",
"'download_content_length'",
"]",
";",
"$",
"stat",
"[",
"'atime'",
"]",
"=",
"time",
"(",
")",
";",
"$",
"stat",
"[",
"'mtime'",
"]",
"=",
"$",
"info",
"[",
"'filetime'",
"]",
";",
"$",
"stat",
"[",
"'mode'",
"]",
"|=",
"0100000",
";",
"}",
"}",
"catch",
"(",
"\\",
"OSS",
"\\",
"Core",
"\\",
"OssException",
"$",
"e",
")",
"{",
"$",
"stat",
"[",
"'mode'",
"]",
"|=",
"040000",
";",
"}",
"return",
"$",
"stat",
";",
"}"
] |
Return array of URL variables.
@param string $path
@param int $flags
@return array
|
[
"Return",
"array",
"of",
"URL",
"variables",
"."
] |
0630ed71351c6b804a815cff553fd0f57509ab54
|
https://github.com/medz/oss-stream-wrapper/blob/0630ed71351c6b804a815cff553fd0f57509ab54/src/AliyunOssStream.php#L471-L504
|
229,462
|
milesj/utility
|
Model/Behavior/ValidateableBehavior.php
|
ValidateableBehavior.validate
|
public function validate(Model $model, $set) {
if (!isset($model->validations[$set])) {
throw new OutOfBoundsException(sprintf('Validation set %s does not exist', $set));
}
$rules = $model->validations[$set];
$settings = $this->settings[$model->alias];
// Add default messages second
if ($settings['useDefaults']) {
$rules = $this->_applyMessages($model, $rules);
}
// Merge in case there are other behaviors modifying the rules
$model->validate = Hash::merge($model->validate, $rules);
return $model;
}
|
php
|
public function validate(Model $model, $set) {
if (!isset($model->validations[$set])) {
throw new OutOfBoundsException(sprintf('Validation set %s does not exist', $set));
}
$rules = $model->validations[$set];
$settings = $this->settings[$model->alias];
// Add default messages second
if ($settings['useDefaults']) {
$rules = $this->_applyMessages($model, $rules);
}
// Merge in case there are other behaviors modifying the rules
$model->validate = Hash::merge($model->validate, $rules);
return $model;
}
|
[
"public",
"function",
"validate",
"(",
"Model",
"$",
"model",
",",
"$",
"set",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"model",
"->",
"validations",
"[",
"$",
"set",
"]",
")",
")",
"{",
"throw",
"new",
"OutOfBoundsException",
"(",
"sprintf",
"(",
"'Validation set %s does not exist'",
",",
"$",
"set",
")",
")",
";",
"}",
"$",
"rules",
"=",
"$",
"model",
"->",
"validations",
"[",
"$",
"set",
"]",
";",
"$",
"settings",
"=",
"$",
"this",
"->",
"settings",
"[",
"$",
"model",
"->",
"alias",
"]",
";",
"// Add default messages second\r",
"if",
"(",
"$",
"settings",
"[",
"'useDefaults'",
"]",
")",
"{",
"$",
"rules",
"=",
"$",
"this",
"->",
"_applyMessages",
"(",
"$",
"model",
",",
"$",
"rules",
")",
";",
"}",
"// Merge in case there are other behaviors modifying the rules\r",
"$",
"model",
"->",
"validate",
"=",
"Hash",
"::",
"merge",
"(",
"$",
"model",
"->",
"validate",
",",
"$",
"rules",
")",
";",
"return",
"$",
"model",
";",
"}"
] |
Set the validation set to use.
@param Model $model
@param string $set
@return Model
@throws OutOfBoundsException
|
[
"Set",
"the",
"validation",
"set",
"to",
"use",
"."
] |
146318ff0a882917defab7f4918b0d198eb5a3c0
|
https://github.com/milesj/utility/blob/146318ff0a882917defab7f4918b0d198eb5a3c0/Model/Behavior/ValidateableBehavior.php#L121-L138
|
229,463
|
milesj/utility
|
Model/Behavior/ValidateableBehavior.php
|
ValidateableBehavior.invalid
|
public function invalid(Model $model, $field, $message, $params = array()) {
$model->invalidate($field, __d($model->validationDomain ?: 'default', $message, $params));
return false;
}
|
php
|
public function invalid(Model $model, $field, $message, $params = array()) {
$model->invalidate($field, __d($model->validationDomain ?: 'default', $message, $params));
return false;
}
|
[
"public",
"function",
"invalid",
"(",
"Model",
"$",
"model",
",",
"$",
"field",
",",
"$",
"message",
",",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"model",
"->",
"invalidate",
"(",
"$",
"field",
",",
"__d",
"(",
"$",
"model",
"->",
"validationDomain",
"?",
":",
"'default'",
",",
"$",
"message",
",",
"$",
"params",
")",
")",
";",
"return",
"false",
";",
"}"
] |
Convenience method to invalidate a field and translate the custom message.
@param Model $model
@param string $field
@param string $message
@param array $params
@return bool
|
[
"Convenience",
"method",
"to",
"invalidate",
"a",
"field",
"and",
"translate",
"the",
"custom",
"message",
"."
] |
146318ff0a882917defab7f4918b0d198eb5a3c0
|
https://github.com/milesj/utility/blob/146318ff0a882917defab7f4918b0d198eb5a3c0/Model/Behavior/ValidateableBehavior.php#L149-L153
|
229,464
|
milesj/utility
|
Model/Behavior/ValidateableBehavior.php
|
ValidateableBehavior.beforeValidate
|
public function beforeValidate(Model $model, $options = array()) {
$default = $this->settings[$model->alias]['defaultSet'];
if (empty($model->validate) && isset($model->validations[$default])) {
$this->validate($model, $default);
}
return true;
}
|
php
|
public function beforeValidate(Model $model, $options = array()) {
$default = $this->settings[$model->alias]['defaultSet'];
if (empty($model->validate) && isset($model->validations[$default])) {
$this->validate($model, $default);
}
return true;
}
|
[
"public",
"function",
"beforeValidate",
"(",
"Model",
"$",
"model",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"default",
"=",
"$",
"this",
"->",
"settings",
"[",
"$",
"model",
"->",
"alias",
"]",
"[",
"'defaultSet'",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"model",
"->",
"validate",
")",
"&&",
"isset",
"(",
"$",
"model",
"->",
"validations",
"[",
"$",
"default",
"]",
")",
")",
"{",
"$",
"this",
"->",
"validate",
"(",
"$",
"model",
",",
"$",
"default",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
If validate is empty and a default set exists, apply the rules.
@param Model $model
@param array $options
@return bool
|
[
"If",
"validate",
"is",
"empty",
"and",
"a",
"default",
"set",
"exists",
"apply",
"the",
"rules",
"."
] |
146318ff0a882917defab7f4918b0d198eb5a3c0
|
https://github.com/milesj/utility/blob/146318ff0a882917defab7f4918b0d198eb5a3c0/Model/Behavior/ValidateableBehavior.php#L162-L170
|
229,465
|
milesj/utility
|
Model/Behavior/ValidateableBehavior.php
|
ValidateableBehavior._applyMessages
|
protected function _applyMessages(Model $model, array $rules) {
foreach ($rules as $key => $value) {
if (is_array($value)) {
if ($key !== 'rule') {
$rules[$key] = $this->_applyMessages($model, $value);
}
// Collapsed rules
} else if (isset($this->_messages[$value]) && $key !== 'rule') {
$rules[$key] = array(
$value => array(
'rule' => $value,
'message' => $this->_messages[$value]
)
);
// Missing message
} else if ($key === 'rule') {
$rule = $value;
if (is_array($rule)) {
$rule = array_shift($params);
}
if (isset($this->_messages[$rule]) && empty($rules['message'])) {
$rules['message'] = $this->_messages[$rule];
}
}
}
return $rules;
}
|
php
|
protected function _applyMessages(Model $model, array $rules) {
foreach ($rules as $key => $value) {
if (is_array($value)) {
if ($key !== 'rule') {
$rules[$key] = $this->_applyMessages($model, $value);
}
// Collapsed rules
} else if (isset($this->_messages[$value]) && $key !== 'rule') {
$rules[$key] = array(
$value => array(
'rule' => $value,
'message' => $this->_messages[$value]
)
);
// Missing message
} else if ($key === 'rule') {
$rule = $value;
if (is_array($rule)) {
$rule = array_shift($params);
}
if (isset($this->_messages[$rule]) && empty($rules['message'])) {
$rules['message'] = $this->_messages[$rule];
}
}
}
return $rules;
}
|
[
"protected",
"function",
"_applyMessages",
"(",
"Model",
"$",
"model",
",",
"array",
"$",
"rules",
")",
"{",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"$",
"key",
"!==",
"'rule'",
")",
"{",
"$",
"rules",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"_applyMessages",
"(",
"$",
"model",
",",
"$",
"value",
")",
";",
"}",
"// Collapsed rules\r",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_messages",
"[",
"$",
"value",
"]",
")",
"&&",
"$",
"key",
"!==",
"'rule'",
")",
"{",
"$",
"rules",
"[",
"$",
"key",
"]",
"=",
"array",
"(",
"$",
"value",
"=>",
"array",
"(",
"'rule'",
"=>",
"$",
"value",
",",
"'message'",
"=>",
"$",
"this",
"->",
"_messages",
"[",
"$",
"value",
"]",
")",
")",
";",
"// Missing message\r",
"}",
"else",
"if",
"(",
"$",
"key",
"===",
"'rule'",
")",
"{",
"$",
"rule",
"=",
"$",
"value",
";",
"if",
"(",
"is_array",
"(",
"$",
"rule",
")",
")",
"{",
"$",
"rule",
"=",
"array_shift",
"(",
"$",
"params",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_messages",
"[",
"$",
"rule",
"]",
")",
"&&",
"empty",
"(",
"$",
"rules",
"[",
"'message'",
"]",
")",
")",
"{",
"$",
"rules",
"[",
"'message'",
"]",
"=",
"$",
"this",
"->",
"_messages",
"[",
"$",
"rule",
"]",
";",
"}",
"}",
"}",
"return",
"$",
"rules",
";",
"}"
] |
Apply and set default messages if they are missing.
@param Model $model
@param array $rules
@return array
|
[
"Apply",
"and",
"set",
"default",
"messages",
"if",
"they",
"are",
"missing",
"."
] |
146318ff0a882917defab7f4918b0d198eb5a3c0
|
https://github.com/milesj/utility/blob/146318ff0a882917defab7f4918b0d198eb5a3c0/Model/Behavior/ValidateableBehavior.php#L193-L224
|
229,466
|
softark/creole
|
block/ListTrait.php
|
ListTrait.isParentItem
|
protected function isParentItem($line)
{
if ($this->_listDepth === 1 || ($marker = $line[0]) !== '*' && $marker !== '#') {
return false;
}
$depthMax = $this->_listDepth - 1;
if (preg_match('/^(#{1,' . $depthMax . '})[^#]+/', $line, $matches)) {
return $this->_nestedListTypes[strlen($matches[1])] === 'ol';
}
if (preg_match('/^(\*{1,' . $depthMax . '})[^\*]+/', $line, $matches)) {
return $this->_nestedListTypes[strlen($matches[1])] === 'ul';
}
return false;
}
|
php
|
protected function isParentItem($line)
{
if ($this->_listDepth === 1 || ($marker = $line[0]) !== '*' && $marker !== '#') {
return false;
}
$depthMax = $this->_listDepth - 1;
if (preg_match('/^(#{1,' . $depthMax . '})[^#]+/', $line, $matches)) {
return $this->_nestedListTypes[strlen($matches[1])] === 'ol';
}
if (preg_match('/^(\*{1,' . $depthMax . '})[^\*]+/', $line, $matches)) {
return $this->_nestedListTypes[strlen($matches[1])] === 'ul';
}
return false;
}
|
[
"protected",
"function",
"isParentItem",
"(",
"$",
"line",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_listDepth",
"===",
"1",
"||",
"(",
"$",
"marker",
"=",
"$",
"line",
"[",
"0",
"]",
")",
"!==",
"'*'",
"&&",
"$",
"marker",
"!==",
"'#'",
")",
"{",
"return",
"false",
";",
"}",
"$",
"depthMax",
"=",
"$",
"this",
"->",
"_listDepth",
"-",
"1",
";",
"if",
"(",
"preg_match",
"(",
"'/^(#{1,'",
".",
"$",
"depthMax",
".",
"'})[^#]+/'",
",",
"$",
"line",
",",
"$",
"matches",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_nestedListTypes",
"[",
"strlen",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
"]",
"===",
"'ol'",
";",
"}",
"if",
"(",
"preg_match",
"(",
"'/^(\\*{1,'",
".",
"$",
"depthMax",
".",
"'})[^\\*]+/'",
",",
"$",
"line",
",",
"$",
"matches",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_nestedListTypes",
"[",
"strlen",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
"]",
"===",
"'ul'",
";",
"}",
"return",
"false",
";",
"}"
] |
check if a line is an item that belongs to a parent list
@param $line
@return bool true if the line is an item of a parent list
|
[
"check",
"if",
"a",
"line",
"is",
"an",
"item",
"that",
"belongs",
"to",
"a",
"parent",
"list"
] |
f56f267e46fa45df1fab01f5d9f1c2bfb0394a9b
|
https://github.com/softark/creole/blob/f56f267e46fa45df1fab01f5d9f1c2bfb0394a9b/block/ListTrait.php#L48-L61
|
229,467
|
softark/creole
|
block/ListTrait.php
|
ListTrait.isSiblingItem
|
protected function isSiblingItem($line)
{
$siblingMarker = $this->_nestedListTypes[$this->_listDepth] == 'ol' ? '*' : '#';
if ($line[0] !== $siblingMarker) {
return false;
}
return
($siblingMarker === '#' && preg_match('/^#{' . $this->_listDepth . '}[^#]+/', $line)) ||
($siblingMarker === '*' && preg_match('/^\*{' . $this->_listDepth . '}[^\*]+/', $line));
}
|
php
|
protected function isSiblingItem($line)
{
$siblingMarker = $this->_nestedListTypes[$this->_listDepth] == 'ol' ? '*' : '#';
if ($line[0] !== $siblingMarker) {
return false;
}
return
($siblingMarker === '#' && preg_match('/^#{' . $this->_listDepth . '}[^#]+/', $line)) ||
($siblingMarker === '*' && preg_match('/^\*{' . $this->_listDepth . '}[^\*]+/', $line));
}
|
[
"protected",
"function",
"isSiblingItem",
"(",
"$",
"line",
")",
"{",
"$",
"siblingMarker",
"=",
"$",
"this",
"->",
"_nestedListTypes",
"[",
"$",
"this",
"->",
"_listDepth",
"]",
"==",
"'ol'",
"?",
"'*'",
":",
"'#'",
";",
"if",
"(",
"$",
"line",
"[",
"0",
"]",
"!==",
"$",
"siblingMarker",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
"$",
"siblingMarker",
"===",
"'#'",
"&&",
"preg_match",
"(",
"'/^#{'",
".",
"$",
"this",
"->",
"_listDepth",
".",
"'}[^#]+/'",
",",
"$",
"line",
")",
")",
"||",
"(",
"$",
"siblingMarker",
"===",
"'*'",
"&&",
"preg_match",
"(",
"'/^\\*{'",
".",
"$",
"this",
"->",
"_listDepth",
".",
"'}[^\\*]+/'",
",",
"$",
"line",
")",
")",
";",
"}"
] |
check if a line is an item that belongs to a sibling list
@param $line
@return bool true if the line is an item of a sibling list
|
[
"check",
"if",
"a",
"line",
"is",
"an",
"item",
"that",
"belongs",
"to",
"a",
"sibling",
"list"
] |
f56f267e46fa45df1fab01f5d9f1c2bfb0394a9b
|
https://github.com/softark/creole/blob/f56f267e46fa45df1fab01f5d9f1c2bfb0394a9b/block/ListTrait.php#L68-L77
|
229,468
|
milesj/utility
|
Model/Behavior/SpamBlockerBehavior.php
|
SpamBlockerBehavior.notify
|
public function notify(Model $model, $data, $status, $points = 0) {
$settings = $this->settings[$model->alias];
$columnMap = $settings['columnMap'];
if ($settings['model'] && $settings['link'] && $settings['email']) {
$Article = ClassRegistry::init(Inflector::classify($settings['model']));
$result = $Article->find('first', array(
'conditions' => array($columnMap['id'] => $data[$columnMap['foreignKey']]),
'recursive' => -1,
'contain' => false
));
// Build variables
$link = str_replace('{id}', $result[$Article->alias][$columnMap['id']], $settings['link']);
if ($settings['useSlug']) {
$link = str_replace('{slug}', $result[$Article->alias][$columnMap['slug']], $settings['link']);
}
$title = $result[$Article->alias][$columnMap['title']];
$email = $data[$columnMap['email']];
$author = $data[$columnMap['author']];
// Send email
$Email = new CakeEmail();
$Email
->to($settings['email'])
->from(array($email => $author))
->subject('Comment Approval: ' . $title)
->helpers(array('Html', 'Time'))
->viewVars(array(
'settings' => $settings,
'article' => $result,
'comment' => $data,
'link' => $link,
'status' => $status,
'points' => $points
));
if (Configure::read('debug')) {
$Email->transport('Debug')->config(array('log' => true));
}
// Use a custom template
if (is_string($settings['sendEmail'])) {
$Email
->template($settings['sendEmail'])
->emailFormat('both')
->send();
// Send a simple message
} else {
$statuses = array_flip($settings['statusMap']);
$message = sprintf("A new comment has been posted for: %s\n\n", $link);
$message .= sprintf("Name: %s <%s>\n", $author, $email);
$message .= sprintf("Status: %s (%s points)\n", $statuses[$status], $points);
$message .= sprintf("Message:\n\n%s", $data[$columnMap['content']]);
$Email->send($message);
}
}
}
|
php
|
public function notify(Model $model, $data, $status, $points = 0) {
$settings = $this->settings[$model->alias];
$columnMap = $settings['columnMap'];
if ($settings['model'] && $settings['link'] && $settings['email']) {
$Article = ClassRegistry::init(Inflector::classify($settings['model']));
$result = $Article->find('first', array(
'conditions' => array($columnMap['id'] => $data[$columnMap['foreignKey']]),
'recursive' => -1,
'contain' => false
));
// Build variables
$link = str_replace('{id}', $result[$Article->alias][$columnMap['id']], $settings['link']);
if ($settings['useSlug']) {
$link = str_replace('{slug}', $result[$Article->alias][$columnMap['slug']], $settings['link']);
}
$title = $result[$Article->alias][$columnMap['title']];
$email = $data[$columnMap['email']];
$author = $data[$columnMap['author']];
// Send email
$Email = new CakeEmail();
$Email
->to($settings['email'])
->from(array($email => $author))
->subject('Comment Approval: ' . $title)
->helpers(array('Html', 'Time'))
->viewVars(array(
'settings' => $settings,
'article' => $result,
'comment' => $data,
'link' => $link,
'status' => $status,
'points' => $points
));
if (Configure::read('debug')) {
$Email->transport('Debug')->config(array('log' => true));
}
// Use a custom template
if (is_string($settings['sendEmail'])) {
$Email
->template($settings['sendEmail'])
->emailFormat('both')
->send();
// Send a simple message
} else {
$statuses = array_flip($settings['statusMap']);
$message = sprintf("A new comment has been posted for: %s\n\n", $link);
$message .= sprintf("Name: %s <%s>\n", $author, $email);
$message .= sprintf("Status: %s (%s points)\n", $statuses[$status], $points);
$message .= sprintf("Message:\n\n%s", $data[$columnMap['content']]);
$Email->send($message);
}
}
}
|
[
"public",
"function",
"notify",
"(",
"Model",
"$",
"model",
",",
"$",
"data",
",",
"$",
"status",
",",
"$",
"points",
"=",
"0",
")",
"{",
"$",
"settings",
"=",
"$",
"this",
"->",
"settings",
"[",
"$",
"model",
"->",
"alias",
"]",
";",
"$",
"columnMap",
"=",
"$",
"settings",
"[",
"'columnMap'",
"]",
";",
"if",
"(",
"$",
"settings",
"[",
"'model'",
"]",
"&&",
"$",
"settings",
"[",
"'link'",
"]",
"&&",
"$",
"settings",
"[",
"'email'",
"]",
")",
"{",
"$",
"Article",
"=",
"ClassRegistry",
"::",
"init",
"(",
"Inflector",
"::",
"classify",
"(",
"$",
"settings",
"[",
"'model'",
"]",
")",
")",
";",
"$",
"result",
"=",
"$",
"Article",
"->",
"find",
"(",
"'first'",
",",
"array",
"(",
"'conditions'",
"=>",
"array",
"(",
"$",
"columnMap",
"[",
"'id'",
"]",
"=>",
"$",
"data",
"[",
"$",
"columnMap",
"[",
"'foreignKey'",
"]",
"]",
")",
",",
"'recursive'",
"=>",
"-",
"1",
",",
"'contain'",
"=>",
"false",
")",
")",
";",
"// Build variables",
"$",
"link",
"=",
"str_replace",
"(",
"'{id}'",
",",
"$",
"result",
"[",
"$",
"Article",
"->",
"alias",
"]",
"[",
"$",
"columnMap",
"[",
"'id'",
"]",
"]",
",",
"$",
"settings",
"[",
"'link'",
"]",
")",
";",
"if",
"(",
"$",
"settings",
"[",
"'useSlug'",
"]",
")",
"{",
"$",
"link",
"=",
"str_replace",
"(",
"'{slug}'",
",",
"$",
"result",
"[",
"$",
"Article",
"->",
"alias",
"]",
"[",
"$",
"columnMap",
"[",
"'slug'",
"]",
"]",
",",
"$",
"settings",
"[",
"'link'",
"]",
")",
";",
"}",
"$",
"title",
"=",
"$",
"result",
"[",
"$",
"Article",
"->",
"alias",
"]",
"[",
"$",
"columnMap",
"[",
"'title'",
"]",
"]",
";",
"$",
"email",
"=",
"$",
"data",
"[",
"$",
"columnMap",
"[",
"'email'",
"]",
"]",
";",
"$",
"author",
"=",
"$",
"data",
"[",
"$",
"columnMap",
"[",
"'author'",
"]",
"]",
";",
"// Send email",
"$",
"Email",
"=",
"new",
"CakeEmail",
"(",
")",
";",
"$",
"Email",
"->",
"to",
"(",
"$",
"settings",
"[",
"'email'",
"]",
")",
"->",
"from",
"(",
"array",
"(",
"$",
"email",
"=>",
"$",
"author",
")",
")",
"->",
"subject",
"(",
"'Comment Approval: '",
".",
"$",
"title",
")",
"->",
"helpers",
"(",
"array",
"(",
"'Html'",
",",
"'Time'",
")",
")",
"->",
"viewVars",
"(",
"array",
"(",
"'settings'",
"=>",
"$",
"settings",
",",
"'article'",
"=>",
"$",
"result",
",",
"'comment'",
"=>",
"$",
"data",
",",
"'link'",
"=>",
"$",
"link",
",",
"'status'",
"=>",
"$",
"status",
",",
"'points'",
"=>",
"$",
"points",
")",
")",
";",
"if",
"(",
"Configure",
"::",
"read",
"(",
"'debug'",
")",
")",
"{",
"$",
"Email",
"->",
"transport",
"(",
"'Debug'",
")",
"->",
"config",
"(",
"array",
"(",
"'log'",
"=>",
"true",
")",
")",
";",
"}",
"// Use a custom template",
"if",
"(",
"is_string",
"(",
"$",
"settings",
"[",
"'sendEmail'",
"]",
")",
")",
"{",
"$",
"Email",
"->",
"template",
"(",
"$",
"settings",
"[",
"'sendEmail'",
"]",
")",
"->",
"emailFormat",
"(",
"'both'",
")",
"->",
"send",
"(",
")",
";",
"// Send a simple message",
"}",
"else",
"{",
"$",
"statuses",
"=",
"array_flip",
"(",
"$",
"settings",
"[",
"'statusMap'",
"]",
")",
";",
"$",
"message",
"=",
"sprintf",
"(",
"\"A new comment has been posted for: %s\\n\\n\"",
",",
"$",
"link",
")",
";",
"$",
"message",
".=",
"sprintf",
"(",
"\"Name: %s <%s>\\n\"",
",",
"$",
"author",
",",
"$",
"email",
")",
";",
"$",
"message",
".=",
"sprintf",
"(",
"\"Status: %s (%s points)\\n\"",
",",
"$",
"statuses",
"[",
"$",
"status",
"]",
",",
"$",
"points",
")",
";",
"$",
"message",
".=",
"sprintf",
"(",
"\"Message:\\n\\n%s\"",
",",
"$",
"data",
"[",
"$",
"columnMap",
"[",
"'content'",
"]",
"]",
")",
";",
"$",
"Email",
"->",
"send",
"(",
"$",
"message",
")",
";",
"}",
"}",
"}"
] |
Sends out an email notifying you of a new comment.
@param Model $model
@param array $data
@param int $status
@param int $points
|
[
"Sends",
"out",
"an",
"email",
"notifying",
"you",
"of",
"a",
"new",
"comment",
"."
] |
146318ff0a882917defab7f4918b0d198eb5a3c0
|
https://github.com/milesj/utility/blob/146318ff0a882917defab7f4918b0d198eb5a3c0/Model/Behavior/SpamBlockerBehavior.php#L330-L393
|
229,469
|
milesj/utility
|
Console/Command/BaseInstallShell.php
|
BaseInstallShell.main
|
public function main() {
$this->stdout->styles('success', array('text' => 'green'));
$this->hr(1);
$this->out(sprintf('%s Steps:', $this->name));
$counter = 1;
foreach ($this->steps as $method) {
$this->steps($counter);
try {
if (!call_user_func(array($this, $method))) {
$this->err('<error>Process aborted!</error>');
break;
}
} catch (Exception $e) {
$this->err(sprintf('<error>Unexpected error has occurred; %s</error>', $e->getMessage()));
break;
}
$counter++;
}
}
|
php
|
public function main() {
$this->stdout->styles('success', array('text' => 'green'));
$this->hr(1);
$this->out(sprintf('%s Steps:', $this->name));
$counter = 1;
foreach ($this->steps as $method) {
$this->steps($counter);
try {
if (!call_user_func(array($this, $method))) {
$this->err('<error>Process aborted!</error>');
break;
}
} catch (Exception $e) {
$this->err(sprintf('<error>Unexpected error has occurred; %s</error>', $e->getMessage()));
break;
}
$counter++;
}
}
|
[
"public",
"function",
"main",
"(",
")",
"{",
"$",
"this",
"->",
"stdout",
"->",
"styles",
"(",
"'success'",
",",
"array",
"(",
"'text'",
"=>",
"'green'",
")",
")",
";",
"$",
"this",
"->",
"hr",
"(",
"1",
")",
";",
"$",
"this",
"->",
"out",
"(",
"sprintf",
"(",
"'%s Steps:'",
",",
"$",
"this",
"->",
"name",
")",
")",
";",
"$",
"counter",
"=",
"1",
";",
"foreach",
"(",
"$",
"this",
"->",
"steps",
"as",
"$",
"method",
")",
"{",
"$",
"this",
"->",
"steps",
"(",
"$",
"counter",
")",
";",
"try",
"{",
"if",
"(",
"!",
"call_user_func",
"(",
"array",
"(",
"$",
"this",
",",
"$",
"method",
")",
")",
")",
"{",
"$",
"this",
"->",
"err",
"(",
"'<error>Process aborted!</error>'",
")",
";",
"break",
";",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"err",
"(",
"sprintf",
"(",
"'<error>Unexpected error has occurred; %s</error>'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
")",
";",
"break",
";",
"}",
"$",
"counter",
"++",
";",
"}",
"}"
] |
Execute installer and cycle through all steps.
|
[
"Execute",
"installer",
"and",
"cycle",
"through",
"all",
"steps",
"."
] |
146318ff0a882917defab7f4918b0d198eb5a3c0
|
https://github.com/milesj/utility/blob/146318ff0a882917defab7f4918b0d198eb5a3c0/Console/Command/BaseInstallShell.php#L95-L118
|
229,470
|
milesj/utility
|
Console/Command/BaseInstallShell.php
|
BaseInstallShell.checkDbConfig
|
public function checkDbConfig() {
if (!$this->dbConfig || !$this->db) {
$dbConfigs = array_keys(get_class_vars('DATABASE_CONFIG'));
$this->out('Available database configurations:');
foreach ($dbConfigs as $i => $db) {
$this->out(sprintf('[%s] <info>%s</info>', $i, $db));
}
$this->out();
$answer = $this->in('Which database should the queries be executed in?', array_keys($dbConfigs));
if (isset($dbConfigs[$answer])) {
$this->setDbConfig($dbConfigs[$answer]);
} else {
$this->checkDbConfig();
}
}
$this->out(sprintf('Database Config: <info>%s</info>', $this->dbConfig));
$answer = strtoupper($this->in('Is this correct?', array('Y', 'N')));
if ($answer === 'N') {
$this->dbConfig = null;
$this->checkDbConfig();
}
// Check that database is connected
if (!$this->db->isConnected()) {
$this->err(sprintf('<error>Database connection for %s failed</error>', $this->dbConfig));
return false;
}
$this->out('<success>Database check successful, proceeding...</success>');
return true;
}
|
php
|
public function checkDbConfig() {
if (!$this->dbConfig || !$this->db) {
$dbConfigs = array_keys(get_class_vars('DATABASE_CONFIG'));
$this->out('Available database configurations:');
foreach ($dbConfigs as $i => $db) {
$this->out(sprintf('[%s] <info>%s</info>', $i, $db));
}
$this->out();
$answer = $this->in('Which database should the queries be executed in?', array_keys($dbConfigs));
if (isset($dbConfigs[$answer])) {
$this->setDbConfig($dbConfigs[$answer]);
} else {
$this->checkDbConfig();
}
}
$this->out(sprintf('Database Config: <info>%s</info>', $this->dbConfig));
$answer = strtoupper($this->in('Is this correct?', array('Y', 'N')));
if ($answer === 'N') {
$this->dbConfig = null;
$this->checkDbConfig();
}
// Check that database is connected
if (!$this->db->isConnected()) {
$this->err(sprintf('<error>Database connection for %s failed</error>', $this->dbConfig));
return false;
}
$this->out('<success>Database check successful, proceeding...</success>');
return true;
}
|
[
"public",
"function",
"checkDbConfig",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"dbConfig",
"||",
"!",
"$",
"this",
"->",
"db",
")",
"{",
"$",
"dbConfigs",
"=",
"array_keys",
"(",
"get_class_vars",
"(",
"'DATABASE_CONFIG'",
")",
")",
";",
"$",
"this",
"->",
"out",
"(",
"'Available database configurations:'",
")",
";",
"foreach",
"(",
"$",
"dbConfigs",
"as",
"$",
"i",
"=>",
"$",
"db",
")",
"{",
"$",
"this",
"->",
"out",
"(",
"sprintf",
"(",
"'[%s] <info>%s</info>'",
",",
"$",
"i",
",",
"$",
"db",
")",
")",
";",
"}",
"$",
"this",
"->",
"out",
"(",
")",
";",
"$",
"answer",
"=",
"$",
"this",
"->",
"in",
"(",
"'Which database should the queries be executed in?'",
",",
"array_keys",
"(",
"$",
"dbConfigs",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"dbConfigs",
"[",
"$",
"answer",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setDbConfig",
"(",
"$",
"dbConfigs",
"[",
"$",
"answer",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"checkDbConfig",
"(",
")",
";",
"}",
"}",
"$",
"this",
"->",
"out",
"(",
"sprintf",
"(",
"'Database Config: <info>%s</info>'",
",",
"$",
"this",
"->",
"dbConfig",
")",
")",
";",
"$",
"answer",
"=",
"strtoupper",
"(",
"$",
"this",
"->",
"in",
"(",
"'Is this correct?'",
",",
"array",
"(",
"'Y'",
",",
"'N'",
")",
")",
")",
";",
"if",
"(",
"$",
"answer",
"===",
"'N'",
")",
"{",
"$",
"this",
"->",
"dbConfig",
"=",
"null",
";",
"$",
"this",
"->",
"checkDbConfig",
"(",
")",
";",
"}",
"// Check that database is connected",
"if",
"(",
"!",
"$",
"this",
"->",
"db",
"->",
"isConnected",
"(",
")",
")",
"{",
"$",
"this",
"->",
"err",
"(",
"sprintf",
"(",
"'<error>Database connection for %s failed</error>'",
",",
"$",
"this",
"->",
"dbConfig",
")",
")",
";",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"out",
"(",
"'<success>Database check successful, proceeding...</success>'",
")",
";",
"return",
"true",
";",
"}"
] |
Check the database status before installation.
@return bool
|
[
"Check",
"the",
"database",
"status",
"before",
"installation",
"."
] |
146318ff0a882917defab7f4918b0d198eb5a3c0
|
https://github.com/milesj/utility/blob/146318ff0a882917defab7f4918b0d198eb5a3c0/Console/Command/BaseInstallShell.php#L125-L163
|
229,471
|
milesj/utility
|
Console/Command/BaseInstallShell.php
|
BaseInstallShell.checkRequiredTables
|
public function checkRequiredTables() {
if ($this->requiredTables) {
$this->out(sprintf('The following tables are required: <info>%s</info>', implode(', ', $this->requiredTables)));
$this->out('<success>Checking tables...</success>');
$tables = $this->db->listSources();
$missing = array();
foreach ($this->requiredTables as $table) {
if (!in_array($this->db->config['prefix'] . $table, $tables)) {
$missing[] = $table;
}
}
if ($missing) {
$this->err(sprintf('<error>Missing tables %s; can not proceed</error>', implode(', ', $missing)));
return false;
}
}
$this->out('<success>Table status good, proceeding...</success>');
return true;
}
|
php
|
public function checkRequiredTables() {
if ($this->requiredTables) {
$this->out(sprintf('The following tables are required: <info>%s</info>', implode(', ', $this->requiredTables)));
$this->out('<success>Checking tables...</success>');
$tables = $this->db->listSources();
$missing = array();
foreach ($this->requiredTables as $table) {
if (!in_array($this->db->config['prefix'] . $table, $tables)) {
$missing[] = $table;
}
}
if ($missing) {
$this->err(sprintf('<error>Missing tables %s; can not proceed</error>', implode(', ', $missing)));
return false;
}
}
$this->out('<success>Table status good, proceeding...</success>');
return true;
}
|
[
"public",
"function",
"checkRequiredTables",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"requiredTables",
")",
"{",
"$",
"this",
"->",
"out",
"(",
"sprintf",
"(",
"'The following tables are required: <info>%s</info>'",
",",
"implode",
"(",
"', '",
",",
"$",
"this",
"->",
"requiredTables",
")",
")",
")",
";",
"$",
"this",
"->",
"out",
"(",
"'<success>Checking tables...</success>'",
")",
";",
"$",
"tables",
"=",
"$",
"this",
"->",
"db",
"->",
"listSources",
"(",
")",
";",
"$",
"missing",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"requiredTables",
"as",
"$",
"table",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"this",
"->",
"db",
"->",
"config",
"[",
"'prefix'",
"]",
".",
"$",
"table",
",",
"$",
"tables",
")",
")",
"{",
"$",
"missing",
"[",
"]",
"=",
"$",
"table",
";",
"}",
"}",
"if",
"(",
"$",
"missing",
")",
"{",
"$",
"this",
"->",
"err",
"(",
"sprintf",
"(",
"'<error>Missing tables %s; can not proceed</error>'",
",",
"implode",
"(",
"', '",
",",
"$",
"missing",
")",
")",
")",
";",
"return",
"false",
";",
"}",
"}",
"$",
"this",
"->",
"out",
"(",
"'<success>Table status good, proceeding...</success>'",
")",
";",
"return",
"true",
";",
"}"
] |
Check that all the required tables exist in the database.
@return bool
|
[
"Check",
"that",
"all",
"the",
"required",
"tables",
"exist",
"in",
"the",
"database",
"."
] |
146318ff0a882917defab7f4918b0d198eb5a3c0
|
https://github.com/milesj/utility/blob/146318ff0a882917defab7f4918b0d198eb5a3c0/Console/Command/BaseInstallShell.php#L170-L192
|
229,472
|
milesj/utility
|
Console/Command/BaseInstallShell.php
|
BaseInstallShell.checkUsersModel
|
public function checkUsersModel() {
if (!$this->usersModel) {
$this->setUsersModel($this->in('What is the name of your users model?'));
}
$this->out(sprintf('Users Model: <info>%s</info>', $this->usersModel));
$answer = strtoupper($this->in('Is this correct?', array('Y', 'N')));
if ($answer === 'N') {
$this->usersModel = null;
$this->checkUsersModel();
}
}
|
php
|
public function checkUsersModel() {
if (!$this->usersModel) {
$this->setUsersModel($this->in('What is the name of your users model?'));
}
$this->out(sprintf('Users Model: <info>%s</info>', $this->usersModel));
$answer = strtoupper($this->in('Is this correct?', array('Y', 'N')));
if ($answer === 'N') {
$this->usersModel = null;
$this->checkUsersModel();
}
}
|
[
"public",
"function",
"checkUsersModel",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"usersModel",
")",
"{",
"$",
"this",
"->",
"setUsersModel",
"(",
"$",
"this",
"->",
"in",
"(",
"'What is the name of your users model?'",
")",
")",
";",
"}",
"$",
"this",
"->",
"out",
"(",
"sprintf",
"(",
"'Users Model: <info>%s</info>'",
",",
"$",
"this",
"->",
"usersModel",
")",
")",
";",
"$",
"answer",
"=",
"strtoupper",
"(",
"$",
"this",
"->",
"in",
"(",
"'Is this correct?'",
",",
"array",
"(",
"'Y'",
",",
"'N'",
")",
")",
")",
";",
"if",
"(",
"$",
"answer",
"===",
"'N'",
")",
"{",
"$",
"this",
"->",
"usersModel",
"=",
"null",
";",
"$",
"this",
"->",
"checkUsersModel",
"(",
")",
";",
"}",
"}"
] |
Determine the users model to use.
@return bool
|
[
"Determine",
"the",
"users",
"model",
"to",
"use",
"."
] |
146318ff0a882917defab7f4918b0d198eb5a3c0
|
https://github.com/milesj/utility/blob/146318ff0a882917defab7f4918b0d198eb5a3c0/Console/Command/BaseInstallShell.php#L222-L235
|
229,473
|
milesj/utility
|
Console/Command/BaseInstallShell.php
|
BaseInstallShell.checkUsersTable
|
public function checkUsersTable() {
if (!$this->usersTable) {
$this->setUsersTable($this->in('What is the name of your users table?'));
}
$this->out(sprintf('Users Table: <info>%s</info>', $this->usersTable));
$answer = strtoupper($this->in('Is this correct?', array('Y', 'N')));
if ($answer === 'N') {
$this->usersTable = null;
$this->checkUsersTable();
} else {
$this->setRequiredTables(array($this->usersTable));
}
$this->checkUsersModel();
$this->out('<success>Users table set, proceeding...</success>');
return true;
}
|
php
|
public function checkUsersTable() {
if (!$this->usersTable) {
$this->setUsersTable($this->in('What is the name of your users table?'));
}
$this->out(sprintf('Users Table: <info>%s</info>', $this->usersTable));
$answer = strtoupper($this->in('Is this correct?', array('Y', 'N')));
if ($answer === 'N') {
$this->usersTable = null;
$this->checkUsersTable();
} else {
$this->setRequiredTables(array($this->usersTable));
}
$this->checkUsersModel();
$this->out('<success>Users table set, proceeding...</success>');
return true;
}
|
[
"public",
"function",
"checkUsersTable",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"usersTable",
")",
"{",
"$",
"this",
"->",
"setUsersTable",
"(",
"$",
"this",
"->",
"in",
"(",
"'What is the name of your users table?'",
")",
")",
";",
"}",
"$",
"this",
"->",
"out",
"(",
"sprintf",
"(",
"'Users Table: <info>%s</info>'",
",",
"$",
"this",
"->",
"usersTable",
")",
")",
";",
"$",
"answer",
"=",
"strtoupper",
"(",
"$",
"this",
"->",
"in",
"(",
"'Is this correct?'",
",",
"array",
"(",
"'Y'",
",",
"'N'",
")",
")",
")",
";",
"if",
"(",
"$",
"answer",
"===",
"'N'",
")",
"{",
"$",
"this",
"->",
"usersTable",
"=",
"null",
";",
"$",
"this",
"->",
"checkUsersTable",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setRequiredTables",
"(",
"array",
"(",
"$",
"this",
"->",
"usersTable",
")",
")",
";",
"}",
"$",
"this",
"->",
"checkUsersModel",
"(",
")",
";",
"$",
"this",
"->",
"out",
"(",
"'<success>Users table set, proceeding...</success>'",
")",
";",
"return",
"true",
";",
"}"
] |
Determine the users table to use.
@return bool
|
[
"Determine",
"the",
"users",
"table",
"to",
"use",
"."
] |
146318ff0a882917defab7f4918b0d198eb5a3c0
|
https://github.com/milesj/utility/blob/146318ff0a882917defab7f4918b0d198eb5a3c0/Console/Command/BaseInstallShell.php#L242-L262
|
229,474
|
milesj/utility
|
Console/Command/BaseInstallShell.php
|
BaseInstallShell.createTables
|
public function createTables() {
$answer = strtoupper($this->in('Existing tables will be deleted, continue?', array('Y', 'N')));
if ($answer === 'N') {
return false;
}
$schemas = glob(CakePlugin::path($this->plugin) . '/Config/Schema/*.sql');
$executed = 0;
$tables = array();
// Loop over schemas and execute queries
$this->out('<success>Creating tables...</success>');
foreach ($schemas as $schema) {
$table = $this->tablePrefix . str_replace('.sql', '', basename($schema));
$tables[] = $table;
$executed += $this->executeSchema($schema);
$this->out($table);
}
// Rollback if a failure occurs
if ($executed != count($schemas)) {
$this->out('<error>Failed to create database tables; rolling back</error>');
foreach ($tables as $table) {
$this->db->execute(sprintf('DROP TABLE `%s`;', $table));
}
return false;
}
$this->out('<success>Tables created successfully, proceeding...</success>');
return true;
}
|
php
|
public function createTables() {
$answer = strtoupper($this->in('Existing tables will be deleted, continue?', array('Y', 'N')));
if ($answer === 'N') {
return false;
}
$schemas = glob(CakePlugin::path($this->plugin) . '/Config/Schema/*.sql');
$executed = 0;
$tables = array();
// Loop over schemas and execute queries
$this->out('<success>Creating tables...</success>');
foreach ($schemas as $schema) {
$table = $this->tablePrefix . str_replace('.sql', '', basename($schema));
$tables[] = $table;
$executed += $this->executeSchema($schema);
$this->out($table);
}
// Rollback if a failure occurs
if ($executed != count($schemas)) {
$this->out('<error>Failed to create database tables; rolling back</error>');
foreach ($tables as $table) {
$this->db->execute(sprintf('DROP TABLE `%s`;', $table));
}
return false;
}
$this->out('<success>Tables created successfully, proceeding...</success>');
return true;
}
|
[
"public",
"function",
"createTables",
"(",
")",
"{",
"$",
"answer",
"=",
"strtoupper",
"(",
"$",
"this",
"->",
"in",
"(",
"'Existing tables will be deleted, continue?'",
",",
"array",
"(",
"'Y'",
",",
"'N'",
")",
")",
")",
";",
"if",
"(",
"$",
"answer",
"===",
"'N'",
")",
"{",
"return",
"false",
";",
"}",
"$",
"schemas",
"=",
"glob",
"(",
"CakePlugin",
"::",
"path",
"(",
"$",
"this",
"->",
"plugin",
")",
".",
"'/Config/Schema/*.sql'",
")",
";",
"$",
"executed",
"=",
"0",
";",
"$",
"tables",
"=",
"array",
"(",
")",
";",
"// Loop over schemas and execute queries",
"$",
"this",
"->",
"out",
"(",
"'<success>Creating tables...</success>'",
")",
";",
"foreach",
"(",
"$",
"schemas",
"as",
"$",
"schema",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"tablePrefix",
".",
"str_replace",
"(",
"'.sql'",
",",
"''",
",",
"basename",
"(",
"$",
"schema",
")",
")",
";",
"$",
"tables",
"[",
"]",
"=",
"$",
"table",
";",
"$",
"executed",
"+=",
"$",
"this",
"->",
"executeSchema",
"(",
"$",
"schema",
")",
";",
"$",
"this",
"->",
"out",
"(",
"$",
"table",
")",
";",
"}",
"// Rollback if a failure occurs",
"if",
"(",
"$",
"executed",
"!=",
"count",
"(",
"$",
"schemas",
")",
")",
"{",
"$",
"this",
"->",
"out",
"(",
"'<error>Failed to create database tables; rolling back</error>'",
")",
";",
"foreach",
"(",
"$",
"tables",
"as",
"$",
"table",
")",
"{",
"$",
"this",
"->",
"db",
"->",
"execute",
"(",
"sprintf",
"(",
"'DROP TABLE `%s`;'",
",",
"$",
"table",
")",
")",
";",
"}",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"out",
"(",
"'<success>Tables created successfully, proceeding...</success>'",
")",
";",
"return",
"true",
";",
"}"
] |
Create the database tables based off the schemas.
@return bool
|
[
"Create",
"the",
"database",
"tables",
"based",
"off",
"the",
"schemas",
"."
] |
146318ff0a882917defab7f4918b0d198eb5a3c0
|
https://github.com/milesj/utility/blob/146318ff0a882917defab7f4918b0d198eb5a3c0/Console/Command/BaseInstallShell.php#L269-L304
|
229,475
|
milesj/utility
|
Console/Command/BaseInstallShell.php
|
BaseInstallShell.createUser
|
public function createUser() {
$data = array();
foreach ($this->userFields as $base => $field) {
$data[$field] = $this->getFieldInput($base);
}
$model = ClassRegistry::init($this->usersModel);
$model->create();
$model->save($data, false);
$this->config = $data;
$this->user = $model->find('first', array(
'conditions' => array($model->alias . '.' . $model->primaryKey => $model->id),
'recursive' => -1
));
return $model->id;
}
|
php
|
public function createUser() {
$data = array();
foreach ($this->userFields as $base => $field) {
$data[$field] = $this->getFieldInput($base);
}
$model = ClassRegistry::init($this->usersModel);
$model->create();
$model->save($data, false);
$this->config = $data;
$this->user = $model->find('first', array(
'conditions' => array($model->alias . '.' . $model->primaryKey => $model->id),
'recursive' => -1
));
return $model->id;
}
|
[
"public",
"function",
"createUser",
"(",
")",
"{",
"$",
"data",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"userFields",
"as",
"$",
"base",
"=>",
"$",
"field",
")",
"{",
"$",
"data",
"[",
"$",
"field",
"]",
"=",
"$",
"this",
"->",
"getFieldInput",
"(",
"$",
"base",
")",
";",
"}",
"$",
"model",
"=",
"ClassRegistry",
"::",
"init",
"(",
"$",
"this",
"->",
"usersModel",
")",
";",
"$",
"model",
"->",
"create",
"(",
")",
";",
"$",
"model",
"->",
"save",
"(",
"$",
"data",
",",
"false",
")",
";",
"$",
"this",
"->",
"config",
"=",
"$",
"data",
";",
"$",
"this",
"->",
"user",
"=",
"$",
"model",
"->",
"find",
"(",
"'first'",
",",
"array",
"(",
"'conditions'",
"=>",
"array",
"(",
"$",
"model",
"->",
"alias",
".",
"'.'",
".",
"$",
"model",
"->",
"primaryKey",
"=>",
"$",
"model",
"->",
"id",
")",
",",
"'recursive'",
"=>",
"-",
"1",
")",
")",
";",
"return",
"$",
"model",
"->",
"id",
";",
"}"
] |
Gather all the data for creating a new user.
@return int
|
[
"Gather",
"all",
"the",
"data",
"for",
"creating",
"a",
"new",
"user",
"."
] |
146318ff0a882917defab7f4918b0d198eb5a3c0
|
https://github.com/milesj/utility/blob/146318ff0a882917defab7f4918b0d198eb5a3c0/Console/Command/BaseInstallShell.php#L311-L329
|
229,476
|
milesj/utility
|
Console/Command/BaseInstallShell.php
|
BaseInstallShell.executeSchema
|
public function executeSchema($path, $track = true) {
if (!file_exists($path)) {
throw new DomainException(sprintf('<error>Schema %s does not exist</error>', basename($path)));
}
$contents = file_get_contents($path);
$contents = String::insert($contents, array('prefix' => $this->tablePrefix), array('before' => '{', 'after' => '}'));
$contents = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $contents);
$queries = explode(';', $contents);
$executed = 0;
foreach ($queries as $query) {
$query = trim($query);
if (!$query) {
continue;
}
if ($this->db->execute($query)) {
$command = trim(substr($query, 0, strpos($query, ' ')));
if ($track) {
if ($command === 'CREATE' || $command === 'ALTER') {
$executed++;
}
} else {
$executed++;
}
}
}
return $executed;
}
|
php
|
public function executeSchema($path, $track = true) {
if (!file_exists($path)) {
throw new DomainException(sprintf('<error>Schema %s does not exist</error>', basename($path)));
}
$contents = file_get_contents($path);
$contents = String::insert($contents, array('prefix' => $this->tablePrefix), array('before' => '{', 'after' => '}'));
$contents = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $contents);
$queries = explode(';', $contents);
$executed = 0;
foreach ($queries as $query) {
$query = trim($query);
if (!$query) {
continue;
}
if ($this->db->execute($query)) {
$command = trim(substr($query, 0, strpos($query, ' ')));
if ($track) {
if ($command === 'CREATE' || $command === 'ALTER') {
$executed++;
}
} else {
$executed++;
}
}
}
return $executed;
}
|
[
"public",
"function",
"executeSchema",
"(",
"$",
"path",
",",
"$",
"track",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"DomainException",
"(",
"sprintf",
"(",
"'<error>Schema %s does not exist</error>'",
",",
"basename",
"(",
"$",
"path",
")",
")",
")",
";",
"}",
"$",
"contents",
"=",
"file_get_contents",
"(",
"$",
"path",
")",
";",
"$",
"contents",
"=",
"String",
"::",
"insert",
"(",
"$",
"contents",
",",
"array",
"(",
"'prefix'",
"=>",
"$",
"this",
"->",
"tablePrefix",
")",
",",
"array",
"(",
"'before'",
"=>",
"'{'",
",",
"'after'",
"=>",
"'}'",
")",
")",
";",
"$",
"contents",
"=",
"preg_replace",
"(",
"'!/\\*[^*]*\\*+([^/][^*]*\\*+)*/!'",
",",
"''",
",",
"$",
"contents",
")",
";",
"$",
"queries",
"=",
"explode",
"(",
"';'",
",",
"$",
"contents",
")",
";",
"$",
"executed",
"=",
"0",
";",
"foreach",
"(",
"$",
"queries",
"as",
"$",
"query",
")",
"{",
"$",
"query",
"=",
"trim",
"(",
"$",
"query",
")",
";",
"if",
"(",
"!",
"$",
"query",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"db",
"->",
"execute",
"(",
"$",
"query",
")",
")",
"{",
"$",
"command",
"=",
"trim",
"(",
"substr",
"(",
"$",
"query",
",",
"0",
",",
"strpos",
"(",
"$",
"query",
",",
"' '",
")",
")",
")",
";",
"if",
"(",
"$",
"track",
")",
"{",
"if",
"(",
"$",
"command",
"===",
"'CREATE'",
"||",
"$",
"command",
"===",
"'ALTER'",
")",
"{",
"$",
"executed",
"++",
";",
"}",
"}",
"else",
"{",
"$",
"executed",
"++",
";",
"}",
"}",
"}",
"return",
"$",
"executed",
";",
"}"
] |
Execute a schema SQL file using the loaded datasource.
@param string $path
@param bool $track
@return int
@throws DomainException
|
[
"Execute",
"a",
"schema",
"SQL",
"file",
"using",
"the",
"loaded",
"datasource",
"."
] |
146318ff0a882917defab7f4918b0d198eb5a3c0
|
https://github.com/milesj/utility/blob/146318ff0a882917defab7f4918b0d198eb5a3c0/Console/Command/BaseInstallShell.php#L339-L372
|
229,477
|
milesj/utility
|
Console/Command/BaseInstallShell.php
|
BaseInstallShell.findUser
|
public function findUser() {
$model = ClassRegistry::init($this->usersModel);
$id = trim($this->in('User ID:'));
if (!$id) {
$this->out('<error>Invalid ID, please try again</error>');
return $this->findUser();
}
$result = $model->find('first', array(
'conditions' => array($model->alias . '.' . $model->primaryKey => $id),
'recursive' => -1
));
if (!$result) {
$this->out('<error>User does not exist, please try again</error>');
return $this->findUser();
}
$this->user = $result;
return $id;
}
|
php
|
public function findUser() {
$model = ClassRegistry::init($this->usersModel);
$id = trim($this->in('User ID:'));
if (!$id) {
$this->out('<error>Invalid ID, please try again</error>');
return $this->findUser();
}
$result = $model->find('first', array(
'conditions' => array($model->alias . '.' . $model->primaryKey => $id),
'recursive' => -1
));
if (!$result) {
$this->out('<error>User does not exist, please try again</error>');
return $this->findUser();
}
$this->user = $result;
return $id;
}
|
[
"public",
"function",
"findUser",
"(",
")",
"{",
"$",
"model",
"=",
"ClassRegistry",
"::",
"init",
"(",
"$",
"this",
"->",
"usersModel",
")",
";",
"$",
"id",
"=",
"trim",
"(",
"$",
"this",
"->",
"in",
"(",
"'User ID:'",
")",
")",
";",
"if",
"(",
"!",
"$",
"id",
")",
"{",
"$",
"this",
"->",
"out",
"(",
"'<error>Invalid ID, please try again</error>'",
")",
";",
"return",
"$",
"this",
"->",
"findUser",
"(",
")",
";",
"}",
"$",
"result",
"=",
"$",
"model",
"->",
"find",
"(",
"'first'",
",",
"array",
"(",
"'conditions'",
"=>",
"array",
"(",
"$",
"model",
"->",
"alias",
".",
"'.'",
".",
"$",
"model",
"->",
"primaryKey",
"=>",
"$",
"id",
")",
",",
"'recursive'",
"=>",
"-",
"1",
")",
")",
";",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"$",
"this",
"->",
"out",
"(",
"'<error>User does not exist, please try again</error>'",
")",
";",
"return",
"$",
"this",
"->",
"findUser",
"(",
")",
";",
"}",
"$",
"this",
"->",
"user",
"=",
"$",
"result",
";",
"return",
"$",
"id",
";",
"}"
] |
Find a user within the users table.
@return int
|
[
"Find",
"a",
"user",
"within",
"the",
"users",
"table",
"."
] |
146318ff0a882917defab7f4918b0d198eb5a3c0
|
https://github.com/milesj/utility/blob/146318ff0a882917defab7f4918b0d198eb5a3c0/Console/Command/BaseInstallShell.php#L379-L401
|
229,478
|
milesj/utility
|
Console/Command/BaseInstallShell.php
|
BaseInstallShell.setDbConfig
|
public function setDbConfig($config) {
$this->dbConfig = $config;
$this->db = ConnectionManager::getDataSource($config);
$this->db->cacheSources = false;
return $this;
}
|
php
|
public function setDbConfig($config) {
$this->dbConfig = $config;
$this->db = ConnectionManager::getDataSource($config);
$this->db->cacheSources = false;
return $this;
}
|
[
"public",
"function",
"setDbConfig",
"(",
"$",
"config",
")",
"{",
"$",
"this",
"->",
"dbConfig",
"=",
"$",
"config",
";",
"$",
"this",
"->",
"db",
"=",
"ConnectionManager",
"::",
"getDataSource",
"(",
"$",
"config",
")",
";",
"$",
"this",
"->",
"db",
"->",
"cacheSources",
"=",
"false",
";",
"return",
"$",
"this",
";",
"}"
] |
Set the database config to use and load the data source.
@param string $config
@return BaseInstallShell
|
[
"Set",
"the",
"database",
"config",
"to",
"use",
"and",
"load",
"the",
"data",
"source",
"."
] |
146318ff0a882917defab7f4918b0d198eb5a3c0
|
https://github.com/milesj/utility/blob/146318ff0a882917defab7f4918b0d198eb5a3c0/Console/Command/BaseInstallShell.php#L476-L483
|
229,479
|
milesj/utility
|
Console/Command/BaseInstallShell.php
|
BaseInstallShell.setRequiredTables
|
public function setRequiredTables(array $tables) {
$this->requiredTables = array_unique(array_merge($this->requiredTables, $tables));
return $this;
}
|
php
|
public function setRequiredTables(array $tables) {
$this->requiredTables = array_unique(array_merge($this->requiredTables, $tables));
return $this;
}
|
[
"public",
"function",
"setRequiredTables",
"(",
"array",
"$",
"tables",
")",
"{",
"$",
"this",
"->",
"requiredTables",
"=",
"array_unique",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"requiredTables",
",",
"$",
"tables",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Set the required tables.
@param array $tables
@return BaseInstallShell
|
[
"Set",
"the",
"required",
"tables",
"."
] |
146318ff0a882917defab7f4918b0d198eb5a3c0
|
https://github.com/milesj/utility/blob/146318ff0a882917defab7f4918b0d198eb5a3c0/Console/Command/BaseInstallShell.php#L491-L495
|
229,480
|
milesj/utility
|
Console/Command/BaseInstallShell.php
|
BaseInstallShell.setUserFields
|
public function setUserFields(array $fields) {
$clean = array();
foreach ($fields as $base => $field) {
if (is_numeric($base)) {
$base = $field;
}
$clean[$base] = $field;
}
$this->userFields = $clean;
return $this;
}
|
php
|
public function setUserFields(array $fields) {
$clean = array();
foreach ($fields as $base => $field) {
if (is_numeric($base)) {
$base = $field;
}
$clean[$base] = $field;
}
$this->userFields = $clean;
return $this;
}
|
[
"public",
"function",
"setUserFields",
"(",
"array",
"$",
"fields",
")",
"{",
"$",
"clean",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"base",
"=>",
"$",
"field",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"base",
")",
")",
"{",
"$",
"base",
"=",
"$",
"field",
";",
"}",
"$",
"clean",
"[",
"$",
"base",
"]",
"=",
"$",
"field",
";",
"}",
"$",
"this",
"->",
"userFields",
"=",
"$",
"clean",
";",
"return",
"$",
"this",
";",
"}"
] |
Set the user fields mapping.
@param array $fields
@return BaseInstallShell
|
[
"Set",
"the",
"user",
"fields",
"mapping",
"."
] |
146318ff0a882917defab7f4918b0d198eb5a3c0
|
https://github.com/milesj/utility/blob/146318ff0a882917defab7f4918b0d198eb5a3c0/Console/Command/BaseInstallShell.php#L532-L546
|
229,481
|
milesj/utility
|
Console/Command/BaseInstallShell.php
|
BaseInstallShell.steps
|
public function steps($step = 0) {
$this->hr(1);
$counter = 1;
foreach ($this->steps as $title => $method) {
if ($counter < $step) {
$this->out('[x] ' . $title);
} else {
$this->out(sprintf('[%s] <info>%s</info>', $counter, $title));
}
$counter++;
}
$this->out();
}
|
php
|
public function steps($step = 0) {
$this->hr(1);
$counter = 1;
foreach ($this->steps as $title => $method) {
if ($counter < $step) {
$this->out('[x] ' . $title);
} else {
$this->out(sprintf('[%s] <info>%s</info>', $counter, $title));
}
$counter++;
}
$this->out();
}
|
[
"public",
"function",
"steps",
"(",
"$",
"step",
"=",
"0",
")",
"{",
"$",
"this",
"->",
"hr",
"(",
"1",
")",
";",
"$",
"counter",
"=",
"1",
";",
"foreach",
"(",
"$",
"this",
"->",
"steps",
"as",
"$",
"title",
"=>",
"$",
"method",
")",
"{",
"if",
"(",
"$",
"counter",
"<",
"$",
"step",
")",
"{",
"$",
"this",
"->",
"out",
"(",
"'[x] '",
".",
"$",
"title",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"out",
"(",
"sprintf",
"(",
"'[%s] <info>%s</info>'",
",",
"$",
"counter",
",",
"$",
"title",
")",
")",
";",
"}",
"$",
"counter",
"++",
";",
"}",
"$",
"this",
"->",
"out",
"(",
")",
";",
"}"
] |
Table of contents.
@param int $step
|
[
"Table",
"of",
"contents",
"."
] |
146318ff0a882917defab7f4918b0d198eb5a3c0
|
https://github.com/milesj/utility/blob/146318ff0a882917defab7f4918b0d198eb5a3c0/Console/Command/BaseInstallShell.php#L577-L593
|
229,482
|
thelia-modules/Paybox
|
Paybox.php
|
Paybox.doPay
|
protected function doPay(Order $order)
{
if ('TEST' == Paybox::getConfigValue('mode', false)) {
$platformUrl = Paybox::getConfigValue('url_serveur_test', false);
} else {
$platformUrl = Paybox::getConfigValue('url_serveur', false);
}
// Be sure to have a valid platform URL, otherwise give up
if (false === $platformUrl) {
throw new \InvalidArgumentException(
Translator::getInstance()->trans(
"The platform URL is not defined, please check Paybox module configuration.",
[],
Paybox::MODULE_DOMAIN
)
);
}
$hashAlgo = $this->getHashAlgorithm();
$clefPrivee = Paybox::getConfigValue('clef_privee');
$paybox_params = $this->doPayPayboxParameters($order)
+ [
'PBX_HASH' => $hashAlgo,
'PBX_SECRET' => $clefPrivee
];
// Generate signature
$param = '';
foreach ($paybox_params as $key => $value) {
$param .= "&" . $key . '=' . $value;
}
$param = ltrim($param, '&');
$binkey = pack('H*', $clefPrivee);
$paybox_params['PBX_HMAC'] = strtoupper(hash_hmac($hashAlgo, $param, $binkey));
return $this->generateGatewayFormResponse($order, $platformUrl, $paybox_params);
}
|
php
|
protected function doPay(Order $order)
{
if ('TEST' == Paybox::getConfigValue('mode', false)) {
$platformUrl = Paybox::getConfigValue('url_serveur_test', false);
} else {
$platformUrl = Paybox::getConfigValue('url_serveur', false);
}
// Be sure to have a valid platform URL, otherwise give up
if (false === $platformUrl) {
throw new \InvalidArgumentException(
Translator::getInstance()->trans(
"The platform URL is not defined, please check Paybox module configuration.",
[],
Paybox::MODULE_DOMAIN
)
);
}
$hashAlgo = $this->getHashAlgorithm();
$clefPrivee = Paybox::getConfigValue('clef_privee');
$paybox_params = $this->doPayPayboxParameters($order)
+ [
'PBX_HASH' => $hashAlgo,
'PBX_SECRET' => $clefPrivee
];
// Generate signature
$param = '';
foreach ($paybox_params as $key => $value) {
$param .= "&" . $key . '=' . $value;
}
$param = ltrim($param, '&');
$binkey = pack('H*', $clefPrivee);
$paybox_params['PBX_HMAC'] = strtoupper(hash_hmac($hashAlgo, $param, $binkey));
return $this->generateGatewayFormResponse($order, $platformUrl, $paybox_params);
}
|
[
"protected",
"function",
"doPay",
"(",
"Order",
"$",
"order",
")",
"{",
"if",
"(",
"'TEST'",
"==",
"Paybox",
"::",
"getConfigValue",
"(",
"'mode'",
",",
"false",
")",
")",
"{",
"$",
"platformUrl",
"=",
"Paybox",
"::",
"getConfigValue",
"(",
"'url_serveur_test'",
",",
"false",
")",
";",
"}",
"else",
"{",
"$",
"platformUrl",
"=",
"Paybox",
"::",
"getConfigValue",
"(",
"'url_serveur'",
",",
"false",
")",
";",
"}",
"// Be sure to have a valid platform URL, otherwise give up\r",
"if",
"(",
"false",
"===",
"$",
"platformUrl",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"Translator",
"::",
"getInstance",
"(",
")",
"->",
"trans",
"(",
"\"The platform URL is not defined, please check Paybox module configuration.\"",
",",
"[",
"]",
",",
"Paybox",
"::",
"MODULE_DOMAIN",
")",
")",
";",
"}",
"$",
"hashAlgo",
"=",
"$",
"this",
"->",
"getHashAlgorithm",
"(",
")",
";",
"$",
"clefPrivee",
"=",
"Paybox",
"::",
"getConfigValue",
"(",
"'clef_privee'",
")",
";",
"$",
"paybox_params",
"=",
"$",
"this",
"->",
"doPayPayboxParameters",
"(",
"$",
"order",
")",
"+",
"[",
"'PBX_HASH'",
"=>",
"$",
"hashAlgo",
",",
"'PBX_SECRET'",
"=>",
"$",
"clefPrivee",
"]",
";",
"// Generate signature\r",
"$",
"param",
"=",
"''",
";",
"foreach",
"(",
"$",
"paybox_params",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"param",
".=",
"\"&\"",
".",
"$",
"key",
".",
"'='",
".",
"$",
"value",
";",
"}",
"$",
"param",
"=",
"ltrim",
"(",
"$",
"param",
",",
"'&'",
")",
";",
"$",
"binkey",
"=",
"pack",
"(",
"'H*'",
",",
"$",
"clefPrivee",
")",
";",
"$",
"paybox_params",
"[",
"'PBX_HMAC'",
"]",
"=",
"strtoupper",
"(",
"hash_hmac",
"(",
"$",
"hashAlgo",
",",
"$",
"param",
",",
"$",
"binkey",
")",
")",
";",
"return",
"$",
"this",
"->",
"generateGatewayFormResponse",
"(",
"$",
"order",
",",
"$",
"platformUrl",
",",
"$",
"paybox_params",
")",
";",
"}"
] |
Payment gateway invocation
@param Order $order processed order
@return Response the HTTP response
|
[
"Payment",
"gateway",
"invocation"
] |
08b9f4478ecbdb234fc373d6540010af34d2d87c
|
https://github.com/thelia-modules/Paybox/blob/08b9f4478ecbdb234fc373d6540010af34d2d87c/Paybox.php#L137-L179
|
229,483
|
thelia-modules/Paybox
|
Paybox.php
|
Paybox.getCurrencyIso4217NumericCode
|
protected function getCurrencyIso4217NumericCode($textCurrencyCode)
{
$currencies = null;
$localIso417data = __DIR__ . DS . "Config" . DS . "iso4217.xml";
$currencyXmlDataUrl = "http://www.currency-iso.org/dam/downloads/lists/list_one.xml";
$xmlData = @file_get_contents($currencyXmlDataUrl);
try {
$currencies = new \SimpleXMLElement($xmlData);
// Update the local currencies copy.
@file_put_contents($localIso417data, $xmlData);
} catch (\Exception $ex) {
Tlog::getInstance()->warning("Failed to get currency XML data from $currencyXmlDataUrl: ".$ex->getMessage());
try {
$currencies = new \SimpleXMLElement(@file_get_contents($localIso417data));
} catch (\Exception $ex) {
Tlog::getInstance()->warning("Failed to get currency XML data from local copy $localIso417data: ".$ex->getMessage());
}
}
if (null !== $currencies) {
foreach ($currencies->CcyTbl->CcyNtry as $country) {
if ($country->Ccy == $textCurrencyCode) {
return (string) $country->CcyNbr;
}
}
}
// Last chance
switch ($textCurrencyCode) {
case 'USD':
return 840;
case 'GBP':
return 826;
break;
case 'EUR':
return 978;
break;
}
throw new \RuntimeException(
Translator::getInstance()->trans(
"Failed to get ISO 4217 data for currency %curr, payment is not possible.",
['%curr' => $textCurrencyCode]
)
);
}
|
php
|
protected function getCurrencyIso4217NumericCode($textCurrencyCode)
{
$currencies = null;
$localIso417data = __DIR__ . DS . "Config" . DS . "iso4217.xml";
$currencyXmlDataUrl = "http://www.currency-iso.org/dam/downloads/lists/list_one.xml";
$xmlData = @file_get_contents($currencyXmlDataUrl);
try {
$currencies = new \SimpleXMLElement($xmlData);
// Update the local currencies copy.
@file_put_contents($localIso417data, $xmlData);
} catch (\Exception $ex) {
Tlog::getInstance()->warning("Failed to get currency XML data from $currencyXmlDataUrl: ".$ex->getMessage());
try {
$currencies = new \SimpleXMLElement(@file_get_contents($localIso417data));
} catch (\Exception $ex) {
Tlog::getInstance()->warning("Failed to get currency XML data from local copy $localIso417data: ".$ex->getMessage());
}
}
if (null !== $currencies) {
foreach ($currencies->CcyTbl->CcyNtry as $country) {
if ($country->Ccy == $textCurrencyCode) {
return (string) $country->CcyNbr;
}
}
}
// Last chance
switch ($textCurrencyCode) {
case 'USD':
return 840;
case 'GBP':
return 826;
break;
case 'EUR':
return 978;
break;
}
throw new \RuntimeException(
Translator::getInstance()->trans(
"Failed to get ISO 4217 data for currency %curr, payment is not possible.",
['%curr' => $textCurrencyCode]
)
);
}
|
[
"protected",
"function",
"getCurrencyIso4217NumericCode",
"(",
"$",
"textCurrencyCode",
")",
"{",
"$",
"currencies",
"=",
"null",
";",
"$",
"localIso417data",
"=",
"__DIR__",
".",
"DS",
".",
"\"Config\"",
".",
"DS",
".",
"\"iso4217.xml\"",
";",
"$",
"currencyXmlDataUrl",
"=",
"\"http://www.currency-iso.org/dam/downloads/lists/list_one.xml\"",
";",
"$",
"xmlData",
"=",
"@",
"file_get_contents",
"(",
"$",
"currencyXmlDataUrl",
")",
";",
"try",
"{",
"$",
"currencies",
"=",
"new",
"\\",
"SimpleXMLElement",
"(",
"$",
"xmlData",
")",
";",
"// Update the local currencies copy.\r",
"@",
"file_put_contents",
"(",
"$",
"localIso417data",
",",
"$",
"xmlData",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"Tlog",
"::",
"getInstance",
"(",
")",
"->",
"warning",
"(",
"\"Failed to get currency XML data from $currencyXmlDataUrl: \"",
".",
"$",
"ex",
"->",
"getMessage",
"(",
")",
")",
";",
"try",
"{",
"$",
"currencies",
"=",
"new",
"\\",
"SimpleXMLElement",
"(",
"@",
"file_get_contents",
"(",
"$",
"localIso417data",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"Tlog",
"::",
"getInstance",
"(",
")",
"->",
"warning",
"(",
"\"Failed to get currency XML data from local copy $localIso417data: \"",
".",
"$",
"ex",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"if",
"(",
"null",
"!==",
"$",
"currencies",
")",
"{",
"foreach",
"(",
"$",
"currencies",
"->",
"CcyTbl",
"->",
"CcyNtry",
"as",
"$",
"country",
")",
"{",
"if",
"(",
"$",
"country",
"->",
"Ccy",
"==",
"$",
"textCurrencyCode",
")",
"{",
"return",
"(",
"string",
")",
"$",
"country",
"->",
"CcyNbr",
";",
"}",
"}",
"}",
"// Last chance\r",
"switch",
"(",
"$",
"textCurrencyCode",
")",
"{",
"case",
"'USD'",
":",
"return",
"840",
";",
"case",
"'GBP'",
":",
"return",
"826",
";",
"break",
";",
"case",
"'EUR'",
":",
"return",
"978",
";",
"break",
";",
"}",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"Translator",
"::",
"getInstance",
"(",
")",
"->",
"trans",
"(",
"\"Failed to get ISO 4217 data for currency %curr, payment is not possible.\"",
",",
"[",
"'%curr'",
"=>",
"$",
"textCurrencyCode",
"]",
")",
")",
";",
"}"
] |
Get the numeric ISO 4217 code of a currency
@param string $textCurrencyCode currency textual code, like EUR or USD
@return string the algorithm
@throw \RuntimeException if no algorithm was found.
|
[
"Get",
"the",
"numeric",
"ISO",
"4217",
"code",
"of",
"a",
"currency"
] |
08b9f4478ecbdb234fc373d6540010af34d2d87c
|
https://github.com/thelia-modules/Paybox/blob/08b9f4478ecbdb234fc373d6540010af34d2d87c/Paybox.php#L270-L320
|
229,484
|
thelia-modules/Paybox
|
Paybox.php
|
Paybox.getHashAlgorithm
|
protected function getHashAlgorithm()
{
// Possible hashes
$hashes = [
'sha512',
'sha256',
'sha384',
'ripemd160',
'sha224',
'mdc2'
];
$hashEnabled = hash_algos();
foreach ($hashes as $hash) {
if (in_array($hash, $hashEnabled)) {
return strtoupper($hash);
}
}
throw new \RuntimeException(
Translator::getInstance()->trans(
"Failed to find a suitable hash algorithm. Please check your PHP configuration."
)
);
}
|
php
|
protected function getHashAlgorithm()
{
// Possible hashes
$hashes = [
'sha512',
'sha256',
'sha384',
'ripemd160',
'sha224',
'mdc2'
];
$hashEnabled = hash_algos();
foreach ($hashes as $hash) {
if (in_array($hash, $hashEnabled)) {
return strtoupper($hash);
}
}
throw new \RuntimeException(
Translator::getInstance()->trans(
"Failed to find a suitable hash algorithm. Please check your PHP configuration."
)
);
}
|
[
"protected",
"function",
"getHashAlgorithm",
"(",
")",
"{",
"// Possible hashes\r",
"$",
"hashes",
"=",
"[",
"'sha512'",
",",
"'sha256'",
",",
"'sha384'",
",",
"'ripemd160'",
",",
"'sha224'",
",",
"'mdc2'",
"]",
";",
"$",
"hashEnabled",
"=",
"hash_algos",
"(",
")",
";",
"foreach",
"(",
"$",
"hashes",
"as",
"$",
"hash",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"hash",
",",
"$",
"hashEnabled",
")",
")",
"{",
"return",
"strtoupper",
"(",
"$",
"hash",
")",
";",
"}",
"}",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"Translator",
"::",
"getInstance",
"(",
")",
"->",
"trans",
"(",
"\"Failed to find a suitable hash algorithm. Please check your PHP configuration.\"",
")",
")",
";",
"}"
] |
Find a suitable hashing algorithm
@return string the algorithm
@throw \RuntimeException if no algorithm was found.
|
[
"Find",
"a",
"suitable",
"hashing",
"algorithm"
] |
08b9f4478ecbdb234fc373d6540010af34d2d87c
|
https://github.com/thelia-modules/Paybox/blob/08b9f4478ecbdb234fc373d6540010af34d2d87c/Paybox.php#L328-L353
|
229,485
|
fuelphp/common
|
src/Table.php
|
Table.addCell
|
public function addCell($content, $attributes = array())
{
$currentRow = $this->getCurrentRow();
//If we have been given a Cell then just add it, else create a new cell
if ( $content instanceof Cell )
{
$currentRow[] = $content;
}
else
{
$currentRow[] = $this->constructCell($content, $attributes);
}
return $this;
}
|
php
|
public function addCell($content, $attributes = array())
{
$currentRow = $this->getCurrentRow();
//If we have been given a Cell then just add it, else create a new cell
if ( $content instanceof Cell )
{
$currentRow[] = $content;
}
else
{
$currentRow[] = $this->constructCell($content, $attributes);
}
return $this;
}
|
[
"public",
"function",
"addCell",
"(",
"$",
"content",
",",
"$",
"attributes",
"=",
"array",
"(",
")",
")",
"{",
"$",
"currentRow",
"=",
"$",
"this",
"->",
"getCurrentRow",
"(",
")",
";",
"//If we have been given a Cell then just add it, else create a new cell",
"if",
"(",
"$",
"content",
"instanceof",
"Cell",
")",
"{",
"$",
"currentRow",
"[",
"]",
"=",
"$",
"content",
";",
"}",
"else",
"{",
"$",
"currentRow",
"[",
"]",
"=",
"$",
"this",
"->",
"constructCell",
"(",
"$",
"content",
",",
"$",
"attributes",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Adds a Cell to the current Row
@param mixed $content Anything that is not a Cell will be added as content to a new Cell
@param array $attributes The array of attributes to assign the new Cell
@return $this
|
[
"Adds",
"a",
"Cell",
"to",
"the",
"current",
"Row"
] |
ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40
|
https://github.com/fuelphp/common/blob/ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40/src/Table.php#L59-L73
|
229,486
|
fuelphp/common
|
src/Table.php
|
Table.constructCell
|
protected function constructCell($content = null, $attributes = array())
{
$cell = new Cell($content);
$cell->setAttributes($attributes);
return $cell;
}
|
php
|
protected function constructCell($content = null, $attributes = array())
{
$cell = new Cell($content);
$cell->setAttributes($attributes);
return $cell;
}
|
[
"protected",
"function",
"constructCell",
"(",
"$",
"content",
"=",
"null",
",",
"$",
"attributes",
"=",
"array",
"(",
")",
")",
"{",
"$",
"cell",
"=",
"new",
"Cell",
"(",
"$",
"content",
")",
";",
"$",
"cell",
"->",
"setAttributes",
"(",
"$",
"attributes",
")",
";",
"return",
"$",
"cell",
";",
"}"
] |
Creates a new Cell with the given content
@param mixed $content The content for the new Cell
@param array $attributes The attributes for the Cell
@return Cell
|
[
"Creates",
"a",
"new",
"Cell",
"with",
"the",
"given",
"content"
] |
ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40
|
https://github.com/fuelphp/common/blob/ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40/src/Table.php#L83-L89
|
229,487
|
fuelphp/common
|
src/Table.php
|
Table.createRow
|
public function createRow($type = EnumRowType::Body)
{
$this->currentRow = new Row;
$this->currentRow->setType($type);
return $this;
}
|
php
|
public function createRow($type = EnumRowType::Body)
{
$this->currentRow = new Row;
$this->currentRow->setType($type);
return $this;
}
|
[
"public",
"function",
"createRow",
"(",
"$",
"type",
"=",
"EnumRowType",
"::",
"Body",
")",
"{",
"$",
"this",
"->",
"currentRow",
"=",
"new",
"Row",
";",
"$",
"this",
"->",
"currentRow",
"->",
"setType",
"(",
"$",
"type",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Creates a new Row object and assigns it as the currently active row
@param EnumRowType $type The type of the new row, uses Body by default
@return $this
|
[
"Creates",
"a",
"new",
"Row",
"object",
"and",
"assigns",
"it",
"as",
"the",
"currently",
"active",
"row"
] |
ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40
|
https://github.com/fuelphp/common/blob/ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40/src/Table.php#L98-L104
|
229,488
|
fuelphp/common
|
src/Table.php
|
Table.addRow
|
public function addRow()
{
switch ( $this->currentRow->getType() )
{
case EnumRowType::Body:
$this->rows[] = $this->currentRow;
break;
case EnumRowType::Header:
$this->headerRows[] = $this->currentRow;
break;
case EnumRowType::Footer:
$this->footerRows[] = $this->currentRow;
break;
default:
throw new \InvalidArgumentException('Unknown row type');
}
$this->currentRow = null;
return $this;
}
|
php
|
public function addRow()
{
switch ( $this->currentRow->getType() )
{
case EnumRowType::Body:
$this->rows[] = $this->currentRow;
break;
case EnumRowType::Header:
$this->headerRows[] = $this->currentRow;
break;
case EnumRowType::Footer:
$this->footerRows[] = $this->currentRow;
break;
default:
throw new \InvalidArgumentException('Unknown row type');
}
$this->currentRow = null;
return $this;
}
|
[
"public",
"function",
"addRow",
"(",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"currentRow",
"->",
"getType",
"(",
")",
")",
"{",
"case",
"EnumRowType",
"::",
"Body",
":",
"$",
"this",
"->",
"rows",
"[",
"]",
"=",
"$",
"this",
"->",
"currentRow",
";",
"break",
";",
"case",
"EnumRowType",
"::",
"Header",
":",
"$",
"this",
"->",
"headerRows",
"[",
"]",
"=",
"$",
"this",
"->",
"currentRow",
";",
"break",
";",
"case",
"EnumRowType",
"::",
"Footer",
":",
"$",
"this",
"->",
"footerRows",
"[",
"]",
"=",
"$",
"this",
"->",
"currentRow",
";",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Unknown row type'",
")",
";",
"}",
"$",
"this",
"->",
"currentRow",
"=",
"null",
";",
"return",
"$",
"this",
";",
"}"
] |
Adds the Row that's currently being constructed to the list of finished Rows
@return $this
|
[
"Adds",
"the",
"Row",
"that",
"s",
"currently",
"being",
"constructed",
"to",
"the",
"list",
"of",
"finished",
"Rows"
] |
ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40
|
https://github.com/fuelphp/common/blob/ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40/src/Table.php#L111-L131
|
229,489
|
fecshop/yii2-fec
|
component/redisqueue/QueueController.php
|
QueueController.actionListen
|
public function actionListen($queueName = null, $queueObjectName = 'queue')
{
while (true) {
if ($this->timeout !==null) {
if ($this->timeout<time()) {
return true;
}
}
if (!$this->process($queueName, $queueObjectName)) {
sleep($this->sleep);
}
}
}
|
php
|
public function actionListen($queueName = null, $queueObjectName = 'queue')
{
while (true) {
if ($this->timeout !==null) {
if ($this->timeout<time()) {
return true;
}
}
if (!$this->process($queueName, $queueObjectName)) {
sleep($this->sleep);
}
}
}
|
[
"public",
"function",
"actionListen",
"(",
"$",
"queueName",
"=",
"null",
",",
"$",
"queueObjectName",
"=",
"'queue'",
")",
"{",
"while",
"(",
"true",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"timeout",
"!==",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"timeout",
"<",
"time",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"process",
"(",
"$",
"queueName",
",",
"$",
"queueObjectName",
")",
")",
"{",
"sleep",
"(",
"$",
"this",
"->",
"sleep",
")",
";",
"}",
"}",
"}"
] |
Continuously process jobs
@param string $queueName
@param string $queueObjectName
@throws \Exception
|
[
"Continuously",
"process",
"jobs"
] |
fda0e381f931bc503e493bec90185162109018e6
|
https://github.com/fecshop/yii2-fec/blob/fda0e381f931bc503e493bec90185162109018e6/component/redisqueue/QueueController.php#L33-L45
|
229,490
|
rougin/spark-plug
|
src/Instance.php
|
Instance.create
|
public static function create($path = '', array $server = array(), array $globals = array())
{
$globals = empty($globals) ? $GLOBALS : $globals;
$server = empty($server) ? $_SERVER : $server;
$sparkplug = new SparkPlug($globals, $server, $path);
return $sparkplug->getCodeIgniter();
}
|
php
|
public static function create($path = '', array $server = array(), array $globals = array())
{
$globals = empty($globals) ? $GLOBALS : $globals;
$server = empty($server) ? $_SERVER : $server;
$sparkplug = new SparkPlug($globals, $server, $path);
return $sparkplug->getCodeIgniter();
}
|
[
"public",
"static",
"function",
"create",
"(",
"$",
"path",
"=",
"''",
",",
"array",
"$",
"server",
"=",
"array",
"(",
")",
",",
"array",
"$",
"globals",
"=",
"array",
"(",
")",
")",
"{",
"$",
"globals",
"=",
"empty",
"(",
"$",
"globals",
")",
"?",
"$",
"GLOBALS",
":",
"$",
"globals",
";",
"$",
"server",
"=",
"empty",
"(",
"$",
"server",
")",
"?",
"$",
"_SERVER",
":",
"$",
"server",
";",
"$",
"sparkplug",
"=",
"new",
"SparkPlug",
"(",
"$",
"globals",
",",
"$",
"server",
",",
"$",
"path",
")",
";",
"return",
"$",
"sparkplug",
"->",
"getCodeIgniter",
"(",
")",
";",
"}"
] |
Creates an instance of CodeIgniter based on the application path.
@param string $path
@param array $server
@param array $globals
@return \CI_Controller
|
[
"Creates",
"an",
"instance",
"of",
"CodeIgniter",
"based",
"on",
"the",
"application",
"path",
"."
] |
a9189c80ddcbafb3b21ea3b491b664c8e860c584
|
https://github.com/rougin/spark-plug/blob/a9189c80ddcbafb3b21ea3b491b664c8e860c584/src/Instance.php#L23-L32
|
229,491
|
fuelphp/common
|
src/Num.php
|
Num.formatBytes
|
public function formatBytes($bytes = 0, $decimals = 0)
{
static $quant = array(
'TB' => 1099511627776, // pow( 1024, 4)
'GB' => 1073741824, // pow( 1024, 3)
'MB' => 1048576, // pow( 1024, 2)
'KB' => 1024, // pow( 1024, 1)
'B ' => 1, // pow( 1024, 0)
);
foreach ($quant as $unit => $mag )
{
if (doubleval($bytes) >= $mag)
{
return sprintf('%01.'.$decimals.'f', ($bytes / $mag)).' '.$unit;
}
}
return false;
}
|
php
|
public function formatBytes($bytes = 0, $decimals = 0)
{
static $quant = array(
'TB' => 1099511627776, // pow( 1024, 4)
'GB' => 1073741824, // pow( 1024, 3)
'MB' => 1048576, // pow( 1024, 2)
'KB' => 1024, // pow( 1024, 1)
'B ' => 1, // pow( 1024, 0)
);
foreach ($quant as $unit => $mag )
{
if (doubleval($bytes) >= $mag)
{
return sprintf('%01.'.$decimals.'f', ($bytes / $mag)).' '.$unit;
}
}
return false;
}
|
[
"public",
"function",
"formatBytes",
"(",
"$",
"bytes",
"=",
"0",
",",
"$",
"decimals",
"=",
"0",
")",
"{",
"static",
"$",
"quant",
"=",
"array",
"(",
"'TB'",
"=>",
"1099511627776",
",",
"// pow( 1024, 4)",
"'GB'",
"=>",
"1073741824",
",",
"// pow( 1024, 3)",
"'MB'",
"=>",
"1048576",
",",
"// pow( 1024, 2)",
"'KB'",
"=>",
"1024",
",",
"// pow( 1024, 1)",
"'B '",
"=>",
"1",
",",
"// pow( 1024, 0)",
")",
";",
"foreach",
"(",
"$",
"quant",
"as",
"$",
"unit",
"=>",
"$",
"mag",
")",
"{",
"if",
"(",
"doubleval",
"(",
"$",
"bytes",
")",
">=",
"$",
"mag",
")",
"{",
"return",
"sprintf",
"(",
"'%01.'",
".",
"$",
"decimals",
".",
"'f'",
",",
"(",
"$",
"bytes",
"/",
"$",
"mag",
")",
")",
".",
"' '",
".",
"$",
"unit",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Converts a number of bytes to a human readable number by taking the
number of that unit that the bytes will go into it. Supports TB value.
Note: Integers in PHP are limited to 32 bits, unless they are on 64 bit
architectures, then they have 64 bit size. If you need to place the
larger size then what the PHP integer type will hold, then use a string.
It will be converted to a double, which should always have 64 bit length.
@param int the byte number to format
@param int number of decimals
@return boolean|string formatted string, or false if formatting failed
@since 1.0.0
|
[
"Converts",
"a",
"number",
"of",
"bytes",
"to",
"a",
"human",
"readable",
"number",
"by",
"taking",
"the",
"number",
"of",
"that",
"unit",
"that",
"the",
"bytes",
"will",
"go",
"into",
"it",
".",
"Supports",
"TB",
"value",
"."
] |
ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40
|
https://github.com/fuelphp/common/blob/ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40/src/Num.php#L174-L193
|
229,492
|
fuelphp/common
|
src/Num.php
|
Num.format
|
public function format($string, $format)
{
if(empty($format) or empty($string))
{
return $string;
}
$result = '';
$fpos = 0;
$spos = 0;
while ((strlen($format) - 1) >= $fpos)
{
if (ctype_alnum(substr($format, $fpos, 1)))
{
$result .= substr($string, $spos, 1);
$spos++;
}
else
{
$result .= substr($format, $fpos, 1);
}
$fpos++;
}
return $result;
}
|
php
|
public function format($string, $format)
{
if(empty($format) or empty($string))
{
return $string;
}
$result = '';
$fpos = 0;
$spos = 0;
while ((strlen($format) - 1) >= $fpos)
{
if (ctype_alnum(substr($format, $fpos, 1)))
{
$result .= substr($string, $spos, 1);
$spos++;
}
else
{
$result .= substr($format, $fpos, 1);
}
$fpos++;
}
return $result;
}
|
[
"public",
"function",
"format",
"(",
"$",
"string",
",",
"$",
"format",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"format",
")",
"or",
"empty",
"(",
"$",
"string",
")",
")",
"{",
"return",
"$",
"string",
";",
"}",
"$",
"result",
"=",
"''",
";",
"$",
"fpos",
"=",
"0",
";",
"$",
"spos",
"=",
"0",
";",
"while",
"(",
"(",
"strlen",
"(",
"$",
"format",
")",
"-",
"1",
")",
">=",
"$",
"fpos",
")",
"{",
"if",
"(",
"ctype_alnum",
"(",
"substr",
"(",
"$",
"format",
",",
"$",
"fpos",
",",
"1",
")",
")",
")",
"{",
"$",
"result",
".=",
"substr",
"(",
"$",
"string",
",",
"$",
"spos",
",",
"1",
")",
";",
"$",
"spos",
"++",
";",
"}",
"else",
"{",
"$",
"result",
".=",
"substr",
"(",
"$",
"format",
",",
"$",
"fpos",
",",
"1",
")",
";",
"}",
"$",
"fpos",
"++",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Formats a number by injecting non-numeric characters in a specified
format into the string in the positions they appear in the format.
Usage:
<code>
$num = new \Fuel\Common\Num();
echo $num->format('1234567890', '(000) 000-0000'); // (123) 456-7890
echo $num->format('1234567890', '000.000.0000'); // 123.456.7890
</code>
@link http://snippets.symfony-project.org/snippet/157
@param string The string to format
@param string The format to apply
@return string Formatted number
@since 1.0.0
|
[
"Formats",
"a",
"number",
"by",
"injecting",
"non",
"-",
"numeric",
"characters",
"in",
"a",
"specified",
"format",
"into",
"the",
"string",
"in",
"the",
"positions",
"they",
"appear",
"in",
"the",
"format",
"."
] |
ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40
|
https://github.com/fuelphp/common/blob/ddb6b9ced050f1ae7b22326d9c8c32b0dabdbf40/src/Num.php#L251-L278
|
229,493
|
joomla-framework/datetime
|
src/Since/DateTimeSince.php
|
DateTimeSince.calc
|
private function calc(DateTime $base, DateTime $datetime = null, $detailLevel = 1)
{
$this->translator = $base->getTranslator();
$datetime = is_null($datetime) ? DateTime::now() : $datetime;
$detailLevel = intval($detailLevel);
$diff = $this->diffInUnits($base->diff($datetime, true), $detailLevel);
$item = 'just_now';
if (!$this->isNow($diff))
{
$item = $base->isAfter($datetime) ? 'in' : 'ago';
}
return array($item, $diff);
}
|
php
|
private function calc(DateTime $base, DateTime $datetime = null, $detailLevel = 1)
{
$this->translator = $base->getTranslator();
$datetime = is_null($datetime) ? DateTime::now() : $datetime;
$detailLevel = intval($detailLevel);
$diff = $this->diffInUnits($base->diff($datetime, true), $detailLevel);
$item = 'just_now';
if (!$this->isNow($diff))
{
$item = $base->isAfter($datetime) ? 'in' : 'ago';
}
return array($item, $diff);
}
|
[
"private",
"function",
"calc",
"(",
"DateTime",
"$",
"base",
",",
"DateTime",
"$",
"datetime",
"=",
"null",
",",
"$",
"detailLevel",
"=",
"1",
")",
"{",
"$",
"this",
"->",
"translator",
"=",
"$",
"base",
"->",
"getTranslator",
"(",
")",
";",
"$",
"datetime",
"=",
"is_null",
"(",
"$",
"datetime",
")",
"?",
"DateTime",
"::",
"now",
"(",
")",
":",
"$",
"datetime",
";",
"$",
"detailLevel",
"=",
"intval",
"(",
"$",
"detailLevel",
")",
";",
"$",
"diff",
"=",
"$",
"this",
"->",
"diffInUnits",
"(",
"$",
"base",
"->",
"diff",
"(",
"$",
"datetime",
",",
"true",
")",
",",
"$",
"detailLevel",
")",
";",
"$",
"item",
"=",
"'just_now'",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isNow",
"(",
"$",
"diff",
")",
")",
"{",
"$",
"item",
"=",
"$",
"base",
"->",
"isAfter",
"(",
"$",
"datetime",
")",
"?",
"'in'",
":",
"'ago'",
";",
"}",
"return",
"array",
"(",
"$",
"item",
",",
"$",
"diff",
")",
";",
"}"
] |
Calculates the difference between dates.
@param DateTime $base The base date.
@param DateTime $datetime The date to compare to. Default is null and this means that
the base date will be compared to the current time.
@param integer $detailLevel The level of detail to retrieve.
@return array
@since 2.0.0
|
[
"Calculates",
"the",
"difference",
"between",
"dates",
"."
] |
732fb60f054fa6aceaef93ff9a12d939d2a4797c
|
https://github.com/joomla-framework/datetime/blob/732fb60f054fa6aceaef93ff9a12d939d2a4797c/src/Since/DateTimeSince.php#L80-L97
|
229,494
|
joomla-framework/datetime
|
src/Since/DateTimeSince.php
|
DateTimeSince.diffInUnits
|
private function diffInUnits(DateInterval $interval, $detailLevel)
{
$units = array('y' => 'year', 'm' => 'month', 'd' => 'day',
'h' => 'hour', 'i' => 'minute', 's' => 'second'
);
$diff = array();
foreach ($units as $format => $unit)
{
$amount = $interval->format('%' . $format);
/** Adding support for weeks */
if ($unit == 'day' && $amount >= 7)
{
$weeks = floor($amount / 7);
$amount -= $weeks * 7;
$diff[] = array(
'amount' => $weeks,
'unit' => 'week'
);
$detailLevel--;
}
// Save only non-zero units of time
if ($amount > 0 && $detailLevel > 0)
{
$diff[] = array(
'amount' => $amount,
'unit' => $unit
);
$detailLevel--;
}
if ($detailLevel === 0)
{
break;
}
}
return $diff;
}
|
php
|
private function diffInUnits(DateInterval $interval, $detailLevel)
{
$units = array('y' => 'year', 'm' => 'month', 'd' => 'day',
'h' => 'hour', 'i' => 'minute', 's' => 'second'
);
$diff = array();
foreach ($units as $format => $unit)
{
$amount = $interval->format('%' . $format);
/** Adding support for weeks */
if ($unit == 'day' && $amount >= 7)
{
$weeks = floor($amount / 7);
$amount -= $weeks * 7;
$diff[] = array(
'amount' => $weeks,
'unit' => 'week'
);
$detailLevel--;
}
// Save only non-zero units of time
if ($amount > 0 && $detailLevel > 0)
{
$diff[] = array(
'amount' => $amount,
'unit' => $unit
);
$detailLevel--;
}
if ($detailLevel === 0)
{
break;
}
}
return $diff;
}
|
[
"private",
"function",
"diffInUnits",
"(",
"DateInterval",
"$",
"interval",
",",
"$",
"detailLevel",
")",
"{",
"$",
"units",
"=",
"array",
"(",
"'y'",
"=>",
"'year'",
",",
"'m'",
"=>",
"'month'",
",",
"'d'",
"=>",
"'day'",
",",
"'h'",
"=>",
"'hour'",
",",
"'i'",
"=>",
"'minute'",
",",
"'s'",
"=>",
"'second'",
")",
";",
"$",
"diff",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"units",
"as",
"$",
"format",
"=>",
"$",
"unit",
")",
"{",
"$",
"amount",
"=",
"$",
"interval",
"->",
"format",
"(",
"'%'",
".",
"$",
"format",
")",
";",
"/** Adding support for weeks */",
"if",
"(",
"$",
"unit",
"==",
"'day'",
"&&",
"$",
"amount",
">=",
"7",
")",
"{",
"$",
"weeks",
"=",
"floor",
"(",
"$",
"amount",
"/",
"7",
")",
";",
"$",
"amount",
"-=",
"$",
"weeks",
"*",
"7",
";",
"$",
"diff",
"[",
"]",
"=",
"array",
"(",
"'amount'",
"=>",
"$",
"weeks",
",",
"'unit'",
"=>",
"'week'",
")",
";",
"$",
"detailLevel",
"--",
";",
"}",
"// Save only non-zero units of time",
"if",
"(",
"$",
"amount",
">",
"0",
"&&",
"$",
"detailLevel",
">",
"0",
")",
"{",
"$",
"diff",
"[",
"]",
"=",
"array",
"(",
"'amount'",
"=>",
"$",
"amount",
",",
"'unit'",
"=>",
"$",
"unit",
")",
";",
"$",
"detailLevel",
"--",
";",
"}",
"if",
"(",
"$",
"detailLevel",
"===",
"0",
")",
"{",
"break",
";",
"}",
"}",
"return",
"$",
"diff",
";",
"}"
] |
Calculates the difference between dates for all units of a time.
@param DateInterval $interval The difference between dates.
@param integer $detailLevel The level of detail to retrieve.
@return array
@since 2.0.0
|
[
"Calculates",
"the",
"difference",
"between",
"dates",
"for",
"all",
"units",
"of",
"a",
"time",
"."
] |
732fb60f054fa6aceaef93ff9a12d939d2a4797c
|
https://github.com/joomla-framework/datetime/blob/732fb60f054fa6aceaef93ff9a12d939d2a4797c/src/Since/DateTimeSince.php#L109-L152
|
229,495
|
joomla-framework/datetime
|
src/Since/DateTimeSince.php
|
DateTimeSince.parseUnits
|
private function parseUnits($diff, $allowAlmost = false)
{
if (empty($diff))
{
return '';
}
$isAlmost = false;
$string = array();
foreach ($diff as $time)
{
if ($allowAlmost)
{
$isAlmost = $this->isAlmost($time);
}
$string[] = $this->translator->choice($time['unit'], $time['amount']);
}
$parsed = $string[0];
// Add 'and' separator
if (count($string) > 1)
{
$theLastOne = $string[count($string) - 1];
unset($string[count($string) - 1]);
$and = $this->translator->get('and');
$parsed = sprintf('%s %s %s', implode(', ', $string), $and, $theLastOne);
}
if ($isAlmost)
{
$parsed = $this->translator->get('almost', array('time' => $parsed));
}
return $parsed;
}
|
php
|
private function parseUnits($diff, $allowAlmost = false)
{
if (empty($diff))
{
return '';
}
$isAlmost = false;
$string = array();
foreach ($diff as $time)
{
if ($allowAlmost)
{
$isAlmost = $this->isAlmost($time);
}
$string[] = $this->translator->choice($time['unit'], $time['amount']);
}
$parsed = $string[0];
// Add 'and' separator
if (count($string) > 1)
{
$theLastOne = $string[count($string) - 1];
unset($string[count($string) - 1]);
$and = $this->translator->get('and');
$parsed = sprintf('%s %s %s', implode(', ', $string), $and, $theLastOne);
}
if ($isAlmost)
{
$parsed = $this->translator->get('almost', array('time' => $parsed));
}
return $parsed;
}
|
[
"private",
"function",
"parseUnits",
"(",
"$",
"diff",
",",
"$",
"allowAlmost",
"=",
"false",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"diff",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"isAlmost",
"=",
"false",
";",
"$",
"string",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"diff",
"as",
"$",
"time",
")",
"{",
"if",
"(",
"$",
"allowAlmost",
")",
"{",
"$",
"isAlmost",
"=",
"$",
"this",
"->",
"isAlmost",
"(",
"$",
"time",
")",
";",
"}",
"$",
"string",
"[",
"]",
"=",
"$",
"this",
"->",
"translator",
"->",
"choice",
"(",
"$",
"time",
"[",
"'unit'",
"]",
",",
"$",
"time",
"[",
"'amount'",
"]",
")",
";",
"}",
"$",
"parsed",
"=",
"$",
"string",
"[",
"0",
"]",
";",
"// Add 'and' separator",
"if",
"(",
"count",
"(",
"$",
"string",
")",
">",
"1",
")",
"{",
"$",
"theLastOne",
"=",
"$",
"string",
"[",
"count",
"(",
"$",
"string",
")",
"-",
"1",
"]",
";",
"unset",
"(",
"$",
"string",
"[",
"count",
"(",
"$",
"string",
")",
"-",
"1",
"]",
")",
";",
"$",
"and",
"=",
"$",
"this",
"->",
"translator",
"->",
"get",
"(",
"'and'",
")",
";",
"$",
"parsed",
"=",
"sprintf",
"(",
"'%s %s %s'",
",",
"implode",
"(",
"', '",
",",
"$",
"string",
")",
",",
"$",
"and",
",",
"$",
"theLastOne",
")",
";",
"}",
"if",
"(",
"$",
"isAlmost",
")",
"{",
"$",
"parsed",
"=",
"$",
"this",
"->",
"translator",
"->",
"get",
"(",
"'almost'",
",",
"array",
"(",
"'time'",
"=>",
"$",
"parsed",
")",
")",
";",
"}",
"return",
"$",
"parsed",
";",
"}"
] |
Parses an array of units into a string.
@param array $diff An array of differences for every unit of a time.
@param boolean $allowAlmost Do you want to get an almost difference?
@return string
@since 2.0.0
|
[
"Parses",
"an",
"array",
"of",
"units",
"into",
"a",
"string",
"."
] |
732fb60f054fa6aceaef93ff9a12d939d2a4797c
|
https://github.com/joomla-framework/datetime/blob/732fb60f054fa6aceaef93ff9a12d939d2a4797c/src/Since/DateTimeSince.php#L164-L202
|
229,496
|
hubzero/orcid-php
|
src/Profile.php
|
Profile.email
|
public function email()
{
$this->raw();
$email = null;
$person = $this->person();
if (isset($person->emails)) {
if (isset($person->emails->email)) {
if (is_array($person->emails->email) && isset($person->emails->email[0])) {
$email = $person->emails->email[0]->value;
}
}
}
return $email;
}
|
php
|
public function email()
{
$this->raw();
$email = null;
$person = $this->person();
if (isset($person->emails)) {
if (isset($person->emails->email)) {
if (is_array($person->emails->email) && isset($person->emails->email[0])) {
$email = $person->emails->email[0]->value;
}
}
}
return $email;
}
|
[
"public",
"function",
"email",
"(",
")",
"{",
"$",
"this",
"->",
"raw",
"(",
")",
";",
"$",
"email",
"=",
"null",
";",
"$",
"person",
"=",
"$",
"this",
"->",
"person",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"person",
"->",
"emails",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"person",
"->",
"emails",
"->",
"email",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"person",
"->",
"emails",
"->",
"email",
")",
"&&",
"isset",
"(",
"$",
"person",
"->",
"emails",
"->",
"email",
"[",
"0",
"]",
")",
")",
"{",
"$",
"email",
"=",
"$",
"person",
"->",
"emails",
"->",
"email",
"[",
"0",
"]",
"->",
"value",
";",
"}",
"}",
"}",
"return",
"$",
"email",
";",
"}"
] |
Grabs the users email if it's set and available
@return string|null
|
[
"Grabs",
"the",
"users",
"email",
"if",
"it",
"s",
"set",
"and",
"available"
] |
2b9a31bd3932af0e18d4b80029901c8ec84a0861
|
https://github.com/hubzero/orcid-php/blob/2b9a31bd3932af0e18d4b80029901c8ec84a0861/src/Profile.php#L81-L97
|
229,497
|
hubzero/orcid-php
|
src/Profile.php
|
Profile.fullName
|
public function fullName()
{
$this->raw();
$details = $this->person()->name;
// "given-names" is a required field on ORCID profiles.
// "family-name", however, may or may not be available.
// https://members.orcid.org/api/tutorial/reading-xml#names
return $details->{'given-names'}->value . ($details->{'family-name'} ? ' ' . $details->{'family-name'}->value : '');
}
|
php
|
public function fullName()
{
$this->raw();
$details = $this->person()->name;
// "given-names" is a required field on ORCID profiles.
// "family-name", however, may or may not be available.
// https://members.orcid.org/api/tutorial/reading-xml#names
return $details->{'given-names'}->value . ($details->{'family-name'} ? ' ' . $details->{'family-name'}->value : '');
}
|
[
"public",
"function",
"fullName",
"(",
")",
"{",
"$",
"this",
"->",
"raw",
"(",
")",
";",
"$",
"details",
"=",
"$",
"this",
"->",
"person",
"(",
")",
"->",
"name",
";",
"// \"given-names\" is a required field on ORCID profiles.",
"// \"family-name\", however, may or may not be available.",
"// https://members.orcid.org/api/tutorial/reading-xml#names",
"return",
"$",
"details",
"->",
"{",
"'given-names'",
"}",
"->",
"value",
".",
"(",
"$",
"details",
"->",
"{",
"'family-name'",
"}",
"?",
"' '",
".",
"$",
"details",
"->",
"{",
"'family-name'",
"}",
"->",
"value",
":",
"''",
")",
";",
"}"
] |
Grabs the raw name elements to create fullname
@return string
|
[
"Grabs",
"the",
"raw",
"name",
"elements",
"to",
"create",
"fullname"
] |
2b9a31bd3932af0e18d4b80029901c8ec84a0861
|
https://github.com/hubzero/orcid-php/blob/2b9a31bd3932af0e18d4b80029901c8ec84a0861/src/Profile.php#L104-L113
|
229,498
|
gridonic/hapi
|
src/Harvest/Model/Range.php
|
Range.today
|
public static function today($timeZone = null)
{
$now = null;
$before = null;
if ( is_null($timeZone) ) {
$now = new \DateTime();
$before = new \DateTime();
} else {
$now = new \DateTime( "now", new \DateTimeZone( $timeZone ) );
$before = new \DateTime( "now", new \DateTimeZone( $timeZone ) );
}
$range = new Range( $before, $now );
return $range;
}
|
php
|
public static function today($timeZone = null)
{
$now = null;
$before = null;
if ( is_null($timeZone) ) {
$now = new \DateTime();
$before = new \DateTime();
} else {
$now = new \DateTime( "now", new \DateTimeZone( $timeZone ) );
$before = new \DateTime( "now", new \DateTimeZone( $timeZone ) );
}
$range = new Range( $before, $now );
return $range;
}
|
[
"public",
"static",
"function",
"today",
"(",
"$",
"timeZone",
"=",
"null",
")",
"{",
"$",
"now",
"=",
"null",
";",
"$",
"before",
"=",
"null",
";",
"if",
"(",
"is_null",
"(",
"$",
"timeZone",
")",
")",
"{",
"$",
"now",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"$",
"before",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"}",
"else",
"{",
"$",
"now",
"=",
"new",
"\\",
"DateTime",
"(",
"\"now\"",
",",
"new",
"\\",
"DateTimeZone",
"(",
"$",
"timeZone",
")",
")",
";",
"$",
"before",
"=",
"new",
"\\",
"DateTime",
"(",
"\"now\"",
",",
"new",
"\\",
"DateTimeZone",
"(",
"$",
"timeZone",
")",
")",
";",
"}",
"$",
"range",
"=",
"new",
"Range",
"(",
"$",
"before",
",",
"$",
"now",
")",
";",
"return",
"$",
"range",
";",
"}"
] |
return Range object set to today
<code>
$range = Range::today( "EST" );
</code>
@param string $timeZone User Time Zone
@return Range
|
[
"return",
"Range",
"object",
"set",
"to",
"today"
] |
018c05b548428aa3e8d1040e0e2b1ec75b85adfe
|
https://github.com/gridonic/hapi/blob/018c05b548428aa3e8d1040e0e2b1ec75b85adfe/src/Harvest/Model/Range.php#L85-L99
|
229,499
|
gridonic/hapi
|
src/Harvest/Model/Range.php
|
Range.thisWeek
|
public static function thisWeek($timeZone = null, $startOfWeek = 0)
{
$now = null;
$before = null;
if ( is_null($timeZone) ) {
$now = new \DateTime();
$before = new \DateTime();
} else {
$now = new \DateTime( "now", new \DateTimeZone( $timeZone ) );
$before = new \DateTime( "now", new \DateTimeZone( $timeZone ) );
}
$dayOfWeek = (int) $now->format( "w" );
$offset = (($dayOfWeek - $startOfWeek ) + 7 ) % 7;
$before->modify( "-$offset day" );
$range = new Range( $before, $now );
return $range;
}
|
php
|
public static function thisWeek($timeZone = null, $startOfWeek = 0)
{
$now = null;
$before = null;
if ( is_null($timeZone) ) {
$now = new \DateTime();
$before = new \DateTime();
} else {
$now = new \DateTime( "now", new \DateTimeZone( $timeZone ) );
$before = new \DateTime( "now", new \DateTimeZone( $timeZone ) );
}
$dayOfWeek = (int) $now->format( "w" );
$offset = (($dayOfWeek - $startOfWeek ) + 7 ) % 7;
$before->modify( "-$offset day" );
$range = new Range( $before, $now );
return $range;
}
|
[
"public",
"static",
"function",
"thisWeek",
"(",
"$",
"timeZone",
"=",
"null",
",",
"$",
"startOfWeek",
"=",
"0",
")",
"{",
"$",
"now",
"=",
"null",
";",
"$",
"before",
"=",
"null",
";",
"if",
"(",
"is_null",
"(",
"$",
"timeZone",
")",
")",
"{",
"$",
"now",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"$",
"before",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"}",
"else",
"{",
"$",
"now",
"=",
"new",
"\\",
"DateTime",
"(",
"\"now\"",
",",
"new",
"\\",
"DateTimeZone",
"(",
"$",
"timeZone",
")",
")",
";",
"$",
"before",
"=",
"new",
"\\",
"DateTime",
"(",
"\"now\"",
",",
"new",
"\\",
"DateTimeZone",
"(",
"$",
"timeZone",
")",
")",
";",
"}",
"$",
"dayOfWeek",
"=",
"(",
"int",
")",
"$",
"now",
"->",
"format",
"(",
"\"w\"",
")",
";",
"$",
"offset",
"=",
"(",
"(",
"$",
"dayOfWeek",
"-",
"$",
"startOfWeek",
")",
"+",
"7",
")",
"%",
"7",
";",
"$",
"before",
"->",
"modify",
"(",
"\"-$offset day\"",
")",
";",
"$",
"range",
"=",
"new",
"Range",
"(",
"$",
"before",
",",
"$",
"now",
")",
";",
"return",
"$",
"range",
";",
"}"
] |
return Range object set to this week
<code>
$range = Range::thisWeek( "EST", Range::SUNDAY );
</code>
@param string $timeZone User Time Zone
@param int $startOfWeek Starting day of the week
@return Range
|
[
"return",
"Range",
"object",
"set",
"to",
"this",
"week"
] |
018c05b548428aa3e8d1040e0e2b1ec75b85adfe
|
https://github.com/gridonic/hapi/blob/018c05b548428aa3e8d1040e0e2b1ec75b85adfe/src/Harvest/Model/Range.php#L112-L129
|
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.