.State 0000666 00000000005 13371317251 0005627 0 ustar 00 beta
.gitignore 0000666 00000000030 13371317251 0006534 0 ustar 00 /vendor/
/composer.lock
CHANGELOG.md 0000666 00000001404 13371317251 0006363 0 ustar 00 # 1.17.01.10
* Quality: Happy new year! (Alexis von Glasow, 2017-01-09T23:56:56+01:00)
* Documentation: New `README.md` file. (Ivan Enderlin, 2016-10-22T17:36:15+02:00)
* Documentation: Update `support` properties. (Ivan Enderlin, 2016-10-11T11:41:21+02:00)
# 1.16.03.15
* Parameter: Fix API documentation, namings… (Metalaka, 2016-01-16T08:02:35+01:00)
# 1.16.01.14
* Quality: Drop PHP5.4. (Ivan Enderlin, 2016-01-11T09:15:27+01:00)
* Quality: Run devtools:cs. (Ivan Enderlin, 2016-01-09T09:12:47+01:00)
* Core: Remove `Hoa\Core`. (Ivan Enderlin, 2016-01-09T08:34:03+01:00)
* Consistency: Remove the flexible entity. (Ivan Enderlin, 2016-01-09T07:47:57+01:00)
* Split from `Hoa\Core`. (Ivan Enderlin, 2016-01-09T07:45:36+01:00)
(first snapshot)
Exception.php 0000666 00000003612 13371317251 0007224 0 ustar 00 implementsInterface('\Hoa\Zformat\Parameterizable')) {
throw new Exception(
'Only parameterizable object can have parameter; ' .
'%s does implement \Hoa\Zformat\Parameterizable.',
1,
$owner
);
}
}
$this->_owner = $owner;
$this->setKeywords($keywords);
$this->setDefault($parameters);
return;
}
/**
* Initialize constants.
*
* @return void
*/
public static function initializeConstants()
{
$c = explode('…', date('d…j…N…w…z…W…m…n…Y…y…g…G…h…H…i…s…u…O…T…U'));
self::$_constants = [
'd' => $c[0],
'j' => $c[1],
'N' => $c[2],
'w' => $c[3],
'z' => $c[4],
'W' => $c[5],
'm' => $c[6],
'n' => $c[7],
'Y' => $c[8],
'y' => $c[9],
'g' => $c[10],
'G' => $c[11],
'h' => $c[12],
'H' => $c[13],
'i' => $c[14],
's' => $c[15],
'u' => $c[16],
'O' => $c[17],
'T' => $c[18],
'U' => $c[19]
];
return;
}
/**
* Get constants.
*
* @return array
*/
public static function getConstants()
{
return self::$_constants;
}
/**
* Set default parameters to a class.
*
* @param array $parameters Parameters to set.
* @return void
* @throws \Hoa\Zformat\Exception
*/
private function setDefault(array $parameters)
{
$this->_parameters = $parameters;
return;
}
/**
* Set parameters.
*
* @param array $parameters Parameters.
* @return void
*/
public function setParameters(array $parameters)
{
$this->resetCache();
foreach ($parameters as $key => $value) {
$this->setParameter($key, $value);
}
return;
}
/**
* Get parameters.
*
* @return array
*/
public function getParameters()
{
return $this->_parameters;
}
/**
* Set a parameter.
*
* @param string $key Key.
* @param mixed $value Value.
* @return mixed
*/
public function setParameter($key, $value)
{
$this->resetCache();
$old = null;
if (true === array_key_exists($key, $this->_parameters)) {
$old = $this->_parameters[$key];
}
$this->_parameters[$key] = $value;
return $old;
}
/**
* Get a parameter.
*
* @param string $parameter Parameter.
* @return mixed
*/
public function getParameter($parameter)
{
if (array_key_exists($parameter, $this->_parameters)) {
return $this->_parameters[$parameter];
}
return null;
}
/**
* Get a formatted parameter (i.e. zFormatted).
*
* @param string $parameter Parameter.
* @return mixed
*/
public function getFormattedParameter($parameter)
{
if (null === $value = $this->getParameter($parameter)) {
return null;
}
return $this->zFormat($value);
}
/**
* Check a branch exists.
*
* @param string $branch Branch.
* @return bool
*/
public function branchExists($branch)
{
$qBranch = preg_quote($branch);
foreach ($this->getParameters() as $key => $value) {
if (0 !== preg_match('#^' . $qBranch . '(.*)?#', $key)) {
return true;
}
}
return false;
}
/**
* Unlinearize a branch to an array.
*
* @param string $branch Branch.
* @return array
*/
public function unlinearizeBranch($branch)
{
$parameters = $this->getParameters();
$out = [];
$lBranch = strlen($branch);
foreach ($parameters as $key => $value) {
if ($branch !== substr($key, 0, $lBranch)) {
continue;
}
$handle = [];
$explode = preg_split(
'#((?= 0) {
$explode[$i] = str_replace('\\.', '.', $explode[$i]);
if ($i != $end) {
$handle = [$explode[$i] => $handle];
} else {
$handle = [$explode[$i] => $this->zFormat($value)];
}
--$i;
}
$out = array_merge_recursive($out, $handle);
}
return $out;
}
/**
* Set keywords.
*
* @param array $keywords Keywords.
* @return void
* @throws \Hoa\Zformat\Exception
*/
public function setKeywords($keywords)
{
$this->resetCache();
foreach ($keywords as $key => $value) {
$this->setKeyword($key, $value);
}
return;
}
/**
* Get keywords.
*
* @return array
*/
public function getKeywords()
{
return $this->_keywords;
}
/**
* Set a keyword.
*
* @param string $key Key.
* @param mixed $value Value.
* @return mixed
*/
public function setKeyword($key, $value)
{
$this->resetCache();
$old = null;
if (true === array_key_exists($key, $this->_keywords)) {
$old = $this->_keywords[$key];
}
$this->_keywords[$key] = $value;
return $old;
}
/**
* Get a keyword.
*
* @param string $keyword Keyword.
* @return mixed
*/
public function getKeyword($keyword)
{
if (true === array_key_exists($keyword, $this->_keywords)) {
return $this->_keywords[$keyword];
}
return null;
}
/**
* zFormat a string.
* zFormat is inspired from the famous Zsh (please, take a look at
* http://zsh.org), and specifically from ZStyle.
*
* ZFormat has the following pattern:
* (:subject[:format]:)
*
* where subject could be a:
* • keyword, i.e. a simple string: foo;
* • reference to an existing parameter, i.e. a simple string prefixed by
* a %: %bar;
* • constant, i.e. a combination of chars, first is prefixed by a _: _Ymd
* will given the current year, followed by the current month and
* finally the current day.
*
* and where the format is a combination of chars, that apply functions on
* the subject:
* • h: to get the head of a path (equivalent to dirname);
* • t: to get the tail of a path (equivalent to basename);
* • r: to get the path without extension;
* • e: to get the extension;
* • l: to get the result in lowercase;
* • u: to get the result in uppercase;
* • U: to get the result with the first letter in uppercase (understand
* classname);
* • s/
Hoa is a modular, extensible and
structured set of PHP libraries.
Moreover, Hoa aims at being a bridge between industrial and research worlds.