repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Translation/src/translation.php | ezcTranslation.parameterCallback | private function parameterCallback( $key, array $params )
{
if ( !isset( $params[strtolower( $key )] ) )
{
throw new ezcTranslationParameterMissingException( $key );
}
$string = $params[strtolower( $key )];
// We use ctype_upper() here to check if the first character of the key
// is an uppercase letter. If it is then we make the first character of
// the returned translation also an upper case character. With this
// mechanism we can correctly upper case translated strings if word
// order changes. See
// {@link ezcTranslationTest::testGetStringWithParameters} for an
// example of this.
if ( ctype_upper( $key[0] ) )
{
$string = ucfirst( $string );
}
return $string;
} | php | private function parameterCallback( $key, array $params )
{
if ( !isset( $params[strtolower( $key )] ) )
{
throw new ezcTranslationParameterMissingException( $key );
}
$string = $params[strtolower( $key )];
// We use ctype_upper() here to check if the first character of the key
// is an uppercase letter. If it is then we make the first character of
// the returned translation also an upper case character. With this
// mechanism we can correctly upper case translated strings if word
// order changes. See
// {@link ezcTranslationTest::testGetStringWithParameters} for an
// example of this.
if ( ctype_upper( $key[0] ) )
{
$string = ucfirst( $string );
}
return $string;
} | [
"private",
"function",
"parameterCallback",
"(",
"$",
"key",
",",
"array",
"$",
"params",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"params",
"[",
"strtolower",
"(",
"$",
"key",
")",
"]",
")",
")",
"{",
"throw",
"new",
"ezcTranslationParameterMissingException",
"(",
"$",
"key",
")",
";",
"}",
"$",
"string",
"=",
"$",
"params",
"[",
"strtolower",
"(",
"$",
"key",
")",
"]",
";",
"// We use ctype_upper() here to check if the first character of the key",
"// is an uppercase letter. If it is then we make the first character of",
"// the returned translation also an upper case character. With this",
"// mechanism we can correctly upper case translated strings if word",
"// order changes. See",
"// {@link ezcTranslationTest::testGetStringWithParameters} for an",
"// example of this.",
"if",
"(",
"ctype_upper",
"(",
"$",
"key",
"[",
"0",
"]",
")",
")",
"{",
"$",
"string",
"=",
"ucfirst",
"(",
"$",
"string",
")",
";",
"}",
"return",
"$",
"string",
";",
"}"
] | Returns the replacement for the key $key from the parameters $params.
The params array is an associative array in the form array('key'=>'value').
This is a callback function used by the getTranslation() method for each
matched parameter in the translated string.
@param string $key
@param array $params
@return string | [
"Returns",
"the",
"replacement",
"for",
"the",
"key",
"$key",
"from",
"the",
"parameters",
"$params",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Translation/src/translation.php#L64-L83 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Translation/src/translation.php | ezcTranslation.getTranslation | public function getTranslation( $key, array $params = array() )
{
if ( !isset( $this->translationMap[$key] ) )
{
throw new ezcTranslationKeyNotAvailableException( $key );
}
$translatedString = $this->translationMap[$key]->translation;
// Little optimization to prevent preg if not needed, it bails out too
// if there is just a percent sign in the string without a valid
// parameter-identifier, but we can live with that.
if ( strstr( $translatedString, '%' ) === false )
{
return $translatedString;
}
// So we do have a possibility of a parameterized string, replace those
// with the parameters. The callback function can actually throw an
// exception to tell that there was a missing parameter.
return (string) preg_replace( '@%(([A-Za-z][a-z_]*[a-z])|[1-9])@e', '$this->parameterCallback("\\1", $params)', $translatedString );
} | php | public function getTranslation( $key, array $params = array() )
{
if ( !isset( $this->translationMap[$key] ) )
{
throw new ezcTranslationKeyNotAvailableException( $key );
}
$translatedString = $this->translationMap[$key]->translation;
// Little optimization to prevent preg if not needed, it bails out too
// if there is just a percent sign in the string without a valid
// parameter-identifier, but we can live with that.
if ( strstr( $translatedString, '%' ) === false )
{
return $translatedString;
}
// So we do have a possibility of a parameterized string, replace those
// with the parameters. The callback function can actually throw an
// exception to tell that there was a missing parameter.
return (string) preg_replace( '@%(([A-Za-z][a-z_]*[a-z])|[1-9])@e', '$this->parameterCallback("\\1", $params)', $translatedString );
} | [
"public",
"function",
"getTranslation",
"(",
"$",
"key",
",",
"array",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"translationMap",
"[",
"$",
"key",
"]",
")",
")",
"{",
"throw",
"new",
"ezcTranslationKeyNotAvailableException",
"(",
"$",
"key",
")",
";",
"}",
"$",
"translatedString",
"=",
"$",
"this",
"->",
"translationMap",
"[",
"$",
"key",
"]",
"->",
"translation",
";",
"// Little optimization to prevent preg if not needed, it bails out too",
"// if there is just a percent sign in the string without a valid",
"// parameter-identifier, but we can live with that.",
"if",
"(",
"strstr",
"(",
"$",
"translatedString",
",",
"'%'",
")",
"===",
"false",
")",
"{",
"return",
"$",
"translatedString",
";",
"}",
"// So we do have a possibility of a parameterized string, replace those",
"// with the parameters. The callback function can actually throw an",
"// exception to tell that there was a missing parameter.",
"return",
"(",
"string",
")",
"preg_replace",
"(",
"'@%(([A-Za-z][a-z_]*[a-z])|[1-9])@e'",
",",
"'$this->parameterCallback(\"\\\\1\", $params)'",
",",
"$",
"translatedString",
")",
";",
"}"
] | Returns the translated version of the original string $key.
This method returns a translated string and substitutes the parameters $param
in the localized string.
@throws ezcTranslationKeyNotAvailableException when the key is not
available in the translation definitions
@throws ezcTranslationParameterMissingException when not enough
parameters are passed for a parameterized string
@param string $key
@param array(string=>string) $params
@return string | [
"Returns",
"the",
"translated",
"version",
"of",
"the",
"original",
"string",
"$key",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Translation/src/translation.php#L99-L117 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Translation/src/translation.php | ezcTranslation.parameterCallbackCompile | private function parameterCallbackCompile( $key, array $params )
{
if ( !isset( $params[strtolower( $key )] ) )
{
throw new ezcTranslationParameterMissingException( $key );
}
// We use ctype_upper() here to check if the first character of the key
// is an uppercase letter. If it is then we make the first character of
// the returned translation also an upper case character. With this
// mechanism we can correctly upper case translated strings if word
// order changes. See
// {@link ezcTranslationTest::testGetStringWithParameters} for an
// example of this.
if ( ctype_upper( $key[0] ) )
{
$string = "' . ucfirst(". $params[strtolower( $key )] . ") . '";
}
else
{
$string = "' . ". $params[strtolower( $key )] . " . '";
}
return $string;
} | php | private function parameterCallbackCompile( $key, array $params )
{
if ( !isset( $params[strtolower( $key )] ) )
{
throw new ezcTranslationParameterMissingException( $key );
}
// We use ctype_upper() here to check if the first character of the key
// is an uppercase letter. If it is then we make the first character of
// the returned translation also an upper case character. With this
// mechanism we can correctly upper case translated strings if word
// order changes. See
// {@link ezcTranslationTest::testGetStringWithParameters} for an
// example of this.
if ( ctype_upper( $key[0] ) )
{
$string = "' . ucfirst(". $params[strtolower( $key )] . ") . '";
}
else
{
$string = "' . ". $params[strtolower( $key )] . " . '";
}
return $string;
} | [
"private",
"function",
"parameterCallbackCompile",
"(",
"$",
"key",
",",
"array",
"$",
"params",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"params",
"[",
"strtolower",
"(",
"$",
"key",
")",
"]",
")",
")",
"{",
"throw",
"new",
"ezcTranslationParameterMissingException",
"(",
"$",
"key",
")",
";",
"}",
"// We use ctype_upper() here to check if the first character of the key",
"// is an uppercase letter. If it is then we make the first character of",
"// the returned translation also an upper case character. With this",
"// mechanism we can correctly upper case translated strings if word",
"// order changes. See",
"// {@link ezcTranslationTest::testGetStringWithParameters} for an",
"// example of this.",
"if",
"(",
"ctype_upper",
"(",
"$",
"key",
"[",
"0",
"]",
")",
")",
"{",
"$",
"string",
"=",
"\"' . ucfirst(\"",
".",
"$",
"params",
"[",
"strtolower",
"(",
"$",
"key",
")",
"]",
".",
"\") . '\"",
";",
"}",
"else",
"{",
"$",
"string",
"=",
"\"' . \"",
".",
"$",
"params",
"[",
"strtolower",
"(",
"$",
"key",
")",
"]",
".",
"\" . '\"",
";",
"}",
"return",
"$",
"string",
";",
"}"
] | Returns the replacement for the key $key from the parameters $params.
The params array is an associative array in the form array('key'=>'value').
This is a callback function used by the compileTranslation() method for each
matched parameter in the translated string.
@param string $key
@param array $params
@return string | [
"Returns",
"the",
"replacement",
"for",
"the",
"key",
"$key",
"from",
"the",
"parameters",
"$params",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Translation/src/translation.php#L131-L153 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Translation/src/translation.php | ezcTranslation.compileTranslation | public function compileTranslation( $key, array $params = array() )
{
if ( !isset( $this->translationMap[$key] ) )
{
throw new ezcTranslationKeyNotAvailableException( $key );
}
$translatedString = var_export( $this->translationMap[$key]->translation, true );
// Little optimization to prevent preg if not needed, it bails out too
// if there is just a percent sign in the string without a valid
// parameter-identifier, but we can live with that.
if ( strstr( $translatedString, '%' ) === false )
{
return $translatedString;
}
// So we do have a possibility of a parameterized string, replace those
// with the parameters. The callback function can actually throw an
// exception to tell that there was a missing parameter.
return (string) preg_replace( '@%(([A-Za-z][a-z_]*[a-z])|[1-9])@e', '$this->parameterCallbackCompile("\\1", $params)', $translatedString );
} | php | public function compileTranslation( $key, array $params = array() )
{
if ( !isset( $this->translationMap[$key] ) )
{
throw new ezcTranslationKeyNotAvailableException( $key );
}
$translatedString = var_export( $this->translationMap[$key]->translation, true );
// Little optimization to prevent preg if not needed, it bails out too
// if there is just a percent sign in the string without a valid
// parameter-identifier, but we can live with that.
if ( strstr( $translatedString, '%' ) === false )
{
return $translatedString;
}
// So we do have a possibility of a parameterized string, replace those
// with the parameters. The callback function can actually throw an
// exception to tell that there was a missing parameter.
return (string) preg_replace( '@%(([A-Za-z][a-z_]*[a-z])|[1-9])@e', '$this->parameterCallbackCompile("\\1", $params)', $translatedString );
} | [
"public",
"function",
"compileTranslation",
"(",
"$",
"key",
",",
"array",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"translationMap",
"[",
"$",
"key",
"]",
")",
")",
"{",
"throw",
"new",
"ezcTranslationKeyNotAvailableException",
"(",
"$",
"key",
")",
";",
"}",
"$",
"translatedString",
"=",
"var_export",
"(",
"$",
"this",
"->",
"translationMap",
"[",
"$",
"key",
"]",
"->",
"translation",
",",
"true",
")",
";",
"// Little optimization to prevent preg if not needed, it bails out too",
"// if there is just a percent sign in the string without a valid",
"// parameter-identifier, but we can live with that.",
"if",
"(",
"strstr",
"(",
"$",
"translatedString",
",",
"'%'",
")",
"===",
"false",
")",
"{",
"return",
"$",
"translatedString",
";",
"}",
"// So we do have a possibility of a parameterized string, replace those",
"// with the parameters. The callback function can actually throw an",
"// exception to tell that there was a missing parameter.",
"return",
"(",
"string",
")",
"preg_replace",
"(",
"'@%(([A-Za-z][a-z_]*[a-z])|[1-9])@e'",
",",
"'$this->parameterCallbackCompile(\"\\\\1\", $params)'",
",",
"$",
"translatedString",
")",
";",
"}"
] | Returns the translated version of the original string $key.
This method returns a translated string and substitutes the parameters $param
in the localized string with PHP code to place the variable data into
the string at a later moment. Instead of the values for each of the
parameters, an expression to get to the data should be sumbitted into
the $params array.
<code>
echo $translation->compileTranslation( "Hello #%nr", array( "nr" => '$this->send->nr' ) );
</code>
Will return something like:
<code>
'Hallo #' . $this->send->nr . ''
</code>
@param string $key
@param array(string=>string) $params
@return string | [
"Returns",
"the",
"translated",
"version",
"of",
"the",
"original",
"string",
"$key",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Translation/src/translation.php#L177-L195 |
thupan/framework | src/Service/Session.php | Session.getInstance | public static function getInstance()
{
if (self::$instance == false) {
self::$config = autoload_config();
ini_set('session.cookie_httponly', self::$config['app']['SESSION_COOKIE_HTTPONLY']);
self::$instance = self::generateToken();
@session_name(self::$instance);
@session_cache_expire(self::$config['app']['SESSION_EXPIRE']);
@session_start();
self::set('s_token', self::$instance);
}
return self::$instance;
} | php | public static function getInstance()
{
if (self::$instance == false) {
self::$config = autoload_config();
ini_set('session.cookie_httponly', self::$config['app']['SESSION_COOKIE_HTTPONLY']);
self::$instance = self::generateToken();
@session_name(self::$instance);
@session_cache_expire(self::$config['app']['SESSION_EXPIRE']);
@session_start();
self::set('s_token', self::$instance);
}
return self::$instance;
} | [
"public",
"static",
"function",
"getInstance",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"instance",
"==",
"false",
")",
"{",
"self",
"::",
"$",
"config",
"=",
"autoload_config",
"(",
")",
";",
"ini_set",
"(",
"'session.cookie_httponly'",
",",
"self",
"::",
"$",
"config",
"[",
"'app'",
"]",
"[",
"'SESSION_COOKIE_HTTPONLY'",
"]",
")",
";",
"self",
"::",
"$",
"instance",
"=",
"self",
"::",
"generateToken",
"(",
")",
";",
"@",
"session_name",
"(",
"self",
"::",
"$",
"instance",
")",
";",
"@",
"session_cache_expire",
"(",
"self",
"::",
"$",
"config",
"[",
"'app'",
"]",
"[",
"'SESSION_EXPIRE'",
"]",
")",
";",
"@",
"session_start",
"(",
")",
";",
"self",
"::",
"set",
"(",
"'s_token'",
",",
"self",
"::",
"$",
"instance",
")",
";",
"}",
"return",
"self",
"::",
"$",
"instance",
";",
"}"
] | Método público para inicializar a classe de sessão.
@method init()
@param none
@return none | [
"Método",
"público",
"para",
"inicializar",
"a",
"classe",
"de",
"sessão",
"."
] | train | https://github.com/thupan/framework/blob/43193c67e87942930fb0cbc53aa069b60b27e749/src/Service/Session.php#L50-L67 |
thupan/framework | src/Service/Session.php | Session.flash | public static function flash($key = false)
{
$value = self::get($key ? $key : 'flash');
self::remove($key ? $key : 'flash');
return $value ? $value : false;
} | php | public static function flash($key = false)
{
$value = self::get($key ? $key : 'flash');
self::remove($key ? $key : 'flash');
return $value ? $value : false;
} | [
"public",
"static",
"function",
"flash",
"(",
"$",
"key",
"=",
"false",
")",
"{",
"$",
"value",
"=",
"self",
"::",
"get",
"(",
"$",
"key",
"?",
"$",
"key",
":",
"'flash'",
")",
";",
"self",
"::",
"remove",
"(",
"$",
"key",
"?",
"$",
"key",
":",
"'flash'",
")",
";",
"return",
"$",
"value",
"?",
"$",
"value",
":",
"false",
";",
"}"
] | Método público retorna valor de uma determinada sessão e se auto-destroi.
@method flash()
@param string
@return string / Bool | [
"Método",
"público",
"retorna",
"valor",
"de",
"uma",
"determinada",
"sessão",
"e",
"se",
"auto",
"-",
"destroi",
"."
] | train | https://github.com/thupan/framework/blob/43193c67e87942930fb0cbc53aa069b60b27e749/src/Service/Session.php#L155-L161 |
thupan/framework | src/Service/Session.php | Session.getArray | public static function getArray()
{
$data = [];
foreach ($_SESSION as $key => $val) {
$data[$key] = $val;
}
return $data;
} | php | public static function getArray()
{
$data = [];
foreach ($_SESSION as $key => $val) {
$data[$key] = $val;
}
return $data;
} | [
"public",
"static",
"function",
"getArray",
"(",
")",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"_SESSION",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"val",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Método público retorna toda sessão em array.
@method getArray()
@param none
@retun Array | [
"Método",
"público",
"retorna",
"toda",
"sessão",
"em",
"array",
"."
] | train | https://github.com/thupan/framework/blob/43193c67e87942930fb0cbc53aa069b60b27e749/src/Service/Session.php#L171-L180 |
mothership-ec/composer | src/Composer/Package/Version/VersionSelector.php | VersionSelector.findBestCandidate | public function findBestCandidate($packageName, $targetPackageVersion = null)
{
$constraint = $targetPackageVersion ? $this->getParser()->parseConstraints($targetPackageVersion) : null;
$candidates = $this->pool->whatProvides(strtolower($packageName), $constraint, true);
if (!$candidates) {
return false;
}
// select highest version if we have many
$package = reset($candidates);
foreach ($candidates as $candidate) {
if (version_compare($package->getVersion(), $candidate->getVersion(), '<')) {
$package = $candidate;
}
}
return $package;
} | php | public function findBestCandidate($packageName, $targetPackageVersion = null)
{
$constraint = $targetPackageVersion ? $this->getParser()->parseConstraints($targetPackageVersion) : null;
$candidates = $this->pool->whatProvides(strtolower($packageName), $constraint, true);
if (!$candidates) {
return false;
}
// select highest version if we have many
$package = reset($candidates);
foreach ($candidates as $candidate) {
if (version_compare($package->getVersion(), $candidate->getVersion(), '<')) {
$package = $candidate;
}
}
return $package;
} | [
"public",
"function",
"findBestCandidate",
"(",
"$",
"packageName",
",",
"$",
"targetPackageVersion",
"=",
"null",
")",
"{",
"$",
"constraint",
"=",
"$",
"targetPackageVersion",
"?",
"$",
"this",
"->",
"getParser",
"(",
")",
"->",
"parseConstraints",
"(",
"$",
"targetPackageVersion",
")",
":",
"null",
";",
"$",
"candidates",
"=",
"$",
"this",
"->",
"pool",
"->",
"whatProvides",
"(",
"strtolower",
"(",
"$",
"packageName",
")",
",",
"$",
"constraint",
",",
"true",
")",
";",
"if",
"(",
"!",
"$",
"candidates",
")",
"{",
"return",
"false",
";",
"}",
"// select highest version if we have many",
"$",
"package",
"=",
"reset",
"(",
"$",
"candidates",
")",
";",
"foreach",
"(",
"$",
"candidates",
"as",
"$",
"candidate",
")",
"{",
"if",
"(",
"version_compare",
"(",
"$",
"package",
"->",
"getVersion",
"(",
")",
",",
"$",
"candidate",
"->",
"getVersion",
"(",
")",
",",
"'<'",
")",
")",
"{",
"$",
"package",
"=",
"$",
"candidate",
";",
"}",
"}",
"return",
"$",
"package",
";",
"}"
] | Given a package name and optional version, returns the latest PackageInterface
that matches.
@param string $packageName
@param string $targetPackageVersion
@return PackageInterface|bool | [
"Given",
"a",
"package",
"name",
"and",
"optional",
"version",
"returns",
"the",
"latest",
"PackageInterface",
"that",
"matches",
"."
] | train | https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Package/Version/VersionSelector.php#L45-L63 |
j-d/draggy | src/Draggy/Autocode/Project.php | Project.& | public function &getEntityByFullyQualifiedName($name)
{
if (!isset( $this->entities[$name] )) {
throw new \RuntimeException( 'An entity by the name of ' . $name . ' could not be located.' );
}
return $this->entities[$name];
} | php | public function &getEntityByFullyQualifiedName($name)
{
if (!isset( $this->entities[$name] )) {
throw new \RuntimeException( 'An entity by the name of ' . $name . ' could not be located.' );
}
return $this->entities[$name];
} | [
"public",
"function",
"&",
"getEntityByFullyQualifiedName",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"entities",
"[",
"$",
"name",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'An entity by the name of '",
".",
"$",
"name",
".",
"' could not be located.'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"entities",
"[",
"$",
"name",
"]",
";",
"}"
] | <user-additions part="otherMethods"> | [
"<user",
"-",
"additions",
"part",
"=",
"otherMethods",
">"
] | train | https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Autocode/Project.php#L175-L182 |
j-d/draggy | src/Draggy/Autocode/Project.php | Project.getAutocodeProperty | public function getAutocodeProperty($property)
{
return isset($this->autocodeProperties[$property])
? $this->autocodeProperties[$property]
: null;
} | php | public function getAutocodeProperty($property)
{
return isset($this->autocodeProperties[$property])
? $this->autocodeProperties[$property]
: null;
} | [
"public",
"function",
"getAutocodeProperty",
"(",
"$",
"property",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"autocodeProperties",
"[",
"$",
"property",
"]",
")",
"?",
"$",
"this",
"->",
"autocodeProperties",
"[",
"$",
"property",
"]",
":",
"null",
";",
"}"
] | @param $property
@return bool | [
"@param",
"$property"
] | train | https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Autocode/Project.php#L378-L383 |
j-d/draggy | src/Draggy/Autocode/Project.php | Project.loadDesign | public function loadDesign(\SimpleXMLElement $xmlDesign)
{
// Load project properties
$projectProperties = (array) $xmlDesign->xpath('project')[0];
$this->setLanguage((string) $projectProperties['language']);
$this->setFramework((string) $projectProperties['framework']);
$this->setOrm((string) $projectProperties['orm']);
$this->setDescription((string) $projectProperties['description']);
$this->configuration = $this->calculateConfiguration();
if ($this->getLanguage() === 'php') {
$this->setAttributeClass('Draggy\\Autocode\\PHPAttribute');
$this->setEntityClass('Draggy\\Autocode\\PHPEntity');
} elseif ($this->getLanguage() === 'js') {
$this->setAttributeClass('Draggy\\Autocode\\JSAttribute');
$this->setEntityClass('Draggy\\Autocode\\Entity');
} elseif ($this->getLanguage() === 'java') {
$this->setAttributeClass('Draggy\\Autocode\\JavaAttribute');
$this->setEntityClass('Draggy\\Autocode\\JavaEntity');
} elseif ($this->getLanguage() === 'cpp') {
$this->setAttributeClass('Draggy\\Autocode\\CPPAttribute');
$this->setEntityClass('Draggy\\Autocode\\CPPEntity');
}
$attributeClass = $this->getAttributeClass();
// Load autocode settings
$autocode = (array) $xmlDesign->xpath('autocode')[0];
$autocodeProperties = (array)$autocode['properties'];
$autocodeConfigurations = (array)$autocode['configurations'];
$autocodeTemplates = (array)$autocode['templates'];
foreach ($autocodeProperties as $propertyName => $propertyValue) {
$this->setAutocodeProperty($propertyName, 'true' === $propertyValue);
}
foreach ($autocodeConfigurations as $configurationName => $configurationValue) {
$this->setAutocodeConfiguration($configurationName, $configurationValue);
}
foreach ($autocodeTemplates as $templateName => $templateValue) {
if (!is_string($templateValue)) {
// Use the default template
$template = $this->getConfiguration()['autocode']['templates'][$templateName]['template'];
} else {
$template = $templateValue;
}
if (!class_exists($template)) {
throw new \RuntimeException(sprintf('The specified class file \'%s\' cannot be loaded', $template));
}
$this->setAutocodeTemplate($templateName, new $template);
}
// Process entities
$modules = $xmlDesign->xpath('module');
// Process in three steps. First create all the entities, second add all the attributes, and finally link the foreign entities.
// This way it can reference foreign entities and attributes because they will exist.
// First step: Add the entities (Classes or Abstracts)
foreach ($modules as $module) {
$moduleName = (string)$module->attributes()->name;
$this->log->appendExtended('Found module: ' . $moduleName);
// Classes
$classes = $module->xpath('*[self::class]');
foreach ($classes as $class) {
$class->addAttribute('fullyQualifiedName', $moduleName . '\\' . $class->attributes()->name);
$entity = $this->xmlEntityToEntity($class, $moduleName);
$entity->setType('class');
$this->addEntity($entity);
}
// Abstracts
$abstracts = $module->xpath('*[self::abstract]');
foreach ($abstracts as $abstract) {
$abstract->addAttribute('fullyQualifiedName', $moduleName . '\\' . $abstract->attributes()->name);
$entity = $this->xmlEntityToEntity($abstract, $moduleName);
$entity->setType('abstract');
$this->addEntity($entity);
}
}
// Add loose entities
$loose = $xmlDesign->xpath('loose')[0];
$classes = $loose->xpath('*[self::class]');
foreach ($classes as $class) {
$class->addAttribute('fullyQualifiedName', $class->attributes()->name); // Add fully qualified name
$entity = $this->xmlEntityToEntity($class);
$entity->setType('class');
$this->addEntity($entity);
}
$abstracts = $loose->xpath('*[self::abstract]');
foreach ($abstracts as $abstract) {
$abstract->addAttribute('fullyQualifiedName', $abstract->attributes()->name); // Add fully qualified name
$entity = $this->xmlEntityToEntity($abstract);
$entity->setType('abstract');
$this->addEntity($entity);
}
// Second step: Add all non-inherited attributes
$classes = $xmlDesign->xpath('*[self::module or self::loose]/*[self::class or self::abstract]');
foreach ($classes as $class) {
$classAttributes = (array)$class->attributes();
$classAttributes = $classAttributes['@attributes'];
$entityName = $classAttributes['name'];
$entityFullyQualifiedName = $classAttributes['fullyQualifiedName'];
$entity = $this->getEntityByFullyQualifiedName($entityFullyQualifiedName);
$attributes = $class->xpath('attribute[not(@inherited=\'true\')]');
foreach ($attributes as $attribute) {
$attributeAttributes = (array)$attribute->attributes();
$attributeAttributes = $attributeAttributes['@attributes'];
$attributeName = $attributeAttributes['name'];
if (!isset( $attributeAttributes['type'] ))
throw new \Exception( 'The attribute ' . $attributeName . ' on the entity ' . $entityName . ' doesn\'t have a type' );
/** @var Attribute $attribute */
$attribute = new $attributeClass( $entity, $attributeName, $attributeAttributes['type']);
foreach ($attributeAttributes as $attributeName => $attributeValue) {
switch ($attributeName) {
case 'autoincrement':
$attribute->setAutoIncrement($attributeValue === 'true');
break;
case 'primary':
$attribute->setPrimary($attributeValue === 'true');
break;
case 'name':
case 'type':
case 'id':
break; // Already dealt with
case 'subtype':
$attribute->setSubtype($attributeValue);
break;
case 'description':
$attribute->setDescription($attributeValue);
break;
case 'size':
$attribute->setSize((int)$attributeValue);
break;
case 'minSize':
$attribute->setMinSize((int)$attributeValue);
break;
case 'min':
$attribute->setMin((int)$attributeValue);
break;
case 'max':
$attribute->setMax((int)$attributeValue);
break;
case 'null':
$attribute->setNull($attributeValue === 'true');
break;
case 'unique':
$attribute->setUnique($attributeValue === 'true');
break;
case 'default':
$attribute->setDefaultValue($attributeValue);
break;
case 'foreign':
$attribute->setForeignTick($attributeValue === 'true');
break;
case 'setter':
$attribute->setSetter($attributeValue === 'true');
break;
case 'getter':
$attribute->setGetter($attributeValue === 'true');
break;
case 'email':
$attribute->setEmail($attributeValue === 'true');
break;
case 'static':
$attribute->setStatic($attributeValue === 'true');
break;
default:
throw new \Exception( 'The attribute ' . $attributeAttributes['name'] . ' on the entity ' . $entityName . ' has an unknown attribute (' . $attributeName . ')' );
}
}
if ($attribute->getAutoIncrement() && !$attribute->getForeignTick())
$attribute->setSetter(false); // If it is autoincrement, can't have a setter unless is a foreign key
$entity->addAttribute($attribute);
}
}
// Find inherited classes and mark their parent entities
$childClasses = $xmlDesign->xpath('*[self::module or self::loose]/*[@inheritingFrom and (self::abstract)]');
foreach ($childClasses as $childClass) {
$childClassAttributes = (array)$childClass->attributes();
$childClassAttributes = $childClassAttributes['@attributes'];
$childClassFullyQualifiedName = $childClassAttributes['fullyQualifiedName'];
$parentName = $childClassAttributes['inheritingFrom'];
$child = &$this->getEntityByFullyQualifiedName($childClassFullyQualifiedName);
$parent = &$this->getEntityByFullyQualifiedName($parentName);
$child->setParentEntity($parent);
$parent->addChildrenEntity($child);
foreach ($parent->getAttributes() as $attrNode) {
$child->addAttributeReference($attrNode);
}
unset($child,$parent);
}
$childClasses = $xmlDesign->xpath('*[self::module or self::loose]/*[@inheritingFrom and (self::class)]');
foreach ($childClasses as $childClass) {
$childClassAttributes = (array)$childClass->attributes();
$childClassAttributes = $childClassAttributes['@attributes'];
$childClassFullyQualifiedName = $childClassAttributes['fullyQualifiedName'];
$parentName = $childClassAttributes['inheritingFrom'];
$child = &$this->getEntityByFullyQualifiedName($childClassFullyQualifiedName);
$parent = &$this->getEntityByFullyQualifiedName($parentName);
$child->setParentEntity($parent);
$parent->addChildrenEntity($child);
foreach ($parent->getAttributes() as $attrNode) {
$child->addAttributeReference($attrNode);
}
unset($child,$parent);
}
// Fix ManyToMany relationships without attributes
$manyToManyRelationships = $xmlDesign->xpath('*[self::module or self::loose]/class[@manyToMany=\'true\']');
// Mark many to many virtual entities
foreach ($manyToManyRelationships as $manyToManyRelationship) {
$manyToManyEntityName = (array)$manyToManyRelationship->attributes();
$manyToManyEntityFullyQualifiedName = $manyToManyEntityName['@attributes']['fullyQualifiedName'];
$manyToManyEntity = &$this->getEntityByFullyQualifiedName($manyToManyEntityFullyQualifiedName);
$manyToManyEntityAttributes = $manyToManyEntity->getAttributes();
if (count($manyToManyEntityAttributes) == 2) { // If it is not 2, is not a proper ManyToMany relationship
$manyToManyEntity->setRenderizable(false);
}
}
// Find and map foreign keys (OneToMany, ManyToOne or OneToOne)
$foreignKeys = $xmlDesign->xpath('relationships/relation[@type=\'one-to-one\' or @type=\'one-to-many\']');
foreach ($foreignKeys as $foreignKey) {
$sourceEntityName = (string)$foreignKey->attributes()->from;
$sourceAttributeName = (string)$foreignKey->attributes()->fromAttribute;
$targetEntityName = (string)$foreignKey->attributes()->to;
$targetAttributeName = (string)$foreignKey->attributes()->toAttribute;
$sourceEntity = &$this->getEntityByFullyQualifiedName($sourceEntityName);
$sourceAttribute = &$sourceEntity->getAttributeByName($sourceAttributeName);
$targetEntity = &$this->getEntityByFullyQualifiedName($targetEntityName);
$targetAttribute = &$targetEntity->getAttributeByName($targetAttributeName);
//echo 'source attr: ' . $sourceEntityName . '\\' . $sourceAttribute->getName() . '<br>';
//echo 'target attr: ' . $targetEntityName . '\\' . $targetAttribute->getName() . '<br><br>';
/*if ($sourceAttribute->getUnique()) // ???
$sourceAttribute->setForeign('OneToOne');
else
$sourceAttribute->setForeign('ManyToOne');
*/
$type = (string)$foreignKey->attributes()->type;
// Backwards compatibility
if ($type == 'one-to-one') {
$type = 'OneToOne';
} elseif ($type == 'many-to-one') {
$type = 'ManyToOne';
}
// End of backwards compatibility
if ($type === 'OneToOne') {
$targetAttribute->setForeign('OneToOne');
} else { // ManyToOne
$targetAttribute->setForeign('ManyToOne');
}
$targetAttribute->setOwnerSide(true);
//$sourceAttribute->setForeignEntity($targetEntity);
//$sourceAttribute->setForeignKey($targetAttribute);
$targetAttribute->setForeignEntity($sourceEntity);
$targetAttribute->setForeignKey($sourceAttribute);
}
$attributesToBeAdded = [];
foreach ($manyToManyRelationships as $manyToManyRelationship) {
$manyToManyEntityNameArray = (array)$manyToManyRelationship->attributes();
$manyToManyEntityName = $manyToManyEntityNameArray['@attributes']['name'];
$manyToManyEntityFullyQualifiedName = $manyToManyEntityNameArray['@attributes']['fullyQualifiedName'];
$manyToManyEntity = & $this->getEntityByFullyQualifiedName($manyToManyEntityFullyQualifiedName);
$manyToManyEntityAttributes = $manyToManyEntity->getAttributes();
if (count($manyToManyEntityAttributes) == 2) { // If it is not 2, is not a proper ManyToMany relationship
$manyToManyOwnerAttribute = $manyToManyEntity->getAttribute(0);
$manyToManyTargetAttribute = $manyToManyEntity->getAttribute(1);
$ownerEntity = &$manyToManyOwnerAttribute->getForeignEntity();
$targetEntity = &$manyToManyTargetAttribute->getForeignEntity();
/** @var Attribute $manyToManyAttributeOwner */
$manyToManyAttributeOwner = new $attributeClass( $ownerEntity, $manyToManyTargetAttribute->getName(), 'array' );
$manyToManyAttributeOwner
->setOwnerSide(true)
->setForeign('ManyToMany')
->setForeignEntity($targetEntity)
->setForeignKey($targetEntity->getPrimaryAttribute())
->setNull($manyToManyTargetAttribute->getNull())
->setManyToManyEntityName($manyToManyEntityName);
/** @var Attribute $manyToManyAttributeTarget */
$manyToManyAttributeTarget = new $attributeClass( $targetEntity, $manyToManyOwnerAttribute->getName(), 'array' );
$manyToManyAttributeTarget
->setForeign('ManyToMany')
->setForeignEntity($ownerEntity)
->setForeignKey($ownerEntity->getPrimaryAttribute())
->setNull($manyToManyOwnerAttribute->getNull())
->setManyToManyEntityName($manyToManyEntityName);
$manyToManyAttributeTarget->setReverseAttribute($manyToManyAttributeOwner);
$manyToManyAttributeOwner->setReverseAttribute($manyToManyAttributeTarget);
$ownerEntity->addAttribute($manyToManyAttributeOwner);
$targetEntity->addAttribute($manyToManyAttributeTarget);
if (!isset($attributesToBeAdded[$ownerEntity->getFullyQualifiedName()][$manyToManyTargetAttribute->getName()])) {
$attributesToBeAdded[$ownerEntity->getFullyQualifiedName()][$manyToManyTargetAttribute->getName()] = 1;
} else {
$attributesToBeAdded[$ownerEntity->getFullyQualifiedName()][$manyToManyTargetAttribute->getName()]++;
}
if (!isset($attributesToBeAdded[$targetEntity->getFullyQualifiedName()][$manyToManyOwnerAttribute->getName()])) {
$attributesToBeAdded[$targetEntity->getFullyQualifiedName()][$manyToManyOwnerAttribute->getName()] = 1;
} else {
$attributesToBeAdded[$targetEntity->getFullyQualifiedName()][$manyToManyOwnerAttribute->getName()]++;
}
// $manyToManyEntity->setRenderizable(false);
}
}
// Add OneToOne and OneToMany inverse attributes
$foreignKeys = $xmlDesign->xpath('relationships/relation[@type=\'one-to-one\' or @type=\'one-to-many\']');
// Find ideal new attribute counters
foreach ($foreignKeys as $foreignKey) {
$relationAttributes = (array)$foreignKey->attributes();
$relationAttributes = $relationAttributes['@attributes'];
$type = $relationAttributes['type'];
// Backwards compatibility
if ($type == 'one-to-one') {
$type = 'OneToOne';
} elseif ($type == 'many-to-one') {
$type = 'ManyToOne';
}
// End of backwards compatibility
$sourceEntityName = (string)$foreignKey->attributes()->from;
$targetEntityName = (string)$foreignKey->attributes()->to;
$sourceEntity = &$this->getEntityByFullyQualifiedName($sourceEntityName);
$targetEntity = & $this->getEntityByFullyQualifiedName($targetEntityName);
if ('OneToOne' === $type) {
$desiredName = $targetEntity->getLowerName();
} else {
$desiredName = $targetEntity->getPluralLowerName();
}
if (!isset($attributesToBeAdded[$sourceEntity->getFullyQualifiedName()][$desiredName])) {
$attributesToBeAdded[$sourceEntity->getFullyQualifiedName()][$desiredName] = 1;
} else {
$attributesToBeAdded[$sourceEntity->getFullyQualifiedName()][$desiredName]++;
}
}
// Actually add the attributes
foreach ($foreignKeys as $foreignKey) {
$relationAttributes = (array)$foreignKey->attributes();
$relationAttributes = $relationAttributes['@attributes'];
$sourceEntityName = (string)$foreignKey->attributes()->from;
$sourceAttributeName = (string)$foreignKey->attributes()->fromAttribute;
$targetEntityName = (string)$foreignKey->attributes()->to;
$targetAttributeName = (string)$foreignKey->attributes()->toAttribute;
$sourceEntity = &$this->getEntityByFullyQualifiedName($sourceEntityName);
$sourceAttribute = &$sourceEntity->getAttributeByName($sourceAttributeName);
$targetEntity = &$this->getEntityByFullyQualifiedName($targetEntityName);
$targetAttribute = &$targetEntity->getAttributeByName($targetAttributeName);
$type = $relationAttributes['type'];
// Backwards compatibility
if ($type == 'one-to-one') {
$type = 'OneToOne';
} elseif ($type == 'many-to-one') {
$type = 'ManyToOne';
}
// End of backwards compatibility
if ($targetEntity->getRenderizable()) {
if ('OneToOne' === $type) {
$desiredName = $targetEntity->getLowerName();
} else {
$desiredName = $targetEntity->getPluralLowerName();
}
list($attributeName, $attributeSuffix) = 1 === $attributesToBeAdded[$sourceEntity->getFullyQualifiedName()][$desiredName]
? $this->getActualAttributeName($sourceEntity, $desiredName)
: $this->getActualAttributeName($sourceEntity, $desiredName, $targetAttribute->getUpperName(), true);
if ($type === 'OneToOne') {
/** @var Attribute $inverseAttribute */
$inverseAttribute = new $attributeClass($sourceEntity, $attributeName, 'object');
$inverseAttribute
->setSuffix($attributeSuffix)
->setInverse(true)
->setSubtype($targetEntity->getRelativePathName())
->setForeign('OneToOne')
->setForeignEntity($targetEntity)
->setForeignKey($targetAttribute)
->setNull($targetAttribute->getNull()) // TODO: CHECK
->setReverseAttribute($targetAttribute);
$targetAttribute->setReverseAttribute($inverseAttribute);
} else { // ManyToOne
/** @var Attribute $inverseAttribute */
$inverseAttribute = new $attributeClass($sourceEntity, $attributeName, 'array');
$inverseAttribute
->setSuffix($attributeSuffix)
->setInverse(true)
->setSubtype($targetEntity->getRelativePathName())
->setForeign('ManyToOne')
->setForeignEntity($targetEntity)
->setForeignKey($targetAttribute)
->setNull($targetAttribute->getNull()) // TODO: CHECK
->setReverseAttribute($targetAttribute);
$targetAttribute->setReverseAttribute($inverseAttribute);
}
if ($sourceEntity->hasAttributeByName($desiredName . $attributeSuffix)) {
$this->log->prepend('*** The ' . $type . ' inverse attribute \'' . $inverseAttribute->getLowerName() . '\' could not be added to the Entity \'' . $sourceEntity->getName() . '\' because there is an attribute with that name already there. It had to be renamed to \'' . $attributeName . '\'.');
}
$sourceEntity->addAttribute($inverseAttribute);
$targetAttribute->setCascadePersist('both'); // Backwards compatibility
$targetAttribute->setCascadeRemove('both'); // Backwards compatibility
foreach ($relationAttributes as $attributeName => $attributeValue) {
switch ($attributeName) {
case 'broken':
break; // Already dealt with
case 'from':
break; // Already dealt with
case 'fromAttribute':
break; // Already dealt with
case 'persist':
$targetAttribute->setCascadePersist($attributeValue);
break;
case 'remove':
$targetAttribute->setCascadeRemove($attributeValue);
break;
case 'to':
break; // Already dealt with
case 'toAttribute':
break; // Already dealt with
case 'type':
break; // Already dealt with
default:
throw new \Exception( 'The relation from the entity ' . $sourceEntity->getName() . ' to the entity ' . $targetEntity->getName() . ' has an unknown attribute (' . $attributeName . ')' );
}
}
}
}
return $this;
} | php | public function loadDesign(\SimpleXMLElement $xmlDesign)
{
// Load project properties
$projectProperties = (array) $xmlDesign->xpath('project')[0];
$this->setLanguage((string) $projectProperties['language']);
$this->setFramework((string) $projectProperties['framework']);
$this->setOrm((string) $projectProperties['orm']);
$this->setDescription((string) $projectProperties['description']);
$this->configuration = $this->calculateConfiguration();
if ($this->getLanguage() === 'php') {
$this->setAttributeClass('Draggy\\Autocode\\PHPAttribute');
$this->setEntityClass('Draggy\\Autocode\\PHPEntity');
} elseif ($this->getLanguage() === 'js') {
$this->setAttributeClass('Draggy\\Autocode\\JSAttribute');
$this->setEntityClass('Draggy\\Autocode\\Entity');
} elseif ($this->getLanguage() === 'java') {
$this->setAttributeClass('Draggy\\Autocode\\JavaAttribute');
$this->setEntityClass('Draggy\\Autocode\\JavaEntity');
} elseif ($this->getLanguage() === 'cpp') {
$this->setAttributeClass('Draggy\\Autocode\\CPPAttribute');
$this->setEntityClass('Draggy\\Autocode\\CPPEntity');
}
$attributeClass = $this->getAttributeClass();
// Load autocode settings
$autocode = (array) $xmlDesign->xpath('autocode')[0];
$autocodeProperties = (array)$autocode['properties'];
$autocodeConfigurations = (array)$autocode['configurations'];
$autocodeTemplates = (array)$autocode['templates'];
foreach ($autocodeProperties as $propertyName => $propertyValue) {
$this->setAutocodeProperty($propertyName, 'true' === $propertyValue);
}
foreach ($autocodeConfigurations as $configurationName => $configurationValue) {
$this->setAutocodeConfiguration($configurationName, $configurationValue);
}
foreach ($autocodeTemplates as $templateName => $templateValue) {
if (!is_string($templateValue)) {
// Use the default template
$template = $this->getConfiguration()['autocode']['templates'][$templateName]['template'];
} else {
$template = $templateValue;
}
if (!class_exists($template)) {
throw new \RuntimeException(sprintf('The specified class file \'%s\' cannot be loaded', $template));
}
$this->setAutocodeTemplate($templateName, new $template);
}
// Process entities
$modules = $xmlDesign->xpath('module');
// Process in three steps. First create all the entities, second add all the attributes, and finally link the foreign entities.
// This way it can reference foreign entities and attributes because they will exist.
// First step: Add the entities (Classes or Abstracts)
foreach ($modules as $module) {
$moduleName = (string)$module->attributes()->name;
$this->log->appendExtended('Found module: ' . $moduleName);
// Classes
$classes = $module->xpath('*[self::class]');
foreach ($classes as $class) {
$class->addAttribute('fullyQualifiedName', $moduleName . '\\' . $class->attributes()->name);
$entity = $this->xmlEntityToEntity($class, $moduleName);
$entity->setType('class');
$this->addEntity($entity);
}
// Abstracts
$abstracts = $module->xpath('*[self::abstract]');
foreach ($abstracts as $abstract) {
$abstract->addAttribute('fullyQualifiedName', $moduleName . '\\' . $abstract->attributes()->name);
$entity = $this->xmlEntityToEntity($abstract, $moduleName);
$entity->setType('abstract');
$this->addEntity($entity);
}
}
// Add loose entities
$loose = $xmlDesign->xpath('loose')[0];
$classes = $loose->xpath('*[self::class]');
foreach ($classes as $class) {
$class->addAttribute('fullyQualifiedName', $class->attributes()->name); // Add fully qualified name
$entity = $this->xmlEntityToEntity($class);
$entity->setType('class');
$this->addEntity($entity);
}
$abstracts = $loose->xpath('*[self::abstract]');
foreach ($abstracts as $abstract) {
$abstract->addAttribute('fullyQualifiedName', $abstract->attributes()->name); // Add fully qualified name
$entity = $this->xmlEntityToEntity($abstract);
$entity->setType('abstract');
$this->addEntity($entity);
}
// Second step: Add all non-inherited attributes
$classes = $xmlDesign->xpath('*[self::module or self::loose]/*[self::class or self::abstract]');
foreach ($classes as $class) {
$classAttributes = (array)$class->attributes();
$classAttributes = $classAttributes['@attributes'];
$entityName = $classAttributes['name'];
$entityFullyQualifiedName = $classAttributes['fullyQualifiedName'];
$entity = $this->getEntityByFullyQualifiedName($entityFullyQualifiedName);
$attributes = $class->xpath('attribute[not(@inherited=\'true\')]');
foreach ($attributes as $attribute) {
$attributeAttributes = (array)$attribute->attributes();
$attributeAttributes = $attributeAttributes['@attributes'];
$attributeName = $attributeAttributes['name'];
if (!isset( $attributeAttributes['type'] ))
throw new \Exception( 'The attribute ' . $attributeName . ' on the entity ' . $entityName . ' doesn\'t have a type' );
/** @var Attribute $attribute */
$attribute = new $attributeClass( $entity, $attributeName, $attributeAttributes['type']);
foreach ($attributeAttributes as $attributeName => $attributeValue) {
switch ($attributeName) {
case 'autoincrement':
$attribute->setAutoIncrement($attributeValue === 'true');
break;
case 'primary':
$attribute->setPrimary($attributeValue === 'true');
break;
case 'name':
case 'type':
case 'id':
break; // Already dealt with
case 'subtype':
$attribute->setSubtype($attributeValue);
break;
case 'description':
$attribute->setDescription($attributeValue);
break;
case 'size':
$attribute->setSize((int)$attributeValue);
break;
case 'minSize':
$attribute->setMinSize((int)$attributeValue);
break;
case 'min':
$attribute->setMin((int)$attributeValue);
break;
case 'max':
$attribute->setMax((int)$attributeValue);
break;
case 'null':
$attribute->setNull($attributeValue === 'true');
break;
case 'unique':
$attribute->setUnique($attributeValue === 'true');
break;
case 'default':
$attribute->setDefaultValue($attributeValue);
break;
case 'foreign':
$attribute->setForeignTick($attributeValue === 'true');
break;
case 'setter':
$attribute->setSetter($attributeValue === 'true');
break;
case 'getter':
$attribute->setGetter($attributeValue === 'true');
break;
case 'email':
$attribute->setEmail($attributeValue === 'true');
break;
case 'static':
$attribute->setStatic($attributeValue === 'true');
break;
default:
throw new \Exception( 'The attribute ' . $attributeAttributes['name'] . ' on the entity ' . $entityName . ' has an unknown attribute (' . $attributeName . ')' );
}
}
if ($attribute->getAutoIncrement() && !$attribute->getForeignTick())
$attribute->setSetter(false); // If it is autoincrement, can't have a setter unless is a foreign key
$entity->addAttribute($attribute);
}
}
// Find inherited classes and mark their parent entities
$childClasses = $xmlDesign->xpath('*[self::module or self::loose]/*[@inheritingFrom and (self::abstract)]');
foreach ($childClasses as $childClass) {
$childClassAttributes = (array)$childClass->attributes();
$childClassAttributes = $childClassAttributes['@attributes'];
$childClassFullyQualifiedName = $childClassAttributes['fullyQualifiedName'];
$parentName = $childClassAttributes['inheritingFrom'];
$child = &$this->getEntityByFullyQualifiedName($childClassFullyQualifiedName);
$parent = &$this->getEntityByFullyQualifiedName($parentName);
$child->setParentEntity($parent);
$parent->addChildrenEntity($child);
foreach ($parent->getAttributes() as $attrNode) {
$child->addAttributeReference($attrNode);
}
unset($child,$parent);
}
$childClasses = $xmlDesign->xpath('*[self::module or self::loose]/*[@inheritingFrom and (self::class)]');
foreach ($childClasses as $childClass) {
$childClassAttributes = (array)$childClass->attributes();
$childClassAttributes = $childClassAttributes['@attributes'];
$childClassFullyQualifiedName = $childClassAttributes['fullyQualifiedName'];
$parentName = $childClassAttributes['inheritingFrom'];
$child = &$this->getEntityByFullyQualifiedName($childClassFullyQualifiedName);
$parent = &$this->getEntityByFullyQualifiedName($parentName);
$child->setParentEntity($parent);
$parent->addChildrenEntity($child);
foreach ($parent->getAttributes() as $attrNode) {
$child->addAttributeReference($attrNode);
}
unset($child,$parent);
}
// Fix ManyToMany relationships without attributes
$manyToManyRelationships = $xmlDesign->xpath('*[self::module or self::loose]/class[@manyToMany=\'true\']');
// Mark many to many virtual entities
foreach ($manyToManyRelationships as $manyToManyRelationship) {
$manyToManyEntityName = (array)$manyToManyRelationship->attributes();
$manyToManyEntityFullyQualifiedName = $manyToManyEntityName['@attributes']['fullyQualifiedName'];
$manyToManyEntity = &$this->getEntityByFullyQualifiedName($manyToManyEntityFullyQualifiedName);
$manyToManyEntityAttributes = $manyToManyEntity->getAttributes();
if (count($manyToManyEntityAttributes) == 2) { // If it is not 2, is not a proper ManyToMany relationship
$manyToManyEntity->setRenderizable(false);
}
}
// Find and map foreign keys (OneToMany, ManyToOne or OneToOne)
$foreignKeys = $xmlDesign->xpath('relationships/relation[@type=\'one-to-one\' or @type=\'one-to-many\']');
foreach ($foreignKeys as $foreignKey) {
$sourceEntityName = (string)$foreignKey->attributes()->from;
$sourceAttributeName = (string)$foreignKey->attributes()->fromAttribute;
$targetEntityName = (string)$foreignKey->attributes()->to;
$targetAttributeName = (string)$foreignKey->attributes()->toAttribute;
$sourceEntity = &$this->getEntityByFullyQualifiedName($sourceEntityName);
$sourceAttribute = &$sourceEntity->getAttributeByName($sourceAttributeName);
$targetEntity = &$this->getEntityByFullyQualifiedName($targetEntityName);
$targetAttribute = &$targetEntity->getAttributeByName($targetAttributeName);
//echo 'source attr: ' . $sourceEntityName . '\\' . $sourceAttribute->getName() . '<br>';
//echo 'target attr: ' . $targetEntityName . '\\' . $targetAttribute->getName() . '<br><br>';
/*if ($sourceAttribute->getUnique()) // ???
$sourceAttribute->setForeign('OneToOne');
else
$sourceAttribute->setForeign('ManyToOne');
*/
$type = (string)$foreignKey->attributes()->type;
// Backwards compatibility
if ($type == 'one-to-one') {
$type = 'OneToOne';
} elseif ($type == 'many-to-one') {
$type = 'ManyToOne';
}
// End of backwards compatibility
if ($type === 'OneToOne') {
$targetAttribute->setForeign('OneToOne');
} else { // ManyToOne
$targetAttribute->setForeign('ManyToOne');
}
$targetAttribute->setOwnerSide(true);
//$sourceAttribute->setForeignEntity($targetEntity);
//$sourceAttribute->setForeignKey($targetAttribute);
$targetAttribute->setForeignEntity($sourceEntity);
$targetAttribute->setForeignKey($sourceAttribute);
}
$attributesToBeAdded = [];
foreach ($manyToManyRelationships as $manyToManyRelationship) {
$manyToManyEntityNameArray = (array)$manyToManyRelationship->attributes();
$manyToManyEntityName = $manyToManyEntityNameArray['@attributes']['name'];
$manyToManyEntityFullyQualifiedName = $manyToManyEntityNameArray['@attributes']['fullyQualifiedName'];
$manyToManyEntity = & $this->getEntityByFullyQualifiedName($manyToManyEntityFullyQualifiedName);
$manyToManyEntityAttributes = $manyToManyEntity->getAttributes();
if (count($manyToManyEntityAttributes) == 2) { // If it is not 2, is not a proper ManyToMany relationship
$manyToManyOwnerAttribute = $manyToManyEntity->getAttribute(0);
$manyToManyTargetAttribute = $manyToManyEntity->getAttribute(1);
$ownerEntity = &$manyToManyOwnerAttribute->getForeignEntity();
$targetEntity = &$manyToManyTargetAttribute->getForeignEntity();
/** @var Attribute $manyToManyAttributeOwner */
$manyToManyAttributeOwner = new $attributeClass( $ownerEntity, $manyToManyTargetAttribute->getName(), 'array' );
$manyToManyAttributeOwner
->setOwnerSide(true)
->setForeign('ManyToMany')
->setForeignEntity($targetEntity)
->setForeignKey($targetEntity->getPrimaryAttribute())
->setNull($manyToManyTargetAttribute->getNull())
->setManyToManyEntityName($manyToManyEntityName);
/** @var Attribute $manyToManyAttributeTarget */
$manyToManyAttributeTarget = new $attributeClass( $targetEntity, $manyToManyOwnerAttribute->getName(), 'array' );
$manyToManyAttributeTarget
->setForeign('ManyToMany')
->setForeignEntity($ownerEntity)
->setForeignKey($ownerEntity->getPrimaryAttribute())
->setNull($manyToManyOwnerAttribute->getNull())
->setManyToManyEntityName($manyToManyEntityName);
$manyToManyAttributeTarget->setReverseAttribute($manyToManyAttributeOwner);
$manyToManyAttributeOwner->setReverseAttribute($manyToManyAttributeTarget);
$ownerEntity->addAttribute($manyToManyAttributeOwner);
$targetEntity->addAttribute($manyToManyAttributeTarget);
if (!isset($attributesToBeAdded[$ownerEntity->getFullyQualifiedName()][$manyToManyTargetAttribute->getName()])) {
$attributesToBeAdded[$ownerEntity->getFullyQualifiedName()][$manyToManyTargetAttribute->getName()] = 1;
} else {
$attributesToBeAdded[$ownerEntity->getFullyQualifiedName()][$manyToManyTargetAttribute->getName()]++;
}
if (!isset($attributesToBeAdded[$targetEntity->getFullyQualifiedName()][$manyToManyOwnerAttribute->getName()])) {
$attributesToBeAdded[$targetEntity->getFullyQualifiedName()][$manyToManyOwnerAttribute->getName()] = 1;
} else {
$attributesToBeAdded[$targetEntity->getFullyQualifiedName()][$manyToManyOwnerAttribute->getName()]++;
}
// $manyToManyEntity->setRenderizable(false);
}
}
// Add OneToOne and OneToMany inverse attributes
$foreignKeys = $xmlDesign->xpath('relationships/relation[@type=\'one-to-one\' or @type=\'one-to-many\']');
// Find ideal new attribute counters
foreach ($foreignKeys as $foreignKey) {
$relationAttributes = (array)$foreignKey->attributes();
$relationAttributes = $relationAttributes['@attributes'];
$type = $relationAttributes['type'];
// Backwards compatibility
if ($type == 'one-to-one') {
$type = 'OneToOne';
} elseif ($type == 'many-to-one') {
$type = 'ManyToOne';
}
// End of backwards compatibility
$sourceEntityName = (string)$foreignKey->attributes()->from;
$targetEntityName = (string)$foreignKey->attributes()->to;
$sourceEntity = &$this->getEntityByFullyQualifiedName($sourceEntityName);
$targetEntity = & $this->getEntityByFullyQualifiedName($targetEntityName);
if ('OneToOne' === $type) {
$desiredName = $targetEntity->getLowerName();
} else {
$desiredName = $targetEntity->getPluralLowerName();
}
if (!isset($attributesToBeAdded[$sourceEntity->getFullyQualifiedName()][$desiredName])) {
$attributesToBeAdded[$sourceEntity->getFullyQualifiedName()][$desiredName] = 1;
} else {
$attributesToBeAdded[$sourceEntity->getFullyQualifiedName()][$desiredName]++;
}
}
// Actually add the attributes
foreach ($foreignKeys as $foreignKey) {
$relationAttributes = (array)$foreignKey->attributes();
$relationAttributes = $relationAttributes['@attributes'];
$sourceEntityName = (string)$foreignKey->attributes()->from;
$sourceAttributeName = (string)$foreignKey->attributes()->fromAttribute;
$targetEntityName = (string)$foreignKey->attributes()->to;
$targetAttributeName = (string)$foreignKey->attributes()->toAttribute;
$sourceEntity = &$this->getEntityByFullyQualifiedName($sourceEntityName);
$sourceAttribute = &$sourceEntity->getAttributeByName($sourceAttributeName);
$targetEntity = &$this->getEntityByFullyQualifiedName($targetEntityName);
$targetAttribute = &$targetEntity->getAttributeByName($targetAttributeName);
$type = $relationAttributes['type'];
// Backwards compatibility
if ($type == 'one-to-one') {
$type = 'OneToOne';
} elseif ($type == 'many-to-one') {
$type = 'ManyToOne';
}
// End of backwards compatibility
if ($targetEntity->getRenderizable()) {
if ('OneToOne' === $type) {
$desiredName = $targetEntity->getLowerName();
} else {
$desiredName = $targetEntity->getPluralLowerName();
}
list($attributeName, $attributeSuffix) = 1 === $attributesToBeAdded[$sourceEntity->getFullyQualifiedName()][$desiredName]
? $this->getActualAttributeName($sourceEntity, $desiredName)
: $this->getActualAttributeName($sourceEntity, $desiredName, $targetAttribute->getUpperName(), true);
if ($type === 'OneToOne') {
/** @var Attribute $inverseAttribute */
$inverseAttribute = new $attributeClass($sourceEntity, $attributeName, 'object');
$inverseAttribute
->setSuffix($attributeSuffix)
->setInverse(true)
->setSubtype($targetEntity->getRelativePathName())
->setForeign('OneToOne')
->setForeignEntity($targetEntity)
->setForeignKey($targetAttribute)
->setNull($targetAttribute->getNull()) // TODO: CHECK
->setReverseAttribute($targetAttribute);
$targetAttribute->setReverseAttribute($inverseAttribute);
} else { // ManyToOne
/** @var Attribute $inverseAttribute */
$inverseAttribute = new $attributeClass($sourceEntity, $attributeName, 'array');
$inverseAttribute
->setSuffix($attributeSuffix)
->setInverse(true)
->setSubtype($targetEntity->getRelativePathName())
->setForeign('ManyToOne')
->setForeignEntity($targetEntity)
->setForeignKey($targetAttribute)
->setNull($targetAttribute->getNull()) // TODO: CHECK
->setReverseAttribute($targetAttribute);
$targetAttribute->setReverseAttribute($inverseAttribute);
}
if ($sourceEntity->hasAttributeByName($desiredName . $attributeSuffix)) {
$this->log->prepend('*** The ' . $type . ' inverse attribute \'' . $inverseAttribute->getLowerName() . '\' could not be added to the Entity \'' . $sourceEntity->getName() . '\' because there is an attribute with that name already there. It had to be renamed to \'' . $attributeName . '\'.');
}
$sourceEntity->addAttribute($inverseAttribute);
$targetAttribute->setCascadePersist('both'); // Backwards compatibility
$targetAttribute->setCascadeRemove('both'); // Backwards compatibility
foreach ($relationAttributes as $attributeName => $attributeValue) {
switch ($attributeName) {
case 'broken':
break; // Already dealt with
case 'from':
break; // Already dealt with
case 'fromAttribute':
break; // Already dealt with
case 'persist':
$targetAttribute->setCascadePersist($attributeValue);
break;
case 'remove':
$targetAttribute->setCascadeRemove($attributeValue);
break;
case 'to':
break; // Already dealt with
case 'toAttribute':
break; // Already dealt with
case 'type':
break; // Already dealt with
default:
throw new \Exception( 'The relation from the entity ' . $sourceEntity->getName() . ' to the entity ' . $targetEntity->getName() . ' has an unknown attribute (' . $attributeName . ')' );
}
}
}
}
return $this;
} | [
"public",
"function",
"loadDesign",
"(",
"\\",
"SimpleXMLElement",
"$",
"xmlDesign",
")",
"{",
"// Load project properties",
"$",
"projectProperties",
"=",
"(",
"array",
")",
"$",
"xmlDesign",
"->",
"xpath",
"(",
"'project'",
")",
"[",
"0",
"]",
";",
"$",
"this",
"->",
"setLanguage",
"(",
"(",
"string",
")",
"$",
"projectProperties",
"[",
"'language'",
"]",
")",
";",
"$",
"this",
"->",
"setFramework",
"(",
"(",
"string",
")",
"$",
"projectProperties",
"[",
"'framework'",
"]",
")",
";",
"$",
"this",
"->",
"setOrm",
"(",
"(",
"string",
")",
"$",
"projectProperties",
"[",
"'orm'",
"]",
")",
";",
"$",
"this",
"->",
"setDescription",
"(",
"(",
"string",
")",
"$",
"projectProperties",
"[",
"'description'",
"]",
")",
";",
"$",
"this",
"->",
"configuration",
"=",
"$",
"this",
"->",
"calculateConfiguration",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getLanguage",
"(",
")",
"===",
"'php'",
")",
"{",
"$",
"this",
"->",
"setAttributeClass",
"(",
"'Draggy\\\\Autocode\\\\PHPAttribute'",
")",
";",
"$",
"this",
"->",
"setEntityClass",
"(",
"'Draggy\\\\Autocode\\\\PHPEntity'",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"getLanguage",
"(",
")",
"===",
"'js'",
")",
"{",
"$",
"this",
"->",
"setAttributeClass",
"(",
"'Draggy\\\\Autocode\\\\JSAttribute'",
")",
";",
"$",
"this",
"->",
"setEntityClass",
"(",
"'Draggy\\\\Autocode\\\\Entity'",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"getLanguage",
"(",
")",
"===",
"'java'",
")",
"{",
"$",
"this",
"->",
"setAttributeClass",
"(",
"'Draggy\\\\Autocode\\\\JavaAttribute'",
")",
";",
"$",
"this",
"->",
"setEntityClass",
"(",
"'Draggy\\\\Autocode\\\\JavaEntity'",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"getLanguage",
"(",
")",
"===",
"'cpp'",
")",
"{",
"$",
"this",
"->",
"setAttributeClass",
"(",
"'Draggy\\\\Autocode\\\\CPPAttribute'",
")",
";",
"$",
"this",
"->",
"setEntityClass",
"(",
"'Draggy\\\\Autocode\\\\CPPEntity'",
")",
";",
"}",
"$",
"attributeClass",
"=",
"$",
"this",
"->",
"getAttributeClass",
"(",
")",
";",
"// Load autocode settings",
"$",
"autocode",
"=",
"(",
"array",
")",
"$",
"xmlDesign",
"->",
"xpath",
"(",
"'autocode'",
")",
"[",
"0",
"]",
";",
"$",
"autocodeProperties",
"=",
"(",
"array",
")",
"$",
"autocode",
"[",
"'properties'",
"]",
";",
"$",
"autocodeConfigurations",
"=",
"(",
"array",
")",
"$",
"autocode",
"[",
"'configurations'",
"]",
";",
"$",
"autocodeTemplates",
"=",
"(",
"array",
")",
"$",
"autocode",
"[",
"'templates'",
"]",
";",
"foreach",
"(",
"$",
"autocodeProperties",
"as",
"$",
"propertyName",
"=>",
"$",
"propertyValue",
")",
"{",
"$",
"this",
"->",
"setAutocodeProperty",
"(",
"$",
"propertyName",
",",
"'true'",
"===",
"$",
"propertyValue",
")",
";",
"}",
"foreach",
"(",
"$",
"autocodeConfigurations",
"as",
"$",
"configurationName",
"=>",
"$",
"configurationValue",
")",
"{",
"$",
"this",
"->",
"setAutocodeConfiguration",
"(",
"$",
"configurationName",
",",
"$",
"configurationValue",
")",
";",
"}",
"foreach",
"(",
"$",
"autocodeTemplates",
"as",
"$",
"templateName",
"=>",
"$",
"templateValue",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"templateValue",
")",
")",
"{",
"// Use the default template",
"$",
"template",
"=",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
"[",
"'autocode'",
"]",
"[",
"'templates'",
"]",
"[",
"$",
"templateName",
"]",
"[",
"'template'",
"]",
";",
"}",
"else",
"{",
"$",
"template",
"=",
"$",
"templateValue",
";",
"}",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"template",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'The specified class file \\'%s\\' cannot be loaded'",
",",
"$",
"template",
")",
")",
";",
"}",
"$",
"this",
"->",
"setAutocodeTemplate",
"(",
"$",
"templateName",
",",
"new",
"$",
"template",
")",
";",
"}",
"// Process entities",
"$",
"modules",
"=",
"$",
"xmlDesign",
"->",
"xpath",
"(",
"'module'",
")",
";",
"// Process in three steps. First create all the entities, second add all the attributes, and finally link the foreign entities.",
"// This way it can reference foreign entities and attributes because they will exist.",
"// First step: Add the entities (Classes or Abstracts)",
"foreach",
"(",
"$",
"modules",
"as",
"$",
"module",
")",
"{",
"$",
"moduleName",
"=",
"(",
"string",
")",
"$",
"module",
"->",
"attributes",
"(",
")",
"->",
"name",
";",
"$",
"this",
"->",
"log",
"->",
"appendExtended",
"(",
"'Found module: '",
".",
"$",
"moduleName",
")",
";",
"// Classes",
"$",
"classes",
"=",
"$",
"module",
"->",
"xpath",
"(",
"'*[self::class]'",
")",
";",
"foreach",
"(",
"$",
"classes",
"as",
"$",
"class",
")",
"{",
"$",
"class",
"->",
"addAttribute",
"(",
"'fullyQualifiedName'",
",",
"$",
"moduleName",
".",
"'\\\\'",
".",
"$",
"class",
"->",
"attributes",
"(",
")",
"->",
"name",
")",
";",
"$",
"entity",
"=",
"$",
"this",
"->",
"xmlEntityToEntity",
"(",
"$",
"class",
",",
"$",
"moduleName",
")",
";",
"$",
"entity",
"->",
"setType",
"(",
"'class'",
")",
";",
"$",
"this",
"->",
"addEntity",
"(",
"$",
"entity",
")",
";",
"}",
"// Abstracts",
"$",
"abstracts",
"=",
"$",
"module",
"->",
"xpath",
"(",
"'*[self::abstract]'",
")",
";",
"foreach",
"(",
"$",
"abstracts",
"as",
"$",
"abstract",
")",
"{",
"$",
"abstract",
"->",
"addAttribute",
"(",
"'fullyQualifiedName'",
",",
"$",
"moduleName",
".",
"'\\\\'",
".",
"$",
"abstract",
"->",
"attributes",
"(",
")",
"->",
"name",
")",
";",
"$",
"entity",
"=",
"$",
"this",
"->",
"xmlEntityToEntity",
"(",
"$",
"abstract",
",",
"$",
"moduleName",
")",
";",
"$",
"entity",
"->",
"setType",
"(",
"'abstract'",
")",
";",
"$",
"this",
"->",
"addEntity",
"(",
"$",
"entity",
")",
";",
"}",
"}",
"// Add loose entities",
"$",
"loose",
"=",
"$",
"xmlDesign",
"->",
"xpath",
"(",
"'loose'",
")",
"[",
"0",
"]",
";",
"$",
"classes",
"=",
"$",
"loose",
"->",
"xpath",
"(",
"'*[self::class]'",
")",
";",
"foreach",
"(",
"$",
"classes",
"as",
"$",
"class",
")",
"{",
"$",
"class",
"->",
"addAttribute",
"(",
"'fullyQualifiedName'",
",",
"$",
"class",
"->",
"attributes",
"(",
")",
"->",
"name",
")",
";",
"// Add fully qualified name",
"$",
"entity",
"=",
"$",
"this",
"->",
"xmlEntityToEntity",
"(",
"$",
"class",
")",
";",
"$",
"entity",
"->",
"setType",
"(",
"'class'",
")",
";",
"$",
"this",
"->",
"addEntity",
"(",
"$",
"entity",
")",
";",
"}",
"$",
"abstracts",
"=",
"$",
"loose",
"->",
"xpath",
"(",
"'*[self::abstract]'",
")",
";",
"foreach",
"(",
"$",
"abstracts",
"as",
"$",
"abstract",
")",
"{",
"$",
"abstract",
"->",
"addAttribute",
"(",
"'fullyQualifiedName'",
",",
"$",
"abstract",
"->",
"attributes",
"(",
")",
"->",
"name",
")",
";",
"// Add fully qualified name",
"$",
"entity",
"=",
"$",
"this",
"->",
"xmlEntityToEntity",
"(",
"$",
"abstract",
")",
";",
"$",
"entity",
"->",
"setType",
"(",
"'abstract'",
")",
";",
"$",
"this",
"->",
"addEntity",
"(",
"$",
"entity",
")",
";",
"}",
"// Second step: Add all non-inherited attributes",
"$",
"classes",
"=",
"$",
"xmlDesign",
"->",
"xpath",
"(",
"'*[self::module or self::loose]/*[self::class or self::abstract]'",
")",
";",
"foreach",
"(",
"$",
"classes",
"as",
"$",
"class",
")",
"{",
"$",
"classAttributes",
"=",
"(",
"array",
")",
"$",
"class",
"->",
"attributes",
"(",
")",
";",
"$",
"classAttributes",
"=",
"$",
"classAttributes",
"[",
"'@attributes'",
"]",
";",
"$",
"entityName",
"=",
"$",
"classAttributes",
"[",
"'name'",
"]",
";",
"$",
"entityFullyQualifiedName",
"=",
"$",
"classAttributes",
"[",
"'fullyQualifiedName'",
"]",
";",
"$",
"entity",
"=",
"$",
"this",
"->",
"getEntityByFullyQualifiedName",
"(",
"$",
"entityFullyQualifiedName",
")",
";",
"$",
"attributes",
"=",
"$",
"class",
"->",
"xpath",
"(",
"'attribute[not(@inherited=\\'true\\')]'",
")",
";",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"attribute",
")",
"{",
"$",
"attributeAttributes",
"=",
"(",
"array",
")",
"$",
"attribute",
"->",
"attributes",
"(",
")",
";",
"$",
"attributeAttributes",
"=",
"$",
"attributeAttributes",
"[",
"'@attributes'",
"]",
";",
"$",
"attributeName",
"=",
"$",
"attributeAttributes",
"[",
"'name'",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"attributeAttributes",
"[",
"'type'",
"]",
")",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"'The attribute '",
".",
"$",
"attributeName",
".",
"' on the entity '",
".",
"$",
"entityName",
".",
"' doesn\\'t have a type'",
")",
";",
"/** @var Attribute $attribute */",
"$",
"attribute",
"=",
"new",
"$",
"attributeClass",
"(",
"$",
"entity",
",",
"$",
"attributeName",
",",
"$",
"attributeAttributes",
"[",
"'type'",
"]",
")",
";",
"foreach",
"(",
"$",
"attributeAttributes",
"as",
"$",
"attributeName",
"=>",
"$",
"attributeValue",
")",
"{",
"switch",
"(",
"$",
"attributeName",
")",
"{",
"case",
"'autoincrement'",
":",
"$",
"attribute",
"->",
"setAutoIncrement",
"(",
"$",
"attributeValue",
"===",
"'true'",
")",
";",
"break",
";",
"case",
"'primary'",
":",
"$",
"attribute",
"->",
"setPrimary",
"(",
"$",
"attributeValue",
"===",
"'true'",
")",
";",
"break",
";",
"case",
"'name'",
":",
"case",
"'type'",
":",
"case",
"'id'",
":",
"break",
";",
"// Already dealt with",
"case",
"'subtype'",
":",
"$",
"attribute",
"->",
"setSubtype",
"(",
"$",
"attributeValue",
")",
";",
"break",
";",
"case",
"'description'",
":",
"$",
"attribute",
"->",
"setDescription",
"(",
"$",
"attributeValue",
")",
";",
"break",
";",
"case",
"'size'",
":",
"$",
"attribute",
"->",
"setSize",
"(",
"(",
"int",
")",
"$",
"attributeValue",
")",
";",
"break",
";",
"case",
"'minSize'",
":",
"$",
"attribute",
"->",
"setMinSize",
"(",
"(",
"int",
")",
"$",
"attributeValue",
")",
";",
"break",
";",
"case",
"'min'",
":",
"$",
"attribute",
"->",
"setMin",
"(",
"(",
"int",
")",
"$",
"attributeValue",
")",
";",
"break",
";",
"case",
"'max'",
":",
"$",
"attribute",
"->",
"setMax",
"(",
"(",
"int",
")",
"$",
"attributeValue",
")",
";",
"break",
";",
"case",
"'null'",
":",
"$",
"attribute",
"->",
"setNull",
"(",
"$",
"attributeValue",
"===",
"'true'",
")",
";",
"break",
";",
"case",
"'unique'",
":",
"$",
"attribute",
"->",
"setUnique",
"(",
"$",
"attributeValue",
"===",
"'true'",
")",
";",
"break",
";",
"case",
"'default'",
":",
"$",
"attribute",
"->",
"setDefaultValue",
"(",
"$",
"attributeValue",
")",
";",
"break",
";",
"case",
"'foreign'",
":",
"$",
"attribute",
"->",
"setForeignTick",
"(",
"$",
"attributeValue",
"===",
"'true'",
")",
";",
"break",
";",
"case",
"'setter'",
":",
"$",
"attribute",
"->",
"setSetter",
"(",
"$",
"attributeValue",
"===",
"'true'",
")",
";",
"break",
";",
"case",
"'getter'",
":",
"$",
"attribute",
"->",
"setGetter",
"(",
"$",
"attributeValue",
"===",
"'true'",
")",
";",
"break",
";",
"case",
"'email'",
":",
"$",
"attribute",
"->",
"setEmail",
"(",
"$",
"attributeValue",
"===",
"'true'",
")",
";",
"break",
";",
"case",
"'static'",
":",
"$",
"attribute",
"->",
"setStatic",
"(",
"$",
"attributeValue",
"===",
"'true'",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"Exception",
"(",
"'The attribute '",
".",
"$",
"attributeAttributes",
"[",
"'name'",
"]",
".",
"' on the entity '",
".",
"$",
"entityName",
".",
"' has an unknown attribute ('",
".",
"$",
"attributeName",
".",
"')'",
")",
";",
"}",
"}",
"if",
"(",
"$",
"attribute",
"->",
"getAutoIncrement",
"(",
")",
"&&",
"!",
"$",
"attribute",
"->",
"getForeignTick",
"(",
")",
")",
"$",
"attribute",
"->",
"setSetter",
"(",
"false",
")",
";",
"// If it is autoincrement, can't have a setter unless is a foreign key",
"$",
"entity",
"->",
"addAttribute",
"(",
"$",
"attribute",
")",
";",
"}",
"}",
"// Find inherited classes and mark their parent entities",
"$",
"childClasses",
"=",
"$",
"xmlDesign",
"->",
"xpath",
"(",
"'*[self::module or self::loose]/*[@inheritingFrom and (self::abstract)]'",
")",
";",
"foreach",
"(",
"$",
"childClasses",
"as",
"$",
"childClass",
")",
"{",
"$",
"childClassAttributes",
"=",
"(",
"array",
")",
"$",
"childClass",
"->",
"attributes",
"(",
")",
";",
"$",
"childClassAttributes",
"=",
"$",
"childClassAttributes",
"[",
"'@attributes'",
"]",
";",
"$",
"childClassFullyQualifiedName",
"=",
"$",
"childClassAttributes",
"[",
"'fullyQualifiedName'",
"]",
";",
"$",
"parentName",
"=",
"$",
"childClassAttributes",
"[",
"'inheritingFrom'",
"]",
";",
"$",
"child",
"=",
"&",
"$",
"this",
"->",
"getEntityByFullyQualifiedName",
"(",
"$",
"childClassFullyQualifiedName",
")",
";",
"$",
"parent",
"=",
"&",
"$",
"this",
"->",
"getEntityByFullyQualifiedName",
"(",
"$",
"parentName",
")",
";",
"$",
"child",
"->",
"setParentEntity",
"(",
"$",
"parent",
")",
";",
"$",
"parent",
"->",
"addChildrenEntity",
"(",
"$",
"child",
")",
";",
"foreach",
"(",
"$",
"parent",
"->",
"getAttributes",
"(",
")",
"as",
"$",
"attrNode",
")",
"{",
"$",
"child",
"->",
"addAttributeReference",
"(",
"$",
"attrNode",
")",
";",
"}",
"unset",
"(",
"$",
"child",
",",
"$",
"parent",
")",
";",
"}",
"$",
"childClasses",
"=",
"$",
"xmlDesign",
"->",
"xpath",
"(",
"'*[self::module or self::loose]/*[@inheritingFrom and (self::class)]'",
")",
";",
"foreach",
"(",
"$",
"childClasses",
"as",
"$",
"childClass",
")",
"{",
"$",
"childClassAttributes",
"=",
"(",
"array",
")",
"$",
"childClass",
"->",
"attributes",
"(",
")",
";",
"$",
"childClassAttributes",
"=",
"$",
"childClassAttributes",
"[",
"'@attributes'",
"]",
";",
"$",
"childClassFullyQualifiedName",
"=",
"$",
"childClassAttributes",
"[",
"'fullyQualifiedName'",
"]",
";",
"$",
"parentName",
"=",
"$",
"childClassAttributes",
"[",
"'inheritingFrom'",
"]",
";",
"$",
"child",
"=",
"&",
"$",
"this",
"->",
"getEntityByFullyQualifiedName",
"(",
"$",
"childClassFullyQualifiedName",
")",
";",
"$",
"parent",
"=",
"&",
"$",
"this",
"->",
"getEntityByFullyQualifiedName",
"(",
"$",
"parentName",
")",
";",
"$",
"child",
"->",
"setParentEntity",
"(",
"$",
"parent",
")",
";",
"$",
"parent",
"->",
"addChildrenEntity",
"(",
"$",
"child",
")",
";",
"foreach",
"(",
"$",
"parent",
"->",
"getAttributes",
"(",
")",
"as",
"$",
"attrNode",
")",
"{",
"$",
"child",
"->",
"addAttributeReference",
"(",
"$",
"attrNode",
")",
";",
"}",
"unset",
"(",
"$",
"child",
",",
"$",
"parent",
")",
";",
"}",
"// Fix ManyToMany relationships without attributes",
"$",
"manyToManyRelationships",
"=",
"$",
"xmlDesign",
"->",
"xpath",
"(",
"'*[self::module or self::loose]/class[@manyToMany=\\'true\\']'",
")",
";",
"// Mark many to many virtual entities",
"foreach",
"(",
"$",
"manyToManyRelationships",
"as",
"$",
"manyToManyRelationship",
")",
"{",
"$",
"manyToManyEntityName",
"=",
"(",
"array",
")",
"$",
"manyToManyRelationship",
"->",
"attributes",
"(",
")",
";",
"$",
"manyToManyEntityFullyQualifiedName",
"=",
"$",
"manyToManyEntityName",
"[",
"'@attributes'",
"]",
"[",
"'fullyQualifiedName'",
"]",
";",
"$",
"manyToManyEntity",
"=",
"&",
"$",
"this",
"->",
"getEntityByFullyQualifiedName",
"(",
"$",
"manyToManyEntityFullyQualifiedName",
")",
";",
"$",
"manyToManyEntityAttributes",
"=",
"$",
"manyToManyEntity",
"->",
"getAttributes",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"manyToManyEntityAttributes",
")",
"==",
"2",
")",
"{",
"// If it is not 2, is not a proper ManyToMany relationship",
"$",
"manyToManyEntity",
"->",
"setRenderizable",
"(",
"false",
")",
";",
"}",
"}",
"// Find and map foreign keys (OneToMany, ManyToOne or OneToOne)",
"$",
"foreignKeys",
"=",
"$",
"xmlDesign",
"->",
"xpath",
"(",
"'relationships/relation[@type=\\'one-to-one\\' or @type=\\'one-to-many\\']'",
")",
";",
"foreach",
"(",
"$",
"foreignKeys",
"as",
"$",
"foreignKey",
")",
"{",
"$",
"sourceEntityName",
"=",
"(",
"string",
")",
"$",
"foreignKey",
"->",
"attributes",
"(",
")",
"->",
"from",
";",
"$",
"sourceAttributeName",
"=",
"(",
"string",
")",
"$",
"foreignKey",
"->",
"attributes",
"(",
")",
"->",
"fromAttribute",
";",
"$",
"targetEntityName",
"=",
"(",
"string",
")",
"$",
"foreignKey",
"->",
"attributes",
"(",
")",
"->",
"to",
";",
"$",
"targetAttributeName",
"=",
"(",
"string",
")",
"$",
"foreignKey",
"->",
"attributes",
"(",
")",
"->",
"toAttribute",
";",
"$",
"sourceEntity",
"=",
"&",
"$",
"this",
"->",
"getEntityByFullyQualifiedName",
"(",
"$",
"sourceEntityName",
")",
";",
"$",
"sourceAttribute",
"=",
"&",
"$",
"sourceEntity",
"->",
"getAttributeByName",
"(",
"$",
"sourceAttributeName",
")",
";",
"$",
"targetEntity",
"=",
"&",
"$",
"this",
"->",
"getEntityByFullyQualifiedName",
"(",
"$",
"targetEntityName",
")",
";",
"$",
"targetAttribute",
"=",
"&",
"$",
"targetEntity",
"->",
"getAttributeByName",
"(",
"$",
"targetAttributeName",
")",
";",
"//echo 'source attr: ' . $sourceEntityName . '\\\\' . $sourceAttribute->getName() . '<br>';",
"//echo 'target attr: ' . $targetEntityName . '\\\\' . $targetAttribute->getName() . '<br><br>';",
"/*if ($sourceAttribute->getUnique()) // ???\n $sourceAttribute->setForeign('OneToOne');\n else\n $sourceAttribute->setForeign('ManyToOne');\n\t */",
"$",
"type",
"=",
"(",
"string",
")",
"$",
"foreignKey",
"->",
"attributes",
"(",
")",
"->",
"type",
";",
"// Backwards compatibility",
"if",
"(",
"$",
"type",
"==",
"'one-to-one'",
")",
"{",
"$",
"type",
"=",
"'OneToOne'",
";",
"}",
"elseif",
"(",
"$",
"type",
"==",
"'many-to-one'",
")",
"{",
"$",
"type",
"=",
"'ManyToOne'",
";",
"}",
"// End of backwards compatibility",
"if",
"(",
"$",
"type",
"===",
"'OneToOne'",
")",
"{",
"$",
"targetAttribute",
"->",
"setForeign",
"(",
"'OneToOne'",
")",
";",
"}",
"else",
"{",
"// ManyToOne",
"$",
"targetAttribute",
"->",
"setForeign",
"(",
"'ManyToOne'",
")",
";",
"}",
"$",
"targetAttribute",
"->",
"setOwnerSide",
"(",
"true",
")",
";",
"//$sourceAttribute->setForeignEntity($targetEntity);",
"//$sourceAttribute->setForeignKey($targetAttribute);",
"$",
"targetAttribute",
"->",
"setForeignEntity",
"(",
"$",
"sourceEntity",
")",
";",
"$",
"targetAttribute",
"->",
"setForeignKey",
"(",
"$",
"sourceAttribute",
")",
";",
"}",
"$",
"attributesToBeAdded",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"manyToManyRelationships",
"as",
"$",
"manyToManyRelationship",
")",
"{",
"$",
"manyToManyEntityNameArray",
"=",
"(",
"array",
")",
"$",
"manyToManyRelationship",
"->",
"attributes",
"(",
")",
";",
"$",
"manyToManyEntityName",
"=",
"$",
"manyToManyEntityNameArray",
"[",
"'@attributes'",
"]",
"[",
"'name'",
"]",
";",
"$",
"manyToManyEntityFullyQualifiedName",
"=",
"$",
"manyToManyEntityNameArray",
"[",
"'@attributes'",
"]",
"[",
"'fullyQualifiedName'",
"]",
";",
"$",
"manyToManyEntity",
"=",
"&",
"$",
"this",
"->",
"getEntityByFullyQualifiedName",
"(",
"$",
"manyToManyEntityFullyQualifiedName",
")",
";",
"$",
"manyToManyEntityAttributes",
"=",
"$",
"manyToManyEntity",
"->",
"getAttributes",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"manyToManyEntityAttributes",
")",
"==",
"2",
")",
"{",
"// If it is not 2, is not a proper ManyToMany relationship",
"$",
"manyToManyOwnerAttribute",
"=",
"$",
"manyToManyEntity",
"->",
"getAttribute",
"(",
"0",
")",
";",
"$",
"manyToManyTargetAttribute",
"=",
"$",
"manyToManyEntity",
"->",
"getAttribute",
"(",
"1",
")",
";",
"$",
"ownerEntity",
"=",
"&",
"$",
"manyToManyOwnerAttribute",
"->",
"getForeignEntity",
"(",
")",
";",
"$",
"targetEntity",
"=",
"&",
"$",
"manyToManyTargetAttribute",
"->",
"getForeignEntity",
"(",
")",
";",
"/** @var Attribute $manyToManyAttributeOwner */",
"$",
"manyToManyAttributeOwner",
"=",
"new",
"$",
"attributeClass",
"(",
"$",
"ownerEntity",
",",
"$",
"manyToManyTargetAttribute",
"->",
"getName",
"(",
")",
",",
"'array'",
")",
";",
"$",
"manyToManyAttributeOwner",
"->",
"setOwnerSide",
"(",
"true",
")",
"->",
"setForeign",
"(",
"'ManyToMany'",
")",
"->",
"setForeignEntity",
"(",
"$",
"targetEntity",
")",
"->",
"setForeignKey",
"(",
"$",
"targetEntity",
"->",
"getPrimaryAttribute",
"(",
")",
")",
"->",
"setNull",
"(",
"$",
"manyToManyTargetAttribute",
"->",
"getNull",
"(",
")",
")",
"->",
"setManyToManyEntityName",
"(",
"$",
"manyToManyEntityName",
")",
";",
"/** @var Attribute $manyToManyAttributeTarget */",
"$",
"manyToManyAttributeTarget",
"=",
"new",
"$",
"attributeClass",
"(",
"$",
"targetEntity",
",",
"$",
"manyToManyOwnerAttribute",
"->",
"getName",
"(",
")",
",",
"'array'",
")",
";",
"$",
"manyToManyAttributeTarget",
"->",
"setForeign",
"(",
"'ManyToMany'",
")",
"->",
"setForeignEntity",
"(",
"$",
"ownerEntity",
")",
"->",
"setForeignKey",
"(",
"$",
"ownerEntity",
"->",
"getPrimaryAttribute",
"(",
")",
")",
"->",
"setNull",
"(",
"$",
"manyToManyOwnerAttribute",
"->",
"getNull",
"(",
")",
")",
"->",
"setManyToManyEntityName",
"(",
"$",
"manyToManyEntityName",
")",
";",
"$",
"manyToManyAttributeTarget",
"->",
"setReverseAttribute",
"(",
"$",
"manyToManyAttributeOwner",
")",
";",
"$",
"manyToManyAttributeOwner",
"->",
"setReverseAttribute",
"(",
"$",
"manyToManyAttributeTarget",
")",
";",
"$",
"ownerEntity",
"->",
"addAttribute",
"(",
"$",
"manyToManyAttributeOwner",
")",
";",
"$",
"targetEntity",
"->",
"addAttribute",
"(",
"$",
"manyToManyAttributeTarget",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"attributesToBeAdded",
"[",
"$",
"ownerEntity",
"->",
"getFullyQualifiedName",
"(",
")",
"]",
"[",
"$",
"manyToManyTargetAttribute",
"->",
"getName",
"(",
")",
"]",
")",
")",
"{",
"$",
"attributesToBeAdded",
"[",
"$",
"ownerEntity",
"->",
"getFullyQualifiedName",
"(",
")",
"]",
"[",
"$",
"manyToManyTargetAttribute",
"->",
"getName",
"(",
")",
"]",
"=",
"1",
";",
"}",
"else",
"{",
"$",
"attributesToBeAdded",
"[",
"$",
"ownerEntity",
"->",
"getFullyQualifiedName",
"(",
")",
"]",
"[",
"$",
"manyToManyTargetAttribute",
"->",
"getName",
"(",
")",
"]",
"++",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"attributesToBeAdded",
"[",
"$",
"targetEntity",
"->",
"getFullyQualifiedName",
"(",
")",
"]",
"[",
"$",
"manyToManyOwnerAttribute",
"->",
"getName",
"(",
")",
"]",
")",
")",
"{",
"$",
"attributesToBeAdded",
"[",
"$",
"targetEntity",
"->",
"getFullyQualifiedName",
"(",
")",
"]",
"[",
"$",
"manyToManyOwnerAttribute",
"->",
"getName",
"(",
")",
"]",
"=",
"1",
";",
"}",
"else",
"{",
"$",
"attributesToBeAdded",
"[",
"$",
"targetEntity",
"->",
"getFullyQualifiedName",
"(",
")",
"]",
"[",
"$",
"manyToManyOwnerAttribute",
"->",
"getName",
"(",
")",
"]",
"++",
";",
"}",
"// $manyToManyEntity->setRenderizable(false);",
"}",
"}",
"// Add OneToOne and OneToMany inverse attributes",
"$",
"foreignKeys",
"=",
"$",
"xmlDesign",
"->",
"xpath",
"(",
"'relationships/relation[@type=\\'one-to-one\\' or @type=\\'one-to-many\\']'",
")",
";",
"// Find ideal new attribute counters",
"foreach",
"(",
"$",
"foreignKeys",
"as",
"$",
"foreignKey",
")",
"{",
"$",
"relationAttributes",
"=",
"(",
"array",
")",
"$",
"foreignKey",
"->",
"attributes",
"(",
")",
";",
"$",
"relationAttributes",
"=",
"$",
"relationAttributes",
"[",
"'@attributes'",
"]",
";",
"$",
"type",
"=",
"$",
"relationAttributes",
"[",
"'type'",
"]",
";",
"// Backwards compatibility",
"if",
"(",
"$",
"type",
"==",
"'one-to-one'",
")",
"{",
"$",
"type",
"=",
"'OneToOne'",
";",
"}",
"elseif",
"(",
"$",
"type",
"==",
"'many-to-one'",
")",
"{",
"$",
"type",
"=",
"'ManyToOne'",
";",
"}",
"// End of backwards compatibility",
"$",
"sourceEntityName",
"=",
"(",
"string",
")",
"$",
"foreignKey",
"->",
"attributes",
"(",
")",
"->",
"from",
";",
"$",
"targetEntityName",
"=",
"(",
"string",
")",
"$",
"foreignKey",
"->",
"attributes",
"(",
")",
"->",
"to",
";",
"$",
"sourceEntity",
"=",
"&",
"$",
"this",
"->",
"getEntityByFullyQualifiedName",
"(",
"$",
"sourceEntityName",
")",
";",
"$",
"targetEntity",
"=",
"&",
"$",
"this",
"->",
"getEntityByFullyQualifiedName",
"(",
"$",
"targetEntityName",
")",
";",
"if",
"(",
"'OneToOne'",
"===",
"$",
"type",
")",
"{",
"$",
"desiredName",
"=",
"$",
"targetEntity",
"->",
"getLowerName",
"(",
")",
";",
"}",
"else",
"{",
"$",
"desiredName",
"=",
"$",
"targetEntity",
"->",
"getPluralLowerName",
"(",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"attributesToBeAdded",
"[",
"$",
"sourceEntity",
"->",
"getFullyQualifiedName",
"(",
")",
"]",
"[",
"$",
"desiredName",
"]",
")",
")",
"{",
"$",
"attributesToBeAdded",
"[",
"$",
"sourceEntity",
"->",
"getFullyQualifiedName",
"(",
")",
"]",
"[",
"$",
"desiredName",
"]",
"=",
"1",
";",
"}",
"else",
"{",
"$",
"attributesToBeAdded",
"[",
"$",
"sourceEntity",
"->",
"getFullyQualifiedName",
"(",
")",
"]",
"[",
"$",
"desiredName",
"]",
"++",
";",
"}",
"}",
"// Actually add the attributes",
"foreach",
"(",
"$",
"foreignKeys",
"as",
"$",
"foreignKey",
")",
"{",
"$",
"relationAttributes",
"=",
"(",
"array",
")",
"$",
"foreignKey",
"->",
"attributes",
"(",
")",
";",
"$",
"relationAttributes",
"=",
"$",
"relationAttributes",
"[",
"'@attributes'",
"]",
";",
"$",
"sourceEntityName",
"=",
"(",
"string",
")",
"$",
"foreignKey",
"->",
"attributes",
"(",
")",
"->",
"from",
";",
"$",
"sourceAttributeName",
"=",
"(",
"string",
")",
"$",
"foreignKey",
"->",
"attributes",
"(",
")",
"->",
"fromAttribute",
";",
"$",
"targetEntityName",
"=",
"(",
"string",
")",
"$",
"foreignKey",
"->",
"attributes",
"(",
")",
"->",
"to",
";",
"$",
"targetAttributeName",
"=",
"(",
"string",
")",
"$",
"foreignKey",
"->",
"attributes",
"(",
")",
"->",
"toAttribute",
";",
"$",
"sourceEntity",
"=",
"&",
"$",
"this",
"->",
"getEntityByFullyQualifiedName",
"(",
"$",
"sourceEntityName",
")",
";",
"$",
"sourceAttribute",
"=",
"&",
"$",
"sourceEntity",
"->",
"getAttributeByName",
"(",
"$",
"sourceAttributeName",
")",
";",
"$",
"targetEntity",
"=",
"&",
"$",
"this",
"->",
"getEntityByFullyQualifiedName",
"(",
"$",
"targetEntityName",
")",
";",
"$",
"targetAttribute",
"=",
"&",
"$",
"targetEntity",
"->",
"getAttributeByName",
"(",
"$",
"targetAttributeName",
")",
";",
"$",
"type",
"=",
"$",
"relationAttributes",
"[",
"'type'",
"]",
";",
"// Backwards compatibility",
"if",
"(",
"$",
"type",
"==",
"'one-to-one'",
")",
"{",
"$",
"type",
"=",
"'OneToOne'",
";",
"}",
"elseif",
"(",
"$",
"type",
"==",
"'many-to-one'",
")",
"{",
"$",
"type",
"=",
"'ManyToOne'",
";",
"}",
"// End of backwards compatibility",
"if",
"(",
"$",
"targetEntity",
"->",
"getRenderizable",
"(",
")",
")",
"{",
"if",
"(",
"'OneToOne'",
"===",
"$",
"type",
")",
"{",
"$",
"desiredName",
"=",
"$",
"targetEntity",
"->",
"getLowerName",
"(",
")",
";",
"}",
"else",
"{",
"$",
"desiredName",
"=",
"$",
"targetEntity",
"->",
"getPluralLowerName",
"(",
")",
";",
"}",
"list",
"(",
"$",
"attributeName",
",",
"$",
"attributeSuffix",
")",
"=",
"1",
"===",
"$",
"attributesToBeAdded",
"[",
"$",
"sourceEntity",
"->",
"getFullyQualifiedName",
"(",
")",
"]",
"[",
"$",
"desiredName",
"]",
"?",
"$",
"this",
"->",
"getActualAttributeName",
"(",
"$",
"sourceEntity",
",",
"$",
"desiredName",
")",
":",
"$",
"this",
"->",
"getActualAttributeName",
"(",
"$",
"sourceEntity",
",",
"$",
"desiredName",
",",
"$",
"targetAttribute",
"->",
"getUpperName",
"(",
")",
",",
"true",
")",
";",
"if",
"(",
"$",
"type",
"===",
"'OneToOne'",
")",
"{",
"/** @var Attribute $inverseAttribute */",
"$",
"inverseAttribute",
"=",
"new",
"$",
"attributeClass",
"(",
"$",
"sourceEntity",
",",
"$",
"attributeName",
",",
"'object'",
")",
";",
"$",
"inverseAttribute",
"->",
"setSuffix",
"(",
"$",
"attributeSuffix",
")",
"->",
"setInverse",
"(",
"true",
")",
"->",
"setSubtype",
"(",
"$",
"targetEntity",
"->",
"getRelativePathName",
"(",
")",
")",
"->",
"setForeign",
"(",
"'OneToOne'",
")",
"->",
"setForeignEntity",
"(",
"$",
"targetEntity",
")",
"->",
"setForeignKey",
"(",
"$",
"targetAttribute",
")",
"->",
"setNull",
"(",
"$",
"targetAttribute",
"->",
"getNull",
"(",
")",
")",
"// TODO: CHECK",
"->",
"setReverseAttribute",
"(",
"$",
"targetAttribute",
")",
";",
"$",
"targetAttribute",
"->",
"setReverseAttribute",
"(",
"$",
"inverseAttribute",
")",
";",
"}",
"else",
"{",
"// ManyToOne",
"/** @var Attribute $inverseAttribute */",
"$",
"inverseAttribute",
"=",
"new",
"$",
"attributeClass",
"(",
"$",
"sourceEntity",
",",
"$",
"attributeName",
",",
"'array'",
")",
";",
"$",
"inverseAttribute",
"->",
"setSuffix",
"(",
"$",
"attributeSuffix",
")",
"->",
"setInverse",
"(",
"true",
")",
"->",
"setSubtype",
"(",
"$",
"targetEntity",
"->",
"getRelativePathName",
"(",
")",
")",
"->",
"setForeign",
"(",
"'ManyToOne'",
")",
"->",
"setForeignEntity",
"(",
"$",
"targetEntity",
")",
"->",
"setForeignKey",
"(",
"$",
"targetAttribute",
")",
"->",
"setNull",
"(",
"$",
"targetAttribute",
"->",
"getNull",
"(",
")",
")",
"// TODO: CHECK",
"->",
"setReverseAttribute",
"(",
"$",
"targetAttribute",
")",
";",
"$",
"targetAttribute",
"->",
"setReverseAttribute",
"(",
"$",
"inverseAttribute",
")",
";",
"}",
"if",
"(",
"$",
"sourceEntity",
"->",
"hasAttributeByName",
"(",
"$",
"desiredName",
".",
"$",
"attributeSuffix",
")",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"prepend",
"(",
"'*** The '",
".",
"$",
"type",
".",
"' inverse attribute \\''",
".",
"$",
"inverseAttribute",
"->",
"getLowerName",
"(",
")",
".",
"'\\' could not be added to the Entity \\''",
".",
"$",
"sourceEntity",
"->",
"getName",
"(",
")",
".",
"'\\' because there is an attribute with that name already there. It had to be renamed to \\''",
".",
"$",
"attributeName",
".",
"'\\'.'",
")",
";",
"}",
"$",
"sourceEntity",
"->",
"addAttribute",
"(",
"$",
"inverseAttribute",
")",
";",
"$",
"targetAttribute",
"->",
"setCascadePersist",
"(",
"'both'",
")",
";",
"// Backwards compatibility",
"$",
"targetAttribute",
"->",
"setCascadeRemove",
"(",
"'both'",
")",
";",
"// Backwards compatibility",
"foreach",
"(",
"$",
"relationAttributes",
"as",
"$",
"attributeName",
"=>",
"$",
"attributeValue",
")",
"{",
"switch",
"(",
"$",
"attributeName",
")",
"{",
"case",
"'broken'",
":",
"break",
";",
"// Already dealt with",
"case",
"'from'",
":",
"break",
";",
"// Already dealt with",
"case",
"'fromAttribute'",
":",
"break",
";",
"// Already dealt with",
"case",
"'persist'",
":",
"$",
"targetAttribute",
"->",
"setCascadePersist",
"(",
"$",
"attributeValue",
")",
";",
"break",
";",
"case",
"'remove'",
":",
"$",
"targetAttribute",
"->",
"setCascadeRemove",
"(",
"$",
"attributeValue",
")",
";",
"break",
";",
"case",
"'to'",
":",
"break",
";",
"// Already dealt with",
"case",
"'toAttribute'",
":",
"break",
";",
"// Already dealt with",
"case",
"'type'",
":",
"break",
";",
"// Already dealt with",
"default",
":",
"throw",
"new",
"\\",
"Exception",
"(",
"'The relation from the entity '",
".",
"$",
"sourceEntity",
"->",
"getName",
"(",
")",
".",
"' to the entity '",
".",
"$",
"targetEntity",
"->",
"getName",
"(",
")",
".",
"' has an unknown attribute ('",
".",
"$",
"attributeName",
".",
"')'",
")",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Loads the XML design to the project
@param \SimpleXMLElement $xmlDesign
@return $this
@throws \RuntimeException
@throws \Exception | [
"Loads",
"the",
"XML",
"design",
"to",
"the",
"project"
] | train | https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Autocode/Project.php#L643-L1158 |
j-d/draggy | src/Draggy/Autocode/Project.php | Project.getActualAttributeName | public function getActualAttributeName(Entity $entity, $name, $hint = '', $force = false)
{
if ($entity->hasAttributeByName($name) || $force) {
if (!$entity->hasAttributeByName($name . $hint)) {
return [$name, $hint];
}
$append = 1;
while ($entity->hasAttributeByName($name . $append . $hint)) {
$append++;
}
return [$name . $append, $hint];
}
return [$name, ''];
} | php | public function getActualAttributeName(Entity $entity, $name, $hint = '', $force = false)
{
if ($entity->hasAttributeByName($name) || $force) {
if (!$entity->hasAttributeByName($name . $hint)) {
return [$name, $hint];
}
$append = 1;
while ($entity->hasAttributeByName($name . $append . $hint)) {
$append++;
}
return [$name . $append, $hint];
}
return [$name, ''];
} | [
"public",
"function",
"getActualAttributeName",
"(",
"Entity",
"$",
"entity",
",",
"$",
"name",
",",
"$",
"hint",
"=",
"''",
",",
"$",
"force",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"entity",
"->",
"hasAttributeByName",
"(",
"$",
"name",
")",
"||",
"$",
"force",
")",
"{",
"if",
"(",
"!",
"$",
"entity",
"->",
"hasAttributeByName",
"(",
"$",
"name",
".",
"$",
"hint",
")",
")",
"{",
"return",
"[",
"$",
"name",
",",
"$",
"hint",
"]",
";",
"}",
"$",
"append",
"=",
"1",
";",
"while",
"(",
"$",
"entity",
"->",
"hasAttributeByName",
"(",
"$",
"name",
".",
"$",
"append",
".",
"$",
"hint",
")",
")",
"{",
"$",
"append",
"++",
";",
"}",
"return",
"[",
"$",
"name",
".",
"$",
"append",
",",
"$",
"hint",
"]",
";",
"}",
"return",
"[",
"$",
"name",
",",
"''",
"]",
";",
"}"
] | Sometimes the automatic name cannot be used because the entity already has an attribute with that name or because is linked many times.
This method gives an actual final name that will be unique.
@param Entity $entity
@param string $name
@param string $hint
@param boolean $force If it should force the use of the hint
@return array | [
"Sometimes",
"the",
"automatic",
"name",
"cannot",
"be",
"used",
"because",
"the",
"entity",
"already",
"has",
"an",
"attribute",
"with",
"that",
"name",
"or",
"because",
"is",
"linked",
"many",
"times",
".",
"This",
"method",
"gives",
"an",
"actual",
"final",
"name",
"that",
"will",
"be",
"unique",
"."
] | train | https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Autocode/Project.php#L1171-L1188 |
j-d/draggy | src/Draggy/Autocode/Project.php | Project.getModelFiles | public function getModelFiles($path)
{
$fileCollection = new FileCollection();
$namespacePath = str_replace('\\', '/', $path . $this->getNamespace() . '/');
$targetPath = $namespacePath;
foreach ($this->getEntities() as $entity) {
if ($entity->getRenderizable()) {
if ($this->getLanguage() === 'php') {
if ($entity->getNamespace() !== '') {
$targetPath = $path . str_replace('\\', '/', $entity->getNamespace()) . '/';
}
} elseif ($this->getLanguage() === 'java') {
if ($entity->getModule() !== '') {
$targetPath = $path . '/' . $this->getAutocodeConfiguration('package') . '/' . str_replace('.', '/', $entity->getModule()) . '/';
}
}
foreach ($this->getAutocodeEntityTemplates() as $template) {
$fileCollection->add($this->renderEntityTemplate($template, $entity, $targetPath));
}
}
}
if ($this->getLanguage() === 'php') {
foreach ($this->modules as $module) {
$targetPath = $path . str_replace('\\', '/', $this->moduleNamespaces[$module]) . '/';
foreach ($this->getAutocodeModuleTemplates() as $template) {
$fileCollection->add($this->renderModuleTemplate($this, $template, $module, $targetPath));
}
}
}
return $fileCollection;
} | php | public function getModelFiles($path)
{
$fileCollection = new FileCollection();
$namespacePath = str_replace('\\', '/', $path . $this->getNamespace() . '/');
$targetPath = $namespacePath;
foreach ($this->getEntities() as $entity) {
if ($entity->getRenderizable()) {
if ($this->getLanguage() === 'php') {
if ($entity->getNamespace() !== '') {
$targetPath = $path . str_replace('\\', '/', $entity->getNamespace()) . '/';
}
} elseif ($this->getLanguage() === 'java') {
if ($entity->getModule() !== '') {
$targetPath = $path . '/' . $this->getAutocodeConfiguration('package') . '/' . str_replace('.', '/', $entity->getModule()) . '/';
}
}
foreach ($this->getAutocodeEntityTemplates() as $template) {
$fileCollection->add($this->renderEntityTemplate($template, $entity, $targetPath));
}
}
}
if ($this->getLanguage() === 'php') {
foreach ($this->modules as $module) {
$targetPath = $path . str_replace('\\', '/', $this->moduleNamespaces[$module]) . '/';
foreach ($this->getAutocodeModuleTemplates() as $template) {
$fileCollection->add($this->renderModuleTemplate($this, $template, $module, $targetPath));
}
}
}
return $fileCollection;
} | [
"public",
"function",
"getModelFiles",
"(",
"$",
"path",
")",
"{",
"$",
"fileCollection",
"=",
"new",
"FileCollection",
"(",
")",
";",
"$",
"namespacePath",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"path",
".",
"$",
"this",
"->",
"getNamespace",
"(",
")",
".",
"'/'",
")",
";",
"$",
"targetPath",
"=",
"$",
"namespacePath",
";",
"foreach",
"(",
"$",
"this",
"->",
"getEntities",
"(",
")",
"as",
"$",
"entity",
")",
"{",
"if",
"(",
"$",
"entity",
"->",
"getRenderizable",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getLanguage",
"(",
")",
"===",
"'php'",
")",
"{",
"if",
"(",
"$",
"entity",
"->",
"getNamespace",
"(",
")",
"!==",
"''",
")",
"{",
"$",
"targetPath",
"=",
"$",
"path",
".",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"entity",
"->",
"getNamespace",
"(",
")",
")",
".",
"'/'",
";",
"}",
"}",
"elseif",
"(",
"$",
"this",
"->",
"getLanguage",
"(",
")",
"===",
"'java'",
")",
"{",
"if",
"(",
"$",
"entity",
"->",
"getModule",
"(",
")",
"!==",
"''",
")",
"{",
"$",
"targetPath",
"=",
"$",
"path",
".",
"'/'",
".",
"$",
"this",
"->",
"getAutocodeConfiguration",
"(",
"'package'",
")",
".",
"'/'",
".",
"str_replace",
"(",
"'.'",
",",
"'/'",
",",
"$",
"entity",
"->",
"getModule",
"(",
")",
")",
".",
"'/'",
";",
"}",
"}",
"foreach",
"(",
"$",
"this",
"->",
"getAutocodeEntityTemplates",
"(",
")",
"as",
"$",
"template",
")",
"{",
"$",
"fileCollection",
"->",
"add",
"(",
"$",
"this",
"->",
"renderEntityTemplate",
"(",
"$",
"template",
",",
"$",
"entity",
",",
"$",
"targetPath",
")",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"getLanguage",
"(",
")",
"===",
"'php'",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"modules",
"as",
"$",
"module",
")",
"{",
"$",
"targetPath",
"=",
"$",
"path",
".",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"this",
"->",
"moduleNamespaces",
"[",
"$",
"module",
"]",
")",
".",
"'/'",
";",
"foreach",
"(",
"$",
"this",
"->",
"getAutocodeModuleTemplates",
"(",
")",
"as",
"$",
"template",
")",
"{",
"$",
"fileCollection",
"->",
"add",
"(",
"$",
"this",
"->",
"renderModuleTemplate",
"(",
"$",
"this",
",",
"$",
"template",
",",
"$",
"module",
",",
"$",
"targetPath",
")",
")",
";",
"}",
"}",
"}",
"return",
"$",
"fileCollection",
";",
"}"
] | Returns a collection of files
@param string $path The path where they would be saved
@return FileCollection | [
"Returns",
"a",
"collection",
"of",
"files"
] | train | https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Autocode/Project.php#L1238-L1275 |
j-d/draggy | src/Draggy/Autocode/Project.php | Project.renderEntityTemplate | public function renderEntityTemplate(EntityTemplate $template, Entity $entity, $path)
{
$template->setEntity($entity);
$fileCollection = new FileCollection();
$entityPath = $path . $template->getPath();
$entityName = $template->getFilename();
if ($entity->shouldRender($template->getTemplateName())) {
$fileCollection->add(new File($entityPath, $entityName, $template->render()));
} else {
$fileCollection->add(new NoFile($entityPath, $entityName, sprintf('The entity \'%s\' is should not have a \'%s\'.', $entity->getFullyQualifiedName(), $template->getTemplateName())));
}
return $fileCollection;
} | php | public function renderEntityTemplate(EntityTemplate $template, Entity $entity, $path)
{
$template->setEntity($entity);
$fileCollection = new FileCollection();
$entityPath = $path . $template->getPath();
$entityName = $template->getFilename();
if ($entity->shouldRender($template->getTemplateName())) {
$fileCollection->add(new File($entityPath, $entityName, $template->render()));
} else {
$fileCollection->add(new NoFile($entityPath, $entityName, sprintf('The entity \'%s\' is should not have a \'%s\'.', $entity->getFullyQualifiedName(), $template->getTemplateName())));
}
return $fileCollection;
} | [
"public",
"function",
"renderEntityTemplate",
"(",
"EntityTemplate",
"$",
"template",
",",
"Entity",
"$",
"entity",
",",
"$",
"path",
")",
"{",
"$",
"template",
"->",
"setEntity",
"(",
"$",
"entity",
")",
";",
"$",
"fileCollection",
"=",
"new",
"FileCollection",
"(",
")",
";",
"$",
"entityPath",
"=",
"$",
"path",
".",
"$",
"template",
"->",
"getPath",
"(",
")",
";",
"$",
"entityName",
"=",
"$",
"template",
"->",
"getFilename",
"(",
")",
";",
"if",
"(",
"$",
"entity",
"->",
"shouldRender",
"(",
"$",
"template",
"->",
"getTemplateName",
"(",
")",
")",
")",
"{",
"$",
"fileCollection",
"->",
"add",
"(",
"new",
"File",
"(",
"$",
"entityPath",
",",
"$",
"entityName",
",",
"$",
"template",
"->",
"render",
"(",
")",
")",
")",
";",
"}",
"else",
"{",
"$",
"fileCollection",
"->",
"add",
"(",
"new",
"NoFile",
"(",
"$",
"entityPath",
",",
"$",
"entityName",
",",
"sprintf",
"(",
"'The entity \\'%s\\' is should not have a \\'%s\\'.'",
",",
"$",
"entity",
"->",
"getFullyQualifiedName",
"(",
")",
",",
"$",
"template",
"->",
"getTemplateName",
"(",
")",
")",
")",
")",
";",
"}",
"return",
"$",
"fileCollection",
";",
"}"
] | @param EntityTemplate $template
@param Entity $entity
@param string $path
@return FileInterface | [
"@param",
"EntityTemplate",
"$template",
"@param",
"Entity",
"$entity",
"@param",
"string",
"$path"
] | train | https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Autocode/Project.php#L1284-L1301 |
j-d/draggy | src/Draggy/Autocode/Project.php | Project.renderModuleTemplate | public function renderModuleTemplate(Project $project, ModuleTemplate $template, $module, $path)
{
$template->setModule($module);
$template->setProject($project);
$fileCollection = new FileCollection();
$modulePath = $path . $template->getPath();
$moduleName = $template->getFilename();
$file = new File($modulePath, $moduleName, $template->render());
$file->setAddToFile(true);
$fileCollection->add($file);
return $fileCollection;
} | php | public function renderModuleTemplate(Project $project, ModuleTemplate $template, $module, $path)
{
$template->setModule($module);
$template->setProject($project);
$fileCollection = new FileCollection();
$modulePath = $path . $template->getPath();
$moduleName = $template->getFilename();
$file = new File($modulePath, $moduleName, $template->render());
$file->setAddToFile(true);
$fileCollection->add($file);
return $fileCollection;
} | [
"public",
"function",
"renderModuleTemplate",
"(",
"Project",
"$",
"project",
",",
"ModuleTemplate",
"$",
"template",
",",
"$",
"module",
",",
"$",
"path",
")",
"{",
"$",
"template",
"->",
"setModule",
"(",
"$",
"module",
")",
";",
"$",
"template",
"->",
"setProject",
"(",
"$",
"project",
")",
";",
"$",
"fileCollection",
"=",
"new",
"FileCollection",
"(",
")",
";",
"$",
"modulePath",
"=",
"$",
"path",
".",
"$",
"template",
"->",
"getPath",
"(",
")",
";",
"$",
"moduleName",
"=",
"$",
"template",
"->",
"getFilename",
"(",
")",
";",
"$",
"file",
"=",
"new",
"File",
"(",
"$",
"modulePath",
",",
"$",
"moduleName",
",",
"$",
"template",
"->",
"render",
"(",
")",
")",
";",
"$",
"file",
"->",
"setAddToFile",
"(",
"true",
")",
";",
"$",
"fileCollection",
"->",
"add",
"(",
"$",
"file",
")",
";",
"return",
"$",
"fileCollection",
";",
"}"
] | @param Project $project
@param ModuleTemplate $template
@param string $module
@param string $path
@return FileInterface | [
"@param",
"Project",
"$project",
"@param",
"ModuleTemplate",
"$template",
"@param",
"string",
"$module",
"@param",
"string",
"$path"
] | train | https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Autocode/Project.php#L1311-L1328 |
j-d/draggy | src/Draggy/Autocode/Project.php | Project.singlelise | public static function singlelise($string)
{
$rules = [
'ies' => 'y',
'ves' => 'f',
's' => '',
];
foreach ($rules as $ending => $replacement) {
if ($ending === substr($string, -strlen($ending))) {
return substr($string, 0, -strlen($ending)) . $replacement;
}
}
return $string . 'Single';
} | php | public static function singlelise($string)
{
$rules = [
'ies' => 'y',
'ves' => 'f',
's' => '',
];
foreach ($rules as $ending => $replacement) {
if ($ending === substr($string, -strlen($ending))) {
return substr($string, 0, -strlen($ending)) . $replacement;
}
}
return $string . 'Single';
} | [
"public",
"static",
"function",
"singlelise",
"(",
"$",
"string",
")",
"{",
"$",
"rules",
"=",
"[",
"'ies'",
"=>",
"'y'",
",",
"'ves'",
"=>",
"'f'",
",",
"'s'",
"=>",
"''",
",",
"]",
";",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"ending",
"=>",
"$",
"replacement",
")",
"{",
"if",
"(",
"$",
"ending",
"===",
"substr",
"(",
"$",
"string",
",",
"-",
"strlen",
"(",
"$",
"ending",
")",
")",
")",
"{",
"return",
"substr",
"(",
"$",
"string",
",",
"0",
",",
"-",
"strlen",
"(",
"$",
"ending",
")",
")",
".",
"$",
"replacement",
";",
"}",
"}",
"return",
"$",
"string",
".",
"'Single'",
";",
"}"
] | Get the plural name from a singular
@param string $string
@return string | [
"Get",
"the",
"plural",
"name",
"from",
"a",
"singular"
] | train | https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Autocode/Project.php#L1370-L1385 |
j-d/draggy | src/Draggy/Autocode/Project.php | Project.pluralise | public static function pluralise($string)
{
$rules = [
'tus' => 'tuses', // status to statuses
'ss' => 'sses', // kiss to kissess
'sh' => 'shes', // dish to dishes
'ch' => 'ches', // witch to witches
'oy' => 'oys', // boy to boys
'ay' => 'ays', // day to days
'ey' => 'eys', // monkey to monkeys
'o' => 'oes', // hero to heroes
'y' => 'ies', // cherry to cherries
'f' => 'ves', // leaf to leaves
];
foreach ($rules as $ending => $replacement) {
if ($ending === substr($string, -strlen($ending))) {
return substr($string, 0, -strlen($ending)) . $replacement;
}
}
return $string . 's';
} | php | public static function pluralise($string)
{
$rules = [
'tus' => 'tuses', // status to statuses
'ss' => 'sses', // kiss to kissess
'sh' => 'shes', // dish to dishes
'ch' => 'ches', // witch to witches
'oy' => 'oys', // boy to boys
'ay' => 'ays', // day to days
'ey' => 'eys', // monkey to monkeys
'o' => 'oes', // hero to heroes
'y' => 'ies', // cherry to cherries
'f' => 'ves', // leaf to leaves
];
foreach ($rules as $ending => $replacement) {
if ($ending === substr($string, -strlen($ending))) {
return substr($string, 0, -strlen($ending)) . $replacement;
}
}
return $string . 's';
} | [
"public",
"static",
"function",
"pluralise",
"(",
"$",
"string",
")",
"{",
"$",
"rules",
"=",
"[",
"'tus'",
"=>",
"'tuses'",
",",
"// status to statuses",
"'ss'",
"=>",
"'sses'",
",",
"// kiss to kissess",
"'sh'",
"=>",
"'shes'",
",",
"// dish to dishes",
"'ch'",
"=>",
"'ches'",
",",
"// witch to witches",
"'oy'",
"=>",
"'oys'",
",",
"// boy to boys",
"'ay'",
"=>",
"'ays'",
",",
"// day to days",
"'ey'",
"=>",
"'eys'",
",",
"// monkey to monkeys",
"'o'",
"=>",
"'oes'",
",",
"// hero to heroes",
"'y'",
"=>",
"'ies'",
",",
"// cherry to cherries",
"'f'",
"=>",
"'ves'",
",",
"// leaf to leaves",
"]",
";",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"ending",
"=>",
"$",
"replacement",
")",
"{",
"if",
"(",
"$",
"ending",
"===",
"substr",
"(",
"$",
"string",
",",
"-",
"strlen",
"(",
"$",
"ending",
")",
")",
")",
"{",
"return",
"substr",
"(",
"$",
"string",
",",
"0",
",",
"-",
"strlen",
"(",
"$",
"ending",
")",
")",
".",
"$",
"replacement",
";",
"}",
"}",
"return",
"$",
"string",
".",
"'s'",
";",
"}"
] | Get the plural name from a singular
Source: http://en.wikipedia.org/wiki/English_plurals
@param string $string
@return string | [
"Get",
"the",
"plural",
"name",
"from",
"a",
"singular",
"Source",
":",
"http",
":",
"//",
"en",
".",
"wikipedia",
".",
"org",
"/",
"wiki",
"/",
"English_plurals"
] | train | https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Autocode/Project.php#L1395-L1419 |
adrenalinkin/config-helper | Extension/AbstractExtension.php | AbstractExtension.getConfigurationsFromFile | protected function getConfigurationsFromFile($fileName, ContainerBuilder $container, $merge = true)
{
$configs = [];
/** @var \Symfony\Component\Finder\SplFileInfo $file */
foreach ($this->getFinder($fileName, $container) as $file) {
$currentConfiguration = Yaml::parse($file->getContents());
// skip empty files
if (empty($currentConfiguration)) {
continue;
}
// merge configurations recursively or just stack
if ($merge) {
$configs = array_merge_recursive($configs, $currentConfiguration);
} else {
$configs[] = reset($currentConfiguration);
}
}
return $configs;
} | php | protected function getConfigurationsFromFile($fileName, ContainerBuilder $container, $merge = true)
{
$configs = [];
/** @var \Symfony\Component\Finder\SplFileInfo $file */
foreach ($this->getFinder($fileName, $container) as $file) {
$currentConfiguration = Yaml::parse($file->getContents());
// skip empty files
if (empty($currentConfiguration)) {
continue;
}
// merge configurations recursively or just stack
if ($merge) {
$configs = array_merge_recursive($configs, $currentConfiguration);
} else {
$configs[] = reset($currentConfiguration);
}
}
return $configs;
} | [
"protected",
"function",
"getConfigurationsFromFile",
"(",
"$",
"fileName",
",",
"ContainerBuilder",
"$",
"container",
",",
"$",
"merge",
"=",
"true",
")",
"{",
"$",
"configs",
"=",
"[",
"]",
";",
"/** @var \\Symfony\\Component\\Finder\\SplFileInfo $file */",
"foreach",
"(",
"$",
"this",
"->",
"getFinder",
"(",
"$",
"fileName",
",",
"$",
"container",
")",
"as",
"$",
"file",
")",
"{",
"$",
"currentConfiguration",
"=",
"Yaml",
"::",
"parse",
"(",
"$",
"file",
"->",
"getContents",
"(",
")",
")",
";",
"// skip empty files",
"if",
"(",
"empty",
"(",
"$",
"currentConfiguration",
")",
")",
"{",
"continue",
";",
"}",
"// merge configurations recursively or just stack",
"if",
"(",
"$",
"merge",
")",
"{",
"$",
"configs",
"=",
"array_merge_recursive",
"(",
"$",
"configs",
",",
"$",
"currentConfiguration",
")",
";",
"}",
"else",
"{",
"$",
"configs",
"[",
"]",
"=",
"reset",
"(",
"$",
"currentConfiguration",
")",
";",
"}",
"}",
"return",
"$",
"configs",
";",
"}"
] | Returns all configurations registered in the specific yaml file.
@param string $fileName Name of the file with extension
@param ContainerBuilder $container Container builder
@param bool $merge Merge configuration recursively or just stack
@return array | [
"Returns",
"all",
"configurations",
"registered",
"in",
"the",
"specific",
"yaml",
"file",
"."
] | train | https://github.com/adrenalinkin/config-helper/blob/97dfdb81aa2ed1878e411f76e0d723003b80062b/Extension/AbstractExtension.php#L40-L62 |
adrenalinkin/config-helper | Extension/AbstractExtension.php | AbstractExtension.getFinder | private function getFinder($fileName, ContainerBuilder $container)
{
$finder = (new Finder())->files()->name($fileName);
$resourcesDir = 'Resources'.DIRECTORY_SEPARATOR.'config';
if (self::$directoriesCache) {
return $finder->in(self::$directoriesCache);
}
foreach ($container->getParameter('kernel.bundles') as $name => $pathToBundle) {
try {
$reflector = new \ReflectionClass($pathToBundle);
} catch (\ReflectionException $e) {
continue;
}
$fileName = $reflector->getFileName();
$fileName = str_replace($name.'.php', $resourcesDir, $fileName);
try {
$finder->in($fileName);
self::$directoriesCache[$name] = $fileName;
} catch (\InvalidArgumentException $e) {
// remove invalid directories
unset(self::$directoriesCache[$name]);
}
}
return $finder;
} | php | private function getFinder($fileName, ContainerBuilder $container)
{
$finder = (new Finder())->files()->name($fileName);
$resourcesDir = 'Resources'.DIRECTORY_SEPARATOR.'config';
if (self::$directoriesCache) {
return $finder->in(self::$directoriesCache);
}
foreach ($container->getParameter('kernel.bundles') as $name => $pathToBundle) {
try {
$reflector = new \ReflectionClass($pathToBundle);
} catch (\ReflectionException $e) {
continue;
}
$fileName = $reflector->getFileName();
$fileName = str_replace($name.'.php', $resourcesDir, $fileName);
try {
$finder->in($fileName);
self::$directoriesCache[$name] = $fileName;
} catch (\InvalidArgumentException $e) {
// remove invalid directories
unset(self::$directoriesCache[$name]);
}
}
return $finder;
} | [
"private",
"function",
"getFinder",
"(",
"$",
"fileName",
",",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"finder",
"=",
"(",
"new",
"Finder",
"(",
")",
")",
"->",
"files",
"(",
")",
"->",
"name",
"(",
"$",
"fileName",
")",
";",
"$",
"resourcesDir",
"=",
"'Resources'",
".",
"DIRECTORY_SEPARATOR",
".",
"'config'",
";",
"if",
"(",
"self",
"::",
"$",
"directoriesCache",
")",
"{",
"return",
"$",
"finder",
"->",
"in",
"(",
"self",
"::",
"$",
"directoriesCache",
")",
";",
"}",
"foreach",
"(",
"$",
"container",
"->",
"getParameter",
"(",
"'kernel.bundles'",
")",
"as",
"$",
"name",
"=>",
"$",
"pathToBundle",
")",
"{",
"try",
"{",
"$",
"reflector",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"pathToBundle",
")",
";",
"}",
"catch",
"(",
"\\",
"ReflectionException",
"$",
"e",
")",
"{",
"continue",
";",
"}",
"$",
"fileName",
"=",
"$",
"reflector",
"->",
"getFileName",
"(",
")",
";",
"$",
"fileName",
"=",
"str_replace",
"(",
"$",
"name",
".",
"'.php'",
",",
"$",
"resourcesDir",
",",
"$",
"fileName",
")",
";",
"try",
"{",
"$",
"finder",
"->",
"in",
"(",
"$",
"fileName",
")",
";",
"self",
"::",
"$",
"directoriesCache",
"[",
"$",
"name",
"]",
"=",
"$",
"fileName",
";",
"}",
"catch",
"(",
"\\",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"// remove invalid directories",
"unset",
"(",
"self",
"::",
"$",
"directoriesCache",
"[",
"$",
"name",
"]",
")",
";",
"}",
"}",
"return",
"$",
"finder",
";",
"}"
] | Build and return finder
@param string $fileName
@param ContainerBuilder $container
@return Finder | [
"Build",
"and",
"return",
"finder"
] | train | https://github.com/adrenalinkin/config-helper/blob/97dfdb81aa2ed1878e411f76e0d723003b80062b/Extension/AbstractExtension.php#L72-L101 |
keboola/php-filter | src/Keboola/Filter/Filter.php | Filter.compareObject | public function compareObject(\stdClass $object)
{
$value = \Keboola\Utils\getDataFromPath($this->columnName, $object, ".");
return $this->compare($value);
} | php | public function compareObject(\stdClass $object)
{
$value = \Keboola\Utils\getDataFromPath($this->columnName, $object, ".");
return $this->compare($value);
} | [
"public",
"function",
"compareObject",
"(",
"\\",
"stdClass",
"$",
"object",
")",
"{",
"$",
"value",
"=",
"\\",
"Keboola",
"\\",
"Utils",
"\\",
"getDataFromPath",
"(",
"$",
"this",
"->",
"columnName",
",",
"$",
"object",
",",
"\".\"",
")",
";",
"return",
"$",
"this",
"->",
"compare",
"(",
"$",
"value",
")",
";",
"}"
] | Compare a value from within an object
using the $columnName, $operator and $value
@param \stdClass $object
@return bool
@throws FilterException | [
"Compare",
"a",
"value",
"from",
"within",
"an",
"object",
"using",
"the",
"$columnName",
"$operator",
"and",
"$value"
] | train | https://github.com/keboola/php-filter/blob/8e38d4b19722824f528a8a4395caa8b2e2cf66e1/src/Keboola/Filter/Filter.php#L92-L96 |
keboola/php-filter | src/Keboola/Filter/Filter.php | Filter.compare | protected function compare($value)
{
if (!method_exists($this, self::$methodList[$this->operator])) {
throw new FilterException("Method for {$this->operator} does not exist!");
}
return $this->{self::$methodList[$this->operator]}($value, $this->value);
} | php | protected function compare($value)
{
if (!method_exists($this, self::$methodList[$this->operator])) {
throw new FilterException("Method for {$this->operator} does not exist!");
}
return $this->{self::$methodList[$this->operator]}($value, $this->value);
} | [
"protected",
"function",
"compare",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"this",
",",
"self",
"::",
"$",
"methodList",
"[",
"$",
"this",
"->",
"operator",
"]",
")",
")",
"{",
"throw",
"new",
"FilterException",
"(",
"\"Method for {$this->operator} does not exist!\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"{",
"self",
"::",
"$",
"methodList",
"[",
"$",
"this",
"->",
"operator",
"]",
"}",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"value",
")",
";",
"}"
] | Compare a single value against $this->value using $this->operator
@param string $value
@return bool
@throws FilterException | [
"Compare",
"a",
"single",
"value",
"against",
"$this",
"-",
">",
"value",
"using",
"$this",
"-",
">",
"operator"
] | train | https://github.com/keboola/php-filter/blob/8e38d4b19722824f528a8a4395caa8b2e2cf66e1/src/Keboola/Filter/Filter.php#L128-L135 |
oroinc/OroLayoutComponent | Loader/Generator/Extension/ImportsAwareLayoutUpdateVisitor.php | ImportsAwareLayoutUpdateVisitor.startVisit | public function startVisit(VisitContext $visitContext)
{
$writer = $visitContext->createWriter();
$class = $visitContext->getClass();
$class->addInterfaceName('Oro\Component\Layout\ImportsAwareLayoutUpdateInterface');
$setFactoryMethod = PhpMethod::create('getImports');
$setFactoryMethod->setBody($writer->write('return '.var_export($this->imports, true).';')->getContent());
$class->setMethod($setFactoryMethod);
} | php | public function startVisit(VisitContext $visitContext)
{
$writer = $visitContext->createWriter();
$class = $visitContext->getClass();
$class->addInterfaceName('Oro\Component\Layout\ImportsAwareLayoutUpdateInterface');
$setFactoryMethod = PhpMethod::create('getImports');
$setFactoryMethod->setBody($writer->write('return '.var_export($this->imports, true).';')->getContent());
$class->setMethod($setFactoryMethod);
} | [
"public",
"function",
"startVisit",
"(",
"VisitContext",
"$",
"visitContext",
")",
"{",
"$",
"writer",
"=",
"$",
"visitContext",
"->",
"createWriter",
"(",
")",
";",
"$",
"class",
"=",
"$",
"visitContext",
"->",
"getClass",
"(",
")",
";",
"$",
"class",
"->",
"addInterfaceName",
"(",
"'Oro\\Component\\Layout\\ImportsAwareLayoutUpdateInterface'",
")",
";",
"$",
"setFactoryMethod",
"=",
"PhpMethod",
"::",
"create",
"(",
"'getImports'",
")",
";",
"$",
"setFactoryMethod",
"->",
"setBody",
"(",
"$",
"writer",
"->",
"write",
"(",
"'return '",
".",
"var_export",
"(",
"$",
"this",
"->",
"imports",
",",
"true",
")",
".",
"';'",
")",
"->",
"getContent",
"(",
")",
")",
";",
"$",
"class",
"->",
"setMethod",
"(",
"$",
"setFactoryMethod",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Loader/Generator/Extension/ImportsAwareLayoutUpdateVisitor.php#L27-L35 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query.php | ezcQuery.getIdentifiers | protected function getIdentifiers( array $aliasList )
{
if ( $this->aliases !== null )
{
foreach ( $aliasList as $key => $alias )
{
$aliasList[$key] = $this->getIdentifier( $alias );
}
}
return $aliasList;
} | php | protected function getIdentifiers( array $aliasList )
{
if ( $this->aliases !== null )
{
foreach ( $aliasList as $key => $alias )
{
$aliasList[$key] = $this->getIdentifier( $alias );
}
}
return $aliasList;
} | [
"protected",
"function",
"getIdentifiers",
"(",
"array",
"$",
"aliasList",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"aliases",
"!==",
"null",
")",
"{",
"foreach",
"(",
"$",
"aliasList",
"as",
"$",
"key",
"=>",
"$",
"alias",
")",
"{",
"$",
"aliasList",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"alias",
")",
";",
"}",
"}",
"return",
"$",
"aliasList",
";",
"}"
] | Returns the correct identifiers for the aliases found in $aliases.
This method is similar to getIdentifier except that it works on an array.
@param array(string) $aliasList
@return array(string) | [
"Returns",
"the",
"correct",
"identifiers",
"for",
"the",
"aliases",
"found",
"in",
"$aliases",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query.php#L271-L281 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query.php | ezcQuery.getPrefixedTableNames | protected function getPrefixedTableNames($tableNames)
{
if ($this->db->options && $this->db->options->tableNamePrefix)
{
switch (true)
{
case is_string($tableNames):
$tableNames = $this->db->options->tableNamePrefix . $tableNames;
break;
case is_array($tableNames):
foreach ($tableNames as $key => $table)
$tableNames[$key] = $this->db->options->tableNamePrefix . $table;
break;
}
}
return $tableNames;
} | php | protected function getPrefixedTableNames($tableNames)
{
if ($this->db->options && $this->db->options->tableNamePrefix)
{
switch (true)
{
case is_string($tableNames):
$tableNames = $this->db->options->tableNamePrefix . $tableNames;
break;
case is_array($tableNames):
foreach ($tableNames as $key => $table)
$tableNames[$key] = $this->db->options->tableNamePrefix . $table;
break;
}
}
return $tableNames;
} | [
"protected",
"function",
"getPrefixedTableNames",
"(",
"$",
"tableNames",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"db",
"->",
"options",
"&&",
"$",
"this",
"->",
"db",
"->",
"options",
"->",
"tableNamePrefix",
")",
"{",
"switch",
"(",
"true",
")",
"{",
"case",
"is_string",
"(",
"$",
"tableNames",
")",
":",
"$",
"tableNames",
"=",
"$",
"this",
"->",
"db",
"->",
"options",
"->",
"tableNamePrefix",
".",
"$",
"tableNames",
";",
"break",
";",
"case",
"is_array",
"(",
"$",
"tableNames",
")",
":",
"foreach",
"(",
"$",
"tableNames",
"as",
"$",
"key",
"=>",
"$",
"table",
")",
"$",
"tableNames",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"db",
"->",
"options",
"->",
"tableNamePrefix",
".",
"$",
"table",
";",
"break",
";",
"}",
"}",
"return",
"$",
"tableNames",
";",
"}"
] | Returns prefixed table names if "tableNamePrefix" option not empty
otherwise return untouched names
@param array|string $tableNames
@return array|string | [
"Returns",
"prefixed",
"table",
"names",
"if",
"tableNamePrefix",
"option",
"not",
"empty",
"otherwise",
"return",
"untouched",
"names"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query.php#L290-L308 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query.php | ezcQuery.doBind | public function doBind( PDOStatement $stmt )
{
foreach ( $this->boundValues as $key => $value )
{
try
{
$stmt->bindValue( $key, $value, $this->boundValuesType[$key] );
}
catch ( PDOException $e )
{
// see comment below
}
}
foreach ( $this->boundParameters as $key => &$value )
{
try
{
$stmt->bindParam( $key, $value, $this->boundParametersType[$key] );
}
catch ( PDOException $e )
{
// we are ignoring this exception since it may only occur when
// a bound parameter is not found in the query anymore.
// this can happen if either drop an expression with a bound value
// created with this query or if you remove a bind in a query by
// replacing it with another one.
// the only other way to avoid this problem is parse the string for the
// bound variables. Note that a simple search will not do since the variable
// name may occur in a string.
}
}
} | php | public function doBind( PDOStatement $stmt )
{
foreach ( $this->boundValues as $key => $value )
{
try
{
$stmt->bindValue( $key, $value, $this->boundValuesType[$key] );
}
catch ( PDOException $e )
{
// see comment below
}
}
foreach ( $this->boundParameters as $key => &$value )
{
try
{
$stmt->bindParam( $key, $value, $this->boundParametersType[$key] );
}
catch ( PDOException $e )
{
// we are ignoring this exception since it may only occur when
// a bound parameter is not found in the query anymore.
// this can happen if either drop an expression with a bound value
// created with this query or if you remove a bind in a query by
// replacing it with another one.
// the only other way to avoid this problem is parse the string for the
// bound variables. Note that a simple search will not do since the variable
// name may occur in a string.
}
}
} | [
"public",
"function",
"doBind",
"(",
"PDOStatement",
"$",
"stmt",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"boundValues",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"try",
"{",
"$",
"stmt",
"->",
"bindValue",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"this",
"->",
"boundValuesType",
"[",
"$",
"key",
"]",
")",
";",
"}",
"catch",
"(",
"PDOException",
"$",
"e",
")",
"{",
"// see comment below",
"}",
"}",
"foreach",
"(",
"$",
"this",
"->",
"boundParameters",
"as",
"$",
"key",
"=>",
"&",
"$",
"value",
")",
"{",
"try",
"{",
"$",
"stmt",
"->",
"bindParam",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"this",
"->",
"boundParametersType",
"[",
"$",
"key",
"]",
")",
";",
"}",
"catch",
"(",
"PDOException",
"$",
"e",
")",
"{",
"// we are ignoring this exception since it may only occur when",
"// a bound parameter is not found in the query anymore.",
"// this can happen if either drop an expression with a bound value",
"// created with this query or if you remove a bind in a query by",
"// replacing it with another one.",
"// the only other way to avoid this problem is parse the string for the",
"// bound variables. Note that a simple search will not do since the variable",
"// name may occur in a string.",
"}",
"}",
"}"
] | Performs binding of variables bound with bindValue and bindParam on the statement $stmt.
This method must be called if you have used the bind methods
in your query and you build the method yourself using build.
@param PDOStatement $stmt
@return void | [
"Performs",
"binding",
"of",
"variables",
"bound",
"with",
"bindValue",
"and",
"bindParam",
"on",
"the",
"statement",
"$stmt",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query.php#L416-L447 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query.php | ezcQuery.prepare | public function prepare()
{
$stmt = $this->db->prepare( $this->getQuery() );
$this->doBind( $stmt );
return $stmt;
} | php | public function prepare()
{
$stmt = $this->db->prepare( $this->getQuery() );
$this->doBind( $stmt );
return $stmt;
} | [
"public",
"function",
"prepare",
"(",
")",
"{",
"$",
"stmt",
"=",
"$",
"this",
"->",
"db",
"->",
"prepare",
"(",
"$",
"this",
"->",
"getQuery",
"(",
")",
")",
";",
"$",
"this",
"->",
"doBind",
"(",
"$",
"stmt",
")",
";",
"return",
"$",
"stmt",
";",
"}"
] | Returns a prepared statement from this query which can be used for execution.
The returned object is a PDOStatement for which you can find extensive
documentation in the PHP manual:
{@link http://php.net/pdostatement-bindcolumn}
prepare() automatically calls doBind() on the statement.
@return PDOStatement | [
"Returns",
"a",
"prepared",
"statement",
"from",
"this",
"query",
"which",
"can",
"be",
"used",
"for",
"execution",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query.php#L459-L464 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query.php | ezcQuery.execute | public function execute()
{
try
{
$stmt = $this->prepare();
if (LOG_DEBUG == Eresus_Kernel::$logLevel)
{
$insider = new DBQueryInsider;
$this->doBind($insider);
$s = $insider->subst($this);
Eresus_Kernel::log(__METHOD__, LOG_DEBUG, '("%s")', $s);
}
$stmt->execute();
}
catch (PDOException $e)
{
throw Eresus_DB_Exception_QueryFailed::create($this, $e);
}
return $stmt;
} | php | public function execute()
{
try
{
$stmt = $this->prepare();
if (LOG_DEBUG == Eresus_Kernel::$logLevel)
{
$insider = new DBQueryInsider;
$this->doBind($insider);
$s = $insider->subst($this);
Eresus_Kernel::log(__METHOD__, LOG_DEBUG, '("%s")', $s);
}
$stmt->execute();
}
catch (PDOException $e)
{
throw Eresus_DB_Exception_QueryFailed::create($this, $e);
}
return $stmt;
} | [
"public",
"function",
"execute",
"(",
")",
"{",
"try",
"{",
"$",
"stmt",
"=",
"$",
"this",
"->",
"prepare",
"(",
")",
";",
"if",
"(",
"LOG_DEBUG",
"==",
"Eresus_Kernel",
"::",
"$",
"logLevel",
")",
"{",
"$",
"insider",
"=",
"new",
"DBQueryInsider",
";",
"$",
"this",
"->",
"doBind",
"(",
"$",
"insider",
")",
";",
"$",
"s",
"=",
"$",
"insider",
"->",
"subst",
"(",
"$",
"this",
")",
";",
"Eresus_Kernel",
"::",
"log",
"(",
"__METHOD__",
",",
"LOG_DEBUG",
",",
"'(\"%s\")'",
",",
"$",
"s",
")",
";",
"}",
"$",
"stmt",
"->",
"execute",
"(",
")",
";",
"}",
"catch",
"(",
"PDOException",
"$",
"e",
")",
"{",
"throw",
"Eresus_DB_Exception_QueryFailed",
"::",
"create",
"(",
"$",
"this",
",",
"$",
"e",
")",
";",
"}",
"return",
"$",
"stmt",
";",
"}"
] | Execute query
@throws Eresus_DB_Exception_QueryFailed
@return PDOStatement | [
"Execute",
"query"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query.php#L543-L564 |
yeaha/owl-core | src/Container.php | Container.get | public function get($id)
{
if (isset($this->values[$id])) {
return $this->values[$id];
}
$callback = $this->getCallback($id);
$value = call_user_func($callback);
return $this->values[$id] = $value;
} | php | public function get($id)
{
if (isset($this->values[$id])) {
return $this->values[$id];
}
$callback = $this->getCallback($id);
$value = call_user_func($callback);
return $this->values[$id] = $value;
} | [
"public",
"function",
"get",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"values",
"[",
"$",
"id",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"values",
"[",
"$",
"id",
"]",
";",
"}",
"$",
"callback",
"=",
"$",
"this",
"->",
"getCallback",
"(",
"$",
"id",
")",
";",
"$",
"value",
"=",
"call_user_func",
"(",
"$",
"callback",
")",
";",
"return",
"$",
"this",
"->",
"values",
"[",
"$",
"id",
"]",
"=",
"$",
"value",
";",
"}"
] | 从容器内获得注册的回调方法执行结果.
注意:
注册的回调方法只会执行一次,即每次get都拿到同样的结果
@param string $id
@return mixed
@throws 指定的$id不存在时 | [
"从容器内获得注册的回调方法执行结果",
"."
] | train | https://github.com/yeaha/owl-core/blob/fd7531c0a5c0142300a96160bd079f2e2d92fe4c/src/Container.php#L67-L77 |
yeaha/owl-core | src/Container.php | Container.getCallback | public function getCallback($id)
{
if ($this->has($id)) {
return $this->callbacks[$id];
}
throw new \UnexpectedValueException(sprintf('"%s" does not exists in container', $id));
} | php | public function getCallback($id)
{
if ($this->has($id)) {
return $this->callbacks[$id];
}
throw new \UnexpectedValueException(sprintf('"%s" does not exists in container', $id));
} | [
"public",
"function",
"getCallback",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"has",
"(",
"$",
"id",
")",
")",
"{",
"return",
"$",
"this",
"->",
"callbacks",
"[",
"$",
"id",
"]",
";",
"}",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"sprintf",
"(",
"'\"%s\" does not exists in container'",
",",
"$",
"id",
")",
")",
";",
"}"
] | 获得指定名字的回调函数.
@param string $id
@return Closuer
@throws 指定的$id不存在时 | [
"获得指定名字的回调函数",
"."
] | train | https://github.com/yeaha/owl-core/blob/fd7531c0a5c0142300a96160bd079f2e2d92fe4c/src/Container.php#L103-L110 |
mothership-ec/composer | src/Composer/DependencyResolver/Request.php | Request.fix | public function fix($packageName, LinkConstraintInterface $constraint = null)
{
$this->addJob($packageName, 'install', $constraint, true);
} | php | public function fix($packageName, LinkConstraintInterface $constraint = null)
{
$this->addJob($packageName, 'install', $constraint, true);
} | [
"public",
"function",
"fix",
"(",
"$",
"packageName",
",",
"LinkConstraintInterface",
"$",
"constraint",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"addJob",
"(",
"$",
"packageName",
",",
"'install'",
",",
"$",
"constraint",
",",
"true",
")",
";",
"}"
] | Mark an existing package as being installed and having to remain installed
These jobs will not be tempered with by the solver | [
"Mark",
"an",
"existing",
"package",
"as",
"being",
"installed",
"and",
"having",
"to",
"remain",
"installed"
] | train | https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/DependencyResolver/Request.php#L49-L52 |
php-lug/lug | src/Component/Grid/Column/Type/JsonType.php | JsonType.render | public function render($data, array $options)
{
$json = $this->getValue($data, $options);
if ($json === null) {
return;
}
if (is_resource($json)) {
throw new InvalidTypeException(sprintf(
'The "%s" %s column type expects anything except a resource.',
$options['column']->getName(),
$this->getName()
));
}
return json_encode($json, $options['options'], $options['depth']);
} | php | public function render($data, array $options)
{
$json = $this->getValue($data, $options);
if ($json === null) {
return;
}
if (is_resource($json)) {
throw new InvalidTypeException(sprintf(
'The "%s" %s column type expects anything except a resource.',
$options['column']->getName(),
$this->getName()
));
}
return json_encode($json, $options['options'], $options['depth']);
} | [
"public",
"function",
"render",
"(",
"$",
"data",
",",
"array",
"$",
"options",
")",
"{",
"$",
"json",
"=",
"$",
"this",
"->",
"getValue",
"(",
"$",
"data",
",",
"$",
"options",
")",
";",
"if",
"(",
"$",
"json",
"===",
"null",
")",
"{",
"return",
";",
"}",
"if",
"(",
"is_resource",
"(",
"$",
"json",
")",
")",
"{",
"throw",
"new",
"InvalidTypeException",
"(",
"sprintf",
"(",
"'The \"%s\" %s column type expects anything except a resource.'",
",",
"$",
"options",
"[",
"'column'",
"]",
"->",
"getName",
"(",
")",
",",
"$",
"this",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"return",
"json_encode",
"(",
"$",
"json",
",",
"$",
"options",
"[",
"'options'",
"]",
",",
"$",
"options",
"[",
"'depth'",
"]",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Column/Type/JsonType.php#L51-L68 |
php-lug/lug | src/Component/Grid/Column/Type/JsonType.php | JsonType.configureOptions | public function configureOptions(OptionsResolver $resolver)
{
parent::configureOptions($resolver);
$resolver
->setDefaults([
'options' => $this->options,
'depth' => $this->depth,
])
->setAllowedTypes('options', 'integer')
->setAllowedTypes('depth', 'integer');
} | php | public function configureOptions(OptionsResolver $resolver)
{
parent::configureOptions($resolver);
$resolver
->setDefaults([
'options' => $this->options,
'depth' => $this->depth,
])
->setAllowedTypes('options', 'integer')
->setAllowedTypes('depth', 'integer');
} | [
"public",
"function",
"configureOptions",
"(",
"OptionsResolver",
"$",
"resolver",
")",
"{",
"parent",
"::",
"configureOptions",
"(",
"$",
"resolver",
")",
";",
"$",
"resolver",
"->",
"setDefaults",
"(",
"[",
"'options'",
"=>",
"$",
"this",
"->",
"options",
",",
"'depth'",
"=>",
"$",
"this",
"->",
"depth",
",",
"]",
")",
"->",
"setAllowedTypes",
"(",
"'options'",
",",
"'integer'",
")",
"->",
"setAllowedTypes",
"(",
"'depth'",
",",
"'integer'",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Column/Type/JsonType.php#L73-L84 |
hametuha/wpametu | src/WPametu/API/Ajax/AjaxBase.php | AjaxBase.register | public function register(){
switch( $this->target ){
case 'all':
add_action('wp_ajax_nopriv_'.$this->action, [$this, 'ajax']);
add_action('wp_ajax_'.$this->action, [$this, 'ajax']);
break;
case 'guest':
add_action('wp_ajax_nopriv_'.$this->action, [$this, 'ajax']);
break;
default:
add_action('wp_ajax_'.$this->action, [$this, 'ajax']);
break;
}
} | php | public function register(){
switch( $this->target ){
case 'all':
add_action('wp_ajax_nopriv_'.$this->action, [$this, 'ajax']);
add_action('wp_ajax_'.$this->action, [$this, 'ajax']);
break;
case 'guest':
add_action('wp_ajax_nopriv_'.$this->action, [$this, 'ajax']);
break;
default:
add_action('wp_ajax_'.$this->action, [$this, 'ajax']);
break;
}
} | [
"public",
"function",
"register",
"(",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"target",
")",
"{",
"case",
"'all'",
":",
"add_action",
"(",
"'wp_ajax_nopriv_'",
".",
"$",
"this",
"->",
"action",
",",
"[",
"$",
"this",
",",
"'ajax'",
"]",
")",
";",
"add_action",
"(",
"'wp_ajax_'",
".",
"$",
"this",
"->",
"action",
",",
"[",
"$",
"this",
",",
"'ajax'",
"]",
")",
";",
"break",
";",
"case",
"'guest'",
":",
"add_action",
"(",
"'wp_ajax_nopriv_'",
".",
"$",
"this",
"->",
"action",
",",
"[",
"$",
"this",
",",
"'ajax'",
"]",
")",
";",
"break",
";",
"default",
":",
"add_action",
"(",
"'wp_ajax_'",
".",
"$",
"this",
"->",
"action",
",",
"[",
"$",
"this",
",",
"'ajax'",
"]",
")",
";",
"break",
";",
"}",
"}"
] | Register ajax. | [
"Register",
"ajax",
"."
] | train | https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/API/Ajax/AjaxBase.php#L86-L99 |
hametuha/wpametu | src/WPametu/API/Ajax/AjaxBase.php | AjaxBase.ajax | public function ajax(){
if( 'post' == $this->method || $this->always_nocache ){
nocache_headers();
}
try{
// Authenticate
if( !$this->auth() ){
$this->error($this->__('Sorry, but you have no permission.'), 403);
}
// Validate
if( !empty($this->required) ){
foreach( $this->required as $key ){
if( !isset($_REQUEST[$key]) ){
$this->error($this->__('Sorry, but request parameters are wrong.'), 400);
}
}
}
// O.K.
$data = $this->get_data();
}catch( \Exception $e ){
$data = [
'error' => true,
'code' => $e->getCode(),
'message' => $e->getMessage()
];
}
header('Content-Type', $this->content_type);
echo $this->encode($data);
exit;
} | php | public function ajax(){
if( 'post' == $this->method || $this->always_nocache ){
nocache_headers();
}
try{
// Authenticate
if( !$this->auth() ){
$this->error($this->__('Sorry, but you have no permission.'), 403);
}
// Validate
if( !empty($this->required) ){
foreach( $this->required as $key ){
if( !isset($_REQUEST[$key]) ){
$this->error($this->__('Sorry, but request parameters are wrong.'), 400);
}
}
}
// O.K.
$data = $this->get_data();
}catch( \Exception $e ){
$data = [
'error' => true,
'code' => $e->getCode(),
'message' => $e->getMessage()
];
}
header('Content-Type', $this->content_type);
echo $this->encode($data);
exit;
} | [
"public",
"function",
"ajax",
"(",
")",
"{",
"if",
"(",
"'post'",
"==",
"$",
"this",
"->",
"method",
"||",
"$",
"this",
"->",
"always_nocache",
")",
"{",
"nocache_headers",
"(",
")",
";",
"}",
"try",
"{",
"// Authenticate",
"if",
"(",
"!",
"$",
"this",
"->",
"auth",
"(",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"$",
"this",
"->",
"__",
"(",
"'Sorry, but you have no permission.'",
")",
",",
"403",
")",
";",
"}",
"// Validate",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"required",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"required",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"_REQUEST",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"$",
"this",
"->",
"__",
"(",
"'Sorry, but request parameters are wrong.'",
")",
",",
"400",
")",
";",
"}",
"}",
"}",
"// O.K.",
"$",
"data",
"=",
"$",
"this",
"->",
"get_data",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"data",
"=",
"[",
"'error'",
"=>",
"true",
",",
"'code'",
"=>",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"'message'",
"=>",
"$",
"e",
"->",
"getMessage",
"(",
")",
"]",
";",
"}",
"header",
"(",
"'Content-Type'",
",",
"$",
"this",
"->",
"content_type",
")",
";",
"echo",
"$",
"this",
"->",
"encode",
"(",
"$",
"data",
")",
";",
"exit",
";",
"}"
] | Do Ajax | [
"Do",
"Ajax"
] | train | https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/API/Ajax/AjaxBase.php#L104-L133 |
hametuha/wpametu | src/WPametu/API/Ajax/AjaxBase.php | AjaxBase.ajax_url | protected function ajax_url(){
$url = admin_url('admin-ajax.php');
if( is_ssl() ){
$url = str_replace('http://', 'https://', $url);
}else{
$url = str_replace('https://', 'http://', $url);
}
return $url;
} | php | protected function ajax_url(){
$url = admin_url('admin-ajax.php');
if( is_ssl() ){
$url = str_replace('http://', 'https://', $url);
}else{
$url = str_replace('https://', 'http://', $url);
}
return $url;
} | [
"protected",
"function",
"ajax_url",
"(",
")",
"{",
"$",
"url",
"=",
"admin_url",
"(",
"'admin-ajax.php'",
")",
";",
"if",
"(",
"is_ssl",
"(",
")",
")",
"{",
"$",
"url",
"=",
"str_replace",
"(",
"'http://'",
",",
"'https://'",
",",
"$",
"url",
")",
";",
"}",
"else",
"{",
"$",
"url",
"=",
"str_replace",
"(",
"'https://'",
",",
"'http://'",
",",
"$",
"url",
")",
";",
"}",
"return",
"$",
"url",
";",
"}"
] | Returns Ajax endpoint
@return string | [
"Returns",
"Ajax",
"endpoint"
] | train | https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/API/Ajax/AjaxBase.php#L141-L149 |
rhosocial/yii2-user | forms/RegisterForm.php | RegisterForm.register | public function register()
{
if ($this->validate()) {
$class = $this->userClass;
$user = new $class(['password' => $this->password]);
/* @var $user User */
$profile = $user->createProfile(['nickname' => $this->nickname, 'first_name' => $this->first_name, 'last_name' => $this->last_name, 'gender' => $this->gender]);
$models[] = $profile;
if (is_string($this->username)) {
$username = $user->createUsername($this->username);
$models[] = $username;
}
$result = $user->register($models);
if ($result == true) {
$this->model = $user;
}
return $result;
}
return false;
} | php | public function register()
{
if ($this->validate()) {
$class = $this->userClass;
$user = new $class(['password' => $this->password]);
/* @var $user User */
$profile = $user->createProfile(['nickname' => $this->nickname, 'first_name' => $this->first_name, 'last_name' => $this->last_name, 'gender' => $this->gender]);
$models[] = $profile;
if (is_string($this->username)) {
$username = $user->createUsername($this->username);
$models[] = $username;
}
$result = $user->register($models);
if ($result == true) {
$this->model = $user;
}
return $result;
}
return false;
} | [
"public",
"function",
"register",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"validate",
"(",
")",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"userClass",
";",
"$",
"user",
"=",
"new",
"$",
"class",
"(",
"[",
"'password'",
"=>",
"$",
"this",
"->",
"password",
"]",
")",
";",
"/* @var $user User */",
"$",
"profile",
"=",
"$",
"user",
"->",
"createProfile",
"(",
"[",
"'nickname'",
"=>",
"$",
"this",
"->",
"nickname",
",",
"'first_name'",
"=>",
"$",
"this",
"->",
"first_name",
",",
"'last_name'",
"=>",
"$",
"this",
"->",
"last_name",
",",
"'gender'",
"=>",
"$",
"this",
"->",
"gender",
"]",
")",
";",
"$",
"models",
"[",
"]",
"=",
"$",
"profile",
";",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"username",
")",
")",
"{",
"$",
"username",
"=",
"$",
"user",
"->",
"createUsername",
"(",
"$",
"this",
"->",
"username",
")",
";",
"$",
"models",
"[",
"]",
"=",
"$",
"username",
";",
"}",
"$",
"result",
"=",
"$",
"user",
"->",
"register",
"(",
"$",
"models",
")",
";",
"if",
"(",
"$",
"result",
"==",
"true",
")",
"{",
"$",
"this",
"->",
"model",
"=",
"$",
"user",
";",
"}",
"return",
"$",
"result",
";",
"}",
"return",
"false",
";",
"}"
] | Register user with current model.
@return bool | [
"Register",
"user",
"with",
"current",
"model",
"."
] | train | https://github.com/rhosocial/yii2-user/blob/96737a9d8ca7e9c42cd2b7736d6c0a90ede6e5bc/forms/RegisterForm.php#L128-L147 |
oroinc/OroLayoutComponent | Extension/Theme/PathProvider/ThemePathProvider.php | ThemePathProvider.getPaths | public function getPaths(array $existingPaths)
{
$themeName = $this->context->getOr('theme');
if ($themeName) {
$themePaths = [];
$themes = $this->getThemesHierarchy($themeName);
foreach ($themes as $theme) {
$existingPaths[] = $themePaths[] = $theme->getDirectory();
}
$actionName = $this->context->getOr('action');
if ($actionName) {
foreach ($themePaths as $path) {
$existingPaths[] = implode(self::DELIMITER, [$path, $actionName]);
}
}
$routeName = $this->context->getOr('route_name');
if ($routeName) {
foreach ($themePaths as $path) {
$existingPaths[] = implode(self::DELIMITER, [$path, $routeName]);
}
}
$pageTemplate = $this->context->getOr('page_template');
if ($pageTemplate) {
$theme = $this->themeManager->getTheme($themeName);
if ($theme->getPageTemplate($this->context->getOr('page_template'), $routeName)) {
foreach ($themePaths as $path) {
$existingPaths[] =
implode(self::DELIMITER, [$path, $routeName, 'page_template', $pageTemplate]);
}
}
}
}
return $existingPaths;
} | php | public function getPaths(array $existingPaths)
{
$themeName = $this->context->getOr('theme');
if ($themeName) {
$themePaths = [];
$themes = $this->getThemesHierarchy($themeName);
foreach ($themes as $theme) {
$existingPaths[] = $themePaths[] = $theme->getDirectory();
}
$actionName = $this->context->getOr('action');
if ($actionName) {
foreach ($themePaths as $path) {
$existingPaths[] = implode(self::DELIMITER, [$path, $actionName]);
}
}
$routeName = $this->context->getOr('route_name');
if ($routeName) {
foreach ($themePaths as $path) {
$existingPaths[] = implode(self::DELIMITER, [$path, $routeName]);
}
}
$pageTemplate = $this->context->getOr('page_template');
if ($pageTemplate) {
$theme = $this->themeManager->getTheme($themeName);
if ($theme->getPageTemplate($this->context->getOr('page_template'), $routeName)) {
foreach ($themePaths as $path) {
$existingPaths[] =
implode(self::DELIMITER, [$path, $routeName, 'page_template', $pageTemplate]);
}
}
}
}
return $existingPaths;
} | [
"public",
"function",
"getPaths",
"(",
"array",
"$",
"existingPaths",
")",
"{",
"$",
"themeName",
"=",
"$",
"this",
"->",
"context",
"->",
"getOr",
"(",
"'theme'",
")",
";",
"if",
"(",
"$",
"themeName",
")",
"{",
"$",
"themePaths",
"=",
"[",
"]",
";",
"$",
"themes",
"=",
"$",
"this",
"->",
"getThemesHierarchy",
"(",
"$",
"themeName",
")",
";",
"foreach",
"(",
"$",
"themes",
"as",
"$",
"theme",
")",
"{",
"$",
"existingPaths",
"[",
"]",
"=",
"$",
"themePaths",
"[",
"]",
"=",
"$",
"theme",
"->",
"getDirectory",
"(",
")",
";",
"}",
"$",
"actionName",
"=",
"$",
"this",
"->",
"context",
"->",
"getOr",
"(",
"'action'",
")",
";",
"if",
"(",
"$",
"actionName",
")",
"{",
"foreach",
"(",
"$",
"themePaths",
"as",
"$",
"path",
")",
"{",
"$",
"existingPaths",
"[",
"]",
"=",
"implode",
"(",
"self",
"::",
"DELIMITER",
",",
"[",
"$",
"path",
",",
"$",
"actionName",
"]",
")",
";",
"}",
"}",
"$",
"routeName",
"=",
"$",
"this",
"->",
"context",
"->",
"getOr",
"(",
"'route_name'",
")",
";",
"if",
"(",
"$",
"routeName",
")",
"{",
"foreach",
"(",
"$",
"themePaths",
"as",
"$",
"path",
")",
"{",
"$",
"existingPaths",
"[",
"]",
"=",
"implode",
"(",
"self",
"::",
"DELIMITER",
",",
"[",
"$",
"path",
",",
"$",
"routeName",
"]",
")",
";",
"}",
"}",
"$",
"pageTemplate",
"=",
"$",
"this",
"->",
"context",
"->",
"getOr",
"(",
"'page_template'",
")",
";",
"if",
"(",
"$",
"pageTemplate",
")",
"{",
"$",
"theme",
"=",
"$",
"this",
"->",
"themeManager",
"->",
"getTheme",
"(",
"$",
"themeName",
")",
";",
"if",
"(",
"$",
"theme",
"->",
"getPageTemplate",
"(",
"$",
"this",
"->",
"context",
"->",
"getOr",
"(",
"'page_template'",
")",
",",
"$",
"routeName",
")",
")",
"{",
"foreach",
"(",
"$",
"themePaths",
"as",
"$",
"path",
")",
"{",
"$",
"existingPaths",
"[",
"]",
"=",
"implode",
"(",
"self",
"::",
"DELIMITER",
",",
"[",
"$",
"path",
",",
"$",
"routeName",
",",
"'page_template'",
",",
"$",
"pageTemplate",
"]",
")",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"existingPaths",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Extension/Theme/PathProvider/ThemePathProvider.php#L37-L75 |
oroinc/OroLayoutComponent | Extension/Theme/PathProvider/ThemePathProvider.php | ThemePathProvider.getThemesHierarchy | protected function getThemesHierarchy($themeName)
{
$hierarchy = [];
while (null !== $themeName) {
$theme = $this->themeManager->getTheme($themeName);
$hierarchy[] = $theme;
$themeName = $theme->getParentTheme();
}
return array_reverse($hierarchy);
} | php | protected function getThemesHierarchy($themeName)
{
$hierarchy = [];
while (null !== $themeName) {
$theme = $this->themeManager->getTheme($themeName);
$hierarchy[] = $theme;
$themeName = $theme->getParentTheme();
}
return array_reverse($hierarchy);
} | [
"protected",
"function",
"getThemesHierarchy",
"(",
"$",
"themeName",
")",
"{",
"$",
"hierarchy",
"=",
"[",
"]",
";",
"while",
"(",
"null",
"!==",
"$",
"themeName",
")",
"{",
"$",
"theme",
"=",
"$",
"this",
"->",
"themeManager",
"->",
"getTheme",
"(",
"$",
"themeName",
")",
";",
"$",
"hierarchy",
"[",
"]",
"=",
"$",
"theme",
";",
"$",
"themeName",
"=",
"$",
"theme",
"->",
"getParentTheme",
"(",
")",
";",
"}",
"return",
"array_reverse",
"(",
"$",
"hierarchy",
")",
";",
"}"
] | Returns theme inheritance hierarchy with root theme as first item
@param string $themeName
@return Theme[] | [
"Returns",
"theme",
"inheritance",
"hierarchy",
"with",
"root",
"theme",
"as",
"first",
"item"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Extension/Theme/PathProvider/ThemePathProvider.php#L84-L96 |
husccexo/php-handlersocket-core | src/HSCore/Driver.php | Driver.send | public function send($command)
{
$string = $command;
$timer = microtime(true);
while ($string) {
$bytes = fwrite($this->socket, $string);
if ($bytes === false) {
$this->close();
throw new HSException('Cannot write to socket');
}
if ($bytes === 0) {
return null;
}
$string = substr($string, $bytes);
}
$this->logs[] = [
'type' => 'sended',
'time' => microtime(true) - $timer,
'command' => $command
];
return $this->receive();
} | php | public function send($command)
{
$string = $command;
$timer = microtime(true);
while ($string) {
$bytes = fwrite($this->socket, $string);
if ($bytes === false) {
$this->close();
throw new HSException('Cannot write to socket');
}
if ($bytes === 0) {
return null;
}
$string = substr($string, $bytes);
}
$this->logs[] = [
'type' => 'sended',
'time' => microtime(true) - $timer,
'command' => $command
];
return $this->receive();
} | [
"public",
"function",
"send",
"(",
"$",
"command",
")",
"{",
"$",
"string",
"=",
"$",
"command",
";",
"$",
"timer",
"=",
"microtime",
"(",
"true",
")",
";",
"while",
"(",
"$",
"string",
")",
"{",
"$",
"bytes",
"=",
"fwrite",
"(",
"$",
"this",
"->",
"socket",
",",
"$",
"string",
")",
";",
"if",
"(",
"$",
"bytes",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"close",
"(",
")",
";",
"throw",
"new",
"HSException",
"(",
"'Cannot write to socket'",
")",
";",
"}",
"if",
"(",
"$",
"bytes",
"===",
"0",
")",
"{",
"return",
"null",
";",
"}",
"$",
"string",
"=",
"substr",
"(",
"$",
"string",
",",
"$",
"bytes",
")",
";",
"}",
"$",
"this",
"->",
"logs",
"[",
"]",
"=",
"[",
"'type'",
"=>",
"'sended'",
",",
"'time'",
"=>",
"microtime",
"(",
"true",
")",
"-",
"$",
"timer",
",",
"'command'",
"=>",
"$",
"command",
"]",
";",
"return",
"$",
"this",
"->",
"receive",
"(",
")",
";",
"}"
] | Send string command to server
@param string $command
@return string
@throws HSException | [
"Send",
"string",
"command",
"to",
"server"
] | train | https://github.com/husccexo/php-handlersocket-core/blob/aaeeece9c90a89bbc861a6fe390bc0c892496bf0/src/HSCore/Driver.php#L78-L106 |
husccexo/php-handlersocket-core | src/HSCore/Driver.php | Driver.encode | public static function encode($string)
{
return is_null($string) ? self::NULL : strtr($string, self::$encodeMap);
} | php | public static function encode($string)
{
return is_null($string) ? self::NULL : strtr($string, self::$encodeMap);
} | [
"public",
"static",
"function",
"encode",
"(",
"$",
"string",
")",
"{",
"return",
"is_null",
"(",
"$",
"string",
")",
"?",
"self",
"::",
"NULL",
":",
"strtr",
"(",
"$",
"string",
",",
"self",
"::",
"$",
"encodeMap",
")",
";",
"}"
] | Encode string for sending to server
@param $string
@return string | [
"Encode",
"string",
"for",
"sending",
"to",
"server"
] | train | https://github.com/husccexo/php-handlersocket-core/blob/aaeeece9c90a89bbc861a6fe390bc0c892496bf0/src/HSCore/Driver.php#L126-L129 |
husccexo/php-handlersocket-core | src/HSCore/Driver.php | Driver.decode | public static function decode($string)
{
return ($string === self::NULL) ? null : strtr($string, self::$decodeMap);
} | php | public static function decode($string)
{
return ($string === self::NULL) ? null : strtr($string, self::$decodeMap);
} | [
"public",
"static",
"function",
"decode",
"(",
"$",
"string",
")",
"{",
"return",
"(",
"$",
"string",
"===",
"self",
"::",
"NULL",
")",
"?",
"null",
":",
"strtr",
"(",
"$",
"string",
",",
"self",
"::",
"$",
"decodeMap",
")",
";",
"}"
] | Decode string from server
@param $string
@return null|string | [
"Decode",
"string",
"from",
"server"
] | train | https://github.com/husccexo/php-handlersocket-core/blob/aaeeece9c90a89bbc861a6fe390bc0c892496bf0/src/HSCore/Driver.php#L138-L141 |
husccexo/php-handlersocket-core | src/HSCore/Driver.php | Driver.open | public function open()
{
$this->socket = stream_socket_client('tcp://'.$this->address, $errc, $errs, STREAM_CLIENT_CONNECT);
if (!$this->socket) {
throw new HSException('Connection to '.$this->address.' failed');
}
} | php | public function open()
{
$this->socket = stream_socket_client('tcp://'.$this->address, $errc, $errs, STREAM_CLIENT_CONNECT);
if (!$this->socket) {
throw new HSException('Connection to '.$this->address.' failed');
}
} | [
"public",
"function",
"open",
"(",
")",
"{",
"$",
"this",
"->",
"socket",
"=",
"stream_socket_client",
"(",
"'tcp://'",
".",
"$",
"this",
"->",
"address",
",",
"$",
"errc",
",",
"$",
"errs",
",",
"STREAM_CLIENT_CONNECT",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"socket",
")",
"{",
"throw",
"new",
"HSException",
"(",
"'Connection to '",
".",
"$",
"this",
"->",
"address",
".",
"' failed'",
")",
";",
"}",
"}"
] | Open Handler Socket
@throwsHSrException | [
"Open",
"Handler",
"Socket"
] | train | https://github.com/husccexo/php-handlersocket-core/blob/aaeeece9c90a89bbc861a6fe390bc0c892496bf0/src/HSCore/Driver.php#L149-L156 |
husccexo/php-handlersocket-core | src/HSCore/Driver.php | Driver.receive | private function receive()
{
$timer = microtime(true);
$str = fgets($this->socket);
if ($str === false) {
$this->close();
throw new HSException('Cannot read from socket');
}
$this->logs[] = [
'type' => 'receive',
'time' => microtime(true) - $timer,
'command' => $str
];
return substr($str, 0, -1);
} | php | private function receive()
{
$timer = microtime(true);
$str = fgets($this->socket);
if ($str === false) {
$this->close();
throw new HSException('Cannot read from socket');
}
$this->logs[] = [
'type' => 'receive',
'time' => microtime(true) - $timer,
'command' => $str
];
return substr($str, 0, -1);
} | [
"private",
"function",
"receive",
"(",
")",
"{",
"$",
"timer",
"=",
"microtime",
"(",
"true",
")",
";",
"$",
"str",
"=",
"fgets",
"(",
"$",
"this",
"->",
"socket",
")",
";",
"if",
"(",
"$",
"str",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"close",
"(",
")",
";",
"throw",
"new",
"HSException",
"(",
"'Cannot read from socket'",
")",
";",
"}",
"$",
"this",
"->",
"logs",
"[",
"]",
"=",
"[",
"'type'",
"=>",
"'receive'",
",",
"'time'",
"=>",
"microtime",
"(",
"true",
")",
"-",
"$",
"timer",
",",
"'command'",
"=>",
"$",
"str",
"]",
";",
"return",
"substr",
"(",
"$",
"str",
",",
"0",
",",
"-",
"1",
")",
";",
"}"
] | Receive one string from server.
String haven't trailing \n
@return string
@throws HSException | [
"Receive",
"one",
"string",
"from",
"server",
".",
"String",
"haven",
"t",
"trailing",
"\\",
"n"
] | train | https://github.com/husccexo/php-handlersocket-core/blob/aaeeece9c90a89bbc861a6fe390bc0c892496bf0/src/HSCore/Driver.php#L203-L222 |
bytic/framework | src/Mvc/Sections/Section.php | Section.compilePath | public function compilePath($path = false)
{
$currentBasePath = $this->getManager()->getCurrent()->getPath();
$path = str_replace($currentBasePath, $this->getPath(), $path);
return $path;
} | php | public function compilePath($path = false)
{
$currentBasePath = $this->getManager()->getCurrent()->getPath();
$path = str_replace($currentBasePath, $this->getPath(), $path);
return $path;
} | [
"public",
"function",
"compilePath",
"(",
"$",
"path",
"=",
"false",
")",
"{",
"$",
"currentBasePath",
"=",
"$",
"this",
"->",
"getManager",
"(",
")",
"->",
"getCurrent",
"(",
")",
"->",
"getPath",
"(",
")",
";",
"$",
"path",
"=",
"str_replace",
"(",
"$",
"currentBasePath",
",",
"$",
"this",
"->",
"getPath",
"(",
")",
",",
"$",
"path",
")",
";",
"return",
"$",
"path",
";",
"}"
] | Compile path for this section from a given path of current section
@param bool $path
@return string | [
"Compile",
"path",
"for",
"this",
"section",
"from",
"a",
"given",
"path",
"of",
"current",
"section"
] | train | https://github.com/bytic/framework/blob/36b4a761f4b64899f3841b0f6c8eb92887e91677/src/Mvc/Sections/Section.php#L73-L78 |
ShaoZeMing/laravel-merchant | src/Auth/Permission.php | Permission.check | public static function check($permission)
{
if (static::isAdministrator()) {
return true;
}
if (is_array($permission)) {
collect($permission)->each(function ($permission) {
call_user_func([Permission::class, 'check'], $permission);
});
return;
}
if (Auth::guard('merchant')->user()->cannot($permission)) {
static::error();
}
} | php | public static function check($permission)
{
if (static::isAdministrator()) {
return true;
}
if (is_array($permission)) {
collect($permission)->each(function ($permission) {
call_user_func([Permission::class, 'check'], $permission);
});
return;
}
if (Auth::guard('merchant')->user()->cannot($permission)) {
static::error();
}
} | [
"public",
"static",
"function",
"check",
"(",
"$",
"permission",
")",
"{",
"if",
"(",
"static",
"::",
"isAdministrator",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"permission",
")",
")",
"{",
"collect",
"(",
"$",
"permission",
")",
"->",
"each",
"(",
"function",
"(",
"$",
"permission",
")",
"{",
"call_user_func",
"(",
"[",
"Permission",
"::",
"class",
",",
"'check'",
"]",
",",
"$",
"permission",
")",
";",
"}",
")",
";",
"return",
";",
"}",
"if",
"(",
"Auth",
"::",
"guard",
"(",
"'merchant'",
")",
"->",
"user",
"(",
")",
"->",
"cannot",
"(",
"$",
"permission",
")",
")",
"{",
"static",
"::",
"error",
"(",
")",
";",
"}",
"}"
] | Check permission.
@param $permission
@return true | [
"Check",
"permission",
"."
] | train | https://github.com/ShaoZeMing/laravel-merchant/blob/20801b1735e7832a6e58b37c2c391328f8d626fa/src/Auth/Permission.php#L18-L35 |
ShaoZeMing/laravel-merchant | src/Auth/Permission.php | Permission.error | public static function error()
{
$response = response(Merchant::content()->withError(trans('merchant.deny')));
Pjax::respond($response);
} | php | public static function error()
{
$response = response(Merchant::content()->withError(trans('merchant.deny')));
Pjax::respond($response);
} | [
"public",
"static",
"function",
"error",
"(",
")",
"{",
"$",
"response",
"=",
"response",
"(",
"Merchant",
"::",
"content",
"(",
")",
"->",
"withError",
"(",
"trans",
"(",
"'merchant.deny'",
")",
")",
")",
";",
"Pjax",
"::",
"respond",
"(",
"$",
"response",
")",
";",
"}"
] | Send error response page. | [
"Send",
"error",
"response",
"page",
"."
] | train | https://github.com/ShaoZeMing/laravel-merchant/blob/20801b1735e7832a6e58b37c2c391328f8d626fa/src/Auth/Permission.php#L76-L81 |
gregorybesson/PlaygroundCms | src/Service/Slideshow.php | Slideshow.getSlideshowMapper | public function getSlideshowMapper()
{
if (null === $this->slideshowMapper) {
$this->slideshowMapper = $this->serviceLocator->get('playgroundcms_slideshow_mapper');
}
return $this->slideshowMapper;
} | php | public function getSlideshowMapper()
{
if (null === $this->slideshowMapper) {
$this->slideshowMapper = $this->serviceLocator->get('playgroundcms_slideshow_mapper');
}
return $this->slideshowMapper;
} | [
"public",
"function",
"getSlideshowMapper",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"slideshowMapper",
")",
"{",
"$",
"this",
"->",
"slideshowMapper",
"=",
"$",
"this",
"->",
"serviceLocator",
"->",
"get",
"(",
"'playgroundcms_slideshow_mapper'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"slideshowMapper",
";",
"}"
] | getSlideshowMapper
@return SlideshowMapper | [
"getSlideshowMapper"
] | train | https://github.com/gregorybesson/PlaygroundCms/blob/e929a283f2a6e82d4f248c930f7aa454ce20cbc3/src/Service/Slideshow.php#L199-L206 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Cache/src/storage/apc/plain.php | ezcCacheStorageApcPlain.fetchData | protected function fetchData( $identifier, $object = false )
{
$data = $this->backend->fetch( $identifier );
if ( is_object( $data ) && $object === false )
{
return $data->data;
}
if ( is_object( $data ) && $object !== false )
{
return $data;
}
else
{
return false;
}
} | php | protected function fetchData( $identifier, $object = false )
{
$data = $this->backend->fetch( $identifier );
if ( is_object( $data ) && $object === false )
{
return $data->data;
}
if ( is_object( $data ) && $object !== false )
{
return $data;
}
else
{
return false;
}
} | [
"protected",
"function",
"fetchData",
"(",
"$",
"identifier",
",",
"$",
"object",
"=",
"false",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"backend",
"->",
"fetch",
"(",
"$",
"identifier",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"data",
")",
"&&",
"$",
"object",
"===",
"false",
")",
"{",
"return",
"$",
"data",
"->",
"data",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"data",
")",
"&&",
"$",
"object",
"!==",
"false",
")",
"{",
"return",
"$",
"data",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Fetches data from the cache.
@param string $identifier The file to fetch data from
@param bool $object return the object and not the clean data
@return mixed The fetched data or false on failure | [
"Fetches",
"data",
"from",
"the",
"cache",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Cache/src/storage/apc/plain.php#L30-L45 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Cache/src/storage/apc/plain.php | ezcCacheStorageApcPlain.prepareData | protected function prepareData( $data )
{
if ( is_resource( $data ) )
{
throw new ezcCacheInvalidDataException( gettype( $data ), array( 'simple', 'array', 'object' ) );
}
return new ezcCacheStorageMemoryDataStruct( $data, $this->properties['location'] );
} | php | protected function prepareData( $data )
{
if ( is_resource( $data ) )
{
throw new ezcCacheInvalidDataException( gettype( $data ), array( 'simple', 'array', 'object' ) );
}
return new ezcCacheStorageMemoryDataStruct( $data, $this->properties['location'] );
} | [
"protected",
"function",
"prepareData",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"is_resource",
"(",
"$",
"data",
")",
")",
"{",
"throw",
"new",
"ezcCacheInvalidDataException",
"(",
"gettype",
"(",
"$",
"data",
")",
",",
"array",
"(",
"'simple'",
",",
"'array'",
",",
"'object'",
")",
")",
";",
"}",
"return",
"new",
"ezcCacheStorageMemoryDataStruct",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"properties",
"[",
"'location'",
"]",
")",
";",
"}"
] | Wraps the data in an ezcCacheStorageMemoryDataStruct structure in order
to store it.
@throws ezcCacheInvalidDataException
If the data submitted can not be handled by this storage (resource).
@param mixed $data Simple type or array
@return ezcCacheStorageMemoryDataStruct Prepared data | [
"Wraps",
"the",
"data",
"in",
"an",
"ezcCacheStorageMemoryDataStruct",
"structure",
"in",
"order",
"to",
"store",
"it",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Cache/src/storage/apc/plain.php#L57-L64 |
bradcornford/Alerter | src/Cornford/Alerter/AlertDisplay.php | AlertDisplay.findDisplayViewFile | protected function findDisplayViewFile()
{
foreach($this->getDirectoryIterator() as $file) {
$name = $file->getFilename();
if ($this->isDisplayViewFile($name)) {
return $file->getPathname();
}
}
throw new AlertDisplayViewException('Could not locate the view file.');
} | php | protected function findDisplayViewFile()
{
foreach($this->getDirectoryIterator() as $file) {
$name = $file->getFilename();
if ($this->isDisplayViewFile($name)) {
return $file->getPathname();
}
}
throw new AlertDisplayViewException('Could not locate the view file.');
} | [
"protected",
"function",
"findDisplayViewFile",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getDirectoryIterator",
"(",
")",
"as",
"$",
"file",
")",
"{",
"$",
"name",
"=",
"$",
"file",
"->",
"getFilename",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isDisplayViewFile",
"(",
"$",
"name",
")",
")",
"{",
"return",
"$",
"file",
"->",
"getPathname",
"(",
")",
";",
"}",
"}",
"throw",
"new",
"AlertDisplayViewException",
"(",
"'Could not locate the view file.'",
")",
";",
"}"
] | Track down the display view file.
@return string
@throws \Cornford\Alerter\Exceptions\AlertDisplayViewException | [
"Track",
"down",
"the",
"display",
"view",
"file",
"."
] | train | https://github.com/bradcornford/Alerter/blob/6533fe7afb9d1bae553385d3e687a24bda6a1333/src/Cornford/Alerter/AlertDisplay.php#L85-L96 |
Innmind/neo4j-dbal | src/Transactions.php | Transactions.open | public function open(): Transaction
{
$response = ($this->fulfill)(
new Request(
Url::fromString('/db/data/transaction'),
Method::post(),
new ProtocolVersion(1, 1),
$this->headers,
$this->body
)
);
$body = Json::decode((string) $response->body());
$location = (string) $response
->headers()
->get('Location')
->values()
->current();
$transaction = new Transaction(
Url::fromString($location),
$this->clock->at($body['transaction']['expires']),
Url::fromString($body['commit'])
);
$this->transactions = $this->transactions->add($transaction);
return $transaction;
} | php | public function open(): Transaction
{
$response = ($this->fulfill)(
new Request(
Url::fromString('/db/data/transaction'),
Method::post(),
new ProtocolVersion(1, 1),
$this->headers,
$this->body
)
);
$body = Json::decode((string) $response->body());
$location = (string) $response
->headers()
->get('Location')
->values()
->current();
$transaction = new Transaction(
Url::fromString($location),
$this->clock->at($body['transaction']['expires']),
Url::fromString($body['commit'])
);
$this->transactions = $this->transactions->add($transaction);
return $transaction;
} | [
"public",
"function",
"open",
"(",
")",
":",
"Transaction",
"{",
"$",
"response",
"=",
"(",
"$",
"this",
"->",
"fulfill",
")",
"(",
"new",
"Request",
"(",
"Url",
"::",
"fromString",
"(",
"'/db/data/transaction'",
")",
",",
"Method",
"::",
"post",
"(",
")",
",",
"new",
"ProtocolVersion",
"(",
"1",
",",
"1",
")",
",",
"$",
"this",
"->",
"headers",
",",
"$",
"this",
"->",
"body",
")",
")",
";",
"$",
"body",
"=",
"Json",
"::",
"decode",
"(",
"(",
"string",
")",
"$",
"response",
"->",
"body",
"(",
")",
")",
";",
"$",
"location",
"=",
"(",
"string",
")",
"$",
"response",
"->",
"headers",
"(",
")",
"->",
"get",
"(",
"'Location'",
")",
"->",
"values",
"(",
")",
"->",
"current",
"(",
")",
";",
"$",
"transaction",
"=",
"new",
"Transaction",
"(",
"Url",
"::",
"fromString",
"(",
"$",
"location",
")",
",",
"$",
"this",
"->",
"clock",
"->",
"at",
"(",
"$",
"body",
"[",
"'transaction'",
"]",
"[",
"'expires'",
"]",
")",
",",
"Url",
"::",
"fromString",
"(",
"$",
"body",
"[",
"'commit'",
"]",
")",
")",
";",
"$",
"this",
"->",
"transactions",
"=",
"$",
"this",
"->",
"transactions",
"->",
"add",
"(",
"$",
"transaction",
")",
";",
"return",
"$",
"transaction",
";",
"}"
] | Open a new transaction
@return Transaction | [
"Open",
"a",
"new",
"transaction"
] | train | https://github.com/Innmind/neo4j-dbal/blob/12cb71e698cc0f4d55b7f2eb40f7b353c778a20b/src/Transactions.php#L66-L93 |
Innmind/neo4j-dbal | src/Transactions.php | Transactions.commit | public function commit(): self
{
($this->fulfill)(
new Request(
$this->current()->commitEndpoint(),
Method::post(),
new ProtocolVersion(1, 1),
$this->headers,
$this->body
)
);
$this->transactions = $this->transactions->dropEnd(1);
return $this;
} | php | public function commit(): self
{
($this->fulfill)(
new Request(
$this->current()->commitEndpoint(),
Method::post(),
new ProtocolVersion(1, 1),
$this->headers,
$this->body
)
);
$this->transactions = $this->transactions->dropEnd(1);
return $this;
} | [
"public",
"function",
"commit",
"(",
")",
":",
"self",
"{",
"(",
"$",
"this",
"->",
"fulfill",
")",
"(",
"new",
"Request",
"(",
"$",
"this",
"->",
"current",
"(",
")",
"->",
"commitEndpoint",
"(",
")",
",",
"Method",
"::",
"post",
"(",
")",
",",
"new",
"ProtocolVersion",
"(",
"1",
",",
"1",
")",
",",
"$",
"this",
"->",
"headers",
",",
"$",
"this",
"->",
"body",
")",
")",
";",
"$",
"this",
"->",
"transactions",
"=",
"$",
"this",
"->",
"transactions",
"->",
"dropEnd",
"(",
"1",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Commit the current transaction
@return self | [
"Commit",
"the",
"current",
"transaction"
] | train | https://github.com/Innmind/neo4j-dbal/blob/12cb71e698cc0f4d55b7f2eb40f7b353c778a20b/src/Transactions.php#L120-L134 |
Innmind/neo4j-dbal | src/Transactions.php | Transactions.rollback | public function rollback(): self
{
($this->fulfill)(
new Request(
$this->current()->endpoint(),
Method::delete(),
new ProtocolVersion(1, 1)
)
);
$this->transactions = $this->transactions->dropEnd(1);
return $this;
} | php | public function rollback(): self
{
($this->fulfill)(
new Request(
$this->current()->endpoint(),
Method::delete(),
new ProtocolVersion(1, 1)
)
);
$this->transactions = $this->transactions->dropEnd(1);
return $this;
} | [
"public",
"function",
"rollback",
"(",
")",
":",
"self",
"{",
"(",
"$",
"this",
"->",
"fulfill",
")",
"(",
"new",
"Request",
"(",
"$",
"this",
"->",
"current",
"(",
")",
"->",
"endpoint",
"(",
")",
",",
"Method",
"::",
"delete",
"(",
")",
",",
"new",
"ProtocolVersion",
"(",
"1",
",",
"1",
")",
")",
")",
";",
"$",
"this",
"->",
"transactions",
"=",
"$",
"this",
"->",
"transactions",
"->",
"dropEnd",
"(",
"1",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Rollback the current transaction
@return self | [
"Rollback",
"the",
"current",
"transaction"
] | train | https://github.com/Innmind/neo4j-dbal/blob/12cb71e698cc0f4d55b7f2eb40f7b353c778a20b/src/Transactions.php#L141-L153 |
dreamfactorysoftware/df-cache | src/Services/Local.php | Local.setStore | protected function setStore($config)
{
$store = array_get($config, 'store');
$availableStores = array_keys(\Config::get('cache.stores', []));
if (empty($store)) {
$store = \Config::get('cache.default');
}
if (!in_array($store, $availableStores)) {
throw new InternalServerErrorException('Invalid cache store provided [' . $store . ']');
}
$this->store = \Cache::store($store);
} | php | protected function setStore($config)
{
$store = array_get($config, 'store');
$availableStores = array_keys(\Config::get('cache.stores', []));
if (empty($store)) {
$store = \Config::get('cache.default');
}
if (!in_array($store, $availableStores)) {
throw new InternalServerErrorException('Invalid cache store provided [' . $store . ']');
}
$this->store = \Cache::store($store);
} | [
"protected",
"function",
"setStore",
"(",
"$",
"config",
")",
"{",
"$",
"store",
"=",
"array_get",
"(",
"$",
"config",
",",
"'store'",
")",
";",
"$",
"availableStores",
"=",
"array_keys",
"(",
"\\",
"Config",
"::",
"get",
"(",
"'cache.stores'",
",",
"[",
"]",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"store",
")",
")",
"{",
"$",
"store",
"=",
"\\",
"Config",
"::",
"get",
"(",
"'cache.default'",
")",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"store",
",",
"$",
"availableStores",
")",
")",
"{",
"throw",
"new",
"InternalServerErrorException",
"(",
"'Invalid cache store provided ['",
".",
"$",
"store",
".",
"']'",
")",
";",
"}",
"$",
"this",
"->",
"store",
"=",
"\\",
"Cache",
"::",
"store",
"(",
"$",
"store",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/dreamfactorysoftware/df-cache/blob/6a2aa5dc2fc7963ce89fd7e8f3d51483d2499451/src/Services/Local.php#L9-L23 |
Eresus/EresusCMS | src/core/lib/forms.php | Form.field_prep | function field_prep(&$item)
{
$item['type'] = strtolower($item['type']);
# Метка
if (!isset($item['label'])) $item['label'] = '';
# Подсказка
if (isset($item['hint'])) $item['label'] = '<span class="hint" title="'.$item['hint'].'">'.$item['label'].'</span>';
# Маска значения
if (isset($item['pattern']) && isset($item['name']))
$this->validator .= "
if (!form.".$item['name'].".value.match(".$item['pattern'].")) {
alert('".(isset($item['errormsg'])?$item['errormsg']:sprintf(errFormPatternError, $item['name'], $item['pattern']))."');
result = false;
form.".$item['name'].".select();
} else ";
# Значение
$item['value'] = isset($item['value']) ? $item['value']
: (isset($item['name']) && isset($this->values[$item['name']]) ? $this->values[$item['name']]
: (isset($item['default']) ? $item['default']
: '' )
);
# ID
if (!isset($item['id'])) $item['id'] = '';
# Элемент отключен
if (!isset($item['disabled'])) $item['disabled'] = '';
# Комментарий
$item['comment'] = isset($item['comment']) ? ' '.$item['comment'] : '';
# Стили
$item['style'] = isset($item['style']) ? explode(';', $item['style']) : array();
# Классы
$item['class'] = isset($item['class']) ? explode(' ', $item['class']) : array();
# Дополнительно
if (!isset($item['extra'])) $item['extra'] = '';
} | php | function field_prep(&$item)
{
$item['type'] = strtolower($item['type']);
# Метка
if (!isset($item['label'])) $item['label'] = '';
# Подсказка
if (isset($item['hint'])) $item['label'] = '<span class="hint" title="'.$item['hint'].'">'.$item['label'].'</span>';
# Маска значения
if (isset($item['pattern']) && isset($item['name']))
$this->validator .= "
if (!form.".$item['name'].".value.match(".$item['pattern'].")) {
alert('".(isset($item['errormsg'])?$item['errormsg']:sprintf(errFormPatternError, $item['name'], $item['pattern']))."');
result = false;
form.".$item['name'].".select();
} else ";
# Значение
$item['value'] = isset($item['value']) ? $item['value']
: (isset($item['name']) && isset($this->values[$item['name']]) ? $this->values[$item['name']]
: (isset($item['default']) ? $item['default']
: '' )
);
# ID
if (!isset($item['id'])) $item['id'] = '';
# Элемент отключен
if (!isset($item['disabled'])) $item['disabled'] = '';
# Комментарий
$item['comment'] = isset($item['comment']) ? ' '.$item['comment'] : '';
# Стили
$item['style'] = isset($item['style']) ? explode(';', $item['style']) : array();
# Классы
$item['class'] = isset($item['class']) ? explode(' ', $item['class']) : array();
# Дополнительно
if (!isset($item['extra'])) $item['extra'] = '';
} | [
"function",
"field_prep",
"(",
"&",
"$",
"item",
")",
"{",
"$",
"item",
"[",
"'type'",
"]",
"=",
"strtolower",
"(",
"$",
"item",
"[",
"'type'",
"]",
")",
";",
"# Метка",
"if",
"(",
"!",
"isset",
"(",
"$",
"item",
"[",
"'label'",
"]",
")",
")",
"$",
"item",
"[",
"'label'",
"]",
"=",
"''",
";",
"# Подсказка",
"if",
"(",
"isset",
"(",
"$",
"item",
"[",
"'hint'",
"]",
")",
")",
"$",
"item",
"[",
"'label'",
"]",
"=",
"'<span class=\"hint\" title=\"'",
".",
"$",
"item",
"[",
"'hint'",
"]",
".",
"'\">'",
".",
"$",
"item",
"[",
"'label'",
"]",
".",
"'</span>'",
";",
"# Маска значения",
"if",
"(",
"isset",
"(",
"$",
"item",
"[",
"'pattern'",
"]",
")",
"&&",
"isset",
"(",
"$",
"item",
"[",
"'name'",
"]",
")",
")",
"$",
"this",
"->",
"validator",
".=",
"\"\n\t\t\t\tif (!form.\"",
".",
"$",
"item",
"[",
"'name'",
"]",
".",
"\".value.match(\"",
".",
"$",
"item",
"[",
"'pattern'",
"]",
".",
"\")) {\n\t\t\t\t\talert('\"",
".",
"(",
"isset",
"(",
"$",
"item",
"[",
"'errormsg'",
"]",
")",
"?",
"$",
"item",
"[",
"'errormsg'",
"]",
":",
"sprintf",
"(",
"errFormPatternError",
",",
"$",
"item",
"[",
"'name'",
"]",
",",
"$",
"item",
"[",
"'pattern'",
"]",
")",
")",
".",
"\"');\n\t\t\t\t\tresult = false;\n\t\t\t\t\tform.\"",
".",
"$",
"item",
"[",
"'name'",
"]",
".",
"\".select();\n\t\t\t\t} else \"",
";",
"# Значение",
"$",
"item",
"[",
"'value'",
"]",
"=",
"isset",
"(",
"$",
"item",
"[",
"'value'",
"]",
")",
"?",
"$",
"item",
"[",
"'value'",
"]",
":",
"(",
"isset",
"(",
"$",
"item",
"[",
"'name'",
"]",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"values",
"[",
"$",
"item",
"[",
"'name'",
"]",
"]",
")",
"?",
"$",
"this",
"->",
"values",
"[",
"$",
"item",
"[",
"'name'",
"]",
"]",
":",
"(",
"isset",
"(",
"$",
"item",
"[",
"'default'",
"]",
")",
"?",
"$",
"item",
"[",
"'default'",
"]",
":",
"''",
")",
")",
";",
"# ID",
"if",
"(",
"!",
"isset",
"(",
"$",
"item",
"[",
"'id'",
"]",
")",
")",
"$",
"item",
"[",
"'id'",
"]",
"=",
"''",
";",
"# Элемент отключен",
"if",
"(",
"!",
"isset",
"(",
"$",
"item",
"[",
"'disabled'",
"]",
")",
")",
"$",
"item",
"[",
"'disabled'",
"]",
"=",
"''",
";",
"# Комментарий",
"$",
"item",
"[",
"'comment'",
"]",
"=",
"isset",
"(",
"$",
"item",
"[",
"'comment'",
"]",
")",
"?",
"' '",
".",
"$",
"item",
"[",
"'comment'",
"]",
":",
"''",
";",
"# Стили",
"$",
"item",
"[",
"'style'",
"]",
"=",
"isset",
"(",
"$",
"item",
"[",
"'style'",
"]",
")",
"?",
"explode",
"(",
"';'",
",",
"$",
"item",
"[",
"'style'",
"]",
")",
":",
"array",
"(",
")",
";",
"# Классы",
"$",
"item",
"[",
"'class'",
"]",
"=",
"isset",
"(",
"$",
"item",
"[",
"'class'",
"]",
")",
"?",
"explode",
"(",
"' '",
",",
"$",
"item",
"[",
"'class'",
"]",
")",
":",
"array",
"(",
")",
";",
"# Дополнительно",
"if",
"(",
"!",
"isset",
"(",
"$",
"item",
"[",
"'extra'",
"]",
")",
")",
"$",
"item",
"[",
"'extra'",
"]",
"=",
"''",
";",
"}"
] | Подготоваливает поле формы для дальнейшей обработки
@access private
@param &array $item Описание поле | [
"Подготоваливает",
"поле",
"формы",
"для",
"дальнейшей",
"обработки"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/lib/forms.php#L65-L98 |
Eresus/EresusCMS | src/core/lib/forms.php | Form.attrs | function attrs($item)
{
$result = '';
if ($item['id']) $result .= ' id="'.$item['id'].'"';
if ($item['disabled']) $result .= ' disabled="disabled"';
if (count($item['class'])) $result .= ' class="'.implode(' ', $item['class']).'"';
# Ширина
if (isset($item['width'])) $item['style'][] = 'width: '.$item['width'];
# Стили
if (count($item['style'])) $result .= ' style="'.implode(';', $item['style']).'"';
$result .= ' '.$item['extra'];
return $result;
} | php | function attrs($item)
{
$result = '';
if ($item['id']) $result .= ' id="'.$item['id'].'"';
if ($item['disabled']) $result .= ' disabled="disabled"';
if (count($item['class'])) $result .= ' class="'.implode(' ', $item['class']).'"';
# Ширина
if (isset($item['width'])) $item['style'][] = 'width: '.$item['width'];
# Стили
if (count($item['style'])) $result .= ' style="'.implode(';', $item['style']).'"';
$result .= ' '.$item['extra'];
return $result;
} | [
"function",
"attrs",
"(",
"$",
"item",
")",
"{",
"$",
"result",
"=",
"''",
";",
"if",
"(",
"$",
"item",
"[",
"'id'",
"]",
")",
"$",
"result",
".=",
"' id=\"'",
".",
"$",
"item",
"[",
"'id'",
"]",
".",
"'\"'",
";",
"if",
"(",
"$",
"item",
"[",
"'disabled'",
"]",
")",
"$",
"result",
".=",
"' disabled=\"disabled\"'",
";",
"if",
"(",
"count",
"(",
"$",
"item",
"[",
"'class'",
"]",
")",
")",
"$",
"result",
".=",
"' class=\"'",
".",
"implode",
"(",
"' '",
",",
"$",
"item",
"[",
"'class'",
"]",
")",
".",
"'\"'",
";",
"# Ширина",
"if",
"(",
"isset",
"(",
"$",
"item",
"[",
"'width'",
"]",
")",
")",
"$",
"item",
"[",
"'style'",
"]",
"[",
"]",
"=",
"'width: '",
".",
"$",
"item",
"[",
"'width'",
"]",
";",
"# Стили",
"if",
"(",
"count",
"(",
"$",
"item",
"[",
"'style'",
"]",
")",
")",
"$",
"result",
".=",
"' style=\"'",
".",
"implode",
"(",
"';'",
",",
"$",
"item",
"[",
"'style'",
"]",
")",
".",
"'\"'",
";",
"$",
"result",
".=",
"' '",
".",
"$",
"item",
"[",
"'extra'",
"]",
";",
"return",
"$",
"result",
";",
"}"
] | Отрисовывает атрибуты элемента
@access private
@param array $item Элемент
@return string Отрисованные атрибуты | [
"Отрисовывает",
"атрибуты",
"элемента"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/lib/forms.php#L109-L121 |
Eresus/EresusCMS | src/core/lib/forms.php | Form.render_hidden | function render_hidden($item)
{
if ($item['name'] === '')
{
Eresus_Kernel::app()->getPage()->addErrorMessage(
sprintf(errFormFieldHasNoName, $item['type'], $this->form['name']));
}
$this->hidden .= '<input type="hidden" name="'.$item['name'].'" value="'.$item['value'].'" />'."\n";
return '';
} | php | function render_hidden($item)
{
if ($item['name'] === '')
{
Eresus_Kernel::app()->getPage()->addErrorMessage(
sprintf(errFormFieldHasNoName, $item['type'], $this->form['name']));
}
$this->hidden .= '<input type="hidden" name="'.$item['name'].'" value="'.$item['value'].'" />'."\n";
return '';
} | [
"function",
"render_hidden",
"(",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"[",
"'name'",
"]",
"===",
"''",
")",
"{",
"Eresus_Kernel",
"::",
"app",
"(",
")",
"->",
"getPage",
"(",
")",
"->",
"addErrorMessage",
"(",
"sprintf",
"(",
"errFormFieldHasNoName",
",",
"$",
"item",
"[",
"'type'",
"]",
",",
"$",
"this",
"->",
"form",
"[",
"'name'",
"]",
")",
")",
";",
"}",
"$",
"this",
"->",
"hidden",
".=",
"'<input type=\"hidden\" name=\"'",
".",
"$",
"item",
"[",
"'name'",
"]",
".",
"'\" value=\"'",
".",
"$",
"item",
"[",
"'value'",
"]",
".",
"'\" />'",
".",
"\"\\n\"",
";",
"return",
"''",
";",
"}"
] | <input type="hidden" />
@access protected
@param array $item Описание поля
@return string Отрисованное поле | [
"<input",
"type",
"=",
"hidden",
"/",
">"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/lib/forms.php#L177-L186 |
Eresus/EresusCMS | src/core/lib/forms.php | Form.render_edit | function render_edit($item)
{
if ($item['name'] === '')
{
Eresus_Kernel::app()->getPage()->addErrorMessage(
sprintf(errFormFieldHasNoName, $item['type'], $this->form['name']));
}
$result = "\t\t".'<tr><td class="formLabel">'.$item['label'].'</td><td><input type="text" name="'.$item['name'].'" value="'.EncodeHTML($item['value']).'"'.(empty($item['maxlength'])?'':' maxlength="'.$item['maxlength'].'"').$this->attrs($item).' />'.$item['comment']."</td></tr>\n";
return $result;
} | php | function render_edit($item)
{
if ($item['name'] === '')
{
Eresus_Kernel::app()->getPage()->addErrorMessage(
sprintf(errFormFieldHasNoName, $item['type'], $this->form['name']));
}
$result = "\t\t".'<tr><td class="formLabel">'.$item['label'].'</td><td><input type="text" name="'.$item['name'].'" value="'.EncodeHTML($item['value']).'"'.(empty($item['maxlength'])?'':' maxlength="'.$item['maxlength'].'"').$this->attrs($item).' />'.$item['comment']."</td></tr>\n";
return $result;
} | [
"function",
"render_edit",
"(",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"[",
"'name'",
"]",
"===",
"''",
")",
"{",
"Eresus_Kernel",
"::",
"app",
"(",
")",
"->",
"getPage",
"(",
")",
"->",
"addErrorMessage",
"(",
"sprintf",
"(",
"errFormFieldHasNoName",
",",
"$",
"item",
"[",
"'type'",
"]",
",",
"$",
"this",
"->",
"form",
"[",
"'name'",
"]",
")",
")",
";",
"}",
"$",
"result",
"=",
"\"\\t\\t\"",
".",
"'<tr><td class=\"formLabel\">'",
".",
"$",
"item",
"[",
"'label'",
"]",
".",
"'</td><td><input type=\"text\" name=\"'",
".",
"$",
"item",
"[",
"'name'",
"]",
".",
"'\" value=\"'",
".",
"EncodeHTML",
"(",
"$",
"item",
"[",
"'value'",
"]",
")",
".",
"'\"'",
".",
"(",
"empty",
"(",
"$",
"item",
"[",
"'maxlength'",
"]",
")",
"?",
"''",
":",
"' maxlength=\"'",
".",
"$",
"item",
"[",
"'maxlength'",
"]",
".",
"'\"'",
")",
".",
"$",
"this",
"->",
"attrs",
"(",
"$",
"item",
")",
".",
"' />'",
".",
"$",
"item",
"[",
"'comment'",
"]",
".",
"\"</td></tr>\\n\"",
";",
"return",
"$",
"result",
";",
"}"
] | <input type="text" />
@access protected
@param array $item Описание поля
@return string Отрисованное поле | [
"<input",
"type",
"=",
"text",
"/",
">"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/lib/forms.php#L197-L206 |
Eresus/EresusCMS | src/core/lib/forms.php | Form.render_password | function render_password($item)
{
if ($item['name'] === '')
{
Eresus_Kernel::app()->getPage()->addErrorMessage(
sprintf(errFormFieldHasNoName, $item['type'], $this->form['name']));
}
$result = "\t\t".'<tr><td class="formLabel">'.$item['label'].'</td><td><input type="password" name="'.$item['name'].'" value="'.EncodeHTML($item['value']).'"'.(empty($item['maxlength'])?'':' maxlength="'.$item['maxlength'].'"').$this->attrs($item).' />'.$item['comment']."</td></tr>\n";
if (isset($item['equal'])) $this->validator .= "if (form.".$item['name'].".value != form.".$item['equal'].".value) {\nalert('".errFormBadConfirm."');\nresult = false;\nform.".$item['name'].".value = '';\nform.".$item['equal'].".value = ''\nform.".$item['equal'].".select();\n} else ";
return $result;
} | php | function render_password($item)
{
if ($item['name'] === '')
{
Eresus_Kernel::app()->getPage()->addErrorMessage(
sprintf(errFormFieldHasNoName, $item['type'], $this->form['name']));
}
$result = "\t\t".'<tr><td class="formLabel">'.$item['label'].'</td><td><input type="password" name="'.$item['name'].'" value="'.EncodeHTML($item['value']).'"'.(empty($item['maxlength'])?'':' maxlength="'.$item['maxlength'].'"').$this->attrs($item).' />'.$item['comment']."</td></tr>\n";
if (isset($item['equal'])) $this->validator .= "if (form.".$item['name'].".value != form.".$item['equal'].".value) {\nalert('".errFormBadConfirm."');\nresult = false;\nform.".$item['name'].".value = '';\nform.".$item['equal'].".value = ''\nform.".$item['equal'].".select();\n} else ";
return $result;
} | [
"function",
"render_password",
"(",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"[",
"'name'",
"]",
"===",
"''",
")",
"{",
"Eresus_Kernel",
"::",
"app",
"(",
")",
"->",
"getPage",
"(",
")",
"->",
"addErrorMessage",
"(",
"sprintf",
"(",
"errFormFieldHasNoName",
",",
"$",
"item",
"[",
"'type'",
"]",
",",
"$",
"this",
"->",
"form",
"[",
"'name'",
"]",
")",
")",
";",
"}",
"$",
"result",
"=",
"\"\\t\\t\"",
".",
"'<tr><td class=\"formLabel\">'",
".",
"$",
"item",
"[",
"'label'",
"]",
".",
"'</td><td><input type=\"password\" name=\"'",
".",
"$",
"item",
"[",
"'name'",
"]",
".",
"'\" value=\"'",
".",
"EncodeHTML",
"(",
"$",
"item",
"[",
"'value'",
"]",
")",
".",
"'\"'",
".",
"(",
"empty",
"(",
"$",
"item",
"[",
"'maxlength'",
"]",
")",
"?",
"''",
":",
"' maxlength=\"'",
".",
"$",
"item",
"[",
"'maxlength'",
"]",
".",
"'\"'",
")",
".",
"$",
"this",
"->",
"attrs",
"(",
"$",
"item",
")",
".",
"' />'",
".",
"$",
"item",
"[",
"'comment'",
"]",
".",
"\"</td></tr>\\n\"",
";",
"if",
"(",
"isset",
"(",
"$",
"item",
"[",
"'equal'",
"]",
")",
")",
"$",
"this",
"->",
"validator",
".=",
"\"if (form.\"",
".",
"$",
"item",
"[",
"'name'",
"]",
".",
"\".value != form.\"",
".",
"$",
"item",
"[",
"'equal'",
"]",
".",
"\".value) {\\nalert('\"",
".",
"errFormBadConfirm",
".",
"\"');\\nresult = false;\\nform.\"",
".",
"$",
"item",
"[",
"'name'",
"]",
".",
"\".value = '';\\nform.\"",
".",
"$",
"item",
"[",
"'equal'",
"]",
".",
"\".value = ''\\nform.\"",
".",
"$",
"item",
"[",
"'equal'",
"]",
".",
"\".select();\\n} else \"",
";",
"return",
"$",
"result",
";",
"}"
] | <input type="password" />
@access protected
@param array $item Описание поля
@return string Отрисованное поле | [
"<input",
"type",
"=",
"password",
"/",
">"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/lib/forms.php#L217-L227 |
Eresus/EresusCMS | src/core/lib/forms.php | Form.render_select | function render_select($item)
{
if ($item['name'] === '')
{
Eresus_Kernel::app()->getPage()->addErrorMessage(
sprintf(errFormFieldHasNoName, $item['type'], $this->form['name']));
}
$result = "\t\t".'<tr><td class="formLabel">'.$item['label'].'</td><td><select name="'.$item['name'].'"'.$this->attrs($item).'>'."\n";
if (!isset($item['items']) && isset($item['values'])) $item['items'] = $item['values'];
for($i = 0; $i< count($item['items']); $i++) {
if (isset($item['values'])) $value = $item['values'][$i]; else $value = $i;
$result .= '<option value="'.$value.'" '.($value == (isset($this->values[$item['name']]) ? $this->values[$item['name']] : (isset($item['value'])?$item['value']:'')) ? 'selected = "selected"' : '').">".$item['items'][$i]."</option>\n";
}
$result .= '</select>'.$item['comment']."</td></tr>\n";
return $result;
} | php | function render_select($item)
{
if ($item['name'] === '')
{
Eresus_Kernel::app()->getPage()->addErrorMessage(
sprintf(errFormFieldHasNoName, $item['type'], $this->form['name']));
}
$result = "\t\t".'<tr><td class="formLabel">'.$item['label'].'</td><td><select name="'.$item['name'].'"'.$this->attrs($item).'>'."\n";
if (!isset($item['items']) && isset($item['values'])) $item['items'] = $item['values'];
for($i = 0; $i< count($item['items']); $i++) {
if (isset($item['values'])) $value = $item['values'][$i]; else $value = $i;
$result .= '<option value="'.$value.'" '.($value == (isset($this->values[$item['name']]) ? $this->values[$item['name']] : (isset($item['value'])?$item['value']:'')) ? 'selected = "selected"' : '').">".$item['items'][$i]."</option>\n";
}
$result .= '</select>'.$item['comment']."</td></tr>\n";
return $result;
} | [
"function",
"render_select",
"(",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"[",
"'name'",
"]",
"===",
"''",
")",
"{",
"Eresus_Kernel",
"::",
"app",
"(",
")",
"->",
"getPage",
"(",
")",
"->",
"addErrorMessage",
"(",
"sprintf",
"(",
"errFormFieldHasNoName",
",",
"$",
"item",
"[",
"'type'",
"]",
",",
"$",
"this",
"->",
"form",
"[",
"'name'",
"]",
")",
")",
";",
"}",
"$",
"result",
"=",
"\"\\t\\t\"",
".",
"'<tr><td class=\"formLabel\">'",
".",
"$",
"item",
"[",
"'label'",
"]",
".",
"'</td><td><select name=\"'",
".",
"$",
"item",
"[",
"'name'",
"]",
".",
"'\"'",
".",
"$",
"this",
"->",
"attrs",
"(",
"$",
"item",
")",
".",
"'>'",
".",
"\"\\n\"",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"item",
"[",
"'items'",
"]",
")",
"&&",
"isset",
"(",
"$",
"item",
"[",
"'values'",
"]",
")",
")",
"$",
"item",
"[",
"'items'",
"]",
"=",
"$",
"item",
"[",
"'values'",
"]",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"item",
"[",
"'items'",
"]",
")",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"item",
"[",
"'values'",
"]",
")",
")",
"$",
"value",
"=",
"$",
"item",
"[",
"'values'",
"]",
"[",
"$",
"i",
"]",
";",
"else",
"$",
"value",
"=",
"$",
"i",
";",
"$",
"result",
".=",
"'<option value=\"'",
".",
"$",
"value",
".",
"'\" '",
".",
"(",
"$",
"value",
"==",
"(",
"isset",
"(",
"$",
"this",
"->",
"values",
"[",
"$",
"item",
"[",
"'name'",
"]",
"]",
")",
"?",
"$",
"this",
"->",
"values",
"[",
"$",
"item",
"[",
"'name'",
"]",
"]",
":",
"(",
"isset",
"(",
"$",
"item",
"[",
"'value'",
"]",
")",
"?",
"$",
"item",
"[",
"'value'",
"]",
":",
"''",
")",
")",
"?",
"'selected = \"selected\"'",
":",
"''",
")",
".",
"\">\"",
".",
"$",
"item",
"[",
"'items'",
"]",
"[",
"$",
"i",
"]",
".",
"\"</option>\\n\"",
";",
"}",
"$",
"result",
".=",
"'</select>'",
".",
"$",
"item",
"[",
"'comment'",
"]",
".",
"\"</td></tr>\\n\"",
";",
"return",
"$",
"result",
";",
"}"
] | <select>
@access protected
@param array $item Описание поля
@return string Отрисованное поле | [
"<select",
">"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/lib/forms.php#L258-L273 |
Eresus/EresusCMS | src/core/lib/forms.php | Form.render_memo | function render_memo($item)
{
if ($item['name'] === '')
{
Eresus_Kernel::app()->getPage()->addErrorMessage(
sprintf(errFormFieldHasNoName, $item['type'], $this->form['name']));
}
if (empty($item['width'])) $item['width'] = '100%';
if (strpos($item['width'], '%') === false) {
$cols = $item['width'];
$item['width'] = '';
} else $cols = '50';
if (isset($item['syntax'])) {
$extension = Eresus_CMS::getLegacyKernel()->extensions->load(
'forms',
'memo_syntax',
isset($item['syntax_extension']) ? $item['syntax_extension'] : null
);
if ($extension) $item = $extension->forms_memo_syntax($this, $item);
}
$result = "\t\t".'<tr><td colspan="2">'.(empty($item['label'])?'':'<span class="formLabel">'.$item['label'].'</span><br />').'<textarea name="'.$item['name'].'" cols="'.$cols.'" rows="'.(empty($item['height'])?'3':$item['height']).'" '.$this->attrs($item).'>'.EncodeHTML($item['value'])."</textarea></td></tr>\n";
return $result;
} | php | function render_memo($item)
{
if ($item['name'] === '')
{
Eresus_Kernel::app()->getPage()->addErrorMessage(
sprintf(errFormFieldHasNoName, $item['type'], $this->form['name']));
}
if (empty($item['width'])) $item['width'] = '100%';
if (strpos($item['width'], '%') === false) {
$cols = $item['width'];
$item['width'] = '';
} else $cols = '50';
if (isset($item['syntax'])) {
$extension = Eresus_CMS::getLegacyKernel()->extensions->load(
'forms',
'memo_syntax',
isset($item['syntax_extension']) ? $item['syntax_extension'] : null
);
if ($extension) $item = $extension->forms_memo_syntax($this, $item);
}
$result = "\t\t".'<tr><td colspan="2">'.(empty($item['label'])?'':'<span class="formLabel">'.$item['label'].'</span><br />').'<textarea name="'.$item['name'].'" cols="'.$cols.'" rows="'.(empty($item['height'])?'3':$item['height']).'" '.$this->attrs($item).'>'.EncodeHTML($item['value'])."</textarea></td></tr>\n";
return $result;
} | [
"function",
"render_memo",
"(",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"[",
"'name'",
"]",
"===",
"''",
")",
"{",
"Eresus_Kernel",
"::",
"app",
"(",
")",
"->",
"getPage",
"(",
")",
"->",
"addErrorMessage",
"(",
"sprintf",
"(",
"errFormFieldHasNoName",
",",
"$",
"item",
"[",
"'type'",
"]",
",",
"$",
"this",
"->",
"form",
"[",
"'name'",
"]",
")",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"item",
"[",
"'width'",
"]",
")",
")",
"$",
"item",
"[",
"'width'",
"]",
"=",
"'100%'",
";",
"if",
"(",
"strpos",
"(",
"$",
"item",
"[",
"'width'",
"]",
",",
"'%'",
")",
"===",
"false",
")",
"{",
"$",
"cols",
"=",
"$",
"item",
"[",
"'width'",
"]",
";",
"$",
"item",
"[",
"'width'",
"]",
"=",
"''",
";",
"}",
"else",
"$",
"cols",
"=",
"'50'",
";",
"if",
"(",
"isset",
"(",
"$",
"item",
"[",
"'syntax'",
"]",
")",
")",
"{",
"$",
"extension",
"=",
"Eresus_CMS",
"::",
"getLegacyKernel",
"(",
")",
"->",
"extensions",
"->",
"load",
"(",
"'forms'",
",",
"'memo_syntax'",
",",
"isset",
"(",
"$",
"item",
"[",
"'syntax_extension'",
"]",
")",
"?",
"$",
"item",
"[",
"'syntax_extension'",
"]",
":",
"null",
")",
";",
"if",
"(",
"$",
"extension",
")",
"$",
"item",
"=",
"$",
"extension",
"->",
"forms_memo_syntax",
"(",
"$",
"this",
",",
"$",
"item",
")",
";",
"}",
"$",
"result",
"=",
"\"\\t\\t\"",
".",
"'<tr><td colspan=\"2\">'",
".",
"(",
"empty",
"(",
"$",
"item",
"[",
"'label'",
"]",
")",
"?",
"''",
":",
"'<span class=\"formLabel\">'",
".",
"$",
"item",
"[",
"'label'",
"]",
".",
"'</span><br />'",
")",
".",
"'<textarea name=\"'",
".",
"$",
"item",
"[",
"'name'",
"]",
".",
"'\" cols=\"'",
".",
"$",
"cols",
".",
"'\" rows=\"'",
".",
"(",
"empty",
"(",
"$",
"item",
"[",
"'height'",
"]",
")",
"?",
"'3'",
":",
"$",
"item",
"[",
"'height'",
"]",
")",
".",
"'\" '",
".",
"$",
"this",
"->",
"attrs",
"(",
"$",
"item",
")",
".",
"'>'",
".",
"EncodeHTML",
"(",
"$",
"item",
"[",
"'value'",
"]",
")",
".",
"\"</textarea></td></tr>\\n\"",
";",
"return",
"$",
"result",
";",
"}"
] | <textarea></textarea>
@access protected
@param array $item Описание поля
@return string Отрисованное поле | [
"<textarea",
">",
"<",
"/",
"textarea",
">"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/lib/forms.php#L310-L332 |
Eresus/EresusCMS | src/core/lib/forms.php | Form.render_html | function render_html($item)
{
if ($item['name'] === '')
{
Eresus_Kernel::app()->getPage()->addErrorMessage(
sprintf(errFormFieldHasNoName, $item['type'], $this->form['name']));
}
$result = '';
$extension = Eresus_CMS::getLegacyKernel()->extensions->load(
'forms',
'html',
isset($item['html_extension']) ? $item['html_extension'] : null
);
if ($extension) $result = $extension->forms_html($this, $item);
return $result;
} | php | function render_html($item)
{
if ($item['name'] === '')
{
Eresus_Kernel::app()->getPage()->addErrorMessage(
sprintf(errFormFieldHasNoName, $item['type'], $this->form['name']));
}
$result = '';
$extension = Eresus_CMS::getLegacyKernel()->extensions->load(
'forms',
'html',
isset($item['html_extension']) ? $item['html_extension'] : null
);
if ($extension) $result = $extension->forms_html($this, $item);
return $result;
} | [
"function",
"render_html",
"(",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"[",
"'name'",
"]",
"===",
"''",
")",
"{",
"Eresus_Kernel",
"::",
"app",
"(",
")",
"->",
"getPage",
"(",
")",
"->",
"addErrorMessage",
"(",
"sprintf",
"(",
"errFormFieldHasNoName",
",",
"$",
"item",
"[",
"'type'",
"]",
",",
"$",
"this",
"->",
"form",
"[",
"'name'",
"]",
")",
")",
";",
"}",
"$",
"result",
"=",
"''",
";",
"$",
"extension",
"=",
"Eresus_CMS",
"::",
"getLegacyKernel",
"(",
")",
"->",
"extensions",
"->",
"load",
"(",
"'forms'",
",",
"'html'",
",",
"isset",
"(",
"$",
"item",
"[",
"'html_extension'",
"]",
")",
"?",
"$",
"item",
"[",
"'html_extension'",
"]",
":",
"null",
")",
";",
"if",
"(",
"$",
"extension",
")",
"$",
"result",
"=",
"$",
"extension",
"->",
"forms_html",
"(",
"$",
"this",
",",
"$",
"item",
")",
";",
"return",
"$",
"result",
";",
"}"
] | <textarea html>
@access protected
@param array $item Описание поля
@return string Отрисованное поле | [
"<textarea",
"html",
">"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/lib/forms.php#L343-L360 |
Eresus/EresusCMS | src/core/lib/forms.php | Form.render_file | function render_file($item)
{
if ($item['name'] === '')
{
Eresus_Kernel::app()->getPage()->addErrorMessage(
sprintf(errFormFieldHasNoName, $item['type'], $this->form['name']));
}
$result = "\t\t".'<tr><td class="formLabel">'.$item['label']."</td><td><input type=\"file\" name=\"".$item['name']."\"".(isset($item['width']) ? ' size="'.$item['width'].'"':'').$this->attrs($item)." />".$item['comment']."</td></tr>\n";
$this->file = true;
return $result;
} | php | function render_file($item)
{
if ($item['name'] === '')
{
Eresus_Kernel::app()->getPage()->addErrorMessage(
sprintf(errFormFieldHasNoName, $item['type'], $this->form['name']));
}
$result = "\t\t".'<tr><td class="formLabel">'.$item['label']."</td><td><input type=\"file\" name=\"".$item['name']."\"".(isset($item['width']) ? ' size="'.$item['width'].'"':'').$this->attrs($item)." />".$item['comment']."</td></tr>\n";
$this->file = true;
return $result;
} | [
"function",
"render_file",
"(",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"[",
"'name'",
"]",
"===",
"''",
")",
"{",
"Eresus_Kernel",
"::",
"app",
"(",
")",
"->",
"getPage",
"(",
")",
"->",
"addErrorMessage",
"(",
"sprintf",
"(",
"errFormFieldHasNoName",
",",
"$",
"item",
"[",
"'type'",
"]",
",",
"$",
"this",
"->",
"form",
"[",
"'name'",
"]",
")",
")",
";",
"}",
"$",
"result",
"=",
"\"\\t\\t\"",
".",
"'<tr><td class=\"formLabel\">'",
".",
"$",
"item",
"[",
"'label'",
"]",
".",
"\"</td><td><input type=\\\"file\\\" name=\\\"\"",
".",
"$",
"item",
"[",
"'name'",
"]",
".",
"\"\\\"\"",
".",
"(",
"isset",
"(",
"$",
"item",
"[",
"'width'",
"]",
")",
"?",
"' size=\"'",
".",
"$",
"item",
"[",
"'width'",
"]",
".",
"'\"'",
":",
"''",
")",
".",
"$",
"this",
"->",
"attrs",
"(",
"$",
"item",
")",
".",
"\" />\"",
".",
"$",
"item",
"[",
"'comment'",
"]",
".",
"\"</td></tr>\\n\"",
";",
"$",
"this",
"->",
"file",
"=",
"true",
";",
"return",
"$",
"result",
";",
"}"
] | <input type="file" />
@access protected
@param array $item Описание поля
@return string Отрисованное поле | [
"<input",
"type",
"=",
"file",
"/",
">"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/lib/forms.php#L371-L381 |
Eresus/EresusCMS | src/core/lib/forms.php | Form.render | function render()
{
$result = ''; # Выходной код
if (empty($this->form['name'])) $result .= ErrorBox(errFormHasNoName);
if (count($this->form['fields'])) foreach($this->form['fields'] as $item) {
# Проверяем права доступа к элементу
if ((!isset($item['access'])) || (UserRights($item['access']))) {
$this->field_prep($item);
$control = 'render_'.$item['type'];
#if (method_exists($this, $control)) $result .= call_user_func(array($this, $control), $item);
if (method_exists($this, $control)) {
$result .= $this->$control($item);
}
else
{
Eresus_Kernel::app()->getPage()->addErrorMessage(
sprintf(errFormUnknownType, $item['type'], $this->form['name']));
}
}
}
$this->onsubmit .= $this->validator;
if (!empty($this->onsubmit))
{
Eresus_Kernel::app()->getPage()->addScripts("
function ".$this->form['name']."Submit()
{
var result = true;
var form = document.forms.namedItem('".$this->form['name']."');
".$this->onsubmit.";
return result;
}
");
}
# FIXME: sub_id - устаревший элемент
$referer = arg('sub_id') ?
Eresus_Kernel::app()->getPage()->url(array('sub_id'=>'')) :
Eresus_Kernel::app()->getPage()->url(array('id'=>''));
$this->hidden .= "\t\t".'<input type="hidden" name="submitURL" value="'.$referer.'" />';
$this->hidden = "\t<div class=\"hidden\">\n\t\t{$this->hidden}\n\t</div>";
$result =
"<form ".(empty($this->form['name'])?'':'name="'.$this->form['name'].'" id="'.$this->form['name'].'" ')."action=\"".
Eresus_Kernel::app()->getPage()->url()."\" method=\"post\"".(empty($this->onsubmit)?'':' onsubmit="return '.$this->form['name'].'Submit();"').($this->file?' enctype="multipart/form-data"':'').">\n".
$this->hidden.
"\n\t<table width=\"100%\">\n".
"\t\t<tr><td style=\"height: 0px; font-size: 0px; padding: 0px;\">".img('style/dot.gif')."</td><td style=\"width: 100%; height: 0px; font-size: 0px; padding: 0px;\">".img('style/dot.gif')."</td>\n\t\t</tr>\n".
$result.
"\t\t<tr><td colspan=\"2\" class=\"ui-button-box\"><br />".
((isset($this->form['buttons']) && isset($this->form['buttons']['ok']))?'<button name="form_ok" type="submit">'.$this->form['buttons']['ok'].'</button> ':'').
(!isset($this->form['buttons']) || in_array('ok', $this->form['buttons'])?"<button name=\"form_ok\" type=\"submit\">".strOk."</button> ":'').
((isset($this->form['buttons']) && isset($this->form['buttons']['apply']))?'<button name="form_apply" type="submit" onclick="formApplyClick(\''.$this->form['name'].'\')">'.$this->form['buttons']['apply']."</button> ":'').
(!isset($this->form['buttons']) || in_array('apply', $this->form['buttons'])?"<button name=\"form_apply\" type=\"submit\" onclick=\"formApplyClick('".$this->form['name']."')\">" . strApply . '</button> ':'').
((isset($this->form['buttons']) && isset($this->form['buttons']['reset']))?'<button name="form_reset" type="reset">'.$this->form['buttons']['reset'].'</button> ':'').
(isset($this->form['buttons']) && in_array('reset', $this->form['buttons'])?"<button name=\"form_reset\" type=\"reset\">".strReset."</button> ":'').
((isset($this->form['buttons']) && isset($this->form['buttons']['cancel']) && (!is_array($this->form['buttons']['cancel'])))?'<input name="form_cancel" type="button" onclick="javascript:history.back();">' . $this->form['buttons']['cancel'] . '</button>' : '').
((!isset($this->form['buttons']) || (in_array('cancel', $this->form['buttons'])))?"<button name=\"form_cancel\" type=\"button\" onclick=\"javascript:history.back();\">".strCancel . '</button>' :'').
((isset($this->form['buttons']['cancel']) && (is_array($this->form['buttons']['cancel'])))?"<button name=\"form_cancel\" type=\"button\" onclick=\"window.location.href='".$this->form['buttons']['cancel']['url']."'\">" . $this->form['buttons']['cancel']['label'] . '</button>':'').
"</td>\n\t\t</tr>\n".
"\t</table>\n</form>\n";
return $result;
} | php | function render()
{
$result = ''; # Выходной код
if (empty($this->form['name'])) $result .= ErrorBox(errFormHasNoName);
if (count($this->form['fields'])) foreach($this->form['fields'] as $item) {
# Проверяем права доступа к элементу
if ((!isset($item['access'])) || (UserRights($item['access']))) {
$this->field_prep($item);
$control = 'render_'.$item['type'];
#if (method_exists($this, $control)) $result .= call_user_func(array($this, $control), $item);
if (method_exists($this, $control)) {
$result .= $this->$control($item);
}
else
{
Eresus_Kernel::app()->getPage()->addErrorMessage(
sprintf(errFormUnknownType, $item['type'], $this->form['name']));
}
}
}
$this->onsubmit .= $this->validator;
if (!empty($this->onsubmit))
{
Eresus_Kernel::app()->getPage()->addScripts("
function ".$this->form['name']."Submit()
{
var result = true;
var form = document.forms.namedItem('".$this->form['name']."');
".$this->onsubmit.";
return result;
}
");
}
# FIXME: sub_id - устаревший элемент
$referer = arg('sub_id') ?
Eresus_Kernel::app()->getPage()->url(array('sub_id'=>'')) :
Eresus_Kernel::app()->getPage()->url(array('id'=>''));
$this->hidden .= "\t\t".'<input type="hidden" name="submitURL" value="'.$referer.'" />';
$this->hidden = "\t<div class=\"hidden\">\n\t\t{$this->hidden}\n\t</div>";
$result =
"<form ".(empty($this->form['name'])?'':'name="'.$this->form['name'].'" id="'.$this->form['name'].'" ')."action=\"".
Eresus_Kernel::app()->getPage()->url()."\" method=\"post\"".(empty($this->onsubmit)?'':' onsubmit="return '.$this->form['name'].'Submit();"').($this->file?' enctype="multipart/form-data"':'').">\n".
$this->hidden.
"\n\t<table width=\"100%\">\n".
"\t\t<tr><td style=\"height: 0px; font-size: 0px; padding: 0px;\">".img('style/dot.gif')."</td><td style=\"width: 100%; height: 0px; font-size: 0px; padding: 0px;\">".img('style/dot.gif')."</td>\n\t\t</tr>\n".
$result.
"\t\t<tr><td colspan=\"2\" class=\"ui-button-box\"><br />".
((isset($this->form['buttons']) && isset($this->form['buttons']['ok']))?'<button name="form_ok" type="submit">'.$this->form['buttons']['ok'].'</button> ':'').
(!isset($this->form['buttons']) || in_array('ok', $this->form['buttons'])?"<button name=\"form_ok\" type=\"submit\">".strOk."</button> ":'').
((isset($this->form['buttons']) && isset($this->form['buttons']['apply']))?'<button name="form_apply" type="submit" onclick="formApplyClick(\''.$this->form['name'].'\')">'.$this->form['buttons']['apply']."</button> ":'').
(!isset($this->form['buttons']) || in_array('apply', $this->form['buttons'])?"<button name=\"form_apply\" type=\"submit\" onclick=\"formApplyClick('".$this->form['name']."')\">" . strApply . '</button> ':'').
((isset($this->form['buttons']) && isset($this->form['buttons']['reset']))?'<button name="form_reset" type="reset">'.$this->form['buttons']['reset'].'</button> ':'').
(isset($this->form['buttons']) && in_array('reset', $this->form['buttons'])?"<button name=\"form_reset\" type=\"reset\">".strReset."</button> ":'').
((isset($this->form['buttons']) && isset($this->form['buttons']['cancel']) && (!is_array($this->form['buttons']['cancel'])))?'<input name="form_cancel" type="button" onclick="javascript:history.back();">' . $this->form['buttons']['cancel'] . '</button>' : '').
((!isset($this->form['buttons']) || (in_array('cancel', $this->form['buttons'])))?"<button name=\"form_cancel\" type=\"button\" onclick=\"javascript:history.back();\">".strCancel . '</button>' :'').
((isset($this->form['buttons']['cancel']) && (is_array($this->form['buttons']['cancel'])))?"<button name=\"form_cancel\" type=\"button\" onclick=\"window.location.href='".$this->form['buttons']['cancel']['url']."'\">" . $this->form['buttons']['cancel']['label'] . '</button>':'').
"</td>\n\t\t</tr>\n".
"\t</table>\n</form>\n";
return $result;
} | [
"function",
"render",
"(",
")",
"{",
"$",
"result",
"=",
"''",
";",
"# Выходной код",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"form",
"[",
"'name'",
"]",
")",
")",
"$",
"result",
".=",
"ErrorBox",
"(",
"errFormHasNoName",
")",
";",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"form",
"[",
"'fields'",
"]",
")",
")",
"foreach",
"(",
"$",
"this",
"->",
"form",
"[",
"'fields'",
"]",
"as",
"$",
"item",
")",
"{",
"# Проверяем права доступа к элементу",
"if",
"(",
"(",
"!",
"isset",
"(",
"$",
"item",
"[",
"'access'",
"]",
")",
")",
"||",
"(",
"UserRights",
"(",
"$",
"item",
"[",
"'access'",
"]",
")",
")",
")",
"{",
"$",
"this",
"->",
"field_prep",
"(",
"$",
"item",
")",
";",
"$",
"control",
"=",
"'render_'",
".",
"$",
"item",
"[",
"'type'",
"]",
";",
"#if (method_exists($this, $control)) $result .= call_user_func(array($this, $control), $item);",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"control",
")",
")",
"{",
"$",
"result",
".=",
"$",
"this",
"->",
"$",
"control",
"(",
"$",
"item",
")",
";",
"}",
"else",
"{",
"Eresus_Kernel",
"::",
"app",
"(",
")",
"->",
"getPage",
"(",
")",
"->",
"addErrorMessage",
"(",
"sprintf",
"(",
"errFormUnknownType",
",",
"$",
"item",
"[",
"'type'",
"]",
",",
"$",
"this",
"->",
"form",
"[",
"'name'",
"]",
")",
")",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"onsubmit",
".=",
"$",
"this",
"->",
"validator",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"onsubmit",
")",
")",
"{",
"Eresus_Kernel",
"::",
"app",
"(",
")",
"->",
"getPage",
"(",
")",
"->",
"addScripts",
"(",
"\"\n\t\t\t\tfunction \"",
".",
"$",
"this",
"->",
"form",
"[",
"'name'",
"]",
".",
"\"Submit()\n\t\t\t\t{\n\t\t\t\t\tvar result = true;\n\t\t\t\t\tvar form = document.forms.namedItem('\"",
".",
"$",
"this",
"->",
"form",
"[",
"'name'",
"]",
".",
"\"');\n\t\t\t\t\t\"",
".",
"$",
"this",
"->",
"onsubmit",
".",
"\";\n\t\t\t\t\treturn result;\n\t\t\t\t}\n\t\t\t\"",
")",
";",
"}",
"# FIXME: sub_id - устаревший элемент",
"$",
"referer",
"=",
"arg",
"(",
"'sub_id'",
")",
"?",
"Eresus_Kernel",
"::",
"app",
"(",
")",
"->",
"getPage",
"(",
")",
"->",
"url",
"(",
"array",
"(",
"'sub_id'",
"=>",
"''",
")",
")",
":",
"Eresus_Kernel",
"::",
"app",
"(",
")",
"->",
"getPage",
"(",
")",
"->",
"url",
"(",
"array",
"(",
"'id'",
"=>",
"''",
")",
")",
";",
"$",
"this",
"->",
"hidden",
".=",
"\"\\t\\t\"",
".",
"'<input type=\"hidden\" name=\"submitURL\" value=\"'",
".",
"$",
"referer",
".",
"'\" />'",
";",
"$",
"this",
"->",
"hidden",
"=",
"\"\\t<div class=\\\"hidden\\\">\\n\\t\\t{$this->hidden}\\n\\t</div>\"",
";",
"$",
"result",
"=",
"\"<form \"",
".",
"(",
"empty",
"(",
"$",
"this",
"->",
"form",
"[",
"'name'",
"]",
")",
"?",
"''",
":",
"'name=\"'",
".",
"$",
"this",
"->",
"form",
"[",
"'name'",
"]",
".",
"'\" id=\"'",
".",
"$",
"this",
"->",
"form",
"[",
"'name'",
"]",
".",
"'\" '",
")",
".",
"\"action=\\\"\"",
".",
"Eresus_Kernel",
"::",
"app",
"(",
")",
"->",
"getPage",
"(",
")",
"->",
"url",
"(",
")",
".",
"\"\\\" method=\\\"post\\\"\"",
".",
"(",
"empty",
"(",
"$",
"this",
"->",
"onsubmit",
")",
"?",
"''",
":",
"' onsubmit=\"return '",
".",
"$",
"this",
"->",
"form",
"[",
"'name'",
"]",
".",
"'Submit();\"'",
")",
".",
"(",
"$",
"this",
"->",
"file",
"?",
"' enctype=\"multipart/form-data\"'",
":",
"''",
")",
".",
"\">\\n\"",
".",
"$",
"this",
"->",
"hidden",
".",
"\"\\n\\t<table width=\\\"100%\\\">\\n\"",
".",
"\"\\t\\t<tr><td style=\\\"height: 0px; font-size: 0px; padding: 0px;\\\">\"",
".",
"img",
"(",
"'style/dot.gif'",
")",
".",
"\"</td><td style=\\\"width: 100%; height: 0px; font-size: 0px; padding: 0px;\\\">\"",
".",
"img",
"(",
"'style/dot.gif'",
")",
".",
"\"</td>\\n\\t\\t</tr>\\n\"",
".",
"$",
"result",
".",
"\"\\t\\t<tr><td colspan=\\\"2\\\" class=\\\"ui-button-box\\\"><br />\"",
".",
"(",
"(",
"isset",
"(",
"$",
"this",
"->",
"form",
"[",
"'buttons'",
"]",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"form",
"[",
"'buttons'",
"]",
"[",
"'ok'",
"]",
")",
")",
"?",
"'<button name=\"form_ok\" type=\"submit\">'",
".",
"$",
"this",
"->",
"form",
"[",
"'buttons'",
"]",
"[",
"'ok'",
"]",
".",
"'</button> '",
":",
"''",
")",
".",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"form",
"[",
"'buttons'",
"]",
")",
"||",
"in_array",
"(",
"'ok'",
",",
"$",
"this",
"->",
"form",
"[",
"'buttons'",
"]",
")",
"?",
"\"<button name=\\\"form_ok\\\" type=\\\"submit\\\">\"",
".",
"strOk",
".",
"\"</button> \"",
":",
"''",
")",
".",
"(",
"(",
"isset",
"(",
"$",
"this",
"->",
"form",
"[",
"'buttons'",
"]",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"form",
"[",
"'buttons'",
"]",
"[",
"'apply'",
"]",
")",
")",
"?",
"'<button name=\"form_apply\" type=\"submit\" onclick=\"formApplyClick(\\''",
".",
"$",
"this",
"->",
"form",
"[",
"'name'",
"]",
".",
"'\\')\">'",
".",
"$",
"this",
"->",
"form",
"[",
"'buttons'",
"]",
"[",
"'apply'",
"]",
".",
"\"</button> \"",
":",
"''",
")",
".",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"form",
"[",
"'buttons'",
"]",
")",
"||",
"in_array",
"(",
"'apply'",
",",
"$",
"this",
"->",
"form",
"[",
"'buttons'",
"]",
")",
"?",
"\"<button name=\\\"form_apply\\\" type=\\\"submit\\\" onclick=\\\"formApplyClick('\"",
".",
"$",
"this",
"->",
"form",
"[",
"'name'",
"]",
".",
"\"')\\\">\"",
".",
"strApply",
".",
"'</button> '",
":",
"''",
")",
".",
"(",
"(",
"isset",
"(",
"$",
"this",
"->",
"form",
"[",
"'buttons'",
"]",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"form",
"[",
"'buttons'",
"]",
"[",
"'reset'",
"]",
")",
")",
"?",
"'<button name=\"form_reset\" type=\"reset\">'",
".",
"$",
"this",
"->",
"form",
"[",
"'buttons'",
"]",
"[",
"'reset'",
"]",
".",
"'</button> '",
":",
"''",
")",
".",
"(",
"isset",
"(",
"$",
"this",
"->",
"form",
"[",
"'buttons'",
"]",
")",
"&&",
"in_array",
"(",
"'reset'",
",",
"$",
"this",
"->",
"form",
"[",
"'buttons'",
"]",
")",
"?",
"\"<button name=\\\"form_reset\\\" type=\\\"reset\\\">\"",
".",
"strReset",
".",
"\"</button> \"",
":",
"''",
")",
".",
"(",
"(",
"isset",
"(",
"$",
"this",
"->",
"form",
"[",
"'buttons'",
"]",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"form",
"[",
"'buttons'",
"]",
"[",
"'cancel'",
"]",
")",
"&&",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"form",
"[",
"'buttons'",
"]",
"[",
"'cancel'",
"]",
")",
")",
")",
"?",
"'<input name=\"form_cancel\" type=\"button\" onclick=\"javascript:history.back();\">'",
".",
"$",
"this",
"->",
"form",
"[",
"'buttons'",
"]",
"[",
"'cancel'",
"]",
".",
"'</button>'",
":",
"''",
")",
".",
"(",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"form",
"[",
"'buttons'",
"]",
")",
"||",
"(",
"in_array",
"(",
"'cancel'",
",",
"$",
"this",
"->",
"form",
"[",
"'buttons'",
"]",
")",
")",
")",
"?",
"\"<button name=\\\"form_cancel\\\" type=\\\"button\\\" onclick=\\\"javascript:history.back();\\\">\"",
".",
"strCancel",
".",
"'</button>'",
":",
"''",
")",
".",
"(",
"(",
"isset",
"(",
"$",
"this",
"->",
"form",
"[",
"'buttons'",
"]",
"[",
"'cancel'",
"]",
")",
"&&",
"(",
"is_array",
"(",
"$",
"this",
"->",
"form",
"[",
"'buttons'",
"]",
"[",
"'cancel'",
"]",
")",
")",
")",
"?",
"\"<button name=\\\"form_cancel\\\" type=\\\"button\\\" onclick=\\\"window.location.href='\"",
".",
"$",
"this",
"->",
"form",
"[",
"'buttons'",
"]",
"[",
"'cancel'",
"]",
"[",
"'url'",
"]",
".",
"\"'\\\">\"",
".",
"$",
"this",
"->",
"form",
"[",
"'buttons'",
"]",
"[",
"'cancel'",
"]",
"[",
"'label'",
"]",
".",
"'</button>'",
":",
"''",
")",
".",
"\"</td>\\n\\t\\t</tr>\\n\"",
".",
"\"\\t</table>\\n</form>\\n\"",
";",
"return",
"$",
"result",
";",
"}"
] | Создание HTML-кода
@access public
@return string HTML-код формы | [
"Создание",
"HTML",
"-",
"кода"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/lib/forms.php#L412-L477 |
nabab/bbn | src/bbn/ide/directories.php | directories._ide_path | private function _ide_path(){
if ( !self::$dev_path ){
$this->_set_appui();
if ( $id = $this->options->from_code(self::IDE_PATH, BBN_APPUI) ){
self::set_ide_path($id);
}
}
return self::$ide_path;
} | php | private function _ide_path(){
if ( !self::$dev_path ){
$this->_set_appui();
if ( $id = $this->options->from_code(self::IDE_PATH, BBN_APPUI) ){
self::set_ide_path($id);
}
}
return self::$ide_path;
} | [
"private",
"function",
"_ide_path",
"(",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"dev_path",
")",
"{",
"$",
"this",
"->",
"_set_appui",
"(",
")",
";",
"if",
"(",
"$",
"id",
"=",
"$",
"this",
"->",
"options",
"->",
"from_code",
"(",
"self",
"::",
"IDE_PATH",
",",
"BBN_APPUI",
")",
")",
"{",
"self",
"::",
"set_ide_path",
"(",
"$",
"id",
")",
";",
"}",
"}",
"return",
"self",
"::",
"$",
"ide_path",
";",
"}"
] | Gets the ID of the development paths option
@return int | [
"Gets",
"the",
"ID",
"of",
"the",
"development",
"paths",
"option"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/ide/directories.php#L46-L54 |
nabab/bbn | src/bbn/ide/directories.php | directories._dev_path | private function _dev_path(){
if ( !self::$dev_path ){
if ( $id = $this->options->from_code(self::DEV_PATH, self::IDE_PATH) ){
self::set_dev_path($id);
}
}
return self::$dev_path;
} | php | private function _dev_path(){
if ( !self::$dev_path ){
if ( $id = $this->options->from_code(self::DEV_PATH, self::IDE_PATH) ){
self::set_dev_path($id);
}
}
return self::$dev_path;
} | [
"private",
"function",
"_dev_path",
"(",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"dev_path",
")",
"{",
"if",
"(",
"$",
"id",
"=",
"$",
"this",
"->",
"options",
"->",
"from_code",
"(",
"self",
"::",
"DEV_PATH",
",",
"self",
"::",
"IDE_PATH",
")",
")",
"{",
"self",
"::",
"set_dev_path",
"(",
"$",
"id",
")",
";",
"}",
"}",
"return",
"self",
"::",
"$",
"dev_path",
";",
"}"
] | Gets the ID of the development paths option
@return int | [
"Gets",
"the",
"ID",
"of",
"the",
"development",
"paths",
"option"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/ide/directories.php#L68-L75 |
nabab/bbn | src/bbn/ide/directories.php | directories._path_type | private function _path_type(){
if ( !self::$path_type ){
if ( $id = $this->options->from_code(self::PATH_TYPE, self::IDE_PATH) ){
self::set_path_type($id);
}
}
return self::$path_type;
} | php | private function _path_type(){
if ( !self::$path_type ){
if ( $id = $this->options->from_code(self::PATH_TYPE, self::IDE_PATH) ){
self::set_path_type($id);
}
}
return self::$path_type;
} | [
"private",
"function",
"_path_type",
"(",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"path_type",
")",
"{",
"if",
"(",
"$",
"id",
"=",
"$",
"this",
"->",
"options",
"->",
"from_code",
"(",
"self",
"::",
"PATH_TYPE",
",",
"self",
"::",
"IDE_PATH",
")",
")",
"{",
"self",
"::",
"set_path_type",
"(",
"$",
"id",
")",
";",
"}",
"}",
"return",
"self",
"::",
"$",
"path_type",
";",
"}"
] | Gets the ID of the paths' types option
@return int | [
"Gets",
"the",
"ID",
"of",
"the",
"paths",
"types",
"option"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/ide/directories.php#L89-L96 |
nabab/bbn | src/bbn/ide/directories.php | directories._files_pref | private function _files_pref(){
if ( !self::$files_pref ){
if ( $id = $this->options->from_code(self::FILES_PREF, self::IDE_PATH) ){
self::set_files_pref($id);
}
}
return self::$files_pref;
} | php | private function _files_pref(){
if ( !self::$files_pref ){
if ( $id = $this->options->from_code(self::FILES_PREF, self::IDE_PATH) ){
self::set_files_pref($id);
}
}
return self::$files_pref;
} | [
"private",
"function",
"_files_pref",
"(",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"files_pref",
")",
"{",
"if",
"(",
"$",
"id",
"=",
"$",
"this",
"->",
"options",
"->",
"from_code",
"(",
"self",
"::",
"FILES_PREF",
",",
"self",
"::",
"IDE_PATH",
")",
")",
"{",
"self",
"::",
"set_files_pref",
"(",
"$",
"id",
")",
";",
"}",
"}",
"return",
"self",
"::",
"$",
"files_pref",
";",
"}"
] | Gets the ID of the paths' types option
@return int | [
"Gets",
"the",
"ID",
"of",
"the",
"paths",
"types",
"option"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/ide/directories.php#L110-L117 |
nabab/bbn | src/bbn/ide/directories.php | directories.rem_dir_opt | private function rem_dir_opt($d){
$sub_files = bbn\file\dir::scan($d);
$files = [];
foreach ( $sub_files as $sub ){
if ( is_file($sub) ){
// Add it to files to be closed
array_push($files, $this->real_to_url($sub));
// Remove file's options
$this->options->remove($this->options->from_code($this->real_to_id($sub), $this->_files_pref()));
}
else {
$f = $this->rem_dir_opt($sub);
if ( !empty($f) ){
$files = array_merge($files, $f);
}
}
}
return $files;
} | php | private function rem_dir_opt($d){
$sub_files = bbn\file\dir::scan($d);
$files = [];
foreach ( $sub_files as $sub ){
if ( is_file($sub) ){
// Add it to files to be closed
array_push($files, $this->real_to_url($sub));
// Remove file's options
$this->options->remove($this->options->from_code($this->real_to_id($sub), $this->_files_pref()));
}
else {
$f = $this->rem_dir_opt($sub);
if ( !empty($f) ){
$files = array_merge($files, $f);
}
}
}
return $files;
} | [
"private",
"function",
"rem_dir_opt",
"(",
"$",
"d",
")",
"{",
"$",
"sub_files",
"=",
"bbn",
"\\",
"file",
"\\",
"dir",
"::",
"scan",
"(",
"$",
"d",
")",
";",
"$",
"files",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"sub_files",
"as",
"$",
"sub",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"sub",
")",
")",
"{",
"// Add it to files to be closed",
"array_push",
"(",
"$",
"files",
",",
"$",
"this",
"->",
"real_to_url",
"(",
"$",
"sub",
")",
")",
";",
"// Remove file's options",
"$",
"this",
"->",
"options",
"->",
"remove",
"(",
"$",
"this",
"->",
"options",
"->",
"from_code",
"(",
"$",
"this",
"->",
"real_to_id",
"(",
"$",
"sub",
")",
",",
"$",
"this",
"->",
"_files_pref",
"(",
")",
")",
")",
";",
"}",
"else",
"{",
"$",
"f",
"=",
"$",
"this",
"->",
"rem_dir_opt",
"(",
"$",
"sub",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"f",
")",
")",
"{",
"$",
"files",
"=",
"array_merge",
"(",
"$",
"files",
",",
"$",
"f",
")",
";",
"}",
"}",
"}",
"return",
"$",
"files",
";",
"}"
] | Deletes all files' options of a folder and returns an array of these files.
@param string $d The folder's path
@return array | [
"Deletes",
"all",
"files",
"options",
"of",
"a",
"folder",
"and",
"returns",
"an",
"array",
"of",
"these",
"files",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/ide/directories.php#L125-L143 |
nabab/bbn | src/bbn/ide/directories.php | directories.superior_sctrl | private function superior_sctrl($tab, $path=''){
if ( ($pos = strpos($tab, '_ctrl')) ){
// Fix the right path
$bits = explode('/', $path);
$count = \strlen(substr($tab, 0, $pos));
if ( !empty($bits) ){
while ( $count >= 0 ){
array_pop($bits);
$count--;
}
$path = implode('/', $bits).(!empty($bits) ? '/' : '');
}
// Fix the tab's name
$tab = '_ctrl';
}
return [
'tab' => $tab,
'path' => $path
];
} | php | private function superior_sctrl($tab, $path=''){
if ( ($pos = strpos($tab, '_ctrl')) ){
// Fix the right path
$bits = explode('/', $path);
$count = \strlen(substr($tab, 0, $pos));
if ( !empty($bits) ){
while ( $count >= 0 ){
array_pop($bits);
$count--;
}
$path = implode('/', $bits).(!empty($bits) ? '/' : '');
}
// Fix the tab's name
$tab = '_ctrl';
}
return [
'tab' => $tab,
'path' => $path
];
} | [
"private",
"function",
"superior_sctrl",
"(",
"$",
"tab",
",",
"$",
"path",
"=",
"''",
")",
"{",
"if",
"(",
"(",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"tab",
",",
"'_ctrl'",
")",
")",
")",
"{",
"// Fix the right path",
"$",
"bits",
"=",
"explode",
"(",
"'/'",
",",
"$",
"path",
")",
";",
"$",
"count",
"=",
"\\",
"strlen",
"(",
"substr",
"(",
"$",
"tab",
",",
"0",
",",
"$",
"pos",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"bits",
")",
")",
"{",
"while",
"(",
"$",
"count",
">=",
"0",
")",
"{",
"array_pop",
"(",
"$",
"bits",
")",
";",
"$",
"count",
"--",
";",
"}",
"$",
"path",
"=",
"implode",
"(",
"'/'",
",",
"$",
"bits",
")",
".",
"(",
"!",
"empty",
"(",
"$",
"bits",
")",
"?",
"'/'",
":",
"''",
")",
";",
"}",
"// Fix the tab's name",
"$",
"tab",
"=",
"'_ctrl'",
";",
"}",
"return",
"[",
"'tab'",
"=>",
"$",
"tab",
",",
"'path'",
"=>",
"$",
"path",
"]",
";",
"}"
] | Checks if the file is a superior super-controller and returns the corrected name and path
@param string $tab The tab'name from file's URL
@param string $path The file's path from file's URL
@return array | [
"Checks",
"if",
"the",
"file",
"is",
"a",
"superior",
"super",
"-",
"controller",
"and",
"returns",
"the",
"corrected",
"name",
"and",
"path"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/ide/directories.php#L152-L171 |
nabab/bbn | src/bbn/ide/directories.php | directories.real_to_id | public function real_to_id($file){
$timer = new bbn\util\timer();
$timer->start('real_to_id');
$url = self::real_to_url($file);
$dir = self::dir(self::dir_from_url($url));
if ( !empty($dir) &&
\defined($dir['bbn_path'])
){
$bbn_p = constant($dir['bbn_path']);
if ( strpos($file, $bbn_p) === 0 ){
$f = substr($file, \strlen($bbn_p));
$timer->stop('real_to_id');
bbn\x::log($timer->results(), "directories");
return bbn\str::parse_path($dir['bbn_path'].'/'.$f);
}
}
// OLD VERSION
/*
$dirs = $this->dirs();
$len = 0;
$bbn_path = '';
$f = '';
foreach ( $dirs as $i => $d ){
if ( !empty($d['bbn_path']) ){
$bbn_p = constant($d['bbn_path']);
if ( strpos($file, $bbn_p) === 0 ){
$p = substr($file, \strlen($bbn_p));
if ( strpos($p, $d['code']) === 0 ){
die(var_dump($file, $bbn_p, $p));
$len_tmp = \count(explode('/', $d['code']));
if ( $len_tmp > $len ){
$len = $len_tmp;
$bbn_path = $d['bbn_path'];
$f = $p;
}
}
}
}
}
return bbn\str::parse_path($bbn_path.'/'.$f);
*/
} | php | public function real_to_id($file){
$timer = new bbn\util\timer();
$timer->start('real_to_id');
$url = self::real_to_url($file);
$dir = self::dir(self::dir_from_url($url));
if ( !empty($dir) &&
\defined($dir['bbn_path'])
){
$bbn_p = constant($dir['bbn_path']);
if ( strpos($file, $bbn_p) === 0 ){
$f = substr($file, \strlen($bbn_p));
$timer->stop('real_to_id');
bbn\x::log($timer->results(), "directories");
return bbn\str::parse_path($dir['bbn_path'].'/'.$f);
}
}
// OLD VERSION
/*
$dirs = $this->dirs();
$len = 0;
$bbn_path = '';
$f = '';
foreach ( $dirs as $i => $d ){
if ( !empty($d['bbn_path']) ){
$bbn_p = constant($d['bbn_path']);
if ( strpos($file, $bbn_p) === 0 ){
$p = substr($file, \strlen($bbn_p));
if ( strpos($p, $d['code']) === 0 ){
die(var_dump($file, $bbn_p, $p));
$len_tmp = \count(explode('/', $d['code']));
if ( $len_tmp > $len ){
$len = $len_tmp;
$bbn_path = $d['bbn_path'];
$f = $p;
}
}
}
}
}
return bbn\str::parse_path($bbn_path.'/'.$f);
*/
} | [
"public",
"function",
"real_to_id",
"(",
"$",
"file",
")",
"{",
"$",
"timer",
"=",
"new",
"bbn",
"\\",
"util",
"\\",
"timer",
"(",
")",
";",
"$",
"timer",
"->",
"start",
"(",
"'real_to_id'",
")",
";",
"$",
"url",
"=",
"self",
"::",
"real_to_url",
"(",
"$",
"file",
")",
";",
"$",
"dir",
"=",
"self",
"::",
"dir",
"(",
"self",
"::",
"dir_from_url",
"(",
"$",
"url",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"dir",
")",
"&&",
"\\",
"defined",
"(",
"$",
"dir",
"[",
"'bbn_path'",
"]",
")",
")",
"{",
"$",
"bbn_p",
"=",
"constant",
"(",
"$",
"dir",
"[",
"'bbn_path'",
"]",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"file",
",",
"$",
"bbn_p",
")",
"===",
"0",
")",
"{",
"$",
"f",
"=",
"substr",
"(",
"$",
"file",
",",
"\\",
"strlen",
"(",
"$",
"bbn_p",
")",
")",
";",
"$",
"timer",
"->",
"stop",
"(",
"'real_to_id'",
")",
";",
"bbn",
"\\",
"x",
"::",
"log",
"(",
"$",
"timer",
"->",
"results",
"(",
")",
",",
"\"directories\"",
")",
";",
"return",
"bbn",
"\\",
"str",
"::",
"parse_path",
"(",
"$",
"dir",
"[",
"'bbn_path'",
"]",
".",
"'/'",
".",
"$",
"f",
")",
";",
"}",
"}",
"// OLD VERSION",
"/*\n $dirs = $this->dirs();\n $len = 0;\n $bbn_path = '';\n $f = '';\n foreach ( $dirs as $i => $d ){\n if ( !empty($d['bbn_path']) ){\n $bbn_p = constant($d['bbn_path']);\n if ( strpos($file, $bbn_p) === 0 ){\n $p = substr($file, \\strlen($bbn_p));\n if ( strpos($p, $d['code']) === 0 ){\n die(var_dump($file, $bbn_p, $p));\n $len_tmp = \\count(explode('/', $d['code']));\n if ( $len_tmp > $len ){\n $len = $len_tmp;\n $bbn_path = $d['bbn_path'];\n $f = $p;\n }\n }\n }\n }\n }\n return bbn\\str::parse_path($bbn_path.'/'.$f);\n */",
"}"
] | Returns the file's ID from the real file's path.
@param string $file The real file's path
@todo Fix the slowness!
@return bool|string | [
"Returns",
"the",
"file",
"s",
"ID",
"from",
"the",
"real",
"file",
"s",
"path",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/ide/directories.php#L289-L331 |
nabab/bbn | src/bbn/ide/directories.php | directories.url_to_real | public function url_to_real($url){
if ( ($dn = $this->dir_from_url($url)) &&
($dir = $this->dir($dn)) &&
($res = $this->get_root_path($dn))
){
$bits = explode('/', substr($url, \strlen($dn), \strlen($url)));
if ( !empty($dir['tabs']) && !empty($bits) ){
// Tab's nane
$tab = array_pop($bits);
// File's name
$fn = array_pop($bits);
// File's path
$fp = implode('/', $bits).'/';
// Check if the file is a superior super-controller
$ssc = $this->superior_sctrl($tab, $fp);
$tab = $ssc['tab'];
$fp = $ssc['path'];
if ( !empty($dir['tabs'][$tab]) ){
$tab = $dir['tabs'][$tab];
$res .= $tab['path'];
if ( !empty($tab['fixed']) ){
$res .= $fp . $tab['fixed'];
}
else {
$res .= $fp . $fn;
$ext_ok = false;
foreach ( $tab['extensions'] as $e ){
$ext = '.' . $e['ext'];
if ( is_file($res . $ext) ){
$res .= $ext;
$ext_ok = true;
break;
}
}
if ( empty($ext_ok) ){
$res .= '.' . $tab['extensions'][0]['ext'];
}
}
}
else {
return false;
}
}
else {
// Remove the last element of the path if it's 'code' (it's the tab's URL in a non MVC architecture)
if ( end($bits) === 'code' ){
array_pop($bits);
}
$res .= implode('/', $bits);
}
return bbn\str::parse_path($res);
}
return false;
} | php | public function url_to_real($url){
if ( ($dn = $this->dir_from_url($url)) &&
($dir = $this->dir($dn)) &&
($res = $this->get_root_path($dn))
){
$bits = explode('/', substr($url, \strlen($dn), \strlen($url)));
if ( !empty($dir['tabs']) && !empty($bits) ){
// Tab's nane
$tab = array_pop($bits);
// File's name
$fn = array_pop($bits);
// File's path
$fp = implode('/', $bits).'/';
// Check if the file is a superior super-controller
$ssc = $this->superior_sctrl($tab, $fp);
$tab = $ssc['tab'];
$fp = $ssc['path'];
if ( !empty($dir['tabs'][$tab]) ){
$tab = $dir['tabs'][$tab];
$res .= $tab['path'];
if ( !empty($tab['fixed']) ){
$res .= $fp . $tab['fixed'];
}
else {
$res .= $fp . $fn;
$ext_ok = false;
foreach ( $tab['extensions'] as $e ){
$ext = '.' . $e['ext'];
if ( is_file($res . $ext) ){
$res .= $ext;
$ext_ok = true;
break;
}
}
if ( empty($ext_ok) ){
$res .= '.' . $tab['extensions'][0]['ext'];
}
}
}
else {
return false;
}
}
else {
// Remove the last element of the path if it's 'code' (it's the tab's URL in a non MVC architecture)
if ( end($bits) === 'code' ){
array_pop($bits);
}
$res .= implode('/', $bits);
}
return bbn\str::parse_path($res);
}
return false;
} | [
"public",
"function",
"url_to_real",
"(",
"$",
"url",
")",
"{",
"if",
"(",
"(",
"$",
"dn",
"=",
"$",
"this",
"->",
"dir_from_url",
"(",
"$",
"url",
")",
")",
"&&",
"(",
"$",
"dir",
"=",
"$",
"this",
"->",
"dir",
"(",
"$",
"dn",
")",
")",
"&&",
"(",
"$",
"res",
"=",
"$",
"this",
"->",
"get_root_path",
"(",
"$",
"dn",
")",
")",
")",
"{",
"$",
"bits",
"=",
"explode",
"(",
"'/'",
",",
"substr",
"(",
"$",
"url",
",",
"\\",
"strlen",
"(",
"$",
"dn",
")",
",",
"\\",
"strlen",
"(",
"$",
"url",
")",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"dir",
"[",
"'tabs'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"bits",
")",
")",
"{",
"// Tab's nane",
"$",
"tab",
"=",
"array_pop",
"(",
"$",
"bits",
")",
";",
"// File's name",
"$",
"fn",
"=",
"array_pop",
"(",
"$",
"bits",
")",
";",
"// File's path",
"$",
"fp",
"=",
"implode",
"(",
"'/'",
",",
"$",
"bits",
")",
".",
"'/'",
";",
"// Check if the file is a superior super-controller",
"$",
"ssc",
"=",
"$",
"this",
"->",
"superior_sctrl",
"(",
"$",
"tab",
",",
"$",
"fp",
")",
";",
"$",
"tab",
"=",
"$",
"ssc",
"[",
"'tab'",
"]",
";",
"$",
"fp",
"=",
"$",
"ssc",
"[",
"'path'",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"dir",
"[",
"'tabs'",
"]",
"[",
"$",
"tab",
"]",
")",
")",
"{",
"$",
"tab",
"=",
"$",
"dir",
"[",
"'tabs'",
"]",
"[",
"$",
"tab",
"]",
";",
"$",
"res",
".=",
"$",
"tab",
"[",
"'path'",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"tab",
"[",
"'fixed'",
"]",
")",
")",
"{",
"$",
"res",
".=",
"$",
"fp",
".",
"$",
"tab",
"[",
"'fixed'",
"]",
";",
"}",
"else",
"{",
"$",
"res",
".=",
"$",
"fp",
".",
"$",
"fn",
";",
"$",
"ext_ok",
"=",
"false",
";",
"foreach",
"(",
"$",
"tab",
"[",
"'extensions'",
"]",
"as",
"$",
"e",
")",
"{",
"$",
"ext",
"=",
"'.'",
".",
"$",
"e",
"[",
"'ext'",
"]",
";",
"if",
"(",
"is_file",
"(",
"$",
"res",
".",
"$",
"ext",
")",
")",
"{",
"$",
"res",
".=",
"$",
"ext",
";",
"$",
"ext_ok",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"ext_ok",
")",
")",
"{",
"$",
"res",
".=",
"'.'",
".",
"$",
"tab",
"[",
"'extensions'",
"]",
"[",
"0",
"]",
"[",
"'ext'",
"]",
";",
"}",
"}",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"// Remove the last element of the path if it's 'code' (it's the tab's URL in a non MVC architecture)",
"if",
"(",
"end",
"(",
"$",
"bits",
")",
"===",
"'code'",
")",
"{",
"array_pop",
"(",
"$",
"bits",
")",
";",
"}",
"$",
"res",
".=",
"implode",
"(",
"'/'",
",",
"$",
"bits",
")",
";",
"}",
"return",
"bbn",
"\\",
"str",
"::",
"parse_path",
"(",
"$",
"res",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Gets the real file's path from an URL
@param string $url The file's URL
@return bool|string | [
"Gets",
"the",
"real",
"file",
"s",
"path",
"from",
"an",
"URL"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/ide/directories.php#L339-L392 |
nabab/bbn | src/bbn/ide/directories.php | directories.dir_from_url | public function dir_from_url($url){
$dir = false;
foreach ( $this->dirs() as $i => $d ){
if ( (strpos($url, $i) === 0) &&
(\strlen($i) > \strlen($dir) )
){
$dir = $i;
break;
}
}
return $dir;
} | php | public function dir_from_url($url){
$dir = false;
foreach ( $this->dirs() as $i => $d ){
if ( (strpos($url, $i) === 0) &&
(\strlen($i) > \strlen($dir) )
){
$dir = $i;
break;
}
}
return $dir;
} | [
"public",
"function",
"dir_from_url",
"(",
"$",
"url",
")",
"{",
"$",
"dir",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"dirs",
"(",
")",
"as",
"$",
"i",
"=>",
"$",
"d",
")",
"{",
"if",
"(",
"(",
"strpos",
"(",
"$",
"url",
",",
"$",
"i",
")",
"===",
"0",
")",
"&&",
"(",
"\\",
"strlen",
"(",
"$",
"i",
")",
">",
"\\",
"strlen",
"(",
"$",
"dir",
")",
")",
")",
"{",
"$",
"dir",
"=",
"$",
"i",
";",
"break",
";",
"}",
"}",
"return",
"$",
"dir",
";",
"}"
] | Returns the dir's name from an URL
@param string $url
@return bool|int|string | [
"Returns",
"the",
"dir",
"s",
"name",
"from",
"an",
"URL"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/ide/directories.php#L400-L411 |
nabab/bbn | src/bbn/ide/directories.php | directories.url_to_id | public function url_to_id($url){
if ( $file = $this->url_to_real($url) ){
return $this->real_to_id($file);
}
return false;
} | php | public function url_to_id($url){
if ( $file = $this->url_to_real($url) ){
return $this->real_to_id($file);
}
return false;
} | [
"public",
"function",
"url_to_id",
"(",
"$",
"url",
")",
"{",
"if",
"(",
"$",
"file",
"=",
"$",
"this",
"->",
"url_to_real",
"(",
"$",
"url",
")",
")",
"{",
"return",
"$",
"this",
"->",
"real_to_id",
"(",
"$",
"file",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Returns the file's ID from its URL
@param string $url The file's URL
@return bool|string | [
"Returns",
"the",
"file",
"s",
"ID",
"from",
"its",
"URL"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/ide/directories.php#L429-L434 |
nabab/bbn | src/bbn/ide/directories.php | directories.id_to_url | public function id_to_url($id){
if ( $file = $this->id_to_real($id) ){
return $this->real_to_url($file);
}
return false;
} | php | public function id_to_url($id){
if ( $file = $this->id_to_real($id) ){
return $this->real_to_url($file);
}
return false;
} | [
"public",
"function",
"id_to_url",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"$",
"file",
"=",
"$",
"this",
"->",
"id_to_real",
"(",
"$",
"id",
")",
")",
"{",
"return",
"$",
"this",
"->",
"real_to_url",
"(",
"$",
"file",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Returns the file's URL from its ID
@param string $id The file's ID
@return bool|string | [
"Returns",
"the",
"file",
"s",
"URL",
"from",
"its",
"ID"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/ide/directories.php#L442-L447 |
nabab/bbn | src/bbn/ide/directories.php | directories.get_root_path | public function get_root_path($code){
/** @var array $dir The directory configuration */
$dir = $this->dir($code);
if ( $dir ){
$path = $this->decipher_path(bbn\str::parse_path($dir['bbn_path'].(!empty($dir['path']) ? '/' . $dir['path'] : '')));
$r = bbn\str::parse_path($path.'/');
return $r;
}
return false;
} | php | public function get_root_path($code){
/** @var array $dir The directory configuration */
$dir = $this->dir($code);
if ( $dir ){
$path = $this->decipher_path(bbn\str::parse_path($dir['bbn_path'].(!empty($dir['path']) ? '/' . $dir['path'] : '')));
$r = bbn\str::parse_path($path.'/');
return $r;
}
return false;
} | [
"public",
"function",
"get_root_path",
"(",
"$",
"code",
")",
"{",
"/** @var array $dir The directory configuration */",
"$",
"dir",
"=",
"$",
"this",
"->",
"dir",
"(",
"$",
"code",
")",
";",
"if",
"(",
"$",
"dir",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"decipher_path",
"(",
"bbn",
"\\",
"str",
"::",
"parse_path",
"(",
"$",
"dir",
"[",
"'bbn_path'",
"]",
".",
"(",
"!",
"empty",
"(",
"$",
"dir",
"[",
"'path'",
"]",
")",
"?",
"'/'",
".",
"$",
"dir",
"[",
"'path'",
"]",
":",
"''",
")",
")",
")",
";",
"$",
"r",
"=",
"bbn",
"\\",
"str",
"::",
"parse_path",
"(",
"$",
"path",
".",
"'/'",
")",
";",
"return",
"$",
"r",
";",
"}",
"return",
"false",
";",
"}"
] | Gets the real root path from a directory's id as recorded in the options.
@param string $code The dir's name (code)
@return bool|string | [
"Gets",
"the",
"real",
"root",
"path",
"from",
"a",
"directory",
"s",
"id",
"as",
"recorded",
"in",
"the",
"options",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/ide/directories.php#L455-L465 |
nabab/bbn | src/bbn/ide/directories.php | directories.dirs | public function dirs($code=false){
$all = $this->options->full_soptions(self::_dev_path());
$cats = [];
$r = [];
foreach ( $all as $a ){
if ( \defined($a['bbn_path']) ){
$k = $a['bbn_path'] . '/' . ($a['code'] === '/' ? '' : $a['code']);
if ( !isset($cats[$a['id_alias']]) ){
unset($a['alias']['cfg']);
$cats[$a['id_alias']] = $a['alias'];
}
unset($a['cfg']);
unset($a['alias']);
$r[$k] = $a;
$r[$k]['title'] = $r[$k]['text'];
$r[$k]['alias_code'] = $cats[$a['id_alias']]['code'];
if ( !empty($cats[$a['id_alias']]['tabs']) ){
$r[$k]['tabs'] = $cats[$a['id_alias']]['tabs'];
}
else{
$r[$k]['extensions'] = $cats[$a['id_alias']]['extensions'];
}
unset($r[$k]['alias']);
}
}
if ( $code ){
return isset($r[$code]) ? $r[$code] : false;
}
return $r;
} | php | public function dirs($code=false){
$all = $this->options->full_soptions(self::_dev_path());
$cats = [];
$r = [];
foreach ( $all as $a ){
if ( \defined($a['bbn_path']) ){
$k = $a['bbn_path'] . '/' . ($a['code'] === '/' ? '' : $a['code']);
if ( !isset($cats[$a['id_alias']]) ){
unset($a['alias']['cfg']);
$cats[$a['id_alias']] = $a['alias'];
}
unset($a['cfg']);
unset($a['alias']);
$r[$k] = $a;
$r[$k]['title'] = $r[$k]['text'];
$r[$k]['alias_code'] = $cats[$a['id_alias']]['code'];
if ( !empty($cats[$a['id_alias']]['tabs']) ){
$r[$k]['tabs'] = $cats[$a['id_alias']]['tabs'];
}
else{
$r[$k]['extensions'] = $cats[$a['id_alias']]['extensions'];
}
unset($r[$k]['alias']);
}
}
if ( $code ){
return isset($r[$code]) ? $r[$code] : false;
}
return $r;
} | [
"public",
"function",
"dirs",
"(",
"$",
"code",
"=",
"false",
")",
"{",
"$",
"all",
"=",
"$",
"this",
"->",
"options",
"->",
"full_soptions",
"(",
"self",
"::",
"_dev_path",
"(",
")",
")",
";",
"$",
"cats",
"=",
"[",
"]",
";",
"$",
"r",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"all",
"as",
"$",
"a",
")",
"{",
"if",
"(",
"\\",
"defined",
"(",
"$",
"a",
"[",
"'bbn_path'",
"]",
")",
")",
"{",
"$",
"k",
"=",
"$",
"a",
"[",
"'bbn_path'",
"]",
".",
"'/'",
".",
"(",
"$",
"a",
"[",
"'code'",
"]",
"===",
"'/'",
"?",
"''",
":",
"$",
"a",
"[",
"'code'",
"]",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"cats",
"[",
"$",
"a",
"[",
"'id_alias'",
"]",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"a",
"[",
"'alias'",
"]",
"[",
"'cfg'",
"]",
")",
";",
"$",
"cats",
"[",
"$",
"a",
"[",
"'id_alias'",
"]",
"]",
"=",
"$",
"a",
"[",
"'alias'",
"]",
";",
"}",
"unset",
"(",
"$",
"a",
"[",
"'cfg'",
"]",
")",
";",
"unset",
"(",
"$",
"a",
"[",
"'alias'",
"]",
")",
";",
"$",
"r",
"[",
"$",
"k",
"]",
"=",
"$",
"a",
";",
"$",
"r",
"[",
"$",
"k",
"]",
"[",
"'title'",
"]",
"=",
"$",
"r",
"[",
"$",
"k",
"]",
"[",
"'text'",
"]",
";",
"$",
"r",
"[",
"$",
"k",
"]",
"[",
"'alias_code'",
"]",
"=",
"$",
"cats",
"[",
"$",
"a",
"[",
"'id_alias'",
"]",
"]",
"[",
"'code'",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"cats",
"[",
"$",
"a",
"[",
"'id_alias'",
"]",
"]",
"[",
"'tabs'",
"]",
")",
")",
"{",
"$",
"r",
"[",
"$",
"k",
"]",
"[",
"'tabs'",
"]",
"=",
"$",
"cats",
"[",
"$",
"a",
"[",
"'id_alias'",
"]",
"]",
"[",
"'tabs'",
"]",
";",
"}",
"else",
"{",
"$",
"r",
"[",
"$",
"k",
"]",
"[",
"'extensions'",
"]",
"=",
"$",
"cats",
"[",
"$",
"a",
"[",
"'id_alias'",
"]",
"]",
"[",
"'extensions'",
"]",
";",
"}",
"unset",
"(",
"$",
"r",
"[",
"$",
"k",
"]",
"[",
"'alias'",
"]",
")",
";",
"}",
"}",
"if",
"(",
"$",
"code",
")",
"{",
"return",
"isset",
"(",
"$",
"r",
"[",
"$",
"code",
"]",
")",
"?",
"$",
"r",
"[",
"$",
"code",
"]",
":",
"false",
";",
"}",
"return",
"$",
"r",
";",
"}"
] | Make dirs' configurations
@param string|bool $code The dir's name (code)
@return array|bool | [
"Make",
"dirs",
"configurations"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/ide/directories.php#L552-L581 |
nabab/bbn | src/bbn/ide/directories.php | directories.create | public function create($dir, $tab, $path, $name, $type){
if ( ($cfg = $this->dir($dir)) &&
($root = $this->get_root_path($dir))
){
$path = $path === './' ? '' : $path . '/';
$ext = bbn\str::file_ext($name);
$default = '';
// MVC
if ( !empty($cfg['tabs']) &&
!empty($tab)
){
$cfg = $cfg['tabs'][$tab];
$root = $root . $cfg['path'];
}
// New file
if ( $type === 'file' ){
if ( !empty($ext) ){
$ext_ok = array_filter($cfg['extensions'], function($e) use ($ext){
return ( $e['ext'] === $ext );
});
if ( !empty($ext_ok) ){
$default = array_values($ext_ok)[0]['default'];
}
}
if ( empty($ext) ||
(!empty($ext) && empty($ext_ok))
){
$ext = $cfg['extensions'][0]['ext'];
$default = $cfg['extensions'][0]['default'];
}
$file = $path . bbn\str::file_ext($name, 1)[0] . '.' . $ext;
$real = $root . $file;
if ( is_file($real) ){
return $this->error("The file already exists");
}
if ( !bbn\file\dir::create_path(dirname($real)) ){
return $this->error("Impossible to create the container directory");
}
if ( !file_put_contents($real, $default) ){
return $this->error("Impossible to create the file");
}
// Add item to options table for permissions
if ( $tab === 'php' ){
if ( !$this->create_perm_by_real($real) ){
return $this->error("Impossible to create the option");
}
}
}
//New directory
else if ( $type === 'dir' ){
$file = $path . '/' . $name;
$real = $root . $file;
if ( is_dir($real) ){
return $this->error("The directory already exists");
}
if ( !bbn\file\dir::create_path($real) ){
return $this->error("Impossible to create the directory");
}
}
return $file;
}
return $this->error("There is a problem in the name (dir) you entered");
} | php | public function create($dir, $tab, $path, $name, $type){
if ( ($cfg = $this->dir($dir)) &&
($root = $this->get_root_path($dir))
){
$path = $path === './' ? '' : $path . '/';
$ext = bbn\str::file_ext($name);
$default = '';
// MVC
if ( !empty($cfg['tabs']) &&
!empty($tab)
){
$cfg = $cfg['tabs'][$tab];
$root = $root . $cfg['path'];
}
// New file
if ( $type === 'file' ){
if ( !empty($ext) ){
$ext_ok = array_filter($cfg['extensions'], function($e) use ($ext){
return ( $e['ext'] === $ext );
});
if ( !empty($ext_ok) ){
$default = array_values($ext_ok)[0]['default'];
}
}
if ( empty($ext) ||
(!empty($ext) && empty($ext_ok))
){
$ext = $cfg['extensions'][0]['ext'];
$default = $cfg['extensions'][0]['default'];
}
$file = $path . bbn\str::file_ext($name, 1)[0] . '.' . $ext;
$real = $root . $file;
if ( is_file($real) ){
return $this->error("The file already exists");
}
if ( !bbn\file\dir::create_path(dirname($real)) ){
return $this->error("Impossible to create the container directory");
}
if ( !file_put_contents($real, $default) ){
return $this->error("Impossible to create the file");
}
// Add item to options table for permissions
if ( $tab === 'php' ){
if ( !$this->create_perm_by_real($real) ){
return $this->error("Impossible to create the option");
}
}
}
//New directory
else if ( $type === 'dir' ){
$file = $path . '/' . $name;
$real = $root . $file;
if ( is_dir($real) ){
return $this->error("The directory already exists");
}
if ( !bbn\file\dir::create_path($real) ){
return $this->error("Impossible to create the directory");
}
}
return $file;
}
return $this->error("There is a problem in the name (dir) you entered");
} | [
"public",
"function",
"create",
"(",
"$",
"dir",
",",
"$",
"tab",
",",
"$",
"path",
",",
"$",
"name",
",",
"$",
"type",
")",
"{",
"if",
"(",
"(",
"$",
"cfg",
"=",
"$",
"this",
"->",
"dir",
"(",
"$",
"dir",
")",
")",
"&&",
"(",
"$",
"root",
"=",
"$",
"this",
"->",
"get_root_path",
"(",
"$",
"dir",
")",
")",
")",
"{",
"$",
"path",
"=",
"$",
"path",
"===",
"'./'",
"?",
"''",
":",
"$",
"path",
".",
"'/'",
";",
"$",
"ext",
"=",
"bbn",
"\\",
"str",
"::",
"file_ext",
"(",
"$",
"name",
")",
";",
"$",
"default",
"=",
"''",
";",
"// MVC",
"if",
"(",
"!",
"empty",
"(",
"$",
"cfg",
"[",
"'tabs'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"tab",
")",
")",
"{",
"$",
"cfg",
"=",
"$",
"cfg",
"[",
"'tabs'",
"]",
"[",
"$",
"tab",
"]",
";",
"$",
"root",
"=",
"$",
"root",
".",
"$",
"cfg",
"[",
"'path'",
"]",
";",
"}",
"// New file",
"if",
"(",
"$",
"type",
"===",
"'file'",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"ext",
")",
")",
"{",
"$",
"ext_ok",
"=",
"array_filter",
"(",
"$",
"cfg",
"[",
"'extensions'",
"]",
",",
"function",
"(",
"$",
"e",
")",
"use",
"(",
"$",
"ext",
")",
"{",
"return",
"(",
"$",
"e",
"[",
"'ext'",
"]",
"===",
"$",
"ext",
")",
";",
"}",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"ext_ok",
")",
")",
"{",
"$",
"default",
"=",
"array_values",
"(",
"$",
"ext_ok",
")",
"[",
"0",
"]",
"[",
"'default'",
"]",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"ext",
")",
"||",
"(",
"!",
"empty",
"(",
"$",
"ext",
")",
"&&",
"empty",
"(",
"$",
"ext_ok",
")",
")",
")",
"{",
"$",
"ext",
"=",
"$",
"cfg",
"[",
"'extensions'",
"]",
"[",
"0",
"]",
"[",
"'ext'",
"]",
";",
"$",
"default",
"=",
"$",
"cfg",
"[",
"'extensions'",
"]",
"[",
"0",
"]",
"[",
"'default'",
"]",
";",
"}",
"$",
"file",
"=",
"$",
"path",
".",
"bbn",
"\\",
"str",
"::",
"file_ext",
"(",
"$",
"name",
",",
"1",
")",
"[",
"0",
"]",
".",
"'.'",
".",
"$",
"ext",
";",
"$",
"real",
"=",
"$",
"root",
".",
"$",
"file",
";",
"if",
"(",
"is_file",
"(",
"$",
"real",
")",
")",
"{",
"return",
"$",
"this",
"->",
"error",
"(",
"\"The file already exists\"",
")",
";",
"}",
"if",
"(",
"!",
"bbn",
"\\",
"file",
"\\",
"dir",
"::",
"create_path",
"(",
"dirname",
"(",
"$",
"real",
")",
")",
")",
"{",
"return",
"$",
"this",
"->",
"error",
"(",
"\"Impossible to create the container directory\"",
")",
";",
"}",
"if",
"(",
"!",
"file_put_contents",
"(",
"$",
"real",
",",
"$",
"default",
")",
")",
"{",
"return",
"$",
"this",
"->",
"error",
"(",
"\"Impossible to create the file\"",
")",
";",
"}",
"// Add item to options table for permissions",
"if",
"(",
"$",
"tab",
"===",
"'php'",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"create_perm_by_real",
"(",
"$",
"real",
")",
")",
"{",
"return",
"$",
"this",
"->",
"error",
"(",
"\"Impossible to create the option\"",
")",
";",
"}",
"}",
"}",
"//New directory",
"else",
"if",
"(",
"$",
"type",
"===",
"'dir'",
")",
"{",
"$",
"file",
"=",
"$",
"path",
".",
"'/'",
".",
"$",
"name",
";",
"$",
"real",
"=",
"$",
"root",
".",
"$",
"file",
";",
"if",
"(",
"is_dir",
"(",
"$",
"real",
")",
")",
"{",
"return",
"$",
"this",
"->",
"error",
"(",
"\"The directory already exists\"",
")",
";",
"}",
"if",
"(",
"!",
"bbn",
"\\",
"file",
"\\",
"dir",
"::",
"create_path",
"(",
"$",
"real",
")",
")",
"{",
"return",
"$",
"this",
"->",
"error",
"(",
"\"Impossible to create the directory\"",
")",
";",
"}",
"}",
"return",
"$",
"file",
";",
"}",
"return",
"$",
"this",
"->",
"error",
"(",
"\"There is a problem in the name (dir) you entered\"",
")",
";",
"}"
] | Creates a a new file or a new directory.
@param string $dir The source's name
@param string|false $tab The tab's name (MVC)
@param string $path The file/directory's path
@param string $name The file/directory's name
@param string $type If it's a file or a directory (file|dir)
@return string|void | [
"Creates",
"a",
"a",
"new",
"file",
"or",
"a",
"new",
"directory",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/ide/directories.php#L611-L674 |
nabab/bbn | src/bbn/ide/directories.php | directories.load | public function load($file, $dir, $tab, bbn\user\preferences $pref = null){
/** @var boolean|array $res */
$res = false;
$file = bbn\str::parse_path($file);
if ( $file && $dir ){
/** @var array $dir_cfg The directory configuration from DB */
if ( \is_array($dir) ){
$dir_cfg = $dir;
$dir = $dir_cfg['value'] ?? $dir_cfg['path'];
}
else{
$dir_cfg = $this->dir($dir);
}
if ( !\is_array($dir_cfg) ){
die(\bbn\x::dump("Problem with the function directories::dir with argument ".$dir));
}
$res = $this->get_file($file, $dir, $tab, $dir_cfg, $pref);
}
return $res;
} | php | public function load($file, $dir, $tab, bbn\user\preferences $pref = null){
/** @var boolean|array $res */
$res = false;
$file = bbn\str::parse_path($file);
if ( $file && $dir ){
/** @var array $dir_cfg The directory configuration from DB */
if ( \is_array($dir) ){
$dir_cfg = $dir;
$dir = $dir_cfg['value'] ?? $dir_cfg['path'];
}
else{
$dir_cfg = $this->dir($dir);
}
if ( !\is_array($dir_cfg) ){
die(\bbn\x::dump("Problem with the function directories::dir with argument ".$dir));
}
$res = $this->get_file($file, $dir, $tab, $dir_cfg, $pref);
}
return $res;
} | [
"public",
"function",
"load",
"(",
"$",
"file",
",",
"$",
"dir",
",",
"$",
"tab",
",",
"bbn",
"\\",
"user",
"\\",
"preferences",
"$",
"pref",
"=",
"null",
")",
"{",
"/** @var boolean|array $res */",
"$",
"res",
"=",
"false",
";",
"$",
"file",
"=",
"bbn",
"\\",
"str",
"::",
"parse_path",
"(",
"$",
"file",
")",
";",
"if",
"(",
"$",
"file",
"&&",
"$",
"dir",
")",
"{",
"/** @var array $dir_cfg The directory configuration from DB */",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"dir",
")",
")",
"{",
"$",
"dir_cfg",
"=",
"$",
"dir",
";",
"$",
"dir",
"=",
"$",
"dir_cfg",
"[",
"'value'",
"]",
"??",
"$",
"dir_cfg",
"[",
"'path'",
"]",
";",
"}",
"else",
"{",
"$",
"dir_cfg",
"=",
"$",
"this",
"->",
"dir",
"(",
"$",
"dir",
")",
";",
"}",
"if",
"(",
"!",
"\\",
"is_array",
"(",
"$",
"dir_cfg",
")",
")",
"{",
"die",
"(",
"\\",
"bbn",
"\\",
"x",
"::",
"dump",
"(",
"\"Problem with the function directories::dir with argument \"",
".",
"$",
"dir",
")",
")",
";",
"}",
"$",
"res",
"=",
"$",
"this",
"->",
"get_file",
"(",
"$",
"file",
",",
"$",
"dir",
",",
"$",
"tab",
",",
"$",
"dir_cfg",
",",
"$",
"pref",
")",
";",
"}",
"return",
"$",
"res",
";",
"}"
] | Loads a file.
@param string $file
@param string|array $dir
@param string $tab
@param bbn\user\preferences|null $pref
@return array|bool | [
"Loads",
"a",
"file",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/ide/directories.php#L685-L705 |
nabab/bbn | src/bbn/ide/directories.php | directories.get_file | protected function get_file($file, $dir, $tab, array $cfg, bbn\user\preferences $pref = null){
if ( isset($cfg['title'], $cfg['bcolor'], $cfg['fcolor']) ){
/** @var string $name The file's name - without path and extension */
$name = bbn\str::file_ext($file, 1)[0];
/** @var string $ext The file's extension */
$ext = bbn\str::file_ext($file);
/** @var string $path The file's path without file's name */
$path = dirname($file) !== '.' ? dirname($file) . '/' : '';
$url = $dir . $path . $name;
$r = $this->get_tab($url, $cfg['title'], $cfg);
$timer = new bbn\util\timer();
/** @var string $root_path The real/actual path to the root directory */
$root_path = $this->get_root_path($dir);
$is_file = true;
// Normal Tab
if ( empty($tab) && empty($cfg['url']) ){
$real_file = $root_path . $file;
$r['url'] = $dir . $file;
$r['title'] = $file;
$r['list'] = [[
'bcolor' => $r['bcolor'],
'fcolor' => $r['fcolor'],
'title' => 'Code',
'url' => 'code',
'static' => 1,
'default' => 1,
'file' => $real_file
]];
//$r['file'] = $real_file;
foreach ( $cfg['extensions'] as $e ){
if ( $e['ext'] === $ext ){
$mode = $e['mode'];
}
}
if ( !is_file($real_file) ){
$is_file = false;
$this->error('Impossible to find the file ' . $real_file);
return false;
}
}
// MVC's Tab
else {
$r['url'] = $cfg['url'];
$r['static'] = 1;
if ( empty($tab) ){
$r['default'] = !empty($cfg['default']) ? true : false;
}
else {
$r['default'] = ( $cfg['url'] === $tab ) ? true : false;
}
// _CTRL
if ( !empty($cfg['fixed']) ){
$ext = bbn\str::file_ext($cfg['fixed']);
foreach ( $cfg['extensions'] as $e ){
if ( $e['ext'] === $ext ){
$file = dirname($file) . '/' . $cfg['fixed'];
$real_file = $root_path . $file;
$mode = $e['mode'];
$r['file'] = $real_file;
if ( !is_file($real_file) ){
$is_file = false;
$value = $e['default'];
}
break;
}
}
}
else {
foreach ( $cfg['extensions'] as $e ){
$ext = $e['ext'];
/** @var string $real_file The absolute full path to the file */
$real_file = $root_path . $file . '.' . $ext;
if ( is_file($real_file) ){
$r['file'] = $real_file;
$mode = $e['mode'];
// Permissions
if ( ($id_opt = $this->real_to_perm($real_file)) &&
($opt = $this->options->option($id_opt))
){
$r['perm_id'] = $opt['id'];
$r['perm_code'] = $opt['code'];
$r['perm_text'] = $opt['text'];
if ( isset($opt['help']) ){
$r['perm_help'] = $opt['help'];
}
$sopt = $this->options->full_options($opt['id']);
$perm_chi = [];
foreach ( $sopt as $so ){
array_push($perm_chi, [
'perm_code' => $so['code'],
'perm_text' => $so['text']
]);
}
$r['perm_children'] = $perm_chi;
}
break;
}
}
if ( empty($mode) ){
$value = $cfg['extensions'][0]['default'];
}
}
}
// Timing problem is here, check out timer below and logs
// Do we need to have a single preference for each tab?
// Guilty: real_to_id takes 0.15 sec and is called 10+ times
$timer->start();
// User's preferences
if ( $is_file &&
$pref &&
($id_option = $this->options->from_code($this->real_to_id($real_file), $this->_files_pref()))
){
$o = $pref->get($id_option);
}
$timer->stop();
if ( empty($tab) && empty($cfg['url']) ){
$r['list'][0]['id_script'] = $this->real_to_id($real_file);
$r['list'][0]['cfg'] = [
'mode' => !empty($mode) ? $mode : $cfg['extensions'][0]['mode'],
'value' => empty($value) ? file_get_contents($real_file) : $value,
'selections' => !empty($o['selections']) ? $o['selections'] : [],
'marks' => !empty($o['marks']) ? $o['marks'] : []
];
}
else {
$r['id_script'] = $this->real_to_id($real_file);
$r['cfg'] = [
'mode' => !empty($mode) ? $mode : $cfg['extensions'][0]['mode'],
'value' => empty($value) ? file_get_contents($real_file) : $value,
'selections' => !empty($o['selections']) ? $o['selections'] : [],
'marks' => !empty($o['marks']) ? $o['marks'] : []
];
}
bbn\x::log($timer->results(), "directories");
return $r;
}
} | php | protected function get_file($file, $dir, $tab, array $cfg, bbn\user\preferences $pref = null){
if ( isset($cfg['title'], $cfg['bcolor'], $cfg['fcolor']) ){
/** @var string $name The file's name - without path and extension */
$name = bbn\str::file_ext($file, 1)[0];
/** @var string $ext The file's extension */
$ext = bbn\str::file_ext($file);
/** @var string $path The file's path without file's name */
$path = dirname($file) !== '.' ? dirname($file) . '/' : '';
$url = $dir . $path . $name;
$r = $this->get_tab($url, $cfg['title'], $cfg);
$timer = new bbn\util\timer();
/** @var string $root_path The real/actual path to the root directory */
$root_path = $this->get_root_path($dir);
$is_file = true;
// Normal Tab
if ( empty($tab) && empty($cfg['url']) ){
$real_file = $root_path . $file;
$r['url'] = $dir . $file;
$r['title'] = $file;
$r['list'] = [[
'bcolor' => $r['bcolor'],
'fcolor' => $r['fcolor'],
'title' => 'Code',
'url' => 'code',
'static' => 1,
'default' => 1,
'file' => $real_file
]];
//$r['file'] = $real_file;
foreach ( $cfg['extensions'] as $e ){
if ( $e['ext'] === $ext ){
$mode = $e['mode'];
}
}
if ( !is_file($real_file) ){
$is_file = false;
$this->error('Impossible to find the file ' . $real_file);
return false;
}
}
// MVC's Tab
else {
$r['url'] = $cfg['url'];
$r['static'] = 1;
if ( empty($tab) ){
$r['default'] = !empty($cfg['default']) ? true : false;
}
else {
$r['default'] = ( $cfg['url'] === $tab ) ? true : false;
}
// _CTRL
if ( !empty($cfg['fixed']) ){
$ext = bbn\str::file_ext($cfg['fixed']);
foreach ( $cfg['extensions'] as $e ){
if ( $e['ext'] === $ext ){
$file = dirname($file) . '/' . $cfg['fixed'];
$real_file = $root_path . $file;
$mode = $e['mode'];
$r['file'] = $real_file;
if ( !is_file($real_file) ){
$is_file = false;
$value = $e['default'];
}
break;
}
}
}
else {
foreach ( $cfg['extensions'] as $e ){
$ext = $e['ext'];
/** @var string $real_file The absolute full path to the file */
$real_file = $root_path . $file . '.' . $ext;
if ( is_file($real_file) ){
$r['file'] = $real_file;
$mode = $e['mode'];
// Permissions
if ( ($id_opt = $this->real_to_perm($real_file)) &&
($opt = $this->options->option($id_opt))
){
$r['perm_id'] = $opt['id'];
$r['perm_code'] = $opt['code'];
$r['perm_text'] = $opt['text'];
if ( isset($opt['help']) ){
$r['perm_help'] = $opt['help'];
}
$sopt = $this->options->full_options($opt['id']);
$perm_chi = [];
foreach ( $sopt as $so ){
array_push($perm_chi, [
'perm_code' => $so['code'],
'perm_text' => $so['text']
]);
}
$r['perm_children'] = $perm_chi;
}
break;
}
}
if ( empty($mode) ){
$value = $cfg['extensions'][0]['default'];
}
}
}
// Timing problem is here, check out timer below and logs
// Do we need to have a single preference for each tab?
// Guilty: real_to_id takes 0.15 sec and is called 10+ times
$timer->start();
// User's preferences
if ( $is_file &&
$pref &&
($id_option = $this->options->from_code($this->real_to_id($real_file), $this->_files_pref()))
){
$o = $pref->get($id_option);
}
$timer->stop();
if ( empty($tab) && empty($cfg['url']) ){
$r['list'][0]['id_script'] = $this->real_to_id($real_file);
$r['list'][0]['cfg'] = [
'mode' => !empty($mode) ? $mode : $cfg['extensions'][0]['mode'],
'value' => empty($value) ? file_get_contents($real_file) : $value,
'selections' => !empty($o['selections']) ? $o['selections'] : [],
'marks' => !empty($o['marks']) ? $o['marks'] : []
];
}
else {
$r['id_script'] = $this->real_to_id($real_file);
$r['cfg'] = [
'mode' => !empty($mode) ? $mode : $cfg['extensions'][0]['mode'],
'value' => empty($value) ? file_get_contents($real_file) : $value,
'selections' => !empty($o['selections']) ? $o['selections'] : [],
'marks' => !empty($o['marks']) ? $o['marks'] : []
];
}
bbn\x::log($timer->results(), "directories");
return $r;
}
} | [
"protected",
"function",
"get_file",
"(",
"$",
"file",
",",
"$",
"dir",
",",
"$",
"tab",
",",
"array",
"$",
"cfg",
",",
"bbn",
"\\",
"user",
"\\",
"preferences",
"$",
"pref",
"=",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"cfg",
"[",
"'title'",
"]",
",",
"$",
"cfg",
"[",
"'bcolor'",
"]",
",",
"$",
"cfg",
"[",
"'fcolor'",
"]",
")",
")",
"{",
"/** @var string $name The file's name - without path and extension */",
"$",
"name",
"=",
"bbn",
"\\",
"str",
"::",
"file_ext",
"(",
"$",
"file",
",",
"1",
")",
"[",
"0",
"]",
";",
"/** @var string $ext The file's extension */",
"$",
"ext",
"=",
"bbn",
"\\",
"str",
"::",
"file_ext",
"(",
"$",
"file",
")",
";",
"/** @var string $path The file's path without file's name */",
"$",
"path",
"=",
"dirname",
"(",
"$",
"file",
")",
"!==",
"'.'",
"?",
"dirname",
"(",
"$",
"file",
")",
".",
"'/'",
":",
"''",
";",
"$",
"url",
"=",
"$",
"dir",
".",
"$",
"path",
".",
"$",
"name",
";",
"$",
"r",
"=",
"$",
"this",
"->",
"get_tab",
"(",
"$",
"url",
",",
"$",
"cfg",
"[",
"'title'",
"]",
",",
"$",
"cfg",
")",
";",
"$",
"timer",
"=",
"new",
"bbn",
"\\",
"util",
"\\",
"timer",
"(",
")",
";",
"/** @var string $root_path The real/actual path to the root directory */",
"$",
"root_path",
"=",
"$",
"this",
"->",
"get_root_path",
"(",
"$",
"dir",
")",
";",
"$",
"is_file",
"=",
"true",
";",
"// Normal Tab",
"if",
"(",
"empty",
"(",
"$",
"tab",
")",
"&&",
"empty",
"(",
"$",
"cfg",
"[",
"'url'",
"]",
")",
")",
"{",
"$",
"real_file",
"=",
"$",
"root_path",
".",
"$",
"file",
";",
"$",
"r",
"[",
"'url'",
"]",
"=",
"$",
"dir",
".",
"$",
"file",
";",
"$",
"r",
"[",
"'title'",
"]",
"=",
"$",
"file",
";",
"$",
"r",
"[",
"'list'",
"]",
"=",
"[",
"[",
"'bcolor'",
"=>",
"$",
"r",
"[",
"'bcolor'",
"]",
",",
"'fcolor'",
"=>",
"$",
"r",
"[",
"'fcolor'",
"]",
",",
"'title'",
"=>",
"'Code'",
",",
"'url'",
"=>",
"'code'",
",",
"'static'",
"=>",
"1",
",",
"'default'",
"=>",
"1",
",",
"'file'",
"=>",
"$",
"real_file",
"]",
"]",
";",
"//$r['file'] = $real_file;",
"foreach",
"(",
"$",
"cfg",
"[",
"'extensions'",
"]",
"as",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"e",
"[",
"'ext'",
"]",
"===",
"$",
"ext",
")",
"{",
"$",
"mode",
"=",
"$",
"e",
"[",
"'mode'",
"]",
";",
"}",
"}",
"if",
"(",
"!",
"is_file",
"(",
"$",
"real_file",
")",
")",
"{",
"$",
"is_file",
"=",
"false",
";",
"$",
"this",
"->",
"error",
"(",
"'Impossible to find the file '",
".",
"$",
"real_file",
")",
";",
"return",
"false",
";",
"}",
"}",
"// MVC's Tab",
"else",
"{",
"$",
"r",
"[",
"'url'",
"]",
"=",
"$",
"cfg",
"[",
"'url'",
"]",
";",
"$",
"r",
"[",
"'static'",
"]",
"=",
"1",
";",
"if",
"(",
"empty",
"(",
"$",
"tab",
")",
")",
"{",
"$",
"r",
"[",
"'default'",
"]",
"=",
"!",
"empty",
"(",
"$",
"cfg",
"[",
"'default'",
"]",
")",
"?",
"true",
":",
"false",
";",
"}",
"else",
"{",
"$",
"r",
"[",
"'default'",
"]",
"=",
"(",
"$",
"cfg",
"[",
"'url'",
"]",
"===",
"$",
"tab",
")",
"?",
"true",
":",
"false",
";",
"}",
"// _CTRL",
"if",
"(",
"!",
"empty",
"(",
"$",
"cfg",
"[",
"'fixed'",
"]",
")",
")",
"{",
"$",
"ext",
"=",
"bbn",
"\\",
"str",
"::",
"file_ext",
"(",
"$",
"cfg",
"[",
"'fixed'",
"]",
")",
";",
"foreach",
"(",
"$",
"cfg",
"[",
"'extensions'",
"]",
"as",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"e",
"[",
"'ext'",
"]",
"===",
"$",
"ext",
")",
"{",
"$",
"file",
"=",
"dirname",
"(",
"$",
"file",
")",
".",
"'/'",
".",
"$",
"cfg",
"[",
"'fixed'",
"]",
";",
"$",
"real_file",
"=",
"$",
"root_path",
".",
"$",
"file",
";",
"$",
"mode",
"=",
"$",
"e",
"[",
"'mode'",
"]",
";",
"$",
"r",
"[",
"'file'",
"]",
"=",
"$",
"real_file",
";",
"if",
"(",
"!",
"is_file",
"(",
"$",
"real_file",
")",
")",
"{",
"$",
"is_file",
"=",
"false",
";",
"$",
"value",
"=",
"$",
"e",
"[",
"'default'",
"]",
";",
"}",
"break",
";",
"}",
"}",
"}",
"else",
"{",
"foreach",
"(",
"$",
"cfg",
"[",
"'extensions'",
"]",
"as",
"$",
"e",
")",
"{",
"$",
"ext",
"=",
"$",
"e",
"[",
"'ext'",
"]",
";",
"/** @var string $real_file The absolute full path to the file */",
"$",
"real_file",
"=",
"$",
"root_path",
".",
"$",
"file",
".",
"'.'",
".",
"$",
"ext",
";",
"if",
"(",
"is_file",
"(",
"$",
"real_file",
")",
")",
"{",
"$",
"r",
"[",
"'file'",
"]",
"=",
"$",
"real_file",
";",
"$",
"mode",
"=",
"$",
"e",
"[",
"'mode'",
"]",
";",
"// Permissions",
"if",
"(",
"(",
"$",
"id_opt",
"=",
"$",
"this",
"->",
"real_to_perm",
"(",
"$",
"real_file",
")",
")",
"&&",
"(",
"$",
"opt",
"=",
"$",
"this",
"->",
"options",
"->",
"option",
"(",
"$",
"id_opt",
")",
")",
")",
"{",
"$",
"r",
"[",
"'perm_id'",
"]",
"=",
"$",
"opt",
"[",
"'id'",
"]",
";",
"$",
"r",
"[",
"'perm_code'",
"]",
"=",
"$",
"opt",
"[",
"'code'",
"]",
";",
"$",
"r",
"[",
"'perm_text'",
"]",
"=",
"$",
"opt",
"[",
"'text'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"opt",
"[",
"'help'",
"]",
")",
")",
"{",
"$",
"r",
"[",
"'perm_help'",
"]",
"=",
"$",
"opt",
"[",
"'help'",
"]",
";",
"}",
"$",
"sopt",
"=",
"$",
"this",
"->",
"options",
"->",
"full_options",
"(",
"$",
"opt",
"[",
"'id'",
"]",
")",
";",
"$",
"perm_chi",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"sopt",
"as",
"$",
"so",
")",
"{",
"array_push",
"(",
"$",
"perm_chi",
",",
"[",
"'perm_code'",
"=>",
"$",
"so",
"[",
"'code'",
"]",
",",
"'perm_text'",
"=>",
"$",
"so",
"[",
"'text'",
"]",
"]",
")",
";",
"}",
"$",
"r",
"[",
"'perm_children'",
"]",
"=",
"$",
"perm_chi",
";",
"}",
"break",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"mode",
")",
")",
"{",
"$",
"value",
"=",
"$",
"cfg",
"[",
"'extensions'",
"]",
"[",
"0",
"]",
"[",
"'default'",
"]",
";",
"}",
"}",
"}",
"// Timing problem is here, check out timer below and logs",
"// Do we need to have a single preference for each tab?",
"// Guilty: real_to_id takes 0.15 sec and is called 10+ times",
"$",
"timer",
"->",
"start",
"(",
")",
";",
"// User's preferences",
"if",
"(",
"$",
"is_file",
"&&",
"$",
"pref",
"&&",
"(",
"$",
"id_option",
"=",
"$",
"this",
"->",
"options",
"->",
"from_code",
"(",
"$",
"this",
"->",
"real_to_id",
"(",
"$",
"real_file",
")",
",",
"$",
"this",
"->",
"_files_pref",
"(",
")",
")",
")",
")",
"{",
"$",
"o",
"=",
"$",
"pref",
"->",
"get",
"(",
"$",
"id_option",
")",
";",
"}",
"$",
"timer",
"->",
"stop",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"tab",
")",
"&&",
"empty",
"(",
"$",
"cfg",
"[",
"'url'",
"]",
")",
")",
"{",
"$",
"r",
"[",
"'list'",
"]",
"[",
"0",
"]",
"[",
"'id_script'",
"]",
"=",
"$",
"this",
"->",
"real_to_id",
"(",
"$",
"real_file",
")",
";",
"$",
"r",
"[",
"'list'",
"]",
"[",
"0",
"]",
"[",
"'cfg'",
"]",
"=",
"[",
"'mode'",
"=>",
"!",
"empty",
"(",
"$",
"mode",
")",
"?",
"$",
"mode",
":",
"$",
"cfg",
"[",
"'extensions'",
"]",
"[",
"0",
"]",
"[",
"'mode'",
"]",
",",
"'value'",
"=>",
"empty",
"(",
"$",
"value",
")",
"?",
"file_get_contents",
"(",
"$",
"real_file",
")",
":",
"$",
"value",
",",
"'selections'",
"=>",
"!",
"empty",
"(",
"$",
"o",
"[",
"'selections'",
"]",
")",
"?",
"$",
"o",
"[",
"'selections'",
"]",
":",
"[",
"]",
",",
"'marks'",
"=>",
"!",
"empty",
"(",
"$",
"o",
"[",
"'marks'",
"]",
")",
"?",
"$",
"o",
"[",
"'marks'",
"]",
":",
"[",
"]",
"]",
";",
"}",
"else",
"{",
"$",
"r",
"[",
"'id_script'",
"]",
"=",
"$",
"this",
"->",
"real_to_id",
"(",
"$",
"real_file",
")",
";",
"$",
"r",
"[",
"'cfg'",
"]",
"=",
"[",
"'mode'",
"=>",
"!",
"empty",
"(",
"$",
"mode",
")",
"?",
"$",
"mode",
":",
"$",
"cfg",
"[",
"'extensions'",
"]",
"[",
"0",
"]",
"[",
"'mode'",
"]",
",",
"'value'",
"=>",
"empty",
"(",
"$",
"value",
")",
"?",
"file_get_contents",
"(",
"$",
"real_file",
")",
":",
"$",
"value",
",",
"'selections'",
"=>",
"!",
"empty",
"(",
"$",
"o",
"[",
"'selections'",
"]",
")",
"?",
"$",
"o",
"[",
"'selections'",
"]",
":",
"[",
"]",
",",
"'marks'",
"=>",
"!",
"empty",
"(",
"$",
"o",
"[",
"'marks'",
"]",
")",
"?",
"$",
"o",
"[",
"'marks'",
"]",
":",
"[",
"]",
"]",
";",
"}",
"bbn",
"\\",
"x",
"::",
"log",
"(",
"$",
"timer",
"->",
"results",
"(",
")",
",",
"\"directories\"",
")",
";",
"return",
"$",
"r",
";",
"}",
"}"
] | Gets a file
@param string $file
@param string $dir
@param string $tab
@param array $cfg
@param bbn\user\preferences|null $pref
@return array | [
"Gets",
"a",
"file"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/ide/directories.php#L727-L865 |
nabab/bbn | src/bbn/ide/directories.php | directories.save | public function save($file, $code, array $cfg = null, bbn\user\preferences $pref = null){
die(var_dump($file, $code, $cfg ));
if ( ($file = bbn\str::parse_path($file)) &&
($real = $this->url_to_real($file)) &&
($dir = $this->dir($this->dir_from_url($file))) &&
\defined('BBN_USER_PATH')
){
$id_file = $this->real_to_id($real);
$ext = bbn\str::file_ext($real, 1);
$id_user = false;
if ( $session = bbn\user\session::get_instance() ){
$id_user = $session->get('user', 'id');
}
// We delete the file if code is empty and we aren't in a _ctrl file
if ( empty($code) ){
$bits = explode('/', $file);
if ( !empty($dir['tabs']) && !empty($bits) ){
$tab = $this->superior_sctrl(array_pop($bits))['tab'];
if ( !empty($dir['tabs'][$tab]) &&
empty($dir['tabs'][$tab]['fixed'])
){
if ( @unlink($real) ){
// Remove permissions
$this->delete_perm($real);
if ( $id_file ){
// Remove file's options
$this->options->remove($this->options->from_code($id_file, $this->_files_pref()));
// Remove ide backups
bbn\file\dir::delete(dirname(BBN_USER_PATH."ide/backup/$id_file")."/$ext[0]/", 1);
}
return [
'deleted' => 1
];
}
}
}
}
if ( is_file($real) && $id_file ){
$filename = empty($dir['tabs']) ? $ext[0].'.'.$ext[1] : $ext[0];
$backup = dirname(BBN_USER_PATH."ide/backup/".$id_file).'/'.$filename.'/'.date('Y-m-d His').'.'.$ext[1];
bbn\file\dir::create_path(dirname($backup));
rename($real, $backup);
}
else if ( !is_dir(dirname($real)) ){
bbn\file\dir::create_path(dirname($real));
}
file_put_contents($real, $code);
if ( $pref && $id_user ){
$this->set_preferences($id_user, $id_file, md5($code), $cfg, $pref);
}
return [
'success' => 1,
'path' => $real
];
}
return $this->error('Error: Save');
} | php | public function save($file, $code, array $cfg = null, bbn\user\preferences $pref = null){
die(var_dump($file, $code, $cfg ));
if ( ($file = bbn\str::parse_path($file)) &&
($real = $this->url_to_real($file)) &&
($dir = $this->dir($this->dir_from_url($file))) &&
\defined('BBN_USER_PATH')
){
$id_file = $this->real_to_id($real);
$ext = bbn\str::file_ext($real, 1);
$id_user = false;
if ( $session = bbn\user\session::get_instance() ){
$id_user = $session->get('user', 'id');
}
// We delete the file if code is empty and we aren't in a _ctrl file
if ( empty($code) ){
$bits = explode('/', $file);
if ( !empty($dir['tabs']) && !empty($bits) ){
$tab = $this->superior_sctrl(array_pop($bits))['tab'];
if ( !empty($dir['tabs'][$tab]) &&
empty($dir['tabs'][$tab]['fixed'])
){
if ( @unlink($real) ){
// Remove permissions
$this->delete_perm($real);
if ( $id_file ){
// Remove file's options
$this->options->remove($this->options->from_code($id_file, $this->_files_pref()));
// Remove ide backups
bbn\file\dir::delete(dirname(BBN_USER_PATH."ide/backup/$id_file")."/$ext[0]/", 1);
}
return [
'deleted' => 1
];
}
}
}
}
if ( is_file($real) && $id_file ){
$filename = empty($dir['tabs']) ? $ext[0].'.'.$ext[1] : $ext[0];
$backup = dirname(BBN_USER_PATH."ide/backup/".$id_file).'/'.$filename.'/'.date('Y-m-d His').'.'.$ext[1];
bbn\file\dir::create_path(dirname($backup));
rename($real, $backup);
}
else if ( !is_dir(dirname($real)) ){
bbn\file\dir::create_path(dirname($real));
}
file_put_contents($real, $code);
if ( $pref && $id_user ){
$this->set_preferences($id_user, $id_file, md5($code), $cfg, $pref);
}
return [
'success' => 1,
'path' => $real
];
}
return $this->error('Error: Save');
} | [
"public",
"function",
"save",
"(",
"$",
"file",
",",
"$",
"code",
",",
"array",
"$",
"cfg",
"=",
"null",
",",
"bbn",
"\\",
"user",
"\\",
"preferences",
"$",
"pref",
"=",
"null",
")",
"{",
"die",
"(",
"var_dump",
"(",
"$",
"file",
",",
"$",
"code",
",",
"$",
"cfg",
")",
")",
";",
"if",
"(",
"(",
"$",
"file",
"=",
"bbn",
"\\",
"str",
"::",
"parse_path",
"(",
"$",
"file",
")",
")",
"&&",
"(",
"$",
"real",
"=",
"$",
"this",
"->",
"url_to_real",
"(",
"$",
"file",
")",
")",
"&&",
"(",
"$",
"dir",
"=",
"$",
"this",
"->",
"dir",
"(",
"$",
"this",
"->",
"dir_from_url",
"(",
"$",
"file",
")",
")",
")",
"&&",
"\\",
"defined",
"(",
"'BBN_USER_PATH'",
")",
")",
"{",
"$",
"id_file",
"=",
"$",
"this",
"->",
"real_to_id",
"(",
"$",
"real",
")",
";",
"$",
"ext",
"=",
"bbn",
"\\",
"str",
"::",
"file_ext",
"(",
"$",
"real",
",",
"1",
")",
";",
"$",
"id_user",
"=",
"false",
";",
"if",
"(",
"$",
"session",
"=",
"bbn",
"\\",
"user",
"\\",
"session",
"::",
"get_instance",
"(",
")",
")",
"{",
"$",
"id_user",
"=",
"$",
"session",
"->",
"get",
"(",
"'user'",
",",
"'id'",
")",
";",
"}",
"// We delete the file if code is empty and we aren't in a _ctrl file",
"if",
"(",
"empty",
"(",
"$",
"code",
")",
")",
"{",
"$",
"bits",
"=",
"explode",
"(",
"'/'",
",",
"$",
"file",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"dir",
"[",
"'tabs'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"bits",
")",
")",
"{",
"$",
"tab",
"=",
"$",
"this",
"->",
"superior_sctrl",
"(",
"array_pop",
"(",
"$",
"bits",
")",
")",
"[",
"'tab'",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"dir",
"[",
"'tabs'",
"]",
"[",
"$",
"tab",
"]",
")",
"&&",
"empty",
"(",
"$",
"dir",
"[",
"'tabs'",
"]",
"[",
"$",
"tab",
"]",
"[",
"'fixed'",
"]",
")",
")",
"{",
"if",
"(",
"@",
"unlink",
"(",
"$",
"real",
")",
")",
"{",
"// Remove permissions",
"$",
"this",
"->",
"delete_perm",
"(",
"$",
"real",
")",
";",
"if",
"(",
"$",
"id_file",
")",
"{",
"// Remove file's options",
"$",
"this",
"->",
"options",
"->",
"remove",
"(",
"$",
"this",
"->",
"options",
"->",
"from_code",
"(",
"$",
"id_file",
",",
"$",
"this",
"->",
"_files_pref",
"(",
")",
")",
")",
";",
"// Remove ide backups",
"bbn",
"\\",
"file",
"\\",
"dir",
"::",
"delete",
"(",
"dirname",
"(",
"BBN_USER_PATH",
".",
"\"ide/backup/$id_file\"",
")",
".",
"\"/$ext[0]/\"",
",",
"1",
")",
";",
"}",
"return",
"[",
"'deleted'",
"=>",
"1",
"]",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"is_file",
"(",
"$",
"real",
")",
"&&",
"$",
"id_file",
")",
"{",
"$",
"filename",
"=",
"empty",
"(",
"$",
"dir",
"[",
"'tabs'",
"]",
")",
"?",
"$",
"ext",
"[",
"0",
"]",
".",
"'.'",
".",
"$",
"ext",
"[",
"1",
"]",
":",
"$",
"ext",
"[",
"0",
"]",
";",
"$",
"backup",
"=",
"dirname",
"(",
"BBN_USER_PATH",
".",
"\"ide/backup/\"",
".",
"$",
"id_file",
")",
".",
"'/'",
".",
"$",
"filename",
".",
"'/'",
".",
"date",
"(",
"'Y-m-d His'",
")",
".",
"'.'",
".",
"$",
"ext",
"[",
"1",
"]",
";",
"bbn",
"\\",
"file",
"\\",
"dir",
"::",
"create_path",
"(",
"dirname",
"(",
"$",
"backup",
")",
")",
";",
"rename",
"(",
"$",
"real",
",",
"$",
"backup",
")",
";",
"}",
"else",
"if",
"(",
"!",
"is_dir",
"(",
"dirname",
"(",
"$",
"real",
")",
")",
")",
"{",
"bbn",
"\\",
"file",
"\\",
"dir",
"::",
"create_path",
"(",
"dirname",
"(",
"$",
"real",
")",
")",
";",
"}",
"file_put_contents",
"(",
"$",
"real",
",",
"$",
"code",
")",
";",
"if",
"(",
"$",
"pref",
"&&",
"$",
"id_user",
")",
"{",
"$",
"this",
"->",
"set_preferences",
"(",
"$",
"id_user",
",",
"$",
"id_file",
",",
"md5",
"(",
"$",
"code",
")",
",",
"$",
"cfg",
",",
"$",
"pref",
")",
";",
"}",
"return",
"[",
"'success'",
"=>",
"1",
",",
"'path'",
"=>",
"$",
"real",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"error",
"(",
"'Error: Save'",
")",
";",
"}"
] | Saves a file.
@param string $file The file's URL
@param string $code The file's content
@param array|null $cfg The user preferences
@param bbn\user\preferences|null $pref
@return array|void | [
"Saves",
"a",
"file",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/ide/directories.php#L876-L932 |
nabab/bbn | src/bbn/ide/directories.php | directories.set_preferences | public function set_preferences($id_user, $id_file, $md5, array $cfg = null, bbn\user\preferences $pref = null){
if ( !empty($id_user) && !empty($id_file) && !empty($pref) ){
$change['md5'] = $md5;
if ( !empty($cfg['selections']) ){
$change['selections'] = $cfg['selections'];
}
if ( isset($cfg, $cfg['marks']) ){
$change['marks'] = $cfg['marks'];
}
if ( !empty($change) ){
$id_option = $this->option_id($id_file);
if ( $pref->set($id_option, $change, $id_user) ){
return true;
}
}
}
return false;
} | php | public function set_preferences($id_user, $id_file, $md5, array $cfg = null, bbn\user\preferences $pref = null){
if ( !empty($id_user) && !empty($id_file) && !empty($pref) ){
$change['md5'] = $md5;
if ( !empty($cfg['selections']) ){
$change['selections'] = $cfg['selections'];
}
if ( isset($cfg, $cfg['marks']) ){
$change['marks'] = $cfg['marks'];
}
if ( !empty($change) ){
$id_option = $this->option_id($id_file);
if ( $pref->set($id_option, $change, $id_user) ){
return true;
}
}
}
return false;
} | [
"public",
"function",
"set_preferences",
"(",
"$",
"id_user",
",",
"$",
"id_file",
",",
"$",
"md5",
",",
"array",
"$",
"cfg",
"=",
"null",
",",
"bbn",
"\\",
"user",
"\\",
"preferences",
"$",
"pref",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"id_user",
")",
"&&",
"!",
"empty",
"(",
"$",
"id_file",
")",
"&&",
"!",
"empty",
"(",
"$",
"pref",
")",
")",
"{",
"$",
"change",
"[",
"'md5'",
"]",
"=",
"$",
"md5",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"cfg",
"[",
"'selections'",
"]",
")",
")",
"{",
"$",
"change",
"[",
"'selections'",
"]",
"=",
"$",
"cfg",
"[",
"'selections'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"cfg",
",",
"$",
"cfg",
"[",
"'marks'",
"]",
")",
")",
"{",
"$",
"change",
"[",
"'marks'",
"]",
"=",
"$",
"cfg",
"[",
"'marks'",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"change",
")",
")",
"{",
"$",
"id_option",
"=",
"$",
"this",
"->",
"option_id",
"(",
"$",
"id_file",
")",
";",
"if",
"(",
"$",
"pref",
"->",
"set",
"(",
"$",
"id_option",
",",
"$",
"change",
",",
"$",
"id_user",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | Sets user's preferences for a file.
@param string $id_user The user's id
@param string $id_file The file's id
@param string $md5 The file's md5
@param array|null $cfg
@param bbn\user\preferences|null $pref
@return bool | [
"Sets",
"user",
"s",
"preferences",
"for",
"a",
"file",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/ide/directories.php#L944-L961 |
nabab/bbn | src/bbn/ide/directories.php | directories.copy | public function copy($dir, $path, $name, $type, $file){
if ( ($cfg = $this->dir($dir)) &&
($root = $this->get_root_path($dir)) &&
bbn\str::check_filename($name)
){
$is_file = $type === 'file';
$wtype = $is_file ? 'file' : 'directory';
$path = $path === './' ? '' : $path . '/';
$bits = explode('/', $file);
// File cfg
$file_cfg = bbn\str::file_ext(array_pop($bits), 1);
// Existing filename without its extension
$fn = $file_cfg[0];
// Existing file's extension
$fe = $file_cfg[1];
// Existing file's path
$fp = implode('/', $bits);
$files = [];
$ext = false;
// MVC
if ( !empty($cfg['tabs']) ){
foreach ( $cfg['tabs'] as $t ){
if (empty($t['fixed']) ){
if ( $is_file ){
// Check all extensions
foreach ( $t['extensions'] as $e ){
$real = $root . $t['path'] . $fp . '/' . $fn . '.' . $e['ext'];
$real_new = $root. $t['path'] . $path . $name . '.' . $e['ext'];
if( file_exists($real) ){
if ( !file_exists($real_new) ){
$files[$real] = $real_new;
$ext = empty($ext) ? $e['ext'] : $ext;
if ( $t['url'] === 'php' ){
$perms = $real_new;
}
}
else {
$this->error("The file $real_new is already exists.");
return false;
}
}
}
}
else {
$real = $root . $t['path'] . $fp . '/' . $fn;
$real_new = $root. $t['path'] . $path . $name;
if ( file_exists($real) ){
if ( !file_exists($real_new) ){
$files[$real] = $real_new;
if ( $t['url'] === 'php' ){
$perms = $real_new;
}
}
else {
$this->error("The directory $real_new is already exists.");
return false;
}
}
}
}
}
}
else {
$real = $root . $file;
$real_new = $root. $path . $name . '.' . $fe;
if ( file_exists($real) ){
if ( !file_exists($real_new) ){
$files[$real] = $real_new;
}
else {
$this->error("The $wtype $real_new is already exists.");
return false;
}
}
}
foreach ($files as $s => $d ){
if ( !file_exists(dirname($d)) ){
if ( !bbn\file\dir::create_path(dirname($d)) ){
$this->error("Impossible to create the path $d");
return false;
}
}
if ( !bbn\file\dir::copy($s, $d) ){
$this->error("Impossible to duplicate the $wtype: $s -> $d");
return false;
}
}
// Create permissions
if ( !empty($perms) ){
if ( $is_file ){
self::create_perm_by_real($perms);
}
else {
$dir_perms = function($fd) use(&$dir_perms){
foreach ( $fd as $f ){
if ( is_file($f) &&
(basename($f) !== '_ctrl.php')
){
self::create_perm_by_real($f);
}
else if ( is_dir($f) ){
$dir_perms(bbn\file\dir::get_files($f, 1));
}
}
};
$dir_perms(bbn\file\dir::get_files($perms, 1));
}
}
if ( $is_file ){
return (!empty($path) ? $path : '') . $name . '.' . (!empty($cfg['tabs']) ? $ext : $fe);
}
return true;
}
return false;
} | php | public function copy($dir, $path, $name, $type, $file){
if ( ($cfg = $this->dir($dir)) &&
($root = $this->get_root_path($dir)) &&
bbn\str::check_filename($name)
){
$is_file = $type === 'file';
$wtype = $is_file ? 'file' : 'directory';
$path = $path === './' ? '' : $path . '/';
$bits = explode('/', $file);
// File cfg
$file_cfg = bbn\str::file_ext(array_pop($bits), 1);
// Existing filename without its extension
$fn = $file_cfg[0];
// Existing file's extension
$fe = $file_cfg[1];
// Existing file's path
$fp = implode('/', $bits);
$files = [];
$ext = false;
// MVC
if ( !empty($cfg['tabs']) ){
foreach ( $cfg['tabs'] as $t ){
if (empty($t['fixed']) ){
if ( $is_file ){
// Check all extensions
foreach ( $t['extensions'] as $e ){
$real = $root . $t['path'] . $fp . '/' . $fn . '.' . $e['ext'];
$real_new = $root. $t['path'] . $path . $name . '.' . $e['ext'];
if( file_exists($real) ){
if ( !file_exists($real_new) ){
$files[$real] = $real_new;
$ext = empty($ext) ? $e['ext'] : $ext;
if ( $t['url'] === 'php' ){
$perms = $real_new;
}
}
else {
$this->error("The file $real_new is already exists.");
return false;
}
}
}
}
else {
$real = $root . $t['path'] . $fp . '/' . $fn;
$real_new = $root. $t['path'] . $path . $name;
if ( file_exists($real) ){
if ( !file_exists($real_new) ){
$files[$real] = $real_new;
if ( $t['url'] === 'php' ){
$perms = $real_new;
}
}
else {
$this->error("The directory $real_new is already exists.");
return false;
}
}
}
}
}
}
else {
$real = $root . $file;
$real_new = $root. $path . $name . '.' . $fe;
if ( file_exists($real) ){
if ( !file_exists($real_new) ){
$files[$real] = $real_new;
}
else {
$this->error("The $wtype $real_new is already exists.");
return false;
}
}
}
foreach ($files as $s => $d ){
if ( !file_exists(dirname($d)) ){
if ( !bbn\file\dir::create_path(dirname($d)) ){
$this->error("Impossible to create the path $d");
return false;
}
}
if ( !bbn\file\dir::copy($s, $d) ){
$this->error("Impossible to duplicate the $wtype: $s -> $d");
return false;
}
}
// Create permissions
if ( !empty($perms) ){
if ( $is_file ){
self::create_perm_by_real($perms);
}
else {
$dir_perms = function($fd) use(&$dir_perms){
foreach ( $fd as $f ){
if ( is_file($f) &&
(basename($f) !== '_ctrl.php')
){
self::create_perm_by_real($f);
}
else if ( is_dir($f) ){
$dir_perms(bbn\file\dir::get_files($f, 1));
}
}
};
$dir_perms(bbn\file\dir::get_files($perms, 1));
}
}
if ( $is_file ){
return (!empty($path) ? $path : '') . $name . '.' . (!empty($cfg['tabs']) ? $ext : $fe);
}
return true;
}
return false;
} | [
"public",
"function",
"copy",
"(",
"$",
"dir",
",",
"$",
"path",
",",
"$",
"name",
",",
"$",
"type",
",",
"$",
"file",
")",
"{",
"if",
"(",
"(",
"$",
"cfg",
"=",
"$",
"this",
"->",
"dir",
"(",
"$",
"dir",
")",
")",
"&&",
"(",
"$",
"root",
"=",
"$",
"this",
"->",
"get_root_path",
"(",
"$",
"dir",
")",
")",
"&&",
"bbn",
"\\",
"str",
"::",
"check_filename",
"(",
"$",
"name",
")",
")",
"{",
"$",
"is_file",
"=",
"$",
"type",
"===",
"'file'",
";",
"$",
"wtype",
"=",
"$",
"is_file",
"?",
"'file'",
":",
"'directory'",
";",
"$",
"path",
"=",
"$",
"path",
"===",
"'./'",
"?",
"''",
":",
"$",
"path",
".",
"'/'",
";",
"$",
"bits",
"=",
"explode",
"(",
"'/'",
",",
"$",
"file",
")",
";",
"// File cfg",
"$",
"file_cfg",
"=",
"bbn",
"\\",
"str",
"::",
"file_ext",
"(",
"array_pop",
"(",
"$",
"bits",
")",
",",
"1",
")",
";",
"// Existing filename without its extension",
"$",
"fn",
"=",
"$",
"file_cfg",
"[",
"0",
"]",
";",
"// Existing file's extension",
"$",
"fe",
"=",
"$",
"file_cfg",
"[",
"1",
"]",
";",
"// Existing file's path",
"$",
"fp",
"=",
"implode",
"(",
"'/'",
",",
"$",
"bits",
")",
";",
"$",
"files",
"=",
"[",
"]",
";",
"$",
"ext",
"=",
"false",
";",
"// MVC",
"if",
"(",
"!",
"empty",
"(",
"$",
"cfg",
"[",
"'tabs'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"cfg",
"[",
"'tabs'",
"]",
"as",
"$",
"t",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"t",
"[",
"'fixed'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"is_file",
")",
"{",
"// Check all extensions",
"foreach",
"(",
"$",
"t",
"[",
"'extensions'",
"]",
"as",
"$",
"e",
")",
"{",
"$",
"real",
"=",
"$",
"root",
".",
"$",
"t",
"[",
"'path'",
"]",
".",
"$",
"fp",
".",
"'/'",
".",
"$",
"fn",
".",
"'.'",
".",
"$",
"e",
"[",
"'ext'",
"]",
";",
"$",
"real_new",
"=",
"$",
"root",
".",
"$",
"t",
"[",
"'path'",
"]",
".",
"$",
"path",
".",
"$",
"name",
".",
"'.'",
".",
"$",
"e",
"[",
"'ext'",
"]",
";",
"if",
"(",
"file_exists",
"(",
"$",
"real",
")",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"real_new",
")",
")",
"{",
"$",
"files",
"[",
"$",
"real",
"]",
"=",
"$",
"real_new",
";",
"$",
"ext",
"=",
"empty",
"(",
"$",
"ext",
")",
"?",
"$",
"e",
"[",
"'ext'",
"]",
":",
"$",
"ext",
";",
"if",
"(",
"$",
"t",
"[",
"'url'",
"]",
"===",
"'php'",
")",
"{",
"$",
"perms",
"=",
"$",
"real_new",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"error",
"(",
"\"The file $real_new is already exists.\"",
")",
";",
"return",
"false",
";",
"}",
"}",
"}",
"}",
"else",
"{",
"$",
"real",
"=",
"$",
"root",
".",
"$",
"t",
"[",
"'path'",
"]",
".",
"$",
"fp",
".",
"'/'",
".",
"$",
"fn",
";",
"$",
"real_new",
"=",
"$",
"root",
".",
"$",
"t",
"[",
"'path'",
"]",
".",
"$",
"path",
".",
"$",
"name",
";",
"if",
"(",
"file_exists",
"(",
"$",
"real",
")",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"real_new",
")",
")",
"{",
"$",
"files",
"[",
"$",
"real",
"]",
"=",
"$",
"real_new",
";",
"if",
"(",
"$",
"t",
"[",
"'url'",
"]",
"===",
"'php'",
")",
"{",
"$",
"perms",
"=",
"$",
"real_new",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"error",
"(",
"\"The directory $real_new is already exists.\"",
")",
";",
"return",
"false",
";",
"}",
"}",
"}",
"}",
"}",
"}",
"else",
"{",
"$",
"real",
"=",
"$",
"root",
".",
"$",
"file",
";",
"$",
"real_new",
"=",
"$",
"root",
".",
"$",
"path",
".",
"$",
"name",
".",
"'.'",
".",
"$",
"fe",
";",
"if",
"(",
"file_exists",
"(",
"$",
"real",
")",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"real_new",
")",
")",
"{",
"$",
"files",
"[",
"$",
"real",
"]",
"=",
"$",
"real_new",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"error",
"(",
"\"The $wtype $real_new is already exists.\"",
")",
";",
"return",
"false",
";",
"}",
"}",
"}",
"foreach",
"(",
"$",
"files",
"as",
"$",
"s",
"=>",
"$",
"d",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"dirname",
"(",
"$",
"d",
")",
")",
")",
"{",
"if",
"(",
"!",
"bbn",
"\\",
"file",
"\\",
"dir",
"::",
"create_path",
"(",
"dirname",
"(",
"$",
"d",
")",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"\"Impossible to create the path $d\"",
")",
";",
"return",
"false",
";",
"}",
"}",
"if",
"(",
"!",
"bbn",
"\\",
"file",
"\\",
"dir",
"::",
"copy",
"(",
"$",
"s",
",",
"$",
"d",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"\"Impossible to duplicate the $wtype: $s -> $d\"",
")",
";",
"return",
"false",
";",
"}",
"}",
"// Create permissions",
"if",
"(",
"!",
"empty",
"(",
"$",
"perms",
")",
")",
"{",
"if",
"(",
"$",
"is_file",
")",
"{",
"self",
"::",
"create_perm_by_real",
"(",
"$",
"perms",
")",
";",
"}",
"else",
"{",
"$",
"dir_perms",
"=",
"function",
"(",
"$",
"fd",
")",
"use",
"(",
"&",
"$",
"dir_perms",
")",
"{",
"foreach",
"(",
"$",
"fd",
"as",
"$",
"f",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"f",
")",
"&&",
"(",
"basename",
"(",
"$",
"f",
")",
"!==",
"'_ctrl.php'",
")",
")",
"{",
"self",
"::",
"create_perm_by_real",
"(",
"$",
"f",
")",
";",
"}",
"else",
"if",
"(",
"is_dir",
"(",
"$",
"f",
")",
")",
"{",
"$",
"dir_perms",
"(",
"bbn",
"\\",
"file",
"\\",
"dir",
"::",
"get_files",
"(",
"$",
"f",
",",
"1",
")",
")",
";",
"}",
"}",
"}",
";",
"$",
"dir_perms",
"(",
"bbn",
"\\",
"file",
"\\",
"dir",
"::",
"get_files",
"(",
"$",
"perms",
",",
"1",
")",
")",
";",
"}",
"}",
"if",
"(",
"$",
"is_file",
")",
"{",
"return",
"(",
"!",
"empty",
"(",
"$",
"path",
")",
"?",
"$",
"path",
":",
"''",
")",
".",
"$",
"name",
".",
"'.'",
".",
"(",
"!",
"empty",
"(",
"$",
"cfg",
"[",
"'tabs'",
"]",
")",
"?",
"$",
"ext",
":",
"$",
"fe",
")",
";",
"}",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Duplicates a file or a directory, MVC or not.
@param string $dir The source's name
@param string $path The new file's path
@param string $name The new filename
@param string $type file|dir
@param string $file The existing file path and name
@return bool|string
@todo Duplicate the users' permissions when duplicating a controller file | [
"Duplicates",
"a",
"file",
"or",
"a",
"directory",
"MVC",
"or",
"not",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/ide/directories.php#L974-L1090 |
nabab/bbn | src/bbn/ide/directories.php | directories.delete | public function delete($dir, $path, $name, $type = 'file'){
if ( ($cfg = $this->dir($dir)) &&
($root = $this->get_root_path($dir))
){
$is_file = $type === 'file';
$wtype = $is_file ? 'file' : 'directory';
$delete = [];
if ( !empty($cfg['tabs']) ){
foreach ( $cfg['tabs'] as $t ){
if ( empty($t['fixed']) ){
$real = $root . $t['path'];
if ( dirname($path) !== '.' ){
$real .= dirname($path) . '/';
}
if ( $is_file ){
foreach ( $t['extensions'] as $e ){
$tmp = $real . $name . '.' . $e['ext'];
if ( file_exists($tmp) && !\in_array($tmp, $delete) ){
array_push($delete, $tmp);
if ( $t['url'] === 'php' ){
$del_perm = $tmp;
}
}
}
}
else {
$real .= $name;
if ( file_exists($real) && !\in_array($real, $delete) ){
array_push($delete, $real);
if ( $t['url'] === 'php' ){
$del_perm = $real;
}
}
}
}
}
}
else {
$real = $root . $path;
if ( file_exists($real) ){
array_push($delete, $real);
}
}
$files = [];
// Remove permissions
if ( !empty($del_perm) ){
$this->delete_perm($del_perm, $type);
}
foreach ( $delete as $d ){
if ( $is_file ){
// Add it to files to be closed
array_push($files, $this->real_to_url($d));
// Delete file
if ( !unlink($d) ){
$this->error("Impossible to delete the file $d");
return false;
}
// Remove file's options
$this->options->remove($this->options->from_code($this->real_to_id($d), $this->_files_pref()));
}
else {
$f = $this->rem_dir_opt($d);
$files = array_merge($files, $f);
// Delete directory
if ( !bbn\file\dir::delete($d) ){
$this->error("Impossible to delete the directory $d");
return false;
}
}
}
return ['files' => $files];
}
return false;
} | php | public function delete($dir, $path, $name, $type = 'file'){
if ( ($cfg = $this->dir($dir)) &&
($root = $this->get_root_path($dir))
){
$is_file = $type === 'file';
$wtype = $is_file ? 'file' : 'directory';
$delete = [];
if ( !empty($cfg['tabs']) ){
foreach ( $cfg['tabs'] as $t ){
if ( empty($t['fixed']) ){
$real = $root . $t['path'];
if ( dirname($path) !== '.' ){
$real .= dirname($path) . '/';
}
if ( $is_file ){
foreach ( $t['extensions'] as $e ){
$tmp = $real . $name . '.' . $e['ext'];
if ( file_exists($tmp) && !\in_array($tmp, $delete) ){
array_push($delete, $tmp);
if ( $t['url'] === 'php' ){
$del_perm = $tmp;
}
}
}
}
else {
$real .= $name;
if ( file_exists($real) && !\in_array($real, $delete) ){
array_push($delete, $real);
if ( $t['url'] === 'php' ){
$del_perm = $real;
}
}
}
}
}
}
else {
$real = $root . $path;
if ( file_exists($real) ){
array_push($delete, $real);
}
}
$files = [];
// Remove permissions
if ( !empty($del_perm) ){
$this->delete_perm($del_perm, $type);
}
foreach ( $delete as $d ){
if ( $is_file ){
// Add it to files to be closed
array_push($files, $this->real_to_url($d));
// Delete file
if ( !unlink($d) ){
$this->error("Impossible to delete the file $d");
return false;
}
// Remove file's options
$this->options->remove($this->options->from_code($this->real_to_id($d), $this->_files_pref()));
}
else {
$f = $this->rem_dir_opt($d);
$files = array_merge($files, $f);
// Delete directory
if ( !bbn\file\dir::delete($d) ){
$this->error("Impossible to delete the directory $d");
return false;
}
}
}
return ['files' => $files];
}
return false;
} | [
"public",
"function",
"delete",
"(",
"$",
"dir",
",",
"$",
"path",
",",
"$",
"name",
",",
"$",
"type",
"=",
"'file'",
")",
"{",
"if",
"(",
"(",
"$",
"cfg",
"=",
"$",
"this",
"->",
"dir",
"(",
"$",
"dir",
")",
")",
"&&",
"(",
"$",
"root",
"=",
"$",
"this",
"->",
"get_root_path",
"(",
"$",
"dir",
")",
")",
")",
"{",
"$",
"is_file",
"=",
"$",
"type",
"===",
"'file'",
";",
"$",
"wtype",
"=",
"$",
"is_file",
"?",
"'file'",
":",
"'directory'",
";",
"$",
"delete",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"cfg",
"[",
"'tabs'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"cfg",
"[",
"'tabs'",
"]",
"as",
"$",
"t",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"t",
"[",
"'fixed'",
"]",
")",
")",
"{",
"$",
"real",
"=",
"$",
"root",
".",
"$",
"t",
"[",
"'path'",
"]",
";",
"if",
"(",
"dirname",
"(",
"$",
"path",
")",
"!==",
"'.'",
")",
"{",
"$",
"real",
".=",
"dirname",
"(",
"$",
"path",
")",
".",
"'/'",
";",
"}",
"if",
"(",
"$",
"is_file",
")",
"{",
"foreach",
"(",
"$",
"t",
"[",
"'extensions'",
"]",
"as",
"$",
"e",
")",
"{",
"$",
"tmp",
"=",
"$",
"real",
".",
"$",
"name",
".",
"'.'",
".",
"$",
"e",
"[",
"'ext'",
"]",
";",
"if",
"(",
"file_exists",
"(",
"$",
"tmp",
")",
"&&",
"!",
"\\",
"in_array",
"(",
"$",
"tmp",
",",
"$",
"delete",
")",
")",
"{",
"array_push",
"(",
"$",
"delete",
",",
"$",
"tmp",
")",
";",
"if",
"(",
"$",
"t",
"[",
"'url'",
"]",
"===",
"'php'",
")",
"{",
"$",
"del_perm",
"=",
"$",
"tmp",
";",
"}",
"}",
"}",
"}",
"else",
"{",
"$",
"real",
".=",
"$",
"name",
";",
"if",
"(",
"file_exists",
"(",
"$",
"real",
")",
"&&",
"!",
"\\",
"in_array",
"(",
"$",
"real",
",",
"$",
"delete",
")",
")",
"{",
"array_push",
"(",
"$",
"delete",
",",
"$",
"real",
")",
";",
"if",
"(",
"$",
"t",
"[",
"'url'",
"]",
"===",
"'php'",
")",
"{",
"$",
"del_perm",
"=",
"$",
"real",
";",
"}",
"}",
"}",
"}",
"}",
"}",
"else",
"{",
"$",
"real",
"=",
"$",
"root",
".",
"$",
"path",
";",
"if",
"(",
"file_exists",
"(",
"$",
"real",
")",
")",
"{",
"array_push",
"(",
"$",
"delete",
",",
"$",
"real",
")",
";",
"}",
"}",
"$",
"files",
"=",
"[",
"]",
";",
"// Remove permissions",
"if",
"(",
"!",
"empty",
"(",
"$",
"del_perm",
")",
")",
"{",
"$",
"this",
"->",
"delete_perm",
"(",
"$",
"del_perm",
",",
"$",
"type",
")",
";",
"}",
"foreach",
"(",
"$",
"delete",
"as",
"$",
"d",
")",
"{",
"if",
"(",
"$",
"is_file",
")",
"{",
"// Add it to files to be closed",
"array_push",
"(",
"$",
"files",
",",
"$",
"this",
"->",
"real_to_url",
"(",
"$",
"d",
")",
")",
";",
"// Delete file",
"if",
"(",
"!",
"unlink",
"(",
"$",
"d",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"\"Impossible to delete the file $d\"",
")",
";",
"return",
"false",
";",
"}",
"// Remove file's options",
"$",
"this",
"->",
"options",
"->",
"remove",
"(",
"$",
"this",
"->",
"options",
"->",
"from_code",
"(",
"$",
"this",
"->",
"real_to_id",
"(",
"$",
"d",
")",
",",
"$",
"this",
"->",
"_files_pref",
"(",
")",
")",
")",
";",
"}",
"else",
"{",
"$",
"f",
"=",
"$",
"this",
"->",
"rem_dir_opt",
"(",
"$",
"d",
")",
";",
"$",
"files",
"=",
"array_merge",
"(",
"$",
"files",
",",
"$",
"f",
")",
";",
"// Delete directory",
"if",
"(",
"!",
"bbn",
"\\",
"file",
"\\",
"dir",
"::",
"delete",
"(",
"$",
"d",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"\"Impossible to delete the directory $d\"",
")",
";",
"return",
"false",
";",
"}",
"}",
"}",
"return",
"[",
"'files'",
"=>",
"$",
"files",
"]",
";",
"}",
"return",
"false",
";",
"}"
] | Deletes a file or a directory.
@param string $dir The source's name
@param string $path The file|directory's path
@param string $name The file|directory's name
@param string $type The type (file|dir)
@return array|bool | [
"Deletes",
"a",
"file",
"or",
"a",
"directory",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/ide/directories.php#L1101-L1174 |
nabab/bbn | src/bbn/ide/directories.php | directories.export | public function export($dir, $path, $name, $type = 'file'){
if ( ($cfg = $this->dir($dir)) &&
($root = $this->get_root_path($dir)) &&
\defined('BBN_USER_PATH')
){
$is_file = $type === 'file';
$wtype = $is_file ? 'file' : 'directory';
$rnd = bbn\str::genpwd();
$root_dest = BBN_USER_PATH . 'tmp/' . $rnd . '/';
$files = [];
if ( !empty($cfg['tabs']) ){
$root_dest_mvc = $root_dest . $name . '/mvc/';
foreach ( $cfg['tabs'] as $t ){
if ( empty($t['fixed']) ){
$real = $t['path'];
if ( dirname($path) !== '.' ){
$real .= dirname($path) . '/';
}
if ( $is_file ){
foreach ( $t['extensions'] as $e ){
if ( is_file($root . $real . $name . '.' . $e['ext']) ){
$real .= $name . '.' . $e['ext'];
array_push($files, [
'src' => $root . $real,
'dest' => $root_dest_mvc . $real,
'is_file' => $is_file
]);
break;
}
}
}
else {
$real .= $name;
if ( is_dir($root . $real) ){
array_push($files, [
'src' =>$root . $real,
'dest' => $root_dest_mvc . $real,
'is_file' => $is_file
]);
}
}
}
}
}
else {
if ( file_exists($root . $path) ){
array_push($files, [
'src' => $root . $path,
'dest' => $root_dest . $path,
'is_file' => $is_file
]);
}
}
foreach ( $files as $f ){
if ( $f['is_file'] ){
if ( !bbn\file\dir::create_path(dirname($f['dest'])) ){
$this->error("Impossible to create the path " . dirname($f['dest']));
return false;
}
}
if ( !bbn\file\dir::copy($f['src'], $f['dest']) ){
$this->error('Impossible to export the ' . $wtype . ' ' . $f['src']);
return false;
}
}
if ( class_exists('\\ZipArchive') ){
$filezip = BBN_USER_PATH.'tmp/'.$name.'.zip';
$zip = new \ZipArchive();
if ( $err = $zip->open($filezip, \ZipArchive::OVERWRITE) ){
if ( file_exists($root_dest) ){
if ( (!$is_file) || !empty($cfg['tabs']) ){
// Create recursive directory iterator
$files = bbn\file\dir::scan($root_dest);
foreach ($files as $file){
$tmp_dest = str_replace(
$root_dest . (empty($cfg['tabs']) ? '/' : ''),
(!empty($cfg['tabs']) ? 'mvc/' : ''),
$file
);
// Add current file to archive
if ( ($file !== $root_dest.$name) &&
is_file($file) &&
!$zip->addFile($file, $tmp_dest)
){
$this->error("Impossible to add $file");
return false;
}
}
}
else {
if ( !$zip->addFile($root_dest, $path) ){
$this->error("Impossible to add $root_dest");
return false;
}
}
if ( $zip->close() ){
if ( !bbn\file\dir::delete(BBN_USER_PATH . 'tmp/' . $rnd, 1) ){
$this->error("Impossible to delete the directory " . BBN_USER_PATH . 'tmp/' . $rnd);
return false;
}
return $filezip;
}
$this->error("Impossible to close the zip file $filezip");
return false;
}
$this->error("The path does not exist: $root_dest");
return false;
}
$this->error("Impossible to create $filezip ($err)");
return false;
}
$this->error("ZipArchive class non-existent");
return false;
}
} | php | public function export($dir, $path, $name, $type = 'file'){
if ( ($cfg = $this->dir($dir)) &&
($root = $this->get_root_path($dir)) &&
\defined('BBN_USER_PATH')
){
$is_file = $type === 'file';
$wtype = $is_file ? 'file' : 'directory';
$rnd = bbn\str::genpwd();
$root_dest = BBN_USER_PATH . 'tmp/' . $rnd . '/';
$files = [];
if ( !empty($cfg['tabs']) ){
$root_dest_mvc = $root_dest . $name . '/mvc/';
foreach ( $cfg['tabs'] as $t ){
if ( empty($t['fixed']) ){
$real = $t['path'];
if ( dirname($path) !== '.' ){
$real .= dirname($path) . '/';
}
if ( $is_file ){
foreach ( $t['extensions'] as $e ){
if ( is_file($root . $real . $name . '.' . $e['ext']) ){
$real .= $name . '.' . $e['ext'];
array_push($files, [
'src' => $root . $real,
'dest' => $root_dest_mvc . $real,
'is_file' => $is_file
]);
break;
}
}
}
else {
$real .= $name;
if ( is_dir($root . $real) ){
array_push($files, [
'src' =>$root . $real,
'dest' => $root_dest_mvc . $real,
'is_file' => $is_file
]);
}
}
}
}
}
else {
if ( file_exists($root . $path) ){
array_push($files, [
'src' => $root . $path,
'dest' => $root_dest . $path,
'is_file' => $is_file
]);
}
}
foreach ( $files as $f ){
if ( $f['is_file'] ){
if ( !bbn\file\dir::create_path(dirname($f['dest'])) ){
$this->error("Impossible to create the path " . dirname($f['dest']));
return false;
}
}
if ( !bbn\file\dir::copy($f['src'], $f['dest']) ){
$this->error('Impossible to export the ' . $wtype . ' ' . $f['src']);
return false;
}
}
if ( class_exists('\\ZipArchive') ){
$filezip = BBN_USER_PATH.'tmp/'.$name.'.zip';
$zip = new \ZipArchive();
if ( $err = $zip->open($filezip, \ZipArchive::OVERWRITE) ){
if ( file_exists($root_dest) ){
if ( (!$is_file) || !empty($cfg['tabs']) ){
// Create recursive directory iterator
$files = bbn\file\dir::scan($root_dest);
foreach ($files as $file){
$tmp_dest = str_replace(
$root_dest . (empty($cfg['tabs']) ? '/' : ''),
(!empty($cfg['tabs']) ? 'mvc/' : ''),
$file
);
// Add current file to archive
if ( ($file !== $root_dest.$name) &&
is_file($file) &&
!$zip->addFile($file, $tmp_dest)
){
$this->error("Impossible to add $file");
return false;
}
}
}
else {
if ( !$zip->addFile($root_dest, $path) ){
$this->error("Impossible to add $root_dest");
return false;
}
}
if ( $zip->close() ){
if ( !bbn\file\dir::delete(BBN_USER_PATH . 'tmp/' . $rnd, 1) ){
$this->error("Impossible to delete the directory " . BBN_USER_PATH . 'tmp/' . $rnd);
return false;
}
return $filezip;
}
$this->error("Impossible to close the zip file $filezip");
return false;
}
$this->error("The path does not exist: $root_dest");
return false;
}
$this->error("Impossible to create $filezip ($err)");
return false;
}
$this->error("ZipArchive class non-existent");
return false;
}
} | [
"public",
"function",
"export",
"(",
"$",
"dir",
",",
"$",
"path",
",",
"$",
"name",
",",
"$",
"type",
"=",
"'file'",
")",
"{",
"if",
"(",
"(",
"$",
"cfg",
"=",
"$",
"this",
"->",
"dir",
"(",
"$",
"dir",
")",
")",
"&&",
"(",
"$",
"root",
"=",
"$",
"this",
"->",
"get_root_path",
"(",
"$",
"dir",
")",
")",
"&&",
"\\",
"defined",
"(",
"'BBN_USER_PATH'",
")",
")",
"{",
"$",
"is_file",
"=",
"$",
"type",
"===",
"'file'",
";",
"$",
"wtype",
"=",
"$",
"is_file",
"?",
"'file'",
":",
"'directory'",
";",
"$",
"rnd",
"=",
"bbn",
"\\",
"str",
"::",
"genpwd",
"(",
")",
";",
"$",
"root_dest",
"=",
"BBN_USER_PATH",
".",
"'tmp/'",
".",
"$",
"rnd",
".",
"'/'",
";",
"$",
"files",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"cfg",
"[",
"'tabs'",
"]",
")",
")",
"{",
"$",
"root_dest_mvc",
"=",
"$",
"root_dest",
".",
"$",
"name",
".",
"'/mvc/'",
";",
"foreach",
"(",
"$",
"cfg",
"[",
"'tabs'",
"]",
"as",
"$",
"t",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"t",
"[",
"'fixed'",
"]",
")",
")",
"{",
"$",
"real",
"=",
"$",
"t",
"[",
"'path'",
"]",
";",
"if",
"(",
"dirname",
"(",
"$",
"path",
")",
"!==",
"'.'",
")",
"{",
"$",
"real",
".=",
"dirname",
"(",
"$",
"path",
")",
".",
"'/'",
";",
"}",
"if",
"(",
"$",
"is_file",
")",
"{",
"foreach",
"(",
"$",
"t",
"[",
"'extensions'",
"]",
"as",
"$",
"e",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"root",
".",
"$",
"real",
".",
"$",
"name",
".",
"'.'",
".",
"$",
"e",
"[",
"'ext'",
"]",
")",
")",
"{",
"$",
"real",
".=",
"$",
"name",
".",
"'.'",
".",
"$",
"e",
"[",
"'ext'",
"]",
";",
"array_push",
"(",
"$",
"files",
",",
"[",
"'src'",
"=>",
"$",
"root",
".",
"$",
"real",
",",
"'dest'",
"=>",
"$",
"root_dest_mvc",
".",
"$",
"real",
",",
"'is_file'",
"=>",
"$",
"is_file",
"]",
")",
";",
"break",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"real",
".=",
"$",
"name",
";",
"if",
"(",
"is_dir",
"(",
"$",
"root",
".",
"$",
"real",
")",
")",
"{",
"array_push",
"(",
"$",
"files",
",",
"[",
"'src'",
"=>",
"$",
"root",
".",
"$",
"real",
",",
"'dest'",
"=>",
"$",
"root_dest_mvc",
".",
"$",
"real",
",",
"'is_file'",
"=>",
"$",
"is_file",
"]",
")",
";",
"}",
"}",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"root",
".",
"$",
"path",
")",
")",
"{",
"array_push",
"(",
"$",
"files",
",",
"[",
"'src'",
"=>",
"$",
"root",
".",
"$",
"path",
",",
"'dest'",
"=>",
"$",
"root_dest",
".",
"$",
"path",
",",
"'is_file'",
"=>",
"$",
"is_file",
"]",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"files",
"as",
"$",
"f",
")",
"{",
"if",
"(",
"$",
"f",
"[",
"'is_file'",
"]",
")",
"{",
"if",
"(",
"!",
"bbn",
"\\",
"file",
"\\",
"dir",
"::",
"create_path",
"(",
"dirname",
"(",
"$",
"f",
"[",
"'dest'",
"]",
")",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"\"Impossible to create the path \"",
".",
"dirname",
"(",
"$",
"f",
"[",
"'dest'",
"]",
")",
")",
";",
"return",
"false",
";",
"}",
"}",
"if",
"(",
"!",
"bbn",
"\\",
"file",
"\\",
"dir",
"::",
"copy",
"(",
"$",
"f",
"[",
"'src'",
"]",
",",
"$",
"f",
"[",
"'dest'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"'Impossible to export the '",
".",
"$",
"wtype",
".",
"' '",
".",
"$",
"f",
"[",
"'src'",
"]",
")",
";",
"return",
"false",
";",
"}",
"}",
"if",
"(",
"class_exists",
"(",
"'\\\\ZipArchive'",
")",
")",
"{",
"$",
"filezip",
"=",
"BBN_USER_PATH",
".",
"'tmp/'",
".",
"$",
"name",
".",
"'.zip'",
";",
"$",
"zip",
"=",
"new",
"\\",
"ZipArchive",
"(",
")",
";",
"if",
"(",
"$",
"err",
"=",
"$",
"zip",
"->",
"open",
"(",
"$",
"filezip",
",",
"\\",
"ZipArchive",
"::",
"OVERWRITE",
")",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"root_dest",
")",
")",
"{",
"if",
"(",
"(",
"!",
"$",
"is_file",
")",
"||",
"!",
"empty",
"(",
"$",
"cfg",
"[",
"'tabs'",
"]",
")",
")",
"{",
"// Create recursive directory iterator",
"$",
"files",
"=",
"bbn",
"\\",
"file",
"\\",
"dir",
"::",
"scan",
"(",
"$",
"root_dest",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"tmp_dest",
"=",
"str_replace",
"(",
"$",
"root_dest",
".",
"(",
"empty",
"(",
"$",
"cfg",
"[",
"'tabs'",
"]",
")",
"?",
"'/'",
":",
"''",
")",
",",
"(",
"!",
"empty",
"(",
"$",
"cfg",
"[",
"'tabs'",
"]",
")",
"?",
"'mvc/'",
":",
"''",
")",
",",
"$",
"file",
")",
";",
"// Add current file to archive",
"if",
"(",
"(",
"$",
"file",
"!==",
"$",
"root_dest",
".",
"$",
"name",
")",
"&&",
"is_file",
"(",
"$",
"file",
")",
"&&",
"!",
"$",
"zip",
"->",
"addFile",
"(",
"$",
"file",
",",
"$",
"tmp_dest",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"\"Impossible to add $file\"",
")",
";",
"return",
"false",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"$",
"zip",
"->",
"addFile",
"(",
"$",
"root_dest",
",",
"$",
"path",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"\"Impossible to add $root_dest\"",
")",
";",
"return",
"false",
";",
"}",
"}",
"if",
"(",
"$",
"zip",
"->",
"close",
"(",
")",
")",
"{",
"if",
"(",
"!",
"bbn",
"\\",
"file",
"\\",
"dir",
"::",
"delete",
"(",
"BBN_USER_PATH",
".",
"'tmp/'",
".",
"$",
"rnd",
",",
"1",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"\"Impossible to delete the directory \"",
".",
"BBN_USER_PATH",
".",
"'tmp/'",
".",
"$",
"rnd",
")",
";",
"return",
"false",
";",
"}",
"return",
"$",
"filezip",
";",
"}",
"$",
"this",
"->",
"error",
"(",
"\"Impossible to close the zip file $filezip\"",
")",
";",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"error",
"(",
"\"The path does not exist: $root_dest\"",
")",
";",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"error",
"(",
"\"Impossible to create $filezip ($err)\"",
")",
";",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"error",
"(",
"\"ZipArchive class non-existent\"",
")",
";",
"return",
"false",
";",
"}",
"}"
] | Exports a file or a directory, normal or MVC.
@param string $dir The source's name
@param string $path The file|directory's path
@param string $name The file|directory's name
@param string $type file|dir
@return bool | [
"Exports",
"a",
"file",
"or",
"a",
"directory",
"normal",
"or",
"MVC",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/ide/directories.php#L1185-L1301 |
nabab/bbn | src/bbn/ide/directories.php | directories.rename | public function rename($dir, $path, $new, $type = 'file'){
if ( ($cfg = $this->dir($dir)) &&
($root = $this->get_root_path($dir)) &&
bbn\str::check_filename($new)
){
$is_file = $type === 'file';
$wtype = $is_file ? 'file' : 'directory';
$pi = pathinfo($path);
$files = [];
if ( $pi['filename'] !== $new ){
if ( !empty($cfg['tabs']) ){
$ext = false;
foreach ( $cfg['tabs'] as $t ){
if ( empty($t['fixed']) ){
// MVC tab's path
$real = $root . $t['path'];
if ( $pi['dirname'] !== '.' ){
$real .= $pi['dirname'] . '/';
}
if ( $is_file ){
foreach ( $t['extensions'] as $e ){
$real_new = $real . $new . '.' . $e['ext'];
$real_ext = $real . $pi['filename'] . '.' . $e['ext'];
if ( file_exists($real_ext) ){
if ( !file_exists($real_new) ){
$ext = empty($ext) ? $e['ext'] : $ext;
$files[$real_ext] = $real_new;
if ( $t['url'] === 'php' ){
$change_perm = [
'old' => $real_ext,
'new' => $real_new,
'type' => 'file'
];
}
}
else {
$this->error("The file $real_new is already exists.");
return false;
}
}
}
if ( !empty($t['default']) ){
$file_url = $this->real_to_url($real_ext);
$file_new_url = $this->real_to_url($real_new);
}
}
else {
$real_new = $real . $new;
$real .= $pi['filename'];
if ( file_exists($real) ){
if ( !file_exists($real_new) ){
$files[$real] = $real_new;
if ( $t['url'] === 'php' ){
$change_perm = [
'old' => $real,
'new' => $real_new,
'type' => 'dir'
];
}
}
else {
$this->error("The directory $real_new is already exists.");
return false;
}
}
}
if ( !empty($t['default']) ){
$file_new = (($pi['dirname'] !== '.') ? $pi['dirname'] . '/' : '') . $new;
$file_new_name = (($pi['dirname'] !== '.') ? $pi['dirname'] . '/' : '') . $new;
}
}
}
}
else {
$real = $root . $path;
$real_new = $root . $new . ($is_file ? '.' . $pi['extension'] : '');
if ( file_exists($real) ){
if ( !file_exists($real_new) ){
$files[$real] = $real_new;
}
else {
$this->error("The $wtype $real_new is already exists.");
return false;
}
if ( $is_file ){
$file_url = $this->real_to_url($real);
$file_new_url = $this->real_to_url($real_new);
$file_new = (($pi['dirname'] !== '.') ? $pi['dirname'] . '/' : '') . $new . '.' . $pi['extension'];
$file_new_name = (($pi['dirname'] !== '.') ? $pi['dirname'] . '/' : '') . $new . '.' . $pi['extension'];
}
else {
$file_new = (($pi['dirname'] !== '.') ? $pi['dirname'] . '/' : '') . $new;
$file_new_name = (($pi['dirname'] !== '.') ? $pi['dirname'] . '/' : '') . $new;
}
}
}
foreach ( $files as $s => $d ){
if ( !rename($s, $d) ){
$this->error("Impossible to rename the $wtype: $s -> $d");
return false;
}
if ( is_file($s) ){
// Remove file's options
$this->options->remove($this->options->from_code($this->real_to_id($s), $this->_files_pref()));
}
else {
$this->rem_dir_opt($s);
}
}
// Change permission
if ( !empty($change_perm) ){
$this->change_perm_by_real($change_perm['old'], $change_perm['new'], $change_perm['type']);
}
return [
'file_url' => $file_url,
'file_new_url' => $file_new_url,
'file_new' => $file_new,
'file_new_name' => $file_new_name,
'file_new_ext' => $ext
];
}
$this->error("The old name and the new name are identical.");
return false;
}
} | php | public function rename($dir, $path, $new, $type = 'file'){
if ( ($cfg = $this->dir($dir)) &&
($root = $this->get_root_path($dir)) &&
bbn\str::check_filename($new)
){
$is_file = $type === 'file';
$wtype = $is_file ? 'file' : 'directory';
$pi = pathinfo($path);
$files = [];
if ( $pi['filename'] !== $new ){
if ( !empty($cfg['tabs']) ){
$ext = false;
foreach ( $cfg['tabs'] as $t ){
if ( empty($t['fixed']) ){
// MVC tab's path
$real = $root . $t['path'];
if ( $pi['dirname'] !== '.' ){
$real .= $pi['dirname'] . '/';
}
if ( $is_file ){
foreach ( $t['extensions'] as $e ){
$real_new = $real . $new . '.' . $e['ext'];
$real_ext = $real . $pi['filename'] . '.' . $e['ext'];
if ( file_exists($real_ext) ){
if ( !file_exists($real_new) ){
$ext = empty($ext) ? $e['ext'] : $ext;
$files[$real_ext] = $real_new;
if ( $t['url'] === 'php' ){
$change_perm = [
'old' => $real_ext,
'new' => $real_new,
'type' => 'file'
];
}
}
else {
$this->error("The file $real_new is already exists.");
return false;
}
}
}
if ( !empty($t['default']) ){
$file_url = $this->real_to_url($real_ext);
$file_new_url = $this->real_to_url($real_new);
}
}
else {
$real_new = $real . $new;
$real .= $pi['filename'];
if ( file_exists($real) ){
if ( !file_exists($real_new) ){
$files[$real] = $real_new;
if ( $t['url'] === 'php' ){
$change_perm = [
'old' => $real,
'new' => $real_new,
'type' => 'dir'
];
}
}
else {
$this->error("The directory $real_new is already exists.");
return false;
}
}
}
if ( !empty($t['default']) ){
$file_new = (($pi['dirname'] !== '.') ? $pi['dirname'] . '/' : '') . $new;
$file_new_name = (($pi['dirname'] !== '.') ? $pi['dirname'] . '/' : '') . $new;
}
}
}
}
else {
$real = $root . $path;
$real_new = $root . $new . ($is_file ? '.' . $pi['extension'] : '');
if ( file_exists($real) ){
if ( !file_exists($real_new) ){
$files[$real] = $real_new;
}
else {
$this->error("The $wtype $real_new is already exists.");
return false;
}
if ( $is_file ){
$file_url = $this->real_to_url($real);
$file_new_url = $this->real_to_url($real_new);
$file_new = (($pi['dirname'] !== '.') ? $pi['dirname'] . '/' : '') . $new . '.' . $pi['extension'];
$file_new_name = (($pi['dirname'] !== '.') ? $pi['dirname'] . '/' : '') . $new . '.' . $pi['extension'];
}
else {
$file_new = (($pi['dirname'] !== '.') ? $pi['dirname'] . '/' : '') . $new;
$file_new_name = (($pi['dirname'] !== '.') ? $pi['dirname'] . '/' : '') . $new;
}
}
}
foreach ( $files as $s => $d ){
if ( !rename($s, $d) ){
$this->error("Impossible to rename the $wtype: $s -> $d");
return false;
}
if ( is_file($s) ){
// Remove file's options
$this->options->remove($this->options->from_code($this->real_to_id($s), $this->_files_pref()));
}
else {
$this->rem_dir_opt($s);
}
}
// Change permission
if ( !empty($change_perm) ){
$this->change_perm_by_real($change_perm['old'], $change_perm['new'], $change_perm['type']);
}
return [
'file_url' => $file_url,
'file_new_url' => $file_new_url,
'file_new' => $file_new,
'file_new_name' => $file_new_name,
'file_new_ext' => $ext
];
}
$this->error("The old name and the new name are identical.");
return false;
}
} | [
"public",
"function",
"rename",
"(",
"$",
"dir",
",",
"$",
"path",
",",
"$",
"new",
",",
"$",
"type",
"=",
"'file'",
")",
"{",
"if",
"(",
"(",
"$",
"cfg",
"=",
"$",
"this",
"->",
"dir",
"(",
"$",
"dir",
")",
")",
"&&",
"(",
"$",
"root",
"=",
"$",
"this",
"->",
"get_root_path",
"(",
"$",
"dir",
")",
")",
"&&",
"bbn",
"\\",
"str",
"::",
"check_filename",
"(",
"$",
"new",
")",
")",
"{",
"$",
"is_file",
"=",
"$",
"type",
"===",
"'file'",
";",
"$",
"wtype",
"=",
"$",
"is_file",
"?",
"'file'",
":",
"'directory'",
";",
"$",
"pi",
"=",
"pathinfo",
"(",
"$",
"path",
")",
";",
"$",
"files",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"pi",
"[",
"'filename'",
"]",
"!==",
"$",
"new",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"cfg",
"[",
"'tabs'",
"]",
")",
")",
"{",
"$",
"ext",
"=",
"false",
";",
"foreach",
"(",
"$",
"cfg",
"[",
"'tabs'",
"]",
"as",
"$",
"t",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"t",
"[",
"'fixed'",
"]",
")",
")",
"{",
"// MVC tab's path",
"$",
"real",
"=",
"$",
"root",
".",
"$",
"t",
"[",
"'path'",
"]",
";",
"if",
"(",
"$",
"pi",
"[",
"'dirname'",
"]",
"!==",
"'.'",
")",
"{",
"$",
"real",
".=",
"$",
"pi",
"[",
"'dirname'",
"]",
".",
"'/'",
";",
"}",
"if",
"(",
"$",
"is_file",
")",
"{",
"foreach",
"(",
"$",
"t",
"[",
"'extensions'",
"]",
"as",
"$",
"e",
")",
"{",
"$",
"real_new",
"=",
"$",
"real",
".",
"$",
"new",
".",
"'.'",
".",
"$",
"e",
"[",
"'ext'",
"]",
";",
"$",
"real_ext",
"=",
"$",
"real",
".",
"$",
"pi",
"[",
"'filename'",
"]",
".",
"'.'",
".",
"$",
"e",
"[",
"'ext'",
"]",
";",
"if",
"(",
"file_exists",
"(",
"$",
"real_ext",
")",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"real_new",
")",
")",
"{",
"$",
"ext",
"=",
"empty",
"(",
"$",
"ext",
")",
"?",
"$",
"e",
"[",
"'ext'",
"]",
":",
"$",
"ext",
";",
"$",
"files",
"[",
"$",
"real_ext",
"]",
"=",
"$",
"real_new",
";",
"if",
"(",
"$",
"t",
"[",
"'url'",
"]",
"===",
"'php'",
")",
"{",
"$",
"change_perm",
"=",
"[",
"'old'",
"=>",
"$",
"real_ext",
",",
"'new'",
"=>",
"$",
"real_new",
",",
"'type'",
"=>",
"'file'",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"error",
"(",
"\"The file $real_new is already exists.\"",
")",
";",
"return",
"false",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"t",
"[",
"'default'",
"]",
")",
")",
"{",
"$",
"file_url",
"=",
"$",
"this",
"->",
"real_to_url",
"(",
"$",
"real_ext",
")",
";",
"$",
"file_new_url",
"=",
"$",
"this",
"->",
"real_to_url",
"(",
"$",
"real_new",
")",
";",
"}",
"}",
"else",
"{",
"$",
"real_new",
"=",
"$",
"real",
".",
"$",
"new",
";",
"$",
"real",
".=",
"$",
"pi",
"[",
"'filename'",
"]",
";",
"if",
"(",
"file_exists",
"(",
"$",
"real",
")",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"real_new",
")",
")",
"{",
"$",
"files",
"[",
"$",
"real",
"]",
"=",
"$",
"real_new",
";",
"if",
"(",
"$",
"t",
"[",
"'url'",
"]",
"===",
"'php'",
")",
"{",
"$",
"change_perm",
"=",
"[",
"'old'",
"=>",
"$",
"real",
",",
"'new'",
"=>",
"$",
"real_new",
",",
"'type'",
"=>",
"'dir'",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"error",
"(",
"\"The directory $real_new is already exists.\"",
")",
";",
"return",
"false",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"t",
"[",
"'default'",
"]",
")",
")",
"{",
"$",
"file_new",
"=",
"(",
"(",
"$",
"pi",
"[",
"'dirname'",
"]",
"!==",
"'.'",
")",
"?",
"$",
"pi",
"[",
"'dirname'",
"]",
".",
"'/'",
":",
"''",
")",
".",
"$",
"new",
";",
"$",
"file_new_name",
"=",
"(",
"(",
"$",
"pi",
"[",
"'dirname'",
"]",
"!==",
"'.'",
")",
"?",
"$",
"pi",
"[",
"'dirname'",
"]",
".",
"'/'",
":",
"''",
")",
".",
"$",
"new",
";",
"}",
"}",
"}",
"}",
"else",
"{",
"$",
"real",
"=",
"$",
"root",
".",
"$",
"path",
";",
"$",
"real_new",
"=",
"$",
"root",
".",
"$",
"new",
".",
"(",
"$",
"is_file",
"?",
"'.'",
".",
"$",
"pi",
"[",
"'extension'",
"]",
":",
"''",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"real",
")",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"real_new",
")",
")",
"{",
"$",
"files",
"[",
"$",
"real",
"]",
"=",
"$",
"real_new",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"error",
"(",
"\"The $wtype $real_new is already exists.\"",
")",
";",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"is_file",
")",
"{",
"$",
"file_url",
"=",
"$",
"this",
"->",
"real_to_url",
"(",
"$",
"real",
")",
";",
"$",
"file_new_url",
"=",
"$",
"this",
"->",
"real_to_url",
"(",
"$",
"real_new",
")",
";",
"$",
"file_new",
"=",
"(",
"(",
"$",
"pi",
"[",
"'dirname'",
"]",
"!==",
"'.'",
")",
"?",
"$",
"pi",
"[",
"'dirname'",
"]",
".",
"'/'",
":",
"''",
")",
".",
"$",
"new",
".",
"'.'",
".",
"$",
"pi",
"[",
"'extension'",
"]",
";",
"$",
"file_new_name",
"=",
"(",
"(",
"$",
"pi",
"[",
"'dirname'",
"]",
"!==",
"'.'",
")",
"?",
"$",
"pi",
"[",
"'dirname'",
"]",
".",
"'/'",
":",
"''",
")",
".",
"$",
"new",
".",
"'.'",
".",
"$",
"pi",
"[",
"'extension'",
"]",
";",
"}",
"else",
"{",
"$",
"file_new",
"=",
"(",
"(",
"$",
"pi",
"[",
"'dirname'",
"]",
"!==",
"'.'",
")",
"?",
"$",
"pi",
"[",
"'dirname'",
"]",
".",
"'/'",
":",
"''",
")",
".",
"$",
"new",
";",
"$",
"file_new_name",
"=",
"(",
"(",
"$",
"pi",
"[",
"'dirname'",
"]",
"!==",
"'.'",
")",
"?",
"$",
"pi",
"[",
"'dirname'",
"]",
".",
"'/'",
":",
"''",
")",
".",
"$",
"new",
";",
"}",
"}",
"}",
"foreach",
"(",
"$",
"files",
"as",
"$",
"s",
"=>",
"$",
"d",
")",
"{",
"if",
"(",
"!",
"rename",
"(",
"$",
"s",
",",
"$",
"d",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"\"Impossible to rename the $wtype: $s -> $d\"",
")",
";",
"return",
"false",
";",
"}",
"if",
"(",
"is_file",
"(",
"$",
"s",
")",
")",
"{",
"// Remove file's options",
"$",
"this",
"->",
"options",
"->",
"remove",
"(",
"$",
"this",
"->",
"options",
"->",
"from_code",
"(",
"$",
"this",
"->",
"real_to_id",
"(",
"$",
"s",
")",
",",
"$",
"this",
"->",
"_files_pref",
"(",
")",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"rem_dir_opt",
"(",
"$",
"s",
")",
";",
"}",
"}",
"// Change permission",
"if",
"(",
"!",
"empty",
"(",
"$",
"change_perm",
")",
")",
"{",
"$",
"this",
"->",
"change_perm_by_real",
"(",
"$",
"change_perm",
"[",
"'old'",
"]",
",",
"$",
"change_perm",
"[",
"'new'",
"]",
",",
"$",
"change_perm",
"[",
"'type'",
"]",
")",
";",
"}",
"return",
"[",
"'file_url'",
"=>",
"$",
"file_url",
",",
"'file_new_url'",
"=>",
"$",
"file_new_url",
",",
"'file_new'",
"=>",
"$",
"file_new",
",",
"'file_new_name'",
"=>",
"$",
"file_new_name",
",",
"'file_new_ext'",
"=>",
"$",
"ext",
"]",
";",
"}",
"$",
"this",
"->",
"error",
"(",
"\"The old name and the new name are identical.\"",
")",
";",
"return",
"false",
";",
"}",
"}"
] | Renames a file or a directory.
@param string $dir The source's name
@param string $path The file|directory's old path (included filename and its extension)
@param string $new The new file's name
@param string $type file|dir
@return array|bool | [
"Renames",
"a",
"file",
"or",
"a",
"directory",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/ide/directories.php#L1312-L1439 |
nabab/bbn | src/bbn/ide/directories.php | directories.change_ext | public function change_ext($ext, $file){
if ( !empty($ext) &&
!empty($file) &&
file_exists($file)
){
$pi = pathinfo($file);
$new = $pi['dirname'].'/'.$pi['filename'].'.'.$ext;
bbn\file\dir::move($file, $new, true);
return [
'file' => $new,
'file_url' => $this->real_to_url($new)
];
}
$this->error("Error.");
} | php | public function change_ext($ext, $file){
if ( !empty($ext) &&
!empty($file) &&
file_exists($file)
){
$pi = pathinfo($file);
$new = $pi['dirname'].'/'.$pi['filename'].'.'.$ext;
bbn\file\dir::move($file, $new, true);
return [
'file' => $new,
'file_url' => $this->real_to_url($new)
];
}
$this->error("Error.");
} | [
"public",
"function",
"change_ext",
"(",
"$",
"ext",
",",
"$",
"file",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"ext",
")",
"&&",
"!",
"empty",
"(",
"$",
"file",
")",
"&&",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"$",
"pi",
"=",
"pathinfo",
"(",
"$",
"file",
")",
";",
"$",
"new",
"=",
"$",
"pi",
"[",
"'dirname'",
"]",
".",
"'/'",
".",
"$",
"pi",
"[",
"'filename'",
"]",
".",
"'.'",
".",
"$",
"ext",
";",
"bbn",
"\\",
"file",
"\\",
"dir",
"::",
"move",
"(",
"$",
"file",
",",
"$",
"new",
",",
"true",
")",
";",
"return",
"[",
"'file'",
"=>",
"$",
"new",
",",
"'file_url'",
"=>",
"$",
"this",
"->",
"real_to_url",
"(",
"$",
"new",
")",
"]",
";",
"}",
"$",
"this",
"->",
"error",
"(",
"\"Error.\"",
")",
";",
"}"
] | Changes the extension to a file.
@param string $ext The new extension
@param string $file The file to change
@return array | [
"Changes",
"the",
"extension",
"to",
"a",
"file",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/ide/directories.php#L1576-L1590 |
nabab/bbn | src/bbn/ide/directories.php | directories.create_perm_by_real | public function create_perm_by_real($file, $type='file'){
if ( !empty($file) &&
\defined('BBN_APP_PATH') &&
file_exists($file) &&
// It must be a controller
(strpos($file, '/mvc/public/') !== false)
){
$is_file = $type === 'file';
// Check if it's an external route
foreach ( $this->routes as $i => $r ){
if ( strpos($file, $r) === 0 ){
// Remove route
$f = substr($file, \strlen($r), \strlen($file));
// Remove /mvc/public
$f = substr($f, \strlen('/mvc/public'), \strlen($f));
// Add the route's name to path
$f = $i . $f;
}
}
// Internal route
if ( empty($f) ){
$root_path = BBN_APP_PATH.'mvc/public/';
if ( strpos($file, $root_path) === 0 ){
// Remove root path
$f = substr($file, \strlen($root_path), \strlen($file));
}
}
if ( !empty($f) ){
$bits = bbn\x::remove_empty(explode('/', $f));
$code = $is_file ? bbn\str::file_ext(array_pop($bits), 1)[0] : array_pop($bits).'/';
$id_parent = $this->options->from_code('page', 'bbn_permissions');
foreach ( $bits as $b ){
if ( !$this->options->from_code($b.'/', $id_parent) ){
$this->options->add([
'id_parent' => $id_parent,
'code' => $b.'/',
'text' => $b
]);
}
$id_parent = $this->options->from_code($b.'/', $id_parent);
}
if ( !$this->options->from_code($code, $id_parent) ){
$this->options->add([
'id_parent' => $id_parent,
'code' => $code,
'text' => $code
]);
}
return $this->options->from_code($code, $id_parent);
}
else if ( !$is_file ){
return $this->options->from_code('page', 'bbn_permissions');
}
return true;
}
return false;
} | php | public function create_perm_by_real($file, $type='file'){
if ( !empty($file) &&
\defined('BBN_APP_PATH') &&
file_exists($file) &&
// It must be a controller
(strpos($file, '/mvc/public/') !== false)
){
$is_file = $type === 'file';
// Check if it's an external route
foreach ( $this->routes as $i => $r ){
if ( strpos($file, $r) === 0 ){
// Remove route
$f = substr($file, \strlen($r), \strlen($file));
// Remove /mvc/public
$f = substr($f, \strlen('/mvc/public'), \strlen($f));
// Add the route's name to path
$f = $i . $f;
}
}
// Internal route
if ( empty($f) ){
$root_path = BBN_APP_PATH.'mvc/public/';
if ( strpos($file, $root_path) === 0 ){
// Remove root path
$f = substr($file, \strlen($root_path), \strlen($file));
}
}
if ( !empty($f) ){
$bits = bbn\x::remove_empty(explode('/', $f));
$code = $is_file ? bbn\str::file_ext(array_pop($bits), 1)[0] : array_pop($bits).'/';
$id_parent = $this->options->from_code('page', 'bbn_permissions');
foreach ( $bits as $b ){
if ( !$this->options->from_code($b.'/', $id_parent) ){
$this->options->add([
'id_parent' => $id_parent,
'code' => $b.'/',
'text' => $b
]);
}
$id_parent = $this->options->from_code($b.'/', $id_parent);
}
if ( !$this->options->from_code($code, $id_parent) ){
$this->options->add([
'id_parent' => $id_parent,
'code' => $code,
'text' => $code
]);
}
return $this->options->from_code($code, $id_parent);
}
else if ( !$is_file ){
return $this->options->from_code('page', 'bbn_permissions');
}
return true;
}
return false;
} | [
"public",
"function",
"create_perm_by_real",
"(",
"$",
"file",
",",
"$",
"type",
"=",
"'file'",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"file",
")",
"&&",
"\\",
"defined",
"(",
"'BBN_APP_PATH'",
")",
"&&",
"file_exists",
"(",
"$",
"file",
")",
"&&",
"// It must be a controller",
"(",
"strpos",
"(",
"$",
"file",
",",
"'/mvc/public/'",
")",
"!==",
"false",
")",
")",
"{",
"$",
"is_file",
"=",
"$",
"type",
"===",
"'file'",
";",
"// Check if it's an external route",
"foreach",
"(",
"$",
"this",
"->",
"routes",
"as",
"$",
"i",
"=>",
"$",
"r",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"file",
",",
"$",
"r",
")",
"===",
"0",
")",
"{",
"// Remove route",
"$",
"f",
"=",
"substr",
"(",
"$",
"file",
",",
"\\",
"strlen",
"(",
"$",
"r",
")",
",",
"\\",
"strlen",
"(",
"$",
"file",
")",
")",
";",
"// Remove /mvc/public",
"$",
"f",
"=",
"substr",
"(",
"$",
"f",
",",
"\\",
"strlen",
"(",
"'/mvc/public'",
")",
",",
"\\",
"strlen",
"(",
"$",
"f",
")",
")",
";",
"// Add the route's name to path",
"$",
"f",
"=",
"$",
"i",
".",
"$",
"f",
";",
"}",
"}",
"// Internal route",
"if",
"(",
"empty",
"(",
"$",
"f",
")",
")",
"{",
"$",
"root_path",
"=",
"BBN_APP_PATH",
".",
"'mvc/public/'",
";",
"if",
"(",
"strpos",
"(",
"$",
"file",
",",
"$",
"root_path",
")",
"===",
"0",
")",
"{",
"// Remove root path",
"$",
"f",
"=",
"substr",
"(",
"$",
"file",
",",
"\\",
"strlen",
"(",
"$",
"root_path",
")",
",",
"\\",
"strlen",
"(",
"$",
"file",
")",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"f",
")",
")",
"{",
"$",
"bits",
"=",
"bbn",
"\\",
"x",
"::",
"remove_empty",
"(",
"explode",
"(",
"'/'",
",",
"$",
"f",
")",
")",
";",
"$",
"code",
"=",
"$",
"is_file",
"?",
"bbn",
"\\",
"str",
"::",
"file_ext",
"(",
"array_pop",
"(",
"$",
"bits",
")",
",",
"1",
")",
"[",
"0",
"]",
":",
"array_pop",
"(",
"$",
"bits",
")",
".",
"'/'",
";",
"$",
"id_parent",
"=",
"$",
"this",
"->",
"options",
"->",
"from_code",
"(",
"'page'",
",",
"'bbn_permissions'",
")",
";",
"foreach",
"(",
"$",
"bits",
"as",
"$",
"b",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"options",
"->",
"from_code",
"(",
"$",
"b",
".",
"'/'",
",",
"$",
"id_parent",
")",
")",
"{",
"$",
"this",
"->",
"options",
"->",
"add",
"(",
"[",
"'id_parent'",
"=>",
"$",
"id_parent",
",",
"'code'",
"=>",
"$",
"b",
".",
"'/'",
",",
"'text'",
"=>",
"$",
"b",
"]",
")",
";",
"}",
"$",
"id_parent",
"=",
"$",
"this",
"->",
"options",
"->",
"from_code",
"(",
"$",
"b",
".",
"'/'",
",",
"$",
"id_parent",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"options",
"->",
"from_code",
"(",
"$",
"code",
",",
"$",
"id_parent",
")",
")",
"{",
"$",
"this",
"->",
"options",
"->",
"add",
"(",
"[",
"'id_parent'",
"=>",
"$",
"id_parent",
",",
"'code'",
"=>",
"$",
"code",
",",
"'text'",
"=>",
"$",
"code",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"options",
"->",
"from_code",
"(",
"$",
"code",
",",
"$",
"id_parent",
")",
";",
"}",
"else",
"if",
"(",
"!",
"$",
"is_file",
")",
"{",
"return",
"$",
"this",
"->",
"options",
"->",
"from_code",
"(",
"'page'",
",",
"'bbn_permissions'",
")",
";",
"}",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Creates a permission option from a real file/dir's path
@param string $file The real file/dir's path
@param string $type The type of real (file/dir)
@return bool | [
"Creates",
"a",
"permission",
"option",
"from",
"a",
"real",
"file",
"/",
"dir",
"s",
"path"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/ide/directories.php#L1647-L1703 |
nabab/bbn | src/bbn/ide/directories.php | directories.change_perm_by_real | public function change_perm_by_real($file, $file_new, $type='file'){
if ( !empty($file) &&
!empty($file_new) &&
file_exists($file_new) &&
($id_opt = $this->real_to_perm($file, $type)) &&
!$this->real_to_perm($file_new, $type)
){
$is_file = $type === 'file';
$code = $is_file ? bbn\str::file_ext(basename($file_new), 1)[0] : basename($file_new).'/';
if ( ($id_parent = $this->create_perm_by_real(dirname($file_new).'/', 'dir'))
){
$this->options->set_prop($id_opt, ['code' => $code]);
$this->options->move($id_opt, $id_parent);
return true;
}
}
return false;
} | php | public function change_perm_by_real($file, $file_new, $type='file'){
if ( !empty($file) &&
!empty($file_new) &&
file_exists($file_new) &&
($id_opt = $this->real_to_perm($file, $type)) &&
!$this->real_to_perm($file_new, $type)
){
$is_file = $type === 'file';
$code = $is_file ? bbn\str::file_ext(basename($file_new), 1)[0] : basename($file_new).'/';
if ( ($id_parent = $this->create_perm_by_real(dirname($file_new).'/', 'dir'))
){
$this->options->set_prop($id_opt, ['code' => $code]);
$this->options->move($id_opt, $id_parent);
return true;
}
}
return false;
} | [
"public",
"function",
"change_perm_by_real",
"(",
"$",
"file",
",",
"$",
"file_new",
",",
"$",
"type",
"=",
"'file'",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"file",
")",
"&&",
"!",
"empty",
"(",
"$",
"file_new",
")",
"&&",
"file_exists",
"(",
"$",
"file_new",
")",
"&&",
"(",
"$",
"id_opt",
"=",
"$",
"this",
"->",
"real_to_perm",
"(",
"$",
"file",
",",
"$",
"type",
")",
")",
"&&",
"!",
"$",
"this",
"->",
"real_to_perm",
"(",
"$",
"file_new",
",",
"$",
"type",
")",
")",
"{",
"$",
"is_file",
"=",
"$",
"type",
"===",
"'file'",
";",
"$",
"code",
"=",
"$",
"is_file",
"?",
"bbn",
"\\",
"str",
"::",
"file_ext",
"(",
"basename",
"(",
"$",
"file_new",
")",
",",
"1",
")",
"[",
"0",
"]",
":",
"basename",
"(",
"$",
"file_new",
")",
".",
"'/'",
";",
"if",
"(",
"(",
"$",
"id_parent",
"=",
"$",
"this",
"->",
"create_perm_by_real",
"(",
"dirname",
"(",
"$",
"file_new",
")",
".",
"'/'",
",",
"'dir'",
")",
")",
")",
"{",
"$",
"this",
"->",
"options",
"->",
"set_prop",
"(",
"$",
"id_opt",
",",
"[",
"'code'",
"=>",
"$",
"code",
"]",
")",
";",
"$",
"this",
"->",
"options",
"->",
"move",
"(",
"$",
"id_opt",
",",
"$",
"id_parent",
")",
";",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Changes permissions to a file/dir from the old and new real file/dir's path
@param string $file The old real file/dir's path
@param string $file_new The new real file/dir's path
@param string $type The type (file/dir)
@return bool | [
"Changes",
"permissions",
"to",
"a",
"file",
"/",
"dir",
"from",
"the",
"old",
"and",
"new",
"real",
"file",
"/",
"dir",
"s",
"path"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/ide/directories.php#L1713-L1730 |
nabab/bbn | src/bbn/ide/directories.php | directories.delete_perm | public function delete_perm($file, $type='file'){
if ( !empty($file) &&
($id_opt = $this->real_to_perm($file, $type)) &&
$this->options->remove($id_opt)
){
return true;
}
return false;
} | php | public function delete_perm($file, $type='file'){
if ( !empty($file) &&
($id_opt = $this->real_to_perm($file, $type)) &&
$this->options->remove($id_opt)
){
return true;
}
return false;
} | [
"public",
"function",
"delete_perm",
"(",
"$",
"file",
",",
"$",
"type",
"=",
"'file'",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"file",
")",
"&&",
"(",
"$",
"id_opt",
"=",
"$",
"this",
"->",
"real_to_perm",
"(",
"$",
"file",
",",
"$",
"type",
")",
")",
"&&",
"$",
"this",
"->",
"options",
"->",
"remove",
"(",
"$",
"id_opt",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Deletes permission from a real file/dir's path
@param string $file The real file/dir's path
@param string $type The type (file/dir)
@return bool | [
"Deletes",
"permission",
"from",
"a",
"real",
"file",
"/",
"dir",
"s",
"path"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/ide/directories.php#L1739-L1747 |
nabab/bbn | src/bbn/ide/directories.php | directories.history | public function history($url){
if ( !empty($url) &&
( $dir = $this->dir_from_url($url) ) &&
( $dir_cfg = $this->dir($dir) ) &&
\defined('BBN_USER_PATH')
){
$res = [];
$all = [];
// IDE backup path
$path = BBN_USER_PATH."ide/backup/$dir";
// Remove dir name from url
$file = substr($url, \strlen($dir), \strlen($url));
// MVC
if ( !empty($dir_cfg['tabs']) ){
foreach ( $dir_cfg['tabs'] as $t ){
if ( empty($t['fixed']) ){
// The file's backup path of the MVC's tab
$p = $path . $t['path'] . $file . '/';
// Get history
$all = self::get_history($p, $t, $all, true);
}
}
}
else {
// The file's backup path of the MVC's tab
$p = $path . $file . '/';
// Get history
$all = self::get_history($p, $dir_cfg, $all);
}
if ( !empty($all) ){
foreach ( $all as $i => $a ){
if ( !empty($dir_cfg['tabs']) ){
$tmp = [];
foreach ( $a as $k => $b ){
array_push($tmp, [
'text' => $k,
'items' => $b
]);
}
}
array_push($res, [
'text' => $i,
'items' => !empty($tmp) ? $tmp : $a
]);
}
}
return ['list' => $res];
}
} | php | public function history($url){
if ( !empty($url) &&
( $dir = $this->dir_from_url($url) ) &&
( $dir_cfg = $this->dir($dir) ) &&
\defined('BBN_USER_PATH')
){
$res = [];
$all = [];
// IDE backup path
$path = BBN_USER_PATH."ide/backup/$dir";
// Remove dir name from url
$file = substr($url, \strlen($dir), \strlen($url));
// MVC
if ( !empty($dir_cfg['tabs']) ){
foreach ( $dir_cfg['tabs'] as $t ){
if ( empty($t['fixed']) ){
// The file's backup path of the MVC's tab
$p = $path . $t['path'] . $file . '/';
// Get history
$all = self::get_history($p, $t, $all, true);
}
}
}
else {
// The file's backup path of the MVC's tab
$p = $path . $file . '/';
// Get history
$all = self::get_history($p, $dir_cfg, $all);
}
if ( !empty($all) ){
foreach ( $all as $i => $a ){
if ( !empty($dir_cfg['tabs']) ){
$tmp = [];
foreach ( $a as $k => $b ){
array_push($tmp, [
'text' => $k,
'items' => $b
]);
}
}
array_push($res, [
'text' => $i,
'items' => !empty($tmp) ? $tmp : $a
]);
}
}
return ['list' => $res];
}
} | [
"public",
"function",
"history",
"(",
"$",
"url",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"url",
")",
"&&",
"(",
"$",
"dir",
"=",
"$",
"this",
"->",
"dir_from_url",
"(",
"$",
"url",
")",
")",
"&&",
"(",
"$",
"dir_cfg",
"=",
"$",
"this",
"->",
"dir",
"(",
"$",
"dir",
")",
")",
"&&",
"\\",
"defined",
"(",
"'BBN_USER_PATH'",
")",
")",
"{",
"$",
"res",
"=",
"[",
"]",
";",
"$",
"all",
"=",
"[",
"]",
";",
"// IDE backup path",
"$",
"path",
"=",
"BBN_USER_PATH",
".",
"\"ide/backup/$dir\"",
";",
"// Remove dir name from url",
"$",
"file",
"=",
"substr",
"(",
"$",
"url",
",",
"\\",
"strlen",
"(",
"$",
"dir",
")",
",",
"\\",
"strlen",
"(",
"$",
"url",
")",
")",
";",
"// MVC",
"if",
"(",
"!",
"empty",
"(",
"$",
"dir_cfg",
"[",
"'tabs'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"dir_cfg",
"[",
"'tabs'",
"]",
"as",
"$",
"t",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"t",
"[",
"'fixed'",
"]",
")",
")",
"{",
"// The file's backup path of the MVC's tab",
"$",
"p",
"=",
"$",
"path",
".",
"$",
"t",
"[",
"'path'",
"]",
".",
"$",
"file",
".",
"'/'",
";",
"// Get history",
"$",
"all",
"=",
"self",
"::",
"get_history",
"(",
"$",
"p",
",",
"$",
"t",
",",
"$",
"all",
",",
"true",
")",
";",
"}",
"}",
"}",
"else",
"{",
"// The file's backup path of the MVC's tab",
"$",
"p",
"=",
"$",
"path",
".",
"$",
"file",
".",
"'/'",
";",
"// Get history",
"$",
"all",
"=",
"self",
"::",
"get_history",
"(",
"$",
"p",
",",
"$",
"dir_cfg",
",",
"$",
"all",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"all",
")",
")",
"{",
"foreach",
"(",
"$",
"all",
"as",
"$",
"i",
"=>",
"$",
"a",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"dir_cfg",
"[",
"'tabs'",
"]",
")",
")",
"{",
"$",
"tmp",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"a",
"as",
"$",
"k",
"=>",
"$",
"b",
")",
"{",
"array_push",
"(",
"$",
"tmp",
",",
"[",
"'text'",
"=>",
"$",
"k",
",",
"'items'",
"=>",
"$",
"b",
"]",
")",
";",
"}",
"}",
"array_push",
"(",
"$",
"res",
",",
"[",
"'text'",
"=>",
"$",
"i",
",",
"'items'",
"=>",
"!",
"empty",
"(",
"$",
"tmp",
")",
"?",
"$",
"tmp",
":",
"$",
"a",
"]",
")",
";",
"}",
"}",
"return",
"[",
"'list'",
"=>",
"$",
"res",
"]",
";",
"}",
"}"
] | Returns all backup history of a file.
@param string $url The file's URL
@return array|bool | [
"Returns",
"all",
"backup",
"history",
"of",
"a",
"file",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/ide/directories.php#L1819-L1867 |
nabab/bbn | src/bbn/ide/directories.php | directories.modes | public function modes($type = false){
if ( \defined('BBN_DATA_PATH') ){
$r = [
'html' => [
'name' => 'HTML',
'mode' => 'htmlmixed',
'code' => is_file(BBN_DATA_PATH.'ide/defaults/default.html') ? file_get_contents(BBN_DATA_PATH.'ide/defaults/default.html') : ''
],
'xml' => [
'name' => 'XML',
'mode' => 'text/xml',
'code' => is_file(BBN_DATA_PATH.'ide/defaults/default.xml') ? file_get_contents(BBN_DATA_PATH.'ide/defaults/default.xml') : ''
],
'js' => [
'name' => 'JavaScript',
'mode' => 'javascript',
'code' => is_file(BBN_DATA_PATH.'ide/defaults/default.js') ? file_get_contents(BBN_DATA_PATH.'ide/defaults/default.js') : ''
],
'svg' => [
'name' => 'SVG',
'mode' => 'text/xml',
'code' => is_file(BBN_DATA_PATH.'ide/defaults/default.svg') ? file_get_contents(BBN_DATA_PATH.'ide/defaults/default.svg') : ''
],
'php' => [
'name' => 'PHP',
'mode' => 'application/x-httpd-php',
'code' => is_file(BBN_DATA_PATH.'ide/defaults/default.php') ? file_get_contents(BBN_DATA_PATH.'ide/defaults/default.php') : ''
],
'css' => [
'name' => 'CSS',
'mode' => 'text/css',
'code' => is_file(BBN_DATA_PATH.'ide/defaults/default.css') ? file_get_contents(BBN_DATA_PATH.'ide/defaults/default.css') : ''
],
'less' => [
'name' => 'LESS',
'mode' => 'text/x-less',
'code' => is_file(BBN_DATA_PATH.'ide/defaults/default.css') ? file_get_contents(BBN_DATA_PATH.'ide/defaults/default.css') : ''
],
'sql' => [
'name' => 'SQL',
'mode' => 'text/x-sql',
'code' => is_file(BBN_DATA_PATH.'ide/defaults/default.sql') ? file_get_contents(BBN_DATA_PATH.'ide/defaults/default.sql') : ''
],
'def' => [
'mode' => 'application/x-httpd-php',
'code' => is_file(BBN_DATA_PATH.'ide/defaults/default.php') ? file_get_contents(BBN_DATA_PATH.'ide/defaults/default.php') : ''
]
];
return $type ? ( isset($r[$type]) ? $r[$type] : false ) : $r;
}
return false;
} | php | public function modes($type = false){
if ( \defined('BBN_DATA_PATH') ){
$r = [
'html' => [
'name' => 'HTML',
'mode' => 'htmlmixed',
'code' => is_file(BBN_DATA_PATH.'ide/defaults/default.html') ? file_get_contents(BBN_DATA_PATH.'ide/defaults/default.html') : ''
],
'xml' => [
'name' => 'XML',
'mode' => 'text/xml',
'code' => is_file(BBN_DATA_PATH.'ide/defaults/default.xml') ? file_get_contents(BBN_DATA_PATH.'ide/defaults/default.xml') : ''
],
'js' => [
'name' => 'JavaScript',
'mode' => 'javascript',
'code' => is_file(BBN_DATA_PATH.'ide/defaults/default.js') ? file_get_contents(BBN_DATA_PATH.'ide/defaults/default.js') : ''
],
'svg' => [
'name' => 'SVG',
'mode' => 'text/xml',
'code' => is_file(BBN_DATA_PATH.'ide/defaults/default.svg') ? file_get_contents(BBN_DATA_PATH.'ide/defaults/default.svg') : ''
],
'php' => [
'name' => 'PHP',
'mode' => 'application/x-httpd-php',
'code' => is_file(BBN_DATA_PATH.'ide/defaults/default.php') ? file_get_contents(BBN_DATA_PATH.'ide/defaults/default.php') : ''
],
'css' => [
'name' => 'CSS',
'mode' => 'text/css',
'code' => is_file(BBN_DATA_PATH.'ide/defaults/default.css') ? file_get_contents(BBN_DATA_PATH.'ide/defaults/default.css') : ''
],
'less' => [
'name' => 'LESS',
'mode' => 'text/x-less',
'code' => is_file(BBN_DATA_PATH.'ide/defaults/default.css') ? file_get_contents(BBN_DATA_PATH.'ide/defaults/default.css') : ''
],
'sql' => [
'name' => 'SQL',
'mode' => 'text/x-sql',
'code' => is_file(BBN_DATA_PATH.'ide/defaults/default.sql') ? file_get_contents(BBN_DATA_PATH.'ide/defaults/default.sql') : ''
],
'def' => [
'mode' => 'application/x-httpd-php',
'code' => is_file(BBN_DATA_PATH.'ide/defaults/default.php') ? file_get_contents(BBN_DATA_PATH.'ide/defaults/default.php') : ''
]
];
return $type ? ( isset($r[$type]) ? $r[$type] : false ) : $r;
}
return false;
} | [
"public",
"function",
"modes",
"(",
"$",
"type",
"=",
"false",
")",
"{",
"if",
"(",
"\\",
"defined",
"(",
"'BBN_DATA_PATH'",
")",
")",
"{",
"$",
"r",
"=",
"[",
"'html'",
"=>",
"[",
"'name'",
"=>",
"'HTML'",
",",
"'mode'",
"=>",
"'htmlmixed'",
",",
"'code'",
"=>",
"is_file",
"(",
"BBN_DATA_PATH",
".",
"'ide/defaults/default.html'",
")",
"?",
"file_get_contents",
"(",
"BBN_DATA_PATH",
".",
"'ide/defaults/default.html'",
")",
":",
"''",
"]",
",",
"'xml'",
"=>",
"[",
"'name'",
"=>",
"'XML'",
",",
"'mode'",
"=>",
"'text/xml'",
",",
"'code'",
"=>",
"is_file",
"(",
"BBN_DATA_PATH",
".",
"'ide/defaults/default.xml'",
")",
"?",
"file_get_contents",
"(",
"BBN_DATA_PATH",
".",
"'ide/defaults/default.xml'",
")",
":",
"''",
"]",
",",
"'js'",
"=>",
"[",
"'name'",
"=>",
"'JavaScript'",
",",
"'mode'",
"=>",
"'javascript'",
",",
"'code'",
"=>",
"is_file",
"(",
"BBN_DATA_PATH",
".",
"'ide/defaults/default.js'",
")",
"?",
"file_get_contents",
"(",
"BBN_DATA_PATH",
".",
"'ide/defaults/default.js'",
")",
":",
"''",
"]",
",",
"'svg'",
"=>",
"[",
"'name'",
"=>",
"'SVG'",
",",
"'mode'",
"=>",
"'text/xml'",
",",
"'code'",
"=>",
"is_file",
"(",
"BBN_DATA_PATH",
".",
"'ide/defaults/default.svg'",
")",
"?",
"file_get_contents",
"(",
"BBN_DATA_PATH",
".",
"'ide/defaults/default.svg'",
")",
":",
"''",
"]",
",",
"'php'",
"=>",
"[",
"'name'",
"=>",
"'PHP'",
",",
"'mode'",
"=>",
"'application/x-httpd-php'",
",",
"'code'",
"=>",
"is_file",
"(",
"BBN_DATA_PATH",
".",
"'ide/defaults/default.php'",
")",
"?",
"file_get_contents",
"(",
"BBN_DATA_PATH",
".",
"'ide/defaults/default.php'",
")",
":",
"''",
"]",
",",
"'css'",
"=>",
"[",
"'name'",
"=>",
"'CSS'",
",",
"'mode'",
"=>",
"'text/css'",
",",
"'code'",
"=>",
"is_file",
"(",
"BBN_DATA_PATH",
".",
"'ide/defaults/default.css'",
")",
"?",
"file_get_contents",
"(",
"BBN_DATA_PATH",
".",
"'ide/defaults/default.css'",
")",
":",
"''",
"]",
",",
"'less'",
"=>",
"[",
"'name'",
"=>",
"'LESS'",
",",
"'mode'",
"=>",
"'text/x-less'",
",",
"'code'",
"=>",
"is_file",
"(",
"BBN_DATA_PATH",
".",
"'ide/defaults/default.css'",
")",
"?",
"file_get_contents",
"(",
"BBN_DATA_PATH",
".",
"'ide/defaults/default.css'",
")",
":",
"''",
"]",
",",
"'sql'",
"=>",
"[",
"'name'",
"=>",
"'SQL'",
",",
"'mode'",
"=>",
"'text/x-sql'",
",",
"'code'",
"=>",
"is_file",
"(",
"BBN_DATA_PATH",
".",
"'ide/defaults/default.sql'",
")",
"?",
"file_get_contents",
"(",
"BBN_DATA_PATH",
".",
"'ide/defaults/default.sql'",
")",
":",
"''",
"]",
",",
"'def'",
"=>",
"[",
"'mode'",
"=>",
"'application/x-httpd-php'",
",",
"'code'",
"=>",
"is_file",
"(",
"BBN_DATA_PATH",
".",
"'ide/defaults/default.php'",
")",
"?",
"file_get_contents",
"(",
"BBN_DATA_PATH",
".",
"'ide/defaults/default.php'",
")",
":",
"''",
"]",
"]",
";",
"return",
"$",
"type",
"?",
"(",
"isset",
"(",
"$",
"r",
"[",
"$",
"type",
"]",
")",
"?",
"$",
"r",
"[",
"$",
"type",
"]",
":",
"false",
")",
":",
"$",
"r",
";",
"}",
"return",
"false",
";",
"}"
] | Returns
@return array | [
"Returns"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/ide/directories.php#L1894-L1945 |
pinepain/amqpy | src/AMQPy/Support/DeliveryBuilder.php | DeliveryBuilder.wrap | public function wrap(AMQPEnvelope $envelope, $properties_skeleton = 'AMQPy\Client\Properties', $envelope_skeleton = 'AMQPy\Client\Envelope')
{
return new $this->wrapper_skeleton($envelope, $properties_skeleton, $envelope_skeleton);
} | php | public function wrap(AMQPEnvelope $envelope, $properties_skeleton = 'AMQPy\Client\Properties', $envelope_skeleton = 'AMQPy\Client\Envelope')
{
return new $this->wrapper_skeleton($envelope, $properties_skeleton, $envelope_skeleton);
} | [
"public",
"function",
"wrap",
"(",
"AMQPEnvelope",
"$",
"envelope",
",",
"$",
"properties_skeleton",
"=",
"'AMQPy\\Client\\Properties'",
",",
"$",
"envelope_skeleton",
"=",
"'AMQPy\\Client\\Envelope'",
")",
"{",
"return",
"new",
"$",
"this",
"->",
"wrapper_skeleton",
"(",
"$",
"envelope",
",",
"$",
"properties_skeleton",
",",
"$",
"envelope_skeleton",
")",
";",
"}"
] | @param AMQPEnvelope $envelope
@param string $properties_skeleton
@param string $envelope_skeleton
@return EnvelopeWrapper | [
"@param",
"AMQPEnvelope",
"$envelope",
"@param",
"string",
"$properties_skeleton",
"@param",
"string",
"$envelope_skeleton"
] | train | https://github.com/pinepain/amqpy/blob/fc61dacc37a97a100caf67232a72be32dd7cc896/src/AMQPy/Support/DeliveryBuilder.php#L27-L30 |
pinepain/amqpy | src/AMQPy/Support/DeliveryBuilder.php | DeliveryBuilder.build | public function build(AMQPEnvelope $envelope)
{
$wrapper = $this->wrap($envelope);
return new $this->delivery_skeleton($wrapper->getBody(), $wrapper->getEnvelope(), $wrapper->getProperties());
} | php | public function build(AMQPEnvelope $envelope)
{
$wrapper = $this->wrap($envelope);
return new $this->delivery_skeleton($wrapper->getBody(), $wrapper->getEnvelope(), $wrapper->getProperties());
} | [
"public",
"function",
"build",
"(",
"AMQPEnvelope",
"$",
"envelope",
")",
"{",
"$",
"wrapper",
"=",
"$",
"this",
"->",
"wrap",
"(",
"$",
"envelope",
")",
";",
"return",
"new",
"$",
"this",
"->",
"delivery_skeleton",
"(",
"$",
"wrapper",
"->",
"getBody",
"(",
")",
",",
"$",
"wrapper",
"->",
"getEnvelope",
"(",
")",
",",
"$",
"wrapper",
"->",
"getProperties",
"(",
")",
")",
";",
"}"
] | @param AMQPEnvelope $envelope
@return Delivery | [
"@param",
"AMQPEnvelope",
"$envelope"
] | train | https://github.com/pinepain/amqpy/blob/fc61dacc37a97a100caf67232a72be32dd7cc896/src/AMQPy/Support/DeliveryBuilder.php#L37-L42 |
willhoffmann/domuserp-php | src/DataReceiver.php | DataReceiver.payload | public function payload(array $data)
{
foreach ($data as $key => $value) {
$this->data->{$key} = $value;
}
return $this;
} | php | public function payload(array $data)
{
foreach ($data as $key => $value) {
$this->data->{$key} = $value;
}
return $this;
} | [
"public",
"function",
"payload",
"(",
"array",
"$",
"data",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"data",
"->",
"{",
"$",
"key",
"}",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Payload the request
@param array $data
@return $this | [
"Payload",
"the",
"request"
] | train | https://github.com/willhoffmann/domuserp-php/blob/44e77a4f02b0252bc26cae4c0e6b2b7d578f10a6/src/DataReceiver.php#L44-L51 |
willhoffmann/domuserp-php | src/DataReceiver.php | DataReceiver.toArray | public function toArray()
{
$this->data->id = $this->id;
return json_decode(json_encode($this->data), true);
} | php | public function toArray()
{
$this->data->id = $this->id;
return json_decode(json_encode($this->data), true);
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"$",
"this",
"->",
"data",
"->",
"id",
"=",
"$",
"this",
"->",
"id",
";",
"return",
"json_decode",
"(",
"json_encode",
"(",
"$",
"this",
"->",
"data",
")",
",",
"true",
")",
";",
"}"
] | Get the request data
@return array | [
"Get",
"the",
"request",
"data"
] | train | https://github.com/willhoffmann/domuserp-php/blob/44e77a4f02b0252bc26cae4c0e6b2b7d578f10a6/src/DataReceiver.php#L58-L63 |
Innmind/neo4j-dbal | src/Result/Result.php | Result.fromRaw | public static function fromRaw(array $response): self
{
$data = $response['data'] ?? [];
return new self(
self::buildNodes($data),
self::buildRelationships($data),
self::buildRows($response)
);
} | php | public static function fromRaw(array $response): self
{
$data = $response['data'] ?? [];
return new self(
self::buildNodes($data),
self::buildRelationships($data),
self::buildRows($response)
);
} | [
"public",
"static",
"function",
"fromRaw",
"(",
"array",
"$",
"response",
")",
":",
"self",
"{",
"$",
"data",
"=",
"$",
"response",
"[",
"'data'",
"]",
"??",
"[",
"]",
";",
"return",
"new",
"self",
"(",
"self",
"::",
"buildNodes",
"(",
"$",
"data",
")",
",",
"self",
"::",
"buildRelationships",
"(",
"$",
"data",
")",
",",
"self",
"::",
"buildRows",
"(",
"$",
"response",
")",
")",
";",
"}"
] | Build a result object out of a standard neo4j rest api response
@param array $response
@return self | [
"Build",
"a",
"result",
"object",
"out",
"of",
"a",
"standard",
"neo4j",
"rest",
"api",
"response"
] | train | https://github.com/Innmind/neo4j-dbal/blob/12cb71e698cc0f4d55b7f2eb40f7b353c778a20b/src/Result/Result.php#L38-L47 |
Innmind/neo4j-dbal | src/Result/Result.php | Result.buildNodes | private static function buildNodes(array $data): MapInterface
{
$nodes = new Map('int', Node::class);
foreach ($data as $response) {
foreach ($response['graph']['nodes'] as $node) {
$labels = Set::of('string', ...\array_values($node['labels']));
$nodes = $nodes->put(
(int) $node['id'],
new Node\Node(
new Id((int) $node['id']),
$labels,
self::buildProperties($node['properties'])
)
);
}
}
return $nodes;
} | php | private static function buildNodes(array $data): MapInterface
{
$nodes = new Map('int', Node::class);
foreach ($data as $response) {
foreach ($response['graph']['nodes'] as $node) {
$labels = Set::of('string', ...\array_values($node['labels']));
$nodes = $nodes->put(
(int) $node['id'],
new Node\Node(
new Id((int) $node['id']),
$labels,
self::buildProperties($node['properties'])
)
);
}
}
return $nodes;
} | [
"private",
"static",
"function",
"buildNodes",
"(",
"array",
"$",
"data",
")",
":",
"MapInterface",
"{",
"$",
"nodes",
"=",
"new",
"Map",
"(",
"'int'",
",",
"Node",
"::",
"class",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"response",
")",
"{",
"foreach",
"(",
"$",
"response",
"[",
"'graph'",
"]",
"[",
"'nodes'",
"]",
"as",
"$",
"node",
")",
"{",
"$",
"labels",
"=",
"Set",
"::",
"of",
"(",
"'string'",
",",
"...",
"\\",
"array_values",
"(",
"$",
"node",
"[",
"'labels'",
"]",
")",
")",
";",
"$",
"nodes",
"=",
"$",
"nodes",
"->",
"put",
"(",
"(",
"int",
")",
"$",
"node",
"[",
"'id'",
"]",
",",
"new",
"Node",
"\\",
"Node",
"(",
"new",
"Id",
"(",
"(",
"int",
")",
"$",
"node",
"[",
"'id'",
"]",
")",
",",
"$",
"labels",
",",
"self",
"::",
"buildProperties",
"(",
"$",
"node",
"[",
"'properties'",
"]",
")",
")",
")",
";",
"}",
"}",
"return",
"$",
"nodes",
";",
"}"
] | @param array $data
@return MapInterface<int, Node> | [
"@param",
"array",
"$data"
] | train | https://github.com/Innmind/neo4j-dbal/blob/12cb71e698cc0f4d55b7f2eb40f7b353c778a20b/src/Result/Result.php#L78-L98 |
Innmind/neo4j-dbal | src/Result/Result.php | Result.buildRelationships | private static function buildRelationships(array $data): MapInterface
{
$relationships = new Map('int', Relationship::class);
foreach ($data as $response) {
foreach ($response['graph']['relationships'] as $rel) {
$relationships = $relationships->put(
(int) $rel['id'],
new Relationship\Relationship(
new Id((int) $rel['id']),
new Type($rel['type']),
new Id((int) $rel['startNode']),
new Id((int) $rel['endNode']),
self::buildProperties($rel['properties'])
)
);
}
}
return $relationships;
} | php | private static function buildRelationships(array $data): MapInterface
{
$relationships = new Map('int', Relationship::class);
foreach ($data as $response) {
foreach ($response['graph']['relationships'] as $rel) {
$relationships = $relationships->put(
(int) $rel['id'],
new Relationship\Relationship(
new Id((int) $rel['id']),
new Type($rel['type']),
new Id((int) $rel['startNode']),
new Id((int) $rel['endNode']),
self::buildProperties($rel['properties'])
)
);
}
}
return $relationships;
} | [
"private",
"static",
"function",
"buildRelationships",
"(",
"array",
"$",
"data",
")",
":",
"MapInterface",
"{",
"$",
"relationships",
"=",
"new",
"Map",
"(",
"'int'",
",",
"Relationship",
"::",
"class",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"response",
")",
"{",
"foreach",
"(",
"$",
"response",
"[",
"'graph'",
"]",
"[",
"'relationships'",
"]",
"as",
"$",
"rel",
")",
"{",
"$",
"relationships",
"=",
"$",
"relationships",
"->",
"put",
"(",
"(",
"int",
")",
"$",
"rel",
"[",
"'id'",
"]",
",",
"new",
"Relationship",
"\\",
"Relationship",
"(",
"new",
"Id",
"(",
"(",
"int",
")",
"$",
"rel",
"[",
"'id'",
"]",
")",
",",
"new",
"Type",
"(",
"$",
"rel",
"[",
"'type'",
"]",
")",
",",
"new",
"Id",
"(",
"(",
"int",
")",
"$",
"rel",
"[",
"'startNode'",
"]",
")",
",",
"new",
"Id",
"(",
"(",
"int",
")",
"$",
"rel",
"[",
"'endNode'",
"]",
")",
",",
"self",
"::",
"buildProperties",
"(",
"$",
"rel",
"[",
"'properties'",
"]",
")",
")",
")",
";",
"}",
"}",
"return",
"$",
"relationships",
";",
"}"
] | @param array $data
@return MapInterface<int, Relationship> | [
"@param",
"array",
"$data"
] | train | https://github.com/Innmind/neo4j-dbal/blob/12cb71e698cc0f4d55b7f2eb40f7b353c778a20b/src/Result/Result.php#L105-L125 |
Innmind/neo4j-dbal | src/Result/Result.php | Result.buildRows | private static function buildRows(array $data): StreamInterface
{
$rows = new Stream(Row::class);
$responses = $data['data'] ?? [];
foreach ($responses as $response) {
foreach ($response['row'] as $idx => $row) {
$rows = $rows->add(new Row\Row(
$data['columns'][$idx],
$row
));
}
}
return $rows;
} | php | private static function buildRows(array $data): StreamInterface
{
$rows = new Stream(Row::class);
$responses = $data['data'] ?? [];
foreach ($responses as $response) {
foreach ($response['row'] as $idx => $row) {
$rows = $rows->add(new Row\Row(
$data['columns'][$idx],
$row
));
}
}
return $rows;
} | [
"private",
"static",
"function",
"buildRows",
"(",
"array",
"$",
"data",
")",
":",
"StreamInterface",
"{",
"$",
"rows",
"=",
"new",
"Stream",
"(",
"Row",
"::",
"class",
")",
";",
"$",
"responses",
"=",
"$",
"data",
"[",
"'data'",
"]",
"??",
"[",
"]",
";",
"foreach",
"(",
"$",
"responses",
"as",
"$",
"response",
")",
"{",
"foreach",
"(",
"$",
"response",
"[",
"'row'",
"]",
"as",
"$",
"idx",
"=>",
"$",
"row",
")",
"{",
"$",
"rows",
"=",
"$",
"rows",
"->",
"add",
"(",
"new",
"Row",
"\\",
"Row",
"(",
"$",
"data",
"[",
"'columns'",
"]",
"[",
"$",
"idx",
"]",
",",
"$",
"row",
")",
")",
";",
"}",
"}",
"return",
"$",
"rows",
";",
"}"
] | @param array $data
@return StreamInterface<Row> | [
"@param",
"array",
"$data"
] | train | https://github.com/Innmind/neo4j-dbal/blob/12cb71e698cc0f4d55b7f2eb40f7b353c778a20b/src/Result/Result.php#L132-L147 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.