Skip to content
Snippets Groups Projects
reference.md 25.9 KiB
Newer Older
## API Reference


### Breyta

* [AbstractMigration](#breytaabstractmigration)
* [AdapterInterface](#breytaadapterinterface)
* [BasicAdapter](#breytabasicadapter)
* [CallbackProgress](#breytacallbackprogress)
Thomas Flori's avatar
Thomas Flori committed
* [Migrations](#breytamigrations)
* [ProgressInterface](#breytaprogressinterface)


### Breyta\Migration

* [CreateMigrationTable](#breytamigrationcreatemigrationtable)


### Breyta\Model

* [Migration](#breytamodelmigration)
* [Statement](#breytamodelstatement)


---

### Breyta\AdapterInterface



#### Interface AdapterInterface

You may want to define an adapter with additional helpers like creating tables etc. The only adapter provided in this
library is a BasicAdapter that just executes sql statements.






#### Methods

* [__construct](#breytaadapterinterface__construct) Adapter gets a callable $executor
* [exec](#breytaadapterinterfaceexec) Execute an sql statement

#### Breyta\AdapterInterface::__construct

```php
public function __construct( callable $executor ): AdapterInterface
```

##### Adapter gets a callable $executor

The executor requires a Breyta\Model\Statement argument and is the only way an adapter can interact with
the database.

**Visibility:** this method is **public**.
<br />


##### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `$executor` | **callable**  |  |



#### Breyta\AdapterInterface::exec

```php
public function exec( string $sql ): mixed
```

##### Execute an sql statement

Returns false on error and an integer of affected rows on success.

**Visibility:** this method is **public**.
<br />
 **Returns**: this method returns **mixed**
<br />

##### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `$sql` | **string**  |  |



**See Also:**

* http://php.net/manual/en/pdo.exec.php - for a details about the return statement


Thomas Flori's avatar
Thomas Flori committed
---

### Breyta\ProgressInterface











#### Methods

* [afterExecution](#breytaprogressinterfaceafterexecution) Output information about the $statement (after it gets executed)
* [afterMigration](#breytaprogressinterfaceaftermigration) Output information about the $migration (after the migration)
* [beforeExecution](#breytaprogressinterfacebeforeexecution) Output information about the $statement (before it gets executed)
* [beforeMigration](#breytaprogressinterfacebeforemigration) Output information about the $migration (before the migration)
* [finish](#breytaprogressinterfacefinish) Output information about what just happened
* [start](#breytaprogressinterfacestart) Output information about starting the migration process

#### Breyta\ProgressInterface::afterExecution

```php
public function afterExecution( \Breyta\Model\Statement $execution )
```

##### Output information about the $statement (after it gets executed)



**Visibility:** this method is **public**.
<br />


##### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `$execution` | **Model\Statement**  |  |



#### Breyta\ProgressInterface::afterMigration

```php
public function afterMigration( \Breyta\Model\Migration $migration )
```

##### Output information about the $migration (after the migration)



**Visibility:** this method is **public**.
<br />


##### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `$migration` | **Model\Migration**  |  |



#### Breyta\ProgressInterface::beforeExecution

```php
public function beforeExecution( \Breyta\Model\Statement $execution )
```

##### Output information about the $statement (before it gets executed)



**Visibility:** this method is **public**.
<br />


##### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `$execution` | **Model\Statement**  |  |



#### Breyta\ProgressInterface::beforeMigration

```php
public function beforeMigration( \Breyta\Model\Migration $migration )
```

##### Output information about the $migration (before the migration)



**Visibility:** this method is **public**.
<br />


##### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `$migration` | **Model\Migration**  |  |



#### Breyta\ProgressInterface::finish

```php
public function finish( \stdClass $info )
```

##### Output information about what just happened

Info contains:
 - `migrations` - an array of Breyta\Model\Migration
 - `task` - the task that is going to be executed (migrate or revert)
 - `count` - an integer how many migrations are going to be executed
 - `executed` - an array of migrations that just got executed

**Visibility:** this method is **public**.
<br />


##### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `$info` | **\stdClass**  |  |



#### Breyta\ProgressInterface::start

```php
public function start( \stdClass $info )
```

##### Output information about starting the migration process

Info contains:
 - `migrations` - an array of Breyta\Model\Migration
 - `task` - the task that is going to be executed (migrate or revert)
 - `count` - an integer how many migrations are going to be executed
 - `toExecute` - an array of migrations that are going to be executed

**Visibility:** this method is **public**.
<br />


##### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `$info` | **\stdClass**  |  |





---

### Breyta\Model\Migration









#### Properties

| Visibility | Name | Type | Description                           |
|------------|------|------|---------------------------------------|
| **public** | `$file` | **string** |  |
| **public** | `$executed` | ** \ DateTime** |  |
| **public** | `$reverted` | ** \ DateTime** |  |
| **public** | `$status` | **string** |  |
| **public** | `$statements` | **string &#124; array &#124; array&lt;Statement>** |  |
| **public** | `$executionTime` | **double** |  |



#### Methods

* [__construct](#breytamodelmigration__construct) 
* [createInstance](#breytamodelmigrationcreateinstance) 

#### Breyta\Model\Migration::__construct

```php
public function __construct(): Migration
```




**Visibility:** this method is **public**.
<br />




#### Breyta\Model\Migration::createInstance

```php
public static function createInstance( array $data = array() )
```




**Static:** this method is **static**.
<br />**Visibility:** this method is **public**.
<br />


##### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `$data` | **array**  |  |





---

Thomas Flori's avatar
Thomas Flori committed
### Breyta\Model\Statement
Thomas Flori's avatar
Thomas Flori committed
#### Properties

| Visibility | Name | Type | Description                           |
|------------|------|------|---------------------------------------|
| **public** | `$raw` | **string** |  |
| **public** | `$teaser` | **string** |  |
| **public** | `$action` | **string** |  |
| **public** | `$type` | **string** |  |
| **public** | `$name` | **string** |  |
| **public** | `$result` | **mixed** |  |
| **public** | `$executionTime` | **double** |  |
| **public** | `$exception` | ** \ PDOException** |  |

Thomas Flori's avatar
Thomas Flori committed
* [__toString](#breytamodelstatement__tostring) 
* [createInstance](#breytamodelstatementcreateinstance) 
Thomas Flori's avatar
Thomas Flori committed
#### Breyta\Model\Statement::__toString
Thomas Flori's avatar
Thomas Flori committed
public function __toString()
```




**Visibility:** this method is **public**.
<br />


Thomas Flori's avatar
Thomas Flori committed


#### Breyta\Model\Statement::createInstance

```php
public static function createInstance( array $data = array() )
```




**Static:** this method is **static**.
<br />**Visibility:** this method is **public**.
<br />


##### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
Thomas Flori's avatar
Thomas Flori committed
| `$data` | **array**  |  |





---

### Breyta\Migrations
Thomas Flori's avatar
Thomas Flori committed

The migration engine that puts all parts together.



#### Constants

| Name | Value |
|------|-------|
| INTERNAL_PREFIX | `'@breyta/'` |


#### Properties

| Visibility | Name | Type | Description                           |
|------------|------|------|---------------------------------------|
| **public static** | `$table` | **string** | The name of the migration table |
| **public static** | `$templatePath` | **string** | The path to the template for migrations |
| **protected** | `$db` | ** \ PDO** |  |
| **protected** | `$path` | **string** |  |
| **protected** | `$migrations` | **array &#124; array&lt;Model \ Migration>** |  |
| **protected** | `$missingMigrations` | **array &#124; array&lt;Model \ Migration>** |  |
| **protected** | `$statements` | **array &#124; array&lt;Model \ Statement>** |  |
| **protected** | `$adapter` | **AdapterInterface** |  |
| **protected** | `$resolver` | **callable** |  |
| **protected** | `$progress` | **ProgressInterface** |  |



#### Methods

* [__construct](#breytamigrations__construct) 
* [createMigration](#breytamigrationscreatemigration) Creates a migration
* [down](#breytamigrationsdown) Revert specific migrations
* [executeStatement](#breytamigrationsexecutestatement) 
* [findMigrations](#breytamigrationsfindmigrations) 
* [getAdapter](#breytamigrationsgetadapter) 
* [getProgress](#breytamigrationsgetprogress) 
* [getStatus](#breytamigrationsgetstatus) Returns the status of the migrations
* [internalClass](#breytamigrationsinternalclass) 
* [isInternal](#breytamigrationsisinternal) 
* [loadMigrations](#breytamigrationsloadmigrations) 
* [migrate](#breytamigrationsmigrate) Migrate all migrations that are not migrated yet
* [migrateTo](#breytamigrationsmigrateto) Migrate all migrations to a specific migration or date time
* [revert](#breytamigrationsrevert) Revert all migrations that have been migrated
* [revertTo](#breytamigrationsrevertto) Revert all migrations to a specific migration or date time
* [saveMigration](#breytamigrationssavemigration) 
* [setProgress](#breytamigrationssetprogress) 
* [up](#breytamigrationsup) Migrate specific migrations

#### Breyta\Migrations::__construct
Thomas Flori's avatar
Thomas Flori committed
public function __construct(
    \PDO $db, \Breyta\string $path, callable $resolver = null, 
    \Breyta\ProgressInterface $progress = null
): Migrations
```




**Visibility:** this method is **public**.
<br />


##### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
Thomas Flori's avatar
Thomas Flori committed
| `$db` | **\PDO**  |  |
| `$path` | **string**  |  |
| `$resolver` | **callable**  |  |
| `$progress` | **ProgressInterface**  |  |
Thomas Flori's avatar
Thomas Flori committed
#### Breyta\Migrations::createMigration
Thomas Flori's avatar
Thomas Flori committed
public function createMigration( string $name ): boolean
Thomas Flori's avatar
Thomas Flori committed
##### Creates a migration

We recommend StudlyCase naming for PSR2 compatibility. Also the files will get a namespace.

**Visibility:** this method is **public**.
<br />
 **Returns**: this method returns **boolean**
<br />

##### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `$name` | **string**  |  |



#### Breyta\Migrations::down

```php
public function down( \Breyta\Model\Migration $migrations ): boolean
```

##### Revert specific migrations



**Visibility:** this method is **public**.
Thomas Flori's avatar
Thomas Flori committed
<br />
 **Returns**: this method returns **boolean**
<br />

##### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `$migrations` | **Model\Migration**  |  |



#### Breyta\Migrations::executeStatement

```php
protected function executeStatement( \Breyta\Model\Statement $statement )
```




**Visibility:** this method is **protected**.
<br />


##### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
Thomas Flori's avatar
Thomas Flori committed
| `$statement` | **Model\Statement**  |  |
Thomas Flori's avatar
Thomas Flori committed
#### Breyta\Migrations::findMigrations
Thomas Flori's avatar
Thomas Flori committed
protected function findMigrations()
Thomas Flori's avatar
Thomas Flori committed
**Visibility:** this method is **protected**.
<br />




#### Breyta\Migrations::getAdapter

```php
protected function getAdapter()
```




**Visibility:** this method is **protected**.
<br />




#### Breyta\Migrations::getProgress

```php
public function getProgress()
```




**Visibility:** this method is **public**.
<br />




#### Breyta\Migrations::getStatus

```php
public function getStatus(): \stdClass
```

##### Returns the status of the migrations

It contains an array of all migrations, the count of migrations that are not migrated yet and an array of
migrations that got removed (if files where removed).

**Visibility:** this method is **public**.
Thomas Flori's avatar
Thomas Flori committed
<br />
 **Returns**: this method returns **\stdClass**
<br />



#### Breyta\Migrations::internalClass

```php
protected static function internalClass( \Breyta\string $file )
```




**Static:** this method is **static**.
<br />**Visibility:** this method is **protected**.
<br />


##### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
Thomas Flori's avatar
Thomas Flori committed
| `$file` | **string**  |  |
Thomas Flori's avatar
Thomas Flori committed
#### Breyta\Migrations::isInternal
Thomas Flori's avatar
Thomas Flori committed
protected static function isInternal( \Breyta\string $file )
Thomas Flori's avatar
Thomas Flori committed

**Static:** this method is **static**.
<br />**Visibility:** this method is **protected**.
<br />


##### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
Thomas Flori's avatar
Thomas Flori committed
| `$file` | **string**  |  |
Thomas Flori's avatar
Thomas Flori committed
#### Breyta\Migrations::loadMigrations
Thomas Flori's avatar
Thomas Flori committed
protected function loadMigrations()
Thomas Flori's avatar
Thomas Flori committed


**Visibility:** this method is **protected**.
<br />




#### Breyta\Migrations::migrate

```php
public function migrate(): boolean
```

##### Migrate all migrations that are not migrated yet



**Visibility:** this method is **public**.
<br />
Thomas Flori's avatar
Thomas Flori committed
 **Returns**: this method returns **boolean**
<br />



#### Breyta\Migrations::migrateTo

```php
public function migrateTo( string $file ): boolean
```

##### Migrate all migrations to a specific migration or date time
Thomas Flori's avatar
Thomas Flori committed
$file can either be a relative file name (or a portion matched with `strpos()`) or a date time string to execute
all migrations to that time.

**Visibility:** this method is **public**.
<br />
 **Returns**: this method returns **boolean**
<br />

##### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
Thomas Flori's avatar
Thomas Flori committed
| `$file` | **string**  |  |
Thomas Flori's avatar
Thomas Flori committed
#### Breyta\Migrations::revert
Thomas Flori's avatar
Thomas Flori committed
```php
public function revert(): boolean
```
Thomas Flori's avatar
Thomas Flori committed
##### Revert all migrations that have been migrated
Thomas Flori's avatar
Thomas Flori committed
**Visibility:** this method is **public**.
<br />
 **Returns**: this method returns **boolean**
<br />
Thomas Flori's avatar
Thomas Flori committed
#### Breyta\Migrations::revertTo
Thomas Flori's avatar
Thomas Flori committed
```php
public function revertTo( string $file ): boolean
```
Thomas Flori's avatar
Thomas Flori committed
##### Revert all migrations to a specific migration or date time
Thomas Flori's avatar
Thomas Flori committed
$file can either be a relative file name (or a portion matched with `strpos()`) or a date time string to execute
all migrations to that time.
Thomas Flori's avatar
Thomas Flori committed
**Note:** This will not revert the migration matched the pattern. It is resetting to the state of the database
to the state when <file> was executed.
Thomas Flori's avatar
Thomas Flori committed
**Visibility:** this method is **public**.
<br />
 **Returns**: this method returns **boolean**
<br />
Thomas Flori's avatar
Thomas Flori committed
##### Parameters
Thomas Flori's avatar
Thomas Flori committed
| Parameter | Type | Description |
|-----------|------|-------------|
| `$file` | **string**  |  |
Thomas Flori's avatar
Thomas Flori committed
#### Breyta\Migrations::saveMigration
Thomas Flori's avatar
Thomas Flori committed
protected function saveMigration(
    \Breyta\Model\Migration $migration, $status, $executionTime
)
Thomas Flori's avatar
Thomas Flori committed
**Visibility:** this method is **protected**.
Thomas Flori's avatar
Thomas Flori committed
##### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `$migration` | **Model\Migration**  |  |
| `$status` |   |  |
| `$executionTime` |   |  |

Thomas Flori's avatar
Thomas Flori committed
#### Breyta\Migrations::setProgress
Thomas Flori's avatar
Thomas Flori committed
public function setProgress( \Breyta\ProgressInterface $progress )
Thomas Flori's avatar
Thomas Flori committed
**Visibility:** this method is **public**.
<br />


##### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
Thomas Flori's avatar
Thomas Flori committed
| `$progress` | **ProgressInterface**  |  |



#### Breyta\Migrations::up

```php
public function up( \Breyta\Model\Migration $migrations ): boolean
```

##### Migrate specific migrations



**Visibility:** this method is **public**.
<br />
 **Returns**: this method returns **boolean**
<br />

##### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `$migrations` | **Model\Migration**  |  |





---

### Breyta\AbstractMigration









#### Properties

| Visibility | Name | Type | Description                           |
|------------|------|------|---------------------------------------|
| **private** | `$adapter` |  |  |



#### Methods

* [__call](#breytaabstractmigration__call) 
* [__construct](#breytaabstractmigration__construct) 
* [down](#breytaabstractmigrationdown) Bring the migration down
* [up](#breytaabstractmigrationup) Bring the migration up

#### Breyta\AbstractMigration::__call

```php
public function __call( $method, $args )
```




**Visibility:** this method is **public**.
<br />


##### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `$method` |   |  |
| `$args` |   |  |



#### Breyta\AbstractMigration::__construct

```php
public function __construct(
    \Breyta\AdapterInterface $adapter
): AbstractMigration
```




**Visibility:** this method is **public**.
<br />


##### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `$adapter` | **AdapterInterface**  |  |



#### Breyta\AbstractMigration::down

```php
abstract public function down()
```

##### Bring the migration down



**Visibility:** this method is **public**.
<br />




#### Breyta\AbstractMigration::up

```php
abstract public function up()
```

##### Bring the migration up



**Visibility:** this method is **public**.
<br />






---

### Breyta\CallbackProgress


**Implements:** [Breyta\ProgressInterface](#breytaprogressinterface)


Stores callbacks for migration progress.




#### Properties

| Visibility | Name | Type | Description                           |
|------------|------|------|---------------------------------------|
| **protected** | `$startCallback` | **callable** |  |
| **protected** | `$beforeMigrationCallback` | **callable** |  |
| **protected** | `$beforeExecutionCallback` | **callable** |  |
| **protected** | `$afterExecutionCallback` | **callable** |  |
| **protected** | `$afterMigrationCallback` | **callable** |  |
| **protected** | `$finishCallback` | **callable** |  |



#### Methods

* [afterExecution](#breytacallbackprogressafterexecution) Output information about the $statement (after it gets executed)
* [afterMigration](#breytacallbackprogressaftermigration) Output information about the $migration (after the migration)
* [beforeExecution](#breytacallbackprogressbeforeexecution) Output information about the $statement (before it gets executed)
* [beforeMigration](#breytacallbackprogressbeforemigration) Output information about the $migration (before the migration)
* [finish](#breytacallbackprogressfinish) Output information about what just happened
* [onAfterExecution](#breytacallbackprogressonafterexecution) 
* [onAfterMigration](#breytacallbackprogressonaftermigration) 
* [onBeforeExecution](#breytacallbackprogressonbeforeexecution) 
* [onBeforeMigration](#breytacallbackprogressonbeforemigration) 
* [onFinish](#breytacallbackprogressonfinish) 
* [onStart](#breytacallbackprogressonstart) 
* [start](#breytacallbackprogressstart) Output information about starting the migration process

#### Breyta\CallbackProgress::afterExecution

```php
public function afterExecution( \Breyta\Model\Statement $execution )
```

##### Output information about the $statement (after it gets executed)



**Visibility:** this method is **public**.
<br />


##### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `$execution` | **Model\Statement**  |  |



#### Breyta\CallbackProgress::afterMigration