-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b4600e0
commit 53c05d8
Showing
7 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/Api/Monetization/Denormalizer/CompanyEligibleRatePlanDenormalizer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace Apigee\Edge\Api\Monetization\Denormalizer; | ||
|
||
use Apigee\Edge\Api\Monetization\Entity\CompanyEligibleRatePlan; | ||
use Apigee\Edge\Api\Monetization\NameConverter\CompanyEligibleRatePlanNameConverter; | ||
use Symfony\Component\PropertyAccess\PropertyAccessorInterface; | ||
use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface; | ||
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface; | ||
use Symfony\Component\Serializer\NameConverter\NameConverterInterface; | ||
|
||
class CompanyEligibleRatePlanDenormalizer extends AcceptedRatePlanDenormalizer | ||
{ | ||
/** | ||
* Fully qualified class name of the company accepted rate plan entity. | ||
* | ||
* @var string | ||
*/ | ||
protected $companyEligibleRatePlanClass = CompanyEligibleRatePlan::class; | ||
|
||
/** | ||
* CompanyEligibleRatePlanDenormalizer constructor. | ||
* | ||
* @param \Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface|null $classMetadataFactory | ||
* @param \Symfony\Component\Serializer\NameConverter\NameConverterInterface|null $nameConverter | ||
* @param \Symfony\Component\PropertyAccess\PropertyAccessorInterface|null $propertyAccessor | ||
* @param \Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface|null $propertyTypeExtractor | ||
*/ | ||
public function __construct(?ClassMetadataFactoryInterface $classMetadataFactory = null, ?NameConverterInterface $nameConverter = null, ?PropertyAccessorInterface $propertyAccessor = null, ?PropertyTypeExtractorInterface $propertyTypeExtractor = null) | ||
{ | ||
$nameConverter = $nameConverter ?? new CompanyEligibleRatePlanNameConverter(); | ||
parent::__construct($classMetadataFactory, $nameConverter, $propertyAccessor, $propertyTypeExtractor); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function denormalize($data, $type, $format = null, array $context = []) | ||
{ | ||
return parent::denormalize($data, $this->companyEligibleRatePlanClass, $format, $context); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function supportsDenormalization($data, $type, $format = null) | ||
{ | ||
if (parent::supportsDenormalization($data, $type, $format)) { | ||
return $data->developer->isCompany; | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Apigee\Edge\Api\Monetization\Entity; | ||
|
||
use Apigee\Edge\Api\Monetization\Entity\Property\CompanyPropertyAwareTrait; | ||
|
||
/** | ||
* Represents an accepted rate plan by a company. | ||
*/ | ||
class CompanyEligibleRatePlan extends AcceptedRatePlan implements CompanyEligibleRatePlanInterface | ||
{ | ||
use CompanyPropertyAwareTrait; | ||
} |
9 changes: 9 additions & 0 deletions
9
src/Api/Monetization/Entity/CompanyEligibleRatePlanInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace Apigee\Edge\Api\Monetization\Entity; | ||
|
||
use Apigee\Edge\Api\Monetization\Entity\Property\CompanyPropertyInterface; | ||
|
||
interface CompanyEligibleRatePlanInterface extends AcceptedRatePlanInterface, CompanyPropertyInterface | ||
{ | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Api/Monetization/NameConverter/CompanyEligibleRatePlanNameConverter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Apigee\Edge\Api\Monetization\NameConverter; | ||
|
||
use Symfony\Component\Serializer\NameConverter\NameConverterInterface; | ||
|
||
/** | ||
* Converts "developer" to "company" on those accepted rate plans that | ||
* belongs to a company. This is only used in the | ||
* CompanyEligibleRatePlanController. | ||
* | ||
* @see \Apigee\Edge\Api\Monetization\Entity\CompanyEligibleRatePlan | ||
*/ | ||
class CompanyEligibleRatePlanNameConverter extends NameConverterBase implements NameConverterInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getExternalToLocalMapping(): array | ||
{ | ||
return [ | ||
'developer' => 'company', | ||
]; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/Api/Monetization/Normalizer/CompanyEligibleRatePlanNormalizer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Apigee\Edge\Api\Monetization\Normalizer; | ||
|
||
use Apigee\Edge\Api\Monetization\Entity\CompanyEligibleRatePlanInterface; | ||
use Apigee\Edge\Api\Monetization\NameConverter\CompanyEligibleRatePlanNameConverter; | ||
use Symfony\Component\PropertyAccess\PropertyAccessorInterface; | ||
use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface; | ||
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface; | ||
use Symfony\Component\Serializer\NameConverter\NameConverterInterface; | ||
|
||
class CompanyEligibleRatePlanNormalizer extends AcceptedRatePlanNormalizer | ||
{ | ||
/** | ||
* CompanyEligibleRatePlanNormalizer constructor. | ||
* | ||
* @param \Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface|null $classMetadataFactory | ||
* @param \Symfony\Component\Serializer\NameConverter\NameConverterInterface|null $nameConverter | ||
* @param \Symfony\Component\PropertyAccess\PropertyAccessorInterface|null $propertyAccessor | ||
* @param \Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface|null $propertyTypeExtractor | ||
*/ | ||
public function __construct(?ClassMetadataFactoryInterface $classMetadataFactory = null, ?NameConverterInterface $nameConverter = null, ?PropertyAccessorInterface $propertyAccessor = null, ?PropertyTypeExtractorInterface $propertyTypeExtractor = null) | ||
{ | ||
$nameConverter = $nameConverter ?? new CompanyEligibleRatePlanNameConverter(); | ||
parent::__construct($classMetadataFactory, $nameConverter, $propertyAccessor, $propertyTypeExtractor); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function supportsNormalization($data, $format = null) | ||
{ | ||
return $data instanceof CompanyEligibleRatePlanInterface; | ||
} | ||
} |