public static function trace($query, $params, $function) { if (Config::getValue('debug')) { return self::traceNoCheck($query, $params, $function); } return $function(); }
private function generateModel() { $tableName = $this->input->getArgument('table'); $className = $this->input->getOption('class'); $fileName = $this->input->getOption('file'); $nameSpace = $this->input->getOption('namespace'); $tablePrefixToRemove = $this->input->getOption('remove-prefix') ?: 't'; $shortArrays = $this->input->getOption('short-arrays'); if (empty($tableName)) { $this->fail("Specify table name e.g. users"); } try { $modelGenerator = new Generator($tableName, $className, $nameSpace, $tablePrefixToRemove, $shortArrays); $this->output->writeln('---------------------------------'); $this->writeInfo('Database name: <info>%s</info>', Config::getValue('db', 'dbname')); $this->writeInfo('Class name: <info>%s</info>', $modelGenerator->getTemplateClassName()); $this->writeInfo('Class namespace: <info>%s</info>', $modelGenerator->getClassNamespace()); $this->output->writeln('---------------------------------'); $this->output->writeln($modelGenerator->templateContents()); $this->output->writeln('---------------------------------'); if ($fileName) { $this->saveClassToFile($modelGenerator, $fileName); } else { $classFileName = ClassPathResolver::forClassAndNamespace($modelGenerator->getTemplateClassName(), $modelGenerator->getClassNamespace())->getClassFileName(); $this->saveClassToFile($modelGenerator, $classFileName); } } catch (GeneratorException $e) { $this->fail($e->getMessage()); } }
private static function _loadLogger($name, $configuration) { $logger = Config::getValue('logger', $configuration); if (!$logger || !isset($logger['class'])) { return new SyslogLogger($name, $configuration); } return new $logger['class']($name, $configuration); }
public function setUp() { $driver = Config::getValue('db', 'driver'); if ($driver == 'sqlite') { $this->markTestSkipped('This test is not for SQLite database.'); } parent::setUp(); }
private function initialize(Twig_Environment $environment) { $initializerClass = Config::getValue('twig', 'initializer'); if ($initializerClass) { $initializer = new $initializerClass(); $initializer->initialize($environment); } }
/** * @return void */ private function registerErrorHandlers() { if (Config::getValue('debug')) { $handler = new DebugErrorHandler(); } else { $handler = new ErrorHandler(); } $handler->register(); }
/** * @test */ public function shouldCreateCorrectUrlWithExtraParams() { //given $defaults = Config::getValue('global'); //when $url = ControllerUrl::createUrl(array('controller' => 'users', 'action' => 'add', 'extraParams' => array('id' => 5, 'name' => 'john'))); //then $this->assertEquals($defaults['prefix_system'] . '/users/add/id/5/name/john', $url); }
public function __construct($loadDefault = true) { if ($loadDefault) { $configDb = Config::getValue('db'); if (!empty($configDb)) { $this->connectDb($configDb); } } }
private static function _setSavePath() { $path = Config::getValue('session', 'path'); if ($path) { if (!is_dir($path)) { mkdir($path, 0700, true); } session_save_path($path); } }
public static function forException(Exception $exception) { if (Config::getValue('debug')) { return new Error($exception->getCode(), self::_classNameAndMessage($exception)); } if ($exception instanceof UserException) { return new Error($exception->getCode(), $exception->getMessage()); } return new Error($exception->getCode(), I18n::t('exception.unknown'), $exception->getMessage()); }
function addFile(array $fileInfo = array(), $stringToRemove = '') { if (!empty($fileInfo)) { $prefixSystem = Config::getValue('global', 'prefix_system'); $suffixCache = Config::getValue('global', 'suffix_cache'); $suffixCache = !empty($suffixCache) ? '?' . $suffixCache : ''; $url = $prefixSystem . $fileInfo['params']['url'] . $suffixCache; $url = Strings::remove($url, $stringToRemove); return _getHtmlFileTag($fileInfo['type'], $url); } return null; }
/** * @test */ public function shouldResolveAction() { //given $routeRule = new RouteRule('GET', '/simple_test/action1', 'simple_test', 'action1', false); $factory = $this->injector->getInstance('\\Ouzo\\ControllerFactory'); $config = Config::getValue('global'); $_SERVER['REQUEST_URI'] = "{$config['prefix_system']}/simple_test/action1"; //when $currentController = $factory->createController($routeRule); //then $this->assertEquals('action1', $currentController->currentAction); }
/** * @test */ public function shouldReturnObjectForConfiguredDialect() { //given $generator = new Generator('products'); //when $templateDialect = $generator->dialectAdapter(); //then $configuredDialectClassPath = Config::getValue('sql_dialect'); $dialectReflectionClass = new ReflectionClass($templateDialect); $generatorDialectClassName = $dialectReflectionClass->getShortName(); $this->assertStringEndsWith($generatorDialectClassName, $configuredDialectClassPath); }
/** * @return Dialect * @throws Exception */ public static function create() { $dialectClass = Config::getValue('sql_dialect'); if (!$dialectClass) { throw new Exception('SQL dialect was not found in config. Please, check for option - sql_dialect.'); } $dialectClass = new $dialectClass(); if (!$dialectClass instanceof Dialect) { throw new Exception('Invalid sql_dialect. Dialect have to extend Dialect class.'); } return $dialectClass; }
public static function create($viewName, $attributes) { $rendererClass = Config::getValue('renderer', $viewName); if ($rendererClass) { return new $rendererClass($viewName, $attributes); } $rendererClass = Config::getValue('renderer', 'default'); if ($rendererClass) { return new $rendererClass($viewName, $attributes); } return new PhtmlRenderer($viewName, $attributes); }
private function createFunction(RouteRule $routeRule) { $applicationPrefix = Config::getValue("global", "prefix_system"); $name = $routeRule->getName(); $uri = $routeRule->getUri(); $uriWithVariables = preg_replace('/:(\\w+)/', '" + $1 + "', $uri); $parameters = $this->prepareParameters($uri); $parametersString = implode(', ', $parameters); $checkParametersStatement = $this->createCheckParameters($parameters); $function = <<<FUNCTION function {$name}({$parametersString}) { {$checkParametersStatement}return "{$applicationPrefix}{$uriWithVariables}"; } FUNCTION; return $name ? $function : ''; }
private static function _createUrlFromArray($params) { $prefixSystem = Config::getValue('global', 'prefix_system'); $controller = Arrays::getValue($params, 'controller'); $action = Arrays::getValue($params, 'action'); $extraParams = Arrays::getValue($params, 'extraParams'); if ($controller && $action) { $url = Joiner::on('/')->join(array($prefixSystem, $controller, $action)); if ($extraParams) { $url .= self::_mergeParams($extraParams); } return $url; } $string = Arrays::getValue($params, 'string'); if ($string) { return $prefixSystem . $string; } throw new InvalidArgumentException('Illegal arguments'); }
private static function shouldWrap($viewName) { return Config::getValue('debug') && !self::isJavaScriptView($viewName); }
private static function _prefixSystem() { return Config::getValue('global', 'prefix_system'); }
public static function getLayoutPath() { $controllerPath = Config::getValue('path', 'layout'); return $controllerPath ? $controllerPath : Path::join('Application', 'Layout'); }
private function _logRequestIfDebugEnabled() { if (Config::getValue('debug')) { Stats::traceHttpRequest($this->currentControllerObject->params); } }
public static function add($name, $path) { $prefixSystem = Config::getValue('global', 'prefix_system'); $pathWithoutPrefix = $prefixSystem ? Strings::removePrefix($path, $prefixSystem) : $path; self::$breadcrumbsMap[] = new self($name, $pathWithoutPrefix); }
/** * @test */ public function shouldClearProperty() { // given Config::overrideProperty('key_to_clear')->with('value'); // when Config::clearProperty('key_to_clear'); // then $value = Config::getValue('key_to_clear'); $this->assertEmpty($value); }
public static function getWidgetNamespace() { $controllerPath = Config::getValue('namespace', 'widget'); return $controllerPath ? $controllerPath : "\\Application\\Widget\\"; }
} private static function createRouteAction($controller, $action) { return $controller . '#' . $action; } /** * @return RouteRule[] */ public static function getRoutes() { return self::$routes; } public static function getRoutesForController($controller) { return Arrays::filter(self::getRoutes(), function (RouteRule $route) use($controller) { return Strings::equalsIgnoreCase($route->getController(), $controller); }); } public static function group($name, $routeFunction) { GroupedRoute::setGroupName($name); $routeFunction(); } public static function clear() { self::$routes = array(); self::$routeKeys = array(); } } Route::$isDebug = Config::getValue('debug');
/** * @test */ public function shouldThrowOnBatchInsert() { //given $previous = Config::getValue('sql_dialect'); Config::overrideProperty('sql_dialect')->with('Ouzo\\Db\\Dialect\\MySqlDialect'); $inserter = new BatchInserter(); $inserter->add(new Product(array('name' => 'product1'))); //when CatchException::when($inserter)->execute(); //then CatchException::assertThat()->hasMessage("Batch insert not supported in mysql")->isInstanceOf('InvalidArgumentException'); Config::overrideProperty('sql_dialect')->with($previous); }
public function __construct($language, $labels) { $this->_labels = $labels; $this->language = $language; $this->pseudoLocalizationEnabled = Config::getValue('pseudo_localization') ? true : false; }
public static function addPrefixIfNeeded($url) { $prefix = Config::getValue('global', 'prefix_system'); $url = Strings::removePrefix($url, $prefix); return $prefix . $url; }
private static function getLanguage() { return Config::getValue('language') ?: I18n::DEFAULT_LANGUAGE; }
/** * @test */ public function shouldAddCacheSuffix() { //given $defaults = Config::getValue('global'); //when $expected = '<script type="text/javascript" src="' . $defaults['prefix_system'] . '/public/js/test.js?' . $defaults['suffix_cache'] . '"></script>' . PHP_EOL; $actual = addFile(array('type' => 'script', 'params' => array('url' => '/public/js/test.js'))); //then $this->assertEquals($expected, $actual); }