public function testVaild()
 {
     $validTrue = UrlSafeBase64::valid('dGVzdA');
     $this->assertTrue($validTrue);
     $validFalse = UrlSafeBase64::valid('test!');
     $this->assertFalse($validFalse);
 }
示例#2
0
 /**
  * Process command to create 404 image and save to target
  * 
  * @param string $target
  * @param string $commands
  * 
  * @return void
  */
 public function process404($target, $commands)
 {
     if (file_exists($target)) {
         return;
     }
     $targetFolder = pathinfo($target, PATHINFO_DIRNAME);
     if (!file_exists($targetFolder)) {
         mkdir($targetFolder, 0777, true);
     }
     $text = 'Not found';
     $backgroundColor = null;
     $color = null;
     $width = null;
     $height = null;
     foreach ($this->analyseCommands($commands) as $command) {
         if ('thumb' === $command['command'] || 'resize' === $command['command']) {
             $width = $command['params'][0];
             $height = $command['params'][1];
         } elseif ('404' === $command['command']) {
             if (isset($command['params'][0]) && UrlSafeBase64::valid($command['params'][0])) {
                 $text = UrlSafeBase64::decode($command['params'][0]);
             }
             if (isset($command['params'][1])) {
                 $backgroundColor = $command['params'][1];
             }
             if (isset($command['params'][2])) {
                 $color = $command['params'][2];
             }
             if (isset($command['params'][3])) {
                 $width = $command['params'][3];
             }
             if (isset($command['params'][4])) {
                 $height = $command['params'][4];
             }
         }
     }
     $this->image404($text, $backgroundColor, $color, $width, $height);
     $this->image->save($target);
 }
示例#3
0
 public function x404($text = null, $backgroundColor = null, $color = null, $width = null, $height = null)
 {
     $this->commands .= '$404' . ($text !== null ? ',' . UrlSafeBase64::encode($text) : '') . ($backgroundColor !== null ? ',' . $backgroundColor : '') . ($color !== null ? ',' . $color : '') . ($width !== null ? ',' . $width : '') . ($height !== null ? ',' . $height : '');
     return $this;
 }