Prism PHP Support
If you follow me on GitHub you may have noticed that I forked and committed quite a bit to the wonderful Prism JS project by Lea Verou. If you don't know what Prism is, it's a lightweight syntax highlighter written in JavaScript. It's what powers the syntax highlighting for my code blocks.
My major contribution to the project was full PHP highlighting support (including 5.3 and 5.4), as well as some improvements to the C-Like language and the inclusion of the CSS extras language. Take a look at the PHP snippet below which is taken from my Titon\Model project.
/**
* @copyright Copyright 2010-2013, The Titon Project
* @license http://opensource.org/licenses/bsd-license.php
* @link http://titon.io
*/
namespace Titon\Model;
use Titon\Common\Base;
use Titon\Common\Traits\Attachable;
use Titon\Model\Relation;
class Model extends Base {
use Attachable;
protected $_config = [
'connection' => 'default',
'table' => '',
'prefix' => '',
'primaryKey' => 'id',
'displayField' => ['title', 'name', 'id'],
'entity' => 'Titon\Model\Entity'
];
public function addRelation(Relation $relation) {
$this->_relations[$relation->getAlias()] = $relation;
$this->attachObject([
'alias' => $relation->getAlias(),
'class' => $relation->getModel(),
'interface' => 'Titon\Model\Model'
]);
return $relation;
}
public function createTable(array $options = [], $temporary = false) {
$schema = $this->getSchema();
$schema->addOptions($options + [
Dialect::ENGINE => 'InnoDB',
Dialect::CHARACTER_SET => $this->getDriver()->getEncoding()
]);
return (bool) $this->query(Query::CREATE_TABLE)
->attribute('temporary', $temporary)
->schema($schema)
->save();
}
public function getPrimaryKey() {
return $this->cache(__METHOD__, function() {
$pk = $this->config->primaryKey;
$schema = $this->getSchema();
if ($schema->hasColumn($pk)) {
return $pk;
}
if ($pk = $schema->getPrimaryKey()) {
return $pk['columns'][0];
}
return 'id';
});
}
}
The language also supports seamless integration with HTML markup. The snippet below is taken from my Titon\Debug project.
<div class="titon-debug">
<div class="debug-head">
<abbr title="<?php echo $file; ?>" class="debug-file">
<?php echo self::parseFile($file) . ':'; ?><!--
--><span class="debug-line"><?php echo $line; ?></span>
</abbr>
</div>
<?php foreach ($vars as $var) { ?>
<div class="debug-output">
<?php if (isset($dump)) {
echo self::_renderTemplate('table', array('value' => $var));
} else { ?>
<pre><code><?php echo \Titon\esc(print_r($var, true)); ?></code></pre>
<?php } ?>
</div>
<?php } ?>
</div>
I hope you all find use in this contribution! Feel free to report any issues or suggestions to me.