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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
231,400
|
fuzz-productions/magic-box
|
src/Filter.php
|
Filter.notEquals
|
protected static function notEquals($column, $filter, $query, $or = false)
{
$method = self::determineMethod('where', $or);
$query->$method($column, '!=', $filter);
}
|
php
|
protected static function notEquals($column, $filter, $query, $or = false)
{
$method = self::determineMethod('where', $or);
$query->$method($column, '!=', $filter);
}
|
[
"protected",
"static",
"function",
"notEquals",
"(",
"$",
"column",
",",
"$",
"filter",
",",
"$",
"query",
",",
"$",
"or",
"=",
"false",
")",
"{",
"$",
"method",
"=",
"self",
"::",
"determineMethod",
"(",
"'where'",
",",
"$",
"or",
")",
";",
"$",
"query",
"->",
"$",
"method",
"(",
"$",
"column",
",",
"'!='",
",",
"$",
"filter",
")",
";",
"}"
] |
Query for items with a value not equal to a filter.
Ex: users?filters[username]=!=common%20username
@param string $column
@param string $filter
@param \Illuminate\Database\Eloquent\Builder $query
@param bool $or
|
[
"Query",
"for",
"items",
"with",
"a",
"value",
"not",
"equal",
"to",
"a",
"filter",
"."
] |
996f8a5cf99177216cbab4a82a8ca79b87d05dfe
|
https://github.com/fuzz-productions/magic-box/blob/996f8a5cf99177216cbab4a82a8ca79b87d05dfe/src/Filter.php#L403-L407
|
231,401
|
fuzz-productions/magic-box
|
src/Filter.php
|
Filter.nullMethod
|
protected static function nullMethod($column, $filter, $query, $or = false)
{
if ($filter === 'NULL') {
$method = self::determineMethod('whereNull', $or);
$query->$method($column);
} else {
$method = self::determineMethod('whereNotNull', $or);
$query->$method($column);
}
}
|
php
|
protected static function nullMethod($column, $filter, $query, $or = false)
{
if ($filter === 'NULL') {
$method = self::determineMethod('whereNull', $or);
$query->$method($column);
} else {
$method = self::determineMethod('whereNotNull', $or);
$query->$method($column);
}
}
|
[
"protected",
"static",
"function",
"nullMethod",
"(",
"$",
"column",
",",
"$",
"filter",
",",
"$",
"query",
",",
"$",
"or",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"filter",
"===",
"'NULL'",
")",
"{",
"$",
"method",
"=",
"self",
"::",
"determineMethod",
"(",
"'whereNull'",
",",
"$",
"or",
")",
";",
"$",
"query",
"->",
"$",
"method",
"(",
"$",
"column",
")",
";",
"}",
"else",
"{",
"$",
"method",
"=",
"self",
"::",
"determineMethod",
"(",
"'whereNotNull'",
",",
"$",
"or",
")",
";",
"$",
"query",
"->",
"$",
"method",
"(",
"$",
"column",
")",
";",
"}",
"}"
] |
Query for items that are either null or not null.
Ex: users?filters[email]=NOT_NULL
Ex: users?filters[address]=NULL
@param string $column
@param string $filter
@param \Illuminate\Database\Eloquent\Builder $query
@param bool $or
|
[
"Query",
"for",
"items",
"that",
"are",
"either",
"null",
"or",
"not",
"null",
"."
] |
996f8a5cf99177216cbab4a82a8ca79b87d05dfe
|
https://github.com/fuzz-productions/magic-box/blob/996f8a5cf99177216cbab4a82a8ca79b87d05dfe/src/Filter.php#L420-L429
|
231,402
|
fuzz-productions/magic-box
|
src/Filter.php
|
Filter.in
|
protected static function in($column, $filter, $query, $or = false)
{
$method = self::determineMethod('whereIn', $or);
$query->$method($column, $filter);
}
|
php
|
protected static function in($column, $filter, $query, $or = false)
{
$method = self::determineMethod('whereIn', $or);
$query->$method($column, $filter);
}
|
[
"protected",
"static",
"function",
"in",
"(",
"$",
"column",
",",
"$",
"filter",
",",
"$",
"query",
",",
"$",
"or",
"=",
"false",
")",
"{",
"$",
"method",
"=",
"self",
"::",
"determineMethod",
"(",
"'whereIn'",
",",
"$",
"or",
")",
";",
"$",
"query",
"->",
"$",
"method",
"(",
"$",
"column",
",",
"$",
"filter",
")",
";",
"}"
] |
Query for items that are in a list.
Ex: users?filters[id]=[1,5,10]
@param string $column
@param string|array $filter
@param \Illuminate\Database\Eloquent\Builder $query
@param bool $or
|
[
"Query",
"for",
"items",
"that",
"are",
"in",
"a",
"list",
"."
] |
996f8a5cf99177216cbab4a82a8ca79b87d05dfe
|
https://github.com/fuzz-productions/magic-box/blob/996f8a5cf99177216cbab4a82a8ca79b87d05dfe/src/Filter.php#L441-L445
|
231,403
|
fuzz-productions/magic-box
|
src/Filter.php
|
Filter.notIn
|
protected static function notIn($column, $filter, $query, $or = false)
{
$method = self::determineMethod('whereNotIn', $or);
$query->$method($column, $filter);
}
|
php
|
protected static function notIn($column, $filter, $query, $or = false)
{
$method = self::determineMethod('whereNotIn', $or);
$query->$method($column, $filter);
}
|
[
"protected",
"static",
"function",
"notIn",
"(",
"$",
"column",
",",
"$",
"filter",
",",
"$",
"query",
",",
"$",
"or",
"=",
"false",
")",
"{",
"$",
"method",
"=",
"self",
"::",
"determineMethod",
"(",
"'whereNotIn'",
",",
"$",
"or",
")",
";",
"$",
"query",
"->",
"$",
"method",
"(",
"$",
"column",
",",
"$",
"filter",
")",
";",
"}"
] |
Query for items that are not in a list.
Ex: users?filters[id]=![1,5,10]
@param string $column
@param string|array $filter
@param \Illuminate\Database\Eloquent\Builder $query
@param bool $or
|
[
"Query",
"for",
"items",
"that",
"are",
"not",
"in",
"a",
"list",
"."
] |
996f8a5cf99177216cbab4a82a8ca79b87d05dfe
|
https://github.com/fuzz-productions/magic-box/blob/996f8a5cf99177216cbab4a82a8ca79b87d05dfe/src/Filter.php#L457-L461
|
231,404
|
fuzz-productions/magic-box
|
src/Filter.php
|
Filter.cleanAndValidateFilter
|
private static function cleanAndValidateFilter($token, $filter)
{
$filter_should_be_scalar = self::shouldBeScalar($token);
// Format the filter, cutting off the trailing ']' if appropriate
$filter = $filter_should_be_scalar ? explode(',', substr($filter, strlen($token))) :
explode(',', substr($filter, strlen($token), -1));
if ($filter_should_be_scalar) {
if (count($filter) > 1) {
return false;
}
// Set to first index if should be scalar
$filter = $filter[0];
}
return $filter;
}
|
php
|
private static function cleanAndValidateFilter($token, $filter)
{
$filter_should_be_scalar = self::shouldBeScalar($token);
// Format the filter, cutting off the trailing ']' if appropriate
$filter = $filter_should_be_scalar ? explode(',', substr($filter, strlen($token))) :
explode(',', substr($filter, strlen($token), -1));
if ($filter_should_be_scalar) {
if (count($filter) > 1) {
return false;
}
// Set to first index if should be scalar
$filter = $filter[0];
}
return $filter;
}
|
[
"private",
"static",
"function",
"cleanAndValidateFilter",
"(",
"$",
"token",
",",
"$",
"filter",
")",
"{",
"$",
"filter_should_be_scalar",
"=",
"self",
"::",
"shouldBeScalar",
"(",
"$",
"token",
")",
";",
"// Format the filter, cutting off the trailing ']' if appropriate",
"$",
"filter",
"=",
"$",
"filter_should_be_scalar",
"?",
"explode",
"(",
"','",
",",
"substr",
"(",
"$",
"filter",
",",
"strlen",
"(",
"$",
"token",
")",
")",
")",
":",
"explode",
"(",
"','",
",",
"substr",
"(",
"$",
"filter",
",",
"strlen",
"(",
"$",
"token",
")",
",",
"-",
"1",
")",
")",
";",
"if",
"(",
"$",
"filter_should_be_scalar",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"filter",
")",
">",
"1",
")",
"{",
"return",
"false",
";",
"}",
"// Set to first index if should be scalar",
"$",
"filter",
"=",
"$",
"filter",
"[",
"0",
"]",
";",
"}",
"return",
"$",
"filter",
";",
"}"
] |
Parse a filter string and confirm that it has a scalar value if it should.
@param string $token
@param string $filter
@return array|bool
|
[
"Parse",
"a",
"filter",
"string",
"and",
"confirm",
"that",
"it",
"has",
"a",
"scalar",
"value",
"if",
"it",
"should",
"."
] |
996f8a5cf99177216cbab4a82a8ca79b87d05dfe
|
https://github.com/fuzz-productions/magic-box/blob/996f8a5cf99177216cbab4a82a8ca79b87d05dfe/src/Filter.php#L505-L523
|
231,405
|
fuzz-productions/magic-box
|
src/Middleware/RepositoryMiddleware.php
|
RepositoryMiddleware.buildRepository
|
public function buildRepository(Request $request): EloquentRepository
{
$input = [];
/** @var \Illuminate\Routing\Route $route */
$route = $request->route();
// Resolve the model class if possible. And setup the repository.
/** @var \Illuminate\Database\Eloquent\Model $model_class */
$model_class = resolve(ModelResolver::class)->resolveModelClass($route);
// Look for /{model-class}/{id} RESTful requests
$parameters = $route->parametersWithoutNulls();
if (! empty($parameters)) {
$id = reset($parameters);
$input = compact('id');
}
// If the method is not GET lets get the input from everywhere.
// @TODO hmm, need to verify what happens on DELETE and PATCH.
if ($request->method() !== 'GET') {
$input += $request->all();
}
// Resolve an eloquent repository bound to our standardized route parameter
$repository = resolve(Repository::class);
$repository->setModelClass($model_class)
->setFilters((array) $request->get('filters'))
->setSortOrder((array) $request->get('sort'))
->setGroupBy((array) $request->get('group'))
->setEagerLoads((array) $request->get('include'))
->setAggregate((array) $request->get('aggregate'))
->setDepthRestriction(config('magic-box.eager_load_depth'))
->setInput($input);
return $repository;
}
|
php
|
public function buildRepository(Request $request): EloquentRepository
{
$input = [];
/** @var \Illuminate\Routing\Route $route */
$route = $request->route();
// Resolve the model class if possible. And setup the repository.
/** @var \Illuminate\Database\Eloquent\Model $model_class */
$model_class = resolve(ModelResolver::class)->resolveModelClass($route);
// Look for /{model-class}/{id} RESTful requests
$parameters = $route->parametersWithoutNulls();
if (! empty($parameters)) {
$id = reset($parameters);
$input = compact('id');
}
// If the method is not GET lets get the input from everywhere.
// @TODO hmm, need to verify what happens on DELETE and PATCH.
if ($request->method() !== 'GET') {
$input += $request->all();
}
// Resolve an eloquent repository bound to our standardized route parameter
$repository = resolve(Repository::class);
$repository->setModelClass($model_class)
->setFilters((array) $request->get('filters'))
->setSortOrder((array) $request->get('sort'))
->setGroupBy((array) $request->get('group'))
->setEagerLoads((array) $request->get('include'))
->setAggregate((array) $request->get('aggregate'))
->setDepthRestriction(config('magic-box.eager_load_depth'))
->setInput($input);
return $repository;
}
|
[
"public",
"function",
"buildRepository",
"(",
"Request",
"$",
"request",
")",
":",
"EloquentRepository",
"{",
"$",
"input",
"=",
"[",
"]",
";",
"/** @var \\Illuminate\\Routing\\Route $route */",
"$",
"route",
"=",
"$",
"request",
"->",
"route",
"(",
")",
";",
"// Resolve the model class if possible. And setup the repository.",
"/** @var \\Illuminate\\Database\\Eloquent\\Model $model_class */",
"$",
"model_class",
"=",
"resolve",
"(",
"ModelResolver",
"::",
"class",
")",
"->",
"resolveModelClass",
"(",
"$",
"route",
")",
";",
"// Look for /{model-class}/{id} RESTful requests",
"$",
"parameters",
"=",
"$",
"route",
"->",
"parametersWithoutNulls",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"parameters",
")",
")",
"{",
"$",
"id",
"=",
"reset",
"(",
"$",
"parameters",
")",
";",
"$",
"input",
"=",
"compact",
"(",
"'id'",
")",
";",
"}",
"// If the method is not GET lets get the input from everywhere.",
"// @TODO hmm, need to verify what happens on DELETE and PATCH.",
"if",
"(",
"$",
"request",
"->",
"method",
"(",
")",
"!==",
"'GET'",
")",
"{",
"$",
"input",
"+=",
"$",
"request",
"->",
"all",
"(",
")",
";",
"}",
"// Resolve an eloquent repository bound to our standardized route parameter",
"$",
"repository",
"=",
"resolve",
"(",
"Repository",
"::",
"class",
")",
";",
"$",
"repository",
"->",
"setModelClass",
"(",
"$",
"model_class",
")",
"->",
"setFilters",
"(",
"(",
"array",
")",
"$",
"request",
"->",
"get",
"(",
"'filters'",
")",
")",
"->",
"setSortOrder",
"(",
"(",
"array",
")",
"$",
"request",
"->",
"get",
"(",
"'sort'",
")",
")",
"->",
"setGroupBy",
"(",
"(",
"array",
")",
"$",
"request",
"->",
"get",
"(",
"'group'",
")",
")",
"->",
"setEagerLoads",
"(",
"(",
"array",
")",
"$",
"request",
"->",
"get",
"(",
"'include'",
")",
")",
"->",
"setAggregate",
"(",
"(",
"array",
")",
"$",
"request",
"->",
"get",
"(",
"'aggregate'",
")",
")",
"->",
"setDepthRestriction",
"(",
"config",
"(",
"'magic-box.eager_load_depth'",
")",
")",
"->",
"setInput",
"(",
"$",
"input",
")",
";",
"return",
"$",
"repository",
";",
"}"
] |
Build a repository based on inbound request data.
@param \Illuminate\Http\Request $request
@return \Fuzz\MagicBox\EloquentRepository
|
[
"Build",
"a",
"repository",
"based",
"on",
"inbound",
"request",
"data",
"."
] |
996f8a5cf99177216cbab4a82a8ca79b87d05dfe
|
https://github.com/fuzz-productions/magic-box/blob/996f8a5cf99177216cbab4a82a8ca79b87d05dfe/src/Middleware/RepositoryMiddleware.php#L32-L68
|
231,406
|
niklongstone/regex-reverse
|
src/RegRev/Metacharacter/CharacterHandler.php
|
CharacterHandler.setSuccessor
|
final public function setSuccessor(CharacterHandler $handler)
{
$this->successor = $handler;
$this->successor->setPrevious($this);
}
|
php
|
final public function setSuccessor(CharacterHandler $handler)
{
$this->successor = $handler;
$this->successor->setPrevious($this);
}
|
[
"final",
"public",
"function",
"setSuccessor",
"(",
"CharacterHandler",
"$",
"handler",
")",
"{",
"$",
"this",
"->",
"successor",
"=",
"$",
"handler",
";",
"$",
"this",
"->",
"successor",
"->",
"setPrevious",
"(",
"$",
"this",
")",
";",
"}"
] |
Sets chain successor.
@param CharacterHandler $handler
|
[
"Sets",
"chain",
"successor",
"."
] |
a93bb266fbc0621094a5d1ad2583b8a54999ea25
|
https://github.com/niklongstone/regex-reverse/blob/a93bb266fbc0621094a5d1ad2583b8a54999ea25/src/RegRev/Metacharacter/CharacterHandler.php#L116-L120
|
231,407
|
niklongstone/regex-reverse
|
src/RegRev/Metacharacter/CharacterHandler.php
|
CharacterHandler.getResult
|
final public function getResult($result = '')
{
$result.= $this->generate();
if ($this->successor !== null) {
return $this->successor->getResult($result);
}
return $result;
}
|
php
|
final public function getResult($result = '')
{
$result.= $this->generate();
if ($this->successor !== null) {
return $this->successor->getResult($result);
}
return $result;
}
|
[
"final",
"public",
"function",
"getResult",
"(",
"$",
"result",
"=",
"''",
")",
"{",
"$",
"result",
".=",
"$",
"this",
"->",
"generate",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"successor",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"successor",
"->",
"getResult",
"(",
"$",
"result",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Gets the result.
@param string $result
@return string
|
[
"Gets",
"the",
"result",
"."
] |
a93bb266fbc0621094a5d1ad2583b8a54999ea25
|
https://github.com/niklongstone/regex-reverse/blob/a93bb266fbc0621094a5d1ad2583b8a54999ea25/src/RegRev/Metacharacter/CharacterHandler.php#L149-L157
|
231,408
|
PaymentSuite/paymentsuite
|
src/PaymentSuite/RedsysBundle/Services/RedsysManager.php
|
RedsysManager.processPayment
|
public function processPayment()
{
$redsysMethod = $this
->redsysMethodFactory
->create();
/**
* At this point, order must be created given a cart, and placed in PaymentBridge.
*
* So, $this->paymentBridge->getOrder() must return an object
*/
$this
->paymentEventDispatcher
->notifyPaymentOrderLoad(
$this->paymentBridge,
$redsysMethod
);
/**
* Order Not found Exception must be thrown just here.
*/
if (!$this->paymentBridge->getOrder()) {
throw new PaymentOrderNotFoundException();
}
/**
* Order exists right here.
*/
$this
->paymentEventDispatcher
->notifyPaymentOrderCreated(
$this->paymentBridge,
$redsysMethod
);
return $this
->redsysFormTypeBuilder
->buildForm();
}
|
php
|
public function processPayment()
{
$redsysMethod = $this
->redsysMethodFactory
->create();
/**
* At this point, order must be created given a cart, and placed in PaymentBridge.
*
* So, $this->paymentBridge->getOrder() must return an object
*/
$this
->paymentEventDispatcher
->notifyPaymentOrderLoad(
$this->paymentBridge,
$redsysMethod
);
/**
* Order Not found Exception must be thrown just here.
*/
if (!$this->paymentBridge->getOrder()) {
throw new PaymentOrderNotFoundException();
}
/**
* Order exists right here.
*/
$this
->paymentEventDispatcher
->notifyPaymentOrderCreated(
$this->paymentBridge,
$redsysMethod
);
return $this
->redsysFormTypeBuilder
->buildForm();
}
|
[
"public",
"function",
"processPayment",
"(",
")",
"{",
"$",
"redsysMethod",
"=",
"$",
"this",
"->",
"redsysMethodFactory",
"->",
"create",
"(",
")",
";",
"/**\n * At this point, order must be created given a cart, and placed in PaymentBridge.\n *\n * So, $this->paymentBridge->getOrder() must return an object\n */",
"$",
"this",
"->",
"paymentEventDispatcher",
"->",
"notifyPaymentOrderLoad",
"(",
"$",
"this",
"->",
"paymentBridge",
",",
"$",
"redsysMethod",
")",
";",
"/**\n * Order Not found Exception must be thrown just here.\n */",
"if",
"(",
"!",
"$",
"this",
"->",
"paymentBridge",
"->",
"getOrder",
"(",
")",
")",
"{",
"throw",
"new",
"PaymentOrderNotFoundException",
"(",
")",
";",
"}",
"/**\n * Order exists right here.\n */",
"$",
"this",
"->",
"paymentEventDispatcher",
"->",
"notifyPaymentOrderCreated",
"(",
"$",
"this",
"->",
"paymentBridge",
",",
"$",
"redsysMethod",
")",
";",
"return",
"$",
"this",
"->",
"redsysFormTypeBuilder",
"->",
"buildForm",
"(",
")",
";",
"}"
] |
Creates form view for Redsys payment.
@return \Symfony\Component\Form\FormView
@throws PaymentOrderNotFoundException
|
[
"Creates",
"form",
"view",
"for",
"Redsys",
"payment",
"."
] |
8ae57df57fa07aff7e59701a0b3c83c504095b92
|
https://github.com/PaymentSuite/paymentsuite/blob/8ae57df57fa07aff7e59701a0b3c83c504095b92/src/PaymentSuite/RedsysBundle/Services/RedsysManager.php#L96-L134
|
231,409
|
PaymentSuite/paymentsuite
|
src/PaymentSuite/RedsysBundle/Services/RedsysManager.php
|
RedsysManager.processResult
|
public function processResult(array $parameters)
{
$this->checkResultParameters($parameters);
$redsysMethod = new RedsysMethod();
$dsSignature = $parameters['Ds_Signature'];
$dsResponse = $parameters['Ds_Response'];
$dsAmount = $parameters['Ds_Amount'];
$dsOrder = $parameters['Ds_Order'];
$dsMerchantCode = $parameters['Ds_MerchantCode'];
$dsCurrency = $parameters['Ds_Currency'];
$dsSecret = $this->secretKey;
$dsDate = $parameters['Ds_Date'];
$dsHour = $parameters['Ds_Hour'];
$dsSecurePayment = $parameters['Ds_SecurePayment'];
$dsCardCountry = $parameters['Ds_Card_Country'];
$dsAuthorisationCode = $parameters['Ds_AuthorisationCode'];
$dsConsumerLanguage = $parameters['Ds_ConsumerLanguage'];
$dsCardType = array_key_exists('Ds_Card_Type', $parameters)
? $parameters['Ds_Card_Type']
: '';
if ($dsSignature != $this
->expectedSignature(
$dsAmount,
$dsOrder,
$dsMerchantCode,
$dsCurrency,
$dsResponse,
$dsSecret
)
) {
throw new InvalidSignatureException();
}
/**
* Adding transaction information to PaymentMethod.
*
* This information is only available in PaymentOrderSuccess event
*/
$redsysMethod
->setDsResponse($dsResponse)
->setDsAuthorisationCode($dsAuthorisationCode)
->setDsCardCountry($dsCardCountry)
->setDsCardType($dsCardType)
->setDsConsumerLanguage($dsConsumerLanguage)
->setDsDate($dsDate)
->setDsHour($dsHour)
->setDsSecurePayment($dsSecurePayment)
->setDsOrder($dsOrder);
/**
* Payment paid done.
*
* Paid process has ended ( No matters result )
*/
$this
->paymentEventDispatcher
->notifyPaymentOrderDone(
$this->paymentBridge,
$redsysMethod
);
/**
* when a transaction is successful, $Ds_Response has a
* value between 0 and 99.
*/
if (!$this->transactionSuccessful($dsResponse)) {
/**
* Payment paid failed.
*
* Paid process has ended failed
*/
$this
->paymentEventDispatcher
->notifyPaymentOrderFail(
$this->paymentBridge,
$redsysMethod
);
throw new PaymentException();
}
/**
* Payment paid successfully.
*
* Paid process has ended successfully
*/
$this
->paymentEventDispatcher
->notifyPaymentOrderSuccess(
$this->paymentBridge,
$redsysMethod
);
return $this;
}
|
php
|
public function processResult(array $parameters)
{
$this->checkResultParameters($parameters);
$redsysMethod = new RedsysMethod();
$dsSignature = $parameters['Ds_Signature'];
$dsResponse = $parameters['Ds_Response'];
$dsAmount = $parameters['Ds_Amount'];
$dsOrder = $parameters['Ds_Order'];
$dsMerchantCode = $parameters['Ds_MerchantCode'];
$dsCurrency = $parameters['Ds_Currency'];
$dsSecret = $this->secretKey;
$dsDate = $parameters['Ds_Date'];
$dsHour = $parameters['Ds_Hour'];
$dsSecurePayment = $parameters['Ds_SecurePayment'];
$dsCardCountry = $parameters['Ds_Card_Country'];
$dsAuthorisationCode = $parameters['Ds_AuthorisationCode'];
$dsConsumerLanguage = $parameters['Ds_ConsumerLanguage'];
$dsCardType = array_key_exists('Ds_Card_Type', $parameters)
? $parameters['Ds_Card_Type']
: '';
if ($dsSignature != $this
->expectedSignature(
$dsAmount,
$dsOrder,
$dsMerchantCode,
$dsCurrency,
$dsResponse,
$dsSecret
)
) {
throw new InvalidSignatureException();
}
/**
* Adding transaction information to PaymentMethod.
*
* This information is only available in PaymentOrderSuccess event
*/
$redsysMethod
->setDsResponse($dsResponse)
->setDsAuthorisationCode($dsAuthorisationCode)
->setDsCardCountry($dsCardCountry)
->setDsCardType($dsCardType)
->setDsConsumerLanguage($dsConsumerLanguage)
->setDsDate($dsDate)
->setDsHour($dsHour)
->setDsSecurePayment($dsSecurePayment)
->setDsOrder($dsOrder);
/**
* Payment paid done.
*
* Paid process has ended ( No matters result )
*/
$this
->paymentEventDispatcher
->notifyPaymentOrderDone(
$this->paymentBridge,
$redsysMethod
);
/**
* when a transaction is successful, $Ds_Response has a
* value between 0 and 99.
*/
if (!$this->transactionSuccessful($dsResponse)) {
/**
* Payment paid failed.
*
* Paid process has ended failed
*/
$this
->paymentEventDispatcher
->notifyPaymentOrderFail(
$this->paymentBridge,
$redsysMethod
);
throw new PaymentException();
}
/**
* Payment paid successfully.
*
* Paid process has ended successfully
*/
$this
->paymentEventDispatcher
->notifyPaymentOrderSuccess(
$this->paymentBridge,
$redsysMethod
);
return $this;
}
|
[
"public",
"function",
"processResult",
"(",
"array",
"$",
"parameters",
")",
"{",
"$",
"this",
"->",
"checkResultParameters",
"(",
"$",
"parameters",
")",
";",
"$",
"redsysMethod",
"=",
"new",
"RedsysMethod",
"(",
")",
";",
"$",
"dsSignature",
"=",
"$",
"parameters",
"[",
"'Ds_Signature'",
"]",
";",
"$",
"dsResponse",
"=",
"$",
"parameters",
"[",
"'Ds_Response'",
"]",
";",
"$",
"dsAmount",
"=",
"$",
"parameters",
"[",
"'Ds_Amount'",
"]",
";",
"$",
"dsOrder",
"=",
"$",
"parameters",
"[",
"'Ds_Order'",
"]",
";",
"$",
"dsMerchantCode",
"=",
"$",
"parameters",
"[",
"'Ds_MerchantCode'",
"]",
";",
"$",
"dsCurrency",
"=",
"$",
"parameters",
"[",
"'Ds_Currency'",
"]",
";",
"$",
"dsSecret",
"=",
"$",
"this",
"->",
"secretKey",
";",
"$",
"dsDate",
"=",
"$",
"parameters",
"[",
"'Ds_Date'",
"]",
";",
"$",
"dsHour",
"=",
"$",
"parameters",
"[",
"'Ds_Hour'",
"]",
";",
"$",
"dsSecurePayment",
"=",
"$",
"parameters",
"[",
"'Ds_SecurePayment'",
"]",
";",
"$",
"dsCardCountry",
"=",
"$",
"parameters",
"[",
"'Ds_Card_Country'",
"]",
";",
"$",
"dsAuthorisationCode",
"=",
"$",
"parameters",
"[",
"'Ds_AuthorisationCode'",
"]",
";",
"$",
"dsConsumerLanguage",
"=",
"$",
"parameters",
"[",
"'Ds_ConsumerLanguage'",
"]",
";",
"$",
"dsCardType",
"=",
"array_key_exists",
"(",
"'Ds_Card_Type'",
",",
"$",
"parameters",
")",
"?",
"$",
"parameters",
"[",
"'Ds_Card_Type'",
"]",
":",
"''",
";",
"if",
"(",
"$",
"dsSignature",
"!=",
"$",
"this",
"->",
"expectedSignature",
"(",
"$",
"dsAmount",
",",
"$",
"dsOrder",
",",
"$",
"dsMerchantCode",
",",
"$",
"dsCurrency",
",",
"$",
"dsResponse",
",",
"$",
"dsSecret",
")",
")",
"{",
"throw",
"new",
"InvalidSignatureException",
"(",
")",
";",
"}",
"/**\n * Adding transaction information to PaymentMethod.\n *\n * This information is only available in PaymentOrderSuccess event\n */",
"$",
"redsysMethod",
"->",
"setDsResponse",
"(",
"$",
"dsResponse",
")",
"->",
"setDsAuthorisationCode",
"(",
"$",
"dsAuthorisationCode",
")",
"->",
"setDsCardCountry",
"(",
"$",
"dsCardCountry",
")",
"->",
"setDsCardType",
"(",
"$",
"dsCardType",
")",
"->",
"setDsConsumerLanguage",
"(",
"$",
"dsConsumerLanguage",
")",
"->",
"setDsDate",
"(",
"$",
"dsDate",
")",
"->",
"setDsHour",
"(",
"$",
"dsHour",
")",
"->",
"setDsSecurePayment",
"(",
"$",
"dsSecurePayment",
")",
"->",
"setDsOrder",
"(",
"$",
"dsOrder",
")",
";",
"/**\n * Payment paid done.\n *\n * Paid process has ended ( No matters result )\n */",
"$",
"this",
"->",
"paymentEventDispatcher",
"->",
"notifyPaymentOrderDone",
"(",
"$",
"this",
"->",
"paymentBridge",
",",
"$",
"redsysMethod",
")",
";",
"/**\n * when a transaction is successful, $Ds_Response has a\n * value between 0 and 99.\n */",
"if",
"(",
"!",
"$",
"this",
"->",
"transactionSuccessful",
"(",
"$",
"dsResponse",
")",
")",
"{",
"/**\n * Payment paid failed.\n *\n * Paid process has ended failed\n */",
"$",
"this",
"->",
"paymentEventDispatcher",
"->",
"notifyPaymentOrderFail",
"(",
"$",
"this",
"->",
"paymentBridge",
",",
"$",
"redsysMethod",
")",
";",
"throw",
"new",
"PaymentException",
"(",
")",
";",
"}",
"/**\n * Payment paid successfully.\n *\n * Paid process has ended successfully\n */",
"$",
"this",
"->",
"paymentEventDispatcher",
"->",
"notifyPaymentOrderSuccess",
"(",
"$",
"this",
"->",
"paymentBridge",
",",
"$",
"redsysMethod",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Processes the POST request sent by Redsys.
@param array $parameters Array with response parameters
@return RedsysManager Self object
@throws InvalidSignatureException Invalid signature
@throws ParameterNotReceivedException Invalid parameters
@throws PaymentException Payment exception
|
[
"Processes",
"the",
"POST",
"request",
"sent",
"by",
"Redsys",
"."
] |
8ae57df57fa07aff7e59701a0b3c83c504095b92
|
https://github.com/PaymentSuite/paymentsuite/blob/8ae57df57fa07aff7e59701a0b3c83c504095b92/src/PaymentSuite/RedsysBundle/Services/RedsysManager.php#L147-L245
|
231,410
|
PaymentSuite/paymentsuite
|
src/PaymentSuite/RedsysBundle/Services/RedsysManager.php
|
RedsysManager.expectedSignature
|
private function expectedSignature(
$amount,
$order,
$merchantCode,
$currency,
$response,
$secret
) {
return strtoupper(sha1(implode('', [
$amount,
$order,
$merchantCode,
$currency,
$response,
$secret,
])));
}
|
php
|
private function expectedSignature(
$amount,
$order,
$merchantCode,
$currency,
$response,
$secret
) {
return strtoupper(sha1(implode('', [
$amount,
$order,
$merchantCode,
$currency,
$response,
$secret,
])));
}
|
[
"private",
"function",
"expectedSignature",
"(",
"$",
"amount",
",",
"$",
"order",
",",
"$",
"merchantCode",
",",
"$",
"currency",
",",
"$",
"response",
",",
"$",
"secret",
")",
"{",
"return",
"strtoupper",
"(",
"sha1",
"(",
"implode",
"(",
"''",
",",
"[",
"$",
"amount",
",",
"$",
"order",
",",
"$",
"merchantCode",
",",
"$",
"currency",
",",
"$",
"response",
",",
"$",
"secret",
",",
"]",
")",
")",
")",
";",
"}"
] |
Returns the expected signature.
@param string $amount Amount
@param string $order Order
@param string $merchantCode Merchant Code
@param string $currency Currency
@param string $response Response code
@param string $secret Secret
@return string Signature
|
[
"Returns",
"the",
"expected",
"signature",
"."
] |
8ae57df57fa07aff7e59701a0b3c83c504095b92
|
https://github.com/PaymentSuite/paymentsuite/blob/8ae57df57fa07aff7e59701a0b3c83c504095b92/src/PaymentSuite/RedsysBundle/Services/RedsysManager.php#L276-L292
|
231,411
|
machour/yii2-swagger-api
|
ApiGenerator.php
|
ApiGenerator.parseModels
|
private function parseModels($definitions)
{
$ret = [];
foreach ($definitions as $definition)
{
$ret[$definition] = $this->parseModel($definition);
}
return $ret;
}
|
php
|
private function parseModels($definitions)
{
$ret = [];
foreach ($definitions as $definition)
{
$ret[$definition] = $this->parseModel($definition);
}
return $ret;
}
|
[
"private",
"function",
"parseModels",
"(",
"$",
"definitions",
")",
"{",
"$",
"ret",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"definitions",
"as",
"$",
"definition",
")",
"{",
"$",
"ret",
"[",
"$",
"definition",
"]",
"=",
"$",
"this",
"->",
"parseModel",
"(",
"$",
"definition",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] |
Returns the models definition
@param array $definitions
@return array
@throws Exception
|
[
"Returns",
"the",
"models",
"definition"
] |
577d9877f196a0a94b06d5623a0ea66cf329409b
|
https://github.com/machour/yii2-swagger-api/blob/577d9877f196a0a94b06d5623a0ea66cf329409b/ApiGenerator.php#L399-L407
|
231,412
|
machour/yii2-swagger-api
|
ApiGenerator.php
|
ApiGenerator.parseModel
|
private function parseModel($definition, $xml = true) {
$model = strpos($definition, '\\') === false ?
$this->modelsNamespace . '\\' . $definition :
$definition;
if (!is_subclass_of($model, ApiModel::class)) {
throw new Exception("The model definition for $model was not found", 501);
}
$ret = [
'type' => 'object',
];
$class = new ReflectionClass($model);
$properties = $this->parseProperties($class);
foreach ($properties as $name => &$property) {
if (isset($property['required'])) {
unset($property['required']);
if (!isset($ret['required'])) {
$ret['required'] = [];
}
$ret['required'][] = $name;
}
}
$ret['properties'] = $properties;
if ($xml) {
$ret['xml'] = ['name' => $definition];
}
return $ret;
}
|
php
|
private function parseModel($definition, $xml = true) {
$model = strpos($definition, '\\') === false ?
$this->modelsNamespace . '\\' . $definition :
$definition;
if (!is_subclass_of($model, ApiModel::class)) {
throw new Exception("The model definition for $model was not found", 501);
}
$ret = [
'type' => 'object',
];
$class = new ReflectionClass($model);
$properties = $this->parseProperties($class);
foreach ($properties as $name => &$property) {
if (isset($property['required'])) {
unset($property['required']);
if (!isset($ret['required'])) {
$ret['required'] = [];
}
$ret['required'][] = $name;
}
}
$ret['properties'] = $properties;
if ($xml) {
$ret['xml'] = ['name' => $definition];
}
return $ret;
}
|
[
"private",
"function",
"parseModel",
"(",
"$",
"definition",
",",
"$",
"xml",
"=",
"true",
")",
"{",
"$",
"model",
"=",
"strpos",
"(",
"$",
"definition",
",",
"'\\\\'",
")",
"===",
"false",
"?",
"$",
"this",
"->",
"modelsNamespace",
".",
"'\\\\'",
".",
"$",
"definition",
":",
"$",
"definition",
";",
"if",
"(",
"!",
"is_subclass_of",
"(",
"$",
"model",
",",
"ApiModel",
"::",
"class",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"The model definition for $model was not found\"",
",",
"501",
")",
";",
"}",
"$",
"ret",
"=",
"[",
"'type'",
"=>",
"'object'",
",",
"]",
";",
"$",
"class",
"=",
"new",
"ReflectionClass",
"(",
"$",
"model",
")",
";",
"$",
"properties",
"=",
"$",
"this",
"->",
"parseProperties",
"(",
"$",
"class",
")",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"name",
"=>",
"&",
"$",
"property",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"property",
"[",
"'required'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"property",
"[",
"'required'",
"]",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"ret",
"[",
"'required'",
"]",
")",
")",
"{",
"$",
"ret",
"[",
"'required'",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"ret",
"[",
"'required'",
"]",
"[",
"]",
"=",
"$",
"name",
";",
"}",
"}",
"$",
"ret",
"[",
"'properties'",
"]",
"=",
"$",
"properties",
";",
"if",
"(",
"$",
"xml",
")",
"{",
"$",
"ret",
"[",
"'xml'",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"definition",
"]",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] |
Returns a model definition
@param $definition
@param bool $xml
@return array
@throws Exception
|
[
"Returns",
"a",
"model",
"definition"
] |
577d9877f196a0a94b06d5623a0ea66cf329409b
|
https://github.com/machour/yii2-swagger-api/blob/577d9877f196a0a94b06d5623a0ea66cf329409b/ApiGenerator.php#L417-L449
|
231,413
|
machour/yii2-swagger-api
|
ApiGenerator.php
|
ApiGenerator.parseProperties
|
private function parseProperties($class)
{
$ret = [];
$defaults = $class->getDefaultProperties();
foreach ($class->getProperties() as $property) {
$tags = self::parseDocCommentTags($property->getDocComment());
list($type, $description) = $this->tokenize($tags[self::T_VAR], 2);
$p = [];
if (strpos($type, '[]') > 0) {
$type = str_replace('[]', '', $type);
$p['type'] = 'array';
$p['xml'] = ['name' => preg_replace('!s$!', '', $property->name), 'wrapped' => true];
if ($this->isDefinedType($type)) {
$p['items'] = ['$ref' => $this->getDefinition($type)];
} else {
$p['items'] = ['type' => $type];
}
} elseif ($this->isDefinedType($type)) {
$p['$ref'] = $this->getDefinition($type);
} else {
$p['type'] = $type;
$enums = isset($tags[self::T_ENUM]) ? $this->mixedToArray($tags[self::T_ENUM]) : [];
foreach ($enums as $enum) {
$p['enum'] = $this->tokenize($enum);
}
}
if (isset($tags[self::T_FORMAT])) {
$p['format'] = $tags[self::T_FORMAT];
}
if (isset($tags[self::T_EXAMPLE])) {
$p['example'] = $tags[self::T_EXAMPLE];
}
if (isset($tags[self::T_REQUIRED])) {
$p['required'] = true;
}
if (!empty($description)) {
$p['description'] = $description;
}
if (!is_null($defaults[$property->name])) {
$p['default'] = $defaults[$property->name];
}
$ret[$property->name] = $p;
}
return $ret;
}
|
php
|
private function parseProperties($class)
{
$ret = [];
$defaults = $class->getDefaultProperties();
foreach ($class->getProperties() as $property) {
$tags = self::parseDocCommentTags($property->getDocComment());
list($type, $description) = $this->tokenize($tags[self::T_VAR], 2);
$p = [];
if (strpos($type, '[]') > 0) {
$type = str_replace('[]', '', $type);
$p['type'] = 'array';
$p['xml'] = ['name' => preg_replace('!s$!', '', $property->name), 'wrapped' => true];
if ($this->isDefinedType($type)) {
$p['items'] = ['$ref' => $this->getDefinition($type)];
} else {
$p['items'] = ['type' => $type];
}
} elseif ($this->isDefinedType($type)) {
$p['$ref'] = $this->getDefinition($type);
} else {
$p['type'] = $type;
$enums = isset($tags[self::T_ENUM]) ? $this->mixedToArray($tags[self::T_ENUM]) : [];
foreach ($enums as $enum) {
$p['enum'] = $this->tokenize($enum);
}
}
if (isset($tags[self::T_FORMAT])) {
$p['format'] = $tags[self::T_FORMAT];
}
if (isset($tags[self::T_EXAMPLE])) {
$p['example'] = $tags[self::T_EXAMPLE];
}
if (isset($tags[self::T_REQUIRED])) {
$p['required'] = true;
}
if (!empty($description)) {
$p['description'] = $description;
}
if (!is_null($defaults[$property->name])) {
$p['default'] = $defaults[$property->name];
}
$ret[$property->name] = $p;
}
return $ret;
}
|
[
"private",
"function",
"parseProperties",
"(",
"$",
"class",
")",
"{",
"$",
"ret",
"=",
"[",
"]",
";",
"$",
"defaults",
"=",
"$",
"class",
"->",
"getDefaultProperties",
"(",
")",
";",
"foreach",
"(",
"$",
"class",
"->",
"getProperties",
"(",
")",
"as",
"$",
"property",
")",
"{",
"$",
"tags",
"=",
"self",
"::",
"parseDocCommentTags",
"(",
"$",
"property",
"->",
"getDocComment",
"(",
")",
")",
";",
"list",
"(",
"$",
"type",
",",
"$",
"description",
")",
"=",
"$",
"this",
"->",
"tokenize",
"(",
"$",
"tags",
"[",
"self",
"::",
"T_VAR",
"]",
",",
"2",
")",
";",
"$",
"p",
"=",
"[",
"]",
";",
"if",
"(",
"strpos",
"(",
"$",
"type",
",",
"'[]'",
")",
">",
"0",
")",
"{",
"$",
"type",
"=",
"str_replace",
"(",
"'[]'",
",",
"''",
",",
"$",
"type",
")",
";",
"$",
"p",
"[",
"'type'",
"]",
"=",
"'array'",
";",
"$",
"p",
"[",
"'xml'",
"]",
"=",
"[",
"'name'",
"=>",
"preg_replace",
"(",
"'!s$!'",
",",
"''",
",",
"$",
"property",
"->",
"name",
")",
",",
"'wrapped'",
"=>",
"true",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"isDefinedType",
"(",
"$",
"type",
")",
")",
"{",
"$",
"p",
"[",
"'items'",
"]",
"=",
"[",
"'$ref'",
"=>",
"$",
"this",
"->",
"getDefinition",
"(",
"$",
"type",
")",
"]",
";",
"}",
"else",
"{",
"$",
"p",
"[",
"'items'",
"]",
"=",
"[",
"'type'",
"=>",
"$",
"type",
"]",
";",
"}",
"}",
"elseif",
"(",
"$",
"this",
"->",
"isDefinedType",
"(",
"$",
"type",
")",
")",
"{",
"$",
"p",
"[",
"'$ref'",
"]",
"=",
"$",
"this",
"->",
"getDefinition",
"(",
"$",
"type",
")",
";",
"}",
"else",
"{",
"$",
"p",
"[",
"'type'",
"]",
"=",
"$",
"type",
";",
"$",
"enums",
"=",
"isset",
"(",
"$",
"tags",
"[",
"self",
"::",
"T_ENUM",
"]",
")",
"?",
"$",
"this",
"->",
"mixedToArray",
"(",
"$",
"tags",
"[",
"self",
"::",
"T_ENUM",
"]",
")",
":",
"[",
"]",
";",
"foreach",
"(",
"$",
"enums",
"as",
"$",
"enum",
")",
"{",
"$",
"p",
"[",
"'enum'",
"]",
"=",
"$",
"this",
"->",
"tokenize",
"(",
"$",
"enum",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"tags",
"[",
"self",
"::",
"T_FORMAT",
"]",
")",
")",
"{",
"$",
"p",
"[",
"'format'",
"]",
"=",
"$",
"tags",
"[",
"self",
"::",
"T_FORMAT",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"tags",
"[",
"self",
"::",
"T_EXAMPLE",
"]",
")",
")",
"{",
"$",
"p",
"[",
"'example'",
"]",
"=",
"$",
"tags",
"[",
"self",
"::",
"T_EXAMPLE",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"tags",
"[",
"self",
"::",
"T_REQUIRED",
"]",
")",
")",
"{",
"$",
"p",
"[",
"'required'",
"]",
"=",
"true",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"description",
")",
")",
"{",
"$",
"p",
"[",
"'description'",
"]",
"=",
"$",
"description",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"defaults",
"[",
"$",
"property",
"->",
"name",
"]",
")",
")",
"{",
"$",
"p",
"[",
"'default'",
"]",
"=",
"$",
"defaults",
"[",
"$",
"property",
"->",
"name",
"]",
";",
"}",
"$",
"ret",
"[",
"$",
"property",
"->",
"name",
"]",
"=",
"$",
"p",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] |
Returns the class properties
Used for models
@param ReflectionClass $class
@return array
|
[
"Returns",
"the",
"class",
"properties"
] |
577d9877f196a0a94b06d5623a0ea66cf329409b
|
https://github.com/machour/yii2-swagger-api/blob/577d9877f196a0a94b06d5623a0ea66cf329409b/ApiGenerator.php#L459-L512
|
231,414
|
machour/yii2-swagger-api
|
ApiGenerator.php
|
ApiGenerator.parseMethods
|
public function parseMethods($class, $produces)
{
$ret = [];
foreach ($class->getMethods() as $method) {
$def = $this->parseMethod($method, $produces);
if ($def) {
$methodDoc = $this->fetchDocComment($method);
$tags = self::parseDocCommentTags($methodDoc);
if (!isset($tags[self::T_PATH])) {
continue;
}
if (!isset($ret[$tags[self::T_PATH]])) {
$ret[$tags[self::T_PATH]] = [];
}
$ret[$tags[self::T_PATH]][$tags[self::T_METHOD]] = $def;
}
}
return $ret;
}
|
php
|
public function parseMethods($class, $produces)
{
$ret = [];
foreach ($class->getMethods() as $method) {
$def = $this->parseMethod($method, $produces);
if ($def) {
$methodDoc = $this->fetchDocComment($method);
$tags = self::parseDocCommentTags($methodDoc);
if (!isset($tags[self::T_PATH])) {
continue;
}
if (!isset($ret[$tags[self::T_PATH]])) {
$ret[$tags[self::T_PATH]] = [];
}
$ret[$tags[self::T_PATH]][$tags[self::T_METHOD]] = $def;
}
}
return $ret;
}
|
[
"public",
"function",
"parseMethods",
"(",
"$",
"class",
",",
"$",
"produces",
")",
"{",
"$",
"ret",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"class",
"->",
"getMethods",
"(",
")",
"as",
"$",
"method",
")",
"{",
"$",
"def",
"=",
"$",
"this",
"->",
"parseMethod",
"(",
"$",
"method",
",",
"$",
"produces",
")",
";",
"if",
"(",
"$",
"def",
")",
"{",
"$",
"methodDoc",
"=",
"$",
"this",
"->",
"fetchDocComment",
"(",
"$",
"method",
")",
";",
"$",
"tags",
"=",
"self",
"::",
"parseDocCommentTags",
"(",
"$",
"methodDoc",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"tags",
"[",
"self",
"::",
"T_PATH",
"]",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"ret",
"[",
"$",
"tags",
"[",
"self",
"::",
"T_PATH",
"]",
"]",
")",
")",
"{",
"$",
"ret",
"[",
"$",
"tags",
"[",
"self",
"::",
"T_PATH",
"]",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"ret",
"[",
"$",
"tags",
"[",
"self",
"::",
"T_PATH",
"]",
"]",
"[",
"$",
"tags",
"[",
"self",
"::",
"T_METHOD",
"]",
"]",
"=",
"$",
"def",
";",
"}",
"}",
"return",
"$",
"ret",
";",
"}"
] |
Returns the methods definition
@param ReflectionClass $class
@param array $produces The class level @produces tags
@return array
@throws Exception
|
[
"Returns",
"the",
"methods",
"definition"
] |
577d9877f196a0a94b06d5623a0ea66cf329409b
|
https://github.com/machour/yii2-swagger-api/blob/577d9877f196a0a94b06d5623a0ea66cf329409b/ApiGenerator.php#L522-L544
|
231,415
|
machour/yii2-swagger-api
|
ApiGenerator.php
|
ApiGenerator.haveParameter
|
private function haveParameter($method, $parameter)
{
foreach ($method->getParameters() as $param) {
if ($param->name == $parameter) {
return true;
}
}
return false;
}
|
php
|
private function haveParameter($method, $parameter)
{
foreach ($method->getParameters() as $param) {
if ($param->name == $parameter) {
return true;
}
}
return false;
}
|
[
"private",
"function",
"haveParameter",
"(",
"$",
"method",
",",
"$",
"parameter",
")",
"{",
"foreach",
"(",
"$",
"method",
"->",
"getParameters",
"(",
")",
"as",
"$",
"param",
")",
"{",
"if",
"(",
"$",
"param",
"->",
"name",
"==",
"$",
"parameter",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Tells if the given method have the given parameter in its signature
@param ReflectionMethod $method The method to inspect
@param string $parameter The parameter name
@return bool Returns TRUE if the parameter is present in the signature, FALSE otherwise
|
[
"Tells",
"if",
"the",
"given",
"method",
"have",
"the",
"given",
"parameter",
"in",
"its",
"signature"
] |
577d9877f196a0a94b06d5623a0ea66cf329409b
|
https://github.com/machour/yii2-swagger-api/blob/577d9877f196a0a94b06d5623a0ea66cf329409b/ApiGenerator.php#L698-L706
|
231,416
|
machour/yii2-swagger-api
|
ApiGenerator.php
|
ApiGenerator.tokenize
|
private function tokenize($input, $limit = -1)
{
$chunks = preg_split('!\s+!', $input, $limit);
if ($limit !== -1 && count($chunks) != $limit) {
$chunks += array_fill(count($chunks), $limit, '');
}
return $chunks;
}
|
php
|
private function tokenize($input, $limit = -1)
{
$chunks = preg_split('!\s+!', $input, $limit);
if ($limit !== -1 && count($chunks) != $limit) {
$chunks += array_fill(count($chunks), $limit, '');
}
return $chunks;
}
|
[
"private",
"function",
"tokenize",
"(",
"$",
"input",
",",
"$",
"limit",
"=",
"-",
"1",
")",
"{",
"$",
"chunks",
"=",
"preg_split",
"(",
"'!\\s+!'",
",",
"$",
"input",
",",
"$",
"limit",
")",
";",
"if",
"(",
"$",
"limit",
"!==",
"-",
"1",
"&&",
"count",
"(",
"$",
"chunks",
")",
"!=",
"$",
"limit",
")",
"{",
"$",
"chunks",
"+=",
"array_fill",
"(",
"count",
"(",
"$",
"chunks",
")",
",",
"$",
"limit",
",",
"''",
")",
";",
"}",
"return",
"$",
"chunks",
";",
"}"
] |
Tokenize an input string
@param string $input The string to be tokenized
@param int $limit The number of tokens to generate
@return array
|
[
"Tokenize",
"an",
"input",
"string"
] |
577d9877f196a0a94b06d5623a0ea66cf329409b
|
https://github.com/machour/yii2-swagger-api/blob/577d9877f196a0a94b06d5623a0ea66cf329409b/ApiGenerator.php#L871-L878
|
231,417
|
machour/yii2-swagger-api
|
ApiGenerator.php
|
ApiGenerator.parseDocCommentDetail
|
public static function parseDocCommentDetail($block)
{
$comment = strtr(trim(preg_replace('/^\s*\**( |\t)?/m', '', trim($block, '/'))), "\r", '');
if (preg_match('/^\s*@\w+/m', $comment, $matches, PREG_OFFSET_CAPTURE)) {
$comment = trim(substr($comment, 0, $matches[0][1]));
}
if (empty($comment)) {
return '';
}
$summary = self::parseDocCommentSummary($block);
$pos = strpos($comment, $summary);
if ($pos !== false) {
$comment = trim(substr_replace($comment, '', $pos, strlen($summary)));
}
return $comment;
}
|
php
|
public static function parseDocCommentDetail($block)
{
$comment = strtr(trim(preg_replace('/^\s*\**( |\t)?/m', '', trim($block, '/'))), "\r", '');
if (preg_match('/^\s*@\w+/m', $comment, $matches, PREG_OFFSET_CAPTURE)) {
$comment = trim(substr($comment, 0, $matches[0][1]));
}
if (empty($comment)) {
return '';
}
$summary = self::parseDocCommentSummary($block);
$pos = strpos($comment, $summary);
if ($pos !== false) {
$comment = trim(substr_replace($comment, '', $pos, strlen($summary)));
}
return $comment;
}
|
[
"public",
"static",
"function",
"parseDocCommentDetail",
"(",
"$",
"block",
")",
"{",
"$",
"comment",
"=",
"strtr",
"(",
"trim",
"(",
"preg_replace",
"(",
"'/^\\s*\\**( |\\t)?/m'",
",",
"''",
",",
"trim",
"(",
"$",
"block",
",",
"'/'",
")",
")",
")",
",",
"\"\\r\"",
",",
"''",
")",
";",
"if",
"(",
"preg_match",
"(",
"'/^\\s*@\\w+/m'",
",",
"$",
"comment",
",",
"$",
"matches",
",",
"PREG_OFFSET_CAPTURE",
")",
")",
"{",
"$",
"comment",
"=",
"trim",
"(",
"substr",
"(",
"$",
"comment",
",",
"0",
",",
"$",
"matches",
"[",
"0",
"]",
"[",
"1",
"]",
")",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"comment",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"summary",
"=",
"self",
"::",
"parseDocCommentSummary",
"(",
"$",
"block",
")",
";",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"comment",
",",
"$",
"summary",
")",
";",
"if",
"(",
"$",
"pos",
"!==",
"false",
")",
"{",
"$",
"comment",
"=",
"trim",
"(",
"substr_replace",
"(",
"$",
"comment",
",",
"''",
",",
"$",
"pos",
",",
"strlen",
"(",
"$",
"summary",
")",
")",
")",
";",
"}",
"return",
"$",
"comment",
";",
"}"
] |
Returns full description from the doc block.
@param string $block
@return string
|
[
"Returns",
"full",
"description",
"from",
"the",
"doc",
"block",
"."
] |
577d9877f196a0a94b06d5623a0ea66cf329409b
|
https://github.com/machour/yii2-swagger-api/blob/577d9877f196a0a94b06d5623a0ea66cf329409b/ApiGenerator.php#L901-L919
|
231,418
|
fuzz-productions/magic-box
|
src/Utility/ChecksRelations.php
|
ChecksRelations.isRelation
|
protected function isRelation(Model $instance, $key, $model_class)
{
// Not a relation method
if (! method_exists($instance, $key)) {
return false;
}
$relation = null;
$safe_instance = new $model_class;
// Get method, dirty and imperfect
$reflected_method = (new \ReflectionMethod($safe_instance, $key))->__toString();
$supported_relations = [
BelongsTo::class,
HasOne::class,
HasMany::class,
BelongsToMany::class,
];
// Find which, if any, of the supported relations are present in the reflected string
foreach ($supported_relations as $supported_relation) {
if (strpos($reflected_method, $supported_relation) !== false) {
$relation = $instance->$key();
break;
}
}
// If the ReflectionMethod guess fails, try to guess based on the concrete return type of a safe instance
// of the model
if (is_null($relation) && ($safe_instance->$key() instanceof Relation)) {
// If the method returns a Relation, we can safely call it
$relation = $instance->$key();
}
return is_null($relation) ? false : $relation;
}
|
php
|
protected function isRelation(Model $instance, $key, $model_class)
{
// Not a relation method
if (! method_exists($instance, $key)) {
return false;
}
$relation = null;
$safe_instance = new $model_class;
// Get method, dirty and imperfect
$reflected_method = (new \ReflectionMethod($safe_instance, $key))->__toString();
$supported_relations = [
BelongsTo::class,
HasOne::class,
HasMany::class,
BelongsToMany::class,
];
// Find which, if any, of the supported relations are present in the reflected string
foreach ($supported_relations as $supported_relation) {
if (strpos($reflected_method, $supported_relation) !== false) {
$relation = $instance->$key();
break;
}
}
// If the ReflectionMethod guess fails, try to guess based on the concrete return type of a safe instance
// of the model
if (is_null($relation) && ($safe_instance->$key() instanceof Relation)) {
// If the method returns a Relation, we can safely call it
$relation = $instance->$key();
}
return is_null($relation) ? false : $relation;
}
|
[
"protected",
"function",
"isRelation",
"(",
"Model",
"$",
"instance",
",",
"$",
"key",
",",
"$",
"model_class",
")",
"{",
"// Not a relation method",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"instance",
",",
"$",
"key",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"relation",
"=",
"null",
";",
"$",
"safe_instance",
"=",
"new",
"$",
"model_class",
";",
"// Get method, dirty and imperfect",
"$",
"reflected_method",
"=",
"(",
"new",
"\\",
"ReflectionMethod",
"(",
"$",
"safe_instance",
",",
"$",
"key",
")",
")",
"->",
"__toString",
"(",
")",
";",
"$",
"supported_relations",
"=",
"[",
"BelongsTo",
"::",
"class",
",",
"HasOne",
"::",
"class",
",",
"HasMany",
"::",
"class",
",",
"BelongsToMany",
"::",
"class",
",",
"]",
";",
"// Find which, if any, of the supported relations are present in the reflected string",
"foreach",
"(",
"$",
"supported_relations",
"as",
"$",
"supported_relation",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"reflected_method",
",",
"$",
"supported_relation",
")",
"!==",
"false",
")",
"{",
"$",
"relation",
"=",
"$",
"instance",
"->",
"$",
"key",
"(",
")",
";",
"break",
";",
"}",
"}",
"// If the ReflectionMethod guess fails, try to guess based on the concrete return type of a safe instance",
"// of the model",
"if",
"(",
"is_null",
"(",
"$",
"relation",
")",
"&&",
"(",
"$",
"safe_instance",
"->",
"$",
"key",
"(",
")",
"instanceof",
"Relation",
")",
")",
"{",
"// If the method returns a Relation, we can safely call it",
"$",
"relation",
"=",
"$",
"instance",
"->",
"$",
"key",
"(",
")",
";",
"}",
"return",
"is_null",
"(",
"$",
"relation",
")",
"?",
"false",
":",
"$",
"relation",
";",
"}"
] |
Safely determine if the specified key name is a relation on the model instance
@todo use PHP7 return type reflection solution as well
@param \Illuminate\Database\Eloquent\Model $instance
@param string $key
@param string $model_class
@return \Illuminate\Database\Eloquent\Relations\Relation|bool
|
[
"Safely",
"determine",
"if",
"the",
"specified",
"key",
"name",
"is",
"a",
"relation",
"on",
"the",
"model",
"instance"
] |
996f8a5cf99177216cbab4a82a8ca79b87d05dfe
|
https://github.com/fuzz-productions/magic-box/blob/996f8a5cf99177216cbab4a82a8ca79b87d05dfe/src/Utility/ChecksRelations.php#L24-L60
|
231,419
|
davin-bao/workflow
|
src/DavinBao/Workflow/WorkflowNode.php
|
WorkFlowNode.attachUser
|
public function attachUser( $user )
{
if( is_object($user))
$user = $user->getKey();
if( is_array($user))
$user = $user['id'];
$this->users()->attach( $user );
}
|
php
|
public function attachUser( $user )
{
if( is_object($user))
$user = $user->getKey();
if( is_array($user))
$user = $user['id'];
$this->users()->attach( $user );
}
|
[
"public",
"function",
"attachUser",
"(",
"$",
"user",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"user",
")",
")",
"$",
"user",
"=",
"$",
"user",
"->",
"getKey",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"user",
")",
")",
"$",
"user",
"=",
"$",
"user",
"[",
"'id'",
"]",
";",
"$",
"this",
"->",
"users",
"(",
")",
"->",
"attach",
"(",
"$",
"user",
")",
";",
"}"
] |
Attach user to current role
@param $user
|
[
"Attach",
"user",
"to",
"current",
"role"
] |
8af8b33ef63e455a2a5a1cdf6ac7bc154d590488
|
https://github.com/davin-bao/workflow/blob/8af8b33ef63e455a2a5a1cdf6ac7bc154d590488/src/DavinBao/Workflow/WorkflowNode.php#L121-L130
|
231,420
|
davin-bao/workflow
|
src/DavinBao/Workflow/WorkflowNode.php
|
WorkFlowNode.detachUser
|
public function detachUser( $user )
{
if( is_object($user))
$user = $user->getKey();
if( is_array($user))
$user = $user['id'];
$this->users()->detach( $user );
}
|
php
|
public function detachUser( $user )
{
if( is_object($user))
$user = $user->getKey();
if( is_array($user))
$user = $user['id'];
$this->users()->detach( $user );
}
|
[
"public",
"function",
"detachUser",
"(",
"$",
"user",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"user",
")",
")",
"$",
"user",
"=",
"$",
"user",
"->",
"getKey",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"user",
")",
")",
"$",
"user",
"=",
"$",
"user",
"[",
"'id'",
"]",
";",
"$",
"this",
"->",
"users",
"(",
")",
"->",
"detach",
"(",
"$",
"user",
")",
";",
"}"
] |
Detach permission form current user
@param $user
|
[
"Detach",
"permission",
"form",
"current",
"user"
] |
8af8b33ef63e455a2a5a1cdf6ac7bc154d590488
|
https://github.com/davin-bao/workflow/blob/8af8b33ef63e455a2a5a1cdf6ac7bc154d590488/src/DavinBao/Workflow/WorkflowNode.php#L136-L145
|
231,421
|
PaymentSuite/paymentsuite
|
src/PaymentSuite/PaypalWebCheckoutBundle/Controller/ProcessController.php
|
ProcessController.processAction
|
public function processAction(Request $request)
{
$orderId = $request
->query
->get('order_id');
try {
$this
->paypalWebCheckoutManager
->processPaypalIPNMessage(
$orderId, $request
->request
->all()
);
$this
->paymentLogger
->log(
'info',
'Paypal payment success. Order number #' . $orderId,
'paypal-web-checkout'
);
} catch (ParameterNotReceivedException $exception) {
$this
->paymentLogger
->log(
'error',
'Parameter ' . $exception->getMessage() . ' not received. Order number #' . $orderId,
'paypal-web-checkout'
);
} catch (PaymentException $exception) {
$this
->paymentLogger
->log(
'error',
'Paypal payment error "' . $exception->getMessage() . '". Order number #' . $orderId,
'paypal-web-checkout'
);
}
return new Response('OK', 200);
}
|
php
|
public function processAction(Request $request)
{
$orderId = $request
->query
->get('order_id');
try {
$this
->paypalWebCheckoutManager
->processPaypalIPNMessage(
$orderId, $request
->request
->all()
);
$this
->paymentLogger
->log(
'info',
'Paypal payment success. Order number #' . $orderId,
'paypal-web-checkout'
);
} catch (ParameterNotReceivedException $exception) {
$this
->paymentLogger
->log(
'error',
'Parameter ' . $exception->getMessage() . ' not received. Order number #' . $orderId,
'paypal-web-checkout'
);
} catch (PaymentException $exception) {
$this
->paymentLogger
->log(
'error',
'Paypal payment error "' . $exception->getMessage() . '". Order number #' . $orderId,
'paypal-web-checkout'
);
}
return new Response('OK', 200);
}
|
[
"public",
"function",
"processAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"orderId",
"=",
"$",
"request",
"->",
"query",
"->",
"get",
"(",
"'order_id'",
")",
";",
"try",
"{",
"$",
"this",
"->",
"paypalWebCheckoutManager",
"->",
"processPaypalIPNMessage",
"(",
"$",
"orderId",
",",
"$",
"request",
"->",
"request",
"->",
"all",
"(",
")",
")",
";",
"$",
"this",
"->",
"paymentLogger",
"->",
"log",
"(",
"'info'",
",",
"'Paypal payment success. Order number #'",
".",
"$",
"orderId",
",",
"'paypal-web-checkout'",
")",
";",
"}",
"catch",
"(",
"ParameterNotReceivedException",
"$",
"exception",
")",
"{",
"$",
"this",
"->",
"paymentLogger",
"->",
"log",
"(",
"'error'",
",",
"'Parameter '",
".",
"$",
"exception",
"->",
"getMessage",
"(",
")",
".",
"' not received. Order number #'",
".",
"$",
"orderId",
",",
"'paypal-web-checkout'",
")",
";",
"}",
"catch",
"(",
"PaymentException",
"$",
"exception",
")",
"{",
"$",
"this",
"->",
"paymentLogger",
"->",
"log",
"(",
"'error'",
",",
"'Paypal payment error \"'",
".",
"$",
"exception",
"->",
"getMessage",
"(",
")",
".",
"'\". Order number #'",
".",
"$",
"orderId",
",",
"'paypal-web-checkout'",
")",
";",
"}",
"return",
"new",
"Response",
"(",
"'OK'",
",",
"200",
")",
";",
"}"
] |
Process Paypal IPN notification.
This controller handles the IPN notification.
The notification is sent using POST method. However,
we expect our internal order_id to be passed as a
query parameter 'order_id'. The resulting URL for
IPN callback notification will have the following form:
http://my-domain.com/payment/paypal_web_checkout/process?order_id=1001
No matter what happens here, this controller will
always return a 200 status HTTP response, otherwise
Paypal notification engine will keep on sending the
message.
@param Request $request Request element
@return Response
|
[
"Process",
"Paypal",
"IPN",
"notification",
"."
] |
8ae57df57fa07aff7e59701a0b3c83c504095b92
|
https://github.com/PaymentSuite/paymentsuite/blob/8ae57df57fa07aff7e59701a0b3c83c504095b92/src/PaymentSuite/PaypalWebCheckoutBundle/Controller/ProcessController.php#L79-L120
|
231,422
|
php-task/TaskBundle
|
src/Executor/SeparateProcessExecutor.php
|
SeparateProcessExecutor.getMaximumAttempts
|
private function getMaximumAttempts($handlerClass)
{
$handler = $this->handlerFactory->create($handlerClass);
if (!$handler instanceof RetryTaskHandlerInterface) {
return 1;
}
return $handler->getMaximumAttempts();
}
|
php
|
private function getMaximumAttempts($handlerClass)
{
$handler = $this->handlerFactory->create($handlerClass);
if (!$handler instanceof RetryTaskHandlerInterface) {
return 1;
}
return $handler->getMaximumAttempts();
}
|
[
"private",
"function",
"getMaximumAttempts",
"(",
"$",
"handlerClass",
")",
"{",
"$",
"handler",
"=",
"$",
"this",
"->",
"handlerFactory",
"->",
"create",
"(",
"$",
"handlerClass",
")",
";",
"if",
"(",
"!",
"$",
"handler",
"instanceof",
"RetryTaskHandlerInterface",
")",
"{",
"return",
"1",
";",
"}",
"return",
"$",
"handler",
"->",
"getMaximumAttempts",
"(",
")",
";",
"}"
] |
Returns maximum attempts for specified handler.
@param string $handlerClass
@return int
|
[
"Returns",
"maximum",
"attempts",
"for",
"specified",
"handler",
"."
] |
be8f0bbdfa3dc9dcaf0e01814166730a336eea07
|
https://github.com/php-task/TaskBundle/blob/be8f0bbdfa3dc9dcaf0e01814166730a336eea07/src/Executor/SeparateProcessExecutor.php#L90-L98
|
231,423
|
php-task/TaskBundle
|
src/Executor/SeparateProcessExecutor.php
|
SeparateProcessExecutor.handle
|
private function handle(TaskExecutionInterface $execution)
{
$process = $this->processFactory->create($execution->getUuid());
$process->run();
if (!$process->isSuccessful()) {
throw $this->createException($process->getErrorOutput());
}
return $process->getOutput();
}
|
php
|
private function handle(TaskExecutionInterface $execution)
{
$process = $this->processFactory->create($execution->getUuid());
$process->run();
if (!$process->isSuccessful()) {
throw $this->createException($process->getErrorOutput());
}
return $process->getOutput();
}
|
[
"private",
"function",
"handle",
"(",
"TaskExecutionInterface",
"$",
"execution",
")",
"{",
"$",
"process",
"=",
"$",
"this",
"->",
"processFactory",
"->",
"create",
"(",
"$",
"execution",
"->",
"getUuid",
"(",
")",
")",
";",
"$",
"process",
"->",
"run",
"(",
")",
";",
"if",
"(",
"!",
"$",
"process",
"->",
"isSuccessful",
"(",
")",
")",
"{",
"throw",
"$",
"this",
"->",
"createException",
"(",
"$",
"process",
"->",
"getErrorOutput",
"(",
")",
")",
";",
"}",
"return",
"$",
"process",
"->",
"getOutput",
"(",
")",
";",
"}"
] |
Handle execution by using console-command.
@param TaskExecutionInterface $execution
@return string
@throws FailedException
@throws SeparateProcessException
|
[
"Handle",
"execution",
"by",
"using",
"console",
"-",
"command",
"."
] |
be8f0bbdfa3dc9dcaf0e01814166730a336eea07
|
https://github.com/php-task/TaskBundle/blob/be8f0bbdfa3dc9dcaf0e01814166730a336eea07/src/Executor/SeparateProcessExecutor.php#L110-L120
|
231,424
|
php-task/TaskBundle
|
src/Executor/SeparateProcessExecutor.php
|
SeparateProcessExecutor.createException
|
private function createException($errorOutput)
{
if (0 !== strpos($errorOutput, FailedException::class)) {
return new SeparateProcessException($errorOutput);
}
$errorOutput = trim(str_replace(FailedException::class, '', $errorOutput));
return new FailedException(new SeparateProcessException($errorOutput));
}
|
php
|
private function createException($errorOutput)
{
if (0 !== strpos($errorOutput, FailedException::class)) {
return new SeparateProcessException($errorOutput);
}
$errorOutput = trim(str_replace(FailedException::class, '', $errorOutput));
return new FailedException(new SeparateProcessException($errorOutput));
}
|
[
"private",
"function",
"createException",
"(",
"$",
"errorOutput",
")",
"{",
"if",
"(",
"0",
"!==",
"strpos",
"(",
"$",
"errorOutput",
",",
"FailedException",
"::",
"class",
")",
")",
"{",
"return",
"new",
"SeparateProcessException",
"(",
"$",
"errorOutput",
")",
";",
"}",
"$",
"errorOutput",
"=",
"trim",
"(",
"str_replace",
"(",
"FailedException",
"::",
"class",
",",
"''",
",",
"$",
"errorOutput",
")",
")",
";",
"return",
"new",
"FailedException",
"(",
"new",
"SeparateProcessException",
"(",
"$",
"errorOutput",
")",
")",
";",
"}"
] |
Create the correct exception.
FailedException for failed executions.
SeparateProcessExceptions for any exception during execution.
@param string $errorOutput
@return FailedException|SeparateProcessException
|
[
"Create",
"the",
"correct",
"exception",
"."
] |
be8f0bbdfa3dc9dcaf0e01814166730a336eea07
|
https://github.com/php-task/TaskBundle/blob/be8f0bbdfa3dc9dcaf0e01814166730a336eea07/src/Executor/SeparateProcessExecutor.php#L132-L141
|
231,425
|
comocode/laravel-ab
|
src/App/Ab.php
|
Ab.saveSession
|
public static function saveSession()
{
if (!empty(self::$instance)) {
foreach (self::$instance as $event) {
$experiment = Experiments::firstOrCreate([
'experiment' => $event->name,
'goal' => $event->goal,
]);
$event = Events::firstOrCreate([
'instance_id' => self::$session->id,
'name' => $event->name,
'value' => $event->fired,
]);
$experiment->events()->save($event);
self::$session->events()->save($event);
}
}
return Session::get(config('laravel-ab.cache_key'));
}
|
php
|
public static function saveSession()
{
if (!empty(self::$instance)) {
foreach (self::$instance as $event) {
$experiment = Experiments::firstOrCreate([
'experiment' => $event->name,
'goal' => $event->goal,
]);
$event = Events::firstOrCreate([
'instance_id' => self::$session->id,
'name' => $event->name,
'value' => $event->fired,
]);
$experiment->events()->save($event);
self::$session->events()->save($event);
}
}
return Session::get(config('laravel-ab.cache_key'));
}
|
[
"public",
"static",
"function",
"saveSession",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"self",
"::",
"$",
"instance",
")",
")",
"{",
"foreach",
"(",
"self",
"::",
"$",
"instance",
"as",
"$",
"event",
")",
"{",
"$",
"experiment",
"=",
"Experiments",
"::",
"firstOrCreate",
"(",
"[",
"'experiment'",
"=>",
"$",
"event",
"->",
"name",
",",
"'goal'",
"=>",
"$",
"event",
"->",
"goal",
",",
"]",
")",
";",
"$",
"event",
"=",
"Events",
"::",
"firstOrCreate",
"(",
"[",
"'instance_id'",
"=>",
"self",
"::",
"$",
"session",
"->",
"id",
",",
"'name'",
"=>",
"$",
"event",
"->",
"name",
",",
"'value'",
"=>",
"$",
"event",
"->",
"fired",
",",
"]",
")",
";",
"$",
"experiment",
"->",
"events",
"(",
")",
"->",
"save",
"(",
"$",
"event",
")",
";",
"self",
"::",
"$",
"session",
"->",
"events",
"(",
")",
"->",
"save",
"(",
"$",
"event",
")",
";",
"}",
"}",
"return",
"Session",
"::",
"get",
"(",
"config",
"(",
"'laravel-ab.cache_key'",
")",
")",
";",
"}"
] |
When the view is rendered, this funciton saves all event->firing pairing to storage.
|
[
"When",
"the",
"view",
"is",
"rendered",
"this",
"funciton",
"saves",
"all",
"event",
"-",
">",
"firing",
"pairing",
"to",
"storage",
"."
] |
d46c3af1b7853aaa32a583048f249be0eef02e11
|
https://github.com/comocode/laravel-ab/blob/d46c3af1b7853aaa32a583048f249be0eef02e11/src/App/Ab.php#L86-L107
|
231,426
|
schemaio/schema-php-client
|
lib/Record.php
|
Record.offsetExists
|
public function offsetExists($index)
{
if (!parent::offsetExists($index) || parent::offsetGet($index) === null) {
if (isset($this->links[$index]['url']) || $index === '$links') {
return true;
}
return false;
}
return true;
}
|
php
|
public function offsetExists($index)
{
if (!parent::offsetExists($index) || parent::offsetGet($index) === null) {
if (isset($this->links[$index]['url']) || $index === '$links') {
return true;
}
return false;
}
return true;
}
|
[
"public",
"function",
"offsetExists",
"(",
"$",
"index",
")",
"{",
"if",
"(",
"!",
"parent",
"::",
"offsetExists",
"(",
"$",
"index",
")",
"||",
"parent",
"::",
"offsetGet",
"(",
"$",
"index",
")",
"===",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"links",
"[",
"$",
"index",
"]",
"[",
"'url'",
"]",
")",
"||",
"$",
"index",
"===",
"'$links'",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Check if record field value exists
@param string $index
@return bool
|
[
"Check",
"if",
"record",
"field",
"value",
"exists"
] |
20759434a6dd7fcc38910eca5ad228287472751b
|
https://github.com/schemaio/schema-php-client/blob/20759434a6dd7fcc38910eca5ad228287472751b/lib/Record.php#L22-L31
|
231,427
|
schemaio/schema-php-client
|
lib/Record.php
|
Record.offsetGet
|
public function offsetGet($field)
{
if ($field === null) {
return;
}
$link_result = null;
if (isset($this->links[$field]['url']) || $field === '$links') {
$link_result = $this->offset_get_link($field);
}
if ($link_result !== null) {
return $link_result;
} else {
return $this->offset_get_result($field);
}
}
|
php
|
public function offsetGet($field)
{
if ($field === null) {
return;
}
$link_result = null;
if (isset($this->links[$field]['url']) || $field === '$links') {
$link_result = $this->offset_get_link($field);
}
if ($link_result !== null) {
return $link_result;
} else {
return $this->offset_get_result($field);
}
}
|
[
"public",
"function",
"offsetGet",
"(",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"field",
"===",
"null",
")",
"{",
"return",
";",
"}",
"$",
"link_result",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"links",
"[",
"$",
"field",
"]",
"[",
"'url'",
"]",
")",
"||",
"$",
"field",
"===",
"'$links'",
")",
"{",
"$",
"link_result",
"=",
"$",
"this",
"->",
"offset_get_link",
"(",
"$",
"field",
")",
";",
"}",
"if",
"(",
"$",
"link_result",
"!==",
"null",
")",
"{",
"return",
"$",
"link_result",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"offset_get_result",
"(",
"$",
"field",
")",
";",
"}",
"}"
] |
Get record field value
@param string $field
@return mixed
|
[
"Get",
"record",
"field",
"value"
] |
20759434a6dd7fcc38910eca5ad228287472751b
|
https://github.com/schemaio/schema-php-client/blob/20759434a6dd7fcc38910eca5ad228287472751b/lib/Record.php#L39-L53
|
231,428
|
schemaio/schema-php-client
|
lib/Record.php
|
Record.offsetSet
|
public function offsetSet($field, $value)
{
if (isset($this->links[$field]['url'])) {
$this->link_data[$field] = $value;
} else {
parent::offsetSet($field, $value);
}
}
|
php
|
public function offsetSet($field, $value)
{
if (isset($this->links[$field]['url'])) {
$this->link_data[$field] = $value;
} else {
parent::offsetSet($field, $value);
}
}
|
[
"public",
"function",
"offsetSet",
"(",
"$",
"field",
",",
"$",
"value",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"links",
"[",
"$",
"field",
"]",
"[",
"'url'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"link_data",
"[",
"$",
"field",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"parent",
"::",
"offsetSet",
"(",
"$",
"field",
",",
"$",
"value",
")",
";",
"}",
"}"
] |
Set record field value
@param string $field
@param mixed $value
@return void
|
[
"Set",
"record",
"field",
"value"
] |
20759434a6dd7fcc38910eca5ad228287472751b
|
https://github.com/schemaio/schema-php-client/blob/20759434a6dd7fcc38910eca5ad228287472751b/lib/Record.php#L62-L69
|
231,429
|
schemaio/schema-php-client
|
lib/Record.php
|
Record.offset_get_link
|
public function offset_get_link($field)
{
$header_links = $this->links;
if ($field === '$links') {
$links = array();
foreach ($header_links['*'] ?: $header_links as $key => $link) {
if ($link['url']) {
$links[$key] = $this->link_url($key);
}
}
return $links;
}
if (!array_key_exists($field, $this->link_data)) {
if (parent::offsetExists($field)) {
$value = parent::offsetGet($field);
// Hack around link formulas
// TODO: find a better way to differentiate from expanded links
if ($header_links[$field]['url'] === '{'.$field.'}') {
unset($this[$field]);
return $this->offset_get_link($field);
}
if (is_array($value)) {
$this->link_data[$field] = Resource::instance(array(
'$url' => $this->link_url($field),
'$data' => $value,
'$links' => isset($header_links[$field]['links'])
? $header_links[$field]['links'] : null
));
} else {
$this->link_data[$field] = $value;
}
return $this->link_data[$field];
} else {
// Avoid storing too much memory from links
$mem_start = memory_get_usage();
$link_url = $this->link_url($field);
$link_data = array();
if (isset(self::$client->default_limit)) {
$link_data['limit'] = self::$client->default_limit;
}
$result = $this->client()->get($link_url, $link_data);
$mem_total = memory_get_usage() - $mem_start;
// Max one megabyte
if ($mem_total < 1048576) {
$this->link_data[$field] = $result;
}
return $result;
}
} else {
return $this->link_data[$field];
}
return null;
}
|
php
|
public function offset_get_link($field)
{
$header_links = $this->links;
if ($field === '$links') {
$links = array();
foreach ($header_links['*'] ?: $header_links as $key => $link) {
if ($link['url']) {
$links[$key] = $this->link_url($key);
}
}
return $links;
}
if (!array_key_exists($field, $this->link_data)) {
if (parent::offsetExists($field)) {
$value = parent::offsetGet($field);
// Hack around link formulas
// TODO: find a better way to differentiate from expanded links
if ($header_links[$field]['url'] === '{'.$field.'}') {
unset($this[$field]);
return $this->offset_get_link($field);
}
if (is_array($value)) {
$this->link_data[$field] = Resource::instance(array(
'$url' => $this->link_url($field),
'$data' => $value,
'$links' => isset($header_links[$field]['links'])
? $header_links[$field]['links'] : null
));
} else {
$this->link_data[$field] = $value;
}
return $this->link_data[$field];
} else {
// Avoid storing too much memory from links
$mem_start = memory_get_usage();
$link_url = $this->link_url($field);
$link_data = array();
if (isset(self::$client->default_limit)) {
$link_data['limit'] = self::$client->default_limit;
}
$result = $this->client()->get($link_url, $link_data);
$mem_total = memory_get_usage() - $mem_start;
// Max one megabyte
if ($mem_total < 1048576) {
$this->link_data[$field] = $result;
}
return $result;
}
} else {
return $this->link_data[$field];
}
return null;
}
|
[
"public",
"function",
"offset_get_link",
"(",
"$",
"field",
")",
"{",
"$",
"header_links",
"=",
"$",
"this",
"->",
"links",
";",
"if",
"(",
"$",
"field",
"===",
"'$links'",
")",
"{",
"$",
"links",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"header_links",
"[",
"'*'",
"]",
"?",
":",
"$",
"header_links",
"as",
"$",
"key",
"=>",
"$",
"link",
")",
"{",
"if",
"(",
"$",
"link",
"[",
"'url'",
"]",
")",
"{",
"$",
"links",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"link_url",
"(",
"$",
"key",
")",
";",
"}",
"}",
"return",
"$",
"links",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"field",
",",
"$",
"this",
"->",
"link_data",
")",
")",
"{",
"if",
"(",
"parent",
"::",
"offsetExists",
"(",
"$",
"field",
")",
")",
"{",
"$",
"value",
"=",
"parent",
"::",
"offsetGet",
"(",
"$",
"field",
")",
";",
"// Hack around link formulas",
"// TODO: find a better way to differentiate from expanded links",
"if",
"(",
"$",
"header_links",
"[",
"$",
"field",
"]",
"[",
"'url'",
"]",
"===",
"'{'",
".",
"$",
"field",
".",
"'}'",
")",
"{",
"unset",
"(",
"$",
"this",
"[",
"$",
"field",
"]",
")",
";",
"return",
"$",
"this",
"->",
"offset_get_link",
"(",
"$",
"field",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"this",
"->",
"link_data",
"[",
"$",
"field",
"]",
"=",
"Resource",
"::",
"instance",
"(",
"array",
"(",
"'$url'",
"=>",
"$",
"this",
"->",
"link_url",
"(",
"$",
"field",
")",
",",
"'$data'",
"=>",
"$",
"value",
",",
"'$links'",
"=>",
"isset",
"(",
"$",
"header_links",
"[",
"$",
"field",
"]",
"[",
"'links'",
"]",
")",
"?",
"$",
"header_links",
"[",
"$",
"field",
"]",
"[",
"'links'",
"]",
":",
"null",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"link_data",
"[",
"$",
"field",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"this",
"->",
"link_data",
"[",
"$",
"field",
"]",
";",
"}",
"else",
"{",
"// Avoid storing too much memory from links",
"$",
"mem_start",
"=",
"memory_get_usage",
"(",
")",
";",
"$",
"link_url",
"=",
"$",
"this",
"->",
"link_url",
"(",
"$",
"field",
")",
";",
"$",
"link_data",
"=",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"client",
"->",
"default_limit",
")",
")",
"{",
"$",
"link_data",
"[",
"'limit'",
"]",
"=",
"self",
"::",
"$",
"client",
"->",
"default_limit",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"client",
"(",
")",
"->",
"get",
"(",
"$",
"link_url",
",",
"$",
"link_data",
")",
";",
"$",
"mem_total",
"=",
"memory_get_usage",
"(",
")",
"-",
"$",
"mem_start",
";",
"// Max one megabyte",
"if",
"(",
"$",
"mem_total",
"<",
"1048576",
")",
"{",
"$",
"this",
"->",
"link_data",
"[",
"$",
"field",
"]",
"=",
"$",
"result",
";",
"}",
"return",
"$",
"result",
";",
"}",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"link_data",
"[",
"$",
"field",
"]",
";",
"}",
"return",
"null",
";",
"}"
] |
Get record field value as a link result
@param string $field
@return Resource
|
[
"Get",
"record",
"field",
"value",
"as",
"a",
"link",
"result"
] |
20759434a6dd7fcc38910eca5ad228287472751b
|
https://github.com/schemaio/schema-php-client/blob/20759434a6dd7fcc38910eca5ad228287472751b/lib/Record.php#L77-L131
|
231,430
|
schemaio/schema-php-client
|
lib/Record.php
|
Record.offset_get_result
|
public function offset_get_result($field)
{
$data_links = null;
if (isset($this->links['*'])) {
$data_links = $this->links['*'];
} else if (isset($this->links[$field]['links'])) {
$data_links = $this->links[$field]['links'];
}
$data_value = parent::offsetExists($field) ? parent::offsetGet($field) : null;
if (is_array($data_value) && !empty($data_value)) {
$collection = isset($this->headers['$collection']) ? $this->headers['$collection'] : null;
$data_record = new Record(array(
'$url' => $this->link_url($field),
'$data' => $data_value,
'$links' => $data_links,
'$collection' => $collection
));
$this->offsetSet($field, $data_record);
return $data_record;
}
else if (!isset($data_value)) {
// Find object within array by id
$data = $this->getArrayCopy();
foreach ($data as $data_val) {
if (isset($data_val['id']) && $data_val['id'] === $field) {
$data_value = $data_val;
break;
}
}
}
return $data_value;
}
|
php
|
public function offset_get_result($field)
{
$data_links = null;
if (isset($this->links['*'])) {
$data_links = $this->links['*'];
} else if (isset($this->links[$field]['links'])) {
$data_links = $this->links[$field]['links'];
}
$data_value = parent::offsetExists($field) ? parent::offsetGet($field) : null;
if (is_array($data_value) && !empty($data_value)) {
$collection = isset($this->headers['$collection']) ? $this->headers['$collection'] : null;
$data_record = new Record(array(
'$url' => $this->link_url($field),
'$data' => $data_value,
'$links' => $data_links,
'$collection' => $collection
));
$this->offsetSet($field, $data_record);
return $data_record;
}
else if (!isset($data_value)) {
// Find object within array by id
$data = $this->getArrayCopy();
foreach ($data as $data_val) {
if (isset($data_val['id']) && $data_val['id'] === $field) {
$data_value = $data_val;
break;
}
}
}
return $data_value;
}
|
[
"public",
"function",
"offset_get_result",
"(",
"$",
"field",
")",
"{",
"$",
"data_links",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"links",
"[",
"'*'",
"]",
")",
")",
"{",
"$",
"data_links",
"=",
"$",
"this",
"->",
"links",
"[",
"'*'",
"]",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"links",
"[",
"$",
"field",
"]",
"[",
"'links'",
"]",
")",
")",
"{",
"$",
"data_links",
"=",
"$",
"this",
"->",
"links",
"[",
"$",
"field",
"]",
"[",
"'links'",
"]",
";",
"}",
"$",
"data_value",
"=",
"parent",
"::",
"offsetExists",
"(",
"$",
"field",
")",
"?",
"parent",
"::",
"offsetGet",
"(",
"$",
"field",
")",
":",
"null",
";",
"if",
"(",
"is_array",
"(",
"$",
"data_value",
")",
"&&",
"!",
"empty",
"(",
"$",
"data_value",
")",
")",
"{",
"$",
"collection",
"=",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"'$collection'",
"]",
")",
"?",
"$",
"this",
"->",
"headers",
"[",
"'$collection'",
"]",
":",
"null",
";",
"$",
"data_record",
"=",
"new",
"Record",
"(",
"array",
"(",
"'$url'",
"=>",
"$",
"this",
"->",
"link_url",
"(",
"$",
"field",
")",
",",
"'$data'",
"=>",
"$",
"data_value",
",",
"'$links'",
"=>",
"$",
"data_links",
",",
"'$collection'",
"=>",
"$",
"collection",
")",
")",
";",
"$",
"this",
"->",
"offsetSet",
"(",
"$",
"field",
",",
"$",
"data_record",
")",
";",
"return",
"$",
"data_record",
";",
"}",
"else",
"if",
"(",
"!",
"isset",
"(",
"$",
"data_value",
")",
")",
"{",
"// Find object within array by id",
"$",
"data",
"=",
"$",
"this",
"->",
"getArrayCopy",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"data_val",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"data_val",
"[",
"'id'",
"]",
")",
"&&",
"$",
"data_val",
"[",
"'id'",
"]",
"===",
"$",
"field",
")",
"{",
"$",
"data_value",
"=",
"$",
"data_val",
";",
"break",
";",
"}",
"}",
"}",
"return",
"$",
"data_value",
";",
"}"
] |
Get record field value as a record result
@param string $field
@return mixed
|
[
"Get",
"record",
"field",
"value",
"as",
"a",
"record",
"result"
] |
20759434a6dd7fcc38910eca5ad228287472751b
|
https://github.com/schemaio/schema-php-client/blob/20759434a6dd7fcc38910eca5ad228287472751b/lib/Record.php#L139-L173
|
231,431
|
schemaio/schema-php-client
|
lib/Record.php
|
Record.link_url
|
public function link_url($field, $id = null)
{
if ($qpos = strpos($this->url, '?')) {
$url = substr($this->url, 0, $qpos);
} else {
$url = $this->url;
}
if ($id) {
$url = preg_replace('/[^\/]+$/', $id, rtrim($url, "/"));
}
return $url."/".$field;
}
|
php
|
public function link_url($field, $id = null)
{
if ($qpos = strpos($this->url, '?')) {
$url = substr($this->url, 0, $qpos);
} else {
$url = $this->url;
}
if ($id) {
$url = preg_replace('/[^\/]+$/', $id, rtrim($url, "/"));
}
return $url."/".$field;
}
|
[
"public",
"function",
"link_url",
"(",
"$",
"field",
",",
"$",
"id",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"qpos",
"=",
"strpos",
"(",
"$",
"this",
"->",
"url",
",",
"'?'",
")",
")",
"{",
"$",
"url",
"=",
"substr",
"(",
"$",
"this",
"->",
"url",
",",
"0",
",",
"$",
"qpos",
")",
";",
"}",
"else",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"url",
";",
"}",
"if",
"(",
"$",
"id",
")",
"{",
"$",
"url",
"=",
"preg_replace",
"(",
"'/[^\\/]+$/'",
",",
"$",
"id",
",",
"rtrim",
"(",
"$",
"url",
",",
"\"/\"",
")",
")",
";",
"}",
"return",
"$",
"url",
".",
"\"/\"",
".",
"$",
"field",
";",
"}"
] |
Build relative url for a link field
@param string $field
@param string $id
|
[
"Build",
"relative",
"url",
"for",
"a",
"link",
"field"
] |
20759434a6dd7fcc38910eca5ad228287472751b
|
https://github.com/schemaio/schema-php-client/blob/20759434a6dd7fcc38910eca5ad228287472751b/lib/Record.php#L191-L204
|
231,432
|
schemaio/schema-php-client
|
lib/Record.php
|
Record.dump
|
public function dump($return = false, $print = true, $depth = 1)
{
$dump = $this->data();
$links = $this->links;
foreach ($links as $key => $link) {
if ($depth < 1) {
try {
$related = $this->{$key};
} catch (ServerException $e) {
$related = array('$error' => $e->getMessage());
}
if ($related instanceof Resource) {
$dump[$key] = $related->dump(true, false, $depth+1);
} else {
$dump[$key] = $related;
}
}
}
if ($links) {
$dump['$links'] = $this->dump_links($links);
}
return $print ? print_r($dump, $return) : $dump;
}
|
php
|
public function dump($return = false, $print = true, $depth = 1)
{
$dump = $this->data();
$links = $this->links;
foreach ($links as $key => $link) {
if ($depth < 1) {
try {
$related = $this->{$key};
} catch (ServerException $e) {
$related = array('$error' => $e->getMessage());
}
if ($related instanceof Resource) {
$dump[$key] = $related->dump(true, false, $depth+1);
} else {
$dump[$key] = $related;
}
}
}
if ($links) {
$dump['$links'] = $this->dump_links($links);
}
return $print ? print_r($dump, $return) : $dump;
}
|
[
"public",
"function",
"dump",
"(",
"$",
"return",
"=",
"false",
",",
"$",
"print",
"=",
"true",
",",
"$",
"depth",
"=",
"1",
")",
"{",
"$",
"dump",
"=",
"$",
"this",
"->",
"data",
"(",
")",
";",
"$",
"links",
"=",
"$",
"this",
"->",
"links",
";",
"foreach",
"(",
"$",
"links",
"as",
"$",
"key",
"=>",
"$",
"link",
")",
"{",
"if",
"(",
"$",
"depth",
"<",
"1",
")",
"{",
"try",
"{",
"$",
"related",
"=",
"$",
"this",
"->",
"{",
"$",
"key",
"}",
";",
"}",
"catch",
"(",
"ServerException",
"$",
"e",
")",
"{",
"$",
"related",
"=",
"array",
"(",
"'$error'",
"=>",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"related",
"instanceof",
"Resource",
")",
"{",
"$",
"dump",
"[",
"$",
"key",
"]",
"=",
"$",
"related",
"->",
"dump",
"(",
"true",
",",
"false",
",",
"$",
"depth",
"+",
"1",
")",
";",
"}",
"else",
"{",
"$",
"dump",
"[",
"$",
"key",
"]",
"=",
"$",
"related",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"links",
")",
"{",
"$",
"dump",
"[",
"'$links'",
"]",
"=",
"$",
"this",
"->",
"dump_links",
"(",
"$",
"links",
")",
";",
"}",
"return",
"$",
"print",
"?",
"print_r",
"(",
"$",
"dump",
",",
"$",
"return",
")",
":",
"$",
"dump",
";",
"}"
] |
Dump raw record values
@param bool $return
@param bool $print
|
[
"Dump",
"raw",
"record",
"values"
] |
20759434a6dd7fcc38910eca5ad228287472751b
|
https://github.com/schemaio/schema-php-client/blob/20759434a6dd7fcc38910eca5ad228287472751b/lib/Record.php#L212-L237
|
231,433
|
juliushaertl/phpdoc-to-rst
|
src/Middleware/ErrorHandlingMiddleware.php
|
ErrorHandlingMiddleware.execute
|
public function execute($command, callable $next)
{
$filename = $command->getFile()->path();
$this->apiDocBuilder->debug('Starting to parse file: ' . $filename);
try {
return $next($command);
} catch (\Exception $e) {
$this->apiDocBuilder->log('Unable to parse file "' . $filename . '", ' . $e->getMessage());
}
return null;
}
|
php
|
public function execute($command, callable $next)
{
$filename = $command->getFile()->path();
$this->apiDocBuilder->debug('Starting to parse file: ' . $filename);
try {
return $next($command);
} catch (\Exception $e) {
$this->apiDocBuilder->log('Unable to parse file "' . $filename . '", ' . $e->getMessage());
}
return null;
}
|
[
"public",
"function",
"execute",
"(",
"$",
"command",
",",
"callable",
"$",
"next",
")",
"{",
"$",
"filename",
"=",
"$",
"command",
"->",
"getFile",
"(",
")",
"->",
"path",
"(",
")",
";",
"$",
"this",
"->",
"apiDocBuilder",
"->",
"debug",
"(",
"'Starting to parse file: '",
".",
"$",
"filename",
")",
";",
"try",
"{",
"return",
"$",
"next",
"(",
"$",
"command",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"apiDocBuilder",
"->",
"log",
"(",
"'Unable to parse file \"'",
".",
"$",
"filename",
".",
"'\", '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Executes this middleware class.
@param CreateCommand $command
@param callable $next
@return object
|
[
"Executes",
"this",
"middleware",
"class",
"."
] |
9a695417d1f3bb709f60cd5c519e46f1ad08c843
|
https://github.com/juliushaertl/phpdoc-to-rst/blob/9a695417d1f3bb709f60cd5c519e46f1ad08c843/src/Middleware/ErrorHandlingMiddleware.php#L49-L59
|
231,434
|
PaymentSuite/paymentsuite
|
src/PaymentSuite/PaypalWebCheckoutBundle/Services/PaypalWebCheckoutManager.php
|
PaypalWebCheckoutManager.generatePaypalForm
|
public function generatePaypalForm()
{
$paypalMethod = $this
->paymentMethodFactory
->createEmpty();
/**
* We expect listeners for the payment.order.load event
* to store the Order into the bridge.
*
* So, $this->paymentBridge->getOrder() must return an object
*/
$this
->paymentEventDispatcher
->notifyPaymentOrderLoad(
$this->paymentBridge,
$paypalMethod
);
/**
* Order Not found Exception must be thrown just here.
*/
if (!$this->paymentBridge->getOrder()) {
throw new PaymentOrderNotFoundException();
}
/**
* We expect the Order to be created and physically flushed.
*/
$this
->paymentEventDispatcher
->notifyPaymentOrderCreated(
$this->paymentBridge,
$paypalMethod
);
return $this
->formTypeFactory
->buildForm();
}
|
php
|
public function generatePaypalForm()
{
$paypalMethod = $this
->paymentMethodFactory
->createEmpty();
/**
* We expect listeners for the payment.order.load event
* to store the Order into the bridge.
*
* So, $this->paymentBridge->getOrder() must return an object
*/
$this
->paymentEventDispatcher
->notifyPaymentOrderLoad(
$this->paymentBridge,
$paypalMethod
);
/**
* Order Not found Exception must be thrown just here.
*/
if (!$this->paymentBridge->getOrder()) {
throw new PaymentOrderNotFoundException();
}
/**
* We expect the Order to be created and physically flushed.
*/
$this
->paymentEventDispatcher
->notifyPaymentOrderCreated(
$this->paymentBridge,
$paypalMethod
);
return $this
->formTypeFactory
->buildForm();
}
|
[
"public",
"function",
"generatePaypalForm",
"(",
")",
"{",
"$",
"paypalMethod",
"=",
"$",
"this",
"->",
"paymentMethodFactory",
"->",
"createEmpty",
"(",
")",
";",
"/**\n * We expect listeners for the payment.order.load event\n * to store the Order into the bridge.\n *\n * So, $this->paymentBridge->getOrder() must return an object\n */",
"$",
"this",
"->",
"paymentEventDispatcher",
"->",
"notifyPaymentOrderLoad",
"(",
"$",
"this",
"->",
"paymentBridge",
",",
"$",
"paypalMethod",
")",
";",
"/**\n * Order Not found Exception must be thrown just here.\n */",
"if",
"(",
"!",
"$",
"this",
"->",
"paymentBridge",
"->",
"getOrder",
"(",
")",
")",
"{",
"throw",
"new",
"PaymentOrderNotFoundException",
"(",
")",
";",
"}",
"/**\n * We expect the Order to be created and physically flushed.\n */",
"$",
"this",
"->",
"paymentEventDispatcher",
"->",
"notifyPaymentOrderCreated",
"(",
"$",
"this",
"->",
"paymentBridge",
",",
"$",
"paypalMethod",
")",
";",
"return",
"$",
"this",
"->",
"formTypeFactory",
"->",
"buildForm",
"(",
")",
";",
"}"
] |
Dispatches order load event and prepares paypal form for submission.
This is a synchronous action that takes place on the implementor
side, i.e. right after click the "pay with checkout" button it the
final stage of a checkout process.
See documentation for PaypalWebCheckout Api Integration at
@link https://developer.paypal.com/docs/integration/web/web-checkout/
@throws PaymentOrderNotFoundException
@return \Symfony\Component\Form\FormView
|
[
"Dispatches",
"order",
"load",
"event",
"and",
"prepares",
"paypal",
"form",
"for",
"submission",
"."
] |
8ae57df57fa07aff7e59701a0b3c83c504095b92
|
https://github.com/PaymentSuite/paymentsuite/blob/8ae57df57fa07aff7e59701a0b3c83c504095b92/src/PaymentSuite/PaypalWebCheckoutBundle/Services/PaypalWebCheckoutManager.php#L102-L141
|
231,435
|
PaymentSuite/paymentsuite
|
src/PaymentSuite/PaypalWebCheckoutBundle/Services/PaypalWebCheckoutManager.php
|
PaypalWebCheckoutManager.processPaypalIPNMessage
|
public function processPaypalIPNMessage($orderId, array $parameters)
{
/**
* Retrieving the order object.
*/
$order = $this
->paymentBridge
->findOrder($orderId);
if (!$order) {
throw new PaymentOrderNotFoundException(sprintf(
'Order #%s not found', $orderId)
);
}
$this
->paymentBridge
->setOrder($order);
/**
* Check that we receive the mandatory parameters.
*/
$this->checkResultParameters($parameters);
/**
* Initializing PaypalWebCheckoutMethod, which is
* an object representation of the payment information
* coming from the payment processor.
*/
$paypalMethod = $this
->paymentMethodFactory
->create(
$parameters['mc_gross'],
$parameters['payment_status'],
$parameters['notify_version'],
$parameters['payer_status'],
$parameters['business'],
null,
$parameters['verify_sign'],
$parameters['payer_email'],
$parameters['txn_id'],
$parameters['payment_type'],
$parameters['receiver_email'],
null,
$parameters['txn_type'],
null,
$parameters['mc_currency'],
null,
$parameters['test_ipn'],
$parameters['ipn_track_id']
);
/**
* Notifying payment.done, which means that the
* payment has been received, although we still
* do not know if it is succesful or not.
* Listening fot this event is useful when one
* wants to record transaction informations.
*/
$this
->paymentEventDispatcher
->notifyPaymentOrderDone(
$this->paymentBridge,
$paypalMethod
);
/**
* Check if the transaction is successful.
*/
if (!$this->transactionSuccessful($parameters)) {
$this
->paymentEventDispatcher
->notifyPaymentOrderFail(
$this->paymentBridge,
$paypalMethod
);
throw new PaymentException();
}
/**
* Payment paid successfully.
*
* Paid process has ended successfully
*/
$this
->paymentEventDispatcher
->notifyPaymentOrderSuccess(
$this->paymentBridge,
$paypalMethod
);
}
|
php
|
public function processPaypalIPNMessage($orderId, array $parameters)
{
/**
* Retrieving the order object.
*/
$order = $this
->paymentBridge
->findOrder($orderId);
if (!$order) {
throw new PaymentOrderNotFoundException(sprintf(
'Order #%s not found', $orderId)
);
}
$this
->paymentBridge
->setOrder($order);
/**
* Check that we receive the mandatory parameters.
*/
$this->checkResultParameters($parameters);
/**
* Initializing PaypalWebCheckoutMethod, which is
* an object representation of the payment information
* coming from the payment processor.
*/
$paypalMethod = $this
->paymentMethodFactory
->create(
$parameters['mc_gross'],
$parameters['payment_status'],
$parameters['notify_version'],
$parameters['payer_status'],
$parameters['business'],
null,
$parameters['verify_sign'],
$parameters['payer_email'],
$parameters['txn_id'],
$parameters['payment_type'],
$parameters['receiver_email'],
null,
$parameters['txn_type'],
null,
$parameters['mc_currency'],
null,
$parameters['test_ipn'],
$parameters['ipn_track_id']
);
/**
* Notifying payment.done, which means that the
* payment has been received, although we still
* do not know if it is succesful or not.
* Listening fot this event is useful when one
* wants to record transaction informations.
*/
$this
->paymentEventDispatcher
->notifyPaymentOrderDone(
$this->paymentBridge,
$paypalMethod
);
/**
* Check if the transaction is successful.
*/
if (!$this->transactionSuccessful($parameters)) {
$this
->paymentEventDispatcher
->notifyPaymentOrderFail(
$this->paymentBridge,
$paypalMethod
);
throw new PaymentException();
}
/**
* Payment paid successfully.
*
* Paid process has ended successfully
*/
$this
->paymentEventDispatcher
->notifyPaymentOrderSuccess(
$this->paymentBridge,
$paypalMethod
);
}
|
[
"public",
"function",
"processPaypalIPNMessage",
"(",
"$",
"orderId",
",",
"array",
"$",
"parameters",
")",
"{",
"/**\n * Retrieving the order object.\n */",
"$",
"order",
"=",
"$",
"this",
"->",
"paymentBridge",
"->",
"findOrder",
"(",
"$",
"orderId",
")",
";",
"if",
"(",
"!",
"$",
"order",
")",
"{",
"throw",
"new",
"PaymentOrderNotFoundException",
"(",
"sprintf",
"(",
"'Order #%s not found'",
",",
"$",
"orderId",
")",
")",
";",
"}",
"$",
"this",
"->",
"paymentBridge",
"->",
"setOrder",
"(",
"$",
"order",
")",
";",
"/**\n * Check that we receive the mandatory parameters.\n */",
"$",
"this",
"->",
"checkResultParameters",
"(",
"$",
"parameters",
")",
";",
"/**\n * Initializing PaypalWebCheckoutMethod, which is\n * an object representation of the payment information\n * coming from the payment processor.\n */",
"$",
"paypalMethod",
"=",
"$",
"this",
"->",
"paymentMethodFactory",
"->",
"create",
"(",
"$",
"parameters",
"[",
"'mc_gross'",
"]",
",",
"$",
"parameters",
"[",
"'payment_status'",
"]",
",",
"$",
"parameters",
"[",
"'notify_version'",
"]",
",",
"$",
"parameters",
"[",
"'payer_status'",
"]",
",",
"$",
"parameters",
"[",
"'business'",
"]",
",",
"null",
",",
"$",
"parameters",
"[",
"'verify_sign'",
"]",
",",
"$",
"parameters",
"[",
"'payer_email'",
"]",
",",
"$",
"parameters",
"[",
"'txn_id'",
"]",
",",
"$",
"parameters",
"[",
"'payment_type'",
"]",
",",
"$",
"parameters",
"[",
"'receiver_email'",
"]",
",",
"null",
",",
"$",
"parameters",
"[",
"'txn_type'",
"]",
",",
"null",
",",
"$",
"parameters",
"[",
"'mc_currency'",
"]",
",",
"null",
",",
"$",
"parameters",
"[",
"'test_ipn'",
"]",
",",
"$",
"parameters",
"[",
"'ipn_track_id'",
"]",
")",
";",
"/**\n * Notifying payment.done, which means that the\n * payment has been received, although we still\n * do not know if it is succesful or not.\n * Listening fot this event is useful when one\n * wants to record transaction informations.\n */",
"$",
"this",
"->",
"paymentEventDispatcher",
"->",
"notifyPaymentOrderDone",
"(",
"$",
"this",
"->",
"paymentBridge",
",",
"$",
"paypalMethod",
")",
";",
"/**\n * Check if the transaction is successful.\n */",
"if",
"(",
"!",
"$",
"this",
"->",
"transactionSuccessful",
"(",
"$",
"parameters",
")",
")",
"{",
"$",
"this",
"->",
"paymentEventDispatcher",
"->",
"notifyPaymentOrderFail",
"(",
"$",
"this",
"->",
"paymentBridge",
",",
"$",
"paypalMethod",
")",
";",
"throw",
"new",
"PaymentException",
"(",
")",
";",
"}",
"/**\n * Payment paid successfully.\n *\n * Paid process has ended successfully\n */",
"$",
"this",
"->",
"paymentEventDispatcher",
"->",
"notifyPaymentOrderSuccess",
"(",
"$",
"this",
"->",
"paymentBridge",
",",
"$",
"paypalMethod",
")",
";",
"}"
] |
Process Paypal IPN response to payment.
When the IPN mesage is validated, a payment success event
should be dispatched.
@param int $orderId Order Id
@param array $parameters parameter array coming from Paypal IPN notification
@throws ParameterNotReceivedException
@throws PaymentException
|
[
"Process",
"Paypal",
"IPN",
"response",
"to",
"payment",
"."
] |
8ae57df57fa07aff7e59701a0b3c83c504095b92
|
https://github.com/PaymentSuite/paymentsuite/blob/8ae57df57fa07aff7e59701a0b3c83c504095b92/src/PaymentSuite/PaypalWebCheckoutBundle/Services/PaypalWebCheckoutManager.php#L155-L246
|
231,436
|
PaymentSuite/paymentsuite
|
src/PaymentSuite/PaypalWebCheckoutBundle/Services/PaypalWebCheckoutManager.php
|
PaypalWebCheckoutManager.transactionSuccessful
|
private function transactionSuccessful($ipnParameters)
{
/**
* First of all we have to check the validity of the IPN
* message. We need to send back the contents of the query
* string coming from Paypal's IPN message.
*/
$ipnNotifyValidateUrl = $this->urlFactory->getApiEndpoint()
. '?'
. http_build_query(
array_merge(
$this->urlFactory->getPaypalNotifyValidateQueryParam(),
$ipnParameters)
);
$ipnValidated = (file_get_contents($ipnNotifyValidateUrl) == 'VERIFIED');
/**
* Matching paid amount with the originating order amount,
* this is a security check to prevent frauds by manually
* changing the papal form.
*/
$amountMatches = $this->paymentBridge->getAmount() / 100 == $ipnParameters['mc_gross'];
$amountMatches = $amountMatches && $this->paymentBridge->getCurrency() == ($ipnParameters['mc_currency']);
/**
* When a transaction is successful, payment_status has a 'Completed' value.
*/
return $amountMatches && $ipnValidated && (strcmp($ipnParameters['payment_status'], 'Completed') === 0);
}
|
php
|
private function transactionSuccessful($ipnParameters)
{
/**
* First of all we have to check the validity of the IPN
* message. We need to send back the contents of the query
* string coming from Paypal's IPN message.
*/
$ipnNotifyValidateUrl = $this->urlFactory->getApiEndpoint()
. '?'
. http_build_query(
array_merge(
$this->urlFactory->getPaypalNotifyValidateQueryParam(),
$ipnParameters)
);
$ipnValidated = (file_get_contents($ipnNotifyValidateUrl) == 'VERIFIED');
/**
* Matching paid amount with the originating order amount,
* this is a security check to prevent frauds by manually
* changing the papal form.
*/
$amountMatches = $this->paymentBridge->getAmount() / 100 == $ipnParameters['mc_gross'];
$amountMatches = $amountMatches && $this->paymentBridge->getCurrency() == ($ipnParameters['mc_currency']);
/**
* When a transaction is successful, payment_status has a 'Completed' value.
*/
return $amountMatches && $ipnValidated && (strcmp($ipnParameters['payment_status'], 'Completed') === 0);
}
|
[
"private",
"function",
"transactionSuccessful",
"(",
"$",
"ipnParameters",
")",
"{",
"/**\n * First of all we have to check the validity of the IPN\n * message. We need to send back the contents of the query\n * string coming from Paypal's IPN message.\n */",
"$",
"ipnNotifyValidateUrl",
"=",
"$",
"this",
"->",
"urlFactory",
"->",
"getApiEndpoint",
"(",
")",
".",
"'?'",
".",
"http_build_query",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"urlFactory",
"->",
"getPaypalNotifyValidateQueryParam",
"(",
")",
",",
"$",
"ipnParameters",
")",
")",
";",
"$",
"ipnValidated",
"=",
"(",
"file_get_contents",
"(",
"$",
"ipnNotifyValidateUrl",
")",
"==",
"'VERIFIED'",
")",
";",
"/**\n * Matching paid amount with the originating order amount,\n * this is a security check to prevent frauds by manually\n * changing the papal form.\n */",
"$",
"amountMatches",
"=",
"$",
"this",
"->",
"paymentBridge",
"->",
"getAmount",
"(",
")",
"/",
"100",
"==",
"$",
"ipnParameters",
"[",
"'mc_gross'",
"]",
";",
"$",
"amountMatches",
"=",
"$",
"amountMatches",
"&&",
"$",
"this",
"->",
"paymentBridge",
"->",
"getCurrency",
"(",
")",
"==",
"(",
"$",
"ipnParameters",
"[",
"'mc_currency'",
"]",
")",
";",
"/**\n * When a transaction is successful, payment_status has a 'Completed' value.\n */",
"return",
"$",
"amountMatches",
"&&",
"$",
"ipnValidated",
"&&",
"(",
"strcmp",
"(",
"$",
"ipnParameters",
"[",
"'payment_status'",
"]",
",",
"'Completed'",
")",
"===",
"0",
")",
";",
"}"
] |
Check if transaction is complete.
When we receive an IPN response, we should
check that the price paid corresponds to the
amount stored in the PaymentMethod. This double
check is essential since the web checkout form
could be mangled.
@link https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNIntro/
@param array $ipnParameters Paypal IPN parameters
@return bool
|
[
"Check",
"if",
"transaction",
"is",
"complete",
"."
] |
8ae57df57fa07aff7e59701a0b3c83c504095b92
|
https://github.com/PaymentSuite/paymentsuite/blob/8ae57df57fa07aff7e59701a0b3c83c504095b92/src/PaymentSuite/PaypalWebCheckoutBundle/Services/PaypalWebCheckoutManager.php#L283-L312
|
231,437
|
colorfield/mastodon-api-php
|
src/ConfigurationVO.php
|
ConfigurationVO.setOAuthCredentials
|
public function setOAuthCredentials(array $config)
{
// @todo change by using ConfigVO
// Throw exeception for mandatory params
if (!isset($config['client_id'])) {
throw new \InvalidArgumentException('Missing client_id.');
}
// Throw exeception for mandatory params
if (!isset($config['client_secret'])) {
throw new \InvalidArgumentException('Missing client_secret.');
}
// Throw exeception for mandatory params
if (!isset($config['bearer'])) {
throw new \InvalidArgumentException('Missing client_secret.');
}
}
|
php
|
public function setOAuthCredentials(array $config)
{
// @todo change by using ConfigVO
// Throw exeception for mandatory params
if (!isset($config['client_id'])) {
throw new \InvalidArgumentException('Missing client_id.');
}
// Throw exeception for mandatory params
if (!isset($config['client_secret'])) {
throw new \InvalidArgumentException('Missing client_secret.');
}
// Throw exeception for mandatory params
if (!isset($config['bearer'])) {
throw new \InvalidArgumentException('Missing client_secret.');
}
}
|
[
"public",
"function",
"setOAuthCredentials",
"(",
"array",
"$",
"config",
")",
"{",
"// @todo change by using ConfigVO",
"// Throw exeception for mandatory params",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"'client_id'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Missing client_id.'",
")",
";",
"}",
"// Throw exeception for mandatory params",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"'client_secret'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Missing client_secret.'",
")",
";",
"}",
"// Throw exeception for mandatory params",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"'bearer'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Missing client_secret.'",
")",
";",
"}",
"}"
] |
Initializes the Configuration Value Object with oAuth credentials
To be used by the MastodonAPI class after authentication.
It should contain the client_id, client_secret and bearer.
@throws \InvalidArgumentException
@param array $config
|
[
"Initializes",
"the",
"Configuration",
"Value",
"Object",
"with",
"oAuth",
"credentials"
] |
cd9cb946032508e48630fffd5a661f3347d0b84f
|
https://github.com/colorfield/mastodon-api-php/blob/cd9cb946032508e48630fffd5a661f3347d0b84f/src/ConfigurationVO.php#L186-L203
|
231,438
|
colorfield/mastodon-api-php
|
src/ConfigurationVO.php
|
ConfigurationVO.getUserAuthenticationConfiguration
|
public function getUserAuthenticationConfiguration($email, $password)
{
return [
'grant_type' => 'password',
'client_id' => $this->getClientId(),
'client_secret' => $this->getClientSecret(),
'username' => $email,
'password' => $password,
'scope' => $this->getScopes(),
];
}
|
php
|
public function getUserAuthenticationConfiguration($email, $password)
{
return [
'grant_type' => 'password',
'client_id' => $this->getClientId(),
'client_secret' => $this->getClientSecret(),
'username' => $email,
'password' => $password,
'scope' => $this->getScopes(),
];
}
|
[
"public",
"function",
"getUserAuthenticationConfiguration",
"(",
"$",
"email",
",",
"$",
"password",
")",
"{",
"return",
"[",
"'grant_type'",
"=>",
"'password'",
",",
"'client_id'",
"=>",
"$",
"this",
"->",
"getClientId",
"(",
")",
",",
"'client_secret'",
"=>",
"$",
"this",
"->",
"getClientSecret",
"(",
")",
",",
"'username'",
"=>",
"$",
"email",
",",
"'password'",
"=>",
"$",
"password",
",",
"'scope'",
"=>",
"$",
"this",
"->",
"getScopes",
"(",
")",
",",
"]",
";",
"}"
] |
Returns the user authentication configuration.
@param $email
@param $password
@return array
|
[
"Returns",
"the",
"user",
"authentication",
"configuration",
"."
] |
cd9cb946032508e48630fffd5a661f3347d0b84f
|
https://github.com/colorfield/mastodon-api-php/blob/cd9cb946032508e48630fffd5a661f3347d0b84f/src/ConfigurationVO.php#L256-L266
|
231,439
|
JPinkney/TVMaze-PHP-API-Wrapper
|
TVMaze/TVMaze.php
|
TVMaze.search
|
public function search($show_name)
{
$relevant_shows = false;
$url = self::APIURL. '/search/shows?q=' . rawurlencode($show_name);
$shows = $this->getFile($url);
if (is_array($shows)) {
$relevant_shows = [];
foreach ($shows as $series) {
$TVShow = new TVShow($series['show']);
$relevant_shows[] = $TVShow;
}
}
return $relevant_shows;
}
|
php
|
public function search($show_name)
{
$relevant_shows = false;
$url = self::APIURL. '/search/shows?q=' . rawurlencode($show_name);
$shows = $this->getFile($url);
if (is_array($shows)) {
$relevant_shows = [];
foreach ($shows as $series) {
$TVShow = new TVShow($series['show']);
$relevant_shows[] = $TVShow;
}
}
return $relevant_shows;
}
|
[
"public",
"function",
"search",
"(",
"$",
"show_name",
")",
"{",
"$",
"relevant_shows",
"=",
"false",
";",
"$",
"url",
"=",
"self",
"::",
"APIURL",
".",
"'/search/shows?q='",
".",
"rawurlencode",
"(",
"$",
"show_name",
")",
";",
"$",
"shows",
"=",
"$",
"this",
"->",
"getFile",
"(",
"$",
"url",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"shows",
")",
")",
"{",
"$",
"relevant_shows",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"shows",
"as",
"$",
"series",
")",
"{",
"$",
"TVShow",
"=",
"new",
"TVShow",
"(",
"$",
"series",
"[",
"'show'",
"]",
")",
";",
"$",
"relevant_shows",
"[",
"]",
"=",
"$",
"TVShow",
";",
"}",
"}",
"return",
"$",
"relevant_shows",
";",
"}"
] |
Takes in a show name
Outputs array of all the related shows for that given name
@param $show_name
@return array
|
[
"Takes",
"in",
"a",
"show",
"name",
"Outputs",
"array",
"of",
"all",
"the",
"related",
"shows",
"for",
"that",
"given",
"name"
] |
174429341ef2009a42f77743faa342726d7d8467
|
https://github.com/JPinkney/TVMaze-PHP-API-Wrapper/blob/174429341ef2009a42f77743faa342726d7d8467/TVMaze/TVMaze.php#L17-L32
|
231,440
|
JPinkney/TVMaze-PHP-API-Wrapper
|
TVMaze/TVMaze.php
|
TVMaze.getPersonByName
|
public function getPersonByName($name){
$name = strtolower($name);
$url = self::APIURL.'/search/people?q='.$name;
$person = $this->getFile($url);
$people = [];
foreach($person as $peeps){
$people[] = new Actor($peeps['person']);
}
return $people;
}
|
php
|
public function getPersonByName($name){
$name = strtolower($name);
$url = self::APIURL.'/search/people?q='.$name;
$person = $this->getFile($url);
$people = [];
foreach($person as $peeps){
$people[] = new Actor($peeps['person']);
}
return $people;
}
|
[
"public",
"function",
"getPersonByName",
"(",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"strtolower",
"(",
"$",
"name",
")",
";",
"$",
"url",
"=",
"self",
"::",
"APIURL",
".",
"'/search/people?q='",
".",
"$",
"name",
";",
"$",
"person",
"=",
"$",
"this",
"->",
"getFile",
"(",
"$",
"url",
")",
";",
"$",
"people",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"person",
"as",
"$",
"peeps",
")",
"{",
"$",
"people",
"[",
"]",
"=",
"new",
"Actor",
"(",
"$",
"peeps",
"[",
"'person'",
"]",
")",
";",
"}",
"return",
"$",
"people",
";",
"}"
] |
Takes in an actors name and outputs their actor object
@param $name
@return array
|
[
"Takes",
"in",
"an",
"actors",
"name",
"and",
"outputs",
"their",
"actor",
"object"
] |
174429341ef2009a42f77743faa342726d7d8467
|
https://github.com/JPinkney/TVMaze-PHP-API-Wrapper/blob/174429341ef2009a42f77743faa342726d7d8467/TVMaze/TVMaze.php#L102-L113
|
231,441
|
JPinkney/TVMaze-PHP-API-Wrapper
|
TVMaze/TVMaze.php
|
TVMaze.getShowByShowID
|
public function getShowByShowID($ID, $embed_cast=null){
if($embed_cast === true){
$url = self::APIURL.'/shows/'.$ID.'?embed=cast';
}else{
$url = self::APIURL.'/shows/'.$ID;
}
$show = $this->getFile($url);
$cast = [];
foreach($show['_embedded']['cast'] as $person){
$actor = new Actor($person['person']);
$character = new Character($person['character']);
$cast[] = [$actor, $character];
}
$TVShow = new TVShow($show);
return $embed_cast === true ? [$TVShow, $cast] : [$TVShow];
}
|
php
|
public function getShowByShowID($ID, $embed_cast=null){
if($embed_cast === true){
$url = self::APIURL.'/shows/'.$ID.'?embed=cast';
}else{
$url = self::APIURL.'/shows/'.$ID;
}
$show = $this->getFile($url);
$cast = [];
foreach($show['_embedded']['cast'] as $person){
$actor = new Actor($person['person']);
$character = new Character($person['character']);
$cast[] = [$actor, $character];
}
$TVShow = new TVShow($show);
return $embed_cast === true ? [$TVShow, $cast] : [$TVShow];
}
|
[
"public",
"function",
"getShowByShowID",
"(",
"$",
"ID",
",",
"$",
"embed_cast",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"embed_cast",
"===",
"true",
")",
"{",
"$",
"url",
"=",
"self",
"::",
"APIURL",
".",
"'/shows/'",
".",
"$",
"ID",
".",
"'?embed=cast'",
";",
"}",
"else",
"{",
"$",
"url",
"=",
"self",
"::",
"APIURL",
".",
"'/shows/'",
".",
"$",
"ID",
";",
"}",
"$",
"show",
"=",
"$",
"this",
"->",
"getFile",
"(",
"$",
"url",
")",
";",
"$",
"cast",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"show",
"[",
"'_embedded'",
"]",
"[",
"'cast'",
"]",
"as",
"$",
"person",
")",
"{",
"$",
"actor",
"=",
"new",
"Actor",
"(",
"$",
"person",
"[",
"'person'",
"]",
")",
";",
"$",
"character",
"=",
"new",
"Character",
"(",
"$",
"person",
"[",
"'character'",
"]",
")",
";",
"$",
"cast",
"[",
"]",
"=",
"[",
"$",
"actor",
",",
"$",
"character",
"]",
";",
"}",
"$",
"TVShow",
"=",
"new",
"TVShow",
"(",
"$",
"show",
")",
";",
"return",
"$",
"embed_cast",
"===",
"true",
"?",
"[",
"$",
"TVShow",
",",
"$",
"cast",
"]",
":",
"[",
"$",
"TVShow",
"]",
";",
"}"
] |
Takes in a show ID and outputs the TVShow Object
@param $ID
@param null $embed_cast
@return array
|
[
"Takes",
"in",
"a",
"show",
"ID",
"and",
"outputs",
"the",
"TVShow",
"Object"
] |
174429341ef2009a42f77743faa342726d7d8467
|
https://github.com/JPinkney/TVMaze-PHP-API-Wrapper/blob/174429341ef2009a42f77743faa342726d7d8467/TVMaze/TVMaze.php#L154-L173
|
231,442
|
JPinkney/TVMaze-PHP-API-Wrapper
|
TVMaze/TVMaze.php
|
TVMaze.getShowAKAs
|
public function getShowAKAs($ID)
{
$url = self::APIURL . '/shows/' . $ID . '/akas';
$akas = $this->getFile($url);
$AKA = new AKA($akas);
if (!empty($akas['name'])) {
return $AKA;
}
return false;
}
|
php
|
public function getShowAKAs($ID)
{
$url = self::APIURL . '/shows/' . $ID . '/akas';
$akas = $this->getFile($url);
$AKA = new AKA($akas);
if (!empty($akas['name'])) {
return $AKA;
}
return false;
}
|
[
"public",
"function",
"getShowAKAs",
"(",
"$",
"ID",
")",
"{",
"$",
"url",
"=",
"self",
"::",
"APIURL",
".",
"'/shows/'",
".",
"$",
"ID",
".",
"'/akas'",
";",
"$",
"akas",
"=",
"$",
"this",
"->",
"getFile",
"(",
"$",
"url",
")",
";",
"$",
"AKA",
"=",
"new",
"AKA",
"(",
"$",
"akas",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"akas",
"[",
"'name'",
"]",
")",
")",
"{",
"return",
"$",
"AKA",
";",
"}",
"return",
"false",
";",
"}"
] |
Takes in a show ID and outputs the AKA Object
@param $ID
@return bool|\JPinkney\TVMaze\AKA
|
[
"Takes",
"in",
"a",
"show",
"ID",
"and",
"outputs",
"the",
"AKA",
"Object"
] |
174429341ef2009a42f77743faa342726d7d8467
|
https://github.com/JPinkney/TVMaze-PHP-API-Wrapper/blob/174429341ef2009a42f77743faa342726d7d8467/TVMaze/TVMaze.php#L183-L197
|
231,443
|
JPinkney/TVMaze-PHP-API-Wrapper
|
TVMaze/TVMaze.php
|
TVMaze.getEpisodesByShowID
|
public function getEpisodesByShowID($ID){
$url = self::APIURL.'/shows/'.$ID.'/episodes';
$episodes = $this->getFile($url);
$allEpisodes = [];
foreach($episodes as $episode){
$ep = new Episode($episode);
$allEpisodes[] = $ep;
}
return $allEpisodes;
}
|
php
|
public function getEpisodesByShowID($ID){
$url = self::APIURL.'/shows/'.$ID.'/episodes';
$episodes = $this->getFile($url);
$allEpisodes = [];
foreach($episodes as $episode){
$ep = new Episode($episode);
$allEpisodes[] = $ep;
}
return $allEpisodes;
}
|
[
"public",
"function",
"getEpisodesByShowID",
"(",
"$",
"ID",
")",
"{",
"$",
"url",
"=",
"self",
"::",
"APIURL",
".",
"'/shows/'",
".",
"$",
"ID",
".",
"'/episodes'",
";",
"$",
"episodes",
"=",
"$",
"this",
"->",
"getFile",
"(",
"$",
"url",
")",
";",
"$",
"allEpisodes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"episodes",
"as",
"$",
"episode",
")",
"{",
"$",
"ep",
"=",
"new",
"Episode",
"(",
"$",
"episode",
")",
";",
"$",
"allEpisodes",
"[",
"]",
"=",
"$",
"ep",
";",
"}",
"return",
"$",
"allEpisodes",
";",
"}"
] |
Takes in a show ID and outputs all the episode objects for that show in an array
@param $ID
@return array
|
[
"Takes",
"in",
"a",
"show",
"ID",
"and",
"outputs",
"all",
"the",
"episode",
"objects",
"for",
"that",
"show",
"in",
"an",
"array"
] |
174429341ef2009a42f77743faa342726d7d8467
|
https://github.com/JPinkney/TVMaze-PHP-API-Wrapper/blob/174429341ef2009a42f77743faa342726d7d8467/TVMaze/TVMaze.php#L206-L219
|
231,444
|
JPinkney/TVMaze-PHP-API-Wrapper
|
TVMaze/TVMaze.php
|
TVMaze.getEpisodeByNumber
|
public function getEpisodeByNumber($ID, $season, $episode)
{
$ep = false;
$url = self::APIURL . '/shows/' . $ID . '/episodebynumber?season='. $season . '&number=' . $episode;
$response = $this->getFile($url);
if (is_array($response)) {
$ep = new Episode($response);
}
return $ep;
}
|
php
|
public function getEpisodeByNumber($ID, $season, $episode)
{
$ep = false;
$url = self::APIURL . '/shows/' . $ID . '/episodebynumber?season='. $season . '&number=' . $episode;
$response = $this->getFile($url);
if (is_array($response)) {
$ep = new Episode($response);
}
return $ep;
}
|
[
"public",
"function",
"getEpisodeByNumber",
"(",
"$",
"ID",
",",
"$",
"season",
",",
"$",
"episode",
")",
"{",
"$",
"ep",
"=",
"false",
";",
"$",
"url",
"=",
"self",
"::",
"APIURL",
".",
"'/shows/'",
".",
"$",
"ID",
".",
"'/episodebynumber?season='",
".",
"$",
"season",
".",
"'&number='",
".",
"$",
"episode",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"getFile",
"(",
"$",
"url",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"response",
")",
")",
"{",
"$",
"ep",
"=",
"new",
"Episode",
"(",
"$",
"response",
")",
";",
"}",
"return",
"$",
"ep",
";",
"}"
] |
Returns a single episodes information by its show ID, season and episode numbers
@param $ID
@param $season
@param $episode
@return Episode|mixed
|
[
"Returns",
"a",
"single",
"episodes",
"information",
"by",
"its",
"show",
"ID",
"season",
"and",
"episode",
"numbers"
] |
174429341ef2009a42f77743faa342726d7d8467
|
https://github.com/JPinkney/TVMaze-PHP-API-Wrapper/blob/174429341ef2009a42f77743faa342726d7d8467/TVMaze/TVMaze.php#L230-L239
|
231,445
|
JPinkney/TVMaze-PHP-API-Wrapper
|
TVMaze/TVMaze.php
|
TVMaze.getEpisodesByAirdate
|
public function getEpisodesByAirdate($ID, $airdate)
{
$url = self::APIURL . '/shows/' . $ID . '/episodesbydate?date=' . date('Y-m-d', strtotime($airdate));
$episodes = $this->getFile($url);
$allEpisodes = [];
if (is_array($episodes)) {
foreach ($episodes as $episode) {
$ep = new Episode($episode);
$allEpisodes[] = $ep;
}
}
return $allEpisodes;
}
|
php
|
public function getEpisodesByAirdate($ID, $airdate)
{
$url = self::APIURL . '/shows/' . $ID . '/episodesbydate?date=' . date('Y-m-d', strtotime($airdate));
$episodes = $this->getFile($url);
$allEpisodes = [];
if (is_array($episodes)) {
foreach ($episodes as $episode) {
$ep = new Episode($episode);
$allEpisodes[] = $ep;
}
}
return $allEpisodes;
}
|
[
"public",
"function",
"getEpisodesByAirdate",
"(",
"$",
"ID",
",",
"$",
"airdate",
")",
"{",
"$",
"url",
"=",
"self",
"::",
"APIURL",
".",
"'/shows/'",
".",
"$",
"ID",
".",
"'/episodesbydate?date='",
".",
"date",
"(",
"'Y-m-d'",
",",
"strtotime",
"(",
"$",
"airdate",
")",
")",
";",
"$",
"episodes",
"=",
"$",
"this",
"->",
"getFile",
"(",
"$",
"url",
")",
";",
"$",
"allEpisodes",
"=",
"[",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"episodes",
")",
")",
"{",
"foreach",
"(",
"$",
"episodes",
"as",
"$",
"episode",
")",
"{",
"$",
"ep",
"=",
"new",
"Episode",
"(",
"$",
"episode",
")",
";",
"$",
"allEpisodes",
"[",
"]",
"=",
"$",
"ep",
";",
"}",
"}",
"return",
"$",
"allEpisodes",
";",
"}"
] |
Returns episodes for a given show ID and ISO 8601 airdate
@param $ID
@param $airdate
@return Episode|mixed
|
[
"Returns",
"episodes",
"for",
"a",
"given",
"show",
"ID",
"and",
"ISO",
"8601",
"airdate"
] |
174429341ef2009a42f77743faa342726d7d8467
|
https://github.com/JPinkney/TVMaze-PHP-API-Wrapper/blob/174429341ef2009a42f77743faa342726d7d8467/TVMaze/TVMaze.php#L249-L262
|
231,446
|
JPinkney/TVMaze-PHP-API-Wrapper
|
TVMaze/TVMaze.php
|
TVMaze.getPersonByID
|
public function getPersonByID($ID){
$url = self::APIURL.'/people/'.$ID;
$show = $this->getFile($url);
return new Actor($show);
}
|
php
|
public function getPersonByID($ID){
$url = self::APIURL.'/people/'.$ID;
$show = $this->getFile($url);
return new Actor($show);
}
|
[
"public",
"function",
"getPersonByID",
"(",
"$",
"ID",
")",
"{",
"$",
"url",
"=",
"self",
"::",
"APIURL",
".",
"'/people/'",
".",
"$",
"ID",
";",
"$",
"show",
"=",
"$",
"this",
"->",
"getFile",
"(",
"$",
"url",
")",
";",
"return",
"new",
"Actor",
"(",
"$",
"show",
")",
";",
"}"
] |
Gets an actor by their ID
@param $ID
@return Actor
|
[
"Gets",
"an",
"actor",
"by",
"their",
"ID"
] |
174429341ef2009a42f77743faa342726d7d8467
|
https://github.com/JPinkney/TVMaze-PHP-API-Wrapper/blob/174429341ef2009a42f77743faa342726d7d8467/TVMaze/TVMaze.php#L316-L320
|
231,447
|
JPinkney/TVMaze-PHP-API-Wrapper
|
TVMaze/TVMaze.php
|
TVMaze.getCastCreditsByID
|
public function getCastCreditsByID($ID){
$url = self::APIURL.'/people/'.$ID.'/castcredits?embed=show';
$castCredit = $this->getFile($url);
$shows_appeared = [];
foreach($castCredit as $series){
$TVShow = new TVShow($series['_embedded']['show']);
$shows_appeared[] = $TVShow;
}
return $shows_appeared;
}
|
php
|
public function getCastCreditsByID($ID){
$url = self::APIURL.'/people/'.$ID.'/castcredits?embed=show';
$castCredit = $this->getFile($url);
$shows_appeared = [];
foreach($castCredit as $series){
$TVShow = new TVShow($series['_embedded']['show']);
$shows_appeared[] = $TVShow;
}
return $shows_appeared;
}
|
[
"public",
"function",
"getCastCreditsByID",
"(",
"$",
"ID",
")",
"{",
"$",
"url",
"=",
"self",
"::",
"APIURL",
".",
"'/people/'",
".",
"$",
"ID",
".",
"'/castcredits?embed=show'",
";",
"$",
"castCredit",
"=",
"$",
"this",
"->",
"getFile",
"(",
"$",
"url",
")",
";",
"$",
"shows_appeared",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"castCredit",
"as",
"$",
"series",
")",
"{",
"$",
"TVShow",
"=",
"new",
"TVShow",
"(",
"$",
"series",
"[",
"'_embedded'",
"]",
"[",
"'show'",
"]",
")",
";",
"$",
"shows_appeared",
"[",
"]",
"=",
"$",
"TVShow",
";",
"}",
"return",
"$",
"shows_appeared",
";",
"}"
] |
Gets an array of all the shows a particular actor has been in
@param $ID
@return array
|
[
"Gets",
"an",
"array",
"of",
"all",
"the",
"shows",
"a",
"particular",
"actor",
"has",
"been",
"in"
] |
174429341ef2009a42f77743faa342726d7d8467
|
https://github.com/JPinkney/TVMaze-PHP-API-Wrapper/blob/174429341ef2009a42f77743faa342726d7d8467/TVMaze/TVMaze.php#L329-L339
|
231,448
|
JPinkney/TVMaze-PHP-API-Wrapper
|
TVMaze/TVMaze.php
|
TVMaze.getCrewCreditsByID
|
public function getCrewCreditsByID($ID){
$url = self::APIURL.'/people/'.$ID.'/crewcredits?embed=show';
$crewCredit = $this->getFile($url);
$shows_appeared = [];
foreach($crewCredit as $series){
$position = $series['type'];
$TVShow = new TVShow($series['_embedded']['show']);
$shows_appeared[] = [$position, $TVShow];
}
return $shows_appeared;
}
|
php
|
public function getCrewCreditsByID($ID){
$url = self::APIURL.'/people/'.$ID.'/crewcredits?embed=show';
$crewCredit = $this->getFile($url);
$shows_appeared = [];
foreach($crewCredit as $series){
$position = $series['type'];
$TVShow = new TVShow($series['_embedded']['show']);
$shows_appeared[] = [$position, $TVShow];
}
return $shows_appeared;
}
|
[
"public",
"function",
"getCrewCreditsByID",
"(",
"$",
"ID",
")",
"{",
"$",
"url",
"=",
"self",
"::",
"APIURL",
".",
"'/people/'",
".",
"$",
"ID",
".",
"'/crewcredits?embed=show'",
";",
"$",
"crewCredit",
"=",
"$",
"this",
"->",
"getFile",
"(",
"$",
"url",
")",
";",
"$",
"shows_appeared",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"crewCredit",
"as",
"$",
"series",
")",
"{",
"$",
"position",
"=",
"$",
"series",
"[",
"'type'",
"]",
";",
"$",
"TVShow",
"=",
"new",
"TVShow",
"(",
"$",
"series",
"[",
"'_embedded'",
"]",
"[",
"'show'",
"]",
")",
";",
"$",
"shows_appeared",
"[",
"]",
"=",
"[",
"$",
"position",
",",
"$",
"TVShow",
"]",
";",
"}",
"return",
"$",
"shows_appeared",
";",
"}"
] |
Gets the position worked at the tv show in a tuple with the tvshow
@param $ID
@return array
|
[
"Gets",
"the",
"position",
"worked",
"at",
"the",
"tv",
"show",
"in",
"a",
"tuple",
"with",
"the",
"tvshow"
] |
174429341ef2009a42f77743faa342726d7d8467
|
https://github.com/JPinkney/TVMaze-PHP-API-Wrapper/blob/174429341ef2009a42f77743faa342726d7d8467/TVMaze/TVMaze.php#L348-L359
|
231,449
|
JPinkney/TVMaze-PHP-API-Wrapper
|
TVMaze/TVMaze.php
|
TVMaze.getFile
|
private function getFile($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
$response = json_decode($result, TRUE);
if (is_array($response) && count($response) > 0 && (!isset($response['status']) || $response['status'] != '404')) {
return $response;
}
return false;
}
|
php
|
private function getFile($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
$response = json_decode($result, TRUE);
if (is_array($response) && count($response) > 0 && (!isset($response['status']) || $response['status'] != '404')) {
return $response;
}
return false;
}
|
[
"private",
"function",
"getFile",
"(",
"$",
"url",
")",
"{",
"$",
"ch",
"=",
"curl_init",
"(",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_HEADER",
",",
"false",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_FOLLOWLOCATION",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_URL",
",",
"$",
"url",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_RETURNTRANSFER",
",",
"TRUE",
")",
";",
"$",
"result",
"=",
"curl_exec",
"(",
"$",
"ch",
")",
";",
"curl_close",
"(",
"$",
"ch",
")",
";",
"$",
"response",
"=",
"json_decode",
"(",
"$",
"result",
",",
"TRUE",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"response",
")",
"&&",
"count",
"(",
"$",
"response",
")",
">",
"0",
"&&",
"(",
"!",
"isset",
"(",
"$",
"response",
"[",
"'status'",
"]",
")",
"||",
"$",
"response",
"[",
"'status'",
"]",
"!=",
"'404'",
")",
")",
"{",
"return",
"$",
"response",
";",
"}",
"return",
"false",
";",
"}"
] |
Function used to get the data from the URL and return the results in an array
@param $url
@return mixed
|
[
"Function",
"used",
"to",
"get",
"the",
"data",
"from",
"the",
"URL",
"and",
"return",
"the",
"results",
"in",
"an",
"array"
] |
174429341ef2009a42f77743faa342726d7d8467
|
https://github.com/JPinkney/TVMaze-PHP-API-Wrapper/blob/174429341ef2009a42f77743faa342726d7d8467/TVMaze/TVMaze.php#L368-L384
|
231,450
|
swoft-cloud/swoft-http-client
|
src/Adapter/CurlAdapter.php
|
CurlAdapter.getDefaultUserAgent
|
public function getDefaultUserAgent(): string
{
$defaultAgent = 'Swoft/' . App::version();
if (\extension_loaded('curl') && \function_exists('curl_version')) {
$defaultAgent .= ' curl/' . \curl_version()['version'];
}
$defaultAgent .= ' PHP/' . PHP_VERSION;
return $defaultAgent;
}
|
php
|
public function getDefaultUserAgent(): string
{
$defaultAgent = 'Swoft/' . App::version();
if (\extension_loaded('curl') && \function_exists('curl_version')) {
$defaultAgent .= ' curl/' . \curl_version()['version'];
}
$defaultAgent .= ' PHP/' . PHP_VERSION;
return $defaultAgent;
}
|
[
"public",
"function",
"getDefaultUserAgent",
"(",
")",
":",
"string",
"{",
"$",
"defaultAgent",
"=",
"'Swoft/'",
".",
"App",
"::",
"version",
"(",
")",
";",
"if",
"(",
"\\",
"extension_loaded",
"(",
"'curl'",
")",
"&&",
"\\",
"function_exists",
"(",
"'curl_version'",
")",
")",
"{",
"$",
"defaultAgent",
".=",
"' curl/'",
".",
"\\",
"curl_version",
"(",
")",
"[",
"'version'",
"]",
";",
"}",
"$",
"defaultAgent",
".=",
"' PHP/'",
".",
"PHP_VERSION",
";",
"return",
"$",
"defaultAgent",
";",
"}"
] |
Get the adapter User-Agent string
@return string
|
[
"Get",
"the",
"adapter",
"User",
"-",
"Agent",
"string"
] |
980ac3701cc100ec605ccb5f7e974861f900d0e9
|
https://github.com/swoft-cloud/swoft-http-client/blob/980ac3701cc100ec605ccb5f7e974861f900d0e9/src/Adapter/CurlAdapter.php#L247-L255
|
231,451
|
shutterstock/presto
|
src/Shutterstock/Presto/Response.php
|
Response.parseHeader
|
public function parseHeader($header)
{
$parsed_header = array();
$header_lines = explode("\r\n", $header);
if (count($header_lines) > 0) {
foreach ($header_lines as $line) {
$header = explode(':', $line);
if (count($header) > 1) {
$label = array_shift($header);
$value = $header;
$value = implode(':', $header);
$value = trim($value);
$parsed_header[$label] = $value;
}
}
}
return $parsed_header;
}
|
php
|
public function parseHeader($header)
{
$parsed_header = array();
$header_lines = explode("\r\n", $header);
if (count($header_lines) > 0) {
foreach ($header_lines as $line) {
$header = explode(':', $line);
if (count($header) > 1) {
$label = array_shift($header);
$value = $header;
$value = implode(':', $header);
$value = trim($value);
$parsed_header[$label] = $value;
}
}
}
return $parsed_header;
}
|
[
"public",
"function",
"parseHeader",
"(",
"$",
"header",
")",
"{",
"$",
"parsed_header",
"=",
"array",
"(",
")",
";",
"$",
"header_lines",
"=",
"explode",
"(",
"\"\\r\\n\"",
",",
"$",
"header",
")",
";",
"if",
"(",
"count",
"(",
"$",
"header_lines",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"header_lines",
"as",
"$",
"line",
")",
"{",
"$",
"header",
"=",
"explode",
"(",
"':'",
",",
"$",
"line",
")",
";",
"if",
"(",
"count",
"(",
"$",
"header",
")",
">",
"1",
")",
"{",
"$",
"label",
"=",
"array_shift",
"(",
"$",
"header",
")",
";",
"$",
"value",
"=",
"$",
"header",
";",
"$",
"value",
"=",
"implode",
"(",
"':'",
",",
"$",
"header",
")",
";",
"$",
"value",
"=",
"trim",
"(",
"$",
"value",
")",
";",
"$",
"parsed_header",
"[",
"$",
"label",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"return",
"$",
"parsed_header",
";",
"}"
] |
Parse response headers into an array
@param string $header headers from request
@return array parsed header array
|
[
"Parse",
"response",
"headers",
"into",
"an",
"array"
] |
5e030a24ac669f43b84c3a30e1217d08fb3ea6be
|
https://github.com/shutterstock/presto/blob/5e030a24ac669f43b84c3a30e1217d08fb3ea6be/src/Shutterstock/Presto/Response.php#L80-L101
|
231,452
|
Oryzone/PHPoAuthUserData
|
src/OAuth/UserData/Extractor/LazyExtractor.php
|
LazyExtractor.getDefaultNormalizersMap
|
protected static function getDefaultNormalizersMap()
{
return array(
self::FIELD_UNIQUE_ID => self::FIELD_UNIQUE_ID,
self::FIELD_USERNAME => self::FIELD_USERNAME,
self::FIELD_FIRST_NAME => self::FIELD_FIRST_NAME,
self::FIELD_LAST_NAME => self::FIELD_LAST_NAME,
self::FIELD_FULL_NAME => self::FIELD_FULL_NAME,
self::FIELD_EMAIL => self::FIELD_EMAIL,
self::FIELD_DESCRIPTION => self::FIELD_DESCRIPTION,
self::FIELD_LOCATION => self::FIELD_LOCATION,
self::FIELD_PROFILE_URL => self::FIELD_PROFILE_URL,
self::FIELD_IMAGE_URL => self::FIELD_IMAGE_URL,
self::FIELD_WEBSITES => self::FIELD_WEBSITES,
self::FIELD_VERIFIED_EMAIL => self::FIELD_VERIFIED_EMAIL,
self::FIELD_EXTRA => self::FIELD_EXTRA,
);
}
|
php
|
protected static function getDefaultNormalizersMap()
{
return array(
self::FIELD_UNIQUE_ID => self::FIELD_UNIQUE_ID,
self::FIELD_USERNAME => self::FIELD_USERNAME,
self::FIELD_FIRST_NAME => self::FIELD_FIRST_NAME,
self::FIELD_LAST_NAME => self::FIELD_LAST_NAME,
self::FIELD_FULL_NAME => self::FIELD_FULL_NAME,
self::FIELD_EMAIL => self::FIELD_EMAIL,
self::FIELD_DESCRIPTION => self::FIELD_DESCRIPTION,
self::FIELD_LOCATION => self::FIELD_LOCATION,
self::FIELD_PROFILE_URL => self::FIELD_PROFILE_URL,
self::FIELD_IMAGE_URL => self::FIELD_IMAGE_URL,
self::FIELD_WEBSITES => self::FIELD_WEBSITES,
self::FIELD_VERIFIED_EMAIL => self::FIELD_VERIFIED_EMAIL,
self::FIELD_EXTRA => self::FIELD_EXTRA,
);
}
|
[
"protected",
"static",
"function",
"getDefaultNormalizersMap",
"(",
")",
"{",
"return",
"array",
"(",
"self",
"::",
"FIELD_UNIQUE_ID",
"=>",
"self",
"::",
"FIELD_UNIQUE_ID",
",",
"self",
"::",
"FIELD_USERNAME",
"=>",
"self",
"::",
"FIELD_USERNAME",
",",
"self",
"::",
"FIELD_FIRST_NAME",
"=>",
"self",
"::",
"FIELD_FIRST_NAME",
",",
"self",
"::",
"FIELD_LAST_NAME",
"=>",
"self",
"::",
"FIELD_LAST_NAME",
",",
"self",
"::",
"FIELD_FULL_NAME",
"=>",
"self",
"::",
"FIELD_FULL_NAME",
",",
"self",
"::",
"FIELD_EMAIL",
"=>",
"self",
"::",
"FIELD_EMAIL",
",",
"self",
"::",
"FIELD_DESCRIPTION",
"=>",
"self",
"::",
"FIELD_DESCRIPTION",
",",
"self",
"::",
"FIELD_LOCATION",
"=>",
"self",
"::",
"FIELD_LOCATION",
",",
"self",
"::",
"FIELD_PROFILE_URL",
"=>",
"self",
"::",
"FIELD_PROFILE_URL",
",",
"self",
"::",
"FIELD_IMAGE_URL",
"=>",
"self",
"::",
"FIELD_IMAGE_URL",
",",
"self",
"::",
"FIELD_WEBSITES",
"=>",
"self",
"::",
"FIELD_WEBSITES",
",",
"self",
"::",
"FIELD_VERIFIED_EMAIL",
"=>",
"self",
"::",
"FIELD_VERIFIED_EMAIL",
",",
"self",
"::",
"FIELD_EXTRA",
"=>",
"self",
"::",
"FIELD_EXTRA",
",",
")",
";",
"}"
] |
Get a default normalizers map
@return array
|
[
"Get",
"a",
"default",
"normalizers",
"map"
] |
4f7a3aa482544765c7ffd6a24f5ee01f05b66d2b
|
https://github.com/Oryzone/PHPoAuthUserData/blob/4f7a3aa482544765c7ffd6a24f5ee01f05b66d2b/src/OAuth/UserData/Extractor/LazyExtractor.php#L139-L156
|
231,453
|
PaymentSuite/paymentsuite
|
src/PaymentSuite/PaylandsBundle/Services/PaylandsApiAdapter.php
|
PaylandsApiAdapter.createTransaction
|
public function createTransaction(PaylandsMethod $paymentMethod)
{
$paymentOrder = $this->client->createPayment(
$paymentMethod->getCustomerExternalId(),
$this->paymentBridge->getAmount(),
(string)$this->paymentBridge->getOrder(),
$this->currencyServiceResolver->getService()
);
$transaction = $this->client->directPayment(
$this->requestStack->getMasterRequest()->getClientIp(),
$paymentOrder['order']['uuid'],
$paymentMethod->getCardUuid()
);
$paymentMethod
->setPaymentStatus($transaction['order']['paid'] ? PaylandsMethod::STATUS_OK : PaylandsMethod::STATUS_KO)
->setPaymentResult($transaction);
}
|
php
|
public function createTransaction(PaylandsMethod $paymentMethod)
{
$paymentOrder = $this->client->createPayment(
$paymentMethod->getCustomerExternalId(),
$this->paymentBridge->getAmount(),
(string)$this->paymentBridge->getOrder(),
$this->currencyServiceResolver->getService()
);
$transaction = $this->client->directPayment(
$this->requestStack->getMasterRequest()->getClientIp(),
$paymentOrder['order']['uuid'],
$paymentMethod->getCardUuid()
);
$paymentMethod
->setPaymentStatus($transaction['order']['paid'] ? PaylandsMethod::STATUS_OK : PaylandsMethod::STATUS_KO)
->setPaymentResult($transaction);
}
|
[
"public",
"function",
"createTransaction",
"(",
"PaylandsMethod",
"$",
"paymentMethod",
")",
"{",
"$",
"paymentOrder",
"=",
"$",
"this",
"->",
"client",
"->",
"createPayment",
"(",
"$",
"paymentMethod",
"->",
"getCustomerExternalId",
"(",
")",
",",
"$",
"this",
"->",
"paymentBridge",
"->",
"getAmount",
"(",
")",
",",
"(",
"string",
")",
"$",
"this",
"->",
"paymentBridge",
"->",
"getOrder",
"(",
")",
",",
"$",
"this",
"->",
"currencyServiceResolver",
"->",
"getService",
"(",
")",
")",
";",
"$",
"transaction",
"=",
"$",
"this",
"->",
"client",
"->",
"directPayment",
"(",
"$",
"this",
"->",
"requestStack",
"->",
"getMasterRequest",
"(",
")",
"->",
"getClientIp",
"(",
")",
",",
"$",
"paymentOrder",
"[",
"'order'",
"]",
"[",
"'uuid'",
"]",
",",
"$",
"paymentMethod",
"->",
"getCardUuid",
"(",
")",
")",
";",
"$",
"paymentMethod",
"->",
"setPaymentStatus",
"(",
"$",
"transaction",
"[",
"'order'",
"]",
"[",
"'paid'",
"]",
"?",
"PaylandsMethod",
"::",
"STATUS_OK",
":",
"PaylandsMethod",
"::",
"STATUS_KO",
")",
"->",
"setPaymentResult",
"(",
"$",
"transaction",
")",
";",
"}"
] |
Sends the payment order to Paylands.
@param PaylandsMethod $paymentMethod
|
[
"Sends",
"the",
"payment",
"order",
"to",
"Paylands",
"."
] |
8ae57df57fa07aff7e59701a0b3c83c504095b92
|
https://github.com/PaymentSuite/paymentsuite/blob/8ae57df57fa07aff7e59701a0b3c83c504095b92/src/PaymentSuite/PaylandsBundle/Services/PaylandsApiAdapter.php#L74-L92
|
231,454
|
PaymentSuite/paymentsuite
|
src/PaymentSuite/PaylandsBundle/Services/PaylandsApiAdapter.php
|
PaylandsApiAdapter.validateCard
|
public function validateCard(PaylandsMethod $paymentMethod)
{
$response = $this->client->retrieveCustomerCards($paymentMethod->getCustomerExternalId());
foreach ($response['cards'] as $card) {
if ($paymentMethod->getCardUuid() == $card['uuid']) {
$paymentMethod
->setPaymentStatus(PaylandsMethod::STATUS_OK)
->setPaymentResult($response);
return;
}
}
throw new CardNotFoundException(sprintf('Card %s not found for customer %s',
$paymentMethod->getCardUuid(),
$paymentMethod->getCustomerExternalId()
));
}
|
php
|
public function validateCard(PaylandsMethod $paymentMethod)
{
$response = $this->client->retrieveCustomerCards($paymentMethod->getCustomerExternalId());
foreach ($response['cards'] as $card) {
if ($paymentMethod->getCardUuid() == $card['uuid']) {
$paymentMethod
->setPaymentStatus(PaylandsMethod::STATUS_OK)
->setPaymentResult($response);
return;
}
}
throw new CardNotFoundException(sprintf('Card %s not found for customer %s',
$paymentMethod->getCardUuid(),
$paymentMethod->getCustomerExternalId()
));
}
|
[
"public",
"function",
"validateCard",
"(",
"PaylandsMethod",
"$",
"paymentMethod",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"retrieveCustomerCards",
"(",
"$",
"paymentMethod",
"->",
"getCustomerExternalId",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"response",
"[",
"'cards'",
"]",
"as",
"$",
"card",
")",
"{",
"if",
"(",
"$",
"paymentMethod",
"->",
"getCardUuid",
"(",
")",
"==",
"$",
"card",
"[",
"'uuid'",
"]",
")",
"{",
"$",
"paymentMethod",
"->",
"setPaymentStatus",
"(",
"PaylandsMethod",
"::",
"STATUS_OK",
")",
"->",
"setPaymentResult",
"(",
"$",
"response",
")",
";",
"return",
";",
"}",
"}",
"throw",
"new",
"CardNotFoundException",
"(",
"sprintf",
"(",
"'Card %s not found for customer %s'",
",",
"$",
"paymentMethod",
"->",
"getCardUuid",
"(",
")",
",",
"$",
"paymentMethod",
"->",
"getCustomerExternalId",
"(",
")",
")",
")",
";",
"}"
] |
Validates against Paylands that the card is associates with customer.
@param PaylandsMethod $paymentMethod
@throws CardNotFoundException
|
[
"Validates",
"against",
"Paylands",
"that",
"the",
"card",
"is",
"associates",
"with",
"customer",
"."
] |
8ae57df57fa07aff7e59701a0b3c83c504095b92
|
https://github.com/PaymentSuite/paymentsuite/blob/8ae57df57fa07aff7e59701a0b3c83c504095b92/src/PaymentSuite/PaylandsBundle/Services/PaylandsApiAdapter.php#L101-L119
|
231,455
|
shutterstock/presto
|
src/Shutterstock/Presto/Presto.php
|
Presto.setAuth
|
public function setAuth($username, $password, $auth_type = null)
{
if (is_null($auth_type)) {
$auth_type = CURLAUTH_BASIC;
}
$this->curl_opts[CURLOPT_HTTPAUTH] = $auth_type;
$this->curl_opts[CURLOPT_USERPWD] = "{$username}:{$password}";
}
|
php
|
public function setAuth($username, $password, $auth_type = null)
{
if (is_null($auth_type)) {
$auth_type = CURLAUTH_BASIC;
}
$this->curl_opts[CURLOPT_HTTPAUTH] = $auth_type;
$this->curl_opts[CURLOPT_USERPWD] = "{$username}:{$password}";
}
|
[
"public",
"function",
"setAuth",
"(",
"$",
"username",
",",
"$",
"password",
",",
"$",
"auth_type",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"auth_type",
")",
")",
"{",
"$",
"auth_type",
"=",
"CURLAUTH_BASIC",
";",
"}",
"$",
"this",
"->",
"curl_opts",
"[",
"CURLOPT_HTTPAUTH",
"]",
"=",
"$",
"auth_type",
";",
"$",
"this",
"->",
"curl_opts",
"[",
"CURLOPT_USERPWD",
"]",
"=",
"\"{$username}:{$password}\"",
";",
"}"
] |
Authorization method and options to use
@param string $username user name to use
@param string $password password to use
@param string $auth_type authentication method to use
|
[
"Authorization",
"method",
"and",
"options",
"to",
"use"
] |
5e030a24ac669f43b84c3a30e1217d08fb3ea6be
|
https://github.com/shutterstock/presto/blob/5e030a24ac669f43b84c3a30e1217d08fb3ea6be/src/Shutterstock/Presto/Presto.php#L203-L211
|
231,456
|
shutterstock/presto
|
src/Shutterstock/Presto/Presto.php
|
Presto.setHeaders
|
public function setHeaders(array $headers, $overwrite_existing = false)
{
if ($overwrite_existing) {
$this->curl_opts[CURLOPT_HTTPHEADER] = $headers;
} else {
$this->curl_opts[CURLOPT_HTTPHEADER] = array_merge(
$this->curl_opts[CURLOPT_HTTPHEADER],
$headers
);
}
}
|
php
|
public function setHeaders(array $headers, $overwrite_existing = false)
{
if ($overwrite_existing) {
$this->curl_opts[CURLOPT_HTTPHEADER] = $headers;
} else {
$this->curl_opts[CURLOPT_HTTPHEADER] = array_merge(
$this->curl_opts[CURLOPT_HTTPHEADER],
$headers
);
}
}
|
[
"public",
"function",
"setHeaders",
"(",
"array",
"$",
"headers",
",",
"$",
"overwrite_existing",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"overwrite_existing",
")",
"{",
"$",
"this",
"->",
"curl_opts",
"[",
"CURLOPT_HTTPHEADER",
"]",
"=",
"$",
"headers",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"curl_opts",
"[",
"CURLOPT_HTTPHEADER",
"]",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"curl_opts",
"[",
"CURLOPT_HTTPHEADER",
"]",
",",
"$",
"headers",
")",
";",
"}",
"}"
] |
Set custom headers, with optional overwrite of existing
@param array $headers key/value list of headers to set
@param boolean $overwrite_existing whether to merge or overwrite existing headers
|
[
"Set",
"custom",
"headers",
"with",
"optional",
"overwrite",
"of",
"existing"
] |
5e030a24ac669f43b84c3a30e1217d08fb3ea6be
|
https://github.com/shutterstock/presto/blob/5e030a24ac669f43b84c3a30e1217d08fb3ea6be/src/Shutterstock/Presto/Presto.php#L229-L239
|
231,457
|
shutterstock/presto
|
src/Shutterstock/Presto/Presto.php
|
Presto.queueRequest
|
public function queueRequest($handle, $url, $callback)
{
if (!is_resource(self::$queue_handle)) {
self::initQueue();
}
self::$request_queue[] = array(
'url' => $url,
'handle' => $handle,
'callback' => $callback,
'response' => '',
);
curl_multi_add_handle(self::$queue_handle, $handle);
}
|
php
|
public function queueRequest($handle, $url, $callback)
{
if (!is_resource(self::$queue_handle)) {
self::initQueue();
}
self::$request_queue[] = array(
'url' => $url,
'handle' => $handle,
'callback' => $callback,
'response' => '',
);
curl_multi_add_handle(self::$queue_handle, $handle);
}
|
[
"public",
"function",
"queueRequest",
"(",
"$",
"handle",
",",
"$",
"url",
",",
"$",
"callback",
")",
"{",
"if",
"(",
"!",
"is_resource",
"(",
"self",
"::",
"$",
"queue_handle",
")",
")",
"{",
"self",
"::",
"initQueue",
"(",
")",
";",
"}",
"self",
"::",
"$",
"request_queue",
"[",
"]",
"=",
"array",
"(",
"'url'",
"=>",
"$",
"url",
",",
"'handle'",
"=>",
"$",
"handle",
",",
"'callback'",
"=>",
"$",
"callback",
",",
"'response'",
"=>",
"''",
",",
")",
";",
"curl_multi_add_handle",
"(",
"self",
"::",
"$",
"queue_handle",
",",
"$",
"handle",
")",
";",
"}"
] |
Queue a request for processing when doing simultaneous requests
@param object $handle curl handle for the reqeust
@param string $url URL to use for the request
@param object $callback function to call after request is processed
|
[
"Queue",
"a",
"request",
"for",
"processing",
"when",
"doing",
"simultaneous",
"requests"
] |
5e030a24ac669f43b84c3a30e1217d08fb3ea6be
|
https://github.com/shutterstock/presto/blob/5e030a24ac669f43b84c3a30e1217d08fb3ea6be/src/Shutterstock/Presto/Presto.php#L364-L377
|
231,458
|
shutterstock/presto
|
src/Shutterstock/Presto/Presto.php
|
Presto.processQueue
|
public static function processQueue()
{
if (count(self::$request_queue) == 0) {
return false;
}
do {
$multi_handle = curl_multi_exec(self::$queue_handle, $active);
} while ($multi_handle == CURLM_CALL_MULTI_PERFORM);
while ($active && $multi_handle == CURLM_OK) {
if (curl_multi_select(self::$queue_handle) != -1) {
do {
$multi_handle = curl_multi_exec(self::$queue_handle, $active);
} while ($multi_handle == CURLM_CALL_MULTI_PERFORM);
}
}
foreach (self::$request_queue as $key => $value) {
$error = curl_error($value['handle']);
if (!empty($error)) {
$info = array(
'is_success' => false,
'url' => $value['url'],
'errorno' => curl_errno($value['handle']),
'error' => $error,
'queue' => 'ON'
);
$result = false;
$header = '';
} else {
$info = curl_getinfo($value['handle']);
$info['is_success'] = true;
$info['queue'] = 'ON';
$body = curl_multi_getcontent($value['handle']);
list($header, $result) = explode("\r\n\r\n", $body, 2);
}
self::logProfiling($info);
self::$request_queue[$key]['response'] = new Response($info, $result, $header);
$callback = $value['callback'];
$callback(self::$request_queue[$key]['response']);
curl_multi_remove_handle(self::$queue_handle, self::$request_queue[$key]['handle']);
}
curl_multi_close(self::$queue_handle);
self::$request_queue = array();
return true;
}
|
php
|
public static function processQueue()
{
if (count(self::$request_queue) == 0) {
return false;
}
do {
$multi_handle = curl_multi_exec(self::$queue_handle, $active);
} while ($multi_handle == CURLM_CALL_MULTI_PERFORM);
while ($active && $multi_handle == CURLM_OK) {
if (curl_multi_select(self::$queue_handle) != -1) {
do {
$multi_handle = curl_multi_exec(self::$queue_handle, $active);
} while ($multi_handle == CURLM_CALL_MULTI_PERFORM);
}
}
foreach (self::$request_queue as $key => $value) {
$error = curl_error($value['handle']);
if (!empty($error)) {
$info = array(
'is_success' => false,
'url' => $value['url'],
'errorno' => curl_errno($value['handle']),
'error' => $error,
'queue' => 'ON'
);
$result = false;
$header = '';
} else {
$info = curl_getinfo($value['handle']);
$info['is_success'] = true;
$info['queue'] = 'ON';
$body = curl_multi_getcontent($value['handle']);
list($header, $result) = explode("\r\n\r\n", $body, 2);
}
self::logProfiling($info);
self::$request_queue[$key]['response'] = new Response($info, $result, $header);
$callback = $value['callback'];
$callback(self::$request_queue[$key]['response']);
curl_multi_remove_handle(self::$queue_handle, self::$request_queue[$key]['handle']);
}
curl_multi_close(self::$queue_handle);
self::$request_queue = array();
return true;
}
|
[
"public",
"static",
"function",
"processQueue",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"self",
"::",
"$",
"request_queue",
")",
"==",
"0",
")",
"{",
"return",
"false",
";",
"}",
"do",
"{",
"$",
"multi_handle",
"=",
"curl_multi_exec",
"(",
"self",
"::",
"$",
"queue_handle",
",",
"$",
"active",
")",
";",
"}",
"while",
"(",
"$",
"multi_handle",
"==",
"CURLM_CALL_MULTI_PERFORM",
")",
";",
"while",
"(",
"$",
"active",
"&&",
"$",
"multi_handle",
"==",
"CURLM_OK",
")",
"{",
"if",
"(",
"curl_multi_select",
"(",
"self",
"::",
"$",
"queue_handle",
")",
"!=",
"-",
"1",
")",
"{",
"do",
"{",
"$",
"multi_handle",
"=",
"curl_multi_exec",
"(",
"self",
"::",
"$",
"queue_handle",
",",
"$",
"active",
")",
";",
"}",
"while",
"(",
"$",
"multi_handle",
"==",
"CURLM_CALL_MULTI_PERFORM",
")",
";",
"}",
"}",
"foreach",
"(",
"self",
"::",
"$",
"request_queue",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"error",
"=",
"curl_error",
"(",
"$",
"value",
"[",
"'handle'",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"error",
")",
")",
"{",
"$",
"info",
"=",
"array",
"(",
"'is_success'",
"=>",
"false",
",",
"'url'",
"=>",
"$",
"value",
"[",
"'url'",
"]",
",",
"'errorno'",
"=>",
"curl_errno",
"(",
"$",
"value",
"[",
"'handle'",
"]",
")",
",",
"'error'",
"=>",
"$",
"error",
",",
"'queue'",
"=>",
"'ON'",
")",
";",
"$",
"result",
"=",
"false",
";",
"$",
"header",
"=",
"''",
";",
"}",
"else",
"{",
"$",
"info",
"=",
"curl_getinfo",
"(",
"$",
"value",
"[",
"'handle'",
"]",
")",
";",
"$",
"info",
"[",
"'is_success'",
"]",
"=",
"true",
";",
"$",
"info",
"[",
"'queue'",
"]",
"=",
"'ON'",
";",
"$",
"body",
"=",
"curl_multi_getcontent",
"(",
"$",
"value",
"[",
"'handle'",
"]",
")",
";",
"list",
"(",
"$",
"header",
",",
"$",
"result",
")",
"=",
"explode",
"(",
"\"\\r\\n\\r\\n\"",
",",
"$",
"body",
",",
"2",
")",
";",
"}",
"self",
"::",
"logProfiling",
"(",
"$",
"info",
")",
";",
"self",
"::",
"$",
"request_queue",
"[",
"$",
"key",
"]",
"[",
"'response'",
"]",
"=",
"new",
"Response",
"(",
"$",
"info",
",",
"$",
"result",
",",
"$",
"header",
")",
";",
"$",
"callback",
"=",
"$",
"value",
"[",
"'callback'",
"]",
";",
"$",
"callback",
"(",
"self",
"::",
"$",
"request_queue",
"[",
"$",
"key",
"]",
"[",
"'response'",
"]",
")",
";",
"curl_multi_remove_handle",
"(",
"self",
"::",
"$",
"queue_handle",
",",
"self",
"::",
"$",
"request_queue",
"[",
"$",
"key",
"]",
"[",
"'handle'",
"]",
")",
";",
"}",
"curl_multi_close",
"(",
"self",
"::",
"$",
"queue_handle",
")",
";",
"self",
"::",
"$",
"request_queue",
"=",
"array",
"(",
")",
";",
"return",
"true",
";",
"}"
] |
Trigger to execute the curl requests
@return boolean whether or not the queue was processed
|
[
"Trigger",
"to",
"execute",
"the",
"curl",
"requests"
] |
5e030a24ac669f43b84c3a30e1217d08fb3ea6be
|
https://github.com/shutterstock/presto/blob/5e030a24ac669f43b84c3a30e1217d08fb3ea6be/src/Shutterstock/Presto/Presto.php#L384-L435
|
231,459
|
shutterstock/presto
|
src/Shutterstock/Presto/Presto.php
|
Presto.arrayToUrlParams
|
public static function arrayToUrlParams($params, $delimiter = '&')
{
$url_params = array();
foreach ($params as $key => $value) {
if (is_array($value)) {
foreach ($value as $subvalue) {
$url_params[] = urlencode($key) . '=' . urlencode($subvalue);
}
} else {
$url_params[] = urlencode($key) . '=' . urlencode($value);
}
}
return implode($delimiter, $url_params);
}
|
php
|
public static function arrayToUrlParams($params, $delimiter = '&')
{
$url_params = array();
foreach ($params as $key => $value) {
if (is_array($value)) {
foreach ($value as $subvalue) {
$url_params[] = urlencode($key) . '=' . urlencode($subvalue);
}
} else {
$url_params[] = urlencode($key) . '=' . urlencode($value);
}
}
return implode($delimiter, $url_params);
}
|
[
"public",
"static",
"function",
"arrayToUrlParams",
"(",
"$",
"params",
",",
"$",
"delimiter",
"=",
"'&'",
")",
"{",
"$",
"url_params",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"foreach",
"(",
"$",
"value",
"as",
"$",
"subvalue",
")",
"{",
"$",
"url_params",
"[",
"]",
"=",
"urlencode",
"(",
"$",
"key",
")",
".",
"'='",
".",
"urlencode",
"(",
"$",
"subvalue",
")",
";",
"}",
"}",
"else",
"{",
"$",
"url_params",
"[",
"]",
"=",
"urlencode",
"(",
"$",
"key",
")",
".",
"'='",
".",
"urlencode",
"(",
"$",
"value",
")",
";",
"}",
"}",
"return",
"implode",
"(",
"$",
"delimiter",
",",
"$",
"url_params",
")",
";",
"}"
] |
Convert an array to a flattened URL parameter structure
This will create a URL parameter string with repeating param keys
If this special behavior is not needed, http_build_query should be used
@param array $params key/value list of url parameters to use
@param string $delimiter optional alternative delimiter to use
@return string flattened URL parameters
|
[
"Convert",
"an",
"array",
"to",
"a",
"flattened",
"URL",
"parameter",
"structure",
"This",
"will",
"create",
"a",
"URL",
"parameter",
"string",
"with",
"repeating",
"param",
"keys",
"If",
"this",
"special",
"behavior",
"is",
"not",
"needed",
"http_build_query",
"should",
"be",
"used"
] |
5e030a24ac669f43b84c3a30e1217d08fb3ea6be
|
https://github.com/shutterstock/presto/blob/5e030a24ac669f43b84c3a30e1217d08fb3ea6be/src/Shutterstock/Presto/Presto.php#L570-L583
|
231,460
|
shutterstock/presto
|
src/Shutterstock/Presto/Presto.php
|
Presto.logProfiling
|
public static function logProfiling(array $log_data)
{
if (self::$profiling_count > self::$profiling_max) {
return;
}
self::$profiling_count++;
if (isset($log_data['errorno'])) {
self::$profiling[] = array(
'url' => $log_data['url'],
'errorno' => $log_data['errorno'],
'error' => $log_data['error'],
'queue' => $log_data['queue'],
);
} else {
self::$profiling[] = array(
'url' => $log_data['url'],
'http_code' => $log_data['http_code'],
'total_time' => $log_data['total_time'],
'pretransfer_time' => $log_data['pretransfer_time'],
'queue' => $log_data['queue'],
);
}
}
|
php
|
public static function logProfiling(array $log_data)
{
if (self::$profiling_count > self::$profiling_max) {
return;
}
self::$profiling_count++;
if (isset($log_data['errorno'])) {
self::$profiling[] = array(
'url' => $log_data['url'],
'errorno' => $log_data['errorno'],
'error' => $log_data['error'],
'queue' => $log_data['queue'],
);
} else {
self::$profiling[] = array(
'url' => $log_data['url'],
'http_code' => $log_data['http_code'],
'total_time' => $log_data['total_time'],
'pretransfer_time' => $log_data['pretransfer_time'],
'queue' => $log_data['queue'],
);
}
}
|
[
"public",
"static",
"function",
"logProfiling",
"(",
"array",
"$",
"log_data",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"profiling_count",
">",
"self",
"::",
"$",
"profiling_max",
")",
"{",
"return",
";",
"}",
"self",
"::",
"$",
"profiling_count",
"++",
";",
"if",
"(",
"isset",
"(",
"$",
"log_data",
"[",
"'errorno'",
"]",
")",
")",
"{",
"self",
"::",
"$",
"profiling",
"[",
"]",
"=",
"array",
"(",
"'url'",
"=>",
"$",
"log_data",
"[",
"'url'",
"]",
",",
"'errorno'",
"=>",
"$",
"log_data",
"[",
"'errorno'",
"]",
",",
"'error'",
"=>",
"$",
"log_data",
"[",
"'error'",
"]",
",",
"'queue'",
"=>",
"$",
"log_data",
"[",
"'queue'",
"]",
",",
")",
";",
"}",
"else",
"{",
"self",
"::",
"$",
"profiling",
"[",
"]",
"=",
"array",
"(",
"'url'",
"=>",
"$",
"log_data",
"[",
"'url'",
"]",
",",
"'http_code'",
"=>",
"$",
"log_data",
"[",
"'http_code'",
"]",
",",
"'total_time'",
"=>",
"$",
"log_data",
"[",
"'total_time'",
"]",
",",
"'pretransfer_time'",
"=>",
"$",
"log_data",
"[",
"'pretransfer_time'",
"]",
",",
"'queue'",
"=>",
"$",
"log_data",
"[",
"'queue'",
"]",
",",
")",
";",
"}",
"}"
] |
Log profiling information for service requests
@param array $log_data profiling information to log
|
[
"Log",
"profiling",
"information",
"for",
"service",
"requests"
] |
5e030a24ac669f43b84c3a30e1217d08fb3ea6be
|
https://github.com/shutterstock/presto/blob/5e030a24ac669f43b84c3a30e1217d08fb3ea6be/src/Shutterstock/Presto/Presto.php#L604-L627
|
231,461
|
opensoft/epl
|
src/Epl/Command/Image/AsciiTextCommand.php
|
AsciiTextCommand.rotationConvertFromDegree
|
private function rotationConvertFromDegree($degree, $asianFont)
{
switch ($degree) {
case 90:
if ($asianFont) {
return 5;
}
return 1;
case 180:
if ($asianFont) {
return 6;
}
return 2;
case 270:
if ($asianFont) {
return 7;
}
return 3;
case 0:
if ($asianFont) {
return 4;
}
return 0;
default:
throw ExceptionCommand::invalidDegree($degree);
}
}
|
php
|
private function rotationConvertFromDegree($degree, $asianFont)
{
switch ($degree) {
case 90:
if ($asianFont) {
return 5;
}
return 1;
case 180:
if ($asianFont) {
return 6;
}
return 2;
case 270:
if ($asianFont) {
return 7;
}
return 3;
case 0:
if ($asianFont) {
return 4;
}
return 0;
default:
throw ExceptionCommand::invalidDegree($degree);
}
}
|
[
"private",
"function",
"rotationConvertFromDegree",
"(",
"$",
"degree",
",",
"$",
"asianFont",
")",
"{",
"switch",
"(",
"$",
"degree",
")",
"{",
"case",
"90",
":",
"if",
"(",
"$",
"asianFont",
")",
"{",
"return",
"5",
";",
"}",
"return",
"1",
";",
"case",
"180",
":",
"if",
"(",
"$",
"asianFont",
")",
"{",
"return",
"6",
";",
"}",
"return",
"2",
";",
"case",
"270",
":",
"if",
"(",
"$",
"asianFont",
")",
"{",
"return",
"7",
";",
"}",
"return",
"3",
";",
"case",
"0",
":",
"if",
"(",
"$",
"asianFont",
")",
"{",
"return",
"4",
";",
"}",
"return",
"0",
";",
"default",
":",
"throw",
"ExceptionCommand",
"::",
"invalidDegree",
"(",
"$",
"degree",
")",
";",
"}",
"}"
] |
0 = normal
1 = 90 degrees
2 = 180 degrees
3 = 270 degrees
@param int $degree
@param $asianFont
@throw ExceptionCommand
@return int
|
[
"0",
"=",
"normal",
"1",
"=",
"90",
"degrees",
"2",
"=",
"180",
"degrees",
"3",
"=",
"270",
"degrees"
] |
61a1152ed3e292d5bd3ec2758076d605bada0623
|
https://github.com/opensoft/epl/blob/61a1152ed3e292d5bd3ec2758076d605bada0623/src/Epl/Command/Image/AsciiTextCommand.php#L163-L190
|
231,462
|
bariew/yii2-event-component
|
EventBootstrap.php
|
EventBootstrap.getEventManager
|
public static function getEventManager($app)
{
if (self::$_eventManager) {
return self::$_eventManager;
}
foreach ($app->components as $name => $config) {
$class = is_string($config) ? $config : @$config['class'];
if($class == str_replace('Bootstrap', 'Manager', get_called_class())){
return self::$_eventManager = $app->$name;
}
}
$eventFile = \Yii::getAlias('@app/config/_events.php');
$app->setComponents([
'eventManager' => [
'class' => 'bariew\eventManager\EventManager',
'events' => file_exists($eventFile) && is_file($eventFile)
? include $eventFile
: []
],
]);
return self::$_eventManager = $app->eventManager;
}
|
php
|
public static function getEventManager($app)
{
if (self::$_eventManager) {
return self::$_eventManager;
}
foreach ($app->components as $name => $config) {
$class = is_string($config) ? $config : @$config['class'];
if($class == str_replace('Bootstrap', 'Manager', get_called_class())){
return self::$_eventManager = $app->$name;
}
}
$eventFile = \Yii::getAlias('@app/config/_events.php');
$app->setComponents([
'eventManager' => [
'class' => 'bariew\eventManager\EventManager',
'events' => file_exists($eventFile) && is_file($eventFile)
? include $eventFile
: []
],
]);
return self::$_eventManager = $app->eventManager;
}
|
[
"public",
"static",
"function",
"getEventManager",
"(",
"$",
"app",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"_eventManager",
")",
"{",
"return",
"self",
"::",
"$",
"_eventManager",
";",
"}",
"foreach",
"(",
"$",
"app",
"->",
"components",
"as",
"$",
"name",
"=>",
"$",
"config",
")",
"{",
"$",
"class",
"=",
"is_string",
"(",
"$",
"config",
")",
"?",
"$",
"config",
":",
"@",
"$",
"config",
"[",
"'class'",
"]",
";",
"if",
"(",
"$",
"class",
"==",
"str_replace",
"(",
"'Bootstrap'",
",",
"'Manager'",
",",
"get_called_class",
"(",
")",
")",
")",
"{",
"return",
"self",
"::",
"$",
"_eventManager",
"=",
"$",
"app",
"->",
"$",
"name",
";",
"}",
"}",
"$",
"eventFile",
"=",
"\\",
"Yii",
"::",
"getAlias",
"(",
"'@app/config/_events.php'",
")",
";",
"$",
"app",
"->",
"setComponents",
"(",
"[",
"'eventManager'",
"=>",
"[",
"'class'",
"=>",
"'bariew\\eventManager\\EventManager'",
",",
"'events'",
"=>",
"file_exists",
"(",
"$",
"eventFile",
")",
"&&",
"is_file",
"(",
"$",
"eventFile",
")",
"?",
"include",
"$",
"eventFile",
":",
"[",
"]",
"]",
",",
"]",
")",
";",
"return",
"self",
"::",
"$",
"_eventManager",
"=",
"$",
"app",
"->",
"eventManager",
";",
"}"
] |
finds and creates app event manager from its settings
@param Application $app yii app
@return EventManager app event manager component
@throws Exception Define event manager
|
[
"finds",
"and",
"creates",
"app",
"event",
"manager",
"from",
"its",
"settings"
] |
0b93904a79b3b39b85832dcbd7131f66f39f976e
|
https://github.com/bariew/yii2-event-component/blob/0b93904a79b3b39b85832dcbd7131f66f39f976e/EventBootstrap.php#L37-L58
|
231,463
|
digilist/dependency-graph
|
src/DependencyNode.php
|
DependencyNode.dependsOn
|
public function dependsOn(self $node)
{
if (!in_array($node, $this->dependencies)) {
$this->dependencies[] = $node;
}
}
|
php
|
public function dependsOn(self $node)
{
if (!in_array($node, $this->dependencies)) {
$this->dependencies[] = $node;
}
}
|
[
"public",
"function",
"dependsOn",
"(",
"self",
"$",
"node",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"node",
",",
"$",
"this",
"->",
"dependencies",
")",
")",
"{",
"$",
"this",
"->",
"dependencies",
"[",
"]",
"=",
"$",
"node",
";",
"}",
"}"
] |
This node as a dependency on the passed node.
@param DependencyNode $node
|
[
"This",
"node",
"as",
"a",
"dependency",
"on",
"the",
"passed",
"node",
"."
] |
dd77f1a81c81d921c135b3c775fed054d4dbd5d2
|
https://github.com/digilist/dependency-graph/blob/dd77f1a81c81d921c135b3c775fed054d4dbd5d2/src/DependencyNode.php#L46-L51
|
231,464
|
digilist/dependency-graph
|
src/DependencyGraph.php
|
DependencyGraph.addNode
|
public function addNode(DependencyNode $node)
{
if (!$this->dependencies->contains($node)) {
$this->dependencies->attach($node, new ArrayObject());
$this->nodes[] = $node;
foreach ($node->getDependencies() as $depency) {
$this->addDependency($node, $depency);
}
}
}
|
php
|
public function addNode(DependencyNode $node)
{
if (!$this->dependencies->contains($node)) {
$this->dependencies->attach($node, new ArrayObject());
$this->nodes[] = $node;
foreach ($node->getDependencies() as $depency) {
$this->addDependency($node, $depency);
}
}
}
|
[
"public",
"function",
"addNode",
"(",
"DependencyNode",
"$",
"node",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"dependencies",
"->",
"contains",
"(",
"$",
"node",
")",
")",
"{",
"$",
"this",
"->",
"dependencies",
"->",
"attach",
"(",
"$",
"node",
",",
"new",
"ArrayObject",
"(",
")",
")",
";",
"$",
"this",
"->",
"nodes",
"[",
"]",
"=",
"$",
"node",
";",
"foreach",
"(",
"$",
"node",
"->",
"getDependencies",
"(",
")",
"as",
"$",
"depency",
")",
"{",
"$",
"this",
"->",
"addDependency",
"(",
"$",
"node",
",",
"$",
"depency",
")",
";",
"}",
"}",
"}"
] |
Add a new node to the graph and adopt the defined dependencies automatically.
@param DependencyNode $node
|
[
"Add",
"a",
"new",
"node",
"to",
"the",
"graph",
"and",
"adopt",
"the",
"defined",
"dependencies",
"automatically",
"."
] |
dd77f1a81c81d921c135b3c775fed054d4dbd5d2
|
https://github.com/digilist/dependency-graph/blob/dd77f1a81c81d921c135b3c775fed054d4dbd5d2/src/DependencyGraph.php#L34-L44
|
231,465
|
digilist/dependency-graph
|
src/DependencyGraph.php
|
DependencyGraph.addDependency
|
public function addDependency(DependencyNode $node, DependencyNode $dependsOn)
{
if (!$this->dependencies->contains($node)) {
$this->addNode($node);
}
if (!$this->dependencies->contains($dependsOn)) {
$this->addNode($dependsOn);
}
if (!$this->arrayObjectContains($dependsOn, $this->dependencies[$node])) {
$this->dependencies[$node]->append($dependsOn);
}
$node->dependsOn($dependsOn);
}
|
php
|
public function addDependency(DependencyNode $node, DependencyNode $dependsOn)
{
if (!$this->dependencies->contains($node)) {
$this->addNode($node);
}
if (!$this->dependencies->contains($dependsOn)) {
$this->addNode($dependsOn);
}
if (!$this->arrayObjectContains($dependsOn, $this->dependencies[$node])) {
$this->dependencies[$node]->append($dependsOn);
}
$node->dependsOn($dependsOn);
}
|
[
"public",
"function",
"addDependency",
"(",
"DependencyNode",
"$",
"node",
",",
"DependencyNode",
"$",
"dependsOn",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"dependencies",
"->",
"contains",
"(",
"$",
"node",
")",
")",
"{",
"$",
"this",
"->",
"addNode",
"(",
"$",
"node",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"dependencies",
"->",
"contains",
"(",
"$",
"dependsOn",
")",
")",
"{",
"$",
"this",
"->",
"addNode",
"(",
"$",
"dependsOn",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"arrayObjectContains",
"(",
"$",
"dependsOn",
",",
"$",
"this",
"->",
"dependencies",
"[",
"$",
"node",
"]",
")",
")",
"{",
"$",
"this",
"->",
"dependencies",
"[",
"$",
"node",
"]",
"->",
"append",
"(",
"$",
"dependsOn",
")",
";",
"}",
"$",
"node",
"->",
"dependsOn",
"(",
"$",
"dependsOn",
")",
";",
"}"
] |
Add a new dependency between two nodes.
If the starting node or the dependend is not added to the graph yet, they will be added automatically.
@param DependencyNode $node
@param DependencyNode $dependsOn
|
[
"Add",
"a",
"new",
"dependency",
"between",
"two",
"nodes",
".",
"If",
"the",
"starting",
"node",
"or",
"the",
"dependend",
"is",
"not",
"added",
"to",
"the",
"graph",
"yet",
"they",
"will",
"be",
"added",
"automatically",
"."
] |
dd77f1a81c81d921c135b3c775fed054d4dbd5d2
|
https://github.com/digilist/dependency-graph/blob/dd77f1a81c81d921c135b3c775fed054d4dbd5d2/src/DependencyGraph.php#L53-L67
|
231,466
|
digilist/dependency-graph
|
src/DependencyGraph.php
|
DependencyGraph.findRootNodes
|
public function findRootNodes()
{
$possibleRoots = new SplObjectStorage();
foreach ($this->nodes as $node) {
$possibleRoots[$node] = true;
}
// Detect all nodes which couldn't be root
foreach ($this->dependencies as $node) {
$nodeDependencies = $this->dependencies[$node];
foreach ($nodeDependencies as $dependency) {
$possibleRoots[$dependency] = false;
}
}
// Create array which contains all roots
$rootNodes = array();
foreach ($possibleRoots as $node) {
if ($possibleRoots[$node]) {
$rootNodes[] = $node;
}
}
return $rootNodes;
}
|
php
|
public function findRootNodes()
{
$possibleRoots = new SplObjectStorage();
foreach ($this->nodes as $node) {
$possibleRoots[$node] = true;
}
// Detect all nodes which couldn't be root
foreach ($this->dependencies as $node) {
$nodeDependencies = $this->dependencies[$node];
foreach ($nodeDependencies as $dependency) {
$possibleRoots[$dependency] = false;
}
}
// Create array which contains all roots
$rootNodes = array();
foreach ($possibleRoots as $node) {
if ($possibleRoots[$node]) {
$rootNodes[] = $node;
}
}
return $rootNodes;
}
|
[
"public",
"function",
"findRootNodes",
"(",
")",
"{",
"$",
"possibleRoots",
"=",
"new",
"SplObjectStorage",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"nodes",
"as",
"$",
"node",
")",
"{",
"$",
"possibleRoots",
"[",
"$",
"node",
"]",
"=",
"true",
";",
"}",
"// Detect all nodes which couldn't be root",
"foreach",
"(",
"$",
"this",
"->",
"dependencies",
"as",
"$",
"node",
")",
"{",
"$",
"nodeDependencies",
"=",
"$",
"this",
"->",
"dependencies",
"[",
"$",
"node",
"]",
";",
"foreach",
"(",
"$",
"nodeDependencies",
"as",
"$",
"dependency",
")",
"{",
"$",
"possibleRoots",
"[",
"$",
"dependency",
"]",
"=",
"false",
";",
"}",
"}",
"// Create array which contains all roots",
"$",
"rootNodes",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"possibleRoots",
"as",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"possibleRoots",
"[",
"$",
"node",
"]",
")",
"{",
"$",
"rootNodes",
"[",
"]",
"=",
"$",
"node",
";",
"}",
"}",
"return",
"$",
"rootNodes",
";",
"}"
] |
Find all connected graphs in the set of all graphs.
@return ArrayObject
|
[
"Find",
"all",
"connected",
"graphs",
"in",
"the",
"set",
"of",
"all",
"graphs",
"."
] |
dd77f1a81c81d921c135b3c775fed054d4dbd5d2
|
https://github.com/digilist/dependency-graph/blob/dd77f1a81c81d921c135b3c775fed054d4dbd5d2/src/DependencyGraph.php#L74-L98
|
231,467
|
digilist/dependency-graph
|
src/DependencyGraph.php
|
DependencyGraph.resolve
|
public function resolve()
{
if ($this->dependencies->count() === 0) {
return array();
}
$resolved = new ArrayObject();
foreach ($this->findRootNodes() as $rootNode) {
$this->innerResolve($rootNode, $resolved, new ArrayObject());
}
//all resolved?
if ($resolved->count() !== count($this->nodes)) {
throw new CircularDependencyException();
}
$resolvedElements = array_map(function (DependencyNode $node) {
return $node->getElement();
}, $resolved->getArrayCopy());
return $resolvedElements;
}
|
php
|
public function resolve()
{
if ($this->dependencies->count() === 0) {
return array();
}
$resolved = new ArrayObject();
foreach ($this->findRootNodes() as $rootNode) {
$this->innerResolve($rootNode, $resolved, new ArrayObject());
}
//all resolved?
if ($resolved->count() !== count($this->nodes)) {
throw new CircularDependencyException();
}
$resolvedElements = array_map(function (DependencyNode $node) {
return $node->getElement();
}, $resolved->getArrayCopy());
return $resolvedElements;
}
|
[
"public",
"function",
"resolve",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"dependencies",
"->",
"count",
"(",
")",
"===",
"0",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"resolved",
"=",
"new",
"ArrayObject",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"findRootNodes",
"(",
")",
"as",
"$",
"rootNode",
")",
"{",
"$",
"this",
"->",
"innerResolve",
"(",
"$",
"rootNode",
",",
"$",
"resolved",
",",
"new",
"ArrayObject",
"(",
")",
")",
";",
"}",
"//all resolved?",
"if",
"(",
"$",
"resolved",
"->",
"count",
"(",
")",
"!==",
"count",
"(",
"$",
"this",
"->",
"nodes",
")",
")",
"{",
"throw",
"new",
"CircularDependencyException",
"(",
")",
";",
"}",
"$",
"resolvedElements",
"=",
"array_map",
"(",
"function",
"(",
"DependencyNode",
"$",
"node",
")",
"{",
"return",
"$",
"node",
"->",
"getElement",
"(",
")",
";",
"}",
",",
"$",
"resolved",
"->",
"getArrayCopy",
"(",
")",
")",
";",
"return",
"$",
"resolvedElements",
";",
"}"
] |
Resolve this dependency graph. In the end a valid path will be returned.
@return DependencyNode[]
|
[
"Resolve",
"this",
"dependency",
"graph",
".",
"In",
"the",
"end",
"a",
"valid",
"path",
"will",
"be",
"returned",
"."
] |
dd77f1a81c81d921c135b3c775fed054d4dbd5d2
|
https://github.com/digilist/dependency-graph/blob/dd77f1a81c81d921c135b3c775fed054d4dbd5d2/src/DependencyGraph.php#L105-L126
|
231,468
|
digilist/dependency-graph
|
src/DependencyGraph.php
|
DependencyGraph.innerResolve
|
private function innerResolve(DependencyNode $rootNode, ArrayObject $resolved, ArrayObject $seen)
{
$seen->append($rootNode);
foreach ($rootNode->getDependencies() as $edge) {
if (!$this->arrayObjectContains($edge, $resolved)) {
if ($this->arrayObjectContains($edge, $seen)) {
throw new CircularDependencyException(
sprintf('Circular dependency detected: %s depends on %s', $rootNode->getName(), $edge->getName())
);
}
$this->innerResolve($edge, $resolved, $seen);
}
}
$resolved->append($rootNode);
}
|
php
|
private function innerResolve(DependencyNode $rootNode, ArrayObject $resolved, ArrayObject $seen)
{
$seen->append($rootNode);
foreach ($rootNode->getDependencies() as $edge) {
if (!$this->arrayObjectContains($edge, $resolved)) {
if ($this->arrayObjectContains($edge, $seen)) {
throw new CircularDependencyException(
sprintf('Circular dependency detected: %s depends on %s', $rootNode->getName(), $edge->getName())
);
}
$this->innerResolve($edge, $resolved, $seen);
}
}
$resolved->append($rootNode);
}
|
[
"private",
"function",
"innerResolve",
"(",
"DependencyNode",
"$",
"rootNode",
",",
"ArrayObject",
"$",
"resolved",
",",
"ArrayObject",
"$",
"seen",
")",
"{",
"$",
"seen",
"->",
"append",
"(",
"$",
"rootNode",
")",
";",
"foreach",
"(",
"$",
"rootNode",
"->",
"getDependencies",
"(",
")",
"as",
"$",
"edge",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"arrayObjectContains",
"(",
"$",
"edge",
",",
"$",
"resolved",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"arrayObjectContains",
"(",
"$",
"edge",
",",
"$",
"seen",
")",
")",
"{",
"throw",
"new",
"CircularDependencyException",
"(",
"sprintf",
"(",
"'Circular dependency detected: %s depends on %s'",
",",
"$",
"rootNode",
"->",
"getName",
"(",
")",
",",
"$",
"edge",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"innerResolve",
"(",
"$",
"edge",
",",
"$",
"resolved",
",",
"$",
"seen",
")",
";",
"}",
"}",
"$",
"resolved",
"->",
"append",
"(",
"$",
"rootNode",
")",
";",
"}"
] |
Inner recursive function.
@param DependencyNode $rootNode
@param ArrayObject|DependencyNode[] $resolved
@param ArrayObject|DependencyNode[] $seen
@return ArrayObject|DependencyNode[]
@throws \Exception
|
[
"Inner",
"recursive",
"function",
"."
] |
dd77f1a81c81d921c135b3c775fed054d4dbd5d2
|
https://github.com/digilist/dependency-graph/blob/dd77f1a81c81d921c135b3c775fed054d4dbd5d2/src/DependencyGraph.php#L137-L153
|
231,469
|
davin-bao/workflow
|
src/DavinBao/Workflow/WorkflowResourceflow.php
|
WorkFlowResourceflow.goFirst
|
public function goFirst(){
//delete others unAndit nodes
$this->deleteAllUnAuditResourceNodes();
//get first user id, if haven't , point to me
$userId = static::$app['auth']->user()->id;
$resNode = $this->resourcenodes()->where('orders', '=', 0)->get()->first();
if($resNode && $resNode->count() >0){
$userId = $resNode->user_id;
}
$firstNode = new WorkFlowResourcenode();
$firstNode->user_id = $userId;
$firstNode->orders = 0;
$this->resourcenodes()->save($firstNode);
$this->node_orders = 0;
$this->status = 'unstart';
return $this->save();
}
|
php
|
public function goFirst(){
//delete others unAndit nodes
$this->deleteAllUnAuditResourceNodes();
//get first user id, if haven't , point to me
$userId = static::$app['auth']->user()->id;
$resNode = $this->resourcenodes()->where('orders', '=', 0)->get()->first();
if($resNode && $resNode->count() >0){
$userId = $resNode->user_id;
}
$firstNode = new WorkFlowResourcenode();
$firstNode->user_id = $userId;
$firstNode->orders = 0;
$this->resourcenodes()->save($firstNode);
$this->node_orders = 0;
$this->status = 'unstart';
return $this->save();
}
|
[
"public",
"function",
"goFirst",
"(",
")",
"{",
"//delete others unAndit nodes",
"$",
"this",
"->",
"deleteAllUnAuditResourceNodes",
"(",
")",
";",
"//get first user id, if haven't , point to me",
"$",
"userId",
"=",
"static",
"::",
"$",
"app",
"[",
"'auth'",
"]",
"->",
"user",
"(",
")",
"->",
"id",
";",
"$",
"resNode",
"=",
"$",
"this",
"->",
"resourcenodes",
"(",
")",
"->",
"where",
"(",
"'orders'",
",",
"'='",
",",
"0",
")",
"->",
"get",
"(",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"$",
"resNode",
"&&",
"$",
"resNode",
"->",
"count",
"(",
")",
">",
"0",
")",
"{",
"$",
"userId",
"=",
"$",
"resNode",
"->",
"user_id",
";",
"}",
"$",
"firstNode",
"=",
"new",
"WorkFlowResourcenode",
"(",
")",
";",
"$",
"firstNode",
"->",
"user_id",
"=",
"$",
"userId",
";",
"$",
"firstNode",
"->",
"orders",
"=",
"0",
";",
"$",
"this",
"->",
"resourcenodes",
"(",
")",
"->",
"save",
"(",
"$",
"firstNode",
")",
";",
"$",
"this",
"->",
"node_orders",
"=",
"0",
";",
"$",
"this",
"->",
"status",
"=",
"'unstart'",
";",
"return",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}"
] |
return this flow to first
|
[
"return",
"this",
"flow",
"to",
"first"
] |
8af8b33ef63e455a2a5a1cdf6ac7bc154d590488
|
https://github.com/davin-bao/workflow/blob/8af8b33ef63e455a2a5a1cdf6ac7bc154d590488/src/DavinBao/Workflow/WorkflowResourceflow.php#L198-L215
|
231,470
|
davin-bao/workflow
|
src/DavinBao/Workflow/WorkflowResourceflow.php
|
WorkFlowResourceflow.goNext
|
public function goNext(){
$currentOrder = $this->node_orders;
$nextNodeOrder = $currentOrder + 1;
$status = 'proceed';
$maxOrder = $this->flow()->first()->nodes()->count();
if($nextNodeOrder > $maxOrder){
$status = 'completed';
$nextNodeOrder = $maxOrder+1;
}
$this->node_orders = $nextNodeOrder;
$this->status = $status;
$this->save();
Log::error($this->errors()->all());
}
|
php
|
public function goNext(){
$currentOrder = $this->node_orders;
$nextNodeOrder = $currentOrder + 1;
$status = 'proceed';
$maxOrder = $this->flow()->first()->nodes()->count();
if($nextNodeOrder > $maxOrder){
$status = 'completed';
$nextNodeOrder = $maxOrder+1;
}
$this->node_orders = $nextNodeOrder;
$this->status = $status;
$this->save();
Log::error($this->errors()->all());
}
|
[
"public",
"function",
"goNext",
"(",
")",
"{",
"$",
"currentOrder",
"=",
"$",
"this",
"->",
"node_orders",
";",
"$",
"nextNodeOrder",
"=",
"$",
"currentOrder",
"+",
"1",
";",
"$",
"status",
"=",
"'proceed'",
";",
"$",
"maxOrder",
"=",
"$",
"this",
"->",
"flow",
"(",
")",
"->",
"first",
"(",
")",
"->",
"nodes",
"(",
")",
"->",
"count",
"(",
")",
";",
"if",
"(",
"$",
"nextNodeOrder",
">",
"$",
"maxOrder",
")",
"{",
"$",
"status",
"=",
"'completed'",
";",
"$",
"nextNodeOrder",
"=",
"$",
"maxOrder",
"+",
"1",
";",
"}",
"$",
"this",
"->",
"node_orders",
"=",
"$",
"nextNodeOrder",
";",
"$",
"this",
"->",
"status",
"=",
"$",
"status",
";",
"$",
"this",
"->",
"save",
"(",
")",
";",
"Log",
"::",
"error",
"(",
"$",
"this",
"->",
"errors",
"(",
")",
"->",
"all",
"(",
")",
")",
";",
"}"
] |
go to next node
@param $nextAuditUsers
|
[
"go",
"to",
"next",
"node"
] |
8af8b33ef63e455a2a5a1cdf6ac7bc154d590488
|
https://github.com/davin-bao/workflow/blob/8af8b33ef63e455a2a5a1cdf6ac7bc154d590488/src/DavinBao/Workflow/WorkflowResourceflow.php#L221-L235
|
231,471
|
PaymentSuite/paymentsuite
|
src/PaymentSuite/PaylandsBundle/Services/PaylandsManager.php
|
PaylandsManager.processPayment
|
public function processPayment(PaylandsMethod $paymentMethod)
{
/*
* At this point, order must be created given a cart, and placed in PaymentBridge.
*
* So, $this->paymentBridge->getOrder() must return an object
*/
$this
->paymentEventDispatcher
->notifyPaymentOrderLoad(
$this->paymentBridge,
$paymentMethod
);
/*
* Order Not found Exception must be thrown just here.
*/
if (!$this->paymentBridge->getOrder()) {
throw new PaymentOrderNotFoundException();
}
/*
* Order exists right here.
*/
$this
->paymentEventDispatcher
->notifyPaymentOrderCreated(
$this->paymentBridge,
$paymentMethod
);
/*
* Try to make the payment transaction
*/
try {
$this->paylandsApiAdapter->validateCard($paymentMethod);
$this->paylandsEventDispatcher->notifyCardValid($paymentMethod);
if (!$paymentMethod->isOnlyTokenizeCard()) {
$this->paylandsApiAdapter->createTransaction($paymentMethod);
}
/*
* Payment paid done.
*
* Paid process has ended ( No matters result )
*/
$this
->paymentEventDispatcher
->notifyPaymentOrderDone(
$this->paymentBridge,
$paymentMethod
);
if (PaylandsMethod::STATUS_OK !== $paymentMethod->getPaymentStatus()) {
throw new PaymentException(sprintf('Order %s could not be paid',
$paymentMethod->getPaymentResult()['order']['uuid']
));
}
/*
* Payment paid successfully.
*
* Paid process has ended successfully
*/
$this
->paymentEventDispatcher
->notifyPaymentOrderSuccess(
$this->paymentBridge,
$paymentMethod
);
} catch (PaymentException $e) {
/*
* Payment paid failed.
*
* Paid process has ended failed
*/
$this
->paymentEventDispatcher
->notifyPaymentOrderFail(
$this->paymentBridge,
$paymentMethod
);
throw $e;
}
return $this;
}
|
php
|
public function processPayment(PaylandsMethod $paymentMethod)
{
/*
* At this point, order must be created given a cart, and placed in PaymentBridge.
*
* So, $this->paymentBridge->getOrder() must return an object
*/
$this
->paymentEventDispatcher
->notifyPaymentOrderLoad(
$this->paymentBridge,
$paymentMethod
);
/*
* Order Not found Exception must be thrown just here.
*/
if (!$this->paymentBridge->getOrder()) {
throw new PaymentOrderNotFoundException();
}
/*
* Order exists right here.
*/
$this
->paymentEventDispatcher
->notifyPaymentOrderCreated(
$this->paymentBridge,
$paymentMethod
);
/*
* Try to make the payment transaction
*/
try {
$this->paylandsApiAdapter->validateCard($paymentMethod);
$this->paylandsEventDispatcher->notifyCardValid($paymentMethod);
if (!$paymentMethod->isOnlyTokenizeCard()) {
$this->paylandsApiAdapter->createTransaction($paymentMethod);
}
/*
* Payment paid done.
*
* Paid process has ended ( No matters result )
*/
$this
->paymentEventDispatcher
->notifyPaymentOrderDone(
$this->paymentBridge,
$paymentMethod
);
if (PaylandsMethod::STATUS_OK !== $paymentMethod->getPaymentStatus()) {
throw new PaymentException(sprintf('Order %s could not be paid',
$paymentMethod->getPaymentResult()['order']['uuid']
));
}
/*
* Payment paid successfully.
*
* Paid process has ended successfully
*/
$this
->paymentEventDispatcher
->notifyPaymentOrderSuccess(
$this->paymentBridge,
$paymentMethod
);
} catch (PaymentException $e) {
/*
* Payment paid failed.
*
* Paid process has ended failed
*/
$this
->paymentEventDispatcher
->notifyPaymentOrderFail(
$this->paymentBridge,
$paymentMethod
);
throw $e;
}
return $this;
}
|
[
"public",
"function",
"processPayment",
"(",
"PaylandsMethod",
"$",
"paymentMethod",
")",
"{",
"/*\n * At this point, order must be created given a cart, and placed in PaymentBridge.\n *\n * So, $this->paymentBridge->getOrder() must return an object\n */",
"$",
"this",
"->",
"paymentEventDispatcher",
"->",
"notifyPaymentOrderLoad",
"(",
"$",
"this",
"->",
"paymentBridge",
",",
"$",
"paymentMethod",
")",
";",
"/*\n * Order Not found Exception must be thrown just here.\n */",
"if",
"(",
"!",
"$",
"this",
"->",
"paymentBridge",
"->",
"getOrder",
"(",
")",
")",
"{",
"throw",
"new",
"PaymentOrderNotFoundException",
"(",
")",
";",
"}",
"/*\n * Order exists right here.\n */",
"$",
"this",
"->",
"paymentEventDispatcher",
"->",
"notifyPaymentOrderCreated",
"(",
"$",
"this",
"->",
"paymentBridge",
",",
"$",
"paymentMethod",
")",
";",
"/*\n * Try to make the payment transaction\n */",
"try",
"{",
"$",
"this",
"->",
"paylandsApiAdapter",
"->",
"validateCard",
"(",
"$",
"paymentMethod",
")",
";",
"$",
"this",
"->",
"paylandsEventDispatcher",
"->",
"notifyCardValid",
"(",
"$",
"paymentMethod",
")",
";",
"if",
"(",
"!",
"$",
"paymentMethod",
"->",
"isOnlyTokenizeCard",
"(",
")",
")",
"{",
"$",
"this",
"->",
"paylandsApiAdapter",
"->",
"createTransaction",
"(",
"$",
"paymentMethod",
")",
";",
"}",
"/*\n * Payment paid done.\n *\n * Paid process has ended ( No matters result )\n */",
"$",
"this",
"->",
"paymentEventDispatcher",
"->",
"notifyPaymentOrderDone",
"(",
"$",
"this",
"->",
"paymentBridge",
",",
"$",
"paymentMethod",
")",
";",
"if",
"(",
"PaylandsMethod",
"::",
"STATUS_OK",
"!==",
"$",
"paymentMethod",
"->",
"getPaymentStatus",
"(",
")",
")",
"{",
"throw",
"new",
"PaymentException",
"(",
"sprintf",
"(",
"'Order %s could not be paid'",
",",
"$",
"paymentMethod",
"->",
"getPaymentResult",
"(",
")",
"[",
"'order'",
"]",
"[",
"'uuid'",
"]",
")",
")",
";",
"}",
"/*\n * Payment paid successfully.\n *\n * Paid process has ended successfully\n */",
"$",
"this",
"->",
"paymentEventDispatcher",
"->",
"notifyPaymentOrderSuccess",
"(",
"$",
"this",
"->",
"paymentBridge",
",",
"$",
"paymentMethod",
")",
";",
"}",
"catch",
"(",
"PaymentException",
"$",
"e",
")",
"{",
"/*\n * Payment paid failed.\n *\n * Paid process has ended failed\n */",
"$",
"this",
"->",
"paymentEventDispatcher",
"->",
"notifyPaymentOrderFail",
"(",
"$",
"this",
"->",
"paymentBridge",
",",
"$",
"paymentMethod",
")",
";",
"throw",
"$",
"e",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Tries to process a payment through Paylands.
@param PaylandsMethod $paymentMethod Payment method
@return PaylandsManager Self object
@throws PaymentException
@throws CardInvalidException
|
[
"Tries",
"to",
"process",
"a",
"payment",
"through",
"Paylands",
"."
] |
8ae57df57fa07aff7e59701a0b3c83c504095b92
|
https://github.com/PaymentSuite/paymentsuite/blob/8ae57df57fa07aff7e59701a0b3c83c504095b92/src/PaymentSuite/PaylandsBundle/Services/PaylandsManager.php#L89-L178
|
231,472
|
juliushaertl/phpdoc-to-rst
|
src/Builder/NamespaceIndexBuilder.php
|
NamespaceIndexBuilder.findChildNamespaces
|
private function findChildNamespaces() {
$currentNamespaceFqsen = (string)$this->currentNamespace->getFqsen();
/** @var Namespace_ $namespace */
foreach ($this->namespaces as $namespace) {
// check if not root and doesn't start with current namespace
if ($currentNamespaceFqsen !== '\\' && strpos((string)$namespace->getFqsen(), $currentNamespaceFqsen . '\\') !== 0) {
continue;
}
if ((string)$namespace->getFqsen() !== $currentNamespaceFqsen && strpos((string)$namespace->getFqsen(), $currentNamespaceFqsen) === 0) {
// only keep first level children
$childrenPath = substr((string)$namespace->getFqsen(), strlen((string)$this->currentNamespace->getFqsen()) + 1);
if (strpos($childrenPath, '\\') === false) {
$this->childNamespaces[] = $namespace;
}
}
}
}
|
php
|
private function findChildNamespaces() {
$currentNamespaceFqsen = (string)$this->currentNamespace->getFqsen();
/** @var Namespace_ $namespace */
foreach ($this->namespaces as $namespace) {
// check if not root and doesn't start with current namespace
if ($currentNamespaceFqsen !== '\\' && strpos((string)$namespace->getFqsen(), $currentNamespaceFqsen . '\\') !== 0) {
continue;
}
if ((string)$namespace->getFqsen() !== $currentNamespaceFqsen && strpos((string)$namespace->getFqsen(), $currentNamespaceFqsen) === 0) {
// only keep first level children
$childrenPath = substr((string)$namespace->getFqsen(), strlen((string)$this->currentNamespace->getFqsen()) + 1);
if (strpos($childrenPath, '\\') === false) {
$this->childNamespaces[] = $namespace;
}
}
}
}
|
[
"private",
"function",
"findChildNamespaces",
"(",
")",
"{",
"$",
"currentNamespaceFqsen",
"=",
"(",
"string",
")",
"$",
"this",
"->",
"currentNamespace",
"->",
"getFqsen",
"(",
")",
";",
"/** @var Namespace_ $namespace */",
"foreach",
"(",
"$",
"this",
"->",
"namespaces",
"as",
"$",
"namespace",
")",
"{",
"// check if not root and doesn't start with current namespace",
"if",
"(",
"$",
"currentNamespaceFqsen",
"!==",
"'\\\\'",
"&&",
"strpos",
"(",
"(",
"string",
")",
"$",
"namespace",
"->",
"getFqsen",
"(",
")",
",",
"$",
"currentNamespaceFqsen",
".",
"'\\\\'",
")",
"!==",
"0",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"(",
"string",
")",
"$",
"namespace",
"->",
"getFqsen",
"(",
")",
"!==",
"$",
"currentNamespaceFqsen",
"&&",
"strpos",
"(",
"(",
"string",
")",
"$",
"namespace",
"->",
"getFqsen",
"(",
")",
",",
"$",
"currentNamespaceFqsen",
")",
"===",
"0",
")",
"{",
"// only keep first level children",
"$",
"childrenPath",
"=",
"substr",
"(",
"(",
"string",
")",
"$",
"namespace",
"->",
"getFqsen",
"(",
")",
",",
"strlen",
"(",
"(",
"string",
")",
"$",
"this",
"->",
"currentNamespace",
"->",
"getFqsen",
"(",
")",
")",
"+",
"1",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"childrenPath",
",",
"'\\\\'",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"childNamespaces",
"[",
"]",
"=",
"$",
"namespace",
";",
"}",
"}",
"}",
"}"
] |
Find child namespaces for current namespace
|
[
"Find",
"child",
"namespaces",
"for",
"current",
"namespace"
] |
9a695417d1f3bb709f60cd5c519e46f1ad08c843
|
https://github.com/juliushaertl/phpdoc-to-rst/blob/9a695417d1f3bb709f60cd5c519e46f1ad08c843/src/Builder/NamespaceIndexBuilder.php#L76-L92
|
231,473
|
coduo/TuTu
|
src/Coduo/TuTu/Kernel.php
|
Kernel.getValue
|
private function getValue($value)
{
if (!is_string($value)) {
return $value;
}
if ($value[0] != '%' || $value[strlen($value) - 1] != '%') {
return $value;
}
$parameter = trim($value, '%');
if ($this->container->hasParameter($parameter)) {
return $this->container->getParameter($parameter);
}
return $value;
}
|
php
|
private function getValue($value)
{
if (!is_string($value)) {
return $value;
}
if ($value[0] != '%' || $value[strlen($value) - 1] != '%') {
return $value;
}
$parameter = trim($value, '%');
if ($this->container->hasParameter($parameter)) {
return $this->container->getParameter($parameter);
}
return $value;
}
|
[
"private",
"function",
"getValue",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"if",
"(",
"$",
"value",
"[",
"0",
"]",
"!=",
"'%'",
"||",
"$",
"value",
"[",
"strlen",
"(",
"$",
"value",
")",
"-",
"1",
"]",
"!=",
"'%'",
")",
"{",
"return",
"$",
"value",
";",
"}",
"$",
"parameter",
"=",
"trim",
"(",
"$",
"value",
",",
"'%'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"container",
"->",
"hasParameter",
"(",
"$",
"parameter",
")",
")",
"{",
"return",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"$",
"parameter",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] |
If value is valid string between "%" characters then it might be a parameter
so we need to try take it from container.
@param $value
@return mixed
|
[
"If",
"value",
"is",
"valid",
"string",
"between",
"%",
"characters",
"then",
"it",
"might",
"be",
"a",
"parameter",
"so",
"we",
"need",
"to",
"try",
"take",
"it",
"from",
"container",
"."
] |
4e5f38ec5ffd0e17c5439c7e12c46d0311b76fdc
|
https://github.com/coduo/TuTu/blob/4e5f38ec5ffd0e17c5439c7e12c46d0311b76fdc/src/Coduo/TuTu/Kernel.php#L337-L353
|
231,474
|
niklongstone/regex-reverse
|
src/RegRev/Metacharacter/Range/Range.php
|
Range.generateNegation
|
private function generateNegation($match)
{
$match = str_split($match);
$chars = str_split($this->getChars());
foreach ($match as $negVal) {
if (($key = array_search($negVal, $chars)) !== false) {
if ($negVal == '\\') {
continue;
}
unset($chars[$key]);
}
}
return implode('', $chars);
}
|
php
|
private function generateNegation($match)
{
$match = str_split($match);
$chars = str_split($this->getChars());
foreach ($match as $negVal) {
if (($key = array_search($negVal, $chars)) !== false) {
if ($negVal == '\\') {
continue;
}
unset($chars[$key]);
}
}
return implode('', $chars);
}
|
[
"private",
"function",
"generateNegation",
"(",
"$",
"match",
")",
"{",
"$",
"match",
"=",
"str_split",
"(",
"$",
"match",
")",
";",
"$",
"chars",
"=",
"str_split",
"(",
"$",
"this",
"->",
"getChars",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"match",
"as",
"$",
"negVal",
")",
"{",
"if",
"(",
"(",
"$",
"key",
"=",
"array_search",
"(",
"$",
"negVal",
",",
"$",
"chars",
")",
")",
"!==",
"false",
")",
"{",
"if",
"(",
"$",
"negVal",
"==",
"'\\\\'",
")",
"{",
"continue",
";",
"}",
"unset",
"(",
"$",
"chars",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"return",
"implode",
"(",
"''",
",",
"$",
"chars",
")",
";",
"}"
] |
Removes the negated character from the available chars list.
@param string $match
@return string
|
[
"Removes",
"the",
"negated",
"character",
"from",
"the",
"available",
"chars",
"list",
"."
] |
a93bb266fbc0621094a5d1ad2583b8a54999ea25
|
https://github.com/niklongstone/regex-reverse/blob/a93bb266fbc0621094a5d1ad2583b8a54999ea25/src/RegRev/Metacharacter/Range/Range.php#L111-L125
|
231,475
|
niklongstone/regex-reverse
|
src/RegRev/Metacharacter/Range/Range.php
|
Range.createRange
|
private function createRange($ranges)
{
$rangeOfString = '';
foreach ($ranges as $range) {
$rangeOfString .= implode('', range($range[0], $range[2]));
}
return $rangeOfString;
}
|
php
|
private function createRange($ranges)
{
$rangeOfString = '';
foreach ($ranges as $range) {
$rangeOfString .= implode('', range($range[0], $range[2]));
}
return $rangeOfString;
}
|
[
"private",
"function",
"createRange",
"(",
"$",
"ranges",
")",
"{",
"$",
"rangeOfString",
"=",
"''",
";",
"foreach",
"(",
"$",
"ranges",
"as",
"$",
"range",
")",
"{",
"$",
"rangeOfString",
".=",
"implode",
"(",
"''",
",",
"range",
"(",
"$",
"range",
"[",
"0",
"]",
",",
"$",
"range",
"[",
"2",
"]",
")",
")",
";",
"}",
"return",
"$",
"rangeOfString",
";",
"}"
] |
Creates the characters ranges.
@param array $ranges
@return string
|
[
"Creates",
"the",
"characters",
"ranges",
"."
] |
a93bb266fbc0621094a5d1ad2583b8a54999ea25
|
https://github.com/niklongstone/regex-reverse/blob/a93bb266fbc0621094a5d1ad2583b8a54999ea25/src/RegRev/Metacharacter/Range/Range.php#L134-L142
|
231,476
|
colorfield/mastodon-api-php
|
src/MastodonAPI.php
|
MastodonAPI.getResponse
|
private function getResponse($endpoint, $operation, array $json)
{
$result = null;
$uri = $this->config->getBaseUrl() . '/api/';
$uri .= ConfigurationVO::API_VERSION . $endpoint;
$allowedOperations = ['get', 'post'];
if(!in_array($operation, $allowedOperations)) {
echo 'ERROR: only ' . implode(',', $allowedOperations) . 'are allowed';
return $result;
}
try {
$response = $this->client->{$operation}($uri, [
'headers' => [
'Authorization' => 'Bearer ' . $this->config->getBearer(),
],
'json' => $json,
]);
// @todo $request->getHeader('content-type')
if($response instanceof ResponseInterface
&& $response->getStatusCode() == '200') {
$result = json_decode($response->getBody(), true);
}else{
echo 'ERROR: Status code ' . $response->getStatusCode();
}
// @todo check thrown exception
} catch (\Exception $exception) {
echo 'ERROR: ' . $exception->getMessage();
}
return $result;
}
|
php
|
private function getResponse($endpoint, $operation, array $json)
{
$result = null;
$uri = $this->config->getBaseUrl() . '/api/';
$uri .= ConfigurationVO::API_VERSION . $endpoint;
$allowedOperations = ['get', 'post'];
if(!in_array($operation, $allowedOperations)) {
echo 'ERROR: only ' . implode(',', $allowedOperations) . 'are allowed';
return $result;
}
try {
$response = $this->client->{$operation}($uri, [
'headers' => [
'Authorization' => 'Bearer ' . $this->config->getBearer(),
],
'json' => $json,
]);
// @todo $request->getHeader('content-type')
if($response instanceof ResponseInterface
&& $response->getStatusCode() == '200') {
$result = json_decode($response->getBody(), true);
}else{
echo 'ERROR: Status code ' . $response->getStatusCode();
}
// @todo check thrown exception
} catch (\Exception $exception) {
echo 'ERROR: ' . $exception->getMessage();
}
return $result;
}
|
[
"private",
"function",
"getResponse",
"(",
"$",
"endpoint",
",",
"$",
"operation",
",",
"array",
"$",
"json",
")",
"{",
"$",
"result",
"=",
"null",
";",
"$",
"uri",
"=",
"$",
"this",
"->",
"config",
"->",
"getBaseUrl",
"(",
")",
".",
"'/api/'",
";",
"$",
"uri",
".=",
"ConfigurationVO",
"::",
"API_VERSION",
".",
"$",
"endpoint",
";",
"$",
"allowedOperations",
"=",
"[",
"'get'",
",",
"'post'",
"]",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"operation",
",",
"$",
"allowedOperations",
")",
")",
"{",
"echo",
"'ERROR: only '",
".",
"implode",
"(",
"','",
",",
"$",
"allowedOperations",
")",
".",
"'are allowed'",
";",
"return",
"$",
"result",
";",
"}",
"try",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"{",
"$",
"operation",
"}",
"(",
"$",
"uri",
",",
"[",
"'headers'",
"=>",
"[",
"'Authorization'",
"=>",
"'Bearer '",
".",
"$",
"this",
"->",
"config",
"->",
"getBearer",
"(",
")",
",",
"]",
",",
"'json'",
"=>",
"$",
"json",
",",
"]",
")",
";",
"// @todo $request->getHeader('content-type')",
"if",
"(",
"$",
"response",
"instanceof",
"ResponseInterface",
"&&",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
"==",
"'200'",
")",
"{",
"$",
"result",
"=",
"json_decode",
"(",
"$",
"response",
"->",
"getBody",
"(",
")",
",",
"true",
")",
";",
"}",
"else",
"{",
"echo",
"'ERROR: Status code '",
".",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
";",
"}",
"// @todo check thrown exception",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"echo",
"'ERROR: '",
".",
"$",
"exception",
"->",
"getMessage",
"(",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Request to an endpoint.
@param $endpoint
@param array $json
@return mixed|null
|
[
"Request",
"to",
"an",
"endpoint",
"."
] |
cd9cb946032508e48630fffd5a661f3347d0b84f
|
https://github.com/colorfield/mastodon-api-php/blob/cd9cb946032508e48630fffd5a661f3347d0b84f/src/MastodonAPI.php#L55-L86
|
231,477
|
schemaio/schema-php-client
|
lib/Cache.php
|
Cache.get_path
|
public function get_path()
{
$cache_path = rtrim($this->params['path'], '/')
.'/client'.'.'.$this->params['client_id'];
foreach (func_get_args() as $arg) {
$cache_path .= '.'.$arg;
}
return $cache_path;
}
|
php
|
public function get_path()
{
$cache_path = rtrim($this->params['path'], '/')
.'/client'.'.'.$this->params['client_id'];
foreach (func_get_args() as $arg) {
$cache_path .= '.'.$arg;
}
return $cache_path;
}
|
[
"public",
"function",
"get_path",
"(",
")",
"{",
"$",
"cache_path",
"=",
"rtrim",
"(",
"$",
"this",
"->",
"params",
"[",
"'path'",
"]",
",",
"'/'",
")",
".",
"'/client'",
".",
"'.'",
".",
"$",
"this",
"->",
"params",
"[",
"'client_id'",
"]",
";",
"foreach",
"(",
"func_get_args",
"(",
")",
"as",
"$",
"arg",
")",
"{",
"$",
"cache_path",
".=",
"'.'",
".",
"$",
"arg",
";",
"}",
"return",
"$",
"cache_path",
";",
"}"
] |
Get path to a cache file
@return string
|
[
"Get",
"path",
"to",
"a",
"cache",
"file"
] |
20759434a6dd7fcc38910eca5ad228287472751b
|
https://github.com/schemaio/schema-php-client/blob/20759434a6dd7fcc38910eca5ad228287472751b/lib/Cache.php#L107-L117
|
231,478
|
schemaio/schema-php-client
|
lib/Cache.php
|
Cache.get_versions
|
public function get_versions()
{
if (!$this->versions) {
$this->versions = array();
if ($json = $this->get_cache('versions')) {
$this->versions = json_decode($json, true);
}
}
return $this->versions;
}
|
php
|
public function get_versions()
{
if (!$this->versions) {
$this->versions = array();
if ($json = $this->get_cache('versions')) {
$this->versions = json_decode($json, true);
}
}
return $this->versions;
}
|
[
"public",
"function",
"get_versions",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"versions",
")",
"{",
"$",
"this",
"->",
"versions",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"json",
"=",
"$",
"this",
"->",
"get_cache",
"(",
"'versions'",
")",
")",
"{",
"$",
"this",
"->",
"versions",
"=",
"json_decode",
"(",
"$",
"json",
",",
"true",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"versions",
";",
"}"
] |
Get cache version info
@return array
|
[
"Get",
"cache",
"version",
"info"
] |
20759434a6dd7fcc38910eca5ad228287472751b
|
https://github.com/schemaio/schema-php-client/blob/20759434a6dd7fcc38910eca5ad228287472751b/lib/Cache.php#L124-L134
|
231,479
|
schemaio/schema-php-client
|
lib/Cache.php
|
Cache.get_index
|
public function get_index()
{
if (!$this->indexes) {
$this->indexes = array();
if ($json = $this->get_cache('index')) {
$this->indexes = json_decode($json, true);
}
}
return $this->indexes;
}
|
php
|
public function get_index()
{
if (!$this->indexes) {
$this->indexes = array();
if ($json = $this->get_cache('index')) {
$this->indexes = json_decode($json, true);
}
}
return $this->indexes;
}
|
[
"public",
"function",
"get_index",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"indexes",
")",
"{",
"$",
"this",
"->",
"indexes",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"json",
"=",
"$",
"this",
"->",
"get_cache",
"(",
"'index'",
")",
")",
"{",
"$",
"this",
"->",
"indexes",
"=",
"json_decode",
"(",
"$",
"json",
",",
"true",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"indexes",
";",
"}"
] |
Get cache index info
@return array
|
[
"Get",
"cache",
"index",
"info"
] |
20759434a6dd7fcc38910eca5ad228287472751b
|
https://github.com/schemaio/schema-php-client/blob/20759434a6dd7fcc38910eca5ad228287472751b/lib/Cache.php#L141-L151
|
231,480
|
schemaio/schema-php-client
|
lib/Cache.php
|
Cache.put
|
public function put($url, $data, $result)
{
if (!array_key_exists('$data', $result)) {
$result['$data'] = null; // Allows for null response
}
$this->get_versions();
$cache_content = $result;
$cache_content['$cached'] = true;
$cache_key = $this->get_key($url, $data);
$cache_path = $this->get_path($cache_key, 'result');
if ($size = $this->write_cache($cache_path, $cache_content)) {
if (isset($result['$cached'])) {
$cached = $result['$cached'];
foreach ($this->result_collections($result) as $collection) {
// Collection may not be cacheable
if (!isset($cached[$collection]) && !isset($this->versions[$collection])) {
continue;
}
$this->put_index($collection, $cache_key, $size);
if (isset($cached[$collection])) {
$this->put_version($collection, $cached[$collection]);
}
}
}
}
}
|
php
|
public function put($url, $data, $result)
{
if (!array_key_exists('$data', $result)) {
$result['$data'] = null; // Allows for null response
}
$this->get_versions();
$cache_content = $result;
$cache_content['$cached'] = true;
$cache_key = $this->get_key($url, $data);
$cache_path = $this->get_path($cache_key, 'result');
if ($size = $this->write_cache($cache_path, $cache_content)) {
if (isset($result['$cached'])) {
$cached = $result['$cached'];
foreach ($this->result_collections($result) as $collection) {
// Collection may not be cacheable
if (!isset($cached[$collection]) && !isset($this->versions[$collection])) {
continue;
}
$this->put_index($collection, $cache_key, $size);
if (isset($cached[$collection])) {
$this->put_version($collection, $cached[$collection]);
}
}
}
}
}
|
[
"public",
"function",
"put",
"(",
"$",
"url",
",",
"$",
"data",
",",
"$",
"result",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"'$data'",
",",
"$",
"result",
")",
")",
"{",
"$",
"result",
"[",
"'$data'",
"]",
"=",
"null",
";",
"// Allows for null response",
"}",
"$",
"this",
"->",
"get_versions",
"(",
")",
";",
"$",
"cache_content",
"=",
"$",
"result",
";",
"$",
"cache_content",
"[",
"'$cached'",
"]",
"=",
"true",
";",
"$",
"cache_key",
"=",
"$",
"this",
"->",
"get_key",
"(",
"$",
"url",
",",
"$",
"data",
")",
";",
"$",
"cache_path",
"=",
"$",
"this",
"->",
"get_path",
"(",
"$",
"cache_key",
",",
"'result'",
")",
";",
"if",
"(",
"$",
"size",
"=",
"$",
"this",
"->",
"write_cache",
"(",
"$",
"cache_path",
",",
"$",
"cache_content",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"result",
"[",
"'$cached'",
"]",
")",
")",
"{",
"$",
"cached",
"=",
"$",
"result",
"[",
"'$cached'",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"result_collections",
"(",
"$",
"result",
")",
"as",
"$",
"collection",
")",
"{",
"// Collection may not be cacheable",
"if",
"(",
"!",
"isset",
"(",
"$",
"cached",
"[",
"$",
"collection",
"]",
")",
"&&",
"!",
"isset",
"(",
"$",
"this",
"->",
"versions",
"[",
"$",
"collection",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"put_index",
"(",
"$",
"collection",
",",
"$",
"cache_key",
",",
"$",
"size",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"cached",
"[",
"$",
"collection",
"]",
")",
")",
"{",
"$",
"this",
"->",
"put_version",
"(",
"$",
"collection",
",",
"$",
"cached",
"[",
"$",
"collection",
"]",
")",
";",
"}",
"}",
"}",
"}",
"}"
] |
Put cache result in file system cache atomicly
@param string $url
@param mixed $data
@param mixed $result
@return void
|
[
"Put",
"cache",
"result",
"in",
"file",
"system",
"cache",
"atomicly"
] |
20759434a6dd7fcc38910eca5ad228287472751b
|
https://github.com/schemaio/schema-php-client/blob/20759434a6dd7fcc38910eca5ad228287472751b/lib/Cache.php#L161-L189
|
231,481
|
schemaio/schema-php-client
|
lib/Cache.php
|
Cache.remove
|
public function remove($url, $data = null)
{
$cache_key = $this->get_key($url, $data);
$cache_path = $this->get_path($cache_key, 'result');
$this->clear_cache($cache_path);
}
|
php
|
public function remove($url, $data = null)
{
$cache_key = $this->get_key($url, $data);
$cache_path = $this->get_path($cache_key, 'result');
$this->clear_cache($cache_path);
}
|
[
"public",
"function",
"remove",
"(",
"$",
"url",
",",
"$",
"data",
"=",
"null",
")",
"{",
"$",
"cache_key",
"=",
"$",
"this",
"->",
"get_key",
"(",
"$",
"url",
",",
"$",
"data",
")",
";",
"$",
"cache_path",
"=",
"$",
"this",
"->",
"get_path",
"(",
"$",
"cache_key",
",",
"'result'",
")",
";",
"$",
"this",
"->",
"clear_cache",
"(",
"$",
"cache_path",
")",
";",
"}"
] |
Remove an entry from cache base on url and data
This is mostly used for caching variables as opposed to client results
@param string $url
@param mixed $data
@return void
|
[
"Remove",
"an",
"entry",
"from",
"cache",
"base",
"on",
"url",
"and",
"data",
"This",
"is",
"mostly",
"used",
"for",
"caching",
"variables",
"as",
"opposed",
"to",
"client",
"results"
] |
20759434a6dd7fcc38910eca5ad228287472751b
|
https://github.com/schemaio/schema-php-client/blob/20759434a6dd7fcc38910eca5ad228287472751b/lib/Cache.php#L224-L229
|
231,482
|
schemaio/schema-php-client
|
lib/Cache.php
|
Cache.clear
|
public function clear($result)
{
$invalid = array();
$this->get_versions();
if (isset($result['$cached'])) {
foreach ((array)$result['$cached'] as $collection => $ver) {
if (!isset($this->versions[$collection]) || $ver != $this->versions[$collection]) {
$this->put_version($collection, $ver);
$invalid[$collection] = true;
// Hack to make admin.settings affect other api.settings
// TODO: figure out how to do this on the server side
if ($collection === 'admin.settings') {
foreach ((array)$this->versions as $vcoll => $vv) {
if (preg_match('/\.settings$/', $vcoll)) {
$invalid[$vcoll] = true;
}
}
}
}
}
}
if (!empty($invalid)) {
$this->clear_indexes($invalid);
}
}
|
php
|
public function clear($result)
{
$invalid = array();
$this->get_versions();
if (isset($result['$cached'])) {
foreach ((array)$result['$cached'] as $collection => $ver) {
if (!isset($this->versions[$collection]) || $ver != $this->versions[$collection]) {
$this->put_version($collection, $ver);
$invalid[$collection] = true;
// Hack to make admin.settings affect other api.settings
// TODO: figure out how to do this on the server side
if ($collection === 'admin.settings') {
foreach ((array)$this->versions as $vcoll => $vv) {
if (preg_match('/\.settings$/', $vcoll)) {
$invalid[$vcoll] = true;
}
}
}
}
}
}
if (!empty($invalid)) {
$this->clear_indexes($invalid);
}
}
|
[
"public",
"function",
"clear",
"(",
"$",
"result",
")",
"{",
"$",
"invalid",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"get_versions",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"result",
"[",
"'$cached'",
"]",
")",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"result",
"[",
"'$cached'",
"]",
"as",
"$",
"collection",
"=>",
"$",
"ver",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"versions",
"[",
"$",
"collection",
"]",
")",
"||",
"$",
"ver",
"!=",
"$",
"this",
"->",
"versions",
"[",
"$",
"collection",
"]",
")",
"{",
"$",
"this",
"->",
"put_version",
"(",
"$",
"collection",
",",
"$",
"ver",
")",
";",
"$",
"invalid",
"[",
"$",
"collection",
"]",
"=",
"true",
";",
"// Hack to make admin.settings affect other api.settings",
"// TODO: figure out how to do this on the server side",
"if",
"(",
"$",
"collection",
"===",
"'admin.settings'",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"this",
"->",
"versions",
"as",
"$",
"vcoll",
"=>",
"$",
"vv",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/\\.settings$/'",
",",
"$",
"vcoll",
")",
")",
"{",
"$",
"invalid",
"[",
"$",
"vcoll",
"]",
"=",
"true",
";",
"}",
"}",
"}",
"}",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"invalid",
")",
")",
"{",
"$",
"this",
"->",
"clear_indexes",
"(",
"$",
"invalid",
")",
";",
"}",
"}"
] |
Clear all cache entries made invalid by result
@param string $url
@param mixed $data
@param mixed $result
@return void
|
[
"Clear",
"all",
"cache",
"entries",
"made",
"invalid",
"by",
"result"
] |
20759434a6dd7fcc38910eca5ad228287472751b
|
https://github.com/schemaio/schema-php-client/blob/20759434a6dd7fcc38910eca5ad228287472751b/lib/Cache.php#L274-L299
|
231,483
|
schemaio/schema-php-client
|
lib/Cache.php
|
Cache.clear_indexes
|
public function clear_indexes($invalid)
{
if (empty($invalid)) {
return;
}
$this->get_index();
foreach ($invalid as $collection => $key) {
// Clear all indexes per collection
if (isset($this->indexes[$collection])) {
if ($key === true) {
foreach ($this->indexes[$collection] as $cache_key => $size) {
$cache_path = $this->get_path($cache_key, 'result');
$this->clear_cache($cache_path);
unset($this->indexes[$collection][$cache_key]);
}
}
// Clear a single index element by key
else if ($key && isset($this->indexes[$collection][$key])) {
$cache_path = $this->get_path($key, 'result');
$this->clear_cache($cache_path);
unset($this->indexes[$collection][$key]);
}
}
}
$index_path = $this->get_path('index');
$this->write_cache($index_path, $this->indexes);
}
|
php
|
public function clear_indexes($invalid)
{
if (empty($invalid)) {
return;
}
$this->get_index();
foreach ($invalid as $collection => $key) {
// Clear all indexes per collection
if (isset($this->indexes[$collection])) {
if ($key === true) {
foreach ($this->indexes[$collection] as $cache_key => $size) {
$cache_path = $this->get_path($cache_key, 'result');
$this->clear_cache($cache_path);
unset($this->indexes[$collection][$cache_key]);
}
}
// Clear a single index element by key
else if ($key && isset($this->indexes[$collection][$key])) {
$cache_path = $this->get_path($key, 'result');
$this->clear_cache($cache_path);
unset($this->indexes[$collection][$key]);
}
}
}
$index_path = $this->get_path('index');
$this->write_cache($index_path, $this->indexes);
}
|
[
"public",
"function",
"clear_indexes",
"(",
"$",
"invalid",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"invalid",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"get_index",
"(",
")",
";",
"foreach",
"(",
"$",
"invalid",
"as",
"$",
"collection",
"=>",
"$",
"key",
")",
"{",
"// Clear all indexes per collection",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"indexes",
"[",
"$",
"collection",
"]",
")",
")",
"{",
"if",
"(",
"$",
"key",
"===",
"true",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"indexes",
"[",
"$",
"collection",
"]",
"as",
"$",
"cache_key",
"=>",
"$",
"size",
")",
"{",
"$",
"cache_path",
"=",
"$",
"this",
"->",
"get_path",
"(",
"$",
"cache_key",
",",
"'result'",
")",
";",
"$",
"this",
"->",
"clear_cache",
"(",
"$",
"cache_path",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"indexes",
"[",
"$",
"collection",
"]",
"[",
"$",
"cache_key",
"]",
")",
";",
"}",
"}",
"// Clear a single index element by key",
"else",
"if",
"(",
"$",
"key",
"&&",
"isset",
"(",
"$",
"this",
"->",
"indexes",
"[",
"$",
"collection",
"]",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"cache_path",
"=",
"$",
"this",
"->",
"get_path",
"(",
"$",
"key",
",",
"'result'",
")",
";",
"$",
"this",
"->",
"clear_cache",
"(",
"$",
"cache_path",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"indexes",
"[",
"$",
"collection",
"]",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"}",
"$",
"index_path",
"=",
"$",
"this",
"->",
"get_path",
"(",
"'index'",
")",
";",
"$",
"this",
"->",
"write_cache",
"(",
"$",
"index_path",
",",
"$",
"this",
"->",
"indexes",
")",
";",
"}"
] |
Clear cache index for a certain collection
@param array $invalid
@return void
|
[
"Clear",
"cache",
"index",
"for",
"a",
"certain",
"collection"
] |
20759434a6dd7fcc38910eca5ad228287472751b
|
https://github.com/schemaio/schema-php-client/blob/20759434a6dd7fcc38910eca5ad228287472751b/lib/Cache.php#L307-L333
|
231,484
|
schemaio/schema-php-client
|
lib/Cache.php
|
Cache.get_cache
|
public function get_cache()
{
$args = func_get_args();
$cache_path = call_user_func_array(array($this, 'get_path'), $args);
if (is_file($cache_path)) {
return file_get_contents($cache_path);
}
return null;
}
|
php
|
public function get_cache()
{
$args = func_get_args();
$cache_path = call_user_func_array(array($this, 'get_path'), $args);
if (is_file($cache_path)) {
return file_get_contents($cache_path);
}
return null;
}
|
[
"public",
"function",
"get_cache",
"(",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"$",
"cache_path",
"=",
"call_user_func_array",
"(",
"array",
"(",
"$",
"this",
",",
"'get_path'",
")",
",",
"$",
"args",
")",
";",
"if",
"(",
"is_file",
"(",
"$",
"cache_path",
")",
")",
"{",
"return",
"file_get_contents",
"(",
"$",
"cache_path",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Get cache content
@return string
|
[
"Get",
"cache",
"content"
] |
20759434a6dd7fcc38910eca5ad228287472751b
|
https://github.com/schemaio/schema-php-client/blob/20759434a6dd7fcc38910eca5ad228287472751b/lib/Cache.php#L340-L349
|
231,485
|
schemaio/schema-php-client
|
lib/Cache.php
|
Cache.write_cache
|
public function write_cache($cache_path, $content)
{
$cache_content = json_encode($content);
$cache_size = strlen($cache_content);
$temp = tempnam($this->params['path'], 'temp');
if (!($f = @fopen($temp, 'wb'))) {
$temp = $this->params['path'].'/'.uniqid('temp');
if (!($f = @fopen($temp, 'wb'))) {
throw new WriteException('Unable to write temporary file '.$temp);
}
}
fwrite($f, $cache_content);
fclose($f);
if (!rename($temp, $cache_path)) {
unlink($cache_path);
rename($temp, $cache_path);
}
chmod($cache_path, $this->params['write_perms']);
return $cache_size;
}
|
php
|
public function write_cache($cache_path, $content)
{
$cache_content = json_encode($content);
$cache_size = strlen($cache_content);
$temp = tempnam($this->params['path'], 'temp');
if (!($f = @fopen($temp, 'wb'))) {
$temp = $this->params['path'].'/'.uniqid('temp');
if (!($f = @fopen($temp, 'wb'))) {
throw new WriteException('Unable to write temporary file '.$temp);
}
}
fwrite($f, $cache_content);
fclose($f);
if (!rename($temp, $cache_path)) {
unlink($cache_path);
rename($temp, $cache_path);
}
chmod($cache_path, $this->params['write_perms']);
return $cache_size;
}
|
[
"public",
"function",
"write_cache",
"(",
"$",
"cache_path",
",",
"$",
"content",
")",
"{",
"$",
"cache_content",
"=",
"json_encode",
"(",
"$",
"content",
")",
";",
"$",
"cache_size",
"=",
"strlen",
"(",
"$",
"cache_content",
")",
";",
"$",
"temp",
"=",
"tempnam",
"(",
"$",
"this",
"->",
"params",
"[",
"'path'",
"]",
",",
"'temp'",
")",
";",
"if",
"(",
"!",
"(",
"$",
"f",
"=",
"@",
"fopen",
"(",
"$",
"temp",
",",
"'wb'",
")",
")",
")",
"{",
"$",
"temp",
"=",
"$",
"this",
"->",
"params",
"[",
"'path'",
"]",
".",
"'/'",
".",
"uniqid",
"(",
"'temp'",
")",
";",
"if",
"(",
"!",
"(",
"$",
"f",
"=",
"@",
"fopen",
"(",
"$",
"temp",
",",
"'wb'",
")",
")",
")",
"{",
"throw",
"new",
"WriteException",
"(",
"'Unable to write temporary file '",
".",
"$",
"temp",
")",
";",
"}",
"}",
"fwrite",
"(",
"$",
"f",
",",
"$",
"cache_content",
")",
";",
"fclose",
"(",
"$",
"f",
")",
";",
"if",
"(",
"!",
"rename",
"(",
"$",
"temp",
",",
"$",
"cache_path",
")",
")",
"{",
"unlink",
"(",
"$",
"cache_path",
")",
";",
"rename",
"(",
"$",
"temp",
",",
"$",
"cache_path",
")",
";",
"}",
"chmod",
"(",
"$",
"cache_path",
",",
"$",
"this",
"->",
"params",
"[",
"'write_perms'",
"]",
")",
";",
"return",
"$",
"cache_size",
";",
"}"
] |
Write to cache atomically
@param string $cache_path
@param mixed $content
@return int
|
[
"Write",
"to",
"cache",
"atomically"
] |
20759434a6dd7fcc38910eca5ad228287472751b
|
https://github.com/schemaio/schema-php-client/blob/20759434a6dd7fcc38910eca5ad228287472751b/lib/Cache.php#L358-L382
|
231,486
|
schemaio/schema-php-client
|
lib/Cache.php
|
Cache.result_collections
|
public function result_collections($result)
{
// Combine $collection and $expanded headers
$collections = isset($result['$collection'])
? array($result['$collection'])
: array();
if (isset($result['$expanded'])) {
foreach ($result['$expanded'] as $expanded_collection) {
$collections[] = $expanded_collection;
}
}
return $collections;
}
|
php
|
public function result_collections($result)
{
// Combine $collection and $expanded headers
$collections = isset($result['$collection'])
? array($result['$collection'])
: array();
if (isset($result['$expanded'])) {
foreach ($result['$expanded'] as $expanded_collection) {
$collections[] = $expanded_collection;
}
}
return $collections;
}
|
[
"public",
"function",
"result_collections",
"(",
"$",
"result",
")",
"{",
"// Combine $collection and $expanded headers",
"$",
"collections",
"=",
"isset",
"(",
"$",
"result",
"[",
"'$collection'",
"]",
")",
"?",
"array",
"(",
"$",
"result",
"[",
"'$collection'",
"]",
")",
":",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"result",
"[",
"'$expanded'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"result",
"[",
"'$expanded'",
"]",
"as",
"$",
"expanded_collection",
")",
"{",
"$",
"collections",
"[",
"]",
"=",
"$",
"expanded_collection",
";",
"}",
"}",
"return",
"$",
"collections",
";",
"}"
] |
Get array of collections affected by a result
@param array $result
@return array
|
[
"Get",
"array",
"of",
"collections",
"affected",
"by",
"a",
"result"
] |
20759434a6dd7fcc38910eca5ad228287472751b
|
https://github.com/schemaio/schema-php-client/blob/20759434a6dd7fcc38910eca5ad228287472751b/lib/Cache.php#L401-L415
|
231,487
|
schemaio/schema-php-client
|
lib/Client.php
|
Client.params
|
public function params($merge = null)
{
if (is_array($merge)) {
$this->params = array_merge($this->params, $merge);
} else if (is_string($key = $merge)) {
return $this->params[$key];
} else {
return $this->params;
}
}
|
php
|
public function params($merge = null)
{
if (is_array($merge)) {
$this->params = array_merge($this->params, $merge);
} else if (is_string($key = $merge)) {
return $this->params[$key];
} else {
return $this->params;
}
}
|
[
"public",
"function",
"params",
"(",
"$",
"merge",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"merge",
")",
")",
"{",
"$",
"this",
"->",
"params",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"params",
",",
"$",
"merge",
")",
";",
"}",
"else",
"if",
"(",
"is_string",
"(",
"$",
"key",
"=",
"$",
"merge",
")",
")",
"{",
"return",
"$",
"this",
"->",
"params",
"[",
"$",
"key",
"]",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"params",
";",
"}",
"}"
] |
Get or set client params
@param mixed $merge
@param array
|
[
"Get",
"or",
"set",
"client",
"params"
] |
20759434a6dd7fcc38910eca5ad228287472751b
|
https://github.com/schemaio/schema-php-client/blob/20759434a6dd7fcc38910eca5ad228287472751b/lib/Client.php#L126-L135
|
231,488
|
schemaio/schema-php-client
|
lib/Client.php
|
Client.request_rescue
|
protected function request_rescue($e)
{
if ($this->params['rescue']
&& $this->params['client_id']
&& $this->params['client_key']) {
if ($this->params['rescued']) {
throw $e; // Prevent recursion
} else {
$this->params(array('rescued' => true));
$this->server = new Connection(array(
'host' => $this->params['rescue']['host'],
'port' => $this->params['rescue']['port'],
'verify_cert' => $this->params['verify_cert']
));
$this->server->connect();
}
}
}
|
php
|
protected function request_rescue($e)
{
if ($this->params['rescue']
&& $this->params['client_id']
&& $this->params['client_key']) {
if ($this->params['rescued']) {
throw $e; // Prevent recursion
} else {
$this->params(array('rescued' => true));
$this->server = new Connection(array(
'host' => $this->params['rescue']['host'],
'port' => $this->params['rescue']['port'],
'verify_cert' => $this->params['verify_cert']
));
$this->server->connect();
}
}
}
|
[
"protected",
"function",
"request_rescue",
"(",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"params",
"[",
"'rescue'",
"]",
"&&",
"$",
"this",
"->",
"params",
"[",
"'client_id'",
"]",
"&&",
"$",
"this",
"->",
"params",
"[",
"'client_key'",
"]",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"params",
"[",
"'rescued'",
"]",
")",
"{",
"throw",
"$",
"e",
";",
"// Prevent recursion",
"}",
"else",
"{",
"$",
"this",
"->",
"params",
"(",
"array",
"(",
"'rescued'",
"=>",
"true",
")",
")",
";",
"$",
"this",
"->",
"server",
"=",
"new",
"Connection",
"(",
"array",
"(",
"'host'",
"=>",
"$",
"this",
"->",
"params",
"[",
"'rescue'",
"]",
"[",
"'host'",
"]",
",",
"'port'",
"=>",
"$",
"this",
"->",
"params",
"[",
"'rescue'",
"]",
"[",
"'port'",
"]",
",",
"'verify_cert'",
"=>",
"$",
"this",
"->",
"params",
"[",
"'verify_cert'",
"]",
")",
")",
";",
"$",
"this",
"->",
"server",
"->",
"connect",
"(",
")",
";",
"}",
"}",
"}"
] |
Request from a rescue server
@param Exception
@return void
|
[
"Request",
"from",
"a",
"rescue",
"server"
] |
20759434a6dd7fcc38910eca5ad228287472751b
|
https://github.com/schemaio/schema-php-client/blob/20759434a6dd7fcc38910eca5ad228287472751b/lib/Client.php#L203-L221
|
231,489
|
schemaio/schema-php-client
|
lib/Client.php
|
Client.request_proxy_data
|
protected function request_proxy_data($data)
{
if (isset($this->params['rescued'])) {
return $data;
}
$data['$proxy'] = array(
'client' => isset($this->params['route']['client'])
? $this->params['route']['client']
: $this->params['client_id'],
'host' => $this->params['host'],
'port' => $this->params['port']
);
if (is_array($this->params['proxy'])) {
$this->server->options['clear'] = isset($this->params['proxy']['clear'])
? $this->params['proxy']['clear'] : false;
$this->server->options['host'] = isset($this->params['proxy']['host'])
? $this->params['proxy']['host'] : $this->params['host'];
$this->server->options['port'] = isset($this->params['proxy']['port'])
? $this->params['proxy']['port'] : $this->params['port'];
}
return $data;
}
|
php
|
protected function request_proxy_data($data)
{
if (isset($this->params['rescued'])) {
return $data;
}
$data['$proxy'] = array(
'client' => isset($this->params['route']['client'])
? $this->params['route']['client']
: $this->params['client_id'],
'host' => $this->params['host'],
'port' => $this->params['port']
);
if (is_array($this->params['proxy'])) {
$this->server->options['clear'] = isset($this->params['proxy']['clear'])
? $this->params['proxy']['clear'] : false;
$this->server->options['host'] = isset($this->params['proxy']['host'])
? $this->params['proxy']['host'] : $this->params['host'];
$this->server->options['port'] = isset($this->params['proxy']['port'])
? $this->params['proxy']['port'] : $this->params['port'];
}
return $data;
}
|
[
"protected",
"function",
"request_proxy_data",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"params",
"[",
"'rescued'",
"]",
")",
")",
"{",
"return",
"$",
"data",
";",
"}",
"$",
"data",
"[",
"'$proxy'",
"]",
"=",
"array",
"(",
"'client'",
"=>",
"isset",
"(",
"$",
"this",
"->",
"params",
"[",
"'route'",
"]",
"[",
"'client'",
"]",
")",
"?",
"$",
"this",
"->",
"params",
"[",
"'route'",
"]",
"[",
"'client'",
"]",
":",
"$",
"this",
"->",
"params",
"[",
"'client_id'",
"]",
",",
"'host'",
"=>",
"$",
"this",
"->",
"params",
"[",
"'host'",
"]",
",",
"'port'",
"=>",
"$",
"this",
"->",
"params",
"[",
"'port'",
"]",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"params",
"[",
"'proxy'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"server",
"->",
"options",
"[",
"'clear'",
"]",
"=",
"isset",
"(",
"$",
"this",
"->",
"params",
"[",
"'proxy'",
"]",
"[",
"'clear'",
"]",
")",
"?",
"$",
"this",
"->",
"params",
"[",
"'proxy'",
"]",
"[",
"'clear'",
"]",
":",
"false",
";",
"$",
"this",
"->",
"server",
"->",
"options",
"[",
"'host'",
"]",
"=",
"isset",
"(",
"$",
"this",
"->",
"params",
"[",
"'proxy'",
"]",
"[",
"'host'",
"]",
")",
"?",
"$",
"this",
"->",
"params",
"[",
"'proxy'",
"]",
"[",
"'host'",
"]",
":",
"$",
"this",
"->",
"params",
"[",
"'host'",
"]",
";",
"$",
"this",
"->",
"server",
"->",
"options",
"[",
"'port'",
"]",
"=",
"isset",
"(",
"$",
"this",
"->",
"params",
"[",
"'proxy'",
"]",
"[",
"'port'",
"]",
")",
"?",
"$",
"this",
"->",
"params",
"[",
"'proxy'",
"]",
"[",
"'port'",
"]",
":",
"$",
"this",
"->",
"params",
"[",
"'port'",
"]",
";",
"}",
"return",
"$",
"data",
";",
"}"
] |
Modify request to pass through an API proxy
@param array $data
@return array
|
[
"Modify",
"request",
"to",
"pass",
"through",
"an",
"API",
"proxy"
] |
20759434a6dd7fcc38910eca5ad228287472751b
|
https://github.com/schemaio/schema-php-client/blob/20759434a6dd7fcc38910eca5ad228287472751b/lib/Client.php#L229-L252
|
231,490
|
schemaio/schema-php-client
|
lib/Client.php
|
Client.response_data
|
protected function response_data($result, $method, $url)
{
if (isset($result['$data'])) {
if (is_array($result['$data'])) {
return Resource::instance($result, $this);
}
return $result['$data'];
}
return null;
}
|
php
|
protected function response_data($result, $method, $url)
{
if (isset($result['$data'])) {
if (is_array($result['$data'])) {
return Resource::instance($result, $this);
}
return $result['$data'];
}
return null;
}
|
[
"protected",
"function",
"response_data",
"(",
"$",
"result",
",",
"$",
"method",
",",
"$",
"url",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"result",
"[",
"'$data'",
"]",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"result",
"[",
"'$data'",
"]",
")",
")",
"{",
"return",
"Resource",
"::",
"instance",
"(",
"$",
"result",
",",
"$",
"this",
")",
";",
"}",
"return",
"$",
"result",
"[",
"'$data'",
"]",
";",
"}",
"return",
"null",
";",
"}"
] |
Instantiate resource for response data if applicable
@param array $result
@return mixed
|
[
"Instantiate",
"resource",
"for",
"response",
"data",
"if",
"applicable"
] |
20759434a6dd7fcc38910eca5ad228287472751b
|
https://github.com/schemaio/schema-php-client/blob/20759434a6dd7fcc38910eca5ad228287472751b/lib/Client.php#L284-L293
|
231,491
|
schemaio/schema-php-client
|
lib/Client.php
|
Client.get
|
public function get($url, $data = null)
{
if ($this->cache) {
$result = $this->cache->get($url, array('$data' => $data));
if (array_key_exists('$data', (array)$result)) {
return $this->response_data($result, 'get', $url);
}
}
return $this->request('get', $url, $data);
}
|
php
|
public function get($url, $data = null)
{
if ($this->cache) {
$result = $this->cache->get($url, array('$data' => $data));
if (array_key_exists('$data', (array)$result)) {
return $this->response_data($result, 'get', $url);
}
}
return $this->request('get', $url, $data);
}
|
[
"public",
"function",
"get",
"(",
"$",
"url",
",",
"$",
"data",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"cache",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"cache",
"->",
"get",
"(",
"$",
"url",
",",
"array",
"(",
"'$data'",
"=>",
"$",
"data",
")",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'$data'",
",",
"(",
"array",
")",
"$",
"result",
")",
")",
"{",
"return",
"$",
"this",
"->",
"response_data",
"(",
"$",
"result",
",",
"'get'",
",",
"$",
"url",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"request",
"(",
"'get'",
",",
"$",
"url",
",",
"$",
"data",
")",
";",
"}"
] |
Call GET method
@param string $url
@param mixed $data
@return mixed
|
[
"Call",
"GET",
"method"
] |
20759434a6dd7fcc38910eca5ad228287472751b
|
https://github.com/schemaio/schema-php-client/blob/20759434a6dd7fcc38910eca5ad228287472751b/lib/Client.php#L302-L312
|
231,492
|
schemaio/schema-php-client
|
lib/Client.php
|
Client.put
|
public function put($url, $data = '$undefined')
{
if ($data === '$undefined') {
$data = ($url instanceof Resource)
? $url->data()
: null;
}
return $this->request('put', $url, $data);
}
|
php
|
public function put($url, $data = '$undefined')
{
if ($data === '$undefined') {
$data = ($url instanceof Resource)
? $url->data()
: null;
}
return $this->request('put', $url, $data);
}
|
[
"public",
"function",
"put",
"(",
"$",
"url",
",",
"$",
"data",
"=",
"'$undefined'",
")",
"{",
"if",
"(",
"$",
"data",
"===",
"'$undefined'",
")",
"{",
"$",
"data",
"=",
"(",
"$",
"url",
"instanceof",
"Resource",
")",
"?",
"$",
"url",
"->",
"data",
"(",
")",
":",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"request",
"(",
"'put'",
",",
"$",
"url",
",",
"$",
"data",
")",
";",
"}"
] |
Call PUT method
@param string $url
@param mixed $data
@return mixed
|
[
"Call",
"PUT",
"method"
] |
20759434a6dd7fcc38910eca5ad228287472751b
|
https://github.com/schemaio/schema-php-client/blob/20759434a6dd7fcc38910eca5ad228287472751b/lib/Client.php#L321-L329
|
231,493
|
schemaio/schema-php-client
|
lib/Client.php
|
Client.auth
|
public function auth($nonce = null, $params = null)
{
$params = $params ?: array();
$client_id = $this->params['client_id'];
$client_key = $this->params['client_key'];
// 1) Get nonce
$nonce = $nonce ?: $this->server->request('auth');
// 2) Create key hash
$key_hash = md5("{$client_id}::{$client_key}");
// 3) Create auth key
$auth_key = md5("{$nonce}{$client_id}{$key_hash}");
// 4) Authenticate with client params
$params['client'] = $client_id;
$params['key'] = $auth_key;
if ($this->params['version']) {
$params['$v'] = $this->params['version'];
}
if ($this->params['api']) {
$params['$api'] = $this->params['api'];
}
if ($this->params['session']) {
$params['$session'] = $this->params['session'];
}
if (isset($this->params['route']['client'])) {
$params['$route'] = $this->params['route'];
}
if (isset($_SERVER['REMOTE_ADDR']) && $ip_address = $_SERVER['REMOTE_ADDR']) {
$params['$ip'] = $ip_address;
}
if ($this->cache) {
$params['$cached'] = $this->cache->get_versions();
}
$this->authed = true;
try {
return $this->server->request('auth', $params);
} catch (NetworkException $e) {
$this->request_rescue($e);
return $this->auth();
}
}
|
php
|
public function auth($nonce = null, $params = null)
{
$params = $params ?: array();
$client_id = $this->params['client_id'];
$client_key = $this->params['client_key'];
// 1) Get nonce
$nonce = $nonce ?: $this->server->request('auth');
// 2) Create key hash
$key_hash = md5("{$client_id}::{$client_key}");
// 3) Create auth key
$auth_key = md5("{$nonce}{$client_id}{$key_hash}");
// 4) Authenticate with client params
$params['client'] = $client_id;
$params['key'] = $auth_key;
if ($this->params['version']) {
$params['$v'] = $this->params['version'];
}
if ($this->params['api']) {
$params['$api'] = $this->params['api'];
}
if ($this->params['session']) {
$params['$session'] = $this->params['session'];
}
if (isset($this->params['route']['client'])) {
$params['$route'] = $this->params['route'];
}
if (isset($_SERVER['REMOTE_ADDR']) && $ip_address = $_SERVER['REMOTE_ADDR']) {
$params['$ip'] = $ip_address;
}
if ($this->cache) {
$params['$cached'] = $this->cache->get_versions();
}
$this->authed = true;
try {
return $this->server->request('auth', $params);
} catch (NetworkException $e) {
$this->request_rescue($e);
return $this->auth();
}
}
|
[
"public",
"function",
"auth",
"(",
"$",
"nonce",
"=",
"null",
",",
"$",
"params",
"=",
"null",
")",
"{",
"$",
"params",
"=",
"$",
"params",
"?",
":",
"array",
"(",
")",
";",
"$",
"client_id",
"=",
"$",
"this",
"->",
"params",
"[",
"'client_id'",
"]",
";",
"$",
"client_key",
"=",
"$",
"this",
"->",
"params",
"[",
"'client_key'",
"]",
";",
"// 1) Get nonce",
"$",
"nonce",
"=",
"$",
"nonce",
"?",
":",
"$",
"this",
"->",
"server",
"->",
"request",
"(",
"'auth'",
")",
";",
"// 2) Create key hash",
"$",
"key_hash",
"=",
"md5",
"(",
"\"{$client_id}::{$client_key}\"",
")",
";",
"// 3) Create auth key",
"$",
"auth_key",
"=",
"md5",
"(",
"\"{$nonce}{$client_id}{$key_hash}\"",
")",
";",
"// 4) Authenticate with client params",
"$",
"params",
"[",
"'client'",
"]",
"=",
"$",
"client_id",
";",
"$",
"params",
"[",
"'key'",
"]",
"=",
"$",
"auth_key",
";",
"if",
"(",
"$",
"this",
"->",
"params",
"[",
"'version'",
"]",
")",
"{",
"$",
"params",
"[",
"'$v'",
"]",
"=",
"$",
"this",
"->",
"params",
"[",
"'version'",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"params",
"[",
"'api'",
"]",
")",
"{",
"$",
"params",
"[",
"'$api'",
"]",
"=",
"$",
"this",
"->",
"params",
"[",
"'api'",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"params",
"[",
"'session'",
"]",
")",
"{",
"$",
"params",
"[",
"'$session'",
"]",
"=",
"$",
"this",
"->",
"params",
"[",
"'session'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"params",
"[",
"'route'",
"]",
"[",
"'client'",
"]",
")",
")",
"{",
"$",
"params",
"[",
"'$route'",
"]",
"=",
"$",
"this",
"->",
"params",
"[",
"'route'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'REMOTE_ADDR'",
"]",
")",
"&&",
"$",
"ip_address",
"=",
"$",
"_SERVER",
"[",
"'REMOTE_ADDR'",
"]",
")",
"{",
"$",
"params",
"[",
"'$ip'",
"]",
"=",
"$",
"ip_address",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"cache",
")",
"{",
"$",
"params",
"[",
"'$cached'",
"]",
"=",
"$",
"this",
"->",
"cache",
"->",
"get_versions",
"(",
")",
";",
"}",
"$",
"this",
"->",
"authed",
"=",
"true",
";",
"try",
"{",
"return",
"$",
"this",
"->",
"server",
"->",
"request",
"(",
"'auth'",
",",
"$",
"params",
")",
";",
"}",
"catch",
"(",
"NetworkException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"request_rescue",
"(",
"$",
"e",
")",
";",
"return",
"$",
"this",
"->",
"auth",
"(",
")",
";",
"}",
"}"
] |
Call AUTH method
@param string $nonce
@param array $params
@return mixed
|
[
"Call",
"AUTH",
"method"
] |
20759434a6dd7fcc38910eca5ad228287472751b
|
https://github.com/schemaio/schema-php-client/blob/20759434a6dd7fcc38910eca5ad228287472751b/lib/Client.php#L362-L409
|
231,494
|
colorfield/mastodon-api-php
|
src/MastodonOAuth.php
|
MastodonOAuth.getResponse
|
private function getResponse($endpoint, array $json)
{
$result = null;
// endpoint
$uri = $this->config->getBaseUrl() . $endpoint;
try {
$response = $this->client->post(
$uri, [
'json' => $json,
]
);
// @todo $request->getHeader('content-type')
if($response->getStatusCode() == '200') {
$result = json_decode($response->getBody(), true);
}else{
echo 'ERROR: Status code ' . $response->getStatusCode();
}
// @todo check thrown exception
} catch (\Exception $exception) {
echo 'ERROR: ' . $exception->getMessage();
}
return $result;
}
|
php
|
private function getResponse($endpoint, array $json)
{
$result = null;
// endpoint
$uri = $this->config->getBaseUrl() . $endpoint;
try {
$response = $this->client->post(
$uri, [
'json' => $json,
]
);
// @todo $request->getHeader('content-type')
if($response->getStatusCode() == '200') {
$result = json_decode($response->getBody(), true);
}else{
echo 'ERROR: Status code ' . $response->getStatusCode();
}
// @todo check thrown exception
} catch (\Exception $exception) {
echo 'ERROR: ' . $exception->getMessage();
}
return $result;
}
|
[
"private",
"function",
"getResponse",
"(",
"$",
"endpoint",
",",
"array",
"$",
"json",
")",
"{",
"$",
"result",
"=",
"null",
";",
"// endpoint",
"$",
"uri",
"=",
"$",
"this",
"->",
"config",
"->",
"getBaseUrl",
"(",
")",
".",
"$",
"endpoint",
";",
"try",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"post",
"(",
"$",
"uri",
",",
"[",
"'json'",
"=>",
"$",
"json",
",",
"]",
")",
";",
"// @todo $request->getHeader('content-type')",
"if",
"(",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
"==",
"'200'",
")",
"{",
"$",
"result",
"=",
"json_decode",
"(",
"$",
"response",
"->",
"getBody",
"(",
")",
",",
"true",
")",
";",
"}",
"else",
"{",
"echo",
"'ERROR: Status code '",
".",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
";",
"}",
"// @todo check thrown exception",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"echo",
"'ERROR: '",
".",
"$",
"exception",
"->",
"getMessage",
"(",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Get response from the endpoint.
@param $endpoint
@param array $json
@return mixed|null
|
[
"Get",
"response",
"from",
"the",
"endpoint",
"."
] |
cd9cb946032508e48630fffd5a661f3347d0b84f
|
https://github.com/colorfield/mastodon-api-php/blob/cd9cb946032508e48630fffd5a661f3347d0b84f/src/MastodonOAuth.php#L47-L69
|
231,495
|
colorfield/mastodon-api-php
|
src/MastodonOAuth.php
|
MastodonOAuth.registerApplication
|
public function registerApplication()
{
$options = $this->config->getAppConfiguration();
$credentials = $this->getResponse(
'/api/'.ConfigurationVO::API_VERSION.'/apps',
$options
);
if (isset($credentials["client_id"])
&& isset($credentials["client_secret"])
) {
$this->config->setClientId($credentials['client_id']);
$this->config->setClientSecret($credentials['client_secret']);
}else {
echo 'ERROR: no credentials in API response';
}
}
|
php
|
public function registerApplication()
{
$options = $this->config->getAppConfiguration();
$credentials = $this->getResponse(
'/api/'.ConfigurationVO::API_VERSION.'/apps',
$options
);
if (isset($credentials["client_id"])
&& isset($credentials["client_secret"])
) {
$this->config->setClientId($credentials['client_id']);
$this->config->setClientSecret($credentials['client_secret']);
}else {
echo 'ERROR: no credentials in API response';
}
}
|
[
"public",
"function",
"registerApplication",
"(",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"config",
"->",
"getAppConfiguration",
"(",
")",
";",
"$",
"credentials",
"=",
"$",
"this",
"->",
"getResponse",
"(",
"'/api/'",
".",
"ConfigurationVO",
"::",
"API_VERSION",
".",
"'/apps'",
",",
"$",
"options",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"credentials",
"[",
"\"client_id\"",
"]",
")",
"&&",
"isset",
"(",
"$",
"credentials",
"[",
"\"client_secret\"",
"]",
")",
")",
"{",
"$",
"this",
"->",
"config",
"->",
"setClientId",
"(",
"$",
"credentials",
"[",
"'client_id'",
"]",
")",
";",
"$",
"this",
"->",
"config",
"->",
"setClientSecret",
"(",
"$",
"credentials",
"[",
"'client_secret'",
"]",
")",
";",
"}",
"else",
"{",
"echo",
"'ERROR: no credentials in API response'",
";",
"}",
"}"
] |
Register the Mastodon application.
Appends client_id and client_secret tp the configuration value object.
|
[
"Register",
"the",
"Mastodon",
"application",
"."
] |
cd9cb946032508e48630fffd5a661f3347d0b84f
|
https://github.com/colorfield/mastodon-api-php/blob/cd9cb946032508e48630fffd5a661f3347d0b84f/src/MastodonOAuth.php#L76-L91
|
231,496
|
colorfield/mastodon-api-php
|
src/MastodonOAuth.php
|
MastodonOAuth.getAuthorizationUrl
|
public function getAuthorizationUrl()
{
$result = null;
if (!$this->config->hasCredentials()) {
$this->registerApplication();
}
//Return the Authorization URL
return "https://{$this->config->getMastodonInstance()}/oauth/authorize/?".http_build_query(
[
"response_type" => "code",
// @todo review usage of singular / plural in redirect_uri
"redirect_uri" => $this->config->getRedirectUris(),
"scope" => $this->config->getScopes(),
"client_id" => $this->config->getClientId(),
]
);
}
|
php
|
public function getAuthorizationUrl()
{
$result = null;
if (!$this->config->hasCredentials()) {
$this->registerApplication();
}
//Return the Authorization URL
return "https://{$this->config->getMastodonInstance()}/oauth/authorize/?".http_build_query(
[
"response_type" => "code",
// @todo review usage of singular / plural in redirect_uri
"redirect_uri" => $this->config->getRedirectUris(),
"scope" => $this->config->getScopes(),
"client_id" => $this->config->getClientId(),
]
);
}
|
[
"public",
"function",
"getAuthorizationUrl",
"(",
")",
"{",
"$",
"result",
"=",
"null",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"config",
"->",
"hasCredentials",
"(",
")",
")",
"{",
"$",
"this",
"->",
"registerApplication",
"(",
")",
";",
"}",
"//Return the Authorization URL",
"return",
"\"https://{$this->config->getMastodonInstance()}/oauth/authorize/?\"",
".",
"http_build_query",
"(",
"[",
"\"response_type\"",
"=>",
"\"code\"",
",",
"// @todo review usage of singular / plural in redirect_uri",
"\"redirect_uri\"",
"=>",
"$",
"this",
"->",
"config",
"->",
"getRedirectUris",
"(",
")",
",",
"\"scope\"",
"=>",
"$",
"this",
"->",
"config",
"->",
"getScopes",
"(",
")",
",",
"\"client_id\"",
"=>",
"$",
"this",
"->",
"config",
"->",
"getClientId",
"(",
")",
",",
"]",
")",
";",
"}"
] |
Returns the authorization URL that will provide the authorization code"
after manual approval.
@return string
|
[
"Returns",
"the",
"authorization",
"URL",
"that",
"will",
"provide",
"the",
"authorization",
"code",
"after",
"manual",
"approval",
"."
] |
cd9cb946032508e48630fffd5a661f3347d0b84f
|
https://github.com/colorfield/mastodon-api-php/blob/cd9cb946032508e48630fffd5a661f3347d0b84f/src/MastodonOAuth.php#L99-L115
|
231,497
|
colorfield/mastodon-api-php
|
src/MastodonOAuth.php
|
MastodonOAuth.getAccessToken
|
public function getAccessToken()
{
$result = null;
$options = $this->config->getAccessTokenConfiguration();
$token = $this->getResponse('/oauth/token', $options);
if (isset($token['access_token'])) {
$this->config->setBearer($token['access_token']);
}else {
echo 'ERROR: no access token in API response';
}
}
|
php
|
public function getAccessToken()
{
$result = null;
$options = $this->config->getAccessTokenConfiguration();
$token = $this->getResponse('/oauth/token', $options);
if (isset($token['access_token'])) {
$this->config->setBearer($token['access_token']);
}else {
echo 'ERROR: no access token in API response';
}
}
|
[
"public",
"function",
"getAccessToken",
"(",
")",
"{",
"$",
"result",
"=",
"null",
";",
"$",
"options",
"=",
"$",
"this",
"->",
"config",
"->",
"getAccessTokenConfiguration",
"(",
")",
";",
"$",
"token",
"=",
"$",
"this",
"->",
"getResponse",
"(",
"'/oauth/token'",
",",
"$",
"options",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"token",
"[",
"'access_token'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"config",
"->",
"setBearer",
"(",
"$",
"token",
"[",
"'access_token'",
"]",
")",
";",
"}",
"else",
"{",
"echo",
"'ERROR: no access token in API response'",
";",
"}",
"}"
] |
Gets the access token.
As a side effect, stores it into the Configuration as bearer.
|
[
"Gets",
"the",
"access",
"token",
".",
"As",
"a",
"side",
"effect",
"stores",
"it",
"into",
"the",
"Configuration",
"as",
"bearer",
"."
] |
cd9cb946032508e48630fffd5a661f3347d0b84f
|
https://github.com/colorfield/mastodon-api-php/blob/cd9cb946032508e48630fffd5a661f3347d0b84f/src/MastodonOAuth.php#L121-L131
|
231,498
|
opensoft/epl
|
src/Epl/CommandHelper.php
|
CommandHelper.asciiText
|
public function asciiText($horizontalStartPosition, $verticalStartPosition, $rotation, $fontSelection,
$horizontalMultiplier, $verticalMultiplier, $reverseImage, $data, $convertRotation = true,
$asianFont = false)
{
$command = new Command\Image\AsciiTextCommand($horizontalStartPosition, $verticalStartPosition, $rotation, $fontSelection,
$horizontalMultiplier, $verticalMultiplier, $reverseImage, $data,
$convertRotation, $asianFont);
$this->getComposite()->addCommand($command);
return $this;
}
|
php
|
public function asciiText($horizontalStartPosition, $verticalStartPosition, $rotation, $fontSelection,
$horizontalMultiplier, $verticalMultiplier, $reverseImage, $data, $convertRotation = true,
$asianFont = false)
{
$command = new Command\Image\AsciiTextCommand($horizontalStartPosition, $verticalStartPosition, $rotation, $fontSelection,
$horizontalMultiplier, $verticalMultiplier, $reverseImage, $data,
$convertRotation, $asianFont);
$this->getComposite()->addCommand($command);
return $this;
}
|
[
"public",
"function",
"asciiText",
"(",
"$",
"horizontalStartPosition",
",",
"$",
"verticalStartPosition",
",",
"$",
"rotation",
",",
"$",
"fontSelection",
",",
"$",
"horizontalMultiplier",
",",
"$",
"verticalMultiplier",
",",
"$",
"reverseImage",
",",
"$",
"data",
",",
"$",
"convertRotation",
"=",
"true",
",",
"$",
"asianFont",
"=",
"false",
")",
"{",
"$",
"command",
"=",
"new",
"Command",
"\\",
"Image",
"\\",
"AsciiTextCommand",
"(",
"$",
"horizontalStartPosition",
",",
"$",
"verticalStartPosition",
",",
"$",
"rotation",
",",
"$",
"fontSelection",
",",
"$",
"horizontalMultiplier",
",",
"$",
"verticalMultiplier",
",",
"$",
"reverseImage",
",",
"$",
"data",
",",
"$",
"convertRotation",
",",
"$",
"asianFont",
")",
";",
"$",
"this",
"->",
"getComposite",
"(",
")",
"->",
"addCommand",
"(",
"$",
"command",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Renders an ASCII text string to the image print buffer.
@param int $horizontalStartPosition
@param int $verticalStartPosition
@param int $rotation
@param int $fontSelection
@param int $horizontalMultiplier
@param int $verticalMultiplier
@param bool $reverseImage
@param string $data
@param bool $convertRotation
@param bool $asianFont
@return \Epl\CommandHelper
@throw ExceptionCommand
|
[
"Renders",
"an",
"ASCII",
"text",
"string",
"to",
"the",
"image",
"print",
"buffer",
"."
] |
61a1152ed3e292d5bd3ec2758076d605bada0623
|
https://github.com/opensoft/epl/blob/61a1152ed3e292d5bd3ec2758076d605bada0623/src/Epl/CommandHelper.php#L51-L60
|
231,499
|
opensoft/epl
|
src/Epl/CommandHelper.php
|
CommandHelper.barCode
|
public function barCode($horizontalStartPosition, $verticalStartPosition, $rotation, $barCodeSelection,
$narrowBarWidth, $wideBarWidth, $barCodeHeight, $printHumanReadable, $data, $convertRotation = true)
{
$command = new Command\Image\BarCodeCommand($horizontalStartPosition, $verticalStartPosition, $rotation, $barCodeSelection,
$narrowBarWidth, $wideBarWidth, $barCodeHeight, $printHumanReadable,
$data, $convertRotation);
$this->getComposite()->addCommand($command);
return $this;
}
|
php
|
public function barCode($horizontalStartPosition, $verticalStartPosition, $rotation, $barCodeSelection,
$narrowBarWidth, $wideBarWidth, $barCodeHeight, $printHumanReadable, $data, $convertRotation = true)
{
$command = new Command\Image\BarCodeCommand($horizontalStartPosition, $verticalStartPosition, $rotation, $barCodeSelection,
$narrowBarWidth, $wideBarWidth, $barCodeHeight, $printHumanReadable,
$data, $convertRotation);
$this->getComposite()->addCommand($command);
return $this;
}
|
[
"public",
"function",
"barCode",
"(",
"$",
"horizontalStartPosition",
",",
"$",
"verticalStartPosition",
",",
"$",
"rotation",
",",
"$",
"barCodeSelection",
",",
"$",
"narrowBarWidth",
",",
"$",
"wideBarWidth",
",",
"$",
"barCodeHeight",
",",
"$",
"printHumanReadable",
",",
"$",
"data",
",",
"$",
"convertRotation",
"=",
"true",
")",
"{",
"$",
"command",
"=",
"new",
"Command",
"\\",
"Image",
"\\",
"BarCodeCommand",
"(",
"$",
"horizontalStartPosition",
",",
"$",
"verticalStartPosition",
",",
"$",
"rotation",
",",
"$",
"barCodeSelection",
",",
"$",
"narrowBarWidth",
",",
"$",
"wideBarWidth",
",",
"$",
"barCodeHeight",
",",
"$",
"printHumanReadable",
",",
"$",
"data",
",",
"$",
"convertRotation",
")",
";",
"$",
"this",
"->",
"getComposite",
"(",
")",
"->",
"addCommand",
"(",
"$",
"command",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Use this command to print standard bar codes
@param int $horizontalStartPosition
@param int $verticalStartPosition
@param int $rotation
@param string $barCodeSelection
@param int $narrowBarWidth
@param int $wideBarWidth
@param int $barCodeHeight
@param bool $printHumanReadable
@param string $data
@param bool $convertRotation
@return \Epl\CommandHelper
@throws \Epl\ExceptionCommand
|
[
"Use",
"this",
"command",
"to",
"print",
"standard",
"bar",
"codes"
] |
61a1152ed3e292d5bd3ec2758076d605bada0623
|
https://github.com/opensoft/epl/blob/61a1152ed3e292d5bd3ec2758076d605bada0623/src/Epl/CommandHelper.php#L79-L87
|
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.