Mwjames has uploaded a new change for review. https://gerrit.wikimedia.org/r/76917
Change subject: Split interfaces ...................................................................... Split interfaces Change-Id: I9e85bd969156bbef64475132a66cb822a82bae7b --- M includes/Setup.php A includes/hooks/HookBase.php M includes/hooks/MediaWikiHook.php A includes/utilities/Accessor.php M includes/utilities/ArrayAccessor.php A includes/utilities/Arrayable.php D includes/utilities/BaseInterfaceProvider.php A includes/utilities/Cacheable.php A includes/utilities/Configurable.php M includes/utilities/HashIdGenerator.php A includes/utilities/IdGenerator.php A includes/utilities/Observer.php D includes/utilities/ObserverInterfaceProvider.php A includes/utilities/Publisher.php A includes/utilities/StoreAccess.php A includes/utilities/Subject.php A includes/utilities/Subscriber.php R includes/utilities/TitleProvider.php 18 files changed, 518 insertions(+), 392 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticMediaWiki refs/changes/17/76917/1 diff --git a/includes/Setup.php b/includes/Setup.php index 117e3cb..1b7e8ee 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -158,28 +158,28 @@ // Utilities $wgAutoloadClasses['SMW\NamespaceExaminer'] = $incDir . '/utilities/NamespaceExaminer.php'; $wgAutoloadClasses['SMW\Profiler'] = $incDir . '/utilities/Profiler.php'; - $wgAutoloadClasses['SMW\IdGenerator'] = $incDir . '/utilities/HashIdGenerator.php'; + $wgAutoloadClasses['SMW\IdGenerator'] = $incDir . '/utilities/IdGenerator.php'; $wgAutoloadClasses['SMW\HashIdGenerator'] = $incDir . '/utilities/HashIdGenerator.php'; - $wgAutoloadClasses['SMW\Accessor'] = $incDir . '/utilities/ArrayAccessor.php'; - $wgAutoloadClasses['SMW\Arrayable'] = $incDir . '/utilities/ArrayAccessor.php'; + $wgAutoloadClasses['SMW\Accessor'] = $incDir . '/utilities/Accessor.php'; + $wgAutoloadClasses['SMW\Arrayable'] = $incDir . '/utilities/Arrayable.php'; $wgAutoloadClasses['SMW\ArrayAccessor'] = $incDir . '/utilities/ArrayAccessor.php'; $wgAutoloadClasses['SMW\MessageReporter'] = $incDir . '/utilities/MessageReporter.php'; $wgAutoloadClasses['SMW\ObservableMessageReporter'] = $incDir . '/utilities/MessageReporter.php'; $wgAutoloadClasses['SMW\ContentParser'] = $incDir . '/utilities/ContentParser.php'; $wgAutoloadClasses['SMW\ChangeObserver'] = $incDir . '/utilities/ChangeObserver.php'; - $wgAutoloadClasses['SMW\TitleProvider'] = $incDir . '/utilities/MediaWikiInterfaceProvider.php'; + $wgAutoloadClasses['SMW\TitleProvider'] = $incDir . '/utilities/TitleProvider.php'; - $wgAutoloadClasses['SMW\Publisher'] = $incDir . '/utilities/ObserverInterfaceProvider.php'; - $wgAutoloadClasses['SMW\Subject'] = $incDir . '/utilities/ObserverInterfaceProvider.php'; - $wgAutoloadClasses['SMW\Observer'] = $incDir . '/utilities/ObserverInterfaceProvider.php'; - $wgAutoloadClasses['SMW\Subscriber'] = $incDir . '/utilities/ObserverInterfaceProvider.php'; + $wgAutoloadClasses['SMW\Publisher'] = $incDir . '/utilities/Publisher.php'; + $wgAutoloadClasses['SMW\Subject'] = $incDir . '/utilities/Subject.php'; + $wgAutoloadClasses['SMW\Observer'] = $incDir . '/utilities/Observer.php'; + $wgAutoloadClasses['SMW\Subscriber'] = $incDir . '/utilities/Subscriber.php'; - $wgAutoloadClasses['SMW\Cacheable'] = $incDir . '/utilities/BaseInterfaceProvider.php'; - $wgAutoloadClasses['SMW\Configurable'] = $incDir . '/utilities/BaseInterfaceProvider.php'; - $wgAutoloadClasses['SMW\StoreAccess'] = $incDir . '/utilities/BaseInterfaceProvider.php'; + $wgAutoloadClasses['SMW\Cacheable'] = $incDir . '/utilities/Cacheable.php'; + $wgAutoloadClasses['SMW\Configurable'] = $incDir . '/utilities/Configurable.php'; + $wgAutoloadClasses['SMW\StoreAccess'] = $incDir . '/utilities/StoreAccess.php'; // Hooks - $wgAutoloadClasses['SMW\HookBase'] = $incDir . '/hooks/MediaWikiHook.php'; + $wgAutoloadClasses['SMW\HookBase'] = $incDir . '/hooks/HookBase.php'; $wgAutoloadClasses['SMW\MediaWikiHook'] = $incDir . '/hooks/MediaWikiHook.php'; $wgAutoloadClasses['SMW\HooksLoader'] = $incDir . '/hooks/HooksLoader.php'; $wgAutoloadClasses['SMW\LinksUpdateConstructed'] = $incDir . '/hooks/LinksUpdateConstructed.php'; diff --git a/includes/hooks/HookBase.php b/includes/hooks/HookBase.php new file mode 100644 index 0000000..fe9e577 --- /dev/null +++ b/includes/hooks/HookBase.php @@ -0,0 +1,15 @@ +<?php + +namespace SMW; + +/** + * Hook base class + * + * @file + * + * @license GNU GPL v2+ + * @since 1.9 + * + * @author mwjames + */ +interface HookBase extends Cacheable, Configurable, StoreAccess {} diff --git a/includes/hooks/MediaWikiHook.php b/includes/hooks/MediaWikiHook.php index a51eef9..c48384e 100644 --- a/includes/hooks/MediaWikiHook.php +++ b/includes/hooks/MediaWikiHook.php @@ -12,7 +12,6 @@ * * @author mwjames */ -interface HookBase extends Cacheable, Configurable, StoreAccess {} /** * MediaWikiHook base class diff --git a/includes/utilities/Accessor.php b/includes/utilities/Accessor.php new file mode 100644 index 0000000..215897a --- /dev/null +++ b/includes/utilities/Accessor.php @@ -0,0 +1,54 @@ +<?php + +namespace SMW; + +use ArrayObject; +use InvalidArgumentException; + +/** + * Interface specifying access to an object + * + * @file + * + * @license GNU GPL v2+ + * @since 1.9 + * + * @author mwjames + */ +interface Accessor { + + /** + * Returns if a specific key can be accessed + * + * @since 1.9 + * + * @param mixed $key specific key + * + * @return boolean + */ + public function has( $key ); + + /** + * Returns a value for a specific key + * + * @since 1.9 + * + * @param mixed $key specific key + * + * @return mixed + */ + public function get( $key ); + + /** + * Sets a value for a specific key + * + * @since 1.9 + * + * @param mixed $key + * @param mixed $value + * + * @return boolean + */ + public function set( $key, $value ); + +} diff --git a/includes/utilities/ArrayAccessor.php b/includes/utilities/ArrayAccessor.php index b3884e0..c1502b1 100644 --- a/includes/utilities/ArrayAccessor.php +++ b/includes/utilities/ArrayAccessor.php @@ -6,7 +6,7 @@ use InvalidArgumentException; /** - * Interface specifying access to an object + * This class enables access to an arbitrary array * * @file * @@ -15,56 +15,6 @@ * * @author mwjames */ -interface Accessor { - - /** - * Returns if a specific key can be accessed - * - * @since 1.9 - * - * @param mixed $key specific key - * - * @return boolean - */ - public function has( $key ); - - /** - * Returns a value for a specific key - * - * @since 1.9 - * - * @param mixed $key specific key - * - * @return mixed - */ - public function get( $key ); - - /** - * Sets a value for a specific key - * - * @since 1.9 - * - * @param mixed $key - * @param mixed $value - * - * @return boolean - */ - public function set( $key, $value ); - -} - -interface Arrayable { - - /** - * Returns an object as array - * - * @since 1.9 - * - * @return array - */ - public function toArray(); - -} /** * This class enables access to an arbitrary array diff --git a/includes/utilities/Arrayable.php b/includes/utilities/Arrayable.php new file mode 100644 index 0000000..a90862d --- /dev/null +++ b/includes/utilities/Arrayable.php @@ -0,0 +1,30 @@ +<?php + +namespace SMW; + +use ArrayObject; +use InvalidArgumentException; + +/** + * Interface specifying returning an array + * + * @file + * + * @license GNU GPL v2+ + * @since 1.9 + * + * @author mwjames + */ +interface Arrayable { + + /** + * Returns an array + * + * @since 1.9 + * + * @return array + */ + public function toArray(); + +} + diff --git a/includes/utilities/BaseInterfaceProvider.php b/includes/utilities/BaseInterfaceProvider.php deleted file mode 100644 index ae601fe..0000000 --- a/includes/utilities/BaseInterfaceProvider.php +++ /dev/null @@ -1,101 +0,0 @@ -<?php - -namespace SMW; - -/** - * Semantic MediaWiki base class to enable access to commonly used objects - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * http://www.gnu.org/copyleft/gpl.html - * - * @file - * - * @license GNU GPL v2+ - * @since 1.9 - * - * @author mwjames - */ - -/** - * Specifies an interface to access a cachable entity (CacheStore etc.) - * - * @ingroup Utility - */ -interface Cacheable { - - /** - * Returns cachable entity - * - * @since 1.9 - * - * @return Cacheable - */ - public function getCache(); - -} - -/** - * Specifies an interface to access a configurable object (Settings) - * - * @ingroup Utility - */ -interface Configurable { - - /** - * Sets a Settings object - * - * @since 1.9 - * - * @param Settings $settings - */ - public function setSettings( Settings $settings ); - - /** - * Returns Settings object - * - * @since 1.9 - * - * @return Settings - */ - public function getSettings(); - -} - -/** - * Specifies an interface to access a Store object - * - * @ingroup Utility - */ -interface StoreAccess { - - /** - * Sets a Store object - * - * @since 1.9 - * - * @param Store $settings - */ - public function setStore( Store $store ); - - /** - * Returns Store object - * - * @since 1.9 - * - * @return Store - */ - public function getStore(); - -} diff --git a/includes/utilities/Cacheable.php b/includes/utilities/Cacheable.php new file mode 100644 index 0000000..edd551b --- /dev/null +++ b/includes/utilities/Cacheable.php @@ -0,0 +1,32 @@ +<?php + +namespace SMW; + +/** + * Semantic MediaWiki interface to access a cachable entity (CacheStore etc.) + * + * @file + * + * @license GNU GPL v2+ + * @since 1.9 + * + * @author mwjames + */ + +/** + * Specifies an interface to access a cachable entity (CacheStore etc.) + * + * @ingroup Utility + */ +interface Cacheable { + + /** + * Returns cachable entity + * + * @since 1.9 + * + * @return Cacheable + */ + public function getCache(); + +} diff --git a/includes/utilities/Configurable.php b/includes/utilities/Configurable.php new file mode 100644 index 0000000..1eb2502 --- /dev/null +++ b/includes/utilities/Configurable.php @@ -0,0 +1,41 @@ +<?php + +namespace SMW; + +/** + * Semantic MediaWiki interface to access a configurable object (Settings) + * + * @file + * + * @license GNU GPL v2+ + * @since 1.9 + * + * @author mwjames + */ + +/** + * Specifies an interface to access a configurable object (Settings) + * + * @ingroup Utility + */ +interface Configurable { + + /** + * Sets a Settings object + * + * @since 1.9 + * + * @param Settings $settings + */ + public function setSettings( Settings $settings ); + + /** + * Returns Settings object + * + * @since 1.9 + * + * @return Settings + */ + public function getSettings(); + +} diff --git a/includes/utilities/HashIdGenerator.php b/includes/utilities/HashIdGenerator.php index a8a64b8..382b5ec 100644 --- a/includes/utilities/HashIdGenerator.php +++ b/includes/utilities/HashIdGenerator.php @@ -14,24 +14,6 @@ */ /** - * This interface is responsible for generating an id - * - * @ingroup Utility - */ -interface IdGenerator { - - /** - * Generates an id - * - * @since 1.9 - * - * @return string - */ - public function generateId(); - -} - -/** * This class is responsible for generating a Hash Id * * @ingroup Utility diff --git a/includes/utilities/IdGenerator.php b/includes/utilities/IdGenerator.php new file mode 100644 index 0000000..e590ef2 --- /dev/null +++ b/includes/utilities/IdGenerator.php @@ -0,0 +1,32 @@ +<?php + +namespace SMW; + +/** + * Interface describing a Id generrator + * + * @file + * + * @license GNU GPL v2+ + * @since 1.9 + * + * @author mwjames + */ + +/** + * Interface describing a Id generrator + * + * @ingroup Utility + */ +interface IdGenerator { + + /** + * Generates an id + * + * @since 1.9 + * + * @return string + */ + public function generateId(); + +} diff --git a/includes/utilities/Observer.php b/includes/utilities/Observer.php new file mode 100644 index 0000000..9f0d0ac --- /dev/null +++ b/includes/utilities/Observer.php @@ -0,0 +1,52 @@ +<?php + +namespace SMW; + +/** + * Contains interfaces and implementation classes to + * enable a Observer-Subject (or Publisher-Subcriber) pattern where + * objects can indepentanly be notfied about a state change and initiate + * an update of its registered Publisher + * + * @file + * + * @license GNU GPL v2+ + * @since 1.9 + * + * @author mwjames + */ + +/** + * Implement the Subsriber interface resutling in an Observer base class + * that accomodates necessary methods to update an invoked publisher + * + * @ingroup Observer + */ +abstract class Observer implements Subscriber { + + /** + * @since 1.9 + * + * @param Publisher|null $subject + */ + public function __construct( Publisher $subject = null ) { + if ( $subject instanceof Publisher ) { + $subject->attach( $this ); + } + } + + /** + * Update handling of an invoked publisher by relying + * on the state object to carry out the task + * + * @since 1.9 + * + * @param Publisher|null $subject + */ + public function update( Publisher $subject ) { + + if ( method_exists( $this, $subject->getState() ) ) { + call_user_func_array( array( $this, $subject->getState() ), array( $subject ) ); + } + } +} diff --git a/includes/utilities/ObserverInterfaceProvider.php b/includes/utilities/ObserverInterfaceProvider.php deleted file mode 100644 index 77cdbb9..0000000 --- a/includes/utilities/ObserverInterfaceProvider.php +++ /dev/null @@ -1,209 +0,0 @@ -<?php - -namespace SMW; - -/** - * Contains all interfaces and implementation classes to - * enable a Observer-Subject (or Publisher-Subcriber) pattern where - * objects can indepentanly be notfied about a state change and initiate - * an update of its registered Publisher - * - * @file - * - * @license GNU GPL v2+ - * @since 1.9 - * - * @author mwjames - */ - -/** - * Interface describing a Subsriber - * - * @ingroup Observer - */ -interface Subscriber { - - /** - * Receive update from a Publisher - * - * @since 1.9 - * - * @param Publisher $publisher - */ - public function update( Publisher $publisher ); - -} - -/** - * Interface describing a Publisher - * - * @ingroup Observer - */ -interface Publisher { - - /** - * Attach an Subscriber - * - * @since 1.9 - * - * @param Subscriber $subscriber - */ - public function attach( Subscriber $subscriber ); - - /** - * Detach an Subscriber - * - * @since 1.9 - * - * @param Subscriber $subscriber - */ - public function detach( Subscriber $subscriber ); - - /** - * Notify an Subscriber - * - * @since 1.9 - */ - public function notify(); - -} - -/** - * Implement the Subsriber interface resutling in an Observer base class - * that accomodates necessary methods to update an invoked publisher - * - * @ingroup Observer - */ -abstract class Observer implements Subscriber { - - /** - * @since 1.9 - * - * @param Publisher|null $subject - */ - public function __construct( Publisher $subject = null ) { - if ( $subject instanceof Publisher ) { - $subject->attach( $this ); - } - } - - /** - * Update handling of an invoked publisher by relying - * on the state object to carry out the task - * - * @since 1.9 - * - * @param Publisher|null $subject - */ - public function update( Publisher $subject ) { - - if ( method_exists( $this, $subject->getState() ) ) { - call_user_func_array( array( $this, $subject->getState() ), array( $subject ) ); - } - } -} - -/** - * Implement the Publisher interface resulting in an Subject base class - * - * @ingroup Observer - */ -abstract class Subject implements Publisher { - - /** @var Subscriber[] */ - protected $observers = array(); - - /** string */ - protected $state = null; - - /** - * @see Publisher::attach - * - * @since 1.9 - * - * @param Subscriber $observer - */ - public function attach( Subscriber $observer ) { - if ( $this->contains( $observer ) === null ) { - $this->observers[] = $observer; - } - } - - /** - * @since 1.9 - * - * @param Subscriber $observer - */ - public function detach( Subscriber $observer ) { - $index = $this->contains( $observer ); - if ( $index !== null ) { - unset( $this->observers[$index] ); - } - } - - /** - * Returns a string which represents an updateable - * Publisher object method - * - * @since 1.9 - * - * @return string - */ - public function getState() { - return $this->state; - } - - /** - * Set a state variable state and initiates to notify - * the attached Subscribers - * - * @since 1.9 - * - * @param string $state - */ - public function setState( $state ) { - $this->state = $state; - $this->notify(); - } - - /** - * Notifies the updater of all invoked Subscribers - * - * @since 1.9 - */ - public function notify() { - foreach ( $this->observers as $observer ) { - $observer->update( $this ); - } - } - - /** - * Returns registered Observers - * - * @since 1.9 - * - * @return array - */ - public function getObservers() { - return $this->observers; - } - - /** - * Returns an index (or null) of a registered Observer - * - * @since 1.9 - * - * @param Subscriber $observer - * - * @return integer|null - */ - protected function contains( Subscriber $observer ) { - foreach ( $this->observers as $key => $obs ) { - if ( $obs === $observer ) { - return $key; - } - } - return null; - } - -} diff --git a/includes/utilities/Publisher.php b/includes/utilities/Publisher.php new file mode 100644 index 0000000..234db51 --- /dev/null +++ b/includes/utilities/Publisher.php @@ -0,0 +1,51 @@ +<?php + +namespace SMW; + +/** + * Contains interfaces and implementation classes to + * enable a Observer-Subject (or Publisher-Subcriber) pattern where + * objects can indepentanly be notfied about a state change and initiate + * an update of its registered Publisher + * + * @file + * + * @license GNU GPL v2+ + * @since 1.9 + * + * @author mwjames + */ + +/** + * Interface describing a Publisher + * + * @ingroup Observer + */ +interface Publisher { + + /** + * Attach an Subscriber + * + * @since 1.9 + * + * @param Subscriber $subscriber + */ + public function attach( Subscriber $subscriber ); + + /** + * Detach an Subscriber + * + * @since 1.9 + * + * @param Subscriber $subscriber + */ + public function detach( Subscriber $subscriber ); + + /** + * Notify an Subscriber + * + * @since 1.9 + */ + public function notify(); + +} diff --git a/includes/utilities/StoreAccess.php b/includes/utilities/StoreAccess.php new file mode 100644 index 0000000..43d4075 --- /dev/null +++ b/includes/utilities/StoreAccess.php @@ -0,0 +1,41 @@ +<?php + +namespace SMW; + +/** + * Semantic MediaWiki base interface to access a Store object + * + * @file + * + * @license GNU GPL v2+ + * @since 1.9 + * + * @author mwjames + */ + +/** + * Specifies an interface to access a Store object + * + * @ingroup Utility + */ +interface StoreAccess { + + /** + * Sets a Store object + * + * @since 1.9 + * + * @param Store $settings + */ + public function setStore( Store $store ); + + /** + * Returns Store object + * + * @since 1.9 + * + * @return Store + */ + public function getStore(); + +} diff --git a/includes/utilities/Subject.php b/includes/utilities/Subject.php new file mode 100644 index 0000000..5b70349 --- /dev/null +++ b/includes/utilities/Subject.php @@ -0,0 +1,122 @@ +<?php + +namespace SMW; + +/** + * Contains interfaces and implementation classes to + * enable a Observer-Subject (or Publisher-Subcriber) pattern where + * objects can indepentanly be notfied about a state change and initiate + * an update of its registered Publisher + * + * @file + * + * @license GNU GPL v2+ + * @since 1.9 + * + * @author mwjames + */ + +/** + * Implement the Publisher interface resulting in an Subject base class + * + * @ingroup Observer + */ +abstract class Subject implements Publisher { + + /** @var Subscriber[] */ + protected $observers = array(); + + /** string */ + protected $state = null; + + /** + * @see Publisher::attach + * + * @since 1.9 + * + * @param Subscriber $observer + */ + public function attach( Subscriber $observer ) { + if ( $this->contains( $observer ) === null ) { + $this->observers[] = $observer; + } + } + + /** + * @since 1.9 + * + * @param Subscriber $observer + */ + public function detach( Subscriber $observer ) { + $index = $this->contains( $observer ); + if ( $index !== null ) { + unset( $this->observers[$index] ); + } + } + + /** + * Returns a string which represents an updateable + * Publisher object method + * + * @since 1.9 + * + * @return string + */ + public function getState() { + return $this->state; + } + + /** + * Set a state variable state and initiates to notify + * the attached Subscribers + * + * @since 1.9 + * + * @param string $state + */ + public function setState( $state ) { + $this->state = $state; + $this->notify(); + } + + /** + * Notifies the updater of all invoked Subscribers + * + * @since 1.9 + */ + public function notify() { + foreach ( $this->observers as $observer ) { + $observer->update( $this ); + } + } + + /** + * Returns registered Observers + * + * @since 1.9 + * + * @return array + */ + public function getObservers() { + return $this->observers; + } + + /** + * Returns an index (or null) of a registered Observer + * + * @since 1.9 + * + * @param Subscriber $observer + * + * @return integer|null + */ + protected function contains( Subscriber $observer ) { + foreach ( $this->observers as $key => $obs ) { + if ( $obs === $observer ) { + return $key; + } + } + return null; + } + +} diff --git a/includes/utilities/Subscriber.php b/includes/utilities/Subscriber.php new file mode 100644 index 0000000..1f6476f --- /dev/null +++ b/includes/utilities/Subscriber.php @@ -0,0 +1,35 @@ +<?php + +namespace SMW; + +/** + * Contains interfaces and implementation classes to + * enable a Observer-Subject (or Publisher-Subcriber) pattern where + * objects can indepentanly be notfied about a state change and initiate + * an update of its registered Publisher + * + * @file + * + * @license GNU GPL v2+ + * @since 1.9 + * + * @author mwjames + */ + +/** + * Interface describing a Subsriber + * + * @ingroup Observer + */ +interface Subscriber { + + /** + * Receive update from a Publisher + * + * @since 1.9 + * + * @param Publisher $publisher + */ + public function update( Publisher $publisher ); + +} diff --git a/includes/utilities/MediaWikiInterfaceProvider.php b/includes/utilities/TitleProvider.php similarity index 100% rename from includes/utilities/MediaWikiInterfaceProvider.php rename to includes/utilities/TitleProvider.php -- To view, visit https://gerrit.wikimedia.org/r/76917 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9e85bd969156bbef64475132a66cb822a82bae7b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/SemanticMediaWiki Gerrit-Branch: master Gerrit-Owner: Mwjames <jamesin.hongkon...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits