Skip to content

Commit 24a6d19

Browse files
committed
Merge branch 'documentation'
2 parents 777a927 + bc16bf7 commit 24a6d19

File tree

5 files changed

+164
-2
lines changed

5 files changed

+164
-2
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Circular reference detect
33

44
[![Build Status](https://travis-ci.org/antalaron/circular-reference-detect.svg?branch=master)](https://travis-ci.org/antalaron/circular-reference-detect) [![Coverage Status](https://coveralls.io/repos/github/antalaron/circular-reference-detect/badge.svg)](https://coveralls.io/github/antalaron/circular-reference-detect?branch=master) [![Latest Stable Version](https://poser.pugx.org/antalaron/circular-reference-detect/v/stable)](https://packagist.org/packages/antalaron/circular-reference-detect) [![Latest Unstable Version](https://poser.pugx.org/antalaron/circular-reference-detect/v/unstable)](https://packagist.org/packages/antalaron/circular-reference-detect) [![License](https://poser.pugx.org/antalaron/circular-reference-detect/license)](https://packagist.org/packages/antalaron/circular-reference-detect)
55

6-
Library to detect reference circular references in array.
6+
PHP library to detect reference circular references in array.
77

88
Installation
99
------------
@@ -29,7 +29,6 @@ require __DIR__.'/vendor/autoload.php';
2929

3030
use Antalaron\Component\CircularReferenceDetect\CircularReferenceDetect;
3131
$a = [
32-
'*' => ['a'],
3332
'a' => ['b'],
3433
'b' => ['c'],
3534
'c' => ['a'],
@@ -38,6 +37,13 @@ $detector = new CircularReferenceDetect();
3837
$detector->hasCircularReference($a);
3938
```
4039

40+
Documentation
41+
-------------
42+
43+
1. [Installation](01-installation.md)
44+
2. [Usage](02-usage.md)
45+
3. [Contributing](03-contributing.md)
46+
4147
License
4248
-------
4349

docs/01-installation.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Installation
2+
============
3+
4+
Requirements
5+
------------
6+
7+
* PHP >= 5.5
8+
* (optional) PHPUnit to run tests.
9+
10+
Autoload
11+
--------
12+
13+
This command requires you to have Composer installed globally, as explained
14+
in the [installation chapter](https://getcomposer.org/doc/00-intro.md)
15+
of the Composer documentation.
16+
17+
Then run the following command to require the library:
18+
```bash
19+
$ composer require antalaron/circular-reference-detect
20+
```

docs/02-usage.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
Usage
2+
=====
3+
4+
Initialize the detector
5+
-----------------------
6+
7+
Simple initiate the class.
8+
9+
```php
10+
require __DIR__.'/vendor/autoload.php';
11+
12+
use Antalaron\Component\CircularReferenceDetect\CircularReferenceDetect;
13+
14+
$detector = new CircularReferenceDetect();
15+
```
16+
17+
Or if you prefer the singleton, use it.
18+
19+
```php
20+
require __DIR__.'/vendor/autoload.php';
21+
22+
use Antalaron\Component\CircularReferenceDetect\CircularReferenceDetect;
23+
24+
$detector = CircularReferenceDetect::newInstance();
25+
```
26+
27+
Check if circular reference exists
28+
----------------------------------
29+
30+
The `hasCircularReference()` returns the circle found first, or false, if there
31+
is no circle.
32+
33+
```php
34+
$a = [
35+
'a' => ['b'],
36+
'b' => ['c'],
37+
'c' => ['a'],
38+
];
39+
40+
$b = [
41+
'a' => ['b'],
42+
'b' => ['c'],
43+
];
44+
45+
(bool) $detector->hasCircularReference($a); // true
46+
$detector->hasCircularReference($a); // ['a', 'b', 'c', 'a']
47+
48+
(bool) $detector->hasCircularReference($b); // false
49+
```
50+
51+
Arguments of `hasCircularReference()`
52+
-------------------------------------
53+
54+
Basically the first argument is an array, with a key/value pair, where the value
55+
is an array, the elemnts of the value is referenced to the key.
56+
57+
```php
58+
$a = [
59+
'a' => ['b', 'd', 'e'],
60+
'b' => ['c', 'd'],
61+
'c' => ['a'],
62+
];
63+
64+
$detector->hasCircularReference($a);
65+
````
66+
67+
You can also search for specific references as starting points, if you pass the
68+
previous array az the second argument, and to the first argument an array of
69+
starting points. It won't find a circle, because from the point of view of the
70+
array `$b`, the circle cannot be reached.
71+
72+
```php
73+
$a = [
74+
'a' => ['b'],
75+
'b' => ['c'],
76+
'c' => ['a'],
77+
'd' => ['e'],
78+
'e' => ['f'],
79+
];
80+
$b = [
81+
'd',
82+
'e',
83+
];
84+
85+
$detector->hasCircularReference($b, $a); // false
86+
```
87+
88+
Options
89+
-------
90+
91+
There is a limit in the search (50), but you can set is with the first argument
92+
of the constructor, or with the `setMaxDepth()` method.
93+
94+
The greater circles will not be found. And by default, the return value will be
95+
false, unless shorter circle can be found.
96+
97+
You can configure that in case of out of limit the class throws an exception,
98+
so you can check that even if circle weas not found, but there is a possibility
99+
to one exists. Pass `true` to the second argument to the constructor, or
100+
call `setThrowExceptionOnReachMaxDepth(true)`.

docs/03-contributing.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Contributing
2+
============
3+
4+
Contributing is welcomed to this library.
5+
6+
Please, use the GitHub's [Issuies](https://github.com/antalaron/circular-reference-detect/issues)
7+
[Pull Request](https://github.com/antalaron/circular-reference-detect/pulls)
8+
feature to do that.
9+
10+
Coding standard
11+
---------------
12+
13+
This library uses the basic coding standard for PHP. Before the pull request,
14+
please test the code wit [php-cs-fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer).
15+
16+
Tests
17+
-----
18+
19+
If you create a feature, please add tests for that, to make sure, it is working.
20+
Please, keep the coverage above 90%.

docs/index.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Circular reference detect
2+
=========================
3+
4+
PHP library to detect reference circular references in array.
5+
6+
Table of contents
7+
-----------------
8+
9+
1. [Installation](01-installation.md)
10+
2. [Usage](02-usage.md)
11+
3. [Contributing](03-contributing.md)
12+
13+
License
14+
-------
15+
16+
This library is under [MIT License](http://opensource.org/licenses/mit-license.php).

0 commit comments

Comments
 (0)