Mantle by Alley

website·Indexed 34 days ago

https://mantle.alley.com/

A modern PHP MVC framework built on top of WordPress. Mantle provides a suite of developer tools including a Bootloader, Service Providers, Blade templating, a fluent HTTP client, and a Queue interface. It incorporates Laravel-inspired features such as Collections, Macroable and Conditionable traits, and a pipeline pattern to extend and bootstrap essential services within the WordPress ecosystem.

Tokens
72.1K
Snippets
503
Records
532
Agent score
63%

What's inside Mantle

  1. Overview of Mantle Testkit

    Mantle Testkit is a standalone package that allows developers to use the Mantle Testing Framework in projects, plugins, or themes that are not based on a Mantle application. It enables the use of Mantle's testing features without requiring project refactoring.
  2. Overview of Mantle File System

    Mantle uses the Flysystem package to provide a consistent API for interacting with different storage backends. This allows developers to switch between local storage (WordPress upload directory), FTP servers, or Amazon S3 buckets without changing the core application logic.
  3. Overview of the Mantle framework for WordPress

    Mantle is an object-oriented framework designed to enhance WordPress for enterprise projects. It provides abstractions, utility functions, and modern development practices (inspired by Laravel) to improve performance, scalability, and maintainability without replacing the underlying WordPress APIs and functions.
  4. Overview of Mantle Testing Framework

    Mantle provides a PHPUnit-based testing framework designed for WordPress applications. It focuses on speed and developer experience, providing helpers to make unit and feature testing more expressive. Tests are located in the tests directory and are split into two categories:

    • Feature Tests: Located in tests/Feature. These boot the Mantle application, allow access to the database and framework services, and are recommended for most tests as they provide the highest confidence in system functionality.
    • Unit Tests: Located in tests/Unit. These focus on isolated portions of code (e.g., a single method), do not boot the Mantle application, and cannot access the database or framework services. They extend the base PHPUnit test case.
    use App	ests	ests//TestCase;
    
    class ExampleTest extends TestCase {
    	public function test_example(): void {
    		$post = static::factory()->post->create_and_get();
    
    		$this->get( get_permalink( $post ) )
    			->assertOk()
    			->assertQueriedObject( $post )
    			->assertSee( $post->post_title );
    	}
    }
  5. Overview of Mantle Support package features

    The mantle-framework/support package includes the following utility features:

    • Classname: Helper for generating CSS class names based on conditions.
    • Collections: Enhanced collection methods.
    • Conditionable: A trait for conditionally calling closures.
    • Helpers: General development helper functions.
    • Hookable: A trait for automatically registering class methods as hooks.
    • HTML Manipulation: A class to query, manipulate, and assert against HTML.
    • Macroable: Allows adding methods to classes from outside the class definition.
    • Mixed Options/Meta Data: Type-safe handling of mixed data for options and metadata.
    • Pipeline: Implementation of the pipeline pattern to execute tasks in order.
    • Singleton: Ensures a class is only instantiated once.
    • Stringable: Creates stringable objects from strings within the Mantle\Support namespace.
    • URI Manipulation: Fluent URI class and helpers for working with URIs.
  6. Overview of Mantle Service Providers

    Service providers in Mantle are the central mechanism for extending the framework and bootstrapping essential services. They are used to encapsulate core application functionality, including registering service container bindings, event listeners, middleware, and routes. A common use case is wrapping a specific application feature (e.g., a content syndication system) into a single provider to manage its setup.
  7. Overview of Mantle Queue system

    Mantle provides a Queue interface to handle asynchronous jobs in the background, preventing user requests from being blocked. While the system is abstracted to allow for different providers, it supports WordPress-backed queues out of the box. This system can be used in any WordPress project by instantiating the bootloader.
    use function Mantle\Queue\dispatch;
    
    // Instantiate the bootloader.
    bootloader()->boot();
    
    // Dispatch a job.
    dispatch( function () {
    		// Perform some task...
    } );
  8. Overview of the Mantle Installation Manager

    The Installation Manager is a class used to manage WordPress installations for testing. It aims to eliminate the need for external dependencies like core testing suites or VIP MU plugins, allowing developers to run tests simply via composer phpunit. It supports two primary use cases: installing WordPress within an existing installation (handling database and config) or installing WordPress in a temporary directory and rsyncing the project into it.
  9. Register WordPress hooks using the Hookable trait

    The Hookable trait allows you to automatically register class methods as WordPress action or filter hooks. This keeps the hook registration logic close to the implementation. It serves as a wrapper around the core add_action and add_filter functions.
  10. Understand the Mantle by Alley root directory structure

    The Mantle by Alley framework organizes application logic and configuration into a standardized root directory structure:

    • app/: Contains core application code, including console commands, routes, models, and providers. It is namespaced as App and uses a WordPress-style autoloader.
    • bootstrap/: Contains app.php for framework bootstrapping. It may also include a cache folder for performance-optimized files like routes and packages.
    • config/: Stores application configuration files.
    • database/: Contains database factories and seeders used for database initialization during testing.
    • routes/: Contains HTTP route definitions. Default files include web.php (web routes) and rest-api.php (REST API routes).
    • tests/: Contains automated tests powered by PHPUnit and the Mantle Test Framework.
  11. Implement custom routing in Mantle

    Mantle provides an MVC framework built on top of WordPress that allows developers to define routes fluently and return responses directly. This abstracts away the need to manually use the WordPress add_rewrite_rule() function for custom URL handling.
  12. Use Blade templating in Mantle for WordPress

    Mantle integrates Laravel's Blade templating engine into WordPress. Blade templates use the .blade.php file extension and can be used alongside traditional PHP templates. The framework automatically detects the extension and applies the correct engine.