/** * Configures this container. * * @param TempFile $document The html file we will convert. * * @param array $config Further configuration for this container. */ public function __construct(TempFile $document, $config = []) { parent::__construct($config); $this->document = $document; }
/** * Method: __construct * ========================================================================= * Here we configure ourselves and then make sure the cache folder exists. * * Example usage: * * ```php * $view = new Gears\View('/path/to/my/views'); * echo $view->make('master'); * ``` * * > NOTE: If you want to provide a custom cache path. It must be injected * > into the constructor. As we check that it exists at construction time. * * For example the following will not work: * * ```php * $view = new Gears\View('/path/to/my/views'); * $view->cachePath = '/custom/cache/path'; * ``` * * But this will work as expected: * * ```php * $view = new Gears\View('/path/to/my/views', * [ * 'cachePath' => '/custom/cache/path' * ]); * ``` * * Parameters: * ------------------------------------------------------------------------- * n/a * * Returns: * ------------------------------------------------------------------------- * void * * Throws: * ------------------------------------------------------------------------- * - RuntimeException: When the cache path is not writeable or * we can not create the folder if it doesn't exist. */ public function __construct($viewsPath, $config = []) { parent::__construct($config); if (is_array($viewsPath)) { $this->viewsPath = $viewsPath; } else { $this->viewsPath = [$viewsPath]; } // Make sure the cache folder exists if (!is_dir($this->cachePath)) { // Lets attempt to create the folder if (!mkdir($this->cachePath, 0777, true)) { // Bail out we couldn't create the folder throw new RuntimeException('Blade Cache Folder could not be created!'); } } // Make sure the cache folder is writeable if (!is_writeable($this->cachePath)) { throw new RuntimeException('Blade Cache Folder not writeable!'); } }
/** * Performs some intial Setup. * * @param string $document This is either a filepath to a docx or html file. * Or it may be a HTML string. The HTML string must * contain a valid DOCTYPE. * * @param array $config Further configuration for the di container. * * @throws RuntimeException When not of the correct document type. */ public function __construct($document, $config = []) { // Configure the container parent::__construct($config); // Is the document a file if (is_file($document)) { // So that the save method can save the PDF in the same folder as // the original source document we need a refrence to it. $this->originalDocument = $this->file($document); // Grab the files extension $ext = $this->originalDocument->getExtension(); if ($ext !== 'docx' && $ext !== 'html') { throw new RuntimeException('Must be a DOCX or HTML file.'); } $this->documentType = $ext; // Save the document to a new temp file // In the case of DOCX files we may make changes to the document // before converting to PDF so to keep the API consitent lets create // a the temp file now. $this->document = $this->tempFile(file_get_contents($document), $ext); } elseif (Str::contains($document, 'DOCTYPE')) { // Again lets save a temp file $this->document = $this->tempFile($document, 'html'); $this->documentType = 'html'; } else { throw new RuntimeException('Unrecognised document type!'); } // Now create a new backend $class = '\\Gears\\Pdf\\' . ucfirst($this->documentType) . '\\Backend'; $this->backend = new $class($this->document, $config); }
/** * Configures this container. * * @param TempFile $document The docx file we will convert. * * @param array $config Further configuration for this container. */ public function __construct(TempFile $document, $config = []) { parent::__construct($config); $this->template = $document; $this->readDocx(); }