-
-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathIdGenerator.php
83 lines (77 loc) · 3.11 KB
/
IdGenerator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\ODM\PHPCR\Id;
use Doctrine\ODM\PHPCR\DocumentManager;
use Doctrine\ODM\PHPCR\Mapping\ClassMetadata;
use Doctrine\ODM\PHPCR\Exception\InvalidArgumentException;
use Doctrine\ODM\PHPCR\Configuration;
use Doctrine\ODM\PHPCR\Id\FieldSlugifierIdGenerator;
/**
* Used to abstract ID generation
*
* @license http://www.opensource.org/licenses/MIT-license.php MIT license
* @link www.doctrine-project.com
* @since 1.0
* @author Benjamin Eberlei <[email protected]>
* @author Lukas Kahwe Smith <[email protected]>
*/
abstract class IdGenerator
{
/**
* Factory method for the predefined strategies.
*
* @param int $generatorType
*
* @return IdGenerator
*/
public static function create($generatorType, Configuration $config)
{
switch ($generatorType) {
case ClassMetadata::GENERATOR_TYPE_ASSIGNED:
$instance = new AssignedIdGenerator();
break;
case ClassMetadata::GENERATOR_TYPE_REPOSITORY:
$instance = new RepositoryIdGenerator();
break;
case ClassMetadata::GENERATOR_TYPE_PARENT:
$instance = new ParentIdGenerator();
break;
case ClassMetadata::GENERATOR_TYPE_AUTO:
$instance = new AutoIdGenerator();
break;
case ClassMetadata::GENERATOR_TYPE_FIELD_SLUGIFIER:
$instance = new FieldSlugifierIdGenerator($config->getSlugifier());
break;
default:
throw new InvalidArgumentException("ID Generator does not exist: $generatorType");
}
return $instance;
}
/**
* Generate the actual id, to be overwritten by extending classes
*
* @param object $document the object to create the id for
* @param ClassMetadata $class class metadata of this object
* @param DocumentManager $dm
* @param object $parent
*
* @return string the id for this document
*/
abstract public function generate($document, ClassMetadata $class, DocumentManager $dm, $parent = null);
}