Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP7 Compatibility #45

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion content/content.debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(){
}
}

public function build() {
public function build(array $context = array()) {
$this->_view = (strlen(trim($_GET['debug'])) == 0 ? 'xml' : $_GET['debug']);

return parent::build();
Expand Down
4 changes: 4 additions & 0 deletions extension.meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
</author>
</authors>
<releases>
<release version="2.0.0" date="TBA" min="4.0.0" max="4.x.x" php-min="5.6.x" php-max="7.x.x">
- Update for Symphony 4.x
- PHP7 Compatibility
</release>
<release version="1.3.4" date="2017-06-20" min="2.4" max="2.x.x">
- Mark compatibility with Symphony 2.7
</release>
Expand Down
48 changes: 24 additions & 24 deletions lib/bitter/formats/symphony.php
Original file line number Diff line number Diff line change
@@ -1,104 +1,104 @@
<?php
/*----------------------------------------------------------------------------*/

class BitterFormatSymphony extends BitterFormat {
protected $tabsize = 4;
protected $line = 1;
protected $output = '';

public function process($source) {
$this->output = $source;

$this->processTabs();
$this->processLines();

return sprintf(
'<pre>%s</pre>',
$this->output
);
}

protected function processTabs() {
// first split the output into manageable chunks
$lines = explode(PHP_EOL, $this->output);
$linesCount = count($lines);
// fix lines one by one
for ($x = 0; $x < $linesCount; $x++) {
// while there are still tabs
while (strpos($lines[$x], "\t") !== FALSE) {
while (strpos($lines[$x], "\t") !== false) {
// replace tabs for spaces
$lines[$x] = preg_replace_callback('%^([^\t]*)([\t]+)%', array($this, 'processTabsLine'), $lines[$x]);
}
}
// concat the final output
$this->output = implode(PHP_EOL, $lines);
}

protected function processTabsLine($matches) {
return $matches[1] . str_repeat(
' ', strlen($matches[2]) * $this->tabsize
);
}

protected function processLines() {
$tokens = preg_split('%(<span class=".*?">|</span>)%', $this->output, 0, PREG_SPLIT_DELIM_CAPTURE);
$stack = array(); $this->output = '';

$this->startLine();

foreach ($tokens as $token) {
// Close:
if (preg_match('%^</%', $token)) {
array_pop($stack);
$this->output .= $token;
}

// Open:
else if (preg_match('%^<%', $token)) {
array_push($stack, $token);
$this->output .= $token;
}

else {
$characters = preg_split('//', $token);

foreach ($characters as $character) {
if ($character == "\n") {
$this->endLine();

foreach ($stack as $alt_token) $this->output .= '</span>';
}

$this->output .= $character;

if ($character == "\n") {
$this->startLine();

foreach ($stack as $alt_token) $this->output .= $alt_token;
}
}
}
}

$this->endLine();
}

protected function startLine() {
$this->output .= "<line id=\"{$this->line}\">";
$this->output .= "<marker></marker>";
$this->output .= "<content>";
}

protected function endLine() {
$this->line++;
$this->output .= '</content>';
$this->output .= '</line>';
}
}

/*----------------------------------------------------------------------------*/

return new BitterFormatSymphony();

/*----------------------------------------------------------------------------*/
?>
?>