diff --git a/CHANGELOG.md b/CHANGELOG.md index 4eadf4b..8f75805 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ All notable changes to this project will be documented in this file. This projec - Added [stellarwp/db](https://github.com/stellarwp/db) as a dependency. - Swapped out direct `$wpdb` calls with the `DB` class. - Added some tests for index checking on tables. +- Reorganized abstract classes and interfaces into `Contracts/` directories. +- Switched away from `StellarWP\Schema\Container` in favor of using `lucatume\DI52\App` and `lucatume\DI52\Container`. ## [1.0.0] 2022-08-17 diff --git a/src/Schema/Activation.php b/src/Schema/Activation.php index 364b7b3..7ab565b 100644 --- a/src/Schema/Activation.php +++ b/src/Schema/Activation.php @@ -65,13 +65,16 @@ public static function init() { $schema_builder->up(); } - if ( ! Config::get_container()->get( 'stellarwp_schema_fully_activated' ) ) { + if ( + ! $container->has( 'stellarwp_schema_fully_activated' ) + && ! $container->get( 'stellarwp_schema_fully_activated' ) + ) { /** * On new installations the full activation code will find an empty state and * will have not activated at this point, do it now if required. */ - Config::get_container()->singleton( Full_Activation_Provider::class, Full_Activation_Provider::class ); - Config::get_container()->get( Full_Activation_Provider::class )->register(); + $container->singleton( Full_Activation_Provider::class, Full_Activation_Provider::class ); + $container->get( Full_Activation_Provider::class )->register(); } } diff --git a/src/Schema/Builder.php b/src/Schema/Builder.php index 1873bc0..7c572c8 100644 --- a/src/Schema/Builder.php +++ b/src/Schema/Builder.php @@ -4,8 +4,9 @@ use StellarWP\Schema\Config; use StellarWP\Schema\Fields; +use StellarWP\Schema\Fields\Contracts\Schema_Interface as Field_Schema_Interface; use StellarWP\Schema\Tables; -use StellarWP\Schema\Tables\Table_Schema_Interface; +use StellarWP\Schema\Tables\Contracts\Schema_Interface as Table_Schema_Interface; use StellarWP\Schema\Tables\Filters\Group_FilterIterator; use WP_CLI; @@ -89,7 +90,7 @@ public function down() { * * @since 1.0.0 * - * @param \Iterator $table_schemas A list of Custom_Table_Interface objects that will have their tables dropped. + * @param \Iterator $table_schemas A list of Table_Schema_Interface objects that will have their tables dropped. */ $table_schemas = apply_filters( 'stellarwp_tables_to_drop', $table_schemas ); @@ -118,7 +119,7 @@ public function down() { * * @since 1.0.0 * - * @param \Iterator $field_classes A list of Custom_Field_Interface objects that will have their fields dropped. + * @param \Iterator $field_classes A list of Field_Schema_Interface objects that will have their fields dropped. */ $field_schemas = apply_filters( 'stellarwp_fields_to_drop', $field_schemas ); diff --git a/src/Schema/Fields/Collection.php b/src/Schema/Fields/Collection.php index 063856e..32e0bd2 100644 --- a/src/Schema/Fields/Collection.php +++ b/src/Schema/Fields/Collection.php @@ -2,6 +2,8 @@ namespace StellarWP\Schema\Fields; +use StellarWP\Schema\Fields\Contracts\Schema_Interface; + class Collection implements \ArrayAccess, \Countable, \Iterator { /** * Table groups. @@ -22,11 +24,11 @@ class Collection implements \ArrayAccess, \Countable, \Iterator { * * @since 1.0.0 * - * @param Field_Schema_Interface $field Field instance. + * @param Schema_Interface $field Field instance. * * @return mixed */ - public function add( Field_Schema_Interface $field ) { + public function add( Schema_Interface $field ) { $this->offsetSet( $field::get_schema_slug(), $field ); $this->register_group( $field ); @@ -55,9 +57,9 @@ public function current() { * * @param string $key Field slug. * - * @return Field_Schema_Interface + * @return Schema_Interface */ - public function get( string $key ): Field_Schema_Interface { + public function get( string $key ): Schema_Interface { return $this->offsetGet( $key ); } @@ -120,7 +122,7 @@ public function offsetUnset( $offset ): void { /** * Registers a group in the group array for the given table. * - * @param Field_Schema_Interface $field Field instance. + * @param Schema_Interface $field Field instance. */ private function register_group( $field ) { $group = $field->group_name(); @@ -154,11 +156,11 @@ public function rewind(): void { * @since 1.0.0 * * @param string $name Field name. - * @param Field_Schema_Interface $field Field instance. + * @param Schema_Interface $field Field instance. * * @return mixed */ - public function set( $name, Field_Schema_Interface $field ) { + public function set( $name, Schema_Interface $field ) { $this->offsetSet( $name, $field ); $this->register_group( $field ); diff --git a/src/Schema/Fields/Abstract_Field.php b/src/Schema/Fields/Contracts/Field.php similarity index 92% rename from src/Schema/Fields/Abstract_Field.php rename to src/Schema/Fields/Contracts/Field.php index a13b0d1..b7e547e 100644 --- a/src/Schema/Fields/Abstract_Field.php +++ b/src/Schema/Fields/Contracts/Field.php @@ -4,22 +4,22 @@ * * @since 1.0.0 * - * @package StellarWP\Schema\Fields + * @package StellarWP\Schema\Fields\Contracts */ -namespace StellarWP\Schema\Fields; +namespace StellarWP\Schema\Fields\Contracts; use StellarWP\Schema\Config; use StellarWP\Schema\Schema; /** - * Class Abstract_Field + * Class Field * * @since 1.0.0 * - * @package StellarWP\Schema\Fields + * @package StellarWP\Schema\Fields\Contracts */ -abstract class Abstract_Field implements Field_Schema_Interface { +abstract class Field implements Schema_Interface { /** * @since 1.0.0 * @@ -139,7 +139,7 @@ public function drop() { * @since 1.0.0 * * @param string $schema_slug The schema slug. - * @param Field_Schema_Interface $field_schema The field schema to be dropped. + * @param Schema_Interface $field_schema The field schema to be dropped. */ do_action( 'stellarwp_pre_drop_field', $schema_slug, $this ); @@ -154,7 +154,7 @@ public function drop() { * @since 1.0.0 * * @param string $schema_slug The schema slug. - * @param Field_Schema_Interface $field_schema The field schema to be dropped. + * @param Schema_Interface $field_schema The field schema to be dropped. */ do_action( 'stellarwp_post_drop_field', $schema_slug, $this ); @@ -166,7 +166,7 @@ public function drop() { * @since 1.0.0 * * @param string $schema_slug The schema slug. - * @param Field_Schema_Interface $field_schema The field schema to be dropped. + * @param Schema_Interface $field_schema The field schema to be dropped. */ do_action( 'stellarwp_post_drop_field_table_version_sync', $schema_slug, $this ); diff --git a/src/Schema/Fields/Field_Schema_Interface.php b/src/Schema/Fields/Contracts/Schema_Interface.php similarity index 88% rename from src/Schema/Fields/Field_Schema_Interface.php rename to src/Schema/Fields/Contracts/Schema_Interface.php index 98a8d6b..eaf53a6 100644 --- a/src/Schema/Fields/Field_Schema_Interface.php +++ b/src/Schema/Fields/Contracts/Schema_Interface.php @@ -4,20 +4,20 @@ * * @since 1.0.0 * - * @package StellarWP\Schema\Fields + * @package StellarWP\Schema\Fields\Contracts */ -namespace StellarWP\Schema\Fields; +namespace StellarWP\Schema\Fields\Contracts; -use StellarWP\Schema\Tables\Abstract_Table; +use StellarWP\Schema\Tables\Contracts\Table; /** * Interface Custom_Field_Interface * * @since 1.0.0 * - * @package StellarWP\Schema\Fields + * @package StellarWP\Schema\Fields\Contracts */ -interface Field_Schema_Interface { +interface Schema_Interface { /** * Allows extending classes that require it to run some methods * immediately after the table creation or update. @@ -75,7 +75,7 @@ public static function group_name(); * * @since 1.0.0 * - * @return Abstract_Table|null + * @return Table|null */ public function table_schema(); } diff --git a/src/Schema/Register.php b/src/Schema/Register.php index 75eb6e8..b812633 100644 --- a/src/Schema/Register.php +++ b/src/Schema/Register.php @@ -18,7 +18,7 @@ class Register { * * @param string $field Field class. * - * @return Fields\Field_Schema_Interface + * @return Fields\Contracts\Schema_Interface */ public static function field( $field ) { Schema::init(); @@ -61,9 +61,9 @@ public static function fields( array $fields ) { * * @since 1.0.0 * - * @param string|Fields\Field_Schema_Interface $field Field Schema class. + * @param string|Fields\Contracts\Schema_Interface $field Field Schema class. * - * @return Fields\Field_Schema_Interface + * @return Fields\Contracts\Schema_Interface */ public static function remove_field( $field ) { Schema::init(); @@ -87,9 +87,9 @@ public static function remove_field( $field ) { * * @since 1.0.0 * - * @param string|Tables\Table_Schema_Interface $table Table Schema class. + * @param string|Tables\Contracts\Schema_Interface $table Table Schema class. * - * @return Tables\Table_Schema_Interface + * @return Tables\Contracts\Schema_Interface */ public static function remove_table( $table ) { Schema::init(); @@ -115,7 +115,7 @@ public static function remove_table( $table ) { * * @param string $table Table class. * - * @return Tables\Table_Schema_Interface + * @return Tables\Contracts\Schema_Interface */ public static function table( $table ) { Schema::init(); diff --git a/src/Schema/Schema.php b/src/Schema/Schema.php index 5ef0591..f5f3f6c 100644 --- a/src/Schema/Schema.php +++ b/src/Schema/Schema.php @@ -52,7 +52,7 @@ public static function init(): void { $container = Config::get_container(); - if ( $container->get( 'stellarwp_schema_registered' ) ) { + if ( $container->has( 'stellarwp_schema_registered' ) && $container->get( 'stellarwp_schema_registered' ) ) { return; } diff --git a/src/Schema/Tables/Collection.php b/src/Schema/Tables/Collection.php index 6a8ea74..4ba103e 100644 --- a/src/Schema/Tables/Collection.php +++ b/src/Schema/Tables/Collection.php @@ -2,6 +2,8 @@ namespace StellarWP\Schema\Tables; +use StellarWP\Schema\Tables\Contracts\Schema_Interface; + class Collection implements \ArrayAccess, \Countable, \Iterator { /** * Table groups. @@ -22,11 +24,11 @@ class Collection implements \ArrayAccess, \Countable, \Iterator { * * @since 1.0.0 * - * @param Table_Schema_Interface $table Table instance. + * @param Schema_Interface $table Table instance. * * @return mixed */ - public function add( Table_Schema_Interface $table ) { + public function add( Schema_Interface $table ) { $this->offsetSet( $table::base_table_name(), $table ); $this->register_group( $table ); @@ -55,9 +57,9 @@ public function current() { * * @param string $key Table base name. * - * @return Table_Schema_Interface + * @return Schema_Interface */ - public function get( string $key ): Table_Schema_Interface { + public function get( string $key ): Schema_Interface { return $this->offsetGet( $key ); } @@ -133,7 +135,7 @@ public function offsetUnset( $offset ): void { /** * Registers a group in the group array for the given table. * - * @param Table_Schema_Interface $table Table instance. + * @param Schema_Interface $table Table instance. */ private function register_group( $table ) { $group = $table->group_name(); @@ -167,11 +169,11 @@ public function rewind(): void { * @since 1.0.0 * * @param string $name Table name. - * @param Table_Schema_Interface $table Table instance. + * @param Schema_Interface $table Table instance. * * @return mixed */ - public function set( $name, Table_Schema_Interface $table ) { + public function set( $name, Schema_Interface $table ) { $this->offsetSet( $name, $table ); $this->register_group( $table ); diff --git a/src/Schema/Tables/Table_Schema_Interface.php b/src/Schema/Tables/Contracts/Schema_Interface.php similarity index 92% rename from src/Schema/Tables/Table_Schema_Interface.php rename to src/Schema/Tables/Contracts/Schema_Interface.php index f51bb03..03062cb 100644 --- a/src/Schema/Tables/Table_Schema_Interface.php +++ b/src/Schema/Tables/Contracts/Schema_Interface.php @@ -4,19 +4,19 @@ * * @since 1.0.0 * - * @package StellarWP\Schema\Tables + * @package StellarWP\Schema\Tables\Contracts */ -namespace StellarWP\Schema\Tables; +namespace StellarWP\Schema\Tables\Contracts; /** - * Interface Table_Schema_Interface + * Interface Schema_Interface * * @since 1.0.0 * - * @package StellarWP\Schema\Tables + * @package StellarWP\Schema\Tables\Contracts */ -interface Table_Schema_Interface { +interface Schema_Interface { /** * Returns the custom table name. * diff --git a/src/Schema/Tables/Abstract_Table.php b/src/Schema/Tables/Contracts/Table.php similarity index 96% rename from src/Schema/Tables/Abstract_Table.php rename to src/Schema/Tables/Contracts/Table.php index 908c0d6..5b3c4c9 100644 --- a/src/Schema/Tables/Abstract_Table.php +++ b/src/Schema/Tables/Contracts/Table.php @@ -1,12 +1,12 @@ get_simple_table() ); - $builder = Config::get_container()->make( Builder::class ); + $builder = Config::get_container()->get( Builder::class ); $table_schemas = $builder->get_registered_table_schemas(); $this->assertNotEmpty( $table_schemas ); diff --git a/tests/wpunit/RegisterTest.php b/tests/wpunit/RegisterTest.php index e7aec27..555a943 100644 --- a/tests/wpunit/RegisterTest.php +++ b/tests/wpunit/RegisterTest.php @@ -2,11 +2,11 @@ namespace StellarWP\Schema\Tests; +use lucatume\DI52\App; use StellarWP\Schema\Config; use StellarWP\Schema\Fields; use StellarWP\Schema\Register; use StellarWP\Schema\Schema; -use StellarWP\Schema\Tables; use StellarWP\Schema\Tests\Traits\Table_Fixtures; class RegisterTest extends SchemaTestCase { @@ -22,7 +22,7 @@ public function it_should_have_fields_in_collection_when_added_individually() { Register::field( $field_1 ); - $this->assertArrayHasKey( $field_1::get_schema_slug(), Config::get_container()->make( Fields\Collection::class ) ); + $this->assertArrayHasKey( $field_1::get_schema_slug(), Config::get_container()->get( Fields\Collection::class ) ); } /** @@ -37,7 +37,7 @@ public function it_should_have_fields_in_collection_when_batch_added() { $field_1, ]); - $this->assertArrayHasKey( $field_1::get_schema_slug(), Config::get_container()->make( Fields\Collection::class ) ); + $this->assertArrayHasKey( $field_1::get_schema_slug(), Config::get_container()->get( Fields\Collection::class ) ); } /** diff --git a/tests/wpunit/Tables/TableTest.php b/tests/wpunit/Tables/TableTest.php index ac5e45d..96dd227 100644 --- a/tests/wpunit/Tables/TableTest.php +++ b/tests/wpunit/Tables/TableTest.php @@ -2,9 +2,7 @@ namespace StellarWP\Schema\Tests\Tables; -use StellarWP\Schema\Tables\Table_Schema_Interface; use StellarWP\Schema\Register; -use StellarWP\Schema\Schema; use StellarWP\Schema\Tests\SchemaTestCase; use StellarWP\Schema\Tests\Traits\Table_Fixtures;