Deprecated: Constant E_STRICT is deprecated in /var/www/PixelForce/vendor/symfony/error-handler/ErrorHandler.php on line 58

Deprecated: Constant E_STRICT is deprecated in /var/www/PixelForce/vendor/symfony/error-handler/ErrorHandler.php on line 76
Symfony Profiler

vendor/friendsofsymfony/ckeditor-bundle/src/Builder/JsonBuilder.php line 71

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the FOSCKEditor Bundle.
  4.  *
  5.  * (c) 2018 - present  Friends of Symfony
  6.  * (c) 2009 - 2017     Eric GELOEN <geloen.eric@gmail.com>
  7.  *
  8.  * For the full copyright and license information, please read the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace FOS\CKEditorBundle\Builder;
  12. use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
  13. /**
  14.  * @author GeLo <geloen.eric@gmail.com>
  15.  */
  16. final class JsonBuilder
  17. {
  18.     /**
  19.      * @var PropertyAccessorInterface
  20.      */
  21.     private $propertyAccessor;
  22.     /**
  23.      * @var array
  24.      */
  25.     private $values = [];
  26.     /**
  27.      * @var array
  28.      */
  29.     private $escapes = [];
  30.     /**
  31.      * @var int
  32.      */
  33.     private $jsonEncodeOptions 0;
  34.     public function __construct(PropertyAccessorInterface $propertyAccessor)
  35.     {
  36.         $this->propertyAccessor $propertyAccessor;
  37.         $this->reset();
  38.     }
  39.     public function getJsonEncodeOptions(): int
  40.     {
  41.         return $this->jsonEncodeOptions;
  42.     }
  43.     public function setJsonEncodeOptions(int $jsonEncodeOptions): self
  44.     {
  45.         $this->jsonEncodeOptions $jsonEncodeOptions;
  46.         return $this;
  47.     }
  48.     public function hasValues(): bool
  49.     {
  50.         return !empty($this->values);
  51.     }
  52.     public function getValues(): array
  53.     {
  54.         return $this->values;
  55.     }
  56.     public function setValues(array $valuesstring $pathPrefix null): self
  57.     {
  58.         foreach ($values as $key => $value) {
  59.             $path sprintf('%s[%s]'$pathPrefix$key);
  60.             if (\is_array($value) && !empty($value)) {
  61.                 $this->setValues($value$path);
  62.             } else {
  63.                 $this->setValue($path$value);
  64.             }
  65.         }
  66.         return $this;
  67.     }
  68.     public function setValue(string $pathmixed $valuebool $escapeValue true): self
  69.     {
  70.         if (!$escapeValue) {
  71.             $placeholder uniqid('friendsofsymfony'true);
  72.             $this->escapes[sprintf('"%s"'$placeholder)] = $value;
  73.             $value $placeholder;
  74.         }
  75.         $this->values[$path] = $value;
  76.         return $this;
  77.     }
  78.     public function removeValue(string $path): self
  79.     {
  80.         unset($this->values[$path], $this->escapes[$path]);
  81.         return $this;
  82.     }
  83.     public function reset(): self
  84.     {
  85.         $this->values = [];
  86.         $this->escapes = [];
  87.         $this->jsonEncodeOptions 0;
  88.         return $this;
  89.     }
  90.     public function build(): string
  91.     {
  92.         $values = [];
  93.         foreach ($this->values as $path => $value) {
  94.             $this->propertyAccessor->setValue($values$path$value);
  95.         }
  96.         $json json_encode($values$this->jsonEncodeOptions);
  97.         \assert(\is_string($json));
  98.         return str_replace(
  99.             array_keys($this->escapes),
  100.             array_values($this->escapes),
  101.             $json
  102.         );
  103.     }
  104. }