repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1
value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
hostnet/accessor-generator-plugin-lib | src/AnnotationProcessor/PropertyInformation.php | PropertyInformation.processAnnotations | public function processAnnotations(): void
{
$class = $this->property->getClass();
$imports = $class ? array_change_key_case($class->getUseStatements()) : [];
$filename = $class ? $class->getFilename() : 'memory';
// Get all the namespaces in which annotations reside.
$namespaces = [];
foreach ($this->annotation_processors as $processor) {
$namespaces[] = $processor->getProcessableAnnotationNamespace();
}
// Filter all imports that could lead to non loaded annotations,
// this would let the DocParser explode with an Exception, while
// the goal is to ignore other annotations besides the one explicitly
// loaded.
$without_foreign_annotations = array_filter(
$imports,
function ($import) use ($namespaces) {
foreach ($namespaces as $namespace) {
if (stripos($namespace, $import) === 0) {
return true;
}
}
return false;
}
);
$this->parser->setImports($without_foreign_annotations);
$this->parser->setIgnoreNotImportedAnnotations(true);
$annotations = $this->parser->parse($this->property->getDocComment(), $filename);
// If the property is encrypted, column type MUST be string.
$is_encrypted = false;
$is_string = true;
foreach ($this->annotation_processors as $processor) {
foreach ($annotations as $annotation) {
$processor->processAnnotation($annotation, $this);
if ($annotation instanceof Generate && isset($annotation->encryption_alias)) {
$is_encrypted = true;
}
if (!($annotation instanceof Column)
|| !isset($annotation->type)
|| \in_array($annotation->type, ['string', 'text'])
) {
continue;
}
$is_string = false;
}
}
if ($is_encrypted && !$is_string) {
throw new \RuntimeException(sprintf(
'Property %s in class %s\%s has an encryption_alias set, but is not declared as column type \'string\'',
$this->getName(),
$this->getNamespace(),
$this->getClass()
));
}
} | php | public function processAnnotations(): void
{
$class = $this->property->getClass();
$imports = $class ? array_change_key_case($class->getUseStatements()) : [];
$filename = $class ? $class->getFilename() : 'memory';
// Get all the namespaces in which annotations reside.
$namespaces = [];
foreach ($this->annotation_processors as $processor) {
$namespaces[] = $processor->getProcessableAnnotationNamespace();
}
// Filter all imports that could lead to non loaded annotations,
// this would let the DocParser explode with an Exception, while
// the goal is to ignore other annotations besides the one explicitly
// loaded.
$without_foreign_annotations = array_filter(
$imports,
function ($import) use ($namespaces) {
foreach ($namespaces as $namespace) {
if (stripos($namespace, $import) === 0) {
return true;
}
}
return false;
}
);
$this->parser->setImports($without_foreign_annotations);
$this->parser->setIgnoreNotImportedAnnotations(true);
$annotations = $this->parser->parse($this->property->getDocComment(), $filename);
// If the property is encrypted, column type MUST be string.
$is_encrypted = false;
$is_string = true;
foreach ($this->annotation_processors as $processor) {
foreach ($annotations as $annotation) {
$processor->processAnnotation($annotation, $this);
if ($annotation instanceof Generate && isset($annotation->encryption_alias)) {
$is_encrypted = true;
}
if (!($annotation instanceof Column)
|| !isset($annotation->type)
|| \in_array($annotation->type, ['string', 'text'])
) {
continue;
}
$is_string = false;
}
}
if ($is_encrypted && !$is_string) {
throw new \RuntimeException(sprintf(
'Property %s in class %s\%s has an encryption_alias set, but is not declared as column type \'string\'',
$this->getName(),
$this->getNamespace(),
$this->getClass()
));
}
} | [
"public",
"function",
"processAnnotations",
"(",
")",
":",
"void",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"property",
"->",
"getClass",
"(",
")",
";",
"$",
"imports",
"=",
"$",
"class",
"?",
"array_change_key_case",
"(",
"$",
"class",
"->",
"getUseSt... | Start the processing of processAnnotations
@return void
@throws \OutOfBoundsException
@throws \Hostnet\Component\AccessorGenerator\Reflection\Exception\ClassDefinitionNotFoundException
@throws \RuntimeException | [
"Start",
"the",
"processing",
"of",
"processAnnotations"
] | 0ff78bed5dddb4bec9fd64500f822a28ce987f62 | https://github.com/hostnet/accessor-generator-plugin-lib/blob/0ff78bed5dddb4bec9fd64500f822a28ce987f62/src/AnnotationProcessor/PropertyInformation.php#L238-L302 | train |
hostnet/accessor-generator-plugin-lib | src/AnnotationProcessor/PropertyInformation.php | PropertyInformation.validateType | private function validateType(string $type): string
{
if ('' === $type) {
throw new \DomainException(sprintf('A type name may not be empty'));
}
if ((int) $type) {
throw new \DomainException(sprintf('A type name may not start with a number. Found %s', $type));
}
if (\in_array($type, static::getValidTypes(), true)) {
// Scalar.
return $type;
}
if ('\\' === $type[0] || ctype_upper($type[0])) {
// Class.
return $type;
}
throw new \DomainException(sprintf('The type %s is not supported for code generation', $type));
} | php | private function validateType(string $type): string
{
if ('' === $type) {
throw new \DomainException(sprintf('A type name may not be empty'));
}
if ((int) $type) {
throw new \DomainException(sprintf('A type name may not start with a number. Found %s', $type));
}
if (\in_array($type, static::getValidTypes(), true)) {
// Scalar.
return $type;
}
if ('\\' === $type[0] || ctype_upper($type[0])) {
// Class.
return $type;
}
throw new \DomainException(sprintf('The type %s is not supported for code generation', $type));
} | [
"private",
"function",
"validateType",
"(",
"string",
"$",
"type",
")",
":",
"string",
"{",
"if",
"(",
"''",
"===",
"$",
"type",
")",
"{",
"throw",
"new",
"\\",
"DomainException",
"(",
"sprintf",
"(",
"'A type name may not be empty'",
")",
")",
";",
"}",
... | Throw exceptions for invalid types or return the valid type.
@see http://php.net/manual/en/language.types.php
@param string $type
@throws \DomainException
@throws \InvalidArgumentException
@return string | [
"Throw",
"exceptions",
"for",
"invalid",
"types",
"or",
"return",
"the",
"valid",
"type",
"."
] | 0ff78bed5dddb4bec9fd64500f822a28ce987f62 | https://github.com/hostnet/accessor-generator-plugin-lib/blob/0ff78bed5dddb4bec9fd64500f822a28ce987f62/src/AnnotationProcessor/PropertyInformation.php#L404-L425 | train |
hostnet/accessor-generator-plugin-lib | src/AnnotationProcessor/PropertyInformation.php | PropertyInformation.setType | public function setType(?string $type): self
{
$this->type = $this->validateType($type);
$this->type_hint || $this->type_hint = $this->type;
return $this;
} | php | public function setType(?string $type): self
{
$this->type = $this->validateType($type);
$this->type_hint || $this->type_hint = $this->type;
return $this;
} | [
"public",
"function",
"setType",
"(",
"?",
"string",
"$",
"type",
")",
":",
"self",
"{",
"$",
"this",
"->",
"type",
"=",
"$",
"this",
"->",
"validateType",
"(",
"$",
"type",
")",
";",
"$",
"this",
"->",
"type_hint",
"||",
"$",
"this",
"->",
"type_h... | Set the type for this property.
The type must be one of the set returned
by getValidTypes.
@see http://php.net/manual/en/language.types.php
@param string|null $type
@throws \DomainException
@throws \InvalidArgumentException
@return PropertyInformation | [
"Set",
"the",
"type",
"for",
"this",
"property",
".",
"The",
"type",
"must",
"be",
"one",
"of",
"the",
"set",
"returned",
"by",
"getValidTypes",
"."
] | 0ff78bed5dddb4bec9fd64500f822a28ce987f62 | https://github.com/hostnet/accessor-generator-plugin-lib/blob/0ff78bed5dddb4bec9fd64500f822a28ce987f62/src/AnnotationProcessor/PropertyInformation.php#L440-L446 | train |
hostnet/accessor-generator-plugin-lib | src/AnnotationProcessor/PropertyInformation.php | PropertyInformation.setTypeHint | public function setTypeHint(string $type_hint): self
{
$this->type_hint = $this->validateType($type_hint);
return $this;
} | php | public function setTypeHint(string $type_hint): self
{
$this->type_hint = $this->validateType($type_hint);
return $this;
} | [
"public",
"function",
"setTypeHint",
"(",
"string",
"$",
"type_hint",
")",
":",
"self",
"{",
"$",
"this",
"->",
"type_hint",
"=",
"$",
"this",
"->",
"validateType",
"(",
"$",
"type_hint",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Manually set the type hint for this property
The type hint must be a valid class name starting
with \ or a capital letter or one of the set returned
by getValidTypes.
Only use this method if you are not pleased
by the automatic type hint that was already
set by the setType method.
@see http://php.net/manual/en/language.types.php
@param string $type_hint
@throws \DomainException
@throws \InvalidArgumentException
@return PropertyInformation | [
"Manually",
"set",
"the",
"type",
"hint",
"for",
"this",
"property",
"The",
"type",
"hint",
"must",
"be",
"a",
"valid",
"class",
"name",
"starting",
"with",
"\\",
"or",
"a",
"capital",
"letter",
"or",
"one",
"of",
"the",
"set",
"returned",
"by",
"getVali... | 0ff78bed5dddb4bec9fd64500f822a28ce987f62 | https://github.com/hostnet/accessor-generator-plugin-lib/blob/0ff78bed5dddb4bec9fd64500f822a28ce987f62/src/AnnotationProcessor/PropertyInformation.php#L466-L471 | train |
hostnet/accessor-generator-plugin-lib | src/AnnotationProcessor/PropertyInformation.php | PropertyInformation.setFullyQualifiedType | public function setFullyQualifiedType(string $type): self
{
if ('' === $type) {
$this->fully_qualified_type = '';
return $this;
}
if ($type[0] === '\\') {
$this->fully_qualified_type = $type;
return $this;
}
throw new \DomainException(sprintf('The type %s is not a valid fully qualified class name', $type));
} | php | public function setFullyQualifiedType(string $type): self
{
if ('' === $type) {
$this->fully_qualified_type = '';
return $this;
}
if ($type[0] === '\\') {
$this->fully_qualified_type = $type;
return $this;
}
throw new \DomainException(sprintf('The type %s is not a valid fully qualified class name', $type));
} | [
"public",
"function",
"setFullyQualifiedType",
"(",
"string",
"$",
"type",
")",
":",
"self",
"{",
"if",
"(",
"''",
"===",
"$",
"type",
")",
"{",
"$",
"this",
"->",
"fully_qualified_type",
"=",
"''",
";",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"$... | Set the fully qualified type for this property.
The type must be a valid class name starting from
the root namespace, so it should start with a \
@param string $type
@throws \DomainException
@return PropertyInformation | [
"Set",
"the",
"fully",
"qualified",
"type",
"for",
"this",
"property",
".",
"The",
"type",
"must",
"be",
"a",
"valid",
"class",
"name",
"starting",
"from",
"the",
"root",
"namespace",
"so",
"it",
"should",
"start",
"with",
"a",
"\\"
] | 0ff78bed5dddb4bec9fd64500f822a28ce987f62 | https://github.com/hostnet/accessor-generator-plugin-lib/blob/0ff78bed5dddb4bec9fd64500f822a28ce987f62/src/AnnotationProcessor/PropertyInformation.php#L483-L498 | train |
hostnet/accessor-generator-plugin-lib | src/AnnotationProcessor/PropertyInformation.php | PropertyInformation.setEncryptionAlias | public function setEncryptionAlias(string $encryption_alias): self
{
if (empty($encryption_alias)) {
throw new \InvalidArgumentException(sprintf('encryption_alias must not be empty %s', $encryption_alias));
}
$this->encryption_alias = $encryption_alias;
return $this;
} | php | public function setEncryptionAlias(string $encryption_alias): self
{
if (empty($encryption_alias)) {
throw new \InvalidArgumentException(sprintf('encryption_alias must not be empty %s', $encryption_alias));
}
$this->encryption_alias = $encryption_alias;
return $this;
} | [
"public",
"function",
"setEncryptionAlias",
"(",
"string",
"$",
"encryption_alias",
")",
":",
"self",
"{",
"if",
"(",
"empty",
"(",
"$",
"encryption_alias",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'encryption_alias ... | Set the encryption alias for this property, used to encrypt the value before storing.
The alias must be added to the composer.json of the app, with the proper keys defined (depending
on if the app will encrypt, decrypt or do both).
"extra": {
"accessor-generator": {
$encryption_alias: {
public-key:
private-key:
...
@param string $encryption_alias
@throws \InvalidArgumentException
@return PropertyInformation | [
"Set",
"the",
"encryption",
"alias",
"for",
"this",
"property",
"used",
"to",
"encrypt",
"the",
"value",
"before",
"storing",
"."
] | 0ff78bed5dddb4bec9fd64500f822a28ce987f62 | https://github.com/hostnet/accessor-generator-plugin-lib/blob/0ff78bed5dddb4bec9fd64500f822a28ce987f62/src/AnnotationProcessor/PropertyInformation.php#L528-L537 | train |
hostnet/accessor-generator-plugin-lib | src/AnnotationProcessor/PropertyInformation.php | PropertyInformation.setIntegerSize | public function setIntegerSize(int $integer_size): self
{
// Check Range.
$max_int_size = PHP_INT_SIZE << 3;
if ($integer_size <= 0 || $integer_size > $max_int_size) {
throw new \RangeException(
sprintf('Integer size %d, does not fit in domain (0, %d]', $integer_size, $max_int_size)
);
}
// Assign.
$this->integer_size = $integer_size;
return $this;
} | php | public function setIntegerSize(int $integer_size): self
{
// Check Range.
$max_int_size = PHP_INT_SIZE << 3;
if ($integer_size <= 0 || $integer_size > $max_int_size) {
throw new \RangeException(
sprintf('Integer size %d, does not fit in domain (0, %d]', $integer_size, $max_int_size)
);
}
// Assign.
$this->integer_size = $integer_size;
return $this;
} | [
"public",
"function",
"setIntegerSize",
"(",
"int",
"$",
"integer_size",
")",
":",
"self",
"{",
"// Check Range.",
"$",
"max_int_size",
"=",
"PHP_INT_SIZE",
"<<",
"3",
";",
"if",
"(",
"$",
"integer_size",
"<=",
"0",
"||",
"$",
"integer_size",
">",
"$",
"ma... | Set the size of the integer that will be stored, in bits.
@throws \InvalidArgumentException
@throws \RangeException
@param int $integer_size
@return PropertyInformation | [
"Set",
"the",
"size",
"of",
"the",
"integer",
"that",
"will",
"be",
"stored",
"in",
"bits",
"."
] | 0ff78bed5dddb4bec9fd64500f822a28ce987f62 | https://github.com/hostnet/accessor-generator-plugin-lib/blob/0ff78bed5dddb4bec9fd64500f822a28ce987f62/src/AnnotationProcessor/PropertyInformation.php#L592-L606 | train |
hostnet/accessor-generator-plugin-lib | src/AnnotationProcessor/PropertyInformation.php | PropertyInformation.setPrecision | public function setPrecision(int $precision): self
{
// Check range.
if ($precision < 0 || $precision > 65) {
throw new \RangeException(sprintf('Precision %d, should be in interval [1,65]', $precision));
}
$this->precision = $precision;
return $this;
} | php | public function setPrecision(int $precision): self
{
// Check range.
if ($precision < 0 || $precision > 65) {
throw new \RangeException(sprintf('Precision %d, should be in interval [1,65]', $precision));
}
$this->precision = $precision;
return $this;
} | [
"public",
"function",
"setPrecision",
"(",
"int",
"$",
"precision",
")",
":",
"self",
"{",
"// Check range.",
"if",
"(",
"$",
"precision",
"<",
"0",
"||",
"$",
"precision",
">",
"65",
")",
"{",
"throw",
"new",
"\\",
"RangeException",
"(",
"sprintf",
"(",... | Set the number of significant digits for a decimal number.
This is only applicable to fixed point storage. The type will be a
string in that case because PHP has no fixed point numbers.
@see http://dev.mysql.com/doc/refman/5.7/en/precision-math-decimal-characteristics.html
@throws \RangeException It has a range of 1 to 65.
@param int $precision
@return PropertyInformation | [
"Set",
"the",
"number",
"of",
"significant",
"digits",
"for",
"a",
"decimal",
"number",
"."
] | 0ff78bed5dddb4bec9fd64500f822a28ce987f62 | https://github.com/hostnet/accessor-generator-plugin-lib/blob/0ff78bed5dddb4bec9fd64500f822a28ce987f62/src/AnnotationProcessor/PropertyInformation.php#L767-L777 | train |
hostnet/accessor-generator-plugin-lib | src/AnnotationProcessor/PropertyInformation.php | PropertyInformation.setScale | public function setScale(int $scale): self
{
// Check range.
if ($scale < 0 || $scale > 30) {
throw new \RangeException(sprintf('Scale "%d", should be in interval [0,30]', $scale));
}
$this->scale = $scale;
return $this;
} | php | public function setScale(int $scale): self
{
// Check range.
if ($scale < 0 || $scale > 30) {
throw new \RangeException(sprintf('Scale "%d", should be in interval [0,30]', $scale));
}
$this->scale = $scale;
return $this;
} | [
"public",
"function",
"setScale",
"(",
"int",
"$",
"scale",
")",
":",
"self",
"{",
"// Check range.",
"if",
"(",
"$",
"scale",
"<",
"0",
"||",
"$",
"scale",
">",
"30",
")",
"{",
"throw",
"new",
"\\",
"RangeException",
"(",
"sprintf",
"(",
"'Scale \"%d\... | Set the number of significant digits after the decimal point.
This is only applicable to fixed point storage. The type will be a float
in that case because PHP has no fixed point numbers.
@see http://dev.mysql.com/doc/refman/5.7/en/precision-math-decimal-characteristics.html
@throws \RangeException
@param int $scale
@return PropertyInformation | [
"Set",
"the",
"number",
"of",
"significant",
"digits",
"after",
"the",
"decimal",
"point",
".",
"This",
"is",
"only",
"applicable",
"to",
"fixed",
"point",
"storage",
".",
"The",
"type",
"will",
"be",
"a",
"float",
"in",
"that",
"case",
"because",
"PHP",
... | 0ff78bed5dddb4bec9fd64500f822a28ce987f62 | https://github.com/hostnet/accessor-generator-plugin-lib/blob/0ff78bed5dddb4bec9fd64500f822a28ce987f62/src/AnnotationProcessor/PropertyInformation.php#L802-L812 | train |
OXID-eSales/paymorrow-module | models/oxpspaymorrowoxpaymentgateway.php | OxpsPaymorrowOxPaymentGateway._savePaymorrowUserPaymentData | protected function _savePaymorrowUserPaymentData( oxOrder $oOrder, $oPmResponseHandler )
{
$aPmResponse = $oPmResponseHandler->getResponse();
$oUserPaymentId = $oOrder->oxorder__oxpaymentid->value;
/** @var OxpsPaymorrowOxUserPayment|oxUserPayment $oUserPayment */
$oUserPayment = oxNew( 'oxuserpayment' );
$oUserPayment->load( $oUserPaymentId );
$sPmBankName = $aPmResponse[self::PAYMORROW_RESPONSE_BANK_NAME];
$sPmIbanCode = $aPmResponse[self::PAYMORROW_RESPONSE_SDD_IBAN];
$sPmBicCode = $aPmResponse[self::PAYMORROW_RESPONSE_SDD_BIC];
$sPmOrderId = $aPmResponse[self::PAYMORROW_RESPONSE_ORDER_ID];
$oUserPayment->setPaymorrowBankName( $sPmBankName );
$oUserPayment->setPaymorrowIBAN( $sPmIbanCode );
$oUserPayment->setPaymorrowBIC( $sPmBicCode );
$oUserPayment->setPaymorrowOrderId( $sPmOrderId );
return $oUserPayment->save();
} | php | protected function _savePaymorrowUserPaymentData( oxOrder $oOrder, $oPmResponseHandler )
{
$aPmResponse = $oPmResponseHandler->getResponse();
$oUserPaymentId = $oOrder->oxorder__oxpaymentid->value;
/** @var OxpsPaymorrowOxUserPayment|oxUserPayment $oUserPayment */
$oUserPayment = oxNew( 'oxuserpayment' );
$oUserPayment->load( $oUserPaymentId );
$sPmBankName = $aPmResponse[self::PAYMORROW_RESPONSE_BANK_NAME];
$sPmIbanCode = $aPmResponse[self::PAYMORROW_RESPONSE_SDD_IBAN];
$sPmBicCode = $aPmResponse[self::PAYMORROW_RESPONSE_SDD_BIC];
$sPmOrderId = $aPmResponse[self::PAYMORROW_RESPONSE_ORDER_ID];
$oUserPayment->setPaymorrowBankName( $sPmBankName );
$oUserPayment->setPaymorrowIBAN( $sPmIbanCode );
$oUserPayment->setPaymorrowBIC( $sPmBicCode );
$oUserPayment->setPaymorrowOrderId( $sPmOrderId );
return $oUserPayment->save();
} | [
"protected",
"function",
"_savePaymorrowUserPaymentData",
"(",
"oxOrder",
"$",
"oOrder",
",",
"$",
"oPmResponseHandler",
")",
"{",
"$",
"aPmResponse",
"=",
"$",
"oPmResponseHandler",
"->",
"getResponse",
"(",
")",
";",
"$",
"oUserPaymentId",
"=",
"$",
"oOrder",
... | Saves Paymorrow User Payment data to oxUserPayments table
@param oxOrder $oOrder
@param OxpsPaymorrowResponseHandler $oPmResponseHandler
@return bool|string | [
"Saves",
"Paymorrow",
"User",
"Payment",
"data",
"to",
"oxUserPayments",
"table"
] | adb5d7f50c2fa5b566abd262161c483c42847b42 | https://github.com/OXID-eSales/paymorrow-module/blob/adb5d7f50c2fa5b566abd262161c483c42847b42/models/oxpspaymorrowoxpaymentgateway.php#L104-L125 | train |
OXID-eSales/paymorrow-module | models/oxpspaymorrowoxpaymentgateway.php | OxpsPaymorrowOxPaymentGateway._handleOrderResponseErrors | protected function _handleOrderResponseErrors( $oPmResponseHandler )
{
$aInitDataForPaymentStep = array();
// If order was declined, collect declination fields and unset error code ("unexpected" error)
if ( $oPmResponseHandler->wasDeclined() ) {
$aInitDataForPaymentStep = (array) $oPmResponseHandler->getDeclinationDataFromResponse();
}
$aErrorsData = (array) $oPmResponseHandler->getErrorDataFromResponse();
// If there are errors add those to the data array
if ( !empty( $aErrorsData ) ) {
$aInitDataForPaymentStep = array_merge( $aInitDataForPaymentStep, $aErrorsData );
}
// If order declination data or errors were present, save the data to session
if ( !empty( $aInitDataForPaymentStep ) ) {
$oPmResponseHandler->setErrorCode( null );
$this->_setSessionInitData( $aInitDataForPaymentStep );
}
} | php | protected function _handleOrderResponseErrors( $oPmResponseHandler )
{
$aInitDataForPaymentStep = array();
// If order was declined, collect declination fields and unset error code ("unexpected" error)
if ( $oPmResponseHandler->wasDeclined() ) {
$aInitDataForPaymentStep = (array) $oPmResponseHandler->getDeclinationDataFromResponse();
}
$aErrorsData = (array) $oPmResponseHandler->getErrorDataFromResponse();
// If there are errors add those to the data array
if ( !empty( $aErrorsData ) ) {
$aInitDataForPaymentStep = array_merge( $aInitDataForPaymentStep, $aErrorsData );
}
// If order declination data or errors were present, save the data to session
if ( !empty( $aInitDataForPaymentStep ) ) {
$oPmResponseHandler->setErrorCode( null );
$this->_setSessionInitData( $aInitDataForPaymentStep );
}
} | [
"protected",
"function",
"_handleOrderResponseErrors",
"(",
"$",
"oPmResponseHandler",
")",
"{",
"$",
"aInitDataForPaymentStep",
"=",
"array",
"(",
")",
";",
"// If order was declined, collect declination fields and unset error code (\"unexpected\" error)",
"if",
"(",
"$",
"oPm... | Check order response for declination status and fields and error fields.
Set all relevant fields to session.
The session data is used to go with redirection to payment step and used to initialize payment forms.
@param OxpsPaymorrowResponseHandler $oPmResponseHandler | [
"Check",
"order",
"response",
"for",
"declination",
"status",
"and",
"fields",
"and",
"error",
"fields",
".",
"Set",
"all",
"relevant",
"fields",
"to",
"session",
".",
"The",
"session",
"data",
"is",
"used",
"to",
"go",
"with",
"redirection",
"to",
"payment"... | adb5d7f50c2fa5b566abd262161c483c42847b42 | https://github.com/OXID-eSales/paymorrow-module/blob/adb5d7f50c2fa5b566abd262161c483c42847b42/models/oxpspaymorrowoxpaymentgateway.php#L134-L155 | train |
techdivision/import-product | src/Observers/ProductWebsiteUpdateObserver.php | ProductWebsiteUpdateObserver.initializeProductWebsite | protected function initializeProductWebsite(array $attr)
{
// try to load the product website relation with the passed product/website ID
if ($this->loadProductWebsite($attr[MemberNames::PRODUCT_ID], $attr[MemberNames::WEBSITE_ID])) {
// throw a runtime exception, if the relation already exists
throw new \RuntimeException(
sprintf(
'Product website relation %d => %d already exsits',
$attr[MemberNames::PRODUCT_ID],
$attr[MemberNames::WEBSITE_ID]
)
);
}
// otherwise simply return the attributes
return $attr;
} | php | protected function initializeProductWebsite(array $attr)
{
// try to load the product website relation with the passed product/website ID
if ($this->loadProductWebsite($attr[MemberNames::PRODUCT_ID], $attr[MemberNames::WEBSITE_ID])) {
// throw a runtime exception, if the relation already exists
throw new \RuntimeException(
sprintf(
'Product website relation %d => %d already exsits',
$attr[MemberNames::PRODUCT_ID],
$attr[MemberNames::WEBSITE_ID]
)
);
}
// otherwise simply return the attributes
return $attr;
} | [
"protected",
"function",
"initializeProductWebsite",
"(",
"array",
"$",
"attr",
")",
"{",
"// try to load the product website relation with the passed product/website ID",
"if",
"(",
"$",
"this",
"->",
"loadProductWebsite",
"(",
"$",
"attr",
"[",
"MemberNames",
"::",
"PRO... | Initialize the product website with the passed attributes and returns an instance.
@param array $attr The product website attributes
@return array The initialized product website
@throws \RuntimeException Is thrown, if the attributes can not be initialized | [
"Initialize",
"the",
"product",
"website",
"with",
"the",
"passed",
"attributes",
"and",
"returns",
"an",
"instance",
"."
] | a596e0c4b0495c918139935a709815c739d61e95 | https://github.com/techdivision/import-product/blob/a596e0c4b0495c918139935a709815c739d61e95/src/Observers/ProductWebsiteUpdateObserver.php#L45-L62 | train |
contributte/thepay-api | src/DataApi/DataApiObject.php | DataApiObject.sortDataProperties | private static function sortDataProperties(array $dataProperties): array
{
$inherited = [];
$own = [];
$calledClassName = static::class;
foreach ($dataProperties as $property) {
$propertyClass = $property->getDeclaringClass();
$propertyClassName = $propertyClass->getName();
if ($propertyClassName === $calledClassName) {
$own[] = $property;
} else {
$inherited[] = $property;
}
}
return array_merge($inherited, $own);
} | php | private static function sortDataProperties(array $dataProperties): array
{
$inherited = [];
$own = [];
$calledClassName = static::class;
foreach ($dataProperties as $property) {
$propertyClass = $property->getDeclaringClass();
$propertyClassName = $propertyClass->getName();
if ($propertyClassName === $calledClassName) {
$own[] = $property;
} else {
$inherited[] = $property;
}
}
return array_merge($inherited, $own);
} | [
"private",
"static",
"function",
"sortDataProperties",
"(",
"array",
"$",
"dataProperties",
")",
":",
"array",
"{",
"$",
"inherited",
"=",
"[",
"]",
";",
"$",
"own",
"=",
"[",
"]",
";",
"$",
"calledClassName",
"=",
"static",
"::",
"class",
";",
"foreach"... | Prepend inherited properties.
@param ReflectionProperty[] $dataProperties
@return ReflectionProperty[] | [
"Prepend",
"inherited",
"properties",
"."
] | 7e28eaf30ad1880533add93cf9e7296e61c09b8e | https://github.com/contributte/thepay-api/blob/7e28eaf30ad1880533add93cf9e7296e61c09b8e/src/DataApi/DataApiObject.php#L76-L95 | train |
hostnet/accessor-generator-plugin-lib | src/Reflection/ReflectionClass.php | ReflectionClass.getName | public function getName(): string
{
// Check cache.
if (null === $this->name) {
$tokens = $this->getTokenStream();
// Find class token
try {
$loc = $tokens->scan(0, [T_CLASS, T_TRAIT]);
} catch (\OutOfBoundsException $e) {
throw new ClassDefinitionNotFoundException('No class is found inside ' . $this->filename . '.', 0, $e);
}
// Get the following token
if ($loc !== null) {
$loc = $tokens->next($loc);
}
// Make sure it is not :: but a name
if ($loc !== null && $tokens->type($loc) === T_STRING) {
// Read the name from the token
$this->name = $tokens->value($loc);
$this->class_location = $loc;
} else {
// Mark the name as NOT found (in contrast to not initialized)
$this->name = false;
}
}
// Return the name if a class was found or throw an exception.
if ($this->name) {
return $this->name;
}
throw new ClassDefinitionNotFoundException('No class is found inside ' . $this->filename . '.');
} | php | public function getName(): string
{
// Check cache.
if (null === $this->name) {
$tokens = $this->getTokenStream();
// Find class token
try {
$loc = $tokens->scan(0, [T_CLASS, T_TRAIT]);
} catch (\OutOfBoundsException $e) {
throw new ClassDefinitionNotFoundException('No class is found inside ' . $this->filename . '.', 0, $e);
}
// Get the following token
if ($loc !== null) {
$loc = $tokens->next($loc);
}
// Make sure it is not :: but a name
if ($loc !== null && $tokens->type($loc) === T_STRING) {
// Read the name from the token
$this->name = $tokens->value($loc);
$this->class_location = $loc;
} else {
// Mark the name as NOT found (in contrast to not initialized)
$this->name = false;
}
}
// Return the name if a class was found or throw an exception.
if ($this->name) {
return $this->name;
}
throw new ClassDefinitionNotFoundException('No class is found inside ' . $this->filename . '.');
} | [
"public",
"function",
"getName",
"(",
")",
":",
"string",
"{",
"// Check cache.",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"name",
")",
"{",
"$",
"tokens",
"=",
"$",
"this",
"->",
"getTokenStream",
"(",
")",
";",
"// Find class token",
"try",
"{",
... | Returns the name of the class, inside this file.
This is the simple class name and not the fully
qualified class name.
@throws Exception\ClassDefinitionNotFoundException
@throws \OutOfBoundsException
@return string | [
"Returns",
"the",
"name",
"of",
"the",
"class",
"inside",
"this",
"file",
"."
] | 0ff78bed5dddb4bec9fd64500f822a28ce987f62 | https://github.com/hostnet/accessor-generator-plugin-lib/blob/0ff78bed5dddb4bec9fd64500f822a28ce987f62/src/Reflection/ReflectionClass.php#L125-L159 | train |
hostnet/accessor-generator-plugin-lib | src/Reflection/ReflectionClass.php | ReflectionClass.getNamespace | public function getNamespace(): string
{
// Check cache.
if (null === $this->namespace) {
$tokens = $this->getTokenStream();
// Find namespace token
try {
$loc = $tokens->scan(0, [T_NAMESPACE]);
} catch (\OutOfBoundsException $e) {
return $this->namespace = '';
}
// Get the next token (start with namespace)
if ($loc !== null) {
$loc = $tokens->next($loc);
}
// If the start of the namespace is found,
// parse it, otherwise save empty namespace.
$this->namespace = '';
if ($loc !== null) {
$this->namespace = $this->parseNamespace($loc);
}
}
return $this->namespace;
} | php | public function getNamespace(): string
{
// Check cache.
if (null === $this->namespace) {
$tokens = $this->getTokenStream();
// Find namespace token
try {
$loc = $tokens->scan(0, [T_NAMESPACE]);
} catch (\OutOfBoundsException $e) {
return $this->namespace = '';
}
// Get the next token (start with namespace)
if ($loc !== null) {
$loc = $tokens->next($loc);
}
// If the start of the namespace is found,
// parse it, otherwise save empty namespace.
$this->namespace = '';
if ($loc !== null) {
$this->namespace = $this->parseNamespace($loc);
}
}
return $this->namespace;
} | [
"public",
"function",
"getNamespace",
"(",
")",
":",
"string",
"{",
"// Check cache.",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"namespace",
")",
"{",
"$",
"tokens",
"=",
"$",
"this",
"->",
"getTokenStream",
"(",
")",
";",
"// Find namespace token",
"t... | Returns the namespace of the class in this file or an empty string if no
namespace was declared.
@return string | [
"Returns",
"the",
"namespace",
"of",
"the",
"class",
"in",
"this",
"file",
"or",
"an",
"empty",
"string",
"if",
"no",
"namespace",
"was",
"declared",
"."
] | 0ff78bed5dddb4bec9fd64500f822a28ce987f62 | https://github.com/hostnet/accessor-generator-plugin-lib/blob/0ff78bed5dddb4bec9fd64500f822a28ce987f62/src/Reflection/ReflectionClass.php#L167-L193 | train |
hostnet/accessor-generator-plugin-lib | src/Reflection/ReflectionClass.php | ReflectionClass.getProperties | public function getProperties(): array
{
// Check cache
if (null === $this->properties) {
$tokens = $this->getTokenStream();
// Create empty set, to denote that
// we parsed all the properties
$this->properties = [];
// Start parsing from the class name location
// and trigger ClassDefinitionNotFoundException when called
// on a file not containing a class.
$vis_loc = $this->getClassNameLocation();
// Scan for public, protected and private because
// these keywords denote the start of a property.
// var is excluded because its use is deprecated.
while ($vis_loc = $tokens->scan($vis_loc, [T_PRIVATE, T_PROTECTED, T_PUBLIC, T_VAR])) {
// Seek forward, skipping static, if it was found and check if we
// really have a property here, otherwise confine and try to find more
// properties.
// We also skip final, to improve error handling and consistent behaviour,
// otherwise final private $foo would be parsed and private final $bar
// would not be parsed.
$var_loc = $tokens->next($vis_loc, [T_COMMENT, T_WHITESPACE, T_STATIC, T_FINAL]);
if ($tokens->type($var_loc) !== T_VARIABLE) {
continue;
}
$doc_comment = $this->parseDocComment($vis_loc); // doc comment
$modifiers = $this->parsePropertyModifiers($vis_loc); // public, protected, private, static
$name = substr($tokens->value($var_loc), 1); // property name
$default = $this->parseDefaultValue($var_loc); // default value
$property = new ReflectionProperty($name, $modifiers, $default, $doc_comment, $this);
$this->properties[] = $property;
}
}
return $this->properties;
} | php | public function getProperties(): array
{
// Check cache
if (null === $this->properties) {
$tokens = $this->getTokenStream();
// Create empty set, to denote that
// we parsed all the properties
$this->properties = [];
// Start parsing from the class name location
// and trigger ClassDefinitionNotFoundException when called
// on a file not containing a class.
$vis_loc = $this->getClassNameLocation();
// Scan for public, protected and private because
// these keywords denote the start of a property.
// var is excluded because its use is deprecated.
while ($vis_loc = $tokens->scan($vis_loc, [T_PRIVATE, T_PROTECTED, T_PUBLIC, T_VAR])) {
// Seek forward, skipping static, if it was found and check if we
// really have a property here, otherwise confine and try to find more
// properties.
// We also skip final, to improve error handling and consistent behaviour,
// otherwise final private $foo would be parsed and private final $bar
// would not be parsed.
$var_loc = $tokens->next($vis_loc, [T_COMMENT, T_WHITESPACE, T_STATIC, T_FINAL]);
if ($tokens->type($var_loc) !== T_VARIABLE) {
continue;
}
$doc_comment = $this->parseDocComment($vis_loc); // doc comment
$modifiers = $this->parsePropertyModifiers($vis_loc); // public, protected, private, static
$name = substr($tokens->value($var_loc), 1); // property name
$default = $this->parseDefaultValue($var_loc); // default value
$property = new ReflectionProperty($name, $modifiers, $default, $doc_comment, $this);
$this->properties[] = $property;
}
}
return $this->properties;
} | [
"public",
"function",
"getProperties",
"(",
")",
":",
"array",
"{",
"// Check cache",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"properties",
")",
"{",
"$",
"tokens",
"=",
"$",
"this",
"->",
"getTokenStream",
"(",
")",
";",
"// Create empty set, to denote... | Returns all private, protected and public properties for this class.
Properties declared with var are not provided as var declarations are
deprecated.
Only declared properties are returned. Properties created at runtime
are not taken into consideration.
@throws ClassDefinitionNotFoundException
@return ReflectionProperty[] | [
"Returns",
"all",
"private",
"protected",
"and",
"public",
"properties",
"for",
"this",
"class",
".",
"Properties",
"declared",
"with",
"var",
"are",
"not",
"provided",
"as",
"var",
"declarations",
"are",
"deprecated",
"."
] | 0ff78bed5dddb4bec9fd64500f822a28ce987f62 | https://github.com/hostnet/accessor-generator-plugin-lib/blob/0ff78bed5dddb4bec9fd64500f822a28ce987f62/src/Reflection/ReflectionClass.php#L287-L329 | train |
hostnet/accessor-generator-plugin-lib | src/Reflection/ReflectionClass.php | ReflectionClass.parseNamespace | private function parseNamespace($loc): string
{
$tokens = $this->getTokenStream();
$ns = '';
if (\in_array($this->tokens->type($loc), [T_FUNCTION, T_CONST])) {
$ns .= $this->tokens->value($loc) . ' ';
$loc = $tokens->next($loc);
}
while (\in_array($tokens->type($loc), [T_NS_SEPARATOR, T_STRING])) {
$ns .= $tokens->value($loc);
$loc = $tokens->next($loc);
}
return $ns;
} | php | private function parseNamespace($loc): string
{
$tokens = $this->getTokenStream();
$ns = '';
if (\in_array($this->tokens->type($loc), [T_FUNCTION, T_CONST])) {
$ns .= $this->tokens->value($loc) . ' ';
$loc = $tokens->next($loc);
}
while (\in_array($tokens->type($loc), [T_NS_SEPARATOR, T_STRING])) {
$ns .= $tokens->value($loc);
$loc = $tokens->next($loc);
}
return $ns;
} | [
"private",
"function",
"parseNamespace",
"(",
"$",
"loc",
")",
":",
"string",
"{",
"$",
"tokens",
"=",
"$",
"this",
"->",
"getTokenStream",
"(",
")",
";",
"$",
"ns",
"=",
"''",
";",
"if",
"(",
"\\",
"in_array",
"(",
"$",
"this",
"->",
"tokens",
"->... | Parse the namespace and return as string
@param int $loc location of the first namespace token (T_STRING)
and not the T_NAMESPACE, T_AS or T_USE.
@return string | [
"Parse",
"the",
"namespace",
"and",
"return",
"as",
"string"
] | 0ff78bed5dddb4bec9fd64500f822a28ce987f62 | https://github.com/hostnet/accessor-generator-plugin-lib/blob/0ff78bed5dddb4bec9fd64500f822a28ce987f62/src/Reflection/ReflectionClass.php#L381-L397 | train |
hostnet/accessor-generator-plugin-lib | src/Reflection/ReflectionClass.php | ReflectionClass.parseDocComment | private function parseDocComment($loc): string
{
$tokens = $this->getTokenStream();
// Look back from T_PUBLIC, T_PROTECTED, T_PRIVATE or T_CLASS
// for the T_DOC_COMMENT token
$loc = $tokens->previous($loc, [T_WHITESPACE, T_STATIC, T_FINAL]);
// Check for doc comment
if ($loc && $tokens->type($loc) === T_DOC_COMMENT) {
$doc_comment = $tokens->value($loc);
// strip off indentation
$doc_comment = preg_replace('/^[ \t]*\*/m', ' *', $doc_comment);
return $doc_comment;
}
return '';
} | php | private function parseDocComment($loc): string
{
$tokens = $this->getTokenStream();
// Look back from T_PUBLIC, T_PROTECTED, T_PRIVATE or T_CLASS
// for the T_DOC_COMMENT token
$loc = $tokens->previous($loc, [T_WHITESPACE, T_STATIC, T_FINAL]);
// Check for doc comment
if ($loc && $tokens->type($loc) === T_DOC_COMMENT) {
$doc_comment = $tokens->value($loc);
// strip off indentation
$doc_comment = preg_replace('/^[ \t]*\*/m', ' *', $doc_comment);
return $doc_comment;
}
return '';
} | [
"private",
"function",
"parseDocComment",
"(",
"$",
"loc",
")",
":",
"string",
"{",
"$",
"tokens",
"=",
"$",
"this",
"->",
"getTokenStream",
"(",
")",
";",
"// Look back from T_PUBLIC, T_PROTECTED, T_PRIVATE or T_CLASS",
"// for the T_DOC_COMMENT token",
"$",
"loc",
"... | Returns the doc comment for a property, method or class. The comment is
stripped of leading whitespaces. Returns an empty string if no doc-
comment or an empty doc comment was found.
@param int $loc location of the visibility modifier or T_CLASS
@return string the contents of the doc comment | [
"Returns",
"the",
"doc",
"comment",
"for",
"a",
"property",
"method",
"or",
"class",
".",
"The",
"comment",
"is",
"stripped",
"of",
"leading",
"whitespaces",
".",
"Returns",
"an",
"empty",
"string",
"if",
"no",
"doc",
"-",
"comment",
"or",
"an",
"empty",
... | 0ff78bed5dddb4bec9fd64500f822a28ce987f62 | https://github.com/hostnet/accessor-generator-plugin-lib/blob/0ff78bed5dddb4bec9fd64500f822a28ce987f62/src/Reflection/ReflectionClass.php#L408-L426 | train |
hostnet/accessor-generator-plugin-lib | src/Reflection/ReflectionClass.php | ReflectionClass.parsePropertyModifiers | private function parsePropertyModifiers($loc): int
{
$tokens = $this->getTokenStream();
$modifiers = 0; // initialize bit filed with all modifiers switched off
// Enable visibility bits
switch ($tokens->type($loc)) {
case T_PRIVATE:
$modifiers |= \ReflectionProperty::IS_PRIVATE;
break;
case T_PROTECTED:
$modifiers |= \ReflectionProperty::IS_PROTECTED;
break;
case T_VAR:
case T_PUBLIC:
$modifiers |= \ReflectionProperty::IS_PUBLIC;
break;
}
// Look forward and backward for STATIC modifier
$prev = $tokens->previous($loc);
$next = $tokens->next($loc);
// If found write the bits
if ($tokens->type($prev) === T_STATIC || $tokens->type($next) === T_STATIC) {
$modifiers |= \ReflectionProperty::IS_STATIC;
}
return $modifiers;
} | php | private function parsePropertyModifiers($loc): int
{
$tokens = $this->getTokenStream();
$modifiers = 0; // initialize bit filed with all modifiers switched off
// Enable visibility bits
switch ($tokens->type($loc)) {
case T_PRIVATE:
$modifiers |= \ReflectionProperty::IS_PRIVATE;
break;
case T_PROTECTED:
$modifiers |= \ReflectionProperty::IS_PROTECTED;
break;
case T_VAR:
case T_PUBLIC:
$modifiers |= \ReflectionProperty::IS_PUBLIC;
break;
}
// Look forward and backward for STATIC modifier
$prev = $tokens->previous($loc);
$next = $tokens->next($loc);
// If found write the bits
if ($tokens->type($prev) === T_STATIC || $tokens->type($next) === T_STATIC) {
$modifiers |= \ReflectionProperty::IS_STATIC;
}
return $modifiers;
} | [
"private",
"function",
"parsePropertyModifiers",
"(",
"$",
"loc",
")",
":",
"int",
"{",
"$",
"tokens",
"=",
"$",
"this",
"->",
"getTokenStream",
"(",
")",
";",
"$",
"modifiers",
"=",
"0",
";",
"// initialize bit filed with all modifiers switched off",
"// Enable v... | Parse visibility and static modifier of the property in to a bit field
combining all the modifiers as is done in by PHP Reflection for the
\ReflectionProperty.
Note that properties can not be final and thus this function does not
scan for T_FINAL.
@see \ReflectionProperty
@param int $loc location of the visibility modifier
@return int | [
"Parse",
"visibility",
"and",
"static",
"modifier",
"of",
"the",
"property",
"in",
"to",
"a",
"bit",
"field",
"combining",
"all",
"the",
"modifiers",
"as",
"is",
"done",
"in",
"by",
"PHP",
"Reflection",
"for",
"the",
"\\",
"ReflectionProperty",
"."
] | 0ff78bed5dddb4bec9fd64500f822a28ce987f62 | https://github.com/hostnet/accessor-generator-plugin-lib/blob/0ff78bed5dddb4bec9fd64500f822a28ce987f62/src/Reflection/ReflectionClass.php#L442-L471 | train |
hostnet/accessor-generator-plugin-lib | src/Reflection/ReflectionClass.php | ReflectionClass.parseDefaultValue | private function parseDefaultValue($loc): ?string
{
$tokens = $this->getTokenStream();
$default = '';
$loc = $tokens->next($loc);
if ($tokens->value($loc) === '=') {
$loc = $tokens->next($loc);
$type = $tokens->type($loc);
if (\in_array($type, [T_DNUMBER, T_LNUMBER, T_CONSTANT_ENCAPSED_STRING])) {
// Easy numbers and strings.
$default = $tokens->value($loc);
} elseif (\in_array($type, [T_STRING, T_NS_SEPARATOR])) {
// Constants, definitions and null
$default = $this->parseNamespace($loc);
$loc = $tokens->next($loc, [T_WHITESPACE, T_COMMENT, T_STRING, T_NS_SEPARATOR]);
if ($tokens->type($loc) === T_PAAMAYIM_NEKUDOTAYIM) {
$loc = $tokens->next($loc);
$default .= '::' . $tokens->value($loc);
}
} elseif (\in_array($type, [T_ARRAY, '['])) {
// Array types, both old array() and shorthand [] notation.
$default = $this->parseArrayDefinition($loc);
} elseif ($type === T_START_HEREDOC) {
// Heredoc and Nowdoc
$default = $this->parseHereNowDocConcat($loc);
}
}
return $default;
} | php | private function parseDefaultValue($loc): ?string
{
$tokens = $this->getTokenStream();
$default = '';
$loc = $tokens->next($loc);
if ($tokens->value($loc) === '=') {
$loc = $tokens->next($loc);
$type = $tokens->type($loc);
if (\in_array($type, [T_DNUMBER, T_LNUMBER, T_CONSTANT_ENCAPSED_STRING])) {
// Easy numbers and strings.
$default = $tokens->value($loc);
} elseif (\in_array($type, [T_STRING, T_NS_SEPARATOR])) {
// Constants, definitions and null
$default = $this->parseNamespace($loc);
$loc = $tokens->next($loc, [T_WHITESPACE, T_COMMENT, T_STRING, T_NS_SEPARATOR]);
if ($tokens->type($loc) === T_PAAMAYIM_NEKUDOTAYIM) {
$loc = $tokens->next($loc);
$default .= '::' . $tokens->value($loc);
}
} elseif (\in_array($type, [T_ARRAY, '['])) {
// Array types, both old array() and shorthand [] notation.
$default = $this->parseArrayDefinition($loc);
} elseif ($type === T_START_HEREDOC) {
// Heredoc and Nowdoc
$default = $this->parseHereNowDocConcat($loc);
}
}
return $default;
} | [
"private",
"function",
"parseDefaultValue",
"(",
"$",
"loc",
")",
":",
"?",
"string",
"{",
"$",
"tokens",
"=",
"$",
"this",
"->",
"getTokenStream",
"(",
")",
";",
"$",
"default",
"=",
"''",
";",
"$",
"loc",
"=",
"$",
"tokens",
"->",
"next",
"(",
"$... | Parses the default value assignment for a property and returns the
default value or null if there is no default value assigned.
The returned value includes single or double quotes as used in the code.
This way we can keep those and this also enables us to parse a default
value of null.
@param int $loc location of the property name (T_STRING)
@return string|null Null if there is no default value, string otherwise | [
"Parses",
"the",
"default",
"value",
"assignment",
"for",
"a",
"property",
"and",
"returns",
"the",
"default",
"value",
"or",
"null",
"if",
"there",
"is",
"no",
"default",
"value",
"assigned",
"."
] | 0ff78bed5dddb4bec9fd64500f822a28ce987f62 | https://github.com/hostnet/accessor-generator-plugin-lib/blob/0ff78bed5dddb4bec9fd64500f822a28ce987f62/src/Reflection/ReflectionClass.php#L485-L516 | train |
hostnet/accessor-generator-plugin-lib | src/Reflection/ReflectionClass.php | ReflectionClass.parseArrayDefinition | private function parseArrayDefinition($loc): string
{
$tokens = $this->getTokenStream();
$found = 0;
$brace = 0;
$code = '';
do {
$type = $tokens->type($loc);
switch ($type) {
case T_ARRAY:
$loc = $tokens->scan($loc, ['(']);
$brace++;
// intentional fallthrough
case '[':
$code .= '[';
$found++;
break;
case '(':
$brace++;
$code .= '(';
break;
case ']':
$found--;
$code .= ']';
break;
case ')':
if (--$brace === 0) {
$found--;
$code .= ']';
} else {
$code .= ')';
}
break;
default:
$code .= $this->arrayWhitespace($loc);
}
} while ($found > 0 && ($loc = $tokens->next($loc)));
return $code;
} | php | private function parseArrayDefinition($loc): string
{
$tokens = $this->getTokenStream();
$found = 0;
$brace = 0;
$code = '';
do {
$type = $tokens->type($loc);
switch ($type) {
case T_ARRAY:
$loc = $tokens->scan($loc, ['(']);
$brace++;
// intentional fallthrough
case '[':
$code .= '[';
$found++;
break;
case '(':
$brace++;
$code .= '(';
break;
case ']':
$found--;
$code .= ']';
break;
case ')':
if (--$brace === 0) {
$found--;
$code .= ']';
} else {
$code .= ')';
}
break;
default:
$code .= $this->arrayWhitespace($loc);
}
} while ($found > 0 && ($loc = $tokens->next($loc)));
return $code;
} | [
"private",
"function",
"parseArrayDefinition",
"(",
"$",
"loc",
")",
":",
"string",
"{",
"$",
"tokens",
"=",
"$",
"this",
"->",
"getTokenStream",
"(",
")",
";",
"$",
"found",
"=",
"0",
";",
"$",
"brace",
"=",
"0",
";",
"$",
"code",
"=",
"''",
";",
... | Parse an array definition. The definition can contain arrays itself. The
whole content of the array definition is stripped from comments and
excessive whitespaces.
@param int $loc location of the token stream where the array starts.
This should point to a T_ARRAY or [ token.
@return string code representation of the parsed array without any comments or excessive whitespace. | [
"Parse",
"an",
"array",
"definition",
".",
"The",
"definition",
"can",
"contain",
"arrays",
"itself",
".",
"The",
"whole",
"content",
"of",
"the",
"array",
"definition",
"is",
"stripped",
"from",
"comments",
"and",
"excessive",
"whitespaces",
"."
] | 0ff78bed5dddb4bec9fd64500f822a28ce987f62 | https://github.com/hostnet/accessor-generator-plugin-lib/blob/0ff78bed5dddb4bec9fd64500f822a28ce987f62/src/Reflection/ReflectionClass.php#L528-L567 | train |
hostnet/accessor-generator-plugin-lib | src/Reflection/ReflectionClass.php | ReflectionClass.arrayWhitespace | private function arrayWhitespace($loc): ?string
{
$tokens = $this->getTokenStream();
$type = $tokens->type($loc);
switch ($type) {
case T_DOUBLE_ARROW:
return ' => ';
case ',':
return ', ';
default:
return $tokens->value($loc);
}
} | php | private function arrayWhitespace($loc): ?string
{
$tokens = $this->getTokenStream();
$type = $tokens->type($loc);
switch ($type) {
case T_DOUBLE_ARROW:
return ' => ';
case ',':
return ', ';
default:
return $tokens->value($loc);
}
} | [
"private",
"function",
"arrayWhitespace",
"(",
"$",
"loc",
")",
":",
"?",
"string",
"{",
"$",
"tokens",
"=",
"$",
"this",
"->",
"getTokenStream",
"(",
")",
";",
"$",
"type",
"=",
"$",
"tokens",
"->",
"type",
"(",
"$",
"loc",
")",
";",
"switch",
"("... | Returns tokens found within an array definition PSR conforming
whitespace to make the code more readable.
@param int $loc location in the token stream
@return string code with PSR spacing for array notation | [
"Returns",
"tokens",
"found",
"within",
"an",
"array",
"definition",
"PSR",
"conforming",
"whitespace",
"to",
"make",
"the",
"code",
"more",
"readable",
"."
] | 0ff78bed5dddb4bec9fd64500f822a28ce987f62 | https://github.com/hostnet/accessor-generator-plugin-lib/blob/0ff78bed5dddb4bec9fd64500f822a28ce987f62/src/Reflection/ReflectionClass.php#L577-L589 | train |
hostnet/accessor-generator-plugin-lib | src/Reflection/ReflectionClass.php | ReflectionClass.parseHereNowDocConcat | private function parseHereNowDocConcat($loc): ?string
{
$tokens = $this->getTokenStream();
$type = substr($tokens->value($loc), 3, 1);
$loc = $tokens->next($loc);
if ($loc) {
$string = substr($tokens->value($loc), 0, -1);
if ($type === '\'') {
return '\'' . implode('\' . "\n" . \'', explode("\n", $string)) . '\'';
}
return '"' . str_replace("\n", '\n', $string) . '"';
}
return null;
} | php | private function parseHereNowDocConcat($loc): ?string
{
$tokens = $this->getTokenStream();
$type = substr($tokens->value($loc), 3, 1);
$loc = $tokens->next($loc);
if ($loc) {
$string = substr($tokens->value($loc), 0, -1);
if ($type === '\'') {
return '\'' . implode('\' . "\n" . \'', explode("\n", $string)) . '\'';
}
return '"' . str_replace("\n", '\n', $string) . '"';
}
return null;
} | [
"private",
"function",
"parseHereNowDocConcat",
"(",
"$",
"loc",
")",
":",
"?",
"string",
"{",
"$",
"tokens",
"=",
"$",
"this",
"->",
"getTokenStream",
"(",
")",
";",
"$",
"type",
"=",
"substr",
"(",
"$",
"tokens",
"->",
"value",
"(",
"$",
"loc",
")"... | Parse heredoc and nowdoc into a concatenated string representation to be
useful for default values and inline assignment.
@param int $loc
@return string|null | [
"Parse",
"heredoc",
"and",
"nowdoc",
"into",
"a",
"concatenated",
"string",
"representation",
"to",
"be",
"useful",
"for",
"default",
"values",
"and",
"inline",
"assignment",
"."
] | 0ff78bed5dddb4bec9fd64500f822a28ce987f62 | https://github.com/hostnet/accessor-generator-plugin-lib/blob/0ff78bed5dddb4bec9fd64500f822a28ce987f62/src/Reflection/ReflectionClass.php#L599-L615 | train |
hostnet/accessor-generator-plugin-lib | src/Reflection/ReflectionClass.php | ReflectionClass.getTokenStream | private function getTokenStream(): TokenStream
{
if (null === $this->tokens) {
$this->tokens = new TokenStream(file_get_contents($this->filename));
}
return $this->tokens;
} | php | private function getTokenStream(): TokenStream
{
if (null === $this->tokens) {
$this->tokens = new TokenStream(file_get_contents($this->filename));
}
return $this->tokens;
} | [
"private",
"function",
"getTokenStream",
"(",
")",
":",
"TokenStream",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"tokens",
")",
"{",
"$",
"this",
"->",
"tokens",
"=",
"new",
"TokenStream",
"(",
"file_get_contents",
"(",
"$",
"this",
"->",
"filena... | Returns the TokenStream instance for the class.
@return TokenStream | [
"Returns",
"the",
"TokenStream",
"instance",
"for",
"the",
"class",
"."
] | 0ff78bed5dddb4bec9fd64500f822a28ce987f62 | https://github.com/hostnet/accessor-generator-plugin-lib/blob/0ff78bed5dddb4bec9fd64500f822a28ce987f62/src/Reflection/ReflectionClass.php#L622-L629 | train |
techdivision/import-product | src/Repositories/CacheWarmer/ProductCacheWarmer.php | ProductCacheWarmer.warm | public function warm()
{
// prepare the caches for the statements
foreach ($this->repository->findAll() as $product) {
// add the product to the cache, register the SKU reference as well
$this->repository->toCache(
$product[$this->repository->getPrimaryKeyName()],
$product,
array($product[MemberNames::SKU] => $product[$this->repository->getPrimaryKeyName()])
);
}
} | php | public function warm()
{
// prepare the caches for the statements
foreach ($this->repository->findAll() as $product) {
// add the product to the cache, register the SKU reference as well
$this->repository->toCache(
$product[$this->repository->getPrimaryKeyName()],
$product,
array($product[MemberNames::SKU] => $product[$this->repository->getPrimaryKeyName()])
);
}
} | [
"public",
"function",
"warm",
"(",
")",
"{",
"// prepare the caches for the statements",
"foreach",
"(",
"$",
"this",
"->",
"repository",
"->",
"findAll",
"(",
")",
"as",
"$",
"product",
")",
"{",
"// add the product to the cache, register the SKU reference as well",
"$... | Warms the cache for the passed repository.
@return void | [
"Warms",
"the",
"cache",
"for",
"the",
"passed",
"repository",
"."
] | a596e0c4b0495c918139935a709815c739d61e95 | https://github.com/techdivision/import-product/blob/a596e0c4b0495c918139935a709815c739d61e95/src/Repositories/CacheWarmer/ProductCacheWarmer.php#L61-L73 | train |
aimeos/ai-admin-jsonadm | admin/jsonadm/src/Admin/JsonAdm/Standard.php | Standard.deleteItems | protected function deleteItems( \Aimeos\MW\View\Iface $view, ServerRequestInterface $request, ResponseInterface $response )
{
$manager = \Aimeos\MShop::create( $this->getContext(), $this->getPath() );
if( ( $id = $view->param( 'id' ) ) == null )
{
$body = (string) $request->getBody();
if( ( $payload = json_decode( $body ) ) === null || !isset( $payload->data ) || !is_array( $payload->data ) ) {
throw new \Aimeos\Admin\JsonAdm\Exception( sprintf( 'Invalid JSON in body' ), 400 );
}
$ids = $this->getIds( $payload );
$manager->deleteItems( $ids );
$view->total = count( $ids );
}
else
{
$manager->deleteItem( $id );
$view->total = 1;
}
return $response;
} | php | protected function deleteItems( \Aimeos\MW\View\Iface $view, ServerRequestInterface $request, ResponseInterface $response )
{
$manager = \Aimeos\MShop::create( $this->getContext(), $this->getPath() );
if( ( $id = $view->param( 'id' ) ) == null )
{
$body = (string) $request->getBody();
if( ( $payload = json_decode( $body ) ) === null || !isset( $payload->data ) || !is_array( $payload->data ) ) {
throw new \Aimeos\Admin\JsonAdm\Exception( sprintf( 'Invalid JSON in body' ), 400 );
}
$ids = $this->getIds( $payload );
$manager->deleteItems( $ids );
$view->total = count( $ids );
}
else
{
$manager->deleteItem( $id );
$view->total = 1;
}
return $response;
} | [
"protected",
"function",
"deleteItems",
"(",
"\\",
"Aimeos",
"\\",
"MW",
"\\",
"View",
"\\",
"Iface",
"$",
"view",
",",
"ServerRequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"manager",
"=",
"\\",
"Aimeos",
"\\",
... | Deletes one or more items
@param \Aimeos\MW\View\Iface $view View instance with "param" view helper
@param \Psr\Http\Message\ServerRequestInterface $request Request object
@param \Psr\Http\Message\ResponseInterface $response Response object
@return \Psr\Http\Message\ResponseInterface Modified response object
@throws \Aimeos\Admin\JsonAdm\Exception If the request body is invalid | [
"Deletes",
"one",
"or",
"more",
"items"
] | 8e4dc6528afcd2199e6555b2e7ead4f75b221005 | https://github.com/aimeos/ai-admin-jsonadm/blob/8e4dc6528afcd2199e6555b2e7ead4f75b221005/admin/jsonadm/src/Admin/JsonAdm/Standard.php#L507-L530 | train |
aimeos/ai-admin-jsonadm | admin/jsonadm/src/Admin/JsonAdm/Standard.php | Standard.patchItems | protected function patchItems( \Aimeos\MW\View\Iface $view, ServerRequestInterface $request, ResponseInterface $response )
{
$body = (string) $request->getBody();
if( ( $payload = json_decode( $body ) ) === null || !isset( $payload->data ) ) {
throw new \Aimeos\Admin\JsonAdm\Exception( sprintf( 'Invalid JSON in body' ), 400 );
}
$manager = \Aimeos\MShop::create( $this->getContext(), $this->getPath() );
if( is_array( $payload->data ) )
{
$data = $this->saveData( $manager, $payload );
$view->data = $data;
$view->total = count( $data );
$response = $response->withHeader( 'Content-Type', 'application/vnd.api+json; ext="bulk"; supported-ext="bulk"' );
}
elseif( ( $id = $view->param( 'id' ) ) != null )
{
$payload->data->id = $id;
$data = $this->saveEntry( $manager, $payload->data );
$view->data = $data;
$view->total = 1;
}
else
{
throw new \Aimeos\Admin\JsonAdm\Exception( sprintf( 'No ID given' ), 400 );
}
return $response;
} | php | protected function patchItems( \Aimeos\MW\View\Iface $view, ServerRequestInterface $request, ResponseInterface $response )
{
$body = (string) $request->getBody();
if( ( $payload = json_decode( $body ) ) === null || !isset( $payload->data ) ) {
throw new \Aimeos\Admin\JsonAdm\Exception( sprintf( 'Invalid JSON in body' ), 400 );
}
$manager = \Aimeos\MShop::create( $this->getContext(), $this->getPath() );
if( is_array( $payload->data ) )
{
$data = $this->saveData( $manager, $payload );
$view->data = $data;
$view->total = count( $data );
$response = $response->withHeader( 'Content-Type', 'application/vnd.api+json; ext="bulk"; supported-ext="bulk"' );
}
elseif( ( $id = $view->param( 'id' ) ) != null )
{
$payload->data->id = $id;
$data = $this->saveEntry( $manager, $payload->data );
$view->data = $data;
$view->total = 1;
}
else
{
throw new \Aimeos\Admin\JsonAdm\Exception( sprintf( 'No ID given' ), 400 );
}
return $response;
} | [
"protected",
"function",
"patchItems",
"(",
"\\",
"Aimeos",
"\\",
"MW",
"\\",
"View",
"\\",
"Iface",
"$",
"view",
",",
"ServerRequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"body",
"=",
"(",
"string",
")",
"$",... | Saves new attributes for one or more items
@param \Aimeos\MW\View\Iface $view View that will contain the "data" and "total" properties afterwards
@param \Psr\Http\Message\ServerRequestInterface $request Request object
@param \Psr\Http\Message\ResponseInterface $response Response object
@return \Psr\Http\Message\ResponseInterface Modified response object
@throws \Aimeos\Admin\JsonAdm\Exception If "id" parameter isn't available or the body is invalid | [
"Saves",
"new",
"attributes",
"for",
"one",
"or",
"more",
"items"
] | 8e4dc6528afcd2199e6555b2e7ead4f75b221005 | https://github.com/aimeos/ai-admin-jsonadm/blob/8e4dc6528afcd2199e6555b2e7ead4f75b221005/admin/jsonadm/src/Admin/JsonAdm/Standard.php#L585-L617 | train |
contributte/thepay-api | src/Helper/Merchant.php | Merchant.buildQuery | public function buildQuery(array $args = []): string
{
$out = array_merge(
$this->payment->getArgs(), // Arguments of the payment
$args, // Optional helper arguments
['signature' => $this->payment->getSignature()] // Signature
);
$str = [];
/** @var string|int $val */
foreach ($out as $key => $val) {
$str[] = rawurlencode((string) $key) . '=' . rawurlencode((string) $val);
}
return implode('&', $str);
} | php | public function buildQuery(array $args = []): string
{
$out = array_merge(
$this->payment->getArgs(), // Arguments of the payment
$args, // Optional helper arguments
['signature' => $this->payment->getSignature()] // Signature
);
$str = [];
/** @var string|int $val */
foreach ($out as $key => $val) {
$str[] = rawurlencode((string) $key) . '=' . rawurlencode((string) $val);
}
return implode('&', $str);
} | [
"public",
"function",
"buildQuery",
"(",
"array",
"$",
"args",
"=",
"[",
"]",
")",
":",
"string",
"{",
"$",
"out",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"payment",
"->",
"getArgs",
"(",
")",
",",
"// Arguments of the payment",
"$",
"args",
",",
"... | Build the query part of the URL from payment data and optional
helper data.
@param array $args Associative array of optional arguments that should
be appended to the URL.
@return string Query part of the URL with all parameters correctly escaped | [
"Build",
"the",
"query",
"part",
"of",
"the",
"URL",
"from",
"payment",
"data",
"and",
"optional",
"helper",
"data",
"."
] | 7e28eaf30ad1880533add93cf9e7296e61c09b8e | https://github.com/contributte/thepay-api/blob/7e28eaf30ad1880533add93cf9e7296e61c09b8e/src/Helper/Merchant.php#L47-L62 | train |
contributte/thepay-api | src/Payment.php | Payment.getArgs | public function getArgs(): array
{
$input = [];
$input['merchantId'] = $this->config->merchantId;
$input['accountId'] = $this->config->accountId;
$value = $this->value;
if ($value !== null) {
$input['value'] = number_format($value, 2, '.', '');
}
if ($this->currency !== null) {
$input['currency'] = $this->currency;
}
if ($this->description !== null) {
$input['description'] = $this->description;
}
if ($this->merchantData !== null) {
$input['merchantData'] = $this->merchantData;
}
if ($this->customerData !== null) {
$input['customerData'] = $this->customerData;
}
if ($this->customerEmail !== null) {
$input['customerEmail'] = $this->customerEmail;
}
if ($this->returnUrl !== null) {
$input['returnUrl'] = $this->returnUrl;
}
if ($this->backToEshopUrl !== null) {
$input['backToEshopUrl'] = $this->backToEshopUrl;
}
if ($this->methodId !== null) {
$input['methodId'] = $this->methodId;
}
if ($this->deposit !== null) {
$input['deposit'] = $this->getDeposit() ? '1' : '0';
}
if ($this->isRecurring !== null) {
$input['isRecurring'] = $this->getIsRecurring() ? '1' : '0';
}
if ($this->merchantSpecificSymbol !== null) {
$input['merchantSpecificSymbol'] = $this->merchantSpecificSymbol;
}
if ($this->eetDph !== null && !$this->eetDph->isEmpty()) {
$input = array_merge($input, $this->eetDph->toArray());
}
return $input;
} | php | public function getArgs(): array
{
$input = [];
$input['merchantId'] = $this->config->merchantId;
$input['accountId'] = $this->config->accountId;
$value = $this->value;
if ($value !== null) {
$input['value'] = number_format($value, 2, '.', '');
}
if ($this->currency !== null) {
$input['currency'] = $this->currency;
}
if ($this->description !== null) {
$input['description'] = $this->description;
}
if ($this->merchantData !== null) {
$input['merchantData'] = $this->merchantData;
}
if ($this->customerData !== null) {
$input['customerData'] = $this->customerData;
}
if ($this->customerEmail !== null) {
$input['customerEmail'] = $this->customerEmail;
}
if ($this->returnUrl !== null) {
$input['returnUrl'] = $this->returnUrl;
}
if ($this->backToEshopUrl !== null) {
$input['backToEshopUrl'] = $this->backToEshopUrl;
}
if ($this->methodId !== null) {
$input['methodId'] = $this->methodId;
}
if ($this->deposit !== null) {
$input['deposit'] = $this->getDeposit() ? '1' : '0';
}
if ($this->isRecurring !== null) {
$input['isRecurring'] = $this->getIsRecurring() ? '1' : '0';
}
if ($this->merchantSpecificSymbol !== null) {
$input['merchantSpecificSymbol'] = $this->merchantSpecificSymbol;
}
if ($this->eetDph !== null && !$this->eetDph->isEmpty()) {
$input = array_merge($input, $this->eetDph->toArray());
}
return $input;
} | [
"public",
"function",
"getArgs",
"(",
")",
":",
"array",
"{",
"$",
"input",
"=",
"[",
"]",
";",
"$",
"input",
"[",
"'merchantId'",
"]",
"=",
"$",
"this",
"->",
"config",
"->",
"merchantId",
";",
"$",
"input",
"[",
"'accountId'",
"]",
"=",
"$",
"thi... | List arguments to put into the URL. Returns associative array of
arguments that should be contained in the ThePay gate call.
@return mixed[] | [
"List",
"arguments",
"to",
"put",
"into",
"the",
"URL",
".",
"Returns",
"associative",
"array",
"of",
"arguments",
"that",
"should",
"be",
"contained",
"in",
"the",
"ThePay",
"gate",
"call",
"."
] | 7e28eaf30ad1880533add93cf9e7296e61c09b8e | https://github.com/contributte/thepay-api/blob/7e28eaf30ad1880533add93cf9e7296e61c09b8e/src/Payment.php#L323-L384 | train |
contributte/thepay-api | src/Payment.php | Payment.getSignature | public function getSignature(): string
{
$input = $this->getArgs();
$items = [];
foreach ($input as $key => $val) {
$items[] = sprintf('%s=%s', $key, $val);
}
$items[] = 'password=' . $this->getMerchantConfig()->password;
return self::hashFunction(implode('&', $items));
} | php | public function getSignature(): string
{
$input = $this->getArgs();
$items = [];
foreach ($input as $key => $val) {
$items[] = sprintf('%s=%s', $key, $val);
}
$items[] = 'password=' . $this->getMerchantConfig()->password;
return self::hashFunction(implode('&', $items));
} | [
"public",
"function",
"getSignature",
"(",
")",
":",
"string",
"{",
"$",
"input",
"=",
"$",
"this",
"->",
"getArgs",
"(",
")",
";",
"$",
"items",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"input",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$... | Returns signature to authenticate the payment. The signature
consists of hash of all specified parameters and the merchant
password specified in the configuration. So no one can alter the
payment, because the password is not known. | [
"Returns",
"signature",
"to",
"authenticate",
"the",
"payment",
".",
"The",
"signature",
"consists",
"of",
"hash",
"of",
"all",
"specified",
"parameters",
"and",
"the",
"merchant",
"password",
"specified",
"in",
"the",
"configuration",
".",
"So",
"no",
"one",
... | 7e28eaf30ad1880533add93cf9e7296e61c09b8e | https://github.com/contributte/thepay-api/blob/7e28eaf30ad1880533add93cf9e7296e61c09b8e/src/Payment.php#L392-L404 | train |
OXID-eSales/paymorrow-module | core/oxpspaymorrowresponsehandler.php | OxpsPaymorrowResponseHandler.wasAccepted | public function wasAccepted()
{
if ( $this->hasErrors() ) {
return false;
}
$aResponse = $this->getResponse();
if ( !empty( $aResponse['pm_order_status'] ) && $aResponse['pm_order_status'] === 'ACCEPTED' ) {
return true;
}
return false;
} | php | public function wasAccepted()
{
if ( $this->hasErrors() ) {
return false;
}
$aResponse = $this->getResponse();
if ( !empty( $aResponse['pm_order_status'] ) && $aResponse['pm_order_status'] === 'ACCEPTED' ) {
return true;
}
return false;
} | [
"public",
"function",
"wasAccepted",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasErrors",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"aResponse",
"=",
"$",
"this",
"->",
"getResponse",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
... | Check of order was accepted with no error codes.
@return bool | [
"Check",
"of",
"order",
"was",
"accepted",
"with",
"no",
"error",
"codes",
"."
] | adb5d7f50c2fa5b566abd262161c483c42847b42 | https://github.com/OXID-eSales/paymorrow-module/blob/adb5d7f50c2fa5b566abd262161c483c42847b42/core/oxpspaymorrowresponsehandler.php#L170-L183 | train |
OXID-eSales/paymorrow-module | core/oxpspaymorrowresponsehandler.php | OxpsPaymorrowResponseHandler.getErrorCodeFromResponseData | public function getErrorCodeFromResponseData( array $aResponseData )
{
foreach ( $aResponseData as $sKey => $iValue ) {
if ( preg_match( '/error_(\d+)_code/', $sKey ) ) {
return (int) $iValue;
}
}
return 999; // UNEXPECTED_ERROR
} | php | public function getErrorCodeFromResponseData( array $aResponseData )
{
foreach ( $aResponseData as $sKey => $iValue ) {
if ( preg_match( '/error_(\d+)_code/', $sKey ) ) {
return (int) $iValue;
}
}
return 999; // UNEXPECTED_ERROR
} | [
"public",
"function",
"getErrorCodeFromResponseData",
"(",
"array",
"$",
"aResponseData",
")",
"{",
"foreach",
"(",
"$",
"aResponseData",
"as",
"$",
"sKey",
"=>",
"$",
"iValue",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/error_(\\d+)_code/'",
",",
"$",
"sKey",... | Returns first match of client error code.
@param array $aResponseData
@return integer | [
"Returns",
"first",
"match",
"of",
"client",
"error",
"code",
"."
] | adb5d7f50c2fa5b566abd262161c483c42847b42 | https://github.com/OXID-eSales/paymorrow-module/blob/adb5d7f50c2fa5b566abd262161c483c42847b42/core/oxpspaymorrowresponsehandler.php#L192-L201 | train |
OXID-eSales/paymorrow-module | core/oxpspaymorrowresponsehandler.php | OxpsPaymorrowResponseHandler.getDeclinationDataFromResponse | public function getDeclinationDataFromResponse()
{
$aDeclinationData = array();
$aResponse = $this->getResponse();
$aExpectedKeys = array('paymentMethod_name', 'paymentMethod_status', 'paymentMethod_declineType');
foreach ( $aExpectedKeys as $sKey ) {
if ( array_key_exists( $sKey, $aResponse ) ) {
$aDeclinationData[$sKey] = $aResponse[$sKey];
}
}
return $aDeclinationData;
} | php | public function getDeclinationDataFromResponse()
{
$aDeclinationData = array();
$aResponse = $this->getResponse();
$aExpectedKeys = array('paymentMethod_name', 'paymentMethod_status', 'paymentMethod_declineType');
foreach ( $aExpectedKeys as $sKey ) {
if ( array_key_exists( $sKey, $aResponse ) ) {
$aDeclinationData[$sKey] = $aResponse[$sKey];
}
}
return $aDeclinationData;
} | [
"public",
"function",
"getDeclinationDataFromResponse",
"(",
")",
"{",
"$",
"aDeclinationData",
"=",
"array",
"(",
")",
";",
"$",
"aResponse",
"=",
"$",
"this",
"->",
"getResponse",
"(",
")",
";",
"$",
"aExpectedKeys",
"=",
"array",
"(",
"'paymentMethod_name'"... | Collects payment method data from order declination response.
@return array | [
"Collects",
"payment",
"method",
"data",
"from",
"order",
"declination",
"response",
"."
] | adb5d7f50c2fa5b566abd262161c483c42847b42 | https://github.com/OXID-eSales/paymorrow-module/blob/adb5d7f50c2fa5b566abd262161c483c42847b42/core/oxpspaymorrowresponsehandler.php#L208-L221 | train |
OXID-eSales/paymorrow-module | core/oxpspaymorrowresponsehandler.php | OxpsPaymorrowResponseHandler.parseGetConfigurationResponse | public function parseGetConfigurationResponse( array $aResponseData )
{
$aConfigurationData = array();
$iKey = 1;
$iMaxIterations = 10000;
while ( !empty( $aResponseData["pm_configuration_${iKey}_key"] ) and ( $iKey <= $iMaxIterations ) ) {
$aConfigurationData[$aResponseData["pm_configuration_${iKey}_key"]] =
isset( $aResponseData["pm_configuration_${iKey}_value"] )
? trim( (string) $aResponseData["pm_configuration_${iKey}_value"] )
: '';
$iKey++;
}
return $aConfigurationData;
} | php | public function parseGetConfigurationResponse( array $aResponseData )
{
$aConfigurationData = array();
$iKey = 1;
$iMaxIterations = 10000;
while ( !empty( $aResponseData["pm_configuration_${iKey}_key"] ) and ( $iKey <= $iMaxIterations ) ) {
$aConfigurationData[$aResponseData["pm_configuration_${iKey}_key"]] =
isset( $aResponseData["pm_configuration_${iKey}_value"] )
? trim( (string) $aResponseData["pm_configuration_${iKey}_value"] )
: '';
$iKey++;
}
return $aConfigurationData;
} | [
"public",
"function",
"parseGetConfigurationResponse",
"(",
"array",
"$",
"aResponseData",
")",
"{",
"$",
"aConfigurationData",
"=",
"array",
"(",
")",
";",
"$",
"iKey",
"=",
"1",
";",
"$",
"iMaxIterations",
"=",
"10000",
";",
"while",
"(",
"!",
"empty",
"... | Parse getConfiguration call response for Paymorrow settings.
@param array $aResponseData
@return array Assoc array with key as setting name for each corresponding value. | [
"Parse",
"getConfiguration",
"call",
"response",
"for",
"Paymorrow",
"settings",
"."
] | adb5d7f50c2fa5b566abd262161c483c42847b42 | https://github.com/OXID-eSales/paymorrow-module/blob/adb5d7f50c2fa5b566abd262161c483c42847b42/core/oxpspaymorrowresponsehandler.php#L249-L264 | train |
OXID-eSales/paymorrow-module | core/oxpspaymorrowresponsehandler.php | OxpsPaymorrowResponseHandler.handlePrepareOrderResponseOK | public function handlePrepareOrderResponseOK( $aResponseData )
{
oxRegistry::get( 'OxpsPaymorrowLogger' )->logWithType( $aResponseData, 'PM_handlePrepareOrderResponseOK' );
$this->setResponse( $aResponseData );
// Trigger user profile update using normalized response data
oxRegistry::get( 'OxpsPaymorrowModule' )->updateProfile( $aResponseData );
return true;
} | php | public function handlePrepareOrderResponseOK( $aResponseData )
{
oxRegistry::get( 'OxpsPaymorrowLogger' )->logWithType( $aResponseData, 'PM_handlePrepareOrderResponseOK' );
$this->setResponse( $aResponseData );
// Trigger user profile update using normalized response data
oxRegistry::get( 'OxpsPaymorrowModule' )->updateProfile( $aResponseData );
return true;
} | [
"public",
"function",
"handlePrepareOrderResponseOK",
"(",
"$",
"aResponseData",
")",
"{",
"oxRegistry",
"::",
"get",
"(",
"'OxpsPaymorrowLogger'",
")",
"->",
"logWithType",
"(",
"$",
"aResponseData",
",",
"'PM_handlePrepareOrderResponseOK'",
")",
";",
"$",
"this",
... | Order preparation successful response handler.
@param array $aResponseData
@return bool | [
"Order",
"preparation",
"successful",
"response",
"handler",
"."
] | adb5d7f50c2fa5b566abd262161c483c42847b42 | https://github.com/OXID-eSales/paymorrow-module/blob/adb5d7f50c2fa5b566abd262161c483c42847b42/core/oxpspaymorrowresponsehandler.php#L273-L282 | train |
OXID-eSales/paymorrow-module | core/oxpspaymorrowresponsehandler.php | OxpsPaymorrowResponseHandler.handleConfirmOrderResponseOK | public function handleConfirmOrderResponseOK( $responseData )
{
oxRegistry::get( 'OxpsPaymorrowLogger' )->logWithType( $responseData, 'PM_handleConfirmOrderResponseOK' );
$this->setResponse( $responseData );
return true;
} | php | public function handleConfirmOrderResponseOK( $responseData )
{
oxRegistry::get( 'OxpsPaymorrowLogger' )->logWithType( $responseData, 'PM_handleConfirmOrderResponseOK' );
$this->setResponse( $responseData );
return true;
} | [
"public",
"function",
"handleConfirmOrderResponseOK",
"(",
"$",
"responseData",
")",
"{",
"oxRegistry",
"::",
"get",
"(",
"'OxpsPaymorrowLogger'",
")",
"->",
"logWithType",
"(",
"$",
"responseData",
",",
"'PM_handleConfirmOrderResponseOK'",
")",
";",
"$",
"this",
"-... | Order confirmation successful response handler.
@param array $responseData
@return bool | [
"Order",
"confirmation",
"successful",
"response",
"handler",
"."
] | adb5d7f50c2fa5b566abd262161c483c42847b42 | https://github.com/OXID-eSales/paymorrow-module/blob/adb5d7f50c2fa5b566abd262161c483c42847b42/core/oxpspaymorrowresponsehandler.php#L305-L311 | train |
OXID-eSales/paymorrow-module | core/oxpspaymorrowresponsehandler.php | OxpsPaymorrowResponseHandler.handleConfirmOrderResponseError | public function handleConfirmOrderResponseError( $responseData )
{
oxRegistry::get( 'OxpsPaymorrowLogger' )->logWithType( $responseData, 'PM_handleConfirmOrderResponseError' );
$this->setResponse( $responseData );
$this->setErrorCode( $this->getErrorCodeFromResponseData( $responseData ) );
return false;
} | php | public function handleConfirmOrderResponseError( $responseData )
{
oxRegistry::get( 'OxpsPaymorrowLogger' )->logWithType( $responseData, 'PM_handleConfirmOrderResponseError' );
$this->setResponse( $responseData );
$this->setErrorCode( $this->getErrorCodeFromResponseData( $responseData ) );
return false;
} | [
"public",
"function",
"handleConfirmOrderResponseError",
"(",
"$",
"responseData",
")",
"{",
"oxRegistry",
"::",
"get",
"(",
"'OxpsPaymorrowLogger'",
")",
"->",
"logWithType",
"(",
"$",
"responseData",
",",
"'PM_handleConfirmOrderResponseError'",
")",
";",
"$",
"this"... | Order confirmation error response handler.
@param array $responseData
@return bool | [
"Order",
"confirmation",
"error",
"response",
"handler",
"."
] | adb5d7f50c2fa5b566abd262161c483c42847b42 | https://github.com/OXID-eSales/paymorrow-module/blob/adb5d7f50c2fa5b566abd262161c483c42847b42/core/oxpspaymorrowresponsehandler.php#L320-L327 | train |
moodev/php-weasel | lib/Weasel/JsonMarshaller/Config/ClassAnnotationDriver.php | ClassAnnotationDriver._getSubClassName | protected function _getSubClassName(\ReflectionClass $rClass)
{
$subClassReader = $this->annotationReaderFactory->getReaderForClass($rClass);
/**
* @var Annotations\JsonTypeName $subNameA
*/
$subNameA = $subClassReader->getSingleClassAnnotation($this->annNS . 'JsonTypeName');
if (isset($subNameA)) {
return $subNameA->getName();
} else {
return $rClass->getName();
}
} | php | protected function _getSubClassName(\ReflectionClass $rClass)
{
$subClassReader = $this->annotationReaderFactory->getReaderForClass($rClass);
/**
* @var Annotations\JsonTypeName $subNameA
*/
$subNameA = $subClassReader->getSingleClassAnnotation($this->annNS . 'JsonTypeName');
if (isset($subNameA)) {
return $subNameA->getName();
} else {
return $rClass->getName();
}
} | [
"protected",
"function",
"_getSubClassName",
"(",
"\\",
"ReflectionClass",
"$",
"rClass",
")",
"{",
"$",
"subClassReader",
"=",
"$",
"this",
"->",
"annotationReaderFactory",
"->",
"getReaderForClass",
"(",
"$",
"rClass",
")",
";",
"/**\n * @var Annotations\\Js... | Find out what name we should use to referr to one of our subtypes.
@param \ReflectionClass $rClass
@return string | [
"Find",
"out",
"what",
"name",
"we",
"should",
"use",
"to",
"referr",
"to",
"one",
"of",
"our",
"subtypes",
"."
] | fecc7cc06cae719489cb4490f414ed6530e70831 | https://github.com/moodev/php-weasel/blob/fecc7cc06cae719489cb4490f414ed6530e70831/lib/Weasel/JsonMarshaller/Config/ClassAnnotationDriver.php#L343-L356 | train |
moodev/php-weasel | lib/Weasel/JsonMarshaller/Config/ClassAnnotationDriver.php | ClassAnnotationDriver.getConfig | public function getConfig()
{
$this->config = new ClassMarshaller();
$this->config->serialization = new Serialization\ClassSerialization();
$this->config->deserialization = new Deserialization\ClassDeserialization();
$reader = $this->_getAnnotationReader();
/**
* @var \Weasel\JsonMarshaller\Config\Annotations\JsonInclude $includer
*/
$includer = $reader->getSingleClassAnnotation($this->annNS . 'JsonInclude');
$this->config->serialization->include = $this->_getIncluderValue($includer);
/**
* Work out what the class' "name" is, just in case inheritance is needed.
* @var \Weasel\JsonMarshaller\Config\Annotations\JsonTypeName $typeNamer
*/
$typeNamer = $reader->getSingleClassAnnotation($this->annNS . 'JsonTypeName');
$name = null;
if (isset($typeNamer)) {
$name = $typeNamer->getName();
}
if (empty($name)) {
// Default to the unqualified class name
$name = $this->rClass->getName();
}
$this->config->deserialization->name = $name;
/**
* @var Annotations\JsonTypeInfo $typeInfo
* @var Annotations\JsonSubTypes $subTypes
*/
$typeInfo = $reader->getSingleClassAnnotation($this->annNS . 'JsonTypeInfo');
$subTypes = $reader->getSingleClassAnnotation($this->annNS . 'JsonSubTypes');
$this->config->deserialization->typeInfo = $this->_getDeserializationTypeInfo($typeInfo, $subTypes);
$this->config->serialization->typeInfo = $this->_getSerializationTypeInfo($typeInfo, $subTypes);
$methods = $this->rClass->getMethods(\ReflectionMethod::IS_PUBLIC);
foreach ($methods as $method) {
$this->_configureMethod($method);
}
$properties = $this->rClass->getProperties(\ReflectionProperty::IS_PUBLIC & ~\ReflectionProperty::IS_STATIC);
foreach ($properties as $property) {
$this->_configureProperty($property);
}
/**
* @var \Weasel\JsonMarshaller\Config\Annotations\JsonIgnoreProperties $ignorer
*/
$ignorer = $reader->getSingleClassAnnotation($this->annNS . 'JsonIgnoreProperties');
if (!empty($ignorer)) {
// The ignorer config affects which properties we will consider.
$this->config->deserialization->ignoreUnknown = $ignorer->getIgnoreUnknown();
$this->config->deserialization->ignoreProperties = $ignorer->getNames();
}
return $this->config;
} | php | public function getConfig()
{
$this->config = new ClassMarshaller();
$this->config->serialization = new Serialization\ClassSerialization();
$this->config->deserialization = new Deserialization\ClassDeserialization();
$reader = $this->_getAnnotationReader();
/**
* @var \Weasel\JsonMarshaller\Config\Annotations\JsonInclude $includer
*/
$includer = $reader->getSingleClassAnnotation($this->annNS . 'JsonInclude');
$this->config->serialization->include = $this->_getIncluderValue($includer);
/**
* Work out what the class' "name" is, just in case inheritance is needed.
* @var \Weasel\JsonMarshaller\Config\Annotations\JsonTypeName $typeNamer
*/
$typeNamer = $reader->getSingleClassAnnotation($this->annNS . 'JsonTypeName');
$name = null;
if (isset($typeNamer)) {
$name = $typeNamer->getName();
}
if (empty($name)) {
// Default to the unqualified class name
$name = $this->rClass->getName();
}
$this->config->deserialization->name = $name;
/**
* @var Annotations\JsonTypeInfo $typeInfo
* @var Annotations\JsonSubTypes $subTypes
*/
$typeInfo = $reader->getSingleClassAnnotation($this->annNS . 'JsonTypeInfo');
$subTypes = $reader->getSingleClassAnnotation($this->annNS . 'JsonSubTypes');
$this->config->deserialization->typeInfo = $this->_getDeserializationTypeInfo($typeInfo, $subTypes);
$this->config->serialization->typeInfo = $this->_getSerializationTypeInfo($typeInfo, $subTypes);
$methods = $this->rClass->getMethods(\ReflectionMethod::IS_PUBLIC);
foreach ($methods as $method) {
$this->_configureMethod($method);
}
$properties = $this->rClass->getProperties(\ReflectionProperty::IS_PUBLIC & ~\ReflectionProperty::IS_STATIC);
foreach ($properties as $property) {
$this->_configureProperty($property);
}
/**
* @var \Weasel\JsonMarshaller\Config\Annotations\JsonIgnoreProperties $ignorer
*/
$ignorer = $reader->getSingleClassAnnotation($this->annNS . 'JsonIgnoreProperties');
if (!empty($ignorer)) {
// The ignorer config affects which properties we will consider.
$this->config->deserialization->ignoreUnknown = $ignorer->getIgnoreUnknown();
$this->config->deserialization->ignoreProperties = $ignorer->getNames();
}
return $this->config;
} | [
"public",
"function",
"getConfig",
"(",
")",
"{",
"$",
"this",
"->",
"config",
"=",
"new",
"ClassMarshaller",
"(",
")",
";",
"$",
"this",
"->",
"config",
"->",
"serialization",
"=",
"new",
"Serialization",
"\\",
"ClassSerialization",
"(",
")",
";",
"$",
... | Get the config for the current class.
@return ClassMarshaller A populated ClassMarshaller config object. | [
"Get",
"the",
"config",
"for",
"the",
"current",
"class",
"."
] | fecc7cc06cae719489cb4490f414ed6530e70831 | https://github.com/moodev/php-weasel/blob/fecc7cc06cae719489cb4490f414ed6530e70831/lib/Weasel/JsonMarshaller/Config/ClassAnnotationDriver.php#L543-L605 | train |
OXID-eSales/paymorrow-module | core/oxpspaymorrowrequestcontrollerproxy.php | OxpsPaymorrowRequestControllerProxy.prepareOrder | public function prepareOrder( array $aPostData, $blSettingsUpdated = false )
{
// Update user profile with values user entered to Paymorrow form
$this->_updateUserData( $aPostData );
// Reset payment method in session and basket on its change
$this->_resetPaymentMethod( $aPostData );
// Send order preparation.verification request
$aResponse = $this->_getRequestController()->pmVerify( $aPostData );
oxRegistry::get( 'OxpsPaymorrowLogger' )->logWithType( $aPostData, 'Proxy-prepareOrderPOST' );
/** @var OxpsPaymorrowResponseHandler $oResponseHandler */
$oResponseHandler = oxRegistry::get( 'OxpsPaymorrowResponseHandler' );
$iResponseErrorCore = $oResponseHandler->getErrorCodeFromResponseData( $aResponse );
// Check of response is an error with configuration update error code 900
if ( ( $iResponseErrorCore === 900 ) and empty( $blSettingsUpdated ) ) {
// Call module settings update in case error code 900 received
oxRegistry::get( 'OxpsPaymorrowModule' )->updateSettings();
// Call the request again
return $this->prepareOrder( $aPostData, true );
}
return json_encode( $aResponse );
} | php | public function prepareOrder( array $aPostData, $blSettingsUpdated = false )
{
// Update user profile with values user entered to Paymorrow form
$this->_updateUserData( $aPostData );
// Reset payment method in session and basket on its change
$this->_resetPaymentMethod( $aPostData );
// Send order preparation.verification request
$aResponse = $this->_getRequestController()->pmVerify( $aPostData );
oxRegistry::get( 'OxpsPaymorrowLogger' )->logWithType( $aPostData, 'Proxy-prepareOrderPOST' );
/** @var OxpsPaymorrowResponseHandler $oResponseHandler */
$oResponseHandler = oxRegistry::get( 'OxpsPaymorrowResponseHandler' );
$iResponseErrorCore = $oResponseHandler->getErrorCodeFromResponseData( $aResponse );
// Check of response is an error with configuration update error code 900
if ( ( $iResponseErrorCore === 900 ) and empty( $blSettingsUpdated ) ) {
// Call module settings update in case error code 900 received
oxRegistry::get( 'OxpsPaymorrowModule' )->updateSettings();
// Call the request again
return $this->prepareOrder( $aPostData, true );
}
return json_encode( $aResponse );
} | [
"public",
"function",
"prepareOrder",
"(",
"array",
"$",
"aPostData",
",",
"$",
"blSettingsUpdated",
"=",
"false",
")",
"{",
"// Update user profile with values user entered to Paymorrow form",
"$",
"this",
"->",
"_updateUserData",
"(",
"$",
"aPostData",
")",
";",
"//... | Order preparation call.
Also perform configuration update on error code 900 received and calls the request again one time.
@param array $aPostData
@param bool $blSettingsUpdated If true, then settings update is not called again.
@return string | [
"Order",
"preparation",
"call",
".",
"Also",
"perform",
"configuration",
"update",
"on",
"error",
"code",
"900",
"received",
"and",
"calls",
"the",
"request",
"again",
"one",
"time",
"."
] | adb5d7f50c2fa5b566abd262161c483c42847b42 | https://github.com/OXID-eSales/paymorrow-module/blob/adb5d7f50c2fa5b566abd262161c483c42847b42/core/oxpspaymorrowrequestcontrollerproxy.php#L64-L91 | train |
OXID-eSales/paymorrow-module | core/oxpspaymorrowrequestcontrollerproxy.php | OxpsPaymorrowRequestControllerProxy.validatePendingOrder | public function validatePendingOrder()
{
/** @var OxpsPaymorrowEshopDataProvider $dataProvider */
$dataProvider = oxNew( 'OxpsPaymorrowEshopDataProvider' );
$data = $dataProvider->collectEshopData();
// Combine basket data and payment session data
$session = $this->getConfig()->getSession();
$sessionData = (array) $session->getVariable( 'pm_verify' );
$data = array_merge( $data, $sessionData );
// Send order preparation/verification request
$aResponse = $this->_getRequestController()->pmVerify( $data );
oxRegistry::get( 'OxpsPaymorrowLogger' )->logWithType( $data, 'Proxy-prepareOrderPOST_reValidate' );
/** @var OxpsPaymorrowResponseHandler $oResponseHandler */
$oResponseHandler = oxRegistry::get( 'OxpsPaymorrowResponseHandler' );
$oResponseHandler->setResponse( $aResponse );
return (bool) $oResponseHandler->wasAccepted();
} | php | public function validatePendingOrder()
{
/** @var OxpsPaymorrowEshopDataProvider $dataProvider */
$dataProvider = oxNew( 'OxpsPaymorrowEshopDataProvider' );
$data = $dataProvider->collectEshopData();
// Combine basket data and payment session data
$session = $this->getConfig()->getSession();
$sessionData = (array) $session->getVariable( 'pm_verify' );
$data = array_merge( $data, $sessionData );
// Send order preparation/verification request
$aResponse = $this->_getRequestController()->pmVerify( $data );
oxRegistry::get( 'OxpsPaymorrowLogger' )->logWithType( $data, 'Proxy-prepareOrderPOST_reValidate' );
/** @var OxpsPaymorrowResponseHandler $oResponseHandler */
$oResponseHandler = oxRegistry::get( 'OxpsPaymorrowResponseHandler' );
$oResponseHandler->setResponse( $aResponse );
return (bool) $oResponseHandler->wasAccepted();
} | [
"public",
"function",
"validatePendingOrder",
"(",
")",
"{",
"/** @var OxpsPaymorrowEshopDataProvider $dataProvider */",
"$",
"dataProvider",
"=",
"oxNew",
"(",
"'OxpsPaymorrowEshopDataProvider'",
")",
";",
"$",
"data",
"=",
"$",
"dataProvider",
"->",
"collectEshopData",
... | Collect current basket data and make verification API call.
Method is independent from JS of front-end forms, so marks terms and conditions as accepted.
It should be used to re-validate already verified order, which user accepted on checkout payment step.
@return bool | [
"Collect",
"current",
"basket",
"data",
"and",
"make",
"verification",
"API",
"call",
".",
"Method",
"is",
"independent",
"from",
"JS",
"of",
"front",
"-",
"end",
"forms",
"so",
"marks",
"terms",
"and",
"conditions",
"as",
"accepted",
".",
"It",
"should",
... | adb5d7f50c2fa5b566abd262161c483c42847b42 | https://github.com/OXID-eSales/paymorrow-module/blob/adb5d7f50c2fa5b566abd262161c483c42847b42/core/oxpspaymorrowrequestcontrollerproxy.php#L100-L120 | train |
OXID-eSales/paymorrow-module | core/oxpspaymorrowrequestcontrollerproxy.php | OxpsPaymorrowRequestControllerProxy._updateUserData | public function _updateUserData( array $aPostData )
{
if ( $oUser = $this->_updateUserProfileData( $aPostData ) ) {
$this->_updateUserActiveShippingAddress( $oUser, $aPostData );
}
} | php | public function _updateUserData( array $aPostData )
{
if ( $oUser = $this->_updateUserProfileData( $aPostData ) ) {
$this->_updateUserActiveShippingAddress( $oUser, $aPostData );
}
} | [
"public",
"function",
"_updateUserData",
"(",
"array",
"$",
"aPostData",
")",
"{",
"if",
"(",
"$",
"oUser",
"=",
"$",
"this",
"->",
"_updateUserProfileData",
"(",
"$",
"aPostData",
")",
")",
"{",
"$",
"this",
"->",
"_updateUserActiveShippingAddress",
"(",
"$... | Update user profile with data posted from Paymorrow form.
@nice-to-have: Adjust unit tests to proxy class and make method protected.
@param array $aPostData | [
"Update",
"user",
"profile",
"with",
"data",
"posted",
"from",
"Paymorrow",
"form",
"."
] | adb5d7f50c2fa5b566abd262161c483c42847b42 | https://github.com/OXID-eSales/paymorrow-module/blob/adb5d7f50c2fa5b566abd262161c483c42847b42/core/oxpspaymorrowrequestcontrollerproxy.php#L145-L150 | train |
OXID-eSales/paymorrow-module | core/oxpspaymorrowrequestcontrollerproxy.php | OxpsPaymorrowRequestControllerProxy._resetPaymentMethod | public function _resetPaymentMethod( array $aPostData )
{
$oSession = oxRegistry::getSession();
if ( $oSession->getVariable( 'paymentid' ) and
array_key_exists( 'paymentid', $aPostData ) and
( $oSession->getVariable( 'paymentid' ) != $aPostData['paymentid'] )
) {
// Remove previous method from sessions
$oSession->deleteVariable( 'paymentid' );
// Adjust basket by removing payment surcharge and recalculating the basket
$oBasket = $oSession->getBasket();
$oBasket->setPayment();
$oBasket->setCost( 'oxpayment' );
$oBasket->calculateBasket( true );
}
} | php | public function _resetPaymentMethod( array $aPostData )
{
$oSession = oxRegistry::getSession();
if ( $oSession->getVariable( 'paymentid' ) and
array_key_exists( 'paymentid', $aPostData ) and
( $oSession->getVariable( 'paymentid' ) != $aPostData['paymentid'] )
) {
// Remove previous method from sessions
$oSession->deleteVariable( 'paymentid' );
// Adjust basket by removing payment surcharge and recalculating the basket
$oBasket = $oSession->getBasket();
$oBasket->setPayment();
$oBasket->setCost( 'oxpayment' );
$oBasket->calculateBasket( true );
}
} | [
"public",
"function",
"_resetPaymentMethod",
"(",
"array",
"$",
"aPostData",
")",
"{",
"$",
"oSession",
"=",
"oxRegistry",
"::",
"getSession",
"(",
")",
";",
"if",
"(",
"$",
"oSession",
"->",
"getVariable",
"(",
"'paymentid'",
")",
"and",
"array_key_exists",
... | Reset changed payment method selection in session for payment surcharge calculation to be valid.
If selected method is not the same as in session, it removes session data and adjusts basket calculation.
@param array $aPostData | [
"Reset",
"changed",
"payment",
"method",
"selection",
"in",
"session",
"for",
"payment",
"surcharge",
"calculation",
"to",
"be",
"valid",
".",
"If",
"selected",
"method",
"is",
"not",
"the",
"same",
"as",
"in",
"session",
"it",
"removes",
"session",
"data",
... | adb5d7f50c2fa5b566abd262161c483c42847b42 | https://github.com/OXID-eSales/paymorrow-module/blob/adb5d7f50c2fa5b566abd262161c483c42847b42/core/oxpspaymorrowrequestcontrollerproxy.php#L158-L175 | train |
OXID-eSales/paymorrow-module | core/oxpspaymorrowrequestcontrollerproxy.php | OxpsPaymorrowRequestControllerProxy._updateUserProfileData | protected function _updateUserProfileData( array $aPostData )
{
/** @var OxpsPaymorrowOxUser|oxUser $oUser */
$oUser = $this->getUser();
if ( empty( $oUser ) or !( $oUser instanceof oxUser ) or !$oUser->getId() ) {
return false;
}
$oUser->mapToProfileDataAndUpdateUser( $aPostData );
return $oUser;
} | php | protected function _updateUserProfileData( array $aPostData )
{
/** @var OxpsPaymorrowOxUser|oxUser $oUser */
$oUser = $this->getUser();
if ( empty( $oUser ) or !( $oUser instanceof oxUser ) or !$oUser->getId() ) {
return false;
}
$oUser->mapToProfileDataAndUpdateUser( $aPostData );
return $oUser;
} | [
"protected",
"function",
"_updateUserProfileData",
"(",
"array",
"$",
"aPostData",
")",
"{",
"/** @var OxpsPaymorrowOxUser|oxUser $oUser */",
"$",
"oUser",
"=",
"$",
"this",
"->",
"getUser",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"oUser",
")",
"or",
"!",... | Get valid, logged in user and update their profile data.
@param array $aPostData
@return bool|OxpsPaymorrowOxUser|oxUser User object if loaded, false otherwise. | [
"Get",
"valid",
"logged",
"in",
"user",
"and",
"update",
"their",
"profile",
"data",
"."
] | adb5d7f50c2fa5b566abd262161c483c42847b42 | https://github.com/OXID-eSales/paymorrow-module/blob/adb5d7f50c2fa5b566abd262161c483c42847b42/core/oxpspaymorrowrequestcontrollerproxy.php#L197-L209 | train |
OXID-eSales/paymorrow-module | core/oxpspaymorrowrequestcontrollerproxy.php | OxpsPaymorrowRequestControllerProxy._updateUserActiveShippingAddress | protected function _updateUserActiveShippingAddress( oxUser $oUser, array $aPostData )
{
/** @var oxAddress $oShippingAddress */
$oShippingAddress = $oUser->getSelectedAddress();
$blShowShippingAddress = (bool) oxRegistry::getSession()->getVariable( 'blshowshipaddress' );
if ( !$blShowShippingAddress or !( $oShippingAddress instanceof oxAddress ) or !$oShippingAddress->getId()
) {
return false;
}
return $oUser->mapShippingDataAndUpdateAddress( $aPostData, $oShippingAddress );
} | php | protected function _updateUserActiveShippingAddress( oxUser $oUser, array $aPostData )
{
/** @var oxAddress $oShippingAddress */
$oShippingAddress = $oUser->getSelectedAddress();
$blShowShippingAddress = (bool) oxRegistry::getSession()->getVariable( 'blshowshipaddress' );
if ( !$blShowShippingAddress or !( $oShippingAddress instanceof oxAddress ) or !$oShippingAddress->getId()
) {
return false;
}
return $oUser->mapShippingDataAndUpdateAddress( $aPostData, $oShippingAddress );
} | [
"protected",
"function",
"_updateUserActiveShippingAddress",
"(",
"oxUser",
"$",
"oUser",
",",
"array",
"$",
"aPostData",
")",
"{",
"/** @var oxAddress $oShippingAddress */",
"$",
"oShippingAddress",
"=",
"$",
"oUser",
"->",
"getSelectedAddress",
"(",
")",
";",
"$",
... | Get user active shipping address if it is used in the session and update it.
@param OxpsPaymorrowOxUser|oxUser $oUser
@param array $aPostData
@return bool | [
"Get",
"user",
"active",
"shipping",
"address",
"if",
"it",
"is",
"used",
"in",
"the",
"session",
"and",
"update",
"it",
"."
] | adb5d7f50c2fa5b566abd262161c483c42847b42 | https://github.com/OXID-eSales/paymorrow-module/blob/adb5d7f50c2fa5b566abd262161c483c42847b42/core/oxpspaymorrowrequestcontrollerproxy.php#L219-L231 | train |
hostnet/accessor-generator-plugin-lib | src/Generator/CodeGenerator.php | CodeGenerator.isAliased | private static function isAliased($name, array $imports): bool
{
$aliases = array_keys($imports);
foreach ($aliases as $alias) {
if (strpos($name, $alias) === 0) {
return true;
}
}
return false;
} | php | private static function isAliased($name, array $imports): bool
{
$aliases = array_keys($imports);
foreach ($aliases as $alias) {
if (strpos($name, $alias) === 0) {
return true;
}
}
return false;
} | [
"private",
"static",
"function",
"isAliased",
"(",
"$",
"name",
",",
"array",
"$",
"imports",
")",
":",
"bool",
"{",
"$",
"aliases",
"=",
"array_keys",
"(",
"$",
"imports",
")",
";",
"foreach",
"(",
"$",
"aliases",
"as",
"$",
"alias",
")",
"{",
"if",... | Returns true if the given class name is in an aliased namespace, false
otherwise.
@param string $name
@param string[] $imports
@return bool | [
"Returns",
"true",
"if",
"the",
"given",
"class",
"name",
"is",
"in",
"an",
"aliased",
"namespace",
"false",
"otherwise",
"."
] | 0ff78bed5dddb4bec9fd64500f822a28ce987f62 | https://github.com/hostnet/accessor-generator-plugin-lib/blob/0ff78bed5dddb4bec9fd64500f822a28ce987f62/src/Generator/CodeGenerator.php#L472-L482 | train |
hostnet/accessor-generator-plugin-lib | src/Generator/CodeGenerator.php | CodeGenerator.fqcn | private static function fqcn($name, array $imports): string
{
// Already FQCN
if ($name[0] === '\\') {
return $name;
}
// Aliased
if (array_key_exists($name, $imports)) {
return '\\' . $imports[$name];
}
// Check other imports
if ($plain = self::getPlainImportIfExists($name, $imports)) {
return '\\' . $plain;
}
// Not a complex type, or otherwise unknown.
return '';
} | php | private static function fqcn($name, array $imports): string
{
// Already FQCN
if ($name[0] === '\\') {
return $name;
}
// Aliased
if (array_key_exists($name, $imports)) {
return '\\' . $imports[$name];
}
// Check other imports
if ($plain = self::getPlainImportIfExists($name, $imports)) {
return '\\' . $plain;
}
// Not a complex type, or otherwise unknown.
return '';
} | [
"private",
"static",
"function",
"fqcn",
"(",
"$",
"name",
",",
"array",
"$",
"imports",
")",
":",
"string",
"{",
"// Already FQCN",
"if",
"(",
"$",
"name",
"[",
"0",
"]",
"===",
"'\\\\'",
")",
"{",
"return",
"$",
"name",
";",
"}",
"// Aliased",
"if"... | Return the fully qualified class name based on the use statements in
the current file.
@param string $name
@param string[] $imports
@return string | [
"Return",
"the",
"fully",
"qualified",
"class",
"name",
"based",
"on",
"the",
"use",
"statements",
"in",
"the",
"current",
"file",
"."
] | 0ff78bed5dddb4bec9fd64500f822a28ce987f62 | https://github.com/hostnet/accessor-generator-plugin-lib/blob/0ff78bed5dddb4bec9fd64500f822a28ce987f62/src/Generator/CodeGenerator.php#L508-L527 | train |
hostnet/accessor-generator-plugin-lib | src/Generator/CodeGenerator.php | CodeGenerator.getUniqueImports | private function getUniqueImports(array $imports): array
{
uksort($imports, function ($a, $b) use ($imports) {
$alias_a = is_numeric($a) ? " as $a;" : '';
$alias_b = is_numeric($b) ? " as $b;" : '';
return strcmp($imports[$a] . $alias_a, $imports[$b] . $alias_b);
});
$unique_imports = [];
$next = null;
do {
$key = key($imports);
$value = current($imports);
$next = next($imports);
if ($value === $next && $key === key($imports)) {
continue;
}
if ($key) {
$unique_imports[$key] = $value;
continue;
}
$unique_imports[] = $value;
} while ($next !== false);
return $unique_imports;
} | php | private function getUniqueImports(array $imports): array
{
uksort($imports, function ($a, $b) use ($imports) {
$alias_a = is_numeric($a) ? " as $a;" : '';
$alias_b = is_numeric($b) ? " as $b;" : '';
return strcmp($imports[$a] . $alias_a, $imports[$b] . $alias_b);
});
$unique_imports = [];
$next = null;
do {
$key = key($imports);
$value = current($imports);
$next = next($imports);
if ($value === $next && $key === key($imports)) {
continue;
}
if ($key) {
$unique_imports[$key] = $value;
continue;
}
$unique_imports[] = $value;
} while ($next !== false);
return $unique_imports;
} | [
"private",
"function",
"getUniqueImports",
"(",
"array",
"$",
"imports",
")",
":",
"array",
"{",
"uksort",
"(",
"$",
"imports",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"use",
"(",
"$",
"imports",
")",
"{",
"$",
"alias_a",
"=",
"is_numeric... | Make sure our use statements are sorted alphabetically and unique. The
array_unique function can not be used because it does not take values
with different array keys into account. This loop does exactly that.
This is useful when a specific class name is imported and aliased as
well.
@param string[] $imports
@return string[] | [
"Make",
"sure",
"our",
"use",
"statements",
"are",
"sorted",
"alphabetically",
"and",
"unique",
".",
"The",
"array_unique",
"function",
"can",
"not",
"be",
"used",
"because",
"it",
"does",
"not",
"take",
"values",
"with",
"different",
"array",
"keys",
"into",
... | 0ff78bed5dddb4bec9fd64500f822a28ce987f62 | https://github.com/hostnet/accessor-generator-plugin-lib/blob/0ff78bed5dddb4bec9fd64500f822a28ce987f62/src/Generator/CodeGenerator.php#L664-L693 | train |
hostnet/accessor-generator-plugin-lib | src/Generator/CodeGenerator.php | CodeGenerator.validateEnumEntity | private function validateEnumEntity(string $entity_class): void
{
if (false === \in_array(EnumeratorCompatibleEntityInterface::class, class_implements($entity_class))) {
throw new \LogicException(sprintf(
'The entity "%s" must implement "%s" in order to use it with enumerator accessor classes.',
$entity_class,
EnumeratorCompatibleEntityInterface::class
));
}
} | php | private function validateEnumEntity(string $entity_class): void
{
if (false === \in_array(EnumeratorCompatibleEntityInterface::class, class_implements($entity_class))) {
throw new \LogicException(sprintf(
'The entity "%s" must implement "%s" in order to use it with enumerator accessor classes.',
$entity_class,
EnumeratorCompatibleEntityInterface::class
));
}
} | [
"private",
"function",
"validateEnumEntity",
"(",
"string",
"$",
"entity_class",
")",
":",
"void",
"{",
"if",
"(",
"false",
"===",
"\\",
"in_array",
"(",
"EnumeratorCompatibleEntityInterface",
"::",
"class",
",",
"class_implements",
"(",
"$",
"entity_class",
")",
... | Ensures the entity class complies to the "standard" for holding parameters.
@param string $entity_class | [
"Ensures",
"the",
"entity",
"class",
"complies",
"to",
"the",
"standard",
"for",
"holding",
"parameters",
"."
] | 0ff78bed5dddb4bec9fd64500f822a28ce987f62 | https://github.com/hostnet/accessor-generator-plugin-lib/blob/0ff78bed5dddb4bec9fd64500f822a28ce987f62/src/Generator/CodeGenerator.php#L700-L709 | train |
techdivision/import-product | src/Subjects/BunchSubject.php | BunchSubject.getVisibilityIdByValue | public function getVisibilityIdByValue($visibility)
{
// query whether or not, the requested visibility is available
if (isset($this->availableVisibilities[$visibility])) {
// load the visibility ID, add the mapping and return the ID
return $this->availableVisibilities[$visibility];
}
// throw an exception, if not
throw new \Exception(
$this->appendExceptionSuffix(
sprintf('Found invalid visibility %s', $visibility)
)
);
} | php | public function getVisibilityIdByValue($visibility)
{
// query whether or not, the requested visibility is available
if (isset($this->availableVisibilities[$visibility])) {
// load the visibility ID, add the mapping and return the ID
return $this->availableVisibilities[$visibility];
}
// throw an exception, if not
throw new \Exception(
$this->appendExceptionSuffix(
sprintf('Found invalid visibility %s', $visibility)
)
);
} | [
"public",
"function",
"getVisibilityIdByValue",
"(",
"$",
"visibility",
")",
"{",
"// query whether or not, the requested visibility is available",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"availableVisibilities",
"[",
"$",
"visibility",
"]",
")",
")",
"{",
"// loa... | Return's the visibility key for the passed visibility string.
@param string $visibility The visibility string to return the key for
@return integer The requested visibility key
@throws \Exception Is thrown, if the requested visibility is not available | [
"Return",
"s",
"the",
"visibility",
"key",
"for",
"the",
"passed",
"visibility",
"string",
"."
] | a596e0c4b0495c918139935a709815c739d61e95 | https://github.com/techdivision/import-product/blob/a596e0c4b0495c918139935a709815c739d61e95/src/Subjects/BunchSubject.php#L238-L253 | train |
techdivision/import-product | src/Subjects/BunchSubject.php | BunchSubject.preLoadEntityId | public function preLoadEntityId(array $product)
{
$this->preLoadedEntityIds[$product[MemberNames::SKU]] = $product[MemberNames::ENTITY_ID];
} | php | public function preLoadEntityId(array $product)
{
$this->preLoadedEntityIds[$product[MemberNames::SKU]] = $product[MemberNames::ENTITY_ID];
} | [
"public",
"function",
"preLoadEntityId",
"(",
"array",
"$",
"product",
")",
"{",
"$",
"this",
"->",
"preLoadedEntityIds",
"[",
"$",
"product",
"[",
"MemberNames",
"::",
"SKU",
"]",
"]",
"=",
"$",
"product",
"[",
"MemberNames",
"::",
"ENTITY_ID",
"]",
";",
... | Pre-load the entity ID for the passed product.
@param array $product The product to be pre-loaded
@return void | [
"Pre",
"-",
"load",
"the",
"entity",
"ID",
"for",
"the",
"passed",
"product",
"."
] | a596e0c4b0495c918139935a709815c739d61e95 | https://github.com/techdivision/import-product/blob/a596e0c4b0495c918139935a709815c739d61e95/src/Subjects/BunchSubject.php#L274-L277 | train |
techdivision/import-product | src/Subjects/BunchSubject.php | BunchSubject.getProductCategoryIds | public function getProductCategoryIds()
{
// initialize the array with the product's category IDs
$categoryIds = array();
// query whether or not category IDs are available for the actual product entity
if (isset($this->productCategoryIds[$lastEntityId = $this->getLastEntityId()])) {
$categoryIds = $this->productCategoryIds[$lastEntityId];
}
// return the array with the product's category IDs
return $categoryIds;
} | php | public function getProductCategoryIds()
{
// initialize the array with the product's category IDs
$categoryIds = array();
// query whether or not category IDs are available for the actual product entity
if (isset($this->productCategoryIds[$lastEntityId = $this->getLastEntityId()])) {
$categoryIds = $this->productCategoryIds[$lastEntityId];
}
// return the array with the product's category IDs
return $categoryIds;
} | [
"public",
"function",
"getProductCategoryIds",
"(",
")",
"{",
"// initialize the array with the product's category IDs",
"$",
"categoryIds",
"=",
"array",
"(",
")",
";",
"// query whether or not category IDs are available for the actual product entity",
"if",
"(",
"isset",
"(",
... | Return's the list with category IDs the product is related with.
@return array The product's category IDs | [
"Return",
"s",
"the",
"list",
"with",
"category",
"IDs",
"the",
"product",
"is",
"related",
"with",
"."
] | a596e0c4b0495c918139935a709815c739d61e95 | https://github.com/techdivision/import-product/blob/a596e0c4b0495c918139935a709815c739d61e95/src/Subjects/BunchSubject.php#L284-L297 | train |
techdivision/import-product | src/Subjects/BunchSubject.php | BunchSubject.getEntityType | public function getEntityType()
{
// query whether or not the entity type with the passed code is available
if (isset($this->entityTypes[$entityTypeCode = $this->getEntityTypeCode()])) {
return $this->entityTypes[$entityTypeCode];
}
// throw a new exception
throw new \Exception(
$this->appendExceptionSuffix(
sprintf('Requested entity type "%s" is not available', $entityTypeCode)
)
);
} | php | public function getEntityType()
{
// query whether or not the entity type with the passed code is available
if (isset($this->entityTypes[$entityTypeCode = $this->getEntityTypeCode()])) {
return $this->entityTypes[$entityTypeCode];
}
// throw a new exception
throw new \Exception(
$this->appendExceptionSuffix(
sprintf('Requested entity type "%s" is not available', $entityTypeCode)
)
);
} | [
"public",
"function",
"getEntityType",
"(",
")",
"{",
"// query whether or not the entity type with the passed code is available",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"entityTypes",
"[",
"$",
"entityTypeCode",
"=",
"$",
"this",
"->",
"getEntityTypeCode",
"(",
... | Return's the entity type for the configured entity type code.
@return array The requested entity type
@throws \Exception Is thrown, if the requested entity type is not available | [
"Return",
"s",
"the",
"entity",
"type",
"for",
"the",
"configured",
"entity",
"type",
"code",
"."
] | a596e0c4b0495c918139935a709815c739d61e95 | https://github.com/techdivision/import-product/blob/a596e0c4b0495c918139935a709815c739d61e95/src/Subjects/BunchSubject.php#L305-L319 | train |
contributte/thepay-api | src/Helper/RadioMerchant.php | RadioMerchant.renderRadio | public function renderRadio(): string
{
$gateUrl = $this->config->gateUrl;
$queryArgs = [
'merchantId' => $this->config->merchantId,
'accountId' => $this->config->accountId,
'name' => $this->name,
'value' => $this->value,
'showIcon' => $this->showIcon,
'selected' => !empty($_REQUEST['tp_radio_value']) ? (int) $_REQUEST['tp_radio_value'] : '',
];
// Currency is an optional argument. For compatibility reasons, it is
// not present in the query at all if its value is empty.
if ($this->currency) {
$queryArgs['currency'] = $this->currency;
}
$queryArgs['signature'] = $this->createSignature($queryArgs);
$queryArgs = http_build_query($queryArgs);
$thepayGateUrl = "{$gateUrl}radiobuttons/index.php?{$queryArgs}";
$thepayGateUrl = Escaper::jsonEncode($thepayGateUrl);
$href = "{$gateUrl}radiobuttons/style/radiobuttons.css?v=" . time();
$out = "<link href=\"{$href}\" type=\"text/css\" rel=\"stylesheet\" />\n";
$out .= "<script type=\"text/javascript\">\n";
$out .= "\tvar thepayGateUrl = {$thepayGateUrl};\n";
if ($this->appendCode) {
$thepayAppendCode = Escaper::jsonEncode($this->appendCode);
$out .= "\tvar thepayAppendCode = {$thepayAppendCode};\n";
}
$out .= "</script>\n";
$src = "{$gateUrl}radiobuttons/js/jquery.js?v=" . time();
$out .= "<script type=\"text/javascript\" src=\"{$src}\" async=\"async\"></script>\n";
$src = "{$gateUrl}radiobuttons/js/radiobuttons.js?v=" . time();
$out .= "<script type=\"text/javascript\" src=\"{$src}\" async=\"async\"></script>\n";
$out .= "<div id=\"thepay-method-box\"></div>\n";
return $out;
} | php | public function renderRadio(): string
{
$gateUrl = $this->config->gateUrl;
$queryArgs = [
'merchantId' => $this->config->merchantId,
'accountId' => $this->config->accountId,
'name' => $this->name,
'value' => $this->value,
'showIcon' => $this->showIcon,
'selected' => !empty($_REQUEST['tp_radio_value']) ? (int) $_REQUEST['tp_radio_value'] : '',
];
// Currency is an optional argument. For compatibility reasons, it is
// not present in the query at all if its value is empty.
if ($this->currency) {
$queryArgs['currency'] = $this->currency;
}
$queryArgs['signature'] = $this->createSignature($queryArgs);
$queryArgs = http_build_query($queryArgs);
$thepayGateUrl = "{$gateUrl}radiobuttons/index.php?{$queryArgs}";
$thepayGateUrl = Escaper::jsonEncode($thepayGateUrl);
$href = "{$gateUrl}radiobuttons/style/radiobuttons.css?v=" . time();
$out = "<link href=\"{$href}\" type=\"text/css\" rel=\"stylesheet\" />\n";
$out .= "<script type=\"text/javascript\">\n";
$out .= "\tvar thepayGateUrl = {$thepayGateUrl};\n";
if ($this->appendCode) {
$thepayAppendCode = Escaper::jsonEncode($this->appendCode);
$out .= "\tvar thepayAppendCode = {$thepayAppendCode};\n";
}
$out .= "</script>\n";
$src = "{$gateUrl}radiobuttons/js/jquery.js?v=" . time();
$out .= "<script type=\"text/javascript\" src=\"{$src}\" async=\"async\"></script>\n";
$src = "{$gateUrl}radiobuttons/js/radiobuttons.js?v=" . time();
$out .= "<script type=\"text/javascript\" src=\"{$src}\" async=\"async\"></script>\n";
$out .= "<div id=\"thepay-method-box\"></div>\n";
return $out;
} | [
"public",
"function",
"renderRadio",
"(",
")",
":",
"string",
"{",
"$",
"gateUrl",
"=",
"$",
"this",
"->",
"config",
"->",
"gateUrl",
";",
"$",
"queryArgs",
"=",
"[",
"'merchantId'",
"=>",
"$",
"this",
"->",
"config",
"->",
"merchantId",
",",
"'accountId... | Generate HTML code for payment component.
@return string HTML code | [
"Generate",
"HTML",
"code",
"for",
"payment",
"component",
"."
] | 7e28eaf30ad1880533add93cf9e7296e61c09b8e | https://github.com/contributte/thepay-api/blob/7e28eaf30ad1880533add93cf9e7296e61c09b8e/src/Helper/RadioMerchant.php#L165-L209 | train |
contributte/thepay-api | src/Helper/RadioMerchant.php | RadioMerchant.showPaymentInstructions | public function showPaymentInstructions(Payment $payment): string
{
if (empty($_REQUEST['tp_radio_value']) || empty($_REQUEST['tp_radio_is_offline'])) {
return '';
}
$this->clearCookies();
$href = "{$this->config->gateUrl}radiobuttons/style/radiobuttons.css?v=" . time();
$href = Escaper::htmlEntityEncode($href);
$out = "<link href=\"{$href}\" type=\"text/css\" rel=\"stylesheet\" />\n";
$out .= "<script type=\"text/javascript\">\n";
$payment->setMethodId(intval($_REQUEST['tp_radio_value']));
$queryArgs = $payment->getArgs();
$queryArgs['signature'] = $payment->getSignature();
$thepayGateUrl = "{$this->config->gateUrl}?" . http_build_query($queryArgs);
$thepayGateUrl = Escaper::jsonEncode($thepayGateUrl);
$out .= "\tvar thepayGateUrl = {$thepayGateUrl},\n";
$thepayDisablePopupCss = Escaper::jsonEncode($this->disablePopupCss);
$out .= "\tthepayDisablePopupCss = {$thepayDisablePopupCss};\n";
$out .= "</script>\n";
$src = "{$this->config->gateUrl}radiobuttons/js/jquery.js?v=" . time();
$src = Escaper::htmlEntityEncode($src);
$out .= "<script type=\"text/javascript\" src=\"{$src}\" async=\"async\"></script>";
$src = "{$this->config->gateUrl}radiobuttons/js/radiobuttons.js?v=" . time();
$src = Escaper::htmlEntityEncode($src);
$out .= "<script type=\"text/javascript\" src=\"{$src}\" async=\"async\"></script>";
$out .= '<div id="thepay-method-result"></div>';
return $out;
} | php | public function showPaymentInstructions(Payment $payment): string
{
if (empty($_REQUEST['tp_radio_value']) || empty($_REQUEST['tp_radio_is_offline'])) {
return '';
}
$this->clearCookies();
$href = "{$this->config->gateUrl}radiobuttons/style/radiobuttons.css?v=" . time();
$href = Escaper::htmlEntityEncode($href);
$out = "<link href=\"{$href}\" type=\"text/css\" rel=\"stylesheet\" />\n";
$out .= "<script type=\"text/javascript\">\n";
$payment->setMethodId(intval($_REQUEST['tp_radio_value']));
$queryArgs = $payment->getArgs();
$queryArgs['signature'] = $payment->getSignature();
$thepayGateUrl = "{$this->config->gateUrl}?" . http_build_query($queryArgs);
$thepayGateUrl = Escaper::jsonEncode($thepayGateUrl);
$out .= "\tvar thepayGateUrl = {$thepayGateUrl},\n";
$thepayDisablePopupCss = Escaper::jsonEncode($this->disablePopupCss);
$out .= "\tthepayDisablePopupCss = {$thepayDisablePopupCss};\n";
$out .= "</script>\n";
$src = "{$this->config->gateUrl}radiobuttons/js/jquery.js?v=" . time();
$src = Escaper::htmlEntityEncode($src);
$out .= "<script type=\"text/javascript\" src=\"{$src}\" async=\"async\"></script>";
$src = "{$this->config->gateUrl}radiobuttons/js/radiobuttons.js?v=" . time();
$src = Escaper::htmlEntityEncode($src);
$out .= "<script type=\"text/javascript\" src=\"{$src}\" async=\"async\"></script>";
$out .= '<div id="thepay-method-result"></div>';
return $out;
} | [
"public",
"function",
"showPaymentInstructions",
"(",
"Payment",
"$",
"payment",
")",
":",
"string",
"{",
"if",
"(",
"empty",
"(",
"$",
"_REQUEST",
"[",
"'tp_radio_value'",
"]",
")",
"||",
"empty",
"(",
"$",
"_REQUEST",
"[",
"'tp_radio_is_offline'",
"]",
")"... | Show instruction for offline payment if ThePay payment method is selected and this method is offline.
Show output of this method somewhere on page with order confirmation.
@return string HTML code with component | [
"Show",
"instruction",
"for",
"offline",
"payment",
"if",
"ThePay",
"payment",
"method",
"is",
"selected",
"and",
"this",
"method",
"is",
"offline",
".",
"Show",
"output",
"of",
"this",
"method",
"somewhere",
"on",
"page",
"with",
"order",
"confirmation",
"."
... | 7e28eaf30ad1880533add93cf9e7296e61c09b8e | https://github.com/contributte/thepay-api/blob/7e28eaf30ad1880533add93cf9e7296e61c09b8e/src/Helper/RadioMerchant.php#L301-L338 | train |
techdivision/import-product | src/Observers/AbstractProductRelationUpdateObserver.php | AbstractProductRelationUpdateObserver.initializeProductRelation | protected function initializeProductRelation(array $attr)
{
// laod child/parent ID
$childId = $attr[MemberNames::CHILD_ID];
$parentId = $attr[MemberNames::PARENT_ID];
// query whether or not the product relation already exists
if ($this->loadProductRelation($parentId, $childId)) {
return;
}
// simply return the attributes
return $attr;
} | php | protected function initializeProductRelation(array $attr)
{
// laod child/parent ID
$childId = $attr[MemberNames::CHILD_ID];
$parentId = $attr[MemberNames::PARENT_ID];
// query whether or not the product relation already exists
if ($this->loadProductRelation($parentId, $childId)) {
return;
}
// simply return the attributes
return $attr;
} | [
"protected",
"function",
"initializeProductRelation",
"(",
"array",
"$",
"attr",
")",
"{",
"// laod child/parent ID",
"$",
"childId",
"=",
"$",
"attr",
"[",
"MemberNames",
"::",
"CHILD_ID",
"]",
";",
"$",
"parentId",
"=",
"$",
"attr",
"[",
"MemberNames",
"::",... | Initialize the product relation with the passed attributes and returns an instance.
@param array $attr The product relation attributes
@return array|null The initialized product relation, or null if the relation already exsist | [
"Initialize",
"the",
"product",
"relation",
"with",
"the",
"passed",
"attributes",
"and",
"returns",
"an",
"instance",
"."
] | a596e0c4b0495c918139935a709815c739d61e95 | https://github.com/techdivision/import-product/blob/a596e0c4b0495c918139935a709815c739d61e95/src/Observers/AbstractProductRelationUpdateObserver.php#L44-L58 | train |
techdivision/import-product | src/Repositories/ProductRepository.php | ProductRepository.findOneBySku | public function findOneBySku($sku)
{
// return the cached result if available
if ($this->isCached($sku)) {
return $this->fromCache($sku);
}
// if not, try to load the product with the passed SKU
$this->productStmt->execute(array(MemberNames::SKU => $sku));
// query whether or not the product is available in the database
if ($product = $this->productStmt->fetch(\PDO::FETCH_ASSOC)) {
// add the product to the cache, register the SKU reference as well
$this->toCache(
$product[$this->getPrimaryKeyName()],
$product,
array($sku => $product[$this->getPrimaryKeyName()])
);
// finally, return it
return $product;
}
} | php | public function findOneBySku($sku)
{
// return the cached result if available
if ($this->isCached($sku)) {
return $this->fromCache($sku);
}
// if not, try to load the product with the passed SKU
$this->productStmt->execute(array(MemberNames::SKU => $sku));
// query whether or not the product is available in the database
if ($product = $this->productStmt->fetch(\PDO::FETCH_ASSOC)) {
// add the product to the cache, register the SKU reference as well
$this->toCache(
$product[$this->getPrimaryKeyName()],
$product,
array($sku => $product[$this->getPrimaryKeyName()])
);
// finally, return it
return $product;
}
} | [
"public",
"function",
"findOneBySku",
"(",
"$",
"sku",
")",
"{",
"// return the cached result if available",
"if",
"(",
"$",
"this",
"->",
"isCached",
"(",
"$",
"sku",
")",
")",
"{",
"return",
"$",
"this",
"->",
"fromCache",
"(",
"$",
"sku",
")",
";",
"}... | Return's the product with the passed SKU.
@param string $sku The SKU of the product to return
@return array|null The product | [
"Return",
"s",
"the",
"product",
"with",
"the",
"passed",
"SKU",
"."
] | a596e0c4b0495c918139935a709815c739d61e95 | https://github.com/techdivision/import-product/blob/a596e0c4b0495c918139935a709815c739d61e95/src/Repositories/ProductRepository.php#L97-L119 | train |
RhubarbPHP/Rhubarb | src/Layout/LayoutModule.php | LayoutModule.getLayoutClassName | public static function getLayoutClassName()
{
if (is_callable(self::$layoutClassName)) {
$func = self::$layoutClassName;
return $func();
}
return self::$layoutClassName;
} | php | public static function getLayoutClassName()
{
if (is_callable(self::$layoutClassName)) {
$func = self::$layoutClassName;
return $func();
}
return self::$layoutClassName;
} | [
"public",
"static",
"function",
"getLayoutClassName",
"(",
")",
"{",
"if",
"(",
"is_callable",
"(",
"self",
"::",
"$",
"layoutClassName",
")",
")",
"{",
"$",
"func",
"=",
"self",
"::",
"$",
"layoutClassName",
";",
"return",
"$",
"func",
"(",
")",
";",
... | Returns the class name of the layout that should be used for the current request.
@return string | [
"Returns",
"the",
"class",
"name",
"of",
"the",
"layout",
"that",
"should",
"be",
"used",
"for",
"the",
"current",
"request",
"."
] | 327ff1f05d6a7e651d41c8e771f3551acfac18ae | https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Layout/LayoutModule.php#L74-L82 | train |
RhubarbPHP/Rhubarb | src/Sendables/SendableProvider.php | SendableProvider.selectProviderAndSend | public static function selectProviderAndSend(Sendable $sendable)
{
$provider = self::createProviderForSendable($sendable);
$provider->send($sendable);
} | php | public static function selectProviderAndSend(Sendable $sendable)
{
$provider = self::createProviderForSendable($sendable);
$provider->send($sendable);
} | [
"public",
"static",
"function",
"selectProviderAndSend",
"(",
"Sendable",
"$",
"sendable",
")",
"{",
"$",
"provider",
"=",
"self",
"::",
"createProviderForSendable",
"(",
"$",
"sendable",
")",
";",
"$",
"provider",
"->",
"send",
"(",
"$",
"sendable",
")",
";... | Selects the currently registered concrete provider for the sendable's base type of provider and
passes it the sendable for sending.
@param Sendable $sendable | [
"Selects",
"the",
"currently",
"registered",
"concrete",
"provider",
"for",
"the",
"sendable",
"s",
"base",
"type",
"of",
"provider",
"and",
"passes",
"it",
"the",
"sendable",
"for",
"sending",
"."
] | 327ff1f05d6a7e651d41c8e771f3551acfac18ae | https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Sendables/SendableProvider.php#L41-L45 | train |
RhubarbPHP/Rhubarb | src/Assets/AssetUrlHandler.php | AssetUrlHandler.getAsset | protected function getAsset()
{
$asset = AssetCatalogueProvider::getAsset($this->token);
if ($this->assetCategory != $asset->getProviderData()["category"]) {
throw new AssetExposureException($this->token);
}
return $asset;
} | php | protected function getAsset()
{
$asset = AssetCatalogueProvider::getAsset($this->token);
if ($this->assetCategory != $asset->getProviderData()["category"]) {
throw new AssetExposureException($this->token);
}
return $asset;
} | [
"protected",
"function",
"getAsset",
"(",
")",
"{",
"$",
"asset",
"=",
"AssetCatalogueProvider",
"::",
"getAsset",
"(",
"$",
"this",
"->",
"token",
")",
";",
"if",
"(",
"$",
"this",
"->",
"assetCategory",
"!=",
"$",
"asset",
"->",
"getProviderData",
"(",
... | Gets the asset for the current URL
@return Asset
@throws AssetExposureException | [
"Gets",
"the",
"asset",
"for",
"the",
"current",
"URL"
] | 327ff1f05d6a7e651d41c8e771f3551acfac18ae | https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Assets/AssetUrlHandler.php#L174-L183 | train |
RhubarbPHP/Rhubarb | src/Mime/MimePartBinaryFile.php | MimePartBinaryFile.fromLocalPath | public static function fromLocalPath($path, $name = "")
{
if ($name == "") {
$name = basename($path);
}
$part = new MimePartBinaryFile();
$part->setTransformedBody(file_get_contents($path));
$part->addHeader("Content-Disposition", "attachment; filename=\"" . $name . "\"");
return $part;
} | php | public static function fromLocalPath($path, $name = "")
{
if ($name == "") {
$name = basename($path);
}
$part = new MimePartBinaryFile();
$part->setTransformedBody(file_get_contents($path));
$part->addHeader("Content-Disposition", "attachment; filename=\"" . $name . "\"");
return $part;
} | [
"public",
"static",
"function",
"fromLocalPath",
"(",
"$",
"path",
",",
"$",
"name",
"=",
"\"\"",
")",
"{",
"if",
"(",
"$",
"name",
"==",
"\"\"",
")",
"{",
"$",
"name",
"=",
"basename",
"(",
"$",
"path",
")",
";",
"}",
"$",
"part",
"=",
"new",
... | Creates an instance to represent a file stored locally.
@param $path
@param string $name
@return MimePartBinaryFile | [
"Creates",
"an",
"instance",
"to",
"represent",
"a",
"file",
"stored",
"locally",
"."
] | 327ff1f05d6a7e651d41c8e771f3551acfac18ae | https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Mime/MimePartBinaryFile.php#L38-L49 | train |
RhubarbPHP/Rhubarb | src/Assets/LocalStorageAssetCatalogueProvider.php | LocalStorageAssetCatalogueProvider.getCategoryDirectory | private function getCategoryDirectory()
{
if (!$this->category){
return "_default";
}
$category = preg_replace("/\\W/","-",$this->category);
$category = preg_replace("/-+/","-",$category);
$category .= crc32($this->category);
return $category;
} | php | private function getCategoryDirectory()
{
if (!$this->category){
return "_default";
}
$category = preg_replace("/\\W/","-",$this->category);
$category = preg_replace("/-+/","-",$category);
$category .= crc32($this->category);
return $category;
} | [
"private",
"function",
"getCategoryDirectory",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"category",
")",
"{",
"return",
"\"_default\"",
";",
"}",
"$",
"category",
"=",
"preg_replace",
"(",
"\"/\\\\W/\"",
",",
"\"-\"",
",",
"$",
"this",
"->",
"ca... | Makes the category name safe to use for a file path but guaranteed unique.
e.g. This! and This@ should both work. | [
"Makes",
"the",
"category",
"name",
"safe",
"to",
"use",
"for",
"a",
"file",
"path",
"but",
"guaranteed",
"unique",
"."
] | 327ff1f05d6a7e651d41c8e771f3551acfac18ae | https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Assets/LocalStorageAssetCatalogueProvider.php#L61-L72 | train |
RhubarbPHP/Rhubarb | src/Assets/LocalStorageAssetCatalogueProvider.php | LocalStorageAssetCatalogueProvider.getAssetPath | protected function getAssetPath(Asset $asset):string
{
// Get the file name from the provider data
$data = $asset->getProviderData();
$path = $this->getRootPath() . "/" . $this->getCategoryDirectory() . "/" . $data["file"];
return $path;
} | php | protected function getAssetPath(Asset $asset):string
{
// Get the file name from the provider data
$data = $asset->getProviderData();
$path = $this->getRootPath() . "/" . $this->getCategoryDirectory() . "/" . $data["file"];
return $path;
} | [
"protected",
"function",
"getAssetPath",
"(",
"Asset",
"$",
"asset",
")",
":",
"string",
"{",
"// Get the file name from the provider data",
"$",
"data",
"=",
"$",
"asset",
"->",
"getProviderData",
"(",
")",
";",
"$",
"path",
"=",
"$",
"this",
"->",
"getRootPa... | Returns the local path for the given asset.
@param Asset $asset
@return string | [
"Returns",
"the",
"local",
"path",
"for",
"the",
"given",
"asset",
"."
] | 327ff1f05d6a7e651d41c8e771f3551acfac18ae | https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Assets/LocalStorageAssetCatalogueProvider.php#L144-L150 | train |
RhubarbPHP/Rhubarb | src/Encryption/Sha512HashProvider.php | Sha512HashProvider.createHash | public function createHash($data, $salt = false)
{
if ($salt === false) {
$salt = sha1(uniqid("sillystring", true) . microtime());
}
$raw = crypt($data, '$6$rounds=10000$' . $salt . '$');
return $raw;
} | php | public function createHash($data, $salt = false)
{
if ($salt === false) {
$salt = sha1(uniqid("sillystring", true) . microtime());
}
$raw = crypt($data, '$6$rounds=10000$' . $salt . '$');
return $raw;
} | [
"public",
"function",
"createHash",
"(",
"$",
"data",
",",
"$",
"salt",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"salt",
"===",
"false",
")",
"{",
"$",
"salt",
"=",
"sha1",
"(",
"uniqid",
"(",
"\"sillystring\"",
",",
"true",
")",
".",
"microtime",
"... | Create's a new hash of the supplied data using the optionally supplied salt.
It's expected that the salt can be randomised if not supplied. This is fact
preferable in nearly all occasions as the salt should be included in the return
value.
@param string $data
@param string|bool $salt
@return string | [
"Create",
"s",
"a",
"new",
"hash",
"of",
"the",
"supplied",
"data",
"using",
"the",
"optionally",
"supplied",
"salt",
"."
] | 327ff1f05d6a7e651d41c8e771f3551acfac18ae | https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Encryption/Sha512HashProvider.php#L37-L46 | train |
RhubarbPHP/Rhubarb | src/Encryption/Sha512HashProvider.php | Sha512HashProvider.compareHash | public function compareHash($data, $hash)
{
$salt = $this->extractSalt($hash);
$newHash = $this->createHash($data, $salt);
return ($newHash == $hash);
} | php | public function compareHash($data, $hash)
{
$salt = $this->extractSalt($hash);
$newHash = $this->createHash($data, $salt);
return ($newHash == $hash);
} | [
"public",
"function",
"compareHash",
"(",
"$",
"data",
",",
"$",
"hash",
")",
"{",
"$",
"salt",
"=",
"$",
"this",
"->",
"extractSalt",
"(",
"$",
"hash",
")",
";",
"$",
"newHash",
"=",
"$",
"this",
"->",
"createHash",
"(",
"$",
"data",
",",
"$",
"... | Computes the hash of the supplied data using the salt contained within an existing hash.
If the resultant value matches the hash the hash and data are equivilant.
@param $data
@param $hash
@return bool | [
"Computes",
"the",
"hash",
"of",
"the",
"supplied",
"data",
"using",
"the",
"salt",
"contained",
"within",
"an",
"existing",
"hash",
"."
] | 327ff1f05d6a7e651d41c8e771f3551acfac18ae | https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Encryption/Sha512HashProvider.php#L70-L77 | train |
RhubarbPHP/Rhubarb | src/Assets/AssetCatalogueProvider.php | AssetCatalogueProvider.storeAsset | public static function storeAsset($filePath, $category, $storeAs = "")
{
// A sane default
$mime = "application/octet-stream";
$name = ($storeAs == "") ? basename($filePath) : $storeAs;
// CSV is detected as text/plain - change this if.
if (preg_match("/\\.csv$/i", $name)){
$mime = "text/csv";
} else {
if (function_exists("finfo_open")) {
$info = new \finfo(FILEINFO_MIME);
$mime = $info->file($filePath);
}
}
$provider = self::getProvider($category);
try {
$asset = $provider->createAssetFromFile($filePath, [
"name" => $name,
"size" => filesize($filePath),
"mimeType" => $mime,
"category" => $category
]);
$asset->mimeType = $mime;
return $asset;
} catch (AssetException $er){
Log::error("Error creating asset from file '$filePath': ".$er->getPrivateMessage());
throw $er;
}
return null;
} | php | public static function storeAsset($filePath, $category, $storeAs = "")
{
// A sane default
$mime = "application/octet-stream";
$name = ($storeAs == "") ? basename($filePath) : $storeAs;
// CSV is detected as text/plain - change this if.
if (preg_match("/\\.csv$/i", $name)){
$mime = "text/csv";
} else {
if (function_exists("finfo_open")) {
$info = new \finfo(FILEINFO_MIME);
$mime = $info->file($filePath);
}
}
$provider = self::getProvider($category);
try {
$asset = $provider->createAssetFromFile($filePath, [
"name" => $name,
"size" => filesize($filePath),
"mimeType" => $mime,
"category" => $category
]);
$asset->mimeType = $mime;
return $asset;
} catch (AssetException $er){
Log::error("Error creating asset from file '$filePath': ".$er->getPrivateMessage());
throw $er;
}
return null;
} | [
"public",
"static",
"function",
"storeAsset",
"(",
"$",
"filePath",
",",
"$",
"category",
",",
"$",
"storeAs",
"=",
"\"\"",
")",
"{",
"// A sane default",
"$",
"mime",
"=",
"\"application/octet-stream\"",
";",
"$",
"name",
"=",
"(",
"$",
"storeAs",
"==",
"... | Stores an asset currently held in a local file in a given asset category
@param string $filePath
@param string $category
@return Asset | [
"Stores",
"an",
"asset",
"currently",
"held",
"in",
"a",
"local",
"file",
"in",
"a",
"given",
"asset",
"category"
] | 327ff1f05d6a7e651d41c8e771f3551acfac18ae | https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Assets/AssetCatalogueProvider.php#L49-L84 | train |
RhubarbPHP/Rhubarb | src/Assets/AssetCatalogueProvider.php | AssetCatalogueProvider.getJwtKey | private static function getJwtKey()
{
$settings = AssetCatalogueSettings::singleton();
$key = $settings->jwtKey;
if ($key == "") {
throw new AssetException("", "No token key is defined in AssetCatalogueSettings");
}
return $key;
} | php | private static function getJwtKey()
{
$settings = AssetCatalogueSettings::singleton();
$key = $settings->jwtKey;
if ($key == "") {
throw new AssetException("", "No token key is defined in AssetCatalogueSettings");
}
return $key;
} | [
"private",
"static",
"function",
"getJwtKey",
"(",
")",
"{",
"$",
"settings",
"=",
"AssetCatalogueSettings",
"::",
"singleton",
"(",
")",
";",
"$",
"key",
"=",
"$",
"settings",
"->",
"jwtKey",
";",
"if",
"(",
"$",
"key",
"==",
"\"\"",
")",
"{",
"throw"... | Gets the key used to sign JWT tokens.
@return string
@throws AssetException | [
"Gets",
"the",
"key",
"used",
"to",
"sign",
"JWT",
"tokens",
"."
] | 327ff1f05d6a7e651d41c8e771f3551acfac18ae | https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Assets/AssetCatalogueProvider.php#L99-L109 | train |
RhubarbPHP/Rhubarb | src/Assets/AssetCatalogueProvider.php | AssetCatalogueProvider.createToken | protected function createToken($data)
{
$key = self::getJwtKey();
$token = array(
"iat" => time(),
"provider" => get_class($this),
"category" => $this->category,
"data" => $data
);
$jwt = JWT::encode($token, $key);
return $jwt;
} | php | protected function createToken($data)
{
$key = self::getJwtKey();
$token = array(
"iat" => time(),
"provider" => get_class($this),
"category" => $this->category,
"data" => $data
);
$jwt = JWT::encode($token, $key);
return $jwt;
} | [
"protected",
"function",
"createToken",
"(",
"$",
"data",
")",
"{",
"$",
"key",
"=",
"self",
"::",
"getJwtKey",
"(",
")",
";",
"$",
"token",
"=",
"array",
"(",
"\"iat\"",
"=>",
"time",
"(",
")",
",",
"\"provider\"",
"=>",
"get_class",
"(",
"$",
"this... | Creates a JWT token to encode an asset using the passed data array.
@param $data
@return string
@throws AssetException | [
"Creates",
"a",
"JWT",
"token",
"to",
"encode",
"an",
"asset",
"using",
"the",
"passed",
"data",
"array",
"."
] | 327ff1f05d6a7e651d41c8e771f3551acfac18ae | https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Assets/AssetCatalogueProvider.php#L142-L156 | train |
RhubarbPHP/Rhubarb | src/Assets/AssetCatalogueProvider.php | AssetCatalogueProvider.getAsset | public static function getAsset($token)
{
$key = self::getJwtKey();
$payload = JWT::decode($token, $key, array('HS256'));
$providerClass = $payload->provider;
$category = $payload->category;
$data = (array) $payload->data;
$provider = new $providerClass($category);
return new Asset($token, $provider, $data);
} | php | public static function getAsset($token)
{
$key = self::getJwtKey();
$payload = JWT::decode($token, $key, array('HS256'));
$providerClass = $payload->provider;
$category = $payload->category;
$data = (array) $payload->data;
$provider = new $providerClass($category);
return new Asset($token, $provider, $data);
} | [
"public",
"static",
"function",
"getAsset",
"(",
"$",
"token",
")",
"{",
"$",
"key",
"=",
"self",
"::",
"getJwtKey",
"(",
")",
";",
"$",
"payload",
"=",
"JWT",
"::",
"decode",
"(",
"$",
"token",
",",
"$",
"key",
",",
"array",
"(",
"'HS256'",
")",
... | Recreates an asset from the data in the passed token.
@param $token
@return Asset
@throws AssetException | [
"Recreates",
"an",
"asset",
"from",
"the",
"data",
"in",
"the",
"passed",
"token",
"."
] | 327ff1f05d6a7e651d41c8e771f3551acfac18ae | https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Assets/AssetCatalogueProvider.php#L165-L178 | train |
RhubarbPHP/Rhubarb | src/Assets/AssetCatalogueProvider.php | AssetCatalogueProvider.getProvider | public static function getProvider($assetCategory = "")
{
if (isset(self::$providerMap[$assetCategory])) {
$class = self::$providerMap[$assetCategory];
} elseif (isset(self::$providerMap[""])){
$class = self::$providerMap[""];
} else {
throw new AssetException("", "No provider mapping could be found for category '".$assetCategory."'");
}
$provider = new $class($assetCategory);
return $provider;
} | php | public static function getProvider($assetCategory = "")
{
if (isset(self::$providerMap[$assetCategory])) {
$class = self::$providerMap[$assetCategory];
} elseif (isset(self::$providerMap[""])){
$class = self::$providerMap[""];
} else {
throw new AssetException("", "No provider mapping could be found for category '".$assetCategory."'");
}
$provider = new $class($assetCategory);
return $provider;
} | [
"public",
"static",
"function",
"getProvider",
"(",
"$",
"assetCategory",
"=",
"\"\"",
")",
"{",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"providerMap",
"[",
"$",
"assetCategory",
"]",
")",
")",
"{",
"$",
"class",
"=",
"self",
"::",
"$",
"providerMa... | Returns an instance of the correct provider for a given category
@param string $assetCategory The category of provider - or empty for the default provider
@return AssetCatalogueProvider
@throws AssetException Thrown if a provider could not be found for the given category | [
"Returns",
"an",
"instance",
"of",
"the",
"correct",
"provider",
"for",
"a",
"given",
"category"
] | 327ff1f05d6a7e651d41c8e771f3551acfac18ae | https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Assets/AssetCatalogueProvider.php#L198-L211 | train |
duncan3dc/cache | src/CacheKeyTrait.php | CacheKeyTrait.validateKey | protected function validateKey($key)
{
if (!is_string($key)) {
throw new CacheKeyException("Cache key must be a string, " . gettype($key) . " given");
}
if (preg_match("/[^A-Za-z0-9\._-]/", $key)) {
throw new CacheKeyException("Cache key contains invalid characters: {$key}");
}
if (strlen($key) > 64) {
throw new CacheKeyException("Cache key cannot be longer than 64 characters: {$key}");
}
} | php | protected function validateKey($key)
{
if (!is_string($key)) {
throw new CacheKeyException("Cache key must be a string, " . gettype($key) . " given");
}
if (preg_match("/[^A-Za-z0-9\._-]/", $key)) {
throw new CacheKeyException("Cache key contains invalid characters: {$key}");
}
if (strlen($key) > 64) {
throw new CacheKeyException("Cache key cannot be longer than 64 characters: {$key}");
}
} | [
"protected",
"function",
"validateKey",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"CacheKeyException",
"(",
"\"Cache key must be a string, \"",
".",
"gettype",
"(",
"$",
"key",
")",
".",
"\" giv... | Check the passed key to ensure it's a valid cache key.
@param string $key
@return void
@throws CacheKeyException | [
"Check",
"the",
"passed",
"key",
"to",
"ensure",
"it",
"s",
"a",
"valid",
"cache",
"key",
"."
] | 826c4ce2ed03c9df64aa8e0440b9e02b8c0f5eb0 | https://github.com/duncan3dc/cache/blob/826c4ce2ed03c9df64aa8e0440b9e02b8c0f5eb0/src/CacheKeyTrait.php#L21-L34 | train |
duncan3dc/cache | src/SimpleCacheTrait.php | SimpleCacheTrait.set | public function set($key, $value, $ttl = null)
{
$item = new Item($key, $value);
if ($ttl !== null) {
$item->expiresAfter($ttl);
}
return $this->save($item);
} | php | public function set($key, $value, $ttl = null)
{
$item = new Item($key, $value);
if ($ttl !== null) {
$item->expiresAfter($ttl);
}
return $this->save($item);
} | [
"public",
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"ttl",
"=",
"null",
")",
"{",
"$",
"item",
"=",
"new",
"Item",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"if",
"(",
"$",
"ttl",
"!==",
"null",
")",
"{",
"$",
"it... | Persists data in the cache, uniquely referenced by a key.
@param string $key The key of the item to store
@param mixed $value The value of the item to store, must be serializable
@param \DateInterval|int|null $ttl The TTL value of this item
@return bool | [
"Persists",
"data",
"in",
"the",
"cache",
"uniquely",
"referenced",
"by",
"a",
"key",
"."
] | 826c4ce2ed03c9df64aa8e0440b9e02b8c0f5eb0 | https://github.com/duncan3dc/cache/blob/826c4ce2ed03c9df64aa8e0440b9e02b8c0f5eb0/src/SimpleCacheTrait.php#L41-L48 | train |
RhubarbPHP/Rhubarb | src/Module.php | Module.getUrlHandlers | protected final function getUrlHandlers()
{
if (!$this->urlHandlersRegistered){
$this->registerUrlHandlers();
$this->urlHandlersRegistered = true;
}
return $this->urlHandlers;
} | php | protected final function getUrlHandlers()
{
if (!$this->urlHandlersRegistered){
$this->registerUrlHandlers();
$this->urlHandlersRegistered = true;
}
return $this->urlHandlers;
} | [
"protected",
"final",
"function",
"getUrlHandlers",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"urlHandlersRegistered",
")",
"{",
"$",
"this",
"->",
"registerUrlHandlers",
"(",
")",
";",
"$",
"this",
"->",
"urlHandlersRegistered",
"=",
"true",
";",
... | Get the finalised collection of url handlers for the module
@return UrlHandlers\UrlHandler[] | [
"Get",
"the",
"finalised",
"collection",
"of",
"url",
"handlers",
"for",
"the",
"module"
] | 327ff1f05d6a7e651d41c8e771f3551acfac18ae | https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Module.php#L142-L150 | train |
RhubarbPHP/Rhubarb | src/Sendables/Email/Email.php | Email.addAttachment | public function addAttachment($path, $newName = "")
{
if ($newName == "") {
$newName = basename($path);
}
$file = new \stdClass();
$file->path = $path;
$file->name = $newName;
$this->attachments[] = $file;
return $this;
} | php | public function addAttachment($path, $newName = "")
{
if ($newName == "") {
$newName = basename($path);
}
$file = new \stdClass();
$file->path = $path;
$file->name = $newName;
$this->attachments[] = $file;
return $this;
} | [
"public",
"function",
"addAttachment",
"(",
"$",
"path",
",",
"$",
"newName",
"=",
"\"\"",
")",
"{",
"if",
"(",
"$",
"newName",
"==",
"\"\"",
")",
"{",
"$",
"newName",
"=",
"basename",
"(",
"$",
"path",
")",
";",
"}",
"$",
"file",
"=",
"new",
"\\... | Adds an attachment
@param string $path The path to the local file
@param string $newName Optionally specify a new name for the file.
@return $this | [
"Adds",
"an",
"attachment"
] | 327ff1f05d6a7e651d41c8e771f3551acfac18ae | https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Sendables/Email/Email.php#L46-L59 | train |
RhubarbPHP/Rhubarb | src/Sendables/Email/Email.php | Email.getMimeDocument | public function getMimeDocument()
{
$textPart = false;
$htmlPart = false;
$html = $this->getHtml();
$text = $this->getText();
$subject = $this->getSubject();
/**
* @var string|bool Tracks which part should contain the text and html parts.
*/
$alternativePart = false;
if (count($this->attachments) > 0) {
$mime = new MimeDocument("multipart/mixed", crc32($html) . crc32($text) . crc32($subject));
} else {
$mime = new MimeDocument("multipart/alternative", crc32($html) . crc32($text) . crc32($subject));
// The outer mime part is our alternative part
$alternativePart = $mime;
}
if ($text != "") {
$textPart = new MimePartText("text/plain");
$textPart->setTransformedBody($text);
}
if ($html != "") {
$htmlPart = new MimePartText("text/html");
$htmlPart->setTransformedBody($html);
}
if ($text != "" && $html != "") {
if (count($this->attachments) > 0) {
// As this email has attachments we need to create an alternative part to store the text and html
$alternativePart = new MimeDocument("multipart/alternative");
$mime->addPart($alternativePart);
}
$alternativePart->addPart($textPart);
$alternativePart->addPart($htmlPart);
} else {
if ($text != "") {
$mime->addPart($textPart);
}
if ($html != "") {
$mime->addPart($htmlPart);
}
}
foreach ($this->attachments as $attachment) {
$mime->addPart(MimePartBinaryFile::fromLocalPath($attachment->path, $attachment->name));
}
$mime->addHeader("To", $this->getRecipientList());
$mime->addHeader("From", $this->getSender()->getRfcFormat());
$mime->addHeader("Subject", $this->getSubject());
$mime->addHeader("Reply-To", $this->getReplyToRecipient());
return $mime;
} | php | public function getMimeDocument()
{
$textPart = false;
$htmlPart = false;
$html = $this->getHtml();
$text = $this->getText();
$subject = $this->getSubject();
/**
* @var string|bool Tracks which part should contain the text and html parts.
*/
$alternativePart = false;
if (count($this->attachments) > 0) {
$mime = new MimeDocument("multipart/mixed", crc32($html) . crc32($text) . crc32($subject));
} else {
$mime = new MimeDocument("multipart/alternative", crc32($html) . crc32($text) . crc32($subject));
// The outer mime part is our alternative part
$alternativePart = $mime;
}
if ($text != "") {
$textPart = new MimePartText("text/plain");
$textPart->setTransformedBody($text);
}
if ($html != "") {
$htmlPart = new MimePartText("text/html");
$htmlPart->setTransformedBody($html);
}
if ($text != "" && $html != "") {
if (count($this->attachments) > 0) {
// As this email has attachments we need to create an alternative part to store the text and html
$alternativePart = new MimeDocument("multipart/alternative");
$mime->addPart($alternativePart);
}
$alternativePart->addPart($textPart);
$alternativePart->addPart($htmlPart);
} else {
if ($text != "") {
$mime->addPart($textPart);
}
if ($html != "") {
$mime->addPart($htmlPart);
}
}
foreach ($this->attachments as $attachment) {
$mime->addPart(MimePartBinaryFile::fromLocalPath($attachment->path, $attachment->name));
}
$mime->addHeader("To", $this->getRecipientList());
$mime->addHeader("From", $this->getSender()->getRfcFormat());
$mime->addHeader("Subject", $this->getSubject());
$mime->addHeader("Reply-To", $this->getReplyToRecipient());
return $mime;
} | [
"public",
"function",
"getMimeDocument",
"(",
")",
"{",
"$",
"textPart",
"=",
"false",
";",
"$",
"htmlPart",
"=",
"false",
";",
"$",
"html",
"=",
"$",
"this",
"->",
"getHtml",
"(",
")",
";",
"$",
"text",
"=",
"$",
"this",
"->",
"getText",
"(",
")",... | Gets a MimeDocument to represent this email.
@return MimeDocument | [
"Gets",
"a",
"MimeDocument",
"to",
"represent",
"this",
"email",
"."
] | 327ff1f05d6a7e651d41c8e771f3551acfac18ae | https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Sendables/Email/Email.php#L176-L239 | train |
RhubarbPHP/Rhubarb | src/Sendables/Email/Email.php | Email.getMailHeaders | public function getMailHeaders()
{
$headers = [];
$html = $this->getHtml();
$text = $this->getText();
$subject = $this->getSubject();
if ($html != "" || count($this->attachments) > 0) {
$mime = new MimeDocument("multipart/alternative", crc32($html) . crc32($text) . crc32($subject));
$headers = $mime->getHeaders();
} else {
$headers["Content-Type"] = "text/plain; charset=utf-8";
}
$headers["From"] = (string)$this->getSender();
$headers["Subject"] = $subject;
return $headers;
} | php | public function getMailHeaders()
{
$headers = [];
$html = $this->getHtml();
$text = $this->getText();
$subject = $this->getSubject();
if ($html != "" || count($this->attachments) > 0) {
$mime = new MimeDocument("multipart/alternative", crc32($html) . crc32($text) . crc32($subject));
$headers = $mime->getHeaders();
} else {
$headers["Content-Type"] = "text/plain; charset=utf-8";
}
$headers["From"] = (string)$this->getSender();
$headers["Subject"] = $subject;
return $headers;
} | [
"public",
"function",
"getMailHeaders",
"(",
")",
"{",
"$",
"headers",
"=",
"[",
"]",
";",
"$",
"html",
"=",
"$",
"this",
"->",
"getHtml",
"(",
")",
";",
"$",
"text",
"=",
"$",
"this",
"->",
"getText",
"(",
")",
";",
"$",
"subject",
"=",
"$",
"... | Returns the mail headers as an array of key value pairs.
@return array | [
"Returns",
"the",
"mail",
"headers",
"as",
"an",
"array",
"of",
"key",
"value",
"pairs",
"."
] | 327ff1f05d6a7e651d41c8e771f3551acfac18ae | https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Sendables/Email/Email.php#L274-L293 | train |
rchouinard/bencode | src/Decoder.php | Decoder.doDecode | private function doDecode()
{
switch ($this->getChar()) {
case "i":
++$this->offset;
return $this->decodeInteger();
case "l":
++$this->offset;
return $this->decodeList();
case "d":
++$this->offset;
return $this->decodeDict();
default:
if (ctype_digit($this->getChar())) {
return $this->decodeString();
}
}
throw new RuntimeException("Unknown entity found at offset $this->offset");
} | php | private function doDecode()
{
switch ($this->getChar()) {
case "i":
++$this->offset;
return $this->decodeInteger();
case "l":
++$this->offset;
return $this->decodeList();
case "d":
++$this->offset;
return $this->decodeDict();
default:
if (ctype_digit($this->getChar())) {
return $this->decodeString();
}
}
throw new RuntimeException("Unknown entity found at offset $this->offset");
} | [
"private",
"function",
"doDecode",
"(",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"getChar",
"(",
")",
")",
"{",
"case",
"\"i\"",
":",
"++",
"$",
"this",
"->",
"offset",
";",
"return",
"$",
"this",
"->",
"decodeInteger",
"(",
")",
";",
"case",
"\... | Iterate over encoded entities in the source string and decode them
@return mixed Returns the decoded value.
@throws RuntimeException | [
"Iterate",
"over",
"encoded",
"entities",
"in",
"the",
"source",
"string",
"and",
"decode",
"them"
] | 7caeb1d9823897701a5901369cfdc326696c679c | https://github.com/rchouinard/bencode/blob/7caeb1d9823897701a5901369cfdc326696c679c/src/Decoder.php#L101-L125 | train |
rchouinard/bencode | src/Decoder.php | Decoder.decodeInteger | private function decodeInteger()
{
$offsetOfE = strpos($this->source, "e", $this->offset);
if (false === $offsetOfE) {
throw new RuntimeException("Unterminated integer entity at offset $this->offset");
}
$currentOffset = $this->offset;
if ("-" == $this->getChar($currentOffset)) {
++$currentOffset;
}
if ($offsetOfE === $currentOffset) {
throw new RuntimeException("Empty integer entity at offset $this->offset");
}
while ($currentOffset < $offsetOfE) {
if (!ctype_digit($this->getChar($currentOffset))) {
throw new RuntimeException("Non-numeric character found in integer entity at offset $this->offset");
}
++$currentOffset;
}
$value = substr($this->source, $this->offset, $offsetOfE - $this->offset);
// One last check to make sure zero-padded integers don't slip by, as
// they're not allowed per bencode specification.
$absoluteValue = (string) abs($value);
if (1 < strlen($absoluteValue) && "0" == $value[0]) {
throw new RuntimeException("Illegal zero-padding found in integer entity at offset $this->offset");
}
$this->offset = $offsetOfE + 1;
// The +0 auto-casts the chunk to either an integer or a float(in cases
// where an integer would overrun the max limits of integer types)
return $value + 0;
} | php | private function decodeInteger()
{
$offsetOfE = strpos($this->source, "e", $this->offset);
if (false === $offsetOfE) {
throw new RuntimeException("Unterminated integer entity at offset $this->offset");
}
$currentOffset = $this->offset;
if ("-" == $this->getChar($currentOffset)) {
++$currentOffset;
}
if ($offsetOfE === $currentOffset) {
throw new RuntimeException("Empty integer entity at offset $this->offset");
}
while ($currentOffset < $offsetOfE) {
if (!ctype_digit($this->getChar($currentOffset))) {
throw new RuntimeException("Non-numeric character found in integer entity at offset $this->offset");
}
++$currentOffset;
}
$value = substr($this->source, $this->offset, $offsetOfE - $this->offset);
// One last check to make sure zero-padded integers don't slip by, as
// they're not allowed per bencode specification.
$absoluteValue = (string) abs($value);
if (1 < strlen($absoluteValue) && "0" == $value[0]) {
throw new RuntimeException("Illegal zero-padding found in integer entity at offset $this->offset");
}
$this->offset = $offsetOfE + 1;
// The +0 auto-casts the chunk to either an integer or a float(in cases
// where an integer would overrun the max limits of integer types)
return $value + 0;
} | [
"private",
"function",
"decodeInteger",
"(",
")",
"{",
"$",
"offsetOfE",
"=",
"strpos",
"(",
"$",
"this",
"->",
"source",
",",
"\"e\"",
",",
"$",
"this",
"->",
"offset",
")",
";",
"if",
"(",
"false",
"===",
"$",
"offsetOfE",
")",
"{",
"throw",
"new",... | Decode a bencode encoded integer
@return integer Returns the decoded integer.
@throws RuntimeException | [
"Decode",
"a",
"bencode",
"encoded",
"integer"
] | 7caeb1d9823897701a5901369cfdc326696c679c | https://github.com/rchouinard/bencode/blob/7caeb1d9823897701a5901369cfdc326696c679c/src/Decoder.php#L133-L170 | train |
rchouinard/bencode | src/Decoder.php | Decoder.decodeList | private function decodeList()
{
$list = array();
$terminated = false;
$listOffset = $this->offset;
while (false !== $this->getChar()) {
if ("e" == $this->getChar()) {
$terminated = true;
break;
}
$list[] = $this->doDecode();
}
if (!$terminated && false === $this->getChar()) {
throw new RuntimeException("Unterminated list definition at offset $listOffset");
}
$this->offset++;
return $list;
} | php | private function decodeList()
{
$list = array();
$terminated = false;
$listOffset = $this->offset;
while (false !== $this->getChar()) {
if ("e" == $this->getChar()) {
$terminated = true;
break;
}
$list[] = $this->doDecode();
}
if (!$terminated && false === $this->getChar()) {
throw new RuntimeException("Unterminated list definition at offset $listOffset");
}
$this->offset++;
return $list;
} | [
"private",
"function",
"decodeList",
"(",
")",
"{",
"$",
"list",
"=",
"array",
"(",
")",
";",
"$",
"terminated",
"=",
"false",
";",
"$",
"listOffset",
"=",
"$",
"this",
"->",
"offset",
";",
"while",
"(",
"false",
"!==",
"$",
"this",
"->",
"getChar",
... | Decode a bencode encoded list
@return array Returns the decoded array.
@throws RuntimeException | [
"Decode",
"a",
"bencode",
"encoded",
"list"
] | 7caeb1d9823897701a5901369cfdc326696c679c | https://github.com/rchouinard/bencode/blob/7caeb1d9823897701a5901369cfdc326696c679c/src/Decoder.php#L206-L228 | train |
rchouinard/bencode | src/Decoder.php | Decoder.decodeDict | private function decodeDict()
{
$dict = array();
$terminated = false;
$dictOffset = $this->offset;
while (false !== $this->getChar()) {
if ("e" == $this->getChar()) {
$terminated = true;
break;
}
$keyOffset = $this->offset;
if (!ctype_digit($this->getChar())) {
throw new RuntimeException("Invalid dictionary key at offset $keyOffset");
}
$key = $this->decodeString();
if (isset ($dict[$key])) {
throw new RuntimeException("Duplicate dictionary key at offset $keyOffset");
}
$dict[$key] = $this->doDecode();
}
if (!$terminated && false === $this->getChar()) {
throw new RuntimeException("Unterminated dictionary definition at offset $dictOffset");
}
$this->offset++;
return $dict;
} | php | private function decodeDict()
{
$dict = array();
$terminated = false;
$dictOffset = $this->offset;
while (false !== $this->getChar()) {
if ("e" == $this->getChar()) {
$terminated = true;
break;
}
$keyOffset = $this->offset;
if (!ctype_digit($this->getChar())) {
throw new RuntimeException("Invalid dictionary key at offset $keyOffset");
}
$key = $this->decodeString();
if (isset ($dict[$key])) {
throw new RuntimeException("Duplicate dictionary key at offset $keyOffset");
}
$dict[$key] = $this->doDecode();
}
if (!$terminated && false === $this->getChar()) {
throw new RuntimeException("Unterminated dictionary definition at offset $dictOffset");
}
$this->offset++;
return $dict;
} | [
"private",
"function",
"decodeDict",
"(",
")",
"{",
"$",
"dict",
"=",
"array",
"(",
")",
";",
"$",
"terminated",
"=",
"false",
";",
"$",
"dictOffset",
"=",
"$",
"this",
"->",
"offset",
";",
"while",
"(",
"false",
"!==",
"$",
"this",
"->",
"getChar",
... | Decode a bencode encoded dictionary
@return array Returns the decoded array.
@throws RuntimeException | [
"Decode",
"a",
"bencode",
"encoded",
"dictionary"
] | 7caeb1d9823897701a5901369cfdc326696c679c | https://github.com/rchouinard/bencode/blob/7caeb1d9823897701a5901369cfdc326696c679c/src/Decoder.php#L236-L268 | train |
rchouinard/bencode | src/Decoder.php | Decoder.getChar | private function getChar($offset = null)
{
if (null === $offset) {
$offset = $this->offset;
}
if (empty ($this->source) || $this->offset >= $this->sourceLength) {
return false;
}
return $this->source[$offset];
} | php | private function getChar($offset = null)
{
if (null === $offset) {
$offset = $this->offset;
}
if (empty ($this->source) || $this->offset >= $this->sourceLength) {
return false;
}
return $this->source[$offset];
} | [
"private",
"function",
"getChar",
"(",
"$",
"offset",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"offset",
")",
"{",
"$",
"offset",
"=",
"$",
"this",
"->",
"offset",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"source",
")",
... | Fetch the character at the specified source offset
If offset is not provided, the current offset is used.
@param integer $offset The offset to retrieve from the source string.
@return string|false Returns the character found at the specified
offset. If the specified offset is out of range, FALSE is returned. | [
"Fetch",
"the",
"character",
"at",
"the",
"specified",
"source",
"offset"
] | 7caeb1d9823897701a5901369cfdc326696c679c | https://github.com/rchouinard/bencode/blob/7caeb1d9823897701a5901369cfdc326696c679c/src/Decoder.php#L279-L290 | train |
RhubarbPHP/Rhubarb | src/Mime/MimePart.php | MimePart.getTransformedBody | final public function getTransformedBody()
{
$encoding = (isset($this->headers["Content-Transfer-Encoding"])) ? $this->headers["Content-Transfer-Encoding"] : "";
$rawBody = $this->getRawBody();
switch ($encoding) {
case "quoted-printable":
return quoted_printable_decode($rawBody);
break;
case "base64":
return base64_decode($rawBody);
break;
default:
return $rawBody;
}
} | php | final public function getTransformedBody()
{
$encoding = (isset($this->headers["Content-Transfer-Encoding"])) ? $this->headers["Content-Transfer-Encoding"] : "";
$rawBody = $this->getRawBody();
switch ($encoding) {
case "quoted-printable":
return quoted_printable_decode($rawBody);
break;
case "base64":
return base64_decode($rawBody);
break;
default:
return $rawBody;
}
} | [
"final",
"public",
"function",
"getTransformedBody",
"(",
")",
"{",
"$",
"encoding",
"=",
"(",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"\"Content-Transfer-Encoding\"",
"]",
")",
")",
"?",
"$",
"this",
"->",
"headers",
"[",
"\"Content-Transfer-Encoding... | Transforms the part as per the transform encoding header and returns the transformed result. | [
"Transforms",
"the",
"part",
"as",
"per",
"the",
"transform",
"encoding",
"header",
"and",
"returns",
"the",
"transformed",
"result",
"."
] | 327ff1f05d6a7e651d41c8e771f3551acfac18ae | https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Mime/MimePart.php#L70-L86 | train |
RhubarbPHP/Rhubarb | src/Mime/MimePart.php | MimePart.setTransformedBody | final public function setTransformedBody($transformedBody)
{
$encoding = (isset($this->headers["Content-Transfer-Encoding"])) ? $this->headers["Content-Transfer-Encoding"] : "";
switch ($encoding) {
case "quoted-printable":
$this->setRawBody(quoted_printable_encode($transformedBody));
break;
case "base64":
$this->setRawBody(chunk_split(base64_encode($transformedBody), 76));
break;
default:
$this->setRawBody($transformedBody);
}
} | php | final public function setTransformedBody($transformedBody)
{
$encoding = (isset($this->headers["Content-Transfer-Encoding"])) ? $this->headers["Content-Transfer-Encoding"] : "";
switch ($encoding) {
case "quoted-printable":
$this->setRawBody(quoted_printable_encode($transformedBody));
break;
case "base64":
$this->setRawBody(chunk_split(base64_encode($transformedBody), 76));
break;
default:
$this->setRawBody($transformedBody);
}
} | [
"final",
"public",
"function",
"setTransformedBody",
"(",
"$",
"transformedBody",
")",
"{",
"$",
"encoding",
"=",
"(",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"\"Content-Transfer-Encoding\"",
"]",
")",
")",
"?",
"$",
"this",
"->",
"headers",
"[",
... | Takes a transformed body and turns it into the raw body string needed for the mime encoding.
@param $transformedBody | [
"Takes",
"a",
"transformed",
"body",
"and",
"turns",
"it",
"into",
"the",
"raw",
"body",
"string",
"needed",
"for",
"the",
"mime",
"encoding",
"."
] | 327ff1f05d6a7e651d41c8e771f3551acfac18ae | https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Mime/MimePart.php#L93-L107 | train |
rchouinard/bencode | src/Encoder.php | Encoder.encode | public static function encode($data)
{
if (is_object($data)) {
if (method_exists($data, "toArray")) {
$data = $data->toArray();
} else {
$data = (array) $data;
}
}
$encoder = new self($data);
$encoded = $encoder->doEncode();
return $encoded;
} | php | public static function encode($data)
{
if (is_object($data)) {
if (method_exists($data, "toArray")) {
$data = $data->toArray();
} else {
$data = (array) $data;
}
}
$encoder = new self($data);
$encoded = $encoder->doEncode();
return $encoded;
} | [
"public",
"static",
"function",
"encode",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"data",
")",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"data",
",",
"\"toArray\"",
")",
")",
"{",
"$",
"data",
"=",
"$",
"data",
"->",
"... | Encode a value into a bencode encoded string
@param mixed $data The value to encode.
@return string Returns the bencode encoded string. | [
"Encode",
"a",
"value",
"into",
"a",
"bencode",
"encoded",
"string"
] | 7caeb1d9823897701a5901369cfdc326696c679c | https://github.com/rchouinard/bencode/blob/7caeb1d9823897701a5901369cfdc326696c679c/src/Encoder.php#L47-L61 | train |
rchouinard/bencode | src/Encoder.php | Encoder.doEncode | private function doEncode($data = null)
{
$data = is_null($data) ? $this->data : $data;
if (is_array($data) && (isset ($data[0]) || empty ($data))) {
return $this->encodeList($data);
} elseif (is_array($data)) {
return $this->encodeDict($data);
} elseif (is_integer($data) || is_float($data)) {
$data = sprintf("%.0f", round($data, 0));
return $this->encodeInteger($data);
} else {
return $this->encodeString($data);
}
} | php | private function doEncode($data = null)
{
$data = is_null($data) ? $this->data : $data;
if (is_array($data) && (isset ($data[0]) || empty ($data))) {
return $this->encodeList($data);
} elseif (is_array($data)) {
return $this->encodeDict($data);
} elseif (is_integer($data) || is_float($data)) {
$data = sprintf("%.0f", round($data, 0));
return $this->encodeInteger($data);
} else {
return $this->encodeString($data);
}
} | [
"private",
"function",
"doEncode",
"(",
"$",
"data",
"=",
"null",
")",
"{",
"$",
"data",
"=",
"is_null",
"(",
"$",
"data",
")",
"?",
"$",
"this",
"->",
"data",
":",
"$",
"data",
";",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
"&&",
"(",
"iss... | Iterate over values and encode them
@param mixed $data The value to encode.
@return string Returns the bencode encoded string. | [
"Iterate",
"over",
"values",
"and",
"encode",
"them"
] | 7caeb1d9823897701a5901369cfdc326696c679c | https://github.com/rchouinard/bencode/blob/7caeb1d9823897701a5901369cfdc326696c679c/src/Encoder.php#L69-L83 | train |
rchouinard/bencode | src/Encoder.php | Encoder.encodeInteger | private function encodeInteger($data = null)
{
$data = is_null($data) ? $this->data : $data;
return sprintf("i%.0fe", $data);
} | php | private function encodeInteger($data = null)
{
$data = is_null($data) ? $this->data : $data;
return sprintf("i%.0fe", $data);
} | [
"private",
"function",
"encodeInteger",
"(",
"$",
"data",
"=",
"null",
")",
"{",
"$",
"data",
"=",
"is_null",
"(",
"$",
"data",
")",
"?",
"$",
"this",
"->",
"data",
":",
"$",
"data",
";",
"return",
"sprintf",
"(",
"\"i%.0fe\"",
",",
"$",
"data",
")... | Encode an integer
@param integer $data The integer to be encoded.
@return string Returns the bencode encoded integer. | [
"Encode",
"an",
"integer"
] | 7caeb1d9823897701a5901369cfdc326696c679c | https://github.com/rchouinard/bencode/blob/7caeb1d9823897701a5901369cfdc326696c679c/src/Encoder.php#L91-L95 | train |
rchouinard/bencode | src/Encoder.php | Encoder.encodeString | private function encodeString($data = null)
{
$data = is_null($data) ? $this->data : $data;
return sprintf("%d:%s", strlen($data), $data);
} | php | private function encodeString($data = null)
{
$data = is_null($data) ? $this->data : $data;
return sprintf("%d:%s", strlen($data), $data);
} | [
"private",
"function",
"encodeString",
"(",
"$",
"data",
"=",
"null",
")",
"{",
"$",
"data",
"=",
"is_null",
"(",
"$",
"data",
")",
"?",
"$",
"this",
"->",
"data",
":",
"$",
"data",
";",
"return",
"sprintf",
"(",
"\"%d:%s\"",
",",
"strlen",
"(",
"$... | Encode a string
@param string $data The string to be encoded.
@return string Returns the bencode encoded string. | [
"Encode",
"a",
"string"
] | 7caeb1d9823897701a5901369cfdc326696c679c | https://github.com/rchouinard/bencode/blob/7caeb1d9823897701a5901369cfdc326696c679c/src/Encoder.php#L103-L107 | train |
rchouinard/bencode | src/Encoder.php | Encoder.encodeList | private function encodeList(array $data = null)
{
$data = is_null($data) ? $this->data : $data;
$list = "";
foreach ($data as $value) {
$list .= $this->doEncode($value);
}
return "l{$list}e";
} | php | private function encodeList(array $data = null)
{
$data = is_null($data) ? $this->data : $data;
$list = "";
foreach ($data as $value) {
$list .= $this->doEncode($value);
}
return "l{$list}e";
} | [
"private",
"function",
"encodeList",
"(",
"array",
"$",
"data",
"=",
"null",
")",
"{",
"$",
"data",
"=",
"is_null",
"(",
"$",
"data",
")",
"?",
"$",
"this",
"->",
"data",
":",
"$",
"data",
";",
"$",
"list",
"=",
"\"\"",
";",
"foreach",
"(",
"$",
... | Encode a list
@param array $data The list to be encoded.
@return string Returns the bencode encoded list. | [
"Encode",
"a",
"list"
] | 7caeb1d9823897701a5901369cfdc326696c679c | https://github.com/rchouinard/bencode/blob/7caeb1d9823897701a5901369cfdc326696c679c/src/Encoder.php#L115-L125 | train |
rchouinard/bencode | src/Encoder.php | Encoder.encodeDict | private function encodeDict(array $data = null)
{
$data = is_null($data) ? $this->data : $data;
ksort($data); // bencode spec requires dicts to be sorted alphabetically
$dict = "";
foreach ($data as $key => $value) {
$dict .= $this->encodeString($key) . $this->doEncode($value);
}
return "d{$dict}e";
} | php | private function encodeDict(array $data = null)
{
$data = is_null($data) ? $this->data : $data;
ksort($data); // bencode spec requires dicts to be sorted alphabetically
$dict = "";
foreach ($data as $key => $value) {
$dict .= $this->encodeString($key) . $this->doEncode($value);
}
return "d{$dict}e";
} | [
"private",
"function",
"encodeDict",
"(",
"array",
"$",
"data",
"=",
"null",
")",
"{",
"$",
"data",
"=",
"is_null",
"(",
"$",
"data",
")",
"?",
"$",
"this",
"->",
"data",
":",
"$",
"data",
";",
"ksort",
"(",
"$",
"data",
")",
";",
"// bencode spec ... | Encode a dictionary
@param array $data The dictionary to be encoded.
@return string Returns the bencode encoded dictionary. | [
"Encode",
"a",
"dictionary"
] | 7caeb1d9823897701a5901369cfdc326696c679c | https://github.com/rchouinard/bencode/blob/7caeb1d9823897701a5901369cfdc326696c679c/src/Encoder.php#L133-L144 | train |
RhubarbPHP/Rhubarb | src/Mime/MimeDocument.php | MimeDocument.fromString | public static function fromString($documentString)
{
$document = new MimeDocument($documentString);
$lines = explode("\n", $documentString);
$boundary = false;
$nextPartLines = [];
$firstBoundaryFound = false;
$mimeMessage = "";
foreach ($lines as $line) {
$line = trim($line);
if (!$boundary) {
if (preg_match("/Content-Type: (multipart\/.+);\s+boundary=\"?([^\"]+)\"?/i", $line, $match)) {
$document->boundary = $match[2];
$document->setContentType($match[1]);
$boundary = $match[2];
continue;
}
} else {
if ($line == "--" . $boundary . "--") {
$part = MimePart::fromLines($nextPartLines);
$document->addPart($part);
break;
}
if ($line == "--" . $boundary) {
if (!$firstBoundaryFound) {
$firstBoundaryFound = true;
} else {
$part = MimePart::fromLines($nextPartLines);
$document->addPart($part);
$nextPartLines = [];
}
} else {
if ($firstBoundaryFound) {
$nextPartLines[] = $line;
} else {
$mimeMessage .= $line . "\r\n";
}
}
}
}
$document->setMessage(trim($mimeMessage));
return $document;
} | php | public static function fromString($documentString)
{
$document = new MimeDocument($documentString);
$lines = explode("\n", $documentString);
$boundary = false;
$nextPartLines = [];
$firstBoundaryFound = false;
$mimeMessage = "";
foreach ($lines as $line) {
$line = trim($line);
if (!$boundary) {
if (preg_match("/Content-Type: (multipart\/.+);\s+boundary=\"?([^\"]+)\"?/i", $line, $match)) {
$document->boundary = $match[2];
$document->setContentType($match[1]);
$boundary = $match[2];
continue;
}
} else {
if ($line == "--" . $boundary . "--") {
$part = MimePart::fromLines($nextPartLines);
$document->addPart($part);
break;
}
if ($line == "--" . $boundary) {
if (!$firstBoundaryFound) {
$firstBoundaryFound = true;
} else {
$part = MimePart::fromLines($nextPartLines);
$document->addPart($part);
$nextPartLines = [];
}
} else {
if ($firstBoundaryFound) {
$nextPartLines[] = $line;
} else {
$mimeMessage .= $line . "\r\n";
}
}
}
}
$document->setMessage(trim($mimeMessage));
return $document;
} | [
"public",
"static",
"function",
"fromString",
"(",
"$",
"documentString",
")",
"{",
"$",
"document",
"=",
"new",
"MimeDocument",
"(",
"$",
"documentString",
")",
";",
"$",
"lines",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"documentString",
")",
";",
"$",
... | Creates a document from a MIME string.
Note this currently only supports a single level of MIME - no nesting.
@param $documentString
@return MimeDocument | [
"Creates",
"a",
"document",
"from",
"a",
"MIME",
"string",
"."
] | 327ff1f05d6a7e651d41c8e771f3551acfac18ae | https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Mime/MimeDocument.php#L125-L176 | train |
RhubarbPHP/Rhubarb | src/Html/ResourceLoader.php | ResourceLoader.addScriptCode | public static function addScriptCode($scriptCode, $dependantResourceUrls = [])
{
$dependantResourceUrls = array_unique($dependantResourceUrls);
self::$resources[] = [$scriptCode, $dependantResourceUrls];
} | php | public static function addScriptCode($scriptCode, $dependantResourceUrls = [])
{
$dependantResourceUrls = array_unique($dependantResourceUrls);
self::$resources[] = [$scriptCode, $dependantResourceUrls];
} | [
"public",
"static",
"function",
"addScriptCode",
"(",
"$",
"scriptCode",
",",
"$",
"dependantResourceUrls",
"=",
"[",
"]",
")",
"{",
"$",
"dependantResourceUrls",
"=",
"array_unique",
"(",
"$",
"dependantResourceUrls",
")",
";",
"self",
"::",
"$",
"resources",
... | Adds javascript script code to the collection
@param $scriptCode
@param array $dependantResourceUrls | [
"Adds",
"javascript",
"script",
"code",
"to",
"the",
"collection"
] | 327ff1f05d6a7e651d41c8e771f3551acfac18ae | https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Html/ResourceLoader.php#L34-L39 | train |
RhubarbPHP/Rhubarb | src/Modelling/ModelState.php | ModelState.addPropertyChangedNotificationHandler | final public function addPropertyChangedNotificationHandler($propertyNames, $callback)
{
if (!is_array($propertyNames)) {
$propertyNames = [$propertyNames];
}
foreach ($propertyNames as $propertyName) {
$this->propertyChangedCallbacks[$propertyName][] = $callback;
}
} | php | final public function addPropertyChangedNotificationHandler($propertyNames, $callback)
{
if (!is_array($propertyNames)) {
$propertyNames = [$propertyNames];
}
foreach ($propertyNames as $propertyName) {
$this->propertyChangedCallbacks[$propertyName][] = $callback;
}
} | [
"final",
"public",
"function",
"addPropertyChangedNotificationHandler",
"(",
"$",
"propertyNames",
",",
"$",
"callback",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"propertyNames",
")",
")",
"{",
"$",
"propertyNames",
"=",
"[",
"$",
"propertyNames",
"]",
... | When the named properties are changed, the callable method provided will be called and passed details of the change.
@param string|string[] $propertyNames The name of a property, or an array of property names
@param callable $callback A callable which will receive 3 parameters: $newValue, $propertyName, $oldValue | [
"When",
"the",
"named",
"properties",
"are",
"changed",
"the",
"callable",
"method",
"provided",
"will",
"be",
"called",
"and",
"passed",
"details",
"of",
"the",
"change",
"."
] | 327ff1f05d6a7e651d41c8e771f3551acfac18ae | https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Modelling/ModelState.php#L84-L93 | train |
RhubarbPHP/Rhubarb | src/Modelling/ModelState.php | ModelState.setModelValue | final protected function setModelValue($propertyName, $value)
{
try {
$oldValue = (isset($this->modelData[$propertyName])) ? $this->modelData[$propertyName]: null;
} catch (\Exception $ex) {
// Catch any exceptions thrown when trying to retrieve the old value for the sake
// of comparison to trigger the property changed handlers.
$oldValue = null;
}
$this->modelData[$propertyName] = $value;
if ($value instanceof ModelState) {
$this->attachChangeListenerToModelProperty($propertyName, $value);
}
if ($oldValue != $value) {
if (!$this->propertyChangeEventsDisabled) {
// Don't fire changes if they are disabled.
$this->raisePropertyChangedCallbacks($propertyName, $value, $oldValue);
$this->traitRaiseEvent("AfterChange", $this);
}
}
} | php | final protected function setModelValue($propertyName, $value)
{
try {
$oldValue = (isset($this->modelData[$propertyName])) ? $this->modelData[$propertyName]: null;
} catch (\Exception $ex) {
// Catch any exceptions thrown when trying to retrieve the old value for the sake
// of comparison to trigger the property changed handlers.
$oldValue = null;
}
$this->modelData[$propertyName] = $value;
if ($value instanceof ModelState) {
$this->attachChangeListenerToModelProperty($propertyName, $value);
}
if ($oldValue != $value) {
if (!$this->propertyChangeEventsDisabled) {
// Don't fire changes if they are disabled.
$this->raisePropertyChangedCallbacks($propertyName, $value, $oldValue);
$this->traitRaiseEvent("AfterChange", $this);
}
}
} | [
"final",
"protected",
"function",
"setModelValue",
"(",
"$",
"propertyName",
",",
"$",
"value",
")",
"{",
"try",
"{",
"$",
"oldValue",
"=",
"(",
"isset",
"(",
"$",
"this",
"->",
"modelData",
"[",
"$",
"propertyName",
"]",
")",
")",
"?",
"$",
"this",
... | Sets a models property value while also raising property changed notifications if appropriate.
This should be used from setters instead of changing $this->modelData directly.
@param $propertyName
@param $value | [
"Sets",
"a",
"models",
"property",
"value",
"while",
"also",
"raising",
"property",
"changed",
"notifications",
"if",
"appropriate",
"."
] | 327ff1f05d6a7e651d41c8e771f3551acfac18ae | https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Modelling/ModelState.php#L123-L146 | train |
RhubarbPHP/Rhubarb | src/Modelling/ModelState.php | ModelState.exportPublicData | final public function exportPublicData()
{
$publicProperties = $this->getPublicPropertyList();
$data = [];
foreach ($publicProperties as $property) {
if (isset($this[$property])) {
$data[$property] = $this[$property];
}
}
return $data;
} | php | final public function exportPublicData()
{
$publicProperties = $this->getPublicPropertyList();
$data = [];
foreach ($publicProperties as $property) {
if (isset($this[$property])) {
$data[$property] = $this[$property];
}
}
return $data;
} | [
"final",
"public",
"function",
"exportPublicData",
"(",
")",
"{",
"$",
"publicProperties",
"=",
"$",
"this",
"->",
"getPublicPropertyList",
"(",
")",
";",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"publicProperties",
"as",
"$",
"property",
")",... | Exports an array of model values that have been marked safe for public consumption.
@return array | [
"Exports",
"an",
"array",
"of",
"model",
"values",
"that",
"have",
"been",
"marked",
"safe",
"for",
"public",
"consumption",
"."
] | 327ff1f05d6a7e651d41c8e771f3551acfac18ae | https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Modelling/ModelState.php#L215-L228 | train |
RhubarbPHP/Rhubarb | src/Modelling/ModelState.php | ModelState.importData | final public function importData($data)
{
foreach ($data as $property => $value) {
if ($this[$property] instanceof ModelState){
$this[$property]->importData($value);
} else {
$this[$property] = $value;
}
}
} | php | final public function importData($data)
{
foreach ($data as $property => $value) {
if ($this[$property] instanceof ModelState){
$this[$property]->importData($value);
} else {
$this[$property] = $value;
}
}
} | [
"final",
"public",
"function",
"importData",
"(",
"$",
"data",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"property",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"[",
"$",
"property",
"]",
"instanceof",
"ModelState",
")",
"{",
"$",
... | Imports an array of model values that have been marked safe for public consumption.
@param array $data | [
"Imports",
"an",
"array",
"of",
"model",
"values",
"that",
"have",
"been",
"marked",
"safe",
"for",
"public",
"consumption",
"."
] | 327ff1f05d6a7e651d41c8e771f3551acfac18ae | https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Modelling/ModelState.php#L262-L271 | train |
RhubarbPHP/Rhubarb | src/Modelling/ModelState.php | ModelState.hasChanged | public function hasChanged()
{
foreach ($this->modelData as $property => $value) {
if ($this->hasPropertyChanged($property)) {
return true;
}
}
// In case model data has been manually unset
$manuallyUnsetProperties = array_diff_key($this->changeSnapshotData, $this->modelData);
foreach ($manuallyUnsetProperties as $property => $value) {
// If it wasn't null before, that's a change
if ($value !== null) {
return true;
}
}
return false;
} | php | public function hasChanged()
{
foreach ($this->modelData as $property => $value) {
if ($this->hasPropertyChanged($property)) {
return true;
}
}
// In case model data has been manually unset
$manuallyUnsetProperties = array_diff_key($this->changeSnapshotData, $this->modelData);
foreach ($manuallyUnsetProperties as $property => $value) {
// If it wasn't null before, that's a change
if ($value !== null) {
return true;
}
}
return false;
} | [
"public",
"function",
"hasChanged",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"modelData",
"as",
"$",
"property",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasPropertyChanged",
"(",
"$",
"property",
")",
")",
"{",
"return",
... | Returns true if the model has changed
@return bool | [
"Returns",
"true",
"if",
"the",
"model",
"has",
"changed"
] | 327ff1f05d6a7e651d41c8e771f3551acfac18ae | https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Modelling/ModelState.php#L278-L296 | train |
RhubarbPHP/Rhubarb | src/Modelling/ModelState.php | ModelState.takeChangeSnapshot | public function takeChangeSnapshot()
{
$this->changeSnapshotData = $this->modelData;
foreach ($this->changeSnapshotData as $key => $value) {
if (is_object($value)) {
$this->changeSnapshotData[$key] = clone $value;
}
}
return $this->changeSnapshotData;
} | php | public function takeChangeSnapshot()
{
$this->changeSnapshotData = $this->modelData;
foreach ($this->changeSnapshotData as $key => $value) {
if (is_object($value)) {
$this->changeSnapshotData[$key] = clone $value;
}
}
return $this->changeSnapshotData;
} | [
"public",
"function",
"takeChangeSnapshot",
"(",
")",
"{",
"$",
"this",
"->",
"changeSnapshotData",
"=",
"$",
"this",
"->",
"modelData",
";",
"foreach",
"(",
"$",
"this",
"->",
"changeSnapshotData",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"... | Takes a snapshot of the model data into change state data.
Essentially this resets the change status on the model object. HasChanged() should return
false after a call to this.
@return array | [
"Takes",
"a",
"snapshot",
"of",
"the",
"model",
"data",
"into",
"change",
"state",
"data",
"."
] | 327ff1f05d6a7e651d41c8e771f3551acfac18ae | https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Modelling/ModelState.php#L306-L317 | train |
RhubarbPHP/Rhubarb | src/Modelling/ModelState.php | ModelState.importRawData | public function importRawData($data)
{
$this->modelData = $data;
foreach ($data as $propertyName => $item) {
if ($item instanceof ModelState) {
$this->attachChangeListenerToModelProperty($propertyName, $item);
}
}
// Make sure we can track changes in existing models.
$this->takeChangeSnapshot();
$this->onDataImported();
} | php | public function importRawData($data)
{
$this->modelData = $data;
foreach ($data as $propertyName => $item) {
if ($item instanceof ModelState) {
$this->attachChangeListenerToModelProperty($propertyName, $item);
}
}
// Make sure we can track changes in existing models.
$this->takeChangeSnapshot();
$this->onDataImported();
} | [
"public",
"function",
"importRawData",
"(",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"modelData",
"=",
"$",
"data",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"propertyName",
"=>",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"instanceof",
"Mode... | Imports raw model data into the model.
The data does not pass through any applicable Set methods or data transforms. If required to do so
call ImportData() instead, but understand the performance penalty of doing so.
@param array $data | [
"Imports",
"raw",
"model",
"data",
"into",
"the",
"model",
"."
] | 327ff1f05d6a7e651d41c8e771f3551acfac18ae | https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Modelling/ModelState.php#L423-L437 | train |
RhubarbPHP/Rhubarb | src/Modelling/ModelState.php | ModelState.attachChangeListenerToModelProperty | private function attachChangeListenerToModelProperty($propertyName, ModelState $item)
{
$item->clearEventHandlers();
$item->attachEventHandler("AfterChange", function () use ($propertyName, $item) {
$this->raisePropertyChangedCallbacks($propertyName, $item, null);
});
} | php | private function attachChangeListenerToModelProperty($propertyName, ModelState $item)
{
$item->clearEventHandlers();
$item->attachEventHandler("AfterChange", function () use ($propertyName, $item) {
$this->raisePropertyChangedCallbacks($propertyName, $item, null);
});
} | [
"private",
"function",
"attachChangeListenerToModelProperty",
"(",
"$",
"propertyName",
",",
"ModelState",
"$",
"item",
")",
"{",
"$",
"item",
"->",
"clearEventHandlers",
"(",
")",
";",
"$",
"item",
"->",
"attachEventHandler",
"(",
"\"AfterChange\"",
",",
"functio... | Attaches a change listener to the model state item and raises a property changed notification when that happens.
@param $propertyName
@param ModelState $item | [
"Attaches",
"a",
"change",
"listener",
"to",
"the",
"model",
"state",
"item",
"and",
"raises",
"a",
"property",
"changed",
"notification",
"when",
"that",
"happens",
"."
] | 327ff1f05d6a7e651d41c8e771f3551acfac18ae | https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/Modelling/ModelState.php#L445-L451 | train |
RhubarbPHP/Rhubarb | src/DependencyInjection/Container.php | Container.getInstance | public final function getInstance($requestedClass, ...$arguments)
{
if (isset($this->singletons[$requestedClass])){
return $this->singletons[$requestedClass];
}
$useSingleton = false;
// Check for singletons first as they should trump previous registrations of non
// singleton mappings.
if (isset($this->concreteClassMappings['_'.$requestedClass])) {
$class = $this->concreteClassMappings['_'.$requestedClass];
$useSingleton = true;
} elseif (isset($this->concreteClassMappings[$requestedClass])){
$class = $this->concreteClassMappings[$requestedClass];
} else {
$class = $requestedClass;
}
$reflection = new \ReflectionClass($class);
if ($reflection->isAbstract()){
throw new ClassMappingException($class);
}
$constructor = $reflection->getConstructor();
if ($constructor == null){
// No defined constructor so exit simply with a new instance.
$instance = $reflection->newInstanceArgs($arguments);
} else {
$instance = $this->generateInstanceFromConstructor($reflection, $constructor, $arguments);
}
if ($useSingleton) {
$this->singletons[$requestedClass] = $instance;
}
return $instance;
} | php | public final function getInstance($requestedClass, ...$arguments)
{
if (isset($this->singletons[$requestedClass])){
return $this->singletons[$requestedClass];
}
$useSingleton = false;
// Check for singletons first as they should trump previous registrations of non
// singleton mappings.
if (isset($this->concreteClassMappings['_'.$requestedClass])) {
$class = $this->concreteClassMappings['_'.$requestedClass];
$useSingleton = true;
} elseif (isset($this->concreteClassMappings[$requestedClass])){
$class = $this->concreteClassMappings[$requestedClass];
} else {
$class = $requestedClass;
}
$reflection = new \ReflectionClass($class);
if ($reflection->isAbstract()){
throw new ClassMappingException($class);
}
$constructor = $reflection->getConstructor();
if ($constructor == null){
// No defined constructor so exit simply with a new instance.
$instance = $reflection->newInstanceArgs($arguments);
} else {
$instance = $this->generateInstanceFromConstructor($reflection, $constructor, $arguments);
}
if ($useSingleton) {
$this->singletons[$requestedClass] = $instance;
}
return $instance;
} | [
"public",
"final",
"function",
"getInstance",
"(",
"$",
"requestedClass",
",",
"...",
"$",
"arguments",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"singletons",
"[",
"$",
"requestedClass",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"si... | Creates an object instance of the requested class, optionally passing additional constructor arguments
@param $requestedClass
@param ...$arguments
@return mixed|object | [
"Creates",
"an",
"object",
"instance",
"of",
"the",
"requested",
"class",
"optionally",
"passing",
"additional",
"constructor",
"arguments"
] | 327ff1f05d6a7e651d41c8e771f3551acfac18ae | https://github.com/RhubarbPHP/Rhubarb/blob/327ff1f05d6a7e651d41c8e771f3551acfac18ae/src/DependencyInjection/Container.php#L76-L115 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.