Example:
table(db()->from('user')->where('active','1'))
->text('name')
->text('email')
->btn_edit()
->btn_delete()
;
Example:
table(db()->from('user')->where('active','1'))
->text('name')
->text('email')
->btn_edit()
->btn_delete()
;
Today I’ve added to db utils ability to create table similar to Laravel:
db()->utils()->create_table($name, function($table_helper) {
$table_helper
->small_int('actor_id', array('length' => 5, 'unsigned' => true, 'nullable' => false, 'auto_inc' => true))
->string('first_name', array('length' => 45, 'nullable' => false))
->string('last_name', array('length' => 45, 'nullable' => false))
->primary('actor_id')
->index('last_name', 'idx_actor_last_name')
->option('engine', 'InnoDB')
->option('charset', 'utf8')
;
});
Full list of supported column types as methods is here:
https://github.com/yfix/yf/blob/master/classes/db/yf_db_utils_helper_create_table.class.php
You can take look at the tests here:
https://github.com/yfix/yf/blob/master/.dev/tests/functional/db/class_db_real_utils_mysql.Test.php#L312
New useful feature done inside validation class – validation rules now supports multiple fields in rule key. This usually needed to set same rulesets for several fields to validate.
Example:
$rules = array(
'test1' => array('min_length:2', 'max_length:12'),
'test2,test3' => array('min_length:2', 'max_length:12'),
'test1,test2,test3 ' => array('is_unique:user.login|between:1,10|chars:a,b,c,d|regex:[a-z0-9]+'),
);
As usual, such new complex feature comes with unit tests:
https://github.com/yfix/yf/blob/master/.dev/tests/unit/class_validate.Test.php#L1189
Also, now spaces are trimmed in keys, as can be seen inside unit tests.
Recently I’ve completed YF db migrations functionality.
Source located here:
https://github.com/yfix/yf/blob/master/classes/db/yf_db_migrator.class.php
There are console helpers:
yf db:migrate compare
yf db:migrate generate
yf db:migrate create
yf db:migrate apply
yf db:migrate list
yf db:migrate dump
General commands:
* compare – will output differencies between current project db structure and expected php_sql db structure, stored in files inside framework and project. Computes differencies in:
tables, columns, indexes, foreign keys. Report about missing or new items and about changed items too.
* generate – will output internal migration commands, not writing anything to disk, useful to figure out how created migration can look like
* create – create new migration file into disk, based on compare result. Usually store file into APP_PATH/share/db/migrations/%new_migration_file%.php.
This method useful to store changes into database for future applying on other hosts.
* apply – apply selected migration into project database. Useful for applying database changes in controlled and repeatable manner.
* list – list available migrations to apply
* dump – dump current database structure into disk into sql_php files.
I’ve added function wildcard_compare($wildcard, $string) into YF framework, which uses php built-in fnmatch() function, which is fast and not using regexps.
There is support for these patterns:
“*” – no or any number of symbols
“?” – exactly one symbol
“[abc]” – one of symbols passed inside square brackets
YF function wildcard_compare() differs from native fnmatch(): it can accept array of wildcards and if any of them matched – then overall return true.
Examples:
wildcard_compare('regex are * useful', 'regex are always useful')
Function source:
https://github.com/yfix/yf/blob/master/share/functions/yf_common_funcs.php#L397
Unit tests (also examples):
https://github.com/yfix/yf/blob/master/.dev/tests/unit/functions/function_wildcard_compare.Test.php
From now on all unit tests are passing on all important and modern php branches:
* 5.3.x (last tested on 5.3.28)
* 5.4.x (last tested on 5.4.31)
* 5.5.x (last tested on 5.5.18)
* 5.6 (tested on 5.6.0RC3, but I’m sure nothing big will be changed in release)
* HHVM 3.2
Important note is that HHVM is really faster when running with common website.
I see about 50% of speedup gain on real YF-based project.
Useful links:
* YF travis-ci (5 php branches tested too): https://travis-ci.org/yfix/yf
* YF drone.io: https://drone.io/github.com/yfix/yf/latest
Say welcome to the new requested feature for templating engine: “foreach_exec”.
It is combination of the “foreach” iterator tag and “execute” class method calling tag.
It works by executing given argument as execute input and then iterates over result array.
As you can understand, called method should return array.
Aim of this tag is to leverage wrapping code amount and speed optimization to avoid
extra big arrays passing into templates by $replace array members.
Examples:
imagine result of the called method _class('unittest2')->_callme2 == array('k1' => 'v1', 'k2' => 'v2'); and now template code: {foreach_exec(unittest2,_callme2)} _{_key}={_val}_ {/foreach_exec} {foreach_exec(@object,_callme2)} _{_key}={_val}_ {/foreach_exec} {foreach_exec(unittest2,_callme2)} _{_key}={_val}_ {elseforeach} no rows {/foreach_exec}