This repository has been archived by the owner on Sep 18, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from deanblackborough/v.3.10.0
V.3.10.0
- Loading branch information
Showing
10 changed files
with
225 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace DBlackborough\Quill; | ||
|
||
/** | ||
* Parse multiple Quill generated deltas strings into the requested format, you can return | ||
* then rendered strings in whatever order you want, just provide the relevant index | ||
* | ||
* @author Dean Blackborough <[email protected]> | ||
* @copyright Dean Blackborough | ||
* @license https://github.com/deanblackborough/php-quill-renderer/blob/master/LICENSE | ||
*/ | ||
class RenderMultiple | ||
{ | ||
/** | ||
* @var \DBlackborough\Quill\Parser\Parse | ||
*/ | ||
private $parser; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $format; | ||
|
||
/** | ||
* Renderer constructor, pass in the $quill_json string and set the requested output format | ||
* | ||
* @param array $quill_json An indexed array of $quill_json string | ||
* @param string $format Requested output format | ||
* | ||
* @throws \Exception | ||
*/ | ||
public function __construct(array $quill_json, string $format = 'HTML') | ||
{ | ||
switch ($format) { | ||
case 'HTML': | ||
$this->parser = new Parser\Html(); | ||
break; | ||
default: | ||
throw new \InvalidArgumentException('Requested $format not supported, formats supported, [HTML]'); | ||
break; | ||
} | ||
|
||
$this->format = $format; | ||
|
||
if ($this->parser->loadMultiple($quill_json) === false) { | ||
throw new \RuntimeException('Failed to load/json_decode the $quill_json strings'); | ||
} | ||
} | ||
|
||
/** | ||
* Pass the content array to the renderer and return the generated output | ||
* | ||
* @param string $index Index to return | ||
* | ||
* @return string | ||
* @throws \Exception | ||
* @throws \BadMethodCallException | ||
* @throws \OutOfRangeException | ||
*/ | ||
public function render(string $index): string | ||
{ | ||
if ($this->parser === null) { | ||
throw new \BadMethodCallException('No parser loaded'); | ||
} | ||
|
||
if ($this->parser->parseMultiple() !== true) { | ||
throw new \Exception('Failed to parse the supplied $quill_json arrays'); | ||
} | ||
|
||
switch ($this->format) { | ||
case 'HTML': | ||
$deltas = $this->parser->deltasByIndex($index); | ||
break; | ||
default: | ||
$deltas = []; | ||
break; | ||
} | ||
|
||
$renderer = new Renderer\Html(); | ||
return $renderer->load($deltas)->render(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.