示例#1
0
    private static function classCode($className, $newConverterPhp, ContentType $destinationContentType, $tempDirectory, $newCommandPhp = null)
    {
        $commandInitialization = null;
        if (!is_null($newCommandPhp)) {
            $newCommandPhp = rtrim($newCommandPhp, ';') . ';';
            $commandInitialization = <<<PHP
\$this->command = {$newCommandPhp}
        \$this->command->configure(\$commandString);
        if (!\$this->command->conforms(\$commandString)) {
            throw new Exception\\AmbiguousPluginCommand(\$commandString);
        }
PHP;
        }
        $converterInitialization = rtrim($newConverterPhp, ';');
        $contentTypeConstructor = "ContentType::byExtention('{$destinationContentType->standardExtension()}')";
        return <<<PHP
<?php
namespace Barberry\\Direction;
use Barberry;
use Barberry\\Exception;
use Barberry\\Plugin;
use Barberry\\ContentType;

class Direction{$className} extends DirectionAbstract {
    protected function init(\$commandString = null) {
        \$this->converter = {$converterInitialization};
        \$this->converter->configure({$contentTypeConstructor}, '{$tempDirectory}');
        {$commandInitialization}
    }
}
PHP;
    }
示例#2
0
 /**
  * @param ContentType $sourceContentType
  * @param ContentType $destinationContentType
  * @param null|string $commandPart
  * @throws \Barberry\Plugin\NotAvailableException
  * @return \Barberry\Plugin\InterfaceConverter
  */
 public function direction(ContentType $sourceContentType, ContentType $destinationContentType, $commandPart = null)
 {
     $directionClassName = 'Barberry\\Direction\\' . 'Direction' . ucfirst($sourceContentType->standardExtension()) . 'To' . ucfirst($destinationContentType->standardExtension());
     if ($destinationContentType == $sourceContentType && !$commandPart) {
         return new Plugin\Null();
     }
     if (class_exists($directionClassName, true)) {
         return new $directionClassName($commandPart);
     }
     throw new Plugin\NotAvailableException($sourceContentType . ' to ' . $destinationContentType);
 }
 public function convert($bin, Plugin\InterfaceCommand $command = null)
 {
     $source = tempnam($this->tempPath, "ooconverter_");
     chmod($source, 0664);
     $destination = $source . '.' . $this->targetContentType->standardExtension();
     file_put_contents($source, $bin);
     $out = exec('python ' . __DIR__ . '/../../../../externals/pyodconverter/DocumentConverter.py ' . "{$source} {$destination}");
     unlink($source);
     if (!is_file($destination)) {
         throw new OpenOfficeException($out);
     }
     $bin = file_get_contents($destination);
     unlink($destination);
     return $bin;
 }
 public function convert($bin, Plugin\InterfaceCommand $command = null)
 {
     $shellCommand = new ShellCommand($command);
     $source = tempnam($this->tempPath, "imagemagick_");
     chmod($source, 0664);
     $destination = $source . '.' . $this->targetContentType->standardExtension();
     file_put_contents($source, $bin);
     exec('convert ' . $source . ' ' . strval($shellCommand) . ' ' . $destination);
     if (is_file($destination)) {
         $bin = file_get_contents($destination);
         unlink($destination);
     }
     unlink($source);
     return $bin;
 }
示例#5
0
 public function getStandardExtension()
 {
     if (is_null($this->standardExtension) && !is_null($this->_bin)) {
         $this->standardExtension = ContentType::byString($this->_bin)->standardExtension();
     }
     return $this->standardExtension;
 }
示例#6
0
 /**
  * @return Response
  * @throws Controller\NotFoundException
  */
 public function DELETE()
 {
     try {
         $this->storage->delete($this->request->id);
     } catch (Storage\NotFoundException $e) {
         throw new Controller\NotFoundException();
     }
     return self::response(ContentType::json(), '{}');
 }
 private function reportOpenOfficeConverter()
 {
     $converter = new Converter();
     $converter->configure(ContentType::pdf(), $this->tempDirectory);
     try {
         $bin = $converter->convert(file_get_contents(__DIR__ . '/../../../../test/data/test.odt'));
     } catch (OpenOfficeException $e) {
         return 'ERROR: Plugin openoffice cannot convert document.';
     }
     return strval(ContentType::pdf()) === strval(ContentType::byString($bin)) ? null : 'ERROR: Plugin openoffice converts to wrong content type.';
 }
示例#8
0
 private static function extractOutputContentType($uri)
 {
     if (preg_match('@\\.([a-z0-9]+)$@i', $uri, $regs)) {
         try {
             return ContentType::byExtention($regs[1]);
         } catch (ContentType\Exception $e) {
         }
     }
     return null;
 }
示例#9
0
 public function testCanDetectOutputContentTypeByContentsOfStorage()
 {
     $this->assertEquals(new Response(ContentType::txt(), '123'), self::c(new Request('/11'), m::mock('Barberry\\Storage\\StorageInterface', array('getById' => '123')))->GET());
 }
 private static function directions()
 {
     return array(array(ContentType::jpeg(), \Barberry\ContentType::gif()), array(ContentType::jpeg(), \Barberry\ContentType::png()), array(ContentType::jpeg(), \Barberry\ContentType::jpeg()), array(ContentType::gif(), \Barberry\ContentType::jpeg()), array(ContentType::gif(), \Barberry\ContentType::png()), array(ContentType::gif(), \Barberry\ContentType::gif()), array(ContentType::png(), \Barberry\ContentType::jpeg()), array(ContentType::png(), \Barberry\ContentType::gif()), array(ContentType::png(), \Barberry\ContentType::png()));
 }
 private static function converter()
 {
     $converter = new Converter();
     return $converter->configure(ContentType::jpeg(), __DIR__ . '/../tmp/');
 }
 private function converter()
 {
     $converter = new Converter();
     return $converter->configure(ContentType::pdf(), $this->tempDir);
 }
示例#13
0
 private static function factory($ext = 'jpg')
 {
     return new Factory(file_get_contents(__FILE__), ContentType::byExtention($ext));
 }
 private static function directions()
 {
     return array(array(ContentType::odt(), '\\Barberry\\ContentType::doc()'), array(ContentType::odt(), '\\Barberry\\ContentType::pdf()'), array(ContentType::ots(), '\\Barberry\\ContentType::xls()'), array(ContentType::ods(), '\\Barberry\\ContentType::xls()'), array(ContentType::ott(), '\\Barberry\\ContentType::doc()'), array(ContentType::ott(), '\\Barberry\\ContentType::pdf()'));
 }