Marko PHP Framework

repository·develop·Indexed 18 days ago

https://github.com/marko-php/marko

An enterprise-grade, modular PHP 8.5+ framework designed for deep extensibility. Marko allows developers to override or intercept framework and third-party module components using preferences, plugins, and observers. The ecosystem includes packages for admin panels (supporting Latte and Twig), admin authentication and RBAC, REST API responses, and amphp async runtime integration via the Revolt event loop.

Tokens
276.2K
Snippets
1.1K
Records
1.3K
Agent score
64%

What's inside Marko

  1. Overview of marko/config features

    develop

    The marko/config package is designed for type-safe configuration management. Key features include:

    • Dot notation: Access nested configuration values using a dot-separated string (e.g., database.host).
    • Automatic merging: Handles the merging of configuration sources.
    • Multi-tenant scope support: Allows for configuration scoped to different tenants.
    • Type safety: Provides explicit methods for retrieving values as specific types (e.g., getString, getInt).
  2. Overview of Marko Core capabilities

    develop

    Marko Core serves as the foundation of the Marko ecosystem. It provides the following essential services for building extensible applications:

    • Dependency Injection: Manage object lifecycles and dependencies.
    • Modules: Organize code into manageable units.
    • Plugins: Extend system functionality.
    • Events: Implement decoupled communication between components.
    • Preferences: Allow extending or replacing classes without modifying their original source code.
  3. Overview of marko/claude-plugins components

    develop

    | Plugin | Description | |---|---|$ | marko-skills | Scaffolding skills for generating modules, commands, services, and other Marko artefacts | | marko-lsp | Marko-aware language server providing completions, diagnostics, and hover docs in editors | | marko-mcp | Codebase introspection MCP server exposing module graph, routes, and config to AI agents |

  4. Understand the Marko documentation structure

    develop

    The Marko documentation is organized into five distinct sections based on the developer's journey. Knowing which section to consult helps you find the right level of detail:

    1. Getting Started: Linear, sequential onboarding for new developers (e.g., Installation, Project Structure).
    2. Concepts: Explains the why behind the architecture and design decisions (e.g., Modularity, Dependency Injection). It does not contain step-by-step instructions.
    3. Packages (Reference): The single source of truth for individual Composer packages. It provides full API references, configuration details, and installation commands.
    4. Guides (How-To): Task-oriented instructions for accomplishing specific goals that might span multiple packages (e.g., "How to set up authentication").
    5. Tutorials: End-to-end, project-oriented builds that guide you from composer create-project to a finished, working application.
  5. Review Marko Framework requirements and included packages

    develop

    The marko/framework metapackage requires PHP 8.5 or higher.

    It includes the following core packages:

    PackageDescription
    marko/coreBootstrap, DI container, module loader, plugins, events
    marko/routingRoute attributes, router, middleware
    marko/cliCommand-line interface and console commands
    marko/errorsError handling abstraction
    marko/errors-simpleSimple error handler for production
    marko/configConfiguration management with scoped values
    marko/hashingPassword hashing and verification
    marko/validationData validation with attribute-based rules
  6. Overview of marko/devserver orchestration

    develop

    The marko/devserver package provides a single CLI entry point to manage a full development stack. It automates the lifecycle of three main components:

    1. PHP built-in server
    2. Docker services
    3. Frontend build tools

    It supports both detached mode (running in the background) and foreground mode (running in the terminal for active log monitoring).

  7. What is a Marko Plugin and when to use it

    develop

    A plugin is a class that intercepts the input or output of a public method on another class without replacing that class. It is Marko's fine-grained extensibility primitive. Plugins are automatically discovered from any module's src/ directory; no manual registration is required.

    When to use

    Use a plugin when you need to modify arguments to, or the result from, a public method on a class without rewriting or subclassing it. Common use cases include:

    • Enriching a return value
    • Validating or transforming inputs before the method runs
    • Short-circuiting (e.g., returning a cached result or a guard/redirect)
    • Logging or observing method calls
    • Chaining transformations across modules

    Note: If you need to perform a total replacement of a class, use a Preference instead. Plugins and Preferences are complementary: Plugins modify behavior, while Preferences swap entire implementations.

  8. What is a Marko module and how to define one

    develop

    In Marko, a module is any Composer package that is recognized by the framework. To turn a standard Composer package into a Marko module, you must set the extra.marko.module flag to true in your composer.json file. This flag enables automatic discovery and wiring into the application without requiring manual service provider registration or kernel configuration.

    At a minimum, a module requires:

    1. A name.
    2. A PSR-4 autoload mapping.
    3. The extra.marko.module: true configuration.
    {
        "name": "app/blog",
        "autoload": {
            "psr-4": {
                "App\\Blog\\": "src/"
            }
        },
        "extra": {
            "marko": {
                "module": true
            }
        }
    }
  9. Configure entity relationships with attributes

    develop

    Relationships are defined using property attributes on your Entity classes. Marko does not support lazy loading; all related entities must be loaded explicitly via eager loading.

    /**
     * HasOne: The foreignKey is the property name on the RELATED entity pointing back to this one.
     */
    #[HasOne(entityClass: Profile::class, foreignKey: 'userId')]
    public ?Profile $profile = null;
    
    /**
     * HasMany: The foreignKey is the property name on the RELATED entity pointing back to this one.
     */
    #[HasMany(entityClass: Comment::class, foreignKey: 'postId')]
    public EntityCollection $comments;
    
    /**
     * BelongsTo: The foreignKey is the property name on THIS entity pointing to the related entity.
     */
    #[BelongsTo(entityClass: Post::class, foreignKey: 'postId')]
    public ?Post $post = null;
    
    /**
     * BelongsToMany: Uses a pivot entity.
     * foreignKey: pivot property pointing to THIS entity.
     * relatedKey: pivot property pointing to the RELATED entity.
     */
    #[BelongsToMany(
        entityClass: Tag::class,
        pivotClass: PostTag::class,
        foreignKey: 'postId',
        relatedKey: 'tagId',
    )]
    public EntityCollection $tags;
  10. Summary of Admin Panel components and capabilities

    develop

    The Marko Admin ecosystem consists of several specialized packages that work together to build a management interface:

    • marko/admin: Core admin functionality, including defining sections via #[AdminSection] and managing menu items with MenuItem.
    • marko/admin-panel: Provides the UI framework, including the AdminMenuBuilder for permission-filtered navigation and the dashboard system using DashboardWidgetInterface.
    • marko/admin-auth: Handles security, including authentication via GuardInterface, role/permission management, and protecting controllers with AdminAuthMiddleware or the #[RequiresPermission] attribute.
    • marko/admin-api: Enables building administrative JSON endpoints using the ApiResponse class.
  11. Understanding the three layers of AI assistance: LSP, MCP, and Skills

    develop

    Marko uses three distinct layers to provide context to AI agents. Choosing the right layer depends on what kind of help you are trying to provide.

    The Three Layers

    1. LSP (Language Server Protocol): Provides factual code intelligence. It answers "what is in the code right now?" (e.g., completions, definitions, hover). Triggered by editor actions like typing or hovering.
    2. MCP (Model Context Protocol): Provides capabilities and lookups. It answers "do this thing or look this up" (e.g., searching for a plugin, validating a module). Triggered when an agent decides it needs runtime information.
    3. Skills: Provides workflows and conventions. It answers "how do I do X the Marko way?" (e.g., a multi-step process to create a module). Triggered when an agent matches a user request to a skill's description.

    Decision Matrix for adding new help

    If you want to provide...Use this layer
    Factual code intel (completions, definitions, hover)LSP feature
    An action or non-trivial computation (search, validate, query)MCP tool
    A multi-step convention with judgment callsSkill
    A one-line, always-on rulePer-package guidelines.md