PHPackages                             zachleigh/yarak - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. zachleigh/yarak

AbandonedArchivedProject[Database &amp; ORM](/categories/database)

zachleigh/yarak
===============

Laravel inspired devtools for Phalcon. Database migrations, model factories and database seeders.

v1.2.0(8y ago)293.8k10MITPHP

Since Mar 3Pushed 7y ago5 watchersCompare

[ Source](https://github.com/zachleigh/yarak)[ Packagist](https://packagist.org/packages/zachleigh/yarak)[ Docs](https://github.com/zachlegih/yarak)[ RSS](/packages/zachleigh-yarak/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (9)Versions (21)Used By (0)

Yarak
=====

[](#yarak)

[![Latest Stable Version](https://camo.githubusercontent.com/9a3c5d754ae6b743e69342387a22f3d386ca3118a1de3d622e3ba3d3a6538359/68747470733a2f2f706f7365722e707567782e6f72672f7a6163686c656967682f796172616b2f762f737461626c65)](https://packagist.org/packages/zachleigh/yarak)[![License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](//packagist.org/packages/zachleigh/yarak)[![Build Status](https://camo.githubusercontent.com/e1948d2e3eb10e996fe112b18b7ee47cf4c32c80582d64d22e88f9c82e376adb/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7a6163686c656967682f796172616b2f6d61737465722e737667)](https://travis-ci.org/zachleigh/yarak)[![Quality Score](https://camo.githubusercontent.com/cb88333de12362ab372af51359d846c0e3aabb6caadc9a011450d2a47a18ccb2/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7a6163686c656967682f796172616b2e737667)](https://scrutinizer-ci.com/g/zachleigh/yarak/)[![StyleCI](https://camo.githubusercontent.com/a3fb0bffc63a6a69fb10f3067c93db24975ac8046abd9d5821c4bf0165238d30/68747470733a2f2f7374796c6563692e696f2f7265706f732f38333732353238392f736869656c643f7374796c653d666c6174)](https://styleci.io/repos/83725289)

*yarak - (Falconry) a state of prime fitness in a falcon*

#### Laravel inspired Phalcon devtools

[](#laravel-inspired-phalcon-devtools)

- Database migrations that rollback step-by-step, reset the database, and refresh the database.
- Model factories for easy test data creation.
- Database seeders that fill your database with a single command.
- Create custom commands in minutes to streamline and personalize your workflow.

Contents
--------

[](#contents)

- [Release Notes](#release-notes)
- [Install](#install)
- [Database](#database)
    - [Generating Database Directories And Files](#generating-database-directories-and-files)
    - [Model Factories](#model-factories)
        - [Defining Factories](#defining-factories)
        - [Using The Factory Helper](#using-the-factory-helper)
        - [Making Multiple Model Instances](#making-multiple-model-instances)
        - [Overriding The Default Attributes](#overriding-the-default-attributes)
        - [Using Named Factories](#using-named-factories)
        - [Model Relationships](#model-relationships)
    - [Database Seeding](#database-seeding)
        - [Creating Database Seeders](#creating-database-seeders)
        - [Writing Database Seeders](#writing-database-seeders)
        - [Using Database Seeders](#using-database-seeders)
- [Migrations](#migrations)
    - [Generating Migrations](#generating-migrations)
    - [Writing Migrations](#writing-migrations)
        - [Creating Tables](#creating-tables)
        - [Updating Tables](#updating-tables)
        - [The Down Method](#the-down-method)
    - [Running Migrations](#running-migrations)
    - [Rolling Back Migrations](#rolling-back-migrations)
    - [Resetting The Database](#resetting-the-database)
    - [Refreshing The Database](#refreshing-the-database)
- [Custom Commands](#custom-commands)
    - [Generating Console Directories And Files](#generating-console-directories-and-files)
    - [Generating Custom Commands](#generating-custom-commands)
    - [Writing Custom Commands](#writing-custom-commands)
        - [Command Signature](#command-signature)
            - [Defining Command Arguments](#defining-command-arguments)
            - [Defining Command Options](#defining-command-options)
            - [Accessing Command Arguments And Options](#accessing-command-arguments-and-options)
        - [Command Output](#command-output)
    - [Using Custom Commands](#using-custom-commands)
- [Calling Yarak In Code](#calling-yarak-in-code)
- [Developing](#developing)
- [Credits and Contributing](#credits-and-contributing)

Release Notes
-------------

[](#release-notes)

##### Moving from 1.1.\* to 1.2.\*

[](#moving-from-11-to-12)

The core command wrapper has been extracted to a separate package ([zachleigh/artisanize](https://github.com/zachleigh/artisanize)). Where possible, Yarak classes have been maintained for the time being in order to minimize update issues. However, some interface type declarations may need to be updated after isntalling the new version.

Install
-------

[](#install)

### Requirements

[](#requirements)

This package assumes you have the following:

- Phalcon &gt;= 3.0
- PHP &gt;= 5.6.5

### Install via composer

[](#install-via-composer)

```
composer require zachleigh/yarak

```

### Register the service

[](#register-the-service)

```
use Yarak\Kernel;

$di->setShared('yarak',function () {
    return new Kernel();
});
```

Yarak requires the following config values in this structure:

```
'database' => [
    'adapter'     => '',
    'host'        => '',
    'username'    => '',
    'password'    => '',
    'dbname'      => '',
    'charset'     => '',
],
'application' => [
    'appDir'         => APP_PATH.'/',
    'commandsDir'    => APP_PATH.'/console/commands',
    'consoleDir'     => APP_PATH.'/console/',
    'databaseDir'    => APP_PATH.'/database/',
    'migrationsDir'  => APP_PATH.'/database/migrations/',
    'modelsDir'      => APP_PATH.'/models/',
],
'namespaces' => [
    'root' => '',
],
```

Yarak uses your application's config so if your config is already structured this way, simply add the necessary values. If your config strategy differs from this, you have several options. First, you can create a specific Yarak config key and set all values there:

```
'yarak' => [
    'database' => [
        'adapter'     => '',
        'host'        => '',
        'username'    => '',
        'password'    => '',
        'dbname'      => '',
        'charset'     => '',
    ],
    'application' => [
        'appDir'         => APP_PATH.'/',
        'commandsDir'    => APP_PATH.'/console/commands',
        'consoleDir'     => APP_PATH.'/console/',
        'databaseDir'    => APP_PATH.'/database/',
        'migrationsDir'  => APP_PATH.'/database/migrations/',
        'modelsDir'      => APP_PATH.'/models/',
    ],
    'namespaces' => [
        'root' => '',
    ],
]
```

Then, when registering the service pass the config path:

```
$di->setShared('yarak',function () {
    return new Kernel('yarak');
});
```

If the config path is multiple levels deep, use dot notation:

```
'services' => [
    'yarak' => [
        'database' => [
            'adapter'     => '',
            'host'        => '',
            'username'    => '',
            'password'    => '',
            'dbname'      => '',
            'charset'     => '',
        ],
        'application' => [
            'appDir'         => APP_PATH.'/',
            'commandsDir'    => APP_PATH.'/console/commands',
            'consoleDir'     => APP_PATH.'/console/',
            'databaseDir'    => APP_PATH.'/database/',
            'migrationsDir'  => APP_PATH.'/database/migrations/',
            'modelsDir'      => APP_PATH.'/models/',
        ],
        'namespaces' => [
            'root' => '',
        ],
    ]
]
```

```
$di->setShared('yarak',function () {
    return new Kernel('services.yarak');
});
```

If you wish to add config values when registering Yarak, pass them as an array and Yarak will merge them into your existing config:

```
$di->setShared('yarak',function () {
    return new Kernel([
        'namespaces' => [
            'root' => '',
        ],
    ]);
});
```

Lastly, you can pass all config values when registering the service. Pass 'false' as the second parameter to the Kernel constructor to turn off config merging.

```
$di->setShared('yarak',function () {
    return new Kernel([
        'database' => [
            'adapter'     => '',
            'host'        => '',
            'username'    => '',
            'password'    => '',
            'dbname'      => '',
            'charset'     => '',
        ],
        'application' => [
            'appDir'         => APP_PATH.'/',
            'commandsDir'    => APP_PATH.'/console/commands',
            'consoleDir'     => APP_PATH.'/console/',
            'databaseDir'    => APP_PATH.'/database/',
            'migrationsDir'  => APP_PATH.'/database/migrations/',
            'modelsDir'      => APP_PATH.'/models/',
        ],
        'namespaces' => [
            'root' => '',
        ],
    ], false);
});
```

### Create a yarak file

[](#create-a-yarak-file)

In the project root, create a file called `yarak`. This file needs to do the following:

- Autoload all project files and vendor directory files
- Load the project services
- Resolve the Yarak kernel from the service container and call the `handle` method on it

Example:

```
#!/usr/bin/env php
