Beispiel #1
0
 public static function trace($query, $params, $function)
 {
     if (Config::getValue('debug')) {
         return self::traceNoCheck($query, $params, $function);
     }
     return $function();
 }
 public function tearDown()
 {
     parent::tearDown();
     Config::clearProperty('namespace', 'controller');
     Config::clearProperty('debug');
     Config::clearProperty('callback', 'afterControllerInit');
 }
 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());
     }
 }
Beispiel #4
0
 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);
 }
 protected function tearDown()
 {
     Config::revertProperty("global", "prefix_system");
     if (Files::exists($this->path)) {
         unlink($this->path);
     }
     parent::tearDown();
 }
Beispiel #6
0
 public function setUp()
 {
     $driver = Config::getValue('db', 'driver');
     if ($driver == 'sqlite') {
         $this->markTestSkipped('This test is not for SQLite database.');
     }
     parent::setUp();
 }
Beispiel #7
0
 private function initialize(Twig_Environment $environment)
 {
     $initializerClass = Config::getValue('twig', 'initializer');
     if ($initializerClass) {
         $initializer = new $initializerClass();
         $initializer->initialize($environment);
     }
 }
Beispiel #8
0
 /**
  * @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);
 }
Beispiel #9
0
 public function __construct($loadDefault = true)
 {
     if ($loadDefault) {
         $configDb = Config::getValue('db');
         if (!empty($configDb)) {
             $this->connectDb($configDb);
         }
     }
 }
Beispiel #10
0
 /**
  * @return void
  */
 private function registerErrorHandlers()
 {
     if (Config::getValue('debug')) {
         $handler = new DebugErrorHandler();
     } else {
         $handler = new ErrorHandler();
     }
     $handler->register();
 }
Beispiel #11
0
 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());
 }
Beispiel #12
0
 /**
  * @test
  */
 public function shouldGetErrorWithClassForDebug()
 {
     //given
     Config::overrideProperty('debug')->with(true);
     $userException = new UserException('Winter is coming!');
     //when
     $error = Error::forException($userException);
     //then
     $this->assertEquals('Ouzo\\UserException: Winter is coming!', $error->message);
 }
 /**
  * @test
  */
 public function shouldCreateRendererAsSetInConfigurationForParticularViewEvenThoughDefaultRendererIsSpecified()
 {
     //given
     Config::overrideProperty('renderer', 'default')->with('DefaultRenderer');
     Config::overrideProperty('renderer', 'my_view')->with('DummyRenderer');
     //when
     $renderer = ViewRendererFactory::create('my_view', array());
     //then
     $this->assertInstanceOf('DummyRenderer', $renderer);
 }
Beispiel #14
0
 /**
  * @test
  */
 public function shouldThrowExceptionForNonExistingLanguage()
 {
     //given
     Config::overrideProperty('language')->with('xx');
     $i18n = new I18n();
     //when
     CatchException::when($i18n)->t('product.description');
     //then
     CatchException::assertThat()->isInstanceOf('Exception');
 }
Beispiel #15
0
 private static function _setSavePath()
 {
     $path = Config::getValue('session', 'path');
     if ($path) {
         if (!is_dir($path)) {
             mkdir($path, 0700, true);
         }
         session_save_path($path);
     }
 }
 /**
  * @test
  */
 public function shouldCreateProperSqlForSqlite()
 {
     //given
     Config::overrideProperty('sql_dialect')->with('\\Ouzo\\Db\\Dialect\\Sqlite3Dialect');
     $restriction = Restrictions::regexp('value');
     //when
     $sql = $restriction->toSql('key');
     //then
     $this->assertEquals('key REGEXP ?', $sql);
     $this->assertEquals(array('value'), $restriction->getValues());
 }
Beispiel #17
0
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 shouldThrowConnectionExceptionFromForPostgres()
 {
     //given
     Config::overrideProperty('sql_dialect')->with('\\Ouzo\\Db\\Dialect\\PostgresDialect');
     Mock::when($this->pdoMock)->errorInfo()->thenReturn(array('57P01', 7, 'Execution error'));
     $executor = StatementExecutor::prepare($this->dbMock, 'SELECT 1', array(), array());
     //when
     CatchException::when($executor)->execute();
     //then
     CatchException::assertThat()->isInstanceOf('\\Ouzo\\DbConnectionException');
     Config::revertProperty('sql_dialect');
 }
Beispiel #20
0
 /**
  * @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;
 }
Beispiel #21
0
 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);
 }
Beispiel #22
0
    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 : '';
    }
Beispiel #23
0
 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');
 }
Beispiel #24
0
 private static function getLanguage()
 {
     return Config::getValue('language') ?: I18n::DEFAULT_LANGUAGE;
 }
Beispiel #25
0
 /**
  * @test
  */
 public function shouldIgnoreDebugMessageIfDebugIsOff()
 {
     //given
     Config::overrideProperty('debug')->with(false);
     //when
     $this->logger->debug('My debug log line without params.');
     //then
     $logContent = $this->_readStreamContent('test://stdout');
     Assert::thatString($logContent)->hasSize(0);
 }
Beispiel #26
0
 public static function getLayoutPath()
 {
     $controllerPath = Config::getValue('path', 'layout');
     return $controllerPath ? $controllerPath : Path::join('Application', 'Layout');
 }
Beispiel #27
0
 public function __construct($language, $labels)
 {
     $this->_labels = $labels;
     $this->language = $language;
     $this->pseudoLocalizationEnabled = Config::getValue('pseudo_localization') ? true : false;
 }
Beispiel #28
0
 private static function _prefixSystem()
 {
     return Config::getValue('global', 'prefix_system');
 }
Beispiel #29
0
 /**
  * @test
  * @dataProvider malformedSlashes
  * @param string $broken
  * @param string $good
  */
 public function shouldReplaceTwoBackSlashes($broken, $good)
 {
     //given
     $this->_path(Config::getPrefixSystem() . $broken);
     //when
     $path = $this->uri->getPathWithoutPrefix();
     //then
     $this->assertEquals($good, $path);
 }
Beispiel #30
0
 private static function shouldWrap($viewName)
 {
     return Config::getValue('debug') && !self::isJavaScriptView($viewName);
 }