@@ -11,19 +11,19 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class Review extends BaseType |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * @var array |
|
| 16 | - * @see http://schema.org/{property_name} |
|
| 17 | - */ |
|
| 18 | - public $allowed = [ |
|
| 19 | - 'itemReviewed', 'reviewBody', 'reviewRating', |
|
| 20 | - ]; |
|
| 14 | + /** |
|
| 15 | + * @var array |
|
| 16 | + * @see http://schema.org/{property_name} |
|
| 17 | + */ |
|
| 18 | + public $allowed = [ |
|
| 19 | + 'itemReviewed', 'reviewBody', 'reviewRating', |
|
| 20 | + ]; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @var array |
|
| 24 | - * @see http://schema.org/{property_name} |
|
| 25 | - */ |
|
| 26 | - public $parents = [ |
|
| 27 | - 'CreativeWork', |
|
| 28 | - ]; |
|
| 22 | + /** |
|
| 23 | + * @var array |
|
| 24 | + * @see http://schema.org/{property_name} |
|
| 25 | + */ |
|
| 26 | + public $parents = [ |
|
| 27 | + 'CreativeWork', |
|
| 28 | + ]; |
|
| 29 | 29 | } |
@@ -11,19 +11,19 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class AggregateRating extends BaseType |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * @var array |
|
| 16 | - * @see http://schema.org/{property_name} |
|
| 17 | - */ |
|
| 18 | - public $allowed = [ |
|
| 19 | - 'itemReviewed', 'ratingCount', 'reviewCount', |
|
| 20 | - ]; |
|
| 14 | + /** |
|
| 15 | + * @var array |
|
| 16 | + * @see http://schema.org/{property_name} |
|
| 17 | + */ |
|
| 18 | + public $allowed = [ |
|
| 19 | + 'itemReviewed', 'ratingCount', 'reviewCount', |
|
| 20 | + ]; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @var array |
|
| 24 | - * @see http://schema.org/{property_name} |
|
| 25 | - */ |
|
| 26 | - public $parents = [ |
|
| 27 | - 'Rating', |
|
| 28 | - ]; |
|
| 22 | + /** |
|
| 23 | + * @var array |
|
| 24 | + * @see http://schema.org/{property_name} |
|
| 25 | + */ |
|
| 26 | + public $parents = [ |
|
| 27 | + 'Rating', |
|
| 28 | + ]; |
|
| 29 | 29 | } |
@@ -15,19 +15,19 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class LocalBusiness extends BaseType |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * @var array |
|
| 20 | - * @see http://schema.org/{property_name} |
|
| 21 | - */ |
|
| 22 | - public $allowed = [ |
|
| 23 | - 'branchOf', 'currenciesAccepted', 'openingHours', 'paymentAccepted', 'priceRange', |
|
| 24 | - ]; |
|
| 18 | + /** |
|
| 19 | + * @var array |
|
| 20 | + * @see http://schema.org/{property_name} |
|
| 21 | + */ |
|
| 22 | + public $allowed = [ |
|
| 23 | + 'branchOf', 'currenciesAccepted', 'openingHours', 'paymentAccepted', 'priceRange', |
|
| 24 | + ]; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var array |
|
| 28 | - * @see http://schema.org/{property_name} |
|
| 29 | - */ |
|
| 30 | - public $parents = [ |
|
| 31 | - 'Organization', 'Place', |
|
| 32 | - ]; |
|
| 26 | + /** |
|
| 27 | + * @var array |
|
| 28 | + * @see http://schema.org/{property_name} |
|
| 29 | + */ |
|
| 30 | + public $parents = [ |
|
| 31 | + 'Organization', 'Place', |
|
| 32 | + ]; |
|
| 33 | 33 | } |
@@ -64,27 +64,27 @@ |
||
| 64 | 64 | */ |
| 65 | 65 | class Person extends BaseType |
| 66 | 66 | { |
| 67 | - /** |
|
| 68 | - * @var array |
|
| 69 | - * @see http://schema.org/{property_name} |
|
| 70 | - */ |
|
| 71 | - public $allowed = [ |
|
| 72 | - 'additionalName', 'address', 'affiliation', 'alumniOf', 'award', 'awards', 'birthDate', |
|
| 73 | - 'birthPlace', 'brand', 'children', 'colleague', 'colleagues', 'contactPoint', |
|
| 74 | - 'contactPoints', 'deathDate', 'deathPlace', 'duns', 'email', 'familyName', 'faxNumber', |
|
| 75 | - 'follows', 'funder', 'gender', 'givenName', 'globalLocationNumber', 'hasOfferCatalog', |
|
| 76 | - 'hasPOS', 'height', 'homeLocation', 'honorificPrefix', 'honorificSuffix', 'isicV4', |
|
| 77 | - 'jobTitle', 'knows', 'makesOffer', 'memberOf', 'naics', 'nationality', 'netWorth', 'owns', |
|
| 78 | - 'parent', 'parents', 'performerIn', 'publishingPrinciples', 'relatedTo', 'seeks', 'sibling', |
|
| 79 | - 'siblings', 'sponsor', 'spouse', 'taxID', 'telephone', 'vatID', 'weight', 'workLocation', |
|
| 80 | - 'worksFor', |
|
| 81 | - ]; |
|
| 67 | + /** |
|
| 68 | + * @var array |
|
| 69 | + * @see http://schema.org/{property_name} |
|
| 70 | + */ |
|
| 71 | + public $allowed = [ |
|
| 72 | + 'additionalName', 'address', 'affiliation', 'alumniOf', 'award', 'awards', 'birthDate', |
|
| 73 | + 'birthPlace', 'brand', 'children', 'colleague', 'colleagues', 'contactPoint', |
|
| 74 | + 'contactPoints', 'deathDate', 'deathPlace', 'duns', 'email', 'familyName', 'faxNumber', |
|
| 75 | + 'follows', 'funder', 'gender', 'givenName', 'globalLocationNumber', 'hasOfferCatalog', |
|
| 76 | + 'hasPOS', 'height', 'homeLocation', 'honorificPrefix', 'honorificSuffix', 'isicV4', |
|
| 77 | + 'jobTitle', 'knows', 'makesOffer', 'memberOf', 'naics', 'nationality', 'netWorth', 'owns', |
|
| 78 | + 'parent', 'parents', 'performerIn', 'publishingPrinciples', 'relatedTo', 'seeks', 'sibling', |
|
| 79 | + 'siblings', 'sponsor', 'spouse', 'taxID', 'telephone', 'vatID', 'weight', 'workLocation', |
|
| 80 | + 'worksFor', |
|
| 81 | + ]; |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * @var array |
|
| 85 | - * @see http://schema.org/{property_name} |
|
| 86 | - */ |
|
| 87 | - public $parents = [ |
|
| 88 | - 'Thing', |
|
| 89 | - ]; |
|
| 83 | + /** |
|
| 84 | + * @var array |
|
| 85 | + * @see http://schema.org/{property_name} |
|
| 86 | + */ |
|
| 87 | + public $parents = [ |
|
| 88 | + 'Thing', |
|
| 89 | + ]; |
|
| 90 | 90 | } |
@@ -54,26 +54,26 @@ |
||
| 54 | 54 | */ |
| 55 | 55 | class Offer extends BaseType |
| 56 | 56 | { |
| 57 | - /** |
|
| 58 | - * @var array |
|
| 59 | - * @see http://schema.org/{property_name} |
|
| 60 | - */ |
|
| 61 | - public $allowed = [ |
|
| 62 | - 'acceptedPaymentMethod', 'addOn', 'advanceBookingRequirement', 'aggregateRating', |
|
| 63 | - 'areaServed', 'availability', 'availabilityEnds', 'availabilityStarts', 'availableAtOrFrom', |
|
| 64 | - 'availableDeliveryMethod', 'businessFunction', 'category', 'deliveryLeadTime', |
|
| 65 | - 'eligibleCustomerType', 'eligibleDuration', 'eligibleQuantity', 'eligibleRegion', |
|
| 66 | - 'eligibleTransactionVolume', 'gtin12', 'gtin13', 'gtin14', 'gtin8', 'includesObject', |
|
| 67 | - 'ineligibleRegion', 'inventoryLevel', 'itemCondition', 'itemOffered', 'mpn', 'price', |
|
| 68 | - 'priceCurrency', 'priceSpecification', 'priceValidUntil', 'review', 'reviews', 'seller', |
|
| 69 | - 'serialNumber', 'sku', 'validFrom', 'validThrough', 'warranty', |
|
| 70 | - ]; |
|
| 57 | + /** |
|
| 58 | + * @var array |
|
| 59 | + * @see http://schema.org/{property_name} |
|
| 60 | + */ |
|
| 61 | + public $allowed = [ |
|
| 62 | + 'acceptedPaymentMethod', 'addOn', 'advanceBookingRequirement', 'aggregateRating', |
|
| 63 | + 'areaServed', 'availability', 'availabilityEnds', 'availabilityStarts', 'availableAtOrFrom', |
|
| 64 | + 'availableDeliveryMethod', 'businessFunction', 'category', 'deliveryLeadTime', |
|
| 65 | + 'eligibleCustomerType', 'eligibleDuration', 'eligibleQuantity', 'eligibleRegion', |
|
| 66 | + 'eligibleTransactionVolume', 'gtin12', 'gtin13', 'gtin14', 'gtin8', 'includesObject', |
|
| 67 | + 'ineligibleRegion', 'inventoryLevel', 'itemCondition', 'itemOffered', 'mpn', 'price', |
|
| 68 | + 'priceCurrency', 'priceSpecification', 'priceValidUntil', 'review', 'reviews', 'seller', |
|
| 69 | + 'serialNumber', 'sku', 'validFrom', 'validThrough', 'warranty', |
|
| 70 | + ]; |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * @var array |
|
| 74 | - * @see http://schema.org/{property_name} |
|
| 75 | - */ |
|
| 76 | - public $parents = [ |
|
| 77 | - 'Intangible', |
|
| 78 | - ]; |
|
| 72 | + /** |
|
| 73 | + * @var array |
|
| 74 | + * @see http://schema.org/{property_name} |
|
| 75 | + */ |
|
| 76 | + public $parents = [ |
|
| 77 | + 'Intangible', |
|
| 78 | + ]; |
|
| 79 | 79 | } |
@@ -92,34 +92,34 @@ |
||
| 92 | 92 | */ |
| 93 | 93 | class CreativeWork extends BaseType |
| 94 | 94 | { |
| 95 | - /** |
|
| 96 | - * @var array |
|
| 97 | - * @see http://schema.org/{property_name} |
|
| 98 | - */ |
|
| 99 | - public $allowed = [ |
|
| 100 | - 'about', 'accessMode', 'accessModeSufficient', 'accessibilityAPI', 'accessibilityControl', |
|
| 101 | - 'accessibilityFeature', 'accessibilityHazard', 'accessibilitySummary', 'accountablePerson', |
|
| 102 | - 'aggregateRating', 'alternativeHeadline', 'associatedMedia', 'audience', 'audio', 'author', |
|
| 103 | - 'award', 'awards', 'character', 'citation', 'comment', 'commentCount', 'contentLocation', |
|
| 104 | - 'contentRating', 'contributor', 'copyrightHolder', 'copyrightYear', 'creator', |
|
| 105 | - 'dateCreated', 'dateModified', 'datePublished', 'discussionUrl', 'editor', |
|
| 106 | - 'educationalAlignment', 'educationalUse', 'encoding', 'encodingFormat', 'encodings', |
|
| 107 | - 'exampleOfWork', 'expires', 'fileFormat', 'funder', 'genre', 'hasPart', 'headline', |
|
| 108 | - 'inLanguage', 'interactionStatistic', 'interactivityType', 'isAccessibleForFree', |
|
| 109 | - 'isBasedOn', 'isBasedOnUrl', 'isFamilyFriendly', 'isPartOf', 'keywords', |
|
| 110 | - 'learningResourceType', 'license', 'locationCreated', 'mainEntity', 'material', 'mentions', |
|
| 111 | - 'offers', 'position', 'producer', 'provider', 'publication', 'publisher', |
|
| 112 | - 'publishingPrinciples', 'recordedAt', 'releasedEvent', 'review', 'reviews', 'schemaVersion', |
|
| 113 | - 'sourceOrganization', 'spatialCoverage', 'sponsor', 'temporalCoverage', 'text', |
|
| 114 | - 'thumbnailUrl', 'timeRequired', 'translator', 'typicalAgeRange', 'version', 'video', |
|
| 115 | - 'workExample', |
|
| 116 | - ]; |
|
| 95 | + /** |
|
| 96 | + * @var array |
|
| 97 | + * @see http://schema.org/{property_name} |
|
| 98 | + */ |
|
| 99 | + public $allowed = [ |
|
| 100 | + 'about', 'accessMode', 'accessModeSufficient', 'accessibilityAPI', 'accessibilityControl', |
|
| 101 | + 'accessibilityFeature', 'accessibilityHazard', 'accessibilitySummary', 'accountablePerson', |
|
| 102 | + 'aggregateRating', 'alternativeHeadline', 'associatedMedia', 'audience', 'audio', 'author', |
|
| 103 | + 'award', 'awards', 'character', 'citation', 'comment', 'commentCount', 'contentLocation', |
|
| 104 | + 'contentRating', 'contributor', 'copyrightHolder', 'copyrightYear', 'creator', |
|
| 105 | + 'dateCreated', 'dateModified', 'datePublished', 'discussionUrl', 'editor', |
|
| 106 | + 'educationalAlignment', 'educationalUse', 'encoding', 'encodingFormat', 'encodings', |
|
| 107 | + 'exampleOfWork', 'expires', 'fileFormat', 'funder', 'genre', 'hasPart', 'headline', |
|
| 108 | + 'inLanguage', 'interactionStatistic', 'interactivityType', 'isAccessibleForFree', |
|
| 109 | + 'isBasedOn', 'isBasedOnUrl', 'isFamilyFriendly', 'isPartOf', 'keywords', |
|
| 110 | + 'learningResourceType', 'license', 'locationCreated', 'mainEntity', 'material', 'mentions', |
|
| 111 | + 'offers', 'position', 'producer', 'provider', 'publication', 'publisher', |
|
| 112 | + 'publishingPrinciples', 'recordedAt', 'releasedEvent', 'review', 'reviews', 'schemaVersion', |
|
| 113 | + 'sourceOrganization', 'spatialCoverage', 'sponsor', 'temporalCoverage', 'text', |
|
| 114 | + 'thumbnailUrl', 'timeRequired', 'translator', 'typicalAgeRange', 'version', 'video', |
|
| 115 | + 'workExample', |
|
| 116 | + ]; |
|
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * @var array |
|
| 120 | - * @see http://schema.org/{property_name} |
|
| 121 | - */ |
|
| 122 | - public $parents = [ |
|
| 123 | - 'Thing', |
|
| 124 | - ]; |
|
| 118 | + /** |
|
| 119 | + * @var array |
|
| 120 | + * @see http://schema.org/{property_name} |
|
| 121 | + */ |
|
| 122 | + public $parents = [ |
|
| 123 | + 'Thing', |
|
| 124 | + ]; |
|
| 125 | 125 | } |
@@ -13,19 +13,19 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class AggregateOffer extends BaseType |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * @var array |
|
| 18 | - * @see http://schema.org/{property_name} |
|
| 19 | - */ |
|
| 20 | - public $allowed = [ |
|
| 21 | - 'highPrice', 'lowPrice', 'offerCount', 'offers', |
|
| 22 | - ]; |
|
| 16 | + /** |
|
| 17 | + * @var array |
|
| 18 | + * @see http://schema.org/{property_name} |
|
| 19 | + */ |
|
| 20 | + public $allowed = [ |
|
| 21 | + 'highPrice', 'lowPrice', 'offerCount', 'offers', |
|
| 22 | + ]; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var array |
|
| 26 | - * @see http://schema.org/{property_name} |
|
| 27 | - */ |
|
| 28 | - public $parents = [ |
|
| 29 | - 'Offer', |
|
| 30 | - ]; |
|
| 24 | + /** |
|
| 25 | + * @var array |
|
| 26 | + * @see http://schema.org/{property_name} |
|
| 27 | + */ |
|
| 28 | + public $parents = [ |
|
| 29 | + 'Offer', |
|
| 30 | + ]; |
|
| 31 | 31 | } |
@@ -12,248 +12,248 @@ |
||
| 12 | 12 | |
| 13 | 13 | abstract class BaseType implements ArrayAccess, JsonSerializable, Type |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * @var array |
|
| 17 | - */ |
|
| 18 | - public $allowed = []; |
|
| 15 | + /** |
|
| 16 | + * @var array |
|
| 17 | + */ |
|
| 18 | + public $allowed = []; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var array |
|
| 22 | - */ |
|
| 23 | - public $parents = []; |
|
| 20 | + /** |
|
| 21 | + * @var array |
|
| 22 | + */ |
|
| 23 | + public $parents = []; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var array |
|
| 27 | - */ |
|
| 28 | - protected $properties = []; |
|
| 25 | + /** |
|
| 26 | + * @var array |
|
| 27 | + */ |
|
| 28 | + protected $properties = []; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @var string |
|
| 32 | - */ |
|
| 33 | - protected $type; |
|
| 30 | + /** |
|
| 31 | + * @var string |
|
| 32 | + */ |
|
| 33 | + protected $type; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @param string $method |
|
| 37 | - * @return static |
|
| 38 | - */ |
|
| 39 | - public function __call($method, array $arguments) |
|
| 40 | - { |
|
| 41 | - return $this->setProperty($method, glsr_get($arguments, 0)); |
|
| 42 | - } |
|
| 35 | + /** |
|
| 36 | + * @param string $method |
|
| 37 | + * @return static |
|
| 38 | + */ |
|
| 39 | + public function __call($method, array $arguments) |
|
| 40 | + { |
|
| 41 | + return $this->setProperty($method, glsr_get($arguments, 0)); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @param string $type |
|
| 46 | - */ |
|
| 47 | - public function __construct($type = null) |
|
| 48 | - { |
|
| 49 | - $this->type = !is_string($type) |
|
| 50 | - ? (new ReflectionClass($this))->getShortName() |
|
| 51 | - : $type; |
|
| 52 | - $this->setAllowedProperties(); |
|
| 53 | - } |
|
| 44 | + /** |
|
| 45 | + * @param string $type |
|
| 46 | + */ |
|
| 47 | + public function __construct($type = null) |
|
| 48 | + { |
|
| 49 | + $this->type = !is_string($type) |
|
| 50 | + ? (new ReflectionClass($this))->getShortName() |
|
| 51 | + : $type; |
|
| 52 | + $this->setAllowedProperties(); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @return string |
|
| 57 | - */ |
|
| 58 | - public function __toString() |
|
| 59 | - { |
|
| 60 | - return $this->toScript(); |
|
| 61 | - } |
|
| 55 | + /** |
|
| 56 | + * @return string |
|
| 57 | + */ |
|
| 58 | + public function __toString() |
|
| 59 | + { |
|
| 60 | + return $this->toScript(); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @return static |
|
| 65 | - */ |
|
| 66 | - public function addProperties(array $properties) |
|
| 67 | - { |
|
| 68 | - foreach ($properties as $property => $value) { |
|
| 69 | - $this->setProperty($property, $value); |
|
| 70 | - } |
|
| 71 | - return $this; |
|
| 72 | - } |
|
| 63 | + /** |
|
| 64 | + * @return static |
|
| 65 | + */ |
|
| 66 | + public function addProperties(array $properties) |
|
| 67 | + { |
|
| 68 | + foreach ($properties as $property => $value) { |
|
| 69 | + $this->setProperty($property, $value); |
|
| 70 | + } |
|
| 71 | + return $this; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * @return string |
|
| 76 | - */ |
|
| 77 | - public function getContext() |
|
| 78 | - { |
|
| 79 | - return 'https://schema.org'; |
|
| 80 | - } |
|
| 74 | + /** |
|
| 75 | + * @return string |
|
| 76 | + */ |
|
| 77 | + public function getContext() |
|
| 78 | + { |
|
| 79 | + return 'https://schema.org'; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * @return array |
|
| 84 | - */ |
|
| 85 | - public function getProperties() |
|
| 86 | - { |
|
| 87 | - return $this->properties; |
|
| 88 | - } |
|
| 82 | + /** |
|
| 83 | + * @return array |
|
| 84 | + */ |
|
| 85 | + public function getProperties() |
|
| 86 | + { |
|
| 87 | + return $this->properties; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * @param string $property |
|
| 92 | - * @param mixed $default |
|
| 93 | - * @return mixed |
|
| 94 | - */ |
|
| 95 | - public function getProperty($property, $default = null) |
|
| 96 | - { |
|
| 97 | - return glsr_get($this->properties, $property, $default); |
|
| 98 | - } |
|
| 90 | + /** |
|
| 91 | + * @param string $property |
|
| 92 | + * @param mixed $default |
|
| 93 | + * @return mixed |
|
| 94 | + */ |
|
| 95 | + public function getProperty($property, $default = null) |
|
| 96 | + { |
|
| 97 | + return glsr_get($this->properties, $property, $default); |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * @return string |
|
| 102 | - */ |
|
| 103 | - public function getType() |
|
| 104 | - { |
|
| 105 | - return $this->type; |
|
| 106 | - } |
|
| 100 | + /** |
|
| 101 | + * @return string |
|
| 102 | + */ |
|
| 103 | + public function getType() |
|
| 104 | + { |
|
| 105 | + return $this->type; |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * @param bool $condition |
|
| 110 | - * @param mixed $callback |
|
| 111 | - * @return static |
|
| 112 | - */ |
|
| 113 | - public function doIf($condition, $callback) |
|
| 114 | - { |
|
| 115 | - if ($condition) { |
|
| 116 | - $callback($this); |
|
| 117 | - } |
|
| 118 | - return $this; |
|
| 119 | - } |
|
| 108 | + /** |
|
| 109 | + * @param bool $condition |
|
| 110 | + * @param mixed $callback |
|
| 111 | + * @return static |
|
| 112 | + */ |
|
| 113 | + public function doIf($condition, $callback) |
|
| 114 | + { |
|
| 115 | + if ($condition) { |
|
| 116 | + $callback($this); |
|
| 117 | + } |
|
| 118 | + return $this; |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * @return array |
|
| 123 | - */ |
|
| 124 | - public function jsonSerialize() |
|
| 125 | - { |
|
| 126 | - return $this->toArray(); |
|
| 127 | - } |
|
| 121 | + /** |
|
| 122 | + * @return array |
|
| 123 | + */ |
|
| 124 | + public function jsonSerialize() |
|
| 125 | + { |
|
| 126 | + return $this->toArray(); |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * @param mixed $offset |
|
| 131 | - * @return bool |
|
| 132 | - */ |
|
| 133 | - public function offsetExists($offset) |
|
| 134 | - { |
|
| 135 | - return array_key_exists($offset, $this->properties); |
|
| 136 | - } |
|
| 129 | + /** |
|
| 130 | + * @param mixed $offset |
|
| 131 | + * @return bool |
|
| 132 | + */ |
|
| 133 | + public function offsetExists($offset) |
|
| 134 | + { |
|
| 135 | + return array_key_exists($offset, $this->properties); |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | - /** |
|
| 139 | - * @param string $offset |
|
| 140 | - * @return mixed |
|
| 141 | - */ |
|
| 142 | - public function offsetGet($offset) |
|
| 143 | - { |
|
| 144 | - return $this->getProperty($offset); |
|
| 145 | - } |
|
| 138 | + /** |
|
| 139 | + * @param string $offset |
|
| 140 | + * @return mixed |
|
| 141 | + */ |
|
| 142 | + public function offsetGet($offset) |
|
| 143 | + { |
|
| 144 | + return $this->getProperty($offset); |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - /** |
|
| 148 | - * @param string $offset |
|
| 149 | - * @param mixed $value |
|
| 150 | - * @return void |
|
| 151 | - */ |
|
| 152 | - public function offsetSet($offset, $value) |
|
| 153 | - { |
|
| 154 | - $this->setProperty($offset, $value); |
|
| 155 | - } |
|
| 147 | + /** |
|
| 148 | + * @param string $offset |
|
| 149 | + * @param mixed $value |
|
| 150 | + * @return void |
|
| 151 | + */ |
|
| 152 | + public function offsetSet($offset, $value) |
|
| 153 | + { |
|
| 154 | + $this->setProperty($offset, $value); |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - /** |
|
| 158 | - * @param string $offset |
|
| 159 | - * @return void |
|
| 160 | - */ |
|
| 161 | - public function offsetUnset($offset) |
|
| 162 | - { |
|
| 163 | - unset($this->properties[$offset]); |
|
| 164 | - } |
|
| 157 | + /** |
|
| 158 | + * @param string $offset |
|
| 159 | + * @return void |
|
| 160 | + */ |
|
| 161 | + public function offsetUnset($offset) |
|
| 162 | + { |
|
| 163 | + unset($this->properties[$offset]); |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * @param string $property |
|
| 168 | - * @param mixed $value |
|
| 169 | - * @return static |
|
| 170 | - */ |
|
| 171 | - public function setProperty($property, $value) |
|
| 172 | - { |
|
| 173 | - if (!in_array($property, $this->allowed) |
|
| 174 | - && 'UnknownType' != (new ReflectionClass($this))->getShortName()) { |
|
| 175 | - glsr_log()->warning($this->getType().' does not allow the "'.$property.'" property'); |
|
| 176 | - return $this; |
|
| 177 | - } |
|
| 178 | - $this->properties[$property] = $value; |
|
| 179 | - return $this; |
|
| 180 | - } |
|
| 166 | + /** |
|
| 167 | + * @param string $property |
|
| 168 | + * @param mixed $value |
|
| 169 | + * @return static |
|
| 170 | + */ |
|
| 171 | + public function setProperty($property, $value) |
|
| 172 | + { |
|
| 173 | + if (!in_array($property, $this->allowed) |
|
| 174 | + && 'UnknownType' != (new ReflectionClass($this))->getShortName()) { |
|
| 175 | + glsr_log()->warning($this->getType().' does not allow the "'.$property.'" property'); |
|
| 176 | + return $this; |
|
| 177 | + } |
|
| 178 | + $this->properties[$property] = $value; |
|
| 179 | + return $this; |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - /** |
|
| 183 | - * @return array |
|
| 184 | - */ |
|
| 185 | - public function toArray() |
|
| 186 | - { |
|
| 187 | - return [ |
|
| 188 | - '@context' => $this->getContext(), |
|
| 189 | - '@type' => $this->getType(), |
|
| 190 | - ] + $this->serializeProperty($this->getProperties()); |
|
| 191 | - } |
|
| 182 | + /** |
|
| 183 | + * @return array |
|
| 184 | + */ |
|
| 185 | + public function toArray() |
|
| 186 | + { |
|
| 187 | + return [ |
|
| 188 | + '@context' => $this->getContext(), |
|
| 189 | + '@type' => $this->getType(), |
|
| 190 | + ] + $this->serializeProperty($this->getProperties()); |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - /** |
|
| 194 | - * @return string |
|
| 195 | - */ |
|
| 196 | - public function toScript() |
|
| 197 | - { |
|
| 198 | - return sprintf('<script type="application/ld+json">%s</script>', |
|
| 199 | - json_encode($this->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) |
|
| 200 | - ); |
|
| 201 | - } |
|
| 193 | + /** |
|
| 194 | + * @return string |
|
| 195 | + */ |
|
| 196 | + public function toScript() |
|
| 197 | + { |
|
| 198 | + return sprintf('<script type="application/ld+json">%s</script>', |
|
| 199 | + json_encode($this->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) |
|
| 200 | + ); |
|
| 201 | + } |
|
| 202 | 202 | |
| 203 | - /** |
|
| 204 | - * @param array|null $parents |
|
| 205 | - * @return array |
|
| 206 | - */ |
|
| 207 | - protected function getParents($parents = null) |
|
| 208 | - { |
|
| 209 | - if (!isset($parents)) { |
|
| 210 | - $parents = $this->parents; |
|
| 211 | - } |
|
| 212 | - $newParents = $parents; |
|
| 213 | - foreach ($parents as $parent) { |
|
| 214 | - $parentClass = glsr(Helper::class)->buildClassName($parent, __NAMESPACE__); |
|
| 215 | - if (!class_exists($parentClass)) { |
|
| 216 | - continue; |
|
| 217 | - } |
|
| 218 | - $newParents = array_merge($newParents, $this->getParents((new $parentClass())->parents)); |
|
| 219 | - } |
|
| 220 | - return array_values(array_unique($newParents)); |
|
| 221 | - } |
|
| 203 | + /** |
|
| 204 | + * @param array|null $parents |
|
| 205 | + * @return array |
|
| 206 | + */ |
|
| 207 | + protected function getParents($parents = null) |
|
| 208 | + { |
|
| 209 | + if (!isset($parents)) { |
|
| 210 | + $parents = $this->parents; |
|
| 211 | + } |
|
| 212 | + $newParents = $parents; |
|
| 213 | + foreach ($parents as $parent) { |
|
| 214 | + $parentClass = glsr(Helper::class)->buildClassName($parent, __NAMESPACE__); |
|
| 215 | + if (!class_exists($parentClass)) { |
|
| 216 | + continue; |
|
| 217 | + } |
|
| 218 | + $newParents = array_merge($newParents, $this->getParents((new $parentClass())->parents)); |
|
| 219 | + } |
|
| 220 | + return array_values(array_unique($newParents)); |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | - /** |
|
| 224 | - * @return void |
|
| 225 | - */ |
|
| 226 | - protected function setAllowedProperties() |
|
| 227 | - { |
|
| 228 | - $parents = $this->getParents(); |
|
| 229 | - foreach ($parents as $parent) { |
|
| 230 | - $parentClass = glsr(Helper::class)->buildClassName($parent, __NAMESPACE__); |
|
| 231 | - if (!class_exists($parentClass)) { |
|
| 232 | - continue; |
|
| 233 | - } |
|
| 234 | - $this->allowed = array_values(array_unique(array_merge((new $parentClass())->allowed, $this->allowed))); |
|
| 235 | - } |
|
| 236 | - } |
|
| 223 | + /** |
|
| 224 | + * @return void |
|
| 225 | + */ |
|
| 226 | + protected function setAllowedProperties() |
|
| 227 | + { |
|
| 228 | + $parents = $this->getParents(); |
|
| 229 | + foreach ($parents as $parent) { |
|
| 230 | + $parentClass = glsr(Helper::class)->buildClassName($parent, __NAMESPACE__); |
|
| 231 | + if (!class_exists($parentClass)) { |
|
| 232 | + continue; |
|
| 233 | + } |
|
| 234 | + $this->allowed = array_values(array_unique(array_merge((new $parentClass())->allowed, $this->allowed))); |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | - /** |
|
| 239 | - * @param mixed $property |
|
| 240 | - * @return array|string |
|
| 241 | - */ |
|
| 242 | - protected function serializeProperty($property) |
|
| 243 | - { |
|
| 244 | - if (is_array($property)) { |
|
| 245 | - return array_map([$this, 'serializeProperty'], $property); |
|
| 246 | - } |
|
| 247 | - if ($property instanceof Type) { |
|
| 248 | - $property = $property->toArray(); |
|
| 249 | - unset($property['@context']); |
|
| 250 | - } |
|
| 251 | - if ($property instanceof DateTimeInterface) { |
|
| 252 | - $property = $property->format(DateTime::ATOM); |
|
| 253 | - } |
|
| 254 | - if (is_object($property)) { |
|
| 255 | - throw new InvalidProperty(); |
|
| 256 | - } |
|
| 257 | - return $property; |
|
| 258 | - } |
|
| 238 | + /** |
|
| 239 | + * @param mixed $property |
|
| 240 | + * @return array|string |
|
| 241 | + */ |
|
| 242 | + protected function serializeProperty($property) |
|
| 243 | + { |
|
| 244 | + if (is_array($property)) { |
|
| 245 | + return array_map([$this, 'serializeProperty'], $property); |
|
| 246 | + } |
|
| 247 | + if ($property instanceof Type) { |
|
| 248 | + $property = $property->toArray(); |
|
| 249 | + unset($property['@context']); |
|
| 250 | + } |
|
| 251 | + if ($property instanceof DateTimeInterface) { |
|
| 252 | + $property = $property->format(DateTime::ATOM); |
|
| 253 | + } |
|
| 254 | + if (is_object($property)) { |
|
| 255 | + throw new InvalidProperty(); |
|
| 256 | + } |
|
| 257 | + return $property; |
|
| 258 | + } |
|
| 259 | 259 | } |
@@ -12,19 +12,19 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class Rating extends BaseType |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * @var array |
|
| 17 | - * @see http://schema.org/{property_name} |
|
| 18 | - */ |
|
| 19 | - public $allowed = [ |
|
| 20 | - 'author', 'bestRating', 'ratingValue', 'worstRating', |
|
| 21 | - ]; |
|
| 15 | + /** |
|
| 16 | + * @var array |
|
| 17 | + * @see http://schema.org/{property_name} |
|
| 18 | + */ |
|
| 19 | + public $allowed = [ |
|
| 20 | + 'author', 'bestRating', 'ratingValue', 'worstRating', |
|
| 21 | + ]; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @var array |
|
| 25 | - * @see http://schema.org/{property_name} |
|
| 26 | - */ |
|
| 27 | - public $parents = [ |
|
| 28 | - 'Intangible', |
|
| 29 | - ]; |
|
| 23 | + /** |
|
| 24 | + * @var array |
|
| 25 | + * @see http://schema.org/{property_name} |
|
| 26 | + */ |
|
| 27 | + public $parents = [ |
|
| 28 | + 'Intangible', |
|
| 29 | + ]; |
|
| 30 | 30 | } |