### Initialize a new Marko project Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/index.mdx Use these commands to install the Marko skeleton, the CLI tool, and start the development environment. ```bash composer create-project marko/skeleton my-app composer global require marko/cli cd my-app marko up ``` -------------------------------- ### CLI Command Example Source: https://github.com/marko-php/marko/blob/develop/docs/DOCS-STANDARDS.md Use 'marko' directly for CLI commands, as the Marko CLI is installed globally. Do not prefix with 'php marko'. ```bash marko ``` -------------------------------- ### Bash Installation Command Source: https://github.com/marko-php/marko/blob/develop/docs/DOCS-STANDARDS.md Use this bash command to install the marko/example package. This is a standard Composer command for package installation. ```bash composer require marko/example ``` -------------------------------- ### Quick Session Management Example in PHP Source: https://github.com/marko-php/marko/blob/develop/packages/session/README.md Demonstrates basic session operations: starting the session, setting a value, adding a flash message, and saving the session. Ensure the SessionInterface is injected into your class. ```php use Marko\Session\Contracts\SessionInterface; public function __construct( private readonly SessionInterface $session, ) {} public function handle(): void { $this->session->start(); $this->session->set('user_id', 42); $this->session->flash()->add('success', 'Profile updated.'); $this->session->save(); } ``` -------------------------------- ### Quick Example: Session Management with Cache Source: https://github.com/marko-php/marko/blob/develop/packages/cache-redis/README.md Demonstrates how to use the CacheInterface to get and save session data with a Time-To-Live (TTL). Ensure the CacheInterface is properly injected. ```php use Marko\Cache\Contracts\CacheInterface; class SessionStore { public function __construct( private CacheInterface $cache, ) {} public function getSession(string $token): ?array { return $this->cache->get("session.$token"); } public function saveSession(string $token, array $data): void { $this->cache->set("session.$token", $data, ttl: 1800); } } ``` -------------------------------- ### Install marko/filesystem-local Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/filesystem-local.md Use Composer to install the local filesystem driver. This also installs the base marko/filesystem package. ```bash composer require marko/filesystem-local ``` -------------------------------- ### Example Marko Package README Structure Source: https://github.com/marko-php/marko/blob/develop/docs/DOCS-STANDARDS.md This markdown structure provides a template for Marko package README files. It includes sections for the package title, installation command, a quick code example, and a link to the full documentation. ```markdown # marko/example One-line description of what the package does. ## Installation ```bash composer require marko/example ``` ## Quick Example ```php // One short snippet showing the core idea ``` ## Documentation Full usage, API reference, and examples: [marko/example](https://marko.build/docs/packages/example/) ``` -------------------------------- ### Start Development Server Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/skeleton.md Use the marko CLI to start the development server for local testing. ```bash marko up ``` -------------------------------- ### Install marko/media-gd Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/media-gd.md Install the package using Composer. This will also install marko/media. ```bash composer require marko/media-gd ``` -------------------------------- ### Install marko/view Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/view.md Install the package via Composer. ```bash composer require marko/view ``` -------------------------------- ### Marko Pub/Sub Configuration Example Source: https://github.com/marko-php/marko/blob/develop/packages/pubsub/README.md Example configuration file for marko/pubsub, specifying the active driver and an optional channel prefix. ```php // config/pubsub.php return [ 'driver' => 'redis', // active driver 'prefix' => '', // optional channel prefix applied by all drivers ]; ``` -------------------------------- ### Installation Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/cache-file.md Install the Marko File Cache Driver using Composer. This will also install the core Marko Cache library. ```APIDOC ## Installation ```bash composer require marko/cache-file ``` This automatically installs `marko/cache`. ``` -------------------------------- ### Install marko/queue-sync Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/queue-sync.md Install the package via Composer. ```bash composer require marko/queue-sync ``` -------------------------------- ### Create Marko Project and Install Blog Package Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/tutorials/build-a-blog.md Use Composer to create a new Marko project and install the blog package. ```bash composer create-project marko/skeleton my-blog cd my-blog composer require marko/blog ``` -------------------------------- ### Installation Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/cache-redis.md Install the Redis cache driver using Composer. This will also install the core `marko/cache` package and `predis/predis`. ```APIDOC ## Installation ```bash composer require marko/cache-redis ``` ``` -------------------------------- ### Install marko/search Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/search.md Install the package via Composer. ```bash composer require marko/search ``` -------------------------------- ### Usage Example Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/session-file.md Example of how to use the session interface after binding the file driver. ```APIDOC ## Usage Example of using the session interface: ```php use Marko\Session\Contracts\SessionInterface; public function __construct( private readonly SessionInterface $session, ) {} public function handle(): void { $this->session->start(); $this->session->set('key', 'value'); $this->session->save(); } ``` ``` -------------------------------- ### Install marko/webhook Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/webhook.md Install the package via Composer. ```bash composer require marko/webhook ``` -------------------------------- ### Install Full Marko Framework Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/getting-started/installation.md Install the metapackage to include core, routing, CLI, error handling, configuration, hashing, and validation. ```bash composer require marko/framework ``` -------------------------------- ### Install marko/session-file Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/session-file.md Install the package via Composer. ```bash composer require marko/session-file ``` -------------------------------- ### Installation Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/authorization.md Install the marko/authorization package using Composer. ```APIDOC ## Installation ```bash composer require marko/authorization ``` ``` -------------------------------- ### Install marko/view-latte Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/view-latte.md Install the package via Composer. ```bash composer require marko/view-latte ``` -------------------------------- ### Install marko/blog via Composer Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/blog.md Install the base package or include required view and database drivers. ```bash composer require marko/blog ``` ```bash composer require marko/blog marko/view-latte marko/database-mysql ``` -------------------------------- ### Installation Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/hashing.md Install the Marko Hashing library using Composer. ```APIDOC ## Installation ```bash composer require marko/hashing ``` ``` -------------------------------- ### Install Marko Pub/Sub Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/pubsub.md Install the base package using Composer. ```bash composer require marko/pubsub ``` -------------------------------- ### Installation Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/session-file.md Install the file-based session driver using Composer. ```APIDOC ## Installation ```bash composer require marko/session-file ``` This command installs both `marko/session-file` and its dependency `marko/session`. ``` -------------------------------- ### Install marko/log Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/log.md Install the package via Composer. ```bash composer require marko/log ``` -------------------------------- ### Install Pub/Sub Redis Driver Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/pubsub.md Install the Redis driver alongside the base package. ```bash composer require marko/pubsub-redis ``` -------------------------------- ### Install marko/translation-file Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/translation-file.md Install the package via Composer. ```bash composer require marko/translation-file ``` -------------------------------- ### Install marko/authorization Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/authorization.md Install the package via Composer. ```bash composer require marko/authorization ``` -------------------------------- ### Install marko/cache-file via Composer Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/cache-file.md Run this command to install the package and its dependency. ```bash composer require marko/cache-file ``` -------------------------------- ### Install Pub/Sub PostgreSQL Driver Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/pubsub.md Install the PostgreSQL driver alongside the base package. ```bash composer require marko/pubsub-pgsql ``` -------------------------------- ### Install Minimal API Stack Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/framework.md Install the Marko framework for a lightweight API, including database and cache support, but excluding session management. ```bash composer require marko/framework \ marko/database marko/database-mysql \ marko/cache marko/cache-file ``` -------------------------------- ### Install Marko Database Packages Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/guides/database.md Install the core database package and the PostgreSQL driver via Composer. ```bash composer require marko/database marko/database-pgsql ``` -------------------------------- ### Install SSE and PubSub packages Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/guides/real-time.md Use Composer to install the SSE package along with a preferred PubSub driver. ```bash # Redis-backed (pattern subscriptions, dedicated infrastructure) composer require marko/sse marko/pubsub-redis # PostgreSQL-backed (zero extra infrastructure) composer require marko/sse marko/pubsub-pgsql ``` -------------------------------- ### Install Admin API package Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/admin-api.md Install the package via Composer. ```bash composer require marko/admin-api ``` -------------------------------- ### Install hashing package Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/hashing.md Install the package via Composer. ```bash composer require marko/hashing ``` -------------------------------- ### Start a session Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/session.md Inject the SessionInterface and call start() to initialize the session. ```php use Marko\Session\Contracts\SessionInterface; public function __construct( private readonly SessionInterface $session, ) {} public function handle(): void { $this->session->start(); } ``` -------------------------------- ### Install marko/mail package Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/mail.md Install the core mail package via Composer. ```bash composer require marko/mail ``` -------------------------------- ### Install Queue Backends Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/guides/queues.md Use Composer to install the required queue backend packages for your environment. ```bash # Database-backed queue composer require marko/queue marko/queue-database # RabbitMQ queue composer require marko/queue marko/queue-rabbitmq ``` -------------------------------- ### Install marko/media-imagick Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/media-imagick.md Install the Imagick image processing driver for marko/media using Composer. ```bash composer require marko/media-imagick ``` -------------------------------- ### Install session package Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/session.md Install the core session package via Composer. ```bash composer require marko/session ``` -------------------------------- ### Quick Example: Database Connection Source: https://github.com/marko-php/marko/blob/develop/packages/config/README.md Demonstrates how to use Marko Config to retrieve database connection details within a class. Ensure the ConfigRepositoryInterface is available and configured. ```php use Marko\Config\ConfigRepositoryInterface; class DatabaseConnection { public function __construct( private ConfigRepositoryInterface $config, ) {} public function connect(): PDO { $host = $this->config->getString('database.host'); $port = $this->config->getInt('database.port'); return new PDO("mysql:host={$host};port={$port}"); } } ``` -------------------------------- ### Install Logging Packages Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/guides/logging.md Use Composer to install the core logging contract and the default file-based driver. ```bash composer require marko/log marko/log-file ``` -------------------------------- ### Start Marko Development Server Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/getting-started/first-application.md Launch the local development server and open the application in the default browser. ```bash marko up marko open ``` -------------------------------- ### Log messages in a PHP Service Source: https://github.com/marko-php/marko/blob/develop/packages/log-file/README.md Inject the LoggerInterface into your service class to log messages. This example shows how to log an informational message at the start of an import process. ```php use Marko\Log\Contracts\LoggerInterface; class ImportService { public function __construct( private LoggerInterface $logger, ) {} public function import(string $file): void { $this->logger->info('Starting import', ['file' => $file]); } } ``` -------------------------------- ### Install Marko Scheduler Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/guides/scheduling.md Install the Marko scheduler package using Composer. ```bash composer require marko/scheduler ``` -------------------------------- ### Install Marko Queue Database Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/queue-database.md Install the database queue driver using Composer. Requires marko/database for the database connection. ```bash composer require marko/queue-database ``` -------------------------------- ### Admin API MeController Response Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/tutorials/build-an-admin-panel.md Example JSON response from the `MeController` at `GET /admin/api/v1/me`, showing the authenticated admin user's profile, roles, and permissions. ```json { "data": { "id": 1, "email": "admin@example.com", "name": "Admin", "roles": [ { "id": 1, "name": "Super Admin", "slug": "super-admin" } ], "permissions": ["posts.view", "posts.create", "posts.edit", "posts.delete"] }, "meta": {} } ``` -------------------------------- ### Install Mail Packages Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/guides/mail.md Install the core mail package and the SMTP transport via Composer. ```bash composer require marko/mail marko/mail-smtp ``` -------------------------------- ### Initialize Marko Project Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/getting-started/first-application.md Use Composer to scaffold a new Marko project and navigate into the directory. ```bash composer create-project marko/skeleton hello-marko cd hello-marko ``` -------------------------------- ### Inject and Use HttpClientInterface Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/http-guzzle.md Inject the HttpClientInterface into your classes and use its methods to make HTTP requests. The example demonstrates a GET request with custom timeout and headers. ```php use Marko\Http\Contracts\HttpClientInterface; class ApiClient { public function __construct( private HttpClientInterface $httpClient, ) {} public function fetchData(): array { $response = $this->httpClient->get('https://api.example.com/data', [ 'timeout' => 10, 'headers' => ['Accept' => 'application/json'], ]); return $response->json(); } } ``` -------------------------------- ### Offset Pagination Example Source: https://github.com/marko-php/marko/blob/develop/packages/pagination/README.md Instantiate and use the OffsetPaginator with item data, total count, items per page, and current page. Check for more pages, get the last page number, and serialize to an array. ```php use Marko\Pagination\OffsetPaginator; $paginator = new OffsetPaginator( items: $items, total: 150, perPage: 15, currentPage: 3, ); $paginator->hasMorePages(); // true $paginator->lastPage(); // 10 $paginator->toArray(); // ['items' => [...], 'meta' => [...], 'links' => [...]] ``` -------------------------------- ### Start Marko Development Server Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/tutorials/build-a-chat.md Use `marko up` to start the development environment, including the PHP server with multiple workers to prevent SSE connections from blocking other requests. ```bash marko up ``` -------------------------------- ### Application Entry Point (`public/index.php`) Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/getting-started/project-structure.md The minimal bootstrap file for a Marko application, responsible for booting the framework and handling requests. ```php handleRequest(); ``` -------------------------------- ### Install Marko Log File Driver Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/log-file.md Use Composer to install the marko/log-file package. This will also install marko/log. ```bash composer require marko/log-file ``` -------------------------------- ### Install Marko Health Package Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/health.md Use Composer to install the marko/health package. This is the first step to enable health monitoring. ```bash composer require marko/health ``` -------------------------------- ### Copy Environment Template Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/skeleton.md Copy the example environment file to .env to configure your application settings. ```bash cp .env.example .env ``` -------------------------------- ### Install Marko Filesystem Package Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/filesystem.md Install the core filesystem package using Composer. This is typically a dependency of a specific driver package. ```bash composer require marko/filesystem ``` -------------------------------- ### Install Filesystem Package Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/framework.md Install the filesystem abstraction layer with a local driver. This is useful for managing file operations within your application. ```bash composer require marko/filesystem marko/filesystem-local ``` -------------------------------- ### Install Filesystem Packages Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/guides/file-storage.md Install the core filesystem package and the desired driver. Use `marko/filesystem-local` for local disk storage or `marko/filesystem-s3` for S3-compatible storage. ```bash # Local filesystem (stores files on disk) composer require marko/filesystem marko/filesystem-local ``` ```bash # Amazon S3 / S3-compatible storage composer require marko/filesystem marko/filesystem-s3 ``` -------------------------------- ### Install Marko PHP Dependencies Source: https://github.com/marko-php/marko/blob/develop/README.md Installs project dependencies using Composer. Ensure you have Composer 2.x installed. ```bash composer install ``` -------------------------------- ### Quick Example: Notification Repository Usage Source: https://github.com/marko-php/marko/blob/develop/packages/notification-database/README.md Demonstrates how to inject and use the NotificationRepository to fetch and manage user notifications. Ensure the NotificationRepositoryInterface is correctly implemented and injected. ```php use Marko\Notification\Database\Repository\NotificationRepositoryInterface; public function __construct( private NotificationRepositoryInterface $notificationRepository, ) {} // Fetch all notifications for a user $notifications = $this->notificationRepository->forNotifiable($user); // Count unread $count = $this->notificationRepository->unreadCount($user); // Mark all as read $this->notificationRepository->markAllAsRead($user); ``` -------------------------------- ### Install marko/mail-log Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/mail-log.md Install the log-based mail driver using Composer. This also installs the necessary marko/mail and marko/log packages. ```bash composer require marko/mail-log ``` -------------------------------- ### Admin Configuration Example Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/admin.md Example configuration for the admin panel, specifying the route prefix and display name. This configuration is read from the `admin` namespace in `marko/config`. ```php return [ 'route_prefix' => '/admin', 'name' => 'My Admin Panel', ]; ``` -------------------------------- ### Install Dev Server Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/dev-server.md Add the package to your project using Composer. ```bash composer require marko/dev-server ``` -------------------------------- ### Install Minimal API Stack Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/getting-started/installation.md Install only the essential packages for a lightweight JSON API, including core, routing, configuration, and environment handling. ```bash composer require marko/core marko/routing marko/config marko/env ``` -------------------------------- ### Example .env File Format Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/env.md Demonstrates the format of a .env file, including key-value pairs, comments, and quoted values. ```dotenv APP_NAME=Marko APP_DEBUG=true DB_HOST=localhost DB_PORT=3306 # Comments start with # SECRET_KEY="quoted values supported" ANOTHER_KEY='single quotes too' ``` -------------------------------- ### Configure Service Patterns Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/dev-server.md Examples of setting service options to auto-detect, use custom commands, or disable. ```php // Auto-detect (default): scan for compose file / package.json 'docker' => true, // Custom command: run exactly this 'docker' => 'docker compose -f infrastructure/compose.yaml up -d', // Disabled: skip entirely 'docker' => false, ``` -------------------------------- ### Initialize Starlight Project Source: https://github.com/marko-php/marko/blob/develop/docs/README.md Use this command to scaffold a new Astro project with the Starlight template. ```bash npm create astro@latest -- --template starlight ``` -------------------------------- ### Install Full Web Application Stack Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/framework.md Install the Marko framework along with common packages for a full-featured web application, including database, cache, session, and logging. ```bash composer require marko/framework \ marko/database marko/database-pgsql \ marko/cache marko/cache-file \ marko/session marko/session-file \ marko/authentication \ marko/log marko/log-file ``` -------------------------------- ### Define Application Entry Point Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/dev-server.md Required bootstrap file for the development server. ```php handleRequest(); ``` -------------------------------- ### Install Marko HTTP Guzzle Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/http-guzzle.md Install the Guzzle-powered HTTP client driver using Composer. This command also installs the base marko/http package. ```bash composer require marko/http-guzzle ``` -------------------------------- ### Install Marko Filesystem S3 Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/filesystem-s3.md Install the S3 filesystem driver using Composer. This also installs the core marko/filesystem package and the AWS SDK for PHP. ```bash composer require marko/filesystem-s3 ``` -------------------------------- ### Install Authentication Token Package Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/authentication-token.md Use Composer to add the authentication-token package to your project. ```bash composer require marko/authentication-token ``` -------------------------------- ### Install marko/encryption-openssl Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/encryption-openssl.md Use Composer to install the OpenSSL encryption driver. This also installs the base marko/encryption package. Ensure the ext-openssl PHP extension is enabled. ```bash composer require marko/encryption-openssl ``` -------------------------------- ### Quick Example of API Client Source: https://github.com/marko-php/marko/blob/develop/packages/http-guzzle/README.md Demonstrates how to use the HttpClientInterface to fetch data from an API. Ensure the HttpClientInterface is correctly injected into the ApiClient constructor. ```php use Marko\Http\Contracts\HttpClientInterface; class ApiClient { public function __construct( private HttpClientInterface $httpClient, ) {} public function fetchData(): array { $response = $this->httpClient->get('https://api.example.com/data', [ 'headers' => ['Accept' => 'application/json'], ]); return $response->json(); } } ``` -------------------------------- ### Install rate-limiting package Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/rate-limiting.md Install the package via Composer. ```bash composer require marko/rate-limiting ``` -------------------------------- ### Install Headless/CLI Application Stack Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/framework.md Install the Marko framework for command-line tools or background workers, including database, logging, and local filesystem support. ```bash composer require marko/framework \ marko/database marko/database-pgsql \ marko/log marko/log-file \ marko/filesystem marko/filesystem-local ``` -------------------------------- ### Install Validation Package Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/guides/validation.md Install the validation library via Composer. ```bash composer require marko/validation ``` -------------------------------- ### Thumbnail Example Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/media-gd.md Example for generating a thumbnail with a maximum dimension constraint. ```APIDOC ## Thumbnail Generate a thumbnail where the longest side is at most 150px: ```php $outputPath = $this->imageProcessor->thumbnail( imagePath: $imagePath, maxDimension: 150, ); ``` ``` -------------------------------- ### Crop Example Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/media-gd.md Example showing how to crop an image to a specific region. ```APIDOC ## Crop Extract a region starting at pixel coordinates (50, 100), 400px wide and 300px tall: ```php $outputPath = $this->imageProcessor->crop( imagePath: $imagePath, x: 50, y: 100, width: 400, height: 300, ); ``` ``` -------------------------------- ### Configure Database Connection in .env Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/tutorials/build-a-blog.md Set up your database connection details in the .env file. Ensure your database is running and accessible. ```bash DB_CONNECTION=pgsql DB_HOST=localhost DB_PORT=5432 DB_DATABASE=my_blog DB_USERNAME=marko DB_PASSWORD=secret ``` -------------------------------- ### Install Authentication Package Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/guides/authentication.md Use Composer to add the authentication package to your project. ```bash composer require marko/authentication ``` -------------------------------- ### Install Marko Database MySQL Driver Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/database-mysql.md Use Composer to install the MySQL driver for Marko's database layer. This also installs the core database interface package. ```bash composer require marko/database-mysql ``` -------------------------------- ### Install marko/config Package Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/config.md Command to install the marko/config package using Composer. ```bash composer require marko/config ``` -------------------------------- ### Install encryption package Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/encryption.md Install the base encryption package via Composer. ```bash composer require marko/encryption ``` -------------------------------- ### DocumentService Example Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/guides/file-storage.md Inject `FilesystemInterface` into your service to perform file operations like saving, loading, and deleting documents. This example demonstrates basic file management within a service class. ```php filesystem->write("documents/$name", $contents); } public function load(string $name): string { return $this->filesystem->read("documents/$name"); } public function remove(string $name): void { $this->filesystem->delete("documents/$name"); } } ``` -------------------------------- ### Install Marko Env Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/env.md Install the Marko Env package using Composer. ```bash composer require marko/env ``` -------------------------------- ### Install Marko Admin Package Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/admin.md Use Composer to install the marko/admin package. ```bash composer require marko/admin ``` -------------------------------- ### Configuration Example Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/encryption-openssl.md Configure the encryption key and cipher in your application's configuration file. The key should be a base64-encoded 32-byte value. ```APIDOC ## Configuration Set the encryption key and cipher in your config: ```php title="config/encryption.php" return [ 'key' => $_ENV['ENCRYPTION_KEY'] ?? '', 'cipher' => $_ENV['ENCRYPTION_CIPHER'] ?? 'aes-256-gcm', ]; ``` Generate a key: ```bash php -r "echo base64_encode(random_bytes(32)) . PHP_EOL;" ``` The key must be a base64-encoded 32-byte value. ``` -------------------------------- ### Install Marko Testing Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/testing.md Install the testing package as a development dependency via Composer. ```bash composer require marko/testing --dev ``` -------------------------------- ### Install Database Packages Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/framework.md Install the database abstraction layer along with a specific driver like MySQL or PostgreSQL. Use this for applications requiring database interaction. ```bash composer require marko/database marko/database-mysql ``` ```bash composer require marko/database marko/database-pgsql ``` -------------------------------- ### Install admin-auth package Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/admin-auth.md Use Composer to add the package to your project. ```bash composer require marko/admin-auth ``` -------------------------------- ### Module Configuration: Boot Callback Source: https://github.com/marko-php/marko/blob/develop/docs/src/content/docs/packages/core.md Use the `boot` callback in `module.php` to execute code after all module bindings are registered. Parameters are auto-injected from the container. ```php return [ 'bindings' => [ PaymentInterface::class => StripePayment::class, ], 'boot' => function (ErrorHandlerInterface $handler): void { $handler->register(); }, ]; ``` -------------------------------- ### Quick Example: Dispatching Jobs Source: https://github.com/marko-php/marko/blob/develop/packages/queue-rabbitmq/README.md Dispatch jobs to the queue immediately or with a delay using the QueueInterface. Ensure the QueueInterface is injected into your class. ```php use Marko\Queue\QueueInterface; public function __construct( private readonly QueueInterface $queue, ) {} public function dispatch(): void { $this->queue->push(new ProcessPayment($orderId)); // Delay by 30 seconds using dead-letter exchange $this->queue->later(30, new SendReceipt($orderId)); } ```