PHPFlip is a standard project architecture. It requires PHP 7.1.
This project (will) comes with standard routing, such as:
- Authentication and Registration
POST /auth/login
(acquire a token for authorization)GET /auth/user
(see current authorized user)POST /auth/forgot
(sending email to reset a password) [WIP]POST /auth/logout
(purge a token, the purged token will be unusable)POST /auth/register/user
(register new user)
- Account Management [WIP]
GET /account
(see detail of account)POST /account
(update an account)POST /account/password
(change password for an account)
- User Management
GET /users
(get user list)POST /users
(create new user)GET /users/{id}
(get a user detail)POST /users/{id}
(update a user)DELETE /users/{id}
(delete a user)
- Core (root of everything)
- Managers
- OrderManager.php
- Entities (Contains class that representate the business logic)
- OrderEntity.php
- UserEntity.php
- Contracts
- Repositories (Connection manager, interact with databases)
- UserRepository.php
- Models
- User.php (Database representation, like DAO or POPO)
- Token.php
- Infrastructures (Mailer, Logger, etc)
- Repositories (Connection manager, interact with databases)
- Validators
- Validator.php
- Rules
- Auth
- LoginRules.php
- ForgotRules.php
- Auth
- Util (Don't touch, unless you know how to defeat a dragon)
- Presenters
- XML.php
- JSON.php
- Protobuf.php
- Presenters
- PubSub
- Emitter.php
- Publishers (It could be grouped per module if needed)
- UserIsNotOnline.php
- Users
- UserHasBeenCreated.php (naming should be as detail as possible)
- UserLostTheirPassword.php
- Orders
- OrderHasBeenMade.php
- Subscribers
- SendToEmail.php
- Transformer
- Transformer.php
- Autobots
- UserAutobot.php
- Managers
PHPFlip has a rigid rules about how to adding new components.
[Documentation WIP]
[Documentation WIP]
[Documentation WIP]
[Documentation WIP]
Here's what you need to do if you want to add new feature:
- You need to create
Manager
. Manager is responsible to managing resource, it has many "hands" to handle it's responsibilities. These "hands" are injected to the manager via service locator. You also needs to create these "hands" too. These "hands" may includes:Repository
Model
Autobot
(Business)Entity
(Validator)Rules
(Event)Emitter
(Optional)Publisher
Subscriber
- After you make a
Manager
. You have to make aRepository
. ARepository
is a class that responsible to interact with database (getting records or persisting records).- Inside
Repository
, there's aModel
.Model
is a class that representates a database record. It's like a Plain Ol' file. You may add some extra contract to define some useful methods.- A
Model
has it's ownAutobot
.Autobot
is a file that responsible to convert a database record to a rigid structure that will be used for application response.
- A
- Inside
- Another class you need to make is an
Entity
.Entity
is a class that contains business logic such as calculation method, creation method, or something else. - You may need a
Rules
after then. Just like it's name,Rules
is responsible to validate any operation, it only contains rulesets that any operation should pass before it can continue. - You can make it more "separated" by making a event-driven class. Just make a
Publisher
(a class that defines an event name) that has one or manySubscriber(s)
(a class that triggered when an event happens). You have to trigger aPublisher
(viaEmitter
), then anySubscriber(s)
that listen to thatPublisher
will triggered based on it's priority.
- TESTING IS IMPORTANT. Make sure you make a test case inside
core-tests
folder. Don't forget to full run unit-test, so you will notice if you make a breaking-changes when making a new feature. - Lastly, you need to fixing you code style to meet our specification. See Code Fixing section below.
composer install
# we assume you have configured your .env file
php artisan migrate --seed
composer global remove 'phpunit/phpunit' -vvv
composer global require 'phpunit/phpunit:^5.0' -vvv
# to test all suites
phpunit
# or via composer
composer run-script test
# or simply
composer test
################################################################################
# or for testing specific core package
phpunit --testsuite Core
# similay like above but via composer
composer run-script test-core
# or simply
composer test-core
################################################################################
# or for testing application
phpunit --testsuite App
# similay like above but via composer
composer run-script test-app
# or simply
composer test-app
composer global require friendsofphp/php-cs-fixer -vvv
# in root folder of this project
composer run-script fix
# or simply
composer fix