Пример #1
0
 public function __construct($config, $url = null)
 {
     if ($config instanceof Config\Config) {
         $config = $config;
     } else {
         $config = new Config\Config($config);
     }
     $this->url = $url = new Url($url);
     $configKey = $url->getUrlKey();
     $defaultConfig = $config->thumbers->current();
     $defaultKey = $config->thumbers->key();
     if (isset($config->thumbers->{$configKey})) {
         if ($defaultKey == $configKey) {
             $this->config = $config->thumbers->{$configKey};
         } else {
             $this->config = $defaultConfig->merge($config->thumbers->{$configKey});
         }
     } else {
         throw new Exception\InvalidArgumentException(sprintf('No config found by key %s', $configKey));
     }
 }
Пример #2
0
 public function testGetUrlKey()
 {
     $url = new Url('http://localhost/EvaThumber/index.php/thumb/d/demo.jpg');
     $url->setUrlScriptName('/EvaThumber/index.php');
     $this->assertEquals('d', $url->getUrlKey());
     $url = new Url('http://localhost/EvaThumber/thumb/d/demo.jpg');
     $url->setUrlScriptName('/EvaThumber/index.php');
     $this->assertEquals('d', $url->getUrlKey());
     $url = new Url('http://localhost/');
     $this->assertEquals('', $url->getUrlKey());
     $url = new Url('http://localhost/thumb');
     $this->assertEquals('', $url->getUrlKey());
     $url = new Url('http://localhost/thumb/');
     $this->assertEquals('', $url->getUrlKey());
     $url = new Url('http://localhost/thumb/d');
     $this->assertEquals('', $url->getUrlKey());
     $url = new Url('http://localhost/thumb/d/');
     $this->assertEquals('d', $url->getUrlKey());
     $url = new Url('http://localhost/thumb/d/foo/bar/demo.jpg');
     $this->assertEquals('d', $url->getUrlKey());
 }