PhpSerializeOptions.php 1.48 KB
Newer Older
Ketan's avatar
Ketan committed
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
<?php
/**
 * @see       https://github.com/zendframework/zend-serializer for the canonical source repository
 * @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
 * @license   https://github.com/zendframework/zend-serializer/blob/master/LICENSE.md New BSD License
 */

namespace Zend\Serializer\Adapter;

use Zend\Json\Json as ZendJson;
use Zend\Serializer\Exception;

class PhpSerializeOptions extends AdapterOptions
{
    /**
     * The list of allowed classes for unserialization (PHP 7.0+).
     *
     * Possible values:
     *
     * - `array` of class names that are allowed to be unserialized
     * - `true` if all classes should be allowed (behavior pre-PHP 7.0)
     * - `false` if no classes should be allowed
     *
     * @var string[]|bool
     */
    protected $unserializeClassWhitelist = true;

    /**
     * @param string[]|bool $unserializeClassWhitelist
     * @return void
     */
    public function setUnserializeClassWhitelist($unserializeClassWhitelist)
    {
        if ($unserializeClassWhitelist !== true && PHP_MAJOR_VERSION < 7) {
            throw new Exception\InvalidArgumentException(
                'Class whitelist for unserialize() is only available on PHP versions 7.0 or higher.'
            );
        }

        $this->unserializeClassWhitelist = $unserializeClassWhitelist;
    }

    /**
     * @return string[]|bool
     */
    public function getUnserializeClassWhitelist()
    {
        return $this->unserializeClassWhitelist;
    }
}