Skip to content

Commit

Permalink
Critical bug fix: Replace '\\' with DIRECTORY_SEPARATOR
Browse files Browse the repository at this point in the history
  • Loading branch information
ncjoes committed Nov 25, 2016
1 parent 416547d commit c7f64c0
Show file tree
Hide file tree
Showing 5 changed files with 230 additions and 6 deletions.
43 changes: 43 additions & 0 deletions src/PopplerPhp/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,32 @@
use NcJoes\PopplerPhp\Exceptions\PopplerPhpException;
use NcJoes\PopplerPhp\Helpers as H;

/**
* Class Config
*
* @package NcJoes\PopplerPhp
*/
class Config
{
/**
* @var Repository $instance
*/
protected static $instance;

/**
* @param $function
* @param $arguments
*
* @return mixed
*/
public static function __callStatic($function, $arguments)
{
return call_user_func_array([static::getInstance(), $function], $arguments);
}

/**
* @return mixed
*/
public static function getInstance()
{
if (!(static::$instance instanceof Repository))
Expand All @@ -24,11 +41,22 @@ public static function getInstance()
return static::$instance;
}

/**
* @param $key
*
* @return bool
*/
public static function isSet($key)
{
return self::get($key, C::DEFAULT) != C::DEFAULT;
}

/**
* @param $dir
*
* @return mixed|string
* @throws PopplerPhpException
*/
public static function setBinDirectory($dir)
{
$real_path = realpath($dir);
Expand All @@ -45,11 +73,21 @@ public static function setBinDirectory($dir)
throw new PopplerPhpException("Poppler bin directory does not exist: ".$dir);
}

/**
* @return mixed
*/
public static function getBinDirectory()
{
return self::get(C::BIN_DIR, H::parseDirName(realpath(__DIR__.'/../../vendor/bin/poppler')));
}

/**
* @param $dir
* @param bool $new
*
* @return mixed|string
* @throws PopplerPhpException
*/
public static function setOutputDirectory($dir, $new = false)
{
$real_path = $new ? $dir : realpath($dir);
Expand All @@ -66,6 +104,11 @@ public static function setOutputDirectory($dir, $new = false)
throw new PopplerPhpException("Output directory does not exist: ".$dir);
}

/**
* @param mixed $default
*
* @return mixed
*/
public static function getOutputDirectory($default = null)
{
$check = is_dir($default);
Expand Down
4 changes: 2 additions & 2 deletions src/PopplerPhp/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ abstract class Constants
const T_DOUBLE = 'double';

//Directory Helpers
const DS = "\\";
const DS = DIRECTORY_SEPARATOR;
const BIN_DIR = 'ncjoes.poppler-php.bin_dir';
const OUTPUT_DIR = 'ncjoes.poppler-php.output_dir';
const OUTPUT_NAME = 'ncjoes.poppler-php.output_name';

//Config Helpers
const DEFAULT = '_d_';
}
}
4 changes: 2 additions & 2 deletions src/PopplerPhp/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public static function parseFileName($name)

public static function parseFileRealPath($dir)
{
$dir = str_replace('/', C::DS, $dir);
$dir = str_replace('\\', C::DS, $dir);

return $dir;
}

}
}
55 changes: 54 additions & 1 deletion src/PopplerPhp/PdfToCairo.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,38 @@
use NcJoes\PopplerPhp\PopplerOptions\HelpFlags;
use NcJoes\PopplerPhp\PopplerOptions\PageRangeOptions;

/**
* Class PdfToCairo
*
* @package NcJoes\PopplerPhp
*/
class PdfToCairo extends PopplerUtil
{
use CairoOptions;
use PageRangeOptions;
use HelpFlags;

/**
* @var string $format
*/
protected $format;

/**
* PdfToCairo constructor.
*
* @param string $pdfFile
* @param array $options
*/
public function __construct($pdfFile = '', array $options = [])
{
$this->bin_file = C::PDF_TO_CAIRO;

return parent::__construct($pdfFile, $options);
}

/**
* @return array
*/
public function utilOptions()
{
return array_merge(
Expand All @@ -37,6 +54,9 @@ public function utilOptions()
);
}

/**
* @return array
*/
public function utilFlags()
{
return array_merge(
Expand All @@ -46,41 +66,59 @@ public function utilFlags()
);
}

/**
* @return array
*/
public function utilOptionRules()
{
return [
'alt' => [],
];
}

/**
* @return array
*/
public function utilFlagRules()
{
return [
'alt' => [],
];
}

/**
* @return string
*/
public function generatePNG()
{
$this->setOutputFormat(C::_PNG);

return $this->generate();
}

/**
* @return string
*/
public function generateJPG()
{
$this->setOutputFormat(C::_JPEG);

return $this->generate();
}

/**
* @return string
*/
public function generateTIFF()
{
$this->setOutputFormat(C::_TIFF);

return $this->generate();
}

/**
* @return string
*/
public function generatePS()
{
$this->setOutputFormat(C::_PS);
Expand All @@ -89,6 +127,9 @@ public function generatePS()
return $this->generate();
}

/**
* @return string
*/
public function generateEPS()
{
$this->setOutputFormat(C::_EPS);
Expand All @@ -97,13 +138,19 @@ public function generateEPS()
return $this->generate();
}

/**
* @return string
*/
public function generatePDF()
{
$this->setOutputFormat(C::_PDF);

return $this->generate();
}

/**
* @return string
*/
public function generateSVG()
{
$this->setOutputFormat(C::_SVG);
Expand All @@ -112,11 +159,17 @@ public function generateSVG()
return $this->generate();
}

/**
* @return string
*/
public function generate()
{
return $this->shellExec();
}

/**
* @return string
*/
public function outputExtension()
{
$dot = '.';
Expand Down Expand Up @@ -147,4 +200,4 @@ public function outputExtension()

return $dot.$extension;
}
}
}
Loading

0 comments on commit c7f64c0

Please sign in to comment.