Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

+151
View File
@@ -0,0 +1,151 @@
<?php
/**
* @brief Event
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage
* @since 5/18/2023
*/
namespace IPS\Events;
/* To prevent PHP errors (extending class does not exist) revealing path */
use Exception;
use IPS\Content\Comment;
use IPS\Content\Item;
use IPS\Dispatcher;
use IPS\Log;
if( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
class Event
{
public function __construct(){}
/**
* @brief Store all listeners for each class type
* @var array
*/
protected static array $_listeners = array();
/**
* Fire an event and call all listener methods
*
* @param string $event
* @param object $object
* @param array|null $payload
* @return void
*/
public static function fire( string $event, object $object, ?array $payload = NULL ) : void
{
/* Don't fire any events during an upgrade */
if( Dispatcher::hasInstance() AND Dispatcher::i()->controllerLocation === 'setup' )
{
return;
}
$params = is_array( $payload ) ? array_values( $payload ) : array();
foreach( static::loadListeners( $object ) as $listener )
{
if( method_exists( $listener, $event ) )
{
/* Don't log unless we have something to run */
Log::debug( print_r( array_merge(['event' => $event], ['listener' => $listener::class ], ['payload' => $payload]) , TRUE ), 'event_fire' );
try
{
$listener->$event( $object, ...$params );
}
catch( Exception $e )
{
/* See the error if we're IN_DEV */
if ( \IPS\IN_DEV )
{
throw $e;
}
Log::log( "{$e->getMessage()} exception in " . get_class( $listener ), 'event_fire' );
}
}
}
}
/**
* Load listeners for a particular object
*
* @param object $object
* @return array
*/
protected static function loadListeners( object $object ) : array
{
$class = get_class( $object );
if( !isset( static::$_listeners[ $class ] ) )
{
/* No listening on cloud apps */
if( static::isCloudClass( $class ) )
{
static::$_listeners[ $class ] = [];
return [];
}
$allListeners = ListenerType::allListeners();
if( isset( $allListeners[ $class ] ) )
{
static::$_listeners = [];
foreach( $allListeners[ $class ] as $listener )
{
static::$_listeners[ $class ][] = new $listener;
}
}
/* Check for underlying classes. This is mainly used for Pages,
which doesn't have pre-determined classnames. */
foreach( $allListeners as $extendedClass => $listners )
{
if( is_subclass_of( $class, $extendedClass ) )
{
foreach( $listners as $listener )
{
static::$_listeners[ $class ][] = new $listener;
}
}
}
}
return static::$_listeners[ $class ] ?? array();
}
/**
* Check if this is part of the cloud app
*
* @param string $class
* @return bool
*/
protected static function isCloudClass( string $class ) : bool
{
if( is_subclass_of( $class, Item::class ) AND $class::$application == 'cloud' )
{
return true;
}
if( is_subclass_of( $class, Comment::class ) )
{
$itemClass = $class::$itemClass;
if( $itemClass::$application == 'cloud' )
{
return true;
}
}
return false;
}
}
+144
View File
@@ -0,0 +1,144 @@
<?php
/**
* @brief ListenerAbstract
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage
* @since 5/18/2023
*/
namespace IPS\Events;
/* To prevent PHP errors (extending class does not exist) revealing path */
use IPS\Application;
use IPS\Data\Store;
use IPS\Events\ListenerType\ContentListenerType;
use IPS\Events\ListenerType\InvoiceListenerType;
use IPS\Events\ListenerType\NodeListenerType;
use IPS\Events\ListenerType\PackageListenerType;
use IPS\Events\ListenerType\MemberListenerType;
use OutOfRangeException;
if( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
class ListenerType
{
public function __construct(){}
/**
* @brief [Required] The class that is handled by this listener
* @var string
*/
public static string $class;
/**
* @brief Determine whether this listener requires an explicitly set class
* Example: MemberListeners are always for \IPS\Member, but ContentListeners
* will require a specific class.
* @var bool
*/
public static bool $requiresClassDeclaration = FALSE;
/**
* Defines the classes that are supported by each Listener Type
* When a new Listener Type is created, we must specify which
* classes are valid (e.g. \IPS\Content, \IPS\Member).
*
* @var array
*/
protected static array $supportedBaseClasses = array();
/**
* Check if this listener supports this particular object
*
* @param string $object
* @return bool
*/
public static function supportsObject( string $object ) : bool
{
foreach( static::$supportedBaseClasses as $class )
{
if( $object == $class )
{
return TRUE;
}
/* If we require a class declaration, then we are working with
base classes, like \IPS\Content\Item, which will not necessarily be
a direct match to the base */
if( static::$requiresClassDeclaration AND is_subclass_of( $object, $class ) )
{
return TRUE;
}
}
return FALSE;
}
/**
* Return the class that is extended by this listener
*
* @return string
*/
public static function getExtendedClass() : string
{
if( static::$requiresClassDeclaration )
{
return static::$class;
}
return static::$supportedBaseClasses[0];
}
/**
* Return all listeners
*
* @return array
*/
public static function allListeners() : array
{
try
{
return Store::i()->listeners;
}
catch( OutOfRangeException ){}
$listeners = [];
foreach( Application::allListeners() as $listenerClass )
{
$extendedClass = $listenerClass::getExtendedClass();
if( !isset( $listeners[ $extendedClass ] ) )
{
$listeners[ $extendedClass ] = [];
}
$listeners[ $extendedClass ][] = $listenerClass;
}
Store::i()->listeners = $listeners;
return $listeners;
}
/**
* Return all available listener types
*
* @return array
*/
public static function listenerTypes() : array
{
return array(
'ContentListenerType' => ContentListenerType::class,
'InvoiceListenerType' => InvoiceListenerType::class,
'MemberListenerType' => MemberListenerType::class,
'NodeListenerType' => NodeListenerType::class,
'PackageListenerType' => PackageListenerType::class,
);
}
}
@@ -0,0 +1,60 @@
<?php
/**
* @brief ContentListenerType
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage
* @since 5/23/2023
*/
namespace IPS\Events\ListenerType;
/* To prevent PHP errors (extending class does not exist) revealing path */
use IPS\Content as ContentClass;
use IPS\Content\Comment as CommentClass;
use IPS\Content\Item as ItemClass;
use IPS\Events\ListenerType;
use IPS\Node\Model;
if (!defined('\IPS\SUITE_UNIQUE_KEY')) {
header(($_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0') . ' 403 Forbidden');
exit;
}
/**
* @method onLoad( ContentClass $object ) : void
* @method onBeforeCreateOrEdit( ContentClass $object, array $values, bool $new = FALSE ) : void
* @method onCreateOrEdit( ContentClass $object, array $values, bool $new = FALSE ) : void
* @method onDelete( ContentClass $object ) : void
* @method onStatusChange( ContentClass $object, string $action ) : void
* @method onMerge( ContentClass $object, array $items ) : void
* @method onItemMove( ItemClass $item, Model $oldContainer, bool $keepLink = FALSE ) : void
* @method onCommentMove( CommentClass $comment, ItemClass $oldItem, bool $skip = FALSE ) : void
* @method onItemView( ItemClass $item ) : void
*/
class ContentListenerType extends ListenerType
{
/**
* @brief Determine whether this listener requires an explicitly set class
* Example: MemberListeners are always for \IPS\Member, but ContentListeners
* will require a specific class.
* @var bool
*/
public static bool $requiresClassDeclaration = TRUE;
/**
* Defines the classes that are supported by each Listener Type
* When a new Listener Type is created, we must specify which
* classes are valid (e.g. \IPS\Content, \IPS\Member).
*
* @var array
*/
protected static array $supportedBaseClasses = array(
ItemClass::class,
CommentClass::class
);
}
@@ -0,0 +1,44 @@
<?php
/**
* @brief InvoiceListenerType
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage
* @since 5/23/2023
*/
namespace IPS\Events\ListenerType;
/* To prevent PHP errors (extending class does not exist) revealing path */
use IPS\Events\ListenerType;
use IPS\Member as MemberClass;
use IPS\nexus\Invoice as InvoiceClass;
if( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* @method onStatusChange( InvoiceClass $invoice, string $status ) : void
* @method onCreateAccountForGuest( InvoiceClass $invoice, MemberClass $member, array $guestData ) : void
* @method onCheckout( InvoiceClass $invoice, string $step ) : void
*/
class InvoiceListenerType extends ListenerType
{
/**
* Defines the classes that are supported by each Listener Type
* When a new Listener Type is created, we must specify which
* classes are valid (e.g. \IPS\Content, \IPS\Member).
*
* @var array
*/
protected static array $supportedBaseClasses = array(
InvoiceClass::class
);
}
@@ -0,0 +1,64 @@
<?php
/**
* @brief MemberListenerType
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage
* @since 5/18/2023
*/
namespace IPS\Events\ListenerType;
/* To prevent PHP errors (extending class does not exist) revealing path */
use IPS\calendar\Event;
use IPS\Content as ContentClass;
use IPS\Content\Reaction;
use IPS\Events\ListenerType;
use IPS\Http\Url;
use IPS\Member as MemberClass;
use IPS\Member\Club;
if( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* @method onCreateAccount( MemberClass $member ) : void
* @method onValidate( MemberClass $member ) : void
* @method onLogin( MemberClass $member ) : void
* @method onLogout( MemberClass $member, Url $returnUrl ) : void
* @method onProfileUpdate( MemberClass $member, array $changes ) : void
* @method onSetAsSpammer( MemberClass $member ) : void
* @method onUnSetAsSpammer( MemberClass $member ) : void
* @method onMerge( MemberClass $member, MemberClass $member2 ) : void
* @method onDelete( MemberClass $member ) : void
* @method onEmailChange( MemberClass $member, string $new, string $old ) : void
* @method onPassChange( MemberClass $member, string $new ) : void
* @method onJoinClub( MemberClass $member, Club $club ) : void
* @method onLeaveClub( MemberClass $member, Club $club ) : void
* @method onEventRsvp( MemberClass $member, Event $event, int $response ) : void
* @method onReact( MemberClass $member, ContentClass $content, Reaction $reaction ) : void
* @method onUnreact( MemberClass $member, ContentClass $content ) : void
* @method onFollow( MemberClass $member, object $object, bool $isAnonymous ): void
* @method onUnfollow( MemberClass $member, object $object ) : void
*/
class MemberListenerType extends ListenerType
{
/**
* Defines the classes that are supported by each Listener Type
* When a new Listener Type is created, we must specify which
* classes are valid (e.g. \IPS\Content, \IPS\Member).
*
* @var array
*/
protected static array $supportedBaseClasses = array(
MemberClass::class
);
}
@@ -0,0 +1,49 @@
<?php
/**
* @brief ContentListenerType
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage
* @since 5/23/2023
*/
namespace IPS\Events\ListenerType;
/* To prevent PHP errors (extending class does not exist) revealing path */
use IPS\Events\ListenerType;
use IPS\Node\Model;
if (!defined('\IPS\SUITE_UNIQUE_KEY')) {
header(($_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0') . ' 403 Forbidden');
exit;
}
/**
* @method onLoad( Model $node ) : void
* @method onDelete( Model $node ) : void
*/
class NodeListenerType extends ListenerType
{
/**
* @brief Determine whether this listener requires an explicitly set class
* Example: MemberListeners are always for \IPS\Member, but ContentListeners
* will require a specific class.
* @var bool
*/
public static bool $requiresClassDeclaration = TRUE;
/**
* Defines the classes that are supported by each Listener Type
* When a new Listener Type is created, we must specify which
* classes are valid (e.g. \IPS\Content, \IPS\Member).
*
* @var array
*/
protected static array $supportedBaseClasses = array(
Model::class
);
}
@@ -0,0 +1,65 @@
<?php
/**
* @brief PackageListenerType
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage
* @since 5/22/2023
*/
namespace IPS\Events\ListenerType;
/* To prevent PHP errors (extending class does not exist) revealing path */
use IPS\Events\ListenerType;
use IPS\Member as MemberClass;
use IPS\nexus\Invoice as InvoiceClass;
use IPS\nexus\Invoice\Item as InvoiceItem;
use IPS\nexus\Package as PackageClass;
use IPS\nexus\Purchase as PurchaseClass;
use IPS\nexus\Purchase\RenewalTerm;
if( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* @method onCancel( InvoiceItem $item, PurchaseClass $purchase ) : void
* @method onChange( InvoiceItem $item, PurchaseClass $purchase, PackageClass $newPackage, int|RenewalTerm $chosenRenewalOption = NULL ) : void
* @method onDelete( InvoiceItem $item, PurchaseClass $purchase ) : void
* @method onExpireWarning( InvoiceItem $item, PurchaseClass $purchase ) : void
* @method onExpire( InvoiceItem $item, PurchaseClass $purchase ) : void
* @method onInvoiceCancel( InvoiceItem $item, InvoiceClass $invoice ) : void
* @method onPaid( InvoiceItem $item, InvoiceClass $invoice ) : void
* @method onPurchaseGenerated( InvoiceItem $item, PurchaseClass $purchase, InvoiceClass $invoice ) : void
* @method onReactivate( InvoiceItem $item, PurchaseClass $purchase ) : void
* @method onRenew( InvoiceItem $item, PurchaseClass $purchase, int $cycles ) : void
* @method onTransfer( InvoiceItem $item, PurchaseClass $purchase, MemberClass $newCustomer ) : void
* @method onUnpaid( InvoiceItem $item, InvoiceClass $invoice, string $status ) : void
*/
class PackageListenerType extends ListenerType
{
/**
* @brief Determine whether this listener requires an explicitly set class
* Example: MemberListeners are always for \IPS\Member, but ContentListeners
* will require a specific class.
* @var bool
*/
public static bool $requiresClassDeclaration = TRUE;
/**
* Defines the classes that are supported by each Listener Type
* When a new Listener Type is created, we must specify which
* classes are valid (e.g. \IPS\Content, \IPS\Member).
*
* @var array
*/
protected static array $supportedBaseClasses = array(
InvoiceItem::class
);
}