Skip to content

Commit

Permalink
Update namespace, @SInCE tags, and composer requirements prior to 1.0…
Browse files Browse the repository at this point in the history
….0 release.
  • Loading branch information
Jeremy Ward committed Dec 7, 2018
1 parent 3dc1fbc commit 12c0082
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor/
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# OOPS-WP: Object Oriented Programming Structures for WordPress

This library provides a collection of interfaces and abstract classes
to support object-oriented development in WordPress.

8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
{
"name": "Jeremy Ward",
"email": "jeremy.ward@webdevstudios.com",
"role": "Senior Backend Engineer",
"homepage": "https://jmichaelward.com"
"role": "Senior Backend Engineer"
}
],
"license": "GPL-2.0-or-later",
"require": {
"php": "^7"
},
"autoload": {
"psr-4": {
"WDS\\OopsWP\\": "src/"
"WebDevStudios\\OopsWP\\": "src/"
}
}
}
19 changes: 19 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 16 additions & 8 deletions src/Structure/Content/PostType.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,33 @@
* Abstract class for a custom post type.
*
* @author Jeremy Ward <jeremy.ward@webdevstudios.com>
* @package WDS\OopsWP\Structure\Content
* @package WebDevStudios\OopsWP\Structure\Content
*/

namespace WDS\OopsWP\Structure\Content;
namespace WebDevStudios\OopsWP\Structure\Content;

use WDS\OopsWP\Utility\Registerable;
use WebDevStudios\OopsWP\Utility\Registerable;

/**
* Class PostType
*
* @package WDS\OopsWP\Structure\Content
* @package WebDevStudios\OopsWP\Structure\Content
* @since 1.0.0
*/
abstract class PostType implements Registerable {
/**
* Post type slug.
*
* @var string
* @since 1.0.0
*/
protected $slug;

/**
* Callback to register the post type with WordPress.
*
* @TODO Add exception if slug is null. Extending classes should be defining their own.
* @TODO Add exception if slug is null. Extending classes should be defining their own.
* @since 1.0.0
*/
public function register() {
register_post_type(
Expand All @@ -40,6 +43,9 @@ public function register() {
*
* Defaults: Everything is set to true by default, with full post type support. Extending classes
* can turn off unwanted settings.
*
* @return array
* @since 1.0.0
*/
private function get_default_registration_arguments() {
return [
Expand All @@ -55,16 +61,18 @@ private function get_default_registration_arguments() {
* At a minimum, the extending class should return an empty array.
*
* @return array
* @since 1.0.0
*/
abstract protected function get_registration_arguments() : array;
abstract protected function get_registration_arguments(): array;

/**
* Get the post type labels.
*
* Extending classes should be responsible for adding their own post type labels for translation purposes.
*
* @see https://codex.wordpress.org/Function_Reference/register_post_type#labels
* @see https://codex.wordpress.org/Function_Reference/register_post_type#labels
* @return array
* @since 1.0.0
*/
abstract protected function get_labels() : array;
abstract protected function get_labels(): array;
}
14 changes: 9 additions & 5 deletions src/Structure/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,26 @@
* Class structure that defines a registered service to run within a plugin or theme.
*
* @author Jeremy Ward <jeremy.ward@webdevstudios.com>
* @package WDS\OopsWP\Structure
* @package WebDevStudios\OopsWP\Structure
* @since 1.0.0
*/

namespace WDS\OopsWP\Structure;
namespace WebDevStudios\OopsWP\Structure;

use WDS\OopsWP\Utility\Runnable;
use WDS\OopsWP\Utility\Hookable;
use WebDevStudios\OopsWP\Utility\Runnable;
use WebDevStudios\OopsWP\Utility\Hookable;

/**
* Class Service
*
* @package WDS\OopsWP\Structure
* @package WebDevStudios\OopsWP\Structure
* @since 1.0.0
*/
abstract class Service implements Runnable, Hookable {
/**
* Run the initialization process.
*
* @since 1.0.0
*/
public function run() {
$this->register_hooks();
Expand Down
17 changes: 12 additions & 5 deletions src/Structure/ServiceRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,32 @@
* extends this ServiceRegistrar class
*
* @author Jeremy Ward <jeremy.ward@webdevstudios.com>
* @package WDS\OopsWP\Structure
* @package WebDevStudios\OopsWP\Structure
* @since 1.0.0
*/

namespace WDS\OopsWP\Structure;
namespace WebDevStudios\OopsWP\Structure;

use WDS\OopsWP\Utility\Runnable;
use WebDevStudios\OopsWP\Utility\Runnable;

/**
* Class ServiceRegistrar
*
* @since 1.0.0
*/
abstract class ServiceRegistrar implements Runnable {
/**
* Array of fully-qualified namespaces of services to instantiate.
*
* @var array
* @since 1.0.0
*/
protected $services = [];

/**
* Run the initialization process.
*
* @since 1.0.0
*/
public function run() {
$this->register_services();
Expand All @@ -35,11 +41,12 @@ public function run() {
/**
* Register this object's services.
*
* @TODO Update this method to make registration fail if a service class doesn't extend our Service abstract.
* @TODO Update this method to make registration fail if a service class doesn't extend our Service abstract.
* @since 1.0.0
*/
private function register_services() {
foreach ( $this->services as $service_class ) {
/* @var $service \WDS\OopsWP\Structure\Service Class instance of a Service. */
/* @var $service \WebDevStudios\OopsWP\Structure\Service Class instance of a Service. */
$service = new $service_class();
$service->run();
}
Expand Down
10 changes: 7 additions & 3 deletions src/Utility/Hookable.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@
* Interface for objects that need to register hooks with WordPress.
*
* @author Jeremy Ward <jeremy.ward@webdevstudios.com>
* @package WDS\OopsWP\Utility
* @package WebDevStudios\OopsWP\Utility
* @since 1.0.0
*/

namespace WDS\OopsWP\Utility;
namespace WebDevStudios\OopsWP\Utility;

/**
* Interface Hookable
*
* @package WDS\OopsWP\Utility
* @package WebDevStudios\OopsWP\Utility
* @since 1.0.0
*/
interface Hookable {
/**
* Register actions and filters with WordPress.
*
* @since 1.0.0
*/
public function register_hooks();
}
12 changes: 8 additions & 4 deletions src/Utility/Registerable.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,26 @@
* gets registered on the `init` action. An object that registers the custom post type might register its own hooks,
* and also use this interface as the callback for registering itself.
*
* @see \WDS\OopsWP\Utility\Hookable
* @see \WebDevStudios\OopsWP\Utility\Hookable
*
* @author Jeremy Ward <jeremy.ward@webdevstudios.com>
* @package WDS\OopsWP\Utility
* @package WebDevStudios\OopsWP\Utility
* @since 1.0.0
*/

namespace WDS\OopsWP\Utility;
namespace WebDevStudios\OopsWP\Utility;

/**
* Interface Registerable
*
* @package WDS\OopsWP\Utility
* @package WebDevStudios\OopsWP\Utility
* @since 1.0.0
*/
interface Registerable {
/**
* Register this object with WordPress.
*
* @since 1.0.0
*/
public function register();
}
10 changes: 7 additions & 3 deletions src/Utility/Runnable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@
* One example might be a service object that bootstraps the registration process for a custom post type.
*
* @author Jeremy Ward <jeremy.ward@webdevstudios.com>
* @package WDS\OopsWP\Utility
* @package WebDevStudios\OopsWP\Utility
* @since 1.0.0
*/

namespace WDS\OopsWP\Utility;
namespace WebDevStudios\OopsWP\Utility;

/**
* Interface Runnable
*
* @package WDS\OopsWP\Utility
* @package WebDevStudios\OopsWP\Utility
* @since 1.0.0
*/
interface Runnable {
/**
* Run the initialization process.
*
* @since 1.0.0
*/
public function run();
}

0 comments on commit 12c0082

Please sign in to comment.