### Start Development Server (Bash)
Source: https://context7.com/sulu/skeleton/llms.txt
Starts the built-in PHP development server to run the Sulu CMS application locally. This is essential for development and testing purposes, making the website and admin interfaces accessible via localhost.
```bash
# Start the development server on localhost:8000
composer serve
# Access the website at:
# http://localhost:8000
# Access the admin interface at:
# http://localhost:8000/admin
```
--------------------------------
### Database Setup and Initialization (Bash)
Source: https://context7.com/sulu/skeleton/llms.txt
Initializes the database schema and populates it with fixtures using Doctrine commands. This includes creating the database, setting up the schema, loading sample data, and initializing media storage. A bootstrap script is also provided for test environments.
```bash
# Create the database
php bin/adminconsole doctrine:database:create
# Create the schema
php bin/adminconsole doctrine:schema:create
# Load fixtures (sample data)
php bin/adminconsole doctrine:fixtures:load
# Initialize media storage
php bin/adminconsole sulu:media:init
# For testing environment, use the bootstrap script
composer bootstrap-test-environment
```
--------------------------------
### Create Data Fixtures with PHP
Source: https://context7.com/sulu/skeleton/llms.txt
Defines database fixtures for loading sample data, commonly used during development and testing phases. This example uses Doctrine Fixtures Bundle to create sample product entities.
```php
setName("Product {$i}");
$product->setDescription("Description for product {$i}");
$product->setPrice(99.99 * $i);
$manager->persist($product);
}
$manager->flush();
}
}
```
--------------------------------
### Execute Sulu Console Commands
Source: https://context7.com/sulu/skeleton/llms.txt
Provides examples of using the Sulu-specific console commands for both admin and website contexts. These commands are essential for managing applications, clearing caches, and performing maintenance tasks.
```bash
# Admin console (for backend operations)
php bin/adminconsole cache:clear
php bin/adminconsole sulu:admin:info
php bin/adminconsole sulu:admin:validate-build
# Website console (for frontend operations)
php bin/websiteconsole cache:clear
php bin/websiteconsole cache:warmup
# Debug and information commands
php bin/console debug:router # List all routes
php bin/console debug:container # List services
php bin/console debug:translation # Check translations
```
--------------------------------
### Running PHPUnit Tests (Bash)
Source: https://context7.com/sulu/skeleton/llms.txt
This snippet outlines the commands for executing PHPUnit tests within a Sulu project. It includes commands to run all tests, run tests with code coverage reports, view the coverage report, and bootstrap the test environment, which typically involves creating a test database. These commands are executed via Composer.
```bash
# Run all tests
composer test
# Run tests with coverage reports
composer test-with-coverage
# View coverage report
open var/reports/html/index.html
# Bootstrap test environment (creates test database)
composer bootstrap-test-environment
```
--------------------------------
### Environment Configuration (.env)
Source: https://context7.com/sulu/skeleton/llms.txt
This section details the environment variable configuration for a Sulu project, typically found in a .env file. It covers essential settings for the application environment, database connection, admin email, default URI, search engine (SEAL), message queue transport, emailer, lock mechanism, and optional trusted proxies/hosts. These variables are crucial for setting up different services and environments.
```dotenv
# .env
APP_ENV=prod
APP_SECRET=your_secret_key_here
DATABASE_URL="mysql://root:password@127.0.0.1:3306/sulu_db?serverVersion=8.4.7&charset=utf8mb4"
# Admin email for system notifications
SULU_ADMIN_EMAIL=admin@example.com
# Default URI for CLI commands
DEFAULT_URI=http://localhost
# Search engine configuration (SEAL)
SEAL_DSN=loupe://%kernel.project_dir%/var/indexes
# Alternative search engines:
# SEAL_DSN="meilisearch://127.0.0.1:7700"
# SEAL_DSN="elasticsearch://127.0.0.1:9200"
# Message queue transport
MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0
# Email configuration
MAILER_DSN=smtp://localhost:1025
# Lock mechanism
LOCK_DSN=flock
# Optional: Trusted proxies for production
# TRUSTED_PROXIES=127.0.0.1,127.0.0.2
# TRUSTED_HOSTS=localhost,example.com
```
--------------------------------
### Configure Kernel for HTTP Caching (PHP)
Source: https://context7.com/sulu/skeleton/llms.txt
This snippet demonstrates how to customize the application kernel in PHP to integrate Sulu-specific features, particularly for HTTP caching. It extends the base SuluKernel and implements the HttpCacheProvider interface, allowing for the creation of a SuluHttpCache instance. Dependencies include FOSHttpCache and SuluBundleHttpCacheBundle.
```php
httpCache instanceof HttpKernelInterface) {
$this->httpCache = new SuluHttpCache($this);
// Optional: Enable user-based caching
// $this->httpCache->addSubscriber(
// new \FOS\HttpCache\SymfonyCache\UserContextListener([
// 'session_name_prefix' => 'SULUSESSID',
// ])
// );
}
return $this->httpCache;
}
}
```
--------------------------------
### Define Page Template (XML)
Source: https://context7.com/sulu/skeleton/llms.txt
Defines a custom page template using XML configuration. This specifies the page's key, view, controller, cache lifetime, metadata (titles for different languages), and properties like title, URL, content editor, and media selection.
```xml
my_custom_pagepages/customSulu\Content\UserInterface\Controller\Website\ContentController::indexAction86400Custom PageEigene SeiteTitleTitelURLAdresseContentInhaltImagesBilder
```
--------------------------------
### Code Quality and Linting Checks (Bash)
Source: https://context7.com/sulu/skeleton/llms.txt
This section provides a comprehensive set of Bash commands for performing code quality checks and linting in a Sulu project. It covers running all linting checks, individual checks for static analysis (PHPStan), PHP code style, Twig templates, YAML validation, service container validation, and Doctrine schema validation. It also includes commands for auto-fixing code issues using tools like Rector.
```bash
# Run all linting checks
composer lint
# Individual linting commands
composer phpstan # Static analysis
composer lint-php-cs # Check PHP code style
composer lint-twig-cs # Check Twig templates
composer lint-yaml # Validate YAML files
composer lint-container # Validate service container
composer lint-doctrine # Validate Doctrine schema
# Auto-fix code issues
composer fix # Fix all auto-fixable issues
composer php-cs-fix # Fix PHP code style
composer twig-cs-fix # Fix Twig templates
composer rector # Apply automated refactoring
```
--------------------------------
### Render Content in Twig Templates (Twig)
Source: https://context7.com/sulu/skeleton/llms.txt
Renders page content within a Twig template, utilizing Sulu's functions and filters for multi-lingual output. It demonstrates accessing content properties like title, rich text content, and media selections, along with navigation helpers.
```twig
{# templates/pages/custom.html.twig #}
{% extends 'base.html.twig' %}
{% block content %}
{{ content.title }}
{# Render rich text content #}
{{ content.content|raw }}
{# Display media selection #}
{% if content.images is defined %}
{% for image in content.images %}
{% endfor %}
{% endif %}
{# Navigation helpers #}
{% endblock %}
```
--------------------------------
### Admin Security Configuration (YAML)
Source: https://context7.com/sulu/skeleton/llms.txt
This YAML snippet defines the security configuration for the Sulu admin interface. It specifies password hashers, user providers, firewall settings for the 'admin' area (including login, logout, and two-factor authentication), and access control rules based on paths and roles. This configuration is essential for managing authentication and authorization within the admin panel.
```yaml
# config/packages/security.yaml
security:
password_hashers:
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
providers:
sulu:
id: sulu_security.user_provider
firewalls:
admin:
pattern: ^/admin(/|$)
lazy: true
provider: sulu
entry_point: sulu_security.authentication_entry_point
json_login:
check_path: sulu_admin.login_check
success_handler: sulu_security.authentication_handler
failure_handler: sulu_security.authentication_handler
logout:
path: sulu_admin.logout
two_factor:
prepare_on_login: true
check_path: 2fa_login_check_admin
authentication_required_handler: sulu_security.two_factor_authentication_required_handler
access_control:
- { path: ^/admin/login$, roles: PUBLIC_ACCESS }
- { path: ^/admin/2fa, roles: PUBLIC_ACCESS }
- { path: ^/admin, roles: ROLE_USER }
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.