public function __construct($sPath = '') { $this->setSettings(\Sylma::get('schema/token')); if ($sPath) { $this->setPath($sPath); } }
public function setPath(array &$aPath, $mValue = null, $bRef = false) { $mCurrent =& $this->aArray; $bNULL = is_null($mValue); do { $sKey = current($aPath); //echo is_object($mCurrent) ? get_class($mCurrent) : print_r($mCurrent); if ($mCurrent instanceof core\argument) { return $mCurrent->setPath($aPath, $mValue, $bRef); } else { if (!is_array($mCurrent)) { $this->launchException("Cannot set value to : " . \Sylma::show($mCurrent), get_defined_vars()); } } if (!array_key_exists($sKey, $mCurrent)) { $mCurrent[$sKey] = array(); } $mPrevious =& $mCurrent; $mCurrent =& $mCurrent[$sKey]; } while (next($aPath) !== false); if (current($aPath) !== false) { $this->throwException(sprintf('Cannot find path "%s" to set value', implode('/', $aPath))); } if ($bNULL) { unset($mPrevious[$sKey]); } else { $mCurrent = $bRef && is_array($mValue) ? $this->createInstance($mValue) : $mValue; } return $mCurrent; }
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 build() { $sSelect = $this->readx('@select'); $sMode = $this->readx('@mode'); if ($sXMode = $this->readx('@xmode')) { $this->getHandler()->startXMode($sXMode); } $aArguments = $this->getTemplate()->parseArguments($this->getNode()->getChildren()); if ($sReflector = $this->readx('@reflector')) { $result = $this->buildReflector($sReflector, $sSelect, $sMode, $aArguments); } else { if ($sImport = $this->readx('@import')) { $result = $this->buildImport($sImport, $sSelect, $sMode, $aArguments); } else { $result = $this->buildDefault($sSelect, $sMode, $sXMode, $aArguments); } } $aResult = $this->getWindow()->parse($result, true); if (\Sylma::read('template/required') && !$result && !$aResult && $this->readx('@required')) { $this->launchException('Apply require a template'); } if ($sXMode) { $this->getHandler()->stopXMode(); } return $aResult; }
public function __construct($sValue) { if (Sylma::read('dom/encoding/check') && !mb_check_encoding($sValue, 'UTF-8')) { //$sValue = utf8_encode($sContent); // TODO , result not always in utf-8 $this->getParent()->throwException('Bad encoding'); } parent::__construct($sValue); }
public function parseRoot(dom\element $el) { $this->loadRootDocument(); $aNS = array(); foreach (\Sylma::get('render/namespaces') as $ns) { $aNS[$ns->read('uri')] = $ns->read('prefix', false); } $this->aNamespaces = $aNS; }
protected function setupDevice() { $args = \Sylma::get(self::DEVICE_SETTINGS); if ($args->read('enable', false)) { $device = $this->create('device'); \Sylma::setManager('device', $device); $device->setSettings($args); } }
public function readScript($sPath, $sUser) { $this->buildScript($sPath); $current = \Sylma::getManager('user'); \Sylma::setManager('user', $this->createUser($sUser)); $result = $this->getScript($sPath); \Sylma::setManager('user', $current); $this->set('result', $result); }
public function __construct() { $this->setDirectory(__FILE__); $this->setArguments(include 'settings.xml.php'); $this->getArguments()->merge(\Sylma::get('users')); $user = $this->createUser(); $user->load(); $this->setUser($user); }
public function remove() { try { $result = $this->getParent()->removeChild($this); } catch (\DOMException $e) { \Sylma::throwException($e->getMessage()); } return $result; }
public function __construct() { $this->setNamespace(self::PARSER_PREFIX, self::PARSER_NS); parent::__construct(); $this->setDirectory(__FILE__); $cache = \Sylma::getManager('fs/cache'); $this->exportDirectory = $cache->getDirectory()->addDirectory((string) $this->getDirectory()); $this->setFiles(array($this->getFile('basic.xml'))); }
public function build(fs\file $file, fs\directory $dir) { if (!\Sylma::isAdmin()) { //$this->throwException('This function is low performance and must not be used in production environnement'); $this->throwException('Unauthorized building access'); } $builder = $this->loadBuilder($file, $dir); $this->aBuilded[] = $file; return $builder->build($dir); }
protected function loadManager($sName, $bDebug = true) { $result = null; if (array_key_exists($sName, $this->aManagers)) { $result = $this->aManagers[$sName]; } else { $result = \Sylma::getManager($sName, $bDebug); } return $result; }
public function asString() { header('Vary: Accept'); if (isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false) { \Sylma::getManager('init')->setHeaderContent('application/json'); } else { \Sylma::getManager('init')->setHeaderContent('text/plain'); } return $this->getSettings()->asJSON(); }
public function __construct() { $this->setDirectory(__FILE__); $this->setNamespaces(array('self' => self::NS, self::PARSER_PREFIX => self::PARSER_NS)); $this->setManager($this->getManager('parser')); $cache = \Sylma::getManager('fs/cache'); $this->exportDirectory = $cache->getDirectory()->addDirectory((string) $this->getDirectory()); $this->setArguments(array()); $this->setFiles(array($this->getFile('basic.xml'))); }
public function checkConfig() { if (\Sylma::read('debug/enable')) { $this->launchException('Cannot test in debug mode'); } if (!$this->login()) { $sUser = implode(':', $this->aUser); $this->launchException("Test need a user authenticated with '{$sUser}'"); } }
public function asDOM() { $aStrings = $this->loadContent(); $result = null; if ($aStrings = $this->loadContent()) { $bChildren = false; $doc = $this->buildDocument($aStrings, \Sylma::read('namespaces/html'), $bChildren); $result = $bChildren ? $doc->getChildren() : $doc->getRoot(); } return $result; }
protected function cleanValid(dom\handler $doc) { require_once 'dom/handler.php'; $cleaner = $this->getTemplate((string) $this->getFile()); $cleaned = $cleaner->parseDocument($doc); $iMode = 0; if (\Sylma::read('initializer/output/indent')) { $iMode = dom\handler::STRING_INDENT; } return $cleaned->asString($iMode); // | dom\handler::STRING_HEAD }
function dsp() { $mArgument = func_get_args(); if (!$mArgument) { $mArgument = 'No message'; } else { if (count($mArgument) == 1) { $mArgument = current($mArgument); } } \Sylma::dsp($mArgument); }
public function importDocument(dom\handler $doc, fs\file $file) { $bElement = \Sylma::read('template/debug/source'); if (!$file->getControler()->getName()) { foreach ($doc->queryx('//*') as $el) { $el->createAttribute('build:source', (string) $file, $this->getNamespace()); if ($bElement) { $el->createAttribute('build:element', $this->getManager('formater')->buildLink($el->asLink()), $this->getNamespace()); } } } return $doc; }
public function asArgument() { $this->setManagers(\Sylma::getManagers()); $args = \Sylma::getSettings(); //$args->set('debug/enable', false); $result = parent::asArgument(); $this->restoreSylma(); $init = $this->getManager('init'); $init->setHeaderContent($init->getMime('html')); //$args->set('debug/enable', true); \Sylma::setSettings($args); return $result; }
public function setCalled($called) { if ($called instanceof common\_var) { $instance = $called->getInstance(); } else { $instance = $called; $called = $this->getControler()->addVar($called); } if (!$instance instanceof _Closure) { $this->getControler()->throwException(sprintf('Cannot call %s', \Sylma::show($called))); } $this->called = $called; }
public function asString() { $init = $this->getManager(); $file = $this->getFile(); if (\Sylma::isAdmin()) { $init->setHeaderCache(0); } else { $iCache = $this->getManager()->read('session/expires'); $init->setHeaderCache($iCache); } $init->setHeaderContent($init->getMime($file->getExtension())); return $file->checkRights(\Sylma::MODE_EXECUTE) ? $file->execute() : $file->read(); }
protected function parseLess(fs\file $file) { $sResult = ''; $less = new Prefixer(); //$less->setImportDir($file->getParent()->getRealPath()); //echo (string) $file->getControler()->getDirectory()->getRealPath(); $less->setImportDir($file->getControler()->getDirectory()->getRealPath()); try { $sResult = $less->compileFile($file->getRealPath()); } catch (\Exception $e) { throw \Sylma::loadException($e); } return $sResult; }
protected function buildContent() { $el = $this->getNode(); if (\Sylma::read('template/debug/source')) { unset($this->aAvoidNamespaces['builder']); } foreach ($el->getAttributes() as $attr) { if (!in_array($attr->getNamespace(), $this->aAvoidNamespaces)) { $sName = $this->buildName($attr->getName(), $attr->getNamespace()); $this->setDefaultAttribute($sName, $attr->getValue()); } } $this->resetAttributes(); parent::buildContent(); }
/** * * @param string $sEmail * @param type $sSubject * @param type $sMessage * @return string */ public function send($sFrom, $sEmail, $sSubject, $sMessage, $bHTML = false) { $sHeaders = "From: {$sFrom}\n"; if ($bHTML) { $sHeaders .= "Content-type: text/html; charset= utf-8\n"; } else { $sHeaders .= 'Content-type: text/plain; charset=utf-8'; } // text if (\Sylma::read('debug/email/enable')) { $sEmail = \Sylma::read('debug/email/default'); } $this->getManager(self::PARSER_MANAGER)->getContext('messages')->add(array('content' => 'Mail sent to ' . $sEmail)); return mail($sEmail, $sSubject, $sMessage, $sHeaders); }
public static function setDevice($sValue) { $aHeader = array(); switch ($sValue) { case 'mobile': $aHeader = self::$aIphone; break; case 'desktop': $aHeader = self::$aUbuntu; break; } if ($aHeader) { \Sylma::getManager('device')->setHttpHeaders($aHeader); } }
public function buildDocument(array $aArray, $sNamespace, &$bChildren = false) { $dom = \Sylma::getManager('dom'); $doc = $dom->create('handler'); $fragment = $doc->createFragment(); $root = $fragment->add($doc->createElement('root', null, array(), $sNamespace)); $this->buildNode($root, $aArray, $sNamespace); if ($root->countChildren() > 1) { $doc->set($root); $bChildren = true; } else { $doc->set($root->getFirst()); } return $doc; }
protected function show($mVar) { $result = $this->createDocument(); $root = $result->addElement('ul', null, array(), \Sylma::read('namespaces/html')); if (is_array($mVar)) { foreach ($mVar as $item) { $root->addElement('li', $this->parseString($item)); } } else { if (is_string($mVar)) { $root->addElement('li', $this->parseString($mVar)); } else { $this->launchException('Cannot show var', get_defined_vars()); } } return $result; }