|
1 month ago | |
---|---|---|
db/migrations | 2 years ago | |
public | 1 month ago | |
resources | 8 months ago | |
src | 10 months ago | |
.editorconfig | 2 years ago | |
.gitignore | 2 years ago | |
LICENSE | 2 years ago | |
README.md | 2 years ago | |
artemis.php | 2 years ago | |
composer.json | 1 month ago | |
composer.lock | 1 month ago | |
config.php | 1 month ago | |
phinx.php | 2 years ago | |
routes.php | 10 months ago |
README.md
artemix.org
My blog.
Requirements
- PHP 7.3+
- Composer
- PDO
- PDO PgSQL
- PostgreSQL 11+
Set up a local work environment
My environment is based on Apache, and is made to flawlessly work with that. I have no example configuration for anything else than Apache / PHP.
Requirements
- Apache 2.4+
- mod_rewrite
- mod_php7
- mod_env: not required, but highly recommended to set once and never again environment variables.
Project setup
$ git clone https://git.sr.ht/~artemis/artemix.org
$ cd artemix.org
$ composer install
Now, you need to point your DocumentRoot
to artemix.org/public
.
You should define the environment variables for DB_DSN
and AUTH_TOKEN
.
DB_DSN
will be the PostgreSQL connection string, see the PDO docs on how to create itAUTH_TOKEN
will be used for authenticating the blog's owner on/admin
. It can be generated by enteringphp artemis.php new:key
and answering prompted questions.
Database setup
Once you've configured your environment, you'll have to set up the database tables.
To do that, run vendor/bin/phinx migrate
, which will create the database.
You're all set!
Architecture
db/
: Migrations, as handled by phinx (may change for something simpler in the future)public/
: Entrypoint, static resources (e.g. icons)index.php
: Every request's entry point. It may be useful to read it to get a hang on what's happening on every request.assets/
: Every asset should be stored heregpg/
: The public ASC keys should be stored here
resources/
: HTML page templates and base resources that need to be built (CSS / JS)assets/
: base CSS and javascript that will need to be built, if changedtemplates/
: HTML page templates, in the twig templating format
src/
: The website's source codeActions/
: Every HTTP request handler, this is what's referenced inroutes.php
Commands/
: Every CLI command (which must be registered inartemis.php
to be usable)Helpers/
: Basic PHP helper functions, to make a dev's life easierServices/
: OOP service classes, this contains the core backend logicRenderers/
: A series of classes made to provide a simpler interface to render common HTML documentsRepositories/
: A series of classes made to provide an interface to interact with the database in a SRP-compliant way
Types/
: Basic PHP data classes to help dealing with a few typesAction.php
: HTTP request handler (action) interfaceCommand.php
: CLI command handler interfaceParsedownExtended.php
: Custom snippet that wraps Parsedown as dependency. Just stupidly locatedRunner.php
: Core class containing all the logic required to bootstrap the request handling system
artemis.php
: The CLI tool, which allows to minify base resources and create keysconfig.php
: The configuration file, which contains environment-agnostic and non-secret dataroutes.php
: The configuration file, which contains every defined Siler route
Notes
The website doesn't have a concept of "middleware", but instead relies on two mechanisms to run preliminary checks (such as the authentication guard, to make sure only authorized users can access the admin panel).
- A "route" in siler's way is simply a code snippet that will be invoked on URI match.
If a route
A
executes on/a
, and a routeB
executes on/a/b
, having the router set up as['A', 'B']
will execute the actions forA
, thenB
. - This mechanism has been extended with one concept: continue / breaks. If an action's
__invoke
method returns the boolean valuefalse
(and nothing else), the router won't continue to try to match actions.
...
The website heavily relies on PHP-DI to provide access to any instance from actions.
It is strongly advised to get to understand the logic dealt by the Runner::__construct
and Runner::http
methods before starting to dig further into the code.
...
You should never interact with the database directly from an Action (by injecting the Database
service),
but you should instead create a repository that will wrap the database access request logic into clear and simple
PHP methods.