Ejemplo n.º 1
0
 /**
  * @depends testInstancesCreation
  */
 public function testConfigParser()
 {
     $configParser = new ConfigParser();
     $config = $configParser->parse('200x300');
     $this->assertInstanceOf('happyproff\\Kartinki\\Config', $config);
     $this->assertEquals(200, $config->getWidth());
     $this->assertEquals(300, $config->getHeight());
     $this->assertEquals(false, $config->isFit());
     $config = $configParser->parse('0x1920:fit');
     $this->assertInstanceOf('happyproff\\Kartinki\\Config', $config);
     $this->assertEquals(0, $config->getWidth());
     $this->assertEquals(1920, $config->getHeight());
     $this->assertEquals(true, $config->isFit());
     $config = $configParser->parse('200x0,quality=60');
     $this->assertInstanceOf('happyproff\\Kartinki\\Config', $config);
     $this->assertEquals(200, $config->getWidth());
     $this->assertEquals(0, $config->getHeight());
     $this->assertEquals(false, $config->isFit());
     $this->assertEquals(60, $config->getQuality());
     $config = $configParser->parse('300x250:fit,quality=99');
     $this->assertInstanceOf('happyproff\\Kartinki\\Config', $config);
     $this->assertEquals(300, $config->getWidth());
     $this->assertEquals(250, $config->getHeight());
     $this->assertEquals(true, $config->isFit());
     $this->assertEquals(99, $config->getQuality());
     $config = $configParser->parse('300x250,quality=10,quality=20');
     $this->assertInstanceOf('happyproff\\Kartinki\\Config', $config);
     $this->assertEquals(300, $config->getWidth());
     $this->assertEquals(250, $config->getHeight());
     $this->assertEquals(false, $config->isFit());
     $this->assertEquals(20, $config->getQuality());
     $config = null;
     try {
         $config = $configParser->parse('');
     } catch (\Exception $e) {
         $this->assertInstanceOf('happyproff\\Kartinki\\Exceptions\\InvalidConfigException', $e);
     }
     $this->assertEquals(null, $config);
     try {
         $config = $configParser->parse('wrong');
     } catch (\Exception $e) {
         $this->assertInstanceOf('happyproff\\Kartinki\\Exceptions\\InvalidConfigException', $e);
     }
     $this->assertEquals(null, $config);
     try {
         $config = $configParser->parse('200x300:fit,rotate');
     } catch (\Exception $e) {
         $this->assertInstanceOf('happyproff\\Kartinki\\Exceptions\\InvalidConfigException', $e);
     }
     $this->assertEquals(null, $config);
     try {
         $config = $configParser->parse('200x300:fit,quality');
     } catch (\Exception $e) {
         $this->assertInstanceOf('happyproff\\Kartinki\\Exceptions\\InvalidConfigException', $e);
     }
     $this->assertEquals(null, $config);
 }
Ejemplo n.º 2
0
                $t_type = CONFIG_TYPE_COMPLEX;
            }
        }
    }
} else {
    $t_type = $f_type;
}
# Parse the value
# - Strings are returned as-is
# - Empty values are typecast as appropriate
$t_value = $f_value;
if ($t_type != CONFIG_TYPE_STRING) {
    try {
        if (!empty($f_value)) {
            $t_parser = new ConfigParser($f_value);
            $t_value = $t_parser->parse(ConfigParser::EXTRA_TOKENS_IGNORE);
        }
        switch ($t_type) {
            case CONFIG_TYPE_INT:
                $t_value = (int) $t_value;
                break;
            case CONFIG_TYPE_FLOAT:
                $t_value = (double) $t_value;
                break;
        }
    } catch (Exception $e) {
        error_parameters($f_config_option, $e->getMessage());
        trigger_error(ERROR_CONFIG_OPT_BAD_SYNTAX, ERROR);
    }
}
if ('action_edit' === $f_edit_action) {
Ejemplo n.º 3
0
 private function __construct($sConfig = null)
 {
     $cp = new ConfigParser($sConfig);
     $this->aConfig = $cp->parse();
 }