/** * Generate PDF-file of ticket * * @param string $html HTML to generate pdf * @param string $outputFile Name of output file * * @return mixed */ public function generatePdfFile($html, $outputFile) { // Override default fonts directory for mPDF define('_MPDF_SYSTEM_TTFONTS', realpath($this->kernel->getRootDir() . '/../web/fonts/open-sans/') . '/'); /** @var \TFox\MpdfPortBundle\Service\MpdfService $mPDFService */ $mPDFService = $this->container->get('tfox.mpdfport'); $mPDFService->setAddDefaultConstructorArgs(false); $constructorArgs = array('mode' => 'BLANK', 'format' => 'A5-L', 'margin_left' => 0, 'margin_right' => 0, 'margin_top' => 0, 'margin_bottom' => 0, 'margin_header' => 0, 'margin_footer' => 0); $mPDF = $mPDFService->getMpdf($constructorArgs); // Open Sans font settings $mPDF->fontdata['opensans'] = array('R' => 'OpenSans-Regular.ttf', 'B' => 'OpenSans-Bold.ttf', 'I' => 'OpenSans-Italic.ttf', 'BI' => 'OpenSans-BoldItalic.ttf'); $mPDF->sans_fonts[] = 'opensans'; $mPDF->available_unifonts[] = 'opensans'; $mPDF->available_unifonts[] = 'opensansI'; $mPDF->available_unifonts[] = 'opensansB'; $mPDF->available_unifonts[] = 'opensansBI'; $mPDF->default_available_fonts[] = 'opensans'; $mPDF->default_available_fonts[] = 'opensansI'; $mPDF->default_available_fonts[] = 'opensansB'; $mPDF->default_available_fonts[] = 'opensansBI'; $mPDF->SetDisplayMode('fullpage'); $mPDF->WriteHTML($html); $pdfFile = $mPDF->Output($outputFile, 'S'); return $pdfFile; }
private function resolvePath($file) { if (isset($this->config['aliases'][$file]['path'])) { return $this->kernel->getRootDir() . '/../web/' . $this->config['aliases'][$file]['path']; } return $file; }
public function getClassName($path) { $srcDir = realpath(sprintf('%s/../src', $this->kernel->getRootDir())); $className = substr($path, strlen($srcDir) + 1); $className = str_replace('/', '\\', $className); $className = str_replace('.php', '', $className); return $className; }
/** * @param string $filePath * @param \Symfony\Component\HttpFoundation\ServerBag $server * * @return bool */ private function authenticate($filePath, ServerBag $server) { $passFile = $this->kernel->getRootDir() . '/../web/var/export/' . substr($filePath, 0, strrpos($filePath, '/')) . '/.htpasswd'; list($auth['user'], $auth['pass']) = explode(':', file_get_contents($passFile)); $user = $server->get('PHP_AUTH_USER'); $pass = crypt($server->get('PHP_AUTH_PW'), md5($server->get('PHP_AUTH_PW'))); return $user == $auth['user'] && $pass == $auth['pass']; }
/** * @param $filename * @return array */ public function getResource($filename) { $builder = new PathBuilder($this->resourcesDir); $fullPath = $builder->getResourcesPath($this->kernel->getRootDir(), $filename); $role = $builder->getRoleFromPath($fullPath); if ($role != null && false === $this->securityContext->isGranted($role)) { throw new AccessDeniedException(); } if (!file_exists($fullPath)) { throw new FileNotFoundException(sprintf("The file %s was not found", $filename)); } $contentType = MimeType::get($filename); return ['contentType' => $contentType, 'content' => file_get_contents($fullPath)]; }
/** * Read scripts info from files */ protected function loadScripts() { $index = 0; $scripts = []; $this->scripts = []; $rootDir = realpath($this->kernel->getRootDir() . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR); $bundles = $this->kernel->getBundles(); foreach ($bundles as $bundle) { $bundleDirName = $bundle->getPath(); $this->getScriptInfo($bundleDirName, $index, $scripts); $relativePathArray = explode(DIRECTORY_SEPARATOR, str_replace($rootDir, '', $bundleDirName)); if ($relativePathArray[0] == '') { unset($relativePathArray[0]); } for ($i = count($relativePathArray); $i >= 0; $i--) { unset($relativePathArray[$i]); $checkPath = $rootDir . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $relativePathArray); if ($this->getScriptInfo($checkPath, $index, $scripts)) { break; } } } if (!empty($scripts)) { usort($scripts, array($this, "compareScripts")); foreach ($scripts as $script) { $this->scripts[$script['key']] = $script; } } }
/** * Override check for Kernel Root Dir. * Otherwise, the app will misbehave on Heroku. * * @return mixed|string */ public function getRootDir() { if (Utils\HerokuDetector::detected()) { return Utils\HerokuDetector::getSymfonyKernelRoot(); } else { return parent::getRootDir(); } }
/** * Builds a new request object based on the given route. * * @param Route $route Route. * @param string $name Name of the route. * @param array $parameters Parameters of the request * * @return Request */ protected function buildRequest(Route $route, $name = null, array $parameters = array()) { if (null !== $name) { $uri = $this->router->generate($name, $parameters); } else { $uri = $route->getPath(); } return new Request([], [], [], [], [], ['REQUEST_URI' => $uri, 'DOCUMENT_URI' => $uri, 'SCRIPT_FILENAME' => realpath($this->kernel->getRootDir() . '/../web') . $this->baseUrl . '/app.php', 'SCRIPT_NAME' => $this->baseUrl . '/app.php'], null); }
/** * Initialize CodeIgniter system paths and defines * * @param Request $request * * @throws \UnexpectedValueException */ public function setCiPaths(Request $request = null) { if (!$this->isConfigValid()) { throw new \UnexpectedValueException('Bundle configuration is not valid. You need to specify application_path and system_path in config.yml'); } if ($this->pathsInitialized === false) { $scriptFile = $request !== null ? '.' . $request->getBasePath() . $request->getScriptName() : __FILE__; $rootPath = realpath($this->kernel->getRootDir() . '/..'); if ($rootPath === false) { throw new \LogicException('Nercury CI bundle was expecting to find kernel root dir in /app directory.'); } $systemPath = $this->getSystemPath() . '/'; $applicationFolder = $this->getAppPath() . '/'; if ($scriptFile === __FILE__) { $scriptFile = $rootPath . '/app.php'; $rootPath = realpath($rootPath . '/' . $systemPath) . '/'; $applicationFolder = realpath($rootPath . '/' . $applicationFolder); } $environment = $this->kernel->getEnvironment(); $environmentMap = array('dev' => 'development', 'test' => 'testing', 'prod' => 'production'); if (array_key_exists($environment, $environmentMap)) { $environment = $environmentMap[$environment]; } define('ENVIRONMENT', $environment); /* * ------------------------------------------------------------------- * Now that we know the path, set the main path constants * ------------------------------------------------------------------- */ // The name of THIS file define('SELF', pathinfo($scriptFile, PATHINFO_BASENAME)); // The PHP file extension // this global constant is deprecated. define('EXT', '.php'); // Path to the system folder define('BASEPATH', str_replace("\\", "/", $systemPath)); // Name of the "system folder" define('SYSDIR', trim(strrchr(trim(BASEPATH, '/'), '/'), '/')); define('APPPATH', $applicationFolder . '/'); // Path to the front controller (this file) define('FCPATH', $applicationFolder . '../'); // if (!defined('APPPATH')) { // // The path to the "application" folder // if (is_dir($application_folder)) { // define('APPPATH', $application_folder . '/'); // } else { // if (!is_dir(BASEPATH . $application_folder . '/')) { // exit("Your application folder path does not appear to be set correctly. Please open the following file and correct this: " . SELF); // } // // define('APPPATH', BASEPATH . $application_folder . '/'); // } // } $this->pathsInitialized = true; } }
/** * Create HTML template for ticket invitation * * @param Ticket $ticket * * @return string */ public function generateHTML(Ticket $ticket) { $twig = $this->templating; $url = $this->router->generate('event_ticket_registration', array('ticket' => $ticket->getId(), 'hash' => $ticket->getHash()), true); $this->qrCode->setText($url); $this->qrCode->setSize(105); $this->qrCode->setPadding(0); $qrCodeBase64 = base64_encode($this->qrCode->get()); $templateContent = $twig->loadTemplate('StfalconEventBundle:Ticket:_pdf.html.twig'); $body = $templateContent->render(array('ticket' => $ticket, 'qrCodeBase64' => $qrCodeBase64, 'path' => realpath($this->kernel->getRootDir() . '/../web') . '/')); return $body; }
/** * @param string $format ImBundle format string * @param string $path cached path for an external image - ex: http/somepath/somefile.jpg or https/somepath/someotherfile.jpg * * The cached path is equivalent to the original path except that the '://' syntax after the protocol is replaced by a simple "/", to conserve a correct URL encoded string * The Twig tag 'imResize' will automatically make this conversion for you * * @return string */ public function downloadExternalImage($format, $path) { $protocol = substr($path, 0, strpos($path, "/")); $newPath = str_replace($protocol . "/", $this->kernel->getRootDir() . '/../web/cache/im/' . $format . '/' . $protocol . '/', $path); $this->wrapper->checkDirectory($newPath); $fp = fopen($newPath, 'w'); $ch = curl_init(str_replace($protocol . '/', $protocol . '://', $path)); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); fclose($fp); return $newPath; }
/** * Initialize code igniter system paths and defines * * @param Request $request * @throws Exception */ public function setCiPaths(Request $request = null) { if (!$this->isConfigValid()) { throw new \Exception('Code Igniter configuration is not valid.'); } if ($this->paths_initalized === false) { $script_file = $request !== null ? '.' . $request->getBasePath() . $request->getScriptName() : __FILE__; $root_path = realpath($this->kernel->getRootDir() . '/..'); if ($root_path === false) { throw new \LogicException('Nercury CI bundle was expecting to find kernel root dir in /app directory.'); } $system_path = $this->getRelativePath($root_path, $this->getSystemPath()) . '/'; $application_folder = $this->getRelativePath($root_path, $this->getAppPath()); if ($script_file === __FILE__) { $script_file = $root_path . '/app.php'; $system_path = realpath($root_path . '/' . $system_path) . '/'; $application_folder = realpath($root_path . '/' . $application_folder); } /* * ------------------------------------------------------------------- * Now that we know the path, set the main path constants * ------------------------------------------------------------------- */ // The name of THIS file define('SELF', pathinfo($script_file, PATHINFO_BASENAME)); // The PHP file extension // this global constant is deprecated. define('EXT', '.php'); // Path to the system folder define('BASEPATH', str_replace("\\", "/", $system_path)); // Path to the front controller (this file) define('FCPATH', str_replace(SELF, '', __FILE__)); // Name of the "system folder" define('SYSDIR', trim(strrchr(trim(BASEPATH, '/'), '/'), '/')); // The path to the "application" folder if (is_dir($application_folder)) { define('APPPATH', $application_folder . '/'); } else { if (!is_dir(BASEPATH . $application_folder . '/')) { exit("Your application folder path does not appear to be set correctly. Please open the following file and correct this: " . SELF); } define('APPPATH', BASEPATH . $application_folder . '/'); } $this->paths_initalized = true; } }
private function parseCSV($ignoreFirstLine) { $finder = new Finder(); $finder->files()->in($this->kernel->getRootDir() . '/../')->name('*Fundraising.csv'); foreach ($finder as $file) { $csv = $file; } $this->output('Load CSV: ' . $csv->getRealPath()); $rows = array(); if (($handle = fopen($csv->getRealPath(), "r")) !== FALSE) { $i = 0; while (($data = fgetcsv($handle, null, ";")) !== FALSE) { $i++; if ($ignoreFirstLine && $i == 1) { continue; } $rows[] = $data; } fclose($handle); } return $rows; }
/** * @return string */ public function updateJsLib() { $response = $this->kernel->handle(Request::create('/js/fp_js_validator.js')); $libFile = $this->kernel->getRootDir() . '/../../Resources/public/js/fp_js_validator.js'; file_put_contents($libFile, $response->getContent()); }
/** * @param Kernel $kernel */ public function __construct(Kernel $kernel) { $this->webDir = $kernel->getRootDir() . '/../web'; }
/** * Collects information about the Symfony kernel. * * @return Value\SymfonyKernelSystemInfo */ public function collect() { ksort($this->bundles, SORT_FLAG_CASE | SORT_STRING); return new Value\SymfonyKernelSystemInfo(['environment' => $this->kernel->getEnvironment(), 'debugMode' => $this->kernel->isDebug(), 'version' => Kernel::VERSION, 'bundles' => $this->bundles, 'rootDir' => $this->kernel->getRootDir(), 'name' => $this->kernel->getName(), 'cacheDir' => $this->kernel->getCacheDir(), 'logDir' => $this->kernel->getLogDir(), 'charset' => $this->kernel->getCharset()]); }
public function getImgSrcDir() { return realpath(parent::getRootDir() . '/../web/img/src'); }
public function getLogDir() { return parent::getRootDir() . '/../var/logs'; }