-
Notifications
You must be signed in to change notification settings - Fork 0
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
1c40c34
commit 21ff723
Showing
88 changed files
with
4,405 additions
and
15 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
composer.phar | ||
/vendor/ | ||
src/Dependencies | ||
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control | ||
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file | ||
# composer.lock |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
158 changes: 158 additions & 0 deletions
158
src/Dependencies/LaunchpadCore/Activation/Activation.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,158 @@ | ||
<?php | ||
|
||
namespace RocketCDN\Dependencies\LaunchpadCore\Activation; | ||
|
||
use RocketCDN\Dependencies\LaunchpadCore\Container\AbstractServiceProvider; | ||
use RocketCDN\Dependencies\LaunchpadCore\Container\HasInflectorInterface; | ||
use RocketCDN\Dependencies\LaunchpadCore\Container\PrefixAwareInterface; | ||
use RocketCDN\Dependencies\LaunchpadCore\Dispatcher\DispatcherAwareInterface; | ||
use RocketCDN\Dependencies\LaunchpadDispatcher\Dispatcher; | ||
use RocketCDN\Dependencies\Psr\Container\ContainerInterface; | ||
|
||
class Activation { | ||
|
||
/** | ||
* Service providers. | ||
* | ||
* @var array | ||
*/ | ||
protected static $providers = []; | ||
|
||
/** | ||
* Parameters. | ||
* | ||
* @var array | ||
*/ | ||
protected static $params = []; | ||
|
||
/** | ||
* Container. | ||
* | ||
* @var ContainerInterface | ||
*/ | ||
protected static $container; | ||
|
||
/** | ||
* Hook dispatcher. | ||
* | ||
* @var Dispatcher | ||
*/ | ||
protected static $dispatcher; | ||
|
||
/** | ||
* Set service providers. | ||
* | ||
* @param array $providers Service providers. | ||
* @return void | ||
*/ | ||
public static function set_providers( array $providers ) { | ||
self::$providers = $providers; | ||
} | ||
|
||
/** | ||
* Set parameters. | ||
* | ||
* @param array $params Parameters. | ||
* @return void | ||
*/ | ||
public static function set_params( array $params ) { | ||
self::$params = $params; | ||
} | ||
|
||
/** | ||
* Set the container. | ||
* | ||
* @param ContainerInterface $container Container. | ||
* @return void | ||
*/ | ||
public static function set_container( ContainerInterface $container ) { | ||
self::$container = $container; | ||
} | ||
|
||
/** | ||
* Set hook dispatcher. | ||
* | ||
* @param Dispatcher $dispatcher Hook dispatcher. | ||
* @return void | ||
*/ | ||
public static function set_dispatcher( Dispatcher $dispatcher ): void { | ||
self::$dispatcher = $dispatcher; | ||
} | ||
|
||
/** | ||
* Performs these actions during the plugin activation | ||
* | ||
* @return void | ||
*/ | ||
public static function activate_plugin() { | ||
|
||
$container = self::$container; | ||
|
||
foreach ( self::$params as $key => $value ) { | ||
self::$container->add( $key, $value ); | ||
} | ||
|
||
$container->share( 'dispatcher', self::$dispatcher ); | ||
|
||
$container->inflector( PrefixAwareInterface::class )->invokeMethod( 'set_prefix', [ key_exists( 'prefix', self::$params ) ? self::$params['prefix'] : '' ] ); | ||
$container->inflector( DispatcherAwareInterface::class )->invokeMethod( 'set_dispatcher', [ $container->get( 'dispatcher' ) ] ); | ||
|
||
$providers = array_filter( | ||
self::$providers, | ||
function ( $provider ) { | ||
if ( is_string( $provider ) ) { | ||
$provider = new $provider(); | ||
} | ||
|
||
if ( ! $provider instanceof ActivationServiceProviderInterface && ( ! $provider instanceof HasInflectorInterface || count( $provider->get_inflectors() ) === 0 ) ) { | ||
return false; | ||
} | ||
|
||
return $provider; | ||
} | ||
); | ||
|
||
/** | ||
* Activation providers. | ||
* | ||
* @param AbstractServiceProvider[] $providers Providers. | ||
* @return AbstractServiceProvider[] | ||
*/ | ||
$providers = apply_filters( "{$container->get('prefix')}deactivate_providers", $providers ); | ||
|
||
$providers = array_map( | ||
function ( $provider ) { | ||
if ( is_string( $provider ) ) { | ||
return new $provider(); | ||
} | ||
return $provider; | ||
}, | ||
$providers | ||
); | ||
|
||
foreach ( $providers as $provider ) { | ||
self::$container->addServiceProvider( $provider ); | ||
} | ||
|
||
foreach ( $providers as $service_provider ) { | ||
if ( ! $service_provider instanceof HasInflectorInterface ) { | ||
continue; | ||
} | ||
$service_provider->register_inflectors(); | ||
} | ||
|
||
foreach ( $providers as $provider ) { | ||
if ( ! $provider instanceof HasActivatorServiceProviderInterface ) { | ||
continue; | ||
} | ||
|
||
foreach ( $provider->get_activators() as $activator ) { | ||
$activator_instance = self::$container->get( $activator ); | ||
if ( ! $activator_instance instanceof ActivationInterface ) { | ||
continue; | ||
} | ||
$activator_instance->activate(); | ||
} | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/Dependencies/LaunchpadCore/Activation/ActivationInterface.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,14 @@ | ||
<?php | ||
|
||
namespace RocketCDN\Dependencies\LaunchpadCore\Activation; | ||
|
||
interface ActivationInterface { | ||
|
||
|
||
/** | ||
* Executes this method on plugin activation | ||
* | ||
* @return void | ||
*/ | ||
public function activate(); | ||
} |
8 changes: 8 additions & 0 deletions
8
src/Dependencies/LaunchpadCore/Activation/ActivationServiceProviderInterface.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,8 @@ | ||
<?php | ||
|
||
namespace RocketCDN\Dependencies\LaunchpadCore\Activation; | ||
|
||
interface ActivationServiceProviderInterface { | ||
|
||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/Dependencies/LaunchpadCore/Activation/HasActivatorServiceProviderInterface.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,13 @@ | ||
<?php | ||
|
||
namespace RocketCDN\Dependencies\LaunchpadCore\Activation; | ||
|
||
interface HasActivatorServiceProviderInterface extends ActivationServiceProviderInterface { | ||
|
||
/** | ||
* Returns list of activators. | ||
* | ||
* @return string[] | ||
*/ | ||
public function get_activators(): array; | ||
} |
Oops, something went wrong.