<?php
/**
* DB version manager
*
* Copyright (c) 2011 Przemek Berezowski (hide@address.com)
* All rights reserved.
*
*
* @category Library
* @package DBVersionManager
* @copyright Copyright (c) 2011 Przemek Berezowski (hide@address.com)
* @version 0.9
* @license New BSD License
*/
/**
* Class Tools
*
* @author pberezowski
*
*/
class Tools {
/**
*
* Reads the file as XML
* @param string $path
* @return SimpleXMLElement
*/
public static function readXml($path) {
$oXml = simplexml_load_file($path);
if ($oXml instanceof SimpleXMLElement) {
return $oXml;
}
Throw new UpdaterException('Could not load xml file from:'.$path);
}
/**
*
* Returns current execution script path
*/
public static function getProjectPath() {
$path = dirname($_SERVER['SCRIPT_FILENAME']);
return $path;
}
/**
* Read the list of files in given directory
* @param string $path
* @return array
* @throws UpdaterException
*/
public static function readDir($path) {
$oDir = dir($path);
if (!oDir) {
Throw new UpdaterException('Could not read directory: '.$path);
}
$paths = array();
while (false !== ($filename = $oDir->read())){
if (is_file($path . '/' . $filename)){
$paths[] = $filename;
}
}
return $paths;
}
/**
* Prints given variable
* @param mixed $what
*/
public static function dump($what) {
echo "<pre>";
print_r($what);
echo "</pre>";
}
}