Skip to content

Commit

Permalink
Copied docs into repo
Browse files Browse the repository at this point in the history
  • Loading branch information
TomHAnderson committed Oct 29, 2024
1 parent 638e5da commit 2240a9b
Show file tree
Hide file tree
Showing 16 changed files with 1,027 additions and 0 deletions.
113 changes: 113 additions & 0 deletions docs/blameable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Blameable

Blameable behavior will automate the update of username or user reference fields on your Entities or Documents. It works through annotations and can update fields on creation, update, property subset update, or even on specific property value change.

* Automatic predefined user field update on creation, update, property subset update, and even on record property changes
* Specific annotations for properties, and no interface required
* Can react to specific property or relation changes to specific value
* Can be nested with other behaviors
* Annotation, Yaml and Xml mapping support for extensions

### Installation

Add `LaravelDoctrine\Extensions\Blameable\BlameableExtension` to `doctrine.extensions` config.

### Property annotation

> @Gedmo\Mapping\Annotation\Blameable
This annotation tells that this column is blameable
by default it updates this column on update. If column is not a string field or an association
it will trigger an exception.

Available configuration options:

| Annotations | Description |
|--|--|
| **on** |is main option and can be **create, update, change** this tells when it should be updated|
| **field** | only valid if **on="change"** is specified, tracks property or a list of properties for changes |
| **value** | only valid if **on="change"** is specified and the tracked field is a single field (not an array), if the tracked field has this **value** then it updates the blame |

Column is a string field:

``` php
<?php

namespace App\Entities;

use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*/
class Article
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
protected $id;

/**
* @ORM\Column(type="string", length=128)
*/
protected $title;

/**
* @ORM\Column(name="body", type="string")
*/
protected $body;

/**
* @var string $createdBy
*
* @Gedmo\Blameable(on="create")
* @ORM\Column(type="string")
*/
protected $createdBy;

/**
* @var string $updatedBy
*
* @Gedmo\Blameable(on="update")
* @ORM\Column(type="string")
*/
protected $updatedBy;

/**
* @var string $contentChangedBy
*
* @ORM\Column(name="content_changed_by", type="string", nullable=true)
* @Gedmo\Blameable(on="change", field={"title", "body"})
*/
protected $contentChangedBy;
}
```

Column is an association:

```php
<?php

namespace App\Entities;

use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*/
class Article
{
/**
* @Gedmo\Blameable(on="create")
* @ORM\ManyToOne(targetEntity="App\Entities\User")
* @ORM\JoinColumn(name="created_by", referencedColumnName="id")
*/
protected $createdBy;
}
```

For full documentation see [here.](https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/blameable.md)
74 changes: 74 additions & 0 deletions docs/custom-functions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Custom datetime functions

A set of extensions to Doctrine 2 that add support for additional queryfunctions available in MySQL and Oracle.

When `LaravelDoctrine\Extensions\BeberleiExtensionsServiceProvider::class` the following functions will be automatically registered.

| DB | Functions |
|--|---------|
| MySQL | `ACOS, ASCII, ASIN, ATAN, ATAN2, BINARY, CEIL, CHAR_LENGTH, CONCAT_WS, COS, COT, COUNTIF, CRC32, DATE, DATE_FORMAT, DATEADD, DATEDIFF, DATESUB, DAY, DAYNAME, DEGREES, FIELD, FIND_IN_SET, FLOOR, FROM_UNIXTIME, GROUP_CONCAT, HOUR, IFELSE, IFNULL, LAST_DAY, MATCH_AGAINST, MD5, MINUTE, MONTH, MONTHNAME, NULLIF, PI, POWER, QUARTER, RADIANS, RAND, REGEXP, REPLACE, ROUND, SECOND, SHA1, SHA2, SIN, SOUNDEX, STD, STRTODATE, SUBSTRING_INDEX, TAN, TIME, TIMESTAMPADD, TIMESTAMPDIFF, UUID_SHORT, WEEK, WEEKDAY, YEAR` |
| Oracle | `DAY, MONTH, NVL, TODATE, TRUNC, YEAR` |
| Sqlite | `DATE, MINUTE, HOUR, DAY, WEEK, WEEKDAY, MONTH, YEAR, STRFTIME*` |

Alternativly you can include the separate classes inside `config/doctrine` config file. Example:

```
<?php
return [
// rest of config file
/*
|--------------------------------------------------------------------------
| Doctrine custom types
|--------------------------------------------------------------------------
*/
'custom_types' => [
'carbondate' => DoctrineExtensions\Types\CarbonDateType::class,
'carbondatetime' => DoctrineExtensions\Types\CarbonDateTimeType::class,
'carbondatetimetz' => DoctrineExtensions\Types\CarbonDateTimeTzType::class,
'carbontime' => DoctrineExtensions\Types\CarbonTimeType::class
],
/*
|--------------------------------------------------------------------------
| Doctrine custom datetime functions
|--------------------------------------------------------------------------
*/
'custom_datetime_functions' => [
'DATEADD' => DoctrineExtensions\Query\Mysql\DateAdd::class,
'DATEDIFF' => DoctrineExtensions\Query\Mysql\DateDiff::class
],
/*
|--------------------------------------------------------------------------
| Doctrine custom numeric functions
|--------------------------------------------------------------------------
*/
'custom_numeric_functions' => [
'ACOS' => DoctrineExtensions\Query\Mysql\Acos::class,
'ASIN' => DoctrineExtensions\Query\Mysql\Asin::class,
'ATAN' => DoctrineExtensions\Query\Mysql\Atan::class,
'ATAN2' => DoctrineExtensions\Query\Mysql\Atan2::class,
'COS' => DoctrineExtensions\Query\Mysql\Cos::class,
'COT' => DoctrineExtensions\Query\Mysql\Cot::class,
'DEGREES' => DoctrineExtensions\Query\Mysql\Degrees::class,
'RADIANS' => DoctrineExtensions\Query\Mysql\Radians::class,
'SIN' => DoctrineExtensions\Query\Mysql\Sin::class,
'TAN' => DoctrineExtensions\Query\Mysql\Ta::class
],
/*
|--------------------------------------------------------------------------
| Doctrine custom string functions
|--------------------------------------------------------------------------
*/
'custom_string_functions' => [
'CHAR_LENGTH' => DoctrineExtensions\Query\Mysql\CharLength::class,
'CONCAT_WS' => DoctrineExtensions\Query\Mysql\ConcatWs::class,
'FIELD' => DoctrineExtensions\Query\Mysql\Field::class,
'FIND_IN_SET' => DoctrineExtensions\Query\Mysql\FindInSet::class,
'REPLACE' => DoctrineExtensions\Query\Mysql\Replace::class,
'SOUNDEX' => DoctrineExtensions\Query\Mysql\Soundex::class,
'STR_TO_DATE' => DoctrineExtensions\Query\Mysql\StrToDate::class
],
];
19 changes: 19 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- Prologue
- [Introduction](/docs/{{version}}/extensions/introduction)
- [Upgrade Guide](/docs/{{version}}/extensions/upgrade)
- Setup
- [Laravel](/docs/{{version}}/extensions/installation)
- [Lumen](/docs/{{version}}/extensions/lumen)
- Behavioral extensions
- [Blameable](/docs/{{version}}/extensions/blameable)
- [IpTraceable](/docs/{{version}}/extensions/iptraceable)
- [Loggable](/docs/{{version}}/extensions/loggable)
- [Sluggable](/docs/{{version}}/extensions/sluggable)
- [SoftDeletes](/docs/{{version}}/extensions/softdeletes)
- [Sortable](/docs/{{version}}/extensions/sortable)
- [Timestamps](/docs/{{version}}/extensions/timestamps)
- [Translatable](/docs/{{version}}/extensions/translatable)
- [Tree](/docs/{{version}}/extensions/tree)
- [Uploadable](/docs/{{version}}/extensions/uploadable)
- Query/Type extensions
- [Custom functions](/docs/{{version}}/extensions/custom-functions)
38 changes: 38 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Installation in Laravel 6+

Install this package with composer:

```
composer require laravel-doctrine/extensions
```

This package wraps extensions from [Gedmo](https://github.com/Atlantic18/DoctrineExtensions) and [Beberlei](https://github.com/beberlei/DoctrineExtensions).

To include Gedmo extensions install them:

```
composer require "gedmo/doctrine-extensions=^3.0"
```

If you are using an **annotation driver**, then add the Gedmo (Behavioral) extensions service provider in `config/app.php`:

```php
LaravelDoctrine\Extensions\GedmoExtensionsServiceProvider::class,
```

Also be sure to enable the extensions in the `extensions` section of `config/doctrine.php`.

To include Beberlei (Query/Type) extensions install them:

```
composer require "beberlei/DoctrineExtensions=^1.0"
```

And then add the Beberlei extensions service provider in `config/app.php`:


```php
LaravelDoctrine\Extensions\BeberleiExtensionsServiceProvider::class,
```
28 changes: 28 additions & 0 deletions docs/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Introduction

This package contains extensions for Doctrine2 that hook into the facilities of Doctrine and offer new functionality
or tools to use Doctrine2 more efficiently. This package contains mostly used behaviors which can be easily attached to your event system
of Doctrine2 and handle the records being flushed in the behavioral way

### Behavioral extensions (Gedmo)

* __Blameable__ - updates string or reference fields on create, update and even property change with a string or object (e.g. user).
* __IpTraceable__ - inherited from Timestampable, sets IP address instead of timestamp
* __Loggable__ - helps tracking changes and history of objects, also supports version management.
* __Sluggable__ - urlizes your specified fields into single unique slug
* __SoftDeleteable__ - allows to implicitly remove records
* __Sortable__ - makes any document or entity sortable
* __Timestampable__ - updates date fields on create, update and even property change.
* __Translatable__ - gives you a very handy solution for translating records into different languages. Easy to setup, easier to use.
* __Tree__ - this extension automates the tree handling process and adds some tree specific functions on repository. (closure, nestedset or materialized path)
* __Uploadable__ - provides file upload handling in entity fields

### Query/Type extensions (Beberlei)

A set of extensions to Doctrine 2 that add support for additional queryfunctions available in MySQL and Oracle.

| DB | Functions |
|--|---------|
| MySQL | `ACOS, ASCII, ASIN, ATAN, ATAN2, BINARY, CEIL, CHAR_LENGTH, CONCAT_WS, COS, COT, COUNTIF, CRC32, DATE, DATE_FORMAT, DATEADD, DATEDIFF, DATESUB, DAY, DAYNAME, DEGREES, FIELD, FIND_IN_SET, FLOOR, FROM_UNIXTIME, GROUP_CONCAT, HOUR, IFELSE, IFNULL, LAST_DAY, MATCH_AGAINST, MD5, MINUTE, MONTH, MONTHNAME, NULLIF, PI, POWER, QUARTER, RADIANS, RAND, REGEXP, REPLACE, ROUND, SECOND, SHA1, SHA2, SIN, SOUNDEX, STD, STRTODATE, SUBSTRING_INDEX, TAN, TIME, TIMESTAMPADD, TIMESTAMPDIFF, UUID_SHORT, WEEK, WEEKDAY, YEAR` |
| Oracle | `DAY, MONTH, NVL, TODATE, TRUNC, YEAR` |
| Sqlite | `DATE, MINUTE, HOUR, DAY, WEEK, WEEKDAY, MONTH, YEAR, STRFTIME*` |
86 changes: 86 additions & 0 deletions docs/iptraceable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Ip Traceable

IpTraceable behavior will automate the update of IP trace on your Entities or Documents. It works through annotations and can update fields on creation, update, property subset update, or even on specific property value change.

* Automatic predefined ip field update on creation, update, property subset update, and even on record property changes
* Specific annotations for properties, and no interface required
* Can react to specific property or relation changes to specific value
* Can be nested with other behaviors
* Annotation, Yaml and Xml mapping support for extensions

### Installation

Add `LaravelDoctrine\Extensions\IpTraceable\IpTraceableExtension` to `doctrine.extensions` config.

### Property annotation

> @Gedmo\Mapping\Annotation\IpTraceable
This annotation tells that this column is ipTraceable by default it updates this column on update. If column is not a string field it will trigger an exception.

Available configuration options:

| Annotations | Description |
|--|--|
| **on** |is main option and can be **create, update, change** this tells when itshould be updated|
| **field** | only valid if **on="change"** is specified, tracks property or a list of properties for changes |
| **value** | only valid if **on="change"** is specified and the tracked field is a single field (not an array), if the tracked field has this **value**then it updates the trace |

``` php
<?php
namespace Entity;

use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*/
class Article
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
protected $id;

/**
* @ORM\Column(type="string", length=128)
*/
protected $title;

/**
* @ORM\Column(name="body", type="string")
*/
protected $body;

/**
* @var string $createdFromIp
*
* @Gedmo\IpTraceable(on="create")
* @ORM\Column(type="string", length=45, nullable=true)
*/
protected $createdFromIp;

/**
* @var string $updatedFromIp
*
* @Gedmo\IpTraceable(on="update")
* @ORM\Column(type="string", length=45, nullable=true)
*/
protected $updatedFromIp;

/**
* @var datetime $contentChangedFromIp
*
* @ORM\Column(name="content_changed_by", type="string", nullable=true, length=45)
* @Gedmo\IpTraceable(on="change", field={"title", "body"})
*/
protected $contentChangedFromIp;
}
```

A `LaravelDoctrine\Extensions\IpTraceable\IpTraceable` trait was included which set's the IP on *create* and *update*

For full documentation see [here.](https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/ip_traceable.md)
Loading

0 comments on commit 2240a9b

Please sign in to comment.