Skip to content

Commit 3b98b74

Browse files
committed
Merge pull request symfony#8 from dunglas/symfony
Major refactoring to prepare the Symfony merge
2 parents d5f336d + 65e1dde commit 3b98b74

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1579
-1766
lines changed

.php_cs

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,10 @@
11
<?php
22

3-
$header = <<<EOF
4-
(c) Kévin Dunglas <dunglas@gmail.com>
5-
6-
This source file is subject to the MIT license that is bundled
7-
with this source code in the file LICENSE.
8-
EOF;
9-
10-
Symfony\CS\Fixer\Contrib\HeaderCommentFixer::setHeader($header);
11-
12-
$finder = Symfony\CS\Finder\DefaultFinder::create()
13-
->notName('Php7Data.php')
14-
->in(array(__DIR__))
15-
;
16-
173
return Symfony\CS\Config\Config::create()
18-
->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL)
19-
->fixers(array(
20-
'-psr0',
21-
'header_comment',
22-
'newline_after_open_tag',
23-
'ordered_use',
24-
'short_array_syntax',
25-
))
4+
->setUsingLinter(false)
265
->setUsingCache(true)
27-
->finder($finder)
6+
->finder(
7+
Symfony\CS\Finder\DefaultFinder::create()
8+
->in(__DIR__)
9+
)
2810
;

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ cache:
77
- $HOME/.composer/cache
88

99
php:
10+
- 5.3
1011
- 5.4
1112
- 5.5
1213
- 5.6
@@ -22,7 +23,7 @@ matrix:
2223
include:
2324
- php: 5.6
2425
env: CS_FIXER=run
25-
- php: 5.4
26+
- php: 5.3
2627
env: COMPOSER_FLAGS="--prefer-lowest"
2728
allow_failures:
2829
- php: nightly
@@ -38,4 +39,4 @@ before_script:
3839

3940
script:
4041
- if [ "$CS_FIXER" = "run" ]; then php-cs-fixer fix --verbose --dry-run ; fi;
41-
- vendor/bin/phpunit
42+
- phpunit

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,4 @@ Try it yourself using [Melody](http://melody.sensiolabs.org/):
149149

150150
## Credits
151151

152-
This library has been created by [Kévin Dunglas](http://dunglas.fr).
152+
This library has been created by [Kévin Dunglas](https://dunglas.fr).

composer.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"validator",
1111
"doctrine"
1212
],
13-
"homepage": "http://dunglas.fr",
13+
"homepage": "https://dunglas.fr",
1414
"license": "MIT",
1515
"authors": [
1616
{
@@ -24,19 +24,20 @@
2424
}
2525
},
2626
"require": {
27-
"php": ">=5.4"
27+
"php": ">=5.3"
2828
},
2929
"require-dev": {
30-
"phpunit/phpunit": "~4.5",
30+
"symfony/phpunit-bridge": "~2.7",
31+
"symfony/serializer": "~2.7",
3132
"doctrine/orm": "~2.3",
3233
"phpdocumentor/reflection": "~1.0"
3334
},
3435
"conflict": {
35-
"phpdocumentor/reflection": "<1.0.4"
36+
"phpdocumentor/reflection": "<1.0.7"
3637
},
3738
"suggest": {
39+
"symfony/serializer": "To use Serializer metadata",
3840
"doctrine/orm": "To use Doctrine metadata",
39-
"symfony/validator": "To use Symfony validator metadata",
4041
"phpdocumentor/reflection": "To use the PHPDoc"
4142
}
4243
}

phpunit.xml.dist

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
1-
<phpunit
2-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/3.7/phpunit.xsd"
4-
bootstrap="vendor/autoload.php">
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
5+
backupGlobals="false"
6+
colors="true"
7+
bootstrap="vendor/autoload.php"
8+
>
9+
<php>
10+
<ini name="error_reporting" value="-1" />
11+
</php>
512

613
<testsuites>
714
<testsuite>
8-
<directory>./src/PropertyInfo/Tests</directory>
15+
<directory>./src/PropertyInfo/Tests/</directory>
916
</testsuite>
1017
</testsuites>
18+
19+
<filter>
20+
<whitelist>
21+
<directory>./</directory>
22+
<exclude>
23+
<directory>./src/PropertyInfo/Tests/</directory>
24+
<directory>./vendor</directory>
25+
</exclude>
26+
</whitelist>
27+
</filter>
1128
</phpunit>

src/PropertyInfo/DescriptionExtractorInterface.php

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/PropertyInfo/Extractors/DoctrineExtractor.php

Lines changed: 57 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@
1111

1212
use Doctrine\Common\Persistence\Mapping\ClassMetadataFactory;
1313
use Doctrine\Common\Persistence\Mapping\MappingException;
14+
use Doctrine\ORM\Mapping\ClassMetadataInfo;
15+
use PropertyInfo\PropertyListRetrieverInterface;
16+
use PropertyInfo\PropertyTypeInfoInterface;
1417
use PropertyInfo\Type;
15-
use PropertyInfo\TypeExtractorInterface;
1618

1719
/**
18-
* Doctrine ORM and ODM Extractor.
20+
* Extracts data using Doctrine ORM and ODM metadata.
1921
*
2022
* @author Kévin Dunglas <dunglas@gmail.com>
2123
*/
22-
class DoctrineExtractor implements TypeExtractorInterface
24+
class DoctrineExtractor implements PropertyListRetrieverInterface, PropertyTypeInfoInterface
2325
{
2426
/**
2527
* @var ClassMetadataFactory
@@ -31,44 +33,61 @@ public function __construct(ClassMetadataFactory $classMetadataFactory)
3133
$this->classMetadataFactory = $classMetadataFactory;
3234
}
3335

34-
public function extractTypes(\ReflectionProperty $reflectionProperty)
36+
/**
37+
* {@inheritdoc}
38+
*/
39+
public function getProperties($class, array $context = array())
3540
{
36-
$className = $reflectionProperty->getDeclaringClass()->getName();
37-
3841
try {
39-
$metadata = $this->classMetadataFactory->getMetadataFor($className);
42+
$metadata = $this->classMetadataFactory->getMetadataFor($class);
4043
} catch (MappingException $exception) {
4144
return;
4245
}
4346

44-
$type = new Type();
45-
$propertyName = $reflectionProperty->getName();
47+
return array_merge($metadata->getFieldNames(), $metadata->getAssociationNames());
48+
}
4649

47-
if ($metadata->hasAssociation($propertyName)) {
48-
$class = $metadata->getAssociationTargetClass($propertyName);
50+
/**
51+
* {@inheritdoc}
52+
*/
53+
public function getTypes($class, $property, array $context = array())
54+
{
55+
try {
56+
$metadata = $this->classMetadataFactory->getMetadataFor($class);
57+
} catch (MappingException $exception) {
58+
return;
59+
}
4960

50-
if ($metadata->isSingleValuedAssociation($propertyName)) {
51-
$type->setCollection(false);
52-
$type->setType('object');
53-
$type->setClass($class);
54-
} else {
55-
$type->setCollection(true);
56-
$type->setType('object');
57-
$type->setClass('Doctrine\Common\Collections\Collection');
61+
if ($metadata->hasAssociation($property)) {
62+
$class = $metadata->getAssociationTargetClass($property);
5863

59-
$collectionType = new Type();
60-
$collectionType->setCollection(false);
61-
$collectionType->setType('object');
62-
$collectionType->setClass($class);
64+
if ($metadata->isSingleValuedAssociation($property)) {
65+
if ($metadata instanceof ClassMetadataInfo) {
66+
$nullable = isset($metadata->discriminatorColumn['nullable']) ? $metadata->discriminatorColumn['nullable'] : false;
67+
} else {
68+
$nullable = false;
69+
}
6370

64-
$type->setCollectionType($collectionType);
71+
return array(new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, $class));
6572
}
6673

67-
return [$type];
74+
return array(new Type(
75+
Type::BUILTIN_TYPE_OBJECT,
76+
false,
77+
'Doctrine\Common\Collections\Collection',
78+
true,
79+
new Type(Type::BUILTIN_TYPE_INT),
80+
new Type(Type::BUILTIN_TYPE_OBJECT, false, $class)
81+
));
6882
}
6983

70-
if ($metadata->hasField($propertyName)) {
71-
$typeOfField = $metadata->getTypeOfField($propertyName);
84+
if ($metadata->hasField($property)) {
85+
$typeOfField = $metadata->getTypeOfField($property);
86+
if ($metadata instanceof ClassMetadataInfo) {
87+
$nullable = $metadata->isNullable($property);
88+
} else {
89+
$nullable = false;
90+
}
7291

7392
switch ($typeOfField) {
7493
case 'date':
@@ -78,33 +97,24 @@ public function extractTypes(\ReflectionProperty $reflectionProperty)
7897
case 'datetimetz':
7998
// No break
8099
case 'time':
81-
$type->setType('object');
82-
$type->setClass('DateTime');
83-
$type->setCollection(false);
84-
85-
return [$type];
100+
return array(new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, 'DateTime'));
86101

87102
case 'array':
88103
// No break
89104
case 'simple_array':
90-
// No break
91-
case 'json_array':
92-
$type->setType('array');
93-
$type->setCollection(true);
105+
return array(new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true, new Type(Type::BUILTIN_TYPE_INT)));
94106

95-
return [$type];
107+
case 'json_array':
108+
return array(new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true));
96109

97110
default:
98-
$type->setType($this->getPhpType($typeOfField));
99-
$type->setCollection(false);
100-
101-
return [$type];
111+
return array(new Type($this->getPhpType($typeOfField), $nullable));
102112
}
103113
}
104114
}
105115

106116
/**
107-
* Gets the corresponding PHP type.
117+
* Gets the corresponding built-in PHP type.
108118
*
109119
* @param string $doctrineType
110120
*
@@ -118,23 +128,23 @@ private function getPhpType($doctrineType)
118128
case 'bigint':
119129
// No break
120130
case 'integer':
121-
return 'int';
131+
return Type::BUILTIN_TYPE_INT;
122132

123133
case 'decimal':
124-
return 'float';
134+
return Type::BUILTIN_TYPE_FLOAT;
125135

126136
case 'text':
127137
// No break
128138
case 'guid':
129-
return 'string';
139+
return Type::BUILTIN_TYPE_STRING;
130140

131141
case 'boolean':
132-
return 'bool';
142+
return Type::BUILTIN_TYPE_BOOL;
133143

134144
case 'blob':
135145
// No break
136146
case 'binary':
137-
return 'resource';
147+
return Type::BUILTIN_TYPE_RESOURCE;
138148

139149
default:
140150
return $doctrineType;

src/PropertyInfo/Extractors/GetterExtractor.php

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy