Skip to content

Commit ba80ddd

Browse files
makasimsaimaz
authored andcommitted
PHP7.2 compatibility. BC compatible. (#852)
* PHP7.2 compatibility. BC compatible. * fix cs * set unlimited memory_limit * add memory limit before composer. * debug * fix * fix tests on sf2 * travis. remove php -i * fix typo. * fix ES endpoint in tests. * remove 3.5, 3.6 symfony from travis matrix. * use yaml extension for sf4 config. * trigger travis * trigger travis.
1 parent a2642ee commit ba80ddd

File tree

12 files changed

+77
-49
lines changed

12 files changed

+77
-49
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ env:
1515
- SYMFONY="~3.2"
1616
- SYMFONY="~3.3"
1717
- SYMFONY="~3.4"
18-
- SYMFONY="~3.5"
19-
- SYMFONY="~3.6"
2018
install:
2119
- wget ${ES_DOWNLOAD_URL}
2220
- tar -xzf elasticsearch-${ES_VERSION}.tar.gz
2321
- ./elasticsearch-${ES_VERSION}/bin/elasticsearch -d
2422
before_script:
23+
- echo 'memory_limit=-1' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
2524
- composer require --no-update symfony/symfony:${SYMFONY}
2625
- composer config -g github-oauth.github.com $GITHUB_COMPOSER_AUTH
2726
- composer install --no-interaction --prefer-dist
27+
2828
script:
2929
- wget -q --waitretry=1 --retry-connrefused -T 10 -O - http://127.0.0.1:9200
3030
- vendor/bin/phpunit --coverage-clover=coverage.clover

Annotation/Object.php

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,7 @@
1111

1212
namespace ONGR\ElasticsearchBundle\Annotation;
1313

14-
/**
15-
* Annotation to mark a class as an object during the parsing process.
16-
*
17-
* `Object` name as class name is forbidden in PHP 7 but we never create this
18-
* class as object and only use it for annotation definition.
19-
*
20-
* @Annotation
21-
* @Target("CLASS")
22-
*
23-
* @deprecated Object is reserved word in PHP 7.2, it will be changed to ObjectType class
24-
*/
25-
final class Object
26-
{
27-
const NAME = 'object';
28-
29-
/**
30-
* In this field you can define options.
31-
*
32-
* @var array
33-
*/
34-
public $options = [];
35-
36-
/**
37-
* {@inheritdoc}
38-
*/
39-
public function dump(array $exclude = [])
40-
{
41-
return array_diff_key(
42-
$this->options,
43-
$exclude
44-
);
45-
}
14+
if (version_compare(PHP_VERSION, '7.2.0') < 0) {
15+
class_alias('ONGR\ElasticsearchBundle\Annotation\ObjectType', 'ONGR\ElasticsearchBundle\Annotation\Object', false);
16+
class_exists('ONGR\ElasticsearchBundle\Annotation\ObjectType');
4617
}

Annotation/ObjectType.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the ONGR package.
5+
*
6+
* (c) NFQ Technologies UAB <info@nfq.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace ONGR\ElasticsearchBundle\Annotation;
13+
14+
/**
15+
* Annotation to mark a class as an object during the parsing process.
16+
*
17+
* `Object` name as class name is forbidden in PHP 7 but we never create this
18+
* class as object and only use it for annotation definition.
19+
*
20+
* @Annotation
21+
* @Target("CLASS")
22+
*
23+
* @deprecated Object is reserved word in PHP 7.2, it will be changed to ObjectType class
24+
*/
25+
final class ObjectType
26+
{
27+
const NAME = 'object';
28+
29+
/**
30+
* In this field you can define options.
31+
*
32+
* @var array
33+
*/
34+
public $options = [];
35+
36+
/**
37+
* {@inheritdoc}
38+
*/
39+
public function dump(array $exclude = [])
40+
{
41+
return array_diff_key(
42+
$this->options,
43+
$exclude
44+
);
45+
}
46+
}

DependencyInjection/ONGRElasticsearchExtension.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use Symfony\Component\DependencyInjection\Definition;
1919
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
2020
use Symfony\Component\DependencyInjection\Reference;
21+
use Symfony\Component\HttpKernel\Kernel;
22+
use Symfony\Component\HttpKernel\KernelEvents;
2123

2224
/**
2325
* This is the class that loads and manages bundle configuration.
@@ -34,6 +36,11 @@ public function load(array $configs, ContainerBuilder $container)
3436

3537
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
3638
$loader->load('services.yml');
39+
40+
if (Kernel::MAJOR_VERSION >= 4) {
41+
$loader->load('services4.yaml');
42+
}
43+
3744
$config['cache'] = isset($config['cache']) ?
3845
$config['cache'] : !$container->getParameter('kernel.debug');
3946
$config['profiler'] = isset($config['profiler']) ?

Mapping/DocumentParser.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class DocumentParser
3030
const PROPERTY_ANNOTATION = 'ONGR\ElasticsearchBundle\Annotation\Property';
3131
const EMBEDDED_ANNOTATION = 'ONGR\ElasticsearchBundle\Annotation\Embedded';
3232
const DOCUMENT_ANNOTATION = 'ONGR\ElasticsearchBundle\Annotation\Document';
33-
const OBJECT_ANNOTATION = 'ONGR\ElasticsearchBundle\Annotation\Object';
33+
const OBJECT_ANNOTATION = 'ONGR\ElasticsearchBundle\Annotation\ObjectType';
3434
const NESTED_ANNOTATION = 'ONGR\ElasticsearchBundle\Annotation\Nested';
3535

3636
// Meta fields
@@ -398,7 +398,7 @@ private function registerAnnotations()
398398
'Document',
399399
'Property',
400400
'Embedded',
401-
'Object',
401+
'ObjectType',
402402
'Nested',
403403
'Id',
404404
'ParentDocument',
@@ -410,6 +410,10 @@ private function registerAnnotations()
410410
foreach ($annotations as $annotation) {
411411
AnnotationRegistry::registerFile(__DIR__ . "/../Annotation/{$annotation}.php");
412412
}
413+
414+
if (version_compare(PHP_VERSION, '7.2.0') < 0) {
415+
AnnotationRegistry::registerFile(__DIR__ . "/../Annotation/Object.php");
416+
}
413417
}
414418

415419
/**
@@ -595,7 +599,7 @@ private function getObjectMapping($className, $directory)
595599
default:
596600
throw new \LogicException(
597601
sprintf(
598-
'%s should have @Object or @Nested annotation to be used as embeddable object.',
602+
'%s should have @ObjectType or @Nested annotation to be used as embeddable object.',
599603
$className
600604
)
601605
);

Resources/config/services.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ parameters:
22
es.logging.path: "%kernel.logs_dir%/elasticsearch_%kernel.environment%.log"
33

44
services:
5-
ONGR\ElasticsearchBundle\Command\:
6-
resource: '../../Command'
7-
tags:
8-
- { name: console.command }
9-
105
es.export:
116
class: ONGR\ElasticsearchBundle\Service\ExportService
127

Resources/config/services4.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
services:
2+
ONGR\ElasticsearchBundle\Command\:
3+
resource: '../../Command'
4+
tags:
5+
- { name: console.command }

Resources/doc/mapping.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ namespace AppBundle\Document;
275275
use ONGR\ElasticsearchBundle\Annotation as ES;
276276
277277
/**
278-
* @ES\Object
278+
* @ES\ObjectType
279279
*/
280280
class CategoryObject
281281
{
@@ -399,7 +399,7 @@ namespace AppBundle\Document;
399399
use ONGR\ElasticsearchBundle\Annotation as ES;
400400
401401
/**
402-
* @ES\Object
402+
* @ES\ObjectType
403403
*/
404404
class VariantObject
405405
{

Result/Converter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Doctrine\Common\Collections\Collection;
1515
use ONGR\ElasticsearchBundle\Annotation\Nested;
16-
use ONGR\ElasticsearchBundle\Annotation\Object;
16+
use ONGR\ElasticsearchBundle\Annotation\ObjectType;
1717
use ONGR\ElasticsearchBundle\Mapping\MetadataCollector;
1818
use ONGR\ElasticsearchBundle\Service\Manager;
1919

@@ -104,7 +104,7 @@ public function assignArrayToObject(array $array, $object, array $aliases)
104104
$value = new \DateTime($value);
105105
}
106106
break;
107-
case Object::NAME:
107+
case ObjectType::NAME:
108108
case Nested::NAME:
109109
if ($aliases[$name]['multiple']) {
110110
$value = new ObjectIterator($this, $value, $aliases[$name]);

Tests/app/fixture/TestBundle/Document/CategoryObject.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* Category object for testing.
1818
*
19-
* @ES\Object
19+
* @ES\ObjectType
2020
*/
2121
class CategoryObject
2222
{

0 commit comments

Comments
 (0)