diff --git a/composer.json b/composer.json index faa17c1b..6b8365bc 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ }, { "name": "Franck Lefevre", - "homepage": "http://blog.rootslabs.net" + "homepage": "https://rootslabs.net/blog/" }, { "name": "Ivan Lanin", @@ -36,13 +36,11 @@ "ext-xml": "*", "zendframework/zend-escaper": "2.4.*", "zendframework/zend-stdlib": "2.4.*", - "zendframework/zend-validator": "2.4.*", "phpoffice/common": "0.2.*" }, "require-dev": { "phpunit/phpunit": "3.7.*", "phpdocumentor/phpdocumentor":"2.*", - "twig/twig":"1.27", "squizlabs/php_codesniffer": "1.*", "phpmd/phpmd": "2.*", "phploc/phploc": "2.*", diff --git a/src/PhpWord/Shared/AbstractEnum.php b/src/PhpWord/Shared/AbstractEnum.php index 4584c2f9..f116e511 100644 --- a/src/PhpWord/Shared/AbstractEnum.php +++ b/src/PhpWord/Shared/AbstractEnum.php @@ -19,16 +19,39 @@ abstract class AbstractEnum return self::$constCacheArray[$calledClass]; } + /** + * Returns all values for this enum + * + * @return array + */ public static function values() { return array_values(self::getConstants()); } - public static function validate($value) + /** + * Returns true the value is valid for this enum + * + * @param strign $value + * @return boolean true if value is valid + */ + public static function isValid($value) { $values = array_values(self::getConstants()); - if (!in_array($value, $values, true)) { + return in_array($value, $values, true); + } + + /** + * Validates that the value passed is a valid value + * + * @param string $value + * @throws \InvalidArgumentException if the value passed is not valid for this enum + */ + public static function validate($value) + { + if (!self::isValid($value)) { $calledClass = get_called_class(); + $values = array_values(self::getConstants()); throw new \InvalidArgumentException("$value is not a valid value for $calledClass, possible values are " . implode(', ', $values)); } } diff --git a/src/PhpWord/SimpleType/Jc.php b/src/PhpWord/SimpleType/Jc.php index e90674a4..5c399a16 100644 --- a/src/PhpWord/SimpleType/Jc.php +++ b/src/PhpWord/SimpleType/Jc.php @@ -17,7 +17,7 @@ namespace PhpOffice\PhpWord\SimpleType; -use Zend\Validator\InArray; +use PhpOffice\PhpWord\Shared\AbstractEnum; /** * Horizontal Alignment Type. @@ -28,10 +28,11 @@ use Zend\Validator\InArray; * @since 0.13.0 * * @see \PhpOffice\PhpWord\SimpleType\JcTable For table alignment modes available since ISO/IEC-29500:2008. + * @link http://www.datypic.com/sc/ooxml/t-w_ST_Jc.html * * @codeCoverageIgnore */ -final class Jc +final class Jc extends AbstractEnum { const START = 'start'; const CENTER = 'center'; @@ -65,34 +66,4 @@ final class Jc * @deprecated 0.13.0 For documents based on ISO/IEC 29500:2008 and later use `BOTH` instead. */ const JUSTIFY = 'justify'; - - /** - * @since 0.13.0 - * - * @return \Zend\Validator\InArray - */ - final public static function getValidator() - { - // todo: consider caching validator instances. - return new InArray( - array ( - 'haystack' => array( - self::START, - self::CENTER, - self::END, - self::BOTH, - self::MEDIUM_KASHIDA, - self::DISTRIBUTE, - self::NUM_TAB, - self::HIGH_KASHIDA, - self::LOW_KASHIDA, - self::THAI_DISTRIBUTE, - self::LEFT, - self::RIGHT, - self::JUSTIFY, - ), - 'strict' => InArray::COMPARE_STRICT, - ) - ); - } } diff --git a/src/PhpWord/SimpleType/JcTable.php b/src/PhpWord/SimpleType/JcTable.php index d9648477..865b25a8 100644 --- a/src/PhpWord/SimpleType/JcTable.php +++ b/src/PhpWord/SimpleType/JcTable.php @@ -17,7 +17,7 @@ namespace PhpOffice\PhpWord\SimpleType; -use Zend\Validator\InArray; +use PhpOffice\PhpWord\Shared\AbstractEnum; /** * Table Alignment Type. @@ -28,25 +28,9 @@ use Zend\Validator\InArray; * * @codeCoverageIgnore */ -final class JcTable +final class JcTable extends AbstractEnum { const START = 'start'; const CENTER = 'center'; const END = 'end'; - - /** - * @since 0.13.0 - * - * @return \Zend\Validator\InArray - */ - final public static function getValidator() - { - // todo: consider caching validator instances. - return new InArray( - array ( - 'haystack' => array(self::START, self::CENTER, self::END), - 'strict' => InArray::COMPARE_STRICT, - ) - ); - } } diff --git a/src/PhpWord/Style/Frame.php b/src/PhpWord/Style/Frame.php index 97faacfb..0a99146b 100644 --- a/src/PhpWord/Style/Frame.php +++ b/src/PhpWord/Style/Frame.php @@ -200,7 +200,7 @@ class Frame extends AbstractStyle */ public function setAlignment($value) { - if (Jc::getValidator()->isValid($value)) { + if (Jc::isValid($value)) { $this->alignment = $value; } diff --git a/src/PhpWord/Style/NumberingLevel.php b/src/PhpWord/Style/NumberingLevel.php index 827d4354..38b9fbee 100644 --- a/src/PhpWord/Style/NumberingLevel.php +++ b/src/PhpWord/Style/NumberingLevel.php @@ -300,7 +300,7 @@ class NumberingLevel extends AbstractStyle */ public function setAlignment($value) { - if (Jc::getValidator()->isValid($value)) { + if (Jc::isValid($value)) { $this->alignment = $value; } diff --git a/src/PhpWord/Style/Paragraph.php b/src/PhpWord/Style/Paragraph.php index a9b53b2b..bad9ace9 100644 --- a/src/PhpWord/Style/Paragraph.php +++ b/src/PhpWord/Style/Paragraph.php @@ -240,7 +240,7 @@ class Paragraph extends Border */ public function setAlignment($value) { - if (Jc::getValidator()->isValid($value)) { + if (Jc::isValid($value)) { $this->alignment = $value; } diff --git a/src/PhpWord/Style/Table.php b/src/PhpWord/Style/Table.php index 91809528..a542af7b 100644 --- a/src/PhpWord/Style/Table.php +++ b/src/PhpWord/Style/Table.php @@ -510,7 +510,7 @@ class Table extends Border */ public function setAlignment($value) { - if (JcTable::getValidator()->isValid($value) || Jc::getValidator()->isValid($value)) { + if (JcTable::isValid($value) || Jc::isValid($value)) { $this->alignment = $value; }