Skip to content

Commit

Permalink
Merge af774e1 into 086a41d
Browse files Browse the repository at this point in the history
  • Loading branch information
tflori committed Sep 8, 2019
2 parents 086a41d + af774e1 commit f653394
Show file tree
Hide file tree
Showing 27 changed files with 6,812 additions and 2,998 deletions.
2 changes: 1 addition & 1 deletion docs/_reference/index.md.twig
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ permalink: /reference.html

---

{% for node in project.indexes.classes.merge(project.indexes.interfaces)|sort %}
{% for node in project.indexes.classes.merge(project.indexes.interfaces)|sort_asc %}
{% include 'class.md.twig' %}
{% endfor %}
2 changes: 1 addition & 1 deletion docs/_reference/method.md.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#### {{ node.FullyQualifiedStructuralElementName|trim('\\') }}::{{ method.name }}

```php?start_inline=true
```php
{{ method.getSignature(80)|replace({'<mixed,': '<'})|raw }}
```

Expand Down
6 changes: 3 additions & 3 deletions docs/bulkInserts.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The advantage of this solution is that you don't have to change existing code bu
have a complete primary key they would still cause a select before they get added to bulk insert. If your entities don't
have a primary key yet (for example auto incremented rows) this method is perfectly fine for you:

```php?start_inline=true
```php
$em = ORM\EntityManager::getInstance(Recipient::class);
$em->useBulkInserts(Recipient::class, 50);

Expand Down Expand Up @@ -50,7 +50,7 @@ for this entity type gets created and inserts for this type are redirected to th
The `BulkInsert` has several options that also can be used with the other method (`EntityManager::useBulkInserts()`
returns the `BulkInsert` object):

```php?start_inline=true
```php
$em = ORM\EntityManager::getInstance(Recipient::class);
$bulkInsert = new ORM\BulkInsert($em->getDbal(), Recipient::class, 50);
$bulkInsert->limit(20); // change the limit afterwards
Expand All @@ -75,7 +75,7 @@ $recipients = $bulkInsert->finish();

The option setter return the bulk insert object and can be chained what makes it easier for setup:

```php?start_inline=true
```php
$em = ORM\EntityManager::getInstance(Recipient::class);
$bulkInsert = $em->useBulkInserts(Recipient::class)->noUpdates();
// add the entities
Expand Down
10 changes: 5 additions & 5 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ when it is required.
A project without dependency injection, different databases, database cluster or anything else can just use configure
with the parameters from `DbConfig`. Or create a `DbConfig` and pass it.

```php?start_inline=true
```php
use ORM\EntityManager;

$entitymanager = new EntityManager([
Expand All @@ -37,7 +37,7 @@ $entitymanager = new EntityManager([

If you are using dependency injection you can pass a function that has to return a `PDO` instance.

```php?start_inline=true
```php
$diContainer = $GLOBALS['DI']; // sorry we don't know how you get your depenency injection container

$entityManager = new ORM\EntityManager([
Expand All @@ -56,7 +56,7 @@ $diContainer->set('entityManager', $entityManager);

You can define PDO attributes in `DbConfig`. We highly recommend two settings for mysql and we set them by default:

```php?start_inline=true
```php
[
// Change sql_mode to ANSI_QUOTES and communication to utf8 on connect
PDO::MYSQL_ATTR_INIT_COMMAND => "SET sql_mode ='ANSI_QUOTES', NAMES utf8",
Expand Down Expand Up @@ -125,7 +125,7 @@ is a subclass of this class. This is done due to `ReflectionClass::isSubclassOf(

If you have legacy tables that you don't want to migrate you may want to create an own `EntityManager` for it:

```php?start_inline=true
```php
use ORM\EntityManager;
use ORM\Entity;

Expand Down Expand Up @@ -158,7 +158,7 @@ The above example uses the last `EntityManager` for other classes. You might wan
defining the last `EntityManager` for the Namespace `App`. The parent matching has precedents so that the following
example will achieve the same:

```php?start_inline=true
```php
namespace App;

use ORM\EntityManager;
Expand Down
14 changes: 7 additions & 7 deletions docs/entities.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ One of the most important things for an ORM: how to fetch an object from databas
related objects? It should be easy what means it should not need much lines to get an entity by primary key or even by
different where conditions.

```php?start_inline=true
```php
/** @var \ORM\EntityManager $entityManager */
$entityManager = $diContainer->get('entityManager'); // or what ever

Expand Down Expand Up @@ -44,7 +44,7 @@ already. This means that fetching by query will always query the database.

Fetching by primary key is a shortcut for the first row:

```php?start_inline=true
```php
$entityManager->fetch(User::class)->where('id', 1)->one();
$entityManager->fetch(User::class, 1);
```
Expand Down Expand Up @@ -73,7 +73,7 @@ Every column is available by magic getter and using the column naming previously
entity definitions. All values are stored twice and you can check if a column got changed and reset the whole entity
or a part of the entity.

```php?start_inline=true
```php
$user = $entityManager->fetch(User::class, 1);
echo $user->email . PHP_EOL; // someone@example.com
var_dump($user->isDirty()); // false
Expand All @@ -95,7 +95,7 @@ setter will check if there is a method `setCreated($value)`<sup>*</sup> and will

The data is stored in protected property $data.

```php?start_inline=true
```php
class User extends ORM\Entity
{
/** @var DateTime */
Expand Down Expand Up @@ -139,7 +139,7 @@ are executed immediately.
The init event get a boolean that says whether the entity is new or not. A new entity is an entity that get created
by you without data or even with data. If you got the data from database add the second parameter to the constructor.

```php?start_inline=true
```php
class User extends ORM\Entity
{
public function onInit($new) {}
Expand All @@ -151,7 +151,7 @@ class User extends ORM\Entity
The change event get three parameters: the `$var` (string) that got changed, the `$oldValue` (mixed) and the current
`$value` (mixed).

```php?start_inline=true
```php
class User extends ORM\Entity
{
public function onChange($var, $oldValue, $value) {}
Expand All @@ -164,7 +164,7 @@ These events don't get any parameters. Because the pre update/persist events get
created you can modify the data here. The post update/persist get called very late, the id is now available and the own
data is resynchronized. You can persist other entities that are related - there is no magic that is doing it for you.

```php?start_inline=true
```php
class User extends ORM\Entity
{
public function prePersist() {}
Expand Down
18 changes: 9 additions & 9 deletions docs/entityDefinition.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ permalink: /entityDefinition.html

Nothing is required and everything should work out of the box. It is like using `PDO` alone.

```php?start_inline=true
```php
class User extends ORM\Entity {}

$user = $entityManager->fetch(User::class, 1);
Expand All @@ -33,7 +33,7 @@ This orm library also handles relations - for more information about configuring

The easiest way to define the table name is by adding the property `$tableName`.

```php?start_inline=true
```php
use ORM\Entity;

class User extends Entity
Expand All @@ -51,7 +51,7 @@ method in an abstract class.
The table name template can be configured in the `Namer` but you should better pass it to the options for the
EntityManager during initialization:

```php?start_inline=true
```php
// only short class name (without namespace; this is the default)
new ORM\EntityManager(['tableNameTemplate' => '%short%']);
namespace App\Models { class User extends \ORM\Entity {} }
Expand Down Expand Up @@ -89,7 +89,7 @@ naming scheme is `snake_lower` what means that your StudlyCaps class name `Custo
The name of a table can be obtained by the public static method `getTableName()`. You can overwrite this function if you
need to or have a different logic to get your table name.

```php?start_inline=true
```php
namespace App\Model;

abstract class Entity extends \ORM\Entity {
Expand All @@ -113,7 +113,7 @@ getters and setters for each property. It's up to you.
Column names follow the naming scheme for columns defined for the EntityManager. You can also define a prefix per
entity. When you use prefixes than the prefix have to be in the correct naming scheme for columns.

```php?start_inline=true
```php
/**
* @property int id
* @property string username
Expand All @@ -133,7 +133,7 @@ User::getColumnName('usrUsername'); // usr_usr_username

You can also provide column aliases:

```php?start_inline=true
```php
/**
* @property foo
* @property gender
Expand All @@ -157,7 +157,7 @@ if you need to or have a logic for your column prefixing.

**IMPORTANT: `getColumnName(getColumnName($name))` should always return the same as `getColumnName($name)`.**

```php?start_inline=true
```php
namespace App\Model;

abstract class Entity extends \ORM\Entity {
Expand All @@ -178,7 +178,7 @@ The identifier can also be non auto incremental (as it is automatically when it
a non auto incremental identifier you set the protected static property `$autoIncrement` to false. To save an entity the
primary key has to be filled.

```php?start_inline=true
```php
// Naming scheme: snake_lower

class A extends ORM\Entity {
Expand All @@ -203,7 +203,7 @@ A primary key can also be generated or fetched from a sequence just before `preP
protected method `generatePrimaryKey()`, implement `ORM\Entity\GeneratesPrimaryKeys` and generate your primary key
there:

```php?start_inline=true
```php
class Tree extends ORM\Entity implements ORM\Entity\GeneratesPrimaryKeys {
protected function generatePrimaryKey()
{
Expand Down

0 comments on commit f653394

Please sign in to comment.