1. Go to this page and download the library: Download zachleigh/yarak 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/ */
zachleigh / yarak example snippets
use Yarak\Kernel;
$di->setShared('yarak',function () {
return new Kernel();
});
#!/usr/bin/env php
use Phalcon\Di\FactoryDefault;
error_reporting(E_ALL);
define('BASE_PATH', __DIR__);
define('APP_PATH', BASE_PATH . '/app');
/*
|--------------------------------------------------------------------------
| Autoload The Application
|--------------------------------------------------------------------------
|
| In order to work properly, Yarak will need both your project files and the
| vendor folder to be autoloaded.
|
*/
-------------
| Handle The Incoming Commands
|--------------------------------------------------------------------------
|
| We'll get the Yarak kernel from the dependency injector and defer to it for
| command handling.
|
*/
$kernel = $di->getYarak();
$kernel->handle();
public function define($class, callable $attributes, $name = 'default')
use App\Models\Users;
$factory->define(Users::class, function (Faker\Generator $faker) {
return [
'username' => $faker->userName,
'email' => $faker->unique()->safeEmail,
'password' => 'password',
];
});
use App\Models\Users;
$factory->define(Users::class, function (Faker\Generator $faker) use ($factory) {
return [
'username' => $faker->userName,
'email' => $faker->unique()->safeEmail,
'password' => $factory->security->hash('password'),
];
});
use App\Models\Users;
$user = factory(Users::class)->make();
use App\Models\Users;
$user = factory(Users::class)->create();
use App\Models\Users;
// Make three users
$users = factory(Users::class, 3)->make();
// Create three users
$users = factory(Users::class, 3)->create();
use App\Models\Users;
// Make a user with username 'bobsmith' and email '[email protected]'
$user = factory(Users::class)->make([
'username' => 'bobsmith',
'email' => '[email protected]'
]);
// Create a user with username 'bobsmith' and email '[email protected]'
$user = factory(Users::class)->create([
'username' => 'bobsmith',
'email' => '[email protected]'
]);
use App\Models\Users;
// Make a user using the factory named 'myUser'
factory(Users::class, 'myUser')->make()
// Create a user using the factory named 'myUser'
factory(Users::class, 'myUser')->create()
use App\Models\Users;
// Make three users using the factory named 'myUser'
$users = factory(Users::class, 'myUser', 3)->make();
// Create three users using the factory named 'myUser'
$users = factory(Users::class, 'myUser', 3)->creates();
use App\Models\Posts;
use App\Models\Users;
$factory->define(Users::class, function (Faker\Generator $faker) use ($factory) {
return [
'username' => $faker->userName,
'email' => $faker->unique()->safeEmail,
'password' => $factory->security->hash('password'),
];
});
$factory->define(Posts::class, function (Faker\Generator $faker) {
return [
'title' => $faker->unique()->sentence(4, true),
'body' => $faker->paragraph(4, true),
];
});
use App\Models\Posts;
use App\Models\Users;
$users = factory(Users::class, 3)->create();
foreach ($users as $user) {
factory(Posts::class)->create([
'users_id' => $user->id
]);
}
use App\Models\Posts;
use App\Models\Users;
$users = factory(Users::class, 3)->create();
foreach ($users as $user) {
factory(Posts::class, 3)->create([
'users_id' => $user->id
]);
}
use App\Models\Posts;
use App\Models\Users;
$factory->define(Users::class, function (Faker\Generator $faker) use ($factory) {
return [
'username' => $faker->userName,
'email' => $faker->unique()->safeEmail,
'password' => $factory->security->hash('password'),
];
});
$factory->define(Posts::class, function (Faker\Generator $faker) {
return [
'title' => $faker->unique()->sentence(4, true),
'body' => $faker->paragraph(4, true),
'users_id' => function () {
return factory(Users::class)->create()->id;
}
];
}, 'withUser');
use App\Models\Posts;
factory(Posts::class, 'withUser', 20)->create();
use App\Models\Users;
use Yarak\DB\Seeders\Seeder;
class UsersTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
factory(Users::class, 5)->create();
}
}
use App\Models\Posts;
use App\Models\Users;
use Yarak\DB\Seeders\Seeder;
class PostsTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$allUsers = Users::find();
foreach ($allUsers as $user) {
factory(Posts::class, 5)->create(['users_id' => $user->getId()]);
}
}
}
use Yarak\DB\Seeders\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$this->call(UsersTableSeeder::class);
$this->call(PostsTableSeeder::class);
}
}
public createTable (mixed $tableName, mixed $schemaName, array $definition)
use Phalcon\Db\Index;
use Phalcon\Db\Column;
//
public function up(Pdo $connection)
{
$connection->createTable(
'users',
null,
[
'columns' => [
new Column('id', [
'type' => Column::TYPE_INTEGER,
'size' => 10,
'unsigned' => true,
'notNull' => true,
'autoIncrement' => true
]),
new Column('username', [
'type' => Column::TYPE_VARCHAR,
'size' => 32,
'notNull' => true
]),
new Column('password', [
'type' => Column::TYPE_CHAR,
'size' => 40,
'notNull' => true
]),
new Column('email', [
'type' => Column::TYPE_VARCHAR,
'size' => 20,
'notNull' => true
]),
new Column('created_at', [
'type' => Column::TYPE_TIMESTAMP,
'notNull' => true,
'default' => 'CURRENT_TIMESTAMP'
])
],
'indexes' => [
new Index('PRIMARY', ['id'], 'PRIMARY'),
new Index('users_username_unique', ['username'], 'UNIQUE'),
new Index('users_email_unique', ['email'], 'UNIQUE')
]
]
);
}
public modifyColumn (mixed $tableName, mixed $schemaName, Phalcon\Db\ColumnInterface $column, [Phalcon\Db\ColumnInterface $currentColumn])
public function up(Pdo $connection)
{
$connection->modifyColumn(
'users',
null,
new Column(
'email',
[
'type' => Column::TYPE_VARCHAR,
'size' => 70,
]
)
);
}
public addColumn (mixed $tableName, mixed $schemaName, Phalcon\Db\ColumnInterface $column)
public function up(Pdo $connection)
{
$connection->addColumn(
'users',
null,
new Column(
'active',
[
'type' => Column::TYPE_CHAR,
'size' => 1,
'notNull' => true,
]
)
);
}
public function down(Pdo $connection)
{
$connection->dropTable('users');
}
public function down(Pdo $connection)
{
$connection->modifyColumn(
'users',
null,
new Column(
'email',
[
'type' => Column::TYPE_VARCHAR,
'size' => 20,
]
)
);
}
public function down(Pdo $connection)
{
$connection->dropColumn('users', null, 'active');
}
if ($this->confirm('Do you wish to continue? ')) {
//
}
$name = $this->ask('What is your name?', 'Nobody');
$password = $this->askPassword('Please type the password');
$car = $this->choose('What is your favourite car?', ['Ferrari', 'Lamborghini', 'Maserati'], 1);
$food = $this->anticipate('What is your favourite food?', ['Pizza', 'Pasta', 'Lasagna'], 'Mozzarella');
$colors = $this->choice('What are your favourite colors (defaults to blue and red)?', ['Blue', 'Red', 'Green'], '0,1');
protected function handle()
{
$this->output->write('Message'); // plain text
$this->output->writeInfo('Message'); // green text
$this->output->writeError('Message'); // red text
$this->output->writeComment('Message'); // yellow text
}
protected function handle()
{
$output = $this->getOutputInterface(); // $output is instance of Symfony\Component\Console\Output\OutputInterface
}
use Yarak\Console\ConsoleKernel;
use App\Console\Commands\ExampleCommand;
use App\Comsone\Commands\YourCustomCommand;
class Kernel extends ConsoleKernel
{
/**
* Your custom Yarak commands.
*
* @var array
*/
protected $commands = [
ExampleCommand::class,
YourCustomCommand::class
];
}
public static function call($command, array $arguments = [], \Phalcon\DiInterface $di = null)
use Yarak\Yarak;
Yarak::call('migrate:rollback', [
'--steps' => 2,
]);
use Yarak\Yarak;
Yarak::call('migrate:rollback', [
'--steps' => 2,
], $di);