Skip to content

Commit

Permalink
PSR-4 + refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
joanrodas committed Apr 14, 2022
1 parent c0fcc87 commit 2cee17c
Show file tree
Hide file tree
Showing 33 changed files with 197 additions and 191 deletions.
7 changes: 5 additions & 2 deletions admin/admin-menus.php → Admin/AdminMenus.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php
namespace PluginPlaceholder\Admin;

class PluginPlaceholderAdminMenus {
use PluginPlaceholder\Includes\BladeLoader;

class AdminMenus {

protected $plugin_name;
protected $plugin_version;
Expand All @@ -10,7 +13,7 @@ class PluginPlaceholderAdminMenus {
public function __construct( $plugin_name, $plugin_version ) {
$this->plugin_name = $plugin_name;
$this->plugin_version = $plugin_version;
$this->blade = PluginPlaceholderBlade::getInstance();
$this->blade = BladeLoader::getInstance();

$this->add_menus();
}
Expand Down
3 changes: 2 additions & 1 deletion admin/ajax-actions.php → Admin/AjaxActions.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace PluginPlaceholder\Admin;

class PluginPlaceholderAjaxActions {
class AjaxActions {

protected $plugin_name;
protected $plugin_version;
Expand Down
3 changes: 2 additions & 1 deletion admin/crons.php → Admin/Crons.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace PluginPlaceholder\Admin;

class PluginPlaceholderCrons {
class Crons {

protected $plugin_name;
protected $plugin_version;
Expand Down
7 changes: 5 additions & 2 deletions admin/emails.php → Admin/Emails.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php
namespace PluginPlaceholder\Admin;

class PluginPlaceholderEmails {
use PluginPlaceholder\Includes\BladeLoader;

class Emails {

protected $plugin_name;
protected $plugin_version;
Expand All @@ -10,7 +13,7 @@ class PluginPlaceholderEmails {
public function __construct( $plugin_name, $plugin_version ) {
$this->plugin_name = $plugin_name;
$this->plugin_version = $plugin_version;
$this->blade = PluginPlaceholderBlade::getInstance();
$this->blade = BladeLoader::getInstance();

$this->send_emails();
}
Expand Down
3 changes: 2 additions & 1 deletion admin/post-actions.php → Admin/PostActions.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace PluginPlaceholder\Admin;

class PluginPlaceholderPostActions {
class PostActions {

protected $plugin_name;
protected $plugin_version;
Expand Down
4 changes: 3 additions & 1 deletion public/api-endpoints.php → General/ApiEndpoints.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php
namespace PluginPlaceholder\General;

use PluboRoutes\Endpoint\GetEndpoint;
use PluboRoutes\Endpoint\PostEndpoint;
use PluboRoutes\Endpoint\PutEndpoint;
use PluboRoutes\Endpoint\DeleteEndpoint;

class PluginPlaceholderApiEndpoints {
class ApiEndpoints {

protected $plugin_name;
protected $plugin_version;
Expand Down
4 changes: 3 additions & 1 deletion public/custom-fields.php → General/CustomFields.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php
namespace PluginPlaceholder\General;

use Carbon_Fields\Container;
use Carbon_Fields\Field;

class PluginPlaceholderCustomFields {
class CustomFields {

protected $plugin_name;
protected $plugin_version;
Expand Down
3 changes: 2 additions & 1 deletion public/custom-post-types.php → General/CustomPostTypes.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace PluginPlaceholder\General;

class PluginPlaceholderCustomPostTypes {
class CustomPostTypes {

protected $plugin_name;
protected $plugin_version;
Expand Down
4 changes: 3 additions & 1 deletion public/routes.php → General/Routes.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php
namespace PluginPlaceholder\General;

use PluboRoutes\Route\Route;
use PluboRoutes\Route\ActionRoute;
use PluboRoutes\Route\RedirectRoute;

class PluginPlaceholderRoutes {
class Routes {

protected $plugin_name;
protected $plugin_version;
Expand Down
7 changes: 5 additions & 2 deletions public/shortcodes.php → General/Shortcodes.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php
namespace PluginPlaceholder\General;

class PluginPlaceholderShortcodes {
use PluginPlaceholder\Includes\BladeLoader;

class Shortcodes {

protected $plugin_name;
protected $plugin_version;
Expand All @@ -10,7 +13,7 @@ class PluginPlaceholderShortcodes {
public function __construct( $plugin_name, $plugin_version ) {
$this->plugin_name = $plugin_name;
$this->plugin_version = $plugin_version;
$this->blade = PluginPlaceholderBlade::getInstance();
$this->blade = BladeLoader::getInstance();

add_action( 'init', array($this, 'add_shortcodes') );
}
Expand Down
3 changes: 2 additions & 1 deletion public/taxonomies.php → General/Taxonomies.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace PluginPlaceholder\General;

class PluginPlaceholderTaxonomies {
class Taxonomies {

protected $plugin_name;
protected $plugin_version;
Expand Down
10 changes: 10 additions & 0 deletions Includes/Activator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace PluginPlaceholder\Includes;

class Activator {

public static function activate() {

}

}
6 changes: 4 additions & 2 deletions includes/blade.php → Includes/BladeLoader.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php
namespace PluginPlaceholder\Includes;

use Jenssegers\Blade\Blade;

class PluginPlaceholderBlade
class BladeLoader
{
private static $instance = NULL;
private $blade;
Expand All @@ -20,7 +22,7 @@ private function __clone() { }

public static function getInstance() {
if ( is_null(self::$instance) ) {
self::$instance = new PluginPlaceholderBlade();
self::$instance = new BladeLoader();
}
return self::$instance;
}
Expand Down
10 changes: 10 additions & 0 deletions Includes/Deactivator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace PluginPlaceholder\Includes;

class Deactivator {

public static function deactivate() {

}

}
3 changes: 2 additions & 1 deletion includes/i18n.php → Includes/Languages.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace PluginPlaceholder\Includes;

class PluginPlaceholderi18n {
class Languages {

public function __construct() {
add_action( 'plugins_loaded', array( $this, 'load_plugin_textdomain' ) );
Expand Down
60 changes: 60 additions & 0 deletions Includes/Loader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
namespace PluginPlaceholder\Includes;

use PluginPlaceholder\Admin\AdminMenus;
use PluginPlaceholder\Admin\AjaxActions;
use PluginPlaceholder\Admin\PostActions;

use PluginPlaceholder\General\ApiEndpoints;
use PluginPlaceholder\General\CustomFields;
use PluginPlaceholder\General\CustomPostTypes;
use PluginPlaceholder\General\Routes;
use PluginPlaceholder\General\Shortcodes;
use PluginPlaceholder\General\Taxonomies;

use PluginPlaceholder\React\ReactLoader;

class Loader {

protected $plugin_name;
protected $plugin_version;

public function __construct() {
$this->plugin_version = defined( 'PLUGIN_PLACEHOLDER_VERSION' ) ? PLUGIN_PLACEHOLDER_VERSION : '1.0.0';
$this->plugin_name = 'plugin-placeholder';
$this->load_dependencies();
}

private function load_dependencies() {
\PluboRoutes\PluboRoutesProcessor::init();

$plugin_i18n = new Languages();

$react = new ReactLoader( $this->plugin_name, $this->plugin_version );

$admin_menus = new AdminMenus($this->plugin_name, $this->plugin_version);
$ajax_actions = new AjaxActions($this->plugin_name, $this->plugin_version);
$post_actions = new PostActions($this->plugin_name, $this->plugin_version);

$api_endpoints = new ApiEndpoints($this->plugin_name, $this->plugin_version);
$custom_fields = new CustomFields($this->plugin_name, $this->plugin_version);
$custom_post_types = new CustomPostTypes($this->plugin_name, $this->plugin_version);
$routes = new Routes($this->plugin_name, $this->plugin_version);
$shortcodes = new Shortcodes($this->plugin_name, $this->plugin_version);
$taxonomies = new Taxonomies($this->plugin_name, $this->plugin_version);

add_filter( 'do_shortcode_tag', function($output, $tag, $attr) {
return "<span style='display: none;' class='plubo-shortcode' data-tag='$tag'></span>" . $output;
}, 22, 3);

add_action('wp_enqueue_scripts', function () {
wp_enqueue_style('plugin-placeholder/app.css', PLUGIN_PLACEHOLDER_URL . 'dist/app.css', false, null);
wp_enqueue_script('plugin-placeholder/app.js', PLUGIN_PLACEHOLDER_URL . 'dist/app.js', [], null, true);

wp_localize_script( 'plugin-placeholder/app.js', 'plugin_placeholder_ajax', array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'ajax-nonce' ),
) );
}, 100);
}
}
30 changes: 30 additions & 0 deletions Includes/Utils.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
namespace PluginPlaceholder\Includes;

class Utils
{
private static $instance = NULL;

private function __construct() {

}

// Clone not allowed
private function __clone() { }

public static function getInstance() {
if ( is_null(self::$instance) ) {
self::$instance = new Utils();
}
return self::$instance;
}

public function make_directive(string $name, callable $handler) {
$this->blade->directive($name, $handler);
}

public function template( $name, $args=array() ) {
return $this->blade->render($name, $args);
}

}
4 changes: 3 additions & 1 deletion react/loader.php → React/ReactLoader.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php
class PluginPlaceholderReactLoader {
namespace PluginPlaceholder\React;

class ReactLoader {

protected $plugin_name;
protected $plugin_version;
Expand Down
File renamed without changes.
File renamed without changes.
32 changes: 0 additions & 32 deletions admin/admin.php

This file was deleted.

7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@
"role": "Developer"
}
],
"autoload": {
"psr-4": {
"PluginPlaceholder\\": ""
}
},
"require": {
"php": ">=7.4",
"jenssegers/blade": "^1.4",
"htmlburger/carbon-fields": "^3.3",
"joanrodas/plubo-routes": "^0.1.0"
"joanrodas/plubo-routes": "^0.4.0"
},
"scripts": {
"post-create-project-cmd": [
Expand Down
Loading

0 comments on commit 2cee17c

Please sign in to comment.