davihu / phalcon-ext
Various extensions and utilities for Phalcon Framework
Installs: 8 971
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.0
Requires (Dev)
- codeception/codeception: ^2.1
README
Various extensions and utilities for Phalcon Framework
Pre-requisites
Installation
Using Composer
You can use the composer
package manager to install. Either run:
$ php composer.phar require davihu/phalcon-ext "^1.2"
or add:
"davihu/phalcon-ext": "^1.2"
to your composer.json file
Whats new?
Version 1.2
Added nested set support
Adds nested set support to your model. Simply use trait \PhalconExt\Mvc\Model\Traits\NestedSetTrait in your model.
Version 1.1
Added SQL database migrations support
Can be easily attached to your console application.
Supported commands:
php console.php migrations generate # generates new migration class
php console.php migrations migrate # migrates database to last version
php console.php migrations migrate 160910160944 # migrates database to selected version
php console.php migrations sql > migrate.sql # saves SQL statements for migration to last version to file migrate.sql
php console.php migrations sql 160910160944 > migrate.sql # saves SQL statements for migration to selected version to file migrate.sql
Set up in console bootstrap file:
-
Choose migrations directory
define('MIGRATIONS_DIR', '... your migrations dir ...');
-
Register dir to your loader
Without namespace usage
$loader->registerDirs([ ... , MIGRATIONS_DIR]);
With namespace usage
$loader->registerNamespaces([ ... , 'Your\\Namespace' => MIGRATIONS_DIR]);
- Register migrations service to DI
Without namespace usage
$di->set('migrations', function () {
return new \PhalconExt\Db\SqlMigrations($this->get('db'), MIGRATIONS_DIR);
}, true);
With namespace usage
$di->set('migrations', function () {
return new \PhalconExt\Db\SqlMigrations($this->get('db'), MIGRATIONS_DIR, 'Your\\Namespace');
}, true);
Writing migrations classes
use PhalconExt\Db\SqlMigrations\AbstractMigration;
class Migration160910160944 extends AbstractMigration
{
public function up()
{
# simple statements
$this->addSql("ALTER TABLE robots ADD COLUMN number VARCHAR(20)");
# routine statements like triggers, procedures and functions
$this->addSql("CREATE TRIGGER MyTrigger ...", true);
}
public function down()
{
$this->addSql("ALTER TABLE robots DROP COLUMN number");
$this->addSql("DROP TRIGGER MyTrigger");
}
}
Thats all, very simple but powerfull!
Contents
Db
- PhalconExt\Mvc\Db\SqlMigrations - Database migrations service directly via. SQL statements
- PhalconExt\Mvc\Db\SqlMigrations\AbstractMigration - Abstract SQL migration, all migrations must extend this class
Model
- PhalconExt\Mvc\Model\Traits\RateLimitAccessTrait - Adds access rate limit support to target model
- PhalconExt\Mvc\Model\Traits\RateLimitLoginTrait - Adds login rate limit support to target model
Validators
- PhalconExt\Validation\Validator\Color - Validates if value is valid color
- PhalconExt\Validation\Validator\EmailDomain - Validates email domain existence via DNS
- PhalconExt\Validation\Validator\PasswordRetype - Validates if password confirmation matches password
- PhalconExt\Validation\Validator\PasswordStrength - Validates password strength
- PhalconExt\Validation\Validator\StringLengthExact - Validates exact string length
License
Phalcon Ext is open-sourced software licensed under the New BSD License. © David Hübner