You are here

function phpwkhtmltopdf_requirements_validate_library in PHP WK HTML to PDF 7.2

Verifies a library exists and returns TRUE if successful, calls the $failed_callback and returns its value if the library is not found.

Parameters

string $library_name The library name to verify.:

callback $failed_callback Callback to execute if the library doesn't exist or there was error getting its details.: <code> function($library_name = "", $library_details = array()) { ... } </code>

Return value

array Returns an array suitable for hook_requirements() containing REQUIREMENT_OK if the library exists, else returns the result fo the $failed_callback function.

1 call to phpwkhtmltopdf_requirements_validate_library()
phpwkhtmltopdf_requirements in ./phpwkhtmltopdf.install
Implements hook_requirements().

File

./phpwkhtmltopdf.install, line 42

Code

function phpwkhtmltopdf_requirements_validate_library($library_name, $failed_callback) {

  // Call the Libraries module's detect function to verify the library is loaded and parsed correctly.
  $lib = libraries_detect($library_name);

  // If the library wasn't found at all or the parsing process found errors, trigger the failed callback.
  if (!$lib || !empty($lib['error'])) {

    // Return the results of the failed callback. It should be a suitable format for the hook_requirements function.
    return $failed_callback($library_name, $lib);
  }

  // Everything checks out okay, return a requirement array for this library containing a REQUIREMENT_OK severity.
  return array(
    $library_name => array(
      'title' => $lib['name'],
      'value' => $lib['version'],
      'severity' => REQUIREMENT_OK,
      'description' => '',
    ),
  );
}