Morningmedley Framework

website·Indexed 30 days ago

https://morningmedley.dev

A development framework designed for creating larger and more complex WordPress projects. It provides a structured application container and various modules including Eloquent database integration, Laravel Blade templating for views, REST API extensions, routing, queue management, and feature flagging.

Tokens
8.5K
Snippets
62
Records
70
Agent score
53%

What's inside Morningmedley

  1. Overview of the Morningmedley framework

    Morningmedley is a development framework designed for building large and complex WordPress applications. It provides a structured architecture to prevent the common issue of bloated functions.php files and technical debt by ensuring every component has a designated place. The framework is built as a collection of software packages installed via Composer, leveraging Symfony components to enhance WordPress usability and functionality.
  2. Overview of Morning Medley Database Integration

    The Database module implements Illuminate Database with a custom connection that utilizes the global WordPress $wpdb instance. This ensures that all queries performed using the default driver and connection are routed through WordPress. Because it wraps Illuminate Database, most standard Laravel database documentation is applicable.
  3. Run Laravel Artisan commands via WP-CLI

    Morningmedley integrates Laravel Artisan as a subcommand of the WordPress CLI. This allows developers to use standard Artisan commands and tools within a WordPress environment by prefixing them with wp artisan.
    wp artisan
  4. Morningmedley Queue implementation overview

    The Morningmedley Queue package implements the Illuminate Queue system. Because it is a wrapper for Illuminate Queue, most standard Laravel queue documentation is applicable. Note that not all Artisan commands are supported; use wp artisan to verify available commands in your environment.
  5. Initialize the Queue database tables

    Before using the queue system, you must create the necessary database tables for job tracking and failed job logging using the following Artisan commands.
    wp artisan make:queue-table
    wp artisan make:queue-failed-table
    wp artisan migrate
  6. Initialize the Morningmedley Application

    If the application was not automatically initialized via create-project, you must manually boot the Composer autoloader and require the application bootstrap file. The app.php file must return a configured and created instance of the Morningmedley application.
    // In functions.php
    require __DIR__ . "/vendor/autoload.php";
    require __DIR__ . "/bootstrap/app.php";
    
    // In bootstrap/app.php
    return MorningMedley::configure(dirname(__FILE__, 2))
        ->create();
  7. Create a new Morningmedley theme or plugin

    To create a new Morningmedley app, navigate to the WordPress /themes or /plugins directory and use composer create-project. The framework automatically determines whether to create theme-relevant files or plugin files based on whether the parent directory is named themes or plugins. After creation, update style.css (for themes) or plugin.php (for plugins) to match your project details.
    composer create-project morningmedley/app project-name
  8. Install Morning Medley View

    Morning Medley View allows the use of Laravel Blade templates within WordPress for server-side rendering of pages and components.
    composer require morningmedley/view
  9. Create a custom module and ServiceProvider in Morningmedley

    Modules in Morningmedley are implemented as Services with ServiceProviders. To create a module, implement your core functionality in a class (the Service) and create a ServiceProvider class to bootstrap it into the application. The ServiceProvider must extend \Illuminate\Support\ServiceProvider and utilizes two primary methods: register() for default configurations and boot() for initializing the module.
    <?php
    
    namespace MyModule;
    
    class ServiceProvider extends \Illuminate\Support\ServiceProvider
    {
        public function register()
        {
            // Add default config or prepare parts for other modules
            $this->mergeConfigFrom(__DIR__ . "/config/config.php", 'my-module');
        }
    
        public function boot(){
            // Initialize the module
            $this->make(\MyModule\Classes\MyModule::class)->setup();
        }
    }
  10. Implement a custom Feature class

    Create a custom feature by extending \MorningMedley\FeatureFlagging\Classes\FeatureTypes\Feature. This allows you to encapsulate the condition logic within the class constructor.
    // Define the custom feature class
    class AdminFeature extends \MorningMedley\FeatureFlagging\Classes\FeatureTypes\Feature {
        public function __construct(protected $callback)
        {
            parent::__construct($callback, fn() => \current_user_can('administrator'));
        }
    }
    
    // Register the custom feature
    use MorningMedley\Facades\Feature;
    
    Feature::register(
        new AdminFeature(fn() => doSomething())
    );
  11. Use environment variables for sensitive data

    Sensitive data like API tokens should be stored in a .env file. Morningmedley loads .env or .env.{WP_ENVIRONMENT_TYPE} (e.g., .env.production). These values are accessed via the env(key) function and should be mapped into a config file to ensure they are cached.
    # File: .env.production
    API_TOKEN=1234VERYSECURE
    // File: config/app.php
    <?php return [
        'api_token' => env('API_TOKEN'),
    ];
    // Accessing the value in the app
    $apiToken = config('app.api_token');