beecubu / php-foundation-api-rest
Simple API-REST Framework based on PHP Object Foundation.
Requires
- php: >=8.4.0
- ext-intl: *
- ext-json: *
- ext-mbstring: *
- beecubu/php-foundation-core: ^3.6
- beecubu/php-foundation-helpers: ^1.11
- delight-im/cookie: ^3.1
- giggsey/libphonenumber-for-php: ^8.12.41
- lion/phroute: ^v2.3
Suggests
- readline: *
- dev-master
- v2.1.0
- v2.0.0
- v1.20.5
- v1.20.4.1
- v1.20.4
- v1.20.3
- v1.20.2.2
- v1.20.2.1
- v1.20.2
- v1.20.1.1
- v1.20.1
- v1.20.0
- v1.19.3
- v1.19.2
- v1.19.1
- v1.19.0
- v1.18.0
- v1.17.0
- v1.16.0
- v1.15.3
- 1.15.2.1
- v1.15.2
- v1.15.1.3
- v1.15.1.2
- v1.15.1.1
- v1.15.1
- v1.15.0.1
- v1.15.0
- v1.14.1
- v1.14.0
- v1.13.2.4
- v1.13.2.3
- v1.13.2.2
- v1.13.2.1
- v1.13.2
- v1.13.1.1
- v1.13.1
- v1.13.0
- v1.12.1
- v1.12.0.4
- v1.12.0.3
- v1.12.0.2
- v1.12.0.1
- v1.12.0
- v1.11.1
- v1.11.0.1
- v1.11.0
- v1.10.5
- v1.10.4
- v1.10.3
- v1.10.2
- v1.10.1
- v1.10.0
- v1.9.1
- v1.9.0
- v1.8.0
- v1.7.0
- v1.6.0
- v1.5.0
- v1.4.0
- v1.3.3
- v1.3.2
- v1.3.1.1
- v1.3.1
- v1.3.0
- v1.2.1
- v1.2.0
- v1.1.0
- v1.0.0.4
- v1.0.0.3
- v1.0.0.2
- v1.0.0.1
- v1.0.0
This package is auto-updated.
Last update: 2026-02-05 13:01:48 UTC
README
Lightweight API-REST framework based on PHP Object Foundation. It provides controllers, session authentication, and an extensible user model while delegating persistence to plugins.
Core features
- Session and CRUD controllers.
- Extensible user model (User, OwnerUser, ApiUser, AdminUser).
- Repository abstraction via interfaces (
IUserRepository,IPInfoCacheRepository). - Repository bootstrap via
RepositoryProvider.
Plugin system The core has no database dependency. Plugins provide concrete repository implementations and register the driver.
Available plugins:
php-foundation-api-rest-mongodbphp-foundation-api-rest-sqlite
Each plugin provides:
- Implementations of
IUserRepositoryandIPInfoCacheRepository. - A
RepositoryBootstrapthat registers repositories viaRepositoryProvider::set(...).
Installation
Install the core and the plugin you need:
composer require beecubu/php-foundation-api-rest
composer require beecubu/php-foundation-api-rest-mongodb
# or
composer require beecubu/php-foundation-api-rest-sqlite
Technical configuration
1) Initialize repositories
MongoDB
use Beecubu\Foundation\ApiRest\MongoDB\RepositoryBootstrap;
RepositoryBootstrap::init();
SQLite
use Beecubu\Foundation\ApiRest\SQLite\RepositoryBootstrap;
RepositoryBootstrap::init();
If you want to inject custom repositories:
use Beecubu\Foundation\ApiRest\Core\Persistence\RepositoryProvider;
use Beecubu\Foundation\ApiRest\SQLite\Core\Persistence\UserDB;
use Beecubu\Foundation\ApiRest\SQLite\Core\Persistence\IPInfoCacheDB;
RepositoryProvider::set(UserDB::current(), IPInfoCacheDB::current());
2) Driver configuration
Each plugin has its own driver configuration:
MongoDB
- Configure the MongoDB connection (URI, database, etc).
- Review your project bootstrap where the connection is created.
SQLite
- Ensure the SQLite file is accessible and writable.
- The driver creates tables on demand.
3) User entities
To customize the user model, create a class that extends ApiUser (or User) and use it where needed.
Basic example:
use Beecubu\Foundation\ApiRest\Core\Entities\Users\ApiUser;
class MyApiUser extends ApiUser
{
// Add your own fields or logic
}
4) Session and authentication
Session endpoints work with ApiUser. The session controller resolves the user via the configured repository.
JWT + secure double-cookie Sessions are persisted as JWTs split across two cookies for extra safety:
- Cookie 1 stores the public part (
header.payload) and is readable by JS. - Cookie 2 stores the signature only and is
HttpOnly.
Both cookies are marked Secure in live mode, scoped to the current subdomain, and share the same expiry.
On each successful login or session refresh, a new JWT is generated and both cookies are updated.
If either cookie is missing or the JWT fails validation, the session is treated as invalid and no user is loaded.
Notes
- The core does not require any database.
- Repository implementations live-in plugins.
- The same API code can run on MongoDB or SQLite by swapping the plugin.