PHP code example of gamernetwork / yolk-support
1. Go to this page and download the library: Download gamernetwork/yolk-support library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
gamernetwork / yolk-support example snippets
use yolk\support\collections\BaseCollection;
use yolk\support\collections\BaseDictionary;
use yolk\support\collections\BaseSet;
$c = new Collection([123, 456, 789]);
$c->count(); // returns 3
$c->contains(456); // returns true
$c->contains(234); // returns false
$c->isEmpty(); // returns false
$c->clear(); // remove all items
$c->isEmpty(); // returns true
$d = new BaseDictionary();
$d->add('foo', 123);
$d->add('bar', 456);
$d->has('foo'); // returns true
$d->has('baz'); // returns false
$d->get('foo'); // returns 123
$d->keys(); // returns ['foo', 'bar']
$d->remove('bar');
$d = new BaseSet();
$d->add('foo');
$d->add('bar');
$d->contains('foo'); // returns true
$d->remove('bar');
$d->contains('bar'); // returns false
use yolk\support\BaseConfig;
$c = new BaseConfig([
'foo' => [
'bar' => 123,
'baz' => 456,
],
]);
$c->get('foo.bar'); // returns 123
$c->set('foo.baz', 789); // changes the value of ['foo']['bar']
// overwrite the 'foo' branch and add an additional value for 'bar'
$c->merge([
'foo' => 'abc',
'bar' => 'def',
]);
$c->get('foo.bar'); // returns null (key doesn't exist)
$c->get('bar'); // returns 'def'
$c->load(__DIR__. 'config.php'); // 'config.php' should create an array called $config
use yolk\support\Field;
$f = new Field('id', Type::INTEGER);
$f = new Field('email', Type::EMAIL, ['', 'OTHER']
]
);
use yolk\contracts\support\Error;
use yolk\support\Field;
$f = new Field('id', Type::INTEGER, ['rns 0
$f->validate(0); // returns [0, Error::REQUIRED]
$f->validate(false); // returns [false, Error::REQUIRED]
$f->validate('123fgh'); // returns [123, Error::NONE]
$f->validate('fghsdfs'); // returns ['fghsdfs', Error::TYPE]
$f->validate(-123); // returns [-123, Error::MIN]
use yolk\support\Fieldset;
$f = new Fieldset();
$f->add($name, $type = Type::TEXT, $rules = []);
use yolk\contracts\support\Error;
use yolk\support\Fieldset;
$f = new Fieldset();
$f->add('id', Type::INTEGER);
$f->add('email', Type::EMAIL, ['
'email' => Error::EMAIL,
],
]