Skip to content

Commit

Permalink
Merge pull request #6 from stellarwp/fix/relocate-contracts
Browse files Browse the repository at this point in the history
Reorganize abstracts & interfaces
  • Loading branch information
borkweb authored Oct 7, 2022
2 parents 08c1159 + 84122ba commit c0a86c8
Show file tree
Hide file tree
Showing 17 changed files with 78 additions and 69 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 6 additions & 3 deletions src/Schema/Activation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/Schema/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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 );

Expand Down
16 changes: 9 additions & 7 deletions src/Schema/Fields/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace StellarWP\Schema\Fields;

use StellarWP\Schema\Fields\Contracts\Schema_Interface;

class Collection implements \ArrayAccess, \Countable, \Iterator {
/**
* Table groups.
Expand All @@ -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 );
Expand Down Expand Up @@ -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 );
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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 );

Expand All @@ -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 );

Expand All @@ -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 );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -75,7 +75,7 @@ public static function group_name();
*
* @since 1.0.0
*
* @return Abstract_Table|null
* @return Table|null
*/
public function table_schema();
}
12 changes: 6 additions & 6 deletions src/Schema/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
16 changes: 9 additions & 7 deletions src/Schema/Tables/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace StellarWP\Schema\Tables;

use StellarWP\Schema\Tables\Contracts\Schema_Interface;

class Collection implements \ArrayAccess, \Countable, \Iterator {
/**
* Table groups.
Expand All @@ -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 );
Expand Down Expand Up @@ -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 );
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Loading

0 comments on commit c0a86c8

Please sign in to comment.