/** * Constructor. * * @param array $options Hiermee kun je de "table" en "dbLink" overschrijven */ public function __construct($options = []) { $availableOptions = array('table', 'dbLink'); foreach ($options as $property => $value) { if (in_array($property, $availableOptions)) { $this->{$property} = $value; } else { \Sledgehammer\notice('Invalid option "' . $property . '"', 'Use: ' . \Sledgehammer\human_implode(' or ', $availableOptions)); } } if ($this->table === null) { $this->table = session_name(); } }
/** * Check if the $token is one of the expected tokens. * * @throws Exception on unexpected tokens. */ private function expectTokens($token, $expectedTokens) { foreach ($expectedTokens as $expectedToken) { if ($this->isEqual($token, $expectedToken)) { return; } } $names = []; foreach ($expectedTokens as $expectedToken) { $names[] = $this->tokenName($expectedToken); } $this->failure('Unexpected token: ' . $this->tokenName($token) . ', expecting "' . \Sledgehammer\human_implode('" or "', $names, '", "') . '"'); }
/** * @param PhpAnalyzer $analyzer * @param string $definition * * @return bool Success */ private function tryGetInfo(PhpAnalyzer $analyzer, $definition) { if (in_array($definition, array('self', 'AutoCompleteTestRepository', 'PHPUnit_Framework_TestCase', 'PHPUnit_TextUI_ResultPrinter'))) { return true; } try { $analyzer->getInfo($definition); return true; } catch (Exception $e) { $suffix = ' (used in'; foreach ($analyzer->usedDefinitions[$definition] as $filename => $lines) { $suffix .= ' "' . $filename . '" on line'; if (count($lines) == 1) { $suffix .= ' ' . $lines[0]; } else { $suffix .= 's ' . \Sledgehammer\human_implode(' and ', $lines); } } $suffix .= ')'; $this->fail($e->getMessage() . $suffix); return false; } }
public function test_environment() { $allowedEnvironments = array('development', 'testing', 'acceptation', 'production', 'phpunit'); $this->assertTrue(in_array(\Sledgehammer\ENVIRONMENT, $allowedEnvironments), '\\Sledgehammer\\ENVIRONMENT moet een van de volgende waarden zijn: "' . \Sledgehammer\human_implode('" of "', $allowedEnvironments, '", "') . '"'); }
/** * Het document genereren. */ public function render() { if ($this->headers == null) { notice(get_class($this) . '->getHeaders() should be executed before ' . get_class($this) . '->render()'); } $variables = array('charset' => $this->headers['charset'], 'title' => array_value($this->headers, 'title'), 'head' => array(), 'htmlParameters' => \Sledgehammer\implode_xml_parameters($this->headers['htmlParameters']), 'bodyParameters' => \Sledgehammer\implode_xml_parameters($this->headers['bodyParameters']), 'body' => $this->content, 'showStatusbar' => $this->showStatusbar); $validHeaders = array('http', 'title', 'charset', 'css', 'meta', 'link', 'javascript', 'htmlParameters', 'bodyParameters'); foreach ($this->headers as $key => $value) { if (!in_array($key, $validHeaders)) { notice('Invalid header: "' . $key . '", expecting "' . \Sledgehammer\human_implode('" or "', $validHeaders, '", "') . '"'); } } // tags binnen de <head> instellen $head = array('meta' => array(), 'link' => array()); if (isset($this->headers['meta'])) { $head['meta'] = $this->headers['meta']; } if (isset($this->headers['link'])) { $head['link'] = $this->headers['link']; } if (isset($this->headers['css'])) { foreach ($this->headers['css'] as $url) { $head['link'][] = array('href' => $url, 'type' => 'text/css', 'rel' => 'stylesheet'); } } $eot = $this->doctype === 'xhtml' ? ' />' : '>'; // End of Tag instellen foreach ($head as $tag => $tags) { foreach ($tags as $parameters) { $variables['head'][] = '<' . $tag . \Sledgehammer\implode_xml_parameters($parameters) . $eot; } } if (isset($this->headers['javascript'])) { foreach ($this->headers['javascript'] as $identifier => $url) { if (is_int($identifier)) { $identifier = $parameters['src']; } ob_start(); javascript_once($url, $identifier); $variables['head'][] = ob_get_clean(); } } $template = new Template('sledgehammer/mvc/templates/doctype/' . $this->doctype . '.php', $variables); $template->render(); }