From 9db4b08f8d50e862a40ce9e33ed0e00d71ae9a2c Mon Sep 17 00:00:00 2001 From: Holger Marx Date: Fri, 9 Oct 2020 13:45:30 +0200 Subject: [PATCH] Base LocalBusiness type on Organization and Place type --- src/ContextTypes/LocalBusiness.php | 32 +++++++++++++++++------------- src/ContextTypes/Organization.php | 4 ++++ src/ContextTypes/Place.php | 2 ++ 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/ContextTypes/LocalBusiness.php b/src/ContextTypes/LocalBusiness.php index 83a316e..6df4b1e 100644 --- a/src/ContextTypes/LocalBusiness.php +++ b/src/ContextTypes/LocalBusiness.php @@ -2,30 +2,34 @@ namespace JsonLd\ContextTypes; -class LocalBusiness extends AbstractContext +class LocalBusiness extends Organization { /** * Property structure * * @var array */ - protected $structure = [ - 'name' => null, - 'description' => null, - 'image' => null, - 'telephone' => null, - 'email' => null, + protected $extendedStructure = [ 'openingHours' => null, - 'address' => PostalAddress::class, - 'geo' => GeoCoordinates::class, - 'review' => Review::class, - 'aggregateRating' => AggregateRating::class, - 'url' => null, 'priceRange' => null, - 'areaServed' => null, - 'hasMap' => null, ]; + /** + * Constructor. Merges extendedStructure up + * + * @param array $attributes + * @param array $extendedStructure + */ + public function __construct(array $attributes, array $extendedStructure = []) + { + $place = new Place([]); + $extendedStructure = array_merge($extendedStructure, $place->structure); + + parent::__construct( + $attributes, array_merge($this->structure, $this->extendedStructure, $extendedStructure) + ); + } + /** * Set the opening hours of the business. * diff --git a/src/ContextTypes/Organization.php b/src/ContextTypes/Organization.php index 863b3d8..61b5660 100644 --- a/src/ContextTypes/Organization.php +++ b/src/ContextTypes/Organization.php @@ -14,6 +14,10 @@ class Organization extends Thing 'logo' => ImageObject::class, 'contactPoint' => ContactPoint::class, 'email' => null, + 'telephone' => null, + 'review' => Review::class, + 'aggregateRating' => AggregateRating::class, + 'areaServed' => null, ]; /** diff --git a/src/ContextTypes/Place.php b/src/ContextTypes/Place.php index bbdee36..2f6e31f 100644 --- a/src/ContextTypes/Place.php +++ b/src/ContextTypes/Place.php @@ -13,6 +13,8 @@ class Place extends Thing 'address' => PostalAddress::class, 'review' => Review::class, 'aggregateRating' => AggregateRating::class, + 'geo' => GeoCoordinates::class, + 'hasMap' => null, ]; /**