PHPackages                             valksor/php-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. valksor/php-bundle

ActiveSymfony-bundle[Framework](/categories/framework)

valksor/php-bundle
==================

Symfony bundle providing integration services, dependency injection configuration, and enhanced functionality for valksor libraries

015PHPCI passing

Since Jan 24Pushed 3mo agoCompare

[ Source](https://github.com/valksor/php-bundle)[ Packagist](https://packagist.org/packages/valksor/php-bundle)[ RSS](/packages/valksor-php-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Valksor Bundle
==============

[](#valksor-bundle)

[![valksor](https://camo.githubusercontent.com/2af5a6a7e5f7da47cd0a924c8b00038f208f45f9b0d5be8d7a497a9808168187/68747470733a2f2f62616467656e2e6e65742f7374617469632f6f72672f76616c6b736f722f677265656e)](https://github.com/valksor)[![BSD-3-Clause](https://camo.githubusercontent.com/72547f8afb6b5ace804caebbf95c3bcbfc027ce9214777bc452f308f3165db01/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4253442d2d332d2d436c617573652d677265656e3f7374796c653d666c6174)](https://github.com/valksor/php-bundle/blob/master/LICENSE)[![Coverage Status](https://camo.githubusercontent.com/97ce3829ba4276df225a2512a2597b2b801eda326688d4606fbbbea929eb6642/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f76616c6b736f722f7068702d62756e646c652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/valksor/php-bundle?branch=master)[![php](https://camo.githubusercontent.com/77da2f7bbc049873edb2d1045a756d7a32e3ba50440a8e0e76a9109f62f0771b/68747470733a2f2f62616467656e2e6e65742f7374617469632f7068702f2533453d382e342f707572706c65)](https://www.php.net/releases/8.4/en.php)

A comprehensive Symfony bundle that provides automatic component discovery, configuration management, and dependency injection for Valksor components and related packages.

Features
--------

[](#features)

- **Automatic Component Discovery**: Automatically discovers and registers Valksor components and ValksorDev packages
- **Dynamic Configuration**: Provides flexible configuration system for all components
- **Build System Integration**: Seamless integration with the new 3-command development architecture
- **Service Registry Support**: Manages extensible flag-based service providers for build tools
- **Dependency Management**: Handles component dependencies and enables/disables components based on availability
- **Doctrine Integration**: Supports Doctrine migrations and database schema management
- **Memoization**: Built-in caching and memoization support for improved performance
- **Bundle Architecture**: Follows Symfony best practices for bundle development

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require valksor/php-bundle
```

Requirements
------------

[](#requirements)

- PHP 8.4 or higher
- Symfony Framework
- Doctrine DBAL (for database-related components)
- Doctrine Migrations (for schema management)

Configuration
-------------

[](#configuration)

The Valksor Bundle provides flexible configuration options for project structure and component management:

### Global Configuration

[](#global-configuration)

```
# config/packages/valksor.yaml
valksor:
    # Project directory structure configuration
    project:
        apps_dir: null # Directory containing applications (relative to project root)
        infrastructure_dir: null # Directory containing shared resources (relative to project root)
        autoload:
            namespace_prefix: null # Namespace prefix for generated autoload classes

    # Component configurations (auto-discovered)
    # Each discovered component can be enabled/disabled individually
```

### Configuration Options

[](#configuration-options)

OptionTypeDefaultDescription`project.apps_dir`string`null`Directory containing applications (relative to project root)`project.infrastructure_dir`string`null`Directory containing shared resources (relative to project root)`project.autoload.namespace_prefix`string`null`Namespace prefix for generated autoload classes*See: [`ValksorConfiguration.php`](DependencyInjection/ValksorConfiguration.php) for the complete configuration schema.*

Usage
-----

[](#usage)

### Basic Setup

[](#basic-setup)

1. Register the bundle in your Symfony application:

```
// config/bundles.php
return [
    // ...
    Valksor\Bundle\ValksorBundle::class => ['all' => true],
    // ...
];
```

2. Create a basic configuration file:

```
# config/packages/valksor.yaml
valksor:
    # Global bundle configuration
    enabled: true

    # Component-specific configurations will be automatically discovered
    # Each discovered component can be enabled/disabled individually
```

### Component Discovery

[](#component-discovery)

The bundle automatically discovers all available components that implement the `Dependency` interface and end with `Configuration` in their class name. Components are discovered from:

- All namespaces starting with `Valksor\`
- All namespaces starting with `ValksorDev\`

### Configuration Examples

[](#configuration-examples)

#### Enable/Disable Specific Components

[](#enabledisable-specific-components)

```
# config/packages/valksor.yaml
valksor:
    # Disable a specific component
    some_component:
        enabled: false

    # Configure a specific component
    another_component:
        enabled: true
        option1: value1
        option2: value2
```

#### Component-Specific Configuration

[](#component-specific-configuration)

Each component can define its own configuration structure. The bundle automatically merges component configurations with the global Valksor configuration.

```
# Example configuration for a hypothetical cache component
valksor:
    cache_component:
        enabled: true
        ttl: 3600
        storage: redis
        redis:
            host: localhost
            port: 6379
```

### Build System Integration

[](#build-system-integration)

The Valksor Bundle provides seamless integration with the new Valksor Dev build system architecture, enabling automatic discovery and configuration of build services through the service registry.

#### Build Services Configuration

[](#build-services-configuration)

When the `valksor-dev/php-dev-build` package is installed, the bundle automatically discovers and configures build services:

```
# config/packages/valksor.yaml
valksor:
    build:
        enabled: true
        services:
            # Binary management (always runs first)
            binaries:
                enabled: true
                flags: [init, dev, prod]
                options:
                    download_dir: "bin/build-tools/"
                    esbuild_version: "latest"
                    tailwind_version: "latest"

            # Hot reload with SSE integration
            hot_reload:
                enabled: true
                flags: [dev]
                options:
                    watch_paths: ["templates/", "src/", "assets/"]
                    exclude_patterns: ["vendor/", "var/"]

            # Tailwind CSS compilation
            tailwind:
                enabled: true
                flags: [dev, prod]
                options:
                    input: "assets/css/app.css"
                    output: "public/build/app.css"
                    minify: false

            # Import map management
            importmap:
                enabled: true
                flags: [dev, prod]
                options:
                    importmap_path: "importmap.json"
                    vendor_dir: "assets/vendor/"

            # Icon generation
            icons:
                enabled: true
                flags: [prod]
                options:
                    input_dir: "assets/icons/"
                    output_dir: "templates/icons/"
```

#### Available Development Commands

[](#available-development-commands)

The bundle registers the following console commands when build services are enabled:

CommandDescriptionServices Run`valksor:dev`Lightweight development (SSE + hot reload)`binaries` + `hot_reload``valksor:watch`Full development environmentAll services with `dev` flag`valksor-prod:build`Production asset buildingAll services with `prod` flag`valksor:hot-reload`Standalone hot reload serviceHot reload only`valksor:tailwind`Tailwind CSS compilationTailwind only`valksor:importmap`Import map synchronizationImport map only`valksor:binary`Binary managementBinary download only#### Service Registry Integration

[](#service-registry-integration)

The bundle integrates with the service registry system to provide:

- **Automatic Provider Discovery**: Scans for build service providers
- **Flag-Based Execution**: Services run based on command flags (`init`, `dev`, `prod`)
- **Dependency Resolution**: Handles service dependencies automatically
- **Process Management**: Coordinates multiple build processes
- **Configuration Validation**: Ensures service configurations are valid

#### SSE Component Integration

[](#sse-component-integration)

When both SSE and build components are enabled, the bundle automatically configures:

```
valksor:
    # SSE configuration for development
    sse:
        enabled: true
        port: 8080
        host: localhost
        ping_interval: 30

    # Build system with integrated SSE
    build:
        services:
            hot_reload:
                enabled: true
                flags: [dev]
                options:
                    sse_port: 8080 # Matches SSE configuration
```

This integration ensures that running `valksor:dev` or `valksor:watch` automatically starts the SSE server with hot reload functionality.

### Import Map System

[](#import-map-system)

The bundle provides a flexible import map system that works seamlessly with both single-app and multi-app Symfony projects.

#### Single-App Projects (Default)

[](#single-app-projects-default)

For standard Symfony applications, the import map system automatically includes the Valksor import map from your project:

```
// importmap.php in your project root
$projectDir = __DIR__;
return include $projectDir . '/valksor/src/Valksor/Bundle/Resources/importmap.php';
```

**How it works:**

- Automatically detects the project structure
- Includes the core Valksor import map with SSE and build system assets
- Works with the standard AssetMapper component
- No additional configuration needed

#### Advanced: Multi-App Projects

[](#advanced-multi-app-projects)

For projects with multiple applications, the import map system can handle separate configurations:

```
// importmap.php in project root
$projectDir = __DIR__;
$apps = 'apps';           // Your apps directory
$infrastructure = 'infrastructure'; // Your infrastructure directory

return include $projectDir . '/valksor/src/Valksor/Bundle/Resources/importmap.php';
```

**How it changes:**

- The import map system can discover assets in multiple app directories
- Supports infrastructure-specific shared assets
- Handles entry point detection for each application (`*.entry.js` files)
- Generates appropriate import maps for each application context

The import map logic automatically adapts based on whether the `$apps` and `$infrastructure` variables are defined, making it work seamlessly in both project structures.

### Working with Components

[](#working-with-components)

#### Accessing Configuration in Services

[](#accessing-configuration-in-services)

You can access component configuration in your services:

```
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Valksor\Bundle\ValksorBundle;

class YourService
{
    public function __construct(ContainerBuilder $builder)
    {
        // Get global Valksor configuration
        $config = ValksorBundle::getConfig('valksor', $builder);

        // Get specific component parameter
        $enabled = ValksorBundle::p($builder, 'your_component', 'enabled');
    }
}
```

#### Creating Custom Components

[](#creating-custom-components)

To create a custom component that will be discovered by the bundle:

1. Create a configuration class that implements the `Dependency` interface:

```
