Download the PHP package popcorn4dinner/policies without Composer
On this page you can find all versions of the php package popcorn4dinner/policies. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download popcorn4dinner/policies
More information about popcorn4dinner/policies
Files in popcorn4dinner/policies
Package policies
Short Description easy to use, non-opinionated library to model complex rules for validations, access control, etc
License MIT
Informations about the package policies
- PHP Policies A PHP library to easily model complex rules or policies for validations, access control, etc
** installation
+BEGIN_SRC sh
composer require popcorn4dinner/policies
+END_SRC
** Example: Validating a user 1) define actions or events as an enum, here CREATE, REGISTER, UPDATE, DELETE and ADMIN_UPDATE 2) create one policy for each of your business rules 3) create a Validator to use your policies and define exceptions
* creating policies ** email address must have the right format
+BEGIN_SRC php :tangle ./examples/Policies/EmailFormatPolicy.php
+END_SRC
**** email address must be unique
+BEGIN_SRC php :tangle ./examples/Policies/EmailUniquenessPolicy.php
+END_SRC
**** password must be longer then 8 characters
+BEGIN_SRC php :tangle ./examples/Policies/PasswordLengthPolicy.php
+END_SRC
**** password must be secure enough
+BEGIN_SRC php :tangle ./examples/Policies/PasswordLengthPolicy.phpolicy.php
+END_SRC
*** creating a validator
+BEGIN_SRC php :tangle ./examples/UserValidatorFactory.php
+END_SRC
*** use PolicyCollections to model more complex rules
+BEGIN_SRC php
class UserValidatorFactory { /**
- @param UserRepositoryInterface $userRepository
-
@return UserValidator */ public function create(UserRepositoryInterface $userRepository) {
$userPolicies = new PolicyCollection( new PasswordLengthPolicy(UserAction::ADMIN_UPDATE()); new PasswordStrengthPolicy(UserAction::ADMIN_UPDATE()) ) $universalPolicies = new PolicyCollection( new EmailFormatPolicy(), new EmailUniquenessPolicy($userRepository) ) return new BasicValidator( $universalPolicies, $standardUserPolicies );
} }
+END_SRC