setEscapeSlash() публичный Метод

If true, forward slashes will be escaped as "\/". By default, forward slashes are not escaped.
public setEscapeSlash ( boolean $enabled )
$enabled boolean Whether forward slashes should be escaped
Пример #1
0
 /**
  * @param string $path The path to the JSON file.
  */
 public function __construct($path)
 {
     $this->path = $path;
     $this->encoder = new JsonEncoder();
     $this->encoder->setPrettyPrinting(true);
     $this->encoder->setEscapeSlash(false);
 }
Пример #2
0
 /**
  * Creates a new resource discovery.
  *
  * @param string               $path         The path to the JSON file.
  * @param BindingInitializer[] $initializers The binding initializers to
  *                                           apply to newly created or
  *                                           unserialized bindings.
  */
 public function __construct($path, array $initializers = array())
 {
     Assert::stringNotEmpty($path, 'The path to the JSON file must be a non-empty string. Got: %s');
     parent::__construct($initializers);
     $this->path = $path;
     $this->encoder = new JsonEncoder();
     $this->encoder->setPrettyPrinting(true);
     $this->encoder->setEscapeSlash(false);
 }
 private function encode($jsonData)
 {
     $encoder = new JsonEncoder();
     $encoder->setPrettyPrinting(true);
     $encoder->setEscapeSlash(false);
     $encoder->setTerminateWithLineFeed(true);
     return $encoder->encode($jsonData);
 }
Пример #4
0
 public function testSlashNotEscaped()
 {
     if (version_compare(PHP_VERSION, '5.4.0', '<')) {
         $this->markTestSkipped('PHP >= 5.4.0 only');
         return;
     }
     $this->encoder->setEscapeSlash(false);
     $this->assertSame('"/"', $this->encoder->encode('/'));
 }
Пример #5
0
 /**
  * Creates a new repository.
  *
  * @param string            $path          The path to the JSON file. If
  *                                         relative, it must be relative to
  *                                         the base directory.
  * @param string            $baseDirectory The base directory of the store.
  *                                         Paths inside that directory are
  *                                         stored as relative paths. Paths
  *                                         outside that directory are stored
  *                                         as absolute paths.
  * @param bool              $validateJson  Whether to validate the JSON file
  *                                         against the schema. Slow but
  *                                         spots problems.
  * @param ChangeStream|null $changeStream  If provided, the repository will
  *                                         append resource changes to this
  *                                         change stream.
  */
 public function __construct($path, $baseDirectory, $validateJson = false, ChangeStream $changeStream = null)
 {
     parent::__construct($changeStream);
     $this->baseDirectory = $baseDirectory;
     $this->path = Path::makeAbsolute($path, $baseDirectory);
     $this->encoder = new JsonEncoder();
     $this->encoder->setPrettyPrinting(true);
     $this->encoder->setEscapeSlash(false);
     if ($validateJson) {
         $this->schemaPath = Path::canonicalize(__DIR__ . '/../res/schema/path-mappings-schema-1.0.json');
     }
 }
Пример #6
0
 private function encode($jsonData)
 {
     $encoder = new JsonEncoder();
     $encoder->setPrettyPrinting(true);
     $encoder->setEscapeSlash(false);
     $encoder->setTerminateWithLineFeed(true);
     $decoder = new JsonDecoder();
     // We can't use realpath(), which doesn't work inside PHARs.
     // However, we want to display nice paths if the file is not found.
     $schema = $decoder->decodeFile(Path::canonicalize(__DIR__ . '/../../res/schema/package-schema-1.0.json'));
     $configSchema = $schema->properties->config;
     return $encoder->encode($jsonData, $configSchema);
 }
Пример #7
0
 private function encodeFile($jsonData, $path)
 {
     if (!is_string($path) || !Path::isAbsolute($path)) {
         throw new IOException(sprintf('Cannot write "%s": Expected an absolute path.', $path));
     }
     if (is_dir($path)) {
         throw new IOException(sprintf('Cannot write %s: Is a directory.', $path));
     }
     $encoder = new JsonEncoder();
     $encoder->setPrettyPrinting(true);
     $encoder->setEscapeSlash(false);
     $encoder->setTerminateWithLineFeed(true);
     $decoder = new JsonDecoder();
     // We can't use realpath(), which doesn't work inside PHARs.
     // However, we want to display nice paths if the file is not found.
     $schema = $decoder->decodeFile(Path::canonicalize(__DIR__ . '/../../res/schema/package-schema-1.0.json'));
     $configSchema = $schema->properties->config;
     if (!is_dir($dir = Path::getDirectory($path))) {
         $filesystem = new Filesystem();
         $filesystem->mkdir($dir);
     }
     $encoder->encodeFile($jsonData, $path, $configSchema);
 }
Пример #8
0
 /**
  * Returns the JSON encoder.
  *
  * @return JsonEncoder The JSON encoder.
  */
 public function getJsonEncoder()
 {
     if (!$this->jsonEncoder) {
         $this->jsonEncoder = new JsonEncoder();
         $this->jsonEncoder->setPrettyPrinting(true);
         $this->jsonEncoder->setEscapeSlash(false);
         $this->jsonEncoder->setTerminateWithLineFeed(true);
     }
     return $this->jsonEncoder;
 }
Пример #9
0
 private function encode(stdClass $jsonData, $path = null)
 {
     $encoder = new JsonEncoder();
     $encoder->setPrettyPrinting(true);
     $encoder->setEscapeSlash(false);
     $encoder->setTerminateWithLineFeed(true);
     $this->validate($jsonData, $path);
     return $encoder->encode($jsonData);
 }
Пример #10
0
 public function __construct($path, $flags = 0)
 {
     Assert::string($path, 'The path must be a string. Got: %s');
     Assert::notEmpty($path, 'The path must not be empty.');
     Assert::integer($flags, 'The flags must be an integer. Got: %s');
     $this->path = $path;
     $this->flags = $flags;
     $this->encoder = new JsonEncoder();
     $this->encoder->setEscapeGtLt($this->flags & self::ESCAPE_GT_LT);
     $this->encoder->setEscapeAmpersand($this->flags & self::ESCAPE_AMPERSAND);
     $this->encoder->setEscapeSingleQuote($this->flags & self::ESCAPE_SINGLE_QUOTE);
     $this->encoder->setEscapeDoubleQuote($this->flags & self::ESCAPE_DOUBLE_QUOTE);
     $this->encoder->setEscapeSlash(!($this->flags & self::NO_ESCAPE_SLASH));
     $this->encoder->setEscapeUnicode(!($this->flags & self::NO_ESCAPE_UNICODE));
     $this->encoder->setPrettyPrinting($this->flags & self::PRETTY_PRINT);
     $this->encoder->setTerminateWithLineFeed($this->flags & self::TERMINATE_WITH_LINE_FEED);
     $this->decoder = new JsonDecoder();
     $this->decoder->setObjectDecoding(JsonDecoder::ASSOC_ARRAY);
 }