umonkey/ufw1

There is no license information available for the latest version (dev-master) of this package.

slim based website framework for pet projects

dev-master 2020-04-03 10:23 UTC

This package is auto-updated.

Last update: 2024-03-29 04:05:13 UTC


README

This projects contains components which I frequently reuse on my websites. It's based on Slim Framework, because it's clean, simple and easy to understand.

Concepts

Uses the ADR pattern (action-domain-responder). Actions are light-weight controllers, with only one action and no logic: the job is to parse input data and pass it to the domain. Domain is a service which handles the input data, does the job (probably invoking other services) and returns the response payload. Reponder renders payload to the actual HTTP response, depending on its contents and other circumstances (XHR, etc). This all makes the application open for unit testing.

Uses dependency injection, named after Symfony services. Services are isolate parts of code which are loaded on demand. Controllers receive arguments extracted from the container by name. Built in services include database, logger, node and file factory, S3, search engine, stemmer, task queue, Telegram notifications, Twig template renderer, a thumbnailer and a wiki engine.

Uses "nodes", individual pieces of content, such as a page, poll, article, forum topic, or a blog entry. This is inspired by Drupal, works well and simplifies document management greatly.

Uses task queue for background task execution. There is a separate daemon which monitors the taskq queue table and runs the task handlers. This lets the application respond quickly, offloading long tasks to the queue worker and serializing tasks. Best for uploading files to the cloud, sending mail and other notifications.

Uses the repository/entity pattern to access data. Entities are currently just wrappers around ArrayObject which enhance it a little. Entities know nothing about the storage and don't interact with it -- that's what repositories do (see the Nodes module). No ORM, no query builders -- SQL is portable and simple enough.

Services

Custom services are configured in config/services.php, standard services are set up with Util::containerSetup().

Key Class Description
db Database Raw database access. Wraps around PDO. Has no query builder or anything, designed to use with SQL. Has some fetch, insert and update helpers, transactional block. Detailed docs are here.
file FileRepository File storage interface. Represents files stored in the database (as nodes). Files can have multiple versions (thumbnails), can be stored locally or on S3. Detailed docs are here.
fts Search Full text document index. Usess MySQL and SQLite built in functions and a custom stemmer. Can translate aliases. Detailed docs are here.
logger Logger Simple file logger, implements PSR-3. Files can have date based names. Details here.
node NodeRepository Document storage. Stores documents as "nodes", in the nodes table, Drupal style. Nodes are of various types, have indexes etc. Detailed docs are here.

Folder structure

  • bin: maintenance scripts.
  • config: various settings. File names are sound, comments explain details.
  • docs: documentation on some components.
  • src: all source files.
  • templates: built in Twig templates, can be used as fallback in real applications.
  • tests: phpunit files.
  • vendor: third party components.

Installing

$ composer require umonkey/ufw1:dev-default

TODO

Major:

  • Switch to action-domain-responder.
  • Uncouple wiki, admin UI, blog etc to separate packages.

Minor:

  • Some common CLI functions.
  • Better unit test coverage.

Recommended reading