-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathModule.php
More file actions
39 lines (32 loc) · 1.05 KB
/
Module.php
File metadata and controls
39 lines (32 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace EdpMarkdown;
class Module extends \Zend\View\Helper\AbstractHelper
{
const MARKDOWN_NORMAL = 'normal';
const MARKDOWN_EXTRA = 'extra';
protected $classWhitelist = array(
self::MARKDOWN_NORMAL => '\Michelf\Markdown',
self::MARKDOWN_EXTRA => '\Michelf\MarkdownExtra'
);
protected static $defaultType = self::MARKDOWN_NORMAL;
public function getViewHelperConfig()
{
return array('services' => array('markdown' => $this));
}
public function __invoke($string = null, $type = null)
{
if (null == $type) {
$type = self::$defaultType;
}
$className = $this->classWhitelist[$type];
if (!class_exists($className)) {
$fileName = str_replace('\\', '/', $className) . '.inc.php';
require_once __DIR__ . '/vendor/php-markdown' . $fileName;
}
return $className::defaultTransform($string);
}
public static function setDefaultType($type)
{
self::$defaultType = $type;
}
}