Skip to content

Commit f2824cf

Browse files
author
Jérôme Poskin
committed
Merge pull request #30 from jmsche/master
Fixed Symfony 2.7 deprecated + renamed String to StringUtil for PHP7 compatibility
2 parents c741c50 + 0fe6902 commit f2824cf

File tree

8 files changed

+52
-22
lines changed

8 files changed

+52
-22
lines changed

Form/Type/FileType.php

+10-7
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@
22

33
namespace Snowcap\CoreBundle\Form\Type;
44

5+
use Snowcap\CoreBundle\File\CondemnedFile;
6+
use Snowcap\CoreBundle\Form\DataTransformer\FileDataTransformer;
57
use Symfony\Component\Form\AbstractType;
6-
use Symfony\Component\Form\FormView;
7-
use Symfony\Component\Form\FormInterface;
88
use Symfony\Component\Form\FormBuilderInterface;
9-
use Symfony\Component\OptionsResolver\OptionsResolver;
10-
use Symfony\Component\Form\FormEvents;
119
use Symfony\Component\Form\FormEvent;
10+
use Symfony\Component\Form\FormEvents;
11+
use Symfony\Component\Form\FormInterface;
12+
use Symfony\Component\Form\FormView;
13+
use Symfony\Component\OptionsResolver\OptionsResolver;
1214
use Symfony\Component\PropertyAccess\PropertyAccess;
1315

14-
use Snowcap\CoreBundle\Form\DataTransformer\FileDataTransformer;
15-
use Snowcap\CoreBundle\File\CondemnedFile;
16-
16+
/**
17+
* Class FileType
18+
* @package Snowcap\CoreBundle\Form\Type
19+
*/
1720
class FileType extends AbstractType
1821
{
1922
/**

Form/Type/ImageType.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44

55
use Symfony\Component\Form\AbstractType;
66

7-
class ImageType extends AbstractType {
7+
/**
8+
* Class ImageType
9+
* @package Snowcap\CoreBundle\Form\Type
10+
*/
11+
class ImageType extends AbstractType
12+
{
813
/**
914
* Returns the name of this type.
1015
*
@@ -16,7 +21,6 @@ function getName()
1621
}
1722

1823
/**
19-
* @param array $options
2024
* @return null|string
2125
*/
2226
public function getParent()

Form/Type/SoundType.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
namespace Snowcap\CoreBundle\Form\Type;
44

55
use Symfony\Component\Form\AbstractType;
6-
use Symfony\Component\Form\FormView;
76
use Symfony\Component\Form\FormInterface;
7+
use Symfony\Component\Form\FormView;
88
use Symfony\Component\OptionsResolver\OptionsResolver;
99

10+
/**
11+
* Class SoundType
12+
* @package Snowcap\CoreBundle\Form\Type
13+
*/
1014
class SoundType extends AbstractType
1115
{
1216
/**

Form/Type/VideoType.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
namespace Snowcap\CoreBundle\Form\Type;
44

55
use Symfony\Component\Form\AbstractType;
6-
use Symfony\Component\Form\FormView;
76
use Symfony\Component\Form\FormInterface;
7+
use Symfony\Component\Form\FormView;
88
use Symfony\Component\OptionsResolver\OptionsResolver;
99

10+
/**
11+
* Class VideoType
12+
* @package Snowcap\CoreBundle\Form\Type
13+
*/
1014
class VideoType extends AbstractType
1115
{
1216
/**
@@ -31,7 +35,7 @@ public function getParent()
3135
public function configureOptions(OptionsResolver $resolver)
3236
{
3337
$resolver
34-
->setOptional(array('provider'))
38+
->setDefined(array('provider'))
3539
->setAllowedValues(array(
3640
'provider' => array('youtube', 'tudou', 'vimeo', 'dailymotion')
3741
));

Listener/FileSubscriber.php

+9-6
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,22 @@
44

55
use Doctrine\Common\Annotations\AnnotationException;
66
use Doctrine\Common\Annotations\AnnotationReader;
7-
use Doctrine\ORM\Event\OnFlushEventArgs;
8-
use Snowcap\CoreBundle\Util\String;
9-
use Symfony\Component\HttpFoundation\File\File;
107
use Doctrine\Common\EventSubscriber;
118
use Doctrine\ORM\EntityManager;
129
use Doctrine\ORM\Event\LifecycleEventArgs;
1310
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
11+
use Doctrine\ORM\Event\OnFlushEventArgs;
1412
use Doctrine\ORM\Event\PreFlushEventArgs;
1513
use Doctrine\ORM\Events;
16-
1714
use Snowcap\CoreBundle\File\CondemnedFile;
15+
use Snowcap\CoreBundle\Util\StringUtil;
16+
use Symfony\Component\HttpFoundation\File\File;
1817
use Symfony\Component\PropertyAccess\PropertyAccess;
1918

19+
/**
20+
* Class FileSubscriber
21+
* @package Snowcap\CoreBundle\Listener
22+
*/
2023
class FileSubscriber implements EventSubscriber
2124
{
2225
/**
@@ -62,7 +65,7 @@ public function getSubscribedEvents()
6265

6366
/**
6467
* @param \Doctrine\ORM\Event\LoadClassMetadataEventArgs $eventArgs
65-
* @throws \UnexpectedValueException
68+
* @throws AnnotationException
6669
*/
6770
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
6871
{
@@ -346,7 +349,7 @@ private function generateFileName($fileEntity, array $fileConfig)
346349
if ($fileConfig['nameCallback'] !== null) {
347350
$accessor = PropertyAccess::createPropertyAccessor();
348351
$filename = $accessor->getValue($fileEntity, $fileConfig['nameCallback']);
349-
$filename = String::slugify($filename);
352+
$filename = StringUtil::slugify($filename);
350353

351354
/*
352355
* Here we add a uniqid at the end of the filename to avoid any cache issue

Twig/Extension/TextExtension.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
namespace Snowcap\CoreBundle\Twig\Extension;
44

5-
use Snowcap\CoreBundle\Util\String;
5+
use Snowcap\CoreBundle\Util\StringUtil;
66

7+
/**
8+
* Class TextExtension
9+
* @package Snowcap\CoreBundle\Twig\Extension
10+
*/
711
class TextExtension extends \Twig_Extension
812
{
9-
1013
const MISSING_EXTENSION_EXCEPTION = 10;
1114

1215
/**
@@ -48,10 +51,11 @@ public function getFilters()
4851

4952
/**
5053
* @param $string
54+
* @return string
5155
*/
5256
public function camelize($string)
5357
{
54-
return String::camelize($string);
58+
return StringUtil::camelize($string);
5559
}
5660

5761
/**

UPGRADE-3.0.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Upgrade to 3.0
2+
3+
The ``String`` class has been renamed to ``StringUtil`` as "string" is a reserved word in PHP7.

Util/String.php Util/StringUtil.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
namespace Snowcap\CoreBundle\Util;
44

5-
class String {
5+
/**
6+
* Class StringUtil
7+
* @package Snowcap\CoreBundle\Util
8+
*/
9+
class StringUtil
10+
{
611
/**
712
* Camelizes a string.
813
*

0 commit comments

Comments
 (0)