### Start and Test Marko Application Source: https://marko.build/docs/getting-started/first-application Use the Marko CLI to start the development server and open the application in the browser. Ensure marko/cli is installed globally if needed. ```bash marko up marko open ``` -------------------------------- ### Installation Source: https://marko.build/docs/packages/filesystem-local Install the marko/filesystem-local package using Composer. This also installs marko/filesystem and requires the ext-fileinfo PHP extension. ```APIDOC ## Installation ```bash composer require marko/filesystem-local ``` This automatically installs `marko/filesystem`. Requires the `ext-fileinfo` PHP extension. ``` -------------------------------- ### Installation Source: https://marko.build/docs/packages/log-file Install the marko/log-file package using Composer. This will also install marko/log. ```APIDOC ## Installation ```bash composer require marko/log-file ``` This automatically installs `marko/log`. ``` -------------------------------- ### Application Entry Point Example Source: https://marko.build/docs/packages/dev-server Example of the `public/index.php` entry point required by `marko up`. This code bootstraps the application and handles requests. ```php handleRequest(); ``` -------------------------------- ### Install marko/queue Source: https://marko.build/docs/packages/queue Install the package via Composer. ```bash composer require marko/queue ``` -------------------------------- ### Install marko/admin-auth Source: https://marko.build/docs/packages/admin-auth Install the package using Composer. ```bash composer require marko/admin-auth ``` -------------------------------- ### Install marko/log Package Source: https://marko.build/docs/packages/log Install the core logging package using Composer. Remember to also install a driver package for log writing. ```bash composer require marko/log ``` -------------------------------- ### Customization Example Source: https://marko.build/docs/packages/pubsub-redis Example demonstrating how to customize the Redis connection. ```APIDOC ## Customization Example ### Description This example shows how to override the default Redis connection by extending `RedisPubSubConnection` and registering it via a Preference. ### Extending RedisPubSubConnection ```php use Amp\Redis\RedisClient; use Marko\PubSub\Redis\RedisPubSubConnection; class TlsRedisPubSubConnection extends RedisPubSubConnection { protected function createClient(): RedisClient { // Example: Using rediss:// for TLS connection return \Amp\Redis\createRedisClient("rediss://$this->host:$this->port"); } } ``` ### Registering the Custom Connection Add the following to your module's configuration file (e.g., `config/container.php`): ```php use Marko\PubSub\Redis\RedisPubSubConnection; return [ 'bindings' => [ RedisPubSubConnection::class => TlsRedisPubSubConnection::class, ], ]; ``` ``` -------------------------------- ### Installation Source: https://marko.build/docs/packages/authorization Install the marko/authorization package using Composer. ```APIDOC ## Installation ```bash composer require marko/authorization ``` ``` -------------------------------- ### Usage Example Source: https://marko.build/docs/packages/filesystem-local Inject the `FilesystemInterface` into your classes to use the local filesystem driver. The example demonstrates writing a report and listing existing reports. ```APIDOC ## Usage Once configured, inject `FilesystemInterface` as usual --- the local driver is used automatically: ```php use Marko\Filesystem\Contracts\FilesystemInterface; class ReportService { public function __construct( private FilesystemInterface $filesystem, ) {} public function generateReport( string $name, string $contents, ): void { $this->filesystem->write( "reports/$name.pdf", $contents, ['visibility' => 'private'], ); } public function listReports(): array { $listing = $this->filesystem->listDirectory('reports'); return $listing->files(); } } ``` ``` -------------------------------- ### Installation Source: https://marko.build/docs/packages/cache-redis Install the marko/cache-redis package using Composer. This will also install marko/cache and predis/predis. ```APIDOC ## Installation ```bash composer require marko/cache-redis ``` This automatically installs `marko/cache` and `predis/predis`. ``` -------------------------------- ### Install Marko Pub/Sub Redis Source: https://marko.build/docs/packages/pubsub-redis Use Composer to install the package. This will also install marko/pubsub and marko/amphp. ```bash composer require marko/pubsub-redis ``` -------------------------------- ### Install marko/pubsub-pgsql Source: https://marko.build/docs/packages/pubsub-pgsql Install the package via composer. ```bash composer require marko/pubsub-pgsql ``` -------------------------------- ### SSE Integration Example Source: https://marko.build/docs/packages/pubsub-redis Example demonstrating how to integrate with marko/sse to stream pub/sub messages to the browser. ```APIDOC ## SSE Integration Example ### Description This example combines `marko/pubsub-redis` with `marko/sse` to stream pub/sub messages directly to a web browser. ### Code ```php use Marko\PubSub\SubscriberInterface; use Marko\Routing\Attributes\Get; use Marko\Sse\SseStream; use Marko\Sse\StreamingResponse; class NotificationController { public function __construct( private SubscriberInterface $subscriber, ) {} #[Get('/users/{userId}/notifications')] public function stream(int $userId): StreamingResponse { $subscription = $this->subscriber->subscribe("user.$userId"); $stream = new SseStream( subscription: $subscription, timeout: 300, ); return new StreamingResponse($stream); } } ``` ``` -------------------------------- ### Installation Source: https://marko.build/docs/packages/hashing Install the Marko Hashing library using Composer. ```APIDOC ## Installation ``` composer require marko/hashing ``` ``` -------------------------------- ### Install Authentication Token Package Source: https://marko.build/docs/packages/authentication-token Use Composer to install the authentication token package. ```bash composer require marko/authentication-token ``` -------------------------------- ### Install Full Web Application Stack Source: https://marko.build/docs/packages/framework Install the Marko Framework with database, caching, sessions, authentication, and logging packages for a complete web application. ```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 ``` -------------------------------- ### Install Minimal API Stack Source: https://marko.build/docs/packages/framework Install the Marko Framework with database and caching for a lightweight API without sessions or views. ```bash composer require marko/framework \ marko/database marko/database-mysql \ marko/cache marko/cache-file ``` -------------------------------- ### Install Marko Media Package Source: https://marko.build/docs/packages/media Use Composer to install the marko/media package. ```bash composer require marko/media ``` -------------------------------- ### Install marko/log-file Source: https://marko.build/docs/packages/log-file Install the package via Composer. ```bash composer require marko/log-file ``` -------------------------------- ### Install Marko Filesystem Package Source: https://marko.build/docs/packages/framework Install the filesystem abstraction layer with the local driver. ```bash composer require marko/filesystem marko/filesystem-local ``` -------------------------------- ### Install marko/media-gd with Composer Source: https://marko.build/docs/packages/media-gd Use Composer to install the marko/media-gd package. This command also installs the core marko/media package. ```bash composer require marko/media-gd ``` -------------------------------- ### Install Marko Filesystem Source: https://marko.build/docs/packages/filesystem Install the core package via Composer. ```bash composer require marko/filesystem ``` -------------------------------- ### Installation Source: https://marko.build/docs/packages/rate-limiting Install the rate-limiting package using Composer. ```APIDOC ## Installation ```bash composer require marko/rate-limiting ``` Requires `marko/cache` for the storage backend and `marko/routing` for the middleware. ``` -------------------------------- ### Install Filesystem Drivers Source: https://marko.build/docs/guides/file-storage Use Composer to install the core package and required storage drivers. ```bash # Local filesystem (stores files on disk) composer require marko/filesystem marko/filesystem-local # Amazon S3 / S3-compatible storage composer require marko/filesystem marko/filesystem-s3 ``` -------------------------------- ### Installation Source: https://marko.build/docs/packages/session-file Install the Marko Session File driver using Composer. ```APIDOC ## Installation Install the Marko Session File driver using Composer. ### Command ```bash composer require marko/session-file ``` This command automatically installs `marko/session` as well. ``` -------------------------------- ### Install marko/view-latte Source: https://marko.build/docs/packages/view-latte Use Composer to install the package and its dependencies. ```bash composer require marko/view-latte ``` -------------------------------- ### Install marko/translation Source: https://marko.build/docs/packages/translation Install the package via Composer. ```bash composer require marko/translation ``` -------------------------------- ### Install Headless/CLI Application Stack Source: https://marko.build/docs/packages/framework Install the Marko Framework with database, logging, and filesystem packages for command-line tools or background workers. ```bash composer require marko/framework \ marko/database marko/database-pgsql \ marko/log marko/log-file \ marko/filesystem marko/filesystem-local ``` -------------------------------- ### Installation Source: https://marko.build/docs/packages/mail-smtp Install the marko/mail-smtp package using Composer. ```APIDOC ## Installation Install the marko/mail-smtp package using Composer: ```bash composer require marko/mail-smtp ``` This command also automatically installs `marko/mail`. ``` -------------------------------- ### Installation Source: https://marko.build/docs/packages/layout Install the Marko Layout component using Composer. ```APIDOC ## Installation ```bash composer require marko/layout ``` ``` -------------------------------- ### Install Database or RabbitMQ Queue Backend Source: https://marko.build/docs/guides/queues Install the necessary composer packages for either a database-backed or RabbitMQ-backed queue system. ```bash composer require marko/queue marko/queue-database ``` ```bash composer require marko/queue marko/queue-rabbitmq ``` -------------------------------- ### Installation Source: https://marko.build/docs/packages/queue-rabbitmq Install the RabbitMQ queue driver and its dependencies using Composer. ```APIDOC ## Installation ```bash composer require marko/queue-rabbitmq ``` This command installs both `marko/queue` and `php-amqplib/php-amqplib`. ``` -------------------------------- ### Install Marko Pagination Source: https://marko.build/docs/packages/pagination Use Composer to install the marko/pagination library. ```bash composer require marko/pagination ``` -------------------------------- ### Install SSE and PubSub Packages Source: https://marko.build/docs/guides/real-time Install the SSE package along with a PubSub driver. Choose Redis for pattern subscriptions and dedicated infrastructure, or PostgreSQL for a zero-extra-infrastructure solution. ```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 ``` -------------------------------- ### Installation Source: https://marko.build/docs/packages/errors-simple Install the Marko Errors Simple library using Composer. ```APIDOC ## Installation Install the Marko Errors Simple library using Composer. ```bash composer require marko/errors-simple ``` The handler registers automatically via module boot --- no configuration required. ``` -------------------------------- ### Install Marko Dev Server Source: https://marko.build/docs/packages/dev-server Install the dev-server package using Composer. ```bash composer require marko/dev-server ``` -------------------------------- ### Install Pub/Sub Driver Source: https://marko.build/docs/packages/pubsub Install a specific driver package alongside the core library, such as marko/pubsub-redis or marko/pubsub-pgsql. ```bash composer require marko/pubsub-redis # or composer require marko/pubsub-pgsql ``` -------------------------------- ### Install marko/mail-log Source: https://marko.build/docs/packages/mail-log Use Composer to install the package and its dependencies. ```bash composer require marko/mail-log ``` -------------------------------- ### Install marko/cache-file Source: https://marko.build/docs/packages/cache-file Use Composer to install the package and its dependencies. ```bash composer require marko/cache-file ``` -------------------------------- ### Subscribing Example Source: https://marko.build/docs/packages/pubsub-redis Example demonstrating how to subscribe to messages using the SubscriberInterface. ```APIDOC ## Subscribing Example ### Description This example shows how to inject and use the `SubscriberInterface` to listen for messages. ### Code ```php use Marko\PubSub\SubscriberInterface; class NotificationListener { public function __construct( private SubscriberInterface $subscriber, ) {} public function listen(int $userId): void { $subscription = $this->subscriber->subscribe("user.$userId"); foreach ($subscription as $message) { $data = json_decode($message->payload, true); // handle notification ... } } } ``` ### Starting the Listener To start the listener process, use the following command: ```bash marko pubsub:listen ``` ``` -------------------------------- ### Pattern Subscriptions Example Source: https://marko.build/docs/packages/pubsub-redis Example demonstrating how to subscribe to channels using glob patterns. ```APIDOC ## Pattern Subscriptions Example ### Description This example shows how to use `psubscribe()` to receive messages from channels matching a glob pattern. ### Code ```php // Assuming $this->subscriber is an instance of SubscriberInterface $subscription = $this->subscriber->psubscribe('user.*'); foreach ($subscription as $message) { // $message->pattern === 'user.*' // $message->channel is the matched channel, e.g. 'user.42' $data = json_decode($message->payload, true); // Handle message... } ``` ``` -------------------------------- ### Install Marko Database Packages Source: https://marko.build/docs/packages/framework Install the database abstraction layer with either the MySQL or PostgreSQL driver. ```bash composer require marko/database marko/database-mysql # or composer require marko/database marko/database-pgsql ``` -------------------------------- ### Install Marko Filesystem Local Driver Source: https://marko.build/docs/packages/filesystem-local Use Composer to install the marko/filesystem-local package. This will also install the marko/filesystem dependency. Ensure the ext-fileinfo PHP extension is enabled. ```bash composer require marko/filesystem-local ``` -------------------------------- ### Install Marko Authentication Package Source: https://marko.build/docs/guides/authentication Use Composer to install the authentication package. ```bash composer require marko/authentication ``` -------------------------------- ### Install Marko Logging Packages Source: https://marko.build/docs/guides/logging Install the core logging contracts and the file driver using Composer. ```bash composer require marko/log marko/log-file ``` -------------------------------- ### Install Marko Hashing Source: https://marko.build/docs/packages/hashing Install the package using Composer. ```bash composer require marko/hashing ``` -------------------------------- ### Start Development Environment Source: https://marko.build/docs/packages/dev-server Starts all detected services (PHP server, Docker, Frontend) in detached mode by default. Use `marko status` and `marko down` to manage. ```bash marko up ``` -------------------------------- ### Install marko/encryption-openssl Source: https://marko.build/docs/packages/encryption-openssl Use Composer to install the package and its dependencies. ```bash composer require marko/encryption-openssl ``` -------------------------------- ### Install Marko Core Source: https://marko.build/docs/packages/core Install the package via Composer. ```bash composer require marko/core ``` -------------------------------- ### Publishing Example Source: https://marko.build/docs/packages/pubsub-redis Example demonstrating how to publish a message using the PublisherInterface. ```APIDOC ## Publishing Example ### Description This example shows how to inject and use the `PublisherInterface` to send messages. ### Code ```php use Marko\PubSub\Message; use Marko\PubSub\PublisherInterface; class NotificationService { public function __construct( private PublisherInterface $publisher, ) {} public function notify(int $userId, string $text): void { $this->publisher->publish( channel: "user.$userId", message: new Message( channel: "user.$userId", payload: json_encode(['text' => $text]), ), ); } } ``` ``` -------------------------------- ### Install Marko Pub/Sub Source: https://marko.build/docs/packages/pubsub Install the core marko/pubsub package using Composer. ```bash composer require marko/pubsub ``` -------------------------------- ### Install marko/http-guzzle Source: https://marko.build/docs/packages/http-guzzle Use Composer to install the package and its dependencies. ```bash composer require marko/http-guzzle ``` -------------------------------- ### Install Marko Session Package Source: https://marko.build/docs/packages/framework Install the session abstraction layer with the file-based driver. ```bash composer require marko/session marko/session-file ``` -------------------------------- ### Install Marko Cache Package Source: https://marko.build/docs/packages/framework Install the cache abstraction layer with the file-based driver. ```bash composer require marko/cache marko/cache-file ``` -------------------------------- ### AdminRouter Class Example Source: https://marko.build/docs/packages/admin Demonstrates how to use AdminConfigInterface to retrieve the route prefix and panel name. The route prefix is validated to start with '/'. ```php use Marko\Admin\Config\AdminConfigInterface; class AdminRouter { public function __construct( private readonly AdminConfigInterface $adminConfig, ) {} public function getBaseUrl(): string { return $this->adminConfig->getRoutePrefix(); // e.g. '/admin' } public function getPanelName(): string { return $this->adminConfig->getName(); // e.g. 'My Admin Panel' } } ``` -------------------------------- ### Initialize Application via public/index.php Source: https://marko.build/docs/getting-started/project-structure The entry point for the application that boots the framework and handles incoming HTTP requests. ```php handleRequest(); ``` -------------------------------- ### Install Marko Search Package Source: https://marko.build/docs/packages/search Use Composer to install the marko/search package. ```bash composer require marko/search ``` -------------------------------- ### Wildcard Permission Matching Examples Source: https://marko.build/docs/packages/admin-auth Demonstrates how wildcard matching works with permissions. A role with 'catalog.*' can access any permission starting with 'catalog.', and '*' matches any permission. ```php use Marko\AdminAuth\Contracts\PermissionRegistryInterface; $permissionRegistry->matches('catalog.*', 'catalog.products.view'); // true $permissionRegistry->matches('catalog.*', 'catalog.products.edit'); // true $permissionRegistry->matches('*', 'anything.here'); // true $permissionRegistry->matches('catalog.products.*', 'catalog.orders'); // false ``` -------------------------------- ### Install Marko Queue Sync Source: https://marko.build/docs/packages/queue-sync Install the Marko Queue Sync package using Composer. ```bash composer require marko/queue-sync ``` -------------------------------- ### Marko CLI Usage Examples Source: https://marko.build/docs/packages/cli Examples of common commands you can run from any directory within a Marko project. ```APIDOC ## Usage ### Running Commands From any directory within a Marko project: ```bash marko list # Show all available commands marko module:list # List installed modules marko cache:clear # Clear cache (if cache module installed) marko db:migrate # Run migrations (if database module installed) ``` ``` -------------------------------- ### SSE Integration for Streaming Notifications Source: https://marko.build/docs/packages/pubsub-redis Combine with marko/sse to stream pub/sub messages to the browser. This example creates a GET endpoint that streams notifications for a specific user. ```php use Marko\PubSub\SubscriberInterface; use Marko\Routing\Attributes\Get; use Marko\Sse\SseStream; use Marko\Sse\StreamingResponse; #[Get('/users/{userId}/notifications')] public function stream(int $userId): StreamingResponse { $subscription = $this->subscriber->subscribe("user.$userId"); $stream = new SseStream( subscription: $subscription, timeout: 300, ); return new StreamingResponse($stream); } ``` -------------------------------- ### Install Marko Authorization Package Source: https://marko.build/docs/packages/authorization Use Composer to install the marko/authorization package. ```bash composer require marko/authorization ``` -------------------------------- ### Install Marko API with Composer Source: https://marko.build/docs/packages/api Use Composer to install the Marko API package. ```bash composer require marko/api ``` -------------------------------- ### Install Marko Scheduler Source: https://marko.build/docs/guides/scheduling Install the Marko Scheduler package using Composer. ```bash composer require marko/scheduler ``` -------------------------------- ### Install Minimal API Stack Source: https://marko.build/docs/getting-started/installation Install only the essential Marko packages for building a lightweight JSON API. ```bash composer require marko/core marko/routing marko/config marko/env ``` -------------------------------- ### Configure Module Bindings Source: https://marko.build/docs/packages/core Use module.php to define bindings and boot logic. ```php return [ 'enabled' => true, 'bindings' => [ PaymentInterface::class => StripePayment::class, ], ]; ``` ```php return [ 'bindings' => [ PaymentInterface::class => StripePayment::class, ], 'boot' => function (ErrorHandlerInterface $handler): void { $handler->register(); }, ]; ``` -------------------------------- ### Start Marko Server Command Source: https://marko.build/docs/tutorials/build-a-rest-api This command starts the Marko development server. Ensure you are in the project's root directory before executing. ```bash marko up ``` -------------------------------- ### Initialize Marko Project Source: https://marko.build/docs/tutorials/build-a-blog Commands to scaffold a new project and navigate into the directory. ```bash composer create-project marko/skeleton my-blog cd my-blog ``` -------------------------------- ### Install PostgreSQL driver Source: https://marko.build/docs/packages/database-pgsql Use Composer to install the driver and its required interface dependencies. ```bash composer require marko/database-pgsql ``` -------------------------------- ### Install Marko HTTP Package Source: https://marko.build/docs/packages/http Install the core marko/http package using Composer. Remember to also install an implementation package. ```bash composer require marko/http ``` -------------------------------- ### Install Marko Session File Driver Source: https://marko.build/docs/packages/session-file Use Composer to install the marko/session-file package. This command also installs the core marko/session dependency. ```bash composer require marko/session-file ``` -------------------------------- ### Install Marko Skeleton Project Source: https://marko.build/docs Use Composer to create a new Marko project and install the Marko CLI globally. Then, navigate into the project directory and run the 'marko up' command. ```bash composer create-project marko/skeleton my-app composer global require marko/cli cd my-app marko up ``` -------------------------------- ### Interface/Implementation Pattern Source: https://marko.build/docs/concepts/modularity Example of package separation and dependency injection usage. ```text marko/cache → CacheInterface (the contract) marko/cache-file → FileCacheDriver (file-based) marko/cache-redis → RedisCacheDriver (Redis-based) ``` ```php use Marko\Cache\Contracts\CacheInterface; class ProductService { public function __construct( private readonly CacheInterface $cache, ) {} } ``` -------------------------------- ### Direct Config Loading Example Source: https://marko.build/docs/packages/config Demonstrates how to load a configuration file directly using PHP's `require` function without the marko/config package. This is useful for simple cases or when modules load their own config. ```php config . '/database.php'; $host = $config['host']; ``` -------------------------------- ### Install Marko Database Dependencies Source: https://marko.build/docs/guides/database Use Composer to install the core database package and the PostgreSQL driver. ```bash composer require marko/database marko/database-pgsql ``` -------------------------------- ### Install marko/queue-database Source: https://marko.build/docs/packages/queue-database Use Composer to add the package to your project. ```bash composer require marko/queue-database ``` -------------------------------- ### Install Notification Packages Source: https://marko.build/docs/guides/notifications Use Composer to install the core notification package and optional database storage support. ```bash composer require marko/notification ``` ```bash composer require marko/notification-database ``` -------------------------------- ### Marko CLI Installation Source: https://marko.build/docs/packages/cli Install the Marko CLI globally using Composer. Ensure Composer's global bin directory is in your system's PATH. ```APIDOC ## Installation ```bash composer global require marko/cli ``` Ensure Composer’s global bin directory is in your PATH. ``` -------------------------------- ### Initialize Marko Project Source: https://marko.build/docs/tutorials/build-a-rest-api Commands to scaffold a new Marko project and install necessary core and database dependencies. ```bash composer create-project marko/skeleton my-api cd my-api composer require marko/core marko/routing marko/config marko/env \ marko/database marko/database-pgsql marko/validation \ marko/authentication marko/authentication-token ``` -------------------------------- ### Install marko/errors-simple Source: https://marko.build/docs/packages/errors-simple Use Composer to install the package. ```bash composer require marko/errors-simple ``` -------------------------------- ### Install marko/media-imagick Source: https://marko.build/docs/packages/media-imagick Use Composer to add the package to your project. ```bash composer require marko/media-imagick ``` -------------------------------- ### Install marko/amphp Source: https://marko.build/docs/packages/amphp Install the package via Composer. ```bash composer require marko/amphp ``` -------------------------------- ### Install Marko Mail Package Source: https://marko.build/docs/packages/mail Use Composer to install the marko/mail package. Remember to also install a driver package for actual email delivery. ```bash composer require marko/mail ``` -------------------------------- ### Install Marko Cache Redis Source: https://marko.build/docs/packages/cache-redis Install the Redis cache driver using Composer. This command also installs the core marko/cache and predis/predis libraries. ```bash composer require marko/cache-redis ``` -------------------------------- ### Create Database and Run Migrations/Seeders Source: https://marko.build/docs/packages/database Commands to create a new database, run migrations using `db:migrate`, and then populate it with data using `db:seed`. This is a common step after switching database drivers or setting up a new environment. ```bash createdb myapp marko db:migrate marko db:seed ``` -------------------------------- ### Install marko/session via Composer Source: https://marko.build/docs/packages/session Use Composer to install the marko/session package. Typically, a driver package like marko/session-file is installed, which includes this package as a dependency. ```bash composer require marko/session ``` -------------------------------- ### Install Marko Cache Package Source: https://marko.build/docs/packages/cache Install the core Marko Cache package using Composer. Note that you typically install a driver package which requires this automatically. ```bash composer require marko/cache ``` -------------------------------- ### Key Prefixing Example Source: https://marko.build/docs/packages/filesystem-s3 Illustrates how a configured prefix is automatically applied to file keys in S3. ```text // With prefix 'uploads': // Application path: 'images/photo.jpg' // S3 key: 'uploads/images/photo.jpg' ``` -------------------------------- ### Basic Configuration File Structure Source: https://marko.build/docs/packages/config A basic example of a configuration file in PHP, returning an associative array. Place such files in your module's `config/` directory. ```php 'localhost', 'port' => 3306, 'name' => 'my_app', 'connection' => [ 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', ], ]; ``` -------------------------------- ### Integration Test with LocalFilesystem Source: https://marko.build/docs/guides/file-storage Use the LocalFilesystem with a temporary directory for integration tests. This example demonstrates creating a filesystem instance and using it with a service. ```php use Marko\Filesystem\Local\Filesystem\LocalFilesystem; use Marko\Filesystem\Contracts\FilesystemInterface; // Create a filesystem in a temp directory $filesystem = new LocalFilesystem( basePath: sys_get_temp_dir() . '/test-' . uniqid(), ); // Use it in your service $service = new DocumentService(filesystem: $filesystem); $service->save('test.txt', 'Hello, world!'); // Assert the file was written expect($filesystem->exists('test.txt'))->toBeTrue(); expect($filesystem->read('test.txt'))->toBe('Hello, world!'); ``` -------------------------------- ### Install Full Web Application Stack Source: https://marko.build/docs/getting-started/installation Install the core Marko framework with common packages for a full web application. Additional packages like database or caching can be added as needed. ```bash composer require marko/framework ``` -------------------------------- ### Install marko/health Package Source: https://marko.build/docs/packages/health Use Composer to install the marko/health package. ```bash composer require marko/health ``` -------------------------------- ### Install marko/admin-api Source: https://marko.build/docs/packages/admin-api Use Composer to add the package to your project. ```bash composer require marko/admin-api ``` -------------------------------- ### Create Marko Project and Install Dependencies Source: https://marko.build/docs/tutorials/build-a-chat Use Composer to create a new Marko project and install necessary components for building a chat application, including routing, database, authentication, PubSub, SSE, and a development server. ```bash composer create-project marko/skeleton my-chat cd my-chat composer require marko/core marko/routing marko/config marko/env \ marko/database marko/database-pgsql \ marko/authentication marko/session marko/session-database \ marko/pubsub marko/pubsub-redis marko/sse \ marko/view marko/view-latte marko/dev-server ``` -------------------------------- ### Install Marko SSE Package Source: https://marko.build/docs/packages/sse Use Composer to install the marko/sse package. ```bash composer require marko/sse ``` -------------------------------- ### DevUpCommand Source: https://marko.build/docs/packages/dev-server Command to start the development environment. ```APIDOC ## POST /dev/up ### Description Starts the development environment. ### Method POST ### Endpoint /dev/up ### Parameters #### Query Parameters - **port** (integer) - Optional - Override the server port. - **detach** (boolean) - Optional - Run in background (detached mode). - **foreground** (boolean) - Optional - Run in foreground mode (overrides detach default). ### Request Example ```json { "port": 8080, "detach": true } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the environment has started successfully. #### Response Example ```json { "status": "Development environment started." } ``` ``` -------------------------------- ### Install marko/webhook Source: https://marko.build/docs/packages/webhook Use Composer to add the package to your project. ```bash composer require marko/webhook ``` -------------------------------- ### Install marko/config Package Source: https://marko.build/docs/packages/config Use Composer to install the marko/config package into your project. ```bash composer require marko/config ``` -------------------------------- ### Configure development server processes Source: https://marko.build/docs/packages/amphp Add the pubsub listener to the marko/dev-server configuration to run it alongside the web server. ```php return [ 'processes' => [ 'pubsub' => 'marko pubsub:listen', ], ]; ``` -------------------------------- ### Install Marko Admin Package Source: https://marko.build/docs/packages/admin Use Composer to install the marko/admin package. ```bash composer require marko/admin ``` -------------------------------- ### Default Dev Server Configuration Source: https://marko.build/docs/packages/dev-server Example configuration file (`config/dev.php`) showing default settings for port, detachment, Docker, frontend, pub/sub, and custom processes. ```php 8000, 'detach' => true, 'docker' => true, 'frontend' => true, 'pubsub' => true, 'processes' => [], ]; ``` -------------------------------- ### Upload and Download Files using FilesystemManager Source: https://marko.build/docs/packages/filesystem-s3 Demonstrates uploading a file with public visibility and downloading a file using the FilesystemManager. ```php use Marko\Filesystem\Manager\FilesystemManager; class MediaService { public function __construct( private FilesystemManager $filesystemManager, ) {} public function upload( string $path, string $contents, ): void { $this->filesystemManager->disk('s3')->write( $path, $contents, ['visibility' => 'public'], ); } public function download( string $path, ): string { return $this->filesystemManager->disk('s3')->read($path); } } ``` -------------------------------- ### Install MySQL driver Source: https://marko.build/docs/packages/database-mysql Use Composer to install the driver and its required interface dependencies. ```bash composer require marko/database-mysql ```