public static function getInstance() { if (self::$instance == null) { self::$instance = new PathBuilder(); } return self::$instance; }
public function testShouldUseBothMethodsAndParam() { $path = "/a/:dog/:abc/123"; $expected = "/a/dog-value/abc-value/123"; $actual = PathBuilder::build($path, $this->object, $this->params); $this->assertSame($expected, $actual); }
public function __construct($method, $path, $params, $headers, $object) { $this->apiBase = $this->apiBase ? $this->apiBase : Alman::getApiBase(); $this->method = $method; $this->path = PathBuilder::build($path, $object, $params); $this->params = ParamsBuilder::build($params); $this->headers = HeadersBuilder::build($headers); }
private function initDatabase() { $configFilePath = PathBuilder::getInstance()->buildAbsolutePath(Constants::CONFIG_DIR, Constants::CONFIG_FILE_DB); $configLoader = new DbConfigLoader(); try { $this->dbConnector = $configLoader->makeConnectorFromFile($configFilePath); } catch (Exception $e) { throw new Exception('Error while loading database configuration: ' . $e->getMessage()); } }
public function testShouldUsePathBuilder() { // Setup $method = "get"; $path = "/testing"; $params = ["param_a" => "1"]; $headers = ["header_a" => "a"]; $object = new \stdClass(); $apiMethod = new ApiMethod($method, $path, $params, $headers, $object); // Assert Equals $this->assertSame(PathBuilder::build($path, $object, $params), $apiMethod->path); }
public static function loadClass($className) { if (class_exists($className, false) || interface_exists($className, false)) { return; } $fileName = $className . '.php'; @(include PathBuilder::getInstance()->buildAbsolutePath(Constants::CLASSES_DIR, $fileName)); // Hack to to be able to throw an exception instead of an E_ERROR. // (see: http://www.phpbar.de/w/autoload() ); if (!class_exists($className, false) && !interface_exists($className, false)) { eval('class ' . $className . ' {' . ' public function __construct() {' . ' throw new Exception( "Class not found: ' . $className . '" );' . ' }' . '}'); } }
function build($id) { $this->items = array(); $this->path = ""; $this->pathFile = ""; $this->htmlCode = ""; parent::build($id); for ($i = 0; $i < sizeof($this->items); $i++) { $path = $this->basePath . $this->getPath($i); $item = $this->items[$i]; if ($i < sizeof($this->items) - 1) { $this->htmlCode .= "<a href=\"{$path}\" {$this->linkAttrs} >{$item}</a>\n\t\t\t\t\t > "; } else { $this->htmlCode .= $item; } } }
public function writeOutput() { if ($this->isFault()) { error_log('Error while handling captcha image request: ' . $this->faultString . ' (' . $this->faultCode . ')'); header('HTTP/1.1 500 Internal Server Error'); die('500 Internal Server Error'); } $outputWidth = 150; $outputHeight = 40; $maxRotation = 30; $minSize = 15; $maxSize = 25; $backgroundCharCount = 45; $font = PathBuilder::getInstance()->buildAbsolutePath(Constants::ASSET_DIR, Constants::CAPTCHA_FONT); $image = imagecreatetruecolor($outputWidth, $outputHeight); $backColor = imagecolorallocate($image, $this->randInt(224, 255), $this->randInt(244, 255), $this->randInt(224, 255)); imagefilledrectangle($image, 0, 0, $outputWidth, $outputHeight, $backColor); for ($i = 0; $i < $backgroundCharCount; ++$i) { $size = $this->randInt($minSize / 2.3, $maxSize / 1.7); $angle = $this->randInt(0, 359); $x = $this->randInt(0, $outputWidth); $y = $this->randInt(0, $outputHeight - $size / 5); $color = imagecolorallocate($image, $this->randInt(120, 224), $this->randInt(120, 224), $this->randInt(120, 224)); $char = chr($this->randInt(33, 126)); imagettftext($image, $size, $angle, $x, $y, $color, $font, $char); } $x = $this->randInt($minSize * 0.7, $maxSize * 0.7); for ($i = 0; $i < strlen($this->returnValue->getValue()); ++$i) { $char = substr($this->returnValue->getValue(), $i, 1); $angle = $this->randInt(-$maxRotation, $maxRotation); $size = $this->randInt($minSize, $maxSize); $y = $this->randInt($size, $outputHeight - $size / 7); $color = imagecolorallocate($image, $this->randInt(0, 127), $this->randInt(0, 127), $this->randInt(0, 127)); $shadow = imagecolorallocate($image, $this->randInt(127, 255), $this->randInt(127, 255), $this->randInt(127, 255)); imagettftext($image, $size, $angle, $x + (int) ($size / 15), $y, $shadow, $font, $char); imagettftext($image, $size, $angle, $x, $y - (int) ($size / 15), $color, $font, $char); $x += (int) ($size + $minSize / 6); } header('Content-Type: image/png'); imagepng($image); imagedestroy($image); }
<?php require_once PathBuilder::getInstance()->buildAbsolutePath(Constants::LIBS_DIR, Constants::LIBS_FILE_XMLRPC); class XmlRpcRequest extends Request { protected function init() { $requestString = file_get_contents('php://input'); if (StringUtils::isEmpty($requestString)) { return; } $requestData = XMLRPC_parse($requestString); $methodStrings = explode('.', XMLRPC_getMethodName($requestData)); $this->methodOwner = $methodStrings[0]; $this->methodName = $methodStrings[1]; $this->methodParams = XMLRPC_getParams($requestData); // TODO: Where to call session_start? session_start(); $this->session = new PhpHttpSession(); } }
function testFileNameWithBackslash() { $path = new PathBuilder(); $this->assertEquals('a.txt', $path->fileName('b\\a.txt')); }