protected function getSettings() { if (!$this->settings) { \Sylma::throwException('No settings defined for device'); } return $this->settings; }
protected function normalizeObject($val, $bEmpty = false) { if ($val instanceof common\_object && !$val instanceof common\argumentable) { \Sylma::throwException(sprintf('Cannot normalize object instance of %s', $val->getInterface()->getName())); } else { if ($val instanceof common\argumentable) { if ($arg = $val->asArgument()) { $mResult = $arg; //$this->normalizeArgument($arg); } else { $mResult = null; } } else { if ($val instanceof common\stringable) { if ($sValue = $val->asString()) { $mResult = $this->normalizeArgument($this->getWindow()->argToInstance($sValue)->asArgument()); } } else { if ($val instanceof common\arrayable) { $mResult = $this->getWindow()->toString($val->asArray()); } else { $mResult = parent::normalizeObject($val, $bEmpty); } } } } return $mResult; }
public function remove() { try { $result = $this->getParent()->removeChild($this); } catch (\DOMException $e) { \Sylma::throwException($e->getMessage()); } return $result; }
function extractDirectory($sFile, $bObject = true) { $sFile = substr($sFile, strlen(getcwd() . MAIN_DIRECTORY) + 1); if (\Sylma::isWindows()) { $sFile = str_replace('\\', '/', $sFile); } $sResult = substr($sFile, 0, strlen($sFile) - strlen(strrchr($sFile, '/'))); if ($bObject) { // object if (!($fs = \Sylma::getManager('fs'))) { Sylma::throwException(sprintf('File controler not yet loaded. Cannot extract path %s', $sFile)); } //echo $fs->getDirectory($sResult); return $fs->getDirectory($sResult); // return \Controler::getDirectory($sResult); } else { // string return $sResult; } }
protected function normalizeObjectUnknown($val, $iMode) { \Sylma::throwException(sprintf('Cannot normalize object @class %s', get_class($val))); }
public function throwException($sMessage, $mSender = array(), $iOffset = 0, array $aVars = array()) { $mSender = (array) $mSender; $mSender[] = '@namespace ' . dom\handler::NS; $mSender[] = $this->asToken(); \Sylma::throwException($sMessage, $mSender, $iOffset + 2, $aVars); }
public function __construct(common\_window $controler, $mContent) { \Sylma::throwException('Must not be used'); $this->setControler($controler); $this->content = $mContent; }
/** * Include classe's file * * @param string $sClass * @param string $sPath * @return bool */ public static function includeClass($sClass, $sPath = '') { $sMain = \Sylma::ROOT; if (!class_exists($sClass, false)) { if (!$sPath) { $sPath = str_replace('\\', '/', $sClass . '.php'); } // include the file $sFile = $sMain . $sPath; if (file_exists($sFile)) { try { require_once $sFile; } catch (core\exception $e) { \Sylma::throwException(sprintf('Cannot load @class %s : %s', $sClass, $e->getMessage()), array('@file ' . $sPath)); } } else { //$this->throwException(sprintf('Cannot load @class %s. @file %s not found !', $sClass, $sFile)); } } return true; }
public function throwException($sMessage, $mSender = array(), $iOffset = 1) { $mSender = (array) $mSender; $mSender[] = '@namespace ' . $this->getNamespace(); \Sylma::throwException($sMessage, $mSender, $iOffset); }
/** * Split a path in an array of keys. Allow use of '..' to get upper levels * * @param string $sPath A relative or absolute path to split * @param? string $sParent The parent path if @param $sPath is relative * * @return array An array of keys */ protected static function parsePath($sPath, $sParent = '') { if ($sPath && $sPath[0] == '/') { $sPath = substr($sPath, 1); } else { if ($sParent) { $sPath = $sParent . '/' . $sPath; } } if (strpos($sPath, '/') !== false) { $aPath = explode('/', $sPath); } else { $aPath = array($sPath); } $aResult = array(); foreach ($aPath as $sSubPath) { if ($sSubPath !== '..') { $aResult[] = $sSubPath; } else { if (!$aResult) { \Sylma::throwException(sprintf('Cannot use .. when current level is root in @path /%s', $sSubPath)); } else { array_pop($aResult); } } } if ($sPath && !$aPath) { $this->throwException(sprintf('Cannot parse path %s', $sPath)); } return $aResult; }
/** * Tmp alias */ protected function launchException($sMessage, array $aVars = array(), array $mSender = array()) { $mSender = (array) $mSender; $mSender[] = '@class ' . get_class($this); \Sylma::throwException($sMessage, $mSender, 3, $aVars); }
/** * Get a copy of the corresponding document * @param integer $iMode : The mode used to load the document */ public function getFreeDocument(array $aNS = array(), $iMode = \Sylma::MODE_READ, $bSecured = false, $bWhitespaces = false) { $result = null; if (!$this->getControler()) { // todo, usefull ? \Sylma::throwException(t('File controler is not ready'), array(), 0); } $this->getControler('dom'); $result = $this->getControler()->create('file/document', array(null, $iMode, array(), $bWhitespaces)); $result->setFile($this); $result->registerNamespaces($aNS); $result->loadFile($bSecured); return $result; }
public function throwException($sMessage, array $aPath = array()) { if ($handler = $this->getHandler(false)) { $handler->throwException($sMessage, $aPath); } else { \Sylma::throwException($sMessage, $aPath); } }
public function runQuery() { $file = $this->getFile($this->read('file')); $creation = new \DateTime($this->read('creation')); $sConnection = $this->read('connection'); $diff = $creation->diff(new \DateTime()); $sContent = preg_replace_callback('/\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}/', function ($aMatch) use($diff) { try { $date = new \DateTime($aMatch[0]); } catch (\Exception $e) { \Sylma::throwException($e->getMessage()); } $new = $date->add($diff); return $new->format('Y-m-d H:i:s'); }, $file->execute()); $this->getManager(self::DB_MANAGER)->getConnection($sConnection)->execute($sContent); return true; }