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,100
|
sulu/SuluProductBundle
|
Product/ProductAttributeManager.php
|
ProductAttributeManager.createProductAttribute
|
public function createProductAttribute(
Attribute $attribute,
ProductInterface $product,
AttributeValue $attributeValue
) {
$productAttribute = $this->productAttributeRepository->createNew();
$productAttribute->setAttribute($attribute);
$productAttribute->setProduct($product);
$productAttribute->setAttributeValue($attributeValue);
$this->entityManager->persist($productAttribute);
$product->addProductAttribute($productAttribute);
return $productAttribute;
}
|
php
|
public function createProductAttribute(
Attribute $attribute,
ProductInterface $product,
AttributeValue $attributeValue
) {
$productAttribute = $this->productAttributeRepository->createNew();
$productAttribute->setAttribute($attribute);
$productAttribute->setProduct($product);
$productAttribute->setAttributeValue($attributeValue);
$this->entityManager->persist($productAttribute);
$product->addProductAttribute($productAttribute);
return $productAttribute;
}
|
[
"public",
"function",
"createProductAttribute",
"(",
"Attribute",
"$",
"attribute",
",",
"ProductInterface",
"$",
"product",
",",
"AttributeValue",
"$",
"attributeValue",
")",
"{",
"$",
"productAttribute",
"=",
"$",
"this",
"->",
"productAttributeRepository",
"->",
"createNew",
"(",
")",
";",
"$",
"productAttribute",
"->",
"setAttribute",
"(",
"$",
"attribute",
")",
";",
"$",
"productAttribute",
"->",
"setProduct",
"(",
"$",
"product",
")",
";",
"$",
"productAttribute",
"->",
"setAttributeValue",
"(",
"$",
"attributeValue",
")",
";",
"$",
"this",
"->",
"entityManager",
"->",
"persist",
"(",
"$",
"productAttribute",
")",
";",
"$",
"product",
"->",
"addProductAttribute",
"(",
"$",
"productAttribute",
")",
";",
"return",
"$",
"productAttribute",
";",
"}"
] |
Creates a new ProductAttribute relation.
@param Attribute $attribute
@param ProductInterface $product
@param AttributeValue $attributeValue
@return ProductAttribute
|
[
"Creates",
"a",
"new",
"ProductAttribute",
"relation",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductAttributeManager.php#L76-L90
|
224,101
|
sulu/SuluProductBundle
|
Product/ProductAttributeManager.php
|
ProductAttributeManager.createAttributeValue
|
public function createAttributeValue(Attribute $attribute, $value, $locale)
{
$attributeValue = $this->attributeValueRepository->createNew();
$attributeValue->setAttribute($attribute);
$this->entityManager->persist($attributeValue);
$attribute->addValue($attributeValue);
$this->setOrCreateAttributeValueTranslation($attributeValue, $value, $locale);
return $attributeValue;
}
|
php
|
public function createAttributeValue(Attribute $attribute, $value, $locale)
{
$attributeValue = $this->attributeValueRepository->createNew();
$attributeValue->setAttribute($attribute);
$this->entityManager->persist($attributeValue);
$attribute->addValue($attributeValue);
$this->setOrCreateAttributeValueTranslation($attributeValue, $value, $locale);
return $attributeValue;
}
|
[
"public",
"function",
"createAttributeValue",
"(",
"Attribute",
"$",
"attribute",
",",
"$",
"value",
",",
"$",
"locale",
")",
"{",
"$",
"attributeValue",
"=",
"$",
"this",
"->",
"attributeValueRepository",
"->",
"createNew",
"(",
")",
";",
"$",
"attributeValue",
"->",
"setAttribute",
"(",
"$",
"attribute",
")",
";",
"$",
"this",
"->",
"entityManager",
"->",
"persist",
"(",
"$",
"attributeValue",
")",
";",
"$",
"attribute",
"->",
"addValue",
"(",
"$",
"attributeValue",
")",
";",
"$",
"this",
"->",
"setOrCreateAttributeValueTranslation",
"(",
"$",
"attributeValue",
",",
"$",
"value",
",",
"$",
"locale",
")",
";",
"return",
"$",
"attributeValue",
";",
"}"
] |
Creates a new attribute value and its translation in the specified locale.
@param Attribute $attribute
@param string $value
@param string $locale
@return AttributeValue
|
[
"Creates",
"a",
"new",
"attribute",
"value",
"and",
"its",
"translation",
"in",
"the",
"specified",
"locale",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductAttributeManager.php#L101-L110
|
224,102
|
sulu/SuluProductBundle
|
Product/ProductAttributeManager.php
|
ProductAttributeManager.setOrCreateAttributeValueTranslation
|
public function setOrCreateAttributeValueTranslation(AttributeValue $attributeValue, $value, $locale)
{
// Check if translation already exists for given locale.
$attributeValueTranslation = null;
/** @var AttributeValueTranslation $translation */
foreach ($attributeValue->getTranslations() as $translation) {
if ($translation->getLocale() === $locale) {
$attributeValueTranslation = $translation;
}
}
if (!$attributeValueTranslation) {
// Create a new attribute value translation.
$attributeValueTranslation = $this->attributeValueTranslationRepository->createNew();
$this->entityManager->persist($attributeValueTranslation);
$attributeValueTranslation->setLocale($locale);
$attributeValueTranslation->setAttributeValue($attributeValue);
$attributeValue->addTranslation($attributeValueTranslation);
}
$attributeValueTranslation->setName($value);
return $attributeValueTranslation;
}
|
php
|
public function setOrCreateAttributeValueTranslation(AttributeValue $attributeValue, $value, $locale)
{
// Check if translation already exists for given locale.
$attributeValueTranslation = null;
/** @var AttributeValueTranslation $translation */
foreach ($attributeValue->getTranslations() as $translation) {
if ($translation->getLocale() === $locale) {
$attributeValueTranslation = $translation;
}
}
if (!$attributeValueTranslation) {
// Create a new attribute value translation.
$attributeValueTranslation = $this->attributeValueTranslationRepository->createNew();
$this->entityManager->persist($attributeValueTranslation);
$attributeValueTranslation->setLocale($locale);
$attributeValueTranslation->setAttributeValue($attributeValue);
$attributeValue->addTranslation($attributeValueTranslation);
}
$attributeValueTranslation->setName($value);
return $attributeValueTranslation;
}
|
[
"public",
"function",
"setOrCreateAttributeValueTranslation",
"(",
"AttributeValue",
"$",
"attributeValue",
",",
"$",
"value",
",",
"$",
"locale",
")",
"{",
"// Check if translation already exists for given locale.",
"$",
"attributeValueTranslation",
"=",
"null",
";",
"/** @var AttributeValueTranslation $translation */",
"foreach",
"(",
"$",
"attributeValue",
"->",
"getTranslations",
"(",
")",
"as",
"$",
"translation",
")",
"{",
"if",
"(",
"$",
"translation",
"->",
"getLocale",
"(",
")",
"===",
"$",
"locale",
")",
"{",
"$",
"attributeValueTranslation",
"=",
"$",
"translation",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"attributeValueTranslation",
")",
"{",
"// Create a new attribute value translation.",
"$",
"attributeValueTranslation",
"=",
"$",
"this",
"->",
"attributeValueTranslationRepository",
"->",
"createNew",
"(",
")",
";",
"$",
"this",
"->",
"entityManager",
"->",
"persist",
"(",
"$",
"attributeValueTranslation",
")",
";",
"$",
"attributeValueTranslation",
"->",
"setLocale",
"(",
"$",
"locale",
")",
";",
"$",
"attributeValueTranslation",
"->",
"setAttributeValue",
"(",
"$",
"attributeValue",
")",
";",
"$",
"attributeValue",
"->",
"addTranslation",
"(",
"$",
"attributeValueTranslation",
")",
";",
"}",
"$",
"attributeValueTranslation",
"->",
"setName",
"(",
"$",
"value",
")",
";",
"return",
"$",
"attributeValueTranslation",
";",
"}"
] |
Checks if AttributeValue already contains a translation in given locale or creates a new one.
@param AttributeValue $attributeValue
@param string $value
@param string $locale
@return AttributeValueTranslation
|
[
"Checks",
"if",
"AttributeValue",
"already",
"contains",
"a",
"translation",
"in",
"given",
"locale",
"or",
"creates",
"a",
"new",
"one",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductAttributeManager.php#L121-L142
|
224,103
|
sulu/SuluProductBundle
|
Product/ProductAttributeManager.php
|
ProductAttributeManager.removeAttributeValueTranslation
|
public function removeAttributeValueTranslation(AttributeValue $attributeValue, $locale)
{
// Check if translation already exists for given locale.
$attributeValueTranslation = $this->retrieveAttributeValueTranslationByLocale($attributeValue, $locale);
if ($attributeValueTranslation) {
$attributeValue->removeTranslation($attributeValueTranslation);
$this->entityManager->remove($attributeValueTranslation);
}
}
|
php
|
public function removeAttributeValueTranslation(AttributeValue $attributeValue, $locale)
{
// Check if translation already exists for given locale.
$attributeValueTranslation = $this->retrieveAttributeValueTranslationByLocale($attributeValue, $locale);
if ($attributeValueTranslation) {
$attributeValue->removeTranslation($attributeValueTranslation);
$this->entityManager->remove($attributeValueTranslation);
}
}
|
[
"public",
"function",
"removeAttributeValueTranslation",
"(",
"AttributeValue",
"$",
"attributeValue",
",",
"$",
"locale",
")",
"{",
"// Check if translation already exists for given locale.",
"$",
"attributeValueTranslation",
"=",
"$",
"this",
"->",
"retrieveAttributeValueTranslationByLocale",
"(",
"$",
"attributeValue",
",",
"$",
"locale",
")",
";",
"if",
"(",
"$",
"attributeValueTranslation",
")",
"{",
"$",
"attributeValue",
"->",
"removeTranslation",
"(",
"$",
"attributeValueTranslation",
")",
";",
"$",
"this",
"->",
"entityManager",
"->",
"remove",
"(",
"$",
"attributeValueTranslation",
")",
";",
"}",
"}"
] |
Removes attribute value translation in given locale from given attribute.
@param AttributeValue $attributeValue
@param string $locale
|
[
"Removes",
"attribute",
"value",
"translation",
"in",
"given",
"locale",
"from",
"given",
"attribute",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductAttributeManager.php#L150-L158
|
224,104
|
sulu/SuluProductBundle
|
Product/ProductAttributeManager.php
|
ProductAttributeManager.removeAllAttributeValueTranslations
|
public function removeAllAttributeValueTranslations(AttributeValue $attributeValue)
{
// Check if translation already exists for given locale.
/** @var AttributeValueTranslation $attributeValueTranslation */
foreach ($attributeValue->getTranslations() as $attributeValueTranslation) {
$attributeValue->removeTranslation($attributeValueTranslation);
$this->entityManager->remove($attributeValueTranslation);
}
}
|
php
|
public function removeAllAttributeValueTranslations(AttributeValue $attributeValue)
{
// Check if translation already exists for given locale.
/** @var AttributeValueTranslation $attributeValueTranslation */
foreach ($attributeValue->getTranslations() as $attributeValueTranslation) {
$attributeValue->removeTranslation($attributeValueTranslation);
$this->entityManager->remove($attributeValueTranslation);
}
}
|
[
"public",
"function",
"removeAllAttributeValueTranslations",
"(",
"AttributeValue",
"$",
"attributeValue",
")",
"{",
"// Check if translation already exists for given locale.",
"/** @var AttributeValueTranslation $attributeValueTranslation */",
"foreach",
"(",
"$",
"attributeValue",
"->",
"getTranslations",
"(",
")",
"as",
"$",
"attributeValueTranslation",
")",
"{",
"$",
"attributeValue",
"->",
"removeTranslation",
"(",
"$",
"attributeValueTranslation",
")",
";",
"$",
"this",
"->",
"entityManager",
"->",
"remove",
"(",
"$",
"attributeValueTranslation",
")",
";",
"}",
"}"
] |
Removes all attribute value translations from given attribute.
@param AttributeValue $attributeValue
|
[
"Removes",
"all",
"attribute",
"value",
"translations",
"from",
"given",
"attribute",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductAttributeManager.php#L165-L173
|
224,105
|
sulu/SuluProductBundle
|
Product/ProductAttributeManager.php
|
ProductAttributeManager.updateOrCreateProductAttributeForProduct
|
public function updateOrCreateProductAttributeForProduct(
ProductInterface $product,
Attribute $attribute,
array $attributeData,
$locale
) {
// Check if ProductAttribute already exists for attribute
$existingProductAttribute = $this->retrieveProductAttributeByAttribute(
$product,
$attribute
);
// If product-attribute already exists we just need to update the translation.
if ($existingProductAttribute) {
$this->setOrCreateAttributeValueTranslation(
$existingProductAttribute->getAttributeValue(),
$attributeData['attributeValueName'],
$locale
);
return;
}
// Create new AttributeValue and ProductAttribute.
$attributeValue = $this->createAttributeValue(
$attribute,
$attributeData['attributeValueName'],
$locale
);
$this->createProductAttribute(
$attribute,
$product,
$attributeValue
);
}
|
php
|
public function updateOrCreateProductAttributeForProduct(
ProductInterface $product,
Attribute $attribute,
array $attributeData,
$locale
) {
// Check if ProductAttribute already exists for attribute
$existingProductAttribute = $this->retrieveProductAttributeByAttribute(
$product,
$attribute
);
// If product-attribute already exists we just need to update the translation.
if ($existingProductAttribute) {
$this->setOrCreateAttributeValueTranslation(
$existingProductAttribute->getAttributeValue(),
$attributeData['attributeValueName'],
$locale
);
return;
}
// Create new AttributeValue and ProductAttribute.
$attributeValue = $this->createAttributeValue(
$attribute,
$attributeData['attributeValueName'],
$locale
);
$this->createProductAttribute(
$attribute,
$product,
$attributeValue
);
}
|
[
"public",
"function",
"updateOrCreateProductAttributeForProduct",
"(",
"ProductInterface",
"$",
"product",
",",
"Attribute",
"$",
"attribute",
",",
"array",
"$",
"attributeData",
",",
"$",
"locale",
")",
"{",
"// Check if ProductAttribute already exists for attribute",
"$",
"existingProductAttribute",
"=",
"$",
"this",
"->",
"retrieveProductAttributeByAttribute",
"(",
"$",
"product",
",",
"$",
"attribute",
")",
";",
"// If product-attribute already exists we just need to update the translation.",
"if",
"(",
"$",
"existingProductAttribute",
")",
"{",
"$",
"this",
"->",
"setOrCreateAttributeValueTranslation",
"(",
"$",
"existingProductAttribute",
"->",
"getAttributeValue",
"(",
")",
",",
"$",
"attributeData",
"[",
"'attributeValueName'",
"]",
",",
"$",
"locale",
")",
";",
"return",
";",
"}",
"// Create new AttributeValue and ProductAttribute.",
"$",
"attributeValue",
"=",
"$",
"this",
"->",
"createAttributeValue",
"(",
"$",
"attribute",
",",
"$",
"attributeData",
"[",
"'attributeValueName'",
"]",
",",
"$",
"locale",
")",
";",
"$",
"this",
"->",
"createProductAttribute",
"(",
"$",
"attribute",
",",
"$",
"product",
",",
"$",
"attributeValue",
")",
";",
"}"
] |
Updates or creates a the product attribute relation for the given product.
@param ProductInterface $product
@param Attribute $attribute
@param array $attributeData
@param string $locale
|
[
"Updates",
"or",
"creates",
"a",
"the",
"product",
"attribute",
"relation",
"for",
"the",
"given",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductAttributeManager.php#L183-L217
|
224,106
|
sulu/SuluProductBundle
|
Product/ProductAttributeManager.php
|
ProductAttributeManager.retrieveProductAttributeByAttribute
|
public function retrieveProductAttributeByAttribute(ProductInterface $product, Attribute $attribute)
{
foreach ($product->getProductAttributes() as $productAttribute) {
if ($productAttribute->getAttribute()->getId() === $attribute->getId()) {
return $productAttribute;
}
}
return null;
}
|
php
|
public function retrieveProductAttributeByAttribute(ProductInterface $product, Attribute $attribute)
{
foreach ($product->getProductAttributes() as $productAttribute) {
if ($productAttribute->getAttribute()->getId() === $attribute->getId()) {
return $productAttribute;
}
}
return null;
}
|
[
"public",
"function",
"retrieveProductAttributeByAttribute",
"(",
"ProductInterface",
"$",
"product",
",",
"Attribute",
"$",
"attribute",
")",
"{",
"foreach",
"(",
"$",
"product",
"->",
"getProductAttributes",
"(",
")",
"as",
"$",
"productAttribute",
")",
"{",
"if",
"(",
"$",
"productAttribute",
"->",
"getAttribute",
"(",
")",
"->",
"getId",
"(",
")",
"===",
"$",
"attribute",
"->",
"getId",
"(",
")",
")",
"{",
"return",
"$",
"productAttribute",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Searches products product-attributes for given attribute.
@param ProductInterface $product
@param Attribute $attribute
@return ProductAttribute|null
|
[
"Searches",
"products",
"product",
"-",
"attributes",
"for",
"given",
"attribute",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductAttributeManager.php#L227-L236
|
224,107
|
sulu/SuluProductBundle
|
Product/ProductAttributeManager.php
|
ProductAttributeManager.retrieveAttributeValueTranslationByLocale
|
private function retrieveAttributeValueTranslationByLocale(AttributeValue $attributeValue, $locale)
{
foreach ($attributeValue->getTranslations() as $attributeValueTranslation) {
if ($attributeValueTranslation->getLocale() === $locale) {
return $attributeValueTranslation;
}
}
return null;
}
|
php
|
private function retrieveAttributeValueTranslationByLocale(AttributeValue $attributeValue, $locale)
{
foreach ($attributeValue->getTranslations() as $attributeValueTranslation) {
if ($attributeValueTranslation->getLocale() === $locale) {
return $attributeValueTranslation;
}
}
return null;
}
|
[
"private",
"function",
"retrieveAttributeValueTranslationByLocale",
"(",
"AttributeValue",
"$",
"attributeValue",
",",
"$",
"locale",
")",
"{",
"foreach",
"(",
"$",
"attributeValue",
"->",
"getTranslations",
"(",
")",
"as",
"$",
"attributeValueTranslation",
")",
"{",
"if",
"(",
"$",
"attributeValueTranslation",
"->",
"getLocale",
"(",
")",
"===",
"$",
"locale",
")",
"{",
"return",
"$",
"attributeValueTranslation",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Returns the translation in given locale for the given AttributeValue.
@param AttributeValue $attributeValue
@param string $locale
@return AttributeValueTranslation|null
|
[
"Returns",
"the",
"translation",
"in",
"given",
"locale",
"for",
"the",
"given",
"AttributeValue",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductAttributeManager.php#L246-L255
|
224,108
|
sulu/SuluProductBundle
|
Entity/UnitRepository.php
|
UnitRepository.findByAbbrevation
|
public function findByAbbrevation($abbrevation, $returnAsEntity = false)
{
try {
$qb = $this->createQueryBuilder('unit')
->select('partial unit.{id}')
->join('unit.mappings', 'mappings', 'WITH', 'mappings.name = :abbrevation')
->setParameter('abbrevation', $abbrevation);
if ($returnAsEntity) {
return $qb->getQuery()->getSingleResult();
}
return $qb->getQuery()->getSingleScalarResult();
} catch (NoResultException $exc) {
return null;
}
}
|
php
|
public function findByAbbrevation($abbrevation, $returnAsEntity = false)
{
try {
$qb = $this->createQueryBuilder('unit')
->select('partial unit.{id}')
->join('unit.mappings', 'mappings', 'WITH', 'mappings.name = :abbrevation')
->setParameter('abbrevation', $abbrevation);
if ($returnAsEntity) {
return $qb->getQuery()->getSingleResult();
}
return $qb->getQuery()->getSingleScalarResult();
} catch (NoResultException $exc) {
return null;
}
}
|
[
"public",
"function",
"findByAbbrevation",
"(",
"$",
"abbrevation",
",",
"$",
"returnAsEntity",
"=",
"false",
")",
"{",
"try",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"createQueryBuilder",
"(",
"'unit'",
")",
"->",
"select",
"(",
"'partial unit.{id}'",
")",
"->",
"join",
"(",
"'unit.mappings'",
",",
"'mappings'",
",",
"'WITH'",
",",
"'mappings.name = :abbrevation'",
")",
"->",
"setParameter",
"(",
"'abbrevation'",
",",
"$",
"abbrevation",
")",
";",
"if",
"(",
"$",
"returnAsEntity",
")",
"{",
"return",
"$",
"qb",
"->",
"getQuery",
"(",
")",
"->",
"getSingleResult",
"(",
")",
";",
"}",
"return",
"$",
"qb",
"->",
"getQuery",
"(",
")",
"->",
"getSingleScalarResult",
"(",
")",
";",
"}",
"catch",
"(",
"NoResultException",
"$",
"exc",
")",
"{",
"return",
"null",
";",
"}",
"}"
] |
Find a unit by it's abbrevation.
@param $abbrevation
@param bool $returnAsEntity
@return mixed|null
|
[
"Find",
"a",
"unit",
"by",
"it",
"s",
"abbrevation",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Entity/UnitRepository.php#L30-L46
|
224,109
|
sulu/SuluProductBundle
|
Entity/UnitRepository.php
|
UnitRepository.findAllByLocale
|
public function findAllByLocale($locale)
{
try {
$qb = $this->getUnitQuery($locale)
->orderBy('unitTranslations.name', 'ASC');
return $qb->getQuery()->getResult();
} catch (NoResultException $exc) {
return null;
}
}
|
php
|
public function findAllByLocale($locale)
{
try {
$qb = $this->getUnitQuery($locale)
->orderBy('unitTranslations.name', 'ASC');
return $qb->getQuery()->getResult();
} catch (NoResultException $exc) {
return null;
}
}
|
[
"public",
"function",
"findAllByLocale",
"(",
"$",
"locale",
")",
"{",
"try",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"getUnitQuery",
"(",
"$",
"locale",
")",
"->",
"orderBy",
"(",
"'unitTranslations.name'",
",",
"'ASC'",
")",
";",
"return",
"$",
"qb",
"->",
"getQuery",
"(",
")",
"->",
"getResult",
"(",
")",
";",
"}",
"catch",
"(",
"NoResultException",
"$",
"exc",
")",
"{",
"return",
"null",
";",
"}",
"}"
] |
Returns the units with the given locale.
@param string $locale The locale to load
@return Unit[]|null
|
[
"Returns",
"the",
"units",
"with",
"the",
"given",
"locale",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Entity/UnitRepository.php#L55-L65
|
224,110
|
sulu/SuluProductBundle
|
Entity/CurrencyRepository.php
|
CurrencyRepository.findByCode
|
public function findByCode($code)
{
try {
$qb = $this->createQueryBuilder('currency')
->andWhere('currency.code = :currencyCode')
->setParameter('currencyCode', $code);
return $qb->getQuery()->getSingleResult();
} catch (NoResultException $exc) {
return null;
}
}
|
php
|
public function findByCode($code)
{
try {
$qb = $this->createQueryBuilder('currency')
->andWhere('currency.code = :currencyCode')
->setParameter('currencyCode', $code);
return $qb->getQuery()->getSingleResult();
} catch (NoResultException $exc) {
return null;
}
}
|
[
"public",
"function",
"findByCode",
"(",
"$",
"code",
")",
"{",
"try",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"createQueryBuilder",
"(",
"'currency'",
")",
"->",
"andWhere",
"(",
"'currency.code = :currencyCode'",
")",
"->",
"setParameter",
"(",
"'currencyCode'",
",",
"$",
"code",
")",
";",
"return",
"$",
"qb",
"->",
"getQuery",
"(",
")",
"->",
"getSingleResult",
"(",
")",
";",
"}",
"catch",
"(",
"NoResultException",
"$",
"exc",
")",
"{",
"return",
"null",
";",
"}",
"}"
] |
Find a currency by it's code.
@param string $code
@return mixed|null
|
[
"Find",
"a",
"currency",
"by",
"it",
"s",
"code",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Entity/CurrencyRepository.php#L49-L60
|
224,111
|
sulu/SuluProductBundle
|
Entity/DeliveryStatus.php
|
DeliveryStatus.removeProduct
|
public function removeProduct(\Sulu\Bundle\ProductBundle\Entity\Product $products)
{
$this->products->removeElement($products);
}
|
php
|
public function removeProduct(\Sulu\Bundle\ProductBundle\Entity\Product $products)
{
$this->products->removeElement($products);
}
|
[
"public",
"function",
"removeProduct",
"(",
"\\",
"Sulu",
"\\",
"Bundle",
"\\",
"ProductBundle",
"\\",
"Entity",
"\\",
"Product",
"$",
"products",
")",
"{",
"$",
"this",
"->",
"products",
"->",
"removeElement",
"(",
"$",
"products",
")",
";",
"}"
] |
Remove products.
@param \Sulu\Bundle\ProductBundle\Entity\Product $products
|
[
"Remove",
"products",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Entity/DeliveryStatus.php#L117-L120
|
224,112
|
unreal4u/mqtt
|
src/Protocol/ConnAck.php
|
ConnAck.throwConnectException
|
private function throwConnectException(): self
{
switch ($this->connectReturnCode) {
case 1:
throw new UnacceptableProtocolVersion(
'The Server does not support the level of the MQTT protocol requested by the Client'
);
case 2:
throw new IdentifierRejected('The Client identifier is correct UTF-8 but not allowed by the Server');
case 3:
throw new ServerUnavailable('The Network Connection has been made but the MQTT service is unavailable');
case 4:
throw new BadUsernameOrPassword('The data in the user name or password is malformed');
case 5:
throw new NotAuthorized('The Client is not authorized to connect');
default:
throw new GenericError(sprintf(
'Reserved for future use or error not implemented yet (Error code: %d)',
$this->connectReturnCode
));
}
}
|
php
|
private function throwConnectException(): self
{
switch ($this->connectReturnCode) {
case 1:
throw new UnacceptableProtocolVersion(
'The Server does not support the level of the MQTT protocol requested by the Client'
);
case 2:
throw new IdentifierRejected('The Client identifier is correct UTF-8 but not allowed by the Server');
case 3:
throw new ServerUnavailable('The Network Connection has been made but the MQTT service is unavailable');
case 4:
throw new BadUsernameOrPassword('The data in the user name or password is malformed');
case 5:
throw new NotAuthorized('The Client is not authorized to connect');
default:
throw new GenericError(sprintf(
'Reserved for future use or error not implemented yet (Error code: %d)',
$this->connectReturnCode
));
}
}
|
[
"private",
"function",
"throwConnectException",
"(",
")",
":",
"self",
"{",
"switch",
"(",
"$",
"this",
"->",
"connectReturnCode",
")",
"{",
"case",
"1",
":",
"throw",
"new",
"UnacceptableProtocolVersion",
"(",
"'The Server does not support the level of the MQTT protocol requested by the Client'",
")",
";",
"case",
"2",
":",
"throw",
"new",
"IdentifierRejected",
"(",
"'The Client identifier is correct UTF-8 but not allowed by the Server'",
")",
";",
"case",
"3",
":",
"throw",
"new",
"ServerUnavailable",
"(",
"'The Network Connection has been made but the MQTT service is unavailable'",
")",
";",
"case",
"4",
":",
"throw",
"new",
"BadUsernameOrPassword",
"(",
"'The data in the user name or password is malformed'",
")",
";",
"case",
"5",
":",
"throw",
"new",
"NotAuthorized",
"(",
"'The Client is not authorized to connect'",
")",
";",
"default",
":",
"throw",
"new",
"GenericError",
"(",
"sprintf",
"(",
"'Reserved for future use or error not implemented yet (Error code: %d)'",
",",
"$",
"this",
"->",
"connectReturnCode",
")",
")",
";",
"}",
"}"
] |
Will throw an exception in case there is something bad with the connection
@see http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/errata01/os/mqtt-v3.1.1-errata01-os-complete.html#_Toc385349257
@return ConnAck
@throws \unreal4u\MQTT\Exceptions\Connect\GenericError
@throws \unreal4u\MQTT\Exceptions\Connect\NotAuthorized
@throws \unreal4u\MQTT\Exceptions\Connect\BadUsernameOrPassword
@throws \unreal4u\MQTT\Exceptions\Connect\ServerUnavailable
@throws \unreal4u\MQTT\Exceptions\Connect\IdentifierRejected
@throws \unreal4u\MQTT\Exceptions\Connect\UnacceptableProtocolVersion
|
[
"Will",
"throw",
"an",
"exception",
"in",
"case",
"there",
"is",
"something",
"bad",
"with",
"the",
"connection"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Protocol/ConnAck.php#L91-L112
|
224,113
|
sulu/SuluProductBundle
|
Product/ProductMediaManager.php
|
ProductMediaManager.initFieldDescriptors
|
protected function initFieldDescriptors($locale)
{
$this->fieldDescriptors = [];
$mediaJoin = [
self::$mediaEntityName => new DoctrineJoinDescriptor(
self::$mediaEntityName,
$this->productEntityName . '.media',
null,
DoctrineJoinDescriptor::JOIN_METHOD_INNER
),
];
$fileVersionJoin = array_merge(
$mediaJoin,
[
self::$fileEntityName => new DoctrineJoinDescriptor(
self::$fileEntityName,
self::$mediaEntityName . '.files'
),
self::$fileVersionEntityName => new DoctrineJoinDescriptor(
self::$fileVersionEntityName,
self::$fileEntityName . '.fileVersions',
self::$fileVersionEntityName . '.version = ' . self::$fileEntityName . '.version'
),
]
);
$fileVersionMetaJoin = array_merge(
$fileVersionJoin,
[
self::$fileVersionMetaEntityName => new DoctrineJoinDescriptor(
self::$fileVersionMetaEntityName,
self::$fileVersionEntityName . '.meta',
self::$fileVersionMetaEntityName . '.locale = \'' . $locale . '\''
),
]
);
$this->fieldDescriptors['product'] = new DoctrineFieldDescriptor(
'id',
'product',
$this->productEntityName,
null,
[],
true,
false
);
$this->fieldDescriptors['id'] = new DoctrineFieldDescriptor(
'id',
'id',
self::$mediaEntityName,
'public.id',
$mediaJoin,
true,
false
);
$this->fieldDescriptors['thumbnails'] = new DoctrineFieldDescriptor(
'id',
'thumbnails',
self::$mediaEntityName,
'media.media.thumbnails',
$mediaJoin,
false,
true,
'thumbnails',
'',
'',
false
);
$this->fieldDescriptors['name'] = new DoctrineFieldDescriptor(
'name',
'name',
self::$fileVersionEntityName,
'public.name',
$fileVersionJoin
);
$this->fieldDescriptors['size'] = new DoctrineFieldDescriptor(
'size',
'size',
self::$fileVersionEntityName,
'media.media.size',
$fileVersionJoin,
false,
true,
'bytes'
);
$this->fieldDescriptors['changed'] = new DoctrineFieldDescriptor(
'changed',
'changed',
self::$fileVersionEntityName,
'public.changed',
$fileVersionJoin,
true,
false,
'date'
);
$this->fieldDescriptors['created'] = new DoctrineFieldDescriptor(
'created',
'created',
self::$fileVersionEntityName,
'public.created',
$fileVersionJoin,
true,
false,
'date'
);
$this->fieldDescriptors['title'] = new DoctrineFieldDescriptor(
'title',
'title',
self::$fileVersionMetaEntityName,
'public.title',
$fileVersionMetaJoin,
false,
true,
'title'
);
$this->fieldDescriptors['description'] = new DoctrineFieldDescriptor(
'description',
'description',
self::$fileVersionMetaEntityName,
'media.media.description',
$fileVersionMetaJoin
);
}
|
php
|
protected function initFieldDescriptors($locale)
{
$this->fieldDescriptors = [];
$mediaJoin = [
self::$mediaEntityName => new DoctrineJoinDescriptor(
self::$mediaEntityName,
$this->productEntityName . '.media',
null,
DoctrineJoinDescriptor::JOIN_METHOD_INNER
),
];
$fileVersionJoin = array_merge(
$mediaJoin,
[
self::$fileEntityName => new DoctrineJoinDescriptor(
self::$fileEntityName,
self::$mediaEntityName . '.files'
),
self::$fileVersionEntityName => new DoctrineJoinDescriptor(
self::$fileVersionEntityName,
self::$fileEntityName . '.fileVersions',
self::$fileVersionEntityName . '.version = ' . self::$fileEntityName . '.version'
),
]
);
$fileVersionMetaJoin = array_merge(
$fileVersionJoin,
[
self::$fileVersionMetaEntityName => new DoctrineJoinDescriptor(
self::$fileVersionMetaEntityName,
self::$fileVersionEntityName . '.meta',
self::$fileVersionMetaEntityName . '.locale = \'' . $locale . '\''
),
]
);
$this->fieldDescriptors['product'] = new DoctrineFieldDescriptor(
'id',
'product',
$this->productEntityName,
null,
[],
true,
false
);
$this->fieldDescriptors['id'] = new DoctrineFieldDescriptor(
'id',
'id',
self::$mediaEntityName,
'public.id',
$mediaJoin,
true,
false
);
$this->fieldDescriptors['thumbnails'] = new DoctrineFieldDescriptor(
'id',
'thumbnails',
self::$mediaEntityName,
'media.media.thumbnails',
$mediaJoin,
false,
true,
'thumbnails',
'',
'',
false
);
$this->fieldDescriptors['name'] = new DoctrineFieldDescriptor(
'name',
'name',
self::$fileVersionEntityName,
'public.name',
$fileVersionJoin
);
$this->fieldDescriptors['size'] = new DoctrineFieldDescriptor(
'size',
'size',
self::$fileVersionEntityName,
'media.media.size',
$fileVersionJoin,
false,
true,
'bytes'
);
$this->fieldDescriptors['changed'] = new DoctrineFieldDescriptor(
'changed',
'changed',
self::$fileVersionEntityName,
'public.changed',
$fileVersionJoin,
true,
false,
'date'
);
$this->fieldDescriptors['created'] = new DoctrineFieldDescriptor(
'created',
'created',
self::$fileVersionEntityName,
'public.created',
$fileVersionJoin,
true,
false,
'date'
);
$this->fieldDescriptors['title'] = new DoctrineFieldDescriptor(
'title',
'title',
self::$fileVersionMetaEntityName,
'public.title',
$fileVersionMetaJoin,
false,
true,
'title'
);
$this->fieldDescriptors['description'] = new DoctrineFieldDescriptor(
'description',
'description',
self::$fileVersionMetaEntityName,
'media.media.description',
$fileVersionMetaJoin
);
}
|
[
"protected",
"function",
"initFieldDescriptors",
"(",
"$",
"locale",
")",
"{",
"$",
"this",
"->",
"fieldDescriptors",
"=",
"[",
"]",
";",
"$",
"mediaJoin",
"=",
"[",
"self",
"::",
"$",
"mediaEntityName",
"=>",
"new",
"DoctrineJoinDescriptor",
"(",
"self",
"::",
"$",
"mediaEntityName",
",",
"$",
"this",
"->",
"productEntityName",
".",
"'.media'",
",",
"null",
",",
"DoctrineJoinDescriptor",
"::",
"JOIN_METHOD_INNER",
")",
",",
"]",
";",
"$",
"fileVersionJoin",
"=",
"array_merge",
"(",
"$",
"mediaJoin",
",",
"[",
"self",
"::",
"$",
"fileEntityName",
"=>",
"new",
"DoctrineJoinDescriptor",
"(",
"self",
"::",
"$",
"fileEntityName",
",",
"self",
"::",
"$",
"mediaEntityName",
".",
"'.files'",
")",
",",
"self",
"::",
"$",
"fileVersionEntityName",
"=>",
"new",
"DoctrineJoinDescriptor",
"(",
"self",
"::",
"$",
"fileVersionEntityName",
",",
"self",
"::",
"$",
"fileEntityName",
".",
"'.fileVersions'",
",",
"self",
"::",
"$",
"fileVersionEntityName",
".",
"'.version = '",
".",
"self",
"::",
"$",
"fileEntityName",
".",
"'.version'",
")",
",",
"]",
")",
";",
"$",
"fileVersionMetaJoin",
"=",
"array_merge",
"(",
"$",
"fileVersionJoin",
",",
"[",
"self",
"::",
"$",
"fileVersionMetaEntityName",
"=>",
"new",
"DoctrineJoinDescriptor",
"(",
"self",
"::",
"$",
"fileVersionMetaEntityName",
",",
"self",
"::",
"$",
"fileVersionEntityName",
".",
"'.meta'",
",",
"self",
"::",
"$",
"fileVersionMetaEntityName",
".",
"'.locale = \\''",
".",
"$",
"locale",
".",
"'\\''",
")",
",",
"]",
")",
";",
"$",
"this",
"->",
"fieldDescriptors",
"[",
"'product'",
"]",
"=",
"new",
"DoctrineFieldDescriptor",
"(",
"'id'",
",",
"'product'",
",",
"$",
"this",
"->",
"productEntityName",
",",
"null",
",",
"[",
"]",
",",
"true",
",",
"false",
")",
";",
"$",
"this",
"->",
"fieldDescriptors",
"[",
"'id'",
"]",
"=",
"new",
"DoctrineFieldDescriptor",
"(",
"'id'",
",",
"'id'",
",",
"self",
"::",
"$",
"mediaEntityName",
",",
"'public.id'",
",",
"$",
"mediaJoin",
",",
"true",
",",
"false",
")",
";",
"$",
"this",
"->",
"fieldDescriptors",
"[",
"'thumbnails'",
"]",
"=",
"new",
"DoctrineFieldDescriptor",
"(",
"'id'",
",",
"'thumbnails'",
",",
"self",
"::",
"$",
"mediaEntityName",
",",
"'media.media.thumbnails'",
",",
"$",
"mediaJoin",
",",
"false",
",",
"true",
",",
"'thumbnails'",
",",
"''",
",",
"''",
",",
"false",
")",
";",
"$",
"this",
"->",
"fieldDescriptors",
"[",
"'name'",
"]",
"=",
"new",
"DoctrineFieldDescriptor",
"(",
"'name'",
",",
"'name'",
",",
"self",
"::",
"$",
"fileVersionEntityName",
",",
"'public.name'",
",",
"$",
"fileVersionJoin",
")",
";",
"$",
"this",
"->",
"fieldDescriptors",
"[",
"'size'",
"]",
"=",
"new",
"DoctrineFieldDescriptor",
"(",
"'size'",
",",
"'size'",
",",
"self",
"::",
"$",
"fileVersionEntityName",
",",
"'media.media.size'",
",",
"$",
"fileVersionJoin",
",",
"false",
",",
"true",
",",
"'bytes'",
")",
";",
"$",
"this",
"->",
"fieldDescriptors",
"[",
"'changed'",
"]",
"=",
"new",
"DoctrineFieldDescriptor",
"(",
"'changed'",
",",
"'changed'",
",",
"self",
"::",
"$",
"fileVersionEntityName",
",",
"'public.changed'",
",",
"$",
"fileVersionJoin",
",",
"true",
",",
"false",
",",
"'date'",
")",
";",
"$",
"this",
"->",
"fieldDescriptors",
"[",
"'created'",
"]",
"=",
"new",
"DoctrineFieldDescriptor",
"(",
"'created'",
",",
"'created'",
",",
"self",
"::",
"$",
"fileVersionEntityName",
",",
"'public.created'",
",",
"$",
"fileVersionJoin",
",",
"true",
",",
"false",
",",
"'date'",
")",
";",
"$",
"this",
"->",
"fieldDescriptors",
"[",
"'title'",
"]",
"=",
"new",
"DoctrineFieldDescriptor",
"(",
"'title'",
",",
"'title'",
",",
"self",
"::",
"$",
"fileVersionMetaEntityName",
",",
"'public.title'",
",",
"$",
"fileVersionMetaJoin",
",",
"false",
",",
"true",
",",
"'title'",
")",
";",
"$",
"this",
"->",
"fieldDescriptors",
"[",
"'description'",
"]",
"=",
"new",
"DoctrineFieldDescriptor",
"(",
"'description'",
",",
"'description'",
",",
"self",
"::",
"$",
"fileVersionMetaEntityName",
",",
"'media.media.description'",
",",
"$",
"fileVersionMetaJoin",
")",
";",
"}"
] |
Initializes field descriptors for product media.
@param string $locale
|
[
"Initializes",
"field",
"descriptors",
"for",
"product",
"media",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductMediaManager.php#L127-L257
|
224,114
|
unreal4u/mqtt
|
src/Internals/WritableContent.php
|
WritableContent.createFixedHeader
|
final public function createFixedHeader(int $variableHeaderLength): string
{
$this->logger->debug('Creating fixed header with values', [
'controlPacketValue' => self::getControlPacketValue(),
'specialFlags' => $this->specialFlags,
'variableHeaderLength' => $variableHeaderLength,
'composed' => decbin(chr((self::getControlPacketValue() << 4) | $this->specialFlags)),
]);
// Binary OR is safe to do because the first 4 bits are always 0 after shifting
return
chr((self::getControlPacketValue() << 4) | $this->specialFlags) .
Utilities::formatRemainingLengthOutput($variableHeaderLength);
}
|
php
|
final public function createFixedHeader(int $variableHeaderLength): string
{
$this->logger->debug('Creating fixed header with values', [
'controlPacketValue' => self::getControlPacketValue(),
'specialFlags' => $this->specialFlags,
'variableHeaderLength' => $variableHeaderLength,
'composed' => decbin(chr((self::getControlPacketValue() << 4) | $this->specialFlags)),
]);
// Binary OR is safe to do because the first 4 bits are always 0 after shifting
return
chr((self::getControlPacketValue() << 4) | $this->specialFlags) .
Utilities::formatRemainingLengthOutput($variableHeaderLength);
}
|
[
"final",
"public",
"function",
"createFixedHeader",
"(",
"int",
"$",
"variableHeaderLength",
")",
":",
"string",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'Creating fixed header with values'",
",",
"[",
"'controlPacketValue'",
"=>",
"self",
"::",
"getControlPacketValue",
"(",
")",
",",
"'specialFlags'",
"=>",
"$",
"this",
"->",
"specialFlags",
",",
"'variableHeaderLength'",
"=>",
"$",
"variableHeaderLength",
",",
"'composed'",
"=>",
"decbin",
"(",
"chr",
"(",
"(",
"self",
"::",
"getControlPacketValue",
"(",
")",
"<<",
"4",
")",
"|",
"$",
"this",
"->",
"specialFlags",
")",
")",
",",
"]",
")",
";",
"// Binary OR is safe to do because the first 4 bits are always 0 after shifting",
"return",
"chr",
"(",
"(",
"self",
"::",
"getControlPacketValue",
"(",
")",
"<<",
"4",
")",
"|",
"$",
"this",
"->",
"specialFlags",
")",
".",
"Utilities",
"::",
"formatRemainingLengthOutput",
"(",
"$",
"variableHeaderLength",
")",
";",
"}"
] |
Returns the fixed header part needed for all methods
This takes into account the basic control packet value, any special flags and, in the second byte, the variable
header length
@param int $variableHeaderLength
@return string
@throws MessageTooBig
|
[
"Returns",
"the",
"fixed",
"header",
"part",
"needed",
"for",
"all",
"methods"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Internals/WritableContent.php#L47-L60
|
224,115
|
unreal4u/mqtt
|
src/Internals/WritableContent.php
|
WritableContent.createSendableMessage
|
final public function createSendableMessage(): string
{
$variableHeader = $this->createVariableHeader();
$this->logger->debug('Created variable header', ['variableHeader' => base64_encode($variableHeader)]);
$payload = $this->createPayload();
$this->logger->debug('Created payload', ['payload' => base64_encode($payload)]);
$fixedHeader = $this->createFixedHeader(strlen($variableHeader . $payload));
$this->logger->debug('Created fixed header', ['fixedHeader' => base64_encode($fixedHeader)]);
return $fixedHeader . $variableHeader . $payload;
}
|
php
|
final public function createSendableMessage(): string
{
$variableHeader = $this->createVariableHeader();
$this->logger->debug('Created variable header', ['variableHeader' => base64_encode($variableHeader)]);
$payload = $this->createPayload();
$this->logger->debug('Created payload', ['payload' => base64_encode($payload)]);
$fixedHeader = $this->createFixedHeader(strlen($variableHeader . $payload));
$this->logger->debug('Created fixed header', ['fixedHeader' => base64_encode($fixedHeader)]);
return $fixedHeader . $variableHeader . $payload;
}
|
[
"final",
"public",
"function",
"createSendableMessage",
"(",
")",
":",
"string",
"{",
"$",
"variableHeader",
"=",
"$",
"this",
"->",
"createVariableHeader",
"(",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'Created variable header'",
",",
"[",
"'variableHeader'",
"=>",
"base64_encode",
"(",
"$",
"variableHeader",
")",
"]",
")",
";",
"$",
"payload",
"=",
"$",
"this",
"->",
"createPayload",
"(",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'Created payload'",
",",
"[",
"'payload'",
"=>",
"base64_encode",
"(",
"$",
"payload",
")",
"]",
")",
";",
"$",
"fixedHeader",
"=",
"$",
"this",
"->",
"createFixedHeader",
"(",
"strlen",
"(",
"$",
"variableHeader",
".",
"$",
"payload",
")",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'Created fixed header'",
",",
"[",
"'fixedHeader'",
"=>",
"base64_encode",
"(",
"$",
"fixedHeader",
")",
"]",
")",
";",
"return",
"$",
"fixedHeader",
".",
"$",
"variableHeader",
".",
"$",
"payload",
";",
"}"
] |
Creates the entire message
@return string
@throws MessageTooBig
|
[
"Creates",
"the",
"entire",
"message"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Internals/WritableContent.php#L67-L77
|
224,116
|
unreal4u/mqtt
|
src/Internals/WritableContent.php
|
WritableContent.createUTF8String
|
final public function createUTF8String(string $nonFormattedString): string
{
$returnString = '';
if ($nonFormattedString !== '') {
$returnString = Utilities::convertNumberToBinaryString(strlen($nonFormattedString)) . $nonFormattedString;
}
return $returnString;
}
|
php
|
final public function createUTF8String(string $nonFormattedString): string
{
$returnString = '';
if ($nonFormattedString !== '') {
$returnString = Utilities::convertNumberToBinaryString(strlen($nonFormattedString)) . $nonFormattedString;
}
return $returnString;
}
|
[
"final",
"public",
"function",
"createUTF8String",
"(",
"string",
"$",
"nonFormattedString",
")",
":",
"string",
"{",
"$",
"returnString",
"=",
"''",
";",
"if",
"(",
"$",
"nonFormattedString",
"!==",
"''",
")",
"{",
"$",
"returnString",
"=",
"Utilities",
"::",
"convertNumberToBinaryString",
"(",
"strlen",
"(",
"$",
"nonFormattedString",
")",
")",
".",
"$",
"nonFormattedString",
";",
"}",
"return",
"$",
"returnString",
";",
"}"
] |
Creates a UTF8 big-endian representation of the given string
@param string $nonFormattedString
@return string
@throws OutOfRangeException
|
[
"Creates",
"a",
"UTF8",
"big",
"-",
"endian",
"representation",
"of",
"the",
"given",
"string"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Internals/WritableContent.php#L100-L108
|
224,117
|
unreal4u/mqtt
|
src/Internals/WritableContent.php
|
WritableContent.expectAnswer
|
public function expectAnswer(string $brokerBitStream, ClientInterface $client): ReadableContentInterface
{
$this->logger->info('String of incoming data confirmed, returning new object', ['callee' => get_class($this)]);
$eventManager = new EventManager($this->logger);
return $eventManager->analyzeHeaders($brokerBitStream, $client);
}
|
php
|
public function expectAnswer(string $brokerBitStream, ClientInterface $client): ReadableContentInterface
{
$this->logger->info('String of incoming data confirmed, returning new object', ['callee' => get_class($this)]);
$eventManager = new EventManager($this->logger);
return $eventManager->analyzeHeaders($brokerBitStream, $client);
}
|
[
"public",
"function",
"expectAnswer",
"(",
"string",
"$",
"brokerBitStream",
",",
"ClientInterface",
"$",
"client",
")",
":",
"ReadableContentInterface",
"{",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"'String of incoming data confirmed, returning new object'",
",",
"[",
"'callee'",
"=>",
"get_class",
"(",
"$",
"this",
")",
"]",
")",
";",
"$",
"eventManager",
"=",
"new",
"EventManager",
"(",
"$",
"this",
"->",
"logger",
")",
";",
"return",
"$",
"eventManager",
"->",
"analyzeHeaders",
"(",
"$",
"brokerBitStream",
",",
"$",
"client",
")",
";",
"}"
] |
Will return an object of the type the broker has returned to us
@param string $brokerBitStream
@param ClientInterface $client
@return ReadableContentInterface
@throws DomainException
|
[
"Will",
"return",
"an",
"object",
"of",
"the",
"type",
"the",
"broker",
"has",
"returned",
"to",
"us"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Internals/WritableContent.php#L119-L125
|
224,118
|
sulu/SuluProductBundle
|
Entity/AttributeSetTranslation.php
|
AttributeSetTranslation.setAttributeSet
|
public function setAttributeSet(\Sulu\Bundle\ProductBundle\Entity\AttributeSet $template)
{
$this->attributeSet = $template;
return $this;
}
|
php
|
public function setAttributeSet(\Sulu\Bundle\ProductBundle\Entity\AttributeSet $template)
{
$this->attributeSet = $template;
return $this;
}
|
[
"public",
"function",
"setAttributeSet",
"(",
"\\",
"Sulu",
"\\",
"Bundle",
"\\",
"ProductBundle",
"\\",
"Entity",
"\\",
"AttributeSet",
"$",
"template",
")",
"{",
"$",
"this",
"->",
"attributeSet",
"=",
"$",
"template",
";",
"return",
"$",
"this",
";",
"}"
] |
Set template.
@param \Sulu\Bundle\ProductBundle\Entity\AttributeSet $template
@return AttributeSetTranslation
|
[
"Set",
"template",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Entity/AttributeSetTranslation.php#L104-L109
|
224,119
|
unreal4u/mqtt
|
src/Internals/ReadableContent.php
|
ReadableContent.checkControlPacketValue
|
private function checkControlPacketValue(int $controlPacketValue): bool
{
// Check whether the first byte corresponds to the expected control packet value
if (static::CONTROL_PACKET_VALUE !== $controlPacketValue) {
throw new InvalidResponseType(sprintf(
'Value of received value does not correspond to response (Expected: %d, Actual: %d)',
static::CONTROL_PACKET_VALUE,
$controlPacketValue
));
}
return true;
}
|
php
|
private function checkControlPacketValue(int $controlPacketValue): bool
{
// Check whether the first byte corresponds to the expected control packet value
if (static::CONTROL_PACKET_VALUE !== $controlPacketValue) {
throw new InvalidResponseType(sprintf(
'Value of received value does not correspond to response (Expected: %d, Actual: %d)',
static::CONTROL_PACKET_VALUE,
$controlPacketValue
));
}
return true;
}
|
[
"private",
"function",
"checkControlPacketValue",
"(",
"int",
"$",
"controlPacketValue",
")",
":",
"bool",
"{",
"// Check whether the first byte corresponds to the expected control packet value",
"if",
"(",
"static",
"::",
"CONTROL_PACKET_VALUE",
"!==",
"$",
"controlPacketValue",
")",
"{",
"throw",
"new",
"InvalidResponseType",
"(",
"sprintf",
"(",
"'Value of received value does not correspond to response (Expected: %d, Actual: %d)'",
",",
"static",
"::",
"CONTROL_PACKET_VALUE",
",",
"$",
"controlPacketValue",
")",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Checks whether the control packet corresponds to this object
@param int $controlPacketValue
@return bool
@throws InvalidResponseType
|
[
"Checks",
"whether",
"the",
"control",
"packet",
"corresponds",
"to",
"this",
"object"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Internals/ReadableContent.php#L52-L64
|
224,120
|
unreal4u/mqtt
|
src/Internals/ReadableContent.php
|
ReadableContent.calculateSizeOfRemainingLengthField
|
private function calculateSizeOfRemainingLengthField(int $size): int
{
$blockSize = $iterations = 0;
while ($size >= $blockSize) {
$iterations++;
$blockSize = 128 ** $iterations;
}
$this->sizeOfRemainingLengthField = $iterations;
return $iterations;
}
|
php
|
private function calculateSizeOfRemainingLengthField(int $size): int
{
$blockSize = $iterations = 0;
while ($size >= $blockSize) {
$iterations++;
$blockSize = 128 ** $iterations;
}
$this->sizeOfRemainingLengthField = $iterations;
return $iterations;
}
|
[
"private",
"function",
"calculateSizeOfRemainingLengthField",
"(",
"int",
"$",
"size",
")",
":",
"int",
"{",
"$",
"blockSize",
"=",
"$",
"iterations",
"=",
"0",
";",
"while",
"(",
"$",
"size",
">=",
"$",
"blockSize",
")",
"{",
"$",
"iterations",
"++",
";",
"$",
"blockSize",
"=",
"128",
"**",
"$",
"iterations",
";",
"}",
"$",
"this",
"->",
"sizeOfRemainingLengthField",
"=",
"$",
"iterations",
";",
"return",
"$",
"iterations",
";",
"}"
] |
Sets the offset of the remaining length field
@param int $size
@return int
|
[
"Sets",
"the",
"offset",
"of",
"the",
"remaining",
"length",
"field"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Internals/ReadableContent.php#L101-L111
|
224,121
|
sulu/SuluProductBundle
|
Entity/AttributeValueTranslation.php
|
AttributeValueTranslation.setAttributeValue
|
public function setAttributeValue(\Sulu\Bundle\ProductBundle\Entity\AttributeValue $attributeValue)
{
$this->attributeValue = $attributeValue;
return $this;
}
|
php
|
public function setAttributeValue(\Sulu\Bundle\ProductBundle\Entity\AttributeValue $attributeValue)
{
$this->attributeValue = $attributeValue;
return $this;
}
|
[
"public",
"function",
"setAttributeValue",
"(",
"\\",
"Sulu",
"\\",
"Bundle",
"\\",
"ProductBundle",
"\\",
"Entity",
"\\",
"AttributeValue",
"$",
"attributeValue",
")",
"{",
"$",
"this",
"->",
"attributeValue",
"=",
"$",
"attributeValue",
";",
"return",
"$",
"this",
";",
"}"
] |
Set attributeValue.
@param \Sulu\Bundle\ProductBundle\Entity\AttributeValue $attributeValue
@return AttributeValueTranslation
|
[
"Set",
"attributeValue",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Entity/AttributeValueTranslation.php#L104-L109
|
224,122
|
dave-redfern/laravel-doctrine-behaviours
|
src/EntityAccessor.php
|
EntityAccessor.callProtectedMethod
|
public static function callProtectedMethod($object, $method, ...$args)
{
$refObject = new \ReflectionObject($object);
$refProp = $refObject->getMethod($method);
$refProp->setAccessible(true);
return $refProp->invokeArgs($object, $args);
}
|
php
|
public static function callProtectedMethod($object, $method, ...$args)
{
$refObject = new \ReflectionObject($object);
$refProp = $refObject->getMethod($method);
$refProp->setAccessible(true);
return $refProp->invokeArgs($object, $args);
}
|
[
"public",
"static",
"function",
"callProtectedMethod",
"(",
"$",
"object",
",",
"$",
"method",
",",
"...",
"$",
"args",
")",
"{",
"$",
"refObject",
"=",
"new",
"\\",
"ReflectionObject",
"(",
"$",
"object",
")",
";",
"$",
"refProp",
"=",
"$",
"refObject",
"->",
"getMethod",
"(",
"$",
"method",
")",
";",
"$",
"refProp",
"->",
"setAccessible",
"(",
"true",
")",
";",
"return",
"$",
"refProp",
"->",
"invokeArgs",
"(",
"$",
"object",
",",
"$",
"args",
")",
";",
"}"
] |
Helper to allow calling protected methods with variable arguments
@param object $object
@param string $method
@param mixed ...$args
@return mixed
|
[
"Helper",
"to",
"allow",
"calling",
"protected",
"methods",
"with",
"variable",
"arguments"
] |
c481eea497a0df6fc46bc2cadb08a0ed0ae819a4
|
https://github.com/dave-redfern/laravel-doctrine-behaviours/blob/c481eea497a0df6fc46bc2cadb08a0ed0ae819a4/src/EntityAccessor.php#L40-L47
|
224,123
|
dave-redfern/laravel-doctrine-behaviours
|
src/EntityAccessor.php
|
EntityAccessor.getProtectedProperty
|
public static function getProtectedProperty($object, $property)
{
$refObject = new \ReflectionObject($object);
$refProp = $refObject->getProperty($property);
$refProp->setAccessible(true);
return $refProp->getValue($object);
}
|
php
|
public static function getProtectedProperty($object, $property)
{
$refObject = new \ReflectionObject($object);
$refProp = $refObject->getProperty($property);
$refProp->setAccessible(true);
return $refProp->getValue($object);
}
|
[
"public",
"static",
"function",
"getProtectedProperty",
"(",
"$",
"object",
",",
"$",
"property",
")",
"{",
"$",
"refObject",
"=",
"new",
"\\",
"ReflectionObject",
"(",
"$",
"object",
")",
";",
"$",
"refProp",
"=",
"$",
"refObject",
"->",
"getProperty",
"(",
"$",
"property",
")",
";",
"$",
"refProp",
"->",
"setAccessible",
"(",
"true",
")",
";",
"return",
"$",
"refProp",
"->",
"getValue",
"(",
"$",
"object",
")",
";",
"}"
] |
Helper to allow accessing protected properties without an accessor
@param object $object
@param string $property
@return mixed
|
[
"Helper",
"to",
"allow",
"accessing",
"protected",
"properties",
"without",
"an",
"accessor"
] |
c481eea497a0df6fc46bc2cadb08a0ed0ae819a4
|
https://github.com/dave-redfern/laravel-doctrine-behaviours/blob/c481eea497a0df6fc46bc2cadb08a0ed0ae819a4/src/EntityAccessor.php#L57-L64
|
224,124
|
dave-redfern/laravel-doctrine-behaviours
|
src/EntityAccessor.php
|
EntityAccessor.setProtectedProperty
|
public static function setProtectedProperty($object, $property, $value)
{
$refObject = new \ReflectionObject($object);
$refProp = $refObject->getProperty($property);
$refProp->setAccessible(true);
$refProp->setValue($object, $value);
return $object;
}
|
php
|
public static function setProtectedProperty($object, $property, $value)
{
$refObject = new \ReflectionObject($object);
$refProp = $refObject->getProperty($property);
$refProp->setAccessible(true);
$refProp->setValue($object, $value);
return $object;
}
|
[
"public",
"static",
"function",
"setProtectedProperty",
"(",
"$",
"object",
",",
"$",
"property",
",",
"$",
"value",
")",
"{",
"$",
"refObject",
"=",
"new",
"\\",
"ReflectionObject",
"(",
"$",
"object",
")",
";",
"$",
"refProp",
"=",
"$",
"refObject",
"->",
"getProperty",
"(",
"$",
"property",
")",
";",
"$",
"refProp",
"->",
"setAccessible",
"(",
"true",
")",
";",
"$",
"refProp",
"->",
"setValue",
"(",
"$",
"object",
",",
"$",
"value",
")",
";",
"return",
"$",
"object",
";",
"}"
] |
Helper to allow setting protected properties, returns the passed object
@param object $object
@param string $property
@param mixed $value
@return object
|
[
"Helper",
"to",
"allow",
"setting",
"protected",
"properties",
"returns",
"the",
"passed",
"object"
] |
c481eea497a0df6fc46bc2cadb08a0ed0ae819a4
|
https://github.com/dave-redfern/laravel-doctrine-behaviours/blob/c481eea497a0df6fc46bc2cadb08a0ed0ae819a4/src/EntityAccessor.php#L75-L83
|
224,125
|
ibuildingsnl/qa-tools
|
installer.php
|
Installer.initTargets
|
private function initTargets($installDir, $filename)
{
if ($installDir === false) {
$installDir = getcwd();
}
$this->installPath = rtrim($installDir, '/') . '/'. $filename;
if (!is_writable($installDir)) {
throw new RuntimeException('The installation directory "' . $installDir . '" is not writable');
}
$this->target = $installDir . DIRECTORY_SEPARATOR . $filename;
$this->tmpPharPath = $installDir . DIRECTORY_SEPARATOR . basename($this->target, '.phar') . '-temp.phar';
$this->tmpPubkeyPath = $this->tmpPharPath . '.pubkey';
}
|
php
|
private function initTargets($installDir, $filename)
{
if ($installDir === false) {
$installDir = getcwd();
}
$this->installPath = rtrim($installDir, '/') . '/'. $filename;
if (!is_writable($installDir)) {
throw new RuntimeException('The installation directory "' . $installDir . '" is not writable');
}
$this->target = $installDir . DIRECTORY_SEPARATOR . $filename;
$this->tmpPharPath = $installDir . DIRECTORY_SEPARATOR . basename($this->target, '.phar') . '-temp.phar';
$this->tmpPubkeyPath = $this->tmpPharPath . '.pubkey';
}
|
[
"private",
"function",
"initTargets",
"(",
"$",
"installDir",
",",
"$",
"filename",
")",
"{",
"if",
"(",
"$",
"installDir",
"===",
"false",
")",
"{",
"$",
"installDir",
"=",
"getcwd",
"(",
")",
";",
"}",
"$",
"this",
"->",
"installPath",
"=",
"rtrim",
"(",
"$",
"installDir",
",",
"'/'",
")",
".",
"'/'",
".",
"$",
"filename",
";",
"if",
"(",
"!",
"is_writable",
"(",
"$",
"installDir",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'The installation directory \"'",
".",
"$",
"installDir",
".",
"'\" is not writable'",
")",
";",
"}",
"$",
"this",
"->",
"target",
"=",
"$",
"installDir",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"filename",
";",
"$",
"this",
"->",
"tmpPharPath",
"=",
"$",
"installDir",
".",
"DIRECTORY_SEPARATOR",
".",
"basename",
"(",
"$",
"this",
"->",
"target",
",",
"'.phar'",
")",
".",
"'-temp.phar'",
";",
"$",
"this",
"->",
"tmpPubkeyPath",
"=",
"$",
"this",
"->",
"tmpPharPath",
".",
"'.pubkey'",
";",
"}"
] |
Initialization methods to set the required filenames and base url
@param mixed $installDir Specific installation directory, or false
@param string $filename Specific filename to save to
@throws RuntimeException If the installation directory is not writable
|
[
"Initialization",
"methods",
"to",
"set",
"the",
"required",
"filenames",
"and",
"base",
"url"
] |
0c4999a74c55b03a826e1c881f75ee3fba6329f7
|
https://github.com/ibuildingsnl/qa-tools/blob/0c4999a74c55b03a826e1c881f75ee3fba6329f7/installer.php#L478-L492
|
224,126
|
ibuildingsnl/qa-tools
|
installer.php
|
Installer.install
|
private function install($version)
{
$retries = 3;
$infoMsg = 'Downloading...';
$infoType = 'info';
$success = false;
while ($retries--) {
try {
if (!$this->quiet) {
out($infoMsg, $infoType);
$infoMsg = 'Retrying...';
$infoType = 'error';
}
$releaseInfo = $this->getReleaseInfo($version);
$this->downloadTemporaryFile($releaseInfo['pharUrl'], $this->tmpPharPath);
$this->downloadTemporaryFile($releaseInfo['pubkeyUrl'], $this->tmpPubkeyPath);
$this->verifyAndSave();
$success = true;
break;
} catch (RuntimeException $e) {
out($e->getMessage(), 'error');
}
}
if (!$this->quiet) {
if ($success) {
out(PHP_EOL . "QA Tools (version {$releaseInfo['version']}) successfully installed to: {$this->target}", 'success');
out("Use it: php {$this->installPath}", 'info');
out('');
} else {
out('The download failed repeatedly, aborting.', 'error');
}
}
return $success;
}
|
php
|
private function install($version)
{
$retries = 3;
$infoMsg = 'Downloading...';
$infoType = 'info';
$success = false;
while ($retries--) {
try {
if (!$this->quiet) {
out($infoMsg, $infoType);
$infoMsg = 'Retrying...';
$infoType = 'error';
}
$releaseInfo = $this->getReleaseInfo($version);
$this->downloadTemporaryFile($releaseInfo['pharUrl'], $this->tmpPharPath);
$this->downloadTemporaryFile($releaseInfo['pubkeyUrl'], $this->tmpPubkeyPath);
$this->verifyAndSave();
$success = true;
break;
} catch (RuntimeException $e) {
out($e->getMessage(), 'error');
}
}
if (!$this->quiet) {
if ($success) {
out(PHP_EOL . "QA Tools (version {$releaseInfo['version']}) successfully installed to: {$this->target}", 'success');
out("Use it: php {$this->installPath}", 'info');
out('');
} else {
out('The download failed repeatedly, aborting.', 'error');
}
}
return $success;
}
|
[
"private",
"function",
"install",
"(",
"$",
"version",
")",
"{",
"$",
"retries",
"=",
"3",
";",
"$",
"infoMsg",
"=",
"'Downloading...'",
";",
"$",
"infoType",
"=",
"'info'",
";",
"$",
"success",
"=",
"false",
";",
"while",
"(",
"$",
"retries",
"--",
")",
"{",
"try",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"quiet",
")",
"{",
"out",
"(",
"$",
"infoMsg",
",",
"$",
"infoType",
")",
";",
"$",
"infoMsg",
"=",
"'Retrying...'",
";",
"$",
"infoType",
"=",
"'error'",
";",
"}",
"$",
"releaseInfo",
"=",
"$",
"this",
"->",
"getReleaseInfo",
"(",
"$",
"version",
")",
";",
"$",
"this",
"->",
"downloadTemporaryFile",
"(",
"$",
"releaseInfo",
"[",
"'pharUrl'",
"]",
",",
"$",
"this",
"->",
"tmpPharPath",
")",
";",
"$",
"this",
"->",
"downloadTemporaryFile",
"(",
"$",
"releaseInfo",
"[",
"'pubkeyUrl'",
"]",
",",
"$",
"this",
"->",
"tmpPubkeyPath",
")",
";",
"$",
"this",
"->",
"verifyAndSave",
"(",
")",
";",
"$",
"success",
"=",
"true",
";",
"break",
";",
"}",
"catch",
"(",
"RuntimeException",
"$",
"e",
")",
"{",
"out",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"'error'",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"quiet",
")",
"{",
"if",
"(",
"$",
"success",
")",
"{",
"out",
"(",
"PHP_EOL",
".",
"\"QA Tools (version {$releaseInfo['version']}) successfully installed to: {$this->target}\"",
",",
"'success'",
")",
";",
"out",
"(",
"\"Use it: php {$this->installPath}\"",
",",
"'info'",
")",
";",
"out",
"(",
"''",
")",
";",
"}",
"else",
"{",
"out",
"(",
"'The download failed repeatedly, aborting.'",
",",
"'error'",
")",
";",
"}",
"}",
"return",
"$",
"success",
";",
"}"
] |
The main install function
@param mixed $version Specific version to install, or false
@return bool If the installation succeeded
|
[
"The",
"main",
"install",
"function"
] |
0c4999a74c55b03a826e1c881f75ee3fba6329f7
|
https://github.com/ibuildingsnl/qa-tools/blob/0c4999a74c55b03a826e1c881f75ee3fba6329f7/installer.php#L501-L541
|
224,127
|
ibuildingsnl/qa-tools
|
installer.php
|
Installer.downloadTemporaryFile
|
private function downloadTemporaryFile($url, $target)
{
try {
if (($fh = @fopen($target, 'w')) === false) {
throw new RuntimeException(
sprintf(
'Could not create file "%s": %s',
$target,
@error_get_last()['message']
)
);
}
if ((@fwrite($fh, $this->httpClient->get($url, 'application/octet-stream'))) === false) {
throw new RuntimeException(
sprintf(
'The "%s" file could not be downloaded: %s',
$url,
@error_get_last()['message']
)
);
}
} finally {
if (is_resource($fh)) {
fclose($fh);
}
}
}
|
php
|
private function downloadTemporaryFile($url, $target)
{
try {
if (($fh = @fopen($target, 'w')) === false) {
throw new RuntimeException(
sprintf(
'Could not create file "%s": %s',
$target,
@error_get_last()['message']
)
);
}
if ((@fwrite($fh, $this->httpClient->get($url, 'application/octet-stream'))) === false) {
throw new RuntimeException(
sprintf(
'The "%s" file could not be downloaded: %s',
$url,
@error_get_last()['message']
)
);
}
} finally {
if (is_resource($fh)) {
fclose($fh);
}
}
}
|
[
"private",
"function",
"downloadTemporaryFile",
"(",
"$",
"url",
",",
"$",
"target",
")",
"{",
"try",
"{",
"if",
"(",
"(",
"$",
"fh",
"=",
"@",
"fopen",
"(",
"$",
"target",
",",
"'w'",
")",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Could not create file \"%s\": %s'",
",",
"$",
"target",
",",
"@",
"error_get_last",
"(",
")",
"[",
"'message'",
"]",
")",
")",
";",
"}",
"if",
"(",
"(",
"@",
"fwrite",
"(",
"$",
"fh",
",",
"$",
"this",
"->",
"httpClient",
"->",
"get",
"(",
"$",
"url",
",",
"'application/octet-stream'",
")",
")",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'The \"%s\" file could not be downloaded: %s'",
",",
"$",
"url",
",",
"@",
"error_get_last",
"(",
")",
"[",
"'message'",
"]",
")",
")",
";",
"}",
"}",
"finally",
"{",
"if",
"(",
"is_resource",
"(",
"$",
"fh",
")",
")",
"{",
"fclose",
"(",
"$",
"fh",
")",
";",
"}",
"}",
"}"
] |
A wrapper around the methods needed to download and save the phar
@param string $url The versioned download url
@param string $target The target location to download to
@throws \RuntimeException
|
[
"A",
"wrapper",
"around",
"the",
"methods",
"needed",
"to",
"download",
"and",
"save",
"the",
"phar"
] |
0c4999a74c55b03a826e1c881f75ee3fba6329f7
|
https://github.com/ibuildingsnl/qa-tools/blob/0c4999a74c55b03a826e1c881f75ee3fba6329f7/installer.php#L621-L648
|
224,128
|
ibuildingsnl/qa-tools
|
installer.php
|
Installer.verifyAndSave
|
private function verifyAndSave()
{
$this->pharValidator->assertPharValid($this->tmpPharPath);
if (!@rename($this->tmpPharPath, $this->target)) {
throw new RuntimeException(
sprintf(
'Could not write to file "%s": %s',
$this->target,
@error_get_last()['message']
)
);
}
if (!@rename($this->tmpPubkeyPath, $this->target . '.pubkey')) {
throw new RuntimeException(
sprintf(
'Could not write to file "%s": %s',
$this->target,
@error_get_last()['message']
)
);
}
chmod($this->target, 0755);
}
|
php
|
private function verifyAndSave()
{
$this->pharValidator->assertPharValid($this->tmpPharPath);
if (!@rename($this->tmpPharPath, $this->target)) {
throw new RuntimeException(
sprintf(
'Could not write to file "%s": %s',
$this->target,
@error_get_last()['message']
)
);
}
if (!@rename($this->tmpPubkeyPath, $this->target . '.pubkey')) {
throw new RuntimeException(
sprintf(
'Could not write to file "%s": %s',
$this->target,
@error_get_last()['message']
)
);
}
chmod($this->target, 0755);
}
|
[
"private",
"function",
"verifyAndSave",
"(",
")",
"{",
"$",
"this",
"->",
"pharValidator",
"->",
"assertPharValid",
"(",
"$",
"this",
"->",
"tmpPharPath",
")",
";",
"if",
"(",
"!",
"@",
"rename",
"(",
"$",
"this",
"->",
"tmpPharPath",
",",
"$",
"this",
"->",
"target",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Could not write to file \"%s\": %s'",
",",
"$",
"this",
"->",
"target",
",",
"@",
"error_get_last",
"(",
")",
"[",
"'message'",
"]",
")",
")",
";",
"}",
"if",
"(",
"!",
"@",
"rename",
"(",
"$",
"this",
"->",
"tmpPubkeyPath",
",",
"$",
"this",
"->",
"target",
".",
"'.pubkey'",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Could not write to file \"%s\": %s'",
",",
"$",
"this",
"->",
"target",
",",
"@",
"error_get_last",
"(",
")",
"[",
"'message'",
"]",
")",
")",
";",
"}",
"chmod",
"(",
"$",
"this",
"->",
"target",
",",
"0755",
")",
";",
"}"
] |
Verifies the downloaded file and saves it to the target location
@throws \RuntimeException
|
[
"Verifies",
"the",
"downloaded",
"file",
"and",
"saves",
"it",
"to",
"the",
"target",
"location"
] |
0c4999a74c55b03a826e1c881f75ee3fba6329f7
|
https://github.com/ibuildingsnl/qa-tools/blob/0c4999a74c55b03a826e1c881f75ee3fba6329f7/installer.php#L655-L679
|
224,129
|
ibuildingsnl/qa-tools
|
installer.php
|
Installer.cleanUp
|
private function cleanUp()
{
if ($this->quiet) {
$errors = explode(PHP_EOL, ob_get_clean());
$shown = [];
foreach ($errors as $error) {
if ($error && !in_array($error, $shown)) {
out($error, 'error');
$shown[] = $error;
}
}
}
if (file_exists($this->tmpPharPath)) {
@unlink($this->tmpPharPath);
}
if (file_exists($this->tmpPubkeyPath)) {
@unlink($this->tmpPharPath);
}
}
|
php
|
private function cleanUp()
{
if ($this->quiet) {
$errors = explode(PHP_EOL, ob_get_clean());
$shown = [];
foreach ($errors as $error) {
if ($error && !in_array($error, $shown)) {
out($error, 'error');
$shown[] = $error;
}
}
}
if (file_exists($this->tmpPharPath)) {
@unlink($this->tmpPharPath);
}
if (file_exists($this->tmpPubkeyPath)) {
@unlink($this->tmpPharPath);
}
}
|
[
"private",
"function",
"cleanUp",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"quiet",
")",
"{",
"$",
"errors",
"=",
"explode",
"(",
"PHP_EOL",
",",
"ob_get_clean",
"(",
")",
")",
";",
"$",
"shown",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"errors",
"as",
"$",
"error",
")",
"{",
"if",
"(",
"$",
"error",
"&&",
"!",
"in_array",
"(",
"$",
"error",
",",
"$",
"shown",
")",
")",
"{",
"out",
"(",
"$",
"error",
",",
"'error'",
")",
";",
"$",
"shown",
"[",
"]",
"=",
"$",
"error",
";",
"}",
"}",
"}",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"tmpPharPath",
")",
")",
"{",
"@",
"unlink",
"(",
"$",
"this",
"->",
"tmpPharPath",
")",
";",
"}",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"tmpPubkeyPath",
")",
")",
"{",
"@",
"unlink",
"(",
"$",
"this",
"->",
"tmpPharPath",
")",
";",
"}",
"}"
] |
Cleans up resources at the end of a failed installation
|
[
"Cleans",
"up",
"resources",
"at",
"the",
"end",
"of",
"a",
"failed",
"installation"
] |
0c4999a74c55b03a826e1c881f75ee3fba6329f7
|
https://github.com/ibuildingsnl/qa-tools/blob/0c4999a74c55b03a826e1c881f75ee3fba6329f7/installer.php#L684-L704
|
224,130
|
sulu/SuluProductBundle
|
Entity/DeliveryStatusTranslation.php
|
DeliveryStatusTranslation.setDeliveryStatus
|
public function setDeliveryStatus(\Sulu\Bundle\ProductBundle\Entity\DeliveryStatus $deliveryStatus)
{
$this->deliveryStatus = $deliveryStatus;
return $this;
}
|
php
|
public function setDeliveryStatus(\Sulu\Bundle\ProductBundle\Entity\DeliveryStatus $deliveryStatus)
{
$this->deliveryStatus = $deliveryStatus;
return $this;
}
|
[
"public",
"function",
"setDeliveryStatus",
"(",
"\\",
"Sulu",
"\\",
"Bundle",
"\\",
"ProductBundle",
"\\",
"Entity",
"\\",
"DeliveryStatus",
"$",
"deliveryStatus",
")",
"{",
"$",
"this",
"->",
"deliveryStatus",
"=",
"$",
"deliveryStatus",
";",
"return",
"$",
"this",
";",
"}"
] |
Set deliveryStatus.
@param \Sulu\Bundle\ProductBundle\Entity\DeliveryStatus $deliveryStatus
@return DeliveryStatusTranslation
|
[
"Set",
"deliveryStatus",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Entity/DeliveryStatusTranslation.php#L104-L109
|
224,131
|
sulu/SuluProductBundle
|
Entity/AttributeSet.php
|
AttributeSet.removeAttribute
|
public function removeAttribute(\Sulu\Bundle\ProductBundle\Entity\Attribute $attributes)
{
$this->attributes->removeElement($attributes);
}
|
php
|
public function removeAttribute(\Sulu\Bundle\ProductBundle\Entity\Attribute $attributes)
{
$this->attributes->removeElement($attributes);
}
|
[
"public",
"function",
"removeAttribute",
"(",
"\\",
"Sulu",
"\\",
"Bundle",
"\\",
"ProductBundle",
"\\",
"Entity",
"\\",
"Attribute",
"$",
"attributes",
")",
"{",
"$",
"this",
"->",
"attributes",
"->",
"removeElement",
"(",
"$",
"attributes",
")",
";",
"}"
] |
Remove attributes.
@param \Sulu\Bundle\ProductBundle\Entity\Attribute $attributes
|
[
"Remove",
"attributes",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Entity/AttributeSet.php#L166-L169
|
224,132
|
sulu/SuluProductBundle
|
Product/ProductLocaleManager.php
|
ProductLocaleManager.retrieveLocale
|
public function retrieveLocale(UserInterface $user = null, $requestLocale = null)
{
$checkedLocale = null;
// When request locale is defined, check if we can use it.
if ($requestLocale && is_string($requestLocale)) {
$checkedLocale = $this->checkLocale($requestLocale);
}
if (!$checkedLocale && $user && $user->getLocale()) {
$checkedLocale = $this->checkLocale($user->getLocale());
}
if ($checkedLocale) {
return $checkedLocale;
}
return $this->configuration['fallback_locale'];
}
|
php
|
public function retrieveLocale(UserInterface $user = null, $requestLocale = null)
{
$checkedLocale = null;
// When request locale is defined, check if we can use it.
if ($requestLocale && is_string($requestLocale)) {
$checkedLocale = $this->checkLocale($requestLocale);
}
if (!$checkedLocale && $user && $user->getLocale()) {
$checkedLocale = $this->checkLocale($user->getLocale());
}
if ($checkedLocale) {
return $checkedLocale;
}
return $this->configuration['fallback_locale'];
}
|
[
"public",
"function",
"retrieveLocale",
"(",
"UserInterface",
"$",
"user",
"=",
"null",
",",
"$",
"requestLocale",
"=",
"null",
")",
"{",
"$",
"checkedLocale",
"=",
"null",
";",
"// When request locale is defined, check if we can use it.",
"if",
"(",
"$",
"requestLocale",
"&&",
"is_string",
"(",
"$",
"requestLocale",
")",
")",
"{",
"$",
"checkedLocale",
"=",
"$",
"this",
"->",
"checkLocale",
"(",
"$",
"requestLocale",
")",
";",
"}",
"if",
"(",
"!",
"$",
"checkedLocale",
"&&",
"$",
"user",
"&&",
"$",
"user",
"->",
"getLocale",
"(",
")",
")",
"{",
"$",
"checkedLocale",
"=",
"$",
"this",
"->",
"checkLocale",
"(",
"$",
"user",
"->",
"getLocale",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"checkedLocale",
")",
"{",
"return",
"$",
"checkedLocale",
";",
"}",
"return",
"$",
"this",
"->",
"configuration",
"[",
"'fallback_locale'",
"]",
";",
"}"
] |
Function returns the locale that should be used by default.
If request-locale is set, then use this one.
Else If users locale matches any of the given locales, that one is taken
as default.
If locale does not match exactly, the users language is compared as well when its provided.
If there are no matches at all, the default-locale as defined in the config
is returned.
@param UserInterface|null $user
@param null|string $requestLocale
@return string
|
[
"Function",
"returns",
"the",
"locale",
"that",
"should",
"be",
"used",
"by",
"default",
".",
"If",
"request",
"-",
"locale",
"is",
"set",
"then",
"use",
"this",
"one",
".",
"Else",
"If",
"users",
"locale",
"matches",
"any",
"of",
"the",
"given",
"locales",
"that",
"one",
"is",
"taken",
"as",
"default",
".",
"If",
"locale",
"does",
"not",
"match",
"exactly",
"the",
"users",
"language",
"is",
"compared",
"as",
"well",
"when",
"its",
"provided",
".",
"If",
"there",
"are",
"no",
"matches",
"at",
"all",
"the",
"default",
"-",
"locale",
"as",
"defined",
"in",
"the",
"config",
"is",
"returned",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductLocaleManager.php#L65-L83
|
224,133
|
sulu/SuluProductBundle
|
Product/ProductLocaleManager.php
|
ProductLocaleManager.checkLocale
|
protected function checkLocale($locale)
{
$languageFound = null;
$language = strstr($locale, '_', true);
foreach ($this->configuration['locales'] as $availableLocale) {
// If locale matches, the exact matching was found.
if ($availableLocale === $locale) {
return $availableLocale;
}
// Check if language (without locale) matches.
if ($language == $availableLocale) {
$languageFound = $availableLocale;
}
}
if ($languageFound) {
return $languageFound;
}
return null;
}
|
php
|
protected function checkLocale($locale)
{
$languageFound = null;
$language = strstr($locale, '_', true);
foreach ($this->configuration['locales'] as $availableLocale) {
// If locale matches, the exact matching was found.
if ($availableLocale === $locale) {
return $availableLocale;
}
// Check if language (without locale) matches.
if ($language == $availableLocale) {
$languageFound = $availableLocale;
}
}
if ($languageFound) {
return $languageFound;
}
return null;
}
|
[
"protected",
"function",
"checkLocale",
"(",
"$",
"locale",
")",
"{",
"$",
"languageFound",
"=",
"null",
";",
"$",
"language",
"=",
"strstr",
"(",
"$",
"locale",
",",
"'_'",
",",
"true",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"configuration",
"[",
"'locales'",
"]",
"as",
"$",
"availableLocale",
")",
"{",
"// If locale matches, the exact matching was found.",
"if",
"(",
"$",
"availableLocale",
"===",
"$",
"locale",
")",
"{",
"return",
"$",
"availableLocale",
";",
"}",
"// Check if language (without locale) matches.",
"if",
"(",
"$",
"language",
"==",
"$",
"availableLocale",
")",
"{",
"$",
"languageFound",
"=",
"$",
"availableLocale",
";",
"}",
"}",
"if",
"(",
"$",
"languageFound",
")",
"{",
"return",
"$",
"languageFound",
";",
"}",
"return",
"null",
";",
"}"
] |
Check if given locale is available in the configured locales.
@param string $locale
@return null|string
|
[
"Check",
"if",
"given",
"locale",
"is",
"available",
"in",
"the",
"configured",
"locales",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductLocaleManager.php#L92-L114
|
224,134
|
sulu/SuluProductBundle
|
Entity/DeliveryStatusRepository.php
|
DeliveryStatusRepository.findAllByLocale
|
public function findAllByLocale($locale)
{
try {
$qb = $this->getStatusQuery($locale);
return $qb->getQuery()->getResult();
} catch (NoResultException $exc) {
return null;
}
}
|
php
|
public function findAllByLocale($locale)
{
try {
$qb = $this->getStatusQuery($locale);
return $qb->getQuery()->getResult();
} catch (NoResultException $exc) {
return null;
}
}
|
[
"public",
"function",
"findAllByLocale",
"(",
"$",
"locale",
")",
"{",
"try",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"getStatusQuery",
"(",
"$",
"locale",
")",
";",
"return",
"$",
"qb",
"->",
"getQuery",
"(",
")",
"->",
"getResult",
"(",
")",
";",
"}",
"catch",
"(",
"NoResultException",
"$",
"exc",
")",
"{",
"return",
"null",
";",
"}",
"}"
] |
Returns the statuses with the given locale.
@param string $locale The locale to load
@return Status[]|null
|
[
"Returns",
"the",
"statuses",
"with",
"the",
"given",
"locale",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Entity/DeliveryStatusRepository.php#L29-L38
|
224,135
|
amsgames/laravel-shop-gateway-paypal
|
src/GatewayPayPal.php
|
GatewayPayPal.onCheckout
|
public function onCheckout($cart)
{
if (!isset($this->creditCard))
throw new CheckoutException('Credit Card is not set.', 0);
if (!in_array($this->creditCard->getType(), $this->validTypes))
throw new CheckoutException('Credit Card is not supported.', 1);
if ($this->getPatternType($this->creditCard->getNumber()) != $this->creditCard->getType())
throw new CheckoutException('Credit Card is invalid.', 2);
}
|
php
|
public function onCheckout($cart)
{
if (!isset($this->creditCard))
throw new CheckoutException('Credit Card is not set.', 0);
if (!in_array($this->creditCard->getType(), $this->validTypes))
throw new CheckoutException('Credit Card is not supported.', 1);
if ($this->getPatternType($this->creditCard->getNumber()) != $this->creditCard->getType())
throw new CheckoutException('Credit Card is invalid.', 2);
}
|
[
"public",
"function",
"onCheckout",
"(",
"$",
"cart",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"creditCard",
")",
")",
"throw",
"new",
"CheckoutException",
"(",
"'Credit Card is not set.'",
",",
"0",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"this",
"->",
"creditCard",
"->",
"getType",
"(",
")",
",",
"$",
"this",
"->",
"validTypes",
")",
")",
"throw",
"new",
"CheckoutException",
"(",
"'Credit Card is not supported.'",
",",
"1",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getPatternType",
"(",
"$",
"this",
"->",
"creditCard",
"->",
"getNumber",
"(",
")",
")",
"!=",
"$",
"this",
"->",
"creditCard",
"->",
"getType",
"(",
")",
")",
"throw",
"new",
"CheckoutException",
"(",
"'Credit Card is invalid.'",
",",
"2",
")",
";",
"}"
] |
Called on cart checkout.
@param Cart $cart Cart.
|
[
"Called",
"on",
"cart",
"checkout",
"."
] |
c0ba041bda3fdcc696e4a01278647f386e9d8715
|
https://github.com/amsgames/laravel-shop-gateway-paypal/blob/c0ba041bda3fdcc696e4a01278647f386e9d8715/src/GatewayPayPal.php#L57-L67
|
224,136
|
amsgames/laravel-shop-gateway-paypal
|
src/GatewayPayPal.php
|
GatewayPayPal.setCreditCard
|
public function setCreditCard(
$type,
$number,
$expireMonth,
$expireYear,
$cvv,
$firstname,
$lastname
) {
$this->creditCard = new CreditCard();
$this->creditCard->setType($type)
->setNumber($number)
->setExpireMonth($expireMonth)
->setExpireYear($expireYear)
->setCvv2($cvv)
->setFirstName($firstname)
->setLastName($lastname);
return $this;
}
|
php
|
public function setCreditCard(
$type,
$number,
$expireMonth,
$expireYear,
$cvv,
$firstname,
$lastname
) {
$this->creditCard = new CreditCard();
$this->creditCard->setType($type)
->setNumber($number)
->setExpireMonth($expireMonth)
->setExpireYear($expireYear)
->setCvv2($cvv)
->setFirstName($firstname)
->setLastName($lastname);
return $this;
}
|
[
"public",
"function",
"setCreditCard",
"(",
"$",
"type",
",",
"$",
"number",
",",
"$",
"expireMonth",
",",
"$",
"expireYear",
",",
"$",
"cvv",
",",
"$",
"firstname",
",",
"$",
"lastname",
")",
"{",
"$",
"this",
"->",
"creditCard",
"=",
"new",
"CreditCard",
"(",
")",
";",
"$",
"this",
"->",
"creditCard",
"->",
"setType",
"(",
"$",
"type",
")",
"->",
"setNumber",
"(",
"$",
"number",
")",
"->",
"setExpireMonth",
"(",
"$",
"expireMonth",
")",
"->",
"setExpireYear",
"(",
"$",
"expireYear",
")",
"->",
"setCvv2",
"(",
"$",
"cvv",
")",
"->",
"setFirstName",
"(",
"$",
"firstname",
")",
"->",
"setLastName",
"(",
"$",
"lastname",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Sets credit card for usage.
@param string $type Card type. i.e. visa, mastercard
@param int $number Card number.
@param mixed $expireMonth Month in which the card expires.
@param mixed $expireYear Year in which the card expires.
@param int $cvv CVV.
@param string $firstname First name printed in card.
@param string $lastname Last name printed in card.
|
[
"Sets",
"credit",
"card",
"for",
"usage",
"."
] |
c0ba041bda3fdcc696e4a01278647f386e9d8715
|
https://github.com/amsgames/laravel-shop-gateway-paypal/blob/c0ba041bda3fdcc696e4a01278647f386e9d8715/src/GatewayPayPal.php#L183-L203
|
224,137
|
amsgames/laravel-shop-gateway-paypal
|
src/GatewayPayPal.php
|
GatewayPayPal.getPatternType
|
private function getPatternType($cardNumber)
{
if (empty($cardNumber)) return;
$types = [
'visa' => '(4\d{12}(?:\d{3})?)',
'amex' => '(3[47]\d{13})',
'jcb' => '(35[2-8][89]\d\d\d{10})',
'maestro' => '((?:5020|5038|6304|6579|6761)\d{12}(?:\d\d)?)',
'solo' => '((?:6334|6767)\d{12}(?:\d\d)?\d?)',
'mastercard' => '(5[1-5]\d{14})',
'switch' => '(?:(?:(?:4903|4905|4911|4936|6333|6759)\d{12})|(?:(?:564182|633110)\d{10})(\d\d)?\d?)',
];
$names = ['visa','amex', 'jcb', 'maestro', 'solo', 'mastercard', 'switch'];
$matches = [];
$pattern = "#^(?:" . implode('|', $types) . ")$#";
$result = preg_match($pattern, str_replace(' ', '', $cardNumber), $matches);
return $result > 0 ? $names[sizeof($matches)-2] : false;
}
|
php
|
private function getPatternType($cardNumber)
{
if (empty($cardNumber)) return;
$types = [
'visa' => '(4\d{12}(?:\d{3})?)',
'amex' => '(3[47]\d{13})',
'jcb' => '(35[2-8][89]\d\d\d{10})',
'maestro' => '((?:5020|5038|6304|6579|6761)\d{12}(?:\d\d)?)',
'solo' => '((?:6334|6767)\d{12}(?:\d\d)?\d?)',
'mastercard' => '(5[1-5]\d{14})',
'switch' => '(?:(?:(?:4903|4905|4911|4936|6333|6759)\d{12})|(?:(?:564182|633110)\d{10})(\d\d)?\d?)',
];
$names = ['visa','amex', 'jcb', 'maestro', 'solo', 'mastercard', 'switch'];
$matches = [];
$pattern = "#^(?:" . implode('|', $types) . ")$#";
$result = preg_match($pattern, str_replace(' ', '', $cardNumber), $matches);
return $result > 0 ? $names[sizeof($matches)-2] : false;
}
|
[
"private",
"function",
"getPatternType",
"(",
"$",
"cardNumber",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"cardNumber",
")",
")",
"return",
";",
"$",
"types",
"=",
"[",
"'visa'",
"=>",
"'(4\\d{12}(?:\\d{3})?)'",
",",
"'amex'",
"=>",
"'(3[47]\\d{13})'",
",",
"'jcb'",
"=>",
"'(35[2-8][89]\\d\\d\\d{10})'",
",",
"'maestro'",
"=>",
"'((?:5020|5038|6304|6579|6761)\\d{12}(?:\\d\\d)?)'",
",",
"'solo'",
"=>",
"'((?:6334|6767)\\d{12}(?:\\d\\d)?\\d?)'",
",",
"'mastercard'",
"=>",
"'(5[1-5]\\d{14})'",
",",
"'switch'",
"=>",
"'(?:(?:(?:4903|4905|4911|4936|6333|6759)\\d{12})|(?:(?:564182|633110)\\d{10})(\\d\\d)?\\d?)'",
",",
"]",
";",
"$",
"names",
"=",
"[",
"'visa'",
",",
"'amex'",
",",
"'jcb'",
",",
"'maestro'",
",",
"'solo'",
",",
"'mastercard'",
",",
"'switch'",
"]",
";",
"$",
"matches",
"=",
"[",
"]",
";",
"$",
"pattern",
"=",
"\"#^(?:\"",
".",
"implode",
"(",
"'|'",
",",
"$",
"types",
")",
".",
"\")$#\"",
";",
"$",
"result",
"=",
"preg_match",
"(",
"$",
"pattern",
",",
"str_replace",
"(",
"' '",
",",
"''",
",",
"$",
"cardNumber",
")",
",",
"$",
"matches",
")",
";",
"return",
"$",
"result",
">",
"0",
"?",
"$",
"names",
"[",
"sizeof",
"(",
"$",
"matches",
")",
"-",
"2",
"]",
":",
"false",
";",
"}"
] |
Returns the credit card type based on a credit card number pattern.
@param string $cardNumber Credit card number.
@return string
|
[
"Returns",
"the",
"credit",
"card",
"type",
"based",
"on",
"a",
"credit",
"card",
"number",
"pattern",
"."
] |
c0ba041bda3fdcc696e4a01278647f386e9d8715
|
https://github.com/amsgames/laravel-shop-gateway-paypal/blob/c0ba041bda3fdcc696e4a01278647f386e9d8715/src/GatewayPayPal.php#L257-L279
|
224,138
|
culturekings/afterpay
|
src/Service/InStore/Refund.php
|
Refund.createOrReverse
|
public function createOrReverse(
Model\InStore\Refund $refund,
Model\InStore\Reversal $refundReversal = null,
HandlerStack $stack = null
) {
try {
return $this->create($refund, $stack);
} catch (ApiException $refundException) {
// http://docs.afterpay.com.au/instore-api-v1.html#create-refund
// Should a success or error response (with exception to 409 conflict) not be received,
// the POS should queue the request ID for reversal
if ($refundException->getErrorResponse()->getErrorCode() == self::ERROR_CONFLICT) {
throw $refundException;
}
$errorResponse = $refundException->getErrorResponse();
} catch (RequestException $refundException) {
// a timeout or other exception has occurred. attempt a reversal
$errorResponse = new Model\ErrorResponse();
$errorResponse->setHttpStatusCode(
$refundException->getResponse() ? $refundException->getResponse()->getStatusCode() : self::ERROR_INTERNAL_ERROR
);
$errorResponse->setMessage($refundException->getMessage());
}
$now = new \DateTime();
if ($refundReversal === null) {
$refundReversal = new Model\InStore\Reversal();
$refundReversal->setReversingRequestId($refund->getRequestId());
$refundReversal->setRequestedAt($now);
}
try {
$reversal = $this->reverse($refundReversal, $stack);
$reversal->setErrorReason($errorResponse);
return $reversal;
} catch (ApiException $reversalException) {
$reversalErrorResponse = $reversalException->getErrorResponse();
if ($reversalErrorResponse->getErrorCode() === self::ERROR_MSG_PRECONDITION_FAILED) {
// there was trouble reversing probably because the refund failed
throw $refundException;
}
throw $reversalException;
}
}
|
php
|
public function createOrReverse(
Model\InStore\Refund $refund,
Model\InStore\Reversal $refundReversal = null,
HandlerStack $stack = null
) {
try {
return $this->create($refund, $stack);
} catch (ApiException $refundException) {
// http://docs.afterpay.com.au/instore-api-v1.html#create-refund
// Should a success or error response (with exception to 409 conflict) not be received,
// the POS should queue the request ID for reversal
if ($refundException->getErrorResponse()->getErrorCode() == self::ERROR_CONFLICT) {
throw $refundException;
}
$errorResponse = $refundException->getErrorResponse();
} catch (RequestException $refundException) {
// a timeout or other exception has occurred. attempt a reversal
$errorResponse = new Model\ErrorResponse();
$errorResponse->setHttpStatusCode(
$refundException->getResponse() ? $refundException->getResponse()->getStatusCode() : self::ERROR_INTERNAL_ERROR
);
$errorResponse->setMessage($refundException->getMessage());
}
$now = new \DateTime();
if ($refundReversal === null) {
$refundReversal = new Model\InStore\Reversal();
$refundReversal->setReversingRequestId($refund->getRequestId());
$refundReversal->setRequestedAt($now);
}
try {
$reversal = $this->reverse($refundReversal, $stack);
$reversal->setErrorReason($errorResponse);
return $reversal;
} catch (ApiException $reversalException) {
$reversalErrorResponse = $reversalException->getErrorResponse();
if ($reversalErrorResponse->getErrorCode() === self::ERROR_MSG_PRECONDITION_FAILED) {
// there was trouble reversing probably because the refund failed
throw $refundException;
}
throw $reversalException;
}
}
|
[
"public",
"function",
"createOrReverse",
"(",
"Model",
"\\",
"InStore",
"\\",
"Refund",
"$",
"refund",
",",
"Model",
"\\",
"InStore",
"\\",
"Reversal",
"$",
"refundReversal",
"=",
"null",
",",
"HandlerStack",
"$",
"stack",
"=",
"null",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"create",
"(",
"$",
"refund",
",",
"$",
"stack",
")",
";",
"}",
"catch",
"(",
"ApiException",
"$",
"refundException",
")",
"{",
"// http://docs.afterpay.com.au/instore-api-v1.html#create-refund",
"// Should a success or error response (with exception to 409 conflict) not be received,",
"// the POS should queue the request ID for reversal",
"if",
"(",
"$",
"refundException",
"->",
"getErrorResponse",
"(",
")",
"->",
"getErrorCode",
"(",
")",
"==",
"self",
"::",
"ERROR_CONFLICT",
")",
"{",
"throw",
"$",
"refundException",
";",
"}",
"$",
"errorResponse",
"=",
"$",
"refundException",
"->",
"getErrorResponse",
"(",
")",
";",
"}",
"catch",
"(",
"RequestException",
"$",
"refundException",
")",
"{",
"// a timeout or other exception has occurred. attempt a reversal",
"$",
"errorResponse",
"=",
"new",
"Model",
"\\",
"ErrorResponse",
"(",
")",
";",
"$",
"errorResponse",
"->",
"setHttpStatusCode",
"(",
"$",
"refundException",
"->",
"getResponse",
"(",
")",
"?",
"$",
"refundException",
"->",
"getResponse",
"(",
")",
"->",
"getStatusCode",
"(",
")",
":",
"self",
"::",
"ERROR_INTERNAL_ERROR",
")",
";",
"$",
"errorResponse",
"->",
"setMessage",
"(",
"$",
"refundException",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"$",
"now",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"if",
"(",
"$",
"refundReversal",
"===",
"null",
")",
"{",
"$",
"refundReversal",
"=",
"new",
"Model",
"\\",
"InStore",
"\\",
"Reversal",
"(",
")",
";",
"$",
"refundReversal",
"->",
"setReversingRequestId",
"(",
"$",
"refund",
"->",
"getRequestId",
"(",
")",
")",
";",
"$",
"refundReversal",
"->",
"setRequestedAt",
"(",
"$",
"now",
")",
";",
"}",
"try",
"{",
"$",
"reversal",
"=",
"$",
"this",
"->",
"reverse",
"(",
"$",
"refundReversal",
",",
"$",
"stack",
")",
";",
"$",
"reversal",
"->",
"setErrorReason",
"(",
"$",
"errorResponse",
")",
";",
"return",
"$",
"reversal",
";",
"}",
"catch",
"(",
"ApiException",
"$",
"reversalException",
")",
"{",
"$",
"reversalErrorResponse",
"=",
"$",
"reversalException",
"->",
"getErrorResponse",
"(",
")",
";",
"if",
"(",
"$",
"reversalErrorResponse",
"->",
"getErrorCode",
"(",
")",
"===",
"self",
"::",
"ERROR_MSG_PRECONDITION_FAILED",
")",
"{",
"// there was trouble reversing probably because the refund failed",
"throw",
"$",
"refundException",
";",
"}",
"throw",
"$",
"reversalException",
";",
"}",
"}"
] |
Helper method to automatically attempt to reverse a refund if an error occurs.
Refund reversal model does not have to be passed in and will be automatically generated if not.
@param Model\InStore\Refund $refund
@param Model\InStore\Reversal|null $refundReversal
@param HandlerStack|null $stack
@return Model\InStore\Refund|Model\InStore\Reversal|array|\JMS\Serializer\scalar|object
|
[
"Helper",
"method",
"to",
"automatically",
"attempt",
"to",
"reverse",
"a",
"refund",
"if",
"an",
"error",
"occurs",
"."
] |
d2fde2eed6d6102464ffd9d3bea7623f31e77a61
|
https://github.com/culturekings/afterpay/blob/d2fde2eed6d6102464ffd9d3bea7623f31e77a61/src/Service/InStore/Refund.php#L100-L145
|
224,139
|
unreal4u/mqtt
|
src/DataTypes/TopicFilter.php
|
TopicFilter.setTopicName
|
private function setTopicName(string $topicFilter): self
{
$this->generalRulesCheck($topicFilter);
$this->topicFilter = $topicFilter;
return $this;
}
|
php
|
private function setTopicName(string $topicFilter): self
{
$this->generalRulesCheck($topicFilter);
$this->topicFilter = $topicFilter;
return $this;
}
|
[
"private",
"function",
"setTopicName",
"(",
"string",
"$",
"topicFilter",
")",
":",
"self",
"{",
"$",
"this",
"->",
"generalRulesCheck",
"(",
"$",
"topicFilter",
")",
";",
"$",
"this",
"->",
"topicFilter",
"=",
"$",
"topicFilter",
";",
"return",
"$",
"this",
";",
"}"
] |
Will validate and set the topic filter
@param string $topicFilter
@return TopicFilter
@throws \OutOfBoundsException
@throws \InvalidArgumentException
|
[
"Will",
"validate",
"and",
"set",
"the",
"topic",
"filter"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/DataTypes/TopicFilter.php#L61-L67
|
224,140
|
ibuildingsnl/qa-tools
|
src/Core/Composer/RequireCache.php
|
RequireCache.storeConfiguration
|
public function storeConfiguration(
Configuration $targetConfiguration,
PackageSet $requiredPackages,
Configuration $newConfiguration
) {
$key = $this->getKey($targetConfiguration, $requiredPackages);
$this->configurations[$key] = $newConfiguration;
}
|
php
|
public function storeConfiguration(
Configuration $targetConfiguration,
PackageSet $requiredPackages,
Configuration $newConfiguration
) {
$key = $this->getKey($targetConfiguration, $requiredPackages);
$this->configurations[$key] = $newConfiguration;
}
|
[
"public",
"function",
"storeConfiguration",
"(",
"Configuration",
"$",
"targetConfiguration",
",",
"PackageSet",
"$",
"requiredPackages",
",",
"Configuration",
"$",
"newConfiguration",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"getKey",
"(",
"$",
"targetConfiguration",
",",
"$",
"requiredPackages",
")",
";",
"$",
"this",
"->",
"configurations",
"[",
"$",
"key",
"]",
"=",
"$",
"newConfiguration",
";",
"}"
] |
Stores the Composer newConfiguration that resulted from requiring the given set of
requiredPackages.
@param Configuration $targetConfiguration The configuration on which the require was performed.
@param PackageSet $requiredPackages
@param Configuration $newConfiguration The configuration that resulted from the require.
@return void
|
[
"Stores",
"the",
"Composer",
"newConfiguration",
"that",
"resulted",
"from",
"requiring",
"the",
"given",
"set",
"of",
"requiredPackages",
"."
] |
0c4999a74c55b03a826e1c881f75ee3fba6329f7
|
https://github.com/ibuildingsnl/qa-tools/blob/0c4999a74c55b03a826e1c881f75ee3fba6329f7/src/Core/Composer/RequireCache.php#L30-L38
|
224,141
|
TypistTech/wp-admin-tabs
|
src/AdminTab.php
|
AdminTab.isActive
|
public function isActive(): bool
{
if (! isset($_SERVER['REQUEST_URI'])) { // Input var okay.
return false;
}
$currentUrl = esc_url_raw(
wp_unslash($_SERVER['REQUEST_URI']) // Input var okay.
);
$matchUrl = str_replace(
esc_url_raw(get_site_url()),
'',
esc_url_raw($this->getUrl())
);
return 0 === strpos($currentUrl, $matchUrl);
}
|
php
|
public function isActive(): bool
{
if (! isset($_SERVER['REQUEST_URI'])) { // Input var okay.
return false;
}
$currentUrl = esc_url_raw(
wp_unslash($_SERVER['REQUEST_URI']) // Input var okay.
);
$matchUrl = str_replace(
esc_url_raw(get_site_url()),
'',
esc_url_raw($this->getUrl())
);
return 0 === strpos($currentUrl, $matchUrl);
}
|
[
"public",
"function",
"isActive",
"(",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
")",
")",
"{",
"// Input var okay.",
"return",
"false",
";",
"}",
"$",
"currentUrl",
"=",
"esc_url_raw",
"(",
"wp_unslash",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
")",
"// Input var okay.",
")",
";",
"$",
"matchUrl",
"=",
"str_replace",
"(",
"esc_url_raw",
"(",
"get_site_url",
"(",
")",
")",
",",
"''",
",",
"esc_url_raw",
"(",
"$",
"this",
"->",
"getUrl",
"(",
")",
")",
")",
";",
"return",
"0",
"===",
"strpos",
"(",
"$",
"currentUrl",
",",
"$",
"matchUrl",
")",
";",
"}"
] |
Whether this tab is active, i.e. current screen is on this tab.
@return bool
|
[
"Whether",
"this",
"tab",
"is",
"active",
"i",
".",
"e",
".",
"current",
"screen",
"is",
"on",
"this",
"tab",
"."
] |
f70386fbe8c2f8823cbee25e5b8fdeddfab00eaf
|
https://github.com/TypistTech/wp-admin-tabs/blob/f70386fbe8c2f8823cbee25e5b8fdeddfab00eaf/src/AdminTab.php#L81-L98
|
224,142
|
TypistTech/wp-admin-tabs
|
src/AdminTabCollection.php
|
AdminTabCollection.add
|
public function add(AdminTab ...$adminTabs)
{
$this->adminTabs = array_unique(
array_merge($this->adminTabs, $adminTabs),
SORT_REGULAR
);
}
|
php
|
public function add(AdminTab ...$adminTabs)
{
$this->adminTabs = array_unique(
array_merge($this->adminTabs, $adminTabs),
SORT_REGULAR
);
}
|
[
"public",
"function",
"add",
"(",
"AdminTab",
"...",
"$",
"adminTabs",
")",
"{",
"$",
"this",
"->",
"adminTabs",
"=",
"array_unique",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"adminTabs",
",",
"$",
"adminTabs",
")",
",",
"SORT_REGULAR",
")",
";",
"}"
] |
Add admin tabs.
@param AdminTab[] ...$adminTabs Admin tabs to be added.
@return void
|
[
"Add",
"admin",
"tabs",
"."
] |
f70386fbe8c2f8823cbee25e5b8fdeddfab00eaf
|
https://github.com/TypistTech/wp-admin-tabs/blob/f70386fbe8c2f8823cbee25e5b8fdeddfab00eaf/src/AdminTabCollection.php#L44-L50
|
224,143
|
joachim-n/case-converter
|
CaseString.php
|
CaseString.sentence
|
public static function sentence($string) {
$pieces = explode(' ', $string);
// Put the first word into lowercase, unless it's all capitals.
if (!preg_match('@^[[:upper:]]+$@', $pieces[0])) {
$pieces[0] = lcfirst($pieces[0]);
}
return new StringAssembler($pieces);
}
|
php
|
public static function sentence($string) {
$pieces = explode(' ', $string);
// Put the first word into lowercase, unless it's all capitals.
if (!preg_match('@^[[:upper:]]+$@', $pieces[0])) {
$pieces[0] = lcfirst($pieces[0]);
}
return new StringAssembler($pieces);
}
|
[
"public",
"static",
"function",
"sentence",
"(",
"$",
"string",
")",
"{",
"$",
"pieces",
"=",
"explode",
"(",
"' '",
",",
"$",
"string",
")",
";",
"// Put the first word into lowercase, unless it's all capitals.",
"if",
"(",
"!",
"preg_match",
"(",
"'@^[[:upper:]]+$@'",
",",
"$",
"pieces",
"[",
"0",
"]",
")",
")",
"{",
"$",
"pieces",
"[",
"0",
"]",
"=",
"lcfirst",
"(",
"$",
"pieces",
"[",
"0",
"]",
")",
";",
"}",
"return",
"new",
"StringAssembler",
"(",
"$",
"pieces",
")",
";",
"}"
] |
Takes a sentence case string.
@param $string
The string.
@return \CaseConverter\StringAssembler
A string assembler object with the string pieces set on it.
|
[
"Takes",
"a",
"sentence",
"case",
"string",
"."
] |
f31486030bd46242218a0d7d75becab0b02da2f4
|
https://github.com/joachim-n/case-converter/blob/f31486030bd46242218a0d7d75becab0b02da2f4/CaseString.php#L105-L114
|
224,144
|
sulu/SuluProductBundle
|
Controller/TemplateController.php
|
TemplateController.productFormAction
|
public function productFormAction()
{
$userLocale = $this->getUser()->getLocale();
$status = $this->getStatus($userLocale);
$units = $this->getUnits($userLocale);
$deliveryStates = $this->getDeliveryStates($userLocale);
return $this->render(
'SuluProductBundle:Template:product.form.html.twig',
[
'MAX_SEARCH_TERMS_LENGTH' => ProductManager::MAX_SEARCH_TERMS_LENGTH,
'status' => $status,
'units' => $units,
'deliveryStates' => $deliveryStates,
'categoryUrl' => $this->getCategoryUrl(),
]
);
}
|
php
|
public function productFormAction()
{
$userLocale = $this->getUser()->getLocale();
$status = $this->getStatus($userLocale);
$units = $this->getUnits($userLocale);
$deliveryStates = $this->getDeliveryStates($userLocale);
return $this->render(
'SuluProductBundle:Template:product.form.html.twig',
[
'MAX_SEARCH_TERMS_LENGTH' => ProductManager::MAX_SEARCH_TERMS_LENGTH,
'status' => $status,
'units' => $units,
'deliveryStates' => $deliveryStates,
'categoryUrl' => $this->getCategoryUrl(),
]
);
}
|
[
"public",
"function",
"productFormAction",
"(",
")",
"{",
"$",
"userLocale",
"=",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"getLocale",
"(",
")",
";",
"$",
"status",
"=",
"$",
"this",
"->",
"getStatus",
"(",
"$",
"userLocale",
")",
";",
"$",
"units",
"=",
"$",
"this",
"->",
"getUnits",
"(",
"$",
"userLocale",
")",
";",
"$",
"deliveryStates",
"=",
"$",
"this",
"->",
"getDeliveryStates",
"(",
"$",
"userLocale",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'SuluProductBundle:Template:product.form.html.twig'",
",",
"[",
"'MAX_SEARCH_TERMS_LENGTH'",
"=>",
"ProductManager",
"::",
"MAX_SEARCH_TERMS_LENGTH",
",",
"'status'",
"=>",
"$",
"status",
",",
"'units'",
"=>",
"$",
"units",
",",
"'deliveryStates'",
"=>",
"$",
"deliveryStates",
",",
"'categoryUrl'",
"=>",
"$",
"this",
"->",
"getCategoryUrl",
"(",
")",
",",
"]",
")",
";",
"}"
] |
Returns template for product list.
@return Response
|
[
"Returns",
"template",
"for",
"product",
"list",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Controller/TemplateController.php#L38-L56
|
224,145
|
sulu/SuluProductBundle
|
Controller/TemplateController.php
|
TemplateController.attributeFormAction
|
public function attributeFormAction()
{
$repository = $this->getDoctrine()
->getRepository('SuluProductBundle:AttributeType');
$types = $repository->findAll();
$attributeTypes = [];
foreach ($types as $type) {
$attributeTypes[] = [
'id' => $type->getId(),
'name' => $type->getName(),
];
}
return $this->render(
'SuluProductBundle:Template:attribute.form.html.twig',
[
'attribute_types' => $attributeTypes,
]
);
}
|
php
|
public function attributeFormAction()
{
$repository = $this->getDoctrine()
->getRepository('SuluProductBundle:AttributeType');
$types = $repository->findAll();
$attributeTypes = [];
foreach ($types as $type) {
$attributeTypes[] = [
'id' => $type->getId(),
'name' => $type->getName(),
];
}
return $this->render(
'SuluProductBundle:Template:attribute.form.html.twig',
[
'attribute_types' => $attributeTypes,
]
);
}
|
[
"public",
"function",
"attributeFormAction",
"(",
")",
"{",
"$",
"repository",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getRepository",
"(",
"'SuluProductBundle:AttributeType'",
")",
";",
"$",
"types",
"=",
"$",
"repository",
"->",
"findAll",
"(",
")",
";",
"$",
"attributeTypes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"types",
"as",
"$",
"type",
")",
"{",
"$",
"attributeTypes",
"[",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"type",
"->",
"getId",
"(",
")",
",",
"'name'",
"=>",
"$",
"type",
"->",
"getName",
"(",
")",
",",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'SuluProductBundle:Template:attribute.form.html.twig'",
",",
"[",
"'attribute_types'",
"=>",
"$",
"attributeTypes",
",",
"]",
")",
";",
"}"
] |
Returns template for attribute list.
@return Response
|
[
"Returns",
"template",
"for",
"attribute",
"list",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Controller/TemplateController.php#L97-L117
|
224,146
|
sulu/SuluProductBundle
|
Controller/TemplateController.php
|
TemplateController.productPricingAction
|
public function productPricingAction()
{
$userLocale = $this->getUser()->getLocale();
/** @var TaxClass[] $taxClasses */
$taxClasses = $this->get('sulu_product.tax_class_manager')->findAll($userLocale);
$taxClassTitles = [];
foreach ($taxClasses as $taxClass) {
$taxClassTitles[] = [
'id' => $taxClass->getId(),
'name' => $taxClass->getName(),
];
}
$currencies = $this->getCurrencies($userLocale);
$defaultCurrency = $this->container->getParameter('sulu_product.default_currency');
$displayRecurringPrices = $this->container->getParameter('sulu_product.display_recurring_prices');
return $this->render(
'SuluProductBundle:Template:product.pricing.html.twig',
[
'taxClasses' => $taxClassTitles,
'currencies' => $currencies,
'defaultCurrency' => $defaultCurrency,
'displayRecurringPrices' => $displayRecurringPrices,
]
);
}
|
php
|
public function productPricingAction()
{
$userLocale = $this->getUser()->getLocale();
/** @var TaxClass[] $taxClasses */
$taxClasses = $this->get('sulu_product.tax_class_manager')->findAll($userLocale);
$taxClassTitles = [];
foreach ($taxClasses as $taxClass) {
$taxClassTitles[] = [
'id' => $taxClass->getId(),
'name' => $taxClass->getName(),
];
}
$currencies = $this->getCurrencies($userLocale);
$defaultCurrency = $this->container->getParameter('sulu_product.default_currency');
$displayRecurringPrices = $this->container->getParameter('sulu_product.display_recurring_prices');
return $this->render(
'SuluProductBundle:Template:product.pricing.html.twig',
[
'taxClasses' => $taxClassTitles,
'currencies' => $currencies,
'defaultCurrency' => $defaultCurrency,
'displayRecurringPrices' => $displayRecurringPrices,
]
);
}
|
[
"public",
"function",
"productPricingAction",
"(",
")",
"{",
"$",
"userLocale",
"=",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"getLocale",
"(",
")",
";",
"/** @var TaxClass[] $taxClasses */",
"$",
"taxClasses",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_product.tax_class_manager'",
")",
"->",
"findAll",
"(",
"$",
"userLocale",
")",
";",
"$",
"taxClassTitles",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"taxClasses",
"as",
"$",
"taxClass",
")",
"{",
"$",
"taxClassTitles",
"[",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"taxClass",
"->",
"getId",
"(",
")",
",",
"'name'",
"=>",
"$",
"taxClass",
"->",
"getName",
"(",
")",
",",
"]",
";",
"}",
"$",
"currencies",
"=",
"$",
"this",
"->",
"getCurrencies",
"(",
"$",
"userLocale",
")",
";",
"$",
"defaultCurrency",
"=",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'sulu_product.default_currency'",
")",
";",
"$",
"displayRecurringPrices",
"=",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'sulu_product.display_recurring_prices'",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'SuluProductBundle:Template:product.pricing.html.twig'",
",",
"[",
"'taxClasses'",
"=>",
"$",
"taxClassTitles",
",",
"'currencies'",
"=>",
"$",
"currencies",
",",
"'defaultCurrency'",
"=>",
"$",
"defaultCurrency",
",",
"'displayRecurringPrices'",
"=>",
"$",
"displayRecurringPrices",
",",
"]",
")",
";",
"}"
] |
Returns template for product pricing.
@return Response
|
[
"Returns",
"template",
"for",
"product",
"pricing",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Controller/TemplateController.php#L124-L152
|
224,147
|
sulu/SuluProductBundle
|
Controller/TemplateController.php
|
TemplateController.getStatus
|
protected function getStatus($locale)
{
/** @var Status[] $statuses */
$statuses = $this->get('sulu_product.status_manager')->findAll($locale);
$statusTitles = [];
foreach ($statuses as $status) {
$statusTitles[] = [
'id' => $status->getId(),
'name' => $status->getName(),
];
}
return $statusTitles;
}
|
php
|
protected function getStatus($locale)
{
/** @var Status[] $statuses */
$statuses = $this->get('sulu_product.status_manager')->findAll($locale);
$statusTitles = [];
foreach ($statuses as $status) {
$statusTitles[] = [
'id' => $status->getId(),
'name' => $status->getName(),
];
}
return $statusTitles;
}
|
[
"protected",
"function",
"getStatus",
"(",
"$",
"locale",
")",
"{",
"/** @var Status[] $statuses */",
"$",
"statuses",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_product.status_manager'",
")",
"->",
"findAll",
"(",
"$",
"locale",
")",
";",
"$",
"statusTitles",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"statuses",
"as",
"$",
"status",
")",
"{",
"$",
"statusTitles",
"[",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"status",
"->",
"getId",
"(",
")",
",",
"'name'",
"=>",
"$",
"status",
"->",
"getName",
"(",
")",
",",
"]",
";",
"}",
"return",
"$",
"statusTitles",
";",
"}"
] |
Returns status for products.
@param string $locale
@return array
|
[
"Returns",
"status",
"for",
"products",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Controller/TemplateController.php#L191-L205
|
224,148
|
sulu/SuluProductBundle
|
Controller/TemplateController.php
|
TemplateController.getUnits
|
protected function getUnits($locale)
{
/** @var Status[] $units */
$units = $this->get('sulu_product.unit_manager')->findAll($locale);
$unitTitles = [];
foreach ($units as $unit) {
$unitTitles[] = [
'id' => $unit->getId(),
'name' => $unit->getName(),
];
}
return $unitTitles;
}
|
php
|
protected function getUnits($locale)
{
/** @var Status[] $units */
$units = $this->get('sulu_product.unit_manager')->findAll($locale);
$unitTitles = [];
foreach ($units as $unit) {
$unitTitles[] = [
'id' => $unit->getId(),
'name' => $unit->getName(),
];
}
return $unitTitles;
}
|
[
"protected",
"function",
"getUnits",
"(",
"$",
"locale",
")",
"{",
"/** @var Status[] $units */",
"$",
"units",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_product.unit_manager'",
")",
"->",
"findAll",
"(",
"$",
"locale",
")",
";",
"$",
"unitTitles",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"units",
"as",
"$",
"unit",
")",
"{",
"$",
"unitTitles",
"[",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"unit",
"->",
"getId",
"(",
")",
",",
"'name'",
"=>",
"$",
"unit",
"->",
"getName",
"(",
")",
",",
"]",
";",
"}",
"return",
"$",
"unitTitles",
";",
"}"
] |
Returns units.
@param string $locale
@return array
|
[
"Returns",
"units",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Controller/TemplateController.php#L214-L228
|
224,149
|
sulu/SuluProductBundle
|
Controller/TemplateController.php
|
TemplateController.getCurrencies
|
protected function getCurrencies($locale)
{
/** @var Currency[] $currencies */
$currencies = $this->get('sulu_product.currency_manager')->findAll($locale);
$currencyTitles = [];
foreach ($currencies as $currency) {
$currencyTitles[] = [
'id' => $currency->getId(),
'name' => $currency->getName(),
'code' => $currency->getCode(),
'number' => $currency->getNumber(),
];
}
return $currencyTitles;
}
|
php
|
protected function getCurrencies($locale)
{
/** @var Currency[] $currencies */
$currencies = $this->get('sulu_product.currency_manager')->findAll($locale);
$currencyTitles = [];
foreach ($currencies as $currency) {
$currencyTitles[] = [
'id' => $currency->getId(),
'name' => $currency->getName(),
'code' => $currency->getCode(),
'number' => $currency->getNumber(),
];
}
return $currencyTitles;
}
|
[
"protected",
"function",
"getCurrencies",
"(",
"$",
"locale",
")",
"{",
"/** @var Currency[] $currencies */",
"$",
"currencies",
"=",
"$",
"this",
"->",
"get",
"(",
"'sulu_product.currency_manager'",
")",
"->",
"findAll",
"(",
"$",
"locale",
")",
";",
"$",
"currencyTitles",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"currencies",
"as",
"$",
"currency",
")",
"{",
"$",
"currencyTitles",
"[",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"currency",
"->",
"getId",
"(",
")",
",",
"'name'",
"=>",
"$",
"currency",
"->",
"getName",
"(",
")",
",",
"'code'",
"=>",
"$",
"currency",
"->",
"getCode",
"(",
")",
",",
"'number'",
"=>",
"$",
"currency",
"->",
"getNumber",
"(",
")",
",",
"]",
";",
"}",
"return",
"$",
"currencyTitles",
";",
"}"
] |
Returns currencies.
@param string $locale
@return array
|
[
"Returns",
"currencies",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Controller/TemplateController.php#L237-L253
|
224,150
|
sulu/SuluProductBundle
|
Controller/TemplateController.php
|
TemplateController.getCategoryUrl
|
protected function getCategoryUrl()
{
$rootKey = $this->container->getParameter('sulu_product.category_root_key');
if (null !== $rootKey) {
return $this->generateUrl(
'get_category_children',
['key' => $rootKey, 'flat' => 'true', 'sortBy' => 'depth', 'sortOrder' => 'asc']
);
}
return $this->generateUrl(
'get_categories',
['flat' => 'true', 'sortBy' => 'depth', 'sortOrder' => 'asc']
);
}
|
php
|
protected function getCategoryUrl()
{
$rootKey = $this->container->getParameter('sulu_product.category_root_key');
if (null !== $rootKey) {
return $this->generateUrl(
'get_category_children',
['key' => $rootKey, 'flat' => 'true', 'sortBy' => 'depth', 'sortOrder' => 'asc']
);
}
return $this->generateUrl(
'get_categories',
['flat' => 'true', 'sortBy' => 'depth', 'sortOrder' => 'asc']
);
}
|
[
"protected",
"function",
"getCategoryUrl",
"(",
")",
"{",
"$",
"rootKey",
"=",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'sulu_product.category_root_key'",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"rootKey",
")",
"{",
"return",
"$",
"this",
"->",
"generateUrl",
"(",
"'get_category_children'",
",",
"[",
"'key'",
"=>",
"$",
"rootKey",
",",
"'flat'",
"=>",
"'true'",
",",
"'sortBy'",
"=>",
"'depth'",
",",
"'sortOrder'",
"=>",
"'asc'",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"generateUrl",
"(",
"'get_categories'",
",",
"[",
"'flat'",
"=>",
"'true'",
",",
"'sortBy'",
"=>",
"'depth'",
",",
"'sortOrder'",
"=>",
"'asc'",
"]",
")",
";",
"}"
] |
Returns url for fetching categories.
If sulu_product.category_root_key is specified only categories of this specific root key
are going to be fetched. Otherwise the whole category tree is returned.
@return string
|
[
"Returns",
"url",
"for",
"fetching",
"categories",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Controller/TemplateController.php#L263-L278
|
224,151
|
sulu/SuluProductBundle
|
Controller/TemplateController.php
|
TemplateController.getDeliveryStates
|
protected function getDeliveryStates($locale)
{
$states = $this->getDeliveryStatusManager()->findAll($locale);
$deliveryStates = [];
foreach ($states as $state) {
$deliveryStates[] = [
'id' => $state->getId(),
'name' => $state->getName(),
];
}
return $deliveryStates;
}
|
php
|
protected function getDeliveryStates($locale)
{
$states = $this->getDeliveryStatusManager()->findAll($locale);
$deliveryStates = [];
foreach ($states as $state) {
$deliveryStates[] = [
'id' => $state->getId(),
'name' => $state->getName(),
];
}
return $deliveryStates;
}
|
[
"protected",
"function",
"getDeliveryStates",
"(",
"$",
"locale",
")",
"{",
"$",
"states",
"=",
"$",
"this",
"->",
"getDeliveryStatusManager",
"(",
")",
"->",
"findAll",
"(",
"$",
"locale",
")",
";",
"$",
"deliveryStates",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"states",
"as",
"$",
"state",
")",
"{",
"$",
"deliveryStates",
"[",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"state",
"->",
"getId",
"(",
")",
",",
"'name'",
"=>",
"$",
"state",
"->",
"getName",
"(",
")",
",",
"]",
";",
"}",
"return",
"$",
"deliveryStates",
";",
"}"
] |
Returns delivery states.
@param string $locale
@return array
|
[
"Returns",
"delivery",
"states",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Controller/TemplateController.php#L287-L300
|
224,152
|
sulu/SuluProductBundle
|
Entity/Unit.php
|
Unit.getTranslation
|
public function getTranslation($locale)
{
$translation = null;
// Use first translation as a fallback.
if (count($this->translations) > 0) {
$translation = $this->translations[0];
}
/** @var UnitTranslation $translationData */
foreach ($this->translations as $translationData) {
if ($translationData->getLocale() == $locale) {
$translation = $translationData;
break;
}
}
return $translation;
}
|
php
|
public function getTranslation($locale)
{
$translation = null;
// Use first translation as a fallback.
if (count($this->translations) > 0) {
$translation = $this->translations[0];
}
/** @var UnitTranslation $translationData */
foreach ($this->translations as $translationData) {
if ($translationData->getLocale() == $locale) {
$translation = $translationData;
break;
}
}
return $translation;
}
|
[
"public",
"function",
"getTranslation",
"(",
"$",
"locale",
")",
"{",
"$",
"translation",
"=",
"null",
";",
"// Use first translation as a fallback.",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"translations",
")",
">",
"0",
")",
"{",
"$",
"translation",
"=",
"$",
"this",
"->",
"translations",
"[",
"0",
"]",
";",
"}",
"/** @var UnitTranslation $translationData */",
"foreach",
"(",
"$",
"this",
"->",
"translations",
"as",
"$",
"translationData",
")",
"{",
"if",
"(",
"$",
"translationData",
"->",
"getLocale",
"(",
")",
"==",
"$",
"locale",
")",
"{",
"$",
"translation",
"=",
"$",
"translationData",
";",
"break",
";",
"}",
"}",
"return",
"$",
"translation",
";",
"}"
] |
Returns the translation for the given locale.
@param string $locale
@return Translation
|
[
"Returns",
"the",
"translation",
"for",
"the",
"given",
"locale",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Entity/Unit.php#L127-L145
|
224,153
|
sulu/SuluProductBundle
|
Controller/ProductVariantAttributeController.php
|
ProductVariantAttributeController.deleteAction
|
public function deleteAction($productId, $attributeId)
{
$this->getVariantAttributeManager()->removeVariantAttributeRelation(
$productId,
$attributeId
);
$this->getDoctrine()->getEntityManager()->flush();
$view = $this->view(null, Response::HTTP_NO_CONTENT);
return $this->handleView($view);
}
|
php
|
public function deleteAction($productId, $attributeId)
{
$this->getVariantAttributeManager()->removeVariantAttributeRelation(
$productId,
$attributeId
);
$this->getDoctrine()->getEntityManager()->flush();
$view = $this->view(null, Response::HTTP_NO_CONTENT);
return $this->handleView($view);
}
|
[
"public",
"function",
"deleteAction",
"(",
"$",
"productId",
",",
"$",
"attributeId",
")",
"{",
"$",
"this",
"->",
"getVariantAttributeManager",
"(",
")",
"->",
"removeVariantAttributeRelation",
"(",
"$",
"productId",
",",
"$",
"attributeId",
")",
";",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getEntityManager",
"(",
")",
"->",
"flush",
"(",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"null",
",",
"Response",
"::",
"HTTP_NO_CONTENT",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] |
Deletes attribute from variant.
@Delete("products/{productId}/variant-attributes/{attributeId}")
@param int $productId
@param int $attributeId
@return Response
|
[
"Deletes",
"attribute",
"from",
"variant",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Controller/ProductVariantAttributeController.php#L121-L133
|
224,154
|
unreal4u/mqtt
|
src/Protocol/Publish.php
|
Publish.createVariableHeaderFlags
|
private function createVariableHeaderFlags(): string
{
if ($this->isRedelivery) {
// DUP flag: if the message is a re-delivery, mark it as such
$this->specialFlags |= 8;
$this->logger->debug('Activating redelivery bit');
}
if ($this->message->isRetained()) {
// RETAIN flag: should the server retain the message?
$this->specialFlags |= 1;
$this->logger->debug('Activating retain flag');
}
// Check QoS level and perform the corresponding actions
if ($this->message->getQoSLevel() !== 0) {
// 0 for QoS lvl2 for QoS lvl1 and 4 for QoS lvl2
$this->specialFlags |= ($this->message->getQoSLevel() * 2);
$this->logger->debug(sprintf('Activating QoS level %d bit', $this->message->getQoSLevel()));
return $this->getPacketIdentifierBinaryRepresentation();
}
return '';
}
|
php
|
private function createVariableHeaderFlags(): string
{
if ($this->isRedelivery) {
// DUP flag: if the message is a re-delivery, mark it as such
$this->specialFlags |= 8;
$this->logger->debug('Activating redelivery bit');
}
if ($this->message->isRetained()) {
// RETAIN flag: should the server retain the message?
$this->specialFlags |= 1;
$this->logger->debug('Activating retain flag');
}
// Check QoS level and perform the corresponding actions
if ($this->message->getQoSLevel() !== 0) {
// 0 for QoS lvl2 for QoS lvl1 and 4 for QoS lvl2
$this->specialFlags |= ($this->message->getQoSLevel() * 2);
$this->logger->debug(sprintf('Activating QoS level %d bit', $this->message->getQoSLevel()));
return $this->getPacketIdentifierBinaryRepresentation();
}
return '';
}
|
[
"private",
"function",
"createVariableHeaderFlags",
"(",
")",
":",
"string",
"{",
"if",
"(",
"$",
"this",
"->",
"isRedelivery",
")",
"{",
"// DUP flag: if the message is a re-delivery, mark it as such",
"$",
"this",
"->",
"specialFlags",
"|=",
"8",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'Activating redelivery bit'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"message",
"->",
"isRetained",
"(",
")",
")",
"{",
"// RETAIN flag: should the server retain the message?",
"$",
"this",
"->",
"specialFlags",
"|=",
"1",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'Activating retain flag'",
")",
";",
"}",
"// Check QoS level and perform the corresponding actions",
"if",
"(",
"$",
"this",
"->",
"message",
"->",
"getQoSLevel",
"(",
")",
"!==",
"0",
")",
"{",
"// 0 for QoS lvl2 for QoS lvl1 and 4 for QoS lvl2",
"$",
"this",
"->",
"specialFlags",
"|=",
"(",
"$",
"this",
"->",
"message",
"->",
"getQoSLevel",
"(",
")",
"*",
"2",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"sprintf",
"(",
"'Activating QoS level %d bit'",
",",
"$",
"this",
"->",
"message",
"->",
"getQoSLevel",
"(",
")",
")",
")",
";",
"return",
"$",
"this",
"->",
"getPacketIdentifierBinaryRepresentation",
"(",
")",
";",
"}",
"return",
"''",
";",
"}"
] |
Sets some common flags and returns the variable header string should there be one
@return string
@throws OutOfRangeException
@throws InvalidQoSLevel
|
[
"Sets",
"some",
"common",
"flags",
"and",
"returns",
"the",
"variable",
"header",
"string",
"should",
"there",
"be",
"one"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Protocol/Publish.php#L100-L123
|
224,155
|
unreal4u/mqtt
|
src/Protocol/Publish.php
|
Publish.shouldExpectAnswer
|
public function shouldExpectAnswer(): bool
{
$shouldExpectAnswer = !($this->message->getQoSLevel() === 0);
$this->logger->debug('Checking whether we should expect an answer or not', [
'shouldExpectAnswer' => $shouldExpectAnswer,
]);
return $shouldExpectAnswer;
}
|
php
|
public function shouldExpectAnswer(): bool
{
$shouldExpectAnswer = !($this->message->getQoSLevel() === 0);
$this->logger->debug('Checking whether we should expect an answer or not', [
'shouldExpectAnswer' => $shouldExpectAnswer,
]);
return $shouldExpectAnswer;
}
|
[
"public",
"function",
"shouldExpectAnswer",
"(",
")",
":",
"bool",
"{",
"$",
"shouldExpectAnswer",
"=",
"!",
"(",
"$",
"this",
"->",
"message",
"->",
"getQoSLevel",
"(",
")",
"===",
"0",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'Checking whether we should expect an answer or not'",
",",
"[",
"'shouldExpectAnswer'",
"=>",
"$",
"shouldExpectAnswer",
",",
"]",
")",
";",
"return",
"$",
"shouldExpectAnswer",
";",
"}"
] |
QoS level 0 does not have to wait for a answer, so return false. Any other QoS level returns true
@return bool
@throws InvalidQoSLevel
|
[
"QoS",
"level",
"0",
"does",
"not",
"have",
"to",
"wait",
"for",
"a",
"answer",
"so",
"return",
"false",
".",
"Any",
"other",
"QoS",
"level",
"returns",
"true"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Protocol/Publish.php#L144-L151
|
224,156
|
unreal4u/mqtt
|
src/Protocol/Publish.php
|
Publish.analyzeFirstByte
|
private function analyzeFirstByte(int $firstByte, QoSLevel $qoSLevel): Publish
{
$this->logger->debug('Analyzing first byte', [sprintf('%08d', decbin($firstByte))]);
// Retained bit is bit 0 of first byte
$this->message->setRetainFlag(false);
if (($firstByte & 1) === 1) {
$this->logger->debug('Setting retain flag to true');
$this->message->setRetainFlag(true);
}
// QoS level is already been taken care of, assign it to the message at this point
$this->message->setQoSLevel($qoSLevel);
// Duplicate message must be checked only on QoS > 0, else set it to false
$this->isRedelivery = false;
if (($firstByte & 8) === 8 && $this->message->getQoSLevel() !== 0) {
// Is a duplicate is always bit 3 of first byte
$this->isRedelivery = true;
$this->logger->debug('Setting redelivery bit');
}
return $this;
}
|
php
|
private function analyzeFirstByte(int $firstByte, QoSLevel $qoSLevel): Publish
{
$this->logger->debug('Analyzing first byte', [sprintf('%08d', decbin($firstByte))]);
// Retained bit is bit 0 of first byte
$this->message->setRetainFlag(false);
if (($firstByte & 1) === 1) {
$this->logger->debug('Setting retain flag to true');
$this->message->setRetainFlag(true);
}
// QoS level is already been taken care of, assign it to the message at this point
$this->message->setQoSLevel($qoSLevel);
// Duplicate message must be checked only on QoS > 0, else set it to false
$this->isRedelivery = false;
if (($firstByte & 8) === 8 && $this->message->getQoSLevel() !== 0) {
// Is a duplicate is always bit 3 of first byte
$this->isRedelivery = true;
$this->logger->debug('Setting redelivery bit');
}
return $this;
}
|
[
"private",
"function",
"analyzeFirstByte",
"(",
"int",
"$",
"firstByte",
",",
"QoSLevel",
"$",
"qoSLevel",
")",
":",
"Publish",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'Analyzing first byte'",
",",
"[",
"sprintf",
"(",
"'%08d'",
",",
"decbin",
"(",
"$",
"firstByte",
")",
")",
"]",
")",
";",
"// Retained bit is bit 0 of first byte",
"$",
"this",
"->",
"message",
"->",
"setRetainFlag",
"(",
"false",
")",
";",
"if",
"(",
"(",
"$",
"firstByte",
"&",
"1",
")",
"===",
"1",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'Setting retain flag to true'",
")",
";",
"$",
"this",
"->",
"message",
"->",
"setRetainFlag",
"(",
"true",
")",
";",
"}",
"// QoS level is already been taken care of, assign it to the message at this point",
"$",
"this",
"->",
"message",
"->",
"setQoSLevel",
"(",
"$",
"qoSLevel",
")",
";",
"// Duplicate message must be checked only on QoS > 0, else set it to false",
"$",
"this",
"->",
"isRedelivery",
"=",
"false",
";",
"if",
"(",
"(",
"$",
"firstByte",
"&",
"8",
")",
"===",
"8",
"&&",
"$",
"this",
"->",
"message",
"->",
"getQoSLevel",
"(",
")",
"!==",
"0",
")",
"{",
"// Is a duplicate is always bit 3 of first byte",
"$",
"this",
"->",
"isRedelivery",
"=",
"true",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'Setting redelivery bit'",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Sets several bits and pieces from the first byte of the fixed header for the Publish packet
@param int $firstByte
@param QoSLevel $qoSLevel
@return Publish
@throws InvalidQoSLevel
|
[
"Sets",
"several",
"bits",
"and",
"pieces",
"from",
"the",
"first",
"byte",
"of",
"the",
"fixed",
"header",
"for",
"the",
"Publish",
"packet"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Protocol/Publish.php#L206-L227
|
224,157
|
unreal4u/mqtt
|
src/Protocol/Publish.php
|
Publish.determineIncomingQoSLevel
|
private function determineIncomingQoSLevel(int $bitString): QoSLevel
{
// QoS lvl are in bit positions 1-2. Shifting is strictly speaking not needed, but increases human comprehension
$shiftedBits = $bitString >> 1;
$incomingQoSLevel = 0;
if (($shiftedBits & 1) === 1) {
$incomingQoSLevel = 1;
}
if (($shiftedBits & 2) === 2) {
$incomingQoSLevel = 2;
}
$this->logger->debug('Setting QoS level', ['bitString' => $bitString, 'incomingQoSLevel' => $incomingQoSLevel]);
return new QoSLevel($incomingQoSLevel);
}
|
php
|
private function determineIncomingQoSLevel(int $bitString): QoSLevel
{
// QoS lvl are in bit positions 1-2. Shifting is strictly speaking not needed, but increases human comprehension
$shiftedBits = $bitString >> 1;
$incomingQoSLevel = 0;
if (($shiftedBits & 1) === 1) {
$incomingQoSLevel = 1;
}
if (($shiftedBits & 2) === 2) {
$incomingQoSLevel = 2;
}
$this->logger->debug('Setting QoS level', ['bitString' => $bitString, 'incomingQoSLevel' => $incomingQoSLevel]);
return new QoSLevel($incomingQoSLevel);
}
|
[
"private",
"function",
"determineIncomingQoSLevel",
"(",
"int",
"$",
"bitString",
")",
":",
"QoSLevel",
"{",
"// QoS lvl are in bit positions 1-2. Shifting is strictly speaking not needed, but increases human comprehension",
"$",
"shiftedBits",
"=",
"$",
"bitString",
">>",
"1",
";",
"$",
"incomingQoSLevel",
"=",
"0",
";",
"if",
"(",
"(",
"$",
"shiftedBits",
"&",
"1",
")",
"===",
"1",
")",
"{",
"$",
"incomingQoSLevel",
"=",
"1",
";",
"}",
"if",
"(",
"(",
"$",
"shiftedBits",
"&",
"2",
")",
"===",
"2",
")",
"{",
"$",
"incomingQoSLevel",
"=",
"2",
";",
"}",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'Setting QoS level'",
",",
"[",
"'bitString'",
"=>",
"$",
"bitString",
",",
"'incomingQoSLevel'",
"=>",
"$",
"incomingQoSLevel",
"]",
")",
";",
"return",
"new",
"QoSLevel",
"(",
"$",
"incomingQoSLevel",
")",
";",
"}"
] |
Finds out the QoS level in a fixed header for the Publish object
@param int $bitString
@return QoSLevel
@throws InvalidQoSLevel
|
[
"Finds",
"out",
"the",
"QoS",
"level",
"in",
"a",
"fixed",
"header",
"for",
"the",
"Publish",
"object"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Protocol/Publish.php#L236-L250
|
224,158
|
unreal4u/mqtt
|
src/Protocol/Publish.php
|
Publish.completePossibleIncompleteMessage
|
private function completePossibleIncompleteMessage(string $rawMQTTHeaders, ClientInterface $client): string
{
// Read at least one extra byte from the stream if we know that the message is too short
if (strlen($rawMQTTHeaders) < 2) {
$rawMQTTHeaders .= $client->readBrokerData(1);
}
$restOfBytes = $this->performRemainingLengthFieldOperations($rawMQTTHeaders, $client);
/*
* A complete message consists of:
* - The very first byte
* - The size of the remaining length field (from 1 to 4 bytes)
* - The $restOfBytes
*
* So we have to compare what we already have vs the above calculation
*
* More information:
* http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/errata01/os/mqtt-v3.1.1-errata01-os-complete.html#_Toc442180832
*/
if (strlen($rawMQTTHeaders) < ($restOfBytes + $this->sizeOfRemainingLengthField + 1)) {
// Read only the portion of data we have left from the socket
$readableDataLeft = ($restOfBytes + $this->sizeOfRemainingLengthField + 1) - strlen($rawMQTTHeaders);
$rawMQTTHeaders .= $client->readBrokerData($readableDataLeft);
}
return $rawMQTTHeaders;
}
|
php
|
private function completePossibleIncompleteMessage(string $rawMQTTHeaders, ClientInterface $client): string
{
// Read at least one extra byte from the stream if we know that the message is too short
if (strlen($rawMQTTHeaders) < 2) {
$rawMQTTHeaders .= $client->readBrokerData(1);
}
$restOfBytes = $this->performRemainingLengthFieldOperations($rawMQTTHeaders, $client);
/*
* A complete message consists of:
* - The very first byte
* - The size of the remaining length field (from 1 to 4 bytes)
* - The $restOfBytes
*
* So we have to compare what we already have vs the above calculation
*
* More information:
* http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/errata01/os/mqtt-v3.1.1-errata01-os-complete.html#_Toc442180832
*/
if (strlen($rawMQTTHeaders) < ($restOfBytes + $this->sizeOfRemainingLengthField + 1)) {
// Read only the portion of data we have left from the socket
$readableDataLeft = ($restOfBytes + $this->sizeOfRemainingLengthField + 1) - strlen($rawMQTTHeaders);
$rawMQTTHeaders .= $client->readBrokerData($readableDataLeft);
}
return $rawMQTTHeaders;
}
|
[
"private",
"function",
"completePossibleIncompleteMessage",
"(",
"string",
"$",
"rawMQTTHeaders",
",",
"ClientInterface",
"$",
"client",
")",
":",
"string",
"{",
"// Read at least one extra byte from the stream if we know that the message is too short",
"if",
"(",
"strlen",
"(",
"$",
"rawMQTTHeaders",
")",
"<",
"2",
")",
"{",
"$",
"rawMQTTHeaders",
".=",
"$",
"client",
"->",
"readBrokerData",
"(",
"1",
")",
";",
"}",
"$",
"restOfBytes",
"=",
"$",
"this",
"->",
"performRemainingLengthFieldOperations",
"(",
"$",
"rawMQTTHeaders",
",",
"$",
"client",
")",
";",
"/*\n * A complete message consists of:\n * - The very first byte\n * - The size of the remaining length field (from 1 to 4 bytes)\n * - The $restOfBytes\n *\n * So we have to compare what we already have vs the above calculation\n *\n * More information:\n * http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/errata01/os/mqtt-v3.1.1-errata01-os-complete.html#_Toc442180832\n */",
"if",
"(",
"strlen",
"(",
"$",
"rawMQTTHeaders",
")",
"<",
"(",
"$",
"restOfBytes",
"+",
"$",
"this",
"->",
"sizeOfRemainingLengthField",
"+",
"1",
")",
")",
"{",
"// Read only the portion of data we have left from the socket",
"$",
"readableDataLeft",
"=",
"(",
"$",
"restOfBytes",
"+",
"$",
"this",
"->",
"sizeOfRemainingLengthField",
"+",
"1",
")",
"-",
"strlen",
"(",
"$",
"rawMQTTHeaders",
")",
";",
"$",
"rawMQTTHeaders",
".=",
"$",
"client",
"->",
"readBrokerData",
"(",
"$",
"readableDataLeft",
")",
";",
"}",
"return",
"$",
"rawMQTTHeaders",
";",
"}"
] |
Gets the full message in case this object needs to
@param string $rawMQTTHeaders
@param ClientInterface $client
@return string
@throws OutOfBoundsException
@throws InvalidArgumentException
@throws MessageTooBig
@throws InvalidQoSLevel
|
[
"Gets",
"the",
"full",
"message",
"in",
"case",
"this",
"object",
"needs",
"to"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Protocol/Publish.php#L263-L290
|
224,159
|
unreal4u/mqtt
|
src/Protocol/Publish.php
|
Publish.fillObject
|
public function fillObject(string $rawMQTTHeaders, ClientInterface $client): ReadableContentInterface
{
// Retrieve full message first
$fullMessage = $this->completePossibleIncompleteMessage($rawMQTTHeaders, $client);
// Handy to maintain for debugging purposes
#$this->logger->debug('Bin data', [\unreal4u\MQTT\DebugTools::convertToBinaryRepresentation($rawMQTTHeaders)]);
// Handy to have: the first byte
$firstByte = ord($fullMessage{0});
// TopicName size is always on the second position after the size of the remaining length field (1 to 4 bytes)
$topicSize = ord($fullMessage{$this->sizeOfRemainingLengthField + 2});
// With the first byte, we can determine the QoS level of the incoming message
$qosLevel = $this->determineIncomingQoSLevel($firstByte);
$messageStartPosition = $this->sizeOfRemainingLengthField + 3;
// If we have a QoS level present, we must retrieve the packet identifier as well
if ($qosLevel->getQoSLevel() > 0) {
$this->logger->debug('QoS level above 0, shifting message start position and getting packet identifier');
// [2 (fixed header) + 2 (topic size) + $topicSize] marks the beginning of the 2 packet identifier bytes
$this->setPacketIdentifier(new PacketIdentifier(Utilities::convertBinaryStringToNumber(
$fullMessage{$this->sizeOfRemainingLengthField + 3 + $topicSize} .
$fullMessage{$this->sizeOfRemainingLengthField + 4 + $topicSize}
)));
$this->logger->debug('Determined packet identifier', ['PI' => $this->getPacketIdentifier()]);
$messageStartPosition += 2;
}
// At this point $rawMQTTHeaders will be always 1 byte long, initialize a Message object with dummy data for now
$this->message = new Message(
// Save to assume a constant here: first 2 bytes will always be fixed header, next 2 bytes are topic size
substr($fullMessage, $messageStartPosition + $topicSize),
new TopicName(substr($fullMessage, $this->sizeOfRemainingLengthField + 3, $topicSize))
);
$this->analyzeFirstByte($firstByte, $qosLevel);
$this->logger->debug('Determined headers', [
'topicSize' => $topicSize,
'QoSLevel' => $this->message->getQoSLevel(),
'isDuplicate' => $this->isRedelivery,
'isRetained' => $this->message->isRetained(),
#'packetIdentifier' => $this->packetIdentifier->getPacketIdentifierValue(), // This is not always set!
]);
return $this;
}
|
php
|
public function fillObject(string $rawMQTTHeaders, ClientInterface $client): ReadableContentInterface
{
// Retrieve full message first
$fullMessage = $this->completePossibleIncompleteMessage($rawMQTTHeaders, $client);
// Handy to maintain for debugging purposes
#$this->logger->debug('Bin data', [\unreal4u\MQTT\DebugTools::convertToBinaryRepresentation($rawMQTTHeaders)]);
// Handy to have: the first byte
$firstByte = ord($fullMessage{0});
// TopicName size is always on the second position after the size of the remaining length field (1 to 4 bytes)
$topicSize = ord($fullMessage{$this->sizeOfRemainingLengthField + 2});
// With the first byte, we can determine the QoS level of the incoming message
$qosLevel = $this->determineIncomingQoSLevel($firstByte);
$messageStartPosition = $this->sizeOfRemainingLengthField + 3;
// If we have a QoS level present, we must retrieve the packet identifier as well
if ($qosLevel->getQoSLevel() > 0) {
$this->logger->debug('QoS level above 0, shifting message start position and getting packet identifier');
// [2 (fixed header) + 2 (topic size) + $topicSize] marks the beginning of the 2 packet identifier bytes
$this->setPacketIdentifier(new PacketIdentifier(Utilities::convertBinaryStringToNumber(
$fullMessage{$this->sizeOfRemainingLengthField + 3 + $topicSize} .
$fullMessage{$this->sizeOfRemainingLengthField + 4 + $topicSize}
)));
$this->logger->debug('Determined packet identifier', ['PI' => $this->getPacketIdentifier()]);
$messageStartPosition += 2;
}
// At this point $rawMQTTHeaders will be always 1 byte long, initialize a Message object with dummy data for now
$this->message = new Message(
// Save to assume a constant here: first 2 bytes will always be fixed header, next 2 bytes are topic size
substr($fullMessage, $messageStartPosition + $topicSize),
new TopicName(substr($fullMessage, $this->sizeOfRemainingLengthField + 3, $topicSize))
);
$this->analyzeFirstByte($firstByte, $qosLevel);
$this->logger->debug('Determined headers', [
'topicSize' => $topicSize,
'QoSLevel' => $this->message->getQoSLevel(),
'isDuplicate' => $this->isRedelivery,
'isRetained' => $this->message->isRetained(),
#'packetIdentifier' => $this->packetIdentifier->getPacketIdentifierValue(), // This is not always set!
]);
return $this;
}
|
[
"public",
"function",
"fillObject",
"(",
"string",
"$",
"rawMQTTHeaders",
",",
"ClientInterface",
"$",
"client",
")",
":",
"ReadableContentInterface",
"{",
"// Retrieve full message first",
"$",
"fullMessage",
"=",
"$",
"this",
"->",
"completePossibleIncompleteMessage",
"(",
"$",
"rawMQTTHeaders",
",",
"$",
"client",
")",
";",
"// Handy to maintain for debugging purposes",
"#$this->logger->debug('Bin data', [\\unreal4u\\MQTT\\DebugTools::convertToBinaryRepresentation($rawMQTTHeaders)]);",
"// Handy to have: the first byte",
"$",
"firstByte",
"=",
"ord",
"(",
"$",
"fullMessage",
"{",
"0",
"}",
")",
";",
"// TopicName size is always on the second position after the size of the remaining length field (1 to 4 bytes)",
"$",
"topicSize",
"=",
"ord",
"(",
"$",
"fullMessage",
"{",
"$",
"this",
"->",
"sizeOfRemainingLengthField",
"+",
"2",
"}",
")",
";",
"// With the first byte, we can determine the QoS level of the incoming message",
"$",
"qosLevel",
"=",
"$",
"this",
"->",
"determineIncomingQoSLevel",
"(",
"$",
"firstByte",
")",
";",
"$",
"messageStartPosition",
"=",
"$",
"this",
"->",
"sizeOfRemainingLengthField",
"+",
"3",
";",
"// If we have a QoS level present, we must retrieve the packet identifier as well",
"if",
"(",
"$",
"qosLevel",
"->",
"getQoSLevel",
"(",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'QoS level above 0, shifting message start position and getting packet identifier'",
")",
";",
"// [2 (fixed header) + 2 (topic size) + $topicSize] marks the beginning of the 2 packet identifier bytes",
"$",
"this",
"->",
"setPacketIdentifier",
"(",
"new",
"PacketIdentifier",
"(",
"Utilities",
"::",
"convertBinaryStringToNumber",
"(",
"$",
"fullMessage",
"{",
"$",
"this",
"->",
"sizeOfRemainingLengthField",
"+",
"3",
"+",
"$",
"topicSize",
"}",
".",
"$",
"fullMessage",
"{",
"$",
"this",
"->",
"sizeOfRemainingLengthField",
"+",
"4",
"+",
"$",
"topicSize",
"}",
")",
")",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'Determined packet identifier'",
",",
"[",
"'PI'",
"=>",
"$",
"this",
"->",
"getPacketIdentifier",
"(",
")",
"]",
")",
";",
"$",
"messageStartPosition",
"+=",
"2",
";",
"}",
"// At this point $rawMQTTHeaders will be always 1 byte long, initialize a Message object with dummy data for now",
"$",
"this",
"->",
"message",
"=",
"new",
"Message",
"(",
"// Save to assume a constant here: first 2 bytes will always be fixed header, next 2 bytes are topic size",
"substr",
"(",
"$",
"fullMessage",
",",
"$",
"messageStartPosition",
"+",
"$",
"topicSize",
")",
",",
"new",
"TopicName",
"(",
"substr",
"(",
"$",
"fullMessage",
",",
"$",
"this",
"->",
"sizeOfRemainingLengthField",
"+",
"3",
",",
"$",
"topicSize",
")",
")",
")",
";",
"$",
"this",
"->",
"analyzeFirstByte",
"(",
"$",
"firstByte",
",",
"$",
"qosLevel",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'Determined headers'",
",",
"[",
"'topicSize'",
"=>",
"$",
"topicSize",
",",
"'QoSLevel'",
"=>",
"$",
"this",
"->",
"message",
"->",
"getQoSLevel",
"(",
")",
",",
"'isDuplicate'",
"=>",
"$",
"this",
"->",
"isRedelivery",
",",
"'isRetained'",
"=>",
"$",
"this",
"->",
"message",
"->",
"isRetained",
"(",
")",
",",
"#'packetIdentifier' => $this->packetIdentifier->getPacketIdentifierValue(), // This is not always set!",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Will perform sanity checks and fill in the Readable object with data
@param string $rawMQTTHeaders
@param ClientInterface $client
@return ReadableContentInterface
@throws MessageTooBig
@throws OutOfBoundsException
@throws InvalidQoSLevel
@throws InvalidArgumentException
@throws OutOfRangeException
|
[
"Will",
"perform",
"sanity",
"checks",
"and",
"fill",
"in",
"the",
"Readable",
"object",
"with",
"data"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Protocol/Publish.php#L303-L347
|
224,160
|
unreal4u/mqtt
|
src/Protocol/Publish.php
|
Publish.composePubRecAnswer
|
private function composePubRecAnswer(): PubRec
{
$this->checkForValidPacketIdentifier();
$pubRec = new PubRec($this->logger);
$pubRec->setPacketIdentifier($this->packetIdentifier);
return $pubRec;
}
|
php
|
private function composePubRecAnswer(): PubRec
{
$this->checkForValidPacketIdentifier();
$pubRec = new PubRec($this->logger);
$pubRec->setPacketIdentifier($this->packetIdentifier);
return $pubRec;
}
|
[
"private",
"function",
"composePubRecAnswer",
"(",
")",
":",
"PubRec",
"{",
"$",
"this",
"->",
"checkForValidPacketIdentifier",
"(",
")",
";",
"$",
"pubRec",
"=",
"new",
"PubRec",
"(",
"$",
"this",
"->",
"logger",
")",
";",
"$",
"pubRec",
"->",
"setPacketIdentifier",
"(",
"$",
"this",
"->",
"packetIdentifier",
")",
";",
"return",
"$",
"pubRec",
";",
"}"
] |
Composes a PubRec answer with the same packetIdentifier as what we received
@return PubRec
@throws InvalidRequest
|
[
"Composes",
"a",
"PubRec",
"answer",
"with",
"the",
"same",
"packetIdentifier",
"as",
"what",
"we",
"received"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Protocol/Publish.php#L380-L386
|
224,161
|
unreal4u/mqtt
|
src/Protocol/Publish.php
|
Publish.composePubAckAnswer
|
private function composePubAckAnswer(): PubAck
{
$this->checkForValidPacketIdentifier();
$pubAck = new PubAck($this->logger);
$pubAck->setPacketIdentifier($this->packetIdentifier);
return $pubAck;
}
|
php
|
private function composePubAckAnswer(): PubAck
{
$this->checkForValidPacketIdentifier();
$pubAck = new PubAck($this->logger);
$pubAck->setPacketIdentifier($this->packetIdentifier);
return $pubAck;
}
|
[
"private",
"function",
"composePubAckAnswer",
"(",
")",
":",
"PubAck",
"{",
"$",
"this",
"->",
"checkForValidPacketIdentifier",
"(",
")",
";",
"$",
"pubAck",
"=",
"new",
"PubAck",
"(",
"$",
"this",
"->",
"logger",
")",
";",
"$",
"pubAck",
"->",
"setPacketIdentifier",
"(",
"$",
"this",
"->",
"packetIdentifier",
")",
";",
"return",
"$",
"pubAck",
";",
"}"
] |
Composes a PubAck answer with the same packetIdentifier as what we received
@return PubAck
@throws InvalidRequest
|
[
"Composes",
"a",
"PubAck",
"answer",
"with",
"the",
"same",
"packetIdentifier",
"as",
"what",
"we",
"received"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Protocol/Publish.php#L394-L400
|
224,162
|
unreal4u/mqtt
|
src/Protocol/Publish.php
|
Publish.checkForValidPacketIdentifier
|
private function checkForValidPacketIdentifier(): self
{
if ($this->packetIdentifier === null) {
$this->logger->critical('No valid packet identifier found at a stage where there MUST be one set');
throw new InvalidRequest('You are trying to send a request without a valid packet identifier');
}
return $this;
}
|
php
|
private function checkForValidPacketIdentifier(): self
{
if ($this->packetIdentifier === null) {
$this->logger->critical('No valid packet identifier found at a stage where there MUST be one set');
throw new InvalidRequest('You are trying to send a request without a valid packet identifier');
}
return $this;
}
|
[
"private",
"function",
"checkForValidPacketIdentifier",
"(",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"packetIdentifier",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"critical",
"(",
"'No valid packet identifier found at a stage where there MUST be one set'",
")",
";",
"throw",
"new",
"InvalidRequest",
"(",
"'You are trying to send a request without a valid packet identifier'",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Will check whether the current object has a packet identifier set. If not, we are in serious problems!
@return Publish
@throws InvalidRequest
|
[
"Will",
"check",
"whether",
"the",
"current",
"object",
"has",
"a",
"packet",
"identifier",
"set",
".",
"If",
"not",
"we",
"are",
"in",
"serious",
"problems!"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Protocol/Publish.php#L408-L416
|
224,163
|
actualreports/pdfgeneratorapi-laravel
|
src/Http/Controllers/TemplateController.php
|
TemplateController.edit
|
public function edit(Request $request, $template)
{
$data = $this->getData();
/**
* Set workspace identifier
*/
\PDFGeneratorAPI::setWorkspace($this->userRepository->getWorkspaceIdentifier(Auth::user()));
return redirect()->away(\PDFGeneratorAPI::editor($template, $data));
}
|
php
|
public function edit(Request $request, $template)
{
$data = $this->getData();
/**
* Set workspace identifier
*/
\PDFGeneratorAPI::setWorkspace($this->userRepository->getWorkspaceIdentifier(Auth::user()));
return redirect()->away(\PDFGeneratorAPI::editor($template, $data));
}
|
[
"public",
"function",
"edit",
"(",
"Request",
"$",
"request",
",",
"$",
"template",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"getData",
"(",
")",
";",
"/**\n * Set workspace identifier\n */",
"\\",
"PDFGeneratorAPI",
"::",
"setWorkspace",
"(",
"$",
"this",
"->",
"userRepository",
"->",
"getWorkspaceIdentifier",
"(",
"Auth",
"::",
"user",
"(",
")",
")",
")",
";",
"return",
"redirect",
"(",
")",
"->",
"away",
"(",
"\\",
"PDFGeneratorAPI",
"::",
"editor",
"(",
"$",
"template",
",",
"$",
"data",
")",
")",
";",
"}"
] |
Redirects to editor to edit the new template
@param \Illuminate\Http\Request $request
@param integer $template
@return \Illuminate\Http\RedirectResponse
|
[
"Redirects",
"to",
"editor",
"to",
"edit",
"the",
"new",
"template"
] |
f5fb75cb7c5f15029844378f9c9c098f7126178a
|
https://github.com/actualreports/pdfgeneratorapi-laravel/blob/f5fb75cb7c5f15029844378f9c9c098f7126178a/src/Http/Controllers/TemplateController.php#L156-L166
|
224,164
|
actualreports/pdfgeneratorapi-laravel
|
src/Http/Controllers/TemplateController.php
|
TemplateController.editAsCopy
|
public function editAsCopy(Request $request, $template)
{
$name = $request->get('name');
$data = $this->getData();
try
{
/**
* Set workspace identifier
*/
\PDFGeneratorAPI::setWorkspace($this->userRepository->getWorkspaceIdentifier(Auth::user()));
$newTemplate = \PDFGeneratorAPI::copy($template, $name);
}
catch(Exception $e)
{
return response()->json([
'error' => $e->getMessage()
], $e->getCode());
}
return redirect()->away(\PDFGeneratorAPI::editor($newTemplate->id, $data));
}
|
php
|
public function editAsCopy(Request $request, $template)
{
$name = $request->get('name');
$data = $this->getData();
try
{
/**
* Set workspace identifier
*/
\PDFGeneratorAPI::setWorkspace($this->userRepository->getWorkspaceIdentifier(Auth::user()));
$newTemplate = \PDFGeneratorAPI::copy($template, $name);
}
catch(Exception $e)
{
return response()->json([
'error' => $e->getMessage()
], $e->getCode());
}
return redirect()->away(\PDFGeneratorAPI::editor($newTemplate->id, $data));
}
|
[
"public",
"function",
"editAsCopy",
"(",
"Request",
"$",
"request",
",",
"$",
"template",
")",
"{",
"$",
"name",
"=",
"$",
"request",
"->",
"get",
"(",
"'name'",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"getData",
"(",
")",
";",
"try",
"{",
"/**\n * Set workspace identifier\n */",
"\\",
"PDFGeneratorAPI",
"::",
"setWorkspace",
"(",
"$",
"this",
"->",
"userRepository",
"->",
"getWorkspaceIdentifier",
"(",
"Auth",
"::",
"user",
"(",
")",
")",
")",
";",
"$",
"newTemplate",
"=",
"\\",
"PDFGeneratorAPI",
"::",
"copy",
"(",
"$",
"template",
",",
"$",
"name",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"[",
"'error'",
"=>",
"$",
"e",
"->",
"getMessage",
"(",
")",
"]",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
")",
";",
"}",
"return",
"redirect",
"(",
")",
"->",
"away",
"(",
"\\",
"PDFGeneratorAPI",
"::",
"editor",
"(",
"$",
"newTemplate",
"->",
"id",
",",
"$",
"data",
")",
")",
";",
"}"
] |
Creates a copy of given template and redirects to editor to edit the new template
@param \Illuminate\Http\Request $request
@param integer $template
@return \Illuminate\Http\RedirectResponse
|
[
"Creates",
"a",
"copy",
"of",
"given",
"template",
"and",
"redirects",
"to",
"editor",
"to",
"edit",
"the",
"new",
"template"
] |
f5fb75cb7c5f15029844378f9c9c098f7126178a
|
https://github.com/actualreports/pdfgeneratorapi-laravel/blob/f5fb75cb7c5f15029844378f9c9c098f7126178a/src/Http/Controllers/TemplateController.php#L193-L215
|
224,165
|
sulu/SuluProductBundle
|
Entity/UnitMapping.php
|
UnitMapping.setUnit
|
public function setUnit(\Sulu\Bundle\ProductBundle\Entity\Unit $unit)
{
$this->unit = $unit;
return $this;
}
|
php
|
public function setUnit(\Sulu\Bundle\ProductBundle\Entity\Unit $unit)
{
$this->unit = $unit;
return $this;
}
|
[
"public",
"function",
"setUnit",
"(",
"\\",
"Sulu",
"\\",
"Bundle",
"\\",
"ProductBundle",
"\\",
"Entity",
"\\",
"Unit",
"$",
"unit",
")",
"{",
"$",
"this",
"->",
"unit",
"=",
"$",
"unit",
";",
"return",
"$",
"this",
";",
"}"
] |
Set unit.
@param \Sulu\Bundle\ProductBundle\Entity\Unit $unit
@return UnitMapping
|
[
"Set",
"unit",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Entity/UnitMapping.php#L75-L80
|
224,166
|
sulu/SuluProductBundle
|
Entity/AttributeRepository.php
|
AttributeRepository.getAttributeQuery
|
private function getAttributeQuery($locale)
{
$queryBuilder = $this->createQueryBuilder('attribute')
->leftJoin('attribute.translations', 'translations', 'WITH', 'translations.locale = :locale')
->leftJoin('attribute.type', 'type')
->setParameter('locale', $locale);
return $queryBuilder;
}
|
php
|
private function getAttributeQuery($locale)
{
$queryBuilder = $this->createQueryBuilder('attribute')
->leftJoin('attribute.translations', 'translations', 'WITH', 'translations.locale = :locale')
->leftJoin('attribute.type', 'type')
->setParameter('locale', $locale);
return $queryBuilder;
}
|
[
"private",
"function",
"getAttributeQuery",
"(",
"$",
"locale",
")",
"{",
"$",
"queryBuilder",
"=",
"$",
"this",
"->",
"createQueryBuilder",
"(",
"'attribute'",
")",
"->",
"leftJoin",
"(",
"'attribute.translations'",
",",
"'translations'",
",",
"'WITH'",
",",
"'translations.locale = :locale'",
")",
"->",
"leftJoin",
"(",
"'attribute.type'",
",",
"'type'",
")",
"->",
"setParameter",
"(",
"'locale'",
",",
"$",
"locale",
")",
";",
"return",
"$",
"queryBuilder",
";",
"}"
] |
Returns the query for attributes.
@param string $locale The locale to load
@return \Doctrine\ORM\QueryBuilder
|
[
"Returns",
"the",
"query",
"for",
"attributes",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Entity/AttributeRepository.php#L106-L114
|
224,167
|
unreal4u/mqtt
|
src/Protocol/Connect/Parameters.php
|
Parameters.setClientId
|
public function setClientId(ClientId $clientId): self
{
$this->clientId = $clientId;
$this->logger->debug('Set clientId', ['actualClientString' => (string)$clientId]);
if ($this->clientId->isEmptyClientId()) {
$this->logger->debug('Empty clientId detected, forcing clean session bit to true');
$this->setCleanSession(true);
}
return $this;
}
|
php
|
public function setClientId(ClientId $clientId): self
{
$this->clientId = $clientId;
$this->logger->debug('Set clientId', ['actualClientString' => (string)$clientId]);
if ($this->clientId->isEmptyClientId()) {
$this->logger->debug('Empty clientId detected, forcing clean session bit to true');
$this->setCleanSession(true);
}
return $this;
}
|
[
"public",
"function",
"setClientId",
"(",
"ClientId",
"$",
"clientId",
")",
":",
"self",
"{",
"$",
"this",
"->",
"clientId",
"=",
"$",
"clientId",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'Set clientId'",
",",
"[",
"'actualClientString'",
"=>",
"(",
"string",
")",
"$",
"clientId",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"clientId",
"->",
"isEmptyClientId",
"(",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'Empty clientId detected, forcing clean session bit to true'",
")",
";",
"$",
"this",
"->",
"setCleanSession",
"(",
"true",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Handles everything related to setting the ClientId
@param ClientId $clientId
@return Parameters
|
[
"Handles",
"everything",
"related",
"to",
"setting",
"the",
"ClientId"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Protocol/Connect/Parameters.php#L173-L183
|
224,168
|
unreal4u/mqtt
|
src/Protocol/Connect/Parameters.php
|
Parameters.getConnectionUrl
|
public function getConnectionUrl(): string
{
return sprintf(
'%s://%s:%d',
$this->brokerPort->getTransmissionProtocol(),
$this->host,
$this->brokerPort->getBrokerPort()
);
}
|
php
|
public function getConnectionUrl(): string
{
return sprintf(
'%s://%s:%d',
$this->brokerPort->getTransmissionProtocol(),
$this->host,
$this->brokerPort->getBrokerPort()
);
}
|
[
"public",
"function",
"getConnectionUrl",
"(",
")",
":",
"string",
"{",
"return",
"sprintf",
"(",
"'%s://%s:%d'",
",",
"$",
"this",
"->",
"brokerPort",
"->",
"getTransmissionProtocol",
"(",
")",
",",
"$",
"this",
"->",
"host",
",",
"$",
"this",
"->",
"brokerPort",
"->",
"getBrokerPort",
"(",
")",
")",
";",
"}"
] |
Returns the connection string
@TODO Currently only TCP connections supported, SSL will come
@return string
|
[
"Returns",
"the",
"connection",
"string"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Protocol/Connect/Parameters.php#L197-L205
|
224,169
|
unreal4u/mqtt
|
src/Protocol/Connect/Parameters.php
|
Parameters.setKeepAlivePeriod
|
public function setKeepAlivePeriod(int $keepAlivePeriod): self
{
if ($keepAlivePeriod > 65535 || $keepAlivePeriod < 0) {
$this->logger->error('Keep alive period must be between 0 and 65535');
throw new \InvalidArgumentException('Keep alive period must be between 0 and 65535');
}
$this->keepAlivePeriod = $keepAlivePeriod;
return $this;
}
|
php
|
public function setKeepAlivePeriod(int $keepAlivePeriod): self
{
if ($keepAlivePeriod > 65535 || $keepAlivePeriod < 0) {
$this->logger->error('Keep alive period must be between 0 and 65535');
throw new \InvalidArgumentException('Keep alive period must be between 0 and 65535');
}
$this->keepAlivePeriod = $keepAlivePeriod;
return $this;
}
|
[
"public",
"function",
"setKeepAlivePeriod",
"(",
"int",
"$",
"keepAlivePeriod",
")",
":",
"self",
"{",
"if",
"(",
"$",
"keepAlivePeriod",
">",
"65535",
"||",
"$",
"keepAlivePeriod",
"<",
"0",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"error",
"(",
"'Keep alive period must be between 0 and 65535'",
")",
";",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Keep alive period must be between 0 and 65535'",
")",
";",
"}",
"$",
"this",
"->",
"keepAlivePeriod",
"=",
"$",
"keepAlivePeriod",
";",
"return",
"$",
"this",
";",
"}"
] |
Keep alive period is measured in positive seconds. The maximum is 18h, 12m and 15s, equivalent to 65535 seconds
@param int $keepAlivePeriod
@return Parameters
@throws \InvalidArgumentException
|
[
"Keep",
"alive",
"period",
"is",
"measured",
"in",
"positive",
"seconds",
".",
"The",
"maximum",
"is",
"18h",
"12m",
"and",
"15s",
"equivalent",
"to",
"65535",
"seconds"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Protocol/Connect/Parameters.php#L224-L233
|
224,170
|
unreal4u/mqtt
|
src/Protocol/Connect/Parameters.php
|
Parameters.setCredentials
|
public function setCredentials(string $username, string $password): self
{
$this->bitFlag &= ~64;
$this->bitFlag &= ~128;
if ($username !== '') {
$this->logger->debug('Username set, setting username flag');
$this->bitFlag |= 128;
$this->username = $username;
}
if ($password !== '') {
$this->logger->debug('Password set, setting password flag');
$this->bitFlag |= 64;
$this->password = $password;
}
return $this;
}
|
php
|
public function setCredentials(string $username, string $password): self
{
$this->bitFlag &= ~64;
$this->bitFlag &= ~128;
if ($username !== '') {
$this->logger->debug('Username set, setting username flag');
$this->bitFlag |= 128;
$this->username = $username;
}
if ($password !== '') {
$this->logger->debug('Password set, setting password flag');
$this->bitFlag |= 64;
$this->password = $password;
}
return $this;
}
|
[
"public",
"function",
"setCredentials",
"(",
"string",
"$",
"username",
",",
"string",
"$",
"password",
")",
":",
"self",
"{",
"$",
"this",
"->",
"bitFlag",
"&=",
"~",
"64",
";",
"$",
"this",
"->",
"bitFlag",
"&=",
"~",
"128",
";",
"if",
"(",
"$",
"username",
"!==",
"''",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'Username set, setting username flag'",
")",
";",
"$",
"this",
"->",
"bitFlag",
"|=",
"128",
";",
"$",
"this",
"->",
"username",
"=",
"$",
"username",
";",
"}",
"if",
"(",
"$",
"password",
"!==",
"''",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'Password set, setting password flag'",
")",
";",
"$",
"this",
"->",
"bitFlag",
"|=",
"64",
";",
"$",
"this",
"->",
"password",
"=",
"$",
"password",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Sets the 6th and 7th bit of the connect flag
@param string $username
@param string $password
@return Parameters
|
[
"Sets",
"the",
"6th",
"and",
"7th",
"bit",
"of",
"the",
"connect",
"flag"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Protocol/Connect/Parameters.php#L242-L260
|
224,171
|
unreal4u/mqtt
|
src/Protocol/Connect/Parameters.php
|
Parameters.setWillRetainBit
|
private function setWillRetainBit(bool $willRetain): self
{
$this->bitFlag &= ~32;
if ($willRetain === true) {
$this->logger->debug('Setting will retain flag');
$this->bitFlag |= 32;
}
return $this;
}
|
php
|
private function setWillRetainBit(bool $willRetain): self
{
$this->bitFlag &= ~32;
if ($willRetain === true) {
$this->logger->debug('Setting will retain flag');
$this->bitFlag |= 32;
}
return $this;
}
|
[
"private",
"function",
"setWillRetainBit",
"(",
"bool",
"$",
"willRetain",
")",
":",
"self",
"{",
"$",
"this",
"->",
"bitFlag",
"&=",
"~",
"32",
";",
"if",
"(",
"$",
"willRetain",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'Setting will retain flag'",
")",
";",
"$",
"this",
"->",
"bitFlag",
"|=",
"32",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Sets the 5th bit of the connect flag
@see http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc385349230
@param bool $willRetain
@return Parameters
|
[
"Sets",
"the",
"5th",
"bit",
"of",
"the",
"connect",
"flag"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Protocol/Connect/Parameters.php#L269-L277
|
224,172
|
unreal4u/mqtt
|
src/Protocol/Connect/Parameters.php
|
Parameters.setWillQoSLevelBit
|
private function setWillQoSLevelBit(int $QoSLevel): self
{
// Reset first the will QoS bits and proceed to set them
$this->bitFlag &= ~8; // Third bit: 8
$this->bitFlag &= ~16; // Fourth bit: 16
if ($QoSLevel !== 0) {
$this->logger->debug(sprintf(
'Setting will QoS level %d flag (bit %d)',
$QoSLevel,
$QoSLevel * 8
));
$this->bitFlag |= ($QoSLevel * 8);
}
return $this;
}
|
php
|
private function setWillQoSLevelBit(int $QoSLevel): self
{
// Reset first the will QoS bits and proceed to set them
$this->bitFlag &= ~8; // Third bit: 8
$this->bitFlag &= ~16; // Fourth bit: 16
if ($QoSLevel !== 0) {
$this->logger->debug(sprintf(
'Setting will QoS level %d flag (bit %d)',
$QoSLevel,
$QoSLevel * 8
));
$this->bitFlag |= ($QoSLevel * 8);
}
return $this;
}
|
[
"private",
"function",
"setWillQoSLevelBit",
"(",
"int",
"$",
"QoSLevel",
")",
":",
"self",
"{",
"// Reset first the will QoS bits and proceed to set them",
"$",
"this",
"->",
"bitFlag",
"&=",
"~",
"8",
";",
"// Third bit: 8",
"$",
"this",
"->",
"bitFlag",
"&=",
"~",
"16",
";",
"// Fourth bit: 16",
"if",
"(",
"$",
"QoSLevel",
"!==",
"0",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"sprintf",
"(",
"'Setting will QoS level %d flag (bit %d)'",
",",
"$",
"QoSLevel",
",",
"$",
"QoSLevel",
"*",
"8",
")",
")",
";",
"$",
"this",
"->",
"bitFlag",
"|=",
"(",
"$",
"QoSLevel",
"*",
"8",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Determines and sets the 3rd and 4th bits of the connect flag
@see http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc385349230
@param int $QoSLevel
@return Parameters
|
[
"Determines",
"and",
"sets",
"the",
"3rd",
"and",
"4th",
"bits",
"of",
"the",
"connect",
"flag"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Protocol/Connect/Parameters.php#L286-L303
|
224,173
|
unreal4u/mqtt
|
src/Protocol/Connect/Parameters.php
|
Parameters.setWill
|
public function setWill(Message $message): self
{
// Proceed only if we have a valid message
$this->bitFlag &= ~4;
if ($message->getTopicName() !== '') {
$this->logger->debug('Setting will flag');
$this->bitFlag |= 4;
}
$this->will = $message;
$this
->setWillRetainBit($message->isRetained())
->setWillQoSLevelBit($message->getQoSLevel());
return $this;
}
|
php
|
public function setWill(Message $message): self
{
// Proceed only if we have a valid message
$this->bitFlag &= ~4;
if ($message->getTopicName() !== '') {
$this->logger->debug('Setting will flag');
$this->bitFlag |= 4;
}
$this->will = $message;
$this
->setWillRetainBit($message->isRetained())
->setWillQoSLevelBit($message->getQoSLevel());
return $this;
}
|
[
"public",
"function",
"setWill",
"(",
"Message",
"$",
"message",
")",
":",
"self",
"{",
"// Proceed only if we have a valid message",
"$",
"this",
"->",
"bitFlag",
"&=",
"~",
"4",
";",
"if",
"(",
"$",
"message",
"->",
"getTopicName",
"(",
")",
"!==",
"''",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'Setting will flag'",
")",
";",
"$",
"this",
"->",
"bitFlag",
"|=",
"4",
";",
"}",
"$",
"this",
"->",
"will",
"=",
"$",
"message",
";",
"$",
"this",
"->",
"setWillRetainBit",
"(",
"$",
"message",
"->",
"isRetained",
"(",
")",
")",
"->",
"setWillQoSLevelBit",
"(",
"$",
"message",
"->",
"getQoSLevel",
"(",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Sets the given will. Will also set the 2nd bit of the connect flags if a message is provided
@see http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc385349230
@param Message $message
@return Parameters
@throws \unreal4u\MQTT\Exceptions\InvalidQoSLevel
@throws \unreal4u\MQTT\Exceptions\MissingTopicName
@throws \unreal4u\MQTT\Exceptions\MessageTooBig
|
[
"Sets",
"the",
"given",
"will",
".",
"Will",
"also",
"set",
"the",
"2nd",
"bit",
"of",
"the",
"connect",
"flags",
"if",
"a",
"message",
"is",
"provided"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Protocol/Connect/Parameters.php#L315-L330
|
224,174
|
unreal4u/mqtt
|
src/Protocol/Connect/Parameters.php
|
Parameters.setCleanSession
|
public function setCleanSession(bool $cleanSession): self
{
$this->bitFlag &= ~2;
if ($cleanSession === true) {
$this->logger->debug('Clean session flag set');
$this->bitFlag |= 2;
}
$this->cleanSession = $cleanSession;
return $this;
}
|
php
|
public function setCleanSession(bool $cleanSession): self
{
$this->bitFlag &= ~2;
if ($cleanSession === true) {
$this->logger->debug('Clean session flag set');
$this->bitFlag |= 2;
}
$this->cleanSession = $cleanSession;
return $this;
}
|
[
"public",
"function",
"setCleanSession",
"(",
"bool",
"$",
"cleanSession",
")",
":",
"self",
"{",
"$",
"this",
"->",
"bitFlag",
"&=",
"~",
"2",
";",
"if",
"(",
"$",
"cleanSession",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'Clean session flag set'",
")",
";",
"$",
"this",
"->",
"bitFlag",
"|=",
"2",
";",
"}",
"$",
"this",
"->",
"cleanSession",
"=",
"$",
"cleanSession",
";",
"return",
"$",
"this",
";",
"}"
] |
Sets the 1st bit of the connect flags
@param bool $cleanSession
@return Parameters
|
[
"Sets",
"the",
"1st",
"bit",
"of",
"the",
"connect",
"flags"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Protocol/Connect/Parameters.php#L338-L347
|
224,175
|
sulu/SuluProductBundle
|
Entity/SpecialPriceRepository.php
|
SpecialPriceRepository.findAllCurrent
|
public function findAllCurrent($limit = 1000, $page = 1)
{
try {
$qb = $this->getValidSpecialPriceQuery();
$adapter = new DoctrineORMAdapter($qb);
$pagerfanta = new Pagerfanta($adapter);
$pagerfanta->setMaxPerPage($limit);
$pagerfanta->setCurrentPage($page);
return $pagerfanta;
} catch (NoResultException $exc) {
return null;
}
}
|
php
|
public function findAllCurrent($limit = 1000, $page = 1)
{
try {
$qb = $this->getValidSpecialPriceQuery();
$adapter = new DoctrineORMAdapter($qb);
$pagerfanta = new Pagerfanta($adapter);
$pagerfanta->setMaxPerPage($limit);
$pagerfanta->setCurrentPage($page);
return $pagerfanta;
} catch (NoResultException $exc) {
return null;
}
}
|
[
"public",
"function",
"findAllCurrent",
"(",
"$",
"limit",
"=",
"1000",
",",
"$",
"page",
"=",
"1",
")",
"{",
"try",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"getValidSpecialPriceQuery",
"(",
")",
";",
"$",
"adapter",
"=",
"new",
"DoctrineORMAdapter",
"(",
"$",
"qb",
")",
";",
"$",
"pagerfanta",
"=",
"new",
"Pagerfanta",
"(",
"$",
"adapter",
")",
";",
"$",
"pagerfanta",
"->",
"setMaxPerPage",
"(",
"$",
"limit",
")",
";",
"$",
"pagerfanta",
"->",
"setCurrentPage",
"(",
"$",
"page",
")",
";",
"return",
"$",
"pagerfanta",
";",
"}",
"catch",
"(",
"NoResultException",
"$",
"exc",
")",
"{",
"return",
"null",
";",
"}",
"}"
] |
Returns the current special prices.
@param int $limit
@param int $page
@return null|Pagerfanta
|
[
"Returns",
"the",
"current",
"special",
"prices",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Entity/SpecialPriceRepository.php#L32-L46
|
224,176
|
sulu/SuluProductBundle
|
Entity/SpecialPriceRepository.php
|
SpecialPriceRepository.findAllCurrentIds
|
public function findAllCurrentIds($limit = 1000)
{
try {
$queryBuilder = $this->getValidSpecialPriceQuery()
->select('specialPrice.id')
->addOrderBy('specialPrice.id', 'DESC');
$query = $queryBuilder->getQuery()
->useResultCache(true, 3600);
$ids = $query->getScalarResult();
return array_column($ids, 'id');
} catch (NoResultException $exc) {
return null;
}
}
|
php
|
public function findAllCurrentIds($limit = 1000)
{
try {
$queryBuilder = $this->getValidSpecialPriceQuery()
->select('specialPrice.id')
->addOrderBy('specialPrice.id', 'DESC');
$query = $queryBuilder->getQuery()
->useResultCache(true, 3600);
$ids = $query->getScalarResult();
return array_column($ids, 'id');
} catch (NoResultException $exc) {
return null;
}
}
|
[
"public",
"function",
"findAllCurrentIds",
"(",
"$",
"limit",
"=",
"1000",
")",
"{",
"try",
"{",
"$",
"queryBuilder",
"=",
"$",
"this",
"->",
"getValidSpecialPriceQuery",
"(",
")",
"->",
"select",
"(",
"'specialPrice.id'",
")",
"->",
"addOrderBy",
"(",
"'specialPrice.id'",
",",
"'DESC'",
")",
";",
"$",
"query",
"=",
"$",
"queryBuilder",
"->",
"getQuery",
"(",
")",
"->",
"useResultCache",
"(",
"true",
",",
"3600",
")",
";",
"$",
"ids",
"=",
"$",
"query",
"->",
"getScalarResult",
"(",
")",
";",
"return",
"array_column",
"(",
"$",
"ids",
",",
"'id'",
")",
";",
"}",
"catch",
"(",
"NoResultException",
"$",
"exc",
")",
"{",
"return",
"null",
";",
"}",
"}"
] |
Returns the ids of a specific amount of special prices.
@param int $limit
@return array|null
|
[
"Returns",
"the",
"ids",
"of",
"a",
"specific",
"amount",
"of",
"special",
"prices",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Entity/SpecialPriceRepository.php#L55-L70
|
224,177
|
sulu/SuluProductBundle
|
Entity/SpecialPriceRepository.php
|
SpecialPriceRepository.getValidSpecialPriceQuery
|
protected function getValidSpecialPriceQuery()
{
$qb = $this->createQueryBuilder('specialPrice')
->leftJoin('specialPrice.product', 'product')
->leftJoin('product.status', 'productStatus')
->where(':now BETWEEN specialPrice.startDate AND specialPrice.endDate')
->andWhere('productStatus.id = :productStatus')
->setParameter('productStatus', Status::ACTIVE)
->setParameter('now', new \DateTime());
return $qb;
}
|
php
|
protected function getValidSpecialPriceQuery()
{
$qb = $this->createQueryBuilder('specialPrice')
->leftJoin('specialPrice.product', 'product')
->leftJoin('product.status', 'productStatus')
->where(':now BETWEEN specialPrice.startDate AND specialPrice.endDate')
->andWhere('productStatus.id = :productStatus')
->setParameter('productStatus', Status::ACTIVE)
->setParameter('now', new \DateTime());
return $qb;
}
|
[
"protected",
"function",
"getValidSpecialPriceQuery",
"(",
")",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"createQueryBuilder",
"(",
"'specialPrice'",
")",
"->",
"leftJoin",
"(",
"'specialPrice.product'",
",",
"'product'",
")",
"->",
"leftJoin",
"(",
"'product.status'",
",",
"'productStatus'",
")",
"->",
"where",
"(",
"':now BETWEEN specialPrice.startDate AND specialPrice.endDate'",
")",
"->",
"andWhere",
"(",
"'productStatus.id = :productStatus'",
")",
"->",
"setParameter",
"(",
"'productStatus'",
",",
"Status",
"::",
"ACTIVE",
")",
"->",
"setParameter",
"(",
"'now'",
",",
"new",
"\\",
"DateTime",
"(",
")",
")",
";",
"return",
"$",
"qb",
";",
"}"
] |
Returns special price querybuilder.
@return \Doctrine\ORM\QueryBuilder
|
[
"Returns",
"special",
"price",
"querybuilder",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Entity/SpecialPriceRepository.php#L77-L88
|
224,178
|
unreal4u/mqtt
|
src/Utilities.php
|
Utilities.convertNumberToBinaryString
|
public static function convertNumberToBinaryString(int $number): string
{
if ($number > 65535) {
throw new OutOfRangeException('This is an INT16 conversion, so the maximum is 65535');
}
return chr($number >> 8) . chr($number & 255);
}
|
php
|
public static function convertNumberToBinaryString(int $number): string
{
if ($number > 65535) {
throw new OutOfRangeException('This is an INT16 conversion, so the maximum is 65535');
}
return chr($number >> 8) . chr($number & 255);
}
|
[
"public",
"static",
"function",
"convertNumberToBinaryString",
"(",
"int",
"$",
"number",
")",
":",
"string",
"{",
"if",
"(",
"$",
"number",
">",
"65535",
")",
"{",
"throw",
"new",
"OutOfRangeException",
"(",
"'This is an INT16 conversion, so the maximum is 65535'",
")",
";",
"}",
"return",
"chr",
"(",
"$",
"number",
">>",
"8",
")",
".",
"chr",
"(",
"$",
"number",
"&",
"255",
")",
";",
"}"
] |
Converts a number to a binary string that the MQTT protocol understands
@param int $number
@return string
@throws OutOfRangeException
|
[
"Converts",
"a",
"number",
"to",
"a",
"binary",
"string",
"that",
"the",
"MQTT",
"protocol",
"understands"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Utilities.php#L51-L58
|
224,179
|
unreal4u/mqtt
|
src/Utilities.php
|
Utilities.convertBinaryStringToNumber
|
public static function convertBinaryStringToNumber(string $binaryString): int
{
return self::convertEndianness((ord($binaryString{1}) << 8) + (ord($binaryString{0}) & 255));
}
|
php
|
public static function convertBinaryStringToNumber(string $binaryString): int
{
return self::convertEndianness((ord($binaryString{1}) << 8) + (ord($binaryString{0}) & 255));
}
|
[
"public",
"static",
"function",
"convertBinaryStringToNumber",
"(",
"string",
"$",
"binaryString",
")",
":",
"int",
"{",
"return",
"self",
"::",
"convertEndianness",
"(",
"(",
"ord",
"(",
"$",
"binaryString",
"{",
"1",
"}",
")",
"<<",
"8",
")",
"+",
"(",
"ord",
"(",
"$",
"binaryString",
"{",
"0",
"}",
")",
"&",
"255",
")",
")",
";",
"}"
] |
Converts a binary representation of a number to an actual int
@param string $binaryString
@return int
@throws OutOfRangeException
|
[
"Converts",
"a",
"binary",
"representation",
"of",
"a",
"number",
"to",
"an",
"actual",
"int"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Utilities.php#L67-L70
|
224,180
|
unreal4u/mqtt
|
src/Utilities.php
|
Utilities.convertRemainingLengthStringToInt
|
public static function convertRemainingLengthStringToInt(string $remainingLengthField): int
{
$multiplier = 128;
$value = 0;
$iteration = 0;
do {
// Extract the next byte in the sequence
$encodedByte = ord($remainingLengthField{$iteration});
// Add the current multiplier^iteration * first half of byte
$value += ($encodedByte & 127) * ($multiplier ** $iteration);
if ($multiplier > 128 ** 3) {
throw new LogicException('Malformed remaining length field');
}
// Prepare for the next iteration
$iteration++;
} while (($encodedByte & 128) !== 0);
return $value;
}
|
php
|
public static function convertRemainingLengthStringToInt(string $remainingLengthField): int
{
$multiplier = 128;
$value = 0;
$iteration = 0;
do {
// Extract the next byte in the sequence
$encodedByte = ord($remainingLengthField{$iteration});
// Add the current multiplier^iteration * first half of byte
$value += ($encodedByte & 127) * ($multiplier ** $iteration);
if ($multiplier > 128 ** 3) {
throw new LogicException('Malformed remaining length field');
}
// Prepare for the next iteration
$iteration++;
} while (($encodedByte & 128) !== 0);
return $value;
}
|
[
"public",
"static",
"function",
"convertRemainingLengthStringToInt",
"(",
"string",
"$",
"remainingLengthField",
")",
":",
"int",
"{",
"$",
"multiplier",
"=",
"128",
";",
"$",
"value",
"=",
"0",
";",
"$",
"iteration",
"=",
"0",
";",
"do",
"{",
"// Extract the next byte in the sequence",
"$",
"encodedByte",
"=",
"ord",
"(",
"$",
"remainingLengthField",
"{",
"$",
"iteration",
"}",
")",
";",
"// Add the current multiplier^iteration * first half of byte",
"$",
"value",
"+=",
"(",
"$",
"encodedByte",
"&",
"127",
")",
"*",
"(",
"$",
"multiplier",
"**",
"$",
"iteration",
")",
";",
"if",
"(",
"$",
"multiplier",
">",
"128",
"**",
"3",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"'Malformed remaining length field'",
")",
";",
"}",
"// Prepare for the next iteration",
"$",
"iteration",
"++",
";",
"}",
"while",
"(",
"(",
"$",
"encodedByte",
"&",
"128",
")",
"!==",
"0",
")",
";",
"return",
"$",
"value",
";",
"}"
] |
The remaining length of a message is encoded in this specific way, the opposite of formatRemainingLengthOutput
Many thanks to Peter's blog for your excellent examples and knowledge.
@see http://indigoo.com/petersblog/?p=263
Original pseudo-algorithm as per the documentation:
<pre>
multiplier = 1
value = 0
do
encodedByte = 'next byte from stream'
value += (encodedByte & 127) * multiplier
if (multiplier > 128*128*128)
throw Error(Malformed Remaining Length)
multiplier *= 128
while ((encodedByte & 128) != 0)
</pre>
@see http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/errata01/os/mqtt-v3.1.1-errata01-os-complete.html#_Toc385349213
@see Utilities::formatRemainingLengthOutput()
@param string $remainingLengthField
@return int
|
[
"The",
"remaining",
"length",
"of",
"a",
"message",
"is",
"encoded",
"in",
"this",
"specific",
"way",
"the",
"opposite",
"of",
"formatRemainingLengthOutput"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Utilities.php#L139-L160
|
224,181
|
sulu/SuluProductBundle
|
Controller/WebsiteProductController.php
|
WebsiteProductController.indexAction
|
public function indexAction(ProductInterface $product, ProductTranslation $translation)
{
$apiProduct = $this->getProductFactory()->createApiEntity($product, $translation->getLocale());
return $this->render(
$this->getProductViewTemplate(),
[
'product' => $apiProduct,
'urls' => $this->getAllRoutesOfProduct($product),
]
);
}
|
php
|
public function indexAction(ProductInterface $product, ProductTranslation $translation)
{
$apiProduct = $this->getProductFactory()->createApiEntity($product, $translation->getLocale());
return $this->render(
$this->getProductViewTemplate(),
[
'product' => $apiProduct,
'urls' => $this->getAllRoutesOfProduct($product),
]
);
}
|
[
"public",
"function",
"indexAction",
"(",
"ProductInterface",
"$",
"product",
",",
"ProductTranslation",
"$",
"translation",
")",
"{",
"$",
"apiProduct",
"=",
"$",
"this",
"->",
"getProductFactory",
"(",
")",
"->",
"createApiEntity",
"(",
"$",
"product",
",",
"$",
"translation",
"->",
"getLocale",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"$",
"this",
"->",
"getProductViewTemplate",
"(",
")",
",",
"[",
"'product'",
"=>",
"$",
"apiProduct",
",",
"'urls'",
"=>",
"$",
"this",
"->",
"getAllRoutesOfProduct",
"(",
"$",
"product",
")",
",",
"]",
")",
";",
"}"
] |
This action is used for displaying a product via a template.
The template that is defined by sulu_product.template parameter is used for displaying
the product.
@param ProductInterface $product
@param ProductTranslation $translation
@return Response
|
[
"This",
"action",
"is",
"used",
"for",
"displaying",
"a",
"product",
"via",
"a",
"template",
".",
"The",
"template",
"that",
"is",
"defined",
"by",
"sulu_product",
".",
"template",
"parameter",
"is",
"used",
"for",
"displaying",
"the",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Controller/WebsiteProductController.php#L35-L46
|
224,182
|
sulu/SuluProductBundle
|
Controller/WebsiteProductController.php
|
WebsiteProductController.getAllRoutesOfProduct
|
public function getAllRoutesOfProduct(ProductInterface $product)
{
$urls = [];
/** @var ProductTranslation $productTranslation */
foreach ($product->getTranslations() as $productTranslation) {
if ($productTranslation->getRoute()) {
$urls[$productTranslation->getLocale()] = $productTranslation->getRoute()->getPath();
}
}
return $urls;
}
|
php
|
public function getAllRoutesOfProduct(ProductInterface $product)
{
$urls = [];
/** @var ProductTranslation $productTranslation */
foreach ($product->getTranslations() as $productTranslation) {
if ($productTranslation->getRoute()) {
$urls[$productTranslation->getLocale()] = $productTranslation->getRoute()->getPath();
}
}
return $urls;
}
|
[
"public",
"function",
"getAllRoutesOfProduct",
"(",
"ProductInterface",
"$",
"product",
")",
"{",
"$",
"urls",
"=",
"[",
"]",
";",
"/** @var ProductTranslation $productTranslation */",
"foreach",
"(",
"$",
"product",
"->",
"getTranslations",
"(",
")",
"as",
"$",
"productTranslation",
")",
"{",
"if",
"(",
"$",
"productTranslation",
"->",
"getRoute",
"(",
")",
")",
"{",
"$",
"urls",
"[",
"$",
"productTranslation",
"->",
"getLocale",
"(",
")",
"]",
"=",
"$",
"productTranslation",
"->",
"getRoute",
"(",
")",
"->",
"getPath",
"(",
")",
";",
"}",
"}",
"return",
"$",
"urls",
";",
"}"
] |
Returns all routes that are defined for given product.
@param ProductInterface $product
@return array
|
[
"Returns",
"all",
"routes",
"that",
"are",
"defined",
"for",
"given",
"product",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Controller/WebsiteProductController.php#L55-L66
|
224,183
|
sulu/SuluProductBundle
|
Product/ProductPriceManager.php
|
ProductPriceManager.getBasePriceForCurrency
|
public function getBasePriceForCurrency(ProductInterface $product, $currency = null)
{
$currency = $currency ?: $this->defaultCurrency;
if ($prices = $product->getPrices()) {
foreach ($prices as $price) {
if ($price->getCurrency()->getCode() == $currency && $price->getMinimumQuantity() == 0) {
return $price;
}
}
}
return null;
}
|
php
|
public function getBasePriceForCurrency(ProductInterface $product, $currency = null)
{
$currency = $currency ?: $this->defaultCurrency;
if ($prices = $product->getPrices()) {
foreach ($prices as $price) {
if ($price->getCurrency()->getCode() == $currency && $price->getMinimumQuantity() == 0) {
return $price;
}
}
}
return null;
}
|
[
"public",
"function",
"getBasePriceForCurrency",
"(",
"ProductInterface",
"$",
"product",
",",
"$",
"currency",
"=",
"null",
")",
"{",
"$",
"currency",
"=",
"$",
"currency",
"?",
":",
"$",
"this",
"->",
"defaultCurrency",
";",
"if",
"(",
"$",
"prices",
"=",
"$",
"product",
"->",
"getPrices",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"prices",
"as",
"$",
"price",
")",
"{",
"if",
"(",
"$",
"price",
"->",
"getCurrency",
"(",
")",
"->",
"getCode",
"(",
")",
"==",
"$",
"currency",
"&&",
"$",
"price",
"->",
"getMinimumQuantity",
"(",
")",
"==",
"0",
")",
"{",
"return",
"$",
"price",
";",
"}",
"}",
"}",
"return",
"null",
";",
"}"
] |
Returns the base prices for the product by a given currency.
@param ProductInterface $product
@param null|string $currency
@return null|ProductPrice
|
[
"Returns",
"the",
"base",
"prices",
"for",
"the",
"product",
"by",
"a",
"given",
"currency",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductPriceManager.php#L134-L146
|
224,184
|
sulu/SuluProductBundle
|
Product/ProductPriceManager.php
|
ProductPriceManager.isValidSpecialPrice
|
private function isValidSpecialPrice(SpecialPrice $specialPrice)
{
$startDate = $specialPrice->getStartDate();
$endDate = $specialPrice->getEndDate();
$now = new \DateTime();
// Check if special price is stil valid.
if (($now >= $startDate && $now <= $endDate) ||
($now >= $startDate && empty($endDate)) ||
(empty($startDate) && empty($endDate))
) {
return true;
}
return false;
}
|
php
|
private function isValidSpecialPrice(SpecialPrice $specialPrice)
{
$startDate = $specialPrice->getStartDate();
$endDate = $specialPrice->getEndDate();
$now = new \DateTime();
// Check if special price is stil valid.
if (($now >= $startDate && $now <= $endDate) ||
($now >= $startDate && empty($endDate)) ||
(empty($startDate) && empty($endDate))
) {
return true;
}
return false;
}
|
[
"private",
"function",
"isValidSpecialPrice",
"(",
"SpecialPrice",
"$",
"specialPrice",
")",
"{",
"$",
"startDate",
"=",
"$",
"specialPrice",
"->",
"getStartDate",
"(",
")",
";",
"$",
"endDate",
"=",
"$",
"specialPrice",
"->",
"getEndDate",
"(",
")",
";",
"$",
"now",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"// Check if special price is stil valid.",
"if",
"(",
"(",
"$",
"now",
">=",
"$",
"startDate",
"&&",
"$",
"now",
"<=",
"$",
"endDate",
")",
"||",
"(",
"$",
"now",
">=",
"$",
"startDate",
"&&",
"empty",
"(",
"$",
"endDate",
")",
")",
"||",
"(",
"empty",
"(",
"$",
"startDate",
")",
"&&",
"empty",
"(",
"$",
"endDate",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Checks if a special price is still valid by today.
@param SpecialPrice $specialPrice
@return bool
|
[
"Checks",
"if",
"a",
"special",
"price",
"is",
"still",
"valid",
"by",
"today",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Product/ProductPriceManager.php#L234-L249
|
224,185
|
kesar/PhpOpenSubtitles
|
src/kesar/PhpOpenSubtitles/HashGenerator.php
|
HashGenerator.get
|
public function get()
{
$handle = fopen($this->filePath, "rb");
$fileSize = filesize($this->filePath);
$hash = array(
3 => 0,
2 => 0,
1 => ($fileSize >> 16) & 0xFFFF,
0 => $fileSize & 0xFFFF
);
for ($i = 0; $i < 8192; $i++) {
$tmp = $this->readUINT64($handle);
$hash = $this->addUINT64($hash, $tmp);
}
$offset = $fileSize - 65536;
fseek($handle, $offset > 0 ? $offset : 0, SEEK_SET);
for ($i = 0; $i < 8192; $i++) {
$tmp = $this->readUINT64($handle);
$hash = $this->addUINT64($hash, $tmp);
}
fclose($handle);
return $this->uINT64FormatHex($hash);
}
|
php
|
public function get()
{
$handle = fopen($this->filePath, "rb");
$fileSize = filesize($this->filePath);
$hash = array(
3 => 0,
2 => 0,
1 => ($fileSize >> 16) & 0xFFFF,
0 => $fileSize & 0xFFFF
);
for ($i = 0; $i < 8192; $i++) {
$tmp = $this->readUINT64($handle);
$hash = $this->addUINT64($hash, $tmp);
}
$offset = $fileSize - 65536;
fseek($handle, $offset > 0 ? $offset : 0, SEEK_SET);
for ($i = 0; $i < 8192; $i++) {
$tmp = $this->readUINT64($handle);
$hash = $this->addUINT64($hash, $tmp);
}
fclose($handle);
return $this->uINT64FormatHex($hash);
}
|
[
"public",
"function",
"get",
"(",
")",
"{",
"$",
"handle",
"=",
"fopen",
"(",
"$",
"this",
"->",
"filePath",
",",
"\"rb\"",
")",
";",
"$",
"fileSize",
"=",
"filesize",
"(",
"$",
"this",
"->",
"filePath",
")",
";",
"$",
"hash",
"=",
"array",
"(",
"3",
"=>",
"0",
",",
"2",
"=>",
"0",
",",
"1",
"=>",
"(",
"$",
"fileSize",
">>",
"16",
")",
"&",
"0xFFFF",
",",
"0",
"=>",
"$",
"fileSize",
"&",
"0xFFFF",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"8192",
";",
"$",
"i",
"++",
")",
"{",
"$",
"tmp",
"=",
"$",
"this",
"->",
"readUINT64",
"(",
"$",
"handle",
")",
";",
"$",
"hash",
"=",
"$",
"this",
"->",
"addUINT64",
"(",
"$",
"hash",
",",
"$",
"tmp",
")",
";",
"}",
"$",
"offset",
"=",
"$",
"fileSize",
"-",
"65536",
";",
"fseek",
"(",
"$",
"handle",
",",
"$",
"offset",
">",
"0",
"?",
"$",
"offset",
":",
"0",
",",
"SEEK_SET",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"8192",
";",
"$",
"i",
"++",
")",
"{",
"$",
"tmp",
"=",
"$",
"this",
"->",
"readUINT64",
"(",
"$",
"handle",
")",
";",
"$",
"hash",
"=",
"$",
"this",
"->",
"addUINT64",
"(",
"$",
"hash",
",",
"$",
"tmp",
")",
";",
"}",
"fclose",
"(",
"$",
"handle",
")",
";",
"return",
"$",
"this",
"->",
"uINT64FormatHex",
"(",
"$",
"hash",
")",
";",
"}"
] |
Hash to send to OpenSubtitles
@return string
|
[
"Hash",
"to",
"send",
"to",
"OpenSubtitles"
] |
8b2ed1a06f393aa33403b27b32cace3c3c7d4ef3
|
https://github.com/kesar/PhpOpenSubtitles/blob/8b2ed1a06f393aa33403b27b32cace3c3c7d4ef3/src/kesar/PhpOpenSubtitles/HashGenerator.php#L22-L50
|
224,186
|
sulu/SuluProductBundle
|
Entity/TaxClassTranslation.php
|
TaxClassTranslation.setTaxClass
|
public function setTaxClass(\Sulu\Bundle\ProductBundle\Entity\TaxClass $taxClass = null)
{
$this->taxClass = $taxClass;
return $this;
}
|
php
|
public function setTaxClass(\Sulu\Bundle\ProductBundle\Entity\TaxClass $taxClass = null)
{
$this->taxClass = $taxClass;
return $this;
}
|
[
"public",
"function",
"setTaxClass",
"(",
"\\",
"Sulu",
"\\",
"Bundle",
"\\",
"ProductBundle",
"\\",
"Entity",
"\\",
"TaxClass",
"$",
"taxClass",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"taxClass",
"=",
"$",
"taxClass",
";",
"return",
"$",
"this",
";",
"}"
] |
Set taxClass.
@param \Sulu\Bundle\ProductBundle\Entity\TaxClass $taxClass
@return TaxClassTranslation
|
[
"Set",
"taxClass",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Entity/TaxClassTranslation.php#L104-L109
|
224,187
|
unreal4u/mqtt
|
src/DataTypes/Message.php
|
Message.getQoSLevel
|
public function getQoSLevel(): int
{
if ($this->qosLevel === null) {
// QoSLevel defaults at 0
$this->qosLevel = new QoSLevel(0);
}
return $this->qosLevel->getQoSLevel();
}
|
php
|
public function getQoSLevel(): int
{
if ($this->qosLevel === null) {
// QoSLevel defaults at 0
$this->qosLevel = new QoSLevel(0);
}
return $this->qosLevel->getQoSLevel();
}
|
[
"public",
"function",
"getQoSLevel",
"(",
")",
":",
"int",
"{",
"if",
"(",
"$",
"this",
"->",
"qosLevel",
"===",
"null",
")",
"{",
"// QoSLevel defaults at 0",
"$",
"this",
"->",
"qosLevel",
"=",
"new",
"QoSLevel",
"(",
"0",
")",
";",
"}",
"return",
"$",
"this",
"->",
"qosLevel",
"->",
"getQoSLevel",
"(",
")",
";",
"}"
] |
Gets the current QoS level
@return int
@throws \unreal4u\MQTT\Exceptions\InvalidQoSLevel
|
[
"Gets",
"the",
"current",
"QoS",
"level"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/DataTypes/Message.php#L102-L109
|
224,188
|
dave-redfern/laravel-doctrine-behaviours
|
src/Traits/Blamable.php
|
Blamable.blameCreator
|
public function blameCreator($user)
{
if (is_null($this->createdBy) && is_null($this->updatedBy)) {
$this->createdBy = $this->updatedBy = $user;
}
}
|
php
|
public function blameCreator($user)
{
if (is_null($this->createdBy) && is_null($this->updatedBy)) {
$this->createdBy = $this->updatedBy = $user;
}
}
|
[
"public",
"function",
"blameCreator",
"(",
"$",
"user",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"createdBy",
")",
"&&",
"is_null",
"(",
"$",
"this",
"->",
"updatedBy",
")",
")",
"{",
"$",
"this",
"->",
"createdBy",
"=",
"$",
"this",
"->",
"updatedBy",
"=",
"$",
"user",
";",
"}",
"}"
] |
Initialise the blamable fields
@param string $user
@return void
|
[
"Initialise",
"the",
"blamable",
"fields"
] |
c481eea497a0df6fc46bc2cadb08a0ed0ae819a4
|
https://github.com/dave-redfern/laravel-doctrine-behaviours/blob/c481eea497a0df6fc46bc2cadb08a0ed0ae819a4/src/Traits/Blamable.php#L64-L69
|
224,189
|
sulu/SuluProductBundle
|
EventListener/ProductTranslationEventListener.php
|
ProductTranslationEventListener.postPersist
|
public function postPersist(ProductTranslationEvent $productTranslationEvent)
{
$this->productRouteManager->saveRoute($productTranslationEvent->getProductTranslation());
$this->entityManager->flush();
}
|
php
|
public function postPersist(ProductTranslationEvent $productTranslationEvent)
{
$this->productRouteManager->saveRoute($productTranslationEvent->getProductTranslation());
$this->entityManager->flush();
}
|
[
"public",
"function",
"postPersist",
"(",
"ProductTranslationEvent",
"$",
"productTranslationEvent",
")",
"{",
"$",
"this",
"->",
"productRouteManager",
"->",
"saveRoute",
"(",
"$",
"productTranslationEvent",
"->",
"getProductTranslation",
"(",
")",
")",
";",
"$",
"this",
"->",
"entityManager",
"->",
"flush",
"(",
")",
";",
"}"
] |
Called when product translation has been created and stored to database.
Will save a new product route.
@param ProductTranslationEvent $productTranslationEvent
|
[
"Called",
"when",
"product",
"translation",
"has",
"been",
"created",
"and",
"stored",
"to",
"database",
".",
"Will",
"save",
"a",
"new",
"product",
"route",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/EventListener/ProductTranslationEventListener.php#L51-L55
|
224,190
|
unreal4u/mqtt
|
src/Protocol/PubRec.php
|
PubRec.performSpecialActions
|
public function performSpecialActions(ClientInterface $client, WritableContentInterface $originalRequest): bool
{
$this->controlPacketIdentifiers($originalRequest);
$pubRel = new PubRel($this->logger);
$pubRel->setPacketIdentifier($this->packetIdentifier);
$pubComp = $client->processObject($pubRel);
$this->logger->debug('Created PubRel as response, got PubComp back', ['PubComp' => $pubComp]);
return true;
}
|
php
|
public function performSpecialActions(ClientInterface $client, WritableContentInterface $originalRequest): bool
{
$this->controlPacketIdentifiers($originalRequest);
$pubRel = new PubRel($this->logger);
$pubRel->setPacketIdentifier($this->packetIdentifier);
$pubComp = $client->processObject($pubRel);
$this->logger->debug('Created PubRel as response, got PubComp back', ['PubComp' => $pubComp]);
return true;
}
|
[
"public",
"function",
"performSpecialActions",
"(",
"ClientInterface",
"$",
"client",
",",
"WritableContentInterface",
"$",
"originalRequest",
")",
":",
"bool",
"{",
"$",
"this",
"->",
"controlPacketIdentifiers",
"(",
"$",
"originalRequest",
")",
";",
"$",
"pubRel",
"=",
"new",
"PubRel",
"(",
"$",
"this",
"->",
"logger",
")",
";",
"$",
"pubRel",
"->",
"setPacketIdentifier",
"(",
"$",
"this",
"->",
"packetIdentifier",
")",
";",
"$",
"pubComp",
"=",
"$",
"client",
"->",
"processObject",
"(",
"$",
"pubRel",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'Created PubRel as response, got PubComp back'",
",",
"[",
"'PubComp'",
"=>",
"$",
"pubComp",
"]",
")",
";",
"return",
"true",
";",
"}"
] |
Any class can overwrite the default behaviour
@param ClientInterface $client
@param WritableContentInterface $originalRequest
@return bool
@throws LogicException
|
[
"Any",
"class",
"can",
"overwrite",
"the",
"default",
"behaviour"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Protocol/PubRec.php#L84-L92
|
224,191
|
sulu/SuluProductBundle
|
Api/Unit.php
|
Unit.getName
|
public function getName()
{
if (!$this->entity->getTranslation($this->locale)) {
return null;
}
return $this->entity->getTranslation($this->locale)->getName();
}
|
php
|
public function getName()
{
if (!$this->entity->getTranslation($this->locale)) {
return null;
}
return $this->entity->getTranslation($this->locale)->getName();
}
|
[
"public",
"function",
"getName",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"entity",
"->",
"getTranslation",
"(",
"$",
"this",
"->",
"locale",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"entity",
"->",
"getTranslation",
"(",
"$",
"this",
"->",
"locale",
")",
"->",
"getName",
"(",
")",
";",
"}"
] |
The name of the type.
@VirtualProperty
@SerializedName("name")
@Groups({"cart"})
@return int The name of the type
|
[
"The",
"name",
"of",
"the",
"type",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/Api/Unit.php#L60-L67
|
224,192
|
dave-redfern/laravel-doctrine-behaviours
|
src/Traits/Timestampable.php
|
Timestampable.initializeTimestamps
|
public function initializeTimestamps()
{
if (is_null($this->createdAt) && is_null($this->updatedAt)) {
$this->createdAt = Carbon::now();
$this->updatedAt = Carbon::now();
}
}
|
php
|
public function initializeTimestamps()
{
if (is_null($this->createdAt) && is_null($this->updatedAt)) {
$this->createdAt = Carbon::now();
$this->updatedAt = Carbon::now();
}
}
|
[
"public",
"function",
"initializeTimestamps",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"createdAt",
")",
"&&",
"is_null",
"(",
"$",
"this",
"->",
"updatedAt",
")",
")",
"{",
"$",
"this",
"->",
"createdAt",
"=",
"Carbon",
"::",
"now",
"(",
")",
";",
"$",
"this",
"->",
"updatedAt",
"=",
"Carbon",
"::",
"now",
"(",
")",
";",
"}",
"}"
] |
Initialises the timestamp properties
|
[
"Initialises",
"the",
"timestamp",
"properties"
] |
c481eea497a0df6fc46bc2cadb08a0ed0ae819a4
|
https://github.com/dave-redfern/laravel-doctrine-behaviours/blob/c481eea497a0df6fc46bc2cadb08a0ed0ae819a4/src/Traits/Timestampable.php#L62-L68
|
224,193
|
sulu/SuluProductBundle
|
DependencyInjection/SuluProductExtension.php
|
SuluProductExtension.retrieveProductTypesMap
|
private function retrieveProductTypesMap()
{
$productTypeMap = [];
LoadProductTypes::processProductTypesFixtures(
function (\DOMElement $element) use (&$productTypeMap) {
$productTypeMap[$element->getAttribute('key')] = $element->getAttribute('id');
}
);
return $productTypeMap;
}
|
php
|
private function retrieveProductTypesMap()
{
$productTypeMap = [];
LoadProductTypes::processProductTypesFixtures(
function (\DOMElement $element) use (&$productTypeMap) {
$productTypeMap[$element->getAttribute('key')] = $element->getAttribute('id');
}
);
return $productTypeMap;
}
|
[
"private",
"function",
"retrieveProductTypesMap",
"(",
")",
"{",
"$",
"productTypeMap",
"=",
"[",
"]",
";",
"LoadProductTypes",
"::",
"processProductTypesFixtures",
"(",
"function",
"(",
"\\",
"DOMElement",
"$",
"element",
")",
"use",
"(",
"&",
"$",
"productTypeMap",
")",
"{",
"$",
"productTypeMap",
"[",
"$",
"element",
"->",
"getAttribute",
"(",
"'key'",
")",
"]",
"=",
"$",
"element",
"->",
"getAttribute",
"(",
"'id'",
")",
";",
"}",
")",
";",
"return",
"$",
"productTypeMap",
";",
"}"
] |
Returns key to id mapping for product-types.
Processes product-types fixtures xml.
@return array
|
[
"Returns",
"key",
"to",
"id",
"mapping",
"for",
"product",
"-",
"types",
".",
"Processes",
"product",
"-",
"types",
"fixtures",
"xml",
"."
] |
9f22c2dab940a04463c98e415b15ea1d62828316
|
https://github.com/sulu/SuluProductBundle/blob/9f22c2dab940a04463c98e415b15ea1d62828316/DependencyInjection/SuluProductExtension.php#L104-L114
|
224,194
|
robwittman/leaky-bucket-rate-limiter
|
src/RateLimiter.php
|
RateLimiter.fetchBucket
|
protected function fetchBucket($key) {
$data = $this->storage->get($key);
return json_decode($data, TRUE);
}
|
php
|
protected function fetchBucket($key) {
$data = $this->storage->get($key);
return json_decode($data, TRUE);
}
|
[
"protected",
"function",
"fetchBucket",
"(",
"$",
"key",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"storage",
"->",
"get",
"(",
"$",
"key",
")",
";",
"return",
"json_decode",
"(",
"$",
"data",
",",
"TRUE",
")",
";",
"}"
] |
Fetch our bucket data from storage
@param string $key
@return void
|
[
"Fetch",
"our",
"bucket",
"data",
"from",
"storage"
] |
c74720acfd80f3a6a258b591faae6f27b786cde4
|
https://github.com/robwittman/leaky-bucket-rate-limiter/blob/c74720acfd80f3a6a258b591faae6f27b786cde4/src/RateLimiter.php#L132-L135
|
224,195
|
robwittman/leaky-bucket-rate-limiter
|
src/RateLimiter.php
|
RateLimiter.save
|
protected function save($bucket) {
return $this->storage->set($this->key, json_encode($bucket->getData()));
}
|
php
|
protected function save($bucket) {
return $this->storage->set($this->key, json_encode($bucket->getData()));
}
|
[
"protected",
"function",
"save",
"(",
"$",
"bucket",
")",
"{",
"return",
"$",
"this",
"->",
"storage",
"->",
"set",
"(",
"$",
"this",
"->",
"key",
",",
"json_encode",
"(",
"$",
"bucket",
"->",
"getData",
"(",
")",
")",
")",
";",
"}"
] |
Save our bucket to storage
@param object $bucket
@return boolean
|
[
"Save",
"our",
"bucket",
"to",
"storage"
] |
c74720acfd80f3a6a258b591faae6f27b786cde4
|
https://github.com/robwittman/leaky-bucket-rate-limiter/blob/c74720acfd80f3a6a258b591faae6f27b786cde4/src/RateLimiter.php#L142-L144
|
224,196
|
unreal4u/mqtt
|
src/Client.php
|
Client.checkAndReturnAnswer
|
private function checkAndReturnAnswer(WritableContentInterface $object): string
{
$returnValue = '';
if ($object->shouldExpectAnswer() === true) {
$this->enableSynchronousTransfer(true);
$returnValue = $this->readBrokerHeader();
$this->enableSynchronousTransfer(false);
}
return $returnValue;
}
|
php
|
private function checkAndReturnAnswer(WritableContentInterface $object): string
{
$returnValue = '';
if ($object->shouldExpectAnswer() === true) {
$this->enableSynchronousTransfer(true);
$returnValue = $this->readBrokerHeader();
$this->enableSynchronousTransfer(false);
}
return $returnValue;
}
|
[
"private",
"function",
"checkAndReturnAnswer",
"(",
"WritableContentInterface",
"$",
"object",
")",
":",
"string",
"{",
"$",
"returnValue",
"=",
"''",
";",
"if",
"(",
"$",
"object",
"->",
"shouldExpectAnswer",
"(",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"enableSynchronousTransfer",
"(",
"true",
")",
";",
"$",
"returnValue",
"=",
"$",
"this",
"->",
"readBrokerHeader",
"(",
")",
";",
"$",
"this",
"->",
"enableSynchronousTransfer",
"(",
"false",
")",
";",
"}",
"return",
"$",
"returnValue",
";",
"}"
] |
Checks on the writable object whether we should wait for an answer and either wait or return an empty string
@param WritableContentInterface $object
@return string
|
[
"Checks",
"on",
"the",
"writable",
"object",
"whether",
"we",
"should",
"wait",
"for",
"an",
"answer",
"and",
"either",
"wait",
"or",
"return",
"an",
"empty",
"string"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Client.php#L140-L150
|
224,197
|
unreal4u/mqtt
|
src/Client.php
|
Client.checkForConnectionErrors
|
private function checkForConnectionErrors(int $errorCode, string $errorDescription): self
{
if ($errorCode !== 0 || $this->socket === null) {
$this->logger->critical('Could not connect to broker', [
'errorCode' => $errorCode,
'errorDescription' => $errorDescription,
]);
throw new NotConnected('Could not connect to broker: ' . $errorDescription, $errorCode);
}
return $this;
}
|
php
|
private function checkForConnectionErrors(int $errorCode, string $errorDescription): self
{
if ($errorCode !== 0 || $this->socket === null) {
$this->logger->critical('Could not connect to broker', [
'errorCode' => $errorCode,
'errorDescription' => $errorDescription,
]);
throw new NotConnected('Could not connect to broker: ' . $errorDescription, $errorCode);
}
return $this;
}
|
[
"private",
"function",
"checkForConnectionErrors",
"(",
"int",
"$",
"errorCode",
",",
"string",
"$",
"errorDescription",
")",
":",
"self",
"{",
"if",
"(",
"$",
"errorCode",
"!==",
"0",
"||",
"$",
"this",
"->",
"socket",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"critical",
"(",
"'Could not connect to broker'",
",",
"[",
"'errorCode'",
"=>",
"$",
"errorCode",
",",
"'errorDescription'",
"=>",
"$",
"errorDescription",
",",
"]",
")",
";",
"throw",
"new",
"NotConnected",
"(",
"'Could not connect to broker: '",
".",
"$",
"errorDescription",
",",
"$",
"errorCode",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Checks for socket error connections, will throw an exception if any is found
@param int $errorCode
@param string $errorDescription
@return Client
@throws \unreal4u\MQTT\Exceptions\NotConnected
|
[
"Checks",
"for",
"socket",
"error",
"connections",
"will",
"throw",
"an",
"exception",
"if",
"any",
"is",
"found"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Client.php#L160-L172
|
224,198
|
unreal4u/mqtt
|
src/Client.php
|
Client.setSocketTimeout
|
private function setSocketTimeout(): self
{
$timeCalculation = $this->connectionParameters->getKeepAlivePeriod() * 1.5;
$seconds = (int)floor($timeCalculation);
stream_set_timeout($this->socket, $seconds, (int)($timeCalculation - $seconds) * 1000);
return $this;
}
|
php
|
private function setSocketTimeout(): self
{
$timeCalculation = $this->connectionParameters->getKeepAlivePeriod() * 1.5;
$seconds = (int)floor($timeCalculation);
stream_set_timeout($this->socket, $seconds, (int)($timeCalculation - $seconds) * 1000);
return $this;
}
|
[
"private",
"function",
"setSocketTimeout",
"(",
")",
":",
"self",
"{",
"$",
"timeCalculation",
"=",
"$",
"this",
"->",
"connectionParameters",
"->",
"getKeepAlivePeriod",
"(",
")",
"*",
"1.5",
";",
"$",
"seconds",
"=",
"(",
"int",
")",
"floor",
"(",
"$",
"timeCalculation",
")",
";",
"stream_set_timeout",
"(",
"$",
"this",
"->",
"socket",
",",
"$",
"seconds",
",",
"(",
"int",
")",
"(",
"$",
"timeCalculation",
"-",
"$",
"seconds",
")",
"*",
"1000",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Calculates and sets the timeout on the socket connection according to the MQTT standard
1.5 times the keep alive period is the maximum amount of time the connection may remain idle before the
broker decides to close it.
Odd numbers will also produce a 0.5 second extra time, take this into account as well
@return Client
|
[
"Calculates",
"and",
"sets",
"the",
"timeout",
"on",
"the",
"socket",
"connection",
"according",
"to",
"the",
"MQTT",
"standard"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Client.php#L211-L218
|
224,199
|
unreal4u/mqtt
|
src/Client.php
|
Client.preSocketCommunication
|
private function preSocketCommunication(WritableContentInterface $object): self
{
$this->objectStack[$object::getControlPacketValue()] = $object;
if ($object instanceof Connect) {
$this->generateSocketConnection($object);
}
return $this;
}
|
php
|
private function preSocketCommunication(WritableContentInterface $object): self
{
$this->objectStack[$object::getControlPacketValue()] = $object;
if ($object instanceof Connect) {
$this->generateSocketConnection($object);
}
return $this;
}
|
[
"private",
"function",
"preSocketCommunication",
"(",
"WritableContentInterface",
"$",
"object",
")",
":",
"self",
"{",
"$",
"this",
"->",
"objectStack",
"[",
"$",
"object",
"::",
"getControlPacketValue",
"(",
")",
"]",
"=",
"$",
"object",
";",
"if",
"(",
"$",
"object",
"instanceof",
"Connect",
")",
"{",
"$",
"this",
"->",
"generateSocketConnection",
"(",
"$",
"object",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Stuff that has to happen before we actually begin sending data through our socket
@param WritableContentInterface $object
@return Client
@throws \unreal4u\MQTT\Exceptions\NotConnected
@throws \unreal4u\MQTT\Exceptions\Connect\NoConnectionParametersDefined
|
[
"Stuff",
"that",
"has",
"to",
"happen",
"before",
"we",
"actually",
"begin",
"sending",
"data",
"through",
"our",
"socket"
] |
84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4
|
https://github.com/unreal4u/mqtt/blob/84f4c49b9e36c42b7e0ec8da0432c91ecb6530b4/src/Client.php#L239-L248
|
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.