You are here

Utility.php in Views PDF 8

File

src/Share/Utility.php
View source
<?php

/**
 * @file
 * Contains \Drupal\views_pdf\Share\Utility
 */
namespace Drupal\views_pdf\Share;

trait Utility {

  /**
   * Create a new reflection class.
   *
   * @param string $class Class name string
   *
   * @return \ReflectionClass|NULL
   */
  private static function reflectionClass(string $class) {
    $reflection = NULL;
    try {
      $reflection = new \ReflectionClass($class);
    } catch (\ReflectionException $e) {
      \Drupal::logger('views_pdf')
        ->error($e
        ->getMessage());
    }
    return $reflection;
  }

  /**
   * Help to get the TCPDF path.
   *
   * @return string
   */
  protected static function getPathTcpdf() {
    $tcpdfPath = self::reflectionClass(\TCPDF::class);
    return $tcpdfPath !== NULL ? dirname($tcpdfPath
      ->getFileName()) : '';
  }

  /**
   * Help to get the Fonts path from TCPDF.
   *
   * @return string
   */
  protected static function getKPathFonts() {
    $tcpdfPath = self::getPathTcpdf();
    return !empty($tcpdfPath) ? $tcpdfPath . '/fonts/' : '';
  }

}

Traits

Namesort descending Description
Utility