Download the PHP package adaiasmagdiel/erlenmeyer without Composer

On this page you can find all versions of the php package adaiasmagdiel/erlenmeyer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package erlenmeyer

Erlenmeyer - Minimal PHP Framework for Web Applications

License: GPL v3
Composer
GitHub Repository

Erlenmeyer is a lightweight PHP framework designed for simplicity and efficiency in building web applications. Inspired by the minimalism of Python's Flask, Erlenmeyer is not a direct clone but a unique solution tailored for PHP developers. It is currently in its early stages, making it perfect for small projects, APIs, or microservices where a lean setup is preferred. I created Erlenmeyer to streamline my own projects, but it's open for anyone seeking a straightforward, no-frills framework.

Table of Contents

Introduction

Erlenmeyer is a lightweight PHP framework designed for simplicity and efficiency in building web applications. Inspired by the minimalism of Python's Flask, Erlenmeyer is not a direct clone but a unique solution tailored for PHP developers. It is currently in its early stages, making it perfect for small projects, APIs, or microservices where a lean setup is preferred. I created Erlenmeyer to streamline my own projects, but it's open for anyone seeking a straightforward, no-frills framework.

Key Characteristics:

Features

Requirements

Installation

Install Erlenmeyer using Composer:

Include it in your PHP project:

Getting Started

First, make sure to import the necessary classes:

Create a new instance of the App class:

Define routes:

Run the application:

Routing

Erlenmeyer supports various HTTP methods for routing:

Dynamic Routes

Define routes with parameters:

Redirects

Set up redirects:

Middlewares

Add global middlewares:

Add route-specific middlewares:

Error Handling

Set a custom 404 handler:

Set exception handlers:

Asset Management

Serve static assets by creating an instance of Assets:

Access assets via /assets/file.ext. For example:

Session Management

Use the Session class to manage sessions:

Request and Response Objects

Request

The Request object provides access to request data:

Response

The Response object allows building responses:

Logging

Erlenmeyer provides a flexible and extensible logging system to help you monitor and debug your application. Logging is essential for tracking events, identifying issues, and understanding application behavior. The logging system is based on the LoggerInterface, which defines the contract for logging messages and exceptions.

Using Loggers

Erlenmeyer provides two built-in loggers: FileLogger for file-based logging with rotation, and ConsoleLogger for logging to the command line using error_log. You can choose either by passing an instance to the App constructor.

Example with FileLogger:

Example with ConsoleLogger:

Log Levels

The logging system supports the following levels, defined in the LogLevel enum:

Level Description
INFO General operational information
DEBUG Detailed debug information
WARNING Indicates something unexpected but recoverable
ERROR Indicates a serious error affecting functionality
CRITICAL Indicates a critical error that may cause the application to crash

These levels can be used when logging messages to categorize their severity.

Creating a Custom Logger

If you need advanced logging features, such as logging to a database, sending logs to an external service, or using a custom format, you can create a custom logger by implementing the LoggerInterface.

Example of a Custom Logger:

To use the custom logger, pass an instance to the App constructor:

Important Note: If no logger is explicitly provided, the App will create a FileLogger without a log directory, which means no logging will occur. You must configure a logger explicitly to enable logging.

Tests

Erlenmeyer uses PestPHP for testing. Run tests with:

Use Cases

Erlenmeyer is suitable for a wide range of web applications. Here are some example use cases:

Use Case Description
Simple REST API Create an API with endpoints for GET, POST, PUT, and DELETE, returning JSON responses.
Basic Web Application Develop an application with routes for HTML pages and session management.
Static Page Generator Serve static assets like CSS and JavaScript for landing pages.
Forms and Uploads Handle POST forms and file uploads with validation.

Example REST API:

Example Form Handling:

License

Erlenmeyer is licensed under the GPLv3. See the COPYRIGHT files for details.

Reference

App

Method Description
__construct(?Assets $assets = null, ?string $logDir = null) Initializes the application.
route(string $method, string $route, callable $action, array $middlewares = []) Registers a route for an HTTP method.
get(string $route, callable $action, array $middlewares = []) Registers a GET route.
post(string $route, callable $action, array $middlewares = []) Registers a POST route.
any(string $route, callable $action, array $middlewares = []) Registers a route for any HTTP method.
match(array $methods, string $route, callable $action, array $middlewares = []) Registers a route for specified methods.
redirect(string $from, string $to, bool $permanent = false) Registers a redirect.
set404Handler(callable $action) Sets the 404 error handler.
addMiddleware(callable $middleware) Adds a global middleware.
setExceptionHandler(string $exceptionClass, callable $handler) Sets an exception handler.
run() Runs the application.

Assets

Method Description
__construct(string $assetsDirectory = "/public", string $assetsRoute = "/assets") Initializes the asset manager.
getAssetsDirectory(): string Returns the assets directory.
getAssetsRoute(): string Returns the assets route.
isAssetRequest(): bool Checks if the request is for an asset.
serveAsset(): bool Serves the requested asset.

Session

Method Description
static get(string $key, $default = null) Gets a session value.
static set(string $key, $value) Sets a session value.
static has(string $key): bool Checks if a session key exists.
static remove(string $key) Removes a session key.
static flash(string $key, $value) Sets a flash message.
static getFlash(string $key, $default = null) Gets and removes a flash message.
static hasFlash(string $key): bool Checks if a flash message exists.

Request

Method Description
__construct(?array $server = null, ?array $get = null, ?array $post = null, ?array $files = null, string $inputStream = 'php://input') Initializes the request.
getHeader(string $name): ?string Gets a specific header.
getHeaders(): array Gets all headers.
getMethod(): string Gets the HTTP method.
getUri(): string Gets the request URI.
getQueryParams(): array Gets query parameters.
getFormData(): array Gets form data.
getJson(): mixed Gets JSON data from the body.
getFiles(): array Gets uploaded files.
isAjax(): bool Checks if the request is AJAX.
isSecure(): bool Checks if the request is secure (HTTPS).

Response

Method Description
__construct(int $statusCode = 200, array $headers = []) Initializes the response.
setStatusCode(int $code): self Sets the HTTP status code.
getStatusCode(): int Gets the HTTP status code.
setHeader(string $name, string $value): self Sets an HTTP header.
removeHeader(string $name): self Removes an HTTP header.
getHeaders(): array Gets all headers.
setContentType(string $contentType): self Sets the content type.
getContentType(): string Gets the content type.
setBody(string $body): self Sets the response body.
getBody(): ?string Gets the response body.
withHtml(string $html): self Sets HTML content.
withTemplate(string $templatePath, array $data = []): self Sets content from a template.
withJson($data, int $options = JSON_PRETTY_PRINT): self Sets JSON content.
withText(string $text): self Sets plain text content.
redirect(string $url, int $statusCode = 302): self Sets a redirect.
withCookie(string $name, string $value, int $expire = 0, string $path = '/', string $domain = '', bool $secure = false, bool $httpOnly = true): self Sets a cookie.
send(): void Sends the response.
isSent(): bool Checks if the response has been sent.
clear(): self Clears the response body and headers.
withError(int $statusCode, string $message = '', ?callable $logger = null): self Sets an error response.
withFile(string $filePath): self Sets the response to send a file.
setCORS(array $options): self Configures CORS headers.

All versions of erlenmeyer with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package adaiasmagdiel/erlenmeyer contains the following files

Loading the files please wait ....