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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
224,200
|
unreal4u/mqtt
|
src/Client.php
|
Client.postSocketCommunication
|
private function postSocketCommunication(ReadableContentInterface $readableContent): WritableContentInterface
{
$originPacket = null;
$originPacketIdentifier = $readableContent->getOriginControlPacket();
if (array_key_exists($originPacketIdentifier, $this->objectStack)) {
$this->logger->debug('Origin packet found, returning it', ['originKey' => $originPacketIdentifier]);
$originPacket = $this->objectStack[$originPacketIdentifier];
unset($this->objectStack[$originPacketIdentifier]);
} elseif ($originPacketIdentifier === 0) {
$originPacket = new EmptyWritableResponse($this->logger);
} else {
$this->logger->warning('No origin packet found!', [
'originKey' => $originPacketIdentifier,
'stack' => array_keys($this->objectStack),
]);
#throw new \LogicException('No origin instance could be found in the stack, please check');
$originPacket = new EmptyWritableResponse($this->logger);
}
return $originPacket;
}
|
php
|
private function postSocketCommunication(ReadableContentInterface $readableContent): WritableContentInterface
{
$originPacket = null;
$originPacketIdentifier = $readableContent->getOriginControlPacket();
if (array_key_exists($originPacketIdentifier, $this->objectStack)) {
$this->logger->debug('Origin packet found, returning it', ['originKey' => $originPacketIdentifier]);
$originPacket = $this->objectStack[$originPacketIdentifier];
unset($this->objectStack[$originPacketIdentifier]);
} elseif ($originPacketIdentifier === 0) {
$originPacket = new EmptyWritableResponse($this->logger);
} else {
$this->logger->warning('No origin packet found!', [
'originKey' => $originPacketIdentifier,
'stack' => array_keys($this->objectStack),
]);
#throw new \LogicException('No origin instance could be found in the stack, please check');
$originPacket = new EmptyWritableResponse($this->logger);
}
return $originPacket;
}
|
[
"private",
"function",
"postSocketCommunication",
"(",
"ReadableContentInterface",
"$",
"readableContent",
")",
":",
"WritableContentInterface",
"{",
"$",
"originPacket",
"=",
"null",
";",
"$",
"originPacketIdentifier",
"=",
"$",
"readableContent",
"->",
"getOriginControlPacket",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"originPacketIdentifier",
",",
"$",
"this",
"->",
"objectStack",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'Origin packet found, returning it'",
",",
"[",
"'originKey'",
"=>",
"$",
"originPacketIdentifier",
"]",
")",
";",
"$",
"originPacket",
"=",
"$",
"this",
"->",
"objectStack",
"[",
"$",
"originPacketIdentifier",
"]",
";",
"unset",
"(",
"$",
"this",
"->",
"objectStack",
"[",
"$",
"originPacketIdentifier",
"]",
")",
";",
"}",
"elseif",
"(",
"$",
"originPacketIdentifier",
"===",
"0",
")",
"{",
"$",
"originPacket",
"=",
"new",
"EmptyWritableResponse",
"(",
"$",
"this",
"->",
"logger",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"logger",
"->",
"warning",
"(",
"'No origin packet found!'",
",",
"[",
"'originKey'",
"=>",
"$",
"originPacketIdentifier",
",",
"'stack'",
"=>",
"array_keys",
"(",
"$",
"this",
"->",
"objectStack",
")",
",",
"]",
")",
";",
"#throw new \\LogicException('No origin instance could be found in the stack, please check');",
"$",
"originPacket",
"=",
"new",
"EmptyWritableResponse",
"(",
"$",
"this",
"->",
"logger",
")",
";",
"}",
"return",
"$",
"originPacket",
";",
"}"
] |
Checks in the object stack whether there is some method that might issue the current ReadableContent
@param ReadableContentInterface $readableContent
@return WritableContentInterface
@throws \LogicException
|
[
"Checks",
"in",
"the",
"object",
"stack",
"whether",
"there",
"is",
"some",
"method",
"that",
"might",
"issue",
"the",
"current",
"ReadableContent"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Client.php#L257-L278
|
224,201
|
sulu/SuluProductBundle
|
Controller/ValueController.php
|
ValueController.cgetAction
|
public function cgetAction(Request $request, $id)
{
try {
if ($request->get('flat') == 'true') {
$list = $this->getListRepresentation($request, $id);
} else {
$list = new CollectionRepresentation(
$this->getManager()->findAllByAttributeIdAndLocale($this->getLocale($request), $id),
self::$entityKey
);
}
$view = $this->view($list, 200);
} catch (AttributeNotFoundException $exc) {
$exception = new EntityNotFoundException($exc->getEntityName(), $exc->getId());
$view = $this->view($exception->toArray(), 404);
}
return $this->handleView($view);
}
|
php
|
public function cgetAction(Request $request, $id)
{
try {
if ($request->get('flat') == 'true') {
$list = $this->getListRepresentation($request, $id);
} else {
$list = new CollectionRepresentation(
$this->getManager()->findAllByAttributeIdAndLocale($this->getLocale($request), $id),
self::$entityKey
);
}
$view = $this->view($list, 200);
} catch (AttributeNotFoundException $exc) {
$exception = new EntityNotFoundException($exc->getEntityName(), $exc->getId());
$view = $this->view($exception->toArray(), 404);
}
return $this->handleView($view);
}
|
[
"public",
"function",
"cgetAction",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
")",
"{",
"try",
"{",
"if",
"(",
"$",
"request",
"->",
"get",
"(",
"'flat'",
")",
"==",
"'true'",
")",
"{",
"$",
"list",
"=",
"$",
"this",
"->",
"getListRepresentation",
"(",
"$",
"request",
",",
"$",
"id",
")",
";",
"}",
"else",
"{",
"$",
"list",
"=",
"new",
"CollectionRepresentation",
"(",
"$",
"this",
"->",
"getManager",
"(",
")",
"->",
"findAllByAttributeIdAndLocale",
"(",
"$",
"this",
"->",
"getLocale",
"(",
"$",
"request",
")",
",",
"$",
"id",
")",
",",
"self",
"::",
"$",
"entityKey",
")",
";",
"}",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"list",
",",
"200",
")",
";",
"}",
"catch",
"(",
"AttributeNotFoundException",
"$",
"exc",
")",
"{",
"$",
"exception",
"=",
"new",
"EntityNotFoundException",
"(",
"$",
"exc",
"->",
"getEntityName",
"(",
")",
",",
"$",
"exc",
"->",
"getId",
"(",
")",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"exception",
"->",
"toArray",
"(",
")",
",",
"404",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] |
Retrieves and shows a attributeValue with the given ID.
@param \Symfony\Component\HttpFoundation\Request $request
@param int $id attribute ID
@return \Symfony\Component\HttpFoundation\Response
|
[
"Retrieves",
"and",
"shows",
"a",
"attributeValue",
"with",
"the",
"given",
"ID",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Controller/ValueController.php#L111-L129
|
224,202
|
sulu/SuluProductBundle
|
Controller/ValueController.php
|
ValueController.postAction
|
public function postAction(Request $request, $attributeId)
{
try {
$attributeValue = $this->getManager()->save(
$request->request->all(),
$this->getLocale($request),
$attributeId
);
$view = $this->view($attributeValue, 200);
} catch (AttributeDependencyNotFoundException $exc) {
$exception = new EntityNotFoundException($exc->getEntityName(), $exc->getId());
$view = $this->view($exception->toArray(), 400);
} catch (MissingAttributeValueException $exc) {
$exception = new MissingArgumentException(self::$entityName, $exc->getAttribute());
$view = $this->view($exception->toArray(), 400);
}
return $this->handleView($view);
}
|
php
|
public function postAction(Request $request, $attributeId)
{
try {
$attributeValue = $this->getManager()->save(
$request->request->all(),
$this->getLocale($request),
$attributeId
);
$view = $this->view($attributeValue, 200);
} catch (AttributeDependencyNotFoundException $exc) {
$exception = new EntityNotFoundException($exc->getEntityName(), $exc->getId());
$view = $this->view($exception->toArray(), 400);
} catch (MissingAttributeValueException $exc) {
$exception = new MissingArgumentException(self::$entityName, $exc->getAttribute());
$view = $this->view($exception->toArray(), 400);
}
return $this->handleView($view);
}
|
[
"public",
"function",
"postAction",
"(",
"Request",
"$",
"request",
",",
"$",
"attributeId",
")",
"{",
"try",
"{",
"$",
"attributeValue",
"=",
"$",
"this",
"->",
"getManager",
"(",
")",
"->",
"save",
"(",
"$",
"request",
"->",
"request",
"->",
"all",
"(",
")",
",",
"$",
"this",
"->",
"getLocale",
"(",
"$",
"request",
")",
",",
"$",
"attributeId",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"attributeValue",
",",
"200",
")",
";",
"}",
"catch",
"(",
"AttributeDependencyNotFoundException",
"$",
"exc",
")",
"{",
"$",
"exception",
"=",
"new",
"EntityNotFoundException",
"(",
"$",
"exc",
"->",
"getEntityName",
"(",
")",
",",
"$",
"exc",
"->",
"getId",
"(",
")",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"exception",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"catch",
"(",
"MissingAttributeValueException",
"$",
"exc",
")",
"{",
"$",
"exception",
"=",
"new",
"MissingArgumentException",
"(",
"self",
"::",
"$",
"entityName",
",",
"$",
"exc",
"->",
"getAttribute",
"(",
")",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"exception",
"->",
"toArray",
"(",
")",
",",
"400",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] |
Creates and stores a new attribute value.
@param \Symfony\Component\HttpFoundation\Request $request
@return \Symfony\Component\HttpFoundation\Response
|
[
"Creates",
"and",
"stores",
"a",
"new",
"attribute",
"value",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Controller/ValueController.php#L207-L225
|
224,203
|
sulu/SuluProductBundle
|
Controller/ValueController.php
|
ValueController.deleteAction
|
public function deleteAction(Request $request, $attributeId, $attributeValueId)
{
try {
$this->getManager()->delete($attributeValueId, $this->getUser()->getId());
$view = $this->view($attributeValueId, 204);
} catch (AttributeValueNotFoundException $exc) {
$exception = new EntityNotFoundException($exc->getEntityName(), $exc->getId());
$view = $this->view($exception->toArray(), 404);
}
return $this->handleView($view);
}
|
php
|
public function deleteAction(Request $request, $attributeId, $attributeValueId)
{
try {
$this->getManager()->delete($attributeValueId, $this->getUser()->getId());
$view = $this->view($attributeValueId, 204);
} catch (AttributeValueNotFoundException $exc) {
$exception = new EntityNotFoundException($exc->getEntityName(), $exc->getId());
$view = $this->view($exception->toArray(), 404);
}
return $this->handleView($view);
}
|
[
"public",
"function",
"deleteAction",
"(",
"Request",
"$",
"request",
",",
"$",
"attributeId",
",",
"$",
"attributeValueId",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"getManager",
"(",
")",
"->",
"delete",
"(",
"$",
"attributeValueId",
",",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"getId",
"(",
")",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"attributeValueId",
",",
"204",
")",
";",
"}",
"catch",
"(",
"AttributeValueNotFoundException",
"$",
"exc",
")",
"{",
"$",
"exception",
"=",
"new",
"EntityNotFoundException",
"(",
"$",
"exc",
"->",
"getEntityName",
"(",
")",
",",
"$",
"exc",
"->",
"getId",
"(",
")",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"exception",
"->",
"toArray",
"(",
")",
",",
"404",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] |
Delete an product attribute value for the given id.
@param \Symfony\Component\HttpFoundation\Request $request
@param int $id the attribute id
@return \Symfony\Component\HttpFoundation\Response
|
[
"Delete",
"an",
"product",
"attribute",
"value",
"for",
"the",
"given",
"id",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Controller/ValueController.php#L235-L246
|
224,204
|
sulu/SuluProductBundle
|
Entity/ProductRepository.php
|
ProductRepository.getProductQuery
|
private function getProductQuery($locale)
{
$qb = $this->createQueryBuilder('product')
->addSelect('prices')
->addSelect('parent')
->addSelect('translations')
->addSelect('status')
->addSelect('type')
->addSelect('currency')
->addSelect('media')
->leftJoin('product.parent', 'parent')
->leftJoin('product.translations', 'translations', 'WITH', 'translations.locale = :locale')
->leftJoin('product.status', 'status')
->leftJoin('status.translations', 'statusTranslations', 'WITH', 'statusTranslations.locale = :locale')
->leftJoin('product.type', 'type')
->leftJoin('product.prices', 'prices')
->leftJoin('prices.currency', 'currency')
->leftJoin('product.media', 'media')
->setParameter('locale', $locale);
return $qb;
}
|
php
|
private function getProductQuery($locale)
{
$qb = $this->createQueryBuilder('product')
->addSelect('prices')
->addSelect('parent')
->addSelect('translations')
->addSelect('status')
->addSelect('type')
->addSelect('currency')
->addSelect('media')
->leftJoin('product.parent', 'parent')
->leftJoin('product.translations', 'translations', 'WITH', 'translations.locale = :locale')
->leftJoin('product.status', 'status')
->leftJoin('status.translations', 'statusTranslations', 'WITH', 'statusTranslations.locale = :locale')
->leftJoin('product.type', 'type')
->leftJoin('product.prices', 'prices')
->leftJoin('prices.currency', 'currency')
->leftJoin('product.media', 'media')
->setParameter('locale', $locale);
return $qb;
}
|
[
"private",
"function",
"getProductQuery",
"(",
"$",
"locale",
")",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"createQueryBuilder",
"(",
"'product'",
")",
"->",
"addSelect",
"(",
"'prices'",
")",
"->",
"addSelect",
"(",
"'parent'",
")",
"->",
"addSelect",
"(",
"'translations'",
")",
"->",
"addSelect",
"(",
"'status'",
")",
"->",
"addSelect",
"(",
"'type'",
")",
"->",
"addSelect",
"(",
"'currency'",
")",
"->",
"addSelect",
"(",
"'media'",
")",
"->",
"leftJoin",
"(",
"'product.parent'",
",",
"'parent'",
")",
"->",
"leftJoin",
"(",
"'product.translations'",
",",
"'translations'",
",",
"'WITH'",
",",
"'translations.locale = :locale'",
")",
"->",
"leftJoin",
"(",
"'product.status'",
",",
"'status'",
")",
"->",
"leftJoin",
"(",
"'status.translations'",
",",
"'statusTranslations'",
",",
"'WITH'",
",",
"'statusTranslations.locale = :locale'",
")",
"->",
"leftJoin",
"(",
"'product.type'",
",",
"'type'",
")",
"->",
"leftJoin",
"(",
"'product.prices'",
",",
"'prices'",
")",
"->",
"leftJoin",
"(",
"'prices.currency'",
",",
"'currency'",
")",
"->",
"leftJoin",
"(",
"'product.media'",
",",
"'media'",
")",
"->",
"setParameter",
"(",
"'locale'",
",",
"$",
"locale",
")",
";",
"return",
"$",
"qb",
";",
"}"
] |
Returns the query for products.
@param string $locale The locale to load
@return \Doctrine\ORM\QueryBuilder
|
[
"Returns",
"the",
"query",
"for",
"products",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Entity/ProductRepository.php#L149-L170
|
224,205
|
sulu/SuluProductBundle
|
Entity/ProductRepository.php
|
ProductRepository.findByLocaleAndIds
|
public function findByLocaleAndIds($locale, array $ids = [])
{
try {
$qb = $this->getProductQuery($locale);
$qb->where('product.id IN (:ids)');
$qb->setParameter('ids', $ids);
$query = $qb->getQuery();
return $query->getResult();
} catch (NoResultException $ex) {
return null;
}
}
|
php
|
public function findByLocaleAndIds($locale, array $ids = [])
{
try {
$qb = $this->getProductQuery($locale);
$qb->where('product.id IN (:ids)');
$qb->setParameter('ids', $ids);
$query = $qb->getQuery();
return $query->getResult();
} catch (NoResultException $ex) {
return null;
}
}
|
[
"public",
"function",
"findByLocaleAndIds",
"(",
"$",
"locale",
",",
"array",
"$",
"ids",
"=",
"[",
"]",
")",
"{",
"try",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"getProductQuery",
"(",
"$",
"locale",
")",
";",
"$",
"qb",
"->",
"where",
"(",
"'product.id IN (:ids)'",
")",
";",
"$",
"qb",
"->",
"setParameter",
"(",
"'ids'",
",",
"$",
"ids",
")",
";",
"$",
"query",
"=",
"$",
"qb",
"->",
"getQuery",
"(",
")",
";",
"return",
"$",
"query",
"->",
"getResult",
"(",
")",
";",
"}",
"catch",
"(",
"NoResultException",
"$",
"ex",
")",
"{",
"return",
"null",
";",
"}",
"}"
] |
Returns all products with the given locale and ids.
@param string $locale The locale to load
@param array $ids
@return ProductInterface[]
|
[
"Returns",
"all",
"products",
"with",
"the",
"given",
"locale",
"and",
"ids",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Entity/ProductRepository.php#L180-L192
|
224,206
|
sulu/SuluProductBundle
|
Product/ProductVariantAttributeManager.php
|
ProductVariantAttributeManager.retrieveFieldDescriptors
|
public function retrieveFieldDescriptors($locale)
{
$fieldDescriptors = [];
$fieldDescriptors['id'] = new DoctrineFieldDescriptor(
'id',
'id',
static::$attributeEntityName,
null,
[
static::$attributeEntityName => new DoctrineJoinDescriptor(
static::$attributeEntityName,
static::$productEntityName . '.variantAttributes'
),
],
true,
false,
'integer'
);
$fieldDescriptors['name'] = new DoctrineFieldDescriptor(
'name',
'name',
static::$attributeTranslationEntityName,
null,
[
static::$attributeEntityName => new DoctrineJoinDescriptor(
static::$attributeEntityName,
static::$productEntityName . '.variantAttributes'
),
static::$attributeTranslationEntityName => new DoctrineJoinDescriptor(
static::$attributeTranslationEntityName,
static::$attributeEntityName . '.translations',
static::$attributeTranslationEntityName . '.locale = \'' . $locale . '\'',
DoctrineJoinDescriptor::JOIN_METHOD_INNER
),
],
false,
true,
'string'
);
return $fieldDescriptors;
}
|
php
|
public function retrieveFieldDescriptors($locale)
{
$fieldDescriptors = [];
$fieldDescriptors['id'] = new DoctrineFieldDescriptor(
'id',
'id',
static::$attributeEntityName,
null,
[
static::$attributeEntityName => new DoctrineJoinDescriptor(
static::$attributeEntityName,
static::$productEntityName . '.variantAttributes'
),
],
true,
false,
'integer'
);
$fieldDescriptors['name'] = new DoctrineFieldDescriptor(
'name',
'name',
static::$attributeTranslationEntityName,
null,
[
static::$attributeEntityName => new DoctrineJoinDescriptor(
static::$attributeEntityName,
static::$productEntityName . '.variantAttributes'
),
static::$attributeTranslationEntityName => new DoctrineJoinDescriptor(
static::$attributeTranslationEntityName,
static::$attributeEntityName . '.translations',
static::$attributeTranslationEntityName . '.locale = \'' . $locale . '\'',
DoctrineJoinDescriptor::JOIN_METHOD_INNER
),
],
false,
true,
'string'
);
return $fieldDescriptors;
}
|
[
"public",
"function",
"retrieveFieldDescriptors",
"(",
"$",
"locale",
")",
"{",
"$",
"fieldDescriptors",
"=",
"[",
"]",
";",
"$",
"fieldDescriptors",
"[",
"'id'",
"]",
"=",
"new",
"DoctrineFieldDescriptor",
"(",
"'id'",
",",
"'id'",
",",
"static",
"::",
"$",
"attributeEntityName",
",",
"null",
",",
"[",
"static",
"::",
"$",
"attributeEntityName",
"=>",
"new",
"DoctrineJoinDescriptor",
"(",
"static",
"::",
"$",
"attributeEntityName",
",",
"static",
"::",
"$",
"productEntityName",
".",
"'.variantAttributes'",
")",
",",
"]",
",",
"true",
",",
"false",
",",
"'integer'",
")",
";",
"$",
"fieldDescriptors",
"[",
"'name'",
"]",
"=",
"new",
"DoctrineFieldDescriptor",
"(",
"'name'",
",",
"'name'",
",",
"static",
"::",
"$",
"attributeTranslationEntityName",
",",
"null",
",",
"[",
"static",
"::",
"$",
"attributeEntityName",
"=>",
"new",
"DoctrineJoinDescriptor",
"(",
"static",
"::",
"$",
"attributeEntityName",
",",
"static",
"::",
"$",
"productEntityName",
".",
"'.variantAttributes'",
")",
",",
"static",
"::",
"$",
"attributeTranslationEntityName",
"=>",
"new",
"DoctrineJoinDescriptor",
"(",
"static",
"::",
"$",
"attributeTranslationEntityName",
",",
"static",
"::",
"$",
"attributeEntityName",
".",
"'.translations'",
",",
"static",
"::",
"$",
"attributeTranslationEntityName",
".",
"'.locale = \\''",
".",
"$",
"locale",
".",
"'\\''",
",",
"DoctrineJoinDescriptor",
"::",
"JOIN_METHOD_INNER",
")",
",",
"]",
",",
"false",
",",
"true",
",",
"'string'",
")",
";",
"return",
"$",
"fieldDescriptors",
";",
"}"
] |
Returns all field-descriptors for variant attributes.
@param string $locale
@return DoctrineFieldDescriptor[]
|
[
"Returns",
"all",
"field",
"-",
"descriptors",
"for",
"variant",
"attributes",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductVariantAttributeManager.php#L63-L106
|
224,207
|
sulu/SuluProductBundle
|
Product/ProductVariantAttributeManager.php
|
ProductVariantAttributeManager.createVariantAttributeRelation
|
public function createVariantAttributeRelation($productId, array $requestData)
{
$variant = $this->retrieveProductById($productId);
$attribute = $this->retrieveAttributeById($this->getProperty($requestData, 'attributeId'));
// Only add if relation does not already exists.
if (!$variant->getVariantAttributes()->contains($attribute)) {
$variant->addVariantAttribute($attribute);
}
return $variant;
}
|
php
|
public function createVariantAttributeRelation($productId, array $requestData)
{
$variant = $this->retrieveProductById($productId);
$attribute = $this->retrieveAttributeById($this->getProperty($requestData, 'attributeId'));
// Only add if relation does not already exists.
if (!$variant->getVariantAttributes()->contains($attribute)) {
$variant->addVariantAttribute($attribute);
}
return $variant;
}
|
[
"public",
"function",
"createVariantAttributeRelation",
"(",
"$",
"productId",
",",
"array",
"$",
"requestData",
")",
"{",
"$",
"variant",
"=",
"$",
"this",
"->",
"retrieveProductById",
"(",
"$",
"productId",
")",
";",
"$",
"attribute",
"=",
"$",
"this",
"->",
"retrieveAttributeById",
"(",
"$",
"this",
"->",
"getProperty",
"(",
"$",
"requestData",
",",
"'attributeId'",
")",
")",
";",
"// Only add if relation does not already exists.",
"if",
"(",
"!",
"$",
"variant",
"->",
"getVariantAttributes",
"(",
")",
"->",
"contains",
"(",
"$",
"attribute",
")",
")",
"{",
"$",
"variant",
"->",
"addVariantAttribute",
"(",
"$",
"attribute",
")",
";",
"}",
"return",
"$",
"variant",
";",
"}"
] |
Creates a new relation between variant and attribute.
@param int $productId
@param array $requestData
@throws AttributeNotFoundException
@throws ProductNotFoundException
@return ProductInterface
|
[
"Creates",
"a",
"new",
"relation",
"between",
"variant",
"and",
"attribute",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductVariantAttributeManager.php#L119-L130
|
224,208
|
sulu/SuluProductBundle
|
Product/ProductVariantAttributeManager.php
|
ProductVariantAttributeManager.removeVariantAttributeRelation
|
public function removeVariantAttributeRelation($productId, $attributeId)
{
$variant = $this->retrieveProductById($productId);
$attribute = $this->retrieveAttributeById($attributeId);
if (!$variant->getVariantAttributes()->contains($attribute)) {
throw new ProductException('Variant does not have relation to attribute');
}
$variant->removeVariantAttribute($attribute);
return $variant;
}
|
php
|
public function removeVariantAttributeRelation($productId, $attributeId)
{
$variant = $this->retrieveProductById($productId);
$attribute = $this->retrieveAttributeById($attributeId);
if (!$variant->getVariantAttributes()->contains($attribute)) {
throw new ProductException('Variant does not have relation to attribute');
}
$variant->removeVariantAttribute($attribute);
return $variant;
}
|
[
"public",
"function",
"removeVariantAttributeRelation",
"(",
"$",
"productId",
",",
"$",
"attributeId",
")",
"{",
"$",
"variant",
"=",
"$",
"this",
"->",
"retrieveProductById",
"(",
"$",
"productId",
")",
";",
"$",
"attribute",
"=",
"$",
"this",
"->",
"retrieveAttributeById",
"(",
"$",
"attributeId",
")",
";",
"if",
"(",
"!",
"$",
"variant",
"->",
"getVariantAttributes",
"(",
")",
"->",
"contains",
"(",
"$",
"attribute",
")",
")",
"{",
"throw",
"new",
"ProductException",
"(",
"'Variant does not have relation to attribute'",
")",
";",
"}",
"$",
"variant",
"->",
"removeVariantAttribute",
"(",
"$",
"attribute",
")",
";",
"return",
"$",
"variant",
";",
"}"
] |
Removes relation between variant and attribute.
@param int $productId
@param int $attributeId
@throws ProductException
@return ProductInterface
|
[
"Removes",
"relation",
"between",
"variant",
"and",
"attribute",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductVariantAttributeManager.php#L142-L154
|
224,209
|
sulu/SuluProductBundle
|
Product/ProductVariantAttributeManager.php
|
ProductVariantAttributeManager.retrieveAttributeById
|
private function retrieveAttributeById($attributeId)
{
$attribute = $this->attributeRepository->find($attributeId);
if (!$attribute) {
throw new AttributeNotFoundException($attributeId);
}
return $attribute;
}
|
php
|
private function retrieveAttributeById($attributeId)
{
$attribute = $this->attributeRepository->find($attributeId);
if (!$attribute) {
throw new AttributeNotFoundException($attributeId);
}
return $attribute;
}
|
[
"private",
"function",
"retrieveAttributeById",
"(",
"$",
"attributeId",
")",
"{",
"$",
"attribute",
"=",
"$",
"this",
"->",
"attributeRepository",
"->",
"find",
"(",
"$",
"attributeId",
")",
";",
"if",
"(",
"!",
"$",
"attribute",
")",
"{",
"throw",
"new",
"AttributeNotFoundException",
"(",
"$",
"attributeId",
")",
";",
"}",
"return",
"$",
"attribute",
";",
"}"
] |
Fetches attribute from db. If not found an exception is thrown.
@param int $attributeId
@throws AttributeNotFoundException
@return Attribute
|
[
"Fetches",
"attribute",
"from",
"db",
".",
"If",
"not",
"found",
"an",
"exception",
"is",
"thrown",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductVariantAttributeManager.php#L165-L173
|
224,210
|
sulu/SuluProductBundle
|
Product/ProductVariantAttributeManager.php
|
ProductVariantAttributeManager.retrieveProductById
|
private function retrieveProductById($productId)
{
// Fetch product.
$product = $this->productRepository->find($productId);
if (!$product) {
throw new ProductNotFoundException($productId);
}
return $product;
}
|
php
|
private function retrieveProductById($productId)
{
// Fetch product.
$product = $this->productRepository->find($productId);
if (!$product) {
throw new ProductNotFoundException($productId);
}
return $product;
}
|
[
"private",
"function",
"retrieveProductById",
"(",
"$",
"productId",
")",
"{",
"// Fetch product.",
"$",
"product",
"=",
"$",
"this",
"->",
"productRepository",
"->",
"find",
"(",
"$",
"productId",
")",
";",
"if",
"(",
"!",
"$",
"product",
")",
"{",
"throw",
"new",
"ProductNotFoundException",
"(",
"$",
"productId",
")",
";",
"}",
"return",
"$",
"product",
";",
"}"
] |
Fetches product from db. If not found an exception is thrown.
@param int $productId
@throws ProductNotFoundException
@return ProductInterface
|
[
"Fetches",
"product",
"from",
"db",
".",
"If",
"not",
"found",
"an",
"exception",
"is",
"thrown",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductVariantAttributeManager.php#L184-L193
|
224,211
|
sulu/SuluProductBundle
|
Controller/VariantController.php
|
VariantController.getAction
|
public function getAction(Request $request, $parentId, $variantId)
{
$locale = $this->getLocale($request);
$view = $this->responseGetById(
$variantId,
function ($id) use ($locale, $parentId) {
$product = $this->getProductManager()->findByIdAndLocale($id, $locale);
if ($product !== null && $product->getParent() && $product->getParent()->getId() == $parentId) {
return $product;
} else {
return null;
}
}
);
return $this->handleView($view);
}
|
php
|
public function getAction(Request $request, $parentId, $variantId)
{
$locale = $this->getLocale($request);
$view = $this->responseGetById(
$variantId,
function ($id) use ($locale, $parentId) {
$product = $this->getProductManager()->findByIdAndLocale($id, $locale);
if ($product !== null && $product->getParent() && $product->getParent()->getId() == $parentId) {
return $product;
} else {
return null;
}
}
);
return $this->handleView($view);
}
|
[
"public",
"function",
"getAction",
"(",
"Request",
"$",
"request",
",",
"$",
"parentId",
",",
"$",
"variantId",
")",
"{",
"$",
"locale",
"=",
"$",
"this",
"->",
"getLocale",
"(",
"$",
"request",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"responseGetById",
"(",
"$",
"variantId",
",",
"function",
"(",
"$",
"id",
")",
"use",
"(",
"$",
"locale",
",",
"$",
"parentId",
")",
"{",
"$",
"product",
"=",
"$",
"this",
"->",
"getProductManager",
"(",
")",
"->",
"findByIdAndLocale",
"(",
"$",
"id",
",",
"$",
"locale",
")",
";",
"if",
"(",
"$",
"product",
"!==",
"null",
"&&",
"$",
"product",
"->",
"getParent",
"(",
")",
"&&",
"$",
"product",
"->",
"getParent",
"(",
")",
"->",
"getId",
"(",
")",
"==",
"$",
"parentId",
")",
"{",
"return",
"$",
"product",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] |
Retrieves and shows the variant with the given ID for the parent product.
@param Request $request
@param int $parentId
@param int $variantId
@return Response
|
[
"Retrieves",
"and",
"shows",
"the",
"variant",
"with",
"the",
"given",
"ID",
"for",
"the",
"parent",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Controller/VariantController.php#L84-L101
|
224,212
|
sulu/SuluProductBundle
|
Controller/VariantController.php
|
VariantController.cgetAction
|
public function cgetAction(Request $request, $parentId)
{
if ($request->get('flat') == 'true') {
/** @var RestHelperInterface $restHelper */
$restHelper = $this->get('sulu_core.doctrine_rest_helper');
/** @var DoctrineListBuilderFactory $factory */
$factory = $this->get('sulu_core.doctrine_list_builder_factory');
$listBuilder = $factory->create(self::$entityName);
$fieldDescriptors = $this->getProductVariantManager()->retrieveFieldDescriptors($this->getLocale($request));
$restHelper->initializeListBuilder(
$listBuilder,
$fieldDescriptors
);
$listBuilder->where($fieldDescriptors['parent'], $parentId);
$listBuilder->addGroupBy($fieldDescriptors['id']);
// Only add group by id if categories are processed.
$fieldsParam = $request->get('fields');
$fields = explode(',', $fieldsParam);
if (isset($filter['categories'])
|| !$fieldsParam
|| array_search('categories', $fields) !== false
) {
$listBuilder->addGroupBy($fieldDescriptors['id']);
}
$list = new ListRepresentation(
$listBuilder->execute(),
self::$entityKey,
'get_product_variants',
array_merge(
$request->query->all(),
[
'parentId' => $parentId,
]
),
$listBuilder->getCurrentPage(),
$listBuilder->getLimit(),
$listBuilder->count()
);
} else {
$list = new CollectionRepresentation(
$this->getProductManager()->findAllByLocale($this->getLocale($request)),
self::$entityKey
);
}
$view = $this->view($list, 200);
return $this->handleView($view);
}
|
php
|
public function cgetAction(Request $request, $parentId)
{
if ($request->get('flat') == 'true') {
/** @var RestHelperInterface $restHelper */
$restHelper = $this->get('sulu_core.doctrine_rest_helper');
/** @var DoctrineListBuilderFactory $factory */
$factory = $this->get('sulu_core.doctrine_list_builder_factory');
$listBuilder = $factory->create(self::$entityName);
$fieldDescriptors = $this->getProductVariantManager()->retrieveFieldDescriptors($this->getLocale($request));
$restHelper->initializeListBuilder(
$listBuilder,
$fieldDescriptors
);
$listBuilder->where($fieldDescriptors['parent'], $parentId);
$listBuilder->addGroupBy($fieldDescriptors['id']);
// Only add group by id if categories are processed.
$fieldsParam = $request->get('fields');
$fields = explode(',', $fieldsParam);
if (isset($filter['categories'])
|| !$fieldsParam
|| array_search('categories', $fields) !== false
) {
$listBuilder->addGroupBy($fieldDescriptors['id']);
}
$list = new ListRepresentation(
$listBuilder->execute(),
self::$entityKey,
'get_product_variants',
array_merge(
$request->query->all(),
[
'parentId' => $parentId,
]
),
$listBuilder->getCurrentPage(),
$listBuilder->getLimit(),
$listBuilder->count()
);
} else {
$list = new CollectionRepresentation(
$this->getProductManager()->findAllByLocale($this->getLocale($request)),
self::$entityKey
);
}
$view = $this->view($list, 200);
return $this->handleView($view);
}
|
[
"public",
"function",
"cgetAction",
"(",
"Request",
"$",
"request",
",",
"$",
"parentId",
")",
"{",
"if",
"(",
"$",
"request",
"->",
"get",
"(",
"'flat'",
")",
"==",
"'true'",
")",
"{",
"/** @var RestHelperInterface $restHelper */",
"$",
"restHelper",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_core.doctrine_rest_helper'",
")",
";",
"/** @var DoctrineListBuilderFactory $factory */",
"$",
"factory",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_core.doctrine_list_builder_factory'",
")",
";",
"$",
"listBuilder",
"=",
"$",
"factory",
"->",
"create",
"(",
"self",
"::",
"$",
"entityName",
")",
";",
"$",
"fieldDescriptors",
"=",
"$",
"this",
"->",
"getProductVariantManager",
"(",
")",
"->",
"retrieveFieldDescriptors",
"(",
"$",
"this",
"->",
"getLocale",
"(",
"$",
"request",
")",
")",
";",
"$",
"restHelper",
"->",
"initializeListBuilder",
"(",
"$",
"listBuilder",
",",
"$",
"fieldDescriptors",
")",
";",
"$",
"listBuilder",
"->",
"where",
"(",
"$",
"fieldDescriptors",
"[",
"'parent'",
"]",
",",
"$",
"parentId",
")",
";",
"$",
"listBuilder",
"->",
"addGroupBy",
"(",
"$",
"fieldDescriptors",
"[",
"'id'",
"]",
")",
";",
"// Only add group by id if categories are processed.",
"$",
"fieldsParam",
"=",
"$",
"request",
"->",
"get",
"(",
"'fields'",
")",
";",
"$",
"fields",
"=",
"explode",
"(",
"','",
",",
"$",
"fieldsParam",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"filter",
"[",
"'categories'",
"]",
")",
"||",
"!",
"$",
"fieldsParam",
"||",
"array_search",
"(",
"'categories'",
",",
"$",
"fields",
")",
"!==",
"false",
")",
"{",
"$",
"listBuilder",
"->",
"addGroupBy",
"(",
"$",
"fieldDescriptors",
"[",
"'id'",
"]",
")",
";",
"}",
"$",
"list",
"=",
"new",
"ListRepresentation",
"(",
"$",
"listBuilder",
"->",
"execute",
"(",
")",
",",
"self",
"::",
"$",
"entityKey",
",",
"'get_product_variants'",
",",
"array_merge",
"(",
"$",
"request",
"->",
"query",
"->",
"all",
"(",
")",
",",
"[",
"'parentId'",
"=>",
"$",
"parentId",
",",
"]",
")",
",",
"$",
"listBuilder",
"->",
"getCurrentPage",
"(",
")",
",",
"$",
"listBuilder",
"->",
"getLimit",
"(",
")",
",",
"$",
"listBuilder",
"->",
"count",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"list",
"=",
"new",
"CollectionRepresentation",
"(",
"$",
"this",
"->",
"getProductManager",
"(",
")",
"->",
"findAllByLocale",
"(",
"$",
"this",
"->",
"getLocale",
"(",
"$",
"request",
")",
")",
",",
"self",
"::",
"$",
"entityKey",
")",
";",
"}",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"list",
",",
"200",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] |
Returns a list of product variants for the requested product.
@param Request $request
@param int $parentId
@return Response
|
[
"Returns",
"a",
"list",
"of",
"product",
"variants",
"for",
"the",
"requested",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Controller/VariantController.php#L111-L166
|
224,213
|
sulu/SuluProductBundle
|
Controller/VariantController.php
|
VariantController.postAction
|
public function postAction(Request $request, $parentId)
{
$requestData = $request->request->all();
$userId = $this->getUser()->getId();
$locale = $this->getLocale($request);
$variant = $this->getProductVariantManager()->createVariant(
$parentId,
$requestData,
$locale,
$userId
);
$this->getEntityManager()->flush();
$apiVariant = $this->getProductFactory()->createApiEntity($variant, $locale);
$view = $this->view($apiVariant, 200);
return $this->handleView($view);
}
|
php
|
public function postAction(Request $request, $parentId)
{
$requestData = $request->request->all();
$userId = $this->getUser()->getId();
$locale = $this->getLocale($request);
$variant = $this->getProductVariantManager()->createVariant(
$parentId,
$requestData,
$locale,
$userId
);
$this->getEntityManager()->flush();
$apiVariant = $this->getProductFactory()->createApiEntity($variant, $locale);
$view = $this->view($apiVariant, 200);
return $this->handleView($view);
}
|
[
"public",
"function",
"postAction",
"(",
"Request",
"$",
"request",
",",
"$",
"parentId",
")",
"{",
"$",
"requestData",
"=",
"$",
"request",
"->",
"request",
"->",
"all",
"(",
")",
";",
"$",
"userId",
"=",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"getId",
"(",
")",
";",
"$",
"locale",
"=",
"$",
"this",
"->",
"getLocale",
"(",
"$",
"request",
")",
";",
"$",
"variant",
"=",
"$",
"this",
"->",
"getProductVariantManager",
"(",
")",
"->",
"createVariant",
"(",
"$",
"parentId",
",",
"$",
"requestData",
",",
"$",
"locale",
",",
"$",
"userId",
")",
";",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"flush",
"(",
")",
";",
"$",
"apiVariant",
"=",
"$",
"this",
"->",
"getProductFactory",
"(",
")",
"->",
"createApiEntity",
"(",
"$",
"variant",
",",
"$",
"locale",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"apiVariant",
",",
"200",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] |
Adds a new variant to given product.
@param Request $request
@param int $parentId
@return Response
|
[
"Adds",
"a",
"new",
"variant",
"to",
"given",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Controller/VariantController.php#L176-L196
|
224,214
|
sulu/SuluProductBundle
|
Controller/VariantController.php
|
VariantController.putAction
|
public function putAction(Request $request, $parentId, $variantId)
{
$requestData = $request->request->all();
$userId = $this->getUser()->getId();
$locale = $this->getLocale($request);
$variant = $this->getProductVariantManager()->updateVariant(
$variantId,
$requestData,
$locale,
$userId
);
if ($variant->getParent()->getId() !== (int) $parentId) {
throw new ProductException('Variant does not exists for given product.');
}
$this->getEntityManager()->flush();
$apiVariant = $this->getProductFactory()->createApiEntity($variant, $locale);
$view = $this->view($apiVariant, 200);
return $this->handleView($view);
}
|
php
|
public function putAction(Request $request, $parentId, $variantId)
{
$requestData = $request->request->all();
$userId = $this->getUser()->getId();
$locale = $this->getLocale($request);
$variant = $this->getProductVariantManager()->updateVariant(
$variantId,
$requestData,
$locale,
$userId
);
if ($variant->getParent()->getId() !== (int) $parentId) {
throw new ProductException('Variant does not exists for given product.');
}
$this->getEntityManager()->flush();
$apiVariant = $this->getProductFactory()->createApiEntity($variant, $locale);
$view = $this->view($apiVariant, 200);
return $this->handleView($view);
}
|
[
"public",
"function",
"putAction",
"(",
"Request",
"$",
"request",
",",
"$",
"parentId",
",",
"$",
"variantId",
")",
"{",
"$",
"requestData",
"=",
"$",
"request",
"->",
"request",
"->",
"all",
"(",
")",
";",
"$",
"userId",
"=",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"getId",
"(",
")",
";",
"$",
"locale",
"=",
"$",
"this",
"->",
"getLocale",
"(",
"$",
"request",
")",
";",
"$",
"variant",
"=",
"$",
"this",
"->",
"getProductVariantManager",
"(",
")",
"->",
"updateVariant",
"(",
"$",
"variantId",
",",
"$",
"requestData",
",",
"$",
"locale",
",",
"$",
"userId",
")",
";",
"if",
"(",
"$",
"variant",
"->",
"getParent",
"(",
")",
"->",
"getId",
"(",
")",
"!==",
"(",
"int",
")",
"$",
"parentId",
")",
"{",
"throw",
"new",
"ProductException",
"(",
"'Variant does not exists for given product.'",
")",
";",
"}",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"flush",
"(",
")",
";",
"$",
"apiVariant",
"=",
"$",
"this",
"->",
"getProductFactory",
"(",
")",
"->",
"createApiEntity",
"(",
"$",
"variant",
",",
"$",
"locale",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"apiVariant",
",",
"200",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] |
Updates an existing variant to given product.
@param Request $request
@param int $parentId
@param int $variantId
@throws ProductException
@return Response
|
[
"Updates",
"an",
"existing",
"variant",
"to",
"given",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Controller/VariantController.php#L209-L233
|
224,215
|
sulu/SuluProductBundle
|
Product/ProductVariantManager.php
|
ProductVariantManager.mapDataToVariant
|
private function mapDataToVariant(ProductInterface $variant, array $variantData, $locale, $userId)
{
$productTranslation = $this->productManager->retrieveOrCreateProductTranslationByLocale($variant, $locale);
$productTranslation->setName($this->getProperty($variantData, 'name'));
$variant->setNumber($this->getProperty($variantData, 'number'));
$this->processAttributes($variant, $variantData, $locale);
$this->processPrices($variant, $variantData);
}
|
php
|
private function mapDataToVariant(ProductInterface $variant, array $variantData, $locale, $userId)
{
$productTranslation = $this->productManager->retrieveOrCreateProductTranslationByLocale($variant, $locale);
$productTranslation->setName($this->getProperty($variantData, 'name'));
$variant->setNumber($this->getProperty($variantData, 'number'));
$this->processAttributes($variant, $variantData, $locale);
$this->processPrices($variant, $variantData);
}
|
[
"private",
"function",
"mapDataToVariant",
"(",
"ProductInterface",
"$",
"variant",
",",
"array",
"$",
"variantData",
",",
"$",
"locale",
",",
"$",
"userId",
")",
"{",
"$",
"productTranslation",
"=",
"$",
"this",
"->",
"productManager",
"->",
"retrieveOrCreateProductTranslationByLocale",
"(",
"$",
"variant",
",",
"$",
"locale",
")",
";",
"$",
"productTranslation",
"->",
"setName",
"(",
"$",
"this",
"->",
"getProperty",
"(",
"$",
"variantData",
",",
"'name'",
")",
")",
";",
"$",
"variant",
"->",
"setNumber",
"(",
"$",
"this",
"->",
"getProperty",
"(",
"$",
"variantData",
",",
"'number'",
")",
")",
";",
"$",
"this",
"->",
"processAttributes",
"(",
"$",
"variant",
",",
"$",
"variantData",
",",
"$",
"locale",
")",
";",
"$",
"this",
"->",
"processPrices",
"(",
"$",
"variant",
",",
"$",
"variantData",
")",
";",
"}"
] |
Maps all the data to a given variant for the given locale.
@param ProductInterface $variant
@param array $variantData
@param string $locale
@param int $userId
|
[
"Maps",
"all",
"the",
"data",
"to",
"a",
"given",
"variant",
"for",
"the",
"given",
"locale",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductVariantManager.php#L283-L292
|
224,216
|
sulu/SuluProductBundle
|
Product/ProductVariantManager.php
|
ProductVariantManager.processAttributes
|
private function processAttributes(ProductInterface $variant, array $variantData, $locale)
{
$parent = $variant->getParent();
// Number of attributes in variantData and parents variant-attributes need to match and must not be 0.
$sizeOfVariantAttributes = count($this->getProperty($variantData, 'attributes'));
$sizeOfParentAttributes = $parent->getVariantAttributes()->count();
if (!$sizeOfVariantAttributes
|| !$sizeOfParentAttributes
|| $sizeOfVariantAttributes != $sizeOfParentAttributes
) {
throw new ProductException('Invalid number of attributes for variant provided.');
}
$attributesDataCopy = $variantData['attributes'];
// For all variants of parent, find corresponding attribute in variant-data.
foreach ($parent->getVariantAttributes() as $variantAttribute) {
foreach ($attributesDataCopy as $index => $attributeData) {
if ($variantAttribute->getId() === $attributeData['attributeId']) {
// Update or create ProductAttribute for variant.
$this->productAttributeManager->updateOrCreateProductAttributeForProduct(
$variant,
$variantAttribute,
$attributeData,
$locale
);
unset($attributesDataCopy[$index]);
}
}
}
// Not all necessary variant attributes were defined in data array.
if (count($attributesDataCopy)) {
throw new ProductException('Invalid attributes for variant provided.');
}
}
|
php
|
private function processAttributes(ProductInterface $variant, array $variantData, $locale)
{
$parent = $variant->getParent();
// Number of attributes in variantData and parents variant-attributes need to match and must not be 0.
$sizeOfVariantAttributes = count($this->getProperty($variantData, 'attributes'));
$sizeOfParentAttributes = $parent->getVariantAttributes()->count();
if (!$sizeOfVariantAttributes
|| !$sizeOfParentAttributes
|| $sizeOfVariantAttributes != $sizeOfParentAttributes
) {
throw new ProductException('Invalid number of attributes for variant provided.');
}
$attributesDataCopy = $variantData['attributes'];
// For all variants of parent, find corresponding attribute in variant-data.
foreach ($parent->getVariantAttributes() as $variantAttribute) {
foreach ($attributesDataCopy as $index => $attributeData) {
if ($variantAttribute->getId() === $attributeData['attributeId']) {
// Update or create ProductAttribute for variant.
$this->productAttributeManager->updateOrCreateProductAttributeForProduct(
$variant,
$variantAttribute,
$attributeData,
$locale
);
unset($attributesDataCopy[$index]);
}
}
}
// Not all necessary variant attributes were defined in data array.
if (count($attributesDataCopy)) {
throw new ProductException('Invalid attributes for variant provided.');
}
}
|
[
"private",
"function",
"processAttributes",
"(",
"ProductInterface",
"$",
"variant",
",",
"array",
"$",
"variantData",
",",
"$",
"locale",
")",
"{",
"$",
"parent",
"=",
"$",
"variant",
"->",
"getParent",
"(",
")",
";",
"// Number of attributes in variantData and parents variant-attributes need to match and must not be 0.",
"$",
"sizeOfVariantAttributes",
"=",
"count",
"(",
"$",
"this",
"->",
"getProperty",
"(",
"$",
"variantData",
",",
"'attributes'",
")",
")",
";",
"$",
"sizeOfParentAttributes",
"=",
"$",
"parent",
"->",
"getVariantAttributes",
"(",
")",
"->",
"count",
"(",
")",
";",
"if",
"(",
"!",
"$",
"sizeOfVariantAttributes",
"||",
"!",
"$",
"sizeOfParentAttributes",
"||",
"$",
"sizeOfVariantAttributes",
"!=",
"$",
"sizeOfParentAttributes",
")",
"{",
"throw",
"new",
"ProductException",
"(",
"'Invalid number of attributes for variant provided.'",
")",
";",
"}",
"$",
"attributesDataCopy",
"=",
"$",
"variantData",
"[",
"'attributes'",
"]",
";",
"// For all variants of parent, find corresponding attribute in variant-data.",
"foreach",
"(",
"$",
"parent",
"->",
"getVariantAttributes",
"(",
")",
"as",
"$",
"variantAttribute",
")",
"{",
"foreach",
"(",
"$",
"attributesDataCopy",
"as",
"$",
"index",
"=>",
"$",
"attributeData",
")",
"{",
"if",
"(",
"$",
"variantAttribute",
"->",
"getId",
"(",
")",
"===",
"$",
"attributeData",
"[",
"'attributeId'",
"]",
")",
"{",
"// Update or create ProductAttribute for variant.",
"$",
"this",
"->",
"productAttributeManager",
"->",
"updateOrCreateProductAttributeForProduct",
"(",
"$",
"variant",
",",
"$",
"variantAttribute",
",",
"$",
"attributeData",
",",
"$",
"locale",
")",
";",
"unset",
"(",
"$",
"attributesDataCopy",
"[",
"$",
"index",
"]",
")",
";",
"}",
"}",
"}",
"// Not all necessary variant attributes were defined in data array.",
"if",
"(",
"count",
"(",
"$",
"attributesDataCopy",
")",
")",
"{",
"throw",
"new",
"ProductException",
"(",
"'Invalid attributes for variant provided.'",
")",
";",
"}",
"}"
] |
Adds variant attributes to variant.
@param ProductInterface $variant
@param array $variantData
@param string $locale
@throws ProductException
|
[
"Adds",
"variant",
"attributes",
"to",
"variant",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductVariantManager.php#L303-L340
|
224,217
|
sulu/SuluProductBundle
|
Product/ProductVariantManager.php
|
ProductVariantManager.processPrices
|
private function processPrices(ProductInterface $variant, array $variantData)
{
if (!isset($variantData['prices']) || !is_array($variantData['prices'])) {
return;
}
$currentPrices = iterator_to_array($variant->getPrices());
foreach ($variantData['prices'] as $price) {
$matchingEntity = $this->retrievePriceByCurrency($currentPrices, $price['currency']['id']);
// Create new price if no match was found.
if (!$matchingEntity) {
$this->productPriceManager->createNewProductPriceForCurrency(
$variant,
$price['price'],
0,
$price['currency']['id']
);
} else {
// Otherwise just update price.
$matchingEntity->setPrice($price['price']);
}
}
// The following prices were not matched and therefore have to be deleted.
foreach ($currentPrices as $price) {
$this->entityManager->remove($price);
}
}
|
php
|
private function processPrices(ProductInterface $variant, array $variantData)
{
if (!isset($variantData['prices']) || !is_array($variantData['prices'])) {
return;
}
$currentPrices = iterator_to_array($variant->getPrices());
foreach ($variantData['prices'] as $price) {
$matchingEntity = $this->retrievePriceByCurrency($currentPrices, $price['currency']['id']);
// Create new price if no match was found.
if (!$matchingEntity) {
$this->productPriceManager->createNewProductPriceForCurrency(
$variant,
$price['price'],
0,
$price['currency']['id']
);
} else {
// Otherwise just update price.
$matchingEntity->setPrice($price['price']);
}
}
// The following prices were not matched and therefore have to be deleted.
foreach ($currentPrices as $price) {
$this->entityManager->remove($price);
}
}
|
[
"private",
"function",
"processPrices",
"(",
"ProductInterface",
"$",
"variant",
",",
"array",
"$",
"variantData",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"variantData",
"[",
"'prices'",
"]",
")",
"||",
"!",
"is_array",
"(",
"$",
"variantData",
"[",
"'prices'",
"]",
")",
")",
"{",
"return",
";",
"}",
"$",
"currentPrices",
"=",
"iterator_to_array",
"(",
"$",
"variant",
"->",
"getPrices",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"variantData",
"[",
"'prices'",
"]",
"as",
"$",
"price",
")",
"{",
"$",
"matchingEntity",
"=",
"$",
"this",
"->",
"retrievePriceByCurrency",
"(",
"$",
"currentPrices",
",",
"$",
"price",
"[",
"'currency'",
"]",
"[",
"'id'",
"]",
")",
";",
"// Create new price if no match was found.",
"if",
"(",
"!",
"$",
"matchingEntity",
")",
"{",
"$",
"this",
"->",
"productPriceManager",
"->",
"createNewProductPriceForCurrency",
"(",
"$",
"variant",
",",
"$",
"price",
"[",
"'price'",
"]",
",",
"0",
",",
"$",
"price",
"[",
"'currency'",
"]",
"[",
"'id'",
"]",
")",
";",
"}",
"else",
"{",
"// Otherwise just update price.",
"$",
"matchingEntity",
"->",
"setPrice",
"(",
"$",
"price",
"[",
"'price'",
"]",
")",
";",
"}",
"}",
"// The following prices were not matched and therefore have to be deleted.",
"foreach",
"(",
"$",
"currentPrices",
"as",
"$",
"price",
")",
"{",
"$",
"this",
"->",
"entityManager",
"->",
"remove",
"(",
"$",
"price",
")",
";",
"}",
"}"
] |
Adds or updates price information for a variant.
@param ProductInterface $variant
@param array $variantData
|
[
"Adds",
"or",
"updates",
"price",
"information",
"for",
"a",
"variant",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductVariantManager.php#L348-L376
|
224,218
|
sulu/SuluProductBundle
|
Product/ProductVariantManager.php
|
ProductVariantManager.retrievePriceByCurrency
|
private function retrievePriceByCurrency(array &$prices, $currencyId)
{
/** @var ProductPrice $price */
foreach ($prices as $index => $price) {
if ($currencyId === $price->getCurrency()->getId()) {
unset($prices[$index]);
return $price;
}
}
return null;
}
|
php
|
private function retrievePriceByCurrency(array &$prices, $currencyId)
{
/** @var ProductPrice $price */
foreach ($prices as $index => $price) {
if ($currencyId === $price->getCurrency()->getId()) {
unset($prices[$index]);
return $price;
}
}
return null;
}
|
[
"private",
"function",
"retrievePriceByCurrency",
"(",
"array",
"&",
"$",
"prices",
",",
"$",
"currencyId",
")",
"{",
"/** @var ProductPrice $price */",
"foreach",
"(",
"$",
"prices",
"as",
"$",
"index",
"=>",
"$",
"price",
")",
"{",
"if",
"(",
"$",
"currencyId",
"===",
"$",
"price",
"->",
"getCurrency",
"(",
")",
"->",
"getId",
"(",
")",
")",
"{",
"unset",
"(",
"$",
"prices",
"[",
"$",
"index",
"]",
")",
";",
"return",
"$",
"price",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Returns price by currency id. If found, the ProductPrice entity is removed
from the prices array.
@param ProductPrice[] $prices
@param $currencyId
@return null|ProductPrice
|
[
"Returns",
"price",
"by",
"currency",
"id",
".",
"If",
"found",
"the",
"ProductPrice",
"entity",
"is",
"removed",
"from",
"the",
"prices",
"array",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductVariantManager.php#L387-L399
|
224,219
|
sulu/SuluProductBundle
|
Entity/ProductAttributeRepository.php
|
ProductAttributeRepository.findByAttributeIdAndProductId
|
public function findByAttributeIdAndProductId($attributeId, $productId)
{
try {
$queryBuilder = $this->createQueryBuilder('productAttribute')
->leftJoin('productAttribute.attribute', 'attribute')
->leftJoin('productAttribute.product', 'product')
->andWhere('attribute.id = :attributeId')
->andWhere('product.id = :productId')
->setParameter('attributeId', $attributeId)
->setParameter('productId', $productId);
return $queryBuilder->getQuery()->getSingleResult();
} catch (NoResultException $exc) {
return null;
}
}
|
php
|
public function findByAttributeIdAndProductId($attributeId, $productId)
{
try {
$queryBuilder = $this->createQueryBuilder('productAttribute')
->leftJoin('productAttribute.attribute', 'attribute')
->leftJoin('productAttribute.product', 'product')
->andWhere('attribute.id = :attributeId')
->andWhere('product.id = :productId')
->setParameter('attributeId', $attributeId)
->setParameter('productId', $productId);
return $queryBuilder->getQuery()->getSingleResult();
} catch (NoResultException $exc) {
return null;
}
}
|
[
"public",
"function",
"findByAttributeIdAndProductId",
"(",
"$",
"attributeId",
",",
"$",
"productId",
")",
"{",
"try",
"{",
"$",
"queryBuilder",
"=",
"$",
"this",
"->",
"createQueryBuilder",
"(",
"'productAttribute'",
")",
"->",
"leftJoin",
"(",
"'productAttribute.attribute'",
",",
"'attribute'",
")",
"->",
"leftJoin",
"(",
"'productAttribute.product'",
",",
"'product'",
")",
"->",
"andWhere",
"(",
"'attribute.id = :attributeId'",
")",
"->",
"andWhere",
"(",
"'product.id = :productId'",
")",
"->",
"setParameter",
"(",
"'attributeId'",
",",
"$",
"attributeId",
")",
"->",
"setParameter",
"(",
"'productId'",
",",
"$",
"productId",
")",
";",
"return",
"$",
"queryBuilder",
"->",
"getQuery",
"(",
")",
"->",
"getSingleResult",
"(",
")",
";",
"}",
"catch",
"(",
"NoResultException",
"$",
"exc",
")",
"{",
"return",
"null",
";",
"}",
"}"
] |
Returns the productAttribute for the given attribute and product id.
@param attributeId
@param productId
@return \Doctrine\ORM\QueryBuilder
|
[
"Returns",
"the",
"productAttribute",
"for",
"the",
"given",
"attribute",
"and",
"product",
"id",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Entity/ProductAttributeRepository.php#L30-L45
|
224,220
|
sulu/SuluProductBundle
|
DataFixtures/ORM/ProductTypes/LoadProductTypes.php
|
LoadProductTypes.processProductTypesFixtures
|
public static function processProductTypesFixtures(callable $elementCallback)
{
$file = dirname(__FILE__) . '/../../product-types.xml';
$doc = new \DOMDocument();
$doc->load($file);
$xpath = new \DOMXpath($doc);
$elements = $xpath->query('/product-types/product-type');
if (!is_null($elements)) {
/** @var \DOMNode $element */
foreach ($elements as $element) {
$elementCallback($element);
}
}
}
|
php
|
public static function processProductTypesFixtures(callable $elementCallback)
{
$file = dirname(__FILE__) . '/../../product-types.xml';
$doc = new \DOMDocument();
$doc->load($file);
$xpath = new \DOMXpath($doc);
$elements = $xpath->query('/product-types/product-type');
if (!is_null($elements)) {
/** @var \DOMNode $element */
foreach ($elements as $element) {
$elementCallback($element);
}
}
}
|
[
"public",
"static",
"function",
"processProductTypesFixtures",
"(",
"callable",
"$",
"elementCallback",
")",
"{",
"$",
"file",
"=",
"dirname",
"(",
"__FILE__",
")",
".",
"'/../../product-types.xml'",
";",
"$",
"doc",
"=",
"new",
"\\",
"DOMDocument",
"(",
")",
";",
"$",
"doc",
"->",
"load",
"(",
"$",
"file",
")",
";",
"$",
"xpath",
"=",
"new",
"\\",
"DOMXpath",
"(",
"$",
"doc",
")",
";",
"$",
"elements",
"=",
"$",
"xpath",
"->",
"query",
"(",
"'/product-types/product-type'",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"elements",
")",
")",
"{",
"/** @var \\DOMNode $element */",
"foreach",
"(",
"$",
"elements",
"as",
"$",
"element",
")",
"{",
"$",
"elementCallback",
"(",
"$",
"element",
")",
";",
"}",
"}",
"}"
] |
Function reads the product-types fixtures file and executes the given
element callback function for each node.
This function is static in order to be able to load product types xml
from another function as well.
@param callable $elementCallback
|
[
"Function",
"reads",
"the",
"product",
"-",
"types",
"fixtures",
"file",
"and",
"executes",
"the",
"given",
"element",
"callback",
"function",
"for",
"each",
"node",
".",
"This",
"function",
"is",
"static",
"in",
"order",
"to",
"be",
"able",
"to",
"load",
"product",
"types",
"xml",
"from",
"another",
"function",
"as",
"well",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/DataFixtures/ORM/ProductTypes/LoadProductTypes.php#L30-L45
|
224,221
|
mrclay/shibalike
|
src/Shibalike/IdP.php
|
IdP.markAsAuthenticated
|
public function markAsAuthenticated($username, array $attrs = null)
{
if (!$attrs) {
$attrs = $this->fetchAttrs($username);
}
$authResult = new AuthResult($username, $attrs);
return $this->_stateMgr->set('authResult', $authResult);
}
|
php
|
public function markAsAuthenticated($username, array $attrs = null)
{
if (!$attrs) {
$attrs = $this->fetchAttrs($username);
}
$authResult = new AuthResult($username, $attrs);
return $this->_stateMgr->set('authResult', $authResult);
}
|
[
"public",
"function",
"markAsAuthenticated",
"(",
"$",
"username",
",",
"array",
"$",
"attrs",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"attrs",
")",
"{",
"$",
"attrs",
"=",
"$",
"this",
"->",
"fetchAttrs",
"(",
"$",
"username",
")",
";",
"}",
"$",
"authResult",
"=",
"new",
"AuthResult",
"(",
"$",
"username",
",",
"$",
"attrs",
")",
";",
"return",
"$",
"this",
"->",
"_stateMgr",
"->",
"set",
"(",
"'authResult'",
",",
"$",
"authResult",
")",
";",
"}"
] |
Mark the user as authenticated and store her in the state manager
@param string $username
@param array $attrs if not provided, fetchAttrs will be called
@return bool was the user state set successfully?
|
[
"Mark",
"the",
"user",
"as",
"authenticated",
"and",
"store",
"her",
"in",
"the",
"state",
"manager"
] |
04242301ed18f5a1b02493bcc193f5efd255112e
|
https://github.com/mrclay/shibalike/blob/04242301ed18f5a1b02493bcc193f5efd255112e/src/Shibalike/IdP.php#L62-L69
|
224,222
|
sulu/SuluProductBundle
|
Product/UnitManager.php
|
UnitManager.findAll
|
public function findAll($locale)
{
$units = $this->unitRepository->findAllByLocale($locale);
array_walk(
$units,
function (&$unit) use ($locale) {
$unit = new Unit($unit, $locale);
}
);
return $units;
}
|
php
|
public function findAll($locale)
{
$units = $this->unitRepository->findAllByLocale($locale);
array_walk(
$units,
function (&$unit) use ($locale) {
$unit = new Unit($unit, $locale);
}
);
return $units;
}
|
[
"public",
"function",
"findAll",
"(",
"$",
"locale",
")",
"{",
"$",
"units",
"=",
"$",
"this",
"->",
"unitRepository",
"->",
"findAllByLocale",
"(",
"$",
"locale",
")",
";",
"array_walk",
"(",
"$",
"units",
",",
"function",
"(",
"&",
"$",
"unit",
")",
"use",
"(",
"$",
"locale",
")",
"{",
"$",
"unit",
"=",
"new",
"Unit",
"(",
"$",
"unit",
",",
"$",
"locale",
")",
";",
"}",
")",
";",
"return",
"$",
"units",
";",
"}"
] |
Find all units.
@param $locale
@return Unit[]
|
[
"Find",
"all",
"units",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/UnitManager.php#L39-L51
|
224,223
|
swisnl/game-of-tests-laravel
|
src/Http/Controllers/ResultsController.php
|
ResultsController.scoreForMonth
|
public function scoreForMonth(Request $request)
{
$repos = new ResultsRepository();
$title = Carbon::createFromDate()->subMonths($request->input('monthsBack', 0))->format('F');
return view(
'game-of-tests::results.list',
[
'title' => $title,
'months_back' => $request->input('monthsBack', 0),
'results' => $repos->getScoreForMonth($request->input('monthsBack', 0))
]
);
}
|
php
|
public function scoreForMonth(Request $request)
{
$repos = new ResultsRepository();
$title = Carbon::createFromDate()->subMonths($request->input('monthsBack', 0))->format('F');
return view(
'game-of-tests::results.list',
[
'title' => $title,
'months_back' => $request->input('monthsBack', 0),
'results' => $repos->getScoreForMonth($request->input('monthsBack', 0))
]
);
}
|
[
"public",
"function",
"scoreForMonth",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"repos",
"=",
"new",
"ResultsRepository",
"(",
")",
";",
"$",
"title",
"=",
"Carbon",
"::",
"createFromDate",
"(",
")",
"->",
"subMonths",
"(",
"$",
"request",
"->",
"input",
"(",
"'monthsBack'",
",",
"0",
")",
")",
"->",
"format",
"(",
"'F'",
")",
";",
"return",
"view",
"(",
"'game-of-tests::results.list'",
",",
"[",
"'title'",
"=>",
"$",
"title",
",",
"'months_back'",
"=>",
"$",
"request",
"->",
"input",
"(",
"'monthsBack'",
",",
"0",
")",
",",
"'results'",
"=>",
"$",
"repos",
"->",
"getScoreForMonth",
"(",
"$",
"request",
"->",
"input",
"(",
"'monthsBack'",
",",
"0",
")",
")",
"]",
")",
";",
"}"
] |
Show rankings of specific month
@param Request $request
@return mixed
|
[
"Show",
"rankings",
"of",
"specific",
"month"
] |
b2874e996dc79a667640eb392a0cdead0591a66b
|
https://github.com/swisnl/game-of-tests-laravel/blob/b2874e996dc79a667640eb392a0cdead0591a66b/src/Http/Controllers/ResultsController.php#L30-L42
|
224,224
|
swisnl/game-of-tests-laravel
|
src/Http/Controllers/ResultsController.php
|
ResultsController.scoreLastMonths
|
public function scoreLastMonths(Request $request)
{
$repos = new ResultsRepository();
return view(
'game-of-tests::results.list',
[
'type' => 'from',
'months_back' => $request->input('monthsBack', 0),
'results' => $repos->getScoreLastMonths($request->input('monthsBack', 0))
]
);
}
|
php
|
public function scoreLastMonths(Request $request)
{
$repos = new ResultsRepository();
return view(
'game-of-tests::results.list',
[
'type' => 'from',
'months_back' => $request->input('monthsBack', 0),
'results' => $repos->getScoreLastMonths($request->input('monthsBack', 0))
]
);
}
|
[
"public",
"function",
"scoreLastMonths",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"repos",
"=",
"new",
"ResultsRepository",
"(",
")",
";",
"return",
"view",
"(",
"'game-of-tests::results.list'",
",",
"[",
"'type'",
"=>",
"'from'",
",",
"'months_back'",
"=>",
"$",
"request",
"->",
"input",
"(",
"'monthsBack'",
",",
"0",
")",
",",
"'results'",
"=>",
"$",
"repos",
"->",
"getScoreLastMonths",
"(",
"$",
"request",
"->",
"input",
"(",
"'monthsBack'",
",",
"0",
")",
")",
"]",
")",
";",
"}"
] |
Show rankings for last X months
@param Request $request
@return mixed
|
[
"Show",
"rankings",
"for",
"last",
"X",
"months"
] |
b2874e996dc79a667640eb392a0cdead0591a66b
|
https://github.com/swisnl/game-of-tests-laravel/blob/b2874e996dc79a667640eb392a0cdead0591a66b/src/Http/Controllers/ResultsController.php#L50-L61
|
224,225
|
swisnl/game-of-tests-laravel
|
src/Http/Controllers/ResultsController.php
|
ResultsController.resultForUser
|
public function resultForUser($user, Request $request)
{
$repos = new ResultsRepository();
$results = $repos->getByUser(
$user,
$request->input('monthsBack', false),
$request->input('fromMonthsBack', false)
);
return view('game-of-tests::results.author', ['results' => $results]);
}
|
php
|
public function resultForUser($user, Request $request)
{
$repos = new ResultsRepository();
$results = $repos->getByUser(
$user,
$request->input('monthsBack', false),
$request->input('fromMonthsBack', false)
);
return view('game-of-tests::results.author', ['results' => $results]);
}
|
[
"public",
"function",
"resultForUser",
"(",
"$",
"user",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"repos",
"=",
"new",
"ResultsRepository",
"(",
")",
";",
"$",
"results",
"=",
"$",
"repos",
"->",
"getByUser",
"(",
"$",
"user",
",",
"$",
"request",
"->",
"input",
"(",
"'monthsBack'",
",",
"false",
")",
",",
"$",
"request",
"->",
"input",
"(",
"'fromMonthsBack'",
",",
"false",
")",
")",
";",
"return",
"view",
"(",
"'game-of-tests::results.author'",
",",
"[",
"'results'",
"=>",
"$",
"results",
"]",
")",
";",
"}"
] |
Show result for specific user.
@param $user
@param Request $request
@return mixed
|
[
"Show",
"result",
"for",
"specific",
"user",
"."
] |
b2874e996dc79a667640eb392a0cdead0591a66b
|
https://github.com/swisnl/game-of-tests-laravel/blob/b2874e996dc79a667640eb392a0cdead0591a66b/src/Http/Controllers/ResultsController.php#L70-L81
|
224,226
|
sulu/SuluProductBundle
|
Product/ProductManager.php
|
ProductManager.getFilterFieldDescriptors
|
public function getFilterFieldDescriptors()
{
$fieldDescriptors = [];
$fieldDescriptors['type_id'] = new DoctrineFieldDescriptor(
'id',
'type_id',
self::$productTypeEntityName,
null,
[
self::$productTypeEntityName => new DoctrineJoinDescriptor(
self::$productTypeEntityName,
static::$productEntityName . '.type'
),
]
);
$fieldDescriptors['status_id'] = new DoctrineFieldDescriptor(
'id',
'status_id',
self::$productStatusEntityName,
null,
[
self::$productStatusEntityName => new DoctrineJoinDescriptor(
self::$productStatusEntityName,
static::$productEntityName . '.status'
),
]
);
$fieldDescriptors['accounts_supplier_id'] = new DoctrineFieldDescriptor(
'id',
'supplier_id',
self::$accountsSupplierEntityName,
null,
[
self::$accountsSupplierEntityName => new DoctrineJoinDescriptor(
self::$accountsSupplierEntityName,
static::$productEntityName . '.supplier'
),
]
);
$fieldDescriptors['is_deprecated'] = new DoctrineFieldDescriptor(
'isDeprecated',
'is_deprecated',
static::$productEntityName,
null,
[]
);
$fieldDescriptors['parent'] = new DoctrineFieldDescriptor(
'id',
'parent',
static::$productEntityName . 'Parent',
'product.parent',
[
static::$productEntityName . 'Parent' => new DoctrineJoinDescriptor(
static::$productEntityName,
static::$productEntityName . '.parent'
),
],
true
);
$fieldDescriptors['categories'] = new DoctrineFieldDescriptor(
'id',
'categories',
static::$productEntityName . 'Categories',
'products.categories',
[
static::$productEntityName . 'Categories' => new DoctrineJoinDescriptor(
static::$productEntityName,
static::$productEntityName . '.categories'
),
],
true
);
$fieldDescriptors['attributes'] = new DoctrineFieldDescriptor(
'id',
'attributes',
static::$productEntityName . 'ProductAttributes',
'products.product-attributes',
[
static::$productEntityName . 'ProductAttributes' => new DoctrineJoinDescriptor(
static::$productEntityName,
static::$productEntityName . '.productAttributes'
),
],
true
);
return $fieldDescriptors;
}
|
php
|
public function getFilterFieldDescriptors()
{
$fieldDescriptors = [];
$fieldDescriptors['type_id'] = new DoctrineFieldDescriptor(
'id',
'type_id',
self::$productTypeEntityName,
null,
[
self::$productTypeEntityName => new DoctrineJoinDescriptor(
self::$productTypeEntityName,
static::$productEntityName . '.type'
),
]
);
$fieldDescriptors['status_id'] = new DoctrineFieldDescriptor(
'id',
'status_id',
self::$productStatusEntityName,
null,
[
self::$productStatusEntityName => new DoctrineJoinDescriptor(
self::$productStatusEntityName,
static::$productEntityName . '.status'
),
]
);
$fieldDescriptors['accounts_supplier_id'] = new DoctrineFieldDescriptor(
'id',
'supplier_id',
self::$accountsSupplierEntityName,
null,
[
self::$accountsSupplierEntityName => new DoctrineJoinDescriptor(
self::$accountsSupplierEntityName,
static::$productEntityName . '.supplier'
),
]
);
$fieldDescriptors['is_deprecated'] = new DoctrineFieldDescriptor(
'isDeprecated',
'is_deprecated',
static::$productEntityName,
null,
[]
);
$fieldDescriptors['parent'] = new DoctrineFieldDescriptor(
'id',
'parent',
static::$productEntityName . 'Parent',
'product.parent',
[
static::$productEntityName . 'Parent' => new DoctrineJoinDescriptor(
static::$productEntityName,
static::$productEntityName . '.parent'
),
],
true
);
$fieldDescriptors['categories'] = new DoctrineFieldDescriptor(
'id',
'categories',
static::$productEntityName . 'Categories',
'products.categories',
[
static::$productEntityName . 'Categories' => new DoctrineJoinDescriptor(
static::$productEntityName,
static::$productEntityName . '.categories'
),
],
true
);
$fieldDescriptors['attributes'] = new DoctrineFieldDescriptor(
'id',
'attributes',
static::$productEntityName . 'ProductAttributes',
'products.product-attributes',
[
static::$productEntityName . 'ProductAttributes' => new DoctrineJoinDescriptor(
static::$productEntityName,
static::$productEntityName . '.productAttributes'
),
],
true
);
return $fieldDescriptors;
}
|
[
"public",
"function",
"getFilterFieldDescriptors",
"(",
")",
"{",
"$",
"fieldDescriptors",
"=",
"[",
"]",
";",
"$",
"fieldDescriptors",
"[",
"'type_id'",
"]",
"=",
"new",
"DoctrineFieldDescriptor",
"(",
"'id'",
",",
"'type_id'",
",",
"self",
"::",
"$",
"productTypeEntityName",
",",
"null",
",",
"[",
"self",
"::",
"$",
"productTypeEntityName",
"=>",
"new",
"DoctrineJoinDescriptor",
"(",
"self",
"::",
"$",
"productTypeEntityName",
",",
"static",
"::",
"$",
"productEntityName",
".",
"'.type'",
")",
",",
"]",
")",
";",
"$",
"fieldDescriptors",
"[",
"'status_id'",
"]",
"=",
"new",
"DoctrineFieldDescriptor",
"(",
"'id'",
",",
"'status_id'",
",",
"self",
"::",
"$",
"productStatusEntityName",
",",
"null",
",",
"[",
"self",
"::",
"$",
"productStatusEntityName",
"=>",
"new",
"DoctrineJoinDescriptor",
"(",
"self",
"::",
"$",
"productStatusEntityName",
",",
"static",
"::",
"$",
"productEntityName",
".",
"'.status'",
")",
",",
"]",
")",
";",
"$",
"fieldDescriptors",
"[",
"'accounts_supplier_id'",
"]",
"=",
"new",
"DoctrineFieldDescriptor",
"(",
"'id'",
",",
"'supplier_id'",
",",
"self",
"::",
"$",
"accountsSupplierEntityName",
",",
"null",
",",
"[",
"self",
"::",
"$",
"accountsSupplierEntityName",
"=>",
"new",
"DoctrineJoinDescriptor",
"(",
"self",
"::",
"$",
"accountsSupplierEntityName",
",",
"static",
"::",
"$",
"productEntityName",
".",
"'.supplier'",
")",
",",
"]",
")",
";",
"$",
"fieldDescriptors",
"[",
"'is_deprecated'",
"]",
"=",
"new",
"DoctrineFieldDescriptor",
"(",
"'isDeprecated'",
",",
"'is_deprecated'",
",",
"static",
"::",
"$",
"productEntityName",
",",
"null",
",",
"[",
"]",
")",
";",
"$",
"fieldDescriptors",
"[",
"'parent'",
"]",
"=",
"new",
"DoctrineFieldDescriptor",
"(",
"'id'",
",",
"'parent'",
",",
"static",
"::",
"$",
"productEntityName",
".",
"'Parent'",
",",
"'product.parent'",
",",
"[",
"static",
"::",
"$",
"productEntityName",
".",
"'Parent'",
"=>",
"new",
"DoctrineJoinDescriptor",
"(",
"static",
"::",
"$",
"productEntityName",
",",
"static",
"::",
"$",
"productEntityName",
".",
"'.parent'",
")",
",",
"]",
",",
"true",
")",
";",
"$",
"fieldDescriptors",
"[",
"'categories'",
"]",
"=",
"new",
"DoctrineFieldDescriptor",
"(",
"'id'",
",",
"'categories'",
",",
"static",
"::",
"$",
"productEntityName",
".",
"'Categories'",
",",
"'products.categories'",
",",
"[",
"static",
"::",
"$",
"productEntityName",
".",
"'Categories'",
"=>",
"new",
"DoctrineJoinDescriptor",
"(",
"static",
"::",
"$",
"productEntityName",
",",
"static",
"::",
"$",
"productEntityName",
".",
"'.categories'",
")",
",",
"]",
",",
"true",
")",
";",
"$",
"fieldDescriptors",
"[",
"'attributes'",
"]",
"=",
"new",
"DoctrineFieldDescriptor",
"(",
"'id'",
",",
"'attributes'",
",",
"static",
"::",
"$",
"productEntityName",
".",
"'ProductAttributes'",
",",
"'products.product-attributes'",
",",
"[",
"static",
"::",
"$",
"productEntityName",
".",
"'ProductAttributes'",
"=>",
"new",
"DoctrineJoinDescriptor",
"(",
"static",
"::",
"$",
"productEntityName",
",",
"static",
"::",
"$",
"productEntityName",
".",
"'.productAttributes'",
")",
",",
"]",
",",
"true",
")",
";",
"return",
"$",
"fieldDescriptors",
";",
"}"
] |
Returns a list of fieldDescriptors just used for filtering.
@return DoctrineFieldDescriptor[]
|
[
"Returns",
"a",
"list",
"of",
"fieldDescriptors",
"just",
"used",
"for",
"filtering",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductManager.php#L276-L370
|
224,227
|
sulu/SuluProductBundle
|
Product/ProductManager.php
|
ProductManager.createProductMedia
|
public function createProductMedia(ApiProductInterface $product, $locale)
{
$media = [];
// We have to replace the media with a media obtained from the mediaManager since the urls and the
// dimensions are added by the mediaManager.
// TODO: implement proxy object who is responsible for generating the urls
foreach ($product->getEntity()->getMedia() as $medium) {
$media[] = $this->mediaManager->getById($medium->getId(), $locale);
}
$product->setMedia($media);
}
|
php
|
public function createProductMedia(ApiProductInterface $product, $locale)
{
$media = [];
// We have to replace the media with a media obtained from the mediaManager since the urls and the
// dimensions are added by the mediaManager.
// TODO: implement proxy object who is responsible for generating the urls
foreach ($product->getEntity()->getMedia() as $medium) {
$media[] = $this->mediaManager->getById($medium->getId(), $locale);
}
$product->setMedia($media);
}
|
[
"public",
"function",
"createProductMedia",
"(",
"ApiProductInterface",
"$",
"product",
",",
"$",
"locale",
")",
"{",
"$",
"media",
"=",
"[",
"]",
";",
"// We have to replace the media with a media obtained from the mediaManager since the urls and the",
"// dimensions are added by the mediaManager.",
"// TODO: implement proxy object who is responsible for generating the urls",
"foreach",
"(",
"$",
"product",
"->",
"getEntity",
"(",
")",
"->",
"getMedia",
"(",
")",
"as",
"$",
"medium",
")",
"{",
"$",
"media",
"[",
"]",
"=",
"$",
"this",
"->",
"mediaManager",
"->",
"getById",
"(",
"$",
"medium",
"->",
"getId",
"(",
")",
",",
"$",
"locale",
")",
";",
"}",
"$",
"product",
"->",
"setMedia",
"(",
"$",
"media",
")",
";",
"}"
] |
Sets product media for api-product
Otherwise api-media will not contain additional info like url,..
@param ApiProductInterface $product
@param string $locale
|
[
"Sets",
"product",
"media",
"for",
"api",
"-",
"product",
"Otherwise",
"api",
"-",
"media",
"will",
"not",
"contain",
"additional",
"info",
"like",
"url",
".."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductManager.php#L754-L764
|
224,228
|
sulu/SuluProductBundle
|
Product/ProductManager.php
|
ProductManager.findAllByIdsAndLocale
|
public function findAllByIdsAndLocale($locale, $ids = '')
{
$products = $this->productRepository->findByLocaleAndIds($locale, explode(',', $ids));
if ($products) {
array_walk(
$products,
function (&$product) use ($locale) {
$product = $this->productFactory->createApiEntity($product, $locale);
}
);
}
return $products;
}
|
php
|
public function findAllByIdsAndLocale($locale, $ids = '')
{
$products = $this->productRepository->findByLocaleAndIds($locale, explode(',', $ids));
if ($products) {
array_walk(
$products,
function (&$product) use ($locale) {
$product = $this->productFactory->createApiEntity($product, $locale);
}
);
}
return $products;
}
|
[
"public",
"function",
"findAllByIdsAndLocale",
"(",
"$",
"locale",
",",
"$",
"ids",
"=",
"''",
")",
"{",
"$",
"products",
"=",
"$",
"this",
"->",
"productRepository",
"->",
"findByLocaleAndIds",
"(",
"$",
"locale",
",",
"explode",
"(",
"','",
",",
"$",
"ids",
")",
")",
";",
"if",
"(",
"$",
"products",
")",
"{",
"array_walk",
"(",
"$",
"products",
",",
"function",
"(",
"&",
"$",
"product",
")",
"use",
"(",
"$",
"locale",
")",
"{",
"$",
"product",
"=",
"$",
"this",
"->",
"productFactory",
"->",
"createApiEntity",
"(",
"$",
"product",
",",
"$",
"locale",
")",
";",
"}",
")",
";",
"}",
"return",
"$",
"products",
";",
"}"
] |
Finds all elements with one of the ids.
@param string $locale
@param string $ids
@return \Sulu\Bundle\ProductBundle\Api\Product[]
|
[
"Finds",
"all",
"elements",
"with",
"one",
"of",
"the",
"ids",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductManager.php#L774-L788
|
224,229
|
sulu/SuluProductBundle
|
Product/ProductManager.php
|
ProductManager.findByLocaleAndInternalItemNumber
|
public function findByLocaleAndInternalItemNumber($locale, $internalItemNumber)
{
$products = $this->productRepository->findByLocaleAndInternalItemNumber(
$locale,
$internalItemNumber
);
if ($products) {
array_walk(
$products,
function (&$product) use ($locale) {
$product = $this->productFactory->createApiEntity($product, $locale);
}
);
}
return $products;
}
|
php
|
public function findByLocaleAndInternalItemNumber($locale, $internalItemNumber)
{
$products = $this->productRepository->findByLocaleAndInternalItemNumber(
$locale,
$internalItemNumber
);
if ($products) {
array_walk(
$products,
function (&$product) use ($locale) {
$product = $this->productFactory->createApiEntity($product, $locale);
}
);
}
return $products;
}
|
[
"public",
"function",
"findByLocaleAndInternalItemNumber",
"(",
"$",
"locale",
",",
"$",
"internalItemNumber",
")",
"{",
"$",
"products",
"=",
"$",
"this",
"->",
"productRepository",
"->",
"findByLocaleAndInternalItemNumber",
"(",
"$",
"locale",
",",
"$",
"internalItemNumber",
")",
";",
"if",
"(",
"$",
"products",
")",
"{",
"array_walk",
"(",
"$",
"products",
",",
"function",
"(",
"&",
"$",
"product",
")",
"use",
"(",
"$",
"locale",
")",
"{",
"$",
"product",
"=",
"$",
"this",
"->",
"productFactory",
"->",
"createApiEntity",
"(",
"$",
"product",
",",
"$",
"locale",
")",
";",
"}",
")",
";",
"}",
"return",
"$",
"products",
";",
"}"
] |
Returns all simple products in the given locale for the given number.
@param string $locale The locale of the product to load
@param $internalItemNumber
@return ProductInterface[]
|
[
"Returns",
"all",
"simple",
"products",
"in",
"the",
"given",
"locale",
"for",
"the",
"given",
"number",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductManager.php#L869-L885
|
224,230
|
sulu/SuluProductBundle
|
Product/ProductManager.php
|
ProductManager.fetchProduct
|
protected function fetchProduct($id, $locale)
{
$product = $this->productRepository->findByIdAndLocale($id, $locale);
if (!$product) {
throw new ProductNotFoundException($id);
}
return $this->productFactory->createApiEntity($product, $locale);
}
|
php
|
protected function fetchProduct($id, $locale)
{
$product = $this->productRepository->findByIdAndLocale($id, $locale);
if (!$product) {
throw new ProductNotFoundException($id);
}
return $this->productFactory->createApiEntity($product, $locale);
}
|
[
"protected",
"function",
"fetchProduct",
"(",
"$",
"id",
",",
"$",
"locale",
")",
"{",
"$",
"product",
"=",
"$",
"this",
"->",
"productRepository",
"->",
"findByIdAndLocale",
"(",
"$",
"id",
",",
"$",
"locale",
")",
";",
"if",
"(",
"!",
"$",
"product",
")",
"{",
"throw",
"new",
"ProductNotFoundException",
"(",
"$",
"id",
")",
";",
"}",
"return",
"$",
"this",
"->",
"productFactory",
"->",
"createApiEntity",
"(",
"$",
"product",
",",
"$",
"locale",
")",
";",
"}"
] |
Fetches a product.
@param int $id
@param string $locale
@throws ProductNotFoundException
@return ApiProductInterface
|
[
"Fetches",
"a",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductManager.php#L969-L978
|
224,231
|
sulu/SuluProductBundle
|
Product/ProductManager.php
|
ProductManager.checkDateString
|
private function checkDateString($dateTimeString)
{
if (empty($dateTimeString)) {
return null;
}
try {
$date = new \DateTime($dateTimeString);
} catch (Exception $e) {
return null;
}
return $date;
}
|
php
|
private function checkDateString($dateTimeString)
{
if (empty($dateTimeString)) {
return null;
}
try {
$date = new \DateTime($dateTimeString);
} catch (Exception $e) {
return null;
}
return $date;
}
|
[
"private",
"function",
"checkDateString",
"(",
"$",
"dateTimeString",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"dateTimeString",
")",
")",
"{",
"return",
"null",
";",
"}",
"try",
"{",
"$",
"date",
"=",
"new",
"\\",
"DateTime",
"(",
"$",
"dateTimeString",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"date",
";",
"}"
] |
Checks if datetime string is valid.
@param string $dateTimeString
@return DateTime
|
[
"Checks",
"if",
"datetime",
"string",
"is",
"valid",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductManager.php#L1001-L1014
|
224,232
|
sulu/SuluProductBundle
|
Product/ProductManager.php
|
ProductManager.copyDataFromChangedToActiveProduct
|
public function copyDataFromChangedToActiveProduct(
ProductInterface $changedProduct,
ProductInterface $activeProduct
) {
// copy all data from changed to active product to ensure
// that products id does not change
$this->convertProduct($changedProduct, $activeProduct);
// remove deprecated state
$activeProduct->setIsDeprecated(false);
}
|
php
|
public function copyDataFromChangedToActiveProduct(
ProductInterface $changedProduct,
ProductInterface $activeProduct
) {
// copy all data from changed to active product to ensure
// that products id does not change
$this->convertProduct($changedProduct, $activeProduct);
// remove deprecated state
$activeProduct->setIsDeprecated(false);
}
|
[
"public",
"function",
"copyDataFromChangedToActiveProduct",
"(",
"ProductInterface",
"$",
"changedProduct",
",",
"ProductInterface",
"$",
"activeProduct",
")",
"{",
"// copy all data from changed to active product to ensure",
"// that products id does not change",
"$",
"this",
"->",
"convertProduct",
"(",
"$",
"changedProduct",
",",
"$",
"activeProduct",
")",
";",
"// remove deprecated state",
"$",
"activeProduct",
"->",
"setIsDeprecated",
"(",
"false",
")",
";",
"}"
] |
Copies all data from a changed product to an active one and
unsets deprecated state of active product.
@param ProductInterface $changedProduct
@param ProductInterface $activeProduct
|
[
"Copies",
"all",
"data",
"from",
"a",
"changed",
"product",
"to",
"an",
"active",
"one",
"and",
"unsets",
"deprecated",
"state",
"of",
"active",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductManager.php#L1023-L1033
|
224,233
|
sulu/SuluProductBundle
|
Product/ProductManager.php
|
ProductManager.parseCommaSeparatedString
|
public function parseCommaSeparatedString($string, $maxLength = self::MAX_SEARCH_TERMS_LENGTH)
{
$result = null;
// Check if string is not empty.
if (strlen(trim($string)) === 0) {
return null;
}
// Lower case for case insensitivity.
$string = mb_strtolower($string, 'UTF-8');
// Convert string to array.
$fields = explode(',', $string);
// Validate and trim each field.
$fields = array_map([$this, 'trimAndValidateField'], $fields);
// Remove null entries.
$fields = array_filter($fields);
// Parse back into string.
$result = implode(',', $fields);
// Check if max length is exceeded.
if (strlen($result) > $maxLength) {
// Shorten to max-length.
$result = substr($result, 0, $maxLength);
$fields = explode(',', $result);
// Remove last element.
array_pop($fields);
// Only one search field is provided and exceeds limit.
if (count($fields) === 0) {
return null;
}
// Parse back into string.
$result = implode(',', $fields);
}
return $result;
}
|
php
|
public function parseCommaSeparatedString($string, $maxLength = self::MAX_SEARCH_TERMS_LENGTH)
{
$result = null;
// Check if string is not empty.
if (strlen(trim($string)) === 0) {
return null;
}
// Lower case for case insensitivity.
$string = mb_strtolower($string, 'UTF-8');
// Convert string to array.
$fields = explode(',', $string);
// Validate and trim each field.
$fields = array_map([$this, 'trimAndValidateField'], $fields);
// Remove null entries.
$fields = array_filter($fields);
// Parse back into string.
$result = implode(',', $fields);
// Check if max length is exceeded.
if (strlen($result) > $maxLength) {
// Shorten to max-length.
$result = substr($result, 0, $maxLength);
$fields = explode(',', $result);
// Remove last element.
array_pop($fields);
// Only one search field is provided and exceeds limit.
if (count($fields) === 0) {
return null;
}
// Parse back into string.
$result = implode(',', $fields);
}
return $result;
}
|
[
"public",
"function",
"parseCommaSeparatedString",
"(",
"$",
"string",
",",
"$",
"maxLength",
"=",
"self",
"::",
"MAX_SEARCH_TERMS_LENGTH",
")",
"{",
"$",
"result",
"=",
"null",
";",
"// Check if string is not empty.",
"if",
"(",
"strlen",
"(",
"trim",
"(",
"$",
"string",
")",
")",
"===",
"0",
")",
"{",
"return",
"null",
";",
"}",
"// Lower case for case insensitivity.",
"$",
"string",
"=",
"mb_strtolower",
"(",
"$",
"string",
",",
"'UTF-8'",
")",
";",
"// Convert string to array.",
"$",
"fields",
"=",
"explode",
"(",
"','",
",",
"$",
"string",
")",
";",
"// Validate and trim each field.",
"$",
"fields",
"=",
"array_map",
"(",
"[",
"$",
"this",
",",
"'trimAndValidateField'",
"]",
",",
"$",
"fields",
")",
";",
"// Remove null entries.",
"$",
"fields",
"=",
"array_filter",
"(",
"$",
"fields",
")",
";",
"// Parse back into string.",
"$",
"result",
"=",
"implode",
"(",
"','",
",",
"$",
"fields",
")",
";",
"// Check if max length is exceeded.",
"if",
"(",
"strlen",
"(",
"$",
"result",
")",
">",
"$",
"maxLength",
")",
"{",
"// Shorten to max-length.",
"$",
"result",
"=",
"substr",
"(",
"$",
"result",
",",
"0",
",",
"$",
"maxLength",
")",
";",
"$",
"fields",
"=",
"explode",
"(",
"','",
",",
"$",
"result",
")",
";",
"// Remove last element.",
"array_pop",
"(",
"$",
"fields",
")",
";",
"// Only one search field is provided and exceeds limit.",
"if",
"(",
"count",
"(",
"$",
"fields",
")",
"===",
"0",
")",
"{",
"return",
"null",
";",
"}",
"// Parse back into string.",
"$",
"result",
"=",
"implode",
"(",
"','",
",",
"$",
"fields",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Parses a comma separated string.
Trims all values and removes empty strings.
@param string $string
@param int $maxLength
@return null|string
|
[
"Parses",
"a",
"comma",
"separated",
"string",
".",
"Trims",
"all",
"values",
"and",
"removes",
"empty",
"strings",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductManager.php#L1451-L1495
|
224,234
|
sulu/SuluProductBundle
|
Product/ProductManager.php
|
ProductManager.priceHasChanged
|
private function priceHasChanged($data, $price)
{
$currencyNotChanged = isset($data['currency']) &&
array_key_exists('name', $data['currency']) &&
$data['currency']['name'] == $price->getCurrency()->getName();
$valueNotChanged = array_key_exists('price', $data) &&
$data['price'] == $price->getPrice();
$minimumQuantityNotChanged = array_key_exists('minimumQuantity', $data) &&
$data['minimumQuantity'] == $price->getEntity()->getMinimumQuantity();
return $currencyNotChanged && $valueNotChanged && $minimumQuantityNotChanged;
}
|
php
|
private function priceHasChanged($data, $price)
{
$currencyNotChanged = isset($data['currency']) &&
array_key_exists('name', $data['currency']) &&
$data['currency']['name'] == $price->getCurrency()->getName();
$valueNotChanged = array_key_exists('price', $data) &&
$data['price'] == $price->getPrice();
$minimumQuantityNotChanged = array_key_exists('minimumQuantity', $data) &&
$data['minimumQuantity'] == $price->getEntity()->getMinimumQuantity();
return $currencyNotChanged && $valueNotChanged && $minimumQuantityNotChanged;
}
|
[
"private",
"function",
"priceHasChanged",
"(",
"$",
"data",
",",
"$",
"price",
")",
"{",
"$",
"currencyNotChanged",
"=",
"isset",
"(",
"$",
"data",
"[",
"'currency'",
"]",
")",
"&&",
"array_key_exists",
"(",
"'name'",
",",
"$",
"data",
"[",
"'currency'",
"]",
")",
"&&",
"$",
"data",
"[",
"'currency'",
"]",
"[",
"'name'",
"]",
"==",
"$",
"price",
"->",
"getCurrency",
"(",
")",
"->",
"getName",
"(",
")",
";",
"$",
"valueNotChanged",
"=",
"array_key_exists",
"(",
"'price'",
",",
"$",
"data",
")",
"&&",
"$",
"data",
"[",
"'price'",
"]",
"==",
"$",
"price",
"->",
"getPrice",
"(",
")",
";",
"$",
"minimumQuantityNotChanged",
"=",
"array_key_exists",
"(",
"'minimumQuantity'",
",",
"$",
"data",
")",
"&&",
"$",
"data",
"[",
"'minimumQuantity'",
"]",
"==",
"$",
"price",
"->",
"getEntity",
"(",
")",
"->",
"getMinimumQuantity",
"(",
")",
";",
"return",
"$",
"currencyNotChanged",
"&&",
"$",
"valueNotChanged",
"&&",
"$",
"minimumQuantityNotChanged",
";",
"}"
] |
Checks if price of a product has changed.
@param array $data
@param float $price
@return bool
|
[
"Checks",
"if",
"price",
"of",
"a",
"product",
"has",
"changed",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductManager.php#L1505-L1518
|
224,235
|
sulu/SuluProductBundle
|
Product/ProductManager.php
|
ProductManager.getExistingActiveOrInactiveProduct
|
protected function getExistingActiveOrInactiveProduct($existingProduct, $statusId, $locale)
{
if (($statusId == StatusEntity::ACTIVE || $statusId == StatusEntity::INACTIVE)
&& $existingProduct->getStatus()->getId() != $statusId
) {
// Check if the same product already exists in IMPORTED state.
$products = $this->productRepository->findByLocaleAndInternalItemNumber(
$locale,
$existingProduct->getInternalItemNumber()
);
foreach ($products as $product) {
if ($product->isDeprecated() && $existingProduct->getId() != $product->getId()) {
$product->setIsDeprecated(false);
return $this->productFactory->createApiEntity($product, $locale);
}
}
}
return null;
}
|
php
|
protected function getExistingActiveOrInactiveProduct($existingProduct, $statusId, $locale)
{
if (($statusId == StatusEntity::ACTIVE || $statusId == StatusEntity::INACTIVE)
&& $existingProduct->getStatus()->getId() != $statusId
) {
// Check if the same product already exists in IMPORTED state.
$products = $this->productRepository->findByLocaleAndInternalItemNumber(
$locale,
$existingProduct->getInternalItemNumber()
);
foreach ($products as $product) {
if ($product->isDeprecated() && $existingProduct->getId() != $product->getId()) {
$product->setIsDeprecated(false);
return $this->productFactory->createApiEntity($product, $locale);
}
}
}
return null;
}
|
[
"protected",
"function",
"getExistingActiveOrInactiveProduct",
"(",
"$",
"existingProduct",
",",
"$",
"statusId",
",",
"$",
"locale",
")",
"{",
"if",
"(",
"(",
"$",
"statusId",
"==",
"StatusEntity",
"::",
"ACTIVE",
"||",
"$",
"statusId",
"==",
"StatusEntity",
"::",
"INACTIVE",
")",
"&&",
"$",
"existingProduct",
"->",
"getStatus",
"(",
")",
"->",
"getId",
"(",
")",
"!=",
"$",
"statusId",
")",
"{",
"// Check if the same product already exists in IMPORTED state.",
"$",
"products",
"=",
"$",
"this",
"->",
"productRepository",
"->",
"findByLocaleAndInternalItemNumber",
"(",
"$",
"locale",
",",
"$",
"existingProduct",
"->",
"getInternalItemNumber",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"products",
"as",
"$",
"product",
")",
"{",
"if",
"(",
"$",
"product",
"->",
"isDeprecated",
"(",
")",
"&&",
"$",
"existingProduct",
"->",
"getId",
"(",
")",
"!=",
"$",
"product",
"->",
"getId",
"(",
")",
")",
"{",
"$",
"product",
"->",
"setIsDeprecated",
"(",
"false",
")",
";",
"return",
"$",
"this",
"->",
"productFactory",
"->",
"createApiEntity",
"(",
"$",
"product",
",",
"$",
"locale",
")",
";",
"}",
"}",
"}",
"return",
"null",
";",
"}"
] |
Checks if a product with the same internal product id as the given product exists in published state and
returns it.
@param Product $existingProduct
@param int $statusId
@param string $locale
@return null|\Sulu\Bundle\ProductBundle\Api\Product
|
[
"Checks",
"if",
"a",
"product",
"with",
"the",
"same",
"internal",
"product",
"id",
"as",
"the",
"given",
"product",
"exists",
"in",
"published",
"state",
"and",
"returns",
"it",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductManager.php#L1703-L1723
|
224,236
|
sulu/SuluProductBundle
|
Product/ProductManager.php
|
ProductManager.setStatusForProduct
|
public function setStatusForProduct(ProductInterface $product, $statusId)
{
// Check if status has changed.
if ($product->getStatus() && $product->getStatus()->getId() === $statusId) {
return;
}
$status = $this->statusRepository->find($statusId);
if (!$status) {
throw new ProductDependencyNotFoundException(self::$productStatusEntityName, $statusId);
}
// Set new status to product.
$product->setStatus($status);
// If product has variants, set status for all variants as well.
if ($product->getType()
&& $product->getType()->getId() === (int) $this->productTypesMap['PRODUCT_WITH_VARIANTS']
) {
$variants = $this->productRepository->findByParent($product);
foreach ($variants as $variant) {
$variant->setStatus($status);
}
}
}
|
php
|
public function setStatusForProduct(ProductInterface $product, $statusId)
{
// Check if status has changed.
if ($product->getStatus() && $product->getStatus()->getId() === $statusId) {
return;
}
$status = $this->statusRepository->find($statusId);
if (!$status) {
throw new ProductDependencyNotFoundException(self::$productStatusEntityName, $statusId);
}
// Set new status to product.
$product->setStatus($status);
// If product has variants, set status for all variants as well.
if ($product->getType()
&& $product->getType()->getId() === (int) $this->productTypesMap['PRODUCT_WITH_VARIANTS']
) {
$variants = $this->productRepository->findByParent($product);
foreach ($variants as $variant) {
$variant->setStatus($status);
}
}
}
|
[
"public",
"function",
"setStatusForProduct",
"(",
"ProductInterface",
"$",
"product",
",",
"$",
"statusId",
")",
"{",
"// Check if status has changed.",
"if",
"(",
"$",
"product",
"->",
"getStatus",
"(",
")",
"&&",
"$",
"product",
"->",
"getStatus",
"(",
")",
"->",
"getId",
"(",
")",
"===",
"$",
"statusId",
")",
"{",
"return",
";",
"}",
"$",
"status",
"=",
"$",
"this",
"->",
"statusRepository",
"->",
"find",
"(",
"$",
"statusId",
")",
";",
"if",
"(",
"!",
"$",
"status",
")",
"{",
"throw",
"new",
"ProductDependencyNotFoundException",
"(",
"self",
"::",
"$",
"productStatusEntityName",
",",
"$",
"statusId",
")",
";",
"}",
"// Set new status to product.",
"$",
"product",
"->",
"setStatus",
"(",
"$",
"status",
")",
";",
"// If product has variants, set status for all variants as well.",
"if",
"(",
"$",
"product",
"->",
"getType",
"(",
")",
"&&",
"$",
"product",
"->",
"getType",
"(",
")",
"->",
"getId",
"(",
")",
"===",
"(",
"int",
")",
"$",
"this",
"->",
"productTypesMap",
"[",
"'PRODUCT_WITH_VARIANTS'",
"]",
")",
"{",
"$",
"variants",
"=",
"$",
"this",
"->",
"productRepository",
"->",
"findByParent",
"(",
"$",
"product",
")",
";",
"foreach",
"(",
"$",
"variants",
"as",
"$",
"variant",
")",
"{",
"$",
"variant",
"->",
"setStatus",
"(",
"$",
"status",
")",
";",
"}",
"}",
"}"
] |
Sets the status for a given product.
@param ProductInterface $product
@param int $statusId
@throws ProductDependencyNotFoundException
|
[
"Sets",
"the",
"status",
"for",
"a",
"given",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductManager.php#L1733-L1757
|
224,237
|
sulu/SuluProductBundle
|
Product/ProductManager.php
|
ProductManager.setDeliveryStatusForProduct
|
public function setDeliveryStatusForProduct($product, $statusId)
{
$status = $this->deliveryStatusRepository->find($statusId);
if (!$status) {
throw new ProductDependencyNotFoundException(self::$productStatusEntityName, $statusId);
}
$product->setDeliveryStatus($status);
}
|
php
|
public function setDeliveryStatusForProduct($product, $statusId)
{
$status = $this->deliveryStatusRepository->find($statusId);
if (!$status) {
throw new ProductDependencyNotFoundException(self::$productStatusEntityName, $statusId);
}
$product->setDeliveryStatus($status);
}
|
[
"public",
"function",
"setDeliveryStatusForProduct",
"(",
"$",
"product",
",",
"$",
"statusId",
")",
"{",
"$",
"status",
"=",
"$",
"this",
"->",
"deliveryStatusRepository",
"->",
"find",
"(",
"$",
"statusId",
")",
";",
"if",
"(",
"!",
"$",
"status",
")",
"{",
"throw",
"new",
"ProductDependencyNotFoundException",
"(",
"self",
"::",
"$",
"productStatusEntityName",
",",
"$",
"statusId",
")",
";",
"}",
"$",
"product",
"->",
"setDeliveryStatus",
"(",
"$",
"status",
")",
";",
"}"
] |
Sets the deliveryStatus for a given product.
@param Product $product
@param int $statusId
@throws ProductDependencyNotFoundException
|
[
"Sets",
"the",
"deliveryStatus",
"for",
"a",
"given",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductManager.php#L1767-L1774
|
224,238
|
sulu/SuluProductBundle
|
Product/ProductManager.php
|
ProductManager.updatePrice
|
protected function updatePrice(ProductPrice $price, $matchedEntry)
{
if (isset($matchedEntry['minimumQuantity'])) {
$price->getEntity()->setMinimumQuantity($matchedEntry['minimumQuantity']);
}
if (isset($matchedEntry['price'])) {
$price->setPrice($matchedEntry['price']);
}
if (isset($matchedEntry['priceInfo'])) {
$price->getEntity()->setPriceInfo($matchedEntry['priceInfo']);
}
if (isset($matchedEntry['currency'])) {
$currency = $this->currencyRepository->find($matchedEntry['currency']['id']);
if (!$currency) {
throw new ProductDependencyNotFoundException(
self::$productPriceEntityName,
$matchedEntry['currency']['id']
);
}
$price->getEntity()->setCurrency($currency);
}
return true;
}
|
php
|
protected function updatePrice(ProductPrice $price, $matchedEntry)
{
if (isset($matchedEntry['minimumQuantity'])) {
$price->getEntity()->setMinimumQuantity($matchedEntry['minimumQuantity']);
}
if (isset($matchedEntry['price'])) {
$price->setPrice($matchedEntry['price']);
}
if (isset($matchedEntry['priceInfo'])) {
$price->getEntity()->setPriceInfo($matchedEntry['priceInfo']);
}
if (isset($matchedEntry['currency'])) {
$currency = $this->currencyRepository->find($matchedEntry['currency']['id']);
if (!$currency) {
throw new ProductDependencyNotFoundException(
self::$productPriceEntityName,
$matchedEntry['currency']['id']
);
}
$price->getEntity()->setCurrency($currency);
}
return true;
}
|
[
"protected",
"function",
"updatePrice",
"(",
"ProductPrice",
"$",
"price",
",",
"$",
"matchedEntry",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"matchedEntry",
"[",
"'minimumQuantity'",
"]",
")",
")",
"{",
"$",
"price",
"->",
"getEntity",
"(",
")",
"->",
"setMinimumQuantity",
"(",
"$",
"matchedEntry",
"[",
"'minimumQuantity'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"matchedEntry",
"[",
"'price'",
"]",
")",
")",
"{",
"$",
"price",
"->",
"setPrice",
"(",
"$",
"matchedEntry",
"[",
"'price'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"matchedEntry",
"[",
"'priceInfo'",
"]",
")",
")",
"{",
"$",
"price",
"->",
"getEntity",
"(",
")",
"->",
"setPriceInfo",
"(",
"$",
"matchedEntry",
"[",
"'priceInfo'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"matchedEntry",
"[",
"'currency'",
"]",
")",
")",
"{",
"$",
"currency",
"=",
"$",
"this",
"->",
"currencyRepository",
"->",
"find",
"(",
"$",
"matchedEntry",
"[",
"'currency'",
"]",
"[",
"'id'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"currency",
")",
"{",
"throw",
"new",
"ProductDependencyNotFoundException",
"(",
"self",
"::",
"$",
"productPriceEntityName",
",",
"$",
"matchedEntry",
"[",
"'currency'",
"]",
"[",
"'id'",
"]",
")",
";",
"}",
"$",
"price",
"->",
"getEntity",
"(",
")",
"->",
"setCurrency",
"(",
"$",
"currency",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Updates the given price with the values from the given array.
@param ProductPrice $price
@param array $matchedEntry
@throws ProductDependencyNotFoundException
@return bool
|
[
"Updates",
"the",
"given",
"price",
"with",
"the",
"values",
"from",
"the",
"given",
"array",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductManager.php#L1786-L1809
|
224,239
|
sulu/SuluProductBundle
|
Product/ProductManager.php
|
ProductManager.addPrice
|
protected function addPrice(ProductInterface $product, $priceData)
{
if (isset($priceData['id'])) {
throw new EntityIdAlreadySetException(self::$productPriceEntityName, $priceData['id']);
} elseif (isset($priceData['price'])) {
$currency = $this->currencyRepository->find($priceData['currency']['id']);
if (!$currency) {
throw new ProductDependencyNotFoundException(
self::$productPriceEntityName,
$priceData['currency']['id']
);
}
$price = new ProductPriceEntity();
$price->setPrice($priceData['price']);
$price->setProduct($product);
$price->setCurrency($currency);
if (isset($priceData['priceInfo'])) {
$price->setPriceInfo($priceData['priceInfo']);
}
if (isset($priceData['minimumQuantity'])) {
$price->setMinimumQuantity($priceData['minimumQuantity']);
}
$product->addPrice($price);
$this->em->persist($price);
}
return true;
}
|
php
|
protected function addPrice(ProductInterface $product, $priceData)
{
if (isset($priceData['id'])) {
throw new EntityIdAlreadySetException(self::$productPriceEntityName, $priceData['id']);
} elseif (isset($priceData['price'])) {
$currency = $this->currencyRepository->find($priceData['currency']['id']);
if (!$currency) {
throw new ProductDependencyNotFoundException(
self::$productPriceEntityName,
$priceData['currency']['id']
);
}
$price = new ProductPriceEntity();
$price->setPrice($priceData['price']);
$price->setProduct($product);
$price->setCurrency($currency);
if (isset($priceData['priceInfo'])) {
$price->setPriceInfo($priceData['priceInfo']);
}
if (isset($priceData['minimumQuantity'])) {
$price->setMinimumQuantity($priceData['minimumQuantity']);
}
$product->addPrice($price);
$this->em->persist($price);
}
return true;
}
|
[
"protected",
"function",
"addPrice",
"(",
"ProductInterface",
"$",
"product",
",",
"$",
"priceData",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"priceData",
"[",
"'id'",
"]",
")",
")",
"{",
"throw",
"new",
"EntityIdAlreadySetException",
"(",
"self",
"::",
"$",
"productPriceEntityName",
",",
"$",
"priceData",
"[",
"'id'",
"]",
")",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"priceData",
"[",
"'price'",
"]",
")",
")",
"{",
"$",
"currency",
"=",
"$",
"this",
"->",
"currencyRepository",
"->",
"find",
"(",
"$",
"priceData",
"[",
"'currency'",
"]",
"[",
"'id'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"currency",
")",
"{",
"throw",
"new",
"ProductDependencyNotFoundException",
"(",
"self",
"::",
"$",
"productPriceEntityName",
",",
"$",
"priceData",
"[",
"'currency'",
"]",
"[",
"'id'",
"]",
")",
";",
"}",
"$",
"price",
"=",
"new",
"ProductPriceEntity",
"(",
")",
";",
"$",
"price",
"->",
"setPrice",
"(",
"$",
"priceData",
"[",
"'price'",
"]",
")",
";",
"$",
"price",
"->",
"setProduct",
"(",
"$",
"product",
")",
";",
"$",
"price",
"->",
"setCurrency",
"(",
"$",
"currency",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"priceData",
"[",
"'priceInfo'",
"]",
")",
")",
"{",
"$",
"price",
"->",
"setPriceInfo",
"(",
"$",
"priceData",
"[",
"'priceInfo'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"priceData",
"[",
"'minimumQuantity'",
"]",
")",
")",
"{",
"$",
"price",
"->",
"setMinimumQuantity",
"(",
"$",
"priceData",
"[",
"'minimumQuantity'",
"]",
")",
";",
"}",
"$",
"product",
"->",
"addPrice",
"(",
"$",
"price",
")",
";",
"$",
"this",
"->",
"em",
"->",
"persist",
"(",
"$",
"price",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Adds a price to the given product.
@param ProductInterface $product The product to add the price to
@param array $priceData The array containing the data for the new price
@throws \Sulu\Component\Rest\Exception\EntityIdAlreadySetException
@throws ProductDependencyNotFoundException
@return bool
|
[
"Adds",
"a",
"price",
"to",
"the",
"given",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductManager.php#L1822-L1852
|
224,240
|
sulu/SuluProductBundle
|
Product/ProductManager.php
|
ProductManager.removePrice
|
protected function removePrice(ProductInterface $product, ProductPriceEntity $price)
{
$this->em->remove($price);
$product->removePrice($price);
return true;
}
|
php
|
protected function removePrice(ProductInterface $product, ProductPriceEntity $price)
{
$this->em->remove($price);
$product->removePrice($price);
return true;
}
|
[
"protected",
"function",
"removePrice",
"(",
"ProductInterface",
"$",
"product",
",",
"ProductPriceEntity",
"$",
"price",
")",
"{",
"$",
"this",
"->",
"em",
"->",
"remove",
"(",
"$",
"price",
")",
";",
"$",
"product",
"->",
"removePrice",
"(",
"$",
"price",
")",
";",
"return",
"true",
";",
"}"
] |
Removes a price from the given product.
@param ProductInterface $product
@param ProductPriceEntity $price
@return bool
|
[
"Removes",
"a",
"price",
"from",
"the",
"given",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductManager.php#L1862-L1868
|
224,241
|
sulu/SuluProductBundle
|
Product/ProductManager.php
|
ProductManager.addCategory
|
protected function addCategory(ProductInterface $product, $categoryData)
{
$category = $this->categoryRepository->find($categoryData['id']);
if (!$category) {
throw new ProductDependencyNotFoundException(
self::$categoryEntityName,
$categoryData['id']
);
}
$product->addCategory($category);
$this->em->persist($category);
return true;
}
|
php
|
protected function addCategory(ProductInterface $product, $categoryData)
{
$category = $this->categoryRepository->find($categoryData['id']);
if (!$category) {
throw new ProductDependencyNotFoundException(
self::$categoryEntityName,
$categoryData['id']
);
}
$product->addCategory($category);
$this->em->persist($category);
return true;
}
|
[
"protected",
"function",
"addCategory",
"(",
"ProductInterface",
"$",
"product",
",",
"$",
"categoryData",
")",
"{",
"$",
"category",
"=",
"$",
"this",
"->",
"categoryRepository",
"->",
"find",
"(",
"$",
"categoryData",
"[",
"'id'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"category",
")",
"{",
"throw",
"new",
"ProductDependencyNotFoundException",
"(",
"self",
"::",
"$",
"categoryEntityName",
",",
"$",
"categoryData",
"[",
"'id'",
"]",
")",
";",
"}",
"$",
"product",
"->",
"addCategory",
"(",
"$",
"category",
")",
";",
"$",
"this",
"->",
"em",
"->",
"persist",
"(",
"$",
"category",
")",
";",
"return",
"true",
";",
"}"
] |
Adds a category to the given product.
@param ProductInterface $product The product to add the price to
@param array $categoryData The array containing the data for the additional category
@throws \Sulu\Component\Rest\Exception\EntityIdAlreadySetException
@throws ProductDependencyNotFoundException
@return bool
|
[
"Adds",
"a",
"category",
"to",
"the",
"given",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductManager.php#L1881-L1897
|
224,242
|
sulu/SuluProductBundle
|
Product/ProductManager.php
|
ProductManager.processAttributes
|
protected function processAttributes(array $data, ProductInterface $product, $locale)
{
if (isset($data['attributes'])) {
// Create local array of all currently assigned attributes of product.
$productAttributes = [];
foreach ($product->getProductAttributes() as $productAttribute) {
$productAttributes[$productAttribute->getAttribute()->getId()] = $productAttribute;
}
// Save all attribute ids which are given in the request.
$attributeIdsInRequest = [];
// Add and change attributes.
foreach ($data['attributes'] as $attributeData) {
if (!isset($attributeData['attributeId'])) {
continue;
}
$attributeId = $attributeData['attributeId'];
$attributeIdsInRequest[$attributeId] = $attributeId;
// Check if a attributeValueName is provided, otherwise do nothing.
if (!array_key_exists('attributeValueName', $attributeData)) {
continue;
}
$attributeDataValueName = trim($attributeData['attributeValueName']);
// Get attributeValueLocale from request.
$attributeValueLocale = $locale;
if (isset($attributeData['attributeValueLocale'])) {
$attributeValueLocale = $attributeData['attributeValueLocale'];
}
// If attribute value is empty do not add.
if ('' === $attributeDataValueName || null === $attributeDataValueName) {
// If already set on product, remove attribute value translation.
if (array_key_exists($attributeId, $productAttributes)) {
/** @var ProductAttribute $productAttribute */
$productAttribute = $productAttributes[$attributeId];
// Remove attribute value translation from attribute value.
$this->productAttributeManager->removeAttributeValueTranslation(
$productAttribute->getAttributeValue(),
$attributeValueLocale
);
// If no more attribute value translation exists,
// remove the whole product attribute from the product.
if ($productAttribute->getAttributeValue()->getTranslations()->isEmpty()) {
$product->removeProductAttribute($productAttribute);
$this->em->remove($productAttribute);
}
}
continue;
}
// Product attribute does not exists.
if (!array_key_exists($attributeId, $productAttributes)) {
$attribute = $this->retrieveAttributeById($attributeId);
// Create new attribute value with translation.
$attributeValue = $this->productAttributeManager->createAttributeValue(
$attribute,
$attributeDataValueName,
$attributeValueLocale
);
// Create new product attribute.
$this->productAttributeManager->createProductAttribute($attribute, $product, $attributeValue);
} else {
// Product attribute exists.
/** @var ProductAttribute $productAttribute */
$productAttribute = $productAttributes[$attributeId];
$attributeValue = $productAttribute->getAttributeValue();
// Create translation in current locale.
$this->productAttributeManager->setOrCreateAttributeValueTranslation(
$attributeValue,
$attributeDataValueName,
$attributeValueLocale
);
}
}
// Delete attributes.
foreach ($productAttributes as $productAttribute) {
if (!array_key_exists($productAttribute->getAttribute()->getId(), $attributeIdsInRequest)) {
// Remove all attribute value translations from attribute value.
$this->productAttributeManager->removeAllAttributeValueTranslations(
$productAttribute->getAttributeValue()
);
// Remove attribute from product.
$product->removeProductAttribute($productAttribute);
$this->em->remove($productAttribute);
}
}
}
}
|
php
|
protected function processAttributes(array $data, ProductInterface $product, $locale)
{
if (isset($data['attributes'])) {
// Create local array of all currently assigned attributes of product.
$productAttributes = [];
foreach ($product->getProductAttributes() as $productAttribute) {
$productAttributes[$productAttribute->getAttribute()->getId()] = $productAttribute;
}
// Save all attribute ids which are given in the request.
$attributeIdsInRequest = [];
// Add and change attributes.
foreach ($data['attributes'] as $attributeData) {
if (!isset($attributeData['attributeId'])) {
continue;
}
$attributeId = $attributeData['attributeId'];
$attributeIdsInRequest[$attributeId] = $attributeId;
// Check if a attributeValueName is provided, otherwise do nothing.
if (!array_key_exists('attributeValueName', $attributeData)) {
continue;
}
$attributeDataValueName = trim($attributeData['attributeValueName']);
// Get attributeValueLocale from request.
$attributeValueLocale = $locale;
if (isset($attributeData['attributeValueLocale'])) {
$attributeValueLocale = $attributeData['attributeValueLocale'];
}
// If attribute value is empty do not add.
if ('' === $attributeDataValueName || null === $attributeDataValueName) {
// If already set on product, remove attribute value translation.
if (array_key_exists($attributeId, $productAttributes)) {
/** @var ProductAttribute $productAttribute */
$productAttribute = $productAttributes[$attributeId];
// Remove attribute value translation from attribute value.
$this->productAttributeManager->removeAttributeValueTranslation(
$productAttribute->getAttributeValue(),
$attributeValueLocale
);
// If no more attribute value translation exists,
// remove the whole product attribute from the product.
if ($productAttribute->getAttributeValue()->getTranslations()->isEmpty()) {
$product->removeProductAttribute($productAttribute);
$this->em->remove($productAttribute);
}
}
continue;
}
// Product attribute does not exists.
if (!array_key_exists($attributeId, $productAttributes)) {
$attribute = $this->retrieveAttributeById($attributeId);
// Create new attribute value with translation.
$attributeValue = $this->productAttributeManager->createAttributeValue(
$attribute,
$attributeDataValueName,
$attributeValueLocale
);
// Create new product attribute.
$this->productAttributeManager->createProductAttribute($attribute, $product, $attributeValue);
} else {
// Product attribute exists.
/** @var ProductAttribute $productAttribute */
$productAttribute = $productAttributes[$attributeId];
$attributeValue = $productAttribute->getAttributeValue();
// Create translation in current locale.
$this->productAttributeManager->setOrCreateAttributeValueTranslation(
$attributeValue,
$attributeDataValueName,
$attributeValueLocale
);
}
}
// Delete attributes.
foreach ($productAttributes as $productAttribute) {
if (!array_key_exists($productAttribute->getAttribute()->getId(), $attributeIdsInRequest)) {
// Remove all attribute value translations from attribute value.
$this->productAttributeManager->removeAllAttributeValueTranslations(
$productAttribute->getAttributeValue()
);
// Remove attribute from product.
$product->removeProductAttribute($productAttribute);
$this->em->remove($productAttribute);
}
}
}
}
|
[
"protected",
"function",
"processAttributes",
"(",
"array",
"$",
"data",
",",
"ProductInterface",
"$",
"product",
",",
"$",
"locale",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'attributes'",
"]",
")",
")",
"{",
"// Create local array of all currently assigned attributes of product.",
"$",
"productAttributes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"product",
"->",
"getProductAttributes",
"(",
")",
"as",
"$",
"productAttribute",
")",
"{",
"$",
"productAttributes",
"[",
"$",
"productAttribute",
"->",
"getAttribute",
"(",
")",
"->",
"getId",
"(",
")",
"]",
"=",
"$",
"productAttribute",
";",
"}",
"// Save all attribute ids which are given in the request.",
"$",
"attributeIdsInRequest",
"=",
"[",
"]",
";",
"// Add and change attributes.",
"foreach",
"(",
"$",
"data",
"[",
"'attributes'",
"]",
"as",
"$",
"attributeData",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"attributeData",
"[",
"'attributeId'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"attributeId",
"=",
"$",
"attributeData",
"[",
"'attributeId'",
"]",
";",
"$",
"attributeIdsInRequest",
"[",
"$",
"attributeId",
"]",
"=",
"$",
"attributeId",
";",
"// Check if a attributeValueName is provided, otherwise do nothing.",
"if",
"(",
"!",
"array_key_exists",
"(",
"'attributeValueName'",
",",
"$",
"attributeData",
")",
")",
"{",
"continue",
";",
"}",
"$",
"attributeDataValueName",
"=",
"trim",
"(",
"$",
"attributeData",
"[",
"'attributeValueName'",
"]",
")",
";",
"// Get attributeValueLocale from request.",
"$",
"attributeValueLocale",
"=",
"$",
"locale",
";",
"if",
"(",
"isset",
"(",
"$",
"attributeData",
"[",
"'attributeValueLocale'",
"]",
")",
")",
"{",
"$",
"attributeValueLocale",
"=",
"$",
"attributeData",
"[",
"'attributeValueLocale'",
"]",
";",
"}",
"// If attribute value is empty do not add.",
"if",
"(",
"''",
"===",
"$",
"attributeDataValueName",
"||",
"null",
"===",
"$",
"attributeDataValueName",
")",
"{",
"// If already set on product, remove attribute value translation.",
"if",
"(",
"array_key_exists",
"(",
"$",
"attributeId",
",",
"$",
"productAttributes",
")",
")",
"{",
"/** @var ProductAttribute $productAttribute */",
"$",
"productAttribute",
"=",
"$",
"productAttributes",
"[",
"$",
"attributeId",
"]",
";",
"// Remove attribute value translation from attribute value.",
"$",
"this",
"->",
"productAttributeManager",
"->",
"removeAttributeValueTranslation",
"(",
"$",
"productAttribute",
"->",
"getAttributeValue",
"(",
")",
",",
"$",
"attributeValueLocale",
")",
";",
"// If no more attribute value translation exists,",
"// remove the whole product attribute from the product.",
"if",
"(",
"$",
"productAttribute",
"->",
"getAttributeValue",
"(",
")",
"->",
"getTranslations",
"(",
")",
"->",
"isEmpty",
"(",
")",
")",
"{",
"$",
"product",
"->",
"removeProductAttribute",
"(",
"$",
"productAttribute",
")",
";",
"$",
"this",
"->",
"em",
"->",
"remove",
"(",
"$",
"productAttribute",
")",
";",
"}",
"}",
"continue",
";",
"}",
"// Product attribute does not exists.",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"attributeId",
",",
"$",
"productAttributes",
")",
")",
"{",
"$",
"attribute",
"=",
"$",
"this",
"->",
"retrieveAttributeById",
"(",
"$",
"attributeId",
")",
";",
"// Create new attribute value with translation.",
"$",
"attributeValue",
"=",
"$",
"this",
"->",
"productAttributeManager",
"->",
"createAttributeValue",
"(",
"$",
"attribute",
",",
"$",
"attributeDataValueName",
",",
"$",
"attributeValueLocale",
")",
";",
"// Create new product attribute.",
"$",
"this",
"->",
"productAttributeManager",
"->",
"createProductAttribute",
"(",
"$",
"attribute",
",",
"$",
"product",
",",
"$",
"attributeValue",
")",
";",
"}",
"else",
"{",
"// Product attribute exists.",
"/** @var ProductAttribute $productAttribute */",
"$",
"productAttribute",
"=",
"$",
"productAttributes",
"[",
"$",
"attributeId",
"]",
";",
"$",
"attributeValue",
"=",
"$",
"productAttribute",
"->",
"getAttributeValue",
"(",
")",
";",
"// Create translation in current locale.",
"$",
"this",
"->",
"productAttributeManager",
"->",
"setOrCreateAttributeValueTranslation",
"(",
"$",
"attributeValue",
",",
"$",
"attributeDataValueName",
",",
"$",
"attributeValueLocale",
")",
";",
"}",
"}",
"// Delete attributes.",
"foreach",
"(",
"$",
"productAttributes",
"as",
"$",
"productAttribute",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"productAttribute",
"->",
"getAttribute",
"(",
")",
"->",
"getId",
"(",
")",
",",
"$",
"attributeIdsInRequest",
")",
")",
"{",
"// Remove all attribute value translations from attribute value.",
"$",
"this",
"->",
"productAttributeManager",
"->",
"removeAllAttributeValueTranslations",
"(",
"$",
"productAttribute",
"->",
"getAttributeValue",
"(",
")",
")",
";",
"// Remove attribute from product.",
"$",
"product",
"->",
"removeProductAttribute",
"(",
"$",
"productAttribute",
")",
";",
"$",
"this",
"->",
"em",
"->",
"remove",
"(",
"$",
"productAttribute",
")",
";",
"}",
"}",
"}",
"}"
] |
Processes attributes of data array.
@param array $data
@param ProductInterface $product
@param string $locale
@throws ProductDependencyNotFoundException
|
[
"Processes",
"attributes",
"of",
"data",
"array",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductManager.php#L1986-L2081
|
224,243
|
sulu/SuluProductBundle
|
Product/ProductManager.php
|
ProductManager.retrieveAttributeById
|
private function retrieveAttributeById($attributeId)
{
$attribute = $this->attributeRepository->find($attributeId);
if (!$attribute) {
throw new ProductDependencyNotFoundException(
self::$attributeEntityName,
$attributeId
);
}
return $attribute;
}
|
php
|
private function retrieveAttributeById($attributeId)
{
$attribute = $this->attributeRepository->find($attributeId);
if (!$attribute) {
throw new ProductDependencyNotFoundException(
self::$attributeEntityName,
$attributeId
);
}
return $attribute;
}
|
[
"private",
"function",
"retrieveAttributeById",
"(",
"$",
"attributeId",
")",
"{",
"$",
"attribute",
"=",
"$",
"this",
"->",
"attributeRepository",
"->",
"find",
"(",
"$",
"attributeId",
")",
";",
"if",
"(",
"!",
"$",
"attribute",
")",
"{",
"throw",
"new",
"ProductDependencyNotFoundException",
"(",
"self",
"::",
"$",
"attributeEntityName",
",",
"$",
"attributeId",
")",
";",
"}",
"return",
"$",
"attribute",
";",
"}"
] |
Finds an attribute with the given id. Else throws an Exception.
@param int $attributeId
@throws ProductDependencyNotFoundException
@return Attribute
|
[
"Finds",
"an",
"attribute",
"with",
"the",
"given",
"id",
".",
"Else",
"throws",
"an",
"Exception",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductManager.php#L2092-L2103
|
224,244
|
sulu/SuluProductBundle
|
Product/ProductManager.php
|
ProductManager.addAllCurrencies
|
private function addAllCurrencies(ProductInterface $product)
{
$currencies = $this->currencyRepository->findAll();
foreach ($product->getPrices() as $price) {
if (($key = array_search($price->getCurrency(), $currencies)) !== false) {
unset($currencies[$key]);
}
}
foreach ($currencies as $currency) {
$price = new ProductPriceEntity();
$price->setCurrency($currency);
$product->addPrice($price);
$price->setProduct($product);
}
}
|
php
|
private function addAllCurrencies(ProductInterface $product)
{
$currencies = $this->currencyRepository->findAll();
foreach ($product->getPrices() as $price) {
if (($key = array_search($price->getCurrency(), $currencies)) !== false) {
unset($currencies[$key]);
}
}
foreach ($currencies as $currency) {
$price = new ProductPriceEntity();
$price->setCurrency($currency);
$product->addPrice($price);
$price->setProduct($product);
}
}
|
[
"private",
"function",
"addAllCurrencies",
"(",
"ProductInterface",
"$",
"product",
")",
"{",
"$",
"currencies",
"=",
"$",
"this",
"->",
"currencyRepository",
"->",
"findAll",
"(",
")",
";",
"foreach",
"(",
"$",
"product",
"->",
"getPrices",
"(",
")",
"as",
"$",
"price",
")",
"{",
"if",
"(",
"(",
"$",
"key",
"=",
"array_search",
"(",
"$",
"price",
"->",
"getCurrency",
"(",
")",
",",
"$",
"currencies",
")",
")",
"!==",
"false",
")",
"{",
"unset",
"(",
"$",
"currencies",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"currencies",
"as",
"$",
"currency",
")",
"{",
"$",
"price",
"=",
"new",
"ProductPriceEntity",
"(",
")",
";",
"$",
"price",
"->",
"setCurrency",
"(",
"$",
"currency",
")",
";",
"$",
"product",
"->",
"addPrice",
"(",
"$",
"price",
")",
";",
"$",
"price",
"->",
"setProduct",
"(",
"$",
"product",
")",
";",
"}",
"}"
] |
Adds an ProductPrice for every currency to the Product, if it is no existing already.
@param ProductInterface $product The product to fill with currencies
|
[
"Adds",
"an",
"ProductPrice",
"for",
"every",
"currency",
"to",
"the",
"Product",
"if",
"it",
"is",
"no",
"existing",
"already",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductManager.php#L2150-L2167
|
224,245
|
sulu/SuluProductBundle
|
Product/ProductManager.php
|
ProductManager.getFilters
|
public function getFilters(Request $request)
{
$filter = [];
$statuses = $request->get('status');
if ($statuses) {
$filter['status'] = explode(',', $statuses);
}
$statusIds = $request->get('status_id');
if ($statusIds) {
$filter['status_id'] = explode(',', $statusIds);
}
$types = $request->get('type');
if ($types) {
$filter['type_id'] = explode(',', $types);
}
$typeIds = $request->get('type_id');
if ($typeIds) {
$filter['type_id'] = explode(',', $typeIds);
}
$supplierId = $request->get('supplier_id');
if ($supplierId) {
$filter['accounts_supplier_id'] = $supplierId;
}
$isDeprecated = $request->get('is_deprecated');
if ($isDeprecated !== null) {
$filter['is_deprecated'] = $isDeprecated;
}
$parent = $request->get('parent');
if ($parent) {
$filter['parent'] = ($parent == 'null') ? null : $parent;
}
$categories = $request->get('categories');
if ($categories) {
$filter['categories'] = ($categories == 'null') ? null : $categories;
}
return $filter;
}
|
php
|
public function getFilters(Request $request)
{
$filter = [];
$statuses = $request->get('status');
if ($statuses) {
$filter['status'] = explode(',', $statuses);
}
$statusIds = $request->get('status_id');
if ($statusIds) {
$filter['status_id'] = explode(',', $statusIds);
}
$types = $request->get('type');
if ($types) {
$filter['type_id'] = explode(',', $types);
}
$typeIds = $request->get('type_id');
if ($typeIds) {
$filter['type_id'] = explode(',', $typeIds);
}
$supplierId = $request->get('supplier_id');
if ($supplierId) {
$filter['accounts_supplier_id'] = $supplierId;
}
$isDeprecated = $request->get('is_deprecated');
if ($isDeprecated !== null) {
$filter['is_deprecated'] = $isDeprecated;
}
$parent = $request->get('parent');
if ($parent) {
$filter['parent'] = ($parent == 'null') ? null : $parent;
}
$categories = $request->get('categories');
if ($categories) {
$filter['categories'] = ($categories == 'null') ? null : $categories;
}
return $filter;
}
|
[
"public",
"function",
"getFilters",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"filter",
"=",
"[",
"]",
";",
"$",
"statuses",
"=",
"$",
"request",
"->",
"get",
"(",
"'status'",
")",
";",
"if",
"(",
"$",
"statuses",
")",
"{",
"$",
"filter",
"[",
"'status'",
"]",
"=",
"explode",
"(",
"','",
",",
"$",
"statuses",
")",
";",
"}",
"$",
"statusIds",
"=",
"$",
"request",
"->",
"get",
"(",
"'status_id'",
")",
";",
"if",
"(",
"$",
"statusIds",
")",
"{",
"$",
"filter",
"[",
"'status_id'",
"]",
"=",
"explode",
"(",
"','",
",",
"$",
"statusIds",
")",
";",
"}",
"$",
"types",
"=",
"$",
"request",
"->",
"get",
"(",
"'type'",
")",
";",
"if",
"(",
"$",
"types",
")",
"{",
"$",
"filter",
"[",
"'type_id'",
"]",
"=",
"explode",
"(",
"','",
",",
"$",
"types",
")",
";",
"}",
"$",
"typeIds",
"=",
"$",
"request",
"->",
"get",
"(",
"'type_id'",
")",
";",
"if",
"(",
"$",
"typeIds",
")",
"{",
"$",
"filter",
"[",
"'type_id'",
"]",
"=",
"explode",
"(",
"','",
",",
"$",
"typeIds",
")",
";",
"}",
"$",
"supplierId",
"=",
"$",
"request",
"->",
"get",
"(",
"'supplier_id'",
")",
";",
"if",
"(",
"$",
"supplierId",
")",
"{",
"$",
"filter",
"[",
"'accounts_supplier_id'",
"]",
"=",
"$",
"supplierId",
";",
"}",
"$",
"isDeprecated",
"=",
"$",
"request",
"->",
"get",
"(",
"'is_deprecated'",
")",
";",
"if",
"(",
"$",
"isDeprecated",
"!==",
"null",
")",
"{",
"$",
"filter",
"[",
"'is_deprecated'",
"]",
"=",
"$",
"isDeprecated",
";",
"}",
"$",
"parent",
"=",
"$",
"request",
"->",
"get",
"(",
"'parent'",
")",
";",
"if",
"(",
"$",
"parent",
")",
"{",
"$",
"filter",
"[",
"'parent'",
"]",
"=",
"(",
"$",
"parent",
"==",
"'null'",
")",
"?",
"null",
":",
"$",
"parent",
";",
"}",
"$",
"categories",
"=",
"$",
"request",
"->",
"get",
"(",
"'categories'",
")",
";",
"if",
"(",
"$",
"categories",
")",
"{",
"$",
"filter",
"[",
"'categories'",
"]",
"=",
"(",
"$",
"categories",
"==",
"'null'",
")",
"?",
"null",
":",
"$",
"categories",
";",
"}",
"return",
"$",
"filter",
";",
"}"
] |
Get filters provided by the request.
@param Request $request
@return List $filter
|
[
"Get",
"filters",
"provided",
"by",
"the",
"request",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductManager.php#L2176-L2221
|
224,246
|
unreal4u/mqtt
|
src/Internals/TopicFilterFunctionality.php
|
TopicFilterFunctionality.addTopics
|
final public function addTopics(TopicFilter ...$topics): self
{
foreach ($topics as $topic) {
// Frequently used: topicName, make it an apart variable for easy access
$topicName = $topic->getTopicFilter();
if (\in_array($topicName, $this->topicHashTable, true) === false) {
// Personally, I find this hacky as hell. However, using the SPL library there seems to be no other way
$this->topicHashTable[] = $topicName;
$this->topics->enqueue($topic);
}
}
return $this;
}
|
php
|
final public function addTopics(TopicFilter ...$topics): self
{
foreach ($topics as $topic) {
// Frequently used: topicName, make it an apart variable for easy access
$topicName = $topic->getTopicFilter();
if (\in_array($topicName, $this->topicHashTable, true) === false) {
// Personally, I find this hacky as hell. However, using the SPL library there seems to be no other way
$this->topicHashTable[] = $topicName;
$this->topics->enqueue($topic);
}
}
return $this;
}
|
[
"final",
"public",
"function",
"addTopics",
"(",
"TopicFilter",
"...",
"$",
"topics",
")",
":",
"self",
"{",
"foreach",
"(",
"$",
"topics",
"as",
"$",
"topic",
")",
"{",
"// Frequently used: topicName, make it an apart variable for easy access",
"$",
"topicName",
"=",
"$",
"topic",
"->",
"getTopicFilter",
"(",
")",
";",
"if",
"(",
"\\",
"in_array",
"(",
"$",
"topicName",
",",
"$",
"this",
"->",
"topicHashTable",
",",
"true",
")",
"===",
"false",
")",
"{",
"// Personally, I find this hacky as hell. However, using the SPL library there seems to be no other way",
"$",
"this",
"->",
"topicHashTable",
"[",
"]",
"=",
"$",
"topicName",
";",
"$",
"this",
"->",
"topics",
"->",
"enqueue",
"(",
"$",
"topic",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
A subscription is based on filters, this function allows us to pass on filters
@param TopicFilter[] $topics
@return self
|
[
"A",
"subscription",
"is",
"based",
"on",
"filters",
"this",
"function",
"allows",
"us",
"to",
"pass",
"on",
"filters"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Internals/TopicFilterFunctionality.php#L34-L47
|
224,247
|
unreal4u/mqtt
|
src/Protocol/Subscribe.php
|
Subscribe.checkForEvent
|
public function checkForEvent(ClientInterface $client): ReadableContentInterface
{
$this->checkPingTime($client);
$publishPacketControlField = $client->readBrokerData(1);
$eventManager = new EventManager($this->logger);
if ((\ord($publishPacketControlField) & 255) > 0) {
$this->logger->debug('Event received', [
'ordValue' => \ord($publishPacketControlField) & 255,
'length' => \strlen($publishPacketControlField)
]);
return $eventManager->analyzeHeaders($publishPacketControlField, $client);
}
$this->logger->debug('No valid publish packet control field found, returning empty response');
return new EmptyReadableResponse($this->logger);
}
|
php
|
public function checkForEvent(ClientInterface $client): ReadableContentInterface
{
$this->checkPingTime($client);
$publishPacketControlField = $client->readBrokerData(1);
$eventManager = new EventManager($this->logger);
if ((\ord($publishPacketControlField) & 255) > 0) {
$this->logger->debug('Event received', [
'ordValue' => \ord($publishPacketControlField) & 255,
'length' => \strlen($publishPacketControlField)
]);
return $eventManager->analyzeHeaders($publishPacketControlField, $client);
}
$this->logger->debug('No valid publish packet control field found, returning empty response');
return new EmptyReadableResponse($this->logger);
}
|
[
"public",
"function",
"checkForEvent",
"(",
"ClientInterface",
"$",
"client",
")",
":",
"ReadableContentInterface",
"{",
"$",
"this",
"->",
"checkPingTime",
"(",
"$",
"client",
")",
";",
"$",
"publishPacketControlField",
"=",
"$",
"client",
"->",
"readBrokerData",
"(",
"1",
")",
";",
"$",
"eventManager",
"=",
"new",
"EventManager",
"(",
"$",
"this",
"->",
"logger",
")",
";",
"if",
"(",
"(",
"\\",
"ord",
"(",
"$",
"publishPacketControlField",
")",
"&",
"255",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'Event received'",
",",
"[",
"'ordValue'",
"=>",
"\\",
"ord",
"(",
"$",
"publishPacketControlField",
")",
"&",
"255",
",",
"'length'",
"=>",
"\\",
"strlen",
"(",
"$",
"publishPacketControlField",
")",
"]",
")",
";",
"return",
"$",
"eventManager",
"->",
"analyzeHeaders",
"(",
"$",
"publishPacketControlField",
",",
"$",
"client",
")",
";",
"}",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'No valid publish packet control field found, returning empty response'",
")",
";",
"return",
"new",
"EmptyReadableResponse",
"(",
"$",
"this",
"->",
"logger",
")",
";",
"}"
] |
Performs a check on the socket connection and returns either the contents or an empty object
@param ClientInterface $client
@return ReadableContentInterface
@throws \DomainException
@throws \unreal4u\MQTT\Exceptions\NotConnected
@throws \unreal4u\MQTT\Exceptions\Connect\NoConnectionParametersDefined
|
[
"Performs",
"a",
"check",
"on",
"the",
"socket",
"connection",
"and",
"returns",
"either",
"the",
"contents",
"or",
"an",
"empty",
"object"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Protocol/Subscribe.php#L94-L110
|
224,248
|
unreal4u/mqtt
|
src/Protocol/Subscribe.php
|
Subscribe.loop
|
public function loop(
ClientInterface $client,
int $idleMicroseconds = 100000,
callable $hookBeforeLoop = null
): \Generator {
$this->shouldLoop = true;
// First of all: subscribe
$this->logger->debug('Beginning loop', ['idleMicroseconds' => $idleMicroseconds]);
$readableContent = $client->processObject($this);
// Allow the user to do certain stuff before looping, for example: an Unsubscribe
if (\is_callable($hookBeforeLoop)) {
$this->logger->notice('Callable detected, executing', ['userFunctionName' => $hookBeforeLoop]);
$hookBeforeLoop($this->logger);
}
while ($this->shouldLoop === true) {
$this->logger->debug('++Loop++');
if ($readableContent instanceof Publish) {
$readableContent->performSpecialActions($client, $this);
// Only if we receive a Publish event from the broker, yield the contents
yield $readableContent->getMessage();
} else {
// Only wait for a certain amount of time if there was nothing in the queue
usleep($idleMicroseconds);
}
$readableContent = $this->checkForEvent($client);
}
}
|
php
|
public function loop(
ClientInterface $client,
int $idleMicroseconds = 100000,
callable $hookBeforeLoop = null
): \Generator {
$this->shouldLoop = true;
// First of all: subscribe
$this->logger->debug('Beginning loop', ['idleMicroseconds' => $idleMicroseconds]);
$readableContent = $client->processObject($this);
// Allow the user to do certain stuff before looping, for example: an Unsubscribe
if (\is_callable($hookBeforeLoop)) {
$this->logger->notice('Callable detected, executing', ['userFunctionName' => $hookBeforeLoop]);
$hookBeforeLoop($this->logger);
}
while ($this->shouldLoop === true) {
$this->logger->debug('++Loop++');
if ($readableContent instanceof Publish) {
$readableContent->performSpecialActions($client, $this);
// Only if we receive a Publish event from the broker, yield the contents
yield $readableContent->getMessage();
} else {
// Only wait for a certain amount of time if there was nothing in the queue
usleep($idleMicroseconds);
}
$readableContent = $this->checkForEvent($client);
}
}
|
[
"public",
"function",
"loop",
"(",
"ClientInterface",
"$",
"client",
",",
"int",
"$",
"idleMicroseconds",
"=",
"100000",
",",
"callable",
"$",
"hookBeforeLoop",
"=",
"null",
")",
":",
"\\",
"Generator",
"{",
"$",
"this",
"->",
"shouldLoop",
"=",
"true",
";",
"// First of all: subscribe",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'Beginning loop'",
",",
"[",
"'idleMicroseconds'",
"=>",
"$",
"idleMicroseconds",
"]",
")",
";",
"$",
"readableContent",
"=",
"$",
"client",
"->",
"processObject",
"(",
"$",
"this",
")",
";",
"// Allow the user to do certain stuff before looping, for example: an Unsubscribe",
"if",
"(",
"\\",
"is_callable",
"(",
"$",
"hookBeforeLoop",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"notice",
"(",
"'Callable detected, executing'",
",",
"[",
"'userFunctionName'",
"=>",
"$",
"hookBeforeLoop",
"]",
")",
";",
"$",
"hookBeforeLoop",
"(",
"$",
"this",
"->",
"logger",
")",
";",
"}",
"while",
"(",
"$",
"this",
"->",
"shouldLoop",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'++Loop++'",
")",
";",
"if",
"(",
"$",
"readableContent",
"instanceof",
"Publish",
")",
"{",
"$",
"readableContent",
"->",
"performSpecialActions",
"(",
"$",
"client",
",",
"$",
"this",
")",
";",
"// Only if we receive a Publish event from the broker, yield the contents",
"yield",
"$",
"readableContent",
"->",
"getMessage",
"(",
")",
";",
"}",
"else",
"{",
"// Only wait for a certain amount of time if there was nothing in the queue",
"usleep",
"(",
"$",
"idleMicroseconds",
")",
";",
"}",
"$",
"readableContent",
"=",
"$",
"this",
"->",
"checkForEvent",
"(",
"$",
"client",
")",
";",
"}",
"}"
] |
Loop and yields different type of results back whenever they are available
Be aware that 1 second is 1000000 microseconds
@param ClientInterface $client
@param int $idleMicroseconds The amount of microseconds the watcher should wait before checking the socket again
@param callable|null $hookBeforeLoop
@return \Generator
@throws \unreal4u\MQTT\Exceptions\NotConnected
@throws \unreal4u\MQTT\Exceptions\Connect\NoConnectionParametersDefined
@throws \DomainException
|
[
"Loop",
"and",
"yields",
"different",
"type",
"of",
"results",
"back",
"whenever",
"they",
"are",
"available"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Protocol/Subscribe.php#L125-L154
|
224,249
|
kesar/PhpOpenSubtitles
|
src/kesar/PhpOpenSubtitles/UrlGenerator.php
|
UrlGenerator.getSubtitleUrls
|
public function getSubtitleUrls(array $subtitles, $all = false)
{
$subtitlesUrls = array();
if (!empty($subtitles['data'])) {
foreach ($subtitles['data'] as $sub) {
if (!empty($sub['SubDownloadLink'])) {
$subtitlesUrls[] = $sub['SubDownloadLink'];
if ($all === false) {
return $subtitlesUrls;
}
}
}
}
return $subtitlesUrls;
}
|
php
|
public function getSubtitleUrls(array $subtitles, $all = false)
{
$subtitlesUrls = array();
if (!empty($subtitles['data'])) {
foreach ($subtitles['data'] as $sub) {
if (!empty($sub['SubDownloadLink'])) {
$subtitlesUrls[] = $sub['SubDownloadLink'];
if ($all === false) {
return $subtitlesUrls;
}
}
}
}
return $subtitlesUrls;
}
|
[
"public",
"function",
"getSubtitleUrls",
"(",
"array",
"$",
"subtitles",
",",
"$",
"all",
"=",
"false",
")",
"{",
"$",
"subtitlesUrls",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"subtitles",
"[",
"'data'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"subtitles",
"[",
"'data'",
"]",
"as",
"$",
"sub",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"sub",
"[",
"'SubDownloadLink'",
"]",
")",
")",
"{",
"$",
"subtitlesUrls",
"[",
"]",
"=",
"$",
"sub",
"[",
"'SubDownloadLink'",
"]",
";",
"if",
"(",
"$",
"all",
"===",
"false",
")",
"{",
"return",
"$",
"subtitlesUrls",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"subtitlesUrls",
";",
"}"
] |
Retrieve the url of the first subtitle found
@param array $subtitles
@param bool $all
@return array
|
[
"Retrieve",
"the",
"url",
"of",
"the",
"first",
"subtitle",
"found"
] |
8b2ed1a06f393aa33403b27b32cace3c3c7d4ef3
|
https://github.com/kesar/PhpOpenSubtitles/blob/8b2ed1a06f393aa33403b27b32cace3c3c7d4ef3/src/kesar/PhpOpenSubtitles/UrlGenerator.php#L15-L31
|
224,250
|
sulu/SuluProductBundle
|
Controller/ProductContentController.php
|
ProductContentController.getAction
|
public function getAction(Request $request, $productId)
{
$locale = $request->get('locale');
$product = $this->fetchProduct($productId);
$content = $this->getProductContentMapper()->get($product, $locale);
$view = $this->view($content, Response::HTTP_OK);
return $this->handleView($view);
}
|
php
|
public function getAction(Request $request, $productId)
{
$locale = $request->get('locale');
$product = $this->fetchProduct($productId);
$content = $this->getProductContentMapper()->get($product, $locale);
$view = $this->view($content, Response::HTTP_OK);
return $this->handleView($view);
}
|
[
"public",
"function",
"getAction",
"(",
"Request",
"$",
"request",
",",
"$",
"productId",
")",
"{",
"$",
"locale",
"=",
"$",
"request",
"->",
"get",
"(",
"'locale'",
")",
";",
"$",
"product",
"=",
"$",
"this",
"->",
"fetchProduct",
"(",
"$",
"productId",
")",
";",
"$",
"content",
"=",
"$",
"this",
"->",
"getProductContentMapper",
"(",
")",
"->",
"get",
"(",
"$",
"product",
",",
"$",
"locale",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"content",
",",
"Response",
"::",
"HTTP_OK",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] |
Action for receiving contents of a given product.
@param Request $request
@param int $productId
@return Response
|
[
"Action",
"for",
"receiving",
"contents",
"of",
"a",
"given",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Controller/ProductContentController.php#L39-L49
|
224,251
|
sulu/SuluProductBundle
|
Controller/ProductContentController.php
|
ProductContentController.putAction
|
public function putAction(Request $request, $productId)
{
$locale = $request->get('locale');
$parameters = $request->request->all();
$product = $this->fetchProduct($productId);
$content = $this->getProductContentMapper()->map($product, $parameters, $locale);
$this->getEntityManager()->flush();
$view = $this->view($content, Response::HTTP_OK);
return $this->handleView($view);
}
|
php
|
public function putAction(Request $request, $productId)
{
$locale = $request->get('locale');
$parameters = $request->request->all();
$product = $this->fetchProduct($productId);
$content = $this->getProductContentMapper()->map($product, $parameters, $locale);
$this->getEntityManager()->flush();
$view = $this->view($content, Response::HTTP_OK);
return $this->handleView($view);
}
|
[
"public",
"function",
"putAction",
"(",
"Request",
"$",
"request",
",",
"$",
"productId",
")",
"{",
"$",
"locale",
"=",
"$",
"request",
"->",
"get",
"(",
"'locale'",
")",
";",
"$",
"parameters",
"=",
"$",
"request",
"->",
"request",
"->",
"all",
"(",
")",
";",
"$",
"product",
"=",
"$",
"this",
"->",
"fetchProduct",
"(",
"$",
"productId",
")",
";",
"$",
"content",
"=",
"$",
"this",
"->",
"getProductContentMapper",
"(",
")",
"->",
"map",
"(",
"$",
"product",
",",
"$",
"parameters",
",",
"$",
"locale",
")",
";",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"flush",
"(",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"content",
",",
"Response",
"::",
"HTTP_OK",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] |
Put action to update content of a product.
@param Request $request
@param int $productId
@throws EntityNotFoundException
@return Response
|
[
"Put",
"action",
"to",
"update",
"content",
"of",
"a",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Controller/ProductContentController.php#L61-L74
|
224,252
|
sulu/SuluProductBundle
|
Controller/ProductContentController.php
|
ProductContentController.fetchProduct
|
public function fetchProduct($productId)
{
/** @var ProductInterface $product */
$product = $this->getProductRepository()->find($productId);
if (!$product) {
throw new EntityNotFoundException($this->getProductRepository()->getClassName(), $productId);
}
return $product;
}
|
php
|
public function fetchProduct($productId)
{
/** @var ProductInterface $product */
$product = $this->getProductRepository()->find($productId);
if (!$product) {
throw new EntityNotFoundException($this->getProductRepository()->getClassName(), $productId);
}
return $product;
}
|
[
"public",
"function",
"fetchProduct",
"(",
"$",
"productId",
")",
"{",
"/** @var ProductInterface $product */",
"$",
"product",
"=",
"$",
"this",
"->",
"getProductRepository",
"(",
")",
"->",
"find",
"(",
"$",
"productId",
")",
";",
"if",
"(",
"!",
"$",
"product",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"$",
"this",
"->",
"getProductRepository",
"(",
")",
"->",
"getClassName",
"(",
")",
",",
"$",
"productId",
")",
";",
"}",
"return",
"$",
"product",
";",
"}"
] |
Fetches product by id from database.
@param int $productId
@throws EntityNotFoundException
@return ProductInterface
|
[
"Fetches",
"product",
"by",
"id",
"from",
"database",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Controller/ProductContentController.php#L85-L94
|
224,253
|
sulu/SuluProductBundle
|
DataFixtures/ORM/CountryTaxes/LoadCountryTaxes.php
|
LoadCountryTaxes.getCountryByCode
|
private function getCountryByCode($code)
{
// Check if country exist in cache.
if (array_key_exists($code, $this->countries)) {
return $this->countries[$code];
}
// Fetch country.
$country = $this->manager->getRepository(static::$countryEntityName)->findOneBy(['code' => $code]);
if (!$country) {
throw new \Doctrine\ORM\EntityNotFoundException('code = ' . $code);
}
// Add country to cache.
$this->countries[$code] = $country;
return $country;
}
|
php
|
private function getCountryByCode($code)
{
// Check if country exist in cache.
if (array_key_exists($code, $this->countries)) {
return $this->countries[$code];
}
// Fetch country.
$country = $this->manager->getRepository(static::$countryEntityName)->findOneBy(['code' => $code]);
if (!$country) {
throw new \Doctrine\ORM\EntityNotFoundException('code = ' . $code);
}
// Add country to cache.
$this->countries[$code] = $country;
return $country;
}
|
[
"private",
"function",
"getCountryByCode",
"(",
"$",
"code",
")",
"{",
"// Check if country exist in cache.",
"if",
"(",
"array_key_exists",
"(",
"$",
"code",
",",
"$",
"this",
"->",
"countries",
")",
")",
"{",
"return",
"$",
"this",
"->",
"countries",
"[",
"$",
"code",
"]",
";",
"}",
"// Fetch country.",
"$",
"country",
"=",
"$",
"this",
"->",
"manager",
"->",
"getRepository",
"(",
"static",
"::",
"$",
"countryEntityName",
")",
"->",
"findOneBy",
"(",
"[",
"'code'",
"=>",
"$",
"code",
"]",
")",
";",
"if",
"(",
"!",
"$",
"country",
")",
"{",
"throw",
"new",
"\\",
"Doctrine",
"\\",
"ORM",
"\\",
"EntityNotFoundException",
"(",
"'code = '",
".",
"$",
"code",
")",
";",
"}",
"// Add country to cache.",
"$",
"this",
"->",
"countries",
"[",
"$",
"code",
"]",
"=",
"$",
"country",
";",
"return",
"$",
"country",
";",
"}"
] |
Finds country by code and caches it.
@param string $code
@throws EntityNotFoundException
@return Country
|
[
"Finds",
"country",
"by",
"code",
"and",
"caches",
"it",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/DataFixtures/ORM/CountryTaxes/LoadCountryTaxes.php#L118-L133
|
224,254
|
laravelflare/mail-debug
|
src/MailDebug/MailDebugManager.php
|
MailDebugManager.mail
|
public function mail(Swift_Mime_Message $message)
{
$this->message = $message;
$this->createPreviewDirectory();
$this->files->put($this->path(), $this->content());
$this->setSession();
$this->cleanOldPreviews();
}
|
php
|
public function mail(Swift_Mime_Message $message)
{
$this->message = $message;
$this->createPreviewDirectory();
$this->files->put($this->path(), $this->content());
$this->setSession();
$this->cleanOldPreviews();
}
|
[
"public",
"function",
"mail",
"(",
"Swift_Mime_Message",
"$",
"message",
")",
"{",
"$",
"this",
"->",
"message",
"=",
"$",
"message",
";",
"$",
"this",
"->",
"createPreviewDirectory",
"(",
")",
";",
"$",
"this",
"->",
"files",
"->",
"put",
"(",
"$",
"this",
"->",
"path",
"(",
")",
",",
"$",
"this",
"->",
"content",
"(",
")",
")",
";",
"$",
"this",
"->",
"setSession",
"(",
")",
";",
"$",
"this",
"->",
"cleanOldPreviews",
"(",
")",
";",
"}"
] |
Perform the Debug Mail Actions.
@param Swift_Mime_Message $message
@return
|
[
"Perform",
"the",
"Debug",
"Mail",
"Actions",
"."
] |
337642f5afd6d585ccfe9fd16efa95a60db9500d
|
https://github.com/laravelflare/mail-debug/blob/337642f5afd6d585ccfe9fd16efa95a60db9500d/src/MailDebug/MailDebugManager.php#L43-L54
|
224,255
|
laravelflare/mail-debug
|
src/MailDebug/MailDebugManager.php
|
MailDebugManager.filename
|
private function filename()
{
$to = str_replace(['@', '.'], ['_at_', '_'], array_keys($this->message->getTo())[0]);
return str_slug($this->message->getDate().'_'.$to.'_'.$this->message->getSubject(), '_').'.html';
}
|
php
|
private function filename()
{
$to = str_replace(['@', '.'], ['_at_', '_'], array_keys($this->message->getTo())[0]);
return str_slug($this->message->getDate().'_'.$to.'_'.$this->message->getSubject(), '_').'.html';
}
|
[
"private",
"function",
"filename",
"(",
")",
"{",
"$",
"to",
"=",
"str_replace",
"(",
"[",
"'@'",
",",
"'.'",
"]",
",",
"[",
"'_at_'",
",",
"'_'",
"]",
",",
"array_keys",
"(",
"$",
"this",
"->",
"message",
"->",
"getTo",
"(",
")",
")",
"[",
"0",
"]",
")",
";",
"return",
"str_slug",
"(",
"$",
"this",
"->",
"message",
"->",
"getDate",
"(",
")",
".",
"'_'",
".",
"$",
"to",
".",
"'_'",
".",
"$",
"this",
"->",
"message",
"->",
"getSubject",
"(",
")",
",",
"'_'",
")",
".",
"'.html'",
";",
"}"
] |
Return the Debug Mail Filename.
@return string
|
[
"Return",
"the",
"Debug",
"Mail",
"Filename",
"."
] |
337642f5afd6d585ccfe9fd16efa95a60db9500d
|
https://github.com/laravelflare/mail-debug/blob/337642f5afd6d585ccfe9fd16efa95a60db9500d/src/MailDebug/MailDebugManager.php#L143-L148
|
224,256
|
laravelflare/mail-debug
|
src/MailDebug/Http/Middleware/MailDebug.php
|
MailDebug.appendToResponse
|
protected function appendToResponse(Response $response)
{
$existingContent = $response->getContent();
$closeBodyPosition = strripos($existingContent, '</body>');
$appendedContent = "
<script>
window.open('".route('mail-debug', ['file' => $this->debug->preview()])."','width=680,height=800,toolbar=0,menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=0,top=0');
</script>";
if ($closeBodyPosition !== false) {
$response->setContent(substr($existingContent, 0, $closeBodyPosition).$appendedContent.substr($existingContent, $closeBodyPosition));
return;
}
$response->setContent($existingContent.$appendedContent);
}
|
php
|
protected function appendToResponse(Response $response)
{
$existingContent = $response->getContent();
$closeBodyPosition = strripos($existingContent, '</body>');
$appendedContent = "
<script>
window.open('".route('mail-debug', ['file' => $this->debug->preview()])."','width=680,height=800,toolbar=0,menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=0,top=0');
</script>";
if ($closeBodyPosition !== false) {
$response->setContent(substr($existingContent, 0, $closeBodyPosition).$appendedContent.substr($existingContent, $closeBodyPosition));
return;
}
$response->setContent($existingContent.$appendedContent);
}
|
[
"protected",
"function",
"appendToResponse",
"(",
"Response",
"$",
"response",
")",
"{",
"$",
"existingContent",
"=",
"$",
"response",
"->",
"getContent",
"(",
")",
";",
"$",
"closeBodyPosition",
"=",
"strripos",
"(",
"$",
"existingContent",
",",
"'</body>'",
")",
";",
"$",
"appendedContent",
"=",
"\"\n <script>\n window.open('\"",
".",
"route",
"(",
"'mail-debug'",
",",
"[",
"'file'",
"=>",
"$",
"this",
"->",
"debug",
"->",
"preview",
"(",
")",
"]",
")",
".",
"\"','width=680,height=800,toolbar=0,menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=0,top=0');\n </script>\"",
";",
"if",
"(",
"$",
"closeBodyPosition",
"!==",
"false",
")",
"{",
"$",
"response",
"->",
"setContent",
"(",
"substr",
"(",
"$",
"existingContent",
",",
"0",
",",
"$",
"closeBodyPosition",
")",
".",
"$",
"appendedContent",
".",
"substr",
"(",
"$",
"existingContent",
",",
"$",
"closeBodyPosition",
")",
")",
";",
"return",
";",
"}",
"$",
"response",
"->",
"setContent",
"(",
"$",
"existingContent",
".",
"$",
"appendedContent",
")",
";",
"}"
] |
Injects the Mail Debug Popup into the Response.
@param \Illuminate\Http\Response
|
[
"Injects",
"the",
"Mail",
"Debug",
"Popup",
"into",
"the",
"Response",
"."
] |
337642f5afd6d585ccfe9fd16efa95a60db9500d
|
https://github.com/laravelflare/mail-debug/blob/337642f5afd6d585ccfe9fd16efa95a60db9500d/src/MailDebug/Http/Middleware/MailDebug.php#L67-L83
|
224,257
|
joachim-n/case-converter
|
StringAssembler.php
|
StringAssembler.camel
|
public function camel() {
if ($this->areTitleCase) {
// If the pieces are already in title case, lower the case of the first
// piece only, unless it's in uppercase.
if (!preg_match('@^[[:upper:]]+$@', $this->pieces[0])) {
$this->pieces[0] = lcfirst($this->pieces[0]);
}
}
else {
$first_piece = array_shift($this->pieces);
$this->pieces = array_map('ucfirst', $this->pieces);
array_unshift($this->pieces, $first_piece);
}
return implode('', $this->pieces);
}
|
php
|
public function camel() {
if ($this->areTitleCase) {
// If the pieces are already in title case, lower the case of the first
// piece only, unless it's in uppercase.
if (!preg_match('@^[[:upper:]]+$@', $this->pieces[0])) {
$this->pieces[0] = lcfirst($this->pieces[0]);
}
}
else {
$first_piece = array_shift($this->pieces);
$this->pieces = array_map('ucfirst', $this->pieces);
array_unshift($this->pieces, $first_piece);
}
return implode('', $this->pieces);
}
|
[
"public",
"function",
"camel",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"areTitleCase",
")",
"{",
"// If the pieces are already in title case, lower the case of the first",
"// piece only, unless it's in uppercase.",
"if",
"(",
"!",
"preg_match",
"(",
"'@^[[:upper:]]+$@'",
",",
"$",
"this",
"->",
"pieces",
"[",
"0",
"]",
")",
")",
"{",
"$",
"this",
"->",
"pieces",
"[",
"0",
"]",
"=",
"lcfirst",
"(",
"$",
"this",
"->",
"pieces",
"[",
"0",
"]",
")",
";",
"}",
"}",
"else",
"{",
"$",
"first_piece",
"=",
"array_shift",
"(",
"$",
"this",
"->",
"pieces",
")",
";",
"$",
"this",
"->",
"pieces",
"=",
"array_map",
"(",
"'ucfirst'",
",",
"$",
"this",
"->",
"pieces",
")",
";",
"array_unshift",
"(",
"$",
"this",
"->",
"pieces",
",",
"$",
"first_piece",
")",
";",
"}",
"return",
"implode",
"(",
"''",
",",
"$",
"this",
"->",
"pieces",
")",
";",
"}"
] |
Outputs the pieces as a camel case string.
@return string
The resulting string.
|
[
"Outputs",
"the",
"pieces",
"as",
"a",
"camel",
"case",
"string",
"."
] |
f31486030bd46242218a0d7d75becab0b02da2f4
|
https://github.com/joachim-n/case-converter/blob/f31486030bd46242218a0d7d75becab0b02da2f4/StringAssembler.php#L44-L61
|
224,258
|
joachim-n/case-converter
|
StringAssembler.php
|
StringAssembler.pascal
|
public function pascal() {
if (!$this->areTitleCase) {
$this->pieces = array_map('ucfirst', $this->pieces);
}
return implode('', $this->pieces);
}
|
php
|
public function pascal() {
if (!$this->areTitleCase) {
$this->pieces = array_map('ucfirst', $this->pieces);
}
return implode('', $this->pieces);
}
|
[
"public",
"function",
"pascal",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"areTitleCase",
")",
"{",
"$",
"this",
"->",
"pieces",
"=",
"array_map",
"(",
"'ucfirst'",
",",
"$",
"this",
"->",
"pieces",
")",
";",
"}",
"return",
"implode",
"(",
"''",
",",
"$",
"this",
"->",
"pieces",
")",
";",
"}"
] |
Outputs the pieces as a pascal case string.
@return string
The resulting string.
|
[
"Outputs",
"the",
"pieces",
"as",
"a",
"pascal",
"case",
"string",
"."
] |
f31486030bd46242218a0d7d75becab0b02da2f4
|
https://github.com/joachim-n/case-converter/blob/f31486030bd46242218a0d7d75becab0b02da2f4/StringAssembler.php#L69-L74
|
224,259
|
joachim-n/case-converter
|
StringAssembler.php
|
StringAssembler.snake
|
public function snake() {
if ($this->areTitleCase) {
foreach ($this->pieces as &$piece) {
if (preg_match('@^[[:upper:]]+$@', $piece)) {
// Leave an entirely uppercase piece alone.
continue;
}
$piece = lcfirst($piece);
}
}
return implode('_', $this->pieces);
}
|
php
|
public function snake() {
if ($this->areTitleCase) {
foreach ($this->pieces as &$piece) {
if (preg_match('@^[[:upper:]]+$@', $piece)) {
// Leave an entirely uppercase piece alone.
continue;
}
$piece = lcfirst($piece);
}
}
return implode('_', $this->pieces);
}
|
[
"public",
"function",
"snake",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"areTitleCase",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"pieces",
"as",
"&",
"$",
"piece",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'@^[[:upper:]]+$@'",
",",
"$",
"piece",
")",
")",
"{",
"// Leave an entirely uppercase piece alone.",
"continue",
";",
"}",
"$",
"piece",
"=",
"lcfirst",
"(",
"$",
"piece",
")",
";",
"}",
"}",
"return",
"implode",
"(",
"'_'",
",",
"$",
"this",
"->",
"pieces",
")",
";",
"}"
] |
Outputs the pieces as a snak case string.
@return string
The resulting string.
|
[
"Outputs",
"the",
"pieces",
"as",
"a",
"snak",
"case",
"string",
"."
] |
f31486030bd46242218a0d7d75becab0b02da2f4
|
https://github.com/joachim-n/case-converter/blob/f31486030bd46242218a0d7d75becab0b02da2f4/StringAssembler.php#L82-L95
|
224,260
|
yosymfony/HttpServer
|
src/HttpServer.php
|
HttpServer.start
|
public function start()
{
$this->loop = React\EventLoop\Factory::create();
$socket = new React\Socket\Server($this->loop);
$http = new React\Http\Server($socket);
$http->on('request', $function = $this->requestHandler->getHandlerFunction());
$socket->listen($this->requestHandler->getPort(), $this->requestHandler->getHost());
$this->loop->run();
}
|
php
|
public function start()
{
$this->loop = React\EventLoop\Factory::create();
$socket = new React\Socket\Server($this->loop);
$http = new React\Http\Server($socket);
$http->on('request', $function = $this->requestHandler->getHandlerFunction());
$socket->listen($this->requestHandler->getPort(), $this->requestHandler->getHost());
$this->loop->run();
}
|
[
"public",
"function",
"start",
"(",
")",
"{",
"$",
"this",
"->",
"loop",
"=",
"React",
"\\",
"EventLoop",
"\\",
"Factory",
"::",
"create",
"(",
")",
";",
"$",
"socket",
"=",
"new",
"React",
"\\",
"Socket",
"\\",
"Server",
"(",
"$",
"this",
"->",
"loop",
")",
";",
"$",
"http",
"=",
"new",
"React",
"\\",
"Http",
"\\",
"Server",
"(",
"$",
"socket",
")",
";",
"$",
"http",
"->",
"on",
"(",
"'request'",
",",
"$",
"function",
"=",
"$",
"this",
"->",
"requestHandler",
"->",
"getHandlerFunction",
"(",
")",
")",
";",
"$",
"socket",
"->",
"listen",
"(",
"$",
"this",
"->",
"requestHandler",
"->",
"getPort",
"(",
")",
",",
"$",
"this",
"->",
"requestHandler",
"->",
"getHost",
"(",
")",
")",
";",
"$",
"this",
"->",
"loop",
"->",
"run",
"(",
")",
";",
"}"
] |
start the loop
|
[
"start",
"the",
"loop"
] |
7c145578044cffe2b1f0f3d3ec3c6829d73f7719
|
https://github.com/yosymfony/HttpServer/blob/7c145578044cffe2b1f0f3d3ec3c6829d73f7719/src/HttpServer.php#L39-L49
|
224,261
|
ericmann/sessionz
|
php/Handlers/MemoryHandler.php
|
MemoryHandler._read
|
protected function _read($id)
{
if (isset($this->cache[$id])) {
/** @var MemoryItem $item */
$item = $this->cache[$id];
if (!$item->is_valid()) {
unset($this->cache[$id]);
return false;
}
return $item->data;
}
return false;
}
|
php
|
protected function _read($id)
{
if (isset($this->cache[$id])) {
/** @var MemoryItem $item */
$item = $this->cache[$id];
if (!$item->is_valid()) {
unset($this->cache[$id]);
return false;
}
return $item->data;
}
return false;
}
|
[
"protected",
"function",
"_read",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"cache",
"[",
"$",
"id",
"]",
")",
")",
"{",
"/** @var MemoryItem $item */",
"$",
"item",
"=",
"$",
"this",
"->",
"cache",
"[",
"$",
"id",
"]",
";",
"if",
"(",
"!",
"$",
"item",
"->",
"is_valid",
"(",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"cache",
"[",
"$",
"id",
"]",
")",
";",
"return",
"false",
";",
"}",
"return",
"$",
"item",
"->",
"data",
";",
"}",
"return",
"false",
";",
"}"
] |
Get an item from the cache if it's still valid, otherwise exire it
and return false.
@param string $id
@return bool|string
|
[
"Get",
"an",
"item",
"from",
"the",
"cache",
"if",
"it",
"s",
"still",
"valid",
"otherwise",
"exire",
"it",
"and",
"return",
"false",
"."
] |
b1a278c54aa13035ed0ca0c297fb117d04036d9b
|
https://github.com/ericmann/sessionz/blob/b1a278c54aa13035ed0ca0c297fb117d04036d9b/php/Handlers/MemoryHandler.php#L37-L51
|
224,262
|
ericmann/sessionz
|
php/Handlers/MemoryHandler.php
|
MemoryHandler.clean
|
public function clean($maxlifetime, $next)
{
$this->cache = array_filter($this->cache, function($item) use ($maxlifetime) {
/** @var MemoryItem $item */
return $item->is_valid($maxlifetime);
});
return $next($maxlifetime);
}
|
php
|
public function clean($maxlifetime, $next)
{
$this->cache = array_filter($this->cache, function($item) use ($maxlifetime) {
/** @var MemoryItem $item */
return $item->is_valid($maxlifetime);
});
return $next($maxlifetime);
}
|
[
"public",
"function",
"clean",
"(",
"$",
"maxlifetime",
",",
"$",
"next",
")",
"{",
"$",
"this",
"->",
"cache",
"=",
"array_filter",
"(",
"$",
"this",
"->",
"cache",
",",
"function",
"(",
"$",
"item",
")",
"use",
"(",
"$",
"maxlifetime",
")",
"{",
"/** @var MemoryItem $item */",
"return",
"$",
"item",
"->",
"is_valid",
"(",
"$",
"maxlifetime",
")",
";",
"}",
")",
";",
"return",
"$",
"next",
"(",
"$",
"maxlifetime",
")",
";",
"}"
] |
Update the internal cache by filtering out any items that are no longer valid.
@param int $maxlifetime
@param callable $next
@codeCoverageIgnore Due to timestamp issues, this is currently untestable ...
@return mixed
|
[
"Update",
"the",
"internal",
"cache",
"by",
"filtering",
"out",
"any",
"items",
"that",
"are",
"no",
"longer",
"valid",
"."
] |
b1a278c54aa13035ed0ca0c297fb117d04036d9b
|
https://github.com/ericmann/sessionz/blob/b1a278c54aa13035ed0ca0c297fb117d04036d9b/php/Handlers/MemoryHandler.php#L82-L90
|
224,263
|
ericmann/sessionz
|
php/Handlers/MemoryHandler.php
|
MemoryHandler.read
|
public function read($id, $next)
{
$data = $this->_read($id);
if ( false === $data ) {
$data = $next($id);
if (false !== $data) {
$item = new MemoryItem($data);
$this->cache[$id] = $item;
}
}
return $data;
}
|
php
|
public function read($id, $next)
{
$data = $this->_read($id);
if ( false === $data ) {
$data = $next($id);
if (false !== $data) {
$item = new MemoryItem($data);
$this->cache[$id] = $item;
}
}
return $data;
}
|
[
"public",
"function",
"read",
"(",
"$",
"id",
",",
"$",
"next",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"_read",
"(",
"$",
"id",
")",
";",
"if",
"(",
"false",
"===",
"$",
"data",
")",
"{",
"$",
"data",
"=",
"$",
"next",
"(",
"$",
"id",
")",
";",
"if",
"(",
"false",
"!==",
"$",
"data",
")",
"{",
"$",
"item",
"=",
"new",
"MemoryItem",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"cache",
"[",
"$",
"id",
"]",
"=",
"$",
"item",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] |
Grab the item from the cache if it exists, otherwise delve deeper
into the stack and retrieve from another underlying middlware.
@param string $id
@param callable $next
@return string
|
[
"Grab",
"the",
"item",
"from",
"the",
"cache",
"if",
"it",
"exists",
"otherwise",
"delve",
"deeper",
"into",
"the",
"stack",
"and",
"retrieve",
"from",
"another",
"underlying",
"middlware",
"."
] |
b1a278c54aa13035ed0ca0c297fb117d04036d9b
|
https://github.com/ericmann/sessionz/blob/b1a278c54aa13035ed0ca0c297fb117d04036d9b/php/Handlers/MemoryHandler.php#L115-L127
|
224,264
|
jasny/audio
|
src/Jasny/Audio/Waveform.php
|
Waveform.calc
|
protected function calc()
{
if (!file_exists($this->track)) throw new \Exception("File '{$this->track}' doesn't exist");
$length = $this->track->getLength();
$rate = null;
$sample_count = $this->track->getSampleCount();
$trim = null;
if ($this->offset || $this->duration) {
$offset = $this->offset >= 0 ? $this->offset : $length + $this->offset;
$trim = $offset . ($this->duration ? " " . (float)$this->duration : '');
$newlength = $this->duration ?: $length - $offset;
$sample_count = floor(($newlength / $length) * $sample_count);
$length = $newlength;
}
// Downsample to max 500 samples per pixel with a minimum sample rate of 4k/s
if ($sample_count / $this->width > 500) {
$rate = max(($this->width / $length) * 500, 4000);
$sample_count = $rate * $length;
}
$this->length = $length;
$this->samples = $this->calcExecute($sample_count, $trim, $rate);
if (!isset($this->level)) {
$this->level = max(-1 * min($this->samples), max($this->samples));
}
}
|
php
|
protected function calc()
{
if (!file_exists($this->track)) throw new \Exception("File '{$this->track}' doesn't exist");
$length = $this->track->getLength();
$rate = null;
$sample_count = $this->track->getSampleCount();
$trim = null;
if ($this->offset || $this->duration) {
$offset = $this->offset >= 0 ? $this->offset : $length + $this->offset;
$trim = $offset . ($this->duration ? " " . (float)$this->duration : '');
$newlength = $this->duration ?: $length - $offset;
$sample_count = floor(($newlength / $length) * $sample_count);
$length = $newlength;
}
// Downsample to max 500 samples per pixel with a minimum sample rate of 4k/s
if ($sample_count / $this->width > 500) {
$rate = max(($this->width / $length) * 500, 4000);
$sample_count = $rate * $length;
}
$this->length = $length;
$this->samples = $this->calcExecute($sample_count, $trim, $rate);
if (!isset($this->level)) {
$this->level = max(-1 * min($this->samples), max($this->samples));
}
}
|
[
"protected",
"function",
"calc",
"(",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"track",
")",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"\"File '{$this->track}' doesn't exist\"",
")",
";",
"$",
"length",
"=",
"$",
"this",
"->",
"track",
"->",
"getLength",
"(",
")",
";",
"$",
"rate",
"=",
"null",
";",
"$",
"sample_count",
"=",
"$",
"this",
"->",
"track",
"->",
"getSampleCount",
"(",
")",
";",
"$",
"trim",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"offset",
"||",
"$",
"this",
"->",
"duration",
")",
"{",
"$",
"offset",
"=",
"$",
"this",
"->",
"offset",
">=",
"0",
"?",
"$",
"this",
"->",
"offset",
":",
"$",
"length",
"+",
"$",
"this",
"->",
"offset",
";",
"$",
"trim",
"=",
"$",
"offset",
".",
"(",
"$",
"this",
"->",
"duration",
"?",
"\" \"",
".",
"(",
"float",
")",
"$",
"this",
"->",
"duration",
":",
"''",
")",
";",
"$",
"newlength",
"=",
"$",
"this",
"->",
"duration",
"?",
":",
"$",
"length",
"-",
"$",
"offset",
";",
"$",
"sample_count",
"=",
"floor",
"(",
"(",
"$",
"newlength",
"/",
"$",
"length",
")",
"*",
"$",
"sample_count",
")",
";",
"$",
"length",
"=",
"$",
"newlength",
";",
"}",
"// Downsample to max 500 samples per pixel with a minimum sample rate of 4k/s",
"if",
"(",
"$",
"sample_count",
"/",
"$",
"this",
"->",
"width",
">",
"500",
")",
"{",
"$",
"rate",
"=",
"max",
"(",
"(",
"$",
"this",
"->",
"width",
"/",
"$",
"length",
")",
"*",
"500",
",",
"4000",
")",
";",
"$",
"sample_count",
"=",
"$",
"rate",
"*",
"$",
"length",
";",
"}",
"$",
"this",
"->",
"length",
"=",
"$",
"length",
";",
"$",
"this",
"->",
"samples",
"=",
"$",
"this",
"->",
"calcExecute",
"(",
"$",
"sample_count",
",",
"$",
"trim",
",",
"$",
"rate",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"level",
")",
")",
"{",
"$",
"this",
"->",
"level",
"=",
"max",
"(",
"-",
"1",
"*",
"min",
"(",
"$",
"this",
"->",
"samples",
")",
",",
"max",
"(",
"$",
"this",
"->",
"samples",
")",
")",
";",
"}",
"}"
] |
Calculate the samples.
@return array
|
[
"Calculate",
"the",
"samples",
"."
] |
5c8bcb93ab4243c79971342f4a414747c716fedf
|
https://github.com/jasny/audio/blob/5c8bcb93ab4243c79971342f4a414747c716fedf/src/Jasny/Audio/Waveform.php#L106-L137
|
224,265
|
jasny/audio
|
src/Jasny/Audio/Waveform.php
|
Waveform.calcExecute
|
protected function calcExecute($sample_count, $trim, $rate)
{
$track = escapeshellarg($this->track);
if ($trim) $trim = "trim $trim";
$resample = $rate ? "-r $rate" : '';
$chunk_size = floor($sample_count / $this->width);
$descriptorspec = array(
1 => array("pipe", "w"), // stdout
2 => array("pipe", "w") // stderr
);
$sox = escapeshellcmd(Track::which('sox'));
$handle = proc_open("$sox $track -t raw $resample -c 1 -e floating-point -L - $trim", $descriptorspec, $pipes);
if (!$handle) throw new \Exception("Failed to get the samples using sox");
$chunk = array();
$samples = array();
while ($data = fread($pipes[1], 4 * $chunk_size)) {
$chunk = unpack('f*', $data);
$chunk[] = 0;
$samples[] = min($chunk);
$samples[] = max($chunk);
};
$err = stream_get_contents($pipes[2]);
$ret = proc_close($handle);
if ($ret != 0) throw new \Exception("Sox command failed. " . trim($err));
return $samples;
}
|
php
|
protected function calcExecute($sample_count, $trim, $rate)
{
$track = escapeshellarg($this->track);
if ($trim) $trim = "trim $trim";
$resample = $rate ? "-r $rate" : '';
$chunk_size = floor($sample_count / $this->width);
$descriptorspec = array(
1 => array("pipe", "w"), // stdout
2 => array("pipe", "w") // stderr
);
$sox = escapeshellcmd(Track::which('sox'));
$handle = proc_open("$sox $track -t raw $resample -c 1 -e floating-point -L - $trim", $descriptorspec, $pipes);
if (!$handle) throw new \Exception("Failed to get the samples using sox");
$chunk = array();
$samples = array();
while ($data = fread($pipes[1], 4 * $chunk_size)) {
$chunk = unpack('f*', $data);
$chunk[] = 0;
$samples[] = min($chunk);
$samples[] = max($chunk);
};
$err = stream_get_contents($pipes[2]);
$ret = proc_close($handle);
if ($ret != 0) throw new \Exception("Sox command failed. " . trim($err));
return $samples;
}
|
[
"protected",
"function",
"calcExecute",
"(",
"$",
"sample_count",
",",
"$",
"trim",
",",
"$",
"rate",
")",
"{",
"$",
"track",
"=",
"escapeshellarg",
"(",
"$",
"this",
"->",
"track",
")",
";",
"if",
"(",
"$",
"trim",
")",
"$",
"trim",
"=",
"\"trim $trim\"",
";",
"$",
"resample",
"=",
"$",
"rate",
"?",
"\"-r $rate\"",
":",
"''",
";",
"$",
"chunk_size",
"=",
"floor",
"(",
"$",
"sample_count",
"/",
"$",
"this",
"->",
"width",
")",
";",
"$",
"descriptorspec",
"=",
"array",
"(",
"1",
"=>",
"array",
"(",
"\"pipe\"",
",",
"\"w\"",
")",
",",
"// stdout",
"2",
"=>",
"array",
"(",
"\"pipe\"",
",",
"\"w\"",
")",
"// stderr",
")",
";",
"$",
"sox",
"=",
"escapeshellcmd",
"(",
"Track",
"::",
"which",
"(",
"'sox'",
")",
")",
";",
"$",
"handle",
"=",
"proc_open",
"(",
"\"$sox $track -t raw $resample -c 1 -e floating-point -L - $trim\"",
",",
"$",
"descriptorspec",
",",
"$",
"pipes",
")",
";",
"if",
"(",
"!",
"$",
"handle",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Failed to get the samples using sox\"",
")",
";",
"$",
"chunk",
"=",
"array",
"(",
")",
";",
"$",
"samples",
"=",
"array",
"(",
")",
";",
"while",
"(",
"$",
"data",
"=",
"fread",
"(",
"$",
"pipes",
"[",
"1",
"]",
",",
"4",
"*",
"$",
"chunk_size",
")",
")",
"{",
"$",
"chunk",
"=",
"unpack",
"(",
"'f*'",
",",
"$",
"data",
")",
";",
"$",
"chunk",
"[",
"]",
"=",
"0",
";",
"$",
"samples",
"[",
"]",
"=",
"min",
"(",
"$",
"chunk",
")",
";",
"$",
"samples",
"[",
"]",
"=",
"max",
"(",
"$",
"chunk",
")",
";",
"}",
";",
"$",
"err",
"=",
"stream_get_contents",
"(",
"$",
"pipes",
"[",
"2",
"]",
")",
";",
"$",
"ret",
"=",
"proc_close",
"(",
"$",
"handle",
")",
";",
"if",
"(",
"$",
"ret",
"!=",
"0",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Sox command failed. \"",
".",
"trim",
"(",
"$",
"err",
")",
")",
";",
"return",
"$",
"samples",
";",
"}"
] |
Calculate the samples
@param int $sample_count
@param string $trim
@param float $rate
@return array
|
[
"Calculate",
"the",
"samples"
] |
5c8bcb93ab4243c79971342f4a414747c716fedf
|
https://github.com/jasny/audio/blob/5c8bcb93ab4243c79971342f4a414747c716fedf/src/Jasny/Audio/Waveform.php#L147-L180
|
224,266
|
jasny/audio
|
src/Jasny/Audio/Waveform.php
|
Waveform.plot
|
public function plot()
{
$this->getSamples();
$im = imagecreatetruecolor($this->width, $this->height);
imagesavealpha($im, true);
imagefill($im, 0, 0, imagecolorallocatealpha($im, 0, 0, 0, 127));
$center = ($this->height / 2);
$scale = ($center / $this->level);
$color = self::strToColor($im, $this->color);
for ($i = 0, $n = count($this->samples); $i < $n-1; $i += 2) {
$max = $center + (-1 * $this->samples[$i] * $scale);
$min = $center + (-1 * $this->samples[$i+1] * $scale);
imageline($im, $i / 2, $min, $i / 2, $max, $color);
}
if (!empty($this->axis)) {
imageline($im, 0, $this->height / 2, $this->width, $this->height / 2, self::strToColor($im, $this->axis));
}
return $im;
}
|
php
|
public function plot()
{
$this->getSamples();
$im = imagecreatetruecolor($this->width, $this->height);
imagesavealpha($im, true);
imagefill($im, 0, 0, imagecolorallocatealpha($im, 0, 0, 0, 127));
$center = ($this->height / 2);
$scale = ($center / $this->level);
$color = self::strToColor($im, $this->color);
for ($i = 0, $n = count($this->samples); $i < $n-1; $i += 2) {
$max = $center + (-1 * $this->samples[$i] * $scale);
$min = $center + (-1 * $this->samples[$i+1] * $scale);
imageline($im, $i / 2, $min, $i / 2, $max, $color);
}
if (!empty($this->axis)) {
imageline($im, 0, $this->height / 2, $this->width, $this->height / 2, self::strToColor($im, $this->axis));
}
return $im;
}
|
[
"public",
"function",
"plot",
"(",
")",
"{",
"$",
"this",
"->",
"getSamples",
"(",
")",
";",
"$",
"im",
"=",
"imagecreatetruecolor",
"(",
"$",
"this",
"->",
"width",
",",
"$",
"this",
"->",
"height",
")",
";",
"imagesavealpha",
"(",
"$",
"im",
",",
"true",
")",
";",
"imagefill",
"(",
"$",
"im",
",",
"0",
",",
"0",
",",
"imagecolorallocatealpha",
"(",
"$",
"im",
",",
"0",
",",
"0",
",",
"0",
",",
"127",
")",
")",
";",
"$",
"center",
"=",
"(",
"$",
"this",
"->",
"height",
"/",
"2",
")",
";",
"$",
"scale",
"=",
"(",
"$",
"center",
"/",
"$",
"this",
"->",
"level",
")",
";",
"$",
"color",
"=",
"self",
"::",
"strToColor",
"(",
"$",
"im",
",",
"$",
"this",
"->",
"color",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"n",
"=",
"count",
"(",
"$",
"this",
"->",
"samples",
")",
";",
"$",
"i",
"<",
"$",
"n",
"-",
"1",
";",
"$",
"i",
"+=",
"2",
")",
"{",
"$",
"max",
"=",
"$",
"center",
"+",
"(",
"-",
"1",
"*",
"$",
"this",
"->",
"samples",
"[",
"$",
"i",
"]",
"*",
"$",
"scale",
")",
";",
"$",
"min",
"=",
"$",
"center",
"+",
"(",
"-",
"1",
"*",
"$",
"this",
"->",
"samples",
"[",
"$",
"i",
"+",
"1",
"]",
"*",
"$",
"scale",
")",
";",
"imageline",
"(",
"$",
"im",
",",
"$",
"i",
"/",
"2",
",",
"$",
"min",
",",
"$",
"i",
"/",
"2",
",",
"$",
"max",
",",
"$",
"color",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"axis",
")",
")",
"{",
"imageline",
"(",
"$",
"im",
",",
"0",
",",
"$",
"this",
"->",
"height",
"/",
"2",
",",
"$",
"this",
"->",
"width",
",",
"$",
"this",
"->",
"height",
"/",
"2",
",",
"self",
"::",
"strToColor",
"(",
"$",
"im",
",",
"$",
"this",
"->",
"axis",
")",
")",
";",
"}",
"return",
"$",
"im",
";",
"}"
] |
Plot the waveform
@return resource
|
[
"Plot",
"the",
"waveform"
] |
5c8bcb93ab4243c79971342f4a414747c716fedf
|
https://github.com/jasny/audio/blob/5c8bcb93ab4243c79971342f4a414747c716fedf/src/Jasny/Audio/Waveform.php#L221-L245
|
224,267
|
jasny/audio
|
src/Jasny/Audio/Waveform.php
|
Waveform.strToColor
|
protected static function strToColor($im, $color)
{
$color = ltrim($color, '#');
if (strpos($color, ',') !== false) {
list($red, $green, $blue, $opacity) = explode(',', $color) + [3 => null];
} else {
$red = hexdec(substr($color, 0, 2));
$green = hexdec(substr($color, 2, 2));
$blue = hexdec(substr($color, 4, 2));
$opacity = 1;
}
$alpha = round((1 - $opacity) * 127);
return imagecolorallocatealpha($im, $red, $green, $blue, $alpha);
}
|
php
|
protected static function strToColor($im, $color)
{
$color = ltrim($color, '#');
if (strpos($color, ',') !== false) {
list($red, $green, $blue, $opacity) = explode(',', $color) + [3 => null];
} else {
$red = hexdec(substr($color, 0, 2));
$green = hexdec(substr($color, 2, 2));
$blue = hexdec(substr($color, 4, 2));
$opacity = 1;
}
$alpha = round((1 - $opacity) * 127);
return imagecolorallocatealpha($im, $red, $green, $blue, $alpha);
}
|
[
"protected",
"static",
"function",
"strToColor",
"(",
"$",
"im",
",",
"$",
"color",
")",
"{",
"$",
"color",
"=",
"ltrim",
"(",
"$",
"color",
",",
"'#'",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"color",
",",
"','",
")",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"red",
",",
"$",
"green",
",",
"$",
"blue",
",",
"$",
"opacity",
")",
"=",
"explode",
"(",
"','",
",",
"$",
"color",
")",
"+",
"[",
"3",
"=>",
"null",
"]",
";",
"}",
"else",
"{",
"$",
"red",
"=",
"hexdec",
"(",
"substr",
"(",
"$",
"color",
",",
"0",
",",
"2",
")",
")",
";",
"$",
"green",
"=",
"hexdec",
"(",
"substr",
"(",
"$",
"color",
",",
"2",
",",
"2",
")",
")",
";",
"$",
"blue",
"=",
"hexdec",
"(",
"substr",
"(",
"$",
"color",
",",
"4",
",",
"2",
")",
")",
";",
"$",
"opacity",
"=",
"1",
";",
"}",
"$",
"alpha",
"=",
"round",
"(",
"(",
"1",
"-",
"$",
"opacity",
")",
"*",
"127",
")",
";",
"return",
"imagecolorallocatealpha",
"(",
"$",
"im",
",",
"$",
"red",
",",
"$",
"green",
",",
"$",
"blue",
",",
"$",
"alpha",
")",
";",
"}"
] |
Create a gd color using a hexidecimal color notation
@param resource $im
@param string $color
@return int
|
[
"Create",
"a",
"gd",
"color",
"using",
"a",
"hexidecimal",
"color",
"notation"
] |
5c8bcb93ab4243c79971342f4a414747c716fedf
|
https://github.com/jasny/audio/blob/5c8bcb93ab4243c79971342f4a414747c716fedf/src/Jasny/Audio/Waveform.php#L254-L269
|
224,268
|
DevGroup-ru/yii2-multilingual
|
src/Multilingual.php
|
Multilingual.retrieveCookieLanguage
|
public function retrieveCookieLanguage()
{
if (Yii::$app instanceof \yii\web\Application === false) {
return;
}
if (Yii::$app->request->cookies->has('language_id')) {
$language_id = intval(Yii::$app->request->cookies->get('language_id')->value);
if (call_user_func(
[
$this->modelsMap['Language'],
'getById'
],
$language_id
) !== null
) {
$this->cookie_language_id = $language_id;
}
}
if ($this->cookie_language_id === null) {
$this->cookie_language_id = $this->language_id;
Yii::$app->response->cookies->add(new Cookie([
'name' => 'language_id',
'value' => $this->cookie_language_id,
]));
}
}
|
php
|
public function retrieveCookieLanguage()
{
if (Yii::$app instanceof \yii\web\Application === false) {
return;
}
if (Yii::$app->request->cookies->has('language_id')) {
$language_id = intval(Yii::$app->request->cookies->get('language_id')->value);
if (call_user_func(
[
$this->modelsMap['Language'],
'getById'
],
$language_id
) !== null
) {
$this->cookie_language_id = $language_id;
}
}
if ($this->cookie_language_id === null) {
$this->cookie_language_id = $this->language_id;
Yii::$app->response->cookies->add(new Cookie([
'name' => 'language_id',
'value' => $this->cookie_language_id,
]));
}
}
|
[
"public",
"function",
"retrieveCookieLanguage",
"(",
")",
"{",
"if",
"(",
"Yii",
"::",
"$",
"app",
"instanceof",
"\\",
"yii",
"\\",
"web",
"\\",
"Application",
"===",
"false",
")",
"{",
"return",
";",
"}",
"if",
"(",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"cookies",
"->",
"has",
"(",
"'language_id'",
")",
")",
"{",
"$",
"language_id",
"=",
"intval",
"(",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"cookies",
"->",
"get",
"(",
"'language_id'",
")",
"->",
"value",
")",
";",
"if",
"(",
"call_user_func",
"(",
"[",
"$",
"this",
"->",
"modelsMap",
"[",
"'Language'",
"]",
",",
"'getById'",
"]",
",",
"$",
"language_id",
")",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"cookie_language_id",
"=",
"$",
"language_id",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"cookie_language_id",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"cookie_language_id",
"=",
"$",
"this",
"->",
"language_id",
";",
"Yii",
"::",
"$",
"app",
"->",
"response",
"->",
"cookies",
"->",
"add",
"(",
"new",
"Cookie",
"(",
"[",
"'name'",
"=>",
"'language_id'",
",",
"'value'",
"=>",
"$",
"this",
"->",
"cookie_language_id",
",",
"]",
")",
")",
";",
"}",
"}"
] |
Retrieves language form cookie
|
[
"Retrieves",
"language",
"form",
"cookie"
] |
50682a48e216df1dde48b56096640e2ff579a3e0
|
https://github.com/DevGroup-ru/yii2-multilingual/blob/50682a48e216df1dde48b56096640e2ff579a3e0/src/Multilingual.php#L334-L360
|
224,269
|
logical-and/php-oauth
|
src/UserData/Extractor/GitHub.php
|
GitHub.getEmailObject
|
private function getEmailObject($emails)
{
// Try to find an email address which is primary and verified.
foreach ($emails as $email) {
if ($email[ 'primary' ] && $email[ 'verified' ]) {
return $email;
}
}
// Try to find an email address which is primary.
foreach ($emails as $email) {
if ($email[ 'primary' ]) {
return $email;
}
}
return $emails[ 0 ];
}
|
php
|
private function getEmailObject($emails)
{
// Try to find an email address which is primary and verified.
foreach ($emails as $email) {
if ($email[ 'primary' ] && $email[ 'verified' ]) {
return $email;
}
}
// Try to find an email address which is primary.
foreach ($emails as $email) {
if ($email[ 'primary' ]) {
return $email;
}
}
return $emails[ 0 ];
}
|
[
"private",
"function",
"getEmailObject",
"(",
"$",
"emails",
")",
"{",
"// Try to find an email address which is primary and verified.",
"foreach",
"(",
"$",
"emails",
"as",
"$",
"email",
")",
"{",
"if",
"(",
"$",
"email",
"[",
"'primary'",
"]",
"&&",
"$",
"email",
"[",
"'verified'",
"]",
")",
"{",
"return",
"$",
"email",
";",
"}",
"}",
"// Try to find an email address which is primary.",
"foreach",
"(",
"$",
"emails",
"as",
"$",
"email",
")",
"{",
"if",
"(",
"$",
"email",
"[",
"'primary'",
"]",
")",
"{",
"return",
"$",
"email",
";",
"}",
"}",
"return",
"$",
"emails",
"[",
"0",
"]",
";",
"}"
] |
Get the right email address from the one's the user provides.
@param array $emails The array of email array objects provided by GitHub.
@return array The email array object.
|
[
"Get",
"the",
"right",
"email",
"address",
"from",
"the",
"one",
"s",
"the",
"user",
"provides",
"."
] |
48fa6e74b147f5a689cb6a03dcf9ea67d1d98bbf
|
https://github.com/logical-and/php-oauth/blob/48fa6e74b147f5a689cb6a03dcf9ea67d1d98bbf/src/UserData/Extractor/GitHub.php#L118-L135
|
224,270
|
logical-and/php-oauth
|
src/ServiceFactory.php
|
ServiceFactory.registerService
|
public function registerService($serviceName, $className)
{
if (!class_exists($className)) {
throw new Exception(sprintf('Service class %s does not exist.', $className));
}
$reflClass = new \ReflectionClass($className);
foreach (['OAuth2', 'OAuth1'] as $version) {
if ($reflClass->implementsInterface('OAuth\\' . $version . '\\Service\\ServiceInterface')) {
$this->serviceClassMap[ $version ][ ucfirst($serviceName) ] = $className;
return $this;
}
}
throw new Exception(sprintf('Service class %s must implement ServiceInterface.', $className));
}
|
php
|
public function registerService($serviceName, $className)
{
if (!class_exists($className)) {
throw new Exception(sprintf('Service class %s does not exist.', $className));
}
$reflClass = new \ReflectionClass($className);
foreach (['OAuth2', 'OAuth1'] as $version) {
if ($reflClass->implementsInterface('OAuth\\' . $version . '\\Service\\ServiceInterface')) {
$this->serviceClassMap[ $version ][ ucfirst($serviceName) ] = $className;
return $this;
}
}
throw new Exception(sprintf('Service class %s must implement ServiceInterface.', $className));
}
|
[
"public",
"function",
"registerService",
"(",
"$",
"serviceName",
",",
"$",
"className",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'Service class %s does not exist.'",
",",
"$",
"className",
")",
")",
";",
"}",
"$",
"reflClass",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"className",
")",
";",
"foreach",
"(",
"[",
"'OAuth2'",
",",
"'OAuth1'",
"]",
"as",
"$",
"version",
")",
"{",
"if",
"(",
"$",
"reflClass",
"->",
"implementsInterface",
"(",
"'OAuth\\\\'",
".",
"$",
"version",
".",
"'\\\\Service\\\\ServiceInterface'",
")",
")",
"{",
"$",
"this",
"->",
"serviceClassMap",
"[",
"$",
"version",
"]",
"[",
"ucfirst",
"(",
"$",
"serviceName",
")",
"]",
"=",
"$",
"className",
";",
"return",
"$",
"this",
";",
"}",
"}",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'Service class %s must implement ServiceInterface.'",
",",
"$",
"className",
")",
")",
";",
"}"
] |
Register a custom service to classname mapping.
@param string $serviceName Name of the service
@param string $className Class to instantiate *
@return ServiceFactory
@throws Exception If the class is nonexistent or does not implement a valid ServiceInterface
|
[
"Register",
"a",
"custom",
"service",
"to",
"classname",
"mapping",
"."
] |
48fa6e74b147f5a689cb6a03dcf9ea67d1d98bbf
|
https://github.com/logical-and/php-oauth/blob/48fa6e74b147f5a689cb6a03dcf9ea67d1d98bbf/src/ServiceFactory.php#L102-L119
|
224,271
|
logical-and/php-oauth
|
src/ServiceFactory.php
|
ServiceFactory.createService
|
public function createService(
$serviceName,
CredentialsInterface $credentials,
TokenStorageInterface $storage,
$scopes = [],
Url $baseApiUri = null,
$apiVersion = ""
) {
foreach ($this->serviceBuilders as $version => $buildMethod) {
$fullyQualifiedServiceName = $this->getFullyQualifiedServiceName($serviceName, $version);
if (class_exists($fullyQualifiedServiceName)) {
return $this->$buildMethod(
$fullyQualifiedServiceName,
$credentials,
$storage,
$scopes,
$baseApiUri,
$apiVersion
);
}
}
return null;
}
|
php
|
public function createService(
$serviceName,
CredentialsInterface $credentials,
TokenStorageInterface $storage,
$scopes = [],
Url $baseApiUri = null,
$apiVersion = ""
) {
foreach ($this->serviceBuilders as $version => $buildMethod) {
$fullyQualifiedServiceName = $this->getFullyQualifiedServiceName($serviceName, $version);
if (class_exists($fullyQualifiedServiceName)) {
return $this->$buildMethod(
$fullyQualifiedServiceName,
$credentials,
$storage,
$scopes,
$baseApiUri,
$apiVersion
);
}
}
return null;
}
|
[
"public",
"function",
"createService",
"(",
"$",
"serviceName",
",",
"CredentialsInterface",
"$",
"credentials",
",",
"TokenStorageInterface",
"$",
"storage",
",",
"$",
"scopes",
"=",
"[",
"]",
",",
"Url",
"$",
"baseApiUri",
"=",
"null",
",",
"$",
"apiVersion",
"=",
"\"\"",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"serviceBuilders",
"as",
"$",
"version",
"=>",
"$",
"buildMethod",
")",
"{",
"$",
"fullyQualifiedServiceName",
"=",
"$",
"this",
"->",
"getFullyQualifiedServiceName",
"(",
"$",
"serviceName",
",",
"$",
"version",
")",
";",
"if",
"(",
"class_exists",
"(",
"$",
"fullyQualifiedServiceName",
")",
")",
"{",
"return",
"$",
"this",
"->",
"$",
"buildMethod",
"(",
"$",
"fullyQualifiedServiceName",
",",
"$",
"credentials",
",",
"$",
"storage",
",",
"$",
"scopes",
",",
"$",
"baseApiUri",
",",
"$",
"apiVersion",
")",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Builds and returns oauth services
It will first try to build an OAuth2 service and if none found it will try to build an OAuth1 service
@param string $serviceName Name of service to create
@param CredentialsInterface $credentials
@param TokenStorageInterface $storage
@param array|null $scopes If creating an oauth2 service, array of scopes
@param null|\OAuth\Common\Http\Url $baseApiUri
@param string $apiVersion version of the api call
@return \OAuth\OAuth1\Service\ServiceInterface|\OAuth\OAuth2\Service\ServiceInterface
|
[
"Builds",
"and",
"returns",
"oauth",
"services",
"It",
"will",
"first",
"try",
"to",
"build",
"an",
"OAuth2",
"service",
"and",
"if",
"none",
"found",
"it",
"will",
"try",
"to",
"build",
"an",
"OAuth1",
"service"
] |
48fa6e74b147f5a689cb6a03dcf9ea67d1d98bbf
|
https://github.com/logical-and/php-oauth/blob/48fa6e74b147f5a689cb6a03dcf9ea67d1d98bbf/src/ServiceFactory.php#L134-L158
|
224,272
|
logical-and/php-oauth
|
src/ServiceFactory.php
|
ServiceFactory.getFullyQualifiedServiceName
|
private function getFullyQualifiedServiceName($serviceName, $type)
{
$serviceName = ucfirst($serviceName);
if (isset($this->serviceClassMap[ $type ][ $serviceName ])) {
return $this->serviceClassMap[ $type ][ $serviceName ];
}
return '\\' . __NAMESPACE__ . '\\' . $type . '\\Service\\' . $serviceName;
}
|
php
|
private function getFullyQualifiedServiceName($serviceName, $type)
{
$serviceName = ucfirst($serviceName);
if (isset($this->serviceClassMap[ $type ][ $serviceName ])) {
return $this->serviceClassMap[ $type ][ $serviceName ];
}
return '\\' . __NAMESPACE__ . '\\' . $type . '\\Service\\' . $serviceName;
}
|
[
"private",
"function",
"getFullyQualifiedServiceName",
"(",
"$",
"serviceName",
",",
"$",
"type",
")",
"{",
"$",
"serviceName",
"=",
"ucfirst",
"(",
"$",
"serviceName",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"serviceClassMap",
"[",
"$",
"type",
"]",
"[",
"$",
"serviceName",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"serviceClassMap",
"[",
"$",
"type",
"]",
"[",
"$",
"serviceName",
"]",
";",
"}",
"return",
"'\\\\'",
".",
"__NAMESPACE__",
".",
"'\\\\'",
".",
"$",
"type",
".",
"'\\\\Service\\\\'",
".",
"$",
"serviceName",
";",
"}"
] |
Gets the fully qualified name of the service
@param string $serviceName The name of the service of which to get the fully qualified name
@param string $type The type of the service to get (either OAuth1 or OAuth2)
@return string The fully qualified name of the service
|
[
"Gets",
"the",
"fully",
"qualified",
"name",
"of",
"the",
"service"
] |
48fa6e74b147f5a689cb6a03dcf9ea67d1d98bbf
|
https://github.com/logical-and/php-oauth/blob/48fa6e74b147f5a689cb6a03dcf9ea67d1d98bbf/src/ServiceFactory.php#L168-L177
|
224,273
|
logical-and/php-oauth
|
src/ServiceFactory.php
|
ServiceFactory.buildV2Service
|
private function buildV2Service(
$serviceName,
CredentialsInterface $credentials,
TokenStorageInterface $storage,
array $scopes,
Url $baseApiUri = null,
$apiVersion = ""
) {
return new $serviceName(
$credentials,
$this->getHttpTransporter(),
$storage,
$this->resolveScopes($serviceName, $scopes),
$baseApiUri,
$apiVersion
);
}
|
php
|
private function buildV2Service(
$serviceName,
CredentialsInterface $credentials,
TokenStorageInterface $storage,
array $scopes,
Url $baseApiUri = null,
$apiVersion = ""
) {
return new $serviceName(
$credentials,
$this->getHttpTransporter(),
$storage,
$this->resolveScopes($serviceName, $scopes),
$baseApiUri,
$apiVersion
);
}
|
[
"private",
"function",
"buildV2Service",
"(",
"$",
"serviceName",
",",
"CredentialsInterface",
"$",
"credentials",
",",
"TokenStorageInterface",
"$",
"storage",
",",
"array",
"$",
"scopes",
",",
"Url",
"$",
"baseApiUri",
"=",
"null",
",",
"$",
"apiVersion",
"=",
"\"\"",
")",
"{",
"return",
"new",
"$",
"serviceName",
"(",
"$",
"credentials",
",",
"$",
"this",
"->",
"getHttpTransporter",
"(",
")",
",",
"$",
"storage",
",",
"$",
"this",
"->",
"resolveScopes",
"(",
"$",
"serviceName",
",",
"$",
"scopes",
")",
",",
"$",
"baseApiUri",
",",
"$",
"apiVersion",
")",
";",
"}"
] |
Builds v2 services
@param string $serviceName The fully qualified service name
@param CredentialsInterface $credentials
@param TokenStorageInterface $storage
@param array|null $scopes Array of scopes for the service
@param Url|null $baseApiUri
@param string $apiVersion
@return \OAuth\OAuth2\Service\ServiceInterface
|
[
"Builds",
"v2",
"services"
] |
48fa6e74b147f5a689cb6a03dcf9ea67d1d98bbf
|
https://github.com/logical-and/php-oauth/blob/48fa6e74b147f5a689cb6a03dcf9ea67d1d98bbf/src/ServiceFactory.php#L191-L207
|
224,274
|
logical-and/php-oauth
|
src/ServiceFactory.php
|
ServiceFactory.resolveScopes
|
private function resolveScopes($serviceName, array $scopes)
{
$reflClass = new \ReflectionClass($serviceName);
$constants = $reflClass->getConstants();
$resolvedScopes = [];
foreach ($scopes as $scope) {
$key = strtoupper('SCOPE_' . $scope);
if (array_key_exists($key, $constants)) {
$resolvedScopes[ ] = $constants[ $key ];
} else {
$resolvedScopes[ ] = $scope;
}
}
return $resolvedScopes;
}
|
php
|
private function resolveScopes($serviceName, array $scopes)
{
$reflClass = new \ReflectionClass($serviceName);
$constants = $reflClass->getConstants();
$resolvedScopes = [];
foreach ($scopes as $scope) {
$key = strtoupper('SCOPE_' . $scope);
if (array_key_exists($key, $constants)) {
$resolvedScopes[ ] = $constants[ $key ];
} else {
$resolvedScopes[ ] = $scope;
}
}
return $resolvedScopes;
}
|
[
"private",
"function",
"resolveScopes",
"(",
"$",
"serviceName",
",",
"array",
"$",
"scopes",
")",
"{",
"$",
"reflClass",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"serviceName",
")",
";",
"$",
"constants",
"=",
"$",
"reflClass",
"->",
"getConstants",
"(",
")",
";",
"$",
"resolvedScopes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"scopes",
"as",
"$",
"scope",
")",
"{",
"$",
"key",
"=",
"strtoupper",
"(",
"'SCOPE_'",
".",
"$",
"scope",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"constants",
")",
")",
"{",
"$",
"resolvedScopes",
"[",
"]",
"=",
"$",
"constants",
"[",
"$",
"key",
"]",
";",
"}",
"else",
"{",
"$",
"resolvedScopes",
"[",
"]",
"=",
"$",
"scope",
";",
"}",
"}",
"return",
"$",
"resolvedScopes",
";",
"}"
] |
Resolves scopes for v2 services
@param string $serviceName The fully qualified service name
@param array $scopes List of scopes for the service
@return array List of resolved scopes
|
[
"Resolves",
"scopes",
"for",
"v2",
"services"
] |
48fa6e74b147f5a689cb6a03dcf9ea67d1d98bbf
|
https://github.com/logical-and/php-oauth/blob/48fa6e74b147f5a689cb6a03dcf9ea67d1d98bbf/src/ServiceFactory.php#L217-L234
|
224,275
|
logical-and/php-oauth
|
src/ServiceFactory.php
|
ServiceFactory.buildV1Service
|
private function buildV1Service(
$serviceName,
CredentialsInterface $credentials,
TokenStorageInterface $storage,
$scopes,
Url $baseApiUri = null
) {
if (!empty($scopes)) {
throw new Exception(
'Scopes passed to ServiceFactory::createService but an OAuth1 service was requested.'
);
}
return new $serviceName(
$credentials,
$this->getHttpTransporter(),
$storage,
new Signature($credentials),
$baseApiUri
);
}
|
php
|
private function buildV1Service(
$serviceName,
CredentialsInterface $credentials,
TokenStorageInterface $storage,
$scopes,
Url $baseApiUri = null
) {
if (!empty($scopes)) {
throw new Exception(
'Scopes passed to ServiceFactory::createService but an OAuth1 service was requested.'
);
}
return new $serviceName(
$credentials,
$this->getHttpTransporter(),
$storage,
new Signature($credentials),
$baseApiUri
);
}
|
[
"private",
"function",
"buildV1Service",
"(",
"$",
"serviceName",
",",
"CredentialsInterface",
"$",
"credentials",
",",
"TokenStorageInterface",
"$",
"storage",
",",
"$",
"scopes",
",",
"Url",
"$",
"baseApiUri",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"scopes",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Scopes passed to ServiceFactory::createService but an OAuth1 service was requested.'",
")",
";",
"}",
"return",
"new",
"$",
"serviceName",
"(",
"$",
"credentials",
",",
"$",
"this",
"->",
"getHttpTransporter",
"(",
")",
",",
"$",
"storage",
",",
"new",
"Signature",
"(",
"$",
"credentials",
")",
",",
"$",
"baseApiUri",
")",
";",
"}"
] |
Builds v1 services
@param string $serviceName The fully qualified service name
@param CredentialsInterface $credentials
@param TokenStorageInterface $storage
@param array $scopes
@param Url $baseApiUri
@return \OAuth\OAuth1\Service\ServiceInterface
@throws Exception
|
[
"Builds",
"v1",
"services"
] |
48fa6e74b147f5a689cb6a03dcf9ea67d1d98bbf
|
https://github.com/logical-and/php-oauth/blob/48fa6e74b147f5a689cb6a03dcf9ea67d1d98bbf/src/ServiceFactory.php#L249-L269
|
224,276
|
appkr/api
|
src/Http/Response.php
|
Response.respond
|
public function respond($payload = [])
{
if ($meta = $this->getMeta()) {
$payload = array_merge(
$payload,
['meta' => $meta]
);
}
if (config('api.convert')) {
$payload = PayloadConverter::run($payload);
}
$statusCode = (config('api.suppress_response_code') === true)
? StatusCode::OK : $this->getStatusCode();
return (! $callback = $this->request->input('callback'))
? $this->response->json(
$payload,
$statusCode,
$this->getHeaders(),
config('api.jsonEncodeOption')
)
: $this->response->jsonp(
$callback,
$payload,
$statusCode,
$this->getHeaders()
);
}
|
php
|
public function respond($payload = [])
{
if ($meta = $this->getMeta()) {
$payload = array_merge(
$payload,
['meta' => $meta]
);
}
if (config('api.convert')) {
$payload = PayloadConverter::run($payload);
}
$statusCode = (config('api.suppress_response_code') === true)
? StatusCode::OK : $this->getStatusCode();
return (! $callback = $this->request->input('callback'))
? $this->response->json(
$payload,
$statusCode,
$this->getHeaders(),
config('api.jsonEncodeOption')
)
: $this->response->jsonp(
$callback,
$payload,
$statusCode,
$this->getHeaders()
);
}
|
[
"public",
"function",
"respond",
"(",
"$",
"payload",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"meta",
"=",
"$",
"this",
"->",
"getMeta",
"(",
")",
")",
"{",
"$",
"payload",
"=",
"array_merge",
"(",
"$",
"payload",
",",
"[",
"'meta'",
"=>",
"$",
"meta",
"]",
")",
";",
"}",
"if",
"(",
"config",
"(",
"'api.convert'",
")",
")",
"{",
"$",
"payload",
"=",
"PayloadConverter",
"::",
"run",
"(",
"$",
"payload",
")",
";",
"}",
"$",
"statusCode",
"=",
"(",
"config",
"(",
"'api.suppress_response_code'",
")",
"===",
"true",
")",
"?",
"StatusCode",
"::",
"OK",
":",
"$",
"this",
"->",
"getStatusCode",
"(",
")",
";",
"return",
"(",
"!",
"$",
"callback",
"=",
"$",
"this",
"->",
"request",
"->",
"input",
"(",
"'callback'",
")",
")",
"?",
"$",
"this",
"->",
"response",
"->",
"json",
"(",
"$",
"payload",
",",
"$",
"statusCode",
",",
"$",
"this",
"->",
"getHeaders",
"(",
")",
",",
"config",
"(",
"'api.jsonEncodeOption'",
")",
")",
":",
"$",
"this",
"->",
"response",
"->",
"jsonp",
"(",
"$",
"callback",
",",
"$",
"payload",
",",
"$",
"statusCode",
",",
"$",
"this",
"->",
"getHeaders",
"(",
")",
")",
";",
"}"
] |
Generic response.
@api
@param array|null $payload
@return \Illuminate\Contracts\Http\Response
|
[
"Generic",
"response",
"."
] |
5b676f6cf3bc74c9e429226c87505f7455700716
|
https://github.com/appkr/api/blob/5b676f6cf3bc74c9e429226c87505f7455700716/src/Http/Response.php#L71-L100
|
224,277
|
appkr/api
|
src/Http/Response.php
|
Response.withCollection
|
public function withCollection($collection, $transformer = null, $resourceKey = null)
{
return $this->respond(
$this->getCollection($collection, $transformer, $resourceKey)
);
}
|
php
|
public function withCollection($collection, $transformer = null, $resourceKey = null)
{
return $this->respond(
$this->getCollection($collection, $transformer, $resourceKey)
);
}
|
[
"public",
"function",
"withCollection",
"(",
"$",
"collection",
",",
"$",
"transformer",
"=",
"null",
",",
"$",
"resourceKey",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"respond",
"(",
"$",
"this",
"->",
"getCollection",
"(",
"$",
"collection",
",",
"$",
"transformer",
",",
"$",
"resourceKey",
")",
")",
";",
"}"
] |
Respond collection of resources.
@param IlluminateCollection|array $collection
@param null $transformer
@param string|null $resourceKey
@return \Illuminate\Contracts\Http\Response
|
[
"Respond",
"collection",
"of",
"resources",
"."
] |
5b676f6cf3bc74c9e429226c87505f7455700716
|
https://github.com/appkr/api/blob/5b676f6cf3bc74c9e429226c87505f7455700716/src/Http/Response.php#L112-L117
|
224,278
|
appkr/api
|
src/Http/Response.php
|
Response.getCollection
|
public function getCollection($collection, $transformer = null, $resourceKey = null)
{
$resource = new FractalCollection(
$collection,
$this->getTransformer($transformer),
$this->getResourceKey($resourceKey)
);
if ($meta = $this->getMeta()) {
$resource->setMeta($meta);
$this->meta = [];
}
return $this->fractal->createData($resource)->toArray();
}
|
php
|
public function getCollection($collection, $transformer = null, $resourceKey = null)
{
$resource = new FractalCollection(
$collection,
$this->getTransformer($transformer),
$this->getResourceKey($resourceKey)
);
if ($meta = $this->getMeta()) {
$resource->setMeta($meta);
$this->meta = [];
}
return $this->fractal->createData($resource)->toArray();
}
|
[
"public",
"function",
"getCollection",
"(",
"$",
"collection",
",",
"$",
"transformer",
"=",
"null",
",",
"$",
"resourceKey",
"=",
"null",
")",
"{",
"$",
"resource",
"=",
"new",
"FractalCollection",
"(",
"$",
"collection",
",",
"$",
"this",
"->",
"getTransformer",
"(",
"$",
"transformer",
")",
",",
"$",
"this",
"->",
"getResourceKey",
"(",
"$",
"resourceKey",
")",
")",
";",
"if",
"(",
"$",
"meta",
"=",
"$",
"this",
"->",
"getMeta",
"(",
")",
")",
"{",
"$",
"resource",
"->",
"setMeta",
"(",
"$",
"meta",
")",
";",
"$",
"this",
"->",
"meta",
"=",
"[",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"fractal",
"->",
"createData",
"(",
"$",
"resource",
")",
"->",
"toArray",
"(",
")",
";",
"}"
] |
Create FractalCollection payload.
@param IlluminateCollection|array $collection
@param null $transformer
@param string|null $resourceKey
@return mixed
|
[
"Create",
"FractalCollection",
"payload",
"."
] |
5b676f6cf3bc74c9e429226c87505f7455700716
|
https://github.com/appkr/api/blob/5b676f6cf3bc74c9e429226c87505f7455700716/src/Http/Response.php#L127-L141
|
224,279
|
appkr/api
|
src/Http/Response.php
|
Response.withItem
|
public function withItem(EloquentModel $model, $transformer = null, $resourceKey = null)
{
return $this->respond(
$this->getItem($model, $transformer, $resourceKey)
);
}
|
php
|
public function withItem(EloquentModel $model, $transformer = null, $resourceKey = null)
{
return $this->respond(
$this->getItem($model, $transformer, $resourceKey)
);
}
|
[
"public",
"function",
"withItem",
"(",
"EloquentModel",
"$",
"model",
",",
"$",
"transformer",
"=",
"null",
",",
"$",
"resourceKey",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"respond",
"(",
"$",
"this",
"->",
"getItem",
"(",
"$",
"model",
",",
"$",
"transformer",
",",
"$",
"resourceKey",
")",
")",
";",
"}"
] |
Respond single item.
@param \Illuminate\Database\Eloquent\Model $model
@param $transformer
@param string|null $resourceKey
@return \Illuminate\Contracts\Http\Response
|
[
"Respond",
"single",
"item",
"."
] |
5b676f6cf3bc74c9e429226c87505f7455700716
|
https://github.com/appkr/api/blob/5b676f6cf3bc74c9e429226c87505f7455700716/src/Http/Response.php#L151-L156
|
224,280
|
appkr/api
|
src/Http/Response.php
|
Response.getItem
|
public function getItem(EloquentModel $model, $transformer = null, $resourceKey = null)
{
$resource = new FractalItem(
$model,
$this->getTransformer($transformer),
$this->getResourceKey($resourceKey)
);
if ($meta = $this->getMeta()) {
$resource->setMeta($meta);
$this->meta = [];
}
return $this->fractal->createData($resource)->toArray();
}
|
php
|
public function getItem(EloquentModel $model, $transformer = null, $resourceKey = null)
{
$resource = new FractalItem(
$model,
$this->getTransformer($transformer),
$this->getResourceKey($resourceKey)
);
if ($meta = $this->getMeta()) {
$resource->setMeta($meta);
$this->meta = [];
}
return $this->fractal->createData($resource)->toArray();
}
|
[
"public",
"function",
"getItem",
"(",
"EloquentModel",
"$",
"model",
",",
"$",
"transformer",
"=",
"null",
",",
"$",
"resourceKey",
"=",
"null",
")",
"{",
"$",
"resource",
"=",
"new",
"FractalItem",
"(",
"$",
"model",
",",
"$",
"this",
"->",
"getTransformer",
"(",
"$",
"transformer",
")",
",",
"$",
"this",
"->",
"getResourceKey",
"(",
"$",
"resourceKey",
")",
")",
";",
"if",
"(",
"$",
"meta",
"=",
"$",
"this",
"->",
"getMeta",
"(",
")",
")",
"{",
"$",
"resource",
"->",
"setMeta",
"(",
"$",
"meta",
")",
";",
"$",
"this",
"->",
"meta",
"=",
"[",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"fractal",
"->",
"createData",
"(",
"$",
"resource",
")",
"->",
"toArray",
"(",
")",
";",
"}"
] |
Create FractalItem payload.
@param \Illuminate\Database\Eloquent\Model $model
@param null $transformer
@param string|null $resourceKey
@return mixed
|
[
"Create",
"FractalItem",
"payload",
"."
] |
5b676f6cf3bc74c9e429226c87505f7455700716
|
https://github.com/appkr/api/blob/5b676f6cf3bc74c9e429226c87505f7455700716/src/Http/Response.php#L166-L180
|
224,281
|
appkr/api
|
src/Http/Response.php
|
Response.withPagination
|
public function withPagination(LengthAwarePaginator $paginator, $transformer = null, $resourceKey = null)
{
return $this->respond(
$this->getPagination($paginator, $transformer, $resourceKey)
);
}
|
php
|
public function withPagination(LengthAwarePaginator $paginator, $transformer = null, $resourceKey = null)
{
return $this->respond(
$this->getPagination($paginator, $transformer, $resourceKey)
);
}
|
[
"public",
"function",
"withPagination",
"(",
"LengthAwarePaginator",
"$",
"paginator",
",",
"$",
"transformer",
"=",
"null",
",",
"$",
"resourceKey",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"respond",
"(",
"$",
"this",
"->",
"getPagination",
"(",
"$",
"paginator",
",",
"$",
"transformer",
",",
"$",
"resourceKey",
")",
")",
";",
"}"
] |
Respond collection of resources with pagination.
@param \Illuminate\Contracts\Pagination\LengthAwarePaginator $paginator
@param $transformer
@param string|null $resourceKey
@return \Illuminate\Contracts\Http\Response
|
[
"Respond",
"collection",
"of",
"resources",
"with",
"pagination",
"."
] |
5b676f6cf3bc74c9e429226c87505f7455700716
|
https://github.com/appkr/api/blob/5b676f6cf3bc74c9e429226c87505f7455700716/src/Http/Response.php#L190-L195
|
224,282
|
appkr/api
|
src/Http/Response.php
|
Response.getPagination
|
public function getPagination(LengthAwarePaginator $paginator, $transformer = null, $resourceKey = null)
{
// Append existing query parameter to pagination link
// @see http://fractal.thephpleague.com/pagination/#including-existing-query-string-values-in-pagination-links
$queryParams = array_diff_key($_GET, array_flip(['page']));
foreach ($queryParams as $key => $value) {
$paginator->appends($key, $value);
}
$collection = $paginator->getCollection();
$resource = new FractalCollection(
$collection,
$this->getTransformer($transformer),
$this->getResourceKey($resourceKey)
);
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
if ($meta = $this->getMeta()) {
$resource->setMeta($meta);
$this->meta = [];
}
return $this->fractal->createData($resource)->toArray();
}
|
php
|
public function getPagination(LengthAwarePaginator $paginator, $transformer = null, $resourceKey = null)
{
// Append existing query parameter to pagination link
// @see http://fractal.thephpleague.com/pagination/#including-existing-query-string-values-in-pagination-links
$queryParams = array_diff_key($_GET, array_flip(['page']));
foreach ($queryParams as $key => $value) {
$paginator->appends($key, $value);
}
$collection = $paginator->getCollection();
$resource = new FractalCollection(
$collection,
$this->getTransformer($transformer),
$this->getResourceKey($resourceKey)
);
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
if ($meta = $this->getMeta()) {
$resource->setMeta($meta);
$this->meta = [];
}
return $this->fractal->createData($resource)->toArray();
}
|
[
"public",
"function",
"getPagination",
"(",
"LengthAwarePaginator",
"$",
"paginator",
",",
"$",
"transformer",
"=",
"null",
",",
"$",
"resourceKey",
"=",
"null",
")",
"{",
"// Append existing query parameter to pagination link",
"// @see http://fractal.thephpleague.com/pagination/#including-existing-query-string-values-in-pagination-links",
"$",
"queryParams",
"=",
"array_diff_key",
"(",
"$",
"_GET",
",",
"array_flip",
"(",
"[",
"'page'",
"]",
")",
")",
";",
"foreach",
"(",
"$",
"queryParams",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"paginator",
"->",
"appends",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"$",
"collection",
"=",
"$",
"paginator",
"->",
"getCollection",
"(",
")",
";",
"$",
"resource",
"=",
"new",
"FractalCollection",
"(",
"$",
"collection",
",",
"$",
"this",
"->",
"getTransformer",
"(",
"$",
"transformer",
")",
",",
"$",
"this",
"->",
"getResourceKey",
"(",
"$",
"resourceKey",
")",
")",
";",
"$",
"resource",
"->",
"setPaginator",
"(",
"new",
"IlluminatePaginatorAdapter",
"(",
"$",
"paginator",
")",
")",
";",
"if",
"(",
"$",
"meta",
"=",
"$",
"this",
"->",
"getMeta",
"(",
")",
")",
"{",
"$",
"resource",
"->",
"setMeta",
"(",
"$",
"meta",
")",
";",
"$",
"this",
"->",
"meta",
"=",
"[",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"fractal",
"->",
"createData",
"(",
"$",
"resource",
")",
"->",
"toArray",
"(",
")",
";",
"}"
] |
Create FractalCollection payload with pagination.
@param \Illuminate\Contracts\Pagination\LengthAwarePaginator $paginator
@param null $transformer
@param string|null $resourceKey
@return mixed
|
[
"Create",
"FractalCollection",
"payload",
"with",
"pagination",
"."
] |
5b676f6cf3bc74c9e429226c87505f7455700716
|
https://github.com/appkr/api/blob/5b676f6cf3bc74c9e429226c87505f7455700716/src/Http/Response.php#L205-L230
|
224,283
|
appkr/api
|
src/Http/Response.php
|
Response.created
|
public function created($primitive = 'Created')
{
$payload = null;
if ($primitive instanceof EloquentModel) {
// If an Eloquent Model was passed as the $primitive argument,
// it just defer the job to respondItem() method.
// On receiving the job, respondItem() method does its best
// to transform the given Elequent Model with SimpleArrayTransformer.
return $this->setStatusCode(StatusCode::CREATED)->withItem($primitive);
}
return $this->setStatusCode(StatusCode::CREATED)->respond(
$this->format($primitive, config('api.successFormat'))
);
}
|
php
|
public function created($primitive = 'Created')
{
$payload = null;
if ($primitive instanceof EloquentModel) {
// If an Eloquent Model was passed as the $primitive argument,
// it just defer the job to respondItem() method.
// On receiving the job, respondItem() method does its best
// to transform the given Elequent Model with SimpleArrayTransformer.
return $this->setStatusCode(StatusCode::CREATED)->withItem($primitive);
}
return $this->setStatusCode(StatusCode::CREATED)->respond(
$this->format($primitive, config('api.successFormat'))
);
}
|
[
"public",
"function",
"created",
"(",
"$",
"primitive",
"=",
"'Created'",
")",
"{",
"$",
"payload",
"=",
"null",
";",
"if",
"(",
"$",
"primitive",
"instanceof",
"EloquentModel",
")",
"{",
"// If an Eloquent Model was passed as the $primitive argument,",
"// it just defer the job to respondItem() method.",
"// On receiving the job, respondItem() method does its best",
"// to transform the given Elequent Model with SimpleArrayTransformer.",
"return",
"$",
"this",
"->",
"setStatusCode",
"(",
"StatusCode",
"::",
"CREATED",
")",
"->",
"withItem",
"(",
"$",
"primitive",
")",
";",
"}",
"return",
"$",
"this",
"->",
"setStatusCode",
"(",
"StatusCode",
"::",
"CREATED",
")",
"->",
"respond",
"(",
"$",
"this",
"->",
"format",
"(",
"$",
"primitive",
",",
"config",
"(",
"'api.successFormat'",
")",
")",
")",
";",
"}"
] |
Respond 201.
@param mixed $primitive
@return $this
|
[
"Respond",
"201",
"."
] |
5b676f6cf3bc74c9e429226c87505f7455700716
|
https://github.com/appkr/api/blob/5b676f6cf3bc74c9e429226c87505f7455700716/src/Http/Response.php#L254-L269
|
224,284
|
appkr/api
|
src/Http/Response.php
|
Response.error
|
public function error($message = 'Unknown Error')
{
$format = config('api.errorFormat');
if ($message instanceof \Exception) {
if (config('api.debug') === true) {
$format['debug'] = [
'line' => $message->getLine(),
'file' => $message->getFile(),
'class' => get_class($message),
'trace' => explode("\n", $message->getTraceAsString()),
];
}
$this->statusCode = $this->translateExceptionCode($message);
$message = $message->getMessage();
}
return $this->respond(
$this->format($message, $format)
);
}
|
php
|
public function error($message = 'Unknown Error')
{
$format = config('api.errorFormat');
if ($message instanceof \Exception) {
if (config('api.debug') === true) {
$format['debug'] = [
'line' => $message->getLine(),
'file' => $message->getFile(),
'class' => get_class($message),
'trace' => explode("\n", $message->getTraceAsString()),
];
}
$this->statusCode = $this->translateExceptionCode($message);
$message = $message->getMessage();
}
return $this->respond(
$this->format($message, $format)
);
}
|
[
"public",
"function",
"error",
"(",
"$",
"message",
"=",
"'Unknown Error'",
")",
"{",
"$",
"format",
"=",
"config",
"(",
"'api.errorFormat'",
")",
";",
"if",
"(",
"$",
"message",
"instanceof",
"\\",
"Exception",
")",
"{",
"if",
"(",
"config",
"(",
"'api.debug'",
")",
"===",
"true",
")",
"{",
"$",
"format",
"[",
"'debug'",
"]",
"=",
"[",
"'line'",
"=>",
"$",
"message",
"->",
"getLine",
"(",
")",
",",
"'file'",
"=>",
"$",
"message",
"->",
"getFile",
"(",
")",
",",
"'class'",
"=>",
"get_class",
"(",
"$",
"message",
")",
",",
"'trace'",
"=>",
"explode",
"(",
"\"\\n\"",
",",
"$",
"message",
"->",
"getTraceAsString",
"(",
")",
")",
",",
"]",
";",
"}",
"$",
"this",
"->",
"statusCode",
"=",
"$",
"this",
"->",
"translateExceptionCode",
"(",
"$",
"message",
")",
";",
"$",
"message",
"=",
"$",
"message",
"->",
"getMessage",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"respond",
"(",
"$",
"this",
"->",
"format",
"(",
"$",
"message",
",",
"$",
"format",
")",
")",
";",
"}"
] |
Generic error response.
@api
@param mixed $message
@return $this
|
[
"Generic",
"error",
"response",
"."
] |
5b676f6cf3bc74c9e429226c87505f7455700716
|
https://github.com/appkr/api/blob/5b676f6cf3bc74c9e429226c87505f7455700716/src/Http/Response.php#L298-L319
|
224,285
|
appkr/api
|
src/Http/Response.php
|
Response.getHeaders
|
public function getHeaders()
{
$defaultHeaders = config('api.defaultHeaders');
return $defaultHeaders
? array_merge($defaultHeaders, $this->headers)
: $this->headers;
}
|
php
|
public function getHeaders()
{
$defaultHeaders = config('api.defaultHeaders');
return $defaultHeaders
? array_merge($defaultHeaders, $this->headers)
: $this->headers;
}
|
[
"public",
"function",
"getHeaders",
"(",
")",
"{",
"$",
"defaultHeaders",
"=",
"config",
"(",
"'api.defaultHeaders'",
")",
";",
"return",
"$",
"defaultHeaders",
"?",
"array_merge",
"(",
"$",
"defaultHeaders",
",",
"$",
"this",
"->",
"headers",
")",
":",
"$",
"this",
"->",
"headers",
";",
"}"
] |
Getter for headers property.
@return array
|
[
"Getter",
"for",
"headers",
"property",
"."
] |
5b676f6cf3bc74c9e429226c87505f7455700716
|
https://github.com/appkr/api/blob/5b676f6cf3bc74c9e429226c87505f7455700716/src/Http/Response.php#L472-L479
|
224,286
|
appkr/api
|
src/Http/Response.php
|
Response.setHeaders
|
public function setHeaders(array $headers)
{
if ($headers) {
$this->headers = array_merge($this->headers, $headers);
}
return $this;
}
|
php
|
public function setHeaders(array $headers)
{
if ($headers) {
$this->headers = array_merge($this->headers, $headers);
}
return $this;
}
|
[
"public",
"function",
"setHeaders",
"(",
"array",
"$",
"headers",
")",
"{",
"if",
"(",
"$",
"headers",
")",
"{",
"$",
"this",
"->",
"headers",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"headers",
",",
"$",
"headers",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Setter for headers property.
@param array $headers
@return $this
|
[
"Setter",
"for",
"headers",
"property",
"."
] |
5b676f6cf3bc74c9e429226c87505f7455700716
|
https://github.com/appkr/api/blob/5b676f6cf3bc74c9e429226c87505f7455700716/src/Http/Response.php#L487-L494
|
224,287
|
appkr/api
|
src/Http/Response.php
|
Response.format
|
public function format($message, array $format)
{
$replace = [
':message' => $message,
':code' => $this->getStatusCode(),
];
array_walk_recursive($format, function (&$value, $key) use ($replace) {
if (isset($replace[$value])) {
$value = $replace[$value];
}
});
return $format;
}
|
php
|
public function format($message, array $format)
{
$replace = [
':message' => $message,
':code' => $this->getStatusCode(),
];
array_walk_recursive($format, function (&$value, $key) use ($replace) {
if (isset($replace[$value])) {
$value = $replace[$value];
}
});
return $format;
}
|
[
"public",
"function",
"format",
"(",
"$",
"message",
",",
"array",
"$",
"format",
")",
"{",
"$",
"replace",
"=",
"[",
"':message'",
"=>",
"$",
"message",
",",
"':code'",
"=>",
"$",
"this",
"->",
"getStatusCode",
"(",
")",
",",
"]",
";",
"array_walk_recursive",
"(",
"$",
"format",
",",
"function",
"(",
"&",
"$",
"value",
",",
"$",
"key",
")",
"use",
"(",
"$",
"replace",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"replace",
"[",
"$",
"value",
"]",
")",
")",
"{",
"$",
"value",
"=",
"$",
"replace",
"[",
"$",
"value",
"]",
";",
"}",
"}",
")",
";",
"return",
"$",
"format",
";",
"}"
] |
Build response payload array based on configured format.
@param mixed $message
@param array $format
@return array
|
[
"Build",
"response",
"payload",
"array",
"based",
"on",
"configured",
"format",
"."
] |
5b676f6cf3bc74c9e429226c87505f7455700716
|
https://github.com/appkr/api/blob/5b676f6cf3bc74c9e429226c87505f7455700716/src/Http/Response.php#L537-L551
|
224,288
|
appkr/api
|
src/Http/Response.php
|
Response.translateExceptionCode
|
private function translateExceptionCode($e)
{
if (! in_array($e->getCode(), [0, -1, null, ''])) {
return $e->getCode();
}
if (method_exists($e, 'getStatusCode')) {
if (! in_array($e->getStatusCode(), [0, -1, null, ''])) {
return $e->getStatusCode();
}
if (($statusCode = $this->getStatusCode()) != StatusCode::OK) {
return $statusCode;
}
}
if ($e instanceof \Illuminate\Database\Eloquent\ModelNotFoundException
or $e instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
) {
return StatusCode::NOT_FOUND;
}
return StatusCode::BAD_REQUEST;
}
|
php
|
private function translateExceptionCode($e)
{
if (! in_array($e->getCode(), [0, -1, null, ''])) {
return $e->getCode();
}
if (method_exists($e, 'getStatusCode')) {
if (! in_array($e->getStatusCode(), [0, -1, null, ''])) {
return $e->getStatusCode();
}
if (($statusCode = $this->getStatusCode()) != StatusCode::OK) {
return $statusCode;
}
}
if ($e instanceof \Illuminate\Database\Eloquent\ModelNotFoundException
or $e instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
) {
return StatusCode::NOT_FOUND;
}
return StatusCode::BAD_REQUEST;
}
|
[
"private",
"function",
"translateExceptionCode",
"(",
"$",
"e",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"[",
"0",
",",
"-",
"1",
",",
"null",
",",
"''",
"]",
")",
")",
"{",
"return",
"$",
"e",
"->",
"getCode",
"(",
")",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"e",
",",
"'getStatusCode'",
")",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"e",
"->",
"getStatusCode",
"(",
")",
",",
"[",
"0",
",",
"-",
"1",
",",
"null",
",",
"''",
"]",
")",
")",
"{",
"return",
"$",
"e",
"->",
"getStatusCode",
"(",
")",
";",
"}",
"if",
"(",
"(",
"$",
"statusCode",
"=",
"$",
"this",
"->",
"getStatusCode",
"(",
")",
")",
"!=",
"StatusCode",
"::",
"OK",
")",
"{",
"return",
"$",
"statusCode",
";",
"}",
"}",
"if",
"(",
"$",
"e",
"instanceof",
"\\",
"Illuminate",
"\\",
"Database",
"\\",
"Eloquent",
"\\",
"ModelNotFoundException",
"or",
"$",
"e",
"instanceof",
"\\",
"Symfony",
"\\",
"Component",
"\\",
"HttpKernel",
"\\",
"Exception",
"\\",
"NotFoundHttpException",
")",
"{",
"return",
"StatusCode",
"::",
"NOT_FOUND",
";",
"}",
"return",
"StatusCode",
"::",
"BAD_REQUEST",
";",
"}"
] |
Translate http status code based on the given exception.
@param \Exception $e
@return int
|
[
"Translate",
"http",
"status",
"code",
"based",
"on",
"the",
"given",
"exception",
"."
] |
5b676f6cf3bc74c9e429226c87505f7455700716
|
https://github.com/appkr/api/blob/5b676f6cf3bc74c9e429226c87505f7455700716/src/Http/Response.php#L588-L611
|
224,289
|
JeffreyHyer/bamboohr
|
src/Api/Employees.php
|
Employees.byId
|
public function byId($id, $fields = null)
{
if (is_null($fields)) {
$fields = self::$defaultFields;
}
return $this->get("employees/{$id}/", ['fields' => implode(',', $fields)]);
}
|
php
|
public function byId($id, $fields = null)
{
if (is_null($fields)) {
$fields = self::$defaultFields;
}
return $this->get("employees/{$id}/", ['fields' => implode(',', $fields)]);
}
|
[
"public",
"function",
"byId",
"(",
"$",
"id",
",",
"$",
"fields",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"fields",
"=",
"self",
"::",
"$",
"defaultFields",
";",
"}",
"return",
"$",
"this",
"->",
"get",
"(",
"\"employees/{$id}/\"",
",",
"[",
"'fields'",
"=>",
"implode",
"(",
"','",
",",
"$",
"fields",
")",
"]",
")",
";",
"}"
] |
Returns an employee identified by the given ID
@param string $id
@param array $fields
@return \BambooHR\Api\Response
|
[
"Returns",
"an",
"employee",
"identified",
"by",
"the",
"given",
"ID"
] |
bdf8beab6573a818e906e4f0a3516b68f37c3b17
|
https://github.com/JeffreyHyer/bamboohr/blob/bdf8beab6573a818e906e4f0a3516b68f37c3b17/src/Api/Employees.php#L104-L111
|
224,290
|
JeffreyHyer/bamboohr
|
src/Api/Employees.php
|
Employees.add
|
public function add(array $fields)
{
$xml = "<employee>";
foreach ($fields as $field => $value) {
$xml .= "<field id=\"{$field}\">{$value}</field>";
}
$xml .= "</employee>";
return $this->post("employees", $xml);
}
|
php
|
public function add(array $fields)
{
$xml = "<employee>";
foreach ($fields as $field => $value) {
$xml .= "<field id=\"{$field}\">{$value}</field>";
}
$xml .= "</employee>";
return $this->post("employees", $xml);
}
|
[
"public",
"function",
"add",
"(",
"array",
"$",
"fields",
")",
"{",
"$",
"xml",
"=",
"\"<employee>\"",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"$",
"xml",
".=",
"\"<field id=\\\"{$field}\\\">{$value}</field>\"",
";",
"}",
"$",
"xml",
".=",
"\"</employee>\"",
";",
"return",
"$",
"this",
"->",
"post",
"(",
"\"employees\"",
",",
"$",
"xml",
")",
";",
"}"
] |
Add a new employee
@param array $fields
@return \BambooHR\Api\Response
|
[
"Add",
"a",
"new",
"employee"
] |
bdf8beab6573a818e906e4f0a3516b68f37c3b17
|
https://github.com/JeffreyHyer/bamboohr/blob/bdf8beab6573a818e906e4f0a3516b68f37c3b17/src/Api/Employees.php#L130-L141
|
224,291
|
JeffreyHyer/bamboohr
|
src/Api/Employees.php
|
Employees.update
|
public function update($id, array $fields)
{
$xml = "<employee>";
foreach ($fields as $field => $value) {
$xml .= "<field id=\"{$field}\">{$value}</field>";
}
$xml .= "</employee>";
return $this->post("employees/{$id}", $xml);
}
|
php
|
public function update($id, array $fields)
{
$xml = "<employee>";
foreach ($fields as $field => $value) {
$xml .= "<field id=\"{$field}\">{$value}</field>";
}
$xml .= "</employee>";
return $this->post("employees/{$id}", $xml);
}
|
[
"public",
"function",
"update",
"(",
"$",
"id",
",",
"array",
"$",
"fields",
")",
"{",
"$",
"xml",
"=",
"\"<employee>\"",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"$",
"xml",
".=",
"\"<field id=\\\"{$field}\\\">{$value}</field>\"",
";",
"}",
"$",
"xml",
".=",
"\"</employee>\"",
";",
"return",
"$",
"this",
"->",
"post",
"(",
"\"employees/{$id}\"",
",",
"$",
"xml",
")",
";",
"}"
] |
Update an existing employee identified by their ID
@param string $id
@param array $fields
@return \BambooHR\Api\Response
|
[
"Update",
"an",
"existing",
"employee",
"identified",
"by",
"their",
"ID"
] |
bdf8beab6573a818e906e4f0a3516b68f37c3b17
|
https://github.com/JeffreyHyer/bamboohr/blob/bdf8beab6573a818e906e4f0a3516b68f37c3b17/src/Api/Employees.php#L151-L162
|
224,292
|
JeffreyHyer/bamboohr
|
src/Api/Employees.php
|
Employees.import
|
public function import(array $data)
{
$xml = "<employees>";
foreach ($data as $user) {
$xml .= "<employee";
$xml .= (isset($user['number']) ? " number=\"{$user['number']}\">" : ">");
foreach ($user as $key => $value) {
if ($key == "number") {
continue;
}
if (is_array($value)) {
$xml .= "<{$key}>";
foreach ($value as $vKey => $vValue) {
$xml .= "<{$vKey}>{$vValue}</{$vKey}>";
}
$xml .= "</{$key}>";
} else {
$xml .= "<{$key}>{$value}</{$key}>";
}
}
$xml .= "</employee>";
}
$xml .= "</employees>";
return $this->post("employees/import", $xml);
}
|
php
|
public function import(array $data)
{
$xml = "<employees>";
foreach ($data as $user) {
$xml .= "<employee";
$xml .= (isset($user['number']) ? " number=\"{$user['number']}\">" : ">");
foreach ($user as $key => $value) {
if ($key == "number") {
continue;
}
if (is_array($value)) {
$xml .= "<{$key}>";
foreach ($value as $vKey => $vValue) {
$xml .= "<{$vKey}>{$vValue}</{$vKey}>";
}
$xml .= "</{$key}>";
} else {
$xml .= "<{$key}>{$value}</{$key}>";
}
}
$xml .= "</employee>";
}
$xml .= "</employees>";
return $this->post("employees/import", $xml);
}
|
[
"public",
"function",
"import",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"xml",
"=",
"\"<employees>\"",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"user",
")",
"{",
"$",
"xml",
".=",
"\"<employee\"",
";",
"$",
"xml",
".=",
"(",
"isset",
"(",
"$",
"user",
"[",
"'number'",
"]",
")",
"?",
"\" number=\\\"{$user['number']}\\\">\"",
":",
"\">\"",
")",
";",
"foreach",
"(",
"$",
"user",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"key",
"==",
"\"number\"",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"xml",
".=",
"\"<{$key}>\"",
";",
"foreach",
"(",
"$",
"value",
"as",
"$",
"vKey",
"=>",
"$",
"vValue",
")",
"{",
"$",
"xml",
".=",
"\"<{$vKey}>{$vValue}</{$vKey}>\"",
";",
"}",
"$",
"xml",
".=",
"\"</{$key}>\"",
";",
"}",
"else",
"{",
"$",
"xml",
".=",
"\"<{$key}>{$value}</{$key}>\"",
";",
"}",
"}",
"$",
"xml",
".=",
"\"</employee>\"",
";",
"}",
"$",
"xml",
".=",
"\"</employees>\"",
";",
"return",
"$",
"this",
"->",
"post",
"(",
"\"employees/import\"",
",",
"$",
"xml",
")",
";",
"}"
] |
An undocumented BambooHR API endpoint for
bulk importing employees.
NOTES:
- This method is untested. Use are your own risk.
- There is some limitations with this implementation of XML
generation. For example, it does not support tag attributes
on nested elements (within the <employee> element). It may or
may not be an issue depending on your use case.
e.g. use of `<termDate isNull="true"></termDate>` wouldn't work
@link https://github.com/BambooHR/bhr-api-php/blob/master/BambooHR/API/API.php#L954
@link https://github.com/BambooHR/bhr-api-php/blob/master/test_import.xml
@param array $data [[_employee_], ...]
@return BambooHR\Api\Response
|
[
"An",
"undocumented",
"BambooHR",
"API",
"endpoint",
"for",
"bulk",
"importing",
"employees",
"."
] |
bdf8beab6573a818e906e4f0a3516b68f37c3b17
|
https://github.com/JeffreyHyer/bamboohr/blob/bdf8beab6573a818e906e4f0a3516b68f37c3b17/src/Api/Employees.php#L280-L312
|
224,293
|
appkr/api
|
src/Http/ResponseFactory.php
|
ResponseFactory.make
|
public function make()
{
if (is_lumen()) {
return new \Laravel\Lumen\Http\ResponseFactory();
}
return app(\Illuminate\Contracts\Routing\ResponseFactory::class);
}
|
php
|
public function make()
{
if (is_lumen()) {
return new \Laravel\Lumen\Http\ResponseFactory();
}
return app(\Illuminate\Contracts\Routing\ResponseFactory::class);
}
|
[
"public",
"function",
"make",
"(",
")",
"{",
"if",
"(",
"is_lumen",
"(",
")",
")",
"{",
"return",
"new",
"\\",
"Laravel",
"\\",
"Lumen",
"\\",
"Http",
"\\",
"ResponseFactory",
"(",
")",
";",
"}",
"return",
"app",
"(",
"\\",
"Illuminate",
"\\",
"Contracts",
"\\",
"Routing",
"\\",
"ResponseFactory",
"::",
"class",
")",
";",
"}"
] |
Create an instance of Laravel or Lumen ResponseFactory
@return \Laravel\Lumen\Http\ResponseFactory
|
[
"Create",
"an",
"instance",
"of",
"Laravel",
"or",
"Lumen",
"ResponseFactory"
] |
5b676f6cf3bc74c9e429226c87505f7455700716
|
https://github.com/appkr/api/blob/5b676f6cf3bc74c9e429226c87505f7455700716/src/Http/ResponseFactory.php#L12-L19
|
224,294
|
logical-and/php-oauth
|
src/OAuth2/Service/AbstractService.php
|
AbstractService.isValidScope
|
public function isValidScope($scope)
{
$reflectionClass = new \ReflectionClass(get_class($this));
return in_array($scope, $reflectionClass->getConstants(), true);
}
|
php
|
public function isValidScope($scope)
{
$reflectionClass = new \ReflectionClass(get_class($this));
return in_array($scope, $reflectionClass->getConstants(), true);
}
|
[
"public",
"function",
"isValidScope",
"(",
"$",
"scope",
")",
"{",
"$",
"reflectionClass",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"get_class",
"(",
"$",
"this",
")",
")",
";",
"return",
"in_array",
"(",
"$",
"scope",
",",
"$",
"reflectionClass",
"->",
"getConstants",
"(",
")",
",",
"true",
")",
";",
"}"
] |
Return whether or not the passed scope value is valid.
@param string $scope
@return bool
|
[
"Return",
"whether",
"or",
"not",
"the",
"passed",
"scope",
"value",
"is",
"valid",
"."
] |
48fa6e74b147f5a689cb6a03dcf9ea67d1d98bbf
|
https://github.com/logical-and/php-oauth/blob/48fa6e74b147f5a689cb6a03dcf9ea67d1d98bbf/src/OAuth2/Service/AbstractService.php#L256-L261
|
224,295
|
yosymfony/HttpServer
|
src/RequestHandler.php
|
RequestHandler.listen
|
public function listen($port, $host = '0.0.0.0')
{
$this->port = $port;
$this->host = $host;
return $this;
}
|
php
|
public function listen($port, $host = '0.0.0.0')
{
$this->port = $port;
$this->host = $host;
return $this;
}
|
[
"public",
"function",
"listen",
"(",
"$",
"port",
",",
"$",
"host",
"=",
"'0.0.0.0'",
")",
"{",
"$",
"this",
"->",
"port",
"=",
"$",
"port",
";",
"$",
"this",
"->",
"host",
"=",
"$",
"host",
";",
"return",
"$",
"this",
";",
"}"
] |
Setup for listen requests
@param int $port
@param string $host
@return RequestHandler
|
[
"Setup",
"for",
"listen",
"requests"
] |
7c145578044cffe2b1f0f3d3ec3c6829d73f7719
|
https://github.com/yosymfony/HttpServer/blob/7c145578044cffe2b1f0f3d3ec3c6829d73f7719/src/RequestHandler.php#L52-L58
|
224,296
|
turtledesign/royalmail-php
|
src/RoyalMail.php
|
RoyalMail.getConnector
|
function getConnector() {
if (empty($this->connector)) $this->connector = new Connector($this->config);
return $this->connector;
}
|
php
|
function getConnector() {
if (empty($this->connector)) $this->connector = new Connector($this->config);
return $this->connector;
}
|
[
"function",
"getConnector",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"connector",
")",
")",
"$",
"this",
"->",
"connector",
"=",
"new",
"Connector",
"(",
"$",
"this",
"->",
"config",
")",
";",
"return",
"$",
"this",
"->",
"connector",
";",
"}"
] |
Get the appropriate connector class
@return \RoyalMail\Connector\baseConnector Variation on...
|
[
"Get",
"the",
"appropriate",
"connector",
"class"
] |
750c4277bcff5466ac73927ece8aae439b74efde
|
https://github.com/turtledesign/royalmail-php/blob/750c4277bcff5466ac73927ece8aae439b74efde/src/RoyalMail.php#L113-L117
|
224,297
|
turtledesign/royalmail-php
|
src/RoyalMail.php
|
RoyalMail.configure
|
function configure($config = []) {
$this->config = array_replace_recursive($this->config, $this->modes[@$config['mode'] ?: $this->config['mode']]);
$this->config = array_replace_recursive($this->config, $config);
return $this;
}
|
php
|
function configure($config = []) {
$this->config = array_replace_recursive($this->config, $this->modes[@$config['mode'] ?: $this->config['mode']]);
$this->config = array_replace_recursive($this->config, $config);
return $this;
}
|
[
"function",
"configure",
"(",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"config",
"=",
"array_replace_recursive",
"(",
"$",
"this",
"->",
"config",
",",
"$",
"this",
"->",
"modes",
"[",
"@",
"$",
"config",
"[",
"'mode'",
"]",
"?",
":",
"$",
"this",
"->",
"config",
"[",
"'mode'",
"]",
"]",
")",
";",
"$",
"this",
"->",
"config",
"=",
"array_replace_recursive",
"(",
"$",
"this",
"->",
"config",
",",
"$",
"config",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Set up config values, these are merged with the defaults.
@param array
@return RoyalMail\RoyalMail $this
|
[
"Set",
"up",
"config",
"values",
"these",
"are",
"merged",
"with",
"the",
"defaults",
"."
] |
750c4277bcff5466ac73927ece8aae439b74efde
|
https://github.com/turtledesign/royalmail-php/blob/750c4277bcff5466ac73927ece8aae439b74efde/src/RoyalMail.php#L134-L140
|
224,298
|
logical-and/php-oauth
|
src/UserData/Arguments/LoadersMap.php
|
LoadersMap.addField
|
public function addField($field)
{
$this->checkValidLoader();
if (!is_string($field)) {
throw new GenericException('Must be string!');
}
$this->loaders[ $this->contextLoader ][ ] = $field;
return $this;
}
|
php
|
public function addField($field)
{
$this->checkValidLoader();
if (!is_string($field)) {
throw new GenericException('Must be string!');
}
$this->loaders[ $this->contextLoader ][ ] = $field;
return $this;
}
|
[
"public",
"function",
"addField",
"(",
"$",
"field",
")",
"{",
"$",
"this",
"->",
"checkValidLoader",
"(",
")",
";",
"if",
"(",
"!",
"is_string",
"(",
"$",
"field",
")",
")",
"{",
"throw",
"new",
"GenericException",
"(",
"'Must be string!'",
")",
";",
"}",
"$",
"this",
"->",
"loaders",
"[",
"$",
"this",
"->",
"contextLoader",
"]",
"[",
"]",
"=",
"$",
"field",
";",
"return",
"$",
"this",
";",
"}"
] |
Add field to context loader
@param string $field
@throws GenericException
@return $this
|
[
"Add",
"field",
"to",
"context",
"loader"
] |
48fa6e74b147f5a689cb6a03dcf9ea67d1d98bbf
|
https://github.com/logical-and/php-oauth/blob/48fa6e74b147f5a689cb6a03dcf9ea67d1d98bbf/src/UserData/Arguments/LoadersMap.php#L66-L76
|
224,299
|
logical-and/php-oauth
|
src/UserData/Arguments/LoadersMap.php
|
LoadersMap.setFields
|
public function setFields(array $fields)
{
$this->checkValidLoader();
// Flatten
$this->loaders[ $this->contextLoader ] = [];
$this->addFields($fields);
return $this;
}
|
php
|
public function setFields(array $fields)
{
$this->checkValidLoader();
// Flatten
$this->loaders[ $this->contextLoader ] = [];
$this->addFields($fields);
return $this;
}
|
[
"public",
"function",
"setFields",
"(",
"array",
"$",
"fields",
")",
"{",
"$",
"this",
"->",
"checkValidLoader",
"(",
")",
";",
"// Flatten",
"$",
"this",
"->",
"loaders",
"[",
"$",
"this",
"->",
"contextLoader",
"]",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"addFields",
"(",
"$",
"fields",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Set fields to context loader
@param array $fields
@return $this
|
[
"Set",
"fields",
"to",
"context",
"loader"
] |
48fa6e74b147f5a689cb6a03dcf9ea67d1d98bbf
|
https://github.com/logical-and/php-oauth/blob/48fa6e74b147f5a689cb6a03dcf9ea67d1d98bbf/src/UserData/Arguments/LoadersMap.php#L101-L110
|
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.