yfix

Yf framework development blog

[forms] render with templates

Posted by yfix on 2016-05-26
Posted in: yf. Leave a comment

Lately I have added ability to render forms using STPL template.

This requirement came from the need of complete different styling of forms, its elements and positions according to design and UI.

More examples can be seen in live docs here:
https://yfix.net/docs/demo/form%2Fstpl
https://yfix.net/docs/demo/form%2Fstpl_and_array
https://yfix.net/docs/demo/form%2Freturn_array

[tests] news: phpunit and codeception updates plus tests inside plugins

Posted by yfix on 2015-11-04
Posted in: yf. Leave a comment

1). From now on tests can be stored inside plugins under subfolder “tests”, for example:

“yf/plugins/my_plugin/tests/unit/my_plugin1.Test.php” – unit test
“yf/plugins/my_plugin/tests/acceptance/my_plugin.Cept.php” – codeception acceptance test

To run tests you should use scripts from folder: “yf/.dev/tests/bin/”
———–
Real examples from github repository:

https://github.com/yfix/yf/blob/master/.dev/tests/bin/codecept_run_all.sh

#!/bin/bash
(command -v codecept > /dev/null && cd ../ && codecept run)

https://github.com/yfix/yf/blob/master/.dev/tests/bin/codecept_run_all_separately.sh

#!/bin/bash
(
cd ../
for f in $(find ./acceptance -type f -name '*Cept.php'); do
	echo $f;
	codecept run acceptance $f;
done
for f in $(find ./functional -type f -name '*Cest.php'); do
	echo $f;
	codecept run functional $f;
done
for f in $(find ./unit -type f -name '*.Test.php'); do
	echo $f;
	codecept run unit $f;
done

https://github.com/yfix/yf/blob/master/.dev/tests/bin/phpunit_run_all.sh

#!/bin/bash
(command -v phpunit > /dev/null && cd ../ && phpunit -d memory_limit=1024M ./)

https://github.com/yfix/yf/blob/master/plugins/test/tests/unit/class_test_plugin.Test.php

<?php
!defined('YF_PATH') && define('YF_PATH', '/home/www/yf/');
require_once YF_PATH.'.dev/tests/yf_unit_tests_setup.php';
class class_test_plugin_test extends yf_unit_tests {
	public function test1() {
		$this->assertTrue(true);
	}
}

https://github.com/yfix/yf/blob/master/plugins/test/tests/acceptance/html5fw_bs3_Cept.php

<?php 
$I = new AcceptanceTester($scenario);
$I->wantTo('ensure that html5 bootstrap3 works');
$I->amOnPage('/test/html5fw_bs3');
$I->see('text');

———–

2). Also latest travis-ci yf setup consists of checking php files syntax based on utility “php-parallel-lint”.

Usually 1600 framework php sources are checked in 7-8 seconds!

https://github.com/yfix/yf/blob/master/.dev/tests/bin/php_parallel_lint_all.sh

#!/bin/bash
# composer global require jakub-onderka/php-parallel-lint
DIR=$( cd $( dirname "${BASH_SOURCE[0]}" ) && pwd )
(
	cd ../../../;
	binary="parallel-lint"
	if [[ -f "$TRAVIS_BUILD_DIR/vendor/bin/$binary" ]]; then
		binary=$TRAVIS_BUILD_DIR"/vendor/bin/"$binary;
	elif [[ -f "$DIR/vendor/bin/$binary" ]]; then
		binary=$DIR"/vendor/bin/"$binary;
	fi
	$binary -e php --exclude libs --exclude vendor .
)

———–

3). Also, now YF core is fully compatible with upcoming PHP 7.0 branch, which is confirmed using unit tests, for example of travis-ci with nightly php build:
https://travis-ci.org/yfix/yf/jobs/88802913
Latest YF builds here:
https://travis-ci.org/yfix/yf

4). All YF unit tests now should inherit from class yf_unit_tests, currently stored here:

https://github.com/yfix/yf/blob/master/.dev/tests/yf_unit_tests_setup_shared.php

<?php
define('APP_PATH', __DIR__.'/_tmp/');
define('STORAGE_PATH', __DIR__.'/_tmp/');
$_SERVER['HTTP_HOST'] = 'test.dev';
if (!defined('YF_PATH')) {
	$CONF['cache']['DRIVER'] = 'tmp';
	$CONF['cache']['NO_CACHE'] = true;
	define('YF_IN_UNIT_TESTS', true);
	define('YF_PATH', dirname(dirname(__DIR__)).'/');
	require YF_PATH.'classes/yf_main.class.php';
	new yf_main($MAIN_TYPE ?: 'user', $no_db_connect = 1, $auto_init_all = 0, $CONF);
	date_default_timezone_set('Europe/Kiev');
	ini_set('display_errors', 'on');
	error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED ^ E_STRICT);
}
abstract class yf_unit_tests extends PHPUnit_Framework_TestCase {
	protected $backupGlobals = false;
	protected $backupStaticAttributes = false;
	protected $runTestInSeparateProcess = false;
	protected $preserveGlobalState = false;
	protected $inIsolation = false;
}

[new feature] html simple_table

Posted by yfix on 2015-04-16
Posted in: core, docs, new feature, php, yf. Tagged: html, new feature, yf. Leave a comment

Just added new widget into html() with name “simple_table”.
Aim of this widget – display key=value data in pretty way with minimal frictions.

More cocs here:
http://yfix.net/docs/html/simple_table

Sample of usage:
https://github.com/yfix/yf/blob/master/.dev/samples/classes/test_html.class.php#L99

[new feature] table now supports query builder object as sql input

Posted by yfix on 2015-02-20
Posted in: new feature, yf. Tagged: core, new feature, table, yf. Leave a comment

Example:


table(db()->from('user')->where('active','1'))
  ->text('name')
  ->text('email')
  ->btn_edit()
  ->btn_delete()
;

yf framework assets usage

Posted by yfix on 2015-01-15
Posted in: yf. Leave a comment

———-
from tpl:
———-

{asset()} flipclock {/asset}
{jquery()}
  $('body').flipclock(function(){
})
{/jquery}

———-
from php
———-

asset('flipclock')
jquery('
  $("body").flipclock(function(){
})
');

bootlint chrome extension

Posted by yfix on 2015-01-15
Posted in: yf. Leave a comment

http://articles.runtings.co.uk/p/bootlint-this-page-chrome.html

useful feature: placeholder image

Posted by yfix on 2014-12-28
Posted in: new feature, php, yf. Tagged: yf. Leave a comment

I want to share new built-in feature from yf framework:
It allows to easily display placeholder image with desired dimensions.

There are several methods to do this:
1. Calling url from any place will display image with width 200px and height 50px:
http://project.dev/dynamic/placeholder/200×50
2. From withing project php code calling helper method will return html “img” tag with data/image with width 200px and height 50px:
module(‘dynamic’)->placeholder_img(array(‘width’ => 200, ‘height’ => 50));

[howto] php autoload virtual model

Posted by yfix on 2014-10-30
Posted in: howto, php, trick. Tagged: autoload, howto, models, php, trick. Leave a comment


class model_test1 {
    public static function __callStatic($name, $args) {
        echo 'Hello from '.__CLASS__.'::'.__FUNCTION__.PHP_EOL;
    }
    public function __call($name, $args) {
        echo 'Hello from '.__CLASS__.'->'.__FUNCTION__.PHP_EOL;
    }
}

spl_autoload_register(function ($class) {
    if (class_exists($class)) {
        return true;
    }
    $try_model = 'model_'.$class;
    if (class_exists($try_model)) {
        eval('class '.$class.' extends '.$try_model.'{};');
        return true;
    }
});

// Existing class call
$ts = microtime();

model_test1::hello();
$model_test1 = new model_test1();
$model_test1->hello();

echo round(microtime() - $ts, 5).PHP_EOL;

// Virtual class call
$ts = microtime();

test1::hello();
$test1 = new test1();
$test1->hello();

echo round(microtime() - $ts, 5).PHP_EOL;

https://github.com/yfix/yf/blob/master/.dev/samples/autoload_virtual_model.php

[new feature] db utils create_table improvements

Posted by yfix on 2014-10-30
Posted in: core, new feature, yf. Tagged: core, create table, db, new feature, yf. Leave a comment

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 feature] validation rules now supports multiple fields in rule key

Posted by yfix on 2014-10-30
Posted in: core, new feature, yf. Tagged: core, new feature, validation, yf. Leave a comment

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.

Posts navigation

← Older Entries
  • Tags

    admin autoload blocks command line config console core create table db debug elseforeach events foreach_exec functions hhvm howto html https if_func migrations models new feature pager php php5.6 rewrite solution table tests tip tpl trick url validation yf
  • Recent Posts

    • [forms] render with templates
    • [tests] news: phpunit and codeception updates plus tests inside plugins
    • [new feature] html simple_table
    • [new feature] table now supports query builder object as sql input
    • yf framework assets usage
  • Meta

    • Register
    • Log in
    • Entries feed
    • Comments feed
    • WordPress.com
  • Archives

    • May 2016
    • November 2015
    • April 2015
    • February 2015
    • January 2015
    • December 2014
    • October 2014
    • August 2014
    • July 2014
    • June 2014
  • Categories

    • core
    • docs
    • howto
    • new feature
    • php
    • tests
    • tpl
    • trick
    • Uncategorized
    • utils
    • yf
Blog at WordPress.com.
yfix
Blog at WordPress.com.
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
  • Follow Following
    • yfix
    • Already have a WordPress.com account? Log in now.
    • yfix
    • Customize
    • Follow Following
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar
 

Loading Comments...